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"
22 ethertype_rule_t::ethertype_rule_t(const ethertype_t& eth,
23 const direction_t& dir)
30 ethertype_rule_t::to_string() const
35 << "ethertype:" << m_eth.to_string() << " dir:" << m_dir.to_string()
42 ethertype_rule_t::operator<(const ethertype_rule_t& other) const
44 return (m_dir > other.m_dir);
48 ethertype_rule_t::operator==(const ethertype_rule_t& other) const
50 return (m_dir == other.m_dir && m_eth == other.m_eth);
54 ethertype_rule_t::getEthertype() const
60 ethertype_rule_t::getDirection() const
66 * A DB of all acl ethertype bindings configs
68 singular_db<interface::key_t, acl_ethertype> acl_ethertype::m_db;
70 acl_ethertype::event_handler acl_ethertype::m_evh;
72 acl_ethertype::acl_ethertype(const interface& itf,
73 const acl_ethertype::ethertype_rules_t& le)
74 : m_itf(itf.singular())
80 acl_ethertype::acl_ethertype(const acl_ethertype& o)
83 , m_binding(o.m_binding)
87 acl_ethertype::~acl_ethertype()
91 // not in the DB anymore.
92 m_db.release(m_itf->key(), this);
96 acl_ethertype::sweep()
99 HW::enqueue(new acl_ethertype_cmds::unbind_cmd(m_binding, m_itf->handle()));
104 const acl_ethertype::key_t&
105 acl_ethertype::key() const
107 return (m_itf->key());
111 acl_ethertype::operator==(const acl_ethertype& other) const
113 return (m_itf->key() == other.m_itf->key() && m_le == other.m_le);
116 std::shared_ptr<acl_ethertype>
117 acl_ethertype::find(const key_t& key)
119 return (m_db.find(key));
123 acl_ethertype::dump(std::ostream& os)
129 acl_ethertype::replay()
133 new acl_ethertype_cmds::bind_cmd(m_binding, m_itf->handle(), m_le));
138 acl_ethertype::to_string() const
140 std::ostringstream s;
141 s << "Acl-Ethertype:" << m_itf->to_string() << " ethertype-rules:";
142 auto it = m_le.cbegin();
143 while (it != m_le.cend()) {
144 s << it->to_string();
147 s << " rules-size:" << m_le.size();
153 acl_ethertype::update(const acl_ethertype& desired)
156 * always update the instance with the latest rules
158 if (!m_binding || desired.m_le != m_le) {
160 new acl_ethertype_cmds::bind_cmd(m_binding, m_itf->handle(), m_le));
166 std::shared_ptr<acl_ethertype>
167 acl_ethertype::find_or_add(const acl_ethertype& temp)
169 return (m_db.find_or_add(temp.m_itf->key(), temp));
172 std::shared_ptr<acl_ethertype>
173 acl_ethertype::singular() const
175 return find_or_add(*this);
178 acl_ethertype::event_handler::event_handler()
180 OM::register_listener(this);
181 inspect::register_handler({ "acl-ethertype" }, "ACL Ethertype bindings",
186 acl_ethertype::event_handler::handle_replay()
192 acl_ethertype::event_handler::handle_populate(const client_db::key_t& key)
195 * dump VPP acl ethertypes
197 std::shared_ptr<acl_ethertype_cmds::dump_cmd> cmd =
198 std::make_shared<acl_ethertype_cmds::dump_cmd>(~0);
203 for (auto& record : *cmd) {
204 auto& payload = record.get_payload();
205 handle_t hdl(payload.sw_if_index);
206 std::shared_ptr<interface> itf = interface::find(hdl);
207 uint8_t n_input = payload.n_input;
208 uint8_t count = payload.count;
209 ethertype_rules_t ler;
211 for (int i = 0; i < count; i++) {
212 ethertype_t e = ethertype_t::from_numeric_val(payload.whitelist[i]);
214 ethertype_rule_t er(e, direction_t::INPUT);
218 ethertype_rule_t er(e, direction_t::OUTPUT);
223 acl_ethertype a_e(*itf, ler);
224 VOM_LOG(log_level_t::DEBUG) << "ethertype dump: " << a_e.to_string();
225 OM::commit(key, a_e);
232 acl_ethertype::event_handler::order() const
234 return (dependency_t::BINDING);
238 acl_ethertype::event_handler::show(std::ostream& os)
245 * fd.io coding-style-patch-verification: ON
248 * eval: (c-set-style "mozilla")