FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
igmp_listen_cmds.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_cmds.hpp"
17 #include "vom/api_types.hpp"
18 
20 
21 namespace VOM {
22 namespace igmp_listen_cmds {
24  const handle_t& itf,
25  const boost::asio::ip::address_v4& gaddr,
26  const igmp_listen::src_addrs_t& saddrs)
27  : rpc_cmd(item)
28  , m_itf(itf)
29  , m_gaddr(gaddr)
30  , m_saddrs(saddrs)
31 {
32 }
33 
34 bool
36 {
37  return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr) &&
38  (m_saddrs == other.m_saddrs));
39 }
40 
41 rc_t
43 {
44  u8 size = m_saddrs.size();
45  msg_t req(con.ctx(), sizeof(vapi_type_ip4_address) * size, std::ref(*this));
46 
47  auto& payload = req.get_request().get_payload();
48  payload.group.sw_if_index = m_itf.value();
49  to_api(m_gaddr, payload.group.gaddr);
50 
51  if (0 == size) {
52  // no sources => (*,G) join
53  payload.group.filter = EXCLUDE;
54  payload.group.n_srcs = 0;
55  } else {
56  // source => (S,G) join
57  payload.group.filter = INCLUDE;
58  u8 i = 0;
59 
60  for (auto addr : m_saddrs) {
61  to_api(addr, payload.group.saddrs[i]);
62  i++;
63  }
64  payload.group.n_srcs = i;
65  }
66 
67  VAPI_CALL(req.execute());
68 
69  return (wait());
70 }
71 
72 std::string
74 {
75  auto addr = m_saddrs.cbegin();
76  std::ostringstream s;
77  s << "igmp-listen: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
78  << " group:" << m_gaddr << " src-addrs:[";
79  while (addr != m_saddrs.cend()) {
80  s << " " << *addr;
81  addr++;
82  }
83  s << " ]";
84  return (s.str());
85 }
86 
88  const handle_t& itf,
89  const boost::asio::ip::address_v4& gaddr)
90  : rpc_cmd(item)
91  , m_itf(itf)
92  , m_gaddr(gaddr)
93 {
94 }
95 
96 bool
98 {
99  return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr));
100 }
101 
102 rc_t
104 {
105  msg_t req(con.ctx(), 0, std::ref(*this));
106 
107  auto& payload = req.get_request().get_payload();
108  payload.group.sw_if_index = m_itf.value();
109  payload.group.n_srcs = 0;
110  payload.group.filter = INCLUDE;
111  to_api(m_gaddr, payload.group.gaddr);
112 
113  VAPI_CALL(req.execute());
114 
115  wait();
117 
118  return rc_t::OK;
119 }
120 
121 std::string
123 {
124  std::ostringstream s;
125  s << "igmp-unlisten: " << m_hw_item.to_string()
126  << " itf:" << m_itf.to_string() << " group:" << m_gaddr;
127 
128  return (s.str());
129 }
130 
132  : m_itf(hdl)
133 {
134 }
135 
137  : m_itf(d.m_itf)
138 {
139 }
140 
141 bool
142 dump_cmd::operator==(const dump_cmd& other) const
143 {
144  return (true);
145 }
146 
147 rc_t
149 {
150  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
151 
152  auto& payload = m_dump->get_request().get_payload();
153  payload.sw_if_index = m_itf.value();
154 
155  VAPI_CALL(m_dump->execute());
156 
157  wait();
158 
159  return rc_t::OK;
160 }
161 
162 std::string
164 {
165  return ("igmp-listen-dump");
166 }
167 
168 }; // namespace igmp_listen_cmds
169 }; // namespace VOM
170 
171 /*
172  * fd.io coding-style-patch-verification: ON
173  *
174  * Local Variables:
175  * eval: (c-set-style "mozilla")
176  * End:
177  */
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
std::string to_string() const
convert to string format for debug purposes
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
Definition: igmp.api:27
Definition: igmp.api:26
int i
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
vhost_vring_addr_t addr
Definition: vhost_user.h:121
unsigned char u8
Definition: types.h:56
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
A functor class that binds the igmp group to the interface.
std::string to_string() const
convert to string format for debug purposes
A representation of the connection to VPP.
Definition: connection.hpp:33
dump_cmd()
Default Constructor.
Definition: dump_cmd.hpp:55
uword size
listen_cmd(HW::item< bool > &item, const handle_t &itf, const boost::asio::ip::address_v4 &gaddr, const igmp_listen::src_addrs_t &saddrs)
Constructor.
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
A cmd class that Unbinds igmp group from an interface.
std::set< boost::asio::ip::address_v4 > src_addrs_t
Definition: igmp_listen.hpp:34
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
rc_t issue(connection &con)
Issue the command to VPP/HW.
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
A cmd class that Dumps all the igmp configs.
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
rc_t issue(connection &con)
Issue the command to VPP/HW.
bool operator==(const unlisten_cmd &i) const
Comparison operator - only used for UT.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
rc_t issue(connection &con)
Issue the command to VPP/HW.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void set(const rc_t &rc)
Set the HW return code - should only be called from the family of Command objects.
Definition: hw.hpp:125
std::unique_ptr< vapi::Igmp_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
bool operator==(const listen_cmd &i) const
Comparison operator - only used for UT.
unlisten_cmd(HW::item< bool > &item, const handle_t &itf, const boost::asio::ip::address_v4 &gaddr)
Constructor.
HW::item< bool > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:134
DEFINE_VAPI_MSG_IDS_IGMP_API_JSON
std::string to_string() const
convert to string format for debug purposes
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vapi::Igmp_listen msg_t
convenient typedef
Definition: rpc_cmd.hpp:46