Skip to content

Commit

Permalink
Remove some unnecessary imports of Scapy module (#5128)
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Fingerhut <andy_fingerhut@alum.wustl.edu>
  • Loading branch information
jafingerhut authored Feb 18, 2025
1 parent 4e622d9 commit eb0468a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion backends/bmv2/bmv2stf.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def checkOutputs(self) -> int:
# We only care that the packet was received on this particular port.
if not expected_pkt:
continue
cmp_result = testutils.compare_pkt(expected_pkt, packets[idx])
cmp_result = testutils.compare_pkt(expected_pkt, packets[idx].build())
if cmp_result != testutils.SUCCESS:
testutils.log.error("Packet %s on port %s differs", idx, interface)
return cmp_result
Expand Down
2 changes: 0 additions & 2 deletions backends/bmv2/run-bmv2-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@
sys.path.append(str(ROOT_DIR))

from bmv2stf import Options, RunBMV2
from scapy.layers.all import *
from scapy.utils import *

from tools import testutils # pylint: disable=wrong-import-position

Expand Down
2 changes: 1 addition & 1 deletion backends/ebpf/targets/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def check_outputs(self):
)
return testutils.FAILURE
for idx, expected_pkt in enumerate(expected):
cmp = testutils.compare_pkt(expected_pkt, packets[idx])
cmp = testutils.compare_pkt(expected_pkt, packets[idx].build())
if cmp != testutils.SUCCESS:
testutils.log.error("Packet %s on port %s differs", idx, interface)
return cmp
Expand Down
6 changes: 2 additions & 4 deletions tools/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
from pathlib import Path
from typing import Any, Dict, List, NamedTuple, Optional, Union

import scapy.packet

# Set up logging.
log = logging.getLogger(__name__)

Expand Down Expand Up @@ -93,7 +91,7 @@ def hex_to_byte(hex_str: str) -> str:
return "".join(byte_vals)


def compare_pkt(expected: str, received: scapy.packet.Packet) -> int:
def compare_pkt(expected: str, received: bytes) -> int:
"""Compare two given byte sequences and check if they are the same.
Report errors if this is not the case."""

Expand All @@ -104,7 +102,7 @@ def compare_pkt(expected: str, received: scapy.packet.Packet) -> int:
strict_length_check = True
expected = expected[:-1]

received = received.build().hex().upper()
received = received.hex().upper()
expected = "".join(expected.split()).upper()
if strict_length_check and len(received) > len(expected):
log.error(
Expand Down

0 comments on commit eb0468a

Please sign in to comment.