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_v4> 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_v4& gaddr,
46 const src_addrs_t& saddrs);
47 igmp_listen(const igmp_binding& igmp_bind,
48 const boost::asio::ip::address_v4& gaddr);
53 igmp_listen(const igmp_listen& o);
63 bool operator==(const igmp_listen& l) const;
66 * Get the object's key
68 const key_t key() const;
71 * Return the 'singular instance' of the IGMP that matches this
74 std::shared_ptr<igmp_listen> singular() const;
77 * convert to string format for debug purposes
79 std::string to_string() const;
82 * Dump all igmp_listens into the stream provided
84 static void dump(std::ostream& os);
87 * Find a listen from its key
89 static std::shared_ptr<igmp_listen> find(const key_t& k);
93 * Class definition for listeners to OM events
95 class event_handler : public OM::listener, public inspect::command_handler
99 virtual ~event_handler() = default;
102 * Handle a populate event
104 void handle_populate(const client_db::key_t& key);
107 * Handle a replay event
109 void handle_replay();
112 * Show the object in the Singular DB
114 void show(std::ostream& os);
117 * Get the sortable Id of the listener
119 dependency_t order() const;
123 * event_handler to register with OM
125 static event_handler m_evh;
128 * Enquue commonds to the VPP command Q for the update
130 void update(const igmp_listen& obj);
133 * Find or add the singular instance in the DB
135 static std::shared_ptr<igmp_listen> find_or_add(const igmp_listen& temp);
138 * It's the VPPHW class that updates the objects in HW
143 * It's the singular_db class that calls replay()
145 friend class singular_db<key_t, igmp_listen>;
148 * Sweep/reap the object if still stale
153 * replay the object to create it in hardware
158 * A reference counting pointer the igmp_binding that this 'igmp listen'
159 * represents. By holding the reference here, we can guarantee that
160 * this object will outlive the igmp_binding
162 const std::shared_ptr<igmp_binding> m_igmp_bind;
165 * The group address for igmp configuration
167 const boost::asio::ip::address_v4 m_gaddr;
170 * The set of src addresses to listen for
172 const src_addrs_t m_saddrs;
175 * HW configuration for the listen. The bool representing the
178 HW::item<bool> m_listen;
181 * A map of all igmp listen keyed against a combination of the interface
182 * and group addr keys.
184 static singular_db<key_t, igmp_listen> m_db;
188 * Ostream output for the key
190 std::ostream& operator<<(std::ostream& os, const igmp_listen::key_t& key);
194 * fd.io coding-style-patch-verification: ON
197 * eval: (c-set-style "mozilla")