blob: 83d44ccc01d388ee7aa9d658b84f218eb2c8177c [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070018#include "vom/route_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070019
20namespace VOM {
21namespace route {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070022namespace ip_route_cmds {
23
24static void
25to_vpp(const route::path& p, vapi_payload_ip_add_del_route& payload)
26{
27 payload.is_drop = 0;
28 payload.is_unreach = 0;
29 payload.is_prohibit = 0;
30 payload.is_local = 0;
31 payload.is_classify = 0;
32 payload.is_multipath = 0;
33 payload.is_resolve_host = 0;
34 payload.is_resolve_attached = 0;
35
Neale Rannsf068c3e2018-01-03 04:18:48 -080036 if (route::path::flags_t::DVR & p.flags()) {
37 payload.is_dvr = 1;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070038 }
39
40 if (route::path::special_t::STANDARD == p.type()) {
41 uint8_t path_v6;
42 to_bytes(p.nh(), &path_v6, payload.next_hop_address);
43
44 if (p.rd()) {
45 payload.next_hop_table_id = p.rd()->table_id();
46 }
47 if (p.itf()) {
48 payload.next_hop_sw_if_index = p.itf()->handle().value();
49 }
50 } else if (route::path::special_t::DROP == p.type()) {
51 payload.is_drop = 1;
52 } else if (route::path::special_t::UNREACH == p.type()) {
53 payload.is_unreach = 1;
54 } else if (route::path::special_t::PROHIBIT == p.type()) {
55 payload.is_prohibit = 1;
56 } else if (route::path::special_t::LOCAL == p.type()) {
57 payload.is_local = 1;
58 }
59 payload.next_hop_weight = p.weight();
60 payload.next_hop_preference = p.preference();
61 payload.next_hop_via_label = 0;
62 payload.classify_table_index = 0;
63}
64
65update_cmd::update_cmd(HW::item<bool>& item,
66 table_id_t id,
67 const prefix_t& prefix,
68 const path_list_t& paths)
Neale Ranns812ed392017-10-16 04:20:13 -070069 : rpc_cmd(item)
70 , m_id(id)
71 , m_prefix(prefix)
72 , m_paths(paths)
73{
74 // no multipath yet.
75 assert(paths.size() == 1);
76}
77
78bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070079update_cmd::operator==(const update_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -070080{
81 return ((m_prefix == other.m_prefix) && (m_id == other.m_id));
82}
83
84rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070085update_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070086{
87 msg_t req(con.ctx(), 0, std::ref(*this));
88
89 auto& payload = req.get_request().get_payload();
90
91 payload.table_id = m_id;
92 payload.is_add = 1;
93 payload.is_multipath = 0;
94
95 m_prefix.to_vpp(&payload.is_ipv6, payload.dst_address,
96 &payload.dst_address_length);
97
98 for (auto& p : m_paths)
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070099 to_vpp(p, payload);
Neale Ranns812ed392017-10-16 04:20:13 -0700100
101 VAPI_CALL(req.execute());
102
103 m_hw_item.set(wait());
104
105 return rc_t::OK;
106}
107
108std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700109update_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700110{
111 std::ostringstream s;
112 s << "ip-route-create: " << m_hw_item.to_string() << " table-id:" << m_id
113 << " prefix:" << m_prefix.to_string() << " paths:" << m_paths;
114
115 return (s.str());
116}
117
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700118delete_cmd::delete_cmd(HW::item<bool>& item,
119 table_id_t id,
120 const prefix_t& prefix)
Neale Ranns812ed392017-10-16 04:20:13 -0700121 : rpc_cmd(item)
122 , m_id(id)
123 , m_prefix(prefix)
124{
125}
126
127bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700128delete_cmd::operator==(const delete_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -0700129{
130 return ((m_prefix == other.m_prefix) && (m_id == other.m_id));
131}
132
133rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700134delete_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -0700135{
136 msg_t req(con.ctx(), 0, std::ref(*this));
137
138 auto& payload = req.get_request().get_payload();
139 payload.table_id = m_id;
140 payload.is_add = 0;
141
142 m_prefix.to_vpp(&payload.is_ipv6, payload.dst_address,
143 &payload.dst_address_length);
144
145 VAPI_CALL(req.execute());
146
147 wait();
148 m_hw_item.set(rc_t::NOOP);
149
150 return rc_t::OK;
151}
152
153std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700154delete_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700155{
156 std::ostringstream s;
157 s << "ip-route-delete: " << m_hw_item.to_string() << " id:" << m_id
158 << " prefix:" << m_prefix.to_string();
159
160 return (s.str());
161}
162
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700163dump_v4_cmd::dump_v4_cmd()
Neale Ranns812ed392017-10-16 04:20:13 -0700164{
165}
166
167bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700168dump_v4_cmd::operator==(const dump_v4_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -0700169{
170 return (true);
171}
172
173rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700174dump_v4_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -0700175{
176 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
177
178 VAPI_CALL(m_dump->execute());
179
180 wait();
181
182 return rc_t::OK;
183}
184
185std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700186dump_v4_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700187{
188 return ("ip-route-v4-dump");
189}
190
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700191dump_v6_cmd::dump_v6_cmd()
Neale Ranns812ed392017-10-16 04:20:13 -0700192{
193}
194
195bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700196dump_v6_cmd::operator==(const dump_v6_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -0700197{
198 return (true);
199}
200
201rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700202dump_v6_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -0700203{
204 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
205
206 VAPI_CALL(m_dump->execute());
207
208 wait();
209
210 return rc_t::OK;
211}
212
213std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700214dump_v6_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700215{
216 return ("ip-route-v6-dump");
217}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700218} // namespace ip_route_cmds
219} // namespace route
220} // namespace vom
221 /*
222 * fd.io coding-style-patch-verification: ON
223 *
224 * Local Variables:
225 * eval: (c-set-style "mozilla")
226 * End:
227 */