diff --git a/feature/b2b/lldp/lldp_neighbors_test.go b/feature/b2b/lldp/lldp_neighbors_test.go index 516fa25..9ee0d37 100644 --- a/feature/b2b/lldp/lldp_neighbors_test.go +++ b/feature/b2b/lldp/lldp_neighbors_test.go @@ -5,7 +5,6 @@ package lldp import ( "testing" "time" - "github.com/open-traffic-generator/conformance/helpers/otg" "github.com/open-traffic-generator/snappi/gosnappi" ) @@ -23,7 +22,7 @@ func TestLldpNeighbors(t *testing.T) { c := lldpNeighborsConfig(api, testConst) api.SetConfig(c) - + api.StartCapture() api.StartProtocols() api.WaitFor( @@ -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 { @@ -56,6 +64,9 @@ 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)) @@ -63,6 +74,11 @@ func lldpNeighborsConfig(api *otg.OtgApi, tc map[string]interface{}) gosnappi.Co 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 } @@ -92,5 +108,7 @@ func lldpNeighborsLldpNeighborsOk(api *otg.OtgApi, tc map[string]interface{}) bo } } - return count == 2 + return true } + + diff --git a/helpers/otg/capture.go b/helpers/otg/capture.go index 961c36a..23d3a52 100644 --- a/helpers/otg/capture.go +++ b/helpers/otg/capture.go @@ -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) @@ -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() +}