FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
igmp_listen.hpp
Go to the documentation of this file.
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_v4> 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_v4& gaddr,
46  const src_addrs_t& saddrs);
47  igmp_listen(const igmp_binding& igmp_bind,
48  const boost::asio::ip::address_v4& gaddr);
49 
50  /**
51  * Copy Constructor
52  */
53  igmp_listen(const igmp_listen& o);
54 
55  /**
56  * Destructor
57  */
58  ~igmp_listen();
59 
60  /**
61  * Comparison operator
62  */
63  bool operator==(const igmp_listen& l) const;
64 
65  /**
66  * Get the object's key
67  */
68  const key_t key() const;
69 
70  /**
71  * Return the 'singular instance' of the IGMP that matches this
72  * object
73  */
74  std::shared_ptr<igmp_listen> singular() const;
75 
76  /**
77  * convert to string format for debug purposes
78  */
79  std::string to_string() const;
80 
81  /**
82  * Dump all igmp_listens into the stream provided
83  */
84  static void dump(std::ostream& os);
85 
86  /**
87  * Find a listen from its key
88  */
89  static std::shared_ptr<igmp_listen> find(const key_t& k);
90 
91 private:
92  /**
93  * Class definition for listeners to OM events
94  */
96  {
97  public:
98  event_handler();
99  virtual ~event_handler() = default;
100 
101  /**
102  * Handle a populate event
103  */
104  void handle_populate(const client_db::key_t& key);
105 
106  /**
107  * Handle a replay event
108  */
109  void handle_replay();
110 
111  /**
112  * Show the object in the Singular DB
113  */
114  void show(std::ostream& os);
115 
116  /**
117  * Get the sortable Id of the listener
118  */
119  dependency_t order() const;
120  };
121 
122  /**
123  * event_handler to register with OM
124  */
125  static event_handler m_evh;
126 
127  /**
128  * Enquue commonds to the VPP command Q for the update
129  */
130  void update(const igmp_listen& obj);
131 
132  /**
133  * Find or add the singular instance in the DB
134  */
135  static std::shared_ptr<igmp_listen> find_or_add(const igmp_listen& temp);
136 
137  /*
138  * It's the VPPHW class that updates the objects in HW
139  */
140  friend class OM;
141 
142  /**
143  * It's the singular_db class that calls replay()
144  */
145  friend class singular_db<key_t, igmp_listen>;
146 
147  /**
148  * Sweep/reap the object if still stale
149  */
150  void sweep(void);
151 
152  /**
153  * replay the object to create it in hardware
154  */
155  void replay(void);
156 
157  /**
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
161  */
162  const std::shared_ptr<igmp_binding> m_igmp_bind;
163 
164  /**
165  * The group address for igmp configuration
166  */
167  const boost::asio::ip::address_v4 m_gaddr;
168 
169  /**
170  * The set of src addresses to listen for
171  */
172  const src_addrs_t m_saddrs;
173 
174  /**
175  * HW configuration for the listen. The bool representing the
176  * do/don't bind.
177  */
178  HW::item<bool> m_listen;
179 
180  /**
181  * A map of all igmp listen keyed against a combination of the interface
182  * and group addr keys.
183  */
185 };
186 
187 /**
188  * Ostream output for the key
189  */
190 std::ostream& operator<<(std::ostream& os, const igmp_listen::key_t& key);
191 };
192 
193 /*
194  * fd.io coding-style-patch-verification: ON
195  *
196  * Local Variables:
197  * eval: (c-set-style "mozilla")
198  * End:
199  */
200 
201 #endif
A representation of igmp configuration on an interface.
Definition: igmp_listen.hpp:31
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
const key_t key() const
Get the object&#39;s key.
Definition: igmp_listen.cpp:71
A representation of IGMP binding on an interface.
igmp_listen(const igmp_binding &igmp_bind, const boost::asio::ip::address_v4 &gaddr, const src_addrs_t &saddrs)
Construct a new object matching the desried state.
Definition: igmp_listen.cpp:28
static void dump(std::ostream &os)
Dump all igmp_listens into the stream provided.
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
std::shared_ptr< igmp_listen > singular() const
Return the &#39;singular instance&#39; of the IGMP that matches this object.
std::set< boost::asio::ip::address_v4 > src_addrs_t
Definition: igmp_listen.hpp:34
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
void event_handler(void *tls_async)
Definition: tls_async.c:340
std::string to_string() const
convert to string format for debug purposes
Definition: igmp_listen.cpp:96
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
The interface to writing objects into VPP OM.
Definition: om.hpp:140
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
static std::shared_ptr< igmp_listen > find(const key_t &k)
Find a listen from its key.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
bool operator==(const igmp_listen &l) const
Comparison operator.
Definition: igmp_listen.cpp:64
~igmp_listen()
Destructor.
Definition: igmp_listen.cpp:55
std::pair< interface::key_t, boost::asio::ip::address > key_t
The key type for igmp_listens.
Definition: igmp_listen.hpp:39