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 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()
100 const acl_ethertype::key_t&
101 acl_ethertype::key() const
103 return (m_itf->key());
107 acl_ethertype::operator==(const acl_ethertype& other) const
109 return (m_itf->key() == other.m_itf->key() && m_le == other.m_le);
112 std::shared_ptr<acl_ethertype>
113 acl_ethertype::find(const key_t& key)
115 return (m_db.find(key));
119 acl_ethertype::dump(std::ostream& os)
125 acl_ethertype::replay()
129 new acl_ethertype_cmds::bind_cmd(m_binding, m_itf->handle(), m_le));
134 acl_ethertype::to_string() const
136 std::ostringstream s;
137 s << "Acl-Ethertype:" << m_itf->to_string() << " ethertype-rules:";
138 auto it = m_le.cbegin();
139 while (it != m_le.cend()) {
140 s << it->to_string();
143 s << " rules-size:" << m_le.size();
149 acl_ethertype::update(const acl_ethertype& old)
152 * always update the instance with the latest rules
154 if (!m_binding || old.m_le != m_le) {
156 new acl_ethertype_cmds::bind_cmd(m_binding, m_itf->handle(), m_le));
160 std::shared_ptr<acl_ethertype>
161 acl_ethertype::find_or_add(const acl_ethertype& temp)
163 return (m_db.find_or_add(temp.m_itf->key(), temp));
166 std::shared_ptr<acl_ethertype>
167 acl_ethertype::singular() const
169 return find_or_add(*this);
172 acl_ethertype::event_handler::event_handler()
174 OM::register_listener(this);
175 inspect::register_handler({ "acl-ethertype" }, "ACL Ethertype bindings",
180 acl_ethertype::event_handler::handle_replay()
186 acl_ethertype::event_handler::handle_populate(const client_db::key_t& key)
192 acl_ethertype::event_handler::order() const
194 return (dependency_t::BINDING);
198 acl_ethertype::event_handler::show(std::ostream& os)
205 * fd.io coding-style-patch-verification: ON
208 * eval: (c-set-style "mozilla")