Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
polybassa committed Sep 23, 2024
1 parent 65100e7 commit 57cd90f
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions test/sendsniff.uts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
+ Test bridge_and_sniff() using tap sockets

~ tap

= Create two tap interfaces

import subprocess
from threading import Thread

tap0, tap1 = [TunTapInterface("tap%d" % i) for i in range(2)]

chk_kwargs = {"timeout": 3}
Expand Down Expand Up @@ -268,6 +264,43 @@ with VEthPair('a_0', 'a_1') as veth_0:
assert (xfrm_count['b_0'] == 2)


= sr() performance test

import subprocess
import shlex

try:
# Create a dedicated network name space to simulate remote host
subprocess.check_call(shlex.split("sudo ip netns add scapy"))
# Create a virtual Ethernet pair to connect default and new NS
subprocess.check_call(shlex.split("sudo ip link add type veth"))
# Move veth1 to the new NS
subprocess.check_call(shlex.split("sudo ip link set veth1 netns scapy"))
# Setup vNIC in the default NS
subprocess.check_call(shlex.split("sudo ip link set veth0 up"))
subprocess.check_call(shlex.split("sudo ip addr add 192.168.168.1/24 dev veth0"))
# Setup vNIC in the dedicated NS
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set lo up"))
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set veth1 up"))
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip addr add 192.168.168.2/24 dev veth1"))
# Perform test
conf.route.resync()
res, unansw = sr(IP(dst='192.168.168.2') / ICMP(seq=(1, 1000)), timeout=1, verbose=False)
finally:
try:
# Bring down the interfaces
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set veth1 down"))
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set lo down"))
# Delete the namespace
subprocess.check_call(shlex.split("sudo ip netns delete scapy"))
# Remove the virtual Ethernet pair
subprocess.check_call(shlex.split("sudo ip link delete veth0"))
except subprocess.CalledProcessError as e:
print(f"Error during cleanup: {e}")

len(res) == 1000


############
############
+ Test arpleak() using a tap socket
Expand Down

0 comments on commit 57cd90f

Please sign in to comment.