FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gbp_endpoint_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 
17 #include "vom/api_types.hpp"
18 
20 
21 namespace VOM {
22 namespace gbp_endpoint_cmds {
23 
24 static vapi_enum_gbp_endpoint_flags
26 {
27  vapi_enum_gbp_endpoint_flags out = GBP_API_ENDPOINT_FLAG_NONE;
28 
30  out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_REMOTE);
32  out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_BOUNCE);
34  out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_LEARNT);
36  out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_EXTERNAL);
37 
38  return (out);
39 }
40 
42  const handle_t& itf,
43  const std::vector<boost::asio::ip::address>& ip_addrs,
44  const mac_address_t& mac,
47  : rpc_cmd(item)
48  , m_itf(itf)
49  , m_ip_addrs(ip_addrs)
50  , m_mac(mac)
51  , m_sclass(sclass)
52  , m_flags(flags)
53 {
54 }
55 
56 bool
58 {
59  return ((m_itf == other.m_itf) && (m_ip_addrs == other.m_ip_addrs) &&
60  (m_mac == other.m_mac) && (m_sclass == other.m_sclass) &&
61  (m_flags == other.m_flags));
62 }
63 
64 rc_t
66 {
67  msg_t req(con.ctx(), m_ip_addrs.size() * sizeof(vapi_type_address),
68  std::ref(*this));
69  uint8_t n;
70 
71  auto& payload = req.get_request().get_payload();
72  payload.endpoint.sw_if_index = m_itf.value();
73  payload.endpoint.sclass = m_sclass;
74  payload.endpoint.n_ips = m_ip_addrs.size();
75  payload.endpoint.flags = to_api(m_flags);
76 
77  for (n = 0; n < payload.endpoint.n_ips; n++) {
78  VOM::to_api(m_ip_addrs[n], payload.endpoint.ips[n]);
79  }
80  to_api(m_mac, payload.endpoint.mac);
81 
82  VAPI_CALL(req.execute());
83 
84  return (wait());
85 }
86 
88 create_cmd::operator()(vapi::Gbp_endpoint_add& reply)
89 {
90  int handle = reply.get_response().get_payload().handle;
91  int retval = reply.get_response().get_payload().retval;
92 
93  VOM_LOG(log_level_t::DEBUG) << this->to_string() << " " << retval;
94 
95  rc_t rc = rc_t::from_vpp_retval(retval);
97 
98  if (rc_t::OK == rc) {
99  hdl = handle;
100  }
101 
102  this->fulfill(HW::item<handle_t>(hdl, rc));
103 
104  return (VAPI_OK);
105 }
106 
109 {
110  std::ostringstream s;
111  s << "gbp-endpoint-create: " << m_hw_item.to_string() << " itf:" << m_itf
112  << " ips:[";
113  for (auto ip : m_ip_addrs)
114  s << ip.to_string();
115 
116  s << "] mac:" << m_mac << " slcass:" << m_sclass
117  << " flags:" << m_flags.to_string();
118 
119  return (s.str());
120 }
121 
123  : rpc_cmd(item)
124 {
125 }
126 
127 bool
129 {
130  return (m_hw_item == other.m_hw_item);
131 }
132 
133 rc_t
135 {
136  msg_t req(con.ctx(), std::ref(*this));
137 
138  auto& payload = req.get_request().get_payload();
139  payload.handle = m_hw_item.data().value();
140 
141  VAPI_CALL(req.execute());
142 
143  return (wait());
144 }
145 
148 {
149  std::ostringstream s;
150  s << "gbp-endpoint-delete: " << m_hw_item.to_string();
151 
152  return (s.str());
153 }
154 
156 {
157 }
158 
159 bool
160 dump_cmd::operator==(const dump_cmd& other) const
161 {
162  return (true);
163 }
164 
165 rc_t
167 {
168  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
169 
170  VAPI_CALL(m_dump->execute());
171 
172  wait();
173 
174  return rc_t::OK;
175 }
176 
179 {
180  return ("gbp-endpoint-dump");
181 }
182 
183 }; // namespace gbp_endpoint_cmds
184 }; // namespace VOM
185 
186 /*
187  * fd.io coding-style-patch-verification: OFF
188  *
189  * Local Variables:
190  * eval: (c-set-style "mozilla")
191  * End:
192  */
vapi_error_e
vapi_error_e
Definition: vapi_common.h:25
GBP_API_ENDPOINT_FLAG_LEARNT
@ GBP_API_ENDPOINT_FLAG_LEARNT
Definition: gbp.api:118
VOM::HW::item< handle_t >
VOM::gbp_endpoint::flags_t::EXTERNAL
const static flags_t EXTERNAL
Definition: gbp_endpoint.hpp:42
VOM::dump_cmd< vapi::Gbp_endpoint_dump >::msg_t
vapi::Gbp_endpoint_dump msg_t
Definition: dump_cmd.hpp:46
mac
vl_api_mac_address_t mac
Definition: l2.api:559
VOM::gbp_endpoint_cmds::delete_cmd::delete_cmd
delete_cmd(HW::item< handle_t > &item)
Constructor.
Definition: gbp_endpoint_cmds.cpp:122
VOM::rpc_cmd< HW::item< handle_t >, vapi::Gbp_endpoint_add >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
DEFINE_VAPI_MSG_IDS_GBP_API_JSON
DEFINE_VAPI_MSG_IDS_GBP_API_JSON
Definition: gbp_endpoint_cmds.cpp:19
VOM_LOG
#define VOM_LOG(lvl)
Definition: logger.hpp:181
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::gbp_endpoint_cmds::delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: gbp_endpoint_cmds.cpp:134
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::rc_t::from_vpp_retval
static const rc_t & from_vpp_retval(int32_t rv)
Get the rc_t from the VPP API value.
Definition: types.cpp:33
VOM::gbp_endpoint_cmds::create_cmd
A command class that creates or updates the GBP endpoint.
Definition: gbp_endpoint_cmds.hpp:30
VOM::gbp_endpoint_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: gbp_endpoint_cmds.cpp:166
VOM::gbp_endpoint_cmds::dump_cmd::dump_cmd
dump_cmd()
Constructor.
Definition: gbp_endpoint_cmds.cpp:155
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
GBP_API_ENDPOINT_FLAG_BOUNCE
@ GBP_API_ENDPOINT_FLAG_BOUNCE
Definition: gbp.api:116
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::sclass_t
uint16_t sclass_t
Definition: gbp_types.hpp:27
GBP_API_ENDPOINT_FLAG_REMOTE
@ GBP_API_ENDPOINT_FLAG_REMOTE
Definition: gbp.api:117
VAPI_OK
@ VAPI_OK
success
Definition: vapi_common.h:27
VOM::rpc_cmd< HW::item< handle_t >, vapi::Gbp_endpoint_add >::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::Gbp_endpoint_dump >::m_dump
std::unique_ptr< vapi::Gbp_endpoint_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::gbp_endpoint_cmds::delete_cmd
A cmd class that deletes a GBP endpoint.
Definition: gbp_endpoint_cmds.hpp:71
VOM::gbp_endpoint_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: gbp_endpoint_cmds.cpp:160
VOM::gbp_endpoint::flags_t::BOUNCE
const static flags_t BOUNCE
Definition: gbp_endpoint.hpp:39
VOM::gbp_endpoint_cmds::create_cmd::create_cmd
create_cmd(HW::item< handle_t > &item, const handle_t &itf, const std::vector< boost::asio::ip::address > &ip_addrs, const mac_address_t &mac, sclass_t sclass, const gbp_endpoint::flags_t &flags)
Constructor.
Definition: gbp_endpoint_cmds.cpp:41
VOM::gbp_endpoint_cmds::delete_cmd::operator==
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: gbp_endpoint_cmds.cpp:128
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::gbp_endpoint_cmds::create_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: gbp_endpoint_cmds.cpp:65
VOM::gbp_endpoint::flags_t::LEARNT
const static flags_t LEARNT
Definition: gbp_endpoint.hpp:41
GBP_API_ENDPOINT_FLAG_NONE
@ GBP_API_ENDPOINT_FLAG_NONE
Definition: gbp.api:115
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
GBP_API_ENDPOINT_FLAG_EXTERNAL
@ GBP_API_ENDPOINT_FLAG_EXTERNAL
Definition: gbp.api:119
VOM::dump_cmd< vapi::Gbp_endpoint_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::gbp_endpoint::flags_t
Endpoint flags.
Definition: gbp_endpoint.hpp:36
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::gbp_endpoint_cmds::dump_cmd
A cmd class that Dumps all the GBP endpoints.
Definition: gbp_endpoint_cmds.hpp:101
VOM::gbp_endpoint_cmds::to_api
static vapi_enum_gbp_endpoint_flags to_api(const gbp_endpoint::flags_t &in)
Definition: gbp_endpoint_cmds.cpp:25
sclass
u16 sclass
Definition: gbp.api:131
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::log_level_t::DEBUG
const static log_level_t DEBUG
Definition: logger.hpp:32
VOM::gbp_endpoint::flags_t::REMOTE
const static flags_t REMOTE
Definition: gbp_endpoint.hpp:40
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::Gbp_endpoint_add >::msg_t
vapi::Gbp_endpoint_add 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::HW::item::data
T & data()
Return the data read/written.
Definition: hw.hpp:109
VOM::gbp_endpoint_cmds::create_cmd::operator==
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
Definition: gbp_endpoint_cmds.cpp:57
VOM::gbp_endpoint_cmds::create_cmd::operator()
virtual vapi_error_e operator()(vapi::Gbp_endpoint_add &reply)
call operator used as a callback by VAPI when the reply is available
Definition: gbp_endpoint_cmds.cpp:88
VOM::mac_address_t
Type def of a Ethernet address.
Definition: types.hpp:295
VOM::gbp_endpoint_cmds::create_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: gbp_endpoint_cmds.cpp:108
gbp_endpoint_cmds.hpp
item
cJSON * item
Definition: cJSON.h:222
VOM::handle_t::INVALID
const static handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
ip
vl_api_address_t ip
Definition: l2.api:558
VOM::gbp_endpoint_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: gbp_endpoint_cmds.cpp:178
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::gbp_endpoint_cmds::delete_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: gbp_endpoint_cmds.cpp:147
VOM::rpc_cmd< HW::item< handle_t >, vapi::Gbp_endpoint_add >::fulfill
void fulfill(const HW::item< handle_t > &d)
Fulfill the commands promise.
Definition: rpc_cmd.hpp:76
api_types.hpp
string
const char *const string
Definition: cJSON.h:172
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105