diff --git a/feature/bgp/policybase/otg_tests/link_bandwidth_test/link_bandwidth_test.go b/feature/bgp/policybase/otg_tests/link_bandwidth_test/link_bandwidth_test.go index e240cd817d6..c7031776efc 100644 --- a/feature/bgp/policybase/otg_tests/link_bandwidth_test/link_bandwidth_test.go +++ b/feature/bgp/policybase/otg_tests/link_bandwidth_test/link_bandwidth_test.go @@ -114,13 +114,13 @@ var ( extCommunitySet = map[string]string{ "linkbw_1M": "link-bandwidth:23456:1M", "linkbw_2G": "link-bandwidth:23456:2G", - "linkbw_any": "^link-bandwidth:.*:.$", + "linkbw_any": "^link-bandwidth:.*:.*$", } extCommunitySetCisco = map[string]string{ "linkbw_1M": "23456:1000000", "linkbw_2G": "23456:2000000000", - "linkbw_any": "^.*:.$", + "linkbw_any": "^.*:.*$", } CommunitySet = map[string]string{ diff --git a/feature/isis/otg_tests/weighted_ecmp_test/README.md b/feature/isis/otg_tests/weighted_ecmp_test/README.md index dee5ca53f52..8a5bdf8448a 100644 --- a/feature/isis/otg_tests/weighted_ecmp_test/README.md +++ b/feature/isis/otg_tests/weighted_ecmp_test/README.md @@ -29,23 +29,25 @@ G[DUT:LAG4] <-- IBGP+IS-IS --> H[LAG3:ATE2]; ## Procedure -In the topology above, - -* Configure 1xLAG interface between ATE1<->DUT and 3xLAG interfaces between - DUT and ATE2. Each LAG interface is expected to be of 2x100Gbps - -* Configure IPv4 and IPv6 L2 adjacencies between DUT and ATE LAG bundles. - Therefore, DUT will have 1xIS-IS adjacency with ATE1 i.e. - DUT:LAG1<->ATE1:LAG1, and 3xIS-IS adjacencies with ATE2 i.e. - DUT:LAG2<->ATE2:LAG1, DUT:LAG3<->ATE2:LAG2 and DUT:LAG4<->ATE2:LAG3 - - * /network-instances/network-instance/protocols/protocol/isis/global/afi-safi - - * /network-instances/network-instance/protocols/protocol/isis/global/config/level-capability, - set to LEVEL_2 - - * /network-instances/network-instance/protocols/protocol/isis/levels/level/config/metric-style - set to WIDE_METRIC +### Test environment setup + +* Configure 1 aggregate interface with 2 100GE ports between DUT and ATE1 +* Configure 3 aggregate interfaces, each with 2 100GE ports between DUT and ATE2. +* Configure IPv4 and IPv6 L2 adjacencies between DUT and ATE aggregate interfaces. + Therefore, DUT will have + * 1xIS-IS adjacency with ATE1 DUT:LAG1<->ATE1:LAG1, + * 3xIS-IS adjacencies between DUT and ATE2 + * DUT:LAG2<->ATE2:LAG1 + * DUT:LAG3<->ATE2:LAG2 + * DUT:LAG4<->ATE2:LAG3 + + * Set ISIS parameters as + * /network-instances/network-instance/protocols/protocol/isis/global/ + * afi-safi/af/config/afi-name: IPV4, IPV6 + * afi-safi/af/config/safi-name: UNICAST + * afi-safi/af/config/enabled: true + * config/level-capability = LEVEL_2 + * /network-instances/network-instance/protocols/protocol/isis/levels/level/config/metric-style = WIDE_METRIC * Configure IPv4 and IPv6 IBGP peering between both ATEs and the DUT using their loopback addresses for both IPv4 and IPv6 address families. @@ -74,7 +76,7 @@ In the topology above, * /network-instances/network-instance/protocols/protocol/isis/interfaces/interface/weighted-ecmp/config/load-balancing-weight set to Auto -## RT-9.1: Equal distribution of traffic +## RT-2.13.1: Equal distribution of traffic * Start 1024 flows from IPv4 addresses in 100.0.2.0/24 to 100.0.1.0/24 @@ -114,7 +116,7 @@ In the topology above, * /interfaces/interface/state/counters/in-pkts -## RT-9.2: Unequal distribution of traffic +## RT-2.13.2: Unequal distribution of traffic * Stop traffic from RT-9.1 and introduce a failure by disabling one of the member interfaces in ATE2:LAG1. @@ -142,17 +144,8 @@ In the topology above, * /interfaces/interface/state/counters/in-pkts -### Config paths - -### Telemetry Parameter Coverage - ## OpenConfig Path and RPC Coverage -The below yaml defines the OC paths intended to be covered by this test. OC paths used for test setup are not listed here. - -TODO(OCPATH): Container path originally part of spec that needs to be separated -into leaves: /routing-policy/defined-sets/prefix-sets/prefix-set: - ```yaml paths: ## Config Paths ## diff --git a/feature/security/gnsi/acctz/tests/record_history_truncation/record_history_truncation_test.go b/feature/security/gnsi/acctz/tests/record_history_truncation/record_history_truncation_test.go index b034ac91b97..1c14c9ef1ab 100644 --- a/feature/security/gnsi/acctz/tests/record_history_truncation/record_history_truncation_test.go +++ b/feature/security/gnsi/acctz/tests/record_history_truncation/record_history_truncation_test.go @@ -20,7 +20,7 @@ import ( "time" "github.com/openconfig/featureprofiles/internal/fptest" - "github.com/openconfig/gnsi/acctz" + acctzpb "github.com/openconfig/gnsi/acctz" "github.com/openconfig/ondatra" "github.com/openconfig/ondatra/gnmi" "google.golang.org/protobuf/types/known/timestamppb" @@ -47,7 +47,7 @@ func TestAccountzRecordHistoryTruncation(t *testing.T) { t.Fatalf("Failed getting accountz record subscribe client, error: %s", err) } - err = acctzSubClient.Send(&acctz.RecordRequest{ + err = acctzSubClient.Send(&acctzpb.RecordRequest{ Timestamp: timestamppb.New(recordStartTime), }) if err != nil { diff --git a/feature/security/gnsi/acctz/tests/record_payload_truncation/record_payload_truncation_test.go b/feature/security/gnsi/acctz/tests/record_payload_truncation/record_payload_truncation_test.go index ec481d3d840..ae532753f6b 100644 --- a/feature/security/gnsi/acctz/tests/record_payload_truncation/record_payload_truncation_test.go +++ b/feature/security/gnsi/acctz/tests/record_payload_truncation/record_payload_truncation_test.go @@ -21,7 +21,7 @@ import ( "time" "github.com/openconfig/featureprofiles/internal/fptest" - "github.com/openconfig/gnsi/acctz" + acctzpb "github.com/openconfig/gnsi/acctz" "github.com/openconfig/ondatra" "github.com/openconfig/ondatra/gnmi" "github.com/openconfig/ondatra/gnmi/oc" @@ -33,7 +33,7 @@ func TestMain(m *testing.M) { } type recordRequestResult struct { - record *acctz.RecordResponse + record *acctzpb.RecordResponse err error } @@ -66,7 +66,7 @@ func TestAccountzRecordPayloadTruncation(t *testing.T) { t.Fatalf("Failed getting accountz record subscribe client, error: %s", err) } - err = acctzSubClient.Send(&acctz.RecordRequest{ + err = acctzSubClient.Send(&acctzpb.RecordRequest{ Timestamp: timestamppb.New(startTime), }) if err != nil { @@ -77,7 +77,7 @@ func TestAccountzRecordPayloadTruncation(t *testing.T) { r := make(chan recordRequestResult) go func(r chan recordRequestResult) { - var response *acctz.RecordResponse + var response *acctzpb.RecordResponse response, err = acctzSubClient.Recv() r <- recordRequestResult{ record: response, @@ -105,7 +105,7 @@ func TestAccountzRecordPayloadTruncation(t *testing.T) { grpcServiceRecord := resp.record.GetGrpcService() - if grpcServiceRecord.GetServiceType() != acctz.GrpcService_GRPC_SERVICE_TYPE_GNMI { + if grpcServiceRecord.GetServiceType() != acctzpb.GrpcService_GRPC_SERVICE_TYPE_GNMI { // Not our gnmi set, nothing to see here. continue } diff --git a/feature/security/gnsi/acctz/tests/record_subscribe_full/record_subscribe_full_test.go b/feature/security/gnsi/acctz/tests/record_subscribe_full/record_subscribe_full_test.go index b04bd0809d5..4c6e329f8d2 100644 --- a/feature/security/gnsi/acctz/tests/record_subscribe_full/record_subscribe_full_test.go +++ b/feature/security/gnsi/acctz/tests/record_subscribe_full/record_subscribe_full_test.go @@ -39,7 +39,7 @@ func TestMain(m *testing.M) { fptest.RunTests(m) } -func prettyPrint(i interface{}) string { +func prettyPrint(i any) string { s, _ := json.MarshalIndent(i, "", "\t") return string(s) } diff --git a/feature/security/gnsi/acctz/tests/record_subscribe_non_grpc/record_subscribe_non_grpc_test.go b/feature/security/gnsi/acctz/tests/record_subscribe_non_grpc/record_subscribe_non_grpc_test.go index 351f2792566..97812587dc9 100644 --- a/feature/security/gnsi/acctz/tests/record_subscribe_non_grpc/record_subscribe_non_grpc_test.go +++ b/feature/security/gnsi/acctz/tests/record_subscribe_non_grpc/record_subscribe_non_grpc_test.go @@ -39,7 +39,7 @@ func TestMain(m *testing.M) { fptest.RunTests(m) } -func prettyPrint(i interface{}) string { +func prettyPrint(i any) string { s, _ := json.MarshalIndent(i, "", "\t") return string(s) } diff --git a/feature/security/gnsi/acctz/tests/record_subscribe_partial/record_subscribe_partial_test.go b/feature/security/gnsi/acctz/tests/record_subscribe_partial/record_subscribe_partial_test.go index 94a32cd457b..136f2d3d7ad 100644 --- a/feature/security/gnsi/acctz/tests/record_subscribe_partial/record_subscribe_partial_test.go +++ b/feature/security/gnsi/acctz/tests/record_subscribe_partial/record_subscribe_partial_test.go @@ -40,7 +40,7 @@ func TestMain(m *testing.M) { fptest.RunTests(m) } -func prettyPrint(i interface{}) string { +func prettyPrint(i any) string { s, _ := json.MarshalIndent(i, "", "\t") return string(s) } diff --git a/feature/system/gnmi/metadata/tests/large_set_consistency_test/README.md b/feature/system/gnmi/metadata/tests/large_set_consistency_test/README.md index 51ac7dab893..e0b5b2ba32b 100644 --- a/feature/system/gnmi/metadata/tests/large_set_consistency_test/README.md +++ b/feature/system/gnmi/metadata/tests/large_set_consistency_test/README.md @@ -40,3 +40,13 @@ dut.testbed ## Minimum DUT platform FFF + +## OpenConfig Path and RPC Coverage + +```yaml +rpcs: + gnmi: + gNMI.Get: + gNMI.Subscribe: + +``` \ No newline at end of file diff --git a/feature/system/gnmi/metadata/tests/large_set_consistency_test/large_set_consistency_test.go b/feature/system/gnmi/metadata/tests/large_set_consistency_test/large_set_consistency_test.go index 84b7e7af943..5dbc85b2572 100644 --- a/feature/system/gnmi/metadata/tests/large_set_consistency_test/large_set_consistency_test.go +++ b/feature/system/gnmi/metadata/tests/large_set_consistency_test/large_set_consistency_test.go @@ -49,57 +49,6 @@ func TestMain(m *testing.M) { fptest.RunTests(m) } -// getDeviceConfig gets a full config from a device but refurbishes it enough so it can be -// pushed out again -func getDeviceConfig(t testing.TB, dev gnmi.DeviceOrOpts) *oc.Root { - config := gnmi.Get[*oc.Root](t, dev, gnmi.OC().Config()) - fptest.WriteQuery(t, "Untouched", gnmi.OC().Config(), config) - - for cname, component := range config.Component { - // Keep the port components in order to preserve the breakout-mode config. - if component.GetPort() == nil { - delete(config.Component, cname) - continue - } - // Need to prune subcomponents that may have a leafref to a component that was - // pruned. - component.Subcomponent = nil - } - - for iname, iface := range config.Interface { - if iface.GetEthernet() == nil { - continue - } - // Ethernet config may not contain meaningful values if it wasn't explicitly - // configured, so use its current state for the config, but prune non-config leaves. - intf := gnmi.Get(t, dev, gnmi.OC().Interface(iname).State()) - breakout := config.GetComponent(intf.GetHardwarePort()).GetPort().GetBreakoutMode() - e := intf.GetEthernet() - // Set port speed to unknown for non breakout interfaces - if breakout.GetGroup(1) == nil && e != nil { - e.SetPortSpeed(oc.IfEthernet_ETHERNET_SPEED_SPEED_UNKNOWN) - } - ygot.PruneConfigFalse(oc.SchemaTree["Interface_Ethernet"], e) - if e.PortSpeed != 0 && e.PortSpeed != oc.IfEthernet_ETHERNET_SPEED_SPEED_UNKNOWN { - iface.Ethernet = e - } - } - - if config.Lldp != nil { - config.Lldp.ChassisId = nil - config.Lldp.ChassisIdType = oc.Lldp_ChassisIdType_UNSET - } - - config.Qos = nil - - for _, ni := range config.NetworkInstance { - ni.Fdb = nil - } - - fptest.WriteQuery(t, "Touched", gnmi.OC().Config(), config) - return config -} - // setEthernetFromBase merges the ethernet config from the interfaces in base config into // the destination config. func setEthernetFromBase(t testing.TB, config *oc.Root) { @@ -244,8 +193,7 @@ func checkMetadata1(t *testing.T, gnmiClient gpb.GNMIClient, dut *ondatra.DUTDev t.Helper() got, getRespTimeStamp := extractMetadataAnnotation(t, gnmiClient, dut) want := metadata1 - t.Logf("getResp: %v ", getRespTimeStamp) - if got != want && done.Load() == 0 { + if got != want && getRespTimeStamp < done.Load() { t.Errorf("extractMetadataAnnotation: got %v, want %v", got, want) } } @@ -268,13 +216,15 @@ func TestLargeSetConsistency(t *testing.T) { p1 := dut.Port(t, "port1") p2 := dut.Port(t, "port2") + fptest.ConfigureDefaultNetworkInstance(t, dut) + // Configuring basic interface and network instance as some devices only populate OC after configuration. gnmi.Replace(t, dut, gnmi.OC().Interface(p1.Name()).Config(), dutPort1.NewOCInterface(p1.Name(), dut)) gnmi.Replace(t, dut, gnmi.OC().Interface(p2.Name()).Config(), dutPort2.NewOCInterface(p2.Name(), dut)) gnmi.Replace(t, dut, gnmi.OC().NetworkInstance(deviations.DefaultNetworkInstance(dut)).Type().Config(), oc.NetworkInstanceTypes_NETWORK_INSTANCE_TYPE_DEFAULT_INSTANCE) - baselineConfig := getDeviceConfig(t, dut) + baselineConfig := fptest.GetDeviceConfig(t, dut) setEthernetFromBase(t, baselineConfig) gnmiClient := dut.RawAPIs().GNMI(t) diff --git a/feature/system/gnmi/metadata/tests/large_set_consistency_test/metadata.textproto b/feature/system/gnmi/metadata/tests/large_set_consistency_test/metadata.textproto index cae8c3c1a46..c346a8d5da2 100644 --- a/feature/system/gnmi/metadata/tests/large_set_consistency_test/metadata.textproto +++ b/feature/system/gnmi/metadata/tests/large_set_consistency_test/metadata.textproto @@ -13,4 +13,12 @@ platform_exceptions: { default_network_instance: "default" } } +platform_exceptions: { + platform: { + vendor: CISCO + } + deviations: { + skip_macaddress_check: true + } +} diff --git a/feature/system/gnmi/set/tests/gnmi_set_test/gnmi_set_test.go b/feature/system/gnmi/set/tests/gnmi_set_test/gnmi_set_test.go index 8152a803887..d169ecec2f9 100644 --- a/feature/system/gnmi/set/tests/gnmi_set_test/gnmi_set_test.go +++ b/feature/system/gnmi/set/tests/gnmi_set_test/gnmi_set_test.go @@ -45,22 +45,8 @@ var ( skipContainerOp = flag.Bool("skip_container_op", false, "Skip ContainerOp test cases.") skipItemOp = flag.Bool("skip_item_op", false, "Skip ItemOp test cases.") - // The following experimental flags fine-tune the RootOp and ContainerOp behavior. Some - // devices require the config to be pruned for these to work. We are still undecided - // whether they should be deviations; pending OpenConfig clarifications. - pruneComponents = flag.Bool("prune_components", true, "Prune components that are not ports. Use this to preserve the breakout-mode settings.") - pruneLLDP = flag.Bool("prune_lldp", true, "Prune LLDP config.") - setEthernetFromState = flag.Bool("set_ethernet_from_state", true, "Set interface/ethernet config from state, mostly to get the port-speed settings correct.") - - // This has no known effect except to reduce logspam while debugging. - pruneQoS = flag.Bool("prune_qos", true, "Prune QoS config.") - // Experimental flags that will likely become a deviation. - cannotDeleteVRF = flag.Bool("cannot_delete_vrf", true, "Device cannot delete VRF.") // See "Note about cannotDeleteVRF" below. - cannotConfigurePortSpeed = flag.Bool("cannot_config_port_speed", false, "Some devices depending on the type of line card may not allow changing port speed, while still supporting the port speed leaf.") - - // Flags to ensure test passes without any dependency to the device config - baseOCConfigIsPresent = flag.Bool("base_oc_config_is_present", false, "No OC config is loaded on router, so Get config on the root returns no data.") + cannotDeleteVRF = flag.Bool("cannot_delete_vrf", true, "Device cannot delete VRF.") // See "Note about cannotDeleteVRF" below. ) var ( @@ -236,10 +222,6 @@ func TestReuseIP(t *testing.T) { forEachPushOp(t, dut, func(t *testing.T, op pushOp, config *oc.Root) { t.Log("Initialize") - if deviations.SkipMacaddressCheck(dut) { - *setEthernetFromState = false - } - config.DeleteInterface(p1.Name()) config.DeleteInterface(agg1) configMember(config.GetOrCreateInterface(p1.Name()), agg1, dut) @@ -840,7 +822,7 @@ func forEachPushOp( f func(t *testing.T, op pushOp, config *oc.Root), ) { baselineConfigOnce.Do(func() { - baselineConfig = getDeviceConfig(t, dut) + baselineConfig = fptest.GetDeviceConfig(t, dut) }) for _, op := range []pushOp{ @@ -850,154 +832,12 @@ func forEachPushOp( if op.shouldSkip() { t.Skip() } - o, err := ygot.DeepCopy(baselineConfig) - if err != nil { - t.Fatalf("Cannot copy baseConfig: %v", err) - } - config := o.(*oc.Root) + config := fptest.CopyDeviceConfig(t, dut, baselineConfig) f(t, op, config) }) } } -// getDeviceConfig gets a full config from a device but refurbishes it enough so it can be -// pushed out again. Ideally, we should be able to push the config we get from the same -// device without modification, but this is not explicitly defined in OpenConfig. -func getDeviceConfig(t testing.TB, dev gnmi.DeviceOrOpts) *oc.Root { - t.Helper() - - // Gets all the config (read-write) paths from root, not the state (read-only) paths. - config := gnmi.Get[*oc.Root](t, dev, gnmi.OC().Config()) - fptest.WriteQuery(t, "Untouched", gnmi.OC().Config(), config) - - // load the base oc config from the device state when no oc config is loaded - if !*baseOCConfigIsPresent { - if ondatra.DUT(t, "dut").Vendor() == ondatra.CISCO { - intfsState := gnmi.GetAll(t, dev, gnmi.OC().InterfaceAny().State()) - for _, intf := range intfsState { - ygot.PruneConfigFalse(oc.SchemaTree["Interface"], intf) - config.DeleteInterface(intf.GetName()) - if intf.GetName() == "Loopback0" || intf.GetName() == "PTP0/RP1/CPU0/0" || intf.GetName() == "Null0" || intf.GetName() == "PTP0/RP0/CPU0/0" { - continue - } - intf.ForwardingViable = nil - intf.Mtu = nil - intf.HoldTime = nil - if intf.Subinterface != nil { - if intf.Subinterface[0].Ipv6 != nil { - intf.Subinterface[0].Ipv6.Autoconf = nil - } - } - config.AppendInterface(intf) - } - vrfsStates := gnmi.GetAll(t, dev, gnmi.OC().NetworkInstanceAny().State()) - for _, vrf := range vrfsStates { - // only needed for containerOp - if vrf.GetName() == "**iid" { - continue - } - if vrf.GetName() == "DEFAULT" { - config.NetworkInstance = nil - vrf.Interface = nil - for _, ni := range config.NetworkInstance { - ni.Mpls = nil - } - } - ygot.PruneConfigFalse(oc.SchemaTree["NetworkInstance"], vrf) - vrf.Table = nil - vrf.RouteLimit = nil - vrf.Mpls = nil - for _, intf := range vrf.Interface { - intf.AssociatedAddressFamilies = nil - } - for _, protocol := range vrf.Protocol { - for _, routes := range protocol.Static { - routes.Description = nil - } - } - config.AppendNetworkInstance(vrf) - } - } - } - - if *pruneComponents { - for cname, component := range config.Component { - // Keep the port components in order to preserve the breakout-mode config. - if component.GetPort() == nil { - delete(config.Component, cname) - continue - } - // Need to prune subcomponents that may have a leafref to a component that was - // pruned. - component.Subcomponent = nil - } - } - - if *setEthernetFromState { - for iname, iface := range config.Interface { - if iface.GetEthernet() == nil { - continue - } - // Ethernet config may not contain meaningful values if it wasn't explicitly - // configured, so use its current state for the config, but prune non-config leaves. - intf := gnmi.Get(t, dev, gnmi.OC().Interface(iname).State()) - e := intf.GetEthernet() - if len(intf.GetHardwarePort()) != 0 { - breakout := config.GetComponent(intf.GetHardwarePort()).GetPort().GetBreakoutMode() - e := intf.GetEthernet() - // Set port speed to unknown for non breakout interfaces - if breakout.GetGroup(1) == nil && e != nil { - e.SetPortSpeed(oc.IfEthernet_ETHERNET_SPEED_SPEED_UNKNOWN) - } - } - ygot.PruneConfigFalse(oc.SchemaTree["Interface_Ethernet"], e) - if e.PortSpeed != 0 && e.PortSpeed != oc.IfEthernet_ETHERNET_SPEED_SPEED_UNKNOWN { - iface.Ethernet = e - } - // need to set mac address for mgmt interface to nil - if intf.GetName() == "MgmtEth0/RP0/CPU0/0" || intf.GetName() == "MgmtEth0/RP1/CPU0/0" && deviations.SkipMacaddressCheck(ondatra.DUT(t, "dut")) { - e.MacAddress = nil - } - // need to set mac address for bundle interface to nil - if iface.Ethernet.AggregateId != nil && deviations.SkipMacaddressCheck(ondatra.DUT(t, "dut")) { - iface.Ethernet.MacAddress = nil - continue - } - } - } - - if !*cannotConfigurePortSpeed { - for _, iface := range config.Interface { - if iface.GetEthernet() == nil { - continue - } - iface.GetEthernet().PortSpeed = oc.IfEthernet_ETHERNET_SPEED_UNSET - iface.GetEthernet().DuplexMode = oc.Ethernet_DuplexMode_UNSET - iface.GetEthernet().EnableFlowControl = nil - } - } - - if *pruneLLDP && config.Lldp != nil { - config.Lldp.ChassisId = nil - config.Lldp.ChassisIdType = oc.Lldp_ChassisIdType_UNSET - } - - if *pruneQoS { - config.Qos = nil - } - - pruneUnsupportedPaths(config) - - fptest.WriteQuery(t, "Touched", gnmi.OC().Config(), config) - return config -} - -func pruneUnsupportedPaths(config *oc.Root) { - for _, ni := range config.NetworkInstance { - ni.Fdb = nil - } -} - // pushScope describe the config scope that the test case wants to modify. This is for // itemOp only; rootOp and containerOp ignore this. type pushScope struct { @@ -1012,23 +852,6 @@ type pushOp interface { push(t testing.TB, dev gnmi.DeviceOrOpts, config *oc.Root, scope *pushScope) } -// setEthernetFromBase merges the ethernet config from the interfaces in base config into -// the destination config. -func setEthernetFromBase(t testing.TB, base *oc.Root, config *oc.Root) { - t.Helper() - - for iname, iface := range config.Interface { - eb := base.GetInterface(iname).GetEthernet() - ec := iface.GetOrCreateEthernet() - if eb == nil || ec == nil { - continue - } - if err := ygot.MergeStructInto(ec, eb); err != nil { - t.Errorf("Cannot merge %s ethernet: %v", iname, err) - } - } -} - // rootOp pushes config using replace at root. type rootOp struct{ base *oc.Root } @@ -1037,9 +860,6 @@ func (rootOp) shouldSkip() bool { return *skipRootOp } func (op rootOp) push(t testing.TB, dev gnmi.DeviceOrOpts, config *oc.Root, _ *pushScope) { t.Helper() - if *setEthernetFromState { - setEthernetFromBase(t, op.base, config) - } fptest.WriteQuery(t, "RootOp", gnmi.OC().Config(), config) dut := ondatra.DUT(t, "dut") if deviations.AddMissingBaseConfigViaCli(dut) { @@ -1060,9 +880,6 @@ func (containerOp) shouldSkip() bool { return *skipContainerOp } func (op containerOp) push(t testing.TB, dev gnmi.DeviceOrOpts, config *oc.Root, _ *pushScope) { t.Helper() - if *setEthernetFromState { - setEthernetFromBase(t, op.base, config) - } fptest.WriteQuery(t, "ContainerOp", gnmi.OC().Config(), config) batch := &gnmi.SetBatch{} @@ -1095,9 +912,6 @@ func (itemOp) shouldSkip() bool { return *skipItemOp } func (op itemOp) push(t testing.TB, dev gnmi.DeviceOrOpts, config *oc.Root, scope *pushScope) { t.Helper() - if *setEthernetFromState { - setEthernetFromBase(t, op.base, config) - } fptest.WriteQuery(t, "ItemOp", gnmi.OC().Config(), config) batch := &gnmi.SetBatch{} diff --git a/internal/deviations/deviations.go b/internal/deviations/deviations.go index 72f44101917..247437e3422 100644 --- a/internal/deviations/deviations.go +++ b/internal/deviations/deviations.go @@ -1203,7 +1203,7 @@ func EnableMultipathUnderAfiSafi(dut *ondatra.DUTDevice) bool { return lookupDUTDeviations(dut).GetEnableMultipathUnderAfiSafi() } -// Device have different default value for allow own as. +// BgpAllowownasDiffDefaultValue permits a device to have a different default value for allow own as. func BgpAllowownasDiffDefaultValue(dut *ondatra.DUTDevice) bool { return lookupDUTDeviations(dut).GetBgpAllowownasDiffDefaultValue() } diff --git a/internal/fptest/config.go b/internal/fptest/config.go new file mode 100644 index 00000000000..bb976eea456 --- /dev/null +++ b/internal/fptest/config.go @@ -0,0 +1,205 @@ +package fptest + +import ( + "flag" + "testing" + + "github.com/openconfig/featureprofiles/internal/deviations" + "github.com/openconfig/ondatra" + "github.com/openconfig/ondatra/gnmi" + "github.com/openconfig/ondatra/gnmi/oc" + "github.com/openconfig/ygot/ygot" +) + +var ( + // Some devices require the config to be pruned for these to work. We are still undecided + // whether they should be deviations; pending OpenConfig clarifications. + pruneComponents = flag.Bool("prune_components", true, "Prune components that are not ports. Use this to preserve the breakout-mode settings.") + pruneLLDP = flag.Bool("prune_lldp", true, "Prune LLDP config.") + setEthernetFromState = flag.Bool("set_ethernet_from_state", true, "Set interface/ethernet config from state, mostly to get the port-speed settings correct.") + + // This has no known effect except to reduce logspam while debugging. + pruneQoS = flag.Bool("prune_qos", true, "Prune QoS config.") + + // Experimental flags that will likely become a deviation. + cannotConfigurePortSpeed = flag.Bool("cannot_config_port_speed", false, "Some devices depending on the type of line card may not allow changing port speed, while still supporting the port speed leaf.") + + // Flags to ensure test passes without any dependency to the device config + baseOCConfigIsPresent = flag.Bool("base_oc_config_is_present", false, "No OC config is loaded on router, so Get config on the root returns no data.") +) + +// GetDeviceConfig gets a full config from a device but refurbishes it enough so it can be +// pushed out again. Ideally, we should be able to push the config we get from the same +// device without modification, but this is not explicitly defined in OpenConfig. +func GetDeviceConfig(t testing.TB, dev gnmi.DeviceOrOpts) *oc.Root { + t.Helper() + + // Gets all the config (read-write) paths from root, not the state (read-only) paths. + config := gnmi.Get[*oc.Root](t, dev, gnmi.OC().Config()) + WriteQuery(t, "Untouched", gnmi.OC().Config(), config) + + // load the base oc config from the device state when no oc config is loaded + if !*baseOCConfigIsPresent { + if ondatra.DUT(t, "dut").Vendor() == ondatra.CISCO { + intfsState := gnmi.GetAll(t, dev, gnmi.OC().InterfaceAny().State()) + for _, intf := range intfsState { + ygot.PruneConfigFalse(oc.SchemaTree["Interface"], intf) + config.DeleteInterface(intf.GetName()) + if intf.GetName() == "Loopback0" || intf.GetName() == "PTP0/RP1/CPU0/0" || intf.GetName() == "Null0" || intf.GetName() == "PTP0/RP0/CPU0/0" { + continue + } + intf.ForwardingViable = nil + intf.Mtu = nil + intf.HoldTime = nil + if intf.Subinterface != nil { + if intf.Subinterface[0].Ipv6 != nil { + intf.Subinterface[0].Ipv6.Autoconf = nil + } + } + config.AppendInterface(intf) + } + vrfsStates := gnmi.GetAll(t, dev, gnmi.OC().NetworkInstanceAny().State()) + for _, vrf := range vrfsStates { + // only needed for containerOp + if vrf.GetName() == "**iid" { + continue + } + if vrf.GetName() == "DEFAULT" { + config.NetworkInstance = nil + vrf.Interface = nil + for _, ni := range config.NetworkInstance { + ni.Mpls = nil + } + } + ygot.PruneConfigFalse(oc.SchemaTree["NetworkInstance"], vrf) + vrf.Table = nil + vrf.RouteLimit = nil + vrf.Mpls = nil + for _, intf := range vrf.Interface { + intf.AssociatedAddressFamilies = nil + } + for _, protocol := range vrf.Protocol { + for _, routes := range protocol.Static { + routes.Description = nil + } + } + config.AppendNetworkInstance(vrf) + } + } + } + + if *pruneComponents { + for cname, component := range config.Component { + // Keep the port components in order to preserve the breakout-mode config. + if component.GetPort() == nil { + delete(config.Component, cname) + continue + } + // Need to prune subcomponents that may have a leafref to a component that was + // pruned. + component.Subcomponent = nil + } + } + + if *setEthernetFromState { + for iname, iface := range config.Interface { + if iface.GetEthernet() == nil { + continue + } + // Ethernet config may not contain meaningful values if it wasn't explicitly + // configured, so use its current state for the config, but prune non-config leaves. + intf := gnmi.Get(t, dev, gnmi.OC().Interface(iname).State()) + e := intf.GetEthernet() + if len(intf.GetHardwarePort()) != 0 { + breakout := config.GetComponent(intf.GetHardwarePort()).GetPort().GetBreakoutMode() + e := intf.GetEthernet() + // Set port speed to unknown for non breakout interfaces + if breakout.GetGroup(1) == nil && e != nil { + e.SetPortSpeed(oc.IfEthernet_ETHERNET_SPEED_SPEED_UNKNOWN) + } + } + ygot.PruneConfigFalse(oc.SchemaTree["Interface_Ethernet"], e) + if e.PortSpeed != 0 && e.PortSpeed != oc.IfEthernet_ETHERNET_SPEED_SPEED_UNKNOWN { + iface.Ethernet = e + } + // need to set mac address for mgmt interface to nil + if intf.GetName() == "MgmtEth0/RP0/CPU0/0" || intf.GetName() == "MgmtEth0/RP1/CPU0/0" && deviations.SkipMacaddressCheck(ondatra.DUT(t, "dut")) { + e.MacAddress = nil + } + // need to set mac address for bundle interface to nil + if iface.Ethernet.AggregateId != nil && deviations.SkipMacaddressCheck(ondatra.DUT(t, "dut")) { + iface.Ethernet.MacAddress = nil + continue + } + } + } + + if !*cannotConfigurePortSpeed { + for _, iface := range config.Interface { + if iface.GetEthernet() == nil { + continue + } + iface.GetEthernet().PortSpeed = oc.IfEthernet_ETHERNET_SPEED_UNSET + iface.GetEthernet().DuplexMode = oc.Ethernet_DuplexMode_UNSET + iface.GetEthernet().EnableFlowControl = nil + } + } + + if *pruneLLDP && config.Lldp != nil { + config.Lldp.ChassisId = nil + config.Lldp.ChassisIdType = oc.Lldp_ChassisIdType_UNSET + } + + if *pruneQoS { + config.Qos = nil + } + + pruneUnsupportedPaths(config) + + WriteQuery(t, "Touched", gnmi.OC().Config(), config) + return config +} + +// CopyDeviceConfig returns a deep copy of a device config but refurbishes it enough so it can be +// pushed out again +func CopyDeviceConfig(t testing.TB, dut *ondatra.DUTDevice, config *oc.Root) *oc.Root { + if deviations.SkipMacaddressCheck(dut) { + *setEthernetFromState = false + } + + o, err := ygot.DeepCopy(config) + if err != nil { + t.Fatalf("Cannot copy baseConfig: %v", err) + } + + copy := o.(*oc.Root) + + if *setEthernetFromState { + setEthernetFromBase(t, config, copy) + } + + return copy +} + +func pruneUnsupportedPaths(config *oc.Root) { + for _, ni := range config.NetworkInstance { + ni.Fdb = nil + } +} + +// setEthernetFromBase merges the ethernet config from the interfaces in base config into +// the destination config. +func setEthernetFromBase(t testing.TB, base *oc.Root, config *oc.Root) { + t.Helper() + + for iname, iface := range config.Interface { + eb := base.GetInterface(iname).GetEthernet() + ec := iface.GetOrCreateEthernet() + if eb == nil || ec == nil { + continue + } + if err := ygot.MergeStructInto(ec, eb); err != nil { + t.Errorf("Cannot merge %s ethernet: %v", iname, err) + } + } +} diff --git a/internal/otg_helpers/otg_config_helpers/otgflowhelpers.go b/internal/otg_helpers/otg_config_helpers/otgflowhelpers.go index fe619f5f735..23ffc578c2d 100644 --- a/internal/otg_helpers/otg_config_helpers/otgflowhelpers.go +++ b/internal/otg_helpers/otg_config_helpers/otgflowhelpers.go @@ -1,4 +1,3 @@ -// Package otgconfighelpers provides helper functions to create different flows on traffic generator. package otgconfighelpers import ( diff --git a/internal/security/acctz/acctz.go b/internal/security/acctz/acctz.go index 6837c82f0bc..6f475e14e1e 100644 --- a/internal/security/acctz/acctz.go +++ b/internal/security/acctz/acctz.go @@ -27,8 +27,8 @@ import ( "testing" "time" - "github.com/openconfig/gnmi/proto/gnmi" - "github.com/openconfig/gnoi/system" + gnmipb "github.com/openconfig/gnmi/proto/gnmi" + systempb "github.com/openconfig/gnoi/system" acctzpb "github.com/openconfig/gnsi/acctz" authzpb "github.com/openconfig/gnsi/authz" cpb "github.com/openconfig/gnsi/credentialz" @@ -113,7 +113,7 @@ func setupUserPassword(t *testing.T, dut *ondatra.DUTDevice, username, password time.Sleep(time.Second) } -func nokiaFailCliRole(t *testing.T) *gnmi.SetRequest { +func nokiaFailCliRole(t *testing.T) *gnmipb.SetRequest { failRoleData, err := json.Marshal([]any{ map[string]any{ "services": []string{"cli"}, @@ -126,22 +126,22 @@ func nokiaFailCliRole(t *testing.T) *gnmi.SetRequest { t.Fatalf("Error with json marshal: %v", err) } - return &gnmi.SetRequest{ - Prefix: &gnmi.Path{ + return &gnmipb.SetRequest{ + Prefix: &gnmipb.Path{ Origin: "native", }, - Replace: []*gnmi.Update{ + Replace: []*gnmipb.Update{ { - Path: &gnmi.Path{ - Elem: []*gnmi.PathElem{ + Path: &gnmipb.Path{ + Elem: []*gnmipb.PathElem{ {Name: "system"}, {Name: "aaa"}, {Name: "authorization"}, {Name: "role", Key: map[string]string{"rolename": failRoleName}}, }, }, - Val: &gnmi.TypedValue{ - Value: &gnmi.TypedValue_JsonIetfVal{ + Val: &gnmipb.TypedValue{ + Value: &gnmipb.TypedValue_JsonIetfVal{ JsonIetfVal: failRoleData, }, }, @@ -157,7 +157,7 @@ func SetupUsers(t *testing.T, dut *ondatra.DUTDevice, configureFailCliRole bool) successUser.SetRole(oc.AaaTypes_SYSTEM_DEFINED_ROLES_SYSTEM_ROLE_ADMIN) failUser := auth.GetOrCreateUser(failUsername) if configureFailCliRole { - var SetRequest *gnmi.SetRequest + var SetRequest *gnmipb.SetRequest // Create failure cli role in native. switch dut.Vendor() { @@ -325,13 +325,13 @@ func SendGnmiRPCs(t *testing.T, dut *ondatra.DUTDevice) []*acctzpb.RecordRespons var records []*acctzpb.RecordResponse grpcConn := dialGrpc(t, target) - gnmiClient := gnmi.NewGNMIClient(grpcConn) + gnmiClient := gnmipb.NewGNMIClient(grpcConn) ctx := context.Background() ctx = metadata.AppendToOutgoingContext(ctx, "username", failUsername) ctx = metadata.AppendToOutgoingContext(ctx, "password", failPassword) // Send an unsuccessful gNMI capabilities request (bad creds in context). - _, err := gnmiClient.Capabilities(ctx, &gnmi.CapabilityRequest{}) + _, err := gnmiClient.Capabilities(ctx, &gnmipb.CapabilityRequest{}) if err != nil { t.Logf("Got expected error fetching capabilities with bad creds, error: %s", err) } else { @@ -364,7 +364,7 @@ func SendGnmiRPCs(t *testing.T, dut *ondatra.DUTDevice) []*acctzpb.RecordRespons ctx = context.Background() ctx = metadata.AppendToOutgoingContext(ctx, "username", successUsername) ctx = metadata.AppendToOutgoingContext(ctx, "password", successPassword) - req := &gnmi.CapabilityRequest{} + req := &gnmipb.CapabilityRequest{} payload, err := anypb.New(req) if err != nil { t.Fatal("Failed creating anypb payload.") @@ -422,14 +422,14 @@ func SendGnoiRPCs(t *testing.T, dut *ondatra.DUTDevice) []*acctzpb.RecordRespons var records []*acctzpb.RecordResponse grpcConn := dialGrpc(t, target) - gnoiSystemClient := system.NewSystemClient(grpcConn) + gnoiSystemClient := systempb.NewSystemClient(grpcConn) ctx := context.Background() ctx = metadata.AppendToOutgoingContext(ctx, "username", failUsername) ctx = metadata.AppendToOutgoingContext(ctx, "password", failPassword) // Send an unsuccessful gNOI system time request (bad creds in context), we don't // care about receiving on it, just want to make the request. - gnoiSystemPingClient, err := gnoiSystemClient.Ping(ctx, &system.PingRequest{ + gnoiSystemPingClient, err := gnoiSystemClient.Ping(ctx, &systempb.PingRequest{ Destination: "127.0.0.1", Count: 1, }) @@ -468,7 +468,7 @@ func SendGnoiRPCs(t *testing.T, dut *ondatra.DUTDevice) []*acctzpb.RecordRespons ctx = context.Background() ctx = metadata.AppendToOutgoingContext(ctx, "username", successUsername) ctx = metadata.AppendToOutgoingContext(ctx, "password", successPassword) - req := &system.PingRequest{ + req := &systempb.PingRequest{ Destination: "127.0.0.1", Count: 1, } diff --git a/testregistry.textproto b/testregistry.textproto index f3da91c3cfe..c51caaafb84 100644 --- a/testregistry.textproto +++ b/testregistry.textproto @@ -1224,7 +1224,8 @@ test: { exec: " " } test: { - id: "TE-9.1: Push MPLS Labels to MPLS payload" + id: "TE-9.1" + description: "Push MPLS Labels to MPLS payload" readme: "https://github.com/openconfig/featureprofiles/blob/main/feature/gribi/otg_tests/mpls_compliance/README.md" } test: {