FD.io VPP  v21.01.1
Vector Packet Processing
acl_ethertype_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 
17 
18 namespace VOM {
19 namespace ACL {
20 namespace acl_ethertype_cmds {
21 
23  const handle_t& itf,
25  : rpc_cmd(item)
26  , m_itf(itf)
27  , m_le(le)
28 {
29 }
30 
31 bool
32 bind_cmd::operator==(const bind_cmd& other) const
33 {
34  return (m_itf == other.m_itf && m_le == other.m_le);
35 }
36 
37 rc_t
39 {
40  msg_t req(con.ctx(), m_le.size(), std::ref(*this));
41  uint32_t i = 0;
42  uint8_t n_input = 0;
43 
44  auto& payload = req.get_request().get_payload();
45  payload.sw_if_index = m_itf.value();
46  payload.count = m_le.size();
47 
48  auto it = m_le.cbegin();
49  while (it != m_le.cend()) {
50  payload.whitelist[i] = it->getEthertype();
51  if (it->getDirection() == direction_t::INPUT)
52  n_input++;
53  ++it;
54  ++i;
55  }
56 
57  payload.n_input = n_input;
58 
59  VAPI_CALL(req.execute());
60 
61  return (wait());
62 }
63 
66 {
67  std::ostringstream s;
68  s << "ACL-Ethertype: " << m_hw_item.to_string()
69  << " itf:" << m_itf.to_string() << " ethertype-rules:";
70  auto it = m_le.cbegin();
71  while (it != m_le.cend()) {
72  s << it->to_string();
73  ++it;
74  }
75 
76  s << " rules-size:" << m_le.size();
77 
78  return (s.str());
79 }
80 
82  : rpc_cmd(item)
83  , m_itf(itf)
84 {
85 }
86 
87 bool
89 {
90  return (m_itf == other.m_itf);
91 }
92 
93 rc_t
95 {
96  msg_t req(con.ctx(), 0, std::ref(*this));
97 
98  auto& payload = req.get_request().get_payload();
99  payload.sw_if_index = m_itf.value();
100  payload.count = 0;
101 
102  payload.n_input = 0;
103 
104  VAPI_CALL(req.execute());
105 
106  wait();
108 
109  return rc_t::OK;
110 }
111 
114 {
115  std::ostringstream s;
116  s << "ACL-Ethertype-Unbind: " << m_hw_item.to_string()
117  << " itf:" << m_itf.to_string();
118  return (s.str());
119 }
120 
122  : m_itf(hdl)
123 {
124 }
125 
127  : m_itf(d.m_itf)
128 {
129 }
130 
131 bool
132 dump_cmd::operator==(const dump_cmd& other) const
133 {
134  return (true);
135 }
136 
137 rc_t
139 {
140  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
141 
142  auto& payload = m_dump->get_request().get_payload();
143  payload.sw_if_index = m_itf.value();
144 
145  VAPI_CALL(m_dump->execute());
146 
147  wait();
148 
149  return rc_t::OK;
150 }
151 
154 {
155  return ("acl-ethertype-dump");
156 }
157 }; // namespace acl_ethertype_cmds
158 }; // namespace ACL
159 }; // namespace VOM
160 
161 /*
162  * fd.io coding-style-patch-verification: OFF
163  *
164  * Local Variables:
165  * eval: (c-set-style "mozilla")
166  * End:
167  */
rc_t issue(connection &con)
Issue the command to VPP/HW.
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
const char *const string
Definition: cJSON.h:172
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
static const direction_t INPUT
Permit Direction.
Definition: types.hpp:151
vapi::Acl_interface_etype_whitelist_dump msg_t
Definition: dump_cmd.hpp:46
A command class that binds the ethertype list to the interface.
A cmd class that Dumps all the acl ethertypes on given interface.
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
A representation of the connection to VPP.
Definition: connection.hpp:33
unbind_cmd(HW::item< bool > &item, const handle_t &itf)
Constructor.
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
A command class that unbinds the ethertype list to the interface.
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
std::multiset< ethertype_rule_t > ethertype_rules_t
The ethertype container.
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
rc_t issue(connection &con)
Issue the command to VPP/HW.
bool operator==(const bind_cmd &i) const
Comparison operator - only used for UT.
bool operator==(const unbind_cmd &i) const
Comparison operator - only used for UT.
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
cJSON * item
Definition: cJSON.h:222
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
bind_cmd(HW::item< bool > &item, const handle_t &itf, const acl_ethertype::ethertype_rules_t &le)
Constructor.
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
std::string to_string() const
convert to string format for debug purposes
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
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:125
std::unique_ptr< vapi::Acl_interface_etype_whitelist_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
rc_t issue(connection &con)
Issue the command to VPP/HW.
std::string to_string() const
convert to string format for debug purposes
std::string to_string() const
convert to string format for debug purposes
save_rewrite_length must be aligned so that reass doesn t overwrite it
Definition: buffer.h:401
HW::item< bool > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:134
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vapi::Acl_interface_set_etype_whitelist msg_t
convenient typedef
Definition: rpc_cmd.hpp:46