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/igmp_listen.hpp"
17 #include "vom/igmp_listen_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
21 singular_db<igmp_listen::key_t, igmp_listen> igmp_listen::m_db;
23 igmp_listen::event_handler igmp_listen::m_evh;
26 * Construct a new object matching the desried state
28 igmp_listen::igmp_listen(const igmp_binding& igmp_bind,
29 const boost::asio::ip::address_v4& gaddr,
30 const igmp_listen::src_addrs_t& saddrs)
31 : m_igmp_bind(igmp_bind.singular())
34 , m_listen(true, rc_t::NOOP)
38 igmp_listen::igmp_listen(const igmp_binding& igmp_bind,
39 const boost::asio::ip::address_v4& gaddr)
40 : m_igmp_bind(igmp_bind.singular())
43 , m_listen(true, rc_t::NOOP)
47 igmp_listen::igmp_listen(const igmp_listen& o)
48 : m_igmp_bind(o.m_igmp_bind)
50 , m_saddrs(o.m_saddrs)
51 , m_listen(o.m_listen)
55 igmp_listen::~igmp_listen()
59 // not in the DB anymore.
60 m_db.release(key(), this);
64 igmp_listen::operator==(const igmp_listen& l) const
66 return ((m_gaddr == l.m_gaddr) && (*m_igmp_bind == *l.m_igmp_bind) &&
67 (m_saddrs == l.m_saddrs));
70 const igmp_listen::key_t
71 igmp_listen::key() const
73 return (make_pair(m_igmp_bind->itf()->key(), m_gaddr));
80 HW::enqueue(new igmp_listen_cmds::unlisten_cmd(
81 m_listen, m_igmp_bind->itf()->handle(), m_gaddr));
90 HW::enqueue(new igmp_listen_cmds::listen_cmd(
91 m_listen, m_igmp_bind->itf()->handle(), m_gaddr, m_saddrs));
96 igmp_listen::to_string() const
98 auto addr = m_saddrs.cbegin();
100 std::ostringstream s;
101 s << "igmp-listen:[" << m_igmp_bind->to_string() << " group:" << m_gaddr
103 while (addr != m_saddrs.cend()) {
107 s << " ] " << m_listen.to_string() << "]";
113 igmp_listen::update(const igmp_listen& desired)
116 * no updates for the listen. chaning the interface or the group addr is a
117 * change to the key, hence a new object
120 HW::enqueue(new igmp_listen_cmds::listen_cmd(
121 m_listen, m_igmp_bind->itf()->handle(), m_gaddr, m_saddrs));
125 std::shared_ptr<igmp_listen>
126 igmp_listen::find_or_add(const igmp_listen& temp)
128 return (m_db.find_or_add(temp.key(), temp));
131 std::shared_ptr<igmp_listen>
132 igmp_listen::find(const key_t& k)
134 return (m_db.find(k));
137 std::shared_ptr<igmp_listen>
138 igmp_listen::singular() const
140 return find_or_add(*this);
144 igmp_listen::dump(std::ostream& os)
149 igmp_listen::event_handler::event_handler()
151 OM::register_listener(this);
152 inspect::register_handler({ "igmp-listen" }, "igmp listener", this);
156 igmp_listen::event_handler::handle_replay()
162 igmp_listen::event_handler::handle_populate(const client_db::key_t& key)
165 * This is done while populating the interfaces
170 igmp_listen::event_handler::order() const
172 return (dependency_t::ENTRY);
176 igmp_listen::event_handler::show(std::ostream& os)
183 * fd.io coding-style-patch-verification: ON
186 * eval: (c-set-style "mozilla")