diff options
author | 2018-05-01 05:17:55 -0700 | |
---|---|---|
committer | 2019-06-18 13:31:39 +0000 | |
commit | 097fa66b986f06281f603767d321ab13ab6c88c3 (patch) | |
tree | ed052819615d08ee4bd0afbc34de7e64e4598105 /extras/vom/vom/route_api_types.cpp | |
parent | 39baa32186fd3e4b20d9f58afbbfe7b8daebed62 (diff) |
fib: fib api updates
Enhance the route add/del APIs to take a set of paths rather than just one.
Most unicast routing protocols calcualte all the available paths in one
run of the algorithm so updating all the paths at once is beneficial for the client.
two knobs control the behaviour:
is_multipath - if set the the set of paths passed will be added to those
that already exist, otherwise the set will replace them.
is_add - add or remove the set
is_add=0, is_multipath=1 and an empty set, results in deleting the route.
It is also considerably faster to add multiple paths at once, than one at a time:
vat# ip_add_del_route 1.1.1.1/32 count 100000 multipath via 10.10.10.11
100000 routes in .572240 secs, 174751.80 routes/sec
vat# ip_add_del_route 1.1.1.1/32 count 100000 multipath via 10.10.10.12
100000 routes in .528383 secs, 189256.54 routes/sec
vat# ip_add_del_route 1.1.1.1/32 count 100000 multipath via 10.10.10.13
100000 routes in .757131 secs, 132077.52 routes/sec
vat# ip_add_del_route 1.1.1.1/32 count 100000 multipath via 10.10.10.14
100000 routes in .878317 secs, 113854.12 routes/sec
vat# ip_route_add_del 1.1.1.1/32 count 100000 multipath via 10.10.10.11 via 10.10.10.12 via 10.10.10.13 via 10.10.10.14
100000 routes in .900212 secs, 111084.93 routes/sec
Change-Id: I416b93f7684745099c1adb0b33edac58c9339c1a
Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
Signed-off-by: Ole Troan <ot@cisco.com>
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'extras/vom/vom/route_api_types.cpp')
-rw-r--r-- | extras/vom/vom/route_api_types.cpp | 164 |
1 files changed, 87 insertions, 77 deletions
diff --git a/extras/vom/vom/route_api_types.cpp b/extras/vom/vom/route_api_types.cpp index d2234796beb..31acc84b6fb 100644 --- a/extras/vom/vom/route_api_types.cpp +++ b/extras/vom/vom/route_api_types.cpp @@ -13,111 +13,121 @@ * limitations under the License. */ +#include <vom/api_types.hpp> #include <vom/route.hpp> #include <vom/route_api_types.hpp> namespace VOM { +const route::itf_flags_t& +from_api(vapi_enum_mfib_itf_flags val) +{ + if (route::itf_flags_t::ACCEPT == val) + return route::itf_flags_t::ACCEPT; + else + return route::itf_flags_t::FORWARD; +} + +vapi_enum_mfib_itf_flags +to_api(const route::itf_flags_t& in) +{ + vapi_enum_mfib_itf_flags out = MFIB_API_ITF_FLAG_NONE; + + if (route::itf_flags_t::ACCEPT & in) + out = static_cast<vapi_enum_mfib_itf_flags>(out | MFIB_API_ITF_FLAG_ACCEPT); + if (route::itf_flags_t::FORWARD & in) + out = + static_cast<vapi_enum_mfib_itf_flags>(out | MFIB_API_ITF_FLAG_FORWARD); + + return (out); +} + void -to_vpp(const route::path& p, vapi_payload_ip_add_del_route& payload) +to_api(const route::path& p, vapi_type_fib_path& payload) { - payload.is_drop = 0; - payload.is_unreach = 0; - payload.is_prohibit = 0; - payload.is_local = 0; - payload.is_classify = 0; - payload.is_resolve_host = 0; - payload.is_resolve_attached = 0; + payload.flags = FIB_API_PATH_FLAG_NONE; + payload.proto = to_api(p.nh_proto()); + payload.sw_if_index = ~0; if (route::path::flags_t::DVR & p.flags()) { - payload.is_dvr = 1; - } - - if (route::path::special_t::STANDARD == p.type()) { - uint8_t path_v6; - to_bytes(p.nh(), &path_v6, payload.next_hop_address); - payload.next_hop_sw_if_index = 0xffffffff; + payload.type = FIB_API_PATH_TYPE_DVR; + } else if (route::path::special_t::STANDARD == p.type()) { + to_api(p.nh(), payload.nh.address); if (p.rd()) { - payload.next_hop_table_id = p.rd()->table_id(); + payload.table_id = p.rd()->table_id(); } if (p.itf()) { - payload.next_hop_sw_if_index = p.itf()->handle().value(); + payload.sw_if_index = p.itf()->handle().value(); } } else if (route::path::special_t::DROP == p.type()) { - payload.is_drop = 1; + payload.type = FIB_API_PATH_TYPE_DROP; } else if (route::path::special_t::UNREACH == p.type()) { - payload.is_unreach = 1; + payload.type = FIB_API_PATH_TYPE_ICMP_UNREACH; } else if (route::path::special_t::PROHIBIT == p.type()) { - payload.is_prohibit = 1; + payload.type = FIB_API_PATH_TYPE_ICMP_PROHIBIT; } else if (route::path::special_t::LOCAL == p.type()) { - payload.is_local = 1; + payload.type = FIB_API_PATH_TYPE_LOCAL; } - payload.next_hop_weight = p.weight(); - payload.next_hop_preference = p.preference(); - payload.next_hop_via_label = 0x100000; - payload.classify_table_index = 0; + + payload.weight = p.weight(); + payload.preference = p.preference(); + payload.n_labels = 0; } -void -to_vpp(const route::path& p, vapi_payload_ip_mroute_add_del& payload) +route::path +from_api(const vapi_type_fib_path& p) { - payload.next_hop_afi = p.nh_proto(); - - if (route::path::special_t::STANDARD == p.type()) { - uint8_t path_v6; - to_bytes(p.nh(), &path_v6, payload.nh_address); + switch (p.type) { + case FIB_API_PATH_TYPE_DVR: { + std::shared_ptr<interface> itf = interface::find(p.sw_if_index); + if (!itf) + throw invalid_decode("fib-path deocde no interface:" + + std::to_string(p.sw_if_index)); - if (p.itf()) { - payload.next_hop_sw_if_index = p.itf()->handle().value(); + return (route::path(*itf, from_api(p.proto), route::path::flags_t::DVR, + p.weight, p.preference)); } + case FIB_API_PATH_TYPE_NORMAL: { + boost::asio::ip::address address = from_api(p.nh.address, p.proto); + std::shared_ptr<interface> itf = interface::find(p.sw_if_index); + if (itf) { + return (route::path(address, *itf, p.weight, p.preference)); + } else { + std::shared_ptr<route_domain> rd = route_domain::find(p.table_id); - payload.next_hop_afi = p.nh_proto(); - } else if (route::path::special_t::LOCAL == p.type()) { - payload.is_local = 1; - } -} + if (!rd) + throw invalid_decode("fib-path deocde no route-domain:" + + std::to_string(p.table_id)); -route::path -from_vpp(const vapi_type_fib_path& p, const nh_proto_t& nhp) -{ - if (p.is_local) { - return route::path(route::path::special_t::LOCAL); - } else if (p.is_drop) { - return route::path(route::path::special_t::DROP); - } else if (p.is_unreach) { - return route::path(route::path::special_t::UNREACH); - } else if (p.is_prohibit) { - return route::path(route::path::special_t::PROHIBIT); - } else { - boost::asio::ip::address address = - from_bytes(nh_proto_t::IPV6 == nhp, p.next_hop); - std::shared_ptr<interface> itf = interface::find(p.sw_if_index); - if (itf) { - if (p.is_dvr) { - return route::path(*itf, nhp, route::path::flags_t::DVR, p.weight, - p.preference); - } else { - return route::path(address, *itf, p.weight, p.preference); - } - } else { - std::shared_ptr<route_domain> rd = route_domain::find(p.table_id); - if (rd) { - return route::path(*rd, address, p.weight, p.preference); + return (route::path(*rd, address, p.weight, p.preference)); } } - } - - VOM_LOG(log_level_t::ERROR) << "cannot decode: "; + case FIB_API_PATH_TYPE_LOCAL: + return (route::path(route::path::special_t::LOCAL)); + case FIB_API_PATH_TYPE_DROP: + return (route::path(route::path::special_t::DROP)); + case FIB_API_PATH_TYPE_ICMP_UNREACH: + return (route::path(route::path::special_t::PROHIBIT)); + case FIB_API_PATH_TYPE_ICMP_PROHIBIT: + return (route::path(route::path::special_t::UNREACH)); - return route::path(route::path::special_t::DROP); -} + case FIB_API_PATH_TYPE_UDP_ENCAP: + case FIB_API_PATH_TYPE_BIER_IMP: + case FIB_API_PATH_TYPE_SOURCE_LOOKUP: + case FIB_API_PATH_TYPE_INTERFACE_RX: + case FIB_API_PATH_TYPE_CLASSIFY: + // not done yet + break; + } + return (route::path(route::path::special_t::DROP)); }; -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "mozilla") - * End: - */ +}; // namespace VOM + /* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "mozilla") + * End: + */ |