FD.io VPP  v19.01.1-17-ge106252
Vector Packet Processing
vxlan_gbp_tunnel_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 vxlan_gbp_tunnel_cmds {
23 
25  const std::string& name,
26  const vxlan_tunnel::endpoint_t& ep,
27  handle_t mcast_itf)
28  : interface::create_cmd<vapi::Vxlan_gbp_tunnel_add_del>(item, name)
29  , m_ep(ep)
30  , m_mcast_itf(mcast_itf)
31 {
32 }
33 
34 bool
36 {
37  return (m_ep == other.m_ep);
38 }
39 
40 rc_t
42 {
43  msg_t req(con.ctx(), std::ref(*this));
44 
45  auto& payload = req.get_request().get_payload();
46 
47  payload.is_add = 1;
48 
49  to_api(m_ep.src, payload.tunnel.src);
50  to_api(m_ep.dst, payload.tunnel.dst);
51  payload.tunnel.mcast_sw_if_index = m_mcast_itf.value();
52  payload.tunnel.encap_table_id = 0;
53  payload.tunnel.vni = m_ep.vni;
54  payload.tunnel.instance = ~0;
55 
56  VAPI_CALL(req.execute());
57 
58  wait();
59 
60  if (rc_t::OK == m_hw_item.rc()) {
62  }
63 
64  return rc_t::OK;
65 }
66 
67 std::string
69 {
70  std::ostringstream s;
71  s << "vxlan-gbp-tunnel-create: " << m_hw_item.to_string() << " "
72  << m_ep.to_string();
73 
74  return (s.str());
75 }
76 
78  const vxlan_tunnel::endpoint_t& ep)
79  : interface::delete_cmd<vapi::Vxlan_gbp_tunnel_add_del>(item)
80  , m_ep(ep)
81 {
82 }
83 
84 bool
86 {
87  return (m_ep == other.m_ep);
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 
97  payload.is_add = 0;
98 
99  to_api(m_ep.src, payload.tunnel.src);
100  to_api(m_ep.dst, payload.tunnel.dst);
101  payload.tunnel.mcast_sw_if_index = ~0;
102  payload.tunnel.encap_table_id = 0;
103  payload.tunnel.vni = m_ep.vni;
104 
105  VAPI_CALL(req.execute());
106 
107  wait();
109 
111  return (rc_t::OK);
112 }
113 
114 std::string
116 {
117  std::ostringstream s;
118  s << "vxlan-gbp-tunnel-delete: " << m_hw_item.to_string() << m_ep.to_string();
119 
120  return (s.str());
121 }
122 
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 = ~0;
140 
141  VAPI_CALL(m_dump->execute());
142 
143  wait();
144 
145  return rc_t::OK;
146 }
147 
148 std::string
150 {
151  return ("vxlan-gbp-tunnel-dump");
152 }
153 } // namespace vxlan_tunnel_cmds
154 } // namespace VOM
155 
156 /*
157  * fd.io coding-style-patch-verification: ON
158  *
159  * Local Variables:
160  * eval: (c-set-style "mozilla")
161  * End:
162  */
A Command class that creates an VXLAN tunnel.
rc_t issue(connection &con)
Issue the command to VPP/HW.
std::string to_string() const
Debug print function.
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
std::string to_string() const
convert to string format for debug purposes
Combaintion of attributes that are a unique key for a VXLAN tunnel.
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:404
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
boost::asio::ip::address dst
The destination IP address of the endpoint.
rc_t issue(connection &con)
Issue the command to VPP/HW.
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
std::string to_string() const
convert to string format for debug purposes
Forward declarations.
Definition: vapi.hpp:44
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
A representation of the connection to VPP.
Definition: connection.hpp:33
void to_api(const ip_address_t &a, vapi_type_address &v)
Definition: api_types.cpp:21
create_cmd(HW::item< handle_t > &item, const std::string &name, const vxlan_tunnel::endpoint_t &ep, handle_t mcast_itf)
Create command constructor taking HW item to update and the endpoint values.
u8 name[64]
Definition: memclnt.api:152
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
DEFINE_VAPI_MSG_IDS_VXLAN_GBP_API_JSON
A representation of an interface in VPP.
Definition: interface.hpp:41
rc_t issue(connection &con)
Issue the command to VPP/HW.
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
delete_cmd(HW::item< handle_t > &item, const vxlan_tunnel::endpoint_t &ep)
delete command constructor taking HW item to update and the endpoint values
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
void insert_interface()
add the created interface to the DB
Definition: interface.hpp:335
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A functor class that creates an VXLAN tunnel.
A cmd class that Dumps all the Vpp interfaces.
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::string to_string() const
convert to string format for debug purposes
uint32_t vni
The VNI of the endpoint.
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
boost::asio::ip::address src
The src IP address of the endpoint.
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
vapi::Vxlan_gbp_tunnel_add_del msg_t
convenient typedef
Definition: rpc_cmd.hpp:46