vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / igmp_listen_cmds.cpp
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
19 DEFINE_VAPI_MSG_IDS_IGMP_API_JSON;
20
21 namespace VOM {
22 namespace igmp_listen_cmds {
23 listen_cmd::listen_cmd(HW::item<bool>& item,
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
35 listen_cmd::operator==(const listen_cmd& other) const
36 {
37   return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr) &&
38           (m_saddrs == other.m_saddrs));
39 }
40
41 rc_t
42 listen_cmd::issue(connection& con)
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
73 listen_cmd::to_string() const
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
87 unlisten_cmd::unlisten_cmd(HW::item<bool>& item,
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
97 unlisten_cmd::operator==(const unlisten_cmd& other) const
98 {
99   return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr));
100 }
101
102 rc_t
103 unlisten_cmd::issue(connection& con)
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();
116   m_hw_item.set(rc_t::NOOP);
117
118   return rc_t::OK;
119 }
120
121 std::string
122 unlisten_cmd::to_string() const
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
131 dump_cmd::dump_cmd(const handle_t& hdl)
132   : m_itf(hdl)
133 {
134 }
135
136 dump_cmd::dump_cmd(const dump_cmd& d)
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
148 dump_cmd::issue(connection& con)
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
163 dump_cmd::to_string() const
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  */