FD.io VPP  v21.10.1-2-g0a485f517
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 
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 
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 
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: OFF
158  *
159  * Local Variables:
160  * eval: (c-set-style "mozilla")
161  * End:
162  */
VOM::vxlan_tunnel_cmds::create_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: vxlan_tunnel_cmds.cpp:68
VOM::HW::item< handle_t >
VOM::vxlan_tunnel::endpoint_t::dst
boost::asio::ip::address dst
The destination IP address of the endpoint.
Definition: vxlan_tunnel.hpp:70
VOM::dump_cmd< vapi::Vxlan_tunnel_dump >::msg_t
vapi::Vxlan_tunnel_dump msg_t
Definition: dump_cmd.hpp:46
VOM::vxlan_tunnel_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: vxlan_tunnel_cmds.cpp:128
VOM::rpc_cmd< HW::item< handle_t >, vapi::Vxlan_add_del_tunnel >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
VOM::HW::item::set
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
VOM::vxlan_tunnel_cmds::dump_cmd
A cmd class that Dumps all the Vpp interfaces.
Definition: vxlan_tunnel_cmds.hpp:103
DEFINE_VAPI_MSG_IDS_VXLAN_API_JSON
DEFINE_VAPI_MSG_IDS_VXLAN_API_JSON
Definition: vxlan_tunnel_cmds.cpp:18
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
name
string name[64]
Definition: fib.api:25
VOM::to_bytes
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
Definition: prefix.cpp:249
VOM::vxlan_tunnel_cmds::dump_cmd::dump_cmd
dump_cmd()
Default Constructor.
Definition: vxlan_tunnel_cmds.cpp:125
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::vxlan_tunnel_cmds::delete_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: vxlan_tunnel_cmds.cpp:117
VOM::vxlan_tunnel_cmds::delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: vxlan_tunnel_cmds.cpp:90
VOM::vxlan_tunnel_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: vxlan_tunnel_cmds.cpp:134
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::vxlan_tunnel_cmds::create_cmd
A Command class that creates an VXLAN tunnel.
Definition: vxlan_tunnel_cmds.hpp:32
VOM::rpc_cmd< HW::item< handle_t >, vapi::Vxlan_add_del_tunnel >::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::Vxlan_tunnel_dump >::m_dump
std::unique_ptr< vapi::Vxlan_tunnel_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::vxlan_tunnel::endpoint_t::vni
uint32_t vni
The VNI of the endpoint.
Definition: vxlan_tunnel.hpp:75
VOM::interface::create_cmd< vapi::Vxlan_add_del_tunnel >::insert_interface
void insert_interface()
add the created interface to the DB
Definition: interface.hpp:343
VOM::vxlan_tunnel_cmds::create_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: vxlan_tunnel_cmds.cpp:39
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::vxlan_tunnel_cmds::create_cmd::create_cmd
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.
Definition: vxlan_tunnel_cmds.cpp:23
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::vxlan_tunnel_cmds::delete_cmd
A functor class that creates an VXLAN tunnel.
Definition: vxlan_tunnel_cmds.hpp:69
VOM::dump_cmd< vapi::Vxlan_tunnel_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::vxlan_tunnel::endpoint_t::src
boost::asio::ip::address src
The src IP address of the endpoint.
Definition: vxlan_tunnel.hpp:65
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::vxlan_tunnel_cmds::delete_cmd::delete_cmd
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
Definition: vxlan_tunnel_cmds.cpp:77
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::rpc_cmd< HW::item< handle_t >, vapi::Vxlan_add_del_tunnel >::msg_t
vapi::Vxlan_add_del_tunnel msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::HW::item::rc
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
VOM::interface::delete_cmd< vapi::Vxlan_add_del_tunnel >::remove_interface
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:412
VOM::vxlan_tunnel_cmds::create_cmd::operator==
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
Definition: vxlan_tunnel_cmds.cpp:33
VOM::vxlan_tunnel_cmds::delete_cmd::operator==
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: vxlan_tunnel_cmds.cpp:84
VOM::vxlan_tunnel::endpoint_t::to_string
std::string to_string() const
Debug print function.
Definition: vxlan_tunnel.cpp:59
VOM::vxlan_tunnel_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: vxlan_tunnel_cmds.cpp:149
item
cJSON * item
Definition: cJSON.h:222
vapi
Forward declarations.
Definition: vapi.hpp:44
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
vxlan_tunnel_cmds.hpp
VOM::vxlan_tunnel::endpoint_t
Combaintion of attributes that are a unique key for a VXLAN tunnel.
Definition: vxlan_tunnel.hpp:39
string
const char *const string
Definition: cJSON.h:172