FD.io VPP  v19.04.4-rc0-5-ge88582fac
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 
33 bool
35 {
36  return (m_name == other.m_name);
37 }
38 
40 create_cmd::operator()(vapi::Pipe_create& reply)
41 {
42  auto& payload = reply.get_response().get_payload();
43 
44  VOM_LOG(log_level_t::DEBUG) << to_string() << " " << payload.retval;
45 
46  const rc_t& rc = rc_t::from_vpp_retval(payload.retval);
47 
48  m_hdl_pair = { pipe::handle_pair_t(payload.pipe_sw_if_index[0],
49  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 
75 std::string
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 
92 bool
94 {
95  return (m_hw_item == other.m_hw_item);
96 }
97 
98 rc_t
100 {
101  msg_t req(con.ctx(), std::ref(*this));
102 
103  VAPI_CALL(req.execute());
104 
105  wait();
107  m_hdl_pair.set(rc_t::NOOP);
108 
110 
111  return (rc_t::OK);
112 }
113 
114 std::string
116 {
117  return ("pipe-delete");
118 }
119 
120 bool
121 dump_cmd::operator==(const dump_cmd& other) const
122 {
123  return (true);
124 }
125 
126 rc_t
128 {
129  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
130 
131  VAPI_CALL(m_dump->execute());
132 
133  wait();
134 
135  return rc_t::OK;
136 }
137 
138 std::string
140 {
141  return ("pipe-dump");
142 }
143 
144 } // namespace pipe_cmds
145 } // namespace VOM
146 
147 /*
148  * fd.io coding-style-patch-verification: ON
149  *
150  * Local Variables:
151  * eval: (c-set-style "mozilla")
152  * End:
153  */
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:407
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:40
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:93
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:364
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:121
u8 name[64]
Definition: memclnt.api:152
#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:139
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
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:34
void insert_interface()
add the created interface to the DB
Definition: interface.hpp:338
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
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:115
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: pipe_cmds.cpp:127
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:99