Skip to content

Commit

Permalink
Align the test with ATE (#1927)
Browse files Browse the repository at this point in the history
  • Loading branch information
ANISH-GOTTAPU authored Aug 2, 2023
1 parent af152e3 commit 6cdd2f5
Showing 1 changed file with 62 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ var (
ateAS2 = uint32(65538)
)

const (
rplPermitAll = "PERMIT-ALL"
)

type otgPortDetails struct {
mac, routerId string
pathId int32
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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),
},
},
},
},
}},
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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": {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 6cdd2f5

Please sign in to comment.