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 --- .../functional_tests/scapy_pkt_builder_test.py | 24 ++++++++++++++++++++++ .../client_utils/scapy_packet_builder.py | 22 +++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py b/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py index ee80e6d8..9c1b04fe 100644 --- a/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py +++ b/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py @@ -163,6 +163,30 @@ class CTRexPktBuilderSanitySCapy_Test(pkt_bld_general_test.CGeneralPktBld_Test): d= pkt_builder.get_vm_data() assert_equal(d['instructions'][1]['pkt_offset'],17) + def test_simple_vm3(self): + try: + raw1 = CTRexScRaw( [ CTRexVmDescFlowVar(name="my_valn",min_val=0,max_val=10,init_val=2,size=1,op="inc"), + CTRexVmDescWrFlowVar (fv_name="my_valn_err",pkt_offset= "802|1Q.vlan" ,offset_fixup=3) # fix the offset as valn is bitfield and not supported right now + ] + ); + + pkt_builder = CScapyTRexPktBuilder(); + + py='5'*128 + pkt=Ether()/ \ + Dot1Q(vlan=12)/ \ + IP(src="16.0.0.1",dst="48.0.0.1")/ \ + UDP(dport=12,sport=1025)/IP()/py + + # set packet + pkt_builder.set_packet(pkt); + pkt_builder.add_command ( raw1 ) + pkt_builder.compile(); + + + d= pkt_builder.get_vm_data() + except CTRexPacketBuildException as e: + assert_equal(str(e), "[errcode:-11] 'variable my_valn_err does not exists '") def tearDown(self): 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