Skip to content

Commit

Permalink
lldp custom tlv
Browse files Browse the repository at this point in the history
  • Loading branch information
arkajyoti-cloud committed Aug 12, 2024
1 parent 3a78548 commit 253ab3a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
24 changes: 21 additions & 3 deletions feature/b2b/lldp/lldp_neighbors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package lldp
import (
"testing"
"time"

"github.com/open-traffic-generator/conformance/helpers/otg"
"github.com/open-traffic-generator/snappi/gosnappi"
)
Expand All @@ -23,7 +22,7 @@ func TestLldpNeighbors(t *testing.T) {
c := lldpNeighborsConfig(api, testConst)

api.SetConfig(c)

api.StartCapture()
api.StartProtocols()

api.WaitFor(
Expand All @@ -35,6 +34,15 @@ func TestLldpNeighbors(t *testing.T) {
func() bool { return lldpNeighborsLldpNeighborsOk(api, testConst) },
&otg.WaitForOpts{FnName: "WaitForLldpNeighbors", Timeout: 30 * time.Second},
)

api.StopProtocols()
api.StopCapture()

port1 := c.Ports().Items()[0]
//----------------------------------------------------------------------
// Get captute byte
//----------------------------------------------------------------------
api.SaveCapture(port1.Name(), "./lldp_capture")
}

func lldpNeighborsConfig(api *otg.OtgApi, tc map[string]interface{}) gosnappi.Config {
Expand All @@ -56,13 +64,21 @@ func lldpNeighborsConfig(api *otg.OtgApi, tc map[string]interface{}) gosnappi.Co
lldpTx.Connection().SetPortName(ptx.Name())
lldpTx.ChassisId().MacAddressSubtype().
SetValue(tc["txMac"].(string))
lldpTx.OrgInfos().Add().SetOui("00120F").SetSubtype(1).Information().SetInfo("036C000010")
lldpTx.OrgInfos().Add().SetOui("0012BB").SetSubtype(1).Information().SetInfo("000F04")
lldpTx.OrgInfos().Add().SetOui("0012BB").SetSubtype(2).Information().SetInfo("014065ae")

lldpRx.SetHoldTime(tc["holdTime"].(uint32))
lldpRx.SetAdvertisementInterval(tc["advInterval"].(uint32))
lldpRx.Connection().SetPortName(prx.Name())
lldpRx.ChassisId().MacAddressSubtype().
SetValue(tc["rxMac"].(string))

c.Captures().Add().
SetName("ca").
SetPortNames([]string{ptx.Name(), prx.Name()}).
SetFormat(gosnappi.CaptureFormat.PCAP)

api.Testing().Logf("Config:\n%v\n", c)
return c
}
Expand Down Expand Up @@ -92,5 +108,7 @@ func lldpNeighborsLldpNeighborsOk(api *otg.OtgApi, tc map[string]interface{}) bo
}
}

return count == 2
return true
}


27 changes: 26 additions & 1 deletion helpers/otg/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (o *OtgApi) GetCapture(portName string) *CapturedPackets {
if err != nil {
t.Fatalf("ERROR: Could not create temporary pcap file: %v\n", err)
}
defer os.Remove(f.Name())
//defer os.Remove(f.Name())

if _, err := f.Write(res); err != nil {
t.Fatalf("ERROR: Could not write bytes to pcap file: %v\n", err)
Expand Down Expand Up @@ -191,3 +191,28 @@ func (o *OtgApi) Uint64ToBytes(num uint64, size int) []byte {

return b
}

func (o *OtgApi) SaveCapture(portName string, fname string) {
t := o.Testing()
api := o.Api()

if !o.TestConfig().OtgCaptureCheck {
t.Log("Skipped GetCapture")
}

t.Logf("Getting capture from port %s ...\n", portName)
defer o.Timer(time.Now(), "GetCapture")

res, err := api.GetCapture(gosnappi.NewCaptureRequest().SetPortName(portName))
o.LogWrnErr(nil, err, true)

f, err := os.Create(fname + ".pcap")
if err != nil {
t.Fatalf("ERROR: Could not create temporary pcap file: %v\n", err)
}

if _, err := f.Write(res); err != nil {
t.Fatalf("ERROR: Could not write bytes to pcap file: %v\n", err)
}
f.Close()
}

0 comments on commit 253ab3a

Please sign in to comment.