FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
igmp_binding.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_binding.hpp"
19 
20 namespace VOM {
21 
22 /**
23  * A DB of all igmp bindings configs
24  */
25 singular_db<igmp_binding::key_t, igmp_binding> igmp_binding::m_db;
26 
27 igmp_binding::event_handler igmp_binding::m_evh;
28 
30  : m_itf(itf.singular())
31  , m_binding(true)
32 {
33 }
34 
36  : m_itf(o.m_itf)
37  , m_binding(o.m_binding)
38 {
39 }
40 
42 {
43  sweep();
44  m_db.release(key(), this);
45 }
46 
47 bool
49 {
50  return (*m_itf == *l.m_itf);
51 }
52 
55 {
56  return (m_itf->key());
57 }
58 
59 void
60 igmp_binding::sweep()
61 {
62  if (m_binding) {
63  HW::enqueue(new igmp_binding_cmds::unbind_cmd(m_binding, m_itf->handle()));
64  }
65  HW::write();
66 }
67 
68 void
69 igmp_binding::dump(std::ostream& os)
70 {
71  db_dump(m_db, os);
72 }
73 
74 void
75 igmp_binding::replay()
76 {
77  if (m_binding) {
78  HW::enqueue(new igmp_binding_cmds::bind_cmd(m_binding, m_itf->handle()));
79  }
80 }
81 
82 std::string
84 {
85  std::ostringstream s;
86  s << "igmp-binding: [" << m_itf->to_string() << " mode:host]";
87 
88  return (s.str());
89 }
90 
91 void
92 igmp_binding::update(const igmp_binding& desired)
93 {
94  /*
95  * the desired state is always that the interface should be created
96  */
97  if (!m_binding) {
98  HW::enqueue(new igmp_binding_cmds::bind_cmd(m_binding, m_itf->handle()));
99  }
100 }
101 
102 std::shared_ptr<igmp_binding>
103 igmp_binding::find_or_add(const igmp_binding& temp)
104 {
105  return (m_db.find_or_add(temp.key(), temp));
106 }
107 
108 std::shared_ptr<igmp_binding>
110 {
111  return (m_db.find(k));
112 }
113 
114 std::shared_ptr<igmp_binding>
116 {
117  return find_or_add(*this);
118 }
119 
120 std::shared_ptr<interface>
122 {
123  return m_itf;
124 }
125 
127 {
128  OM::register_listener(this);
129  inspect::register_handler({ "igmp-binding" }, "IGMP bindings", this);
130 }
131 
132 void
133 igmp_binding::event_handler::handle_replay()
134 {
135  m_db.replay();
136 }
137 
138 void
139 igmp_binding::event_handler::handle_populate(const client_db::key_t& key)
140 {
141  /* done with igmp_dump in igmp_listen */
142 }
143 
145 igmp_binding::event_handler::order() const
146 {
147  return (dependency_t::BINDING);
148 }
149 
150 void
151 igmp_binding::event_handler::show(std::ostream& os)
152 {
153  db_dump(m_db, os);
154 }
155 }
156 /*
157  * fd.io coding-style-patch-verification: ON
158  *
159  * Local Variables:
160  * eval: (c-set-style "mozilla")
161  * End:
162  */
std::string to_string() const
convert to string format for debug purposes
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
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
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
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
A representation of IGMP binding on an interface.
A command class that binds the IGMP config to the interface.
const key_t key() const
Get the object&#39;s key.
A representation of an interface in VPP.
Definition: interface.hpp:41
~igmp_binding()
Destructor.
void event_handler(void *tls_async)
Definition: tls_async.c:340
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
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
A cmd class that Unbinds IGMP Config from an interface.
Then L2/objects that bind to interfaces, BD, ACLS, etc.
std::shared_ptr< igmp_binding > singular() const
Return the &#39;singular&#39; of the IGMP binding that matches this object.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
static void dump(std::ostream &os)
Dump all IGMP bindings into the stream provided.
interface::key_t key_t
A binding is tied to a given interface, hence its key is that of the interface.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
igmp_binding(const interface &itf)
Construct a new object matching the desried state.
std::shared_ptr< interface > itf() const
Return the matching&#39;singular&#39; of the interface.
static std::shared_ptr< igmp_binding > find(const key_t &k)
Find a listen from its key.
bool operator==(const igmp_binding &l) const
Equal operator.
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127