FD.io VPP  v21.01
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  */
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
static const rc_t & from_vpp_retval(int32_t rv)
Get the rc_t from the VPP API value.
Definition: types.cpp:33
A cmd class that Delete an interface.
Definition: pipe_cmds.hpp:67
#define VOM_LOG(lvl)
Definition: logger.hpp:181
DEFINE_VAPI_MSG_IDS_PIPE_API_JSON
Definition: pipe_cmds.cpp:18
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:412
const char *const string
Definition: cJSON.h:172
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
static const log_level_t DEBUG
Definition: logger.hpp:32
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
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
Forward declarations.
Definition: vapi.hpp:44
A functor class that creates an interface.
Definition: pipe_cmds.hpp:30
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: pipe_cmds.cpp:92
delete_cmd(HW::item< handle_t > &item, HW::item< pipe::handle_pair_t > &end_pair)
Constructor.
Definition: pipe_cmds.cpp:85
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
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: pipe_cmds.cpp:120
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: pipe_cmds.cpp:57
void fulfill(const HW::item< handle_t > &d)
Fulfill the commands promise.
Definition: rpc_cmd.hpp:76
std::string to_string() const
convert to string format for debug purposes
Definition: pipe_cmds.cpp:138
A representation of an interface in VPP.
Definition: interface.hpp:41
A cmd class that Dumps all the Vpp interfaces.
Definition: pipe_cmds.hpp:97
string name[64]
Definition: ip.api:44
cJSON * item
Definition: cJSON.h:222
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
success
Definition: vapi_common.h:27
std::pair< handle_t, handle_t > handle_pair_t
Definition: pipe.hpp:34
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.
Definition: pipe_cmds.cpp:33
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
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&#39;s VLAN.
Definition: pipe_cmds.cpp:23
u32 instance
Definition: gre.api:51
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
Definition: pipe_cmds.cpp:114
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: pipe_cmds.cpp:126
std::string to_string() const
convert to string format for debug purposes
Definition: pipe_cmds.cpp:76
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_error_e
Definition: vapi_common.h:25
vapi::Pipe_create msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: pipe_cmds.cpp:98