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