Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions boards/default/distros/fedora/fedora.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
serviceTemplate = """[Unit]
Requires=multi-user.target
After=multi-user.target
Requires=network-online.target
After=network-online.target
Before=firesim.target
Wants=firesim.target

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Requires=multi-user.target
After=multi-user.target
Requires=network-online.target
After=network-online.target
Before=firesim.target
Wants=firesim.target

[Service]
ExecStart=/etc/firesim/firesim.sh
StandardOutput=journal+console
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,43 @@
#
# Start the network....
#

# Debian ifupdown needs the /run/network lock directory
mkdir -p /run/network

# Write DNS to /etc/resolv.conf
resolvconf_file="/etc/resolv.conf"
rm -f $resolvconf_file
echo "nameserver 172.16.1.3" > $resolvconf_file

# mac address of NIC at eth0 decides ip address we'd like to use
ifname=eth0
read _ addr _ _ <<< $(/sbin/ip link | /bin/grep -A 1 "$ifname" | /usr/bin/tail -1)
# Extract the bottom 2 bytes of mac addr
IFS=: read -r _ _ _ _ machigh maclow <<< $addr

case "$1" in
start)
printf "Starting network: "
/sbin/ifup -a
ifname=eth0
if test -r "/sys/class/net/${ifname}/address" ; then
/sbin/ip link set dev "$ifname" up &&
IFS=: read -r _ _ _ _ machigh maclow < "/sys/class/net/${ifname}/address" &&
/sbin/ip addr add "172.16.$((16#$machigh)).$((16#$maclow))/16" dev "$ifname"
fi
# /sbin/ifup eth0
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
stop)
printf "Stopping network: "
/sbin/ifdown -a
# /sbin/ifdown eth0
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
start)
printf "Starting network: "
# Use sed to substitute target address 172.16.machigh.maclow for the first interface (eth0) in /etc/network/interfaces
/bin/sed -i -e "1,/^address/{s/^address.*/address 172.16.$((16#$machigh)).$((16#$maclow))/;}" /etc/network/interfaces
sbin/ifup -a
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
stop)
printf "Stopping network: "
/sbin/ifdown -a
# Not functionalyl necessary, substitute "firemarshal_ip_addr_uninitialized" for eth0 in /etc/network/interfaces to make the file understandable for users
/bin/sed -i -e "1,/^address/{s/^address.*/address firemarshal_ip_addr_uninitialized/;}" /etc/network/interfaces
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1

esac

exit $?

Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

# marshal requires eth0 to be the first interface in this file, please add other interfaces below it
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address firemarshal_ip_addr_uninitialized
netmask 255.255.0.0
gateway 172.16.0.1
dns-nameservers 172.16.1.3
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ DEVICE=eth0
BOOTPROTO=static
ONBOOT=on
PREFIX=16
PEERDNS=yes
DNS1=172.16.1.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NETWORKING=yes
NETWORKING_IPV6=no
GATEWAY=172.16.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ case "$macpref" in
maclow=$(echo $mac | cut -c 16-17 -)
cp /etc/firesim/ifcfg-static /etc/sysconfig/network-scripts/ifcfg-eth0
echo IPADDR=172.16.$((16#$machigh)).$((16#$maclow)) >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo default via 172.16.0.1 dev eth0 > /etc/sysconfig/network-scripts/route-eth0
cp /etc/firesim/network-static /etc/sysconfig/network
;;
"52:54:00")
echo "this looks like not FireSim. exiting"
Expand Down
5 changes: 4 additions & 1 deletion scripts/fullTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
'qemu',
'run',
'simArgs',
'noDrivers'
'noDrivers',
'internet',
'network',
'fed-nw-internet'
],

# This tests both no-disk and spike. In theory, most (maybe all?) tests
Expand Down
28 changes: 28 additions & 0 deletions test/fed-nw-internet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name" : "fed-nw-internet",
"base" : "fedora-base.json",
"host-init" : "host-init.sh",
"overlay": "overlay",
"testing" : {
"refDir" : "refOutput",
"strip" : true
},
"jobs" : [
{
"name" : "j0",
"command" : "timeout 75 /root/test-server.sh"
},
{
"name" : "j1",
"command" : "/root/test-client-1.sh"
},
{
"name" : "j2",
"command" : "/root/test-client-2.sh"
},
{
"name" : "j3",
"command" : 'yum install -y wget && wget fires.im && echo "Success : yum + wget"'
}
]
}
91 changes: 91 additions & 0 deletions test/fed-nw-internet/client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <arpa/inet.h>
#include <time.h>


int main(int argc, char *argv[])
{
int sockfd = 0, res = 0, n = 0;
char recvBuff[1024];
struct sockaddr_in serv_addr;
fd_set myset;
struct timeval tv;
int valopt;
socklen_t lon;

if(argc != 2)
{
printf("\nUsage: %s <ip of server>\n",argv[0]);
return 1;
}

memset(&serv_addr, '0', sizeof(serv_addr));

serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(5000);

if(inet_pton(AF_INET, argv[1], &serv_addr.sin_addr)<=0)
{
printf("\nError : inet_pton error occured\n");
return 1;
}

memset(recvBuff, '0',sizeof(recvBuff));

if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
printf("\nError : Could not create socket (%d %s) \n", errno, strerror(errno));
return 1;
}


int t = 0;
while(1){

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistent tab size

if(t >= 30)
{
printf("\nError : Could not connect to server (%d %s) \n", errno, strerror(errno));
return 1;
}
if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) >= 0) {
break;
}
sleep(1);

t += 1;
}


while ((n = read(sockfd, recvBuff, sizeof(recvBuff)-1)) > 0)
{
recvBuff[n] = 0;
if(fputs(recvBuff, stdout) == EOF)
{
printf("\nError : Fputs error\n");
}
}

if(n < 0)
{
printf("\nError : Read error\n");
} else {
if (strncmp(recvBuff,argv[1],strlen(argv[1])) == 0) {
printf("\nSuccess : %s\n", argv[1]);
} else {
printf("\n Error : Expected : %s Received : %s\n", argv[1], recvBuff);
}
}

close(sockfd);

return 0;
}
3 changes: 3 additions & 0 deletions test/fed-nw-internet/host-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
riscv64-unknown-linux-gnu-gcc client.c -o overlay/root/client
riscv64-unknown-linux-gnu-gcc server.c -o overlay/root/server
14 changes: 14 additions & 0 deletions test/fed-nw-internet/overlay/root/test-client-1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#/bin/bash
ip_read=`ip -f inet addr show eth0 | grep -Po 'inet \K[\d.]+'`
if [ "$ip_read" = "172.16.0.3" ]; then
/root/client 172.16.0.2
if [ "$?" -eq "0" ]; then
echo 'Success : ip + client'
else
echo 'Failed : client'
fi
else
echo 'Failed : ip'
echo 'Expected : 172.16.0.3'
echo 'Received : $ip_read'
fi
14 changes: 14 additions & 0 deletions test/fed-nw-internet/overlay/root/test-client-2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#/bin/bash
ip_read=`ip -f inet addr show eth0 | grep -Po 'inet \K[\d.]+'`
if [ "$ip_read" = "172.16.0.4" ]; then
/root/client 172.16.0.2
if [ "$?" -eq "0" ]; then
echo 'Success : ip + client'
else
echo 'Failed : client'
fi
else
echo 'Failed : ip'
echo 'Expected : 172.16.0.4'
echo 'Received : $ip_read'
fi
14 changes: 14 additions & 0 deletions test/fed-nw-internet/overlay/root/test-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#/bin/bash
ip_read=`ip -f inet addr show eth0 | grep -Po 'inet \K[\d.]+'`
if [ "$ip_read" = "172.16.0.2" ]; then
/root/server 2
if [ "$?" -eq "0" ]; then
echo 'Success : ip + server'
else
echo 'Failed : server'
fi
else
echo 'Failed : ip'
echo 'Expected : 172.16.0.2'
echo 'Received : $ip_read'
fi
1 change: 1 addition & 0 deletions test/fed-nw-internet/refOutput/fed-nw-internet-j0/uartlog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Success : ip + server
1 change: 1 addition & 0 deletions test/fed-nw-internet/refOutput/fed-nw-internet-j1/uartlog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Success : ip + client
1 change: 1 addition & 0 deletions test/fed-nw-internet/refOutput/fed-nw-internet-j2/uartlog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Success : ip + client
1 change: 1 addition & 0 deletions test/fed-nw-internet/refOutput/fed-nw-internet-j3/uartlog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Success : yum + wget
56 changes: 56 additions & 0 deletions test/fed-nw-internet/server.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{
if(argc != 2)
{
printf("\nUsage: %s <num_clients>\n",argv[0]);
return 1;
}

int num_clients = *(int *)(argv[1]);

int listenfd = 0, connfd = 0;
struct sockaddr_in serv_addr;

char sendBuff[1025];
time_t ticks;

listenfd = socket(AF_INET, SOCK_STREAM, 0);
memset(&serv_addr, '0', sizeof(serv_addr));
memset(sendBuff, '0', sizeof(sendBuff));

serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(5000);

bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));

listen(listenfd, 10);

for (int i = 0; i < 2; i += 1) {

connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);

printf("Sending\n");
snprintf(sendBuff, sizeof(sendBuff), "172.16.0.2\r\n");
write(connfd, sendBuff, strlen(sendBuff));
printf("Closing\n");
close(connfd);
}

close(listenfd);

return 0;

}
9 changes: 9 additions & 0 deletions test/internet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name" : "internet",
"base" : "br-base.json",
"command" : 'wget -S fires.im && echo "Success : wget"',
"testing" : {
"refDir" : "refOutput",
"strip" : true
}
}
1 change: 1 addition & 0 deletions test/internet/refOutput/internet/uartlog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Success : wget
Loading