FD.io VPP  v20.05-21-gb1500e9ff
Vector Packet Processing
vxlan_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 
19 
20 namespace VOM {
21 namespace vxlan_tunnel_cmds {
22 
24  const std::string& name,
25  const vxlan_tunnel::endpoint_t& ep,
26  handle_t mcast_itf)
27  : interface::create_cmd<vapi::Vxlan_add_del_tunnel>(item, name)
28  , m_ep(ep)
29  , m_mcast_itf(mcast_itf)
30 {}
31 
32 bool
34 {
35  return (m_ep == other.m_ep);
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.is_add = 1;
45  to_bytes(m_ep.src,
46  (uint8_t*)&payload.src_address.af,
47  (uint8_t*)&payload.src_address.un);
48  to_bytes(m_ep.dst,
49  (uint8_t*)&payload.dst_address.af,
50  (uint8_t*)&payload.dst_address.un);
51  payload.mcast_sw_if_index = m_mcast_itf.value();
52  payload.encap_vrf_id = 0;
53  payload.decap_next_index = ~0;
54  payload.vni = m_ep.vni;
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-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_add_del_tunnel>(item)
80  , m_ep(ep)
81 {}
82 
83 bool
85 {
86  return (m_ep == other.m_ep);
87 }
88 
89 rc_t
91 {
92  msg_t req(con.ctx(), std::ref(*this));
93 
94  auto payload = req.get_request().get_payload();
95  payload.is_add = 0;
96  to_bytes(m_ep.src,
97  (uint8_t*)&payload.src_address.af,
98  (uint8_t*)&payload.src_address.un);
99  to_bytes(m_ep.dst,
100  (uint8_t*)&payload.dst_address.af,
101  (uint8_t*)&payload.dst_address.un);
102  payload.mcast_sw_if_index = ~0;
103  payload.encap_vrf_id = 0;
104  payload.decap_next_index = ~0;
105  payload.vni = m_ep.vni;
106 
107  VAPI_CALL(req.execute());
108 
109  wait();
111 
113  return (rc_t::OK);
114 }
115 
116 std::string
118 {
119  std::ostringstream s;
120  s << "vxlan-tunnel-delete: " << m_hw_item.to_string() << m_ep.to_string();
121 
122  return (s.str());
123 }
124 
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 ("Vpp-vxlan_tunnels-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  */
std::string to_string() const
convert to string format for debug purposes
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
rc_t issue(connection &con)
Issue the command to VPP/HW.
rc_t issue(connection &con)
Issue the command to VPP/HW.
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
Combaintion of attributes that are a unique key for a VXLAN tunnel.
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:412
boost::asio::ip::address dst
The destination IP address of the endpoint.
std::string to_string() const
convert to string format for debug purposes
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
A Command class that creates an VXLAN tunnel.
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
Forward declarations.
Definition: vapi.hpp:44
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
Definition: prefix.cpp:249
A representation of the connection to VPP.
Definition: connection.hpp:33
rc_t issue(connection &con)
Issue the command to VPP/HW.
A functor class that creates an VXLAN tunnel.
A cmd class that Dumps all the Vpp interfaces.
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.
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
A representation of an interface in VPP.
Definition: interface.hpp:41
DEFINE_VAPI_MSG_IDS_VXLAN_API_JSON
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
string name[64]
Definition: ip.api:44
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
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
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:343
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
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
uint32_t vni
The VNI of the endpoint.
std::string to_string() const
Debug print function.
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
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
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vapi::Vxlan_add_del_tunnel msg_t
convenient typedef
Definition: rpc_cmd.hpp:46