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 #ifndef __VOM_IGMP_LISTEN_H__
17 #define __VOM_IGMP_LISTEN_H__
20 #include "vom/igmp_binding.hpp"
21 #include "vom/inspect.hpp"
22 #include "vom/interface.hpp"
23 #include "vom/object_base.hpp"
25 #include "vom/singular_db.hpp"
29 * A representation of igmp configuration on an interface
31 class igmp_listen : public object_base
34 typedef std::set<boost::asio::ip::address> src_addrs_t;
37 * The key type for igmp_listens
39 typedef std::pair<interface::key_t, boost::asio::ip::address> key_t;
42 * Construct a new object matching the desried state
44 igmp_listen(const igmp_binding& igmp_bind,
45 const boost::asio::ip::address& gaddr,
46 const src_addrs_t& saddrs);
51 igmp_listen(const igmp_listen& o);
61 bool operator==(const igmp_listen& l) const;
64 * Get the object's key
66 const key_t key() const;
69 * Return the 'singular instance' of the IGMP that matches this
72 std::shared_ptr<igmp_listen> singular() const;
75 * convert to string format for debug purposes
77 std::string to_string() const;
80 * Dump all igmp_listens into the stream provided
82 static void dump(std::ostream& os);
85 * Find a listen from its key
87 static std::shared_ptr<igmp_listen> find(const key_t& k);
91 * Class definition for listeners to OM events
93 class event_handler : public OM::listener, public inspect::command_handler
97 virtual ~event_handler() = default;
100 * Handle a populate event
102 void handle_populate(const client_db::key_t& key);
105 * Handle a replay event
107 void handle_replay();
110 * Show the object in the Singular DB
112 void show(std::ostream& os);
115 * Get the sortable Id of the listener
117 dependency_t order() const;
121 * event_handler to register with OM
123 static event_handler m_evh;
126 * Enquue commonds to the VPP command Q for the update
128 void update(const igmp_listen& obj);
131 * Find or add the singular instance in the DB
133 static std::shared_ptr<igmp_listen> find_or_add(const igmp_listen& temp);
136 * It's the VPPHW class that updates the objects in HW
141 * It's the singular_db class that calls replay()
143 friend class singular_db<key_t, igmp_listen>;
146 * Sweep/reap the object if still stale
151 * replay the object to create it in hardware
156 * A reference counting pointer the igmp_binding that this 'igmp listen'
157 * represents. By holding the reference here, we can guarantee that
158 * this object will outlive the igmp_binding
160 const std::shared_ptr<igmp_binding> m_igmp_bind;
163 * The group address for igmp configuration
165 const boost::asio::ip::address m_gaddr;
168 * The set of src addresses to listen for
170 const src_addrs_t m_saddrs;
173 * HW configuration for the listen. The bool representing the
176 HW::item<bool> m_listen;
179 * A map of all igmp listen keyed against a combination of the interface
180 * and group addr keys.
182 static singular_db<key_t, igmp_listen> m_db;
186 * Ostream output for the key
188 std::ostream& operator<<(std::ostream& os, const igmp_listen::key_t& key);
192 * fd.io coding-style-patch-verification: ON
195 * eval: (c-set-style "mozilla")