Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RT 7.4 aspath_and_community_test.go #3607

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package aspath_and_community_test

import (
"context"
"fmt"
"strconv"
"testing"
Expand All @@ -26,19 +27,22 @@ import (
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/featureprofiles/internal/helpers"
"github.com/openconfig/featureprofiles/internal/otgutils"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
)

const (
prefixV4Len = 30
prefixV6Len = 126
trafficPps = 100
totalPackets = 1200
bgpName = "BGP"
ImpPolicy = "routing-policy-ASPATH-COMMUNITY"
RPLPermitAll = "PERMIT-ALL"
prefixV4Len = 30
prefixV6Len = 126
trafficPps = 100
totalPackets = 1200
bgpName = "BGP"
ImpPolicy = "routing-policy-ASPATH-COMMUNITY"
RPLPermitAll = "PERMIT-ALL"
communitySetName = "any_my_3_comms"
aspathSetName = "any_my_aspath"
)

var prefixesV4 = [][]string{
Expand All @@ -61,7 +65,7 @@ func TestMain(m *testing.M) {
fptest.RunTests(m)
}

func configureImportBGPPolicy(t *testing.T, dut *ondatra.DUTDevice, ipv4 string, ipv6 string, aspathMatch []string, communityMatch string, aspathSetName string, communitySetName string, commMatchSetOptions oc.E_BgpPolicy_MatchSetOptionsType, aspMatchSetOptions oc.E_RoutingPolicy_MatchSetOptionsType) {
func configureImportBGPPolicy(t *testing.T, dut *ondatra.DUTDevice, ipv4, ipv6 string, aspathMatch []string, communityMatch, aspathSetName, communitySetName string, commMatchSetOptions, aspMatchSetOptions oc.E_RoutingPolicy_MatchSetOptionsType) {
root := &oc.Root{}
rp := root.GetOrCreateRoutingPolicy()
pdef1 := rp.GetOrCreatePolicyDefinition(ImpPolicy)
Expand All @@ -73,10 +77,15 @@ func configureImportBGPPolicy(t *testing.T, dut *ondatra.DUTDevice, ipv4 string,
stmt1.GetOrCreateActions().SetPolicyResult(oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE)
}

aspathSet := rp.GetOrCreateDefinedSets().GetOrCreateBgpDefinedSets().GetOrCreateAsPathSet(aspathSetName)
aspathSet.SetAsPathSetMember(aspathMatch)
stmt1.GetOrCreateConditions().GetOrCreateBgpConditions().GetOrCreateMatchAsPathSet().SetAsPathSet(aspathSetName)
stmt1.GetOrCreateConditions().GetOrCreateBgpConditions().GetOrCreateMatchAsPathSet().SetMatchSetOptions(aspMatchSetOptions)
if !deviations.BgpAspathsetUnsupported(dut) {
aspathSet := rp.GetOrCreateDefinedSets().GetOrCreateBgpDefinedSets().GetOrCreateAsPathSet(aspathSetName)
aspathSet.SetAsPathSetMember(aspathMatch)
stmt1.GetOrCreateConditions().GetOrCreateBgpConditions().GetOrCreateMatchAsPathSet().SetAsPathSet(aspathSetName)
stmt1.GetOrCreateConditions().GetOrCreateBgpConditions().GetOrCreateMatchAsPathSet().SetMatchSetOptions(aspMatchSetOptions)
} else {
configureAsPolicy(t, dut)
}

pdAllow := rp.GetOrCreatePolicyDefinition(RPLPermitAll)
st, err := pdAllow.AppendNewStatement("id-1")
if err != nil {
Expand All @@ -100,7 +109,6 @@ func configureImportBGPPolicy(t *testing.T, dut *ondatra.DUTDevice, ipv4 string,
cs = append(cs, oc.UnionString(communityMatch))
}
communitySet.SetCommunityMember(cs)
communitySet.SetMatchSetOptions(commMatchSetOptions)
}

var communitySetCLIConfig string
Expand All @@ -118,6 +126,7 @@ func configureImportBGPPolicy(t *testing.T, dut *ondatra.DUTDevice, ipv4 string,
stmt1.GetOrCreateConditions().GetOrCreateBgpConditions().SetCommunitySet(communitySetName)
} else {
stmt1.GetOrCreateConditions().GetOrCreateBgpConditions().GetOrCreateMatchCommunitySet().SetCommunitySet(communitySetName)
stmt1.GetOrCreateConditions().GetOrCreateBgpConditions().GetOrCreateMatchCommunitySet().SetMatchSetOptions(commMatchSetOptions)
}

if deviations.CommunityMemberRegexUnsupported(dut) && communitySetName == "any_my_3_comms" {
Expand All @@ -144,13 +153,67 @@ func configureImportBGPPolicy(t *testing.T, dut *ondatra.DUTDevice, ipv4 string,
gnmi.Replace(t, dut, pathV4.Config(), policyV4)
}

// configureAsPolicy is used to configure vendor specific config statement.
func configureAsPolicy(t *testing.T, dut *ondatra.DUTDevice) {
t.Helper()
var config string
gnmiClient := dut.RawAPIs().GNMI(t)

switch dut.Vendor() {
case ondatra.JUNIPER:
config = juniperCLI()
t.Logf("Push the CLI config:%s", dut.Vendor())
}

gpbSetRequest, err := buildCliConfigRequest(config)
if err != nil {
t.Fatalf("Cannot build a gNMI SetRequest: %v", err)
}

if _, err = gnmiClient.Set(context.Background(), gpbSetRequest); err != nil {
t.Fatalf("gnmiClient.Set() with unexpected error: %v", err)
}
}

// Build config with Origin set to cli and Ascii encoded config.
func buildCliConfigRequest(config string) (*gpb.SetRequest, error) {
gpbSetRequest := &gpb.SetRequest{
Update: []*gpb.Update{{
Path: &gpb.Path{
Origin: "cli",
Elem: []*gpb.PathElem{},
},
Val: &gpb.TypedValue{
Value: &gpb.TypedValue_AsciiVal{
AsciiVal: config,
},
},
}},
}
return gpbSetRequest, nil
}

// juniperCLI returns Juniper CLI config statement.
func juniperCLI() string {
return fmt.Sprintf(`
policy-options {
policy-statement %s {
term match_as_and_community {
from as-path %s;
then accept;
}
}
as-path %s ".*([100-109]|200)+.*";
}`, ImpPolicy, aspathSetName, aspathSetName)
}

func configureOTG(t *testing.T, bs *cfgplugins.BGPSession, prefixesV4 [][]string, prefixesV6 [][]string) {
var communityMembers = [][][]int{
{
{100, 1}, {200, 2}, {300, 3},
},
{
{100, 1},
{101, 1},
},
{
{109, 1},
Expand Down Expand Up @@ -285,9 +348,7 @@ func TestCommunitySet(t *testing.T) {
ipv6 := bs.ATETop.Devices().Items()[1].Ethernets().Items()[0].Ipv6Addresses().Items()[0].Address()
aspathMatch := []string{"(10[0-9]|200)"}
communityMatch := "(10[0-9]:1)"
communitySetName := "any_my_3_comms"
aspathSetName := "any_my_aspath"
commMatchSetOptions := oc.BgpPolicy_MatchSetOptionsType_ANY
commMatchSetOptions := oc.RoutingPolicy_MatchSetOptionsType_ANY
aspMatchSetOptions := oc.RoutingPolicy_MatchSetOptionsType_ANY
configureImportBGPPolicy(t, bs.DUT, ipv4, ipv6, aspathMatch, communityMatch, aspathSetName, communitySetName, commMatchSetOptions, aspMatchSetOptions)
sleepTime := time.Duration(totalPackets/trafficPps) + 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ platform_exceptions: {
}
}

platform_exceptions: {
platform: {
vendor: JUNIPER
}
deviations: {
bgp_aspathset_unsupported: true
}
}
5 changes: 5 additions & 0 deletions internal/deviations/deviations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,8 @@ func OTNChannelAssignmentCiscoNumbering(dut *ondatra.DUTDevice) bool {
func CiscoPreFECBERInactiveValue(dut *ondatra.DUTDevice) bool {
return lookupDUTDeviations(dut).GetCiscoPreFecBerInactiveValue()
}

// BgpAspathsetUnsupported returns true if as-path-set for bgp-defined-sets is unsupported
func BgpAspathsetUnsupported(dut *ondatra.DUTDevice) bool {
return lookupDUTDeviations(dut).GetBgpAspathsetUnsupported()
}
4 changes: 4 additions & 0 deletions proto/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ 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;
// bgp_aspathset_unsupported is set to true for devices that do not support as-path-set for bgp-defined-sets.
// Juniper: b/330173167
bool bgp_aspathset_unsupported = 234;

// Reserved field numbers and identifiers.
reserved 84, 9, 28, 20, 90, 97, 55, 89, 19, 36, 35, 40, 173;
}
Expand Down
98 changes: 56 additions & 42 deletions proto/metadata_go_proto/metadata.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading