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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/igmp_listen_cmds.hpp"
17 #include "vom/api_types.hpp"
19 DEFINE_VAPI_MSG_IDS_IGMP_API_JSON;
22 namespace igmp_listen_cmds {
23 listen_cmd::listen_cmd(HW::item<bool>& item,
25 const boost::asio::ip::address& gaddr,
26 const igmp_listen::src_addrs_t& saddrs)
35 listen_cmd::operator==(const listen_cmd& other) const
37 return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr));
41 listen_cmd::issue(connection& con)
43 u8 size = m_saddrs.size();
44 msg_t req(con.ctx(), sizeof(vapi_type_ip4_address) * size, std::ref(*this));
46 auto& payload = req.get_request().get_payload();
47 payload.group.sw_if_index = m_itf.value();
48 to_api(m_gaddr.to_v4(), payload.group.gaddr);
51 // no sources => (*,G) join
52 payload.group.filter = EXCLUDE;
53 payload.group.n_srcs = 0;
55 // source => (S,G) join
56 payload.group.filter = INCLUDE;
59 for (auto addr : m_saddrs) {
60 to_api(addr, payload.group.saddrs[i]);
63 payload.group.n_srcs = i;
66 VAPI_CALL(req.execute());
72 listen_cmd::to_string() const
74 auto addr = m_saddrs.cbegin();
76 s << "igmp-listen: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
77 << " group:" << m_gaddr << " src-addrs:[";
78 while (addr != m_saddrs.cend()) {
86 unlisten_cmd::unlisten_cmd(HW::item<bool>& item,
88 const boost::asio::ip::address& gaddr)
96 unlisten_cmd::operator==(const unlisten_cmd& other) const
98 return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr));
102 unlisten_cmd::issue(connection& con)
104 msg_t req(con.ctx(), 0, std::ref(*this));
106 auto& payload = req.get_request().get_payload();
107 payload.group.sw_if_index = m_itf.value();
108 payload.group.n_srcs = 0;
109 payload.group.filter = INCLUDE;
110 to_api(m_gaddr.to_v4(), payload.group.gaddr);
112 VAPI_CALL(req.execute());
115 m_hw_item.set(rc_t::NOOP);
121 unlisten_cmd::to_string() const
123 std::ostringstream s;
124 s << "igmp-unlisten: " << m_hw_item.to_string()
125 << " itf:" << m_itf.to_string() << " group:" << m_gaddr;
130 dump_cmd::dump_cmd(const handle_t& hdl)
135 dump_cmd::dump_cmd(const dump_cmd& d)
141 dump_cmd::operator==(const dump_cmd& other) const
147 dump_cmd::issue(connection& con)
149 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
151 auto& payload = m_dump->get_request().get_payload();
152 payload.sw_if_index = m_itf.value();
154 VAPI_CALL(m_dump->execute());
162 dump_cmd::to_string() const
164 return ("igmp-listen-dump");
167 }; // namespace igmp_listen_cmds
171 * fd.io coding-style-patch-verification: ON
174 * eval: (c-set-style "mozilla")