FD.io VPP  v21.10.1-2-g0a485f517
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 bool
35 {
36  return ((m_itf_from == o.m_itf_from) && (m_itf_to == o.m_itf_to) &&
37  (m_state == o.m_state));
38 }
39 
40 rc_t
42 {
43  msg_t req(con.ctx(), std::ref(*this));
44 
45  auto& payload = req.get_request().get_payload();
46  payload.is_l2 = 0;
47  payload.sw_if_index_from = m_itf_from.value();
48  payload.sw_if_index_to = m_itf_to.value();
49  payload.state = (vapi_enum_span_state)m_state.value();
50 
51  VAPI_CALL(req.execute());
52 
53  return (wait());
54 }
55 
58 {
59  std::ostringstream s;
60  s << "itf-span-config: " << m_hw_item.to_string()
61  << " itf-from:" << m_itf_from.to_string()
62  << " itf-to:" << m_itf_to.to_string() << " state:" << m_state.to_string();
63 
64  return (s.str());
65 }
66 
68  const handle_t& itf_from,
69  const handle_t& itf_to)
70  : rpc_cmd(item)
71  , m_itf_from(itf_from)
72  , m_itf_to(itf_to)
73 {}
74 
75 bool
77 {
78  return ((m_itf_from == o.m_itf_from) && (m_itf_to == o.m_itf_to));
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.is_l2 = 0;
88  payload.sw_if_index_from = m_itf_from.value();
89  payload.sw_if_index_to = m_itf_to.value();
90  payload.state = SPAN_STATE_API_DISABLED;
91 
92  VAPI_CALL(req.execute());
93 
94  wait();
96 
97  return rc_t::OK;
98 }
99 
102 {
103  std::ostringstream s;
104  s << "itf-span-unconfig: " << m_hw_item.to_string()
105  << " itf-from:" << m_itf_from.to_string()
106  << " itf-to:" << m_itf_to.to_string();
107 
108  return (s.str());
109 }
110 
112 
113 bool
114 dump_cmd::operator==(const dump_cmd& other) const
115 {
116  return (true);
117 }
118 
119 rc_t
121 {
122  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
123 
124  auto& payload = m_dump->get_request().get_payload();
125  payload.is_l2 = 0;
126 
127  VAPI_CALL(m_dump->execute());
128 
129  wait();
130 
131  return rc_t::OK;
132 }
133 
136 {
137  return ("interface-span-dump");
138 }
139 
140 }; // namespace interface_span_cmds
141 }; // namespace VOM
142 
143 /*
144  * fd.io coding-style-patch-verification: OFF
145  *
146  * Local Variables:
147  * eval: (c-set-style "mozilla")
148  * End:
149  */
VOM::interface_span_cmds::unconfig_cmd::unconfig_cmd
unconfig_cmd(HW::item< bool > &item, const handle_t &itf_from, const handle_t &itf_to)
Constructor.
Definition: interface_span_cmds.cpp:67
VOM::HW::item< bool >
VOM::interface_span_cmds::config_cmd
A command class that configures the interface span.
Definition: interface_span_cmds.hpp:31
VOM::interface_span_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: interface_span_cmds.cpp:120
VOM::dump_cmd< vapi::Sw_interface_span_dump >::msg_t
vapi::Sw_interface_span_dump msg_t
Definition: dump_cmd.hpp:46
DEFINE_VAPI_MSG_IDS_SPAN_API_JSON
DEFINE_VAPI_MSG_IDS_SPAN_API_JSON
Definition: interface_span_cmds.cpp:18
VOM::rpc_cmd< HW::item< bool >, vapi::Sw_interface_span_enable_disable >::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
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::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
state
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::interface_span_cmds::config_cmd::config_cmd
config_cmd(HW::item< bool > &item, const handle_t &itf_from, const handle_t &itf_to, const interface_span::state_t &state)
Constructor.
Definition: interface_span_cmds.cpp:23
VOM::rpc_cmd< HW::item< bool >, vapi::Sw_interface_span_enable_disable >::m_hw_item
HW::item< bool > & 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::Sw_interface_span_dump >::m_dump
std::unique_ptr< vapi::Sw_interface_span_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::interface_span_cmds::unconfig_cmd
A cmd class that Unconfigs interface span.
Definition: interface_span_cmds.hpp:75
VOM::interface_span::state_t
The state of the interface - rx/tx or both to be mirrored.
Definition: interface_span.hpp:36
VOM::enum_base::value
int value() const
Return the value of the enum - same as integer conversion.
Definition: enum_base.hpp:88
VOM::interface_span_cmds::dump_cmd
A cmd class that Dumps all the interface spans.
Definition: interface_span_cmds.hpp:114
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::interface_span_cmds::config_cmd::operator==
bool operator==(const config_cmd &i) const
Comparison operator - only used for UT.
Definition: interface_span_cmds.cpp:34
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::interface_span_cmds::unconfig_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: interface_span_cmds.cpp:101
VOM::dump_cmd< vapi::Sw_interface_span_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
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
interface_span_cmds.hpp
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::interface_span_cmds::config_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: interface_span_cmds.cpp:41
VOM::rpc_cmd< HW::item< bool >, vapi::Sw_interface_span_enable_disable >::msg_t
vapi::Sw_interface_span_enable_disable msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::enum_base::to_string
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
VOM::handle_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
VOM::interface_span_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: interface_span_cmds.cpp:135
VOM::interface_span_cmds::dump_cmd::dump_cmd
dump_cmd()
Constructor.
Definition: interface_span_cmds.cpp:111
item
cJSON * item
Definition: cJSON.h:222
SPAN_STATE_API_DISABLED
@ SPAN_STATE_API_DISABLED
Definition: span.api:23
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::interface_span_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: interface_span_cmds.cpp:114
VOM::interface_span_cmds::unconfig_cmd::operator==
bool operator==(const unconfig_cmd &i) const
Comparison operator - only used for UT.
Definition: interface_span_cmds.cpp:76
VOM::interface_span_cmds::config_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: interface_span_cmds.cpp:57
VOM::interface_span_cmds::unconfig_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: interface_span_cmds.cpp:82
string
const char *const string
Definition: cJSON.h:172