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

go snappi - cannot send traffic to SROS. #191

Open
asadarafat opened this issue Oct 12, 2022 · 1 comment
Open

go snappi - cannot send traffic to SROS. #191

asadarafat opened this issue Oct 12, 2022 · 1 comment
Assignees

Comments

@asadarafat
Copy link

asadarafat commented Oct 12, 2022

i build the network in CLAB and i have issue when sending traffic from IXIA-C to SROS.

/*
Test IPv4 Forwarding with
- Endpoints: OTG 1.1.1.1 -----> 1.1.1.2 DUT 2.2.2.1 ------> OTG 2.2.2.2
- Static Route on DUT: 20.20.20.0/24 -> 2.2.2.2
- TCP flow from OTG: 10.10.10.1 -> 20.20.20.1+

To run: go run ipv4_forwarding.go -dstMac=<MAC of 1.1.1.2>
*/

package main

import (
	"flag"
	"fmt"
	"log"
	"time"

	"github.com/open-traffic-generator/snappi/gosnappi"
)

// hostname and interfaces of ixia-c-one node from containerlab topology.
const (
	// otgHost = "https://clab-ixiac01-ixia-c"
	otgHost  = "https://clab-Vodafone-CO-HCO-ixia-c"
	otgPort1 = "eth1"
	otgPort2 = "eth2"
)

var (
	dstMac   = "ff:ff:ff:ff:ff:ff"
	srcMac   = "00:00:00:00:00:aa"
	pktCount = 1000
)

func main() {
	// replace value of dstMac with actual MAC of DUT interface connected to otgPort1
	flag.StringVar(&dstMac, "dstMac", dstMac, "Destination MAC address to be used for all packets")
	flag.Parse()

	api, config := newConfig()

	// push traffic configuration to otgHost
	res, err := api.SetConfig(config)
	checkResponse(res, err)

	// start transmitting configured flows
	ts := api.NewTransmitState().SetState(gosnappi.TransmitStateState.START)
	res, err = api.SetTransmitState(ts)
	checkResponse(res, err)

	// fetch flow metrics and wait for received frame count to be correct
	mr := api.NewMetricsRequest()
	mr.Flow()
	waitFor(
		func() bool {
			res, err := api.GetMetrics(mr)
			checkResponse(res, err)
			// return res.FlowMetrics().Items()[0].Transmit() == gosnappi.FlowMetricTransmit.STOPPED && res.FlowMetrics().Items()[0].FramesRx() == int64(pktCount)
			return res.FlowMetrics().Items()[0].Transmit() == gosnappi.FlowMetricTransmit.STOPPED && res.FlowMetrics().Items()[0].FramesRx() == int64(pktCount)
			// return false
		},
		3600*time.Second, // limit the execution time
	)
}

func checkResponse(res interface{}, err error) {
	if err != nil {
		log.Fatal(err)
	}
	switch v := res.(type) {
	case gosnappi.MetricsResponse:
		log.Printf("Metrics Response:\n%s\n", v)
	case gosnappi.ResponseWarning:
		for _, w := range v.Warnings() {
			log.Println("WARNING:", w)
		}
	default:
		log.Fatal("Unknown response type:", v)
	}
}

func newConfig() (gosnappi.GosnappiApi, gosnappi.Config) {
	// create a new API handle to make API calls against otgHost
	api := gosnappi.NewApi()
	api.NewHttpTransport().SetLocation(otgHost).SetVerify(false)

	// create an empty traffic configuration
	config := api.NewConfig()

	// create traffic endpoints
	p1 := config.Ports().Add().SetName("p1").SetLocation(otgPort1)
	p2 := config.Ports().Add().SetName("p2").SetLocation(otgPort2)

	// create a flow and set the endpoints
	f1 := config.Flows().Add().SetName("p1.v4.p2")
	f1.TxRx().Port().SetTxName(p1.Name()).SetRxName(p2.Name())

	// enable per flow metrics tracking
	f1.Metrics().SetEnable(true)
	// set size, count and transmit rate for all packets in the flow
	f1.Size().SetFixed(1400)
	f1.Rate().SetPps(1000)
	// f1.Rate().SetMbps(1)
	// f1.Duration().FixedPackets().SetPackets(int32(pktCount))
	f1.Duration().Continuous()

	// configure headers for all packets in the flow
	eth := f1.Packet().Add().Ethernet()
	eth.Src().SetValue(srcMac)
	eth.Dst().SetValue(dstMac)

	ip := f1.Packet().Add().Ipv4()
	// ip.Src().SetValue("10.10.10.1")
	// ip.Dst().Increment().SetStart("10.20.20.1").SetStep("0.0.0.1").SetCount(5)

	ip.Src().SetValue("10.1.1.1")
	ip.Dst().Increment().SetStart("10.2.2.1").SetStep("0.0.0.1").SetCount(5)

	tcp := f1.Packet().Add().Tcp()

	tcp.SrcPort().SetValue(3250)
	tcp.DstPort().Decrement().SetStart(8070).SetStep(2).SetCount(10)

	log.Printf("OTG configuration:\n%s\n", config)
	return api, config
}

func waitFor(fn func() bool, timeout time.Duration) {
	start := time.Now()
	for {
		if fn() {
			return
		}
		fmt.Printf("Execution time limit: " + timeout.String())
		if time.Since(start) > timeout {
			log.Fatal("Timeout occurred !")
		}
		time.Sleep(500 * time.Millisecond)
	}
}

when running the code i got the following exception

[suuser@nsp-kvm-host-antwerp topo-ixia-c]$ sudo go run  clab-ixia-srl-ipv4-fwd.go -dstMac "aa:c1:ab:1a:8c:ee"
2022/10/12 10:40:27 OTG configuration:
flows:
- duration:
    choice: continuous
    continuous:
      gap: 12
  metrics:
    enable: true
    loss: false
    timestamps: false
  name: p1.v4.p2
  packet:
  - choice: ethernet
    ethernet:
      dst:
        choice: value
        value: aa:c1:ab:1a:8c:ee
      src:
        choice: value
        value: 00:00:00:00:00:aa
  - choice: ipv4
    ipv4:
      dst:
        choice: increment
        increment:
          count: 5
          start: 10.2.2.1
          step: 0.0.0.1
      src:
        choice: value
        value: 10.1.1.1
  - choice: tcp
    tcp:
      dst_port:
        choice: decrement
        decrement:
          count: 10
          start: 8070
          step: 2
      src_port:
        choice: value
        value: 3250
  rate:
    choice: pps
    pps: "1000"
  size:
    choice: fixed
    fixed: 1400
  tx_rx:
    choice: port
    port:
      rx_name: p2
      tx_name: p1
ports:
- location: eth1
  name: p1
- location: eth2
  name: p2

2022/10/12 10:40:27 response not implemented
exit status 1

any idea what went wrong?

@ashutshkumr
Copy link
Contributor

@asadarafat could you please let us know which version of ixia-c-one and gosnappi are you using ?

I don't see any issues with the test and suspect version incompatibility.

@ashutshkumr ashutshkumr self-assigned this Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants