e2726cd0e20db410315defcf34ede69e52bbdf21
[vpp.git] / extras / vom / vom / igmp_binding.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_BINDING_H__
17 #define __VOM_IGMP_BINDING_H__
18
19 #include "vom/hw.hpp"
20 #include "vom/inspect.hpp"
21 #include "vom/interface.hpp"
22 #include "vom/object_base.hpp"
23 #include "vom/om.hpp"
24 #include "vom/singular_db.hpp"
25
26 namespace VOM {
27 /**
28  * A representation of IGMP binding on an interface
29  */
30 class igmp_binding : public object_base
31 {
32 public:
33   /**
34    * Construct a new object matching the desried state
35    */
36   igmp_binding(const interface& itf);
37
38   /**
39    * Copy Constructor
40    */
41   igmp_binding(const igmp_binding& o);
42
43   /**
44    * Destructor
45    */
46   ~igmp_binding();
47
48   /**
49    * Equal operator
50    */
51   bool operator==(const igmp_binding& l) const;
52
53   /**
54    * Return the 'singular' of the IGMP binding that matches this object
55    */
56   std::shared_ptr<igmp_binding> singular() const;
57
58   /**
59    * convert to string format for debug purposes
60    */
61   std::string to_string() const;
62
63   /**
64    * Return the matching'singular' of the interface
65    */
66   std::shared_ptr<interface> itf() const;
67
68   /**
69    * Dump all IGMP bindings into the stream provided
70    */
71   static void dump(std::ostream& os);
72
73 private:
74   /**
75    * Class definition for listeners to OM events
76    */
77   class event_handler : public OM::listener, public inspect::command_handler
78   {
79   public:
80     event_handler();
81     virtual ~event_handler() = default;
82
83     /**
84      * Handle a populate event
85      */
86     void handle_populate(const client_db::key_t& key);
87
88     /**
89      * Handle a replay event
90      */
91     void handle_replay();
92
93     /**
94      * Show the object in the Singular DB
95      */
96     void show(std::ostream& os);
97
98     /**
99      * Get the sortable Id of the listener
100      */
101     dependency_t order() const;
102   };
103
104   /**
105    * event_handler to register with OM
106    */
107   static event_handler m_evh;
108
109   /**
110    * Enquue commonds to the VPP command Q for the update
111    */
112   void update(const igmp_binding& obj);
113
114   /**
115    * Find or add IGMP binding to the OM
116    */
117   static std::shared_ptr<igmp_binding> find_or_add(const igmp_binding& temp);
118
119   /*
120    * It's the OM class that calls singular()
121    */
122   friend class OM;
123
124   /**
125    * It's the singular_db class that calls replay()
126    */
127   friend class singular_db<interface::key_t, igmp_binding>;
128
129   /**
130    * Sweep/reap the object if still stale
131    */
132   void sweep(void);
133
134   /**
135    * replay the object to create it in hardware
136    */
137   void replay(void);
138
139   /**
140    * A reference counting pointer to the interface on which IGMP config
141    * resides. By holding the reference here, we can guarantee that
142    * this object will outlive the interface
143    */
144   const std::shared_ptr<interface> m_itf;
145
146   /**
147    * HW configuration for the binding. The bool representing the
148    * do/don't bind.
149    */
150   HW::item<bool> m_binding;
151
152   /**
153    * A map of all IGMP bindings keyed against the interface.
154    */
155   static singular_db<interface::key_t, igmp_binding> m_db;
156 };
157 };
158
159 /*
160  * fd.io coding-style-patch-verification: ON
161  *
162  * Local Variables:
163  * eval: (c-set-style "mozilla")
164  * End:
165  */
166
167 #endif