From 6cdd2f5d3fbc58e20996027bf98e57e7d8c4e3f1 Mon Sep 17 00:00:00 2001 From: ANISH-GOTTAPU <48308607+ANISH-GOTTAPU@users.noreply.github.com> Date: Thu, 3 Aug 2023 00:44:43 +0530 Subject: [PATCH] Align the test with ATE (#1927) --- .../route_propagation_test.go | 116 ++++++++++-------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/feature/bgp/addpath/otg_tests/route_propagation_test/route_propagation_test.go b/feature/bgp/addpath/otg_tests/route_propagation_test/route_propagation_test.go index f655557a6ee..81d9c7bc2bf 100644 --- a/feature/bgp/addpath/otg_tests/route_propagation_test/route_propagation_test.go +++ b/feature/bgp/addpath/otg_tests/route_propagation_test/route_propagation_test.go @@ -64,6 +64,10 @@ var ( ateAS2 = uint32(65538) ) +const ( + rplPermitAll = "PERMIT-ALL" +) + type otgPortDetails struct { mac, routerId string pathId int32 @@ -192,7 +196,7 @@ type dutData struct { func configureRoutingPolicy(d *oc.Root) (*oc.RoutingPolicy, error) { rp := d.GetOrCreateRoutingPolicy() - pdef := rp.GetOrCreatePolicyDefinition("PERMIT-ALL") + pdef := rp.GetOrCreatePolicyDefinition(rplPermitAll) stmt, err := pdef.AppendNewStatement("20") if err != nil { return nil, err @@ -205,16 +209,31 @@ func (d *dutData) Configure(t *testing.T, dut *ondatra.DUTDevice) { for _, a := range []attrs.Attributes{dutPort1, dutPort2} { ocName := dut.Port(t, a.Name).Name() gnmi.Replace(t, dut, gnmi.OC().Interface(ocName).Config(), a.NewOCInterface(ocName, dut)) - if deviations.ExplicitInterfaceInDefaultVRF(dut) { + } + + t.Log("Configure Network Instance") + dutConfNIPath := gnmi.OC().NetworkInstance(deviations.DefaultNetworkInstance(dut)) + gnmi.Replace(t, dut, dutConfNIPath.Type().Config(), oc.NetworkInstanceTypes_NETWORK_INSTANCE_TYPE_DEFAULT_INSTANCE) + + if deviations.ExplicitPortSpeed(dut) { + for _, a := range []attrs.Attributes{dutPort1, dutPort2} { + fptest.SetPortSpeed(t, dut.Port(t, a.Name)) + } + } + if deviations.ExplicitInterfaceInDefaultVRF(dut) { + for _, a := range []attrs.Attributes{dutPort1, dutPort2} { + ocName := dut.Port(t, a.Name).Name() fptest.AssignToNetworkInstance(t, dut, ocName, deviations.DefaultNetworkInstance(dut), 0) } } + dutProto := gnmi.OC().NetworkInstance(deviations.DefaultNetworkInstance(dut)). Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP") key := oc.NetworkInstance_Protocol_Key{ Identifier: oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, Name: "BGP", } + niOC := &oc.NetworkInstance{ Name: ygot.String(deviations.DefaultNetworkInstance(dut)), Type: oc.NetworkInstanceTypes_NETWORK_INSTANCE_TYPE_DEFAULT_INSTANCE, @@ -240,11 +259,32 @@ func (d *dutData) AwaitBGPEstablished(t *testing.T, dut *ondatra.DUTDevice) { Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP"). Bgp(). Neighbor(neighbor). - SessionState().State(), time.Second*15, oc.Bgp_Neighbor_SessionState_ESTABLISHED) + SessionState().State(), time.Second*120, oc.Bgp_Neighbor_SessionState_ESTABLISHED) } t.Log("BGP sessions established") } +func getPeerGroup(pgn string, aftype oc.E_BgpTypes_AFI_SAFI_TYPE, dut *ondatra.DUTDevice) *oc.NetworkInstance_Protocol_Bgp_PeerGroup { + bgp := &oc.NetworkInstance_Protocol_Bgp{} + pg := bgp.GetOrCreatePeerGroup(pgn) + + if deviations.RoutePolicyUnderAFIUnsupported(dut) { + //policy under peer group + rpl := pg.GetOrCreateApplyPolicy() + rpl.SetExportPolicy([]string{rplPermitAll}) + rpl.SetImportPolicy([]string{rplPermitAll}) + return pg + } + + //policy under peer group AFI + afisafi := pg.GetOrCreateAfiSafi(aftype) + afisafi.Enabled = ygot.Bool(true) + rpl := afisafi.GetOrCreateApplyPolicy() + rpl.SetExportPolicy([]string{rplPermitAll}) + rpl.SetImportPolicy([]string{rplPermitAll}) + return pg +} + func verifyOTGBGPTelemetry(t *testing.T, otg *otg.OTG, c gosnappi.Config, state string) { for _, d := range c.Devices().Items() { for _, ip := range d.Bgp().Ipv4Interfaces().Items() { @@ -333,6 +373,7 @@ func checkOTGBGP6Prefix(t *testing.T, otg *otg.OTG, config gosnappi.Config, expe } func TestBGP(t *testing.T) { + dut := ondatra.DUT(t, "dut") tests := []struct { desc, fullDesc string skipReason string @@ -344,20 +385,8 @@ func TestBGP(t *testing.T) { fullDesc: "Advertise prefixes from ATE port1, observe received prefixes at ATE port2", dut: dutData{&oc.NetworkInstance_Protocol_Bgp{ PeerGroup: map[string]*oc.NetworkInstance_Protocol_Bgp_PeerGroup{ - "BGP-PEER-GROUP1": { - PeerGroupName: ygot.String("BGP-PEER-GROUP1"), - ApplyPolicy: &oc.NetworkInstance_Protocol_Bgp_PeerGroup_ApplyPolicy{ - ExportPolicy: []string{"PERMIT-ALL"}, - ImportPolicy: []string{"PERMIT-ALL"}, - }, - }, - "BGP-PEER-GROUP2": { - PeerGroupName: ygot.String("BGP-PEER-GROUP2"), - ApplyPolicy: &oc.NetworkInstance_Protocol_Bgp_PeerGroup_ApplyPolicy{ - ExportPolicy: []string{"PERMIT-ALL"}, - ImportPolicy: []string{"PERMIT-ALL"}, - }, - }, + "BGP-PEER-GROUP1": getPeerGroup("BGP-PEER-GROUP1", oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, dut), + "BGP-PEER-GROUP2": getPeerGroup("BGP-PEER-GROUP2", oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, dut), }, Global: &oc.NetworkInstance_Protocol_Bgp_Global{ As: ygot.Uint32(dutAS), @@ -374,11 +403,23 @@ func TestBGP(t *testing.T) { PeerAs: ygot.Uint32(ateAS1), NeighborAddress: ygot.String("192.0.2.2"), PeerGroup: ygot.String("BGP-PEER-GROUP1"), + AfiSafi: map[oc.E_BgpTypes_AFI_SAFI_TYPE]*oc.NetworkInstance_Protocol_Bgp_Neighbor_AfiSafi{ + oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST: { + AfiSafiName: oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, + Enabled: ygot.Bool(true), + }, + }, }, "192.0.2.6": { PeerAs: ygot.Uint32(ateAS2), NeighborAddress: ygot.String("192.0.2.6"), PeerGroup: ygot.String("BGP-PEER-GROUP2"), + AfiSafi: map[oc.E_BgpTypes_AFI_SAFI_TYPE]*oc.NetworkInstance_Protocol_Bgp_Neighbor_AfiSafi{ + oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST: { + AfiSafiName: oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, + Enabled: ygot.Bool(true), + }, + }, }, }, }}, @@ -401,20 +442,8 @@ func TestBGP(t *testing.T) { fullDesc: "Advertise IPv6 prefixes from ATE port1, observe received prefixes at ATE port2", dut: dutData{&oc.NetworkInstance_Protocol_Bgp{ PeerGroup: map[string]*oc.NetworkInstance_Protocol_Bgp_PeerGroup{ - "BGP-PEER-GROUP1": { - PeerGroupName: ygot.String("BGP-PEER-GROUP1"), - ApplyPolicy: &oc.NetworkInstance_Protocol_Bgp_PeerGroup_ApplyPolicy{ - ExportPolicy: []string{"PERMIT-ALL"}, - ImportPolicy: []string{"PERMIT-ALL"}, - }, - }, - "BGP-PEER-GROUP2": { - PeerGroupName: ygot.String("BGP-PEER-GROUP2"), - ApplyPolicy: &oc.NetworkInstance_Protocol_Bgp_PeerGroup_ApplyPolicy{ - ExportPolicy: []string{"PERMIT-ALL"}, - ImportPolicy: []string{"PERMIT-ALL"}, - }, - }, + "BGP-PEER-GROUP1": getPeerGroup("BGP-PEER-GROUP1", oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, dut), + "BGP-PEER-GROUP2": getPeerGroup("BGP-PEER-GROUP2", oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, dut), }, Global: &oc.NetworkInstance_Protocol_Bgp_Global{ As: ygot.Uint32(dutAS), @@ -471,20 +500,8 @@ func TestBGP(t *testing.T) { fullDesc: "IPv4 routes with an IPv6 next-hop when negotiating RFC5549 - validating that routes are accepted and advertised with the specified values.", dut: dutData{&oc.NetworkInstance_Protocol_Bgp{ PeerGroup: map[string]*oc.NetworkInstance_Protocol_Bgp_PeerGroup{ - "BGP-PEER-GROUP1": { - PeerGroupName: ygot.String("BGP-PEER-GROUP1"), - ApplyPolicy: &oc.NetworkInstance_Protocol_Bgp_PeerGroup_ApplyPolicy{ - ExportPolicy: []string{"PERMIT-ALL"}, - ImportPolicy: []string{"PERMIT-ALL"}, - }, - }, - "BGP-PEER-GROUP2": { - PeerGroupName: ygot.String("BGP-PEER-GROUP2"), - ApplyPolicy: &oc.NetworkInstance_Protocol_Bgp_PeerGroup_ApplyPolicy{ - ExportPolicy: []string{"PERMIT-ALL"}, - ImportPolicy: []string{"PERMIT-ALL"}, - }, - }, + "BGP-PEER-GROUP1": getPeerGroup("BGP-PEER-GROUP1", oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, dut), + "BGP-PEER-GROUP2": getPeerGroup("BGP-PEER-GROUP2", oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, dut), }, Global: &oc.NetworkInstance_Protocol_Bgp_Global{ As: ygot.Uint32(dutAS), @@ -506,10 +523,6 @@ func TestBGP(t *testing.T) { AfiSafiName: oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, Enabled: ygot.Bool(true), }, - oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST: { - AfiSafiName: oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, - Enabled: ygot.Bool(true), - }, }, }, "192.0.2.6": { @@ -548,11 +561,6 @@ func TestBGP(t *testing.T) { t.Skip(tc.skipReason) } - dut := ondatra.DUT(t, "dut") - t.Log("Configure Network Instance") - dutConfNIPath := gnmi.OC().NetworkInstance(deviations.DefaultNetworkInstance(dut)) - gnmi.Replace(t, dut, dutConfNIPath.Type().Config(), oc.NetworkInstanceTypes_NETWORK_INSTANCE_TYPE_DEFAULT_INSTANCE) - tc.dut.Configure(t, dut) ate := ondatra.ATE(t, "ate")