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:
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.
18 #include "vom/route_cmds.hpp"
22 namespace ip_route_cmds {
25 to_vpp(const route::path& p, vapi_payload_ip_add_del_route& payload)
28 payload.is_unreach = 0;
29 payload.is_prohibit = 0;
31 payload.is_classify = 0;
32 payload.is_multipath = 0;
33 payload.is_resolve_host = 0;
34 payload.is_resolve_attached = 0;
36 if (route::path::flags_t::DVR & p.flags()) {
40 if (route::path::special_t::STANDARD == p.type()) {
42 to_bytes(p.nh(), &path_v6, payload.next_hop_address);
45 payload.next_hop_table_id = p.rd()->table_id();
48 payload.next_hop_sw_if_index = p.itf()->handle().value();
50 } else if (route::path::special_t::DROP == p.type()) {
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()) {
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;
65 update_cmd::update_cmd(HW::item<bool>& item,
67 const prefix_t& prefix,
68 const path_list_t& paths)
75 assert(paths.size() == 1);
79 update_cmd::operator==(const update_cmd& other) const
81 return ((m_prefix == other.m_prefix) && (m_id == other.m_id));
85 update_cmd::issue(connection& con)
87 msg_t req(con.ctx(), 0, std::ref(*this));
89 auto& payload = req.get_request().get_payload();
91 payload.table_id = m_id;
93 payload.is_multipath = 0;
95 m_prefix.to_vpp(&payload.is_ipv6, payload.dst_address,
96 &payload.dst_address_length);
98 for (auto& p : m_paths)
101 VAPI_CALL(req.execute());
107 update_cmd::to_string() const
109 std::ostringstream s;
110 s << "ip-route-create: " << m_hw_item.to_string() << " table-id:" << m_id
111 << " prefix:" << m_prefix.to_string() << " paths:" << m_paths;
116 delete_cmd::delete_cmd(HW::item<bool>& item,
118 const prefix_t& prefix)
126 delete_cmd::operator==(const delete_cmd& other) const
128 return ((m_prefix == other.m_prefix) && (m_id == other.m_id));
132 delete_cmd::issue(connection& con)
134 msg_t req(con.ctx(), 0, std::ref(*this));
136 auto& payload = req.get_request().get_payload();
137 payload.table_id = m_id;
140 m_prefix.to_vpp(&payload.is_ipv6, payload.dst_address,
141 &payload.dst_address_length);
143 VAPI_CALL(req.execute());
146 m_hw_item.set(rc_t::NOOP);
152 delete_cmd::to_string() const
154 std::ostringstream s;
155 s << "ip-route-delete: " << m_hw_item.to_string() << " id:" << m_id
156 << " prefix:" << m_prefix.to_string();
161 dump_v4_cmd::dump_v4_cmd()
166 dump_v4_cmd::operator==(const dump_v4_cmd& other) const
172 dump_v4_cmd::issue(connection& con)
174 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
176 VAPI_CALL(m_dump->execute());
184 dump_v4_cmd::to_string() const
186 return ("ip-route-v4-dump");
189 dump_v6_cmd::dump_v6_cmd()
194 dump_v6_cmd::operator==(const dump_v6_cmd& other) const
200 dump_v6_cmd::issue(connection& con)
202 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
204 VAPI_CALL(m_dump->execute());
212 dump_v6_cmd::to_string() const
214 return ("ip-route-v6-dump");
216 } // namespace ip_route_cmds
220 * fd.io coding-style-patch-verification: ON
223 * eval: (c-set-style "mozilla")