feat(evaluation): Added results and modified scripts and execution for a test evaluation
Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
@@ -6,12 +6,17 @@ from scapy.all import Ether, IP, UDP, send, sendp, Raw, sniff
|
||||
global initial_timestamp
|
||||
initial_timestamp = int(time.time() * 1000)
|
||||
|
||||
|
||||
# Simulated ACK sending function
|
||||
def send_ack(destination_IP, my_port, sender_port):
|
||||
ack_data = ""
|
||||
###################
|
||||
# With localhost:
|
||||
ack_packet = IP(dst=destination_IP) / UDP(dport=sender_port, sport=my_port) / Raw(load=str(ack_data))
|
||||
ack_packet = (
|
||||
IP(dst=destination_IP)
|
||||
/ UDP(dport=sender_port, sport=my_port)
|
||||
/ Raw(load=str(ack_data))
|
||||
)
|
||||
send(ack_packet, verbose=False)
|
||||
###################
|
||||
# With netns:
|
||||
@@ -20,18 +25,25 @@ def send_ack(destination_IP, my_port, sender_port):
|
||||
###################
|
||||
print(f"Sent ACK: {ack_data}")
|
||||
|
||||
|
||||
# Process incoming packets
|
||||
def process_packet(pkt):
|
||||
################### Save timestamps ###################
|
||||
if Raw in pkt:
|
||||
with open(save_file, "a") as f: # open as "a" for append
|
||||
with open(save_file, "a") as f: # open as "a" for append
|
||||
global initial_timestamp
|
||||
receival_time = str(int(time.time() * 1000) - initial_timestamp) # time of arrival at receiver
|
||||
send_time = pkt[Raw].load # time it was sent from the sender
|
||||
receival_time = str(
|
||||
int(time.time() * 1000) - initial_timestamp
|
||||
) # time of arrival at receiver
|
||||
send_time = pkt[Raw].load # time it was sent from the sender
|
||||
################### Conversion & error handling ###################
|
||||
try:
|
||||
send_time = int(send_time.decode("utf-8").split("X")[0]) # decode the payload and stop at "X"
|
||||
except ValueError: # For the last packet without a timestamp but "END" as payload
|
||||
send_time = int(
|
||||
send_time.decode("utf-8").split("X")[0]
|
||||
) # decode the payload and stop at "X"
|
||||
except (
|
||||
ValueError
|
||||
): # For the last packet without a timestamp but "END" as payload
|
||||
print(f"END for {my_port}")
|
||||
send_ack(destination_IP, my_port, sender_port)
|
||||
return
|
||||
@@ -45,23 +57,32 @@ def process_packet(pkt):
|
||||
|
||||
send_ack(destination_IP, my_port, sender_port)
|
||||
|
||||
|
||||
# Main loop
|
||||
def main(destination_IP, my_port, sender_port):
|
||||
###################
|
||||
# With localhost:
|
||||
sniff(iface="lo", filter=f"udp and dst port {my_port}", prn=process_packet, store=False)
|
||||
sniff(
|
||||
iface="lo",
|
||||
filter=f"udp and dst port {my_port}",
|
||||
prn=process_packet,
|
||||
store=False,
|
||||
)
|
||||
###################
|
||||
# With netns:
|
||||
# sniff(iface="ns-g", filter=f"udp and dst port {my_port}", prn=process_packet, store=False)
|
||||
###################
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 4:
|
||||
print("Usage: python receive_and_ack.py <destination_IP> <my_port> <sender_port>")
|
||||
print(
|
||||
"Usage: python receive_and_ack.py <destination_IP> <my_port> <sender_port>"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
destination_IP = sys.argv[1] # Clear
|
||||
my_port = int(sys.argv[2]) # Port to listen on
|
||||
sender_port = int(sys.argv[3]) # Port to send acks to
|
||||
destination_IP = sys.argv[1] # Clear
|
||||
my_port = int(sys.argv[2]) # Port to listen on
|
||||
sender_port = int(sys.argv[3]) # Port to send acks to
|
||||
save_file = f"timestamps_{my_port}"
|
||||
main(destination_IP, my_port, sender_port)
|
||||
|
||||
Reference in New Issue
Block a user