FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
acl_binding.cpp
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 #include "vom/acl_binding.hpp"
17 #include "vom/acl_binding_cmds.hpp"
18 
19 namespace VOM {
20 namespace ACL {
21 template <>
23 l2_binding::event_handler::order() const
24 {
25  return (dependency_t::BINDING);
26 }
27 
28 template <>
30 {
31  /* hack to get this function instantiated */
32  order();
33 
35  inspect::register_handler({ "l2-acl-binding" }, "L2 ACL bindings", this);
36 }
37 
38 template <>
39 void
40 l2_binding::event_handler::handle_populate(const client_db::key_t& key)
41 {
42  /* hack to get this function instantiated */
43  order();
44 
45  /*
46  * dump VPP Bridge domains
47  */
48  std::shared_ptr<binding_cmds::l2_dump_cmd> cmd =
49  std::make_shared<binding_cmds::l2_dump_cmd>();
50 
52  HW::write();
53 
54  for (auto& record : *cmd) {
55  auto& payload = record.get_payload();
56 
57  std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
58 
59  if (itf) {
60  for (int ii = 0; ii < payload.count; ii++) {
61  std::shared_ptr<l2_list> acl = l2_list::find(payload.acls[ii]);
62 
63  if (acl) {
66  } else {
67  VOM_LOG(log_level_t::ERROR) << "no ACL id:" << payload.acls[ii];
68  }
69  }
70  } else {
71  VOM_LOG(log_level_t::ERROR) << "no interface:" << payload.sw_if_index;
72  }
73  }
74 }
75 
76 template <>
78 l3_binding::event_handler::order() const
79 {
80  return (dependency_t::BINDING);
81 }
82 
83 template <>
85 {
86  /* hack to get this function instantiated */
87  order();
88 
90  inspect::register_handler({ "l3-acl-binding" }, "L3 ACL bindings", this);
91 }
92 
93 template <>
94 void
95 l3_binding::event_handler::handle_populate(const client_db::key_t& key)
96 {
97  /* hack to get this function instantiated */
98  order();
99 
100  std::shared_ptr<binding_cmds::l3_dump_cmd> cmd =
101  std::make_shared<binding_cmds::l3_dump_cmd>();
102 
103  HW::enqueue(cmd);
104  HW::write();
105 
106  for (auto& record : *cmd) {
107  auto& payload = record.get_payload();
108 
109  std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
110  uint8_t n_input = payload.n_input;
111 
112  if (itf) {
113  for (int ii = 0; ii < payload.count; ii++) {
114  std::shared_ptr<l3_list> acl = l3_list::find(payload.acls[ii]);
115 
116  if (acl) {
117  if (n_input) {
119  n_input--;
121  } else {
124  }
125  } else {
126  VOM_LOG(log_level_t::ERROR) << "no ACL id:" << payload.acls[ii];
127  }
128  }
129  } else {
130  VOM_LOG(log_level_t::ERROR) << "no interface:" << payload.sw_if_index;
131  }
132  }
133 }
134 
135 template <>
136 void
137 l3_binding::update(const binding& obj)
138 {
139  if (!m_binding) {
141  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
142  }
143  HW::write();
144 }
145 
146 template <>
147 void
148 l3_binding::sweep(void)
149 {
150  if (m_binding) {
152  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
153  }
154  HW::write();
155 }
156 
157 template <>
158 void
159 l3_binding::replay(void)
160 {
161  if (m_binding) {
163  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
164  }
165 }
166 
167 template <>
168 void
169 l2_binding::update(const binding& obj)
170 {
171  if (!m_binding) {
173  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
174  }
175  HW::write();
176 }
177 
178 template <>
179 void
180 l2_binding::sweep(void)
181 {
182  if (m_binding) {
184  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
185  }
186  HW::write();
187 }
188 
189 template <>
190 void
191 l2_binding::replay(void)
192 {
193  if (m_binding) {
195  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
196  }
197 }
198 };
199 
200 std::ostream&
201 operator<<(std::ostream& os,
202  const std::pair<direction_t, interface::key_t>& key)
203 {
204  os << "[" << key.first.to_string() << " " << key.second << "]";
205 
206  return (os);
207 }
208 };
209 
210 /*
211  * fd.io coding-style-patch-verification: OFF
212  *
213  * Local Variables:
214  * eval: (c-set-style "mozilla")
215  * End:
216  */
VOM::HW::write
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
VOM::OM::commit
static rc_t commit(const client_db::key_t &key, const OBJ &obj)
Make the State in VPP reflect the expressed desired state.
Definition: om.hpp:202
VOM_LOG
#define VOM_LOG(lvl)
Definition: logger.hpp:181
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::inspect::register_handler
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
Definition: inspect.cpp:85
VOM::dependency_t
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
acl_binding_cmds.hpp
VOM::ACL::l2_list::find
static std::shared_ptr< l2_list > find(const handle_t &handle)
Definition: acl_l2_list.cpp:123
binding
description no binding
Definition: map.api:409
key
typedef key
Definition: ipsec_types.api:88
VOM::ACL::l3_list::find
static std::shared_ptr< l3_list > find(const handle_t &handle)
Definition: acl_l3_list.cpp:123
VOM::OM::register_listener
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
acl_binding.hpp
VOM::direction_t::OUTPUT
const static direction_t OUTPUT
Deny Direction.
Definition: types.hpp:156
VOM::client_db::key_t
const typedef std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
VOM::direction_t::INPUT
const static direction_t INPUT
Permit Direction.
Definition: types.hpp:151
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
VOM::ACL::binding_cmds::bind_cmd
A command class that binds the ACL to the interface.
Definition: acl_binding_cmds.hpp:32
VOM::operator<<
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Definition: acl_binding.cpp:201
VOM::ACL::binding_cmds::unbind_cmd
A command class that binds the ACL to the interface.
Definition: acl_binding_cmds.hpp:88
VOM::dependency_t::BINDING
@ BINDING
Then L2/objects that bind to interfaces, BD, ACLS, etc.
VOM::ACL::binding
A binding between an ACL and an interface.
Definition: acl_binding.hpp:39
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
VOM::cmd
A representation of a method call to VPP.
Definition: cmd.hpp:32
VOM::log_level_t::ERROR
const static log_level_t ERROR
Definition: logger.hpp:29
VOM::dependency_t::ACL
@ ACL
ACLs.
VOM::interface::find
static std::shared_ptr< interface > find(const handle_t &h)
The the singular instance of the interface in the DB by handle.
Definition: interface.cpp:538