FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
acl_list_cmds.hpp
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 
16 #ifndef __VOM_ACL_LIST_CMDS_H__
17 #define __VOM_ACL_LIST_CMDS_H__
18 
19 #include "vom/acl_l2_list.hpp"
20 #include "vom/acl_l3_list.hpp"
21 #include "vom/dump_cmd.hpp"
22 #include "vom/rpc_cmd.hpp"
23 
24 #include <vapi/acl.api.vapi.hpp>
25 
26 namespace VOM {
27 namespace ACL {
28 namespace list_cmds {
29 /**
30  * A command class that Create the list
31  */
32 template <typename LIST, typename UPDATE>
33 class update_cmd : public rpc_cmd<HW::item<handle_t>, UPDATE>
34 {
35 public:
36  typedef typename LIST::rules_t cmd_rules_t;
37  typedef typename LIST::key_t cmd_key_t;
38 
39  /**
40  * Constructor
41  */
43  const cmd_key_t& key,
44  const cmd_rules_t& rules)
45  : rpc_cmd<HW::item<handle_t>, UPDATE>(item)
46  , m_key(key)
47  , m_rules(rules)
48  {
49  }
50 
51  /**
52  * Issue the command to VPP/HW
53  */
55 
56  /**
57  * convert to string format for debug purposes
58  */
60  {
61  std::ostringstream s;
62  s << "ACL-list-update:[ " << this->item().to_string() << " rule-list:[";
63  for (auto rule : m_rules) {
64  s << " " << rule.to_string();
65  }
66  s << "]]";
67 
68  return (s.str());
69  }
70 
71  /**
72  * Comparison operator - only used for UT
73  */
74  bool operator==(const update_cmd& other) const
75  {
76  return ((m_key == other.m_key) && (m_rules == other.m_rules));
77  }
78 
79  void succeeded()
80  {
82  LIST::add(m_key, this->item());
83  }
84 
85  /**
86  * A callback function for handling ACL creates
87  */
88  virtual vapi_error_e operator()(UPDATE& reply)
89  {
90  int acl_index = reply.get_response().get_payload().acl_index;
91  int retval = reply.get_response().get_payload().retval;
92 
93  VOM_LOG(log_level_t::DEBUG) << this->to_string() << " retval:" << retval
94  << " acl_index:" << acl_index;
95 
96  rc_t rc = rc_t::from_vpp_retval(retval);
97  handle_t handle(acl_index);
98 
99  HW::item<handle_t> res(handle, rc);
100 
101  this->fulfill(res);
102 
103  return (VAPI_OK);
104  }
105 
106 private:
107  /**
108  * add the created acl to the DB
109  */
110  void insert_acl() { LIST::add(m_key, this->item()); }
111 
112  /**
113  * The key.
114  */
115  const cmd_key_t& m_key;
116 
117  /**
118  * The rules
119  */
120  const cmd_rules_t& m_rules;
121 };
122 
123 /**
124  * A cmd class that Deletes an ACL
125  */
126 template <typename LIST, typename DELETE>
127 class delete_cmd : public rpc_cmd<HW::item<handle_t>, DELETE>
128 {
129 public:
130  /**
131  * Constructor
132  */
134  : rpc_cmd<HW::item<handle_t>, DELETE>(item)
135  {
136  }
137 
138  /**
139  * Issue the command to VPP/HW
140  */
142 
143  /**
144  * convert to string format for debug purposes
145  */
147  {
148  std::ostringstream s;
149  s << "ACL-list-delete: " << this->item().to_string();
150 
151  return (s.str());
152  }
153 
154  /**
155  * Comparison operator - only used for UT
156  */
157  bool operator==(const delete_cmd& other) const
158  {
159  return (this->item().data() == other.item().data());
160  }
161 
162 private:
163  /**
164  * remove the acl from the DB
165  */
166  void remove_acl() { LIST::remove(this->item()); }
167 };
168 
169 /**
170  * A cmd class that Dumps all the ACLs
171  */
172 template <typename DUMP>
173 class dump_cmd : public VOM::dump_cmd<DUMP>
174 {
175 public:
176  /**
177  * Constructor
178  */
179  dump_cmd() = default;
180 
181  /**
182  * Issue the command to VPP/HW
183  */
185 
186  /**
187  * convert to string format for debug purposes
188  */
189  std::string to_string() const { return ("acl-list-dump"); }
190 
191  /**
192  * Comparison operator - only used for UT
193  */
194  bool operator==(const dump_cmd& i) const { return true; }
195 };
196 
197 /**
198  * Typedef the L3 ACL commands
199  */
203 
204 /**
205  * Typedef the L2 ACL commands
206  */
210 
211 }; // namespace list_cmds
212 }; // namespace ACL
213 }; // namespace VOM
214 
215 /*
216  * fd.io coding-style-patch-verification: OFF
217  *
218  * Local Variables:
219  * eval: (c-set-style "mozilla")
220  * End:
221  */
222 
223 #endif
vapi_error_e
vapi_error_e
Definition: vapi_common.h:25
VOM::HW::item< handle_t >
VOM::ACL::list_cmds::delete_cmd
A cmd class that Deletes an ACL.
Definition: acl_list_cmds.hpp:127
VOM::ACL::list_cmds::dump_cmd::dump_cmd
dump_cmd()=default
Constructor.
VOM::ACL::list_cmds::l2_update_cmd
update_cmd< l2_list, vapi::Macip_acl_add > l2_update_cmd
Typedef the L2 ACL commands.
Definition: acl_list_cmds.hpp:207
acl_l3_list.hpp
VOM_LOG
#define VOM_LOG(lvl)
Definition: logger.hpp:181
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::rc_t::from_vpp_retval
static const rc_t & from_vpp_retval(int32_t rv)
Get the rc_t from the VPP API value.
Definition: types.cpp:33
VOM::ACL::list_cmds::l2_delete_cmd
delete_cmd< l2_list, vapi::Macip_acl_del > l2_delete_cmd
Definition: acl_list_cmds.hpp:208
VOM::ACL::list_cmds::l3_dump_cmd
dump_cmd< vapi::Acl_dump > l3_dump_cmd
Definition: acl_list_cmds.hpp:202
VOM::ACL::list_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: acl_list_cmds.hpp:194
VOM::ACL::list_cmds::update_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: acl_list_cmds.cpp:55
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
VOM::ACL::list_cmds::update_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: acl_list_cmds.hpp:59
acl_l2_list.hpp
VOM::ACL::list_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: acl_list_cmds.hpp:189
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::ACL::list_cmds::dump_cmd
A cmd class that Dumps all the ACLs.
Definition: acl_list_cmds.hpp:173
VOM::ACL::list_cmds::delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: acl_list_cmds.hpp:141
VOM::ACL::list_cmds::delete_cmd::delete_cmd
delete_cmd(HW::item< handle_t > &item)
Constructor.
Definition: acl_list_cmds.hpp:133
VAPI_OK
@ VAPI_OK
success
Definition: vapi_common.h:27
key
typedef key
Definition: ipsec_types.api:88
VOM::ACL::list_cmds::delete_cmd::operator==
bool operator==(const delete_cmd &other) const
Comparison operator - only used for UT.
Definition: acl_list_cmds.hpp:157
VOM::ACL::list_cmds::update_cmd::operator()
virtual vapi_error_e operator()(UPDATE &reply)
A callback function for handling ACL creates.
Definition: acl_list_cmds.hpp:88
VOM::ACL::list_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: acl_list_cmds.cpp:106
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::ACL::list_cmds::l3_delete_cmd
delete_cmd< l3_list, vapi::Acl_del > l3_delete_cmd
Definition: acl_list_cmds.hpp:201
acl_index
u32 acl_index
Definition: abf.api:60
VOM::rc_t::INVALID
const static rc_t INVALID
HW write reported invalid input.
Definition: types.hpp:114
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::ACL::list_cmds::l2_dump_cmd
dump_cmd< vapi::Macip_acl_dump > l2_dump_cmd
Definition: acl_list_cmds.hpp:209
VOM::log_level_t::DEBUG
const static log_level_t DEBUG
Definition: logger.hpp:32
dump_cmd.hpp
data
u8 data[128]
Definition: ipsec_types.api:92
VOM::ACL::list_cmds::update_cmd::update_cmd
update_cmd(HW::item< handle_t > &item, const cmd_key_t &key, const cmd_rules_t &rules)
Constructor.
Definition: acl_list_cmds.hpp:42
VOM::HW::item::data
T & data()
Return the data read/written.
Definition: hw.hpp:109
VOM::rpc_cmd< HW::item< handle_t >, UPDATE >::item
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
VOM::ACL::list_cmds::update_cmd::cmd_rules_t
LIST::rules_t cmd_rules_t
Definition: acl_list_cmds.hpp:36
VOM::HW
Definition: hw.hpp:34
rules
vl_api_gbp_rule_t rules[n_rules]
Definition: gbp.api:338
VOM::ACL::list_cmds::delete_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: acl_list_cmds.hpp:146
VOM::ACL::list_cmds::update_cmd::cmd_key_t
LIST::key_t cmd_key_t
Definition: acl_list_cmds.hpp:37
VOM::ACL::list_cmds::update_cmd
A command class that Create the list.
Definition: acl_list_cmds.hpp:33
VOM::ACL::list_cmds::update_cmd::operator==
bool operator==(const update_cmd &other) const
Comparison operator - only used for UT.
Definition: acl_list_cmds.hpp:74
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::dump_cmd
A base class for VPP dump commands.
Definition: dump_cmd.hpp:43
VOM::rpc_cmd< HW::item< handle_t >, UPDATE >::fulfill
void fulfill(const HW::item< handle_t > &d)
Fulfill the commands promise.
Definition: rpc_cmd.hpp:76
VOM::ACL::list_cmds::update_cmd::succeeded
void succeeded()
Called by the HW Command Q when it is disabled to indicate the command can be considered successful w...
Definition: acl_list_cmds.hpp:79
VOM::ACL::list_cmds::l3_update_cmd
update_cmd< l3_list, vapi::Acl_add_replace > l3_update_cmd
Typedef the L3 ACL commands.
Definition: acl_list_cmds.hpp:200
rpc_cmd.hpp
VOM::dependency_t::ACL
@ ACL
ACLs.
string
const char *const string
Definition: cJSON.h:172