From dda9b08e2b57f785b71bccf4dab57ef4b2fb1dc3 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Wed, 3 Feb 2016 11:36:58 +0200 Subject: sanity check for var does not exists --- .../client_utils/scapy_packet_builder.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'scripts/automation/trex_control_plane/client_utils') diff --git a/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py b/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py index fda77cf7..79616ad7 100644 --- a/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py +++ b/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py @@ -441,6 +441,12 @@ class CTRexVmDescBase(object): print yaml.dump(self.get_json(), default_flow_style=False) + def get_var_ref (self): + ''' + virtual function return a ref var name + ''' + return None + def get_var_name(self): ''' virtual function return the varible name if exists @@ -520,6 +526,9 @@ class CTRexVmDescWrFlowVar(CTRexVmDescBase): self.is_big =is_big; assert(type(is_big)==bool); + def get_var_ref (self): + return self.name + def get_obj (self): return CTRexVmInsWrFlowVar(self.name,self.pkt_offset+self.offset_fixup,self.add_val,self.is_big) @@ -622,15 +631,22 @@ class CScapyTRexPktBuilder(object): # make sure we have varibles once vars={}; + + # add it add var to dit for desc in obj.commands: - print desc.__dict__ var_name = desc.get_var_name() - print var_name if var_name : if vars.has_key(var_name): - raise CTRexPacketBuildException(-11,("varible %s define twice ") % (var_name) ); + raise CTRexPacketBuildException(-11,("variable %s define twice ") % (var_name) ); else: vars[var_name]=1 + + # check that all write exits + for desc in obj.commands: + var_name = desc.get_var_ref() + if var_name : + if not vars.has_key(var_name): + raise CTRexPacketBuildException(-11,("variable %s does not exists ") % (var_name) ); desc.compile(self); for desc in obj.commands: -- cgit 1.2.3-korg