mibuild/sim: able to visualize arp requests with wireshark

now need to find why that is not responding...
This commit is contained in:
Florent Kermarrec 2015-03-06 20:16:30 +01:00
parent a64acdfa65
commit e60a97534b
2 changed files with 31 additions and 6 deletions

View File

@ -6,6 +6,9 @@ import os
import pty import pty
import time import time
import threading import threading
import subprocess
import struct
import fcntl
messages= { messages= {
"EXIT": 0, "EXIT": 0,
@ -30,6 +33,14 @@ class VerilatorServer:
self.serial = master self.serial = master
self.serial_name = os.ttyname(slave) 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.ack = False
self._print_banner() self._print_banner()
@ -67,6 +78,8 @@ class VerilatorServer:
if hasattr(self, "socket"): if hasattr(self, "socket"):
self.socket.shutdown(socket.SHUT_RDWR) self.socket.shutdown(socket.SHUT_RDWR)
self.socket.close() self.socket.close()
os.system("openvpn --rmtun --dev tap0")
os.system("rm -f /dev/net/tap")
self._cleanup_file() self._cleanup_file()
# XXX proof of concept # XXX proof of concept
@ -74,6 +87,10 @@ server = VerilatorServer()
server.accept() server.accept()
print("Connection accepted") print("Connection accepted")
TUNSETIFF = 0x400454ca
IFF_TAP = 0x0002
IFF_NO_PI = 0x1000
def read(): def read():
while True: while True:
packet = server.recv() packet = server.recv()
@ -82,10 +99,10 @@ def read():
c = bytes(chr(packet[1]).encode('utf-8')) c = bytes(chr(packet[1]).encode('utf-8'))
os.write(server.serial, c) os.write(server.serial, c)
elif packet[0] == messages["ETHERNET"]: elif packet[0] == messages["ETHERNET"]:
print("received ethernet") tap = os.open("/dev/net/tun", os.O_RDWR)
for d in packet[1:]: fcntl.ioctl(tap, TUNSETIFF, struct.pack("16sH", b"tap0", IFF_TAP | IFF_NO_PI))
print("{:02X}".format(d), end="") os.write(tap, packet[1+8:-4])
print("") os.close(tap)
elif packet[0] == messages["ACK"]: elif packet[0] == messages["ACK"]:
server.ack = True server.ack = True
@ -104,5 +121,9 @@ readthread.start()
writethread = threading.Thread(target=write, daemon=True) writethread = threading.Thread(target=write, daemon=True)
writethread.start() writethread.start()
while True: try:
while True:
time.sleep(1) time.sleep(1)
except KeyboardInterrupt:
server.close()

View File

@ -153,6 +153,7 @@ int console_service(struct sim *s)
return 0; return 0;
} }
#ifdef ETH_SOURCE_STB
int eth_last_source_stb = 0; int eth_last_source_stb = 0;
int ethernet_service(struct sim *s) { int ethernet_service(struct sim *s) {
@ -171,6 +172,7 @@ int ethernet_service(struct sim *s) {
} }
eth_last_source_stb = ETH_SOURCE_STB; eth_last_source_stb = ETH_SOURCE_STB;
} }
#endif
void sim_tick(struct sim *s) void sim_tick(struct sim *s)
{ {
@ -219,7 +221,9 @@ int main(int argc, char **argv, char **env)
if (SYS_CLK) { if (SYS_CLK) {
if (console_service(&s) != 0) if (console_service(&s) != 0)
s.run = false; s.run = false;
#ifdef ETH_SOURCE_STB
ethernet_service(&s); ethernet_service(&s);
#endif
} }
} }
s.end = clock(); s.end = clock();