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.
16 #ifndef __VOM_ROUTE_H__
17 #define __VOM_ROUTE_H__
19 #include "vom/interface.hpp"
20 #include "vom/prefix.hpp"
21 #include "vom/route_domain.hpp"
22 #include "vom/singular_db.hpp"
24 #include <vapi/ip.api.vapi.hpp>
28 * Types belonging to Routing
32 * A path for IP or MPLS routes
40 class special_t : public enum_base<special_t>
44 * A standard path type. this includes path types
45 * that use the next-hop and interface
47 const static special_t STANDARD;
50 * A local/for-us/recieve
52 const static special_t LOCAL;
57 const static special_t DROP;
60 * a path will return ICMP unreachables
62 const static special_t UNREACH;
65 * a path will return ICMP prohibit
67 const static special_t PROHIBIT;
71 * Private constructor taking the value and the string name
73 special_t(int v, const std::string& s);
77 * constructor for special paths
79 path(special_t special);
82 * Constructor for standard non-recursive paths
84 path(const boost::asio::ip::address& nh,
85 const interface& interface,
87 uint8_t preference = 0);
90 * Constructor for standard recursive paths
92 path(const route_domain& rd,
93 const boost::asio::ip::address& nh,
95 uint8_t preference = 0);
98 * Constructor for DVR paths or attached paths.
100 path(const interface& interface,
101 const nh_proto_t& proto,
103 uint8_t preference = 0);
111 * Convert the path into the VPP API representation
113 void to_vpp(vapi_type_fib_path& path) const;
114 void to_vpp(vapi_payload_ip_add_del_route& payload) const;
117 * Less than operator for set insertion
119 bool operator<(const path& p) const;
122 * convert to string format for debug purposes
124 std::string to_string() const;
128 * The special path tpye
133 * The next-hop protocol
135 nh_proto_t m_nh_proto;
140 boost::asio::ip::address m_nh;
143 * For recursive routes, this is the table in which the
144 * the next-hop exists.
146 std::shared_ptr<route_domain> m_rd;
149 * The next-hop interface [if present].
151 std::shared_ptr<interface> m_interface;
161 uint8_t m_preference;
165 * A path-list is a set of paths
167 typedef std::set<path> path_list_t;
170 * ostream output for iterator
172 std::ostream& operator<<(std::ostream& os, const path_list_t& path_list);
177 class ip_route : public object_base
181 * The key for a route
183 typedef std::pair<route::table_id_t, prefix_t> key_t;
186 * Construct a route in the default table
188 ip_route(const prefix_t& prefix);
193 ip_route(const ip_route& r);
196 * Construct a route in the given route domain
198 ip_route(const route_domain& rd, const prefix_t& prefix);
206 * Return the matching 'singular instance'
208 std::shared_ptr<ip_route> singular() const;
213 void add(const path& path);
218 void remove(const path& path);
221 * Find the instnace of the route domain in the OM
223 static std::shared_ptr<ip_route> find(const ip_route& temp);
226 * Dump all route-doamin into the stream provided
228 static void dump(std::ostream& os);
231 * replay the object to create it in hardware
236 * Convert to string for debugging
238 std::string to_string() const;
241 * A command class that creates or updates the route
244 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Ip_add_del_route>
250 update_cmd(HW::item<bool>& item,
252 const prefix_t& prefix,
253 const path_list_t& paths);
256 * Issue the command to VPP/HW
258 rc_t issue(connection& con);
261 * convert to string format for debug purposes
263 std::string to_string() const;
266 * Comparison operator - only used for UT
268 bool operator==(const update_cmd& i) const;
271 route::table_id_t m_id;
273 const path_list_t m_paths;
277 * A cmd class that deletes a route
280 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Ip_add_del_route>
286 delete_cmd(HW::item<bool>& item, table_id_t id, const prefix_t& prefix);
289 * Issue the command to VPP/HW
291 rc_t issue(connection& con);
294 * convert to string format for debug purposes
296 std::string to_string() const;
299 * Comparison operator - only used for UT
301 bool operator==(const delete_cmd& i) const;
304 route::table_id_t m_id;
309 * A cmd class that Dumps ipv4 fib
311 class dump_v4_cmd : public VOM::dump_cmd<vapi::Ip_fib_dump>
318 dump_v4_cmd(const dump_cmd& d);
321 * Issue the command to VPP/HW
323 rc_t issue(connection& con);
325 * convert to string format for debug purposes
327 std::string to_string() const;
330 * Comparison operator - only used for UT
332 bool operator==(const dump_v4_cmd& i) const;
342 * A cmd class that Dumps ipv6 fib
344 class dump_v6_cmd : public VOM::dump_cmd<vapi::Ip6_fib_dump>
351 dump_v6_cmd(const dump_cmd& d);
354 * Issue the command to VPP/HW
356 rc_t issue(connection& con);
358 * convert to string format for debug purposes
360 std::string to_string() const;
363 * Comparison operator - only used for UT
365 bool operator==(const dump_v6_cmd& i) const;
376 * Class definition for listeners to OM events
378 class event_handler : public OM::listener, public inspect::command_handler
382 virtual ~event_handler() = default;
385 * Handle a populate event
387 void handle_populate(const client_db::key_t& key);
390 * Handle a replay event
392 void handle_replay();
395 * Show the object in the Singular DB
397 void show(std::ostream& os);
400 * Get the sortable Id of the listener
402 dependency_t order() const;
406 * event_handler to register with OM
408 static event_handler m_evh;
411 * Find or add the instnace of the route domain in the OM
413 static std::shared_ptr<ip_route> find_or_add(const ip_route& temp);
416 * It's the OM class that updates the objects in HW
418 friend class VOM::OM;
421 * It's the singular_db class that calls replay()
423 friend class singular_db<key_t, ip_route>;
426 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
428 void update(const ip_route& obj);
431 * Sweep/reap the object if still stale
436 * HW configuration for the result of creating the route
441 * The route domain the route is in.
443 std::shared_ptr<route_domain> m_rd;
446 * The prefix to match
456 * A map of all routes
458 static singular_db<key_t, ip_route> m_db;
461 std::ostream& operator<<(std::ostream& os, const ip_route::key_t& key);
466 * fd.io coding-style-patch-verification: ON
469 * eval: (c-set-style "mozilla")