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

changed int types to uint with gosnappi 0.12 #59

Merged
merged 2 commits into from
Sep 19, 2023
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
10 changes: 5 additions & 5 deletions cmd/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var bgpTypeEnum gosnappi.BgpV4PeerAsTypeEnum // BGP peering type as gosnappi enu
var bgpPeerIP string // Peer IP address
var bgpRoute string // Route to advertise
var bgpRouteAddress string // Address part of the route to advertise
var bgpRoutePrefix int32 // Prefix mask part of the route to advertise
var bgpRoutePrefix uint32 // Prefix mask part of the route to advertise

// bgpCmd represents the bgp command
var bgpCmd = &cobra.Command{
Expand Down Expand Up @@ -80,7 +80,7 @@ For more information, go to https://github.com/open-traffic-generator/otgen
log.Fatalf("Wrong netmask prefix format in the route: %s", bgpRoute)
}
if 0 <= p && p <= 32 {
bgpRoutePrefix = int32(p)
bgpRoutePrefix = uint32(p)
} else {
log.Fatalf("Netmask prefix has to be from 0 to 32 in the route: %s", bgpRoute)
}
Expand Down Expand Up @@ -164,9 +164,9 @@ func newBgp(config gosnappi.Config) {
bgpIPv4Peer = bgpIPv4Interface.Peers().Add().SetName(bgpDeviceIPv4Interface.Name() + ".bgp.peer." + bgpPeerIP)
}

bgpIPv4Peer.SetAsNumber(int32(bgpASN)).SetAsType(bgpTypeEnum) // TODO update as_number_width for longer ASNs
bgpIPv4Peer.SetPeerAddress(bgpPeerIP) // TODO check if it is IPv6
if bgpRoute != "" { // TODO IPv6
bgpIPv4Peer.SetAsNumber(bgpASN).SetAsType(bgpTypeEnum)
bgpIPv4Peer.SetPeerAddress(bgpPeerIP) // TODO check if it is IPv6
if bgpRoute != "" { // TODO IPv6
var bgpIPv4PeerRouteRange gosnappi.BgpV4RouteRange
for _, v := range bgpIPv4Peer.V4Routes().Items() {
if v.HasNextHopMode() && v.NextHopMode() == gosnappi.BgpV4RouteRangeNextHopMode.LOCAL_IP {
Expand Down
4 changes: 2 additions & 2 deletions cmd/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var devicePortLocation string // Test port location string
var deviceMac string // Device ethernet MAC
var deviceIPv4 string // Device IPv4 address
var deviceGWv4 string // Device IPv4 default gateway
var devicePrefixv4 int32 // Device IPv4 network prefix
var devicePrefixv4 uint32 // Device IPv4 network prefix

// deviceCmd represents the device command
var deviceCmd = &cobra.Command{
Expand Down Expand Up @@ -99,7 +99,7 @@ func init() {
deviceCmd.Flags().StringVarP(&deviceMac, "mac", "M", "", fmt.Sprintf("Device MAC address (default \"%s\")", MAC_DEFAULT_SRC))
deviceCmd.Flags().StringVarP(&deviceIPv4, "ip", "I", IPV4_DEFAULT_SRC, "Device IP address") // TODO consider IP/prefix format: split(a, "/")
deviceCmd.Flags().StringVarP(&deviceGWv4, "gw", "G", IPV4_DEFAULT_GW, "Device default gateway")
deviceCmd.Flags().Int32VarP(&devicePrefixv4, "prefix", "P", IPV4_DEFAULT_PREFIX, "Device network prefix")
deviceCmd.Flags().Uint32VarP(&devicePrefixv4, "prefix", "P", IPV4_DEFAULT_PREFIX, "Device network prefix")

var deviceCmdCreateCopy = *deviceCmd
var deviceCmdAddCopy = *deviceCmd
Expand Down
20 changes: 10 additions & 10 deletions cmd/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ var flowIPv6 bool // IP version 6
var flowSrc string // Source IP address
var flowDst string // Destination IP address
var flowProto string // IP transport protocol
var flowSrcPort int32 // Source TCP/UDP port
var flowDstPort int32 // Destination TCP/UDP port
var flowSrcPort uint32 // Source TCP/UDP port
var flowDstPort uint32 // Destination TCP/UDP port
var flowTxRxSwap bool // Swap default values between Tx and Rx, source and destination
var flowRate int64 // Packet per second rate
var flowFixedPackets int32 // Number of packets to transmit
var flowFixedSize int32 // Frame size in bytes
var flowRate uint64 // Packet per second rate
var flowFixedPackets uint32 // Number of packets to transmit
var flowFixedSize uint32 // Frame size in bytes
var flowDisableMetrics bool // Disable flow metrics
var flowLossMetrics bool // Enable loss metrics
var flowLatencyMetrics string // Enable latency metrics mode
Expand Down Expand Up @@ -236,18 +236,18 @@ func init() {
// Transport protocol
flowCmd.Flags().StringVarP(&flowProto, "proto", "P", PROTO_TCP, "IP transport protocol: \"icmp\" | \"tcp\" | \"udp\"")

flowCmd.Flags().Int32VarP(&flowSrcPort, "sport", "", SPORT_DEFAULT, "Source TCP/UDP port. If not specified, an incremental set of source ports would be used for each packet")
flowCmd.Flags().Int32VarP(&flowDstPort, "dport", "p", DPORT_DEFAULT, "Destination TCP/UDP port")
flowCmd.Flags().Uint32VarP(&flowSrcPort, "sport", "", SPORT_DEFAULT, "Source TCP/UDP port. If not specified, an incremental set of source ports would be used for each packet")
flowCmd.Flags().Uint32VarP(&flowDstPort, "dport", "p", DPORT_DEFAULT, "Destination TCP/UDP port")

flowCmd.Flags().BoolVarP(&flowTxRxSwap, "swap", "", false, "Swap default values between Tx and Rx, source and destination")

flowCmd.Flags().Int64VarP(&flowRate, "rate", "r", 0, "Packet per second rate. If not specified, default rate decision would be left to the traffic engine")
flowCmd.Flags().Uint64VarP(&flowRate, "rate", "r", 0, "Packet per second rate. If not specified, default rate decision would be left to the traffic engine")

// We use 1000 as a default value for packet count instead of continuos mode per OTG spec,
// as we want to prevent situations when unsuspecting user end up with non-stopping traffic
// if no parameter was specified
flowCmd.Flags().Int32VarP(&flowFixedPackets, "count", "c", 1000, "Number of packets to transmit. Use 0 for continuos mode")
flowCmd.Flags().Int32VarP(&flowFixedSize, "size", "", 0, "Frame size in bytes. If not specified, the minimum supported by the traffic engine will be used")
flowCmd.Flags().Uint32VarP(&flowFixedPackets, "count", "c", 1000, "Number of packets to transmit. Use 0 for continuos mode")
flowCmd.Flags().Uint32VarP(&flowFixedSize, "size", "", 0, "Frame size in bytes. If not specified, the minimum supported by the traffic engine will be used")

// Metrics
flowCmd.Flags().BoolVarP(&flowDisableMetrics, "nometrics", "", false, "Disable flow metrics")
Expand Down
30 changes: 15 additions & 15 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var otgYaml bool // Format of OTG input is YAML. Mutually exclu
var otgJson bool // Format of OTG input is JSON. Mutually exclusive with --yaml
var otgFile string // OTG configuration file
var otgRxBgpStr string // How many BGP routes shall we receive to consider the protocol is up. In routes or multiples of routes advertised
var otgRxBgpNumber int32 // Parsed number of BGP routes we shall receive
var otgRxBgpNumber uint64 // Parsed number of BGP routes we shall receive
var otgRxBgpMultiplier int // Parsed multiplier of advertised BGP routes we shall receive
var otgMetrics string // Metrics types to report as a comma-separated list: "port" for PortMetrics, "flow" for FlowMetrics, "bgp4" for Bgpv4Metrics
var otgMetricsMap map[string]bool // Metrics to report parsed into a map
Expand Down Expand Up @@ -86,7 +86,7 @@ For more information, go to https://github.com/open-traffic-generator/otgen
if err != nil {
log.Fatalf("Incorrect format for --rxbgp routes number: %s is not an integer", otgRxBgpStr)
}
otgRxBgpNumber = int32(n)
otgRxBgpNumber = uint64(n)
log.Debugf("Will use %d for number of expected number of BGP routes to receive", otgRxBgpNumber)
} else {
log.Fatalf("Incorrect format for --rxbgp parameter: %s has to be an integer or an integer with \"x\" suffix for a multiplier", otgRxBgpStr)
Expand Down Expand Up @@ -223,7 +223,7 @@ func startProtocols(api gosnappi.GosnappiApi, config gosnappi.Config) (gosnappi.

// Detect protocols present in the configuration
var configuredProtocols = make(map[string]bool)
var routesPerProtocol = make(map[string]int32)
var routesPerProtocol = make(map[string]uint64)
for _, d := range config.Devices().Items() {
if d.Bgp().RouterId() != "" {
proto := "bgp4"
Expand All @@ -237,7 +237,7 @@ func startProtocols(api gosnappi.GosnappiApi, config gosnappi.Config) (gosnappi.
for _, p := range i.Peers().Items() {
for _, r := range p.V4Routes().Items() {
for _, a := range r.Addresses().Items() {
routesPerProtocol[proto] += a.Count()
routesPerProtocol[proto] += uint64(a.Count())
}
}
}
Expand All @@ -264,8 +264,8 @@ func startProtocols(api gosnappi.GosnappiApi, config gosnappi.Config) (gosnappi.
res, err := api.GetMetrics(req)
printMetricsResponse(res, err)
protocolState[proto] = true
advertisedRoutes := int32(0)
receivedRoutes := int32(0)
advertisedRoutes := uint64(0)
receivedRoutes := uint64(0)
for _, m := range res.Bgpv4Metrics().Items() {
// Check if protocol came up
if m.SessionState() != gosnappi.Bgpv4MetricSessionState.UP {
Expand All @@ -284,7 +284,7 @@ func startProtocols(api gosnappi.GosnappiApi, config gosnappi.Config) (gosnappi.
if otgRxBgpNumber > 0 && receivedRoutes < otgRxBgpNumber {
// Not all expected routes were received yet
protocolState[proto] = false
} else if otgRxBgpMultiplier > 0 && receivedRoutes < advertisedRoutes*int32(otgRxBgpMultiplier) {
} else if otgRxBgpMultiplier > 0 && receivedRoutes < advertisedRoutes*uint64(otgRxBgpMultiplier) {
// Not all expected routes were received yet
protocolState[proto] = false
}
Expand Down Expand Up @@ -402,18 +402,18 @@ func stopProtocols(api gosnappi.GosnappiApi, config gosnappi.Config) (gosnappi.G
return api, config
}

func calculateTrafficTargets(config gosnappi.Config) (int64, time.Duration) {
func calculateTrafficTargets(config gosnappi.Config) (uint64, time.Duration) {
// Initialize packet counts and rates per flow if they were provided as parameters. Calculate ETA
pktCountTotal := int64(0)
pktCountTotal := uint64(0)
flowETA := time.Duration(0)
trafficETA := time.Duration(0)
for _, f := range config.Flows().Items() {
pktCountFlow := f.Duration().FixedPackets().Packets()
pktCountTotal += int64(pktCountFlow)
pktCountTotal += uint64(pktCountFlow)
ratePPSFlow := f.Rate().Pps()
// Calculate ETA it will take to transmit the flow
if ratePPSFlow > 0 {
flowETA = time.Duration(float64(int64(pktCountFlow)/ratePPSFlow)) * time.Second
flowETA = time.Duration(float64(uint64(pktCountFlow)/ratePPSFlow)) * time.Second
}
if flowETA > trafficETA {
trafficETA = flowETA // The longest flow to finish
Expand All @@ -422,11 +422,11 @@ func calculateTrafficTargets(config gosnappi.Config) (int64, time.Duration) {
return pktCountTotal, trafficETA
}

func isTrafficRunning(mr gosnappi.MetricsResponse, targetTx int64) bool {
func isTrafficRunning(mr gosnappi.MetricsResponse, targetTx uint64) bool {
trafficRunning := false // we'll check if there are flows still running

if mr.Choice() == "port_metrics" {
total_tx := int64(0)
total_tx := uint64(0)
for _, pm := range mr.PortMetrics().Items() {
total_tx += pm.FramesTx()
}
Expand All @@ -446,11 +446,11 @@ func isTrafficRunning(mr gosnappi.MetricsResponse, targetTx int64) bool {
return trafficRunning
}

func isTrafficRunningWithETA(mr gosnappi.MetricsResponse, targetTx int64, start time.Time, trafficETA time.Duration) bool {
func isTrafficRunningWithETA(mr gosnappi.MetricsResponse, targetTx uint64, start time.Time, trafficETA time.Duration) bool {
trafficRunning := false // we'll check if there are flows still running

if mr.Choice() == "port_metrics" {
total_tx := int64(0)
total_tx := uint64(0)
for _, pm := range mr.PortMetrics().Items() {
total_tx += pm.FramesTx()
}
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/mum4k/termdash v0.18.0
github.com/olekukonko/tablewriter v0.0.5
github.com/open-traffic-generator/snappi/gosnappi v0.11.17
github.com/open-traffic-generator/snappi/gosnappi v0.12.3
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
google.golang.org/protobuf v1.31.0
Expand All @@ -21,15 +21,15 @@ require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.2 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading
Loading