FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
interface_span_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 
19 
20 namespace VOM {
21 namespace interface_span_cmds {
22 
24  const handle_t& itf_from,
25  const handle_t& itf_to,
27  : rpc_cmd(item)
28  , m_itf_from(itf_from)
29  , m_itf_to(itf_to)
30  , m_state(state)
31 {
32 }
33 
34 bool
36 {
37  return ((m_itf_from == o.m_itf_from) && (m_itf_to == o.m_itf_to) &&
38  (m_state == o.m_state));
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.is_l2 = 0;
48  payload.sw_if_index_from = m_itf_from.value();
49  payload.sw_if_index_to = m_itf_to.value();
50  payload.state = m_state.value();
51 
52  VAPI_CALL(req.execute());
53 
54  m_hw_item.set(wait());
55 
56  return rc_t::OK;
57 }
58 
59 std::string
61 {
62  std::ostringstream s;
63  s << "itf-span-config: " << m_hw_item.to_string()
64  << " itf-from:" << m_itf_from.to_string()
65  << " itf-to:" << m_itf_to.to_string() << " state:" << m_state.to_string();
66 
67  return (s.str());
68 }
69 
71  const handle_t& itf_from,
72  const handle_t& itf_to)
73  : rpc_cmd(item)
74  , m_itf_from(itf_from)
75  , m_itf_to(itf_to)
76 {
77 }
78 
79 bool
81 {
82  return ((m_itf_from == o.m_itf_from) && (m_itf_to == o.m_itf_to));
83 }
84 
85 rc_t
87 {
88  msg_t req(con.ctx(), std::ref(*this));
89 
90  auto& payload = req.get_request().get_payload();
91  payload.is_l2 = 0;
92  payload.sw_if_index_from = m_itf_from.value();
93  payload.sw_if_index_to = m_itf_to.value();
94  payload.state = 0;
95 
96  VAPI_CALL(req.execute());
97 
98  wait();
100 
101  return rc_t::OK;
102 }
103 
104 std::string
106 {
107  std::ostringstream s;
108  s << "itf-span-unconfig: " << m_hw_item.to_string()
109  << " itf-from:" << m_itf_from.to_string()
110  << " itf-to:" << m_itf_to.to_string();
111 
112  return (s.str());
113 }
114 
116 {
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  auto& payload = m_dump->get_request().get_payload();
131  payload.is_l2 = 0;
132 
133  VAPI_CALL(m_dump->execute());
134 
135  wait();
136 
137  return rc_t::OK;
138 }
139 
140 std::string
142 {
143  return ("interface-span-dump");
144 }
145 
146 }; // namespace interface_span_cmds
147 }; // namespace VOM
148 
149 /*
150  * fd.io coding-style-patch-verification: ON
151  *
152  * Local Variables:
153  * eval: (c-set-style "mozilla")
154  * End:
155  */
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:101
HW::item< bool > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:131
int value() const
Return the value of the enum - same as integer conversion.
Definition: enum_base.hpp:67
uint32_t value() const
get the value of the handle
Definition: types.cpp:92
std::string to_string() const
convert to string format for debug purposes
bool operator==(const config_cmd &i) const
Comparison operator - only used for UT.
Error codes that VPP will return during a HW write.
Definition: types.hpp:84
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
A command class that configures the interface span.
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:68
A cmd class that Unconfigs interface span.
A representation of the connection to VPP.
Definition: connection.hpp:33
std::string to_string() const
convert to string format for debug purposes
config_cmd(HW::item< bool > &item, const handle_t &itf_from, const handle_t &itf_to, const interface_span::state_t &state)
Constructor.
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:64
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:38
A cmd class that Dumps all the interface spans.
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
unconfig_cmd(HW::item< bool > &item, const handle_t &itf_from, const handle_t &itf_to)
Constructor.
std::string to_string() const
convert to string format for debug purposes
A type declaration of an interface handle in VPP.
Definition: types.hpp:164
rc_t issue(connection &con)
Issue the command to VPP/HW.
bool operator==(const unconfig_cmd &i) const
Comparison operator - only used for UT.
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:106
rc_t issue(connection &con)
Issue the command to VPP/HW.
vhost_vring_state_t state
Definition: vhost-user.h:82
rc_t issue(connection &con)
Issue the command to VPP/HW.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:51
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
vapi::Sw_interface_span_enable_disable msg_t
convenient typedef
Definition: rpc_cmd.hpp:44
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
The state of the interface - rx/tx or both to be mirrored.
DEFINE_VAPI_MSG_IDS_SPAN_API_JSON