Permalink
Browse files

lab6

  • Loading branch information...
1 parent fe0c7e6 commit bde6cefeb699c4c29df9ccf4e17cfab9e32ec797 @aclements aclements committed Nov 13, 2009
Showing with 57,117 additions and 15 deletions.
  1. +30 −2 GNUmakefile
  2. +2 −2 conf/lab.mk
  3. +3 −0 fs/Makefrag
  4. +11 −0 fs/index.html
  5. +130 −0 grade-lab6.sh
  6. +24 −0 inc/lib.h
  7. +87 −0 inc/ns.h
  8. +1 −0 inc/syscall.h
  9. +11 −4 kern/Makefrag
  10. +1 −0 kern/e100.c
  11. +3 −0 kern/e100.h
  12. +10 −3 kern/init.c
  13. +250 −0 kern/pci.c
  14. +33 −0 kern/pci.h
  15. +710 −0 kern/pcireg.h
  16. +12 −0 kern/picirq.c
  17. +1 −1 kern/picirq.h
  18. +10 −0 kern/syscall.c
  19. +26 −0 kern/time.c
  20. +11 −0 kern/time.h
  21. +5 −0 kern/trap.c
  22. +4 −0 lib/Makefrag
  23. +4 −0 lib/entry.S
  24. +1 −1 lib/file.c
  25. +140 −0 lib/malloc.c
  26. +158 −0 lib/nsipc.c
  27. +56 −0 lib/sockets.c
  28. +6 −0 lib/syscall.c
  29. +21 −0 net/Makefrag
  30. +11 −0 net/input.c
  31. +13 −0 net/lwip/FILES
  32. +72 −0 net/lwip/Makefrag
  33. +571 −0 net/lwip/api/api_lib.c
  34. +1,210 −0 net/lwip/api/api_msg.c
  35. +74 −0 net/lwip/api/err.c
  36. +235 −0 net/lwip/api/netbuf.c
  37. +353 −0 net/lwip/api/netdb.c
  38. +126 −0 net/lwip/api/netifapi.c
  39. +1,924 −0 net/lwip/api/sockets.c
  40. +559 −0 net/lwip/api/tcpip.c
  41. +1,553 −0 net/lwip/core/dhcp.c
  42. +814 −0 net/lwip/core/dns.c
  43. +253 −0 net/lwip/core/init.c
  44. +432 −0 net/lwip/core/ipv4/autoip.c
  45. +317 −0 net/lwip/core/ipv4/icmp.c
  46. +808 −0 net/lwip/core/ipv4/igmp.c
  47. +278 −0 net/lwip/core/ipv4/inet.c
  48. +426 −0 net/lwip/core/ipv4/inet_chksum.c
  49. +624 −0 net/lwip/core/ipv4/ip.c
  50. +84 −0 net/lwip/core/ipv4/ip_addr.c
  51. +783 −0 net/lwip/core/ipv4/ip_frag.c
  52. +1 −0 net/lwip/core/ipv6/README
  53. +179 −0 net/lwip/core/ipv6/icmp6.c
  54. +163 −0 net/lwip/core/ipv6/inet6.c
  55. +375 −0 net/lwip/core/ipv6/ip6.c
  56. +72 −0 net/lwip/core/ipv6/ip6_addr.c
  57. +631 −0 net/lwip/core/mem.c
  58. +370 −0 net/lwip/core/memp.c
  59. +663 −0 net/lwip/core/netif.c
  60. +779 −0 net/lwip/core/pbuf.c
  61. +336 −0 net/lwip/core/raw.c
  62. +657 −0 net/lwip/core/snmp/asn1_dec.c
  63. +611 −0 net/lwip/core/snmp/asn1_enc.c
  64. +4,126 −0 net/lwip/core/snmp/mib2.c
  65. +1,183 −0 net/lwip/core/snmp/mib_structs.c
  66. +1,453 −0 net/lwip/core/snmp/msg_in.c
  67. +683 −0 net/lwip/core/snmp/msg_out.c
  68. +149 −0 net/lwip/core/stats.c
  69. +344 −0 net/lwip/core/sys.c
  70. +1,420 −0 net/lwip/core/tcp.c
  71. +1,350 −0 net/lwip/core/tcp_in.c
  72. +953 −0 net/lwip/core/tcp_out.c
  73. +824 −0 net/lwip/core/udp.c
  74. +105 −0 net/lwip/include/ipv4/lwip/autoip.h
  75. +121 −0 net/lwip/include/ipv4/lwip/icmp.h
  76. +162 −0 net/lwip/include/ipv4/lwip/igmp.h
  77. +100 −0 net/lwip/include/ipv4/lwip/inet.h
  78. +58 −0 net/lwip/include/ipv4/lwip/inet_chksum.h
  79. +173 −0 net/lwip/include/ipv4/lwip/ip.h
  80. +165 −0 net/lwip/include/ipv4/lwip/ip_addr.h
  81. +76 −0 net/lwip/include/ipv4/lwip/ip_frag.h
  82. +100 −0 net/lwip/include/ipv6/lwip/icmp.h
  83. +68 −0 net/lwip/include/ipv6/lwip/inet.h
  84. +127 −0 net/lwip/include/ipv6/lwip/ip.h
  85. +97 −0 net/lwip/include/ipv6/lwip/ip_addr.h
  86. +217 −0 net/lwip/include/lwip/api.h
  87. +160 −0 net/lwip/include/lwip/api_msg.h
  88. +228 −0 net/lwip/include/lwip/arch.h
  89. +97 −0 net/lwip/include/lwip/debug.h
  90. +47 −0 net/lwip/include/lwip/def.h
  91. +246 −0 net/lwip/include/lwip/dhcp.h
  92. +92 −0 net/lwip/include/lwip/dns.h
  93. +87 −0 net/lwip/include/lwip/err.h
  94. +48 −0 net/lwip/include/lwip/init.h
  95. +103 −0 net/lwip/include/lwip/mem.h
  96. +94 −0 net/lwip/include/lwip/memp.h
  97. +101 −0 net/lwip/include/lwip/memp_std.h
  98. +76 −0 net/lwip/include/lwip/netbuf.h
  99. +109 −0 net/lwip/include/lwip/netdb.h
  100. +263 −0 net/lwip/include/lwip/netif.h
  101. +100 −0 net/lwip/include/lwip/netifapi.h
  102. +1,704 −0 net/lwip/include/lwip/opt.h
  103. +118 −0 net/lwip/include/lwip/pbuf.h
  104. +97 −0 net/lwip/include/lwip/raw.h
  105. +81 −0 net/lwip/include/lwip/sio.h
  106. +364 −0 net/lwip/include/lwip/snmp.h
  107. +97 −0 net/lwip/include/lwip/snmp_asn1.h
  108. +307 −0 net/lwip/include/lwip/snmp_msg.h
  109. +262 −0 net/lwip/include/lwip/snmp_structs.h
  110. +358 −0 net/lwip/include/lwip/sockets.h
  111. +283 −0 net/lwip/include/lwip/stats.h
  112. +246 −0 net/lwip/include/lwip/sys.h
  113. +641 −0 net/lwip/include/lwip/tcp.h
  114. +139 −0 net/lwip/include/lwip/tcpip.h
  115. +150 −0 net/lwip/include/lwip/udp.h
  116. +175 −0 net/lwip/include/netif/etharp.h
  117. +53 −0 net/lwip/include/netif/loopif.h
  118. +161 −0 net/lwip/include/netif/ppp_oe.h
  119. +50 −0 net/lwip/include/netif/slipif.h
  120. +41 −0 net/lwip/jos/arch/cc.h
  121. +17 −0 net/lwip/jos/arch/i386/setjmp.h
  122. +39 −0 net/lwip/jos/arch/longjmp.S
  123. +7 −0 net/lwip/jos/arch/perf.h
  124. +166 −0 net/lwip/jos/arch/perror.c
  125. +7 −0 net/lwip/jos/arch/perror.h
  126. +10 −0 net/lwip/jos/arch/setjmp.h
  127. +322 −0 net/lwip/jos/arch/sys_arch.c
  128. +23 −0 net/lwip/jos/arch/sys_arch.h
  129. +175 −0 net/lwip/jos/arch/thread.c
  130. +18 −0 net/lwip/jos/arch/thread.h
  131. +65 −0 net/lwip/jos/arch/threadq.h
  132. +255 −0 net/lwip/jos/jif/jif.c
  133. +4 −0 net/lwip/jos/jif/jif.h
  134. +63 −0 net/lwip/jos/lwipopts.h
  135. +25 −0 net/lwip/netif/FILES
  136. +1,186 −0 net/lwip/netif/etharp.c
  137. +313 −0 net/lwip/netif/ethernetif.c
  138. +66 −0 net/lwip/netif/loopif.c
  139. +988 −0 net/lwip/netif/ppp/auth.c
  140. +111 −0 net/lwip/netif/ppp/auth.h
  141. +902 −0 net/lwip/netif/ppp/chap.c
  142. +166 −0 net/lwip/netif/ppp/chap.h
  143. +396 −0 net/lwip/netif/ppp/chpms.c
  144. +64 −0 net/lwip/netif/ppp/chpms.h
  145. +906 −0 net/lwip/netif/ppp/fsm.c
  146. +169 −0 net/lwip/netif/ppp/fsm.h
  147. +1,440 −0 net/lwip/netif/ppp/ipcp.c
  148. +124 −0 net/lwip/netif/ppp/ipcp.h
  149. +2,035 −0 net/lwip/netif/ppp/lcp.c
  150. +167 −0 net/lwip/netif/ppp/lcp.h
  151. +82 −0 net/lwip/netif/ppp/magic.c
  152. +67 −0 net/lwip/netif/ppp/magic.h
  153. +318 −0 net/lwip/netif/ppp/md5.c
  154. +55 −0 net/lwip/netif/ppp/md5.h
  155. +617 −0 net/lwip/netif/ppp/pap.c
  156. +131 −0 net/lwip/netif/ppp/pap.h
  157. +2,003 −0 net/lwip/netif/ppp/ppp.c
  158. +465 −0 net/lwip/netif/ppp/ppp.h
  159. +1,227 −0 net/lwip/netif/ppp/ppp_oe.c
  160. +86 −0 net/lwip/netif/ppp/pppdebug.h
  161. +248 −0 net/lwip/netif/ppp/randm.c
  162. +81 −0 net/lwip/netif/ppp/randm.h
  163. +660 −0 net/lwip/netif/ppp/vj.c
  164. +155 −0 net/lwip/netif/ppp/vj.h
  165. +75 −0 net/lwip/netif/ppp/vjbsdhdr.h
  166. +279 −0 net/lwip/netif/slipif.c
  167. +22 −0 net/ns.h
  168. +12 −0 net/output.c
  169. +412 −0 net/serv.c
  170. +29 −0 net/timer.c
  171. +2 −2 user/Makefrag
  172. +92 −0 user/echosrv.c
  173. +69 −0 user/echotest.c
  174. +327 −0 user/httpd.c
  175. +24 −0 user/testtime.c
View
@@ -89,6 +89,10 @@ PERL := perl
CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O1 -fno-builtin -I$(TOP) -MD
CFLAGS += -Wall -Wno-format -Wno-unused -Werror -gstabs -m32
+CFLAGS += -I$(TOP)/net/lwip/include \
+ -I$(TOP)/net/lwip/include/ipv4 \
+ -I$(TOP)/net/lwip/jos
+
# Add -fno-stack-protector if the option exists.
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
@@ -114,7 +118,8 @@ all:
# make it so that no intermediate .o files are ever deleted
.PRECIOUS: %.o $(OBJDIR)/boot/%.o $(OBJDIR)/kern/%.o \
- $(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/user/%.o
+ $(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/net/%.o \
+ $(OBJDIR)/user/%.o
KERN_CFLAGS := $(CFLAGS) -DJOS_KERNEL -gstabs
USER_CFLAGS := $(CFLAGS) -DJOS_USER -gstabs
@@ -128,10 +133,16 @@ include kern/Makefrag
include lib/Makefrag
include user/Makefrag
include fs/Makefrag
+include net/Makefrag
+
+PORT7 := $(shell expr $(GDBPORT) + 1)
+PORT80 := $(shell expr $(GDBPORT) + 2)
IMAGES = $(OBJDIR)/kern/kernel.img $(OBJDIR)/fs/fs.img
-QEMUOPTS = -hda $(OBJDIR)/kern/kernel.img -hdb $(OBJDIR)/fs/fs.img -serial mon:stdio
+QEMUOPTS = -hda $(OBJDIR)/kern/kernel.img -hdb $(OBJDIR)/fs/fs.img -serial mon:stdio \
+ -net user -net nic,model=i82559er -redir tcp:$(PORT7)::7 \
+ -redir tcp:$(PORT80)::80 $(QEMUEXTRA)
.gdbinit: .gdbinit.tmpl
sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
@@ -188,6 +199,23 @@ xrun-%:
$(V)$(MAKE) "DEFS=-DTEST=_binary_obj_user_$*_start -DTESTSIZE=_binary_obj_user_$*_size" $(IMAGES)
$(QEMU) $(QEMUOPTS)
+# For network connections
+which-ports:
+ @echo "Local port $(PORT7) forwards to JOS port 7 (echo server)"
+ @echo "Local port $(PORT80) forwards to JOS port 80 (web server)"
+
+nc-80:
+ nc localhost $(PORT80)
+
+nc-7:
+ nc localhost $(PORT7)
+
+telnet-80:
+ telnet localhost $(PORT80)
+
+telnet-7:
+ telnet localhost $(PORT7)
+
# This magic automatically generates makefile dependencies
# for header files included from C source files we compile,
# and keeps those dependencies up-to-date every time we recompile.
View
@@ -1,2 +1,2 @@
-LAB=5
-PACKAGEDATE=Tue Nov 3 13:41:56 EST 2009
+LAB=6
+PACKAGEDATE=Fri Nov 13 02:30:19 EST 2009
View
@@ -18,6 +18,9 @@ USERAPPS := $(OBJDIR)/user/cat \
FSIMGTXTFILES := fs/newmotd \
fs/motd
+FSIMGTXTFILES := $(FSIMGTXTFILES) \
+ fs/index.html
+
FSIMGFILES := $(FSIMGTXTFILES) $(USERAPPS)
View
@@ -0,0 +1,11 @@
+<html>
+<head>
+ <title>jhttpd on JOS</title>
+</head>
+<body>
+ <center>
+ <h2>This file came from JOS.</h2>
+ <blink>Cheesy web page!</blink>
+ </center>
+</body>
+</html>
View
@@ -0,0 +1,130 @@
+#!/bin/sh
+
+qemuopts="-hda obj/kern/kernel.img -hdb obj/fs/fs.img"
+. ./grade-functions.sh
+
+$make
+
+rand() {
+ perl -e "my \$r = int(1024 + rand() * (65535 - 1024));print \"\$r\\n\";"
+}
+
+qemu_test_httpd() {
+ pts=5
+
+ echo ""
+
+ perl -e "print ' wget localhost:$http_port/: '"
+ if wget -o wget.log -O /dev/null localhost:$http_port/; then
+ echo "WRONG, got back data";
+ else
+ if egrep "ERROR 404" wget.log >/dev/null; then
+ score=`expr $pts + $score`
+ echo "OK";
+ else
+ echo "WRONG, did not get 404 error";
+ fi
+ fi
+
+ perl -e "print ' wget localhost:$http_port/index.html: '"
+ if wget -o /dev/null -O qemu.out localhost:$http_port/index.html; then
+ if diff qemu.out fs/index.html > /dev/null; then
+ score=`expr $pts + $score`
+ echo "OK";
+ else
+ echo "WRONG, returned data does not match index.html";
+ fi
+ else
+ echo "WRONG, got error";
+ fi
+
+ perl -e "print ' wget localhost:$http_port/random_file.txt: '"
+ if wget -o wget.log -O /dev/null localhost:$http_port/random_file.txt; then
+ echo "WRONG, got back data";
+ else
+ if egrep "ERROR 404" wget.log >/dev/null; then
+ score=`expr $pts + $score`
+ echo "OK";
+ else
+ echo "WRONG, did not get 404 error";
+ fi
+ fi
+
+ kill $qemu_pid
+ wait 2> /dev/null
+
+ t1=`date +%s.%N 2>/dev/null`
+ time=`echo "scale=1; ($t1-$t0)/1" | sed 's/.N/.0/g' | bc 2>/dev/null`
+ time="(${time}s)"
+}
+
+qemu_test_echosrv() {
+ pts=85
+
+ str="$t0: network server works"
+ echo $str | nc -q 3 localhost $echosrv_port > qemu.out
+
+ kill $qemu_pid
+ wait 2> /dev/null
+
+ t1=`date +%s.%N 2>/dev/null`
+ time=`echo "scale=1; ($t1-$t0)/1" | sed 's/.N/.0/g' | bc 2>/dev/null`
+ time="(${time}s)"
+
+ if egrep "^$str\$" qemu.out > /dev/null
+ then
+ score=`expr $pts + $score`
+ echo OK $time
+ else
+ echo WRONG $time
+ fi
+}
+
+# Override run to start QEMU and return without waiting
+run() {
+ t0=`date +%s.%N 2>/dev/null`
+ # The timeout here doesn't really matter, but it helps prevent
+ # runaway qemu's
+ (
+ ulimit -t $timeout
+ exec $qemu -nographic $qemuopts -serial file:jos.out -monitor null -no-reboot
+ ) >$out 2>$err &
+ qemu_pid=$!
+
+ sleep 8 # wait for qemu to start up
+}
+
+# Make continuetest a no-op and run the tests ourselves
+continuetest () {
+ return
+}
+
+# Reset the file system to its original, pristine state
+resetfs() {
+ rm -f obj/fs/fs.img
+ $make obj/fs/fs.img >$out
+}
+
+score=0
+
+http_port=`rand`
+echosrv_port=`rand`
+echo "using http port: $http_port"
+echo "using echo server port: $echosrv_port"
+
+qemuopts="$qemuopts -net user -net nic,model=i82559er"
+qemuopts="$qemuopts -redir tcp:$echosrv_port::7 -redir tcp:$http_port::80"
+
+resetfs
+
+runtest1 -tag 'tcp echo server [echosrv]' echosrv
+qemu_test_echosrv
+
+runtest1 -tag 'web server [httpd]' httpd
+qemu_test_httpd
+
+echo "Score: $score/100"
+
+if [ $score -lt 100 ]; then
+ exit 1
+fi
View
@@ -20,6 +20,8 @@
#include <inc/fs.h>
#include <inc/fd.h>
#include <inc/args.h>
+#include <inc/malloc.h>
+#include <inc/ns.h>
#define USED(x) (void)(x)
@@ -52,6 +54,7 @@ int sys_page_map(envid_t src_env, void *src_pg,
int sys_page_unmap(envid_t env, void *pg);
int sys_ipc_try_send(envid_t to_env, uint32_t value, void *pg, int perm);
int sys_ipc_recv(void *rcv_pg);
+unsigned int sys_time_msec(void);
// This must be inlined. Exercise for reader: why?
static __inline envid_t sys_exofork(void) __attribute__((always_inline));
@@ -103,6 +106,27 @@ int fsipc_dirty(int fileid, off_t offset);
int fsipc_remove(const char *path);
int fsipc_sync(void);
+// sockets.c
+int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
+int bind(int s, struct sockaddr *name, socklen_t namelen);
+int shutdown(int s, int how);
+int closesocket(int s);
+int connect(int s, const struct sockaddr *name, socklen_t namelen);
+int listen(int s, int backlog);
+int recv(int s, void *mem, int len, unsigned int flags);
+int send(int s, const void *dataptr, int size, unsigned int flags);
+int socket(int domain, int type, int protocol);
+
+// nsipc.c
+int nsipc_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
+int nsipc_bind(int s, struct sockaddr *name, socklen_t namelen);
+int nsipc_shutdown(int s, int how);
+int nsipc_close(int s);
+int nsipc_connect(int s, const struct sockaddr *name, socklen_t namelen);
+int nsipc_listen(int s, int backlog);
+int nsipc_recv(int s, void *mem, int len, unsigned int flags);
+int nsipc_send(int s, const void *dataptr, int size, unsigned int flags);
+int nsipc_socket(int domain, int type, int protocol);
// pageref.c
int pageref(void *addr);
View
@@ -0,0 +1,87 @@
+// See COPYRIGHT for copyright information.
+
+#ifndef JOS_INC_NS_H
+#define JOS_INC_NS_H
+
+#include <inc/types.h>
+#include <lwip/sockets.h>
+
+// Definitions for requests from clients to network server
+
+#define NSREQ_ACCEPT 1
+#define NSREQ_BIND 2
+#define NSREQ_SHUTDOWN 3
+#define NSREQ_CLOSE 4
+#define NSREQ_CONNECT 5
+#define NSREQ_LISTEN 6
+#define NSREQ_RECV 7
+#define NSREQ_SEND 8
+#define NSREQ_SOCKET 9
+
+// The following two messages pass a page containing a struct jif_pkt
+#define NSREQ_INPUT 10
+#define NSREQ_OUTPUT 11
+
+// The following message passes no page
+#define NSREQ_TIMER 12
+
+struct Nsreq_accept {
+ int req_s;
+};
+
+struct Nsret_accept {
+ struct sockaddr ret_addr;
+ socklen_t ret_addrlen;
+};
+
+struct Nsreq_bind {
+ int req_s;
+ struct sockaddr req_name;
+ socklen_t req_namelen;
+};
+
+struct Nsreq_shutdown {
+ int req_s;
+ int req_how;
+};
+
+struct Nsreq_close {
+ int req_s;
+};
+
+struct Nsreq_connect {
+ int req_s;
+ struct sockaddr req_name;
+ socklen_t req_namelen;
+};
+
+struct Nsreq_listen {
+ int req_s;
+ int req_backlog;
+};
+
+struct Nsreq_recv {
+ int req_s;
+ int req_len;
+ unsigned int req_flags;
+};
+
+struct Nsreq_send {
+ int req_s;
+ int req_size;
+ unsigned int req_flags;
+ char req_dataptr[0];
+};
+
+struct Nsreq_socket {
+ int req_domain;
+ int req_type;
+ int req_protocol;
+};
+
+struct jif_pkt {
+ int jp_len;
+ char jp_data[0];
+};
+
+#endif // !JOS_INC_NS_H
View
@@ -18,6 +18,7 @@ enum
SYS_yield,
SYS_ipc_try_send,
SYS_ipc_recv,
+ SYS_time_msec,
NSYSCALLS
};
View
@@ -31,18 +31,25 @@ KERN_SRCFILES := kern/entry.S \
lib/readline.c \
lib/string.c
+# Source files for LAB6
+KERN_SRCFILES += kern/e100.c \
+ kern/pci.c \
+ kern/time.c
+
# Only build files if they exist.
KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
-# Binary program images to embed within the kernel.
KERN_BINFILES := user/idle \
- user/forktree \
user/pingpong \
user/primes \
- user/testfsipc \
user/writemotd \
user/icode \
- fs/fs
+ user/testtime \
+ user/httpd \
+ user/echosrv \
+ user/echotest \
+ fs/fs \
+ net/ns
KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES))
KERN_OBJFILES := $(patsubst %.S, $(OBJDIR)/%.o, $(KERN_OBJFILES))
View
@@ -0,0 +1 @@
+// LAB 6: Your driver code here
View
@@ -0,0 +1,3 @@
+#ifndef JOS_KERN_E100_H
+#define JOS_KERN_E100_H
+#endif // JOS_KERN_E100_H
Oops, something went wrong.

0 comments on commit bde6cef

Please sign in to comment.