Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFLOW-1: loopback sub-interface index and handling of source-address when configuring sflow collector #3445

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions feature/sflow/otg_tests/sflow_base_test/sflow_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand All @@ -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())
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down
18 changes: 5 additions & 13 deletions internal/cfgplugins/sflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading