FD.io VPP  v18.10-34-gcce845e
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 
25  const handle_t& itf,
26  const std::vector<boost::asio::ip::address>& ip_addrs,
27  const mac_address_t& mac,
29  : rpc_cmd(item)
30  , m_itf(itf)
31  , m_ip_addrs(ip_addrs)
32  , m_mac(mac)
33  , m_epg_id(epg_id)
34 {
35 }
36 
37 bool
39 {
40  return ((m_itf == other.m_itf) && (m_ip_addrs == other.m_ip_addrs) &&
41  (m_mac == other.m_mac) && (m_epg_id == other.m_epg_id));
42 }
43 
44 rc_t
46 {
47  msg_t req(con.ctx(), m_ip_addrs.size() * sizeof(vapi_type_address),
48  std::ref(*this));
49  uint8_t n;
50 
51  auto& payload = req.get_request().get_payload();
52  payload.endpoint.sw_if_index = m_itf.value();
53  payload.endpoint.epg_id = m_epg_id;
54  payload.endpoint.n_ips = m_ip_addrs.size();
55 
56  for (n = 0; n < payload.endpoint.n_ips; n++) {
57  payload.endpoint.ips[n] = to_api(m_ip_addrs[n]);
58  }
59  payload.endpoint.mac = to_api(m_mac);
60 
61  VAPI_CALL(req.execute());
62 
63  return (wait());
64 }
65 
67 create_cmd::operator()(vapi::Gbp_endpoint_add& reply)
68 {
69  int handle = reply.get_response().get_payload().handle;
70  int retval = reply.get_response().get_payload().retval;
71 
72  VOM_LOG(log_level_t::DEBUG) << this->to_string() << " " << retval;
73 
74  rc_t rc = rc_t::from_vpp_retval(retval);
76 
77  if (rc_t::OK == rc) {
78  hdl = handle;
79  }
80 
81  this->fulfill(HW::item<handle_t>(hdl, rc));
82 
83  return (VAPI_OK);
84 }
85 
86 std::string
88 {
89  std::ostringstream s;
90  s << "gbp-endpoint-create: " << m_hw_item.to_string() << " itf:" << m_itf
91  << " ips:[";
92  for (auto ip : m_ip_addrs)
93  s << ip.to_string();
94 
95  s << "] mac:" << m_mac;
96  s << " epg-id:" << m_epg_id;
97 
98  return (s.str());
99 }
100 
102  : rpc_cmd(item)
103 {
104 }
105 
106 bool
108 {
109  return (m_hw_item == other.m_hw_item);
110 }
111 
112 rc_t
114 {
115  msg_t req(con.ctx(), std::ref(*this));
116 
117  auto& payload = req.get_request().get_payload();
118  payload.handle = m_hw_item.data().value();
119 
120  VAPI_CALL(req.execute());
121 
122  return (wait());
123 }
124 
125 std::string
127 {
128  std::ostringstream s;
129  s << "gbp-endpoint-delete: " << m_hw_item.to_string();
130 
131  return (s.str());
132 }
133 
135 {
136 }
137 
138 bool
139 dump_cmd::operator==(const dump_cmd& other) const
140 {
141  return (true);
142 }
143 
144 rc_t
146 {
147  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
148 
149  VAPI_CALL(m_dump->execute());
150 
151  wait();
152 
153  return rc_t::OK;
154 }
155 
156 std::string
158 {
159  return ("gbp-endpoint-dump");
160 }
161 
162 }; // namespace gbp_endpoint_cmds
163 }; // namespace VOM
164 
165 /*
166  * fd.io coding-style-patch-verification: ON
167  *
168  * Local Variables:
169  * eval: (c-set-style "mozilla")
170  * End:
171  */
static const rc_t & from_vpp_retval(int32_t rv)
Get the rc_t from the VPP API value.
Definition: types.cpp:33
#define VOM_LOG(lvl)
Definition: logger.hpp:181
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
uint32_t epg_id_t
EPG IDs are 32 bit integers.
Error codes that VPP will return during a HW write.
Definition: types.hpp:84
static const log_level_t DEBUG
Definition: logger.hpp:32
rc_t issue(connection &con)
Issue the command to VPP/HW.
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:263
A cmd class that deletes a GBP endpoint.
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
T & data()
Return the data read/written.
Definition: hw.hpp:108
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
A representation of the connection to VPP.
Definition: connection.hpp:33
A cmd class that Dumps all the GBP endpoints.
u16 epg_id
Definition: gbp.api:30
A command class that creates or updates the GBP endpoint.
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:38
virtual vapi_error_e operator()(vapi::Gbp_endpoint_add &reply)
call operator used as a callback by VAPI when the reply is available
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
std::string to_string() const
convert to string format for debug purposes
std::string to_string() const
convert to string format for debug purposes
delete_cmd(HW::item< handle_t > &item)
Constructor.
void fulfill(const HW::item< handle_t > &d)
Fulfill the commands promise.
Definition: rpc_cmd.hpp:74
DEFINE_VAPI_MSG_IDS_GBP_API_JSON
A type declaration of an interface handle in VPP.
Definition: types.hpp:228
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:104
success
Definition: vapi_common.h:27
static vapi_type_ip4_address to_api(const boost::asio::ip::address_v4 &a)
Definition: api_types.cpp:21
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
rc_t issue(connection &con)
Issue the command to VPP/HW.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
std::string to_string() const
convert to string format for debug purposes
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
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, epg_id_t epg_id)
Constructor.
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
Type def of a Ethernet address.
Definition: types.hpp:290
rc_t issue(connection &con)
Issue the command to VPP/HW.
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
vl_api_mac_address_t mac
Definition: gbp.api:31
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:132
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:64
vapi_error_e
Definition: vapi_common.h:25
vapi::Gbp_endpoint_add msg_t
convenient typedef
Definition: rpc_cmd.hpp:44