diff --git a/orchagent/p4orch/tests/Makefile.am b/orchagent/p4orch/tests/Makefile.am index d541bbe637..4aeb07f1ae 100644 --- a/orchagent/p4orch/tests/Makefile.am +++ b/orchagent/p4orch/tests/Makefile.am @@ -23,8 +23,8 @@ CFLAGS_TSAN = -fsanitize=thread CFLAGS_USAN = -fsanitize=undefined p4orch_tests_SOURCES = $(ORCHAGENT_DIR)/orch.cpp \ - $(ORCHAGENT_DIR)/vrforch.cpp \ $(ORCHAGENT_DIR)/vxlanorch.cpp \ + $(ORCHAGENT_DIR)/vrforch.cpp \ $(ORCHAGENT_DIR)/copporch.cpp \ $(ORCHAGENT_DIR)/switch/switch_capabilities.cpp \ $(ORCHAGENT_DIR)/switch/switch_helper.cpp \ @@ -52,6 +52,7 @@ p4orch_tests_SOURCES = $(ORCHAGENT_DIR)/orch.cpp \ $(P4ORCH_DIR)/l3_admit_manager.cpp \ $(P4ORCH_DIR)/ext_tables_manager.cpp \ $(top_srcdir)/tests/mock_tests/fake_response_publisher.cpp \ + fake_routeorch.cpp \ fake_portorch.cpp \ fake_crmorch.cpp \ fake_flexcounterorch.cpp \ diff --git a/orchagent/p4orch/tests/fake_routeorch.cpp b/orchagent/p4orch/tests/fake_routeorch.cpp new file mode 100644 index 0000000000..74d7c3de8e --- /dev/null +++ b/orchagent/p4orch/tests/fake_routeorch.cpp @@ -0,0 +1,232 @@ +extern "C" +{ +#include "sai.h" +} +#include +#include "routeorch.h" +#include "nhgorch.h" + +/* Default maximum number of next hop groups */ +#define DEFAULT_NUMBER_OF_ECMP_GROUPS 128 +#define DEFAULT_MAX_ECMP_GROUP_SIZE 32 + +extern sai_object_id_t gVirtualRouterId; +extern sai_object_id_t gSwitchId; + +extern sai_next_hop_group_api_t* sai_next_hop_group_api; +extern sai_route_api_t* sai_route_api; +extern sai_mpls_api_t* sai_mpls_api; +extern sai_switch_api_t* sai_switch_api; +extern size_t gMaxBulkSize; + +RouteOrch::RouteOrch(DBConnector *db, vector &tableNames, SwitchOrch *switchOrch, NeighOrch *neighOrch, IntfsOrch *intfsOrch, VRFOrch *vrfOrch, FgNhgOrch *fgNhgOrch, Srv6Orch *srv6Orch) : + gRouteBulker(sai_route_api, gMaxBulkSize), + gLabelRouteBulker(sai_mpls_api, gMaxBulkSize), + gNextHopGroupMemberBulker(sai_next_hop_group_api, gSwitchId, gMaxBulkSize), + Orch(db, tableNames) +{ + +} + +std::string RouteOrch::getLinkLocalEui64Addr(const MacAddress &mac) +{ + SWSS_LOG_ENTER(); + + string ip_prefix; + const uint8_t *gmac = mac.getMac(); + + uint8_t eui64_interface_id[EUI64_INTF_ID_LEN]; + char ipv6_ll_addr[INET6_ADDRSTRLEN] = {0}; + + /* Link-local IPv6 address autogenerated by kernel with eui64 interface-id + * derived from the MAC address of the host interface. + */ + eui64_interface_id[0] = gmac[0] ^ 0x02; + eui64_interface_id[1] = gmac[1]; + eui64_interface_id[2] = gmac[2]; + eui64_interface_id[3] = 0xff; + eui64_interface_id[4] = 0xfe; + eui64_interface_id[5] = gmac[3]; + eui64_interface_id[6] = gmac[4]; + eui64_interface_id[7] = gmac[5]; + + snprintf(ipv6_ll_addr, INET6_ADDRSTRLEN, "fe80::%02x%02x:%02x%02x:%02x%02x:%02x%02x", + eui64_interface_id[0], eui64_interface_id[1], eui64_interface_id[2], + eui64_interface_id[3], eui64_interface_id[4], eui64_interface_id[5], + eui64_interface_id[6], eui64_interface_id[7]); + + ip_prefix = string(ipv6_ll_addr); + + return ip_prefix; +} + +void RouteOrch::addLinkLocalRouteToMe(sai_object_id_t vrf_id, IpPrefix linklocal_prefix) +{ + +} + +void RouteOrch::delLinkLocalRouteToMe(sai_object_id_t vrf_id, IpPrefix linklocal_prefix) +{ + +} + +void RouteOrch::updateDefRouteState(string ip, bool add) +{ +} + +bool RouteOrch::hasNextHopGroup(const NextHopGroupKey& nexthops) const +{ + return true; +} + +void RouteOrch::attach(Observer *observer, const IpAddress& dstAddr, sai_object_id_t vrf_id) +{ +} + +void RouteOrch::detach(Observer *observer, const IpAddress& dstAddr, sai_object_id_t vrf_id) +{ + +} + +bool RouteOrch::validnexthopinNextHopGroup(const NextHopKey &nexthop, uint32_t& count) +{ + return true; +} + +bool RouteOrch::invalidnexthopinNextHopGroup(const NextHopKey &nexthop, uint32_t& count) +{ + return true; +} + +void RouteOrch::doTask(Consumer& consumer) +{ + +} + +void RouteOrch::notifyNextHopChangeObservers(sai_object_id_t vrf_id, const IpPrefix &prefix, const NextHopGroupKey &nexthops, bool add) +{ + +} + +void RouteOrch::increaseNextHopRefCount(const NextHopGroupKey &nexthops) +{ + +} + +void RouteOrch::decreaseNextHopRefCount(const NextHopGroupKey &nexthops) +{ + +} + +bool RouteOrch::isRefCounterZero(const NextHopGroupKey &nexthops) const +{ + return true; +} + +bool RouteOrch::createFineGrainedNextHopGroup(sai_object_id_t &next_hop_group_id, vector &nhg_attrs) +{ + return true; +} + +bool RouteOrch::removeFineGrainedNextHopGroup(sai_object_id_t &next_hop_group_id) +{ + return true; +} + +bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) +{ + return true; +} + +bool RouteOrch::removeNextHopGroup(const NextHopGroupKey &nexthops) +{ + return true; +} + +void RouteOrch::addNextHopRoute(const NextHopKey& nextHop, const RouteKey& routeKey) +{ + +} + +void RouteOrch::removeNextHopRoute(const NextHopKey& nextHop, const RouteKey& routeKey) +{ + +} + +bool RouteOrch::updateNextHopRoutes(const NextHopKey& nextHop, uint32_t& numRoutes) +{ + return true; +} + +bool RouteOrch::getRoutesForNexthop(std::set& routeKeys, const NextHopKey& nexthopKey) +{ + return true; +} + +void RouteOrch::addTempRoute(RouteBulkContext& ctx, const NextHopGroupKey &nextHops) +{ + +} + +bool RouteOrch::addRoute(RouteBulkContext& ctx, const NextHopGroupKey &nextHops) +{ + return true; +} + +bool RouteOrch::addRoutePost(const RouteBulkContext& ctx, const NextHopGroupKey &nextHops) +{ + return true; +} + +bool RouteOrch::removeRoute(RouteBulkContext& ctx) +{ + return true; +} + +bool RouteOrch::removeRoutePost(const RouteBulkContext& ctx) +{ + return true; +} + +bool RouteOrch::createRemoteVtep(sai_object_id_t vrf_id, const NextHopKey &nextHop) +{ + return true; +} + +bool RouteOrch::deleteRemoteVtep(sai_object_id_t vrf_id, const NextHopKey &nextHop) +{ + return true; +} + +bool RouteOrch::removeOverlayNextHops(sai_object_id_t vrf_id, const NextHopGroupKey &ol_nextHops) +{ + return true; +} + +void RouteOrch::increaseNextHopGroupCount() +{ +} + +void RouteOrch::decreaseNextHopGroupCount() +{ +} + +bool RouteOrch::checkNextHopGroupCount() +{ + return true; +} + + +void RouteOrch::incNhgRefCount(const std::string &nhg_index) +{ +} + +void RouteOrch::decNhgRefCount(const std::string &nhg_index) +{ + +} + +void RouteOrch::publishRouteState(const RouteBulkContext& ctx, const ReturnCode& status) +{ + +} diff --git a/orchagent/p4orch/tests/test_main.cpp b/orchagent/p4orch/tests/test_main.cpp index 787e0622f4..3805f216bd 100644 --- a/orchagent/p4orch/tests/test_main.cpp +++ b/orchagent/p4orch/tests/test_main.cpp @@ -15,6 +15,7 @@ extern "C" #include "mock_sai_virtual_router.h" #include "p4orch.h" #include "portsorch.h" +#include "routeorch.h" #include "sai_serialize.h" #include "switchorch.h" #include "vrforch.h" @@ -47,6 +48,7 @@ PortsOrch *gPortsOrch; CrmOrch *gCrmOrch; P4Orch *gP4Orch; VRFOrch *gVrfOrch; +RouteOrch *gRouteOrch; FlowCounterRouteOrch *gFlowCounterRouteOrch; SwitchOrch *gSwitchOrch; Directory gDirectory; @@ -55,12 +57,14 @@ swss::DBConnector *gStateDb; swss::DBConnector *gConfigDb; swss::DBConnector *gCountersDb; MacAddress gVxlanMacAddress; +MacAddress gMacAddress; sai_router_interface_api_t *sai_router_intfs_api; sai_neighbor_api_t *sai_neighbor_api; sai_next_hop_api_t *sai_next_hop_api; sai_next_hop_group_api_t *sai_next_hop_group_api; sai_route_api_t *sai_route_api; +sai_mpls_api_t *sai_mpls_api; sai_acl_api_t *sai_acl_api; sai_policer_api_t *sai_policer_api; sai_virtual_router_api_t *sai_virtual_router_api; @@ -182,6 +186,7 @@ int main(int argc, char *argv[]) sai_next_hop_api_t next_hop_api; sai_next_hop_group_api_t next_hop_group_api; sai_route_api_t route_api; + sai_mpls_api_t mpls_api; sai_acl_api_t acl_api; sai_policer_api_t policer_api; sai_virtual_router_api_t virtual_router_api; @@ -199,6 +204,7 @@ int main(int argc, char *argv[]) sai_next_hop_api = &next_hop_api; sai_next_hop_group_api = &next_hop_group_api; sai_route_api = &route_api; + sai_mpls_api = &mpls_api; sai_acl_api = &acl_api; sai_policer_api = &policer_api; sai_virtual_router_api = &virtual_router_api; @@ -228,6 +234,13 @@ int main(int argc, char *argv[]) gCrmOrch = &crm_orch; VRFOrch vrf_orch(gAppDb, APP_VRF_TABLE_NAME, gStateDb, STATE_VRF_OBJECT_TABLE_NAME); gVrfOrch = &vrf_orch; + const int routeorch_pri = 5; + vector route_tables = { + { APP_ROUTE_TABLE_NAME, routeorch_pri }, + { APP_LABEL_ROUTE_TABLE_NAME, routeorch_pri } + }; + RouteOrch route_orch(gAppDb, route_tables, NULL, NULL, NULL, NULL, NULL, NULL); + gRouteOrch = &route_orch; gDirectory.set(static_cast(&vrf_orch)); FlowCounterRouteOrch flow_counter_route_orch(gConfigDb, std::vector{});