Skip to content

Commit

Permalink
RT-1.32 : actions_MED_LocPref_prepend_flow_control_test.go (#2767)
Browse files Browse the repository at this point in the history
* updated RT-1.32

* resolving conflicts

* Fixing go static error

* Resolving conflicts

* Resolving conflicts

* Changed folder name as per latest git commit

* updating with git copy of README

* Resolving conflicts

* Resolving conflicts

* updated

* updating deviations

* resolving conflicts

* Resvoling conflicts

* resolving conflicts

* Added verification for setmedincrease policy

* updated verification

* Resolving conflicts

* resoving conflicts

* Resolving conflicts

* Resolving commit

* resolving conflicts

* REsolving conflicts

* removed space

* updated with native cli

* resolving conflicts

* Update deviations.go

* Update deviations.go

* Update deviations.go

* Update metadata.pb.go

* Update metadata.pb.go

* Update actions_MED_LocPref_prepend_flow_control_test.go

* Update metadata.textproto

* Update metadata.textproto

* Update deviations.go

* Update metadata.proto

* Update metadata.pb.go

* regenerated proto stubs

* REsolving conflicts

* Resolving conflicts

* Update internal/deviations/deviations.go

Co-authored-by: Darren Loher <[email protected]>

* updating comments

* REsolving erros

* updating comment

* updating review comment

---------

Co-authored-by: Swetha-haridasula <[email protected]>
Co-authored-by: Nisha Sadhasivam <[email protected]>
Co-authored-by: Pramod Maurya <[email protected]>
Co-authored-by: Darren Loher <[email protected]>
  • Loading branch information
5 people authored Dec 23, 2024
1 parent 1d3aa0f commit 6c2fef6
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package actions_med_localpref_prepend_flow_control_test

import (
"fmt"
"strconv"
"strings"
"testing"
Expand All @@ -25,6 +26,7 @@ import (
"github.com/openconfig/featureprofiles/internal/attrs"
"github.com/openconfig/featureprofiles/internal/deviations"
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/featureprofiles/internal/helpers"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
Expand All @@ -40,12 +42,12 @@ func TestMain(m *testing.M) {
}

const (
advertisedRoutesv4Net1 = "192.168.10.0"
advertisedRoutesv6Net1 = "2024:db8:128:128::"
advertisedRoutesv4Net2 = "192.168.20.0"
advertisedRoutesv6Net2 = "2024:db8:64:64::"
advertisedRoutesv4PrefixLen = 24
advertisedRoutesv6PrefixLen = 64
advertisedRoutesv4Net1 = "192.168.10.1"
advertisedRoutesv6Net1 = "2024:db8:128:128::1"
advertisedRoutesv4Net2 = "192.168.20.1"
advertisedRoutesv6Net2 = "2024:db8:64:64::1"
advertisedRoutesv4PrefixLen = 32
advertisedRoutesv6PrefixLen = 128
dutAS = 64500
ateAS = 64501
plenIPv4 = 30
Expand Down Expand Up @@ -209,6 +211,24 @@ func VerifyBgpState(t *testing.T, dut *ondatra.DUTDevice) {
t.Log("BGP sessions Established")
}

// juniperBgpPolicyMEDAdd is used to configure set metric add via native cli as an alternative for below xpath.
// routing-policy/policy-definitions/policy-definition/statements/statement/actions/bgp-actions/config/set-med
func juniperBgpPolicyMEDAdd(polName string, metric int) string {
return fmt.Sprintf(`
policy-options {
policy-statement %s {
term 1 {
then {
metric add %d;
}
}
term 2 {
then accept;
}
}
}`, polName, metric)
}

// configureASLocalPrefMEDPolicy configures MED, Local Pref, AS prepend etc
func configureASLocalPrefMEDPolicy(t *testing.T, dut *ondatra.DUTDevice, policyType, policyValue, statement string, ASN uint32) {
t.Helper()
Expand All @@ -228,12 +248,25 @@ func configureASLocalPrefMEDPolicy(t *testing.T, dut *ondatra.DUTDevice, policyT
actions.PolicyResult = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE
case setMEDPolicy:
if strings.Contains(policyValue, "+") {
actions.GetOrCreateBgpActions().SetMed = oc.UnionString(policyValue)
if deviations.BgpSetMedV7Unsupported(dut) {
t.Logf("Push the CLI config:%s", dut.Vendor())
metric, _ := strconv.Atoi(policyValue)
switch dut.Vendor() {
case ondatra.JUNIPER:
config := juniperBgpPolicyMEDAdd(setMEDPolicy, metric)
helpers.GnmiCLIConfig(t, dut, config)
default:
t.Fatalf("BgpSetMedV7Unsupported deviation needs cli configuration for vendor %s which is not defined", dut.Vendor())
}
} else {
actions.GetOrCreateBgpActions().SetMed = oc.UnionString(policyValue)
actions.PolicyResult = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE
}
} else {
metric, _ := strconv.Atoi(policyValue)
actions.GetOrCreateBgpActions().SetMed = oc.UnionUint32(uint32(metric))
actions.PolicyResult = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE
}
actions.PolicyResult = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE
case setPrependPolicy:
metric, _ := strconv.Atoi(policyValue)
asPrepend := actions.GetOrCreateBgpActions().GetOrCreateSetAsPathPrepend()
Expand Down Expand Up @@ -298,15 +331,13 @@ func deleteBGPImportExportPolicy(t *testing.T, dut *ondatra.DUTDevice, ipv4, ipv
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())
}
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 Down Expand Up @@ -445,6 +476,7 @@ func configureOTG(t *testing.T, otg *otg.OTG) gosnappi.Config {
t.Logf("Pushing config to ATE and starting protocols...")
otg.PushConfig(t, config)
otg.StartProtocols(t)

return config
}

Expand All @@ -454,7 +486,7 @@ func validateOTGBgpPrefixV4AndASLocalPrefMED(t *testing.T, otg *otg.OTG, dut *on
_, ok := gnmi.WatchAll(t,
otg,
gnmi.OTG().BgpPeer(peerName).UnicastIpv4PrefixAny().State(),
30*time.Second,
60*time.Second,
func(v *ygnmi.Value[*otgtelemetry.BgpPeer_UnicastIpv4Prefix]) bool {
_, present := v.Val()
return present
Expand All @@ -466,7 +498,7 @@ func validateOTGBgpPrefixV4AndASLocalPrefMED(t *testing.T, otg *otg.OTG, dut *on
if bgpPrefix.Address != nil && bgpPrefix.GetAddress() == ipAddr &&
bgpPrefix.PrefixLength != nil && bgpPrefix.GetPrefixLength() == prefixLen {
foundPrefix = true
t.Logf("Prefix recevied on OTG is correct, got prefix %v, want prefix %v", bgpPrefix, ipAddr)
t.Logf("Prefix recevied on OTG is correct, got prefix %v, want prefix %v", bgpPrefix.GetAddress(), ipAddr)
switch pathAttr {
case setMEDPolicy:
if bgpPrefix.GetMultiExitDiscriminator() != metric {
Expand All @@ -475,12 +507,14 @@ func validateOTGBgpPrefixV4AndASLocalPrefMED(t *testing.T, otg *otg.OTG, dut *on
t.Logf("For Prefix %v, got MED %d want MED %d", bgpPrefix.GetAddress(), bgpPrefix.GetMultiExitDiscriminator(), metric)
}
case setLocalPrefPolicy:
validateImportRoutingPolicy(t, dut, ipAddr, metric)
if !deviations.BGPRibOcPathUnsupported(dut) {
validateImportRoutingPolicy(t, dut, ipAddr, metric)
}
case setPrependPolicy:
if len(bgpPrefix.AsPath[0].GetAsNumbers()) != int(metric) {
t.Errorf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath[0].GetAsNumbers()), int(metric))
} else {
t.Logf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath), int(metric))
t.Logf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath[0].GetAsNumbers()), int(metric))
}
case setNxtPolicy:
if bgpPrefix.GetMultiExitDiscriminator() != metric {
Expand All @@ -491,7 +525,7 @@ func validateOTGBgpPrefixV4AndASLocalPrefMED(t *testing.T, otg *otg.OTG, dut *on
if len(bgpPrefix.AsPath[0].GetAsNumbers()) != asnRepeatN+1 {
t.Errorf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath[0].GetAsNumbers()), asnRepeatN+1)
} else {
t.Logf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath), asnRepeatN+1)
t.Logf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath[0].GetAsNumbers()), asnRepeatN+1)
}
default:
t.Errorf("Incorrect BGP Path Attribute. Expected MED, Local Pref or AS Path Prepend!!!!")
Expand All @@ -511,7 +545,7 @@ func validateOTGBgpPrefixV6AndASLocalPrefMED(t *testing.T, otg *otg.OTG, dut *on
_, ok := gnmi.WatchAll(t,
otg,
gnmi.OTG().BgpPeer(peerName).UnicastIpv6PrefixAny().State(),
30*time.Second,
60*time.Second,
func(v *ygnmi.Value[*otgtelemetry.BgpPeer_UnicastIpv6Prefix]) bool {
_, present := v.Val()
return present
Expand All @@ -523,7 +557,7 @@ func validateOTGBgpPrefixV6AndASLocalPrefMED(t *testing.T, otg *otg.OTG, dut *on
if bgpPrefix.Address != nil && bgpPrefix.GetAddress() == ipAddr &&
bgpPrefix.PrefixLength != nil && bgpPrefix.GetPrefixLength() == prefixLen {
foundPrefix = true
t.Logf("Prefix recevied on OTG is correct, got prefix %v, want prefix %v", bgpPrefix, ipAddr)
t.Logf("Prefix recevied on OTG is correct, got prefix %v, want prefix %v", bgpPrefix.GetAddress(), ipAddr)
switch pathAttr {
case setMEDPolicy:
if bgpPrefix.GetMultiExitDiscriminator() != metric {
Expand All @@ -532,12 +566,14 @@ func validateOTGBgpPrefixV6AndASLocalPrefMED(t *testing.T, otg *otg.OTG, dut *on
t.Logf("For Prefix %v, got MED %d want MED %d", bgpPrefix.GetAddress(), bgpPrefix.GetMultiExitDiscriminator(), metric)
}
case setLocalPrefPolicy:
validateImportRoutingPolicyV6(t, dut, ipAddr, metric)
if !deviations.BGPRibOcPathUnsupported(dut) {
validateImportRoutingPolicyV6(t, dut, ipAddr, metric)
}
case setPrependPolicy:
if len(bgpPrefix.AsPath[0].GetAsNumbers()) != int(metric) {
t.Errorf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath[0].GetAsNumbers()), int(metric))
} else {
t.Logf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath), int(metric))
t.Logf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath[0].GetAsNumbers()), int(metric))
}
case setNxtPolicy:
if bgpPrefix.GetMultiExitDiscriminator() != metric {
Expand All @@ -548,7 +584,7 @@ func validateOTGBgpPrefixV6AndASLocalPrefMED(t *testing.T, otg *otg.OTG, dut *on
if len(bgpPrefix.AsPath[0].GetAsNumbers()) != asnRepeatN+1 {
t.Errorf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath[0].GetAsNumbers()), asnRepeatN+1)
} else {
t.Logf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath), asnRepeatN+1)
t.Logf("For Prefix %v, got AS Path Prepend %d want AS Path Prepend %d", bgpPrefix.GetAddress(), len(bgpPrefix.AsPath[0].GetAsNumbers()), asnRepeatN+1)
}
default:
t.Errorf("Incorrect Routing Policy. Expected MED, Local Pref or AS Path Prepend!!!!")
Expand Down Expand Up @@ -735,6 +771,7 @@ func TestBGPPolicy(t *testing.T) {
if tc.isDeletePolicy {
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)
if !deviations.DefaultRoutePolicyUnsupported(dut) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ platform_exceptions: {
skip_setting_statement_for_policy: true
}
}
platform_exceptions: {
platform: {
vendor: JUNIPER
}
deviations: {
bgp_rib_oc_path_unsupported: true
bgp_set_med_v7_unsupported: true
}
}
platform_exceptions: {
platform: {
vendor: NOKIA
Expand Down
6 changes: 6 additions & 0 deletions internal/deviations/deviations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1258,3 +1258,9 @@ func IsisDisSysidUnsupported(dut *ondatra.DUTDevice) bool {
func IsisDatabaseOverloadsUnsupported(dut *ondatra.DUTDevice) bool {
return lookupDUTDeviations(dut).GetIsisDatabaseOverloadsUnsupported()
}

// BgpSetMedV7Unsupported returns true if devices which are not
// supporting bgp set med union type in OC.
func BgpSetMedV7Unsupported(dut *ondatra.DUTDevice) bool {
return lookupDUTDeviations(dut).GetBgpSetMedV7Unsupported()
}
4 changes: 4 additions & 0 deletions proto/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,10 @@ message Metadata {
bool isis_dis_sysid_unsupported = 239;
// Cisco: b/378616912
bool isis_database_overloads_unsupported = 240;
// Juniper: b/358534837
// Devices that do not support setting med value using union type in OC.
bool bgp_set_med_v7_unsupported = 241;

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

0 comments on commit 6c2fef6

Please sign in to comment.