Skip to content

Commit

Permalink
<RT-1.2>Set MED and configure BGP policy (openconfig#2634)
Browse files Browse the repository at this point in the history
* set MED

* Run go fmt
  • Loading branch information
cfernanz authored Feb 6, 2024
1 parent 4590011 commit 1139171
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1139171

Please sign in to comment.