From 097fa66b986f06281f603767d321ab13ab6c88c3 Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Tue, 1 May 2018 05:17:55 -0700 Subject: 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 Signed-off-by: Ole Troan Signed-off-by: Paul Vinciguerra --- extras/vom/vom/api_types.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'extras/vom/vom/api_types.cpp') diff --git a/extras/vom/vom/api_types.cpp b/extras/vom/vom/api_types.cpp index ea75d7fd8ee..721034fc810 100644 --- a/extras/vom/vom/api_types.cpp +++ b/extras/vom/vom/api_types.cpp @@ -45,6 +45,11 @@ from_api(vapi_enum_ip_neighbor_flags f) return out; } +invalid_decode::invalid_decode(const std::string reason) + : reason(reason) +{ +} + void to_api(const boost::asio::ip::address_v4& a, vapi_type_ip4_address& v) { @@ -82,6 +87,16 @@ to_api(const ip_address_t& a, } } +void +to_api(const ip_address_t& a, vapi_union_address_union& u) +{ + if (a.is_v4()) { + memcpy(u.ip4, a.to_v4().to_bytes().data(), 4); + } else { + memcpy(u.ip6, a.to_v6().to_bytes().data(), 16); + } +} + boost::asio::ip::address_v6 from_api(const vapi_type_ip6_address& v) { @@ -122,6 +137,26 @@ from_api(const vapi_type_address& v) return addr; } +ip_address_t +from_api(const vapi_union_address_union& u, vapi_enum_fib_path_nh_proto proto) +{ + boost::asio::ip::address addr; + + if (FIB_API_PATH_NH_PROTO_IP6 == proto) { + std::array a; + std::copy(u.ip6, u.ip6 + 16, std::begin(a)); + boost::asio::ip::address_v6 v6(a); + addr = v6; + } else if (FIB_API_PATH_NH_PROTO_IP4 == proto) { + std::array a; + std::copy(u.ip6, u.ip6 + 4, std::begin(a)); + boost::asio::ip::address_v4 v4(a); + addr = v4; + } + + return addr; +} + ip_address_t from_api(const vapi_union_address_union& u, vapi_enum_address_family af) { @@ -187,7 +222,42 @@ to_api(const route::mprefix_t& p) v.af = af; return v; } -}; + +vapi_enum_fib_path_nh_proto +to_api(const nh_proto_t& p) +{ + if (p == nh_proto_t::IPV4) { + return FIB_API_PATH_NH_PROTO_IP4; + } else if (p == nh_proto_t::IPV6) { + return FIB_API_PATH_NH_PROTO_IP6; + } else if (p == nh_proto_t::ETHERNET) { + return FIB_API_PATH_NH_PROTO_ETHERNET; + } else if (p == nh_proto_t::MPLS) { + return FIB_API_PATH_NH_PROTO_MPLS; + } + + return FIB_API_PATH_NH_PROTO_IP4; +} +const nh_proto_t& +from_api(vapi_enum_fib_path_nh_proto p) +{ + switch (p) { + case FIB_API_PATH_NH_PROTO_IP4: + return nh_proto_t::IPV4; + case FIB_API_PATH_NH_PROTO_IP6: + return nh_proto_t::IPV6; + case FIB_API_PATH_NH_PROTO_ETHERNET: + return nh_proto_t::ETHERNET; + case FIB_API_PATH_NH_PROTO_MPLS: + return nh_proto_t::MPLS; + case FIB_API_PATH_NH_PROTO_BIER: + break; + } + + return nh_proto_t::IPV4; +} + +}; // VOM /* * fd.io coding-style-patch-verification: ON -- cgit 1.2.3-korg