diff --git a/src/vnsw/agent/oper/test/SConscript b/src/vnsw/agent/oper/test/SConscript index 716d85a82cb..dd27613f58f 100644 --- a/src/vnsw/agent/oper/test/SConscript +++ b/src/vnsw/agent/oper/test/SConscript @@ -25,6 +25,8 @@ oper_flaky_test_suite = [] test_agent_sandesh = AgentEnv.MakeTestCmd(env, 'test_agent_sandesh', oper_test_suite) test_config_manager = AgentEnv.MakeTestCmd(env, 'test_config_manager', oper_test_suite) test_intf = AgentEnv.MakeTestCmd(env, 'test_intf', oper_test_suite) +test_intf_policy = AgentEnv.MakeTestCmd(env, 'test_intf_policy', + oper_test_suite) test_find_scale = AgentEnv.MakeTestCmd(env, 'test_find_scale', oper_test_suite) test_logical_intf = AgentEnv.MakeTestCmd(env, 'test_logical_intf', oper_test_suite) test_vrf_assign = AgentEnv.MakeTestCmd(env, 'test_vrf_assign', oper_test_suite) diff --git a/src/vnsw/agent/oper/test/test_intf_policy.cc b/src/vnsw/agent/oper/test/test_intf_policy.cc new file mode 100644 index 00000000000..ba2d92597e3 --- /dev/null +++ b/src/vnsw/agent/oper/test/test_intf_policy.cc @@ -0,0 +1,439 @@ +/* + * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. + */ + +#include "base/os.h" +#if 0 +#include + +#include + +#ifdef __linux__ +#include +#include +#include +#endif + +#ifdef __FreeBSD__ +#include +#include +#endif +#endif +#include "testing/gunit.h" + +#include +#include +#include +#include + +#include + +#include "cfg/cfg_init.h" +#include "cfg/cfg_interface.h" +#include "oper/operdb_init.h" +#include "controller/controller_init.h" +#include "pkt/pkt_init.h" +#include "services/services_init.h" +#include "vrouter/ksync/ksync_init.h" +#include "oper/interface_common.h" +#include "oper/nexthop.h" +#include "route/route.h" +#include "oper/vrf.h" +#include "oper/mpls.h" +#include "oper/vm.h" +#include "oper/vn.h" +#include "filter/acl.h" +#include "test_cmn_util.h" +#include "vr_types.h" +#include +#include +#include +#include "uve/test/test_uve_util.h" + +void RouterIdDepInit(Agent *agent) { +} + +class PolicyTest : public ::testing::Test { +public: + PolicyTest() : util_() { + agent_ = Agent::GetInstance(); + } + + void SetPolicyDisabledStatus(struct PortInfo *input, bool status) { + ostringstream str; + + str << ""; + if (status) { + str << "true"; + } else { + str << "false"; + } + str << ""; + + AddNode("virtual-machine-interface", input[0].name, input[0].intf_id, + str.str().c_str()); + } + + TestUveUtil util_; + Agent *agent_; +}; + +TEST_F(PolicyTest, IntfPolicyDisable_Vn) { + struct PortInfo input[] = { + {"vnet1", 1, "1.1.1.1", "00:00:00:00:00:01", 1, 1}, + }; + + CreateVmportEnv(input, 1, 1); + client->WaitForIdle(); + EXPECT_TRUE(VmPortFind(1)); + + //Verify that interface has policy enabled + VmInterface *intf = static_cast(VmPortGet(1)); + EXPECT_TRUE(intf->policy_enabled()); + + //Verify that interface's MPLS label points to policy-enabled NH + const NextHop *nh = MplsToNextHop(intf->label()); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's L2 MPLS label points to policy-enabled NH + nh = MplsToNextHop(intf->l2_label()); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's route points to policy-enabled NH + nh = RouteToNextHop("vrf1", intf->primary_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's L2 route points to policy-enabled NH + MacAddress mac(intf->vm_mac()); + nh = L2RouteToNextHop("vrf1", mac); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's flow_key_nh points to policy-enabled NH + nh = intf->flow_key_nh(); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's mdata route points to policy-enabled NH + nh = RouteToNextHop(agent_->fabric_vrf_name(), intf->mdata_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Configure disable-policy as true on interface + //--------------------------------------------- + SetPolicyDisabledStatus(input, true); + client->WaitForIdle(); + + //Verify that policy is disabled on interface + EXPECT_FALSE(intf->policy_enabled()); + + //Verify that interface's MPLS label points to policy-disabled NH + nh = MplsToNextHop(intf->label()); + EXPECT_TRUE(nh != NULL); + EXPECT_FALSE(nh->PolicyEnabled()); + + //Verify that interface's L2 MPLS label points to policy-disabled NH + nh = MplsToNextHop(intf->l2_label()); + EXPECT_TRUE(nh != NULL); + EXPECT_FALSE(nh->PolicyEnabled()); + + //Verify that interface's route points to policy-disabled NH + nh = RouteToNextHop("vrf1", intf->primary_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_FALSE(nh->PolicyEnabled()); + + //Verify that interface's L2 route points to policy-disabled NH + nh = L2RouteToNextHop("vrf1", mac); + EXPECT_TRUE(nh != NULL); + EXPECT_FALSE(nh->PolicyEnabled()); + + //Verify that interface's flow_key_nh still points to policy-enabled NH + nh = intf->flow_key_nh(); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's mdata route still points to policy-enabled NH + nh = RouteToNextHop(agent_->fabric_vrf_name(), intf->mdata_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Configure disable-policy as false on interface + //--------------------------------------------- + SetPolicyDisabledStatus(input, false); + client->WaitForIdle(); + + //Verify that policy is enabled + EXPECT_TRUE(intf->policy_enabled()); + + //Verify that interface's MPLS label points to policy-enabled NH + nh = MplsToNextHop(intf->label()); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's L2 MPLS label points to policy-enabled NH + nh = MplsToNextHop(intf->l2_label()); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's route points to policy-enabled NH + nh = RouteToNextHop("vrf1", intf->primary_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's L2 route points to policy-enabled NH + nh = L2RouteToNextHop("vrf1", mac); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's flow_key_nh points to policy-enabled NH + nh = intf->flow_key_nh(); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's mdata route points to policy-enabled NH + nh = RouteToNextHop(agent_->fabric_vrf_name(), intf->mdata_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + DeleteVmportEnv(input, 1, true, 1); + client->WaitForIdle(); + EXPECT_FALSE(VmPortFind(1)); + client->Reset(); +} + +TEST_F(PolicyTest, IntfPolicyDisable_Fip) { + struct PortInfo input[] = { + {"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1} + }; + + //Add VN + util_.VnAdd(input[0].vn_id); + // Nova Port add message + util_.NovaPortAdd(&input[0]); + // Config Port add + util_.ConfigPortAdd(&input[0]); + //Verify that the port is inactive + EXPECT_TRUE(VmPortInactive(input, 0)); + + //Add necessary objects and links to make vm-intf active + util_.VmAdd(input[0].vm_id); + util_.VrfAdd(input[0].vn_id); + AddLink("virtual-network", "vn1", "routing-instance", "vrf1"); + client->WaitForIdle(); + AddLink("virtual-network", "vn1", "virtual-machine-interface", "vnet1"); + client->WaitForIdle(); + AddLink("virtual-machine", "vm1", "virtual-machine-interface", "vnet1"); + client->WaitForIdle(); + AddVmPortVrf("vnet1", "", 0); + client->WaitForIdle(); + AddInstanceIp("instance0", input[0].vm_id, input[0].addr); + AddLink("virtual-machine-interface", input[0].name, + "instance-ip", "instance0"); + client->WaitForIdle(3); + AddLink("virtual-machine-interface-routing-instance", "vnet1", + "routing-instance", "vrf1"); + client->WaitForIdle(3); + AddLink("virtual-machine-interface-routing-instance", "vnet1", + "virtual-machine-interface", "vnet1"); + client->WaitForIdle(3); + EXPECT_TRUE(VmPortActive(input, 0)); + const VmInterface *intf = VmInterfaceGet(input[0].intf_id); + EXPECT_TRUE(intf != NULL); + EXPECT_FALSE(intf->policy_enabled()); + + //Create a VN for floating-ip + client->Reset(); + AddVn("default-project:vn2", 2); + client->WaitForIdle(); + WAIT_FOR(1000, 100, (client->vn_notify_ >= 1)); + AddVrf("default-project:vn2:vn2"); + client->WaitForIdle(); + EXPECT_TRUE(client->VrfNotifyWait(1)); + EXPECT_TRUE(VrfFind("default-project:vn2:vn2")); + AddLink("virtual-network", "default-project:vn2", "routing-instance", + "default-project:vn2:vn2"); + client->WaitForIdle(); + + // Configure Floating-IP + AddFloatingIpPool("fip-pool1", 1); + AddFloatingIp("fip1", 1, "71.1.1.100"); + AddLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1"); + AddLink("floating-ip-pool", "fip-pool1", "virtual-network", + "default-project:vn2"); + client->WaitForIdle(); + AddLink("virtual-machine-interface", "vnet1", "floating-ip", "fip1"); + client->WaitForIdle(); + WAIT_FOR(1000, 500, ((VmPortFloatingIpCount(1, 1) == true))); + EXPECT_TRUE(intf->policy_enabled()); + + //Verify that interface's MPLS label points to policy-enabled NH + const NextHop *nh = MplsToNextHop(intf->label()); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's L2 MPLS label points to policy-enabled NH + nh = MplsToNextHop(intf->l2_label()); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's route points to policy-enabled NH + nh = RouteToNextHop("vrf1", intf->primary_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's L2 route points to policy-enabled NH + MacAddress mac(intf->vm_mac()); + nh = L2RouteToNextHop("vrf1", mac); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's flow_key_nh points to policy-enabled NH + nh = intf->flow_key_nh(); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's mdata route points to policy-enabled NH + nh = RouteToNextHop(agent_->fabric_vrf_name(), intf->mdata_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Configure disable-policy as true on interface + //--------------------------------------------- + SetPolicyDisabledStatus(input, true); + client->WaitForIdle(); + + //Verify that policy is disabled on interface + EXPECT_FALSE(intf->policy_enabled()); + + //Verify that interface's MPLS label points to policy-disabled NH + nh = MplsToNextHop(intf->label()); + EXPECT_TRUE(nh != NULL); + EXPECT_FALSE(nh->PolicyEnabled()); + + //Verify that interface's L2 MPLS label points to policy-disabled NH + nh = MplsToNextHop(intf->l2_label()); + EXPECT_TRUE(nh != NULL); + EXPECT_FALSE(nh->PolicyEnabled()); + + //Verify that interface's route points to policy-disabled NH + nh = RouteToNextHop("vrf1", intf->primary_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_FALSE(nh->PolicyEnabled()); + + //Verify that interface's L2 route points to policy-disabled NH + nh = L2RouteToNextHop("vrf1", mac); + EXPECT_TRUE(nh != NULL); + EXPECT_FALSE(nh->PolicyEnabled()); + + //Verify that interface's flow_key_nh still points to policy-enabled NH + nh = intf->flow_key_nh(); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's mdata route still points to policy-enabled NH + nh = RouteToNextHop(agent_->fabric_vrf_name(), intf->mdata_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Configure disable-policy as false on interface + //--------------------------------------------- + SetPolicyDisabledStatus(input, false); + client->WaitForIdle(); + + //Verify that policy is enabled + EXPECT_TRUE(intf->policy_enabled()); + + //Verify that interface's MPLS label points to policy-enabled NH + nh = MplsToNextHop(intf->label()); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's L2 MPLS label points to policy-enabled NH + nh = MplsToNextHop(intf->l2_label()); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's route points to policy-enabled NH + nh = RouteToNextHop("vrf1", intf->primary_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's L2 route points to policy-enabled NH + nh = L2RouteToNextHop("vrf1", mac); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's flow_key_nh points to policy-enabled NH + nh = intf->flow_key_nh(); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Verify that interface's mdata route points to policy-enabled NH + nh = RouteToNextHop(agent_->fabric_vrf_name(), intf->mdata_ip_addr(), 32); + EXPECT_TRUE(nh != NULL); + EXPECT_TRUE(nh->PolicyEnabled()); + + //Delete the floating-IP + DelLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1"); + DelLink("virtual-machine-interface", "vnet1", "floating-ip", "fip1"); + DelFloatingIp("fip1"); + client->WaitForIdle(); + + //cleanup + DelLink("floating-ip-pool", "fip-pool1", "virtual-network", + "default-project:vn2"); + DelLink("floating-ip-pool", "fip-pool1", "virtual-network", "vn1"); + DelFloatingIpPool("fip-pool1"); + DelLink("virtual-machine-interface-routing-instance", "vnet1", + "routing-instance", "vrf1"); + DelLink("virtual-machine-interface-routing-instance", "vnet1", + "virtual-machine-interface", "vnet1"); + DelLink("virtual-machine", "vm1", "virtual-machine-interface", "vnet1"); + DelLink("virtual-network", "vn1", "virtual-machine-interface", "vnet1"); + client->WaitForIdle(); + DelLink("virtual-network", "default-project:vn2", "routing-instance", + "default-project:vn2:vn2"); + client->WaitForIdle(3); + DelLink("virtual-machine-interface", input[0].name, + "instance-ip", "instance0"); + DelLink("virtual-network", "vn1", "routing-instance", "vrf1"); + client->WaitForIdle(3); + + DelNode("virtual-network", "default-project:vn2"); + DelVrf("default-project:vn2:vn2"); + client->WaitForIdle(3); + DelNode("virtual-machine-interface-routing-instance", "vnet1"); + client->WaitForIdle(3); + DelNode("virtual-machine", "vm1"); + DelNode("routing-instance", "vrf1"); + client->WaitForIdle(3); + DelNode("virtual-machine-interface", "vnet1"); + DelInstanceIp("instance0"); + client->WaitForIdle(3); + IntfCfgDel(input, 0); + util_.VnDelete(input[0].vn_id); + client->WaitForIdle(3); + WAIT_FOR(1000, 500, (VnGet(input[0].vn_id) == NULL)); + + //clear counters at the end of test case + client->Reset(); +} + +int main(int argc, char **argv) { + GETUSERARGS(); + + client = TestInit(init_file, ksync_init, false, false, false); + + int ret = RUN_ALL_TESTS(); + + usleep(10000); + client->WaitForIdle(); + usleep(10000); + TestShutdown(); + delete client; + + return ret; +} diff --git a/src/vnsw/agent/oper/vm_interface.cc b/src/vnsw/agent/oper/vm_interface.cc index b779e422819..672790d2179 100644 --- a/src/vnsw/agent/oper/vm_interface.cc +++ b/src/vnsw/agent/oper/vm_interface.cc @@ -62,7 +62,7 @@ VmInterface::VmInterface(const boost::uuids::uuid &uuid) : do_dhcp_relay_(false), vm_name_(), vm_project_uuid_(nil_uuid()), vxlan_id_(0), bridging_(false), layer3_forwarding_(true), flood_unknown_unicast_(false), - mac_set_(false), ecmp_(false), ecmp6_(false), + mac_set_(false), ecmp_(false), ecmp6_(false), disable_policy_(false), tx_vlan_id_(kInvalidVlanId), rx_vlan_id_(kInvalidVlanId), parent_(NULL), local_preference_(VmInterface::INVALID), oper_dhcp_options_(), sg_list_(), floating_ip_list_(), service_vlan_list_(), static_route_list_(), @@ -97,8 +97,8 @@ VmInterface::VmInterface(const boost::uuids::uuid &uuid, vm_project_uuid_(vm_project_uuid), vxlan_id_(0), bridging_(false), layer3_forwarding_(true), flood_unknown_unicast_(false), mac_set_(false), - ecmp_(false), ecmp6_(false), tx_vlan_id_(tx_vlan_id), - rx_vlan_id_(rx_vlan_id), parent_(parent), + ecmp_(false), ecmp6_(false), disable_policy_(false), + tx_vlan_id_(tx_vlan_id), rx_vlan_id_(rx_vlan_id), parent_(parent), local_preference_(VmInterface::INVALID), oper_dhcp_options_(), sg_list_(), floating_ip_list_(), service_vlan_list_(), static_route_list_(), allowed_address_pair_list_(), vrf_assign_rule_list_(), @@ -754,6 +754,7 @@ static void BuildAttributes(Agent *agent, IFMapNode *node, if (cfg->mac_addresses().size()) { data->vm_mac_ = cfg->mac_addresses().at(0); } + data->disable_policy_ = cfg->disable_policy(); } static void UpdateAttributes(Agent *agent, VmInterfaceConfigData *data) { @@ -1637,7 +1638,8 @@ VmInterfaceConfigData::VmInterfaceConfigData(Agent *agent, IFMapNode *node) : cfg_name_(""), vm_uuid_(), vm_name_(), vn_uuid_(), vrf_name_(""), fabric_port_(true), need_linklocal_ip_(false), bridging_(true), layer3_forwarding_(true), mirror_enable_(false), ecmp_(false), - ecmp6_(false), dhcp_enable_(true), admin_state_(true), analyzer_name_(""), + ecmp6_(false), dhcp_enable_(true), admin_state_(true), + disable_policy_(false), analyzer_name_(""), local_preference_(VmInterface::INVALID), oper_dhcp_options_(), mirror_direction_(Interface::UNKNOWN), sg_list_(), floating_ip_list_(), service_vlan_list_(), static_route_list_(), @@ -1806,6 +1808,11 @@ bool VmInterface::CopyConfig(const InterfaceTable *table, ret = true; } + if (disable_policy_ != data->disable_policy_) { + disable_policy_ = data->disable_policy_; + ret = true; + } + bool mac_set = true; boost::system::error_code ec; MacAddress addr(vm_mac_, &ec); @@ -2391,6 +2398,10 @@ bool VmInterface::WaitForTraffic() const { // Compute if policy is to be enabled on the interface bool VmInterface::PolicyEnabled() const { + if (disable_policy_) { + return false; + } + // Policy not supported for fabric ports if (fabric_port_) { return false; diff --git a/src/vnsw/agent/oper/vm_interface.h b/src/vnsw/agent/oper/vm_interface.h index 8fddc69778c..4f5632789a7 100644 --- a/src/vnsw/agent/oper/vm_interface.h +++ b/src/vnsw/agent/oper/vm_interface.h @@ -820,6 +820,11 @@ class VmInterface : public Interface { bool mac_set_; bool ecmp_; bool ecmp6_; + // disable-policy configuration on VMI. When this is configured, policy + // dependent features like flows, floating-IP and SG will not work on this + // VMI. However metadata-services will work because metadata route will + // still point to policy enabled NH. + bool disable_policy_; // VLAN Tag and the parent interface when VLAN is enabled uint16_t tx_vlan_id_; uint16_t rx_vlan_id_; @@ -989,6 +994,7 @@ struct VmInterfaceConfigData : public VmInterfaceData { bool ecmp6_; bool dhcp_enable_; // is DHCP enabled for the interface (from subnet config) bool admin_state_; + bool disable_policy_; std::string analyzer_name_; VmInterface::Preference local_preference_; OperDhcpOptions oper_dhcp_options_; diff --git a/src/vnsw/agent/test/test_cmn_util.h b/src/vnsw/agent/test/test_cmn_util.h index 01e7563cb8b..bf4487cd2ff 100644 --- a/src/vnsw/agent/test/test_cmn_util.h +++ b/src/vnsw/agent/test/test_cmn_util.h @@ -172,8 +172,11 @@ Inet4MulticastRouteEntry *MCRouteGet(const string &vrf_name, const string &grp_a BridgeRouteEntry *L2RouteGet(const string &vrf_name, const MacAddress &mac); BridgeRouteEntry *L2RouteGet(const string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr); +const NextHop* L2RouteToNextHop(const string &vrf, const MacAddress &mac); EvpnRouteEntry *EvpnRouteGet(const string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t ethernet_tag); +const NextHop* RouteToNextHop(const string &vrf_name, const Ip4Address &addr, + int plen); bool TunnelNHFind(const Ip4Address &server_ip); bool TunnelNHFind(const Ip4Address &server_ip, bool policy, TunnelType::Type type); bool EcmpTunnelRouteAdd(const Peer *peer, const string &vrf_name, const Ip4Address &vm_ip, @@ -377,6 +380,7 @@ void DelEncapList(Agent *agent); void VxLanNetworkIdentifierMode(bool config); void GlobalForwardingMode(std::string mode); int MplsToVrfId(int label); +const NextHop* MplsToNextHop(uint32_t label); void AddInterfaceRouteTable(const char *name, int id, TestIp4Prefix *addr, int count); void AddInterfaceRouteTable(const char *name, int id, TestIp4Prefix *addr, diff --git a/src/vnsw/agent/test/test_util.cc b/src/vnsw/agent/test/test_util.cc index ae7b20927ec..fc7e6830a3b 100644 --- a/src/vnsw/agent/test/test_util.cc +++ b/src/vnsw/agent/test/test_util.cc @@ -1322,6 +1322,14 @@ BridgeRouteEntry *L2RouteGet(const string &vrf_name, return L2RouteGet(vrf_name, mac, IpAddress()); } +const NextHop* L2RouteToNextHop(const string &vrf, const MacAddress &mac) { + BridgeRouteEntry* rt = L2RouteGet(vrf, mac); + if (rt == NULL) + return NULL; + + return rt->GetActiveNextHop(); +} + EvpnRouteEntry *EvpnRouteGet(const string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t ethernet_tag) { Agent *agent = Agent::GetInstance(); @@ -1364,6 +1372,14 @@ InetUnicastRouteEntry* RouteGetV6(const string &vrf_name, const Ip6Address &addr return route; } +const NextHop* RouteToNextHop(const string &vrf_name, const Ip4Address &addr, + int plen) { + InetUnicastRouteEntry* rt = RouteGet(vrf_name, addr, plen); + if (rt == NULL) + return NULL; + + return rt->GetActiveNextHop(); +} Inet4MulticastRouteEntry *MCRouteGet(const string &vrf_name, const Ip4Address &grp_addr) { VrfEntry *vrf = Agent::GetInstance()->vrf_table()->FindVrfFromName(vrf_name); @@ -3341,6 +3357,14 @@ PktGen *TxIpPacketUtil(int ifindex, const char *sip, const char *dip, return NULL; } +const NextHop* MplsToNextHop(uint32_t label) { + MplsLabel *mpls = Agent::GetInstance()->mpls_table()->FindMplsLabel(label); + if (mpls) { + return mpls->nexthop(); + } + return NULL; +} + int MplsToVrfId(int label) { int vrf = 0; MplsLabel *mpls = Agent::GetInstance()->mpls_table()->FindMplsLabel(label);