diff options
author | 2016-01-13 10:40:23 +0200 | |
---|---|---|
committer | 2016-01-13 10:40:23 +0200 | |
commit | 6092cc6f8b7d6d5f44b9c6cc600fc819257996e3 (patch) | |
tree | 360c42940d54212d334eb75f0cbfe43062d13e80 /scripts/automation/regression/unit_tests/pkt_bld_tests/vm_test.py | |
parent | 898fadae0e9bf9d0eb46abf286a888d791bdaf96 (diff) |
add Dan's packet builder functional tests
Diffstat (limited to 'scripts/automation/regression/unit_tests/pkt_bld_tests/vm_test.py')
-rwxr-xr-x | scripts/automation/regression/unit_tests/pkt_bld_tests/vm_test.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/scripts/automation/regression/unit_tests/pkt_bld_tests/vm_test.py b/scripts/automation/regression/unit_tests/pkt_bld_tests/vm_test.py new file mode 100755 index 00000000..603c52db --- /dev/null +++ b/scripts/automation/regression/unit_tests/pkt_bld_tests/vm_test.py @@ -0,0 +1,77 @@ +#!/router/bin/python + +import pkt_bld_general_test +from client_utils.packet_builder import * +from nose.tools import assert_equal +from nose.tools import assert_not_equal +from nose.tools import assert_raises +from nose.tools import raises + +class CTRexVM_Test(pkt_bld_general_test.CGeneralPktBld_Test): + + def setUp(self): + self.vm = CTRexPktBuilder.CTRexVM() + + def test_add_flow_man_inst(self): + self.vm.add_flow_man_inst("src_ip") + assert_raises(CTRexPktBuilder.VMVarNameExistsError, self.vm.add_flow_man_inst, "src_ip") + self.vm.add_flow_man_inst("dst_ip", size=8, operation="inc", init_value=5, max_value=100) + assert_equal(self.vm.vm_variables["dst_ip"].dump(), + {"type": "flow_var", + "name": "dst_ip", + "size": 8, + # "big_endian": True, + "op": "inc", +# "split_by_core": False, + "init_value": "5", + "min_value": "1", + "max_value": "100"}) + assert_raises(CTRexPktBuilder.VMFieldNameError, self.vm.add_flow_man_inst, "src_mac", no_field=1) + + def test_load_flow_man(self): + vm2 = CTRexPktBuilder.CTRexVM() + vm2.add_flow_man_inst("dst_ip", size=8, operation="inc", init_value=5, max_value=100) + self.vm.load_flow_man(vm2.vm_variables["dst_ip"]) + assert_equal(self.vm.vm_variables["dst_ip"].dump(), + vm2.vm_variables["dst_ip"].dump()) + + def test_set_vm_var_field(self): + self.vm.add_flow_man_inst("src_ip") + self.vm.set_vm_var_field("src_ip", "size", 8) + assert_equal(self.vm.vm_variables["src_ip"].size, 8) + assert_raises(KeyError, self.vm.set_vm_var_field, "no_var", "no_field", 10) + assert_raises(CTRexPktBuilder.VMFieldNameError, self.vm.set_vm_var_field, "src_ip", "no_field", 10) + assert_raises(CTRexPktBuilder.VMFieldValueError, self.vm.set_vm_var_field, "src_ip", "operation", "rand") + + def test_dump(self): + self.vm.add_flow_man_inst("dst_ip", size=8, operation="inc", init_value=5, max_value=100) + self.vm.add_flow_man_inst("src_ip", size=8, operation="dec", init_value=10, min_value=2, max_value=100) + from pprint import pprint + print '' + pprint (self.vm.dump()) + assert_equal(self.vm.dump(), + {'instructions': [{'init_value': '10', + 'max_value': '100', + 'min_value': '2', + 'name': 'src_ip', + 'op': 'dec', + 'size': 8, + 'type': 'flow_var'}, + {'init_value': '5', + 'max_value': '100', + 'min_value': '1', + 'name': 'dst_ip', + 'op': 'inc', + 'size': 8, + 'type': 'flow_var'}], + 'split_by_var': ''} + ) + + + def tearDown(self): + pass + + +if __name__ == "__main__": + pass + |