FD.io VPP  v18.07.1-19-g511ce25
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  : interface::create_cmd<vapi::Vxlan_add_del_tunnel>(item, name)
27  , m_ep(ep)
28 {
29 }
30 
31 bool
33 {
34  return (m_ep == other.m_ep);
35 }
36 
37 rc_t
39 {
40  msg_t req(con.ctx(), std::ref(*this));
41 
42  auto& payload = req.get_request().get_payload();
43  payload.is_add = 1;
44  payload.is_ipv6 = 0;
45  to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address);
46  to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address);
47  payload.mcast_sw_if_index = ~0;
48  payload.encap_vrf_id = 0;
49  payload.decap_next_index = ~0;
50  payload.vni = m_ep.vni;
51 
52  VAPI_CALL(req.execute());
53 
54  wait();
55 
56  if (rc_t::OK == m_hw_item.rc()) {
58  }
59 
60  return rc_t::OK;
61 }
62 
63 std::string
65 {
66  std::ostringstream s;
67  s << "vxlan-tunnel-create: " << m_hw_item.to_string() << m_ep.to_string();
68 
69  return (s.str());
70 }
71 
73  const vxlan_tunnel::endpoint_t& ep)
74  : interface::delete_cmd<vapi::Vxlan_add_del_tunnel>(item)
75  , m_ep(ep)
76 {
77 }
78 
79 bool
81 {
82  return (m_ep == other.m_ep);
83 }
84 
85 rc_t
87 {
88  msg_t req(con.ctx(), std::ref(*this));
89 
90  auto payload = req.get_request().get_payload();
91  payload.is_add = 0;
92  payload.is_ipv6 = 0;
93  to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address);
94  to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address);
95  payload.mcast_sw_if_index = ~0;
96  payload.encap_vrf_id = 0;
97  payload.decap_next_index = ~0;
98  payload.vni = m_ep.vni;
99 
100  VAPI_CALL(req.execute());
101 
102  wait();
104 
106  return (rc_t::OK);
107 }
108 
109 std::string
111 {
112  std::ostringstream s;
113  s << "vxlan-tunnel-delete: " << m_hw_item.to_string() << m_ep.to_string();
114 
115  return (s.str());
116 }
117 
119 {
120 }
121 
122 bool
123 dump_cmd::operator==(const dump_cmd& other) const
124 {
125  return (true);
126 }
127 
128 rc_t
130 {
131  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
132 
133  auto& payload = m_dump->get_request().get_payload();
134  payload.sw_if_index = ~0;
135 
136  VAPI_CALL(m_dump->execute());
137 
138  wait();
139 
140  return rc_t::OK;
141 }
142 
143 std::string
145 {
146  return ("Vpp-vxlan_tunnels-Dump");
147 }
148 } // namespace vxlan_tunnel_cmds
149 } // namespace VOM
150 
151 /*
152  * fd.io coding-style-patch-verification: ON
153  *
154  * Local Variables:
155  * eval: (c-set-style "mozilla")
156  * End:
157  */
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:99
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
rc_t issue(connection &con)
Issue the command to VPP/HW.
rc_t issue(connection &con)
Issue the command to VPP/HW.
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:386
boost::asio::ip::address dst
The destination IP address of the endpoint.
Error codes that VPP will return during a HW write.
Definition: types.hpp:84
A Command class that creates an VXLAN tunnel.
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
Forward declarations.
Definition: vapi.hpp:44
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:118
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.
#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
A representation of an interface in VPP.
Definition: interface.hpp:41
DEFINE_VAPI_MSG_IDS_VXLAN_API_JSON
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:104
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
create_cmd(HW::item< handle_t > &item, const std::string &name, const vxlan_tunnel::endpoint_t &ep)
Create command constructor taking HW item to update and the endpoint values.
void insert_interface()
add the created interface to the DB
Definition: interface.hpp:318
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:124
uint32_t vni
The VNI of the endpoint.
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
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:132
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:64
vapi::Vxlan_add_del_tunnel msg_t
convenient typedef
Definition: rpc_cmd.hpp:44