FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
neighbour_cmds.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "vom/neighbour_cmds.hpp"
17 #include "vom/api_types.hpp"
18 
20 
21 namespace VOM {
22 namespace neighbour_cmds {
24  handle_t itf,
25  const mac_address_t& mac,
26  const boost::asio::ip::address& ip_addr,
28  : srpc_cmd(item)
29  , m_itf(itf)
30  , m_mac(mac)
31  , m_ip_addr(ip_addr)
32  , m_flags(flags)
33 {}
34 
35 bool
37 {
38  return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
39  (m_itf == other.m_itf) && (m_flags == other.m_flags));
40 }
41 
42 rc_t
44 {
45  msg_t req(con.ctx(), std::ref(*this));
46 
47  auto& payload = req.get_request().get_payload();
48  payload.is_add = 1;
49  payload.neighbor.sw_if_index = m_itf.value();
50 
51  to_api(m_mac, payload.neighbor.mac_address);
52  to_api(m_ip_addr, payload.neighbor.ip_address);
53  payload.neighbor.flags = to_api(m_flags);
54 
55  VAPI_CALL(req.execute());
56 
57  return (wait());
58 }
59 
62 {
63  std::ostringstream s;
64  s << "nieghbour-create: " << m_hw_item.to_string()
65  << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string()
66  << " ip:" << m_ip_addr.to_string();
67 
68  return (s.str());
69 }
70 
72  handle_t itf,
73  const mac_address_t& mac,
74  const boost::asio::ip::address& ip_addr,
76  : srpc_cmd(item)
77  , m_itf(itf)
78  , m_mac(mac)
79  , m_ip_addr(ip_addr)
80  , m_flags(flags)
81 {}
82 
83 bool
85 {
86  return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
87  (m_itf == other.m_itf));
88 }
89 
90 rc_t
92 {
93  msg_t req(con.ctx(), std::ref(*this));
94 
95  auto& payload = req.get_request().get_payload();
96  payload.is_add = 0;
97  payload.neighbor.sw_if_index = m_itf.value();
98 
99  to_api(m_mac, payload.neighbor.mac_address);
100  to_api(m_ip_addr, payload.neighbor.ip_address);
101  payload.neighbor.flags = to_api(m_flags);
102 
103  VAPI_CALL(req.execute());
104 
105  wait();
107 
108  return rc_t::OK;
109 }
110 
113 {
114  std::ostringstream s;
115  s << "neighbour-delete: " << m_hw_item.to_string()
116  << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string()
117  << " ip:" << m_ip_addr.to_string();
118 
119  return (s.str());
120 }
121 
123  : m_itf(hdl)
124  , m_proto(proto)
125 {}
126 
128  : m_itf(d.m_itf)
129  , m_proto(d.m_proto)
130 {}
131 
132 bool
133 dump_cmd::operator==(const dump_cmd& other) const
134 {
135  return (true);
136 }
137 
138 rc_t
140 {
141  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
142 
143  auto& payload = m_dump->get_request().get_payload();
144  payload.sw_if_index = m_itf.value();
145  payload.af = to_api(m_proto);
146 
147  VAPI_CALL(m_dump->execute());
148 
149  wait();
150 
151  return rc_t::OK;
152 }
153 
156 {
157  std::ostringstream s;
158 
159  s << "neighbour-dump: " << m_itf.to_string() << " " << m_proto.to_string();
160 
161  return (s.str());
162 }
163 } // namespace neighbour_cmds
164 } // namespace vom
165 
166 /*
167  * fd.io coding-style-patch-verification: OFF
168  *
169  * Local Variables:
170  * eval: (c-set-style "mozilla")
171  * End:
172  */
VOM::HW::item< handle_t >
VOM::dump_cmd< vapi::Ip_neighbor_dump >::msg_t
vapi::Ip_neighbor_dump msg_t
Definition: dump_cmd.hpp:46
mac
vl_api_mac_address_t mac
Definition: l2.api:559
VOM::neighbour_cmds::delete_cmd::delete_cmd
delete_cmd(HW::item< handle_t > &item, handle_t itf, const mac_address_t &mac, const boost::asio::ip::address &ip_addr, const neighbour::flags_t &flags)
Constructor.
Definition: neighbour_cmds.cpp:71
VOM::rpc_cmd< HW::item< handle_t >, vapi::Ip_neighbor_add_del >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
VOM::HW::item::set
void set(const rc_t &rc)
Set the HW return code - should only be called from the family of Command objects.
Definition: hw.hpp:125
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
neighbour_cmds.hpp
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::neighbour_cmds::delete_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: neighbour_cmds.cpp:112
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::rpc_cmd< HW::item< handle_t >, vapi::Ip_neighbor_add_del >::m_hw_item
HW::item< handle_t > & m_hw_item
A reference to an object's HW::item that the command will update.
Definition: rpc_cmd.hpp:134
VOM::dump_cmd< vapi::Ip_neighbor_dump >::m_dump
std::unique_ptr< vapi::Ip_neighbor_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::neighbour_cmds::create_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: neighbour_cmds.cpp:61
DEFINE_VAPI_MSG_IDS_IP_NEIGHBOR_API_JSON
DEFINE_VAPI_MSG_IDS_IP_NEIGHBOR_API_JSON
Definition: neighbour_cmds.cpp:19
VOM::neighbour_cmds::create_cmd::create_cmd
create_cmd(HW::item< handle_t > &item, handle_t itf, const mac_address_t &mac, const boost::asio::ip::address &ip_addr, const neighbour::flags_t &flags)
Constructor.
Definition: neighbour_cmds.cpp:23
VOM::neighbour_cmds::delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: neighbour_cmds.cpp:91
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::neighbour_cmds::delete_cmd::operator==
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: neighbour_cmds.cpp:84
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::dump_cmd< vapi::Ip_neighbor_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::neighbour_cmds::create_cmd::operator==
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
Definition: neighbour_cmds.cpp:36
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::neighbour_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: neighbour_cmds.cpp:139
address
manual_print typedef address
Definition: ip_types.api:96
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::neighbour_cmds::create_cmd
A command class that creates or updates the bridge domain ARP Entry.
Definition: neighbour_cmds.hpp:31
VOM::to_api
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
VOM::rpc_cmd< HW::item< handle_t >, vapi::Ip_neighbor_add_del >::msg_t
vapi::Ip_neighbor_add_del msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::enum_base::to_string
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
VOM::neighbour_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: neighbour_cmds.cpp:155
VOM::neighbour_cmds::create_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: neighbour_cmds.cpp:43
VOM::neighbour_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: neighbour_cmds.cpp:133
VOM::neighbour_cmds::dump_cmd
A cmd class that Dumps all the neighbours.
Definition: neighbour_cmds.hpp:105
VOM::l3_proto_t
An L3 protocol can be used to construct a prefix that is used to match packets are part of a route.
Definition: prefix.hpp:52
VOM::handle_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
VOM::srpc_cmd
Definition: srpc_cmd.hpp:24
VOM::neighbour_cmds::delete_cmd
A cmd class that deletes a bridge domain ARP entry.
Definition: neighbour_cmds.hpp:68
VOM::mac_address_t::to_string
std::string to_string() const
String conversion.
Definition: types.cpp:148
VOM::mac_address_t
Type def of a Ethernet address.
Definition: types.hpp:295
item
cJSON * item
Definition: cJSON.h:222
VOM::dump_cmd< vapi::Ip_neighbor_dump >::dump_cmd
dump_cmd()
Default Constructor.
Definition: dump_cmd.hpp:55
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
VOM::neighbour::flags_t
Definition: neighbour.hpp:30
api_types.hpp
string
const char *const string
Definition: cJSON.h:172
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105