cd1da0bdd27244c85517d7bad70ceb0d8e9aa10d
[vpp.git] / extras / vom / vom / igmp_listen.hpp
1 /*
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15
16 #ifndef __VOM_IGMP_LISTEN_H__
17 #define __VOM_IGMP_LISTEN_H__
18
19 #include "vom/hw.hpp"
20 #include "vom/igmp_binding.hpp"
21 #include "vom/inspect.hpp"
22 #include "vom/interface.hpp"
23 #include "vom/object_base.hpp"
24 #include "vom/om.hpp"
25 #include "vom/singular_db.hpp"
26
27 namespace VOM {
28 /**
29  * A representation of igmp configuration on an interface
30  */
31 class igmp_listen : public object_base
32 {
33 public:
34   typedef std::set<boost::asio::ip::address> src_addrs_t;
35
36   /**
37    * The key type for igmp_listens
38    */
39   typedef std::pair<interface::key_t, boost::asio::ip::address> key_t;
40
41   /**
42    * Construct a new object matching the desried state
43    */
44   igmp_listen(const igmp_binding& igmp_bind,
45               const boost::asio::ip::address& gaddr,
46               const src_addrs_t& saddrs);
47
48   /**
49    * Copy Constructor
50    */
51   igmp_listen(const igmp_listen& o);
52
53   /**
54    * Destructor
55    */
56   ~igmp_listen();
57
58   /**
59    * Comparison operator
60    */
61   bool operator==(const igmp_listen& l) const;
62
63   /**
64    * Get the object's key
65    */
66   const key_t key() const;
67
68   /**
69    * Return the 'singular instance' of the IGMP that matches this
70    * object
71    */
72   std::shared_ptr<igmp_listen> singular() const;
73
74   /**
75    * convert to string format for debug purposes
76    */
77   std::string to_string() const;
78
79   /**
80    * Dump all igmp_listens into the stream provided
81    */
82   static void dump(std::ostream& os);
83
84   /**
85    * Find a listen from its key
86    */
87   static std::shared_ptr<igmp_listen> find(const key_t& k);
88
89 private:
90   /**
91    * Class definition for listeners to OM events
92    */
93   class event_handler : public OM::listener, public inspect::command_handler
94   {
95   public:
96     event_handler();
97     virtual ~event_handler() = default;
98
99     /**
100      * Handle a populate event
101      */
102     void handle_populate(const client_db::key_t& key);
103
104     /**
105      * Handle a replay event
106      */
107     void handle_replay();
108
109     /**
110      * Show the object in the Singular DB
111      */
112     void show(std::ostream& os);
113
114     /**
115      * Get the sortable Id of the listener
116      */
117     dependency_t order() const;
118   };
119
120   /**
121    * event_handler to register with OM
122    */
123   static event_handler m_evh;
124
125   /**
126    * Enquue commonds to the VPP command Q for the update
127    */
128   void update(const igmp_listen& obj);
129
130   /**
131    * Find or add the singular instance in the DB
132    */
133   static std::shared_ptr<igmp_listen> find_or_add(const igmp_listen& temp);
134
135   /*
136    * It's the VPPHW class that updates the objects in HW
137    */
138   friend class OM;
139
140   /**
141    * It's the singular_db class that calls replay()
142    */
143   friend class singular_db<key_t, igmp_listen>;
144
145   /**
146    * Sweep/reap the object if still stale
147    */
148   void sweep(void);
149
150   /**
151    * replay the object to create it in hardware
152    */
153   void replay(void);
154
155   /**
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
159    */
160   const std::shared_ptr<igmp_binding> m_igmp_bind;
161
162   /**
163    * The group address for igmp configuration
164    */
165   const boost::asio::ip::address m_gaddr;
166
167   /**
168    * The set of src addresses to listen for
169    */
170   const src_addrs_t m_saddrs;
171
172   /**
173    * HW configuration for the listen. The bool representing the
174    * do/don't bind.
175    */
176   HW::item<bool> m_listen;
177
178   /**
179    * A map of all igmp listen keyed against a combination of the interface
180    * and group addr keys.
181    */
182   static singular_db<key_t, igmp_listen> m_db;
183 };
184
185 /**
186  * Ostream output for the key
187  */
188 std::ostream& operator<<(std::ostream& os, const igmp_listen::key_t& key);
189 };
190
191 /*
192  * fd.io coding-style-patch-verification: ON
193  *
194  * Local Variables:
195  * eval: (c-set-style "mozilla")
196  * End:
197  */
198
199 #endif