Skip to content

Commit

Permalink
fix actions_MED_LocPref_prepend_flow_control_test.go for cisco (openc…
Browse files Browse the repository at this point in the history
…onfig#3047)

* fix actions_MED_LocPref_prepend_flow_control_test.go for cisco

* .
  • Loading branch information
nsadhasivam authored Jun 2, 2024
1 parent 57039f2 commit 5aa62e6
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,36 +306,39 @@ For each section of configuration below, prepare a gnmi.SetBatch with all the c
* Validate that the ATE receives the prefix ```ipv4-network-2``` from DUT neighbor on ATE Port-1 and it has 11 ASN on as-path. First equal to ATE port-2 ASN and other 10 equal to ```23456``` ASN.
* Validate that the ATE receives the prefix ```ipv6-network-2``` from DUT neighbor on ATE Port-1 and it has 11 ASN on as-path. First equal to ATE port-2 ASN and other 10 equal to ```23456``` ASN.

## Config parameter coverage
## OpenConfig Path and RPC Coverage

* /network-instances/network-instance/protocols/protocol/bgp/global/afi-safis/afi-safi/config/
* /network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/config/default-export-policy
* /network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/config/default-import-policy
* /network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/config/export-policy
* /network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/config/import-policy
* /routing-policy/policy-definitions/policy-definition/config/name
* /routing-policy/policy-definitions/policy-definition/statements/statement/actions/bgp-actions/config/local-preference
* /routing-policy/policy-definitions/policy-definition/statements/statement/actions/bgp-actions/config/local-prefrence
* /routing-policy/policy-definitions/policy-definition/statements/statement/actions/bgp-actions/config/med
* /routing-policy/policy-definitions/policy-definition/statements/statement/actions/bgp-actions/prepend/config/asn
* /routing-policy/policy-definitions/policy-definition/statements/statement/actions/bgp-actions/prepend/config/repead-n
* /routing-policy/policy-definitions/policy-definition/statements/statement/actions/config/policy-result
* /routing-policy/policy-definitions/policy-definition/statements/statement/config/name
The below yaml defines the OC paths intended to be covered by this test.

## Telemetry parameter coverage
```yaml
paths:
## Config parameter coverage
/network-instances/network-instance/protocols/protocol/bgp/global/afi-safis/afi-safi/config/enabled:
/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/config/default-export-policy:
/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/config/default-import-policy:
/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/config/export-policy:
/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/config/import-policy:
/routing-policy/policy-definitions/policy-definition/config/name:
/routing-policy/policy-definitions/policy-definition/statements/statement/actions/bgp-actions/config/set-local-pref:
/routing-policy/policy-definitions/policy-definition/statements/statement/actions/bgp-actions/config/set-med:
/routing-policy/policy-definitions/policy-definition/statements/statement/actions/bgp-actions/set-as-path-prepend/config/asn:
/routing-policy/policy-definitions/policy-definition/statements/statement/actions/bgp-actions/set-as-path-prepend/config/repeat-n:
/routing-policy/policy-definitions/policy-definition/statements/statement/actions/config/policy-result:
/routing-policy/policy-definitions/policy-definition/statements/statement/config/name:

* /network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/state/import-policy
* /network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/state/export-policy
* /network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/state/default-import-policy
* /network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/state/default-export-policy
## Telemetry parameter coverage
/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/state/import-policy:
/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/state/export-policy:
/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/state/default-import-policy:
/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/afi-safis/afi-safi/apply-policy/state/default-export-policy:

## Protocol/RPC Parameter Coverage

* gNMI
* Subscribe (ONCE)
* Set (REPLACE)
## Protocol/RPC Parameter Coverage
rpcs:
gnmi:
gNMI.Subscribe:
gNMI.Set:
```
## Required DUT platform
* FFF

Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func createNewBgpSession(dut *ondatra.DUTDevice) *oc.NetworkInstance_Protocol {
bgpNbr1.PeerGroup = ygot.String(peerGrpNameV6)
bgpNbr1.PeerAs = ygot.Uint32(nb.peerAs)
bgpNbr1.Enabled = ygot.Bool(true)
af6 := bgpNbr.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST)
af6 := bgpNbr1.GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST)
af6.Enabled = ygot.Bool(true)
}
return niProto
Expand All @@ -194,7 +194,7 @@ func VerifyBgpState(t *testing.T, dut *ondatra.DUTDevice) {
t.Helper()
var nbrIP = []string{atePort1.IPv4, atePort1.IPv6, atePort2.IPv4, atePort2.IPv6}
bgpPath := gnmi.OC().NetworkInstance(deviations.DefaultNetworkInstance(dut)).Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").Bgp()
watch := gnmi.Watch(t, dut, bgpPath.State(), time.Minute, func(val *ygnmi.Value[*oc.NetworkInstance_Protocol_Bgp]) bool {
watch := gnmi.Watch(t, dut, bgpPath.State(), 2*time.Minute, func(val *ygnmi.Value[*oc.NetworkInstance_Protocol_Bgp]) bool {
path, _ := val.Val()
for _, nbr := range nbrIP {
if path.GetNeighbor(nbr).GetSessionState() != oc.Bgp_Neighbor_SessionState_ESTABLISHED {
Expand Down Expand Up @@ -241,7 +241,9 @@ func configureASLocalPrefMEDPolicy(t *testing.T, dut *ondatra.DUTDevice, policyT
asPrepend.RepeatN = ygot.Uint8(uint8(metric))
actions.PolicyResult = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE
case setNxtPolicy:
actions.PolicyResult = oc.RoutingPolicy_PolicyResultType_NEXT_STATEMENT
if !deviations.SkipSettingStatementForPolicy(dut) {
actions.PolicyResult = oc.RoutingPolicy_PolicyResultType_NEXT_STATEMENT
}
metric, _ := strconv.Atoi(policyValue)
actions.GetOrCreateBgpActions().SetMed = oc.UnionUint32(uint32(metric))

Expand Down Expand Up @@ -290,12 +292,21 @@ func configureBGPImportExportPolicy(t *testing.T, dut *ondatra.DUTDevice, ipv4,
}

// deleteBGPImportExportPolicy configures import/export policies
func deleteBGPImportExportPolicy(t *testing.T, dut *ondatra.DUTDevice, ipv4, ipv6 string) {
func deleteBGPImportExportPolicy(t *testing.T, dut *ondatra.DUTDevice, ipv4, ipv6 string, ipv4_2 string, ipv6_2 string) {
t.Helper()
bgpPath := gnmi.OC().NetworkInstance(deviations.DefaultNetworkInstance(dut)).Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").Bgp()
batchConfig := &gnmi.SetBatch{}
nbrPolPathv4 := bgpPath.Neighbor(ipv4).AfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).ApplyPolicy()
nbrPolPathv6 := bgpPath.Neighbor(ipv6).AfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).ApplyPolicy()
if deviations.DefaultRoutePolicyUnsupported(dut) {
// deleteBGPImportExportPolicy on port2 needed when default policy is not supported
nbrPolPathv4_2 := bgpPath.Neighbor(ipv4_2).AfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).ApplyPolicy()
nbrPolPathv6_2 := bgpPath.Neighbor(ipv6_2).AfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).ApplyPolicy()
gnmi.BatchDelete(batchConfig, nbrPolPathv4_2.ImportPolicy().Config())
gnmi.BatchDelete(batchConfig, nbrPolPathv4_2.ExportPolicy().Config())
gnmi.BatchDelete(batchConfig, nbrPolPathv6_2.ImportPolicy().Config())
gnmi.BatchDelete(batchConfig, nbrPolPathv6_2.ExportPolicy().Config())
}
gnmi.BatchDelete(batchConfig, nbrPolPathv4.ImportPolicy().Config())
gnmi.BatchDelete(batchConfig, nbrPolPathv4.ExportPolicy().Config())
gnmi.BatchDelete(batchConfig, nbrPolPathv6.ImportPolicy().Config())
Expand All @@ -319,12 +330,14 @@ func verifyBgpPolicyTelemetry(t *testing.T, dut *ondatra.DUTDevice, ipAddr strin

peerTel := gnmi.Get(t, dut, afiSafiPath.State())

if gotDefExPolicy := peerTel.GetApplyPolicy().GetDefaultExportPolicy(); gotDefExPolicy != defPol {
t.Errorf("Default export policy type mismatch: got %v, want %v", gotDefExPolicy, defPol)
}
if !deviations.DefaultRoutePolicyUnsupported(dut) {
if gotDefExPolicy := peerTel.GetApplyPolicy().GetDefaultExportPolicy(); gotDefExPolicy != defPol {
t.Errorf("Default export policy type mismatch: got %v, want %v", gotDefExPolicy, defPol)
}

if gotDefImPolicy := peerTel.GetApplyPolicy().GetDefaultImportPolicy(); gotDefImPolicy != defPol {
t.Errorf("Default import policy type mismatch: got %v, want %v", gotDefImPolicy, defPol)
if gotDefImPolicy := peerTel.GetApplyPolicy().GetDefaultImportPolicy(); gotDefImPolicy != defPol {
t.Errorf("Default import policy type mismatch: got %v, want %v", gotDefImPolicy, defPol)
}
}

if appliedPol != "" {
Expand Down Expand Up @@ -720,14 +733,23 @@ func TestBGPPolicy(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
// Delete BGP import export policy
if tc.isDeletePolicy {
deleteBGPImportExportPolicy(t, dut, tc.deleteNbrv4, tc.deleteNbrv6)
deleteBGPImportExportPolicy(t, dut, tc.deleteNbrv4, tc.deleteNbrv6, atePort2.IPv4, atePort2.IPv6)
}
// Configure Routing Policy on the DUT.
configureASLocalPrefMEDPolicy(t, dut, tc.rpPolicy, tc.policyValue, tc.policyStatement, tc.asn)
// Configure BGP default import export policy on Port1
configureBGPDefaultImportExportPolicy(t, dut, atePort1.IPv4, atePort1.IPv6, tc.defPolicyPort1)
// Configure BGP default import export policy on Port2
configureBGPDefaultImportExportPolicy(t, dut, atePort2.IPv4, atePort2.IPv6, tc.defPolicyPort2)
if !deviations.DefaultRoutePolicyUnsupported(dut) {
// Configure BGP default import export policy on Port1
configureBGPDefaultImportExportPolicy(t, dut, atePort1.IPv4, atePort1.IPv6, tc.defPolicyPort1)
// Configure BGP default import export policy on Port2
configureBGPDefaultImportExportPolicy(t, dut, atePort2.IPv4, atePort2.IPv6, tc.defPolicyPort2)
} else {
if tc.rpPolicy == setLocalPrefPolicy {
tc.policyTypePort2 = setLocalPrefPolicy
// when default policy is not configured on port2 ebgp configuration is needed for setLocalPrefPolicy
t.Logf("Configuring BGP import export policy on Port2 when default policy is not configured for %v", tc.rpPolicy)
configureBGPImportExportPolicy(t, dut, atePort2.IPv4, atePort2.IPv6, tc.rpPolicy)
}
}
// Configure BGP import export policy
configureBGPImportExportPolicy(t, dut, tc.polNbrv4, tc.polNbrv6, tc.rpPolicy)

Expand Down Expand Up @@ -756,11 +778,26 @@ func validateImportRoutingPolicy(t *testing.T, dut *ondatra.DUTDevice, prefix st
if prefixAddr[0] == prefix {
found = true
t.Logf("Found Route(prefix %s, origin: %v, pathid: %d) => %s", k.Prefix, k.Origin, k.PathId, lr.GetPrefix())
attrSet := gnmi.Get[*oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet](t, dut, bgpRIBPath.AttrSet(lr.GetAttrIndex()).State())
if attrSet == nil || attrSet.GetLocalPref() != metricValue {
t.Errorf("No local pref found for prefix %s", prefix)
if !deviations.SkipCheckingAttributeIndex(dut) {
attrSet := gnmi.Get[*oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet](t, dut, bgpRIBPath.AttrSet(lr.GetAttrIndex()).State())
if attrSet == nil || attrSet.GetLocalPref() != metricValue {
t.Errorf("No local pref found for prefix %s", prefix)
}
break
} else {
attrSetList := gnmi.GetAll[*oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet](t, dut, bgpRIBPath.AttrSetAny().State())
foundLP := false
for _, attrSet := range attrSetList {
if attrSet.GetLocalPref() == metricValue {
foundLP = true
t.Logf("Found local pref %d for prefix %s", attrSet.GetLocalPref(), prefix)
break
}
}
if !foundLP {
t.Errorf("No local pref found for prefix %s", prefix)
}
}
break
}
}

Expand All @@ -779,11 +816,26 @@ func validateImportRoutingPolicyV6(t *testing.T, dut *ondatra.DUTDevice, prefix
if prefixAddr[0] == prefix {
found = true
t.Logf("Found Route(prefix %s, origin: %v, pathid: %d) => %s", k.Prefix, k.Origin, k.PathId, lr.GetPrefix())
attrSet := gnmi.Get[*oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet](t, dut, bgpRIBPath.AttrSet(lr.GetAttrIndex()).State())
if attrSet == nil || attrSet.GetLocalPref() != metricValue {
t.Errorf("No local pref found for prefix %s", prefix)
if !deviations.SkipCheckingAttributeIndex(dut) {
attrSet := gnmi.Get[*oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet](t, dut, bgpRIBPath.AttrSet(lr.GetAttrIndex()).State())
if attrSet == nil || attrSet.GetLocalPref() != metricValue {
t.Errorf("No local pref found for prefix %s", prefix)
}
break
} else {
attrSetList := gnmi.GetAll[*oc.NetworkInstance_Protocol_Bgp_Rib_AttrSet](t, dut, bgpRIBPath.AttrSetAny().State())
foundLP := false
for _, attrSet := range attrSetList {
if attrSet.GetLocalPref() == metricValue {
foundLP = true
t.Logf("Found local pref %d for prefix %s", attrSet.GetLocalPref(), prefix)
break
}
}
if !foundLP {
t.Errorf("No local pref found for prefix %s", prefix)
}
}
break
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ platform_exceptions: {
deviations: {
ipv4_missing_enabled: true
prepolicy_received_routes: true
default_route_policy_unsupported: true
skip_checking_attribute_index: true
skip_setting_statement_for_policy: true
}
}
platform_exceptions: {
Expand Down
5 changes: 5 additions & 0 deletions internal/deviations/deviations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,3 +1013,8 @@ func SkipCheckingAttributeIndex(dut *ondatra.DUTDevice) bool {
func FlattenPolicyWithMultipleStatements(dut *ondatra.DUTDevice) bool {
return lookupDUTDeviations(dut).GetFlattenPolicyWithMultipleStatements()
}

// DefaultRoutePolicyUnsupported returns true if default route policy is not supported
func DefaultRoutePolicyUnsupported(dut *ondatra.DUTDevice) bool {
return lookupDUTDeviations(dut).GetDefaultRoutePolicyUnsupported()
}
3 changes: 3 additions & 0 deletions proto/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ message Metadata {
// with multiple statements.
// CISCO: b/338526243
bool flatten_policy_with_multiple_statements = 189;
// default_route_policy_unsupported is set to true for devices that do not
// support default route policy.
bool default_route_policy_unsupported = 190;

// Reserved field numbers and identifiers.
reserved 84, 9, 28, 20, 90, 97, 55, 89, 19;
Expand Down
Loading

0 comments on commit 5aa62e6

Please sign in to comment.