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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __VOM_ACL_LIST_CMDS_H__
17 #define __VOM_ACL_LIST_CMDS_H__
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"
24 #include <vapi/acl.api.vapi.hpp>
30 * A command class that Create the list
32 template <typename LIST, typename UPDATE>
33 class update_cmd : public rpc_cmd<HW::item<handle_t>, UPDATE>
36 typedef typename LIST::rules_t cmd_rules_t;
37 typedef typename LIST::key_t cmd_key_t;
42 update_cmd(HW::item<handle_t>& item,
44 const cmd_rules_t& rules)
45 : rpc_cmd<HW::item<handle_t>, UPDATE>(item)
52 * Issue the command to VPP/HW
54 rc_t issue(connection& con);
57 * convert to string format for debug purposes
59 std::string to_string() const
62 s << "ACL-list-update:[ " << this->item().to_string() << " rule-list:[";
63 for (auto rule : m_rules) {
64 s << " " << rule.to_string();
72 * Comparison operator - only used for UT
74 bool operator==(const update_cmd& other) const
76 return ((m_key == other.m_key) && (m_rules == other.m_rules));
81 rpc_cmd<HW::item<handle_t>, UPDATE>::succeeded();
82 LIST::add(m_key, this->item());
86 * A callback function for handling ACL creates
88 virtual vapi_error_e operator()(UPDATE& reply)
90 int acl_index = reply.get_response().get_payload().acl_index;
91 int retval = reply.get_response().get_payload().retval;
93 VOM_LOG(log_level_t::DEBUG) << this->to_string() << " retval:" << retval
94 << " acl_index:" << acl_index;
96 rc_t rc = rc_t::from_vpp_retval(retval);
97 handle_t handle(acl_index);
99 HW::item<handle_t> res(handle, rc);
108 * add the created acl to the DB
110 void insert_acl() { LIST::add(m_key, this->item()); }
115 const cmd_key_t& m_key;
120 const cmd_rules_t& m_rules;
124 * A cmd class that Deletes an ACL
126 template <typename LIST, typename DELETE>
127 class delete_cmd : public rpc_cmd<HW::item<handle_t>, DELETE>
133 delete_cmd(HW::item<handle_t>& item)
134 : rpc_cmd<HW::item<handle_t>, DELETE>(item)
139 * Issue the command to VPP/HW
141 rc_t issue(connection& con) { return (rc_t::INVALID); }
144 * convert to string format for debug purposes
146 std::string to_string() const
148 std::ostringstream s;
149 s << "ACL-list-delete: " << this->item().to_string();
155 * Comparison operator - only used for UT
157 bool operator==(const delete_cmd& other) const
159 return (this->item().data() == other.item().data());
164 * remove the acl from the DB
166 void remove_acl() { LIST::remove(this->item()); }
170 * A cmd class that Dumps all the ACLs
172 template <typename DUMP>
173 class dump_cmd : public VOM::dump_cmd<DUMP>
179 dump_cmd() = default;
182 * Issue the command to VPP/HW
184 rc_t issue(connection& con);
187 * convert to string format for debug purposes
189 std::string to_string() const { return ("acl-list-dump"); }
192 * Comparison operator - only used for UT
194 bool operator==(const dump_cmd& i) const { return true; }
198 * Typedef the L3 ACL commands
200 typedef update_cmd<l3_list, vapi::Acl_add_replace> l3_update_cmd;
201 typedef delete_cmd<l3_list, vapi::Acl_del> l3_delete_cmd;
202 typedef dump_cmd<vapi::Acl_dump> l3_dump_cmd;
205 * Typedef the L2 ACL commands
207 typedef update_cmd<l2_list, vapi::Macip_acl_add> l2_update_cmd;
208 typedef delete_cmd<l2_list, vapi::Macip_acl_del> l2_delete_cmd;
209 typedef dump_cmd<vapi::Macip_acl_dump> l2_dump_cmd;
211 }; // namespace list_cmds
216 * fd.io coding-style-patch-verification: ON
219 * eval: (c-set-style "mozilla")