From 1139171167f376654217968747d632f1baae2f3b Mon Sep 17 00:00:00 2001 From: Calvin F <131898783+cfernanz@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:28:00 -0800 Subject: [PATCH] Set MED and configure BGP policy (#2634) * set MED * Run go fmt --- .../route_installation_test/README.md | 2 +- .../route_installation_test.go | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/feature/bgp/policybase/otg_tests/route_installation_test/README.md b/feature/bgp/policybase/otg_tests/route_installation_test/README.md index 7f9d7800334..537844a7399 100644 --- a/feature/bgp/policybase/otg_tests/route_installation_test/README.md +++ b/feature/bgp/policybase/otg_tests/route_installation_test/README.md @@ -15,7 +15,7 @@ Base BGP policy configuration and route installation. * Default accept for policies. * Default deny for policies. * Explicitly specifying local preference. - * TODO: Explicitly specifying MED value. + * Explicitly specifying MED value. * Explicitly prepending AS for advertisement with a specified AS number. * Validate that traffic can be forwarded to **all** installed routes diff --git a/feature/bgp/policybase/otg_tests/route_installation_test/route_installation_test.go b/feature/bgp/policybase/otg_tests/route_installation_test/route_installation_test.go index c4a588e2625..51b4ff15589 100644 --- a/feature/bgp/policybase/otg_tests/route_installation_test/route_installation_test.go +++ b/feature/bgp/policybase/otg_tests/route_installation_test/route_installation_test.go @@ -88,6 +88,8 @@ const ( acceptPolicy = "PERMIT-ALL" setLocalPrefPolicy = "SET-LOCAL-PREF" localPrefValue = 100 + setMEDPolicy = "SET-MED-PREF" + medValue = 100 setAspathPrependPolicy = "SET-ASPATH-PREPEND" asPathRepeatValue = 3 aclStatement1 = "10" @@ -230,7 +232,7 @@ func bgpCreateNbr(localAs, peerAs uint32, policy string, dut *ondatra.DUTDevice) } // configureBGPPolicy configures a BGP routing policy to accept or reject routes based on prefix match conditions -// Additonally, it configures LocalPreference and ASPathprepend as part of the BGP policy. +// Additionally, it configures LocalPreference, ASPathprepend and MED as part of the BGP policy. func configureBGPPolicy(d *oc.Root) (*oc.RoutingPolicy, error) { rp := d.GetOrCreateRoutingPolicy() pset := rp.GetOrCreateDefinedSets().GetOrCreatePrefixSet(prefixSet) @@ -282,6 +284,15 @@ func configureBGPPolicy(d *oc.Root) (*oc.RoutingPolicy, error) { aspend.RepeatN = ygot.Uint8(asPathRepeatValue) actions5.PolicyResult = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE + pdef6 := rp.GetOrCreatePolicyDefinition(setMEDPolicy) + stmt, err = pdef6.AppendNewStatement(aclStatement2) + if err != nil { + return nil, err + } + actions6 := stmt.GetOrCreateActions() + actions6.GetOrCreateBgpActions().SetMed = oc.UnionUint32(medValue) + actions6.PolicyResult = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE + return rp, nil } @@ -695,6 +706,13 @@ func TestBGPPolicy(t *testing.T) { received: routeCount, sent: 0, wantLoss: false, + }, { + desc: "Configure Set MED Policy", + policy: setMEDPolicy, + installed: routeCount, + received: routeCount, + sent: 0, + wantLoss: false, }} for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) {