Debian Codegraph @

contrib/ports/unix/proj/unixsim/simrouter.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * This file is part of the lwIP TCP/IP stack.
28 *
29 * Author: Adam Dunkels <[email protected]>
30 *
31 */
32
33 #include "lwip/debug.h"
34
35 #include <unistd.h>
36
37
38 #include "lwip/mem.h"
39 #include "lwip/memp.h"
40 #include "lwip/sys.h"
41 #include "lwip/tcp_impl.h"
42
43 #include "lwip/stats.h"
44
45
46 #include "lwip/tcpip.h"
47
48 #include "netif/tapif.h"
49
50 #include "netif/unixif.h"
51 #include "netif/dropif.h"
52
53 #include "netif/tcpdump.h"
54
55
56 #include "lwip/ip_addr.h"
57
58 #include "arch/perf.h"
59
60 #include "httpd.h"
61 #include "udpecho.h"
62 #include "tcpecho.h"
63 #include "shell.h"
64
65 /* nonstatic debug cmd option, exported in lwipopts.h */
66 unsigned char debug_flags;
67
68 /*-----------------------------------------------------------------------------------*/
69 static void
70 tcp_timeout(void *data)
71 {
72 LWIP_UNUSED_ARG(data);
73 #if TCP_DEBUG
74 tcp_debug_print_pcbs();
75 #endif /* TCP_DEBUG */
76 sys_timeout(5000, tcp_timeout, NULL);
77 }
78 /*-----------------------------------------------------------------------------------*/
79
80 struct netif netif_tap, netif_unix;
81
82 /*-----------------------------------------------------------------------------------*/
83 static void
84 tcpip_init_done(void *arg)
85 {
86 ip_addr_t ipaddr, netmask, gw;
87 sys_sem_t *sem;
88 sem = (sys_sem_t *)arg;
89
90 IP4_ADDR(&gw, 192,168,0,1);
91 IP4_ADDR(&ipaddr, 192,168,0,2);
92 IP4_ADDR(&netmask, 255,255,255,0);
93
94 netif_set_default(netif_add(&netif_tap, &ipaddr, &netmask, &gw, NULL, tapif_init,
95 tcpip_input));
96 #if LWIP_IPV6
97 netif_create_ip6_linklocal_address(&netif_tap, 1);
98 #endif
99
100 IP4_ADDR(&gw, 192,168,1,1);
101 IP4_ADDR(&ipaddr, 192,168,1,1);
102 IP4_ADDR(&netmask, 255,255,255,0);
103 netif_set_default(netif_add(&netif_unix, &ipaddr, &netmask, &gw, NULL, unixif_init_server,
104 tcpip_input));
105 #if LWIP_IPV6
106 netif_create_ip6_linklocal_address(&netif_unix, 1);
107 #endif
108
109 system("route add 192.168.1.1 192.168.0.2");
110 system("route add 192.168.1.2 192.168.0.2");
111
112
113 /*netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, sioslipif_init1,
114 tcpip_input)); */
115
116 tcpecho_init();
117 shell_init();
118 httpd_init();
119 udpecho_init();
120
121 printf("Applications started.\n");
122
123 sys_timeout(5000, tcp_timeout, NULL);
124
125 sys_sem_signal(sem);
126 }
127
128
129 static void
130 main_thread(void *arg)
131 {
132 sys_sem_t sem;
133 LWIP_UNUSED_ARG(arg);
134
135 if(sys_sem_new(&sem, 0) != ERR_OK) {
136 LWIP_ASSERT("Failed to create semaphore", 0);
137 }
138 tcpip_init(tcpip_init_done, &sem);
139 sys_sem_wait(&sem);
140 printf("TCP/IP initialized.\n");
141
142 #ifdef MEM_PERF
143 mem_perf_init("/tmp/memstats.client");
144 #endif /* MEM_PERF */
145 /* Block forever. */
146 sys_sem_wait(&sem);
147 }
148 /*-----------------------------------------------------------------------------------*/
149 int
150 main(void)
151 {
152 #ifdef PERF
153 perf_init("/tmp/client.perf");
154 #endif /* PERF */
155
156 tcpdump_init();
157
158 printf("System initialized.\n");
159 sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
160 pause();
161 return 0;
162 }
163 /*-----------------------------------------------------------------------------------*/
164
165
166
167
168
169
170
171