FD.io VPP  v18.01.2-1-g9b554f3
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>
33  : public rpc_cmd<HW::item<handle_t>, HW::item<handle_t>, UPDATE>
34 {
35 public:
36  typedef typename list<RULE>::rules_t cmd_rules_t;
37  typedef typename list<RULE>::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>, 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  */
54  rc_t issue(connection& con);
55 
56  /**
57  * convert to string format for debug purposes
58  */
59  std::string to_string() const
60  {
61  std::ostringstream s;
62  s << "ACL-list-update: " << this->item().to_string();
63 
64  return (s.str());
65  }
66 
67  /**
68  * Comparison operator - only used for UT
69  */
70  bool operator==(const update_cmd& other) const
71  {
72  return ((m_key == other.m_key) && (m_rules == other.m_rules));
73  }
74 
75  void complete()
76  {
77  std::shared_ptr<list<RULE>> sp = list<RULE>::find(m_key);
78  if (sp && this->item()) {
79  list<RULE>::add(this->item().data(), sp);
80  }
81  }
82 
83  void succeeded()
84  {
86  complete();
87  }
88 
89  /**
90  * A callback function for handling ACL creates
91  */
92  virtual vapi_error_e operator()(UPDATE& reply)
93  {
94  int acl_index = reply.get_response().get_payload().acl_index;
95  int retval = reply.get_response().get_payload().retval;
96 
97  VOM_LOG(log_level_t::DEBUG) << this->to_string() << " " << retval;
98 
99  HW::item<handle_t> res(acl_index, rc_t::from_vpp_retval(retval));
100 
101  this->fulfill(res);
102 
103  return (VAPI_OK);
104  }
105 
106 private:
107  /**
108  * The key.
109  */
110  const cmd_key_t& m_key;
111 
112  /**
113  * The rules
114  */
115  const cmd_rules_t& m_rules;
116 };
117 
118 /**
119  * A cmd class that Deletes an ACL
120  */
121 template <typename DELETE>
122 class delete_cmd : public rpc_cmd<HW::item<handle_t>, rc_t, DELETE>
123 {
124 public:
125  /**
126  * Constructor
127  */
129  : rpc_cmd<HW::item<handle_t>, rc_t, DELETE>(item)
130  {
131  }
132 
133  /**
134  * Issue the command to VPP/HW
135  */
136  rc_t issue(connection& con) { return (rc_t::INVALID); }
137 
138  /**
139  * convert to string format for debug purposes
140  */
141  std::string to_string() const
142  {
143  std::ostringstream s;
144  s << "ACL-list-delete: " << this->item().to_string();
145 
146  return (s.str());
147  }
148 
149  /**
150  * Comparison operator - only used for UT
151  */
152  bool operator==(const delete_cmd& other) const
153  {
154  return (this->item().data() == other.item().data());
155  }
156 };
157 
158 /**
159  * A cmd class that Dumps all the ACLs
160  */
161 template <typename DUMP>
162 class dump_cmd : public VOM::dump_cmd<DUMP>
163 {
164 public:
165  /**
166  * Constructor
167  */
168  dump_cmd() = default;
169  dump_cmd(const dump_cmd& d) = default;
170 
171  /**
172  * Issue the command to VPP/HW
173  */
174  rc_t issue(connection& con) { return rc_t::INVALID; }
175 
176  /**
177  * convert to string format for debug purposes
178  */
179  std::string to_string() const { return ("acl-list-dump"); }
180 
181 private:
182  /**
183  * HW reutrn code
184  */
186 };
187 
188 /**
189  * Typedef the L3 ACL commands
190  */
194 
195 /**
196  * Typedef the L2 ACL commands
197  */
201 
202 }; // namespace list_cmds
203 }; // namespace ACL
204 }; // namespace VOM
205 
206 /*
207  * fd.io coding-style-patch-verification: ON
208  *
209  * Local Variables:
210  * eval: (c-set-style "mozilla")
211  * End:
212  */
213 
214 #endif
std::string to_string() const
convert to string format for debug purposes
update_cmd< l3_rule, vapi::Acl_add_replace > l3_update_cmd
Typedef the L3 ACL commands.
delete_cmd(HW::item< handle_t > &item)
Constructor.
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:36
#define VOM_LOG(lvl)
Definition: logger.hpp:181
static void add(const handle_t &handle, std::shared_ptr< list > sp)
Definition: acl_list.hpp:144
Definition: hw.hpp:33
update_cmd(HW::item< handle_t > &item, const cmd_key_t &key, const cmd_rules_t &rules)
Constructor.
delete_cmd< vapi::Macip_acl_del > l2_delete_cmd
Error codes that VPP will return during a HW write.
Definition: types.hpp:84
static const log_level_t DEBUG
Definition: logger.hpp:32
static std::shared_ptr< list > find(const handle_t &handle)
Definition: acl_list.hpp:134
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
Definition: hw.hpp:160
T & data()
Return the data read/written.
Definition: hw.hpp:108
std::string key_t
The KEY can be used to uniquely identify the ACL.
Definition: acl_list.hpp:45
std::string to_string() const
convert to string format for debug purposes
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.
delete_cmd< vapi::Acl_del > l3_delete_cmd
bool operator==(const delete_cmd &other) const
Comparison operator - only used for UT.
HW::item< handle_t > & 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 Deletes an ACL.
A type declaration of an interface handle in VPP.
Definition: types.hpp:164
success
Definition: vapi_common.h:27
virtual vapi_error_e operator()(UPDATE &reply)
A callback function for handling ACL creates.
std::string to_string() const
convert to string format for debug purposes
dump_cmd< vapi::Macip_acl_dump > l2_dump_cmd
void fulfill(const HW::item< handle_t > &d)
Fulfill the commands promise.
Definition: rpc_cmd.hpp:74
static const rc_t INVALID
HW write reported invalid input.
Definition: types.hpp:111
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
update_cmd< l2_rule, vapi::Macip_acl_add > l2_update_cmd
Typedef the L2 ACL commands.
rc_t issue(connection &con)
Issue the command to VPP/HW.
std::multiset< RULE > rules_t
The rule container type.
Definition: acl_list.hpp:50
rc_t issue(connection &con)
Issue the command to VPP/HW.
A base class for VPP dump commands.
Definition: dump_cmd.hpp:43
vapi_error_e
Definition: vapi_common.h:25