2 * Copyright (c) 2018 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/acl_ethertype.hpp"
17 #include "vom/acl_ethertype_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
23 ethertype_rule_t::ethertype_rule_t(const ethertype_t& eth,
24 const direction_t& dir)
31 ethertype_rule_t::to_string() const
36 << "ethertype:" << m_eth.to_string() << " dir:" << m_dir.to_string()
43 ethertype_rule_t::operator<(const ethertype_rule_t& other) const
45 return (m_dir > other.m_dir);
49 ethertype_rule_t::operator==(const ethertype_rule_t& other) const
51 return (m_dir == other.m_dir && m_eth == other.m_eth);
55 ethertype_rule_t::getEthertype() const
61 ethertype_rule_t::getDirection() const
67 * A DB of all acl ethertype bindings configs
69 singular_db<interface::key_t, acl_ethertype> acl_ethertype::m_db;
71 acl_ethertype::event_handler acl_ethertype::m_evh;
73 acl_ethertype::acl_ethertype(const interface& itf,
74 const acl_ethertype::ethertype_rules_t& le)
75 : m_itf(itf.singular())
81 acl_ethertype::acl_ethertype(const acl_ethertype& o)
84 , m_binding(o.m_binding)
88 acl_ethertype::~acl_ethertype()
92 // not in the DB anymore.
93 m_db.release(m_itf->key(), this);
97 acl_ethertype::sweep()
100 HW::enqueue(new acl_ethertype_cmds::unbind_cmd(m_binding, m_itf->handle()));
105 const acl_ethertype::key_t&
106 acl_ethertype::key() const
108 return (m_itf->key());
112 acl_ethertype::operator==(const acl_ethertype& other) const
114 return (m_itf->key() == other.m_itf->key() && m_le == other.m_le);
117 std::shared_ptr<acl_ethertype>
118 acl_ethertype::find(const key_t& key)
120 return (m_db.find(key));
124 acl_ethertype::dump(std::ostream& os)
130 acl_ethertype::replay()
134 new acl_ethertype_cmds::bind_cmd(m_binding, m_itf->handle(), m_le));
139 acl_ethertype::to_string() const
141 std::ostringstream s;
142 s << "Acl-Ethertype:" << m_itf->to_string() << " ethertype-rules:";
143 auto it = m_le.cbegin();
144 while (it != m_le.cend()) {
145 s << it->to_string();
148 s << " rules-size:" << m_le.size();
154 acl_ethertype::update(const acl_ethertype& desired)
157 * always update the instance with the latest rules
159 if (!m_binding || desired.m_le != m_le) {
161 new acl_ethertype_cmds::bind_cmd(m_binding, m_itf->handle(), m_le));
167 std::shared_ptr<acl_ethertype>
168 acl_ethertype::find_or_add(const acl_ethertype& temp)
170 return (m_db.find_or_add(temp.m_itf->key(), temp));
173 std::shared_ptr<acl_ethertype>
174 acl_ethertype::singular() const
176 return find_or_add(*this);
179 acl_ethertype::event_handler::event_handler()
181 OM::register_listener(this);
182 inspect::register_handler({ "acl-ethertype" }, "ACL Ethertype bindings",
187 acl_ethertype::event_handler::handle_replay()
193 acl_ethertype::event_handler::handle_populate(const client_db::key_t& key)
196 * dump VPP acl ethertypes
198 std::shared_ptr<acl_ethertype_cmds::dump_cmd> cmd =
199 std::make_shared<acl_ethertype_cmds::dump_cmd>(~0);
204 for (auto& record : *cmd) {
205 auto& payload = record.get_payload();
206 handle_t hdl(payload.sw_if_index);
207 std::shared_ptr<interface> itf = interface::find(hdl);
208 uint8_t n_input = payload.n_input;
209 uint8_t count = payload.count;
210 ethertype_rules_t ler;
212 for (int i = 0; i < count; i++) {
213 ethertype_t e = ethertype_t::from_numeric_val(payload.whitelist[i]);
215 ethertype_rule_t er(e, direction_t::INPUT);
219 ethertype_rule_t er(e, direction_t::OUTPUT);
224 acl_ethertype a_e(*itf, ler);
225 VOM_LOG(log_level_t::DEBUG) << "ethertype dump: " << a_e.to_string();
226 OM::commit(key, a_e);
233 acl_ethertype::event_handler::order() const
235 return (dependency_t::BINDING);
239 acl_ethertype::event_handler::show(std::ostream& os)
246 * fd.io coding-style-patch-verification: ON
249 * eval: (c-set-style "mozilla")