diff options
author | 2016-07-31 16:57:05 +0300 | |
---|---|---|
committer | 2016-07-31 16:57:05 +0300 | |
commit | c1867ec4a2ceee37f9423f9bfbfd1d6e58ef16fa (patch) | |
tree | e74ff1e798914a20d4a8492651668dcba332e820 /scripts/automation | |
parent | 893d0feef9ba6fa3fb36c49f4b5bcad47cb2bf60 (diff) |
fixed error handling in get_all_pkt_offsets, added return of error code tuple as same as build_pkt
Diffstat (limited to 'scripts/automation')
-rwxr-xr-x | scripts/automation/trex_control_plane/stl/examples/scapy_server.py | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/scripts/automation/trex_control_plane/stl/examples/scapy_server.py b/scripts/automation/trex_control_plane/stl/examples/scapy_server.py index 4762f1a6..55f7cb54 100755 --- a/scripts/automation/trex_control_plane/stl/examples/scapy_server.py +++ b/scripts/automation/trex_control_plane/stl/examples/scapy_server.py @@ -237,35 +237,40 @@ def check_update(dbMD5,fieldMD5): if fieldMD5_parsed == currentFieldMD5: resField = pktResult('Success',0,'None').convert2tuple() else: - resField = pktResult('Fail',0,'Field DB is not up to date').convert2tuple() + resField = pktResult('Fail',-1,'Field DB is not up to date').convert2tuple() if dbMD5_parsed == currentDBMD5: resDB = pktResult('Success',0,'None').convert2tuple() else: - resDB = pktResult('Fail',0,'Protocol DB is not up to date').convert2tuple() + resDB = pktResult('Fail',-1,'Protocol DB is not up to date').convert2tuple() return json.dumps([resField,resDB]) #pkt_desc as json #dictionary of offsets per protocol. tuple for each field: (name, offset, size) at json format def get_all_pkt_offsets(pkt_desc): pkt_desc= json.loads(pkt_desc) - pkt_protocols = pkt_desc.split('/') - scapy_pkt = eval(pkt_desc) - total_protocols = len(pkt_protocols) - res = {} - for i in range(total_protocols): - fields = [] - for field in scapy_pkt.fields_desc: - size = field.get_size_bytes() - if field.name is 'load': - size = len(scapy_pkt) - fields.append([field.name, field.offset, size]) - res[pkt_protocols[i]] = fields - scapy_pkt=scapy_pkt.payload - return json.dumps(res) - - + try: + pkt_protocols = pkt_desc.split('/') + scapy_pkt = eval(pkt_desc) + total_protocols = len(pkt_protocols) + res = {} + for i in range(total_protocols): + fields = [] + for field in scapy_pkt.fields_desc: + size = field.get_size_bytes() + if field.name is 'load': + size = len(scapy_pkt) + fields.append([field.name, field.offset, size]) + res[pkt_protocols[i]] = fields + scapy_pkt=scapy_pkt.payload + pktRes = pktResult('Success',0,'None').convert2tuple() + FinalRes = [pktRes,res] + return json.dumps(FinalRes) + except: + pktRes = pktResult('Pkt build Failed',str(sys.exc_info()[0]),str(sys.exc_info()[1])).convert2tuple() + res = [pktRes,{}] + res = json.dumps(res) + return res -def get_supported_cmds(): |