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"
18 DEFINE_VAPI_MSG_IDS_IGMP_API_JSON;
21 namespace igmp_listen_cmds {
22 listen_cmd::listen_cmd(HW::item<bool>& item,
24 const boost::asio::ip::address& gaddr,
25 const igmp_listen::src_addrs_t& saddrs)
34 listen_cmd::operator==(const listen_cmd& other) const
36 return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr));
40 listen_cmd::issue(connection& con)
42 u8 size = m_saddrs.size();
43 msg_t req(con.ctx(), sizeof(vapi_type_ip4_address) * size, std::ref(*this));
45 auto& payload = req.get_request().get_payload();
46 payload.group.sw_if_index = m_itf.value();
47 payload.group.filter = EXCLUDE;
48 to_bytes(m_gaddr.to_v4(), (u8*)&payload.group.gaddr);
49 auto addr = m_saddrs.cbegin();
51 while (addr != m_saddrs.cend()) {
52 to_bytes(addr->to_v4(), (u8*)&payload.group.saddrs[i]);
57 payload.group.n_srcs = i;
58 VAPI_CALL(req.execute());
64 listen_cmd::to_string() const
66 auto addr = m_saddrs.cbegin();
68 s << "igmp-listen: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
69 << " group:" << m_gaddr << " src-addrs:[";
70 while (addr != m_saddrs.cend()) {
78 unlisten_cmd::unlisten_cmd(HW::item<bool>& item,
80 const boost::asio::ip::address& gaddr)
88 unlisten_cmd::operator==(const unlisten_cmd& other) const
90 return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr));
94 unlisten_cmd::issue(connection& con)
96 msg_t req(con.ctx(), 0, std::ref(*this));
98 auto& payload = req.get_request().get_payload();
99 payload.group.sw_if_index = m_itf.value();
100 payload.group.n_srcs = 0;
101 payload.group.filter = INCLUDE;
102 to_bytes(m_gaddr.to_v4(), (u8*)&payload.group.gaddr);
104 VAPI_CALL(req.execute());
107 m_hw_item.set(rc_t::NOOP);
113 unlisten_cmd::to_string() const
115 std::ostringstream s;
116 s << "igmp-unlisten: " << m_hw_item.to_string()
117 << " itf:" << m_itf.to_string() << " group:" << m_gaddr;
122 dump_cmd::dump_cmd(const handle_t& hdl)
127 dump_cmd::dump_cmd(const dump_cmd& d)
133 dump_cmd::operator==(const dump_cmd& other) const
139 dump_cmd::issue(connection& con)
141 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
143 auto& payload = m_dump->get_request().get_payload();
144 payload.sw_if_index = m_itf.value();
146 VAPI_CALL(m_dump->execute());
154 dump_cmd::to_string() const
156 return ("igmp-listen-dump");
159 }; // namespace igmp_listen_cmds
163 * fd.io coding-style-patch-verification: ON
166 * eval: (c-set-style "mozilla")