FD.io VPP  v18.01.2-1-g9b554f3
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 <>
22 void
23 l2_binding::event_handler::handle_populate(const client_db::key_t& key)
24 {
25  /*
26  * dump VPP Bridge domains
27  */
28  std::shared_ptr<binding_cmds::l2_dump_cmd> cmd =
29  std::make_shared<binding_cmds::l2_dump_cmd>();
30 
31  HW::enqueue(cmd);
32  HW::write();
33 
34  for (auto& record : *cmd) {
35  auto& payload = record.get_payload();
36 
37  std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
38 
39  for (int ii = 0; ii < payload.count; ii++) {
40  std::shared_ptr<l2_list> acl = l2_list::find(payload.acls[ii]);
41 
43 
44  OM::commit(key, binding);
45  }
46  }
47 }
48 
49 template <>
50 void
51 l3_binding::event_handler::handle_populate(const client_db::key_t& key)
52 {
53  std::shared_ptr<binding_cmds::l3_dump_cmd> cmd =
54  std::make_shared<binding_cmds::l3_dump_cmd>();
55 
56  HW::enqueue(cmd);
57  HW::write();
58 
59  for (auto& record : *cmd) {
60  auto& payload = record.get_payload();
61 
62  std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
63  uint8_t n_input = payload.n_input;
64 
65  for (int ii = 0; ii < payload.count; ii++) {
66  std::shared_ptr<l3_list> acl = l3_list::find(payload.acls[ii]);
67 
68  if (n_input) {
70  n_input--;
71  OM::commit(key, binding);
72  } else {
74  OM::commit(key, binding);
75  }
76  }
77  }
78 }
79 
80 template <>
81 void
82 l3_binding::update(const binding& obj)
83 {
84  if (!m_binding) {
86  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
87  }
88  HW::write();
89 }
90 
91 template <>
92 void
93 l3_binding::sweep(void)
94 {
95  if (m_binding) {
97  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
98  }
99  HW::write();
100 }
101 
102 template <>
103 void
104 l3_binding::replay(void)
105 {
106  if (m_binding) {
108  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
109  }
110 }
111 
112 template <>
113 void
114 l2_binding::update(const binding& obj)
115 {
116  if (!m_binding) {
118  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
119  }
120  HW::write();
121 }
122 
123 template <>
124 void
125 l2_binding::sweep(void)
126 {
127  if (m_binding) {
129  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
130  }
131  HW::write();
132 }
133 
134 template <>
135 void
136 l2_binding::replay(void)
137 {
138  if (m_binding) {
140  m_binding, m_direction, m_itf->handle(), m_acl->handle()));
141  }
142 }
143 };
144 
145 std::ostream&
146 operator<<(std::ostream& os,
147  const std::pair<direction_t, interface::key_t>& key)
148 {
149  os << "[" << key.first.to_string() << " " << key.second << "]";
150 
151  return (os);
152 }
153 };
154 
155 /*
156  * fd.io coding-style-patch-verification: ON
157  *
158  * Local Variables:
159  * eval: (c-set-style "mozilla")
160  * End:
161  */
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:402
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:225
static const direction_t INPUT
Permit Direction.
Definition: types.hpp:148
static std::shared_ptr< list > find(const handle_t &handle)
Definition: acl_list.hpp:134
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
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:189
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:153
A binding between an ACL and an interface.
Definition: acl_binding.hpp:37