From 187483fa1e10677f8d660fa879709ad776720b97 Mon Sep 17 00:00:00 2001 From: Nisha Sadhasivam Date: Fri, 26 Jul 2024 16:19:29 +0530 Subject: [PATCH 1/2] fix match_100_set_linkbw_2G policy as per expected result in README on cisco (#3331) * fix match_100_set_linkbw_2G policy as per expected result in README for cisco * fix for arista and SA failure --- .../link_bandwidth_test.go | 34 ++++++ .../link_bandwidth_test/metadata.textproto | 1 + internal/deviations/deviations.go | 5 + proto/metadata.proto | 2 + proto/metadata_go_proto/metadata.pb.go | 105 ++++++++++-------- 5 files changed, 103 insertions(+), 44 deletions(-) diff --git a/feature/experimental/bgp/otg_tests/link_bandwidth_test/link_bandwidth_test.go b/feature/experimental/bgp/otg_tests/link_bandwidth_test/link_bandwidth_test.go index 4e2aedf07a82..dcb0012b4938 100644 --- a/feature/experimental/bgp/otg_tests/link_bandwidth_test/link_bandwidth_test.go +++ b/feature/experimental/bgp/otg_tests/link_bandwidth_test/link_bandwidth_test.go @@ -23,6 +23,7 @@ import ( "github.com/open-traffic-generator/snappi/gosnappi" "github.com/openconfig/featureprofiles/internal/attrs" + "github.com/openconfig/featureprofiles/internal/cfgplugins" "github.com/openconfig/featureprofiles/internal/deviations" "github.com/openconfig/featureprofiles/internal/fptest" "github.com/openconfig/featureprofiles/internal/helpers" @@ -181,6 +182,9 @@ func TestBGPLinkBandwidth(t *testing.T) { } baseSetupConfigAndVerification(t, td) configureExtCommunityRoutingPolicy(t, dut) + if deviations.BgpExplicitExtendedCommunityEnable(dut) { + enableExtCommunityCLIConfig(t, dut) + } testCases := []testCase{ { name: "Policy set not_match_100_set_linkbw_1M", @@ -224,6 +228,17 @@ func TestBGPLinkBandwidth(t *testing.T) { } } +func enableExtCommunityCLIConfig(t *testing.T, dut *ondatra.DUTDevice) { + var extCommunityEnableCLIConfig string + switch dut.Vendor() { + case ondatra.CISCO: + extCommunityEnableCLIConfig = fmt.Sprintf("router bgp %v instance BGP neighbor-group %v \n ebgp-recv-extcommunity-dmz \n ebgp-send-extcommunity-dmz\n", dutAS, cfgplugins.BGPPeerGroup1) + default: + t.Fatalf("Unsupported vendor %s for deviation 'BgpExplicitExtendedCommunityEnable'", dut.Vendor()) + } + helpers.GnmiCLIConfig(t, dut, extCommunityEnableCLIConfig) +} + func applyPolicyDut(t *testing.T, dut *ondatra.DUTDevice, policyName string) { // Apply ipv4 policy to bgp neighbour. root := &oc.Root{} @@ -241,6 +256,17 @@ func applyPolicyDut(t *testing.T, dut *ondatra.DUTDevice, policyName string) { policy = root.GetOrCreateNetworkInstance(dni).GetOrCreateProtocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, bgpName).GetOrCreateBgp().GetOrCreateNeighbor(atePort1.IPv6).GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).GetOrCreateApplyPolicy() policy.SetImportPolicy([]string{policyName}) gnmi.Replace(t, dut, path.Config(), policy) + + ni := root.GetOrCreateNetworkInstance(deviations.DefaultNetworkInstance(dut)) + niProto := ni.GetOrCreateProtocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP") + bgp := niProto.GetOrCreateBgp() + bgp.GetOrCreatePeerGroup(cfgplugins.BGPPeerGroup1).GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Enabled = ygot.Bool(true) + bgp.GetOrCreatePeerGroup(cfgplugins.BGPPeerGroup1).GetOrCreateAfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Enabled = ygot.Bool(true) + bgpNbrV4 := bgp.GetOrCreateNeighbor(atePort1.IPv4) + bgpNbrV4.PeerGroup = ygot.String(cfgplugins.BGPPeerGroup1) + bgpNbrV6 := bgp.GetOrCreateNeighbor(atePort1.IPv6) + bgpNbrV6.PeerGroup = ygot.String(cfgplugins.BGPPeerGroup1) + gnmi.Update(t, dut, gnmi.OC().NetworkInstance(deviations.DefaultNetworkInstance(dut)).Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "BGP").Config(), niProto) } func validatPolicyDut(t *testing.T, dut *ondatra.DUTDevice, policyName string) { @@ -292,6 +318,10 @@ func validateRouteCommunityV4Prefix(t *testing.T, td testData, community, v4Pref } } default: + if len(bgpPrefix.ExtendedCommunity) == 0 { + t.Errorf("ERROR extended community is empty, expected %v", community) + return + } for _, ec := range bgpPrefix.ExtendedCommunity { lbSubType := ec.Structured.NonTransitive_2OctetAsType.LinkBandwidthSubtype listCommunity := strings.Split(community, ":") @@ -359,6 +389,10 @@ func validateRouteCommunityV6Prefix(t *testing.T, td testData, community, v6Pref } } default: + if len(bgpPrefix.ExtendedCommunity) == 0 { + t.Errorf("ERROR extended community is empty, expected %v", community) + return + } for _, ec := range bgpPrefix.ExtendedCommunity { lbSubType := ec.Structured.NonTransitive_2OctetAsType.LinkBandwidthSubtype listCommunity := strings.Split(community, ":") diff --git a/feature/experimental/bgp/otg_tests/link_bandwidth_test/metadata.textproto b/feature/experimental/bgp/otg_tests/link_bandwidth_test/metadata.textproto index cad8f6e271fc..b991682d3ed9 100644 --- a/feature/experimental/bgp/otg_tests/link_bandwidth_test/metadata.textproto +++ b/feature/experimental/bgp/otg_tests/link_bandwidth_test/metadata.textproto @@ -35,6 +35,7 @@ platform_exceptions: { skip_bgp_send_community_type: true bgp_extended_community_index_unsupported: true bgp_conditions_match_community_set_unsupported: true + bgp_explicit_extended_community_enable: true } } tags: TAGS_AGGREGATION diff --git a/internal/deviations/deviations.go b/internal/deviations/deviations.go index 7dc84c6636ab..9f1f345a5fc7 100644 --- a/internal/deviations/deviations.go +++ b/internal/deviations/deviations.go @@ -1098,3 +1098,8 @@ func BgpDeleteLinkBandwidthUnsupported(dut *ondatra.DUTDevice) bool { func QOSInQueueDropCounterUnsupported(dut *ondatra.DUTDevice) bool { return lookupDUTDeviations(dut).GetQosInqueueDropCounterUnsupported() } + +// BgpExplicitExtendedCommunityEnable returns true if explicit extended community enable is needed +func BgpExplicitExtendedCommunityEnable(dut *ondatra.DUTDevice) bool { + return lookupDUTDeviations(dut).GetBgpExplicitExtendedCommunityEnable() +} diff --git a/proto/metadata.proto b/proto/metadata.proto index 531768af7483..7c5499da55d9 100644 --- a/proto/metadata.proto +++ b/proto/metadata.proto @@ -594,6 +594,8 @@ message Metadata { // qos_inqueue_drop_counter_Unsupported is set to true for devices that do not support qos ingress queue drop counters. // Juniper: b/341130490 bool qos_inqueue_drop_counter_unsupported = 207; + // Devices that need bgp extended community enable explicitly + bool bgp_explicit_extended_community_enable = 208; // Reserved field numbers and identifiers. reserved 84, 9, 28, 20, 90, 97, 55, 89, 19, 36, 35; diff --git a/proto/metadata_go_proto/metadata.pb.go b/proto/metadata_go_proto/metadata.pb.go index 74ecb4eaaa9d..a2e7b4a8fd3d 100644 --- a/proto/metadata_go_proto/metadata.pb.go +++ b/proto/metadata_go_proto/metadata.pb.go @@ -14,18 +14,19 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.27.1 -// protoc v3.12.4 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: metadata.proto package metadata_go_proto import ( + reflect "reflect" + sync "sync" + proto "github.com/openconfig/ondatra/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) const ( @@ -688,7 +689,8 @@ type Metadata_Deviations struct { // Arista: partnerissuetracker.corp.google.com/issues/317422300 SkipSettingAllowMultipleAs bool `protobuf:"varint,140,opt,name=skip_setting_allow_multiple_as,json=skipSettingAllowMultipleAs,proto3" json:"skip_setting_allow_multiple_as,omitempty"` // Skip tests with decap encap vrf as PBF action - // Nokia: partnerissuetracker.corp.google.com/issues/323251581 + // + // Nokia: partnerissuetracker.corp.google.com/issues/323251581 SkipPbfWithDecapEncapVrf bool `protobuf:"varint,141,opt,name=skip_pbf_with_decap_encap_vrf,json=skipPbfWithDecapEncapVrf,proto3" json:"skip_pbf_with_decap_encap_vrf,omitempty"` // Devices which does not support copying TTL. // Juniper: b/307258544 @@ -874,6 +876,8 @@ type Metadata_Deviations struct { // qos_inqueue_drop_counter_Unsupported is set to true for devices that do not support qos ingress queue drop counters. // Juniper: b/341130490 QosInqueueDropCounterUnsupported bool `protobuf:"varint,207,opt,name=qos_inqueue_drop_counter_unsupported,json=qosInqueueDropCounterUnsupported,proto3" json:"qos_inqueue_drop_counter_unsupported,omitempty"` + // Devices that need bgp extended community enable explicitly + BgpExplicitExtendedCommunityEnable bool `protobuf:"varint,208,opt,name=bgp_explicit_extended_community_enable,json=bgpExplicitExtendedCommunityEnable,proto3" json:"bgp_explicit_extended_community_enable,omitempty"` } func (x *Metadata_Deviations) Reset() { @@ -2231,6 +2235,13 @@ func (x *Metadata_Deviations) GetQosInqueueDropCounterUnsupported() bool { return false } +func (x *Metadata_Deviations) GetBgpExplicitExtendedCommunityEnable() bool { + if x != nil { + return x.BgpExplicitExtendedCommunityEnable + } + return false +} + type Metadata_PlatformExceptions struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -2294,7 +2305,7 @@ var file_metadata_proto_rawDesc = []byte{ 0x74, 0x69, 0x6e, 0x67, 0x1a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x6f, 0x6e, 0x64, 0x61, 0x74, 0x72, 0x61, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x62, 0x65, - 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xfb, 0x74, 0x0a, 0x08, 0x4d, 0x65, 0x74, 0x61, + 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd0, 0x75, 0x0a, 0x08, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x6c, 0x61, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x6c, 0x61, 0x6e, 0x49, @@ -2328,7 +2339,7 @@ var file_metadata_proto_rawDesc = []byte{ 0x67, 0x65, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x67, 0x65, 0x78, 0x4a, 0x04, 0x08, 0x02, 0x10, 0x03, 0x52, 0x0e, 0x68, 0x61, 0x72, 0x64, 0x77, 0x61, 0x72, 0x65, 0x5f, - 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x1a, 0xce, 0x6c, 0x0a, 0x0a, 0x44, 0x65, 0x76, 0x69, 0x61, 0x74, + 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x1a, 0xa3, 0x6d, 0x0a, 0x0a, 0x44, 0x65, 0x76, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x30, 0x0a, 0x14, 0x69, 0x70, 0x76, 0x34, 0x5f, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, 0x69, 0x70, 0x76, 0x34, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x45, @@ -3193,44 +3204,50 @@ var file_metadata_proto_rawDesc = []byte{ 0x75, 0x6e, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x18, 0xcf, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x20, 0x71, 0x6f, 0x73, 0x49, 0x6e, 0x71, 0x75, 0x65, 0x75, 0x65, 0x44, 0x72, 0x6f, 0x70, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x55, 0x6e, 0x73, 0x75, 0x70, 0x70, 0x6f, - 0x72, 0x74, 0x65, 0x64, 0x4a, 0x04, 0x08, 0x54, 0x10, 0x55, 0x4a, 0x04, 0x08, 0x09, 0x10, 0x0a, - 0x4a, 0x04, 0x08, 0x1c, 0x10, 0x1d, 0x4a, 0x04, 0x08, 0x14, 0x10, 0x15, 0x4a, 0x04, 0x08, 0x5a, - 0x10, 0x5b, 0x4a, 0x04, 0x08, 0x61, 0x10, 0x62, 0x4a, 0x04, 0x08, 0x37, 0x10, 0x38, 0x4a, 0x04, - 0x08, 0x59, 0x10, 0x5a, 0x4a, 0x04, 0x08, 0x13, 0x10, 0x14, 0x4a, 0x04, 0x08, 0x24, 0x10, 0x25, - 0x4a, 0x04, 0x08, 0x23, 0x10, 0x24, 0x1a, 0xa0, 0x01, 0x0a, 0x12, 0x50, 0x6c, 0x61, 0x74, 0x66, - 0x6f, 0x72, 0x6d, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x41, 0x0a, - 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x25, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x74, 0x65, 0x73, - 0x74, 0x69, 0x6e, 0x67, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x50, 0x6c, - 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, - 0x12, 0x47, 0x0a, 0x0a, 0x64, 0x65, 0x76, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, + 0x72, 0x74, 0x65, 0x64, 0x12, 0x53, 0x0a, 0x26, 0x62, 0x67, 0x70, 0x5f, 0x65, 0x78, 0x70, 0x6c, + 0x69, 0x63, 0x69, 0x74, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x65, 0x64, 0x5f, 0x63, 0x6f, + 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x74, 0x79, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x18, 0xd0, + 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x22, 0x62, 0x67, 0x70, 0x45, 0x78, 0x70, 0x6c, 0x69, 0x63, + 0x69, 0x74, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x65, 0x64, 0x43, 0x6f, 0x6d, 0x6d, 0x75, 0x6e, + 0x69, 0x74, 0x79, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x4a, 0x04, 0x08, 0x54, 0x10, 0x55, 0x4a, + 0x04, 0x08, 0x09, 0x10, 0x0a, 0x4a, 0x04, 0x08, 0x1c, 0x10, 0x1d, 0x4a, 0x04, 0x08, 0x14, 0x10, + 0x15, 0x4a, 0x04, 0x08, 0x5a, 0x10, 0x5b, 0x4a, 0x04, 0x08, 0x61, 0x10, 0x62, 0x4a, 0x04, 0x08, + 0x37, 0x10, 0x38, 0x4a, 0x04, 0x08, 0x59, 0x10, 0x5a, 0x4a, 0x04, 0x08, 0x13, 0x10, 0x14, 0x4a, + 0x04, 0x08, 0x24, 0x10, 0x25, 0x4a, 0x04, 0x08, 0x23, 0x10, 0x24, 0x1a, 0xa0, 0x01, 0x0a, 0x12, + 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x12, 0x41, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0x2e, 0x44, 0x65, 0x76, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x0a, 0x64, - 0x65, 0x76, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xfa, 0x01, 0x0a, 0x07, 0x54, 0x65, - 0x73, 0x74, 0x62, 0x65, 0x64, 0x12, 0x17, 0x0a, 0x13, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, - 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0f, - 0x0a, 0x0b, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x44, 0x55, 0x54, 0x10, 0x01, 0x12, - 0x1a, 0x0a, 0x16, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x44, - 0x55, 0x54, 0x5f, 0x34, 0x4c, 0x49, 0x4e, 0x4b, 0x53, 0x10, 0x02, 0x12, 0x1a, 0x0a, 0x16, 0x54, - 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x41, 0x54, 0x45, 0x5f, 0x32, - 0x4c, 0x49, 0x4e, 0x4b, 0x53, 0x10, 0x03, 0x12, 0x1a, 0x0a, 0x16, 0x54, 0x45, 0x53, 0x54, 0x42, - 0x45, 0x44, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x41, 0x54, 0x45, 0x5f, 0x34, 0x4c, 0x49, 0x4e, 0x4b, - 0x53, 0x10, 0x04, 0x12, 0x1e, 0x0a, 0x1a, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x44, - 0x55, 0x54, 0x5f, 0x41, 0x54, 0x45, 0x5f, 0x39, 0x4c, 0x49, 0x4e, 0x4b, 0x53, 0x5f, 0x4c, 0x41, - 0x47, 0x10, 0x05, 0x12, 0x1e, 0x0a, 0x1a, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x44, - 0x55, 0x54, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x41, 0x54, 0x45, 0x5f, 0x32, 0x4c, 0x49, 0x4e, 0x4b, - 0x53, 0x10, 0x06, 0x12, 0x1a, 0x0a, 0x16, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x44, - 0x55, 0x54, 0x5f, 0x41, 0x54, 0x45, 0x5f, 0x38, 0x4c, 0x49, 0x4e, 0x4b, 0x53, 0x10, 0x07, 0x12, - 0x15, 0x0a, 0x11, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x34, - 0x30, 0x30, 0x5a, 0x52, 0x10, 0x08, 0x22, 0x6d, 0x0a, 0x04, 0x54, 0x61, 0x67, 0x73, 0x12, 0x14, - 0x0a, 0x10, 0x54, 0x41, 0x47, 0x53, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, - 0x45, 0x44, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x41, 0x47, 0x53, 0x5f, 0x41, 0x47, 0x47, - 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x54, 0x41, - 0x47, 0x53, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x43, 0x45, 0x4e, 0x54, 0x45, 0x52, 0x5f, 0x45, 0x44, - 0x47, 0x45, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x54, 0x41, 0x47, 0x53, 0x5f, 0x45, 0x44, 0x47, - 0x45, 0x10, 0x03, 0x12, 0x10, 0x0a, 0x0c, 0x54, 0x41, 0x47, 0x53, 0x5f, 0x54, 0x52, 0x41, 0x4e, - 0x53, 0x49, 0x54, 0x10, 0x04, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x61, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x52, 0x08, 0x70, 0x6c, 0x61, + 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x47, 0x0a, 0x0a, 0x64, 0x65, 0x76, 0x69, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x6f, 0x70, 0x65, 0x6e, + 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x2e, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x44, 0x65, 0x76, 0x69, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x52, 0x0a, 0x64, 0x65, 0x76, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xfa, + 0x01, 0x0a, 0x07, 0x54, 0x65, 0x73, 0x74, 0x62, 0x65, 0x64, 0x12, 0x17, 0x0a, 0x13, 0x54, 0x45, + 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, + 0x44, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x44, + 0x55, 0x54, 0x10, 0x01, 0x12, 0x1a, 0x0a, 0x16, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, + 0x44, 0x55, 0x54, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x34, 0x4c, 0x49, 0x4e, 0x4b, 0x53, 0x10, 0x02, + 0x12, 0x1a, 0x0a, 0x16, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x44, 0x55, 0x54, 0x5f, + 0x41, 0x54, 0x45, 0x5f, 0x32, 0x4c, 0x49, 0x4e, 0x4b, 0x53, 0x10, 0x03, 0x12, 0x1a, 0x0a, 0x16, + 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x41, 0x54, 0x45, 0x5f, + 0x34, 0x4c, 0x49, 0x4e, 0x4b, 0x53, 0x10, 0x04, 0x12, 0x1e, 0x0a, 0x1a, 0x54, 0x45, 0x53, 0x54, + 0x42, 0x45, 0x44, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x41, 0x54, 0x45, 0x5f, 0x39, 0x4c, 0x49, 0x4e, + 0x4b, 0x53, 0x5f, 0x4c, 0x41, 0x47, 0x10, 0x05, 0x12, 0x1e, 0x0a, 0x1a, 0x54, 0x45, 0x53, 0x54, + 0x42, 0x45, 0x44, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x41, 0x54, 0x45, 0x5f, + 0x32, 0x4c, 0x49, 0x4e, 0x4b, 0x53, 0x10, 0x06, 0x12, 0x1a, 0x0a, 0x16, 0x54, 0x45, 0x53, 0x54, + 0x42, 0x45, 0x44, 0x5f, 0x44, 0x55, 0x54, 0x5f, 0x41, 0x54, 0x45, 0x5f, 0x38, 0x4c, 0x49, 0x4e, + 0x4b, 0x53, 0x10, 0x07, 0x12, 0x15, 0x0a, 0x11, 0x54, 0x45, 0x53, 0x54, 0x42, 0x45, 0x44, 0x5f, + 0x44, 0x55, 0x54, 0x5f, 0x34, 0x30, 0x30, 0x5a, 0x52, 0x10, 0x08, 0x22, 0x6d, 0x0a, 0x04, 0x54, + 0x61, 0x67, 0x73, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x41, 0x47, 0x53, 0x5f, 0x55, 0x4e, 0x53, 0x50, + 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x41, 0x47, + 0x53, 0x5f, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x01, 0x12, + 0x18, 0x0a, 0x14, 0x54, 0x41, 0x47, 0x53, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x43, 0x45, 0x4e, 0x54, + 0x45, 0x52, 0x5f, 0x45, 0x44, 0x47, 0x45, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x54, 0x41, 0x47, + 0x53, 0x5f, 0x45, 0x44, 0x47, 0x45, 0x10, 0x03, 0x12, 0x10, 0x0a, 0x0c, 0x54, 0x41, 0x47, 0x53, + 0x5f, 0x54, 0x52, 0x41, 0x4e, 0x53, 0x49, 0x54, 0x10, 0x04, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( From ae4d456553b98091abed0c50050c50a3ac29f5f6 Mon Sep 17 00:00:00 2001 From: Marc Charlebois <105758144+MarcCharlebois@users.noreply.github.com> Date: Fri, 26 Jul 2024 09:10:28 -0700 Subject: [PATCH 2/2] gNOI-6.1 refactor proposal (#3101) * gNOI-6.1 refactor "This code is a Contribution to the OpenConfig Feature Profiles project ("Work") made under the Google Software Grant and Corporate Contributor License Agreement ("CLA") and governed by the Apache License 2.0. No other rights or licenses in or to any of Nokia's intellectual property are granted for any other purpose. This code is provided on an "as is" basis without any warranties of any kind." * added juniper's path to the map. "This code is a Contribution to the OpenConfig Feature Profiles project ("Work") made under the Google Software Grant and Corporate Contributor License Agreement ("CLA") and governed by the Apache License 2.0. No other rights or licenses in or to any of Nokia's intellectual property are granted for any other purpose. This code is provided on an "as is" basis without any warranties of any kind." --- .../tests/factory_reset_test/README.md | 9 +- .../factory_reset_test/factory_reset_test.go | 234 ++++++++++-------- .../factory_reset_test/metadata.textproto | 2 +- 3 files changed, 133 insertions(+), 112 deletions(-) diff --git a/feature/gnoi/factory_reset/tests/factory_reset_test/README.md b/feature/gnoi/factory_reset/tests/factory_reset_test/README.md index 0bfcfb35233a..062a5187a1f8 100644 --- a/feature/gnoi/factory_reset/tests/factory_reset_test/README.md +++ b/feature/gnoi/factory_reset/tests/factory_reset_test/README.md @@ -1,16 +1,15 @@ # gNOI-6.1: Factory Reset ## Summary -Performs Factory Reset with and without disk-encryption +Performs Factory Reset ## Procedure -* Create dummy files in the harddisk of the router using bash dd -* Checks for disk-encryption status and performs reset on both the scenarios +* Create a sample file in the harddisk of the router using gNOI PUT RPC * Secure ZTP server should be up and running in the background for the router to boot up with the base config once factory reset command is sent on the box. * Send out Factory reset via GNOI Raw API * Wait for the box to boot up via Secure ZTP * The base config is updated on the box via Secure ZTP -* Connect to the router and check if the files in the harddisk are removed as a part of verifying Factory reset. +* Send a gNOI file STAT RPC to check if the file in the harddisk are removed as a part of verifying Factory reset. ## OpenConfig Path and RPC Coverage @@ -21,4 +20,6 @@ paths used for test setup are not listed here. rpcs: gnoi: factory_reset.FactoryReset.Start: + file.File.Put: + file.File.Stat: ``` diff --git a/feature/gnoi/factory_reset/tests/factory_reset_test/factory_reset_test.go b/feature/gnoi/factory_reset/tests/factory_reset_test/factory_reset_test.go index 93d161332a57..25a626b7b73e 100644 --- a/feature/gnoi/factory_reset/tests/factory_reset_test/factory_reset_test.go +++ b/feature/gnoi/factory_reset/tests/factory_reset_test/factory_reset_test.go @@ -2,25 +2,32 @@ package factoryreset import ( "context" - "fmt" - "path" - "strings" + "crypto/md5" + "crypto/rand" + "io" + "path/filepath" + "regexp" "testing" "time" "github.com/openconfig/featureprofiles/internal/fptest" frpb "github.com/openconfig/gnoi/factory_reset" + fpb "github.com/openconfig/gnoi/file" + "github.com/openconfig/gnoi/types" + "github.com/openconfig/gnoigo" "github.com/openconfig/ondatra" "github.com/openconfig/ondatra/gnmi" "github.com/openconfig/testt" ) var ( - filesCreated = []string{} - fileCreateDevRand = "bash dd if=/dev/urandom of=%s bs=1M count=2" - checkFileExists = "bash [ -f \"%s\" ] && echo \"YES_exists\"" - fileExists = "YES_exists" - fileCreate = "bash fallocate -l %dM %s" + remoteFilePath = map[ondatra.Vendor]string{ + ondatra.CISCO: "/misc/disk1/", + ondatra.NOKIA: "/tmp/", + ondatra.JUNIPER: "/var/tmp/", + } + afterReset = false + fileName = "devrandom.log" ) const maxRebootTime = 40 // 40 mins wait time for the factory reset and sztp to kick in @@ -28,54 +35,6 @@ func TestMain(m *testing.M) { fptest.RunTests(m) } -type encryptionCommands struct { - EncryptionStatus string - EncryptionActivate string - EncryptionDeactivate string - DevicePaths []string -} - -var enCiscoCommands encryptionCommands - -// creating files before factory reset -func createFiles(t *testing.T, dut *ondatra.DUTDevice, devicePaths []string) { - for _, folderPath := range devicePaths { - fPath := path.Join(folderPath, "devrandom.log") - dut.CLI().Run(t, fmt.Sprintf(fileCreateDevRand, fPath)) - t.Log("Check if the file is created") - time.Sleep(30 * time.Second) - filesCreated = append(filesCreated, fPath) - fPath = path.Join(folderPath, ".devrandom.log") - dut.CLI().Run(t, fmt.Sprintf(fileCreateDevRand, fPath)) - - filesCreated = append(filesCreated, fPath) - fPath = path.Join(folderPath, "largeFile.log") - dut.CLI().Run(t, fmt.Sprintf(fileCreate, 100, fPath)) - - filesCreated = append(filesCreated, fPath) - } - for _, f := range filesCreated { - resp := dut.CLI().Run(t, fmt.Sprintf(checkFileExists, f)) - t.Logf("%v", resp) - if !strings.Contains(resp, fileExists) { - t.Fatalf("Unable to Create a file object %s in device %s", f, dut.Name()) - } - } - -} - -// checkFiles check if the files created are deleted from the device after factory reset -func checkFiles(t *testing.T, dut *ondatra.DUTDevice) { - for _, f := range filesCreated { - resp := dut.CLI().Run(t, fmt.Sprintf(checkFileExists, f)) - t.Logf(resp) - if strings.Contains(resp, fileExists) == true { - t.Fatalf("File %s not cleared by system Reset, in device %s", f, dut.Name()) - } - - } -} - func deviceBootStatus(t *testing.T, dut *ondatra.DUTDevice) { startReboot := time.Now() t.Logf("Wait for DUT to boot up by polling the telemetry output.") @@ -100,13 +59,119 @@ func deviceBootStatus(t *testing.T, dut *ondatra.DUTDevice) { t.Logf("Device boot time: %.2f minutes", time.Since(startReboot).Minutes()) } -// performs factory reset -func factoryReset(t *testing.T, dut *ondatra.DUTDevice, devicePaths []string) { - createFiles(t, dut, devicePaths) +func gNOIPutFile(t *testing.T, dut *ondatra.DUTDevice, gnoiClient gnoigo.Clients, fName string) { + dutVendor := dut.Vendor() + fullPath := filepath.Join(remoteFilePath[dutVendor], fName) + stream, err := gnoiClient.File().Put(context.Background()) + t.Logf("Attempting to send gNOI File Put here: %v", fullPath) + if err != nil { + t.Fatalf("Failed to create stream channel: %v", err) + } + defer stream.CloseSend() + h := md5.New() + fPutOpen := &fpb.PutRequest_Open{ + Open: &fpb.PutRequest_Details{ + RemoteFile: fullPath, + Permissions: 744, + }, + } + err = stream.Send(&fpb.PutRequest{ + Request: fPutOpen, + }) + if err != nil { + t.Fatalf("Stream failed to send PutRequest: %v", err) + } + + b := make([]byte, 64*1024) + n, err := rand.Read(b) + if err != nil && err != io.EOF { + t.Fatalf("Error reading bytes: %v", err) + } + h.Write(b[:n]) + req := &fpb.PutRequest{ + Request: &fpb.PutRequest_Contents{ + Contents: b[:n], + }, + } + err = stream.Send(req) + if err != nil { + t.Fatalf("Stream failed to send Req: %v", err) + } + + hashReq := &fpb.PutRequest{ + Request: &fpb.PutRequest_Hash{ + Hash: &types.HashType{ + Method: types.HashType_MD5, + Hash: h.Sum(nil), + }, + }, + } + err = stream.Send(hashReq) + if err != nil { + t.Fatalf("Stream failed to send hash: %v", err) + } + + _, err = stream.CloseAndRecv() + if err != nil { + t.Fatalf("Problem closing the stream: %v", err) + } +} + +func gNOIStatFile(t *testing.T, dut *ondatra.DUTDevice, fName string) { + dutVendor := dut.Vendor() + fullPath := filepath.Join(remoteFilePath[dutVendor], fName) gnoiClient, err := dut.RawAPIs().BindingDUT().DialGNOI(context.Background()) if err != nil { t.Fatalf("Error dialing gNOI: %v", err) } + if _, ok := remoteFilePath[dutVendor]; !ok { + t.Fatalf("Please add support for vendor %v in var remoteFilePath ", dutVendor) + } + + in := &fpb.StatRequest{ + Path: remoteFilePath[dutVendor], + } + statResp, err := gnoiClient.File().Stat(context.Background(), in) + if err != nil { + t.Fatalf("Error fetching stat path %v for the created file on DUT. %v", remoteFilePath[dutVendor], err) + } + + if len(statResp.GetStats()) == 0 { + t.Log("gNOI STAT did not find any files") + } + + r := regexp.MustCompile(fName) + var isCreatedFile bool + + for _, fileStats := range statResp.GetStats() { + isCreatedFile = r.MatchString(fileStats.GetPath()) && (fileStats.GetSize() == uint64(64*1024)) + if isCreatedFile { + break + } + } + if isCreatedFile { + if !afterReset { + t.Logf("gNOI PUT successfully created file: %s", fullPath) + } else { + t.Errorf("gNOI PUT file was found after Factory Reset: %s", fullPath) + } + } + if !isCreatedFile { + if !afterReset { + t.Error("gNOI PUT file was never Created") + } else { + t.Logf("Did not find %s in the list of files", fullPath) + } + } +} + +func factoryReset(t *testing.T, dut *ondatra.DUTDevice) { + gnoiClient, err := dut.RawAPIs().BindingDUT().DialGNOI(context.Background()) + if err != nil { + t.Fatalf("Error dialing gNOI: %v", err) + } + gNOIPutFile(t, dut, gnoiClient, fileName) + gNOIStatFile(t, dut, fileName) facRe, err := gnoiClient.FactoryReset().Start(context.Background(), &frpb.StartRequest{FactoryOs: false, ZeroFill: false}) if err != nil { t.Fatalf("Failed to initiate Factory Reset on the device, Error : %v ", err) @@ -114,56 +179,11 @@ func factoryReset(t *testing.T, dut *ondatra.DUTDevice, devicePaths []string) { t.Logf("Factory reset Response %v ", facRe) time.Sleep(2 * time.Minute) deviceBootStatus(t, dut) - dutNew := ondatra.DUT(t, "dut") - checkFiles(t, dutNew) - t.Log("Factory reset successfull") + afterReset = true + gNOIStatFile(t, dut, fileName) } func TestFactoryReset(t *testing.T) { dut := ondatra.DUT(t, "dut") - - switch dut.Vendor() { - case ondatra.CISCO: - enCiscoCommands = encryptionCommands{EncryptionStatus: "show disk-encryption status", EncryptionActivate: "disk-encryption activate", EncryptionDeactivate: "disk-encryption deactivate", DevicePaths: []string{"/misc/disk1"}} - t.Logf("Cisco commands for disk encryption %v ", enCiscoCommands) - default: - t.Fatalf("Disk Encryption commands is missing for %v ", dut.Vendor().String()) - } - - showDiskEncryptionStatus := dut.CLI().Run(t, enCiscoCommands.EncryptionStatus) - t.Logf("Disk encryption status %v", showDiskEncryptionStatus) - - if strings.Contains(showDiskEncryptionStatus, "Not Encrypted") { - t.Log("Performing Factory reset without Encryption\n") - factoryReset(t, dut, enCiscoCommands.DevicePaths) - t.Log("Stablise after factory reset\n") - time.Sleep(5 * time.Minute) - t.Log("Activate Encryption\n") - encrypt := dut.CLI().Run(t, enCiscoCommands.EncryptionActivate) - t.Logf("Sleep for 5 mins after disk-encryption activate") - time.Sleep(5 * time.Minute) - t.Logf("Device encryption acrivare: %v", encrypt) - deviceBootStatus(t, dut) - encrypt = dut.CLI().Run(t, enCiscoCommands.EncryptionStatus) - t.Logf("Show device encryption status: %v", encrypt) - t.Log("Wait for the system to stabilize\n") - time.Sleep(5 * time.Minute) - factoryReset(t, dut, enCiscoCommands.DevicePaths) - } else { - t.Log("Performing Factory reset with Encryption\n") - factoryReset(t, dut, enCiscoCommands.DevicePaths) - t.Log("Stablise after factory reset\n") - time.Sleep(5 * time.Minute) - t.Log("Deactivate Encryption\n") - encrypt := dut.CLI().Run(t, enCiscoCommands.EncryptionDeactivate) - t.Logf("Device encrytion deactivate: %v", encrypt) - t.Logf("Sleep for 5 mins after disk-encryption deactivate") - time.Sleep(5 * time.Minute) - deviceBootStatus(t, dut) - encrypt = dut.CLI().Run(t, enCiscoCommands.EncryptionStatus) - t.Logf("Show device encrytion status: %v", encrypt) - t.Logf("Wait for the system to stabilize\n") - time.Sleep(5 * time.Minute) - factoryReset(t, dut, enCiscoCommands.DevicePaths) - } + factoryReset(t, dut) } diff --git a/feature/gnoi/factory_reset/tests/factory_reset_test/metadata.textproto b/feature/gnoi/factory_reset/tests/factory_reset_test/metadata.textproto index 231f9b845d80..9ce3bad8abe1 100644 --- a/feature/gnoi/factory_reset/tests/factory_reset_test/metadata.textproto +++ b/feature/gnoi/factory_reset/tests/factory_reset_test/metadata.textproto @@ -4,4 +4,4 @@ uuid: "15e3ade1-e3c4-4da3-8553-3a9ef5fba344" plan_id: "gNOI-6.1" description: "Factory Reset" -testbed: TESTBED_DUT_ATE_2LINKS +testbed: TESTBED_DUT