mibuild/sim: able to visualize arp requests with wireshark
now need to find why that is not responding...
This commit is contained in:
parent
a64acdfa65
commit
e60a97534b
|
@ -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()
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue