blob: 0bc698beef5f02dc250c79578333bf7e3525c497 [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 */
57 std::string to_string() const
58 {
59 std::ostringstream s;
60 s << "acl-bind:[" << m_direction.to_string() << " itf:" << m_itf.to_string()
61 << " acl:" << m_acl.to_string() << "]";
62
63 return (s.str());
64 }
65
66 /**
67 * Comparison operator - only used for UT
68 */
69 bool operator==(const bind_cmd& other) const
70 {
71 return ((m_itf == other.m_itf) && (m_acl == m_acl));
72 }
73
74private:
75 /**
76 * The direction of the binding
77 */
78 const direction_t m_direction;
79
80 /**
81 * The interface to bind to
82 */
83 const handle_t m_itf;
84
85 /**
86 * The ACL to bind
87 */
88 const handle_t m_acl;
89};
90
91/**
92 * A command class that binds the ACL to the interface
93 */
94template <typename BIND>
95class unbind_cmd : public rpc_cmd<HW::item<bool>, rc_t, BIND>
96{
97public:
98 /**
99 * Constructor
100 */
101 unbind_cmd(HW::item<bool>& item,
102 const direction_t& direction,
103 const handle_t& itf,
104 const handle_t& acl)
105 : rpc_cmd<HW::item<bool>, rc_t, BIND>(item)
106 , m_direction(direction)
107 , m_itf(itf)
108 , m_acl(acl)
109 {
110 }
111
112 /**
113 * Issue the command to VPP/HW
114 */
115 rc_t issue(connection& con);
116
117 /**
118 * convert to string format for debug purposes
119 */
120 std::string to_string() const
121 {
122 std::ostringstream s;
123 s << "acl-unbind:[" << m_direction.to_string()
124 << " itf:" << m_itf.to_string() << " acl:" << m_acl.to_string() << "]";
125
126 return (s.str());
127 }
128
129 /**
130 * Comparison operator - only used for UT
131 */
132 bool operator==(const unbind_cmd& other) const
133 {
134 return ((m_itf == other.m_itf) && (m_acl == m_acl));
135 }
136
137private:
138 /**
139 * The direction of the binding
140 */
141 const direction_t m_direction;
142
143 /**
144 * The interface to bind to
145 */
146 const handle_t m_itf;
147
148 /**
149 * The ACL to bind
150 */
151 const handle_t m_acl;
152};
153
154/**
155 * A cmd class that Dumps all the ACLs
156 */
157template <typename DUMP>
158class dump_cmd : public VOM::dump_cmd<DUMP>
159{
160public:
161 /**
162 * Constructor
163 */
164 dump_cmd() = default;
165 dump_cmd(const dump_cmd& d) = default;
166
167 /**
168 * Issue the command to VPP/HW
169 */
170 rc_t issue(connection& con);
171
172 /**
173 * convert to string format for debug purposes
174 */
175 std::string to_string() const { return ("acl-bind-dump"); }
176
177private:
178 /**
179 * HW reutrn code
180 */
181 HW::item<bool> item;
182};
183
184/**
185 * Typedef the L3 ACL binding commands
186 */
187typedef bind_cmd<vapi::Acl_interface_add_del> l3_bind_cmd;
188typedef unbind_cmd<vapi::Acl_interface_add_del> l3_unbind_cmd;
189typedef dump_cmd<vapi::Acl_interface_list_dump> l3_dump_cmd;
190
191/**
192 * Typedef the L2 binding type
193 */
194typedef bind_cmd<vapi::Macip_acl_interface_add_del> l2_bind_cmd;
195typedef unbind_cmd<vapi::Macip_acl_interface_add_del> l2_unbind_cmd;
196typedef dump_cmd<vapi::Macip_acl_interface_list_dump> l2_dump_cmd;
197
198}; // namespace binding_cmds
199}; // namespace ACL
200}; // namespace VOM
201
202/*
203 * fd.io coding-style-patch-verification: ON
204 *
205 * Local Variables:
206 * eval: (c-set-style "mozilla")
207 * End:
208 */
209
210#endif