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