FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
tap_interface_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 
18 #include <vapi/tap.api.vapi.hpp>
19 
20 namespace VOM {
21 namespace tap_interface_cmds {
23  const std::string& name,
24  route::prefix_t& prefix,
25  const l2_address_t& l2_address)
26  : interface::create_cmd<vapi::Tap_connect>(item, name)
27  , m_prefix(prefix)
28  , m_l2_address(l2_address)
29 {
30 }
31 
32 rc_t
34 {
35  msg_t req(con.ctx(), std::ref(*this));
36 
37  auto& payload = req.get_request().get_payload();
38  memset(payload.tap_name, 0, sizeof(payload.tap_name));
39  memcpy(payload.tap_name, m_name.c_str(),
40  std::min(m_name.length(), sizeof(payload.tap_name)));
41  if (m_prefix != route::prefix_t::ZERO) {
42  if (m_prefix.address().is_v6()) {
43  m_prefix.to_vpp(&payload.ip6_address_set, payload.ip6_address,
44  &payload.ip6_mask_width);
45  } else {
46  m_prefix.to_vpp(&payload.ip4_address_set, payload.ip4_address,
47  &payload.ip4_mask_width);
48  payload.ip4_address_set = 1;
49  }
50  }
51 
52  if (m_l2_address != l2_address_t::ZERO) {
53  m_l2_address.to_bytes(payload.mac_address, 6);
54  } else {
55  payload.use_random_mac = 1;
56  }
57 
58  VAPI_CALL(req.execute());
59 
60  m_hw_item = wait();
61 
62  return rc_t::OK;
63 }
64 
65 std::string
67 {
68  std::ostringstream s;
69  s << "tap-intf-create: " << m_hw_item.to_string()
70  << " ip-prefix:" << m_prefix.to_string();
71 
72  return (s.str());
73 }
74 
76  : interface::delete_cmd<vapi::Tap_delete>(item)
77 {
78 }
79 
80 rc_t
82 {
83  // finally... call VPP
84 
85  return rc_t::OK;
86 }
87 std::string
89 {
90  std::ostringstream s;
91  s << "tap-itf-delete: " << m_hw_item.to_string();
92 
93  return (s.str());
94 }
95 
97 {
98 }
99 
100 bool
101 dump_cmd::operator==(const dump_cmd& other) const
102 {
103  return (true);
104 }
105 
106 rc_t
108 {
109  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
110 
111  VAPI_CALL(m_dump->execute());
112 
113  wait();
114 
115  return rc_t::OK;
116 }
117 
118 std::string
120 {
121  return ("tap-itf-dump");
122 }
123 } // namespace tap_interface_cmds
124 } // namespace VOM
125 
126 /*
127  * fd.io coding-style-patch-verification: ON
128  *
129  * Local Variables:
130  * eval: (c-set-style "mozilla")
131  * End:
132  */
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:131
rc_t issue(connection &con)
Issue the command to VPP/HW.
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:201
std::string to_string() const
convert to string format for debug purposes
Error codes that VPP will return during a HW write.
Definition: types.hpp:84
std::string to_string() const
convert to string format for debug purposes
static const l2_address_t ZERO
An all 0&#39;s L2 address.
Definition: types.hpp:284
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
Type def of a L2 address as read from VPP.
Definition: types.hpp:265
create_cmd(HW::item< handle_t > &item, const std::string &name, route::prefix_t &prefix, const l2_address_t &l2_address)
Forward declarations.
Definition: vapi.hpp:44
std::string to_string() const
convert to string format for debug purposes
const std::string & m_name
The name of the interface to be created.
Definition: interface.hpp:297
A representation of the connection to VPP.
Definition: connection.hpp:33
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:170
A functor class that creates an interface.
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:64
rc_t issue(connection &con)
Issue the command to VPP/HW.
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
void to_vpp(uint8_t *is_ip6, uint8_t *addr, uint8_t *len) const
Convert the prefix into VPP API parameters.
Definition: prefix.cpp:238
A representation of an interface in VPP.
Definition: interface.hpp:41
A cmd class that Dumps all the Vpp Interfaces.
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:106
delete_cmd(HW::item< handle_t > &item)
A functor class that deletes a Tap interface.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:51
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
rc_t issue(connection &con)
Issue the command to VPP/HW.
static const prefix_t ZERO
The all Zeros prefix.
Definition: prefix.hpp:163
const boost::asio::ip::address & address() const
Get the address.
Definition: prefix.cpp:136
A prefix defintion.
Definition: prefix.hpp:91
HW::item< handle_t > wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:89
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.