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 | #include "vom/route.hpp" |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 17 | #include "vom/route_cmds.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 18 | #include "vom/singular_db.hpp" |
| 19 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 20 | namespace VOM { |
| 21 | namespace route { |
Neale Ranns | 10e7a9f | 2017-11-14 08:40:43 -0800 | [diff] [blame] | 22 | ip_route::event_handler ip_route::m_evh; |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 23 | singular_db<ip_route::key_t, ip_route> ip_route::m_db; |
| 24 | |
| 25 | const path::special_t path::special_t::STANDARD(0, "standard"); |
| 26 | const path::special_t path::special_t::LOCAL(0, "local"); |
| 27 | const path::special_t path::special_t::DROP(0, "standard"); |
| 28 | const path::special_t path::special_t::UNREACH(0, "unreachable"); |
| 29 | const path::special_t path::special_t::PROHIBIT(0, "prohibit"); |
| 30 | |
| 31 | path::special_t::special_t(int v, const std::string& s) |
| 32 | : enum_base<path::special_t>(v, s) |
| 33 | { |
| 34 | } |
| 35 | |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 36 | const path::flags_t path::flags_t::NONE(0, "none"); |
| 37 | const path::flags_t path::flags_t::DVR((1 << 0), "dvr"); |
| 38 | |
| 39 | path::flags_t::flags_t(int v, const std::string& s) |
| 40 | : enum_base<path::flags_t>(v, s) |
| 41 | { |
| 42 | } |
| 43 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 44 | path::path(special_t special) |
| 45 | : m_type(special) |
| 46 | , m_nh_proto(nh_proto_t::IPV4) |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 47 | , m_flags(flags_t::NONE) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 48 | , m_nh() |
| 49 | , m_rd(nullptr) |
| 50 | , m_interface(nullptr) |
| 51 | , m_weight(1) |
| 52 | , m_preference(0) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | path::path(const boost::asio::ip::address& nh, |
| 57 | const interface& interface, |
| 58 | uint8_t weight, |
| 59 | uint8_t preference) |
| 60 | : m_type(special_t::STANDARD) |
| 61 | , m_nh_proto(nh_proto_t::from_address(nh)) |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 62 | , m_flags(flags_t::NONE) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 63 | , m_nh(nh) |
| 64 | , m_rd(nullptr) |
| 65 | , m_interface(interface.singular()) |
| 66 | , m_weight(weight) |
| 67 | , m_preference(preference) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | path::path(const route_domain& rd, |
| 72 | const boost::asio::ip::address& nh, |
| 73 | uint8_t weight, |
| 74 | uint8_t preference) |
| 75 | : m_type(special_t::STANDARD) |
| 76 | , m_nh_proto(nh_proto_t::from_address(nh)) |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 77 | , m_flags(flags_t::NONE) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 78 | , m_nh(nh) |
| 79 | , m_rd(rd.singular()) |
| 80 | , m_interface(nullptr) |
| 81 | , m_weight(weight) |
| 82 | , m_preference(preference) |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | path::path(const interface& interface, |
| 87 | const nh_proto_t& proto, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 88 | const flags_t& flags, |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 89 | uint8_t weight, |
| 90 | uint8_t preference) |
| 91 | : m_type(special_t::STANDARD) |
| 92 | , m_nh_proto(proto) |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 93 | , m_flags(flags) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 94 | , m_nh() |
| 95 | , m_rd(nullptr) |
| 96 | , m_interface(interface.singular()) |
| 97 | , m_weight(weight) |
| 98 | , m_preference(preference) |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | path::path(const path& p) |
| 103 | : m_type(p.m_type) |
| 104 | , m_nh_proto(p.m_nh_proto) |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 105 | , m_flags(p.m_flags) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 106 | , m_nh(p.m_nh) |
| 107 | , m_rd(p.m_rd) |
| 108 | , m_interface(p.m_interface) |
| 109 | , m_weight(p.m_weight) |
| 110 | , m_preference(p.m_preference) |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | bool |
| 115 | path::operator<(const path& p) const |
| 116 | { |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 117 | if (m_nh_proto < p.m_nh_proto) |
| 118 | return true; |
| 119 | if (m_flags < p.m_flags) |
| 120 | return true; |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 121 | if (m_type < p.m_type) |
| 122 | return true; |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 123 | if (m_rd && !p.m_rd) |
| 124 | return false; |
| 125 | if (!m_rd && p.m_rd) |
| 126 | return true; |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 127 | if (m_rd->table_id() < p.m_rd->table_id()) |
| 128 | return true; |
| 129 | if (m_nh < p.m_nh) |
| 130 | return true; |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 131 | if (m_interface && !p.m_interface) |
| 132 | return false; |
| 133 | if (!m_interface && p.m_interface) |
| 134 | return true; |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 135 | if (m_interface->handle() < p.m_interface->handle()) |
| 136 | return true; |
| 137 | |
| 138 | return (false); |
| 139 | } |
| 140 | |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 141 | path::~path() |
| 142 | { |
| 143 | } |
| 144 | |
| 145 | bool |
| 146 | path::operator==(const path& p) const |
| 147 | { |
| 148 | bool result = true; |
| 149 | if (m_rd && !p.m_rd) |
| 150 | return false; |
| 151 | if (!m_rd && p.m_rd) |
| 152 | return false; |
| 153 | if (m_rd && p.m_rd) |
| 154 | result &= (*m_rd == *p.m_rd); |
| 155 | if (m_interface && !p.m_interface) |
| 156 | return false; |
| 157 | if (!m_interface && p.m_interface) |
| 158 | return false; |
| 159 | if (m_interface && p.m_interface) |
| 160 | result &= (*m_interface == *p.m_interface); |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 161 | return (result && (m_type == p.m_type) && (m_nh == p.m_nh) && |
| 162 | (m_nh_proto == p.m_nh_proto) && (m_flags == p.m_flags)); |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 165 | std::string |
| 166 | path::to_string() const |
| 167 | { |
| 168 | std::ostringstream s; |
| 169 | |
| 170 | s << "path:[" |
| 171 | << "type:" << m_type.to_string() << " proto:" << m_nh_proto.to_string() |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 172 | << " flags:" << m_flags.to_string() << " neighbour:" << m_nh.to_string(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 173 | if (m_rd) { |
| 174 | s << " " << m_rd->to_string(); |
| 175 | } |
| 176 | if (m_interface) { |
| 177 | s << " " << m_interface->to_string(); |
| 178 | } |
| 179 | s << " weight:" << static_cast<int>(m_weight) |
| 180 | << " preference:" << static_cast<int>(m_preference) << "]"; |
| 181 | |
| 182 | return (s.str()); |
| 183 | } |
| 184 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 185 | path::special_t |
| 186 | path::type() const |
| 187 | { |
| 188 | return m_type; |
| 189 | } |
| 190 | |
| 191 | nh_proto_t |
| 192 | path::nh_proto() const |
| 193 | { |
| 194 | return m_nh_proto; |
| 195 | } |
| 196 | |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 197 | path::flags_t |
| 198 | path::flags() const |
| 199 | { |
| 200 | return m_flags; |
| 201 | } |
| 202 | |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 203 | const boost::asio::ip::address& |
| 204 | path::nh() const |
| 205 | { |
| 206 | return m_nh; |
| 207 | } |
| 208 | |
| 209 | std::shared_ptr<route_domain> |
| 210 | path::rd() const |
| 211 | { |
| 212 | return m_rd; |
| 213 | } |
| 214 | |
| 215 | std::shared_ptr<interface> |
| 216 | path::itf() const |
| 217 | { |
| 218 | return m_interface; |
| 219 | } |
| 220 | |
| 221 | uint8_t |
| 222 | path::weight() const |
| 223 | { |
| 224 | return m_weight; |
| 225 | } |
| 226 | |
| 227 | uint8_t |
| 228 | path::preference() const |
| 229 | { |
| 230 | return m_preference; |
| 231 | } |
| 232 | |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 233 | ip_route::ip_route(const prefix_t& prefix, const path& p) |
| 234 | : m_hw(false) |
| 235 | , m_rd(route_domain::get_default()) |
| 236 | , m_prefix(prefix) |
| 237 | , m_paths({ p }) |
| 238 | { |
| 239 | } |
| 240 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 241 | ip_route::ip_route(const prefix_t& prefix) |
| 242 | : m_hw(false) |
| 243 | , m_rd(route_domain::get_default()) |
| 244 | , m_prefix(prefix) |
| 245 | , m_paths() |
| 246 | { |
| 247 | } |
| 248 | |
| 249 | ip_route::ip_route(const ip_route& r) |
| 250 | : m_hw(r.m_hw) |
| 251 | , m_rd(r.m_rd) |
| 252 | , m_prefix(r.m_prefix) |
| 253 | , m_paths(r.m_paths) |
| 254 | { |
| 255 | } |
| 256 | |
| 257 | ip_route::ip_route(const route_domain& rd, const prefix_t& prefix) |
| 258 | : m_hw(false) |
| 259 | , m_rd(rd.singular()) |
| 260 | , m_prefix(prefix) |
| 261 | , m_paths() |
| 262 | { |
| 263 | } |
| 264 | |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 265 | ip_route::ip_route(const route_domain& rd, |
| 266 | const prefix_t& prefix, |
| 267 | const path& p) |
| 268 | : m_hw(false) |
| 269 | , m_rd(rd.singular()) |
| 270 | , m_prefix(prefix) |
| 271 | , m_paths({ p }) |
| 272 | { |
| 273 | } |
| 274 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 275 | ip_route::~ip_route() |
| 276 | { |
| 277 | sweep(); |
| 278 | |
| 279 | // not in the DB anymore. |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 280 | m_db.release(key(), this); |
| 281 | m_paths.clear(); |
| 282 | } |
| 283 | |
| 284 | const ip_route::key_t |
| 285 | ip_route::key() const |
| 286 | { |
| 287 | return (std::make_pair(m_rd->table_id(), m_prefix)); |
| 288 | } |
| 289 | |
| 290 | bool |
| 291 | ip_route::operator==(const ip_route& i) const |
| 292 | { |
| 293 | return ((key() == i.key()) && (m_paths == i.m_paths)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void |
| 297 | ip_route::add(const path& path) |
| 298 | { |
| 299 | m_paths.insert(path); |
| 300 | } |
| 301 | |
| 302 | void |
| 303 | ip_route::remove(const path& path) |
| 304 | { |
| 305 | m_paths.erase(path); |
| 306 | } |
| 307 | |
| 308 | void |
| 309 | ip_route::sweep() |
| 310 | { |
| 311 | if (m_hw) { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 312 | HW::enqueue( |
| 313 | new ip_route_cmds::delete_cmd(m_hw, m_rd->table_id(), m_prefix)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 314 | } |
| 315 | HW::write(); |
| 316 | } |
| 317 | |
| 318 | void |
| 319 | ip_route::replay() |
| 320 | { |
| 321 | if (m_hw) { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 322 | HW::enqueue( |
| 323 | new ip_route_cmds::update_cmd(m_hw, m_rd->table_id(), m_prefix, m_paths)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | std::string |
| 327 | ip_route::to_string() const |
| 328 | { |
| 329 | std::ostringstream s; |
| 330 | s << "route:[" << m_rd->to_string() << ", " << m_prefix.to_string() << " [" |
| 331 | << m_paths << "]" |
| 332 | << "]"; |
| 333 | |
| 334 | return (s.str()); |
| 335 | } |
| 336 | |
| 337 | void |
| 338 | ip_route::update(const ip_route& r) |
| 339 | { |
| 340 | /* |
| 341 | * create the table if it is not yet created |
| 342 | */ |
| 343 | if (rc_t::OK != m_hw.rc()) { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 344 | HW::enqueue( |
| 345 | new ip_route_cmds::update_cmd(m_hw, m_rd->table_id(), m_prefix, m_paths)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | std::shared_ptr<ip_route> |
| 350 | ip_route::find_or_add(const ip_route& temp) |
| 351 | { |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 352 | return (m_db.find_or_add(temp.key(), temp)); |
| 353 | } |
| 354 | |
| 355 | std::shared_ptr<ip_route> |
| 356 | ip_route::find(const key_t& k) |
| 357 | { |
| 358 | return (m_db.find(k)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | std::shared_ptr<ip_route> |
| 362 | ip_route::singular() const |
| 363 | { |
| 364 | return find_or_add(*this); |
| 365 | } |
| 366 | |
| 367 | void |
| 368 | ip_route::dump(std::ostream& os) |
| 369 | { |
| 370 | m_db.dump(os); |
| 371 | } |
| 372 | |
| 373 | ip_route::event_handler::event_handler() |
| 374 | { |
| 375 | OM::register_listener(this); |
| 376 | inspect::register_handler({ "ip-route" }, "ip route configurations", this); |
| 377 | } |
| 378 | |
| 379 | void |
| 380 | ip_route::event_handler::handle_replay() |
| 381 | { |
| 382 | m_db.replay(); |
| 383 | } |
| 384 | |
| 385 | void |
| 386 | ip_route::event_handler::handle_populate(const client_db::key_t& key) |
| 387 | { |
Neale Ranns | 1d78155 | 2017-11-27 04:52:35 -0800 | [diff] [blame] | 388 | std::shared_ptr<ip_route_cmds::dump_v4_cmd> cmd_v4 = |
| 389 | std::make_shared<ip_route_cmds::dump_v4_cmd>(); |
| 390 | std::shared_ptr<ip_route_cmds::dump_v6_cmd> cmd_v6 = |
| 391 | std::make_shared<ip_route_cmds::dump_v6_cmd>(); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 392 | |
| 393 | HW::enqueue(cmd_v4); |
| 394 | HW::enqueue(cmd_v6); |
| 395 | HW::write(); |
| 396 | |
| 397 | for (auto& record : *cmd_v4) { |
| 398 | auto& payload = record.get_payload(); |
| 399 | |
| 400 | prefix_t pfx(0, payload.address, payload.address_length); |
| 401 | |
| 402 | /** |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 403 | * populating the route domain here |
| 404 | */ |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 405 | route_domain rd_temp(payload.table_id); |
Neale Ranns | 7016b00 | 2018-01-25 07:28:19 -0800 | [diff] [blame] | 406 | std::shared_ptr<route_domain> rd = route_domain::find(payload.table_id); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 407 | if (!rd) { |
| 408 | OM::commit(key, rd_temp); |
| 409 | } |
| 410 | ip_route ip_r(rd_temp, pfx); |
| 411 | |
| 412 | for (unsigned int i = 0; i < payload.count; i++) { |
| 413 | vapi_type_fib_path p = payload.path[i]; |
| 414 | if (p.is_local) { |
| 415 | path path_v4(path::special_t::LOCAL); |
| 416 | ip_r.add(path_v4); |
| 417 | } else if (p.is_drop) { |
| 418 | path path_v4(path::special_t::DROP); |
| 419 | ip_r.add(path_v4); |
| 420 | } else if (p.is_unreach) { |
| 421 | path path_v4(path::special_t::UNREACH); |
| 422 | ip_r.add(path_v4); |
| 423 | } else if (p.is_prohibit) { |
| 424 | path path_v4(path::special_t::PROHIBIT); |
| 425 | ip_r.add(path_v4); |
| 426 | } else { |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 427 | boost::asio::ip::address address = from_bytes(0, p.next_hop); |
Mohsin Kazmi | a370679 | 2018-01-12 19:11:44 +0100 | [diff] [blame] | 428 | std::shared_ptr<interface> itf = interface::find(p.sw_if_index); |
| 429 | if (itf) { |
| 430 | path path_v4(address, *itf, p.weight, p.preference); |
| 431 | ip_r.add(path_v4); |
| 432 | } else { |
| 433 | path path_v4(rd_temp, address, p.weight, p.preference); |
| 434 | ip_r.add(path_v4); |
| 435 | } |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | VOM_LOG(log_level_t::DEBUG) << "ip-route-dump: " << ip_r.to_string(); |
| 439 | |
| 440 | /* |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 441 | * Write each of the discovered interfaces into the OM, |
| 442 | * but disable the HW Command q whilst we do, so that no |
| 443 | * commands are sent to VPP |
| 444 | */ |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 445 | OM::commit(key, ip_r); |
| 446 | } |
| 447 | |
| 448 | for (auto& record : *cmd_v6) { |
| 449 | auto& payload = record.get_payload(); |
| 450 | |
| 451 | prefix_t pfx(1, payload.address, payload.address_length); |
| 452 | route_domain rd_temp(payload.table_id); |
Neale Ranns | 7016b00 | 2018-01-25 07:28:19 -0800 | [diff] [blame] | 453 | std::shared_ptr<route_domain> rd = route_domain::find(payload.table_id); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 454 | if (!rd) { |
| 455 | OM::commit(key, rd_temp); |
| 456 | } |
| 457 | ip_route ip_r(rd_temp, pfx); |
| 458 | |
| 459 | for (unsigned int i = 0; i < payload.count; i++) { |
| 460 | vapi_type_fib_path p = payload.path[i]; |
| 461 | if (p.is_local) { |
| 462 | path path_v6(path::special_t::LOCAL); |
| 463 | ip_r.add(path_v6); |
| 464 | } else if (p.is_drop) { |
| 465 | path path_v6(path::special_t::DROP); |
| 466 | ip_r.add(path_v6); |
| 467 | } else if (p.is_unreach) { |
| 468 | path path_v6(path::special_t::UNREACH); |
| 469 | ip_r.add(path_v6); |
| 470 | } else if (p.is_prohibit) { |
| 471 | path path_v6(path::special_t::PROHIBIT); |
| 472 | ip_r.add(path_v6); |
| 473 | } else { |
| 474 | std::shared_ptr<interface> itf = interface::find(p.sw_if_index); |
| 475 | boost::asio::ip::address address = from_bytes(1, p.next_hop); |
Mohsin Kazmi | a370679 | 2018-01-12 19:11:44 +0100 | [diff] [blame] | 476 | if (itf) { |
| 477 | path path_v6(address, *itf, p.weight, p.preference); |
| 478 | ip_r.add(path_v6); |
| 479 | } else { |
| 480 | path path_v6(rd_temp, address, p.weight, p.preference); |
| 481 | ip_r.add(path_v6); |
| 482 | } |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | VOM_LOG(log_level_t::DEBUG) << "ip-route-dump: " << ip_r.to_string(); |
| 486 | |
| 487 | /* |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 488 | * Write each of the discovered interfaces into the OM, |
| 489 | * but disable the HW Command q whilst we do, so that no |
| 490 | * commands are sent to VPP |
| 491 | */ |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 492 | OM::commit(key, ip_r); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | dependency_t |
| 497 | ip_route::event_handler::order() const |
| 498 | { |
Mohsin Kazmi | 18e955e | 2018-01-08 12:58:32 +0100 | [diff] [blame] | 499 | return (dependency_t::ENTRY); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | void |
| 503 | ip_route::event_handler::show(std::ostream& os) |
| 504 | { |
| 505 | m_db.dump(os); |
| 506 | } |
| 507 | |
| 508 | std::ostream& |
| 509 | operator<<(std::ostream& os, const ip_route::key_t& key) |
| 510 | { |
| 511 | os << "[" << key.first << ", " << key.second.to_string() << "]"; |
| 512 | |
| 513 | return (os); |
| 514 | } |
| 515 | |
| 516 | std::ostream& |
| 517 | operator<<(std::ostream& os, const path_list_t& key) |
| 518 | { |
| 519 | os << "["; |
| 520 | for (auto k : key) { |
| 521 | os << k.to_string() << " "; |
| 522 | } |
| 523 | os << "]"; |
| 524 | |
| 525 | return (os); |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | /* |
| 530 | * fd.io coding-style-patch-verification: ON |
| 531 | * |
| 532 | * Local Variables: |
| 533 | * eval: (c-set-style "mozilla") |
| 534 | * End: |
| 535 | */ |