pkt_gen: MoonGen Incorrect RX_MBPS Calculation
[vswitchperf.git] / tools / pkt_gen / xena / xena_json.py
index 39cc56c..1ce7b46 100644 (file)
@@ -95,7 +95,7 @@ class XenaJSON(object):
         ]
 
         self.json_data['StreamProfileHandler']['EntityList'][entity][
-            'StreamConfig']['HwModifiers'].append(segments)
+            'StreamConfig']['HwModifiers'] = (segments)
 
     def _create_packet_header(self):
         """
@@ -233,6 +233,22 @@ class XenaJSON(object):
         self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][
             'Enabled'] = 'true'
 
+    def modify_2544_tput_options(self, initial_value, minimum_value,
+                                 maximum_value, value_resolution,
+                                 use_pass_threshhold, pass_threshhold):
+        self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][
+            'RateIterationOptions']['InitialValue'] = initial_value
+        self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][
+            'RateIterationOptions']['MinimumValue'] = minimum_value
+        self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][
+            'RateIterationOptions']['MaximumValue'] = maximum_value
+        self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][
+            'RateIterationOptions']['ValueResolution'] = value_resolution
+        self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][
+            'RateIterationOptions']['UsePassThreshold'] = use_pass_threshhold
+        self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][
+            'RateIterationOptions']['PassThreshold'] = pass_threshhold
+
     def set_chassis_info(self, hostname, pwd):
         """
         Set the chassis info
@@ -308,10 +324,56 @@ class XenaJSON(object):
         self.json_data['PortHandler']['EntityList'][index]['PortRef'][
             'PortIndex'] = port
 
-    def set_test_options(self, packet_sizes, duration, iterations, loss_rate,
-                         micro_tpld=False):
+    def set_port_ip_v4(self, port, ip_addr, netmask, gateway):
+        """
+        Set the port IP info
+        :param port: port number as int of port to set ip info
+        :param ip_addr: ip address in dot notation format as string
+        :param netmask: cidr number for netmask (ie 24/16/8) as int
+        :param gateway: gateway address in dot notation format
+        :return: None
+        """
+        available_ports = range(len(
+            self.json_data['PortHandler']['EntityList']))
+        if port not in available_ports:
+            raise ValueError("{}{}{}".format(
+                'Port assignment must be an available port ',
+                'number in baseconfig file. Port=', port))
+        self.json_data['PortHandler']['EntityList'][
+            port]["IpV4Address"] = ip_addr
+        self.json_data['PortHandler']['EntityList'][
+            port]["IpV4Gateway"] = gateway
+        self.json_data['PortHandler']['EntityList'][
+            port]["IpV4RoutingPrefix"] = int(netmask)
+
+    def set_port_ip_v6(self, port, ip_addr, netmask, gateway):
+        """
+        Set the port IP info
+        :param port: port number as int of port to set ip info
+        :param ip_addr: ip address as 8 groups of 4 hexadecimal groups separated
+         by a colon.
+        :param netmask: cidr number for netmask (ie 24/16/8) as int
+        :param gateway: gateway address as string in 8 group of 4 hexadecimal
+                        groups separated by a colon.
+        :return: None
         """
-        Set the test options
+        available_ports = range(len(
+            self.json_data['PortHandler']['EntityList']))
+        if port not in available_ports:
+            raise ValueError("{}{}{}".format(
+                'Port assignment must be an available port ',
+                'number in baseconfig file. Port=', port))
+        self.json_data['PortHandler']['EntityList'][
+            port]["IpV6Address"] = ip_addr
+        self.json_data['PortHandler']['EntityList'][
+            port]["IpV6Gateway"] = gateway
+        self.json_data['PortHandler']['EntityList'][
+            port]["IpV6RoutingPrefix"] = int(netmask)
+
+    def set_test_options_tput(self, packet_sizes, duration, iterations,
+                              loss_rate, micro_tpld=False):
+        """
+        Set the tput test options
         :param packet_sizes: List of packet sizes to test, single int entry is
          acceptable for one packet size testing
         :param duration: time for each test in seconds as int
@@ -333,6 +395,35 @@ class XenaJSON(object):
         self.json_data['TestOptions']['TestTypeOptionMap']['Throughput'][
             'Iterations'] = iterations
 
+    def set_test_options_back2back(self, packet_sizes, duration,
+                                   iterations, startvalue, endvalue,
+                                   micro_tpld=False):
+        """
+        Set the back2back test options
+        :param packet_sizes: List of packet sizes to test, single int entry is
+         acceptable for one packet size testing
+        :param duration: time for each test in seconds as int
+        :param iterations: number of iterations of testing as int
+        :param micro_tpld: boolean if micro_tpld should be enabled or disabled
+        :param StartValue: start value
+        :param EndValue: end value
+        :return: None
+        """
+        if isinstance(packet_sizes, int):
+            packet_sizes = [packet_sizes]
+        self.json_data['TestOptions']['PacketSizes'][
+            'CustomPacketSizes'] = packet_sizes
+        self.json_data['TestOptions']['TestTypeOptionMap']['Back2Back'][
+            'Duration'] = duration
+        self.json_data['TestOptions']['FlowCreationOptions'][
+            'UseMicroTpldOnDemand'] = 'true' if micro_tpld else 'false'
+        self.json_data['TestOptions']['TestTypeOptionMap']['Back2Back'][
+            'Iterations'] = iterations
+        self.json_data['TestOptions']['TestTypeOptionMap']['Back2Back'][
+            'RateSweepOptions']['StartValue'] = startvalue
+        self.json_data['TestOptions']['TestTypeOptionMap']['Back2Back'][
+            'RateSweepOptions']['EndValue'] = endvalue
+
     def set_topology_blocks(self):
         """
         Set the test topology to a West to East config for half duplex flow with
@@ -418,6 +509,22 @@ def print_json_report(json_data):
         print("Chassis Password: {}".format(json_data['ChassisManager'][
             'ChassisList'][0]['Password']))
         print("### Port Configuration ###")
+        print("Port 1 IPv4:{}/{} gateway:{}".format(
+            json_data['PortHandler']['EntityList'][0]["IpV4Address"],
+            json_data['PortHandler']['EntityList'][0]["IpV4RoutingPrefix"],
+            json_data['PortHandler']['EntityList'][0]["IpV4Gateway"]))
+        print("Port 1 IPv6:{}/{} gateway:{}".format(
+            json_data['PortHandler']['EntityList'][0]["IpV6Address"],
+            json_data['PortHandler']['EntityList'][0]["IpV6RoutingPrefix"],
+            json_data['PortHandler']['EntityList'][0]["IpV6Gateway"]))
+        print("Port 2 IPv4:{}/{} gateway:{}".format(
+            json_data['PortHandler']['EntityList'][1]["IpV4Address"],
+            json_data['PortHandler']['EntityList'][1]["IpV4RoutingPrefix"],
+            json_data['PortHandler']['EntityList'][1]["IpV4Gateway"]))
+        print("Port 2 IPv6:{}/{} gateway:{}".format(
+            json_data['PortHandler']['EntityList'][1]["IpV6Address"],
+            json_data['PortHandler']['EntityList'][1]["IpV6RoutingPrefix"],
+            json_data['PortHandler']['EntityList'][1]["IpV6Gateway"]))
         print("Port 1: {}/{} group: {}".format(
             json_data['PortHandler']['EntityList'][0]['PortRef']['ModuleIndex'],
             json_data['PortHandler']['EntityList'][0]['PortRef']['PortIndex'],
@@ -512,14 +619,20 @@ if __name__ == "__main__":
     JSON.set_chassis_info('192.168.0.5', 'vsperf')
     JSON.set_port(0, 1, 0)
     JSON.set_port(1, 1, 1)
+    JSON.set_port_ip_v4(0, '192.168.240.10', 32, '192.168.240.1')
+    JSON.set_port_ip_v4(1, '192.168.240.11', 32, '192.168.240.1')
+    JSON.set_port_ip_v6(0, 'a1a1:a2a2:a3a3:a4a4:a5a5:a6a6:a7a7:a8a8', 128,
+                        'a1a1:a2a2:a3a3:a4a4:a5a5:a6a6:a7a7:1111')
+    JSON.set_port_ip_v6(1, 'b1b1:b2b2:b3b3:b4b4:b5b5:b6b6:b7b7:b8b8', 128,
+                        'b1b1:b2b2:b3b3:b4b4:b5b5:b6b6:b7b7:1111')
     JSON.set_header_layer2(dst_mac='dd:dd:dd:dd:dd:dd',
                            src_mac='ee:ee:ee:ee:ee:ee')
     JSON.set_header_vlan(vlan_id=5)
     JSON.set_header_layer3(src_ip='192.168.100.2', dst_ip='192.168.100.3',
                            protocol='udp')
     JSON.set_header_layer4_udp(source_port=3000, destination_port=3001)
-    JSON.set_test_options(packet_sizes=[64], duration=10, iterations=1,
-                          loss_rate=0.0, micro_tpld=True)
+    JSON.set_test_options_tput(packet_sizes=[64], duration=10, iterations=1,
+                               loss_rate=0.0, micro_tpld=True)
     JSON.add_header_segments(flows=4000, multistream_layer='L4')
     JSON.set_topology_blocks()
     write_json_file(JSON.json_data, './testthis.x2544')