summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py
diff options
context:
space:
mode:
authorAnton Kiselev <anton.kisel@gmail.com>2016-11-01 19:19:48 +0700
committerAnton Kiselev <anton.kisel@gmail.com>2016-11-04 19:55:01 +0700
commit3e48c0b5d1b21554eea8d12bc66175a9157a6951 (patch)
tree130d2b97e0e78a1e2f769ad2be467da2b45dab23 /scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py
parent7fc45ee2375e9e5a346595e29dfd526e6a5bec87 (diff)
scapy server python 3 compatibility fixes(file and pseudo-random generator)
Signed-off-by: Anton Kiselev <anton.kisel@gmail.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py b/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py
index 118d7d6e..80e2fc99 100755
--- a/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py
+++ b/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py
@@ -282,12 +282,17 @@ def get_sample_field_val(scapy_layer, fieldId):
def generate_random_bytes(sz, seed, start, end):
# generate bytes of specified range with a fixed seed and size
- rnd = random.Random(seed)
- end = end + 1 # to include end value
- res = [rnd.randrange(start, end) for _i in range(sz)]
+ rnd = random.Random()
+ n = end - start + 1
if is_python(2):
+ rnd = random.Random(seed)
+ res = [start + int(rnd.random()*n) for _i in range(sz)]
return ''.join(chr(x) for x in res)
else:
+ rnd = random.Random()
+ # to generate same random sequence as 2.x
+ rnd.seed(seed, version=1)
+ res = [start + int(rnd.random()*n) for _i in range(sz)]
return bytes(res)
def generate_bytes_from_template(sz, template):
@@ -363,7 +368,7 @@ class Scapy_service(Scapy_service_api):
def _load_definitions_from_json(self):
# load protocol definitions from a json file
self.protocol_definitions = {}
- with file('protocols.json') as f:
+ with open('protocols.json', 'r') as f:
protocols = json.load(f)
for protocol in protocols:
self.protocol_definitions[ protocol['id'] ] = protocol