Use scapy for test data.
+from scapy.layers.inet import IP
from networkml.parsers.pcap.pcap_utils import extract_macs
from networkml.parsers.pcap.pcap_utils import extract_protocol
from networkml.parsers.pcap.pcap_utils import extract_session_size
@@ -5,6 +6,11 @@ from networkml.parsers.pcap.pcap_utils import is_external
from networkml.parsers.pcap.pcap_utils import is_private
from networkml.parsers.pcap.pcap_utils import is_protocol
from networkml.parsers.pcap.pcap_utils import packet_size
+from scapy.layers.l2 import Ether
+from scapy.layers.inet import IP, TCP
+
+
+TEST_IP_DATA = bytes(Ether()/IP(len=99,proto=6)/TCP()).hex()
def test_extract_macs():
@@ -42,21 +48,21 @@ def test_is_private():
def test_packet_size():
- packet = ['0', '1234567890123456789012345678901234567890']
+ packet = ['0', TEST_IP_DATA]
size = packet_size(packet)
- assert size == 13398
+ assert size == 99
def test_extract_session_size():
- session = [['0', '1234567890123456789012345678901234567890']]
+ session = [['0', TEST_IP_DATA]]
session_size = extract_session_size(session)
- assert session_size == 13398
+ assert session_size == 99
def test_extract_protocol():
- session = [['0', '12345678901234567890123456789012345678901234567890']]
+ session = [['0', TEST_IP_DATA]]
protocol = extract_protocol(session)
- assert protocol == '78'
+ assert protocol == '06'
def test_is_external():
@@ -67,8 +73,8 @@ def test_is_external():
def test_is_protocol():
- session = [['0', '12345678901234567890123456789012345678901234567890']]
- protocol = is_protocol(session, '78')
+ session = [['0', TEST_IP_DATA]]
+ protocol = is_protocol(session, '06')
assert protocol == True
- protocol = is_protocol(session, 78)
+ protocol = is_protocol(session, 6)
assert protocol == False
