Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 1 | /* |
| 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 | #ifndef __VOM_ROUTE_DOMAIN_H__ |
| 17 | #define __VOM_ROUTE_DOMAIN_H__ |
| 18 | |
Neale Ranns | 10e7a9f | 2017-11-14 08:40:43 -0800 | [diff] [blame] | 19 | #include "vom/inspect.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 20 | #include "vom/object_base.hpp" |
| 21 | #include "vom/om.hpp" |
| 22 | #include "vom/prefix.hpp" |
| 23 | #include "vom/singular_db.hpp" |
| 24 | |
| 25 | #include <vapi/ip.api.vapi.hpp> |
| 26 | |
| 27 | namespace VOM { |
| 28 | /** |
| 29 | * A route-domain is a VRF. |
| 30 | * creating a route-domain object will construct both an IPv4 |
| 31 | * and IPv6 table. |
| 32 | */ |
| 33 | class route_domain : public object_base |
| 34 | { |
| 35 | public: |
| 36 | /** |
| 37 | * The Key for a route-domain |
| 38 | */ |
| 39 | typedef route::table_id_t key_t; |
| 40 | |
| 41 | /** |
| 42 | * Construct a new object matching the desried state |
| 43 | */ |
| 44 | route_domain(route::table_id_t id); |
| 45 | |
| 46 | /** |
| 47 | * Copy Constructor |
| 48 | */ |
| 49 | route_domain(const route_domain& o); |
| 50 | |
| 51 | /** |
| 52 | * Destructor |
| 53 | */ |
| 54 | ~route_domain(); |
| 55 | |
| 56 | /** |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 57 | * comparison operator - for UT |
| 58 | */ |
| 59 | bool operator==(const route_domain& r) const; |
| 60 | |
| 61 | /** |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 62 | * Return the matching 'singular instance' |
| 63 | */ |
| 64 | std::shared_ptr<route_domain> singular() const; |
| 65 | |
| 66 | /** |
| 67 | * Debug print function |
| 68 | */ |
| 69 | std::string to_string() const; |
| 70 | |
| 71 | /** |
| 72 | * Get the table ID |
| 73 | */ |
| 74 | route::table_id_t table_id() const; |
| 75 | |
| 76 | /** |
| 77 | * Get the route-domain's key |
| 78 | */ |
| 79 | key_t key() const; |
| 80 | |
| 81 | /** |
| 82 | * Find the instnace of the route domain in the OM |
| 83 | */ |
| 84 | static std::shared_ptr<route_domain> find(const route_domain& temp); |
| 85 | |
| 86 | /** |
| 87 | * Dump all route-doamin into the stream provided |
| 88 | */ |
| 89 | static void dump(std::ostream& os); |
| 90 | |
| 91 | /** |
| 92 | * Return the sigular instance for the default table |
| 93 | */ |
| 94 | static std::shared_ptr<route_domain> get_default(); |
| 95 | |
| 96 | /** |
| 97 | * replay the object to create it in hardware |
| 98 | */ |
| 99 | void replay(void); |
| 100 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 101 | private: |
| 102 | /** |
Neale Ranns | 10e7a9f | 2017-11-14 08:40:43 -0800 | [diff] [blame] | 103 | * Class definition for listeners to OM events |
| 104 | */ |
| 105 | class event_handler : public OM::listener, public inspect::command_handler |
| 106 | { |
| 107 | public: |
| 108 | event_handler(); |
| 109 | virtual ~event_handler() = default; |
| 110 | |
| 111 | /** |
| 112 | * Handle a populate event |
| 113 | */ |
| 114 | void handle_populate(const client_db::key_t& key); |
| 115 | |
| 116 | /** |
| 117 | * Handle a replay event |
| 118 | */ |
| 119 | void handle_replay(); |
| 120 | |
| 121 | /** |
| 122 | * Show the object in the Singular DB |
| 123 | */ |
| 124 | void show(std::ostream& os); |
| 125 | |
| 126 | /** |
| 127 | * Get the sortable Id of the listener |
| 128 | */ |
| 129 | dependency_t order() const; |
| 130 | }; |
| 131 | |
| 132 | /** |
| 133 | * Instance of the event handler to register with OM |
| 134 | */ |
| 135 | static event_handler m_evh; |
| 136 | |
| 137 | /** |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 138 | * Commit the acculmulated changes into VPP. i.e. to a 'HW" write. |
| 139 | */ |
| 140 | void update(const route_domain& obj); |
| 141 | |
| 142 | /** |
| 143 | * Find or add the instnace of the route domain in the OM |
| 144 | */ |
| 145 | static std::shared_ptr<route_domain> find_or_add(const route_domain& temp); |
| 146 | |
| 147 | /* |
| 148 | * It's the OM class that updates the objects in HW |
| 149 | */ |
| 150 | friend class OM; |
| 151 | |
| 152 | /** |
| 153 | * It's the singular_db class that calls replay() |
| 154 | */ |
| 155 | friend class singular_db<route::table_id_t, route_domain>; |
| 156 | |
| 157 | /** |
| 158 | * Sweep/reap the object if still stale |
| 159 | */ |
| 160 | void sweep(void); |
| 161 | |
| 162 | /** |
| 163 | * HW configuration for the result of creating the v4 table |
| 164 | */ |
| 165 | HW::item<bool> m_hw_v4; |
| 166 | |
| 167 | /** |
| 168 | * HW configuration for the result of creating the v6 table |
| 169 | */ |
| 170 | HW::item<bool> m_hw_v6; |
| 171 | |
| 172 | /** |
| 173 | * VPP understands Table-IDs not table names. |
| 174 | * The table IDs for V4 and V6 are the same. |
| 175 | */ |
| 176 | route::table_id_t m_table_id; |
| 177 | |
| 178 | /** |
| 179 | * A map of all interfaces key against the interface's name |
| 180 | */ |
| 181 | static singular_db<route::table_id_t, route_domain> m_db; |
| 182 | }; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 183 | }; // namespace VOM |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * fd.io coding-style-patch-verification: ON |
| 187 | * |
| 188 | * Local Variables: |
| 189 | * eval: (c-set-style "mozilla") |
| 190 | * End: |
| 191 | */ |
| 192 | |
| 193 | #endif |