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_v4& 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) &&
38 (m_saddrs == other.m_saddrs));
42 listen_cmd::issue(connection& con)
44 u8 size = m_saddrs.size();
45 msg_t req(con.ctx(), sizeof(vapi_type_ip4_address) * size, std::ref(*this));
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);
52 // no sources => (*,G) join
53 payload.group.filter = EXCLUDE;
54 payload.group.n_srcs = 0;
56 // source => (S,G) join
57 payload.group.filter = INCLUDE;
60 for (auto addr : m_saddrs) {
61 to_api(addr, payload.group.saddrs[i]);
64 payload.group.n_srcs = i;
67 VAPI_CALL(req.execute());
73 listen_cmd::to_string() const
75 auto addr = m_saddrs.cbegin();
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()) {
87 unlisten_cmd::unlisten_cmd(HW::item<bool>& item,
89 const boost::asio::ip::address_v4& gaddr)
97 unlisten_cmd::operator==(const unlisten_cmd& other) const
99 return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr));
103 unlisten_cmd::issue(connection& con)
105 msg_t req(con.ctx(), 0, std::ref(*this));
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);
113 VAPI_CALL(req.execute());
116 m_hw_item.set(rc_t::NOOP);
122 unlisten_cmd::to_string() const
124 std::ostringstream s;
125 s << "igmp-unlisten: " << m_hw_item.to_string()
126 << " itf:" << m_itf.to_string() << " group:" << m_gaddr;
131 dump_cmd::dump_cmd(const handle_t& hdl)
136 dump_cmd::dump_cmd(const dump_cmd& d)
142 dump_cmd::operator==(const dump_cmd& other) const
148 dump_cmd::issue(connection& con)
150 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
152 auto& payload = m_dump->get_request().get_payload();
153 payload.sw_if_index = m_itf.value();
155 VAPI_CALL(m_dump->execute());
163 dump_cmd::to_string() const
165 return ("igmp-listen-dump");
168 }; // namespace igmp_listen_cmds
172 * fd.io coding-style-patch-verification: ON
175 * eval: (c-set-style "mozilla")