VOM: mroutes
[vpp.git] / extras / vom / vom / mroute_cmds.cpp
1 /*
2  * Copyright (c) 2017 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 <sstream>
17
18 #include "vom/api_types.hpp"
19 #include "vom/mroute_cmds.hpp"
20 #include "vom/route_api_types.hpp"
21
22 namespace VOM {
23 namespace route {
24 namespace ip_mroute_cmds {
25
26 update_cmd::update_cmd(HW::item<bool>& item,
27                        table_id_t id,
28                        const mprefix_t& mprefix,
29                        const path& path,
30                        const itf_flags_t& flags)
31   : rpc_cmd(item)
32   , m_id(id)
33   , m_mprefix(mprefix)
34   , m_path(path)
35   , m_flags(flags)
36 {
37 }
38
39 bool
40 update_cmd::operator==(const update_cmd& other) const
41 {
42   return ((m_mprefix == other.m_mprefix) && (m_id == other.m_id));
43 }
44
45 rc_t
46 update_cmd::issue(connection& con)
47 {
48   msg_t req(con.ctx(), std::ref(*this));
49
50   auto& payload = req.get_request().get_payload();
51
52   payload.table_id = m_id;
53   payload.is_add = 1;
54
55   m_mprefix.to_vpp(&payload.is_ipv6, payload.grp_address, payload.src_address,
56                    &payload.grp_address_length);
57
58   to_vpp(m_path, payload);
59   payload.itf_flags = m_flags.value();
60
61   VAPI_CALL(req.execute());
62
63   return (wait());
64 }
65
66 std::string
67 update_cmd::to_string() const
68 {
69   std::ostringstream s;
70   s << "ip-mroute-create: " << m_hw_item.to_string() << " table-id:" << m_id
71     << " mprefix:" << m_mprefix.to_string() << " path:" << m_path.to_string()
72     << " flags:" << m_flags;
73
74   return (s.str());
75 }
76
77 delete_cmd::delete_cmd(HW::item<bool>& item,
78                        table_id_t id,
79                        const mprefix_t& mprefix,
80                        const path& path,
81                        const itf_flags_t& flags)
82   : rpc_cmd(item)
83   , m_id(id)
84   , m_mprefix(mprefix)
85   , m_path(path)
86   , m_flags(flags)
87 {
88 }
89
90 bool
91 delete_cmd::operator==(const delete_cmd& other) const
92 {
93   return ((m_mprefix == other.m_mprefix) && (m_id == other.m_id));
94 }
95
96 rc_t
97 delete_cmd::issue(connection& con)
98 {
99   msg_t req(con.ctx(), std::ref(*this));
100
101   auto& payload = req.get_request().get_payload();
102   payload.table_id = m_id;
103   payload.is_add = 0;
104
105   m_mprefix.to_vpp(&payload.is_ipv6, payload.grp_address, payload.src_address,
106                    &payload.grp_address_length);
107
108   to_vpp(m_path, payload);
109   payload.itf_flags = m_flags.value();
110
111   VAPI_CALL(req.execute());
112
113   wait();
114   m_hw_item.set(rc_t::NOOP);
115
116   return rc_t::OK;
117 }
118
119 std::string
120 delete_cmd::to_string() const
121 {
122   std::ostringstream s;
123   s << "ip-mroute-delete: " << m_hw_item.to_string() << " id:" << m_id
124     << " mprefix:" << m_mprefix.to_string();
125
126   return (s.str());
127 }
128
129 dump_v4_cmd::dump_v4_cmd()
130 {
131 }
132
133 bool
134 dump_v4_cmd::operator==(const dump_v4_cmd& other) const
135 {
136   return (true);
137 }
138
139 rc_t
140 dump_v4_cmd::issue(connection& con)
141 {
142   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
143
144   VAPI_CALL(m_dump->execute());
145
146   wait();
147
148   return rc_t::OK;
149 }
150
151 std::string
152 dump_v4_cmd::to_string() const
153 {
154   return ("ip-mroute-v4-dump");
155 }
156
157 dump_v6_cmd::dump_v6_cmd()
158 {
159 }
160
161 bool
162 dump_v6_cmd::operator==(const dump_v6_cmd& other) const
163 {
164   return (true);
165 }
166
167 rc_t
168 dump_v6_cmd::issue(connection& con)
169 {
170   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
171
172   VAPI_CALL(m_dump->execute());
173
174   wait();
175
176   return rc_t::OK;
177 }
178
179 std::string
180 dump_v6_cmd::to_string() const
181 {
182   return ("ip-mroute-v6-dump");
183 }
184 } // namespace ip_mroute_cmds
185 } // namespace mroute
186 } // namespace vom
187   /*
188    * fd.io coding-style-patch-verification: ON
189    *
190    * Local Variables:
191    * eval: (c-set-style "mozilla")
192    * End:
193    */