summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Kiselev <anton.kisel@gmail.com>2017-03-07 14:54:08 +0700
committerYaroslav Brustinov <ybrustin@cisco.com>2017-03-07 18:13:23 +0200
commit322ff95c089574b9efc61bf57f2dfed89c0527a5 (patch)
tree8d727019d78efc41633c3f4693bbdbd77bbddad2
parent029cbdcf5d183b344fe572b21157293cef1c62e0 (diff)
scapy_server: add build_pkt_details test with offset & length verification
Signed-off-by: Anton Kiselev <anton.kisel@gmail.com>
-rw-r--r--scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py b/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py
index 7d70931b..430e5693 100644
--- a/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py
+++ b/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py
@@ -19,9 +19,35 @@ TEST_PKT_DEF = [
layer_def("TCP", sport="443")
]
-def test_build_pkt():
- pkt = build_pkt_get_scapy(TEST_PKT_DEF)
+def test_build_pkt_details():
+ pkt_data = build_pkt(TEST_PKT_DEF)
+ pkt = build_pkt_to_scapy(pkt_data)
assert(pkt[TCP].sport == 443)
+ ether = pkt_data['data'][0]
+ ip = pkt_data['data'][1]
+ tcp = pkt_data['data'][2]
+ assert(len(pkt_data["binary"]) == 72) #b64 encoded data
+
+ # absolute frame offset
+ assert(ether['offset'] == 0)
+ assert(ip['offset'] == 14)
+ assert(tcp['offset'] == 34)
+
+ # relative field offsets
+ tcp_sport = tcp["fields"][0]
+ assert(tcp_sport["id"] == "sport")
+ assert(tcp_sport["offset"] == 0)
+ assert(tcp_sport["length"] == 2)
+
+ tcp_dport = tcp["fields"][1]
+ assert(tcp_dport["id"] == "dport")
+ assert(tcp_dport["offset"] == 2)
+ assert(tcp_sport["length"] == 2)
+
+ tcp_chksum = tcp["fields"][8]
+ assert(tcp_chksum["id"] == "chksum")
+ assert(tcp_chksum["offset"] == 16)
+ assert(tcp_chksum["length"] == 2)
def test_build_invalid_structure_pkt():
ether_fields = {"dst": TEST_MAC_1, "type": "LOOP"}