FD.io VPP  v19.01.2-3-gf61a1a8
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 
18 namespace VOM {
19 namespace neighbour_cmds {
21  handle_t itf,
22  const mac_address_t& mac,
23  const boost::asio::ip::address& ip_addr)
24  : rpc_cmd(item)
25  , m_itf(itf)
26  , m_mac(mac)
27  , m_ip_addr(ip_addr)
28 {
29 }
30 
31 bool
33 {
34  return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
35  (m_itf == other.m_itf));
36 }
37 
38 rc_t
40 {
41  msg_t req(con.ctx(), std::ref(*this));
42 
43  auto& payload = req.get_request().get_payload();
44  payload.sw_if_index = m_itf.value();
45  payload.is_add = 1;
46  payload.is_static = 1;
47  m_mac.to_bytes(payload.mac_address, 6);
48  to_bytes(m_ip_addr, &payload.is_ipv6, payload.dst_address);
49 
50  VAPI_CALL(req.execute());
51 
52  return (wait());
53 }
54 
55 std::string
57 {
58  std::ostringstream s;
59  s << "nieghbour-create: " << m_hw_item.to_string()
60  << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string()
61  << " ip:" << m_ip_addr.to_string();
62 
63  return (s.str());
64 }
65 
67  handle_t itf,
68  const mac_address_t& mac,
69  const boost::asio::ip::address& ip_addr)
70  : rpc_cmd(item)
71  , m_itf(itf)
72  , m_mac(mac)
73  , m_ip_addr(ip_addr)
74 {
75 }
76 
77 bool
79 {
80  return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
81  (m_itf == other.m_itf));
82 }
83 
84 rc_t
86 {
87  msg_t req(con.ctx(), std::ref(*this));
88 
89  auto& payload = req.get_request().get_payload();
90  payload.sw_if_index = m_itf.value();
91  payload.is_add = 0;
92  payload.is_static = 1;
93  m_mac.to_bytes(payload.mac_address, 6);
94  to_bytes(m_ip_addr, &payload.is_ipv6, payload.dst_address);
95 
96  VAPI_CALL(req.execute());
97 
98  wait();
100 
101  return rc_t::OK;
102 }
103 
104 std::string
106 {
107  std::ostringstream s;
108  s << "neighbour-delete: " << m_hw_item.to_string()
109  << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string()
110  << " ip:" << m_ip_addr.to_string();
111 
112  return (s.str());
113 }
114 
115 dump_cmd::dump_cmd(const handle_t& hdl, const l3_proto_t& proto)
116  : m_itf(hdl)
117  , m_proto(proto)
118 {
119 }
120 
122  : m_itf(d.m_itf)
123  , m_proto(d.m_proto)
124 {
125 }
126 
127 bool
128 dump_cmd::operator==(const dump_cmd& other) const
129 {
130  return (true);
131 }
132 
133 rc_t
135 {
136  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
137 
138  auto& payload = m_dump->get_request().get_payload();
139  payload.sw_if_index = m_itf.value();
140  payload.is_ipv6 = m_proto.is_ipv6();
141 
142  VAPI_CALL(m_dump->execute());
143 
144  wait();
145 
146  return rc_t::OK;
147 }
148 
149 std::string
151 {
152  std::ostringstream s;
153 
154  s << "neighbour-dump: " << m_itf.to_string() << " " << m_proto.to_string();
155 
156  return (s.str());
157 }
158 } // namespace neighbour_cmds
159 } // namespace vom
160 
161 /*
162  * fd.io coding-style-patch-verification: ON
163  *
164  * Local Variables:
165  * eval: (c-set-style "mozilla")
166  * End:
167  */
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:30
A cmd class that deletes a bridge domain ARP entry.
std::string to_string() const
convert to string format for debug purposes
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
std::string to_string() const
String conversion.
Definition: types.cpp:148
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
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 wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
rc_t issue(connection &con)
Issue the command to VPP/HW.
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
Definition: prefix.cpp:218
A representation of the connection to VPP.
Definition: connection.hpp:33
dump_cmd()
Default Constructor.
Definition: dump_cmd.hpp:55
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
delete_cmd(HW::item< bool > &item, handle_t itf, const mac_address_t &mac, const boost::asio::ip::address &ip_addr)
Constructor.
create_cmd(HW::item< bool > &item, handle_t itf, const mac_address_t &mac, const boost::asio::ip::address &ip_addr)
Constructor.
std::string to_string() const
convert to string format for debug purposes
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
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
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:140
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
std::string to_string() const
convert to string format for debug purposes
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
rc_t issue(connection &con)
Issue the command to VPP/HW.
Type def of a Ethernet address.
Definition: types.hpp:295
vl_api_mac_address_t mac
Definition: gbp.api:118
HW::item< bool > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:134
bool is_ipv6()
Definition: prefix.cpp:35
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vapi::Ip_neighbor_add_del msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.