aboutsummaryrefslogtreecommitdiffstats
path: root/resources/traffic_profiles
diff options
context:
space:
mode:
Diffstat (limited to 'resources/traffic_profiles')
-rwxr-xr-xresources/traffic_profiles/trex/profile_trex_stateless_base_class.py76
1 files changed, 43 insertions, 33 deletions
diff --git a/resources/traffic_profiles/trex/profile_trex_stateless_base_class.py b/resources/traffic_profiles/trex/profile_trex_stateless_base_class.py
index b5a4ba9a11..6576cb7bdf 100755
--- a/resources/traffic_profiles/trex/profile_trex_stateless_base_class.py
+++ b/resources/traffic_profiles/trex/profile_trex_stateless_base_class.py
@@ -24,18 +24,19 @@ from string import ascii_letters
from trex.stl.api import *
-class TrafficStreamsBaseClass(object):
+class TrafficStreamsBaseClass:
"""Base class for stream profiles for T-rex traffic generator."""
+
STREAM_TABLE = {
- 'IMIX_v4': [
- {'size': 60, 'pps': 28, 'isg': 0},
- {'size': 590, 'pps': 20, 'isg': 0.1},
- {'size': 1514, 'pps': 4, 'isg': 0.2}
+ u"IMIX_v4": [
+ {u"size": 60, u"pps": 28, u"isg": 0},
+ {u"size": 590, u"pps": 20, u"isg": 0.1},
+ {u"size": 1514, u"pps": 4, u"isg": 0.2}
],
'IMIX_v4_1': [
- {'size': 64, 'pps': 28, 'isg': 0},
- {'size': 570, 'pps': 16, 'isg': 0.1},
- {'size': 1518, 'pps': 4, 'isg': 0.2}
+ {u"size": 64, u"pps": 28, u"isg": 0},
+ {u"size": 570, u"pps": 16, u"isg": 0.1},
+ {u"size": 1518, u"pps": 4, u"isg": 0.2}
]
}
@@ -56,7 +57,7 @@ class TrafficStreamsBaseClass(object):
:returns: The generated payload.
:rtype: str
"""
- payload = ""
+ payload = u""
for _ in range(length):
payload += choice(ascii_letters)
@@ -78,11 +79,11 @@ class TrafficStreamsBaseClass(object):
ip1 = socket.inet_pton(socket.AF_INET6, start_ip)
ip2 = socket.inet_pton(socket.AF_INET6, end_ip)
- hi1, lo1 = struct.unpack('!QQ', ip1)
- hi2, lo2 = struct.unpack('!QQ', ip2)
+ hi1, lo1 = struct.unpack(u"!QQ", ip1)
+ hi2, lo2 = struct.unpack(u"!QQ", ip2)
if ((hi1 << 64) | lo1) > ((hi2 << 64) | lo2):
- raise ValueError("IPv6: start_ip is greater then end_ip")
+ raise ValueError(u"IPv6: start_ip is greater then end_ip")
return lo1, abs(int(lo1) - int(lo2))
@@ -124,18 +125,22 @@ class TrafficStreamsBaseClass(object):
# Direction 0 --> 1
pkt_a = STLPktBuilder(
- pkt=base_pkt_a / self._gen_payload(payload_len), vm=vm1)
+ pkt=base_pkt_a / self._gen_payload(payload_len), vm=vm1
+ )
# Direction 1 --> 0
pkt_b = STLPktBuilder(
- pkt=base_pkt_b / self._gen_payload(payload_len), vm=vm2)
+ pkt=base_pkt_b / self._gen_payload(payload_len), vm=vm2
+ )
# Packets for latency measurement:
# Direction 0 --> 1
pkt_lat_a = STLPktBuilder(
- pkt=base_pkt_a / self._gen_payload(payload_len), vm=vm1)
+ pkt=base_pkt_a / self._gen_payload(payload_len), vm=vm1
+ )
# Direction 1 --> 0
pkt_lat_b = STLPktBuilder(
- pkt=base_pkt_b / self._gen_payload(payload_len), vm=vm2)
+ pkt=base_pkt_b / self._gen_payload(payload_len), vm=vm2
+ )
# Create the streams:
# Direction 0 --> 1
@@ -147,26 +152,29 @@ class TrafficStreamsBaseClass(object):
# Streams for latency measurement:
# Direction 0 --> 1
- lat_stream1 = STLStream(packet=pkt_lat_a,
- flow_stats=STLFlowLatencyStats(pg_id=0),
- mode=STLTXCont(pps=9000))
+ lat_stream1 = STLStream(
+ packet=pkt_lat_a, flow_stats=STLFlowLatencyStats(pg_id=0),
+ mode=STLTXCont(pps=9000)
+ )
# Direction 1 --> 0
# second traffic stream with a phase of 10ns (inter-stream gap)
- lat_stream2 = STLStream(packet=pkt_lat_b, isg=10.0,
- flow_stats=STLFlowLatencyStats(pg_id=1),
- mode=STLTXCont(pps=9000))
+ lat_stream2 = STLStream(
+ packet=pkt_lat_b, isg=10.0,
+ flow_stats=STLFlowLatencyStats(pg_id=1),
+ mode=STLTXCont(pps=9000)
+ )
return [stream1, stream2, lat_stream1, lat_stream2]
# Frame size is defined as a string, e.g.IMIX_v4_1:
elif isinstance(self.framesize, str):
- stream1 = []
- stream2 = []
+ stream1 = list()
+ stream2 = list()
for stream in self.STREAM_TABLE[self.framesize]:
- payload_len_a = max(0, stream['size'] - len(base_pkt_a) - 4)
- payload_len_b = max(0, stream['size'] - len(base_pkt_b) - 4)
+ payload_len_a = max(0, stream[u"size"] - len(base_pkt_a) - 4)
+ payload_len_b = max(0, stream[u"size"] - len(base_pkt_b) - 4)
# Create a base packet and pad it to size
pkt_a = STLPktBuilder(
pkt=base_pkt_a / self._gen_payload(payload_len_a),
@@ -176,12 +184,14 @@ class TrafficStreamsBaseClass(object):
vm=vm2)
# Create the streams:
- stream1.append(STLStream(packet=pkt_a,
- isg=stream['isg'],
- mode=STLTXCont(pps=stream['pps'])))
- stream2.append(STLStream(packet=pkt_b,
- isg=stream['isg'],
- mode=STLTXCont(pps=stream['pps'])))
+ stream1.append(STLStream(
+ packet=pkt_a, isg=stream[u"isg"],
+ mode=STLTXCont(pps=stream[u"pps"]))
+ )
+ stream2.append(STLStream(
+ packet=pkt_b, isg=stream[u"isg"],
+ mode=STLTXCont(pps=stream[u"pps"]))
+ )
streams = list()
streams.extend(stream1)
streams.extend(stream2)
@@ -198,6 +208,6 @@ class TrafficStreamsBaseClass(object):
:returns: Traffic streams.
:rtype: list
"""
- self.framesize = kwargs['framesize']
+ self.framesize = kwargs[u"framesize"]
return self.create_streams()