FD.io VPP  v19.01.3-6-g70449b9b9
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 
33 bool
35 {
36  return (m_ep == other.m_ep);
37 }
38 
39 rc_t
41 {
42  msg_t req(con.ctx(), std::ref(*this));
43 
44  auto& payload = req.get_request().get_payload();
45  payload.is_add = 1;
46  payload.is_ipv6 = 0;
47  to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address);
48  to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address);
49  payload.mcast_sw_if_index = m_mcast_itf.value();
50  payload.encap_vrf_id = 0;
51  payload.decap_next_index = ~0;
52  payload.vni = m_ep.vni;
53 
54  VAPI_CALL(req.execute());
55 
56  wait();
57 
58  if (rc_t::OK == m_hw_item.rc()) {
60  }
61 
62  return rc_t::OK;
63 }
64 
65 std::string
67 {
68  std::ostringstream s;
69  s << "vxlan-tunnel-create: " << m_hw_item.to_string() << " "
70  << m_ep.to_string();
71 
72  return (s.str());
73 }
74 
76  const vxlan_tunnel::endpoint_t& ep)
77  : interface::delete_cmd<vapi::Vxlan_add_del_tunnel>(item)
78  , m_ep(ep)
79 {
80 }
81 
82 bool
84 {
85  return (m_ep == other.m_ep);
86 }
87 
88 rc_t
90 {
91  msg_t req(con.ctx(), std::ref(*this));
92 
93  auto payload = req.get_request().get_payload();
94  payload.is_add = 0;
95  payload.is_ipv6 = 0;
96  to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address);
97  to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address);
98  payload.mcast_sw_if_index = ~0;
99  payload.encap_vrf_id = 0;
100  payload.decap_next_index = ~0;
101  payload.vni = m_ep.vni;
102 
103  VAPI_CALL(req.execute());
104 
105  wait();
107 
109  return (rc_t::OK);
110 }
111 
112 std::string
114 {
115  std::ostringstream s;
116  s << "vxlan-tunnel-delete: " << m_hw_item.to_string() << m_ep.to_string();
117 
118  return (s.str());
119 }
120 
122 {
123 }
124 
125 bool
126 dump_cmd::operator==(const dump_cmd& other) const
127 {
128  return (true);
129 }
130 
131 rc_t
133 {
134  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
135 
136  auto& payload = m_dump->get_request().get_payload();
137  payload.sw_if_index = ~0;
138 
139  VAPI_CALL(m_dump->execute());
140 
141  wait();
142 
143  return rc_t::OK;
144 }
145 
146 std::string
148 {
149  return ("Vpp-vxlan_tunnels-Dump");
150 }
151 } // namespace vxlan_tunnel_cmds
152 } // namespace VOM
153 
154 /*
155  * fd.io coding-style-patch-verification: ON
156  *
157  * Local Variables:
158  * eval: (c-set-style "mozilla")
159  * End:
160  */
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:404
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:218
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.
u8 name[64]
Definition: memclnt.api:152
#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
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:335
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