From e60a97534bdbd33023efa311a7194d67bf71f62e Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 6 Mar 2015 20:16:30 +0100 Subject: [PATCH] mibuild/sim: able to visualize arp requests with wireshark now need to find why that is not responding... --- mibuild/sim/server.py | 33 +++++++++++++++++++++++++++------ mibuild/sim/server_tb.cpp | 4 ++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/mibuild/sim/server.py b/mibuild/sim/server.py index ea8bb03c..87981fca 100644 --- a/mibuild/sim/server.py +++ b/mibuild/sim/server.py @@ -6,6 +6,9 @@ import os import pty import time import threading +import subprocess +import struct +import fcntl messages= { "EXIT": 0, @@ -30,6 +33,14 @@ class VerilatorServer: self.serial = master self.serial_name = os.ttyname(slave) + os.system("openvpn --mktun --dev tap0") + os.system("ip link set tap0 up") + os.system("ip addr add 192.169.0.14/24 dev tap0") + os.system("iface tap0 inet") + os.system("mknod /dev/net/tap c 10 200") + os.system("chmod 600 /dev/net/tap") + + self.ack = False self._print_banner() @@ -67,6 +78,8 @@ class VerilatorServer: if hasattr(self, "socket"): self.socket.shutdown(socket.SHUT_RDWR) self.socket.close() + os.system("openvpn --rmtun --dev tap0") + os.system("rm -f /dev/net/tap") self._cleanup_file() # XXX proof of concept @@ -74,6 +87,10 @@ server = VerilatorServer() server.accept() print("Connection accepted") +TUNSETIFF = 0x400454ca +IFF_TAP = 0x0002 +IFF_NO_PI = 0x1000 + def read(): while True: packet = server.recv() @@ -82,10 +99,10 @@ def read(): c = bytes(chr(packet[1]).encode('utf-8')) os.write(server.serial, c) elif packet[0] == messages["ETHERNET"]: - print("received ethernet") - for d in packet[1:]: - print("{:02X}".format(d), end="") - print("") + tap = os.open("/dev/net/tun", os.O_RDWR) + fcntl.ioctl(tap, TUNSETIFF, struct.pack("16sH", b"tap0", IFF_TAP | IFF_NO_PI)) + os.write(tap, packet[1+8:-4]) + os.close(tap) elif packet[0] == messages["ACK"]: server.ack = True @@ -104,5 +121,9 @@ readthread.start() writethread = threading.Thread(target=write, daemon=True) writethread.start() -while True: - time.sleep(1) +try: + while True: + time.sleep(1) +except KeyboardInterrupt: + server.close() + diff --git a/mibuild/sim/server_tb.cpp b/mibuild/sim/server_tb.cpp index 5203a7aa..8563eebf 100644 --- a/mibuild/sim/server_tb.cpp +++ b/mibuild/sim/server_tb.cpp @@ -153,6 +153,7 @@ int console_service(struct sim *s) return 0; } +#ifdef ETH_SOURCE_STB int eth_last_source_stb = 0; int ethernet_service(struct sim *s) { @@ -171,6 +172,7 @@ int ethernet_service(struct sim *s) { } eth_last_source_stb = ETH_SOURCE_STB; } +#endif void sim_tick(struct sim *s) { @@ -219,7 +221,9 @@ int main(int argc, char **argv, char **env) if (SYS_CLK) { if (console_service(&s) != 0) s.run = false; +#ifdef ETH_SOURCE_STB ethernet_service(&s); +#endif } } s.end = clock(); -- 2.30.2