add access to scapy.all from eval, tests to IPOptions, TCPOptions
authorAnton Kiselev <[email protected]>
Tue, 1 Nov 2016 11:02:22 +0000 (18:02 +0700)
committerAnton Kiselev <[email protected]>
Fri, 4 Nov 2016 12:54:57 +0000 (19:54 +0700)
Signed-off-by: Anton Kiselev <[email protected]>
scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py
scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py

index 79f5d52..118d7d6 100755 (executable)
@@ -424,7 +424,7 @@ class Scapy_service(Scapy_service_api):
         if type(val) == type({}):
             value_type = val['vtype']
             if value_type == 'EXPRESSION':
-                return eval(val['expr'], {})
+                return eval(val['expr'], scapy.all.__dict__)
             elif value_type == 'BYTES':   # bytes payload(ex Raw.load)
                 return generate_bytes(val)
             elif value_type == 'OBJECT':
index 0cecbfe..d1207ca 100644 (file)
@@ -159,6 +159,28 @@ def test_layer_random_value():
     ether_fields = fields_to_map(res['data'][0]['fields'])
     assert(re.match(RE_MAC, ether_fields['src']['value']))
 
+def test_IP_options():
+    options_expr = "[IPOption_SSRR(copy_flag=0, routers=['1.2.3.4', '5.6.7.8'])]"
+    res = build_pkt([
+        layer_def("Ether"),
+        layer_def("IP", options={"vtype": "EXPRESSION", "expr": options_expr}),
+        ])
+    pkt = build_pkt_to_scapy(res)
+    options = pkt[IP].options
+    assert(options[0].__class__.__name__ == 'IPOption_SSRR')
+    assert(options[0].copy_flag == 0)
+    assert(options[0].routers == ['1.2.3.4', '5.6.7.8'])
+
+def test_TCP_options():
+    options_expr = "[('MSS', 1460), ('NOP', None), ('NOP', None), ('SAckOK', b'')]"
+    pkt = build_pkt_get_scapy([
+        layer_def("Ether"),
+        layer_def("IP"),
+        layer_def("TCP", options={"vtype": "EXPRESSION", "expr": options_expr}),
+        ])
+    options = pkt[TCP].options
+    assert(options[0] == ('MSS', 1460) )
+
 def test_layer_wrong_structure():
     payload = [
             layer_def("Ether"),