diff --git a/feature/sflow/otg_tests/sflow_base_test/sflow_base_test.go b/feature/sflow/otg_tests/sflow_base_test/sflow_base_test.go index 67016c76757..f2c61917635 100644 --- a/feature/sflow/otg_tests/sflow_base_test/sflow_base_test.go +++ b/feature/sflow/otg_tests/sflow_base_test/sflow_base_test.go @@ -94,6 +94,9 @@ var ( IPv6Len: plenIPv6, MAC: "02:00:02:01:01:01", } + + loopbackSubIntfNum = 1 + dutlo0Attrs = attrs.Attributes{ Desc: "Loopback ip", IPv4: "203.0.113.1", @@ -173,7 +176,12 @@ func TestSFlowTraffic(t *testing.T) { ate := ondatra.ATE(t, "ate") - loopbackIntfName := netutil.LoopbackInterface(t, dut, 1) + switch dut.Vendor() { + case ondatra.JUNIPER: + loopbackSubIntfNum = 0 + } + + loopbackIntfName := netutil.LoopbackInterface(t, dut, loopbackSubIntfNum) // Configure DUT if !deviations.InterfaceConfigVRFBeforeAddress(dut) { @@ -200,7 +208,7 @@ func TestSFlowTraffic(t *testing.T) { t.Run("SFLOW-1.1_ReplaceDUTConfigSFlow", func(t *testing.T) { sfBatch := &gnmi.SetBatch{} - cfgplugins.NewSFlowGlobalCfg(t, sfBatch, nil, dut, mgmtVRF, loopbackIntfName) + cfgplugins.NewSFlowGlobalCfg(t, sfBatch, nil, dut, mgmtVRF, loopbackIntfName, dutlo0Attrs.IPv4, dutlo0Attrs.IPv6) sfBatch.Set(t, dut) gotSamplingConfig := gnmi.Get(t, dut, gnmi.OC().Sampling().Sflow().Config()) @@ -239,10 +247,6 @@ func TestSFlowTraffic(t *testing.T) { testFlowFixed(t, ate, config, IPv6) }) }) - - defer func() { - gnmi.Delete(t, dut, gnmi.OC().NetworkInstance(mgmtVRF).Config()) - }() } func testFlowFixed(t *testing.T, ate *ondatra.ATEDevice, config gosnappi.Config, ip IPType) { @@ -354,7 +358,7 @@ func addInterfacesToVRF(t *testing.T, dut *ondatra.DUTDevice, vrfname string, in } func configureLoopbackOnDUT(t *testing.T, dut *ondatra.DUTDevice) { - loopbackIntfName := netutil.LoopbackInterface(t, dut, 1) + loopbackIntfName := netutil.LoopbackInterface(t, dut, loopbackSubIntfNum) loop := dutlo0Attrs.NewOCInterface(loopbackIntfName, dut) loop.Type = oc.IETFInterfaces_InterfaceType_softwareLoopback loop.Description = ygot.String(fmt.Sprintf("Port %s", loopbackIntfName)) diff --git a/internal/cfgplugins/sflow.go b/internal/cfgplugins/sflow.go index 842250f7f02..bf0086daba0 100644 --- a/internal/cfgplugins/sflow.go +++ b/internal/cfgplugins/sflow.go @@ -30,7 +30,7 @@ import ( // configuration including any deviations for the device. // If sfglobal is nil, default values are provided. // The SFlow configuration is returned to give the caller an option to override default values. -func NewSFlowGlobalCfg(t *testing.T, batch *gnmi.SetBatch, newcfg *oc.Sampling_Sflow, d *ondatra.DUTDevice, ni, intfName string) *oc.Sampling_Sflow { +func NewSFlowGlobalCfg(t *testing.T, batch *gnmi.SetBatch, newcfg *oc.Sampling_Sflow, d *ondatra.DUTDevice, ni, intfName string, srcAddrV4 string, srcAddrV6 string) *oc.Sampling_Sflow { c := new(oc.Sampling_Sflow) if newcfg == nil { @@ -41,7 +41,7 @@ func NewSFlowGlobalCfg(t *testing.T, batch *gnmi.SetBatch, newcfg *oc.Sampling_S c.Dscp = ygot.Uint8(8) c.GetOrCreateInterface(d.Port(t, "port1").Name()).Enabled = ygot.Bool(true) c.GetOrCreateInterface(d.Port(t, "port2").Name()).Enabled = ygot.Bool(true) - coll := NewSFlowCollector(t, batch, nil, d, ni, intfName) + coll := NewSFlowCollector(t, batch, nil, d, ni, intfName, srcAddrV4, srcAddrV6) for _, col := range coll { c.AppendCollector(col) } @@ -56,7 +56,7 @@ func NewSFlowGlobalCfg(t *testing.T, batch *gnmi.SetBatch, newcfg *oc.Sampling_S // NewSFlowCollector creates a collector to be appended to SFlowConfig. // If sfc is nil, default values are provided. -func NewSFlowCollector(t *testing.T, batch *gnmi.SetBatch, newcfg *oc.Sampling_Sflow_Collector, d *ondatra.DUTDevice, ni, intfName string) []*oc.Sampling_Sflow_Collector { +func NewSFlowCollector(t *testing.T, batch *gnmi.SetBatch, newcfg *oc.Sampling_Sflow_Collector, d *ondatra.DUTDevice, ni, intfName string, srcAddrV4 string, srcAddrV6 string) []*oc.Sampling_Sflow_Collector { coll := []*oc.Sampling_Sflow_Collector{} if newcfg == nil { @@ -76,11 +76,7 @@ func NewSFlowCollector(t *testing.T, batch *gnmi.SetBatch, newcfg *oc.Sampling_S helpers.GnmiCLIConfig(t, d, sFlowSourceAddressCli) } } else { - addresses := []string{} - for _, addr := range intf.GetSubinterface(0).GetIpv4().Address { - addresses = append(addresses, addr.GetIp()) - } - cV4.SetSourceAddress(addresses[0]) + cV4.SetSourceAddress(srcAddrV4) } cV4.SetNetworkInstance(ni) coll = append(coll, cV4) @@ -98,11 +94,7 @@ func NewSFlowCollector(t *testing.T, batch *gnmi.SetBatch, newcfg *oc.Sampling_S helpers.GnmiCLIConfig(t, d, sFlowSourceAddressCli) } } else { - addresses := []string{} - for _, addr := range intf.GetSubinterface(0).GetIpv6().Address { - addresses = append(addresses, addr.GetIp()) - } - cV6.SetSourceAddress(addresses[0]) + cV6.SetSourceAddress(srcAddrV6) } cV6.SetNetworkInstance(ni) coll = append(coll, cV6)