FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
sub_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 #include "vom/cmd.hpp"
18 
19 #include <vapi/vpe.api.vapi.hpp>
20 
21 namespace VOM {
22 namespace sub_interface_cmds {
23 
25  const std::string& name,
26  const handle_t& parent,
27  uint16_t vlan)
28  : interface::create_cmd<vapi::Create_vlan_subif>(item, name)
29  , m_parent(parent)
30  , m_vlan(vlan)
31 {
32 }
33 
34 bool
36 {
37  return ((m_name == other.m_name) && (m_parent == other.m_parent) &&
38  (m_vlan == other.m_vlan));
39 }
40 
41 rc_t
43 {
44  msg_t req(con.ctx(), std::ref(*this));
45 
46  auto& payload = req.get_request().get_payload();
47  payload.sw_if_index = m_parent.value();
48  payload.vlan_id = m_vlan;
49 
50  VAPI_CALL(req.execute());
51 
52  wait();
53 
54  if (m_hw_item.rc() == rc_t::OK) {
56  }
57 
58  return rc_t::OK;
59 }
60 
61 std::string
63 {
64  std::ostringstream s;
65  s << "sub-itf-create: " << m_hw_item.to_string() << " parent:" << m_parent
66  << " vlan:" << m_vlan;
67  return (s.str());
68 }
69 
71  : interface::delete_cmd<vapi::Delete_subif>(item)
72 {
73 }
74 
75 bool
77 {
78  return (m_hw_item == other.m_hw_item);
79 }
80 
81 rc_t
83 {
84  msg_t req(con.ctx(), std::ref(*this));
85 
86  auto& payload = req.get_request().get_payload();
87  payload.sw_if_index = m_hw_item.data().value();
88 
89  VAPI_CALL(req.execute());
90 
91  wait();
93 
95  return (rc_t::OK);
96 }
97 
98 std::string
100 {
101  std::ostringstream s;
102 
103  s << "sub-itf-delete: " << m_hw_item.to_string();
104 
105  return (s.str());
106 }
107 } // namespace sub_interface_cmds
108 } // namespace VOM
109  /*
110  * fd.io coding-style-patch-verification: ON
111  *
112  * Local Variables:
113  * eval: (c-set-style "mozilla")
114  * End:
115  */
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:412
delete_cmd(HW::item< handle_t > &item)
Constructor.
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
T & data()
Return the data read/written.
Definition: hw.hpp:109
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
Forward declarations.
Definition: vapi.hpp:44
rc_t issue(connection &con)
Issue the command to VPP/HW.
create_cmd(HW::item< handle_t > &item, const std::string &name, const handle_t &parent, uint16_t vlan)
Cstrunctor taking the reference to the parent and the sub-interface&#39;s VLAN.
const std::string & m_name
The name of the interface to be created.
Definition: interface.hpp:369
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 interface.
u8 name[64]
Definition: memclnt.api:152
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
A cmd class that Delete an interface.
A representation of an interface in VPP.
Definition: interface.hpp:41
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
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
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
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
std::string to_string() const
convert to string format for debug purposes
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
std::string to_string() const
convert to string format for debug purposes
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
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
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vapi::Create_vlan_subif msg_t
convenient typedef
Definition: rpc_cmd.hpp:46