blob: 73f015df37764486a60e8d866320f8a475102867 [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -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#include "vom/acl_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070017#include "vom/acl_binding_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070018
19namespace VOM {
20namespace ACL {
21template <>
Mohsin Kazmib5eb3b12018-02-26 18:36:17 +010022l2_binding::event_handler::event_handler()
23{
24 OM::register_listener(this);
25 inspect::register_handler({ "l2-acl-binding" }, "L2 ACL bindings", this);
26}
27
28template <>
Neale Ranns812ed392017-10-16 04:20:13 -070029void
30l2_binding::event_handler::handle_populate(const client_db::key_t& key)
31{
32 /*
Neale Ranns1d781552017-11-27 04:52:35 -080033 * dump VPP Bridge domains
34 */
35 std::shared_ptr<binding_cmds::l2_dump_cmd> cmd =
36 std::make_shared<binding_cmds::l2_dump_cmd>();
Neale Ranns812ed392017-10-16 04:20:13 -070037
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
49 l2_binding binding(direction_t::INPUT, *itf, *acl);
50
51 OM::commit(key, binding);
52 }
53 }
54}
55
56template <>
Mohsin Kazmib5eb3b12018-02-26 18:36:17 +010057l3_binding::event_handler::event_handler()
58{
59 OM::register_listener(this);
60 inspect::register_handler({ "l3-acl-binding" }, "L3 ACL bindings", this);
61}
62
63template <>
Neale Ranns812ed392017-10-16 04:20:13 -070064void
65l3_binding::event_handler::handle_populate(const client_db::key_t& key)
66{
Neale Ranns1d781552017-11-27 04:52:35 -080067 std::shared_ptr<binding_cmds::l3_dump_cmd> cmd =
68 std::make_shared<binding_cmds::l3_dump_cmd>();
Neale Ranns812ed392017-10-16 04:20:13 -070069
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) {
83 l3_binding binding(direction_t::INPUT, *itf, *acl);
84 n_input--;
85 OM::commit(key, binding);
86 } else {
87 l3_binding binding(direction_t::OUTPUT, *itf, *acl);
88 OM::commit(key, binding);
89 }
90 }
91 }
92}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070093
94template <>
95void
96l3_binding::update(const binding& obj)
97{
98 if (!m_binding) {
99 HW::enqueue(new binding_cmds::l3_bind_cmd(
100 m_binding, m_direction, m_itf->handle(), m_acl->handle()));
101 }
102 HW::write();
103}
104
105template <>
106void
107l3_binding::sweep(void)
108{
109 if (m_binding) {
110 HW::enqueue(new binding_cmds::l3_unbind_cmd(
111 m_binding, m_direction, m_itf->handle(), m_acl->handle()));
112 }
113 HW::write();
114}
115
116template <>
117void
118l3_binding::replay(void)
119{
120 if (m_binding) {
121 HW::enqueue(new binding_cmds::l3_bind_cmd(
122 m_binding, m_direction, m_itf->handle(), m_acl->handle()));
123 }
124}
125
126template <>
127void
128l2_binding::update(const binding& obj)
129{
130 if (!m_binding) {
131 HW::enqueue(new binding_cmds::l2_bind_cmd(
132 m_binding, m_direction, m_itf->handle(), m_acl->handle()));
133 }
134 HW::write();
135}
136
137template <>
138void
139l2_binding::sweep(void)
140{
141 if (m_binding) {
142 HW::enqueue(new binding_cmds::l2_unbind_cmd(
143 m_binding, m_direction, m_itf->handle(), m_acl->handle()));
144 }
145 HW::write();
146}
147
148template <>
149void
150l2_binding::replay(void)
151{
152 if (m_binding) {
153 HW::enqueue(new binding_cmds::l2_bind_cmd(
154 m_binding, m_direction, m_itf->handle(), m_acl->handle()));
155 }
156}
Neale Ranns812ed392017-10-16 04:20:13 -0700157};
158
159std::ostream&
160operator<<(std::ostream& os,
Neale Rannsfd920602017-11-23 12:15:00 -0800161 const std::pair<direction_t, interface::key_t>& key)
Neale Ranns812ed392017-10-16 04:20:13 -0700162{
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 */