FD.io VPP  v21.06-3-gbb25fbf28
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 
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 
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: OFF
111  *
112  * Local Variables:
113  * eval: (c-set-style "mozilla")
114  * End:
115  */
VOM::HW::item< handle_t >
VOM::rpc_cmd< HW::item< handle_t >, vapi::Create_vlan_subif >::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
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
VOM::sub_interface_cmds::delete_cmd::delete_cmd
delete_cmd(HW::item< handle_t > &item)
Constructor.
Definition: sub_interface_cmds.cpp:70
name
string name[64]
Definition: fib.api:25
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::sub_interface_cmds::delete_cmd::operator==
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: sub_interface_cmds.cpp:76
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::sub_interface_cmds::create_cmd::create_cmd
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's VLAN.
Definition: sub_interface_cmds.cpp:24
cmd.hpp
VOM::sub_interface_cmds::create_cmd::operator==
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
Definition: sub_interface_cmds.cpp:35
VOM::rpc_cmd< HW::item< handle_t >, vapi::Create_vlan_subif >::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::sub_interface_cmds::create_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: sub_interface_cmds.cpp:62
VOM::interface::create_cmd< vapi::Create_vlan_subif >::insert_interface
void insert_interface()
add the created interface to the DB
Definition: interface.hpp:343
sub_interface_cmds.hpp
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::sub_interface_cmds::delete_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: sub_interface_cmds.cpp:99
VOM::sub_interface_cmds::create_cmd
A functor class that creates an interface.
Definition: sub_interface_cmds.hpp:31
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::sub_interface_cmds::delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: sub_interface_cmds.cpp:82
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::Create_vlan_subif >::msg_t
vapi::Create_vlan_subif 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::HW::item::data
T & data()
Return the data read/written.
Definition: hw.hpp:109
VOM::interface::delete_cmd< vapi::Delete_subif >::remove_interface
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:412
VOM::sub_interface_cmds::delete_cmd
A cmd class that Delete an interface.
Definition: sub_interface_cmds.hpp:73
item
cJSON * item
Definition: cJSON.h:222
VOM::sub_interface_cmds::create_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: sub_interface_cmds.cpp:42
VOM::interface::create_cmd< vapi::Create_vlan_subif >::m_name
const std::string & m_name
The name of the interface to be created.
Definition: interface.hpp:369
vapi
Forward declarations.
Definition: vapi.hpp:44
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
string
const char *const string
Definition: cJSON.h:172