FD.io VPP  v18.11-rc0-18-g2a3fb1a
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 {
25  inspect::register_handler({ "l2-acl-binding" }, "L2 ACL bindings", this);
26 }
27 
28 template <>
29 void
30 l2_binding::event_handler::handle_populate(const client_db::key_t& key)
31 {
32  /*
33  * dump VPP Bridge domains
34  */
35  std::shared_ptr<binding_cmds::l2_dump_cmd> cmd =
36  std::make_shared<binding_cmds::l2_dump_cmd>();
37 
38  HW::enqueue(cmd);
39  HW::write();
40 
41  for (auto& record : *cmd) {
42  auto& payload = record.get_payload();
43 
44  std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
45 
46  for (int ii = 0; ii < payload.count; ii++) {
47  std::shared_ptr<l2_list> acl = l2_list::find(payload.acls[ii]);
48 
50 
51  OM::commit(key, binding);
52  }
53  }
54 }
55 
56 template <>
58 {
60  inspect::register_handler({ "l3-acl-binding" }, "L3 ACL bindings", this);
61 }
62 
63 template <>
64 void
65 l3_binding::event_handler::handle_populate(const client_db::key_t& key)
66 {
67  std::shared_ptr<binding_cmds::l3_dump_cmd> cmd =
68  std::make_shared<binding_cmds::l3_dump_cmd>();
69 
70  HW::enqueue(cmd);
71  HW::write();
72 
73  for (auto& record : *cmd) {
74  auto& payload = record.get_payload();
75 
76  std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
77  uint8_t n_input = payload.n_input;
78 
79  for (int ii = 0; ii < payload.count; ii++) {
80  std::shared_ptr<l3_list> acl = l3_list::find(payload.acls[ii]);
81 
82  if (n_input) {
84  n_input--;
85  OM::commit(key, binding);
86  } else {
88  OM::commit(key, binding);
89  }
90  }
91  }
92 }
93 
94 template <>
95 void
96 l3_binding::update(const binding& obj)
97 {
98  if (!m_binding) {
100  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
101  }
102  HW::write();
103 }
104 
105 template <>
106 void
107 l3_binding::sweep(void)
108 {
109  if (m_binding) {
111  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
112  }
113  HW::write();
114 }
115 
116 template <>
117 void
118 l3_binding::replay(void)
119 {
120  if (m_binding) {
122  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
123  }
124 }
125 
126 template <>
127 void
128 l2_binding::update(const binding& obj)
129 {
130  if (!m_binding) {
132  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
133  }
134  HW::write();
135 }
136 
137 template <>
138 void
139 l2_binding::sweep(void)
140 {
141  if (m_binding) {
143  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
144  }
145  HW::write();
146 }
147 
148 template <>
149 void
150 l2_binding::replay(void)
151 {
152  if (m_binding) {
154  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
155  }
156 }
157 };
158 
159 std::ostream&
160 operator<<(std::ostream& os,
161  const std::pair<direction_t, interface::key_t>& key)
162 {
163  os << "[" << key.first.to_string() << " " << key.second << "]";
164 
165  return (os);
166 }
167 };
168 
169 /*
170  * fd.io coding-style-patch-verification: ON
171  *
172  * Local Variables:
173  * eval: (c-set-style "mozilla")
174  * End:
175  */
A command class that binds the ACL to the interface.
const 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
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:461
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
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:236
static const direction_t INPUT
Permit Direction.
Definition: types.hpp:146
static std::shared_ptr< list > find(const handle_t &handle)
Definition: acl_list.hpp:135
A command class that binds the ACL to the interface.
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
void event_handler(void *tls_async)
Definition: tls_async.c:311
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:194
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
static const direction_t OUTPUT
Deny Direction.
Definition: types.hpp:151
A binding between an ACL and an interface.
Definition: acl_binding.hpp:38
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127