open-traffic-generator / snappi

Open Traffic Generator SDK in Python and Go
MIT License
69 stars 7 forks source link

GoSnappi: existing node of input json is updated by FromJSON with defaults #125

Closed rudranil-das closed 2 years ago

rudranil-das commented 2 years ago

Observation from Snappi version: 0.6.5

Let me illustrate this with an example of - rate node of input json being updated by FromJSON (of gosnappi.Config) with defaults [i.e. "choice":1,"pps":1000].

Input json to (gosnappi.Config->)FromJSON

flows": [
    {
      "duration": {
        "choice": "fixed_packets",
        "fixed_packets": {
          "gap": 12,
          "packets": 50000
        }
      },
      "name": "flw",
      "packet": [
        {
          "choice": "ethernet",
          "ethernet": {}
        },
        {
          "choice": "ipv4",
          "ipv4": {}
        },
        {
          "choice": "tcp",
          "tcp": {
            "dst_port": {
              "choice": "values",
              "values": [
                3000,
                3010,
                3030
              ]
            },
            "src_port": {
              "choice": "increment",
              "increment": {
                "count": 501,
                "start": 5000,
                "step": 2
              }
            }
          }
        }
      ],
      "rate": {
        "choice": "percentage",
        "percentage": 10
      },
      "size": {
        "choice": "fixed",
        "fixed": 1518
      },
      "tx_rx": {
        "choice": "port",
        "port": {
          "tx_name": "tx"
        }
      }
    }
  ],
  "layer1": [
    {
      "auto_negotiate": true,
      "ieee_media_defaults": true,
      "mtu": 1600,
      "name": "l1",
      "port_names": [
        "tx"
      ],
      "promiscuous": true,
      "speed": "speed_1_gbps"
    }
  ],
  "ports": [
    {
      "location": "10.39.32.156:5555",
      "name": "tx"
    }
  ]
}   

Output object dump from (gosnappi.Config->)FromJSON is

{
   "ports":[
      {
         "location":"10.39.32.156:5555",
         "name":"tx"
      }
   ],
   "layer1":[
      {
         "port_names":[
            "tx"
         ],
         "speed":5,
         "promiscuous":true,
         "mtu":1600,
         "ieee_media_defaults":true,
         "auto_negotiate":true,
         "name":"l1"
      }
   ],
   "flows":[
      {
         "tx_rx":{
            "choice":1,
            "port":{
               "tx_name":"tx"
            }
         },
         "packet":[
            {
               "choice":2,
               "ethernet":{

               }
            },
            {
               "choice":5,
               "ipv4":{

               }
            },
            {
               "choice":9,
               "tcp":{
                  "src_port":{
                     "choice":3,
                     "value":0,
                     "increment":{
                        "start":5000,
                        "step":2,
                        "count":501
                     }
                  },
                  "dst_port":{
                     "choice":1,
                     "value":0,
                     "values":[
                        3000,
                        3010,
                        3030
                     ]
                  }
               }
            }
         ],
         "size":{
            "choice":1,
            "fixed":1518
         },
         "rate":{
            "choice":1,
            "pps":1000,
            "percentage":10
         },
         "duration":{
            "choice":1,
            "fixed_packets":{
               "packets":50000,
               "gap":12
            }
         },
         "name":"flw"
      }
   ]
}

If you look at the "rate" block, "choice" is reset to "1" [which is PPS] and "pps" = 1000 attribute is added.

I think setdefaults in workflow of FromJSON is causing this (but you can validate the same)

Similar issue is observed for FromJSON in following cases:

1. protocol header fields: "values" cases where choice is unmarshalled as "value", and default value of "value" field is assigned.

2. Other constructs like FlowDelay, FlowDurationInterBurstGap (could be in other places as well)

3. Constructs (like mentioned above) for other gosnappi APIs like FlowsUpdate
rudranil-das commented 2 years ago

This is a high priority issue for gosnappi integration in ixia-c as it is blocking 40+ E2E sanity-cases. @arkajyoti-cloud

ashutshkumr commented 2 years ago

@Rangababu-R I see multiple problems with JSON deserialization here. Let's break it up into multiple issues if needed.

Rangababu-R commented 2 years ago

looks like there is an issue with setDefaults. will fix and get back on this