FD.io VPP  v21.06-3-gbb25fbf28
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,
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 
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 
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 
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: OFF
173  *
174  * Local Variables:
175  * eval: (c-set-style "mozilla")
176  * End:
177  */
VOM::HW::item< bool >
EXCLUDE
@ EXCLUDE
Definition: igmp.api:27
VOM::dump_cmd< vapi::Igmp_dump >::msg_t
vapi::Igmp_dump msg_t
Definition: dump_cmd.hpp:46
VOM::rpc_cmd< HW::item< bool >, vapi::Igmp_listen >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
VOM::HW::item::set
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
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::igmp_listen_cmds::unlisten_cmd::unlisten_cmd
unlisten_cmd(HW::item< bool > &item, const handle_t &itf, const boost::asio::ip::address_v4 &gaddr)
Constructor.
Definition: igmp_listen_cmds.cpp:87
VOM::igmp_listen_cmds::listen_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: igmp_listen_cmds.cpp:73
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
con
Connection con
Definition: vapi_cpp_test.cpp:56
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
VOM::rpc_cmd< HW::item< bool >, vapi::Igmp_listen >::m_hw_item
HW::item< bool > & m_hw_item
A reference to an object's HW::item that the command will update.
Definition: rpc_cmd.hpp:134
VOM::dump_cmd< vapi::Igmp_dump >::m_dump
std::unique_ptr< vapi::Igmp_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::igmp_listen_cmds::unlisten_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: igmp_listen_cmds.cpp:122
VOM::igmp_listen_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: igmp_listen_cmds.cpp:142
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::dump_cmd
A cmd class that Dumps all the igmp configs.
Definition: igmp_listen_cmds.hpp:116
VOM::igmp_listen_cmds::listen_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: igmp_listen_cmds.cpp:42
VOM::igmp_listen_cmds::unlisten_cmd
A cmd class that Unbinds igmp group from an interface.
Definition: igmp_listen_cmds.hpp:76
DEFINE_VAPI_MSG_IDS_IGMP_API_JSON
DEFINE_VAPI_MSG_IDS_IGMP_API_JSON
Definition: igmp_listen_cmds.cpp:19
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::igmp_listen_cmds::unlisten_cmd::operator==
bool operator==(const unlisten_cmd &i) const
Comparison operator - only used for UT.
Definition: igmp_listen_cmds.cpp:97
VOM::dump_cmd< vapi::Igmp_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
VOM::igmp_listen_cmds::listen_cmd::operator==
bool operator==(const listen_cmd &i) const
Comparison operator - only used for UT.
Definition: igmp_listen_cmds.cpp:35
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::to_api
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
VOM::rpc_cmd< HW::item< bool >, vapi::Igmp_listen >::msg_t
vapi::Igmp_listen msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
size
u32 size
Definition: vhost_user.h:125
VOM::handle_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
INCLUDE
@ INCLUDE
Definition: igmp.api: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
gaddr
vl_api_ip4_address_t gaddr
Definition: igmp.api:70
VOM::igmp_listen_cmds::unlisten_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: igmp_listen_cmds.cpp:103
igmp_listen_cmds.hpp
item
cJSON * item
Definition: cJSON.h:222
VOM::igmp_listen_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: igmp_listen_cmds.cpp:148
VOM::dump_cmd< vapi::Igmp_dump >::dump_cmd
dump_cmd()
Default Constructor.
Definition: dump_cmd.hpp:55
u8
unsigned char u8
Definition: types.h:56
VOM::igmp_listen_cmds::listen_cmd::listen_cmd
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.
Definition: igmp_listen_cmds.cpp:23
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::igmp_listen_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: igmp_listen_cmds.cpp:163
api_types.hpp
string
const char *const string
Definition: cJSON.h:172