Skip to content

Commit

Permalink
Add/Replace prefix-set test scenarios (#3308)
Browse files Browse the repository at this point in the history
* Add/Replace prefix-set test scenarios

* move readme to correct directory

* fixed CI checks

* ci check fix
  • Loading branch information
self-maurya authored Jul 19, 2024
1 parent 3d2410a commit 502ee20
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
For each section of configuration below, prepare a gnmi.SetBatch with all the configuration items appended to one SetBatch. Then apply the configuration to the DUT in one gnmi.Set using the `replace` option

### RT-1.53.1 [TODO:https://github.com/openconfig/featureprofiles/issues/3306]
#### Validate that a prefix list can be created correctly
#### Create a prefix-set with 2 prefixes
* Create a prefix-set with name "prefix-set-a"
* /routing-policy/defined-sets/prefix-sets/prefix-set/config/name
* Set the mode to IPv4
Expand All @@ -30,7 +30,7 @@ For each section of configuration below, prepare a gnmi.SetBatch with all the c
* /routing-policy/defined-sets/prefix-sets/prefix-set/prefixes/prefix/state/masklength-range

### RT-1.53.2 [TODO:https://github.com/openconfig/featureprofiles/issues/3306]
#### Validate that a prefix list can be replaced correctly
#### Replace the prefix-set by replacing an existing prefix with new prefix
* Define two prefixes 10.240.31.48/28 and 173.36.144.0/20 with mask "exact"
* /routing-policy/defined-sets/prefix-sets/prefix-set/prefixes/prefix/config/ip-prefix
* /routing-policy/defined-sets/prefix-sets/prefix-set/prefixes/prefix/config/masklength-range
Expand All @@ -42,7 +42,7 @@ For each section of configuration below, prepare a gnmi.SetBatch with all the c
* /routing-policy/defined-sets/prefix-sets/prefix-set/prefixes/prefix/state/masklength-range

### RT-1.53.3 [TODO:https://github.com/openconfig/featureprofiles/issues/3306]
#### Validate that a prefix list can be updated correctly
### Replace the prefix-set with 2 existing and a new prR
* Define three prefixes 10.240.31.48/28, 10.240.31.64/28 and 173.36.144.0/20 with mask "exact"
* /routing-policy/defined-sets/prefix-sets/prefix-set/prefixes/prefix/config/ip-prefix
* /routing-policy/defined-sets/prefix-sets/prefix-set/prefixes/prefix/config/masklength-range
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# proto-file: github.com/openconfig/featureprofiles/proto/metadata.proto
# proto-message: Metadata

uuid: "619040ac-21a0-403f-b38e-6d5d0aed433a"
plan_id: "RT-1.53"
description: "prefix-list test"
testbed: TESTBED_DUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package prefix_set_test

import (
"testing"

"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
)

const (
prefixSetA = "PFX_SET_A"
pfx1 = "10.240.31.48/28"
pfx2 = "173.36.128.0/20"
pfx3 = "173.36.144.0/20"
pfx4 = "10.240.31.64/28"
mskLen = "exact"
)

func TestMain(m *testing.M) {
fptest.RunTests(m)
}

func TestPrefixSet(t *testing.T) {
dut := ondatra.DUT(t, "dut")

dutOcRoot := &oc.Root{}
rp := dutOcRoot.GetOrCreateRoutingPolicy()
ds := rp.GetOrCreateDefinedSets()

// create a prefix-set with 2 prefixes
v4PrefixSet := ds.GetOrCreatePrefixSet(prefixSetA)
v4PrefixSet.SetMode(oc.PrefixSet_Mode_IPV4)
v4PrefixSet.GetOrCreatePrefix(pfx1, mskLen)
v4PrefixSet.GetOrCreatePrefix(pfx2, mskLen)

gnmi.Replace(t, dut, gnmi.OC().RoutingPolicy().DefinedSets().PrefixSet(prefixSetA).Config(), v4PrefixSet)
prefixSet := gnmi.Get[*oc.RoutingPolicy_DefinedSets_PrefixSet](t, dut, gnmi.OC().RoutingPolicy().DefinedSets().PrefixSet(prefixSetA).State())
if len(prefixSet.Prefix) != 2 {
t.Errorf("Prefix set has %v prefixes, want 2", len(prefixSet.Prefix))
}
for _, pfx := range []string{pfx1, pfx2} {
if x := prefixSet.GetPrefix(pfx, mskLen); x == nil {
t.Errorf("%s not found in prefix-set %s", pfx, prefixSetA)
}
}

// replace the prefix-set by replacing an existing prefix with new prefix
v4PrefixSet = ds.GetOrCreatePrefixSet(prefixSetA)
v4PrefixSet.SetMode(oc.PrefixSet_Mode_IPV4)
v4PrefixSet.GetOrCreatePrefix(pfx1, mskLen)
v4PrefixSet.GetOrCreatePrefix(pfx3, mskLen)

gnmi.Replace(t, dut, gnmi.OC().RoutingPolicy().DefinedSets().PrefixSet(prefixSetA).Config(), v4PrefixSet)
prefixSet = gnmi.Get[*oc.RoutingPolicy_DefinedSets_PrefixSet](t, dut, gnmi.OC().RoutingPolicy().DefinedSets().PrefixSet(prefixSetA).State())
if len(prefixSet.Prefix) != 2 {
t.Errorf("Prefix set has %v prefixes, want 2", len(prefixSet.Prefix))
}
for _, pfx := range []string{pfx1, pfx3} {
if x := prefixSet.GetPrefix(pfx, mskLen); x == nil {
t.Errorf("%s not found in prefix-set %s", pfx, prefixSetA)
}
}

// replace the prefix-set with 2 existing and a new prefix
v4PrefixSet = ds.GetOrCreatePrefixSet(prefixSetA)
v4PrefixSet.SetMode(oc.PrefixSet_Mode_IPV4)
v4PrefixSet.GetOrCreatePrefix(pfx1, mskLen)
v4PrefixSet.GetOrCreatePrefix(pfx3, mskLen)
v4PrefixSet.GetOrCreatePrefix(pfx4, mskLen)

gnmi.Replace(t, dut, gnmi.OC().RoutingPolicy().DefinedSets().PrefixSet(prefixSetA).Config(), v4PrefixSet)
prefixSet = gnmi.Get[*oc.RoutingPolicy_DefinedSets_PrefixSet](t, dut, gnmi.OC().RoutingPolicy().DefinedSets().PrefixSet(prefixSetA).State())
if len(prefixSet.Prefix) != 3 {
t.Errorf("Prefix set has %v prefixes, want 3", len(prefixSet.Prefix))
}
for _, pfx := range []string{pfx1, pfx3, pfx4} {
if x := prefixSet.GetPrefix(pfx, mskLen); x == nil {
t.Errorf("%s not found in prefix-set %s", pfx, prefixSetA)
}
}
}

0 comments on commit 502ee20

Please sign in to comment.