FD.io VPP  v19.08.3-2-gbabecb413
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 
19 namespace VOM {
20 namespace neighbour_cmds {
22  handle_t itf,
23  const mac_address_t& mac,
24  const boost::asio::ip::address& ip_addr,
26  : srpc_cmd(item)
27  , m_itf(itf)
28  , m_mac(mac)
29  , m_ip_addr(ip_addr)
30  , m_flags(flags)
31 {
32 }
33 
34 bool
36 {
37  return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
38  (m_itf == other.m_itf) && (m_flags == other.m_flags));
39 }
40 
41 rc_t
43 {
44  msg_t req(con.ctx(), std::ref(*this));
45 
46  auto& payload = req.get_request().get_payload();
47  payload.is_add = 1;
48  payload.neighbor.sw_if_index = m_itf.value();
49 
50  to_api(m_mac, payload.neighbor.mac_address);
51  to_api(m_ip_addr, payload.neighbor.ip_address);
52  payload.neighbor.flags = to_api(m_flags);
53 
54  VAPI_CALL(req.execute());
55 
56  return (wait());
57 }
58 
59 std::string
61 {
62  std::ostringstream s;
63  s << "nieghbour-create: " << m_hw_item.to_string()
64  << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string()
65  << " ip:" << m_ip_addr.to_string();
66 
67  return (s.str());
68 }
69 
71  handle_t itf,
72  const mac_address_t& mac,
73  const boost::asio::ip::address& ip_addr,
75  : srpc_cmd(item)
76  , m_itf(itf)
77  , m_mac(mac)
78  , m_ip_addr(ip_addr)
79  , m_flags(flags)
80 {
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 
111 std::string
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 }
127 
129  : m_itf(d.m_itf)
130  , m_proto(d.m_proto)
131 {
132 }
133 
134 bool
135 dump_cmd::operator==(const dump_cmd& other) const
136 {
137  return (true);
138 }
139 
140 rc_t
142 {
143  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
144 
145  auto& payload = m_dump->get_request().get_payload();
146  payload.sw_if_index = m_itf.value();
147  payload.is_ipv6 = m_proto.is_ipv6();
148 
149  VAPI_CALL(m_dump->execute());
150 
151  wait();
152 
153  return rc_t::OK;
154 }
155 
156 std::string
158 {
159  std::ostringstream s;
160 
161  s << "neighbour-dump: " << m_itf.to_string() << " " << m_proto.to_string();
162 
163  return (s.str());
164 }
165 } // namespace neighbour_cmds
166 } // namespace vom
167 
168 /*
169  * fd.io coding-style-patch-verification: ON
170  *
171  * Local Variables:
172  * eval: (c-set-style "mozilla")
173  * End:
174  */
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
typedef address
Definition: ip_types.api:83
u32 flags
Definition: vhost_user.h:141
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
A cmd class that deletes a bridge domain ARP entry.
vl_api_mac_address_t mac
Definition: l2.api:490
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
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
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
rc_t issue(connection &con)
Issue the command to VPP/HW.
A representation of the connection to VPP.
Definition: connection.hpp:33
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.
dump_cmd()
Default Constructor.
Definition: dump_cmd.hpp:55
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
std::string to_string() const
convert to string format for debug purposes
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
rc_t issue(connection &con)
Issue the command to VPP/HW.
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
A cmd class that Dumps all the neighbours.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
std::string to_string() const
String conversion.
Definition: types.cpp:148
std::string to_string() const
convert to string format for debug purposes
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A command class that creates or updates the bridge domain ARP Entry.
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
std::unique_ptr< vapi::Ip_neighbor_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
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.
rc_t issue(connection &con)
Issue the command to VPP/HW.
bool is_ipv6() const
Definition: prefix.cpp:35
Type def of a Ethernet address.
Definition: types.hpp:295
std::string to_string() const
convert to string format for debug purposes
HW::item< handle_t > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:134
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125
vapi::Ip_neighbor_add_del msg_t
convenient typedef
Definition: rpc_cmd.hpp:46