Skip to content

Commit

Permalink
fixing bgp_afi_safi_defaults_test with deviations (openconfig#3603)
Browse files Browse the repository at this point in the history
* fixing bgp_afi_safi_defaults_test with deviations

* README modified to add validation for extended nexthop encoding, and the validation is only required for IPv4 unicast at neighbor level

* deviations format fix
  • Loading branch information
ram-mac authored Nov 23, 2024
1 parent b3d9c73 commit 3b0a8a5
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 89 deletions.
7 changes: 6 additions & 1 deletion feature/bgp/otg_tests/bgp_afi_safi_defaults/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ BGP AFI SAFI OC DEFAULTS TEST
defines as the defaults i.e,
* For BGP, there are no defaults for AFI-SAFI at the neighbor and peer-group levels. However at the
global level the default is "false"
* For BGP neighbor level extended-next-hop encoding to be configured and validated too
* This test currently only verifies the defaults for ipv4-unicast and ipv6-unicast families.
However, this test can be extended further to cover for other AFI-SAFIs as well in future.
* The test will check for default implementations under the neighbor and peer-group hierarchies and
Expand All @@ -32,6 +33,8 @@ BGP AFI SAFI OC DEFAULTS TEST
* Ensure that there are no AFI-SAFI configurations at the global and peer-group levels.
* On the ATE side ensure that IPv4-unicast and IPv6-unicast AFI-SAFI are enabled==true for
IPv4 and IPv6 neighbors.
* Ensure that there is extended-next-hop encoding feature is configured via OC path and the
default value of this should be set to false

* Verification:
* For IPv4 neighbor, ensure that the IPv4 neighborship is up and IPv6-unicast capability is
Expand Down Expand Up @@ -95,6 +98,7 @@ paths:
/network-instances/network-instance/protocols/protocol/bgp/peer-groups/peer-group/config/peer-as:
/network-instances/network-instance/protocols/protocol/bgp/peer-groups/peer-group/afi-safis/afi-safi/config/enabled:
/network-instances/network-instance/protocols/protocol/bgp/global/afi-safis/afi-safi/config/enabled:
/network-instances/network-instance/protocols/protocol/bgp/global/afi-safis/afi-safi/ipv4-unicast/config/extended-next-hop-encoding:

## Telemetry Parameter coverage

Expand All @@ -105,6 +109,7 @@ paths:
/network-instances/network-instance/protocols/protocol/bgp/peer-groups/peer-group/state/peer-type:
/network-instances/network-instance/protocols/protocol/bgp/peer-groups/peer-group/state/peer-as:
/network-instances/network-instance/protocols/protocol/bgp/peer-groups/peer-group/state/local-as:
/network-instances/network-instance/protocols/protocol/bgp/global/afi-safis/afi-safi/ipv4-unicast/state/extended-next-hop-encoding:

rpcs:
gnmi:
Expand All @@ -114,4 +119,4 @@ rpcs:
```
## Minimum DUT Required
vRX - Virtual Router Device
vRX - Virtual Router Device
Original file line number Diff line number Diff line change
Expand Up @@ -155,43 +155,59 @@ func bgpCreateNbr(t *testing.T, localAs, peerAs uint32, dut *ondatra.DUTDevice,

switch afiSafiLevel {
case globalLevel:
global.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(true)
global.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(true)
if !isV4Only {
extNh := global.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).GetOrCreateIpv4Unicast()
extNh.ExtendedNextHopEncoding = ygot.Bool(true)
pg1.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(false)
pg1.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(false)
pg2.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(false)
pg2.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(false)
if isV4Only {
global.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(true)
global.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(false)
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(true)
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(false)
} else {
global.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(false)
global.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(true)
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(false)
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(true)
}
if deviations.BGPGlobalExtendedNextHopEncodingUnsupported(dut) {
global.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Ipv4Unicast = nil
}
case nbrLevel:
if nbr.isV4 == true {
af4 := nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST)
af4.Enabled = ygot.Bool(true)
if isV4Only {
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(true)
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(false)
extNh := nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).GetOrCreateIpv4Unicast()
if !deviations.BgpExtendedNextHopEncodingLeafUnsupported(dut) {
extNh.ExtendedNextHopEncoding = ygot.Bool(true)
}
} else {
af6 := nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST)
af6.Enabled = ygot.Bool(true)
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(false)
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(true)
}
if deviations.BGPGlobalExtendedNextHopEncodingUnsupported(dut) {
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Ipv4Unicast = nil
}
case peerGrpLevel:
pg1af4 := pg1.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST)
pg1af4.Enabled = ygot.Bool(true)
pg1af6 := pg1.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST)
pg1af6.Enabled = ygot.Bool(true)

pg2af4 := pg2.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST)
pg2af4.Enabled = ygot.Bool(true)
ext2Nh := pg2af4.GetOrCreateIpv4Unicast()
ext2Nh.ExtendedNextHopEncoding = ygot.Bool(true)
pg2af6 := pg2.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST)
pg2af6.Enabled = ygot.Bool(true)
if isV4Only {
pg1.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(true)
pg1.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(false)
pg2.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(true)
pg2.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(false)
} else {
pg1.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(false)
pg1.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(true)
pg2.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(false)
pg2.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(true)
}
case afiSafiSetToFalse:
t.Log("AFI-SAFI is set to false")
if nbr.isV4 {
af4 := nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST)
af4.Enabled = ygot.Bool(false)
if isV4Only {
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(false)
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(false)
} else {
af6 := nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST)
af6.Enabled = ygot.Bool(false)
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(false)
nv4.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(false)
}
}
}
Expand Down Expand Up @@ -244,8 +260,11 @@ func verifyBgpSession(t *testing.T, dut *ondatra.DUTDevice, nbrsList []*bgpNeigh
for _, nbr := range nbrsList {
nbrPath := bgpPath.Neighbor(nbr.neighborip)
state := gnmi.Get(t, dut, nbrPath.SessionState().State())
t.Logf("BGP adjacency for %s: %v", nbr.neighborip, state)
if state == oc.Bgp_Neighbor_SessionState_ESTABLISHED {
t.Errorf("BGP peer %s status got %d, want other than ESTABLISHED", nbr.neighborip, state)
} else {
t.Logf("BGP peer %s status got %d, want other than ESTABLISHED", nbr.neighborip, state)
}
}
}
Expand Down Expand Up @@ -313,7 +332,7 @@ func configureOTG(t *testing.T, otg *otg.OTG, otgPeerList []string) gosnappi.Con
}

// verifyBGPCapabilities is used to Verify BGP capabilities like route refresh as32 and mpbgp.
func verifyBgpCapabilities(t *testing.T, dut *ondatra.DUTDevice, afiSafiLevel string, nbrs []*bgpNeighbor) {
func verifyBgpCapabilities(t *testing.T, dut *ondatra.DUTDevice, afiSafiLevel string, nbrs []*bgpNeighbor, isV4Only bool) {
t.Helper()
t.Log("Verifying BGP AFI-SAFI capabilities.")

Expand All @@ -327,11 +346,32 @@ func verifyBgpCapabilities(t *testing.T, dut *ondatra.DUTDevice, afiSafiLevel st
oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST: false,
oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST: false,
}

for _, cap := range gnmi.GetAll(t, dut, nbrPath.State()) {
capabilities[cap.GetAfiSafiName()] = cap.GetActive()
if deviations.BgpAfiSafiWildcardNotSupported(dut) {
t.Logf("AFI-SAFI wildcard/getall not supported")
afiSafiType := []oc.E_BgpTypes_AFI_SAFI_TYPE{oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST}
afiSafiList := []*oc.NetworkInstance_Protocol_Bgp_Neighbor_AfiSafi{}
for _, afiSafi := range afiSafiType {
if nbr.isV4 && afiSafi == oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST {
continue
}
if !nbr.isV4 && afiSafi == oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST {
continue
}
t.Logf("AFI-SAFI state: %v", gnmi.Get(t, dut, statePath.Neighbor(nbr.neighborip).AfiSafi(afiSafi).State()))
afiSafiList = append(afiSafiList, gnmi.Get(t, dut, statePath.Neighbor(nbr.neighborip).AfiSafi(afiSafi).State()))
t.Logf("AFI-SAFI list: %v", afiSafiList)
}
for _, cap := range afiSafiList {
capabilities[cap.GetAfiSafiName()] = cap.GetActive()
}
t.Logf("Capabilities for peer %v are %v", nbr.neighborip, capabilities)
} else {
gnmi.GetAll(t, dut, nbrPath.State())
for _, cap := range gnmi.GetAll(t, dut, nbrPath.State()) {
capabilities[cap.GetAfiSafiName()] = cap.GetActive()
}
t.Logf("Capabilities for peer %v are %v", nbr.neighborip, capabilities)
}

switch afiSafiLevel {
case nbrLevel:
if nbr.isV4 && capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST] {
Expand All @@ -342,20 +382,25 @@ func verifyBgpCapabilities(t *testing.T, dut *ondatra.DUTDevice, afiSafiLevel st
}
t.Logf("Capabilities for peer %v are %v", nbr.neighborip, capabilities)
case peerGrpLevel:
if capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST] == true &&
capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST] == true {
if isV4Only && capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST] == true {
t.Logf("Both V4 and V6 AFI-SAFI are inherited from peer-group level for peer: %v, %v", nbr.neighborip, capabilities)
} else if !isV4Only && capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST] == true {
t.Logf("Both V4 and V6 AFI-SAFI are inherited from peer-group level for peer: %v, %v", nbr.neighborip, capabilities)
} else {
t.Errorf("Both V4 and V6 AFI-SAFI are not inherited from peer-group level for peer: %v, %v", nbr.neighborip, capabilities)
}
t.Logf("Capabilities for peer %v are %v", nbr.neighborip, capabilities)
case globalLevel:
if capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST] == true &&
capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST] == true {
if isV4Only && capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST] == true {
t.Logf("Both V4 and V6 AFI-SAFI are inherited from global level for peer: %v, %v", nbr.neighborip, capabilities)
} else if !isV4Only && capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST] == true {
t.Logf("Both V4 and V6 AFI-SAFI are inherited from global level for peer: %v, %v", nbr.neighborip, capabilities)
} else {
t.Errorf("Both V4 and V6 AFI-SAFI are not inherited from global level for peer: %v, %v", nbr.neighborip, capabilities)
}
t.Logf("Capabilities for peer %v are %v", nbr.neighborip, capabilities)
case afiSafiSetToFalse:
t.Logf("afiSafiSetToFalse capabilities: %v, v4 -> %v, v6 ->%v", isV4Only, capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST], capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST])
if nbr.isV4 && capabilities[oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST] == true {
t.Errorf("AFI-SAFI are Active after disabling: %v, %v", capabilities, nbr.neighborip)
}
Expand Down Expand Up @@ -430,7 +475,7 @@ func TestAfiSafiOcDefaults(t *testing.T) {
desc: "Validate AFI-SAFI OC defaults at peer group level for BGPv4 peers",
afiSafiLevel: peerGrpLevel,
nbrs: []*bgpNeighbor{nbr1, nbr3},
isV4Only: false,
isV4Only: true,
otgPeerList: []string{otgPort1V4Peer, otgPort2V4Peer},
}, {
desc: "Validate AFI-SAFI OC defaults at global level for V4 peers",
Expand Down Expand Up @@ -480,7 +525,7 @@ func TestAfiSafiOcDefaults(t *testing.T) {
t.Run("Verify BGP telemetry", func(t *testing.T) {
verifyBgpTelemetry(t, dut, tc.nbrs)
verifyOtgBgpTelemetry(t, otg, otgConfig, tc.otgPeerList, "ESTABLISHED")
verifyBgpCapabilities(t, dut, tc.afiSafiLevel, tc.nbrs)
verifyBgpCapabilities(t, dut, tc.afiSafiLevel, tc.nbrs, tc.isV4Only)
})
})
}
Expand Down Expand Up @@ -540,10 +585,14 @@ func TestAfiSafiSetToFalse(t *testing.T) {
t.Run("Configure OTG", func(t *testing.T) {
configureOTG(t, otg, tc.otgPeerList)
})
t.Logf("Verify BGP session on DUT")
time.Sleep(60 * time.Second)

t.Run("Verify BGP telemetry", func(t *testing.T) {
t.Run("Verify BGP session", func(t *testing.T) {
verifyBgpSession(t, dut, tc.nbrs)
verifyBgpCapabilities(t, dut, tc.afiSafiLevel, tc.nbrs)
})
t.Run("Verify BGP capabilities", func(t *testing.T) {
verifyBgpCapabilities(t, dut, tc.afiSafiLevel, tc.nbrs, tc.isV4Only)
})
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ platform_exceptions: {
}
deviations: {
ipv4_missing_enabled: true
bgp_extended_next_hop_encoding_leaf_unsupported: true
bgp_afi_safi_wildcard_not_supported: true
}
}
platform_exceptions: {
Expand Down
16 changes: 16 additions & 0 deletions internal/deviations/deviations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,19 @@ func OTNChannelAssignmentCiscoNumbering(dut *ondatra.DUTDevice) bool {
func CiscoPreFECBERInactiveValue(dut *ondatra.DUTDevice) bool {
return lookupDUTDeviations(dut).GetCiscoPreFecBerInactiveValue()
}

// BgpExtendedNextHopEncodingLeafUnsupported return true if bgp extended next hop encoding leaf is unsupported
// Cisco supports the extended nexthop encoding set to true by default that is excercised in the Script where the extended-nexthop-encoding
// a bool value is set to true.
func BgpExtendedNextHopEncodingLeafUnsupported(dut *ondatra.DUTDevice) bool {
return lookupDUTDeviations(dut).GetBgpExtendedNextHopEncodingLeafUnsupported()
}

// BgpAfiSafiWildcardNotSupported return true if bgp afi/safi wildcard query is not supported.
// For example, this yang path query includes the wildcard key `afi-safi-name=`:
// `/network-instances/network-instance[name=DEFAULT]/protocols/protocol[identifier=BGP][name=BGP]/bgp/neighbors/neighbor[neighbor-address=192.0.2.2]/afi-safis/afi-safi[afi-safi-name=]`.
// Use of this deviation is permitted if a query using an explicit key is supported (such as
// `oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST`).
func BgpAfiSafiWildcardNotSupported(dut *ondatra.DUTDevice) bool {
return lookupDUTDeviations(dut).GetBgpAfiSafiWildcardNotSupported()
}
7 changes: 6 additions & 1 deletion proto/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,12 @@ message Metadata {
bool otn_channel_assignment_cisco_numbering = 232;
// Cisco pre-fec-ber inactive value for CISCO-ACACIA vendors
bool cisco_pre_fec_ber_inactive_value = 233;
// Device does not support bgp extended next hop encoding leaf.
// Cisco: b/377433951
bool bgp_extended_next_hop_encoding_leaf_unsupported = 234;
// Device does not support bgp afi safi wildcard.
// Cisco: b/379863985
bool bgp_afi_safi_wildcard_not_supported = 235;
// Reserved field numbers and identifiers.
reserved 84, 9, 28, 20, 90, 97, 55, 89, 19, 36, 35, 40, 173;
}
Expand Down Expand Up @@ -676,4 +682,3 @@ message Metadata {
// checks.
bool path_presence_test = 7;
}

Loading

0 comments on commit 3b0a8a5

Please sign in to comment.