FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
igmp_listen.cpp
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 #include "vom/igmp_listen.hpp"
17 #include "vom/igmp_listen_cmds.hpp"
19 
20 namespace VOM {
21 singular_db<igmp_listen::key_t, igmp_listen> igmp_listen::m_db;
22 
23 igmp_listen::event_handler igmp_listen::m_evh;
24 
25 /**
26  * Construct a new object matching the desried state
27  */
29  const boost::asio::ip::address_v4& gaddr,
31  : m_igmp_bind(igmp_bind.singular())
32  , m_gaddr(gaddr)
33  , m_saddrs(saddrs)
34  , m_listen(true, rc_t::NOOP)
35 {
36 }
37 
39  const boost::asio::ip::address_v4& gaddr)
40  : m_igmp_bind(igmp_bind.singular())
41  , m_gaddr(gaddr)
42  , m_saddrs()
43  , m_listen(true, rc_t::NOOP)
44 {
45 }
46 
48  : m_igmp_bind(o.m_igmp_bind)
49  , m_gaddr(o.m_gaddr)
50  , m_saddrs(o.m_saddrs)
51  , m_listen(o.m_listen)
52 {
53 }
54 
56 {
57  sweep();
58 
59  // not in the DB anymore.
60  m_db.release(key(), this);
61 }
62 
63 bool
65 {
66  return ((m_gaddr == l.m_gaddr) && (*m_igmp_bind == *l.m_igmp_bind) &&
67  (m_saddrs == l.m_saddrs));
68 }
69 
72 {
73  return (make_pair(m_igmp_bind->itf()->key(), m_gaddr));
74 }
75 
76 void
77 igmp_listen::sweep()
78 {
79  if (m_listen) {
81  m_listen, m_igmp_bind->itf()->handle(), m_gaddr));
82  }
83  HW::write();
84 }
85 
86 void
87 igmp_listen::replay()
88 {
89  if (m_listen) {
90  HW::enqueue(new igmp_listen_cmds::listen_cmd(
91  m_listen, m_igmp_bind->itf()->handle(), m_gaddr, m_saddrs));
92  }
93 }
94 
97 {
98  auto addr = m_saddrs.cbegin();
99 
100  std::ostringstream s;
101  s << "igmp-listen:[" << m_igmp_bind->to_string() << " group:" << m_gaddr
102  << " src-addrs: [";
103  while (addr != m_saddrs.cend()) {
104  s << " " << *addr;
105  ++addr;
106  }
107  s << " ] " << m_listen.to_string() << "]";
108 
109  return (s.str());
110 }
111 
112 void
113 igmp_listen::update(const igmp_listen& desired)
114 {
115  /*
116  * no updates for the listen. chaning the interface or the group addr is a
117  * change to the key, hence a new object
118  */
119  if (!m_listen) {
121  m_listen, m_igmp_bind->itf()->handle(), m_gaddr, m_saddrs));
122  }
123 }
124 
125 std::shared_ptr<igmp_listen>
126 igmp_listen::find_or_add(const igmp_listen& temp)
127 {
128  return (m_db.find_or_add(temp.key(), temp));
129 }
130 
131 std::shared_ptr<igmp_listen>
133 {
134  return (m_db.find(k));
135 }
136 
137 std::shared_ptr<igmp_listen>
139 {
140  return find_or_add(*this);
141 }
142 
143 void
144 igmp_listen::dump(std::ostream& os)
145 {
146  db_dump(m_db, os);
147 }
148 
150 {
151  OM::register_listener(this);
152  inspect::register_handler({ "igmp-listen" }, "igmp listener", this);
153 }
154 
155 void
156 igmp_listen::event_handler::handle_replay()
157 {
158  m_db.replay();
159 }
160 
161 void
162 igmp_listen::event_handler::handle_populate(const client_db::key_t& key)
163 {
164  /**
165  * This is done while populating the interfaces
166  */
167 }
168 
170 igmp_listen::event_handler::order() const
171 {
172  return (dependency_t::ENTRY);
173 }
174 
175 void
176 igmp_listen::event_handler::show(std::ostream& os)
177 {
178  db_dump(m_db, os);
179 }
180 }
181 
182 /*
183  * fd.io coding-style-patch-verification: OFF
184  *
185  * Local Variables:
186  * eval: (c-set-style "mozilla")
187  * End:
188  */
VOM::HW::write
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::inspect::register_handler
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
Definition: inspect.cpp:85
VOM::dependency_t
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
VOM::dependency_t::ENTRY
@ ENTRY
Entries in Tables.
VOM::igmp_listen
A representation of igmp configuration on an interface.
Definition: igmp_listen.hpp:31
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
key
typedef key
Definition: ipsec_types.api:88
VOM::db_dump
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
Definition: singular_db_funcs.hpp:35
VOM::igmp_listen_cmds::listen_cmd
A functor class that binds the igmp group to the interface.
Definition: igmp_listen_cmds.hpp:31
VOM::igmp_listen_cmds::unlisten_cmd
A cmd class that Unbinds igmp group from an interface.
Definition: igmp_listen_cmds.hpp:76
VOM::OM::register_listener
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
VOM::igmp_listen::singular
std::shared_ptr< igmp_listen > singular() const
Return the 'singular instance' of the IGMP that matches this object.
Definition: igmp_listen.cpp:138
VOM::client_db::key_t
const typedef 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
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::igmp_listen::find
static std::shared_ptr< igmp_listen > find(const key_t &k)
Find a listen from its key.
Definition: igmp_listen.cpp:132
igmp_listen
int igmp_listen(vlib_main_t *vm, igmp_filter_mode_t mode, u32 sw_if_index, const ip46_address_t *saddrs, const ip46_address_t *gaddr)
igmp listen Called by a host to request reception of multicast packets
Definition: igmp.c:133
singular_db_funcs.hpp
true
#define true
Definition: cJSON.c:65
VOM::igmp_listen::dump
static void dump(std::ostream &os)
Dump all igmp_listens into the stream provided.
Definition: igmp_listen.cpp:144
VOM::igmp_listen::igmp_listen
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
saddrs
vl_api_ip4_address_t saddrs[n_srcs]
Definition: igmp.api:71
VOM::igmp_listen::src_addrs_t
std::set< boost::asio::ip::address_v4 > src_addrs_t
Definition: igmp_listen.hpp:34
VOM::igmp_binding
A representation of IGMP binding on an interface.
Definition: igmp_binding.hpp:30
VOM::igmp_listen::operator==
bool operator==(const igmp_listen &l) const
Comparison operator.
Definition: igmp_listen.cpp:64
gaddr
vl_api_ip4_address_t gaddr
Definition: igmp.api:70
VOM::igmp_listen::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: igmp_listen.cpp:96
igmp_listen_cmds.hpp
VOM::igmp_listen::key_t
std::pair< interface::key_t, boost::asio::ip::address > key_t
The key type for igmp_listens.
Definition: igmp_listen.hpp:39
VOM::igmp_listen::~igmp_listen
~igmp_listen()
Destructor.
Definition: igmp_listen.cpp:55
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::igmp_listen::key
const key_t key() const
Get the object's key.
Definition: igmp_listen.cpp:71
show
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
igmp_listen.hpp
string
const char *const string
Definition: cJSON.h:172