FD.io VPP  v18.01.2-1-g9b554f3
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  m_hw_item = 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:101
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
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
void remove_interface()
add the created interface to the DB
Definition: interface.hpp:340
uint32_t value() const
get the value of the handle
Definition: types.cpp:92
delete_cmd(HW::item< handle_t > &item)
Constructor.
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
Definition: hw.hpp:160
T & data()
Return the data read/written.
Definition: hw.hpp:108
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.
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
rc_t issue(connection &con)
Issue the command to VPP/HW.
A functor class that creates an interface.
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:64
#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:164
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:106
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:51
void insert_interface()
add the created interface to the DB
Definition: interface.hpp:270
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
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
HW::item< handle_t > wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:89