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"
26 * Types belonging to Routing
30 * A path for IP or MPLS routes
38 class special_t : public enum_base<special_t>
42 * A standard path type. this includes path types
43 * that use the next-hop and interface
45 const static special_t STANDARD;
48 * A local/for-us/recieve
50 const static special_t LOCAL;
55 const static special_t DROP;
58 * a path will return ICMP unreachables
60 const static special_t UNREACH;
63 * a path will return ICMP prohibit
65 const static special_t PROHIBIT;
69 * Private constructor taking the value and the string name
71 special_t(int v, const std::string& s);
75 * constructor for special paths
77 path(special_t special);
80 * Constructor for standard non-recursive paths
82 path(const boost::asio::ip::address& nh,
83 const interface& interface,
85 uint8_t preference = 0);
88 * Constructor for standard recursive paths
90 path(const route_domain& rd,
91 const boost::asio::ip::address& nh,
93 uint8_t preference = 0);
96 * Constructor for DVR paths or attached paths.
98 path(const interface& interface,
99 const nh_proto_t& proto,
101 uint8_t preference = 0);
109 * Convert the path into the VPP API representation
111 void to_vpp(vapi_payload_ip_add_del_route& payload) const;
114 * Less than operator for set insertion
116 bool operator<(const path& p) const;
119 * convert to string format for debug purposes
121 std::string to_string() const;
126 special_t type() const;
127 nh_proto_t nh_proto() const;
128 const boost::asio::ip::address& nh() const;
129 std::shared_ptr<route_domain> rd() const;
130 std::shared_ptr<interface> itf() const;
131 uint8_t weight() const;
132 uint8_t preference() const;
136 * The special path tpye
141 * The next-hop protocol
143 nh_proto_t m_nh_proto;
148 boost::asio::ip::address m_nh;
151 * For recursive routes, this is the table in which the
152 * the next-hop exists.
154 std::shared_ptr<route_domain> m_rd;
157 * The next-hop interface [if present].
159 std::shared_ptr<interface> m_interface;
169 uint8_t m_preference;
173 * A path-list is a set of paths
175 typedef std::set<path> path_list_t;
178 * ostream output for iterator
180 std::ostream& operator<<(std::ostream& os, const path_list_t& path_list);
185 class ip_route : public object_base
189 * The key for a route
191 typedef std::pair<route::table_id_t, prefix_t> key_t;
194 * Construct a route in the default table
196 ip_route(const prefix_t& prefix);
201 ip_route(const ip_route& r);
204 * Construct a route in the given route domain
206 ip_route(const route_domain& rd, const prefix_t& prefix);
214 * Return the matching 'singular instance'
216 std::shared_ptr<ip_route> singular() const;
221 void add(const path& path);
226 void remove(const path& path);
229 * Find the instnace of the route domain in the OM
231 static std::shared_ptr<ip_route> find(const ip_route& temp);
234 * Dump all route-doamin into the stream provided
236 static void dump(std::ostream& os);
239 * replay the object to create it in hardware
244 * Convert to string for debugging
246 std::string to_string() const;
250 * Class definition for listeners to OM events
252 class event_handler : public OM::listener, public inspect::command_handler
256 virtual ~event_handler() = default;
259 * Handle a populate event
261 void handle_populate(const client_db::key_t& key);
264 * Handle a replay event
266 void handle_replay();
269 * Show the object in the Singular DB
271 void show(std::ostream& os);
274 * Get the sortable Id of the listener
276 dependency_t order() const;
280 * event_handler to register with OM
282 static event_handler m_evh;
285 * Find or add the instnace of the route domain in the OM
287 static std::shared_ptr<ip_route> find_or_add(const ip_route& temp);
290 * It's the OM class that updates the objects in HW
292 friend class VOM::OM;
295 * It's the singular_db class that calls replay()
297 friend class singular_db<key_t, ip_route>;
300 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
302 void update(const ip_route& obj);
305 * Sweep/reap the object if still stale
310 * HW configuration for the result of creating the route
315 * The route domain the route is in.
317 std::shared_ptr<route_domain> m_rd;
320 * The prefix to match
330 * A map of all routes
332 static singular_db<key_t, ip_route> m_db;
335 std::ostream& operator<<(std::ostream& os, const ip_route::key_t& key);
340 * fd.io coding-style-patch-verification: ON
343 * eval: (c-set-style "mozilla")