FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
pipe_cmds.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 
16 #include "vom/pipe_cmds.hpp"
17 
19 
20 namespace VOM {
21 namespace pipe_cmds {
22 
24  const std::string& name,
25  uint32_t instance,
27  : interface::create_cmd<vapi::Pipe_create>(item, name)
28  , m_hdl_pair(ends)
29  , m_instance(instance)
30 {}
31 
32 bool
34 {
35  return (m_name == other.m_name);
36 }
37 
39 create_cmd::operator()(vapi::Pipe_create& reply)
40 {
41  auto& payload = reply.get_response().get_payload();
42 
43  VOM_LOG(log_level_t::DEBUG) << to_string() << " " << payload.retval;
44 
45  const rc_t& rc = rc_t::from_vpp_retval(payload.retval);
46 
47  m_hdl_pair = { pipe::handle_pair_t(
48  static_cast<handle_t>(payload.pipe_sw_if_index[0]),
49  static_cast<handle_t>(payload.pipe_sw_if_index[1])),
50  rc };
51 
52  fulfill(HW::item<handle_t>(payload.sw_if_index, rc));
53 
54  return (VAPI_OK);
55 }
56 rc_t
58 {
59  msg_t req(con.ctx(), std::ref(*this));
60 
61  auto& payload = req.get_request().get_payload();
62 
63  payload.is_specified = 1;
64  payload.user_instance = m_instance;
65 
66  VAPI_CALL(req.execute());
67 
68  if (rc_t::OK == wait()) {
70  }
71 
72  return rc_t::OK;
73 }
74 
77 {
78  std::ostringstream s;
79 
80  s << "pipe-create: " << m_name << " instance:" << m_instance;
81 
82  return (s.str());
83 }
84 
87  : interface::delete_cmd<vapi::Pipe_delete>(item)
88  , m_hdl_pair(end_pair)
89 {}
90 
91 bool
93 {
94  return (m_hw_item == other.m_hw_item);
95 }
96 
97 rc_t
99 {
100  msg_t req(con.ctx(), std::ref(*this));
101 
102  VAPI_CALL(req.execute());
103 
104  wait();
106  m_hdl_pair.set(rc_t::NOOP);
107 
109 
110  return (rc_t::OK);
111 }
112 
115 {
116  return ("pipe-delete");
117 }
118 
119 bool
120 dump_cmd::operator==(const dump_cmd& other) const
121 {
122  return (true);
123 }
124 
125 rc_t
127 {
128  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
129 
130  VAPI_CALL(m_dump->execute());
131 
132  wait();
133 
134  return rc_t::OK;
135 }
136 
139 {
140  return ("pipe-dump");
141 }
142 
143 } // namespace pipe_cmds
144 } // namespace VOM
145 
146 /*
147  * fd.io coding-style-patch-verification: OFF
148  *
149  * Local Variables:
150  * eval: (c-set-style "mozilla")
151  * End:
152  */
VOM::pipe_cmds::create_cmd
A functor class that creates an interface.
Definition: pipe_cmds.hpp:30
vapi_error_e
vapi_error_e
Definition: vapi_common.h:25
VOM::HW::item< handle_t >
VOM::dump_cmd< vapi::Pipe_dump >::msg_t
vapi::Pipe_dump msg_t
Definition: dump_cmd.hpp:46
VOM::rpc_cmd< HW::item< handle_t >, vapi::Pipe_create >::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::pipe_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: pipe_cmds.cpp:126
VOM_LOG
#define VOM_LOG(lvl)
Definition: logger.hpp:181
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::rc_t::from_vpp_retval
static const rc_t & from_vpp_retval(int32_t rv)
Get the rc_t from the VPP API value.
Definition: types.cpp:33
name
string name[64]
Definition: fib.api:25
VOM::pipe_cmds::create_cmd::operator()
virtual vapi_error_e operator()(vapi::Pipe_create &reply)
call operator used as a callback by VAPI when the reply is available
Definition: pipe_cmds.cpp:39
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::pipe_cmds::dump_cmd
A cmd class that Dumps all the Vpp interfaces.
Definition: pipe_cmds.hpp:97
VOM::pipe_cmds::delete_cmd::operator==
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: pipe_cmds.cpp:92
VAPI_OK
@ VAPI_OK
success
Definition: vapi_common.h:27
VOM::rpc_cmd< HW::item< handle_t >, vapi::Pipe_delete >::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::dump_cmd< vapi::Pipe_dump >::m_dump
std::unique_ptr< vapi::Pipe_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::interface::create_cmd< vapi::Pipe_create >::insert_interface
void insert_interface()
add the created interface to the DB
Definition: interface.hpp:343
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::pipe_cmds::delete_cmd::delete_cmd
delete_cmd(HW::item< handle_t > &item, HW::item< pipe::handle_pair_t > &end_pair)
Constructor.
Definition: pipe_cmds.cpp:85
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::dump_cmd< vapi::Pipe_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
VOM::pipe_cmds::create_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: pipe_cmds.cpp:57
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::log_level_t::DEBUG
const static log_level_t DEBUG
Definition: logger.hpp:32
VOM::rpc_cmd< HW::item< handle_t >, vapi::Pipe_create >::msg_t
vapi::Pipe_create msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::interface::delete_cmd< vapi::Pipe_delete >::remove_interface
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:412
VOM::pipe_cmds::create_cmd::operator==
bool operator==(const create_cmd &i) const
Comparison operator - only used for UT.
Definition: pipe_cmds.cpp:33
VOM::pipe_cmds::delete_cmd
A cmd class that Delete an interface.
Definition: pipe_cmds.hpp:67
instance
u32 instance
Definition: gre.api:51
VOM::pipe::handle_pair_t
std::pair< handle_t, handle_t > handle_pair_t
Definition: pipe.hpp:34
VOM::pipe_cmds::create_cmd::create_cmd
create_cmd(HW::item< handle_t > &item, const std::string &name, uint32_t instance, HW::item< pipe::handle_pair_t > &ends)
Cstrunctor taking the reference to the parent and the sub-interface's VLAN.
Definition: pipe_cmds.cpp:23
pipe_cmds.hpp
item
cJSON * item
Definition: cJSON.h:222
DEFINE_VAPI_MSG_IDS_PIPE_API_JSON
DEFINE_VAPI_MSG_IDS_PIPE_API_JSON
Definition: pipe_cmds.cpp:18
VOM::interface::create_cmd< vapi::Pipe_create >::m_name
const std::string & m_name
The name of the interface to be created.
Definition: interface.hpp:369
VOM::pipe_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: pipe_cmds.cpp:120
vapi
Forward declarations.
Definition: vapi.hpp:44
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::rpc_cmd< HW::item< handle_t >, vapi::Pipe_create >::fulfill
void fulfill(const HW::item< handle_t > &d)
Fulfill the commands promise.
Definition: rpc_cmd.hpp:76
VOM::pipe_cmds::create_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: pipe_cmds.cpp:76
VOM::pipe_cmds::delete_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: pipe_cmds.cpp:114
VOM::pipe_cmds::delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: pipe_cmds.cpp:98
VOM::pipe_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: pipe_cmds.cpp:138
string
const char *const string
Definition: cJSON.h:172