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);
114 * comparison operator
116 bool operator==(const path& p) const;
119 * Less than operator for set insertion
121 bool operator<(const path& p) const;
124 * convert to string format for debug purposes
126 std::string to_string() const;
131 special_t type() const;
132 nh_proto_t nh_proto() const;
133 const boost::asio::ip::address& nh() const;
134 std::shared_ptr<route_domain> rd() const;
135 std::shared_ptr<interface> itf() const;
136 uint8_t weight() const;
137 uint8_t preference() const;
141 * The special path tpye
146 * The next-hop protocol
148 nh_proto_t m_nh_proto;
153 boost::asio::ip::address m_nh;
156 * For recursive routes, this is the table in which the
157 * the next-hop exists.
159 std::shared_ptr<route_domain> m_rd;
162 * The next-hop interface [if present].
164 std::shared_ptr<interface> m_interface;
174 uint8_t m_preference;
178 * A path-list is a set of paths
180 typedef std::set<path> path_list_t;
183 * ostream output for iterator
185 std::ostream& operator<<(std::ostream& os, const path_list_t& path_list);
190 class ip_route : public object_base
194 * The key for a route
196 typedef std::pair<route::table_id_t, prefix_t> key_t;
199 * Construct a route in the default table
201 ip_route(const prefix_t& prefix);
204 * Construct a route with a path
206 ip_route(const prefix_t& prefix, const path& p);
211 ip_route(const ip_route& r);
214 * Construct a route in the given route domain
216 ip_route(const route_domain& rd, const prefix_t& prefix);
219 * Construct a route in the given route domain with a path
221 ip_route(const route_domain& rd, const prefix_t& prefix, const path& p);
229 * Get the route's key
231 const key_t key() const;
234 * Comparison operator
236 bool operator==(const ip_route& i) const;
239 * Return the matching 'singular instance'
241 std::shared_ptr<ip_route> singular() const;
246 void add(const path& path);
251 void remove(const path& path);
254 * Find the instnace of the route domain in the OM
256 static std::shared_ptr<ip_route> find(const ip_route& temp);
259 * Dump all route-doamin into the stream provided
261 static void dump(std::ostream& os);
264 * replay the object to create it in hardware
269 * Convert to string for debugging
271 std::string to_string() const;
274 * Return the matching 'singular instance'
276 static std::shared_ptr<ip_route> find(const key_t& k);
280 * Class definition for listeners to OM events
282 class event_handler : public OM::listener, public inspect::command_handler
286 virtual ~event_handler() = default;
289 * Handle a populate event
291 void handle_populate(const client_db::key_t& key);
294 * Handle a replay event
296 void handle_replay();
299 * Show the object in the Singular DB
301 void show(std::ostream& os);
304 * Get the sortable Id of the listener
306 dependency_t order() const;
310 * event_handler to register with OM
312 static event_handler m_evh;
315 * Find or add the instnace of the route domain in the OM
317 static std::shared_ptr<ip_route> find_or_add(const ip_route& temp);
320 * It's the OM class that updates the objects in HW
322 friend class VOM::OM;
325 * It's the singular_db class that calls replay()
327 friend class singular_db<key_t, ip_route>;
330 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
332 void update(const ip_route& obj);
335 * Sweep/reap the object if still stale
340 * HW configuration for the result of creating the route
345 * The route domain the route is in.
347 std::shared_ptr<route_domain> m_rd;
350 * The prefix to match
360 * A map of all routes
362 static singular_db<key_t, ip_route> m_db;
365 std::ostream& operator<<(std::ostream& os, const ip_route::key_t& key);
370 * fd.io coding-style-patch-verification: ON
373 * eval: (c-set-style "mozilla")