blob: b9af66e70c83135c41beee5d5052c69dea949aa6 [file] [log] [blame]
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001/*
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_BINDING_CMDS_H__
17#define __VOM_ACL_BINDING_CMDS_H__
18
19#include "vom/acl_binding.hpp"
20#include "vom/dump_cmd.hpp"
21#include "vom/rpc_cmd.hpp"
22
23#include <vapi/acl.api.vapi.hpp>
24
25namespace VOM {
26namespace ACL {
27namespace binding_cmds {
28/**
29 * A command class that binds the ACL to the interface
30 */
31template <typename BIND>
32class bind_cmd : public rpc_cmd<HW::item<bool>, rc_t, BIND>
33{
34public:
35 /**
36 * Constructor
37 */
38 bind_cmd(HW::item<bool>& item,
39 const direction_t& direction,
40 const handle_t& itf,
41 const handle_t& acl)
42 : rpc_cmd<HW::item<bool>, rc_t, BIND>(item)
43 , m_direction(direction)
44 , m_itf(itf)
45 , m_acl(acl)
46 {
47 }
48
49 /**
50 * Issue the command to VPP/HW
51 */
52 rc_t issue(connection& con);
53
54 /**
55 * convert to string format for debug purposes
56 */
Mohsin Kazmib5eb3b12018-02-26 18:36:17 +010057 std::string to_string() const;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070058
59 /**
60 * Comparison operator - only used for UT
61 */
62 bool operator==(const bind_cmd& other) const
63 {
64 return ((m_itf == other.m_itf) && (m_acl == m_acl));
65 }
66
67private:
68 /**
69 * The direction of the binding
70 */
71 const direction_t m_direction;
72
73 /**
74 * The interface to bind to
75 */
76 const handle_t m_itf;
77
78 /**
79 * The ACL to bind
80 */
81 const handle_t m_acl;
82};
83
84/**
85 * A command class that binds the ACL to the interface
86 */
87template <typename BIND>
88class unbind_cmd : public rpc_cmd<HW::item<bool>, rc_t, BIND>
89{
90public:
91 /**
92 * Constructor
93 */
94 unbind_cmd(HW::item<bool>& item,
95 const direction_t& direction,
96 const handle_t& itf,
97 const handle_t& acl)
98 : rpc_cmd<HW::item<bool>, rc_t, BIND>(item)
99 , m_direction(direction)
100 , m_itf(itf)
101 , m_acl(acl)
102 {
103 }
104
105 /**
106 * Issue the command to VPP/HW
107 */
108 rc_t issue(connection& con);
109
110 /**
111 * convert to string format for debug purposes
112 */
Mohsin Kazmib5eb3b12018-02-26 18:36:17 +0100113 std::string to_string() const;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700114
115 /**
116 * Comparison operator - only used for UT
117 */
118 bool operator==(const unbind_cmd& other) const
119 {
120 return ((m_itf == other.m_itf) && (m_acl == m_acl));
121 }
122
123private:
124 /**
125 * The direction of the binding
126 */
127 const direction_t m_direction;
128
129 /**
130 * The interface to bind to
131 */
132 const handle_t m_itf;
133
134 /**
135 * The ACL to bind
136 */
137 const handle_t m_acl;
138};
139
140/**
141 * A cmd class that Dumps all the ACLs
142 */
143template <typename DUMP>
144class dump_cmd : public VOM::dump_cmd<DUMP>
145{
146public:
147 /**
148 * Constructor
149 */
150 dump_cmd() = default;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700151
152 /**
153 * Issue the command to VPP/HW
154 */
155 rc_t issue(connection& con);
156
157 /**
158 * convert to string format for debug purposes
159 */
Mohsin Kazmib5eb3b12018-02-26 18:36:17 +0100160 std::string to_string() const;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700161
162private:
163 /**
164 * HW reutrn code
165 */
166 HW::item<bool> item;
167};
168
169/**
170 * Typedef the L3 ACL binding commands
171 */
172typedef bind_cmd<vapi::Acl_interface_add_del> l3_bind_cmd;
173typedef unbind_cmd<vapi::Acl_interface_add_del> l3_unbind_cmd;
174typedef dump_cmd<vapi::Acl_interface_list_dump> l3_dump_cmd;
175
176/**
177 * Typedef the L2 binding type
178 */
179typedef bind_cmd<vapi::Macip_acl_interface_add_del> l2_bind_cmd;
180typedef unbind_cmd<vapi::Macip_acl_interface_add_del> l2_unbind_cmd;
181typedef dump_cmd<vapi::Macip_acl_interface_list_dump> l2_dump_cmd;
182
183}; // namespace binding_cmds
184}; // namespace ACL
185}; // namespace VOM
186
187/*
188 * fd.io coding-style-patch-verification: ON
189 *
190 * Local Variables:
191 * eval: (c-set-style "mozilla")
192 * End:
193 */
194
195#endif