42 #include "contiki-lib.h"
43 #include "contiki-net.h"
44 #include "net/ipv6/uip-ds6-route.h"
48 #define DEBUG DEBUG_NONE
51 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
52 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
54 #ifndef VIZTOOL_MAX_PAYLOAD_LEN
55 #define VIZTOOL_MAX_PAYLOAD_LEN 60
59 static unsigned char buf[VIZTOOL_MAX_PAYLOAD_LEN];
62 #define VIZTOOL_UDP_PORT 60001
65 #define REQUEST_TYPE_ND 1
66 #define REQUEST_TYPE_RT 2
67 #define REQUEST_TYPE_DRT 3
68 #define REQUEST_TYPE_ADDR 4
69 #define REQUEST_TYPE_TOTALS 0xFF
74 static uip_ipaddr_t *addr;
77 process_request() CC_NON_BANKED
86 left = VIZTOOL_MAX_PAYLOAD_LEN - 1;
89 if(buf[0] == REQUEST_TYPE_ND) {
91 PRINTF(
"Neighbors\n");
92 for(nbr = nbr_table_head(ds6_neighbors);
94 nbr = nbr_table_next(ds6_neighbors, nbr)) {
95 entry_size =
sizeof(i) +
sizeof(uip_ipaddr_t) +
sizeof(
uip_lladdr_t)
98 PRINT6ADDR(&nbr->ipaddr);
100 PRINTLLADDR(&nbr->lladdr);
101 PRINTF(
" - %u\n", nbr->state);
103 memcpy(buf + len, &i,
sizeof(i));
105 memcpy(buf + len, uip_ds6_nbr_get_ipaddr(nbr),
sizeof(uip_ipaddr_t));
106 len +=
sizeof(uip_ipaddr_t);
107 memcpy(buf + len, uip_ds6_nbr_get_ll(nbr),
sizeof(
uip_lladdr_t));
109 memcpy(buf + len, &nbr->state,
111 len +=
sizeof(nbr->state);
116 if(left < entry_size) {
120 }
else if(buf[0] == REQUEST_TYPE_RT) {
123 PRINTF(
"Routing table\n");
124 rt = uip_ds6_route_head();
126 for(i = buf[1]; i < uip_ds6_route_num_routes(); i++) {
128 entry_size =
sizeof(i) +
sizeof(rt->ipaddr)
130 +
sizeof(rt->state.lifetime)
131 +
sizeof(rt->state.learned_from);
133 memcpy(buf + len, &i,
sizeof(i));
135 memcpy(buf + len, &rt->ipaddr,
sizeof(rt->ipaddr));
136 len +=
sizeof(rt->ipaddr);
137 memcpy(buf + len, &rt->length,
sizeof(rt->length));
138 len +=
sizeof(rt->length);
140 PRINT6ADDR(&rt->ipaddr);
141 PRINTF(
" - %02x", rt->length);
143 PRINT6ADDR(uip_ds6_route_nexthop(rt));
145 flip = uip_htonl(rt->state.lifetime);
146 memcpy(buf + len, &flip,
sizeof(flip));
148 PRINTF(
" - %08lx", rt->state.lifetime);
150 memcpy(buf + len, &rt->state.learned_from,
151 sizeof(rt->state.learned_from));
152 len +=
sizeof(rt->state.learned_from);
154 PRINTF(
" - %02x [%u]\n", rt->state.learned_from, entry_size);
159 rt = uip_ds6_route_next(rt);
161 if(left < entry_size) {
166 }
else if(buf[0] == REQUEST_TYPE_DRT) {
169 PRINTF(
"Default Route\n");
170 addr = uip_ds6_defrt_choose();
172 defrt = uip_ds6_defrt_lookup(addr);
177 if(defrt !=
NULL && i < 1) {
178 entry_size =
sizeof(i) +
sizeof(defrt->ipaddr)
179 +
sizeof(defrt->isinfinite);
181 memcpy(buf + len, &i,
sizeof(i));
183 memcpy(buf + len, &defrt->ipaddr,
sizeof(defrt->ipaddr));
184 len +=
sizeof(defrt->ipaddr);
185 memcpy(buf + len, &defrt->isinfinite,
sizeof(defrt->isinfinite));
186 len +=
sizeof(defrt->isinfinite);
188 PRINT6ADDR(&defrt->ipaddr);
189 PRINTF(
" - %u\n", defrt->isinfinite);
193 }
else if(buf[0] == REQUEST_TYPE_ADDR) {
194 PRINTF(
"Unicast Addresses\n");
195 for(i = buf[1]; i < UIP_DS6_ADDR_NB; i++) {
196 if(uip_ds6_if.addr_list[i].isused) {
197 entry_size =
sizeof(i) +
sizeof(uip_ds6_if.addr_list[i].ipaddr);
199 memcpy(buf + len, &i,
sizeof(i));
201 memcpy(buf + len, &uip_ds6_if.addr_list[i].ipaddr,
202 sizeof(uip_ds6_if.addr_list[i].ipaddr));
203 len +=
sizeof(uip_ds6_if.addr_list[i].ipaddr);
205 PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
210 if(left < entry_size) {
215 }
else if(buf[0] == REQUEST_TYPE_TOTALS) {
216 memset(&buf[2], 0, 4);
217 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
218 if(uip_ds6_if.addr_list[i].isused) {
222 for(nbr = nbr_table_head(ds6_neighbors);
224 nbr = nbr_table_next(ds6_neighbors, nbr)) {
228 buf[4] = uip_ds6_route_num_routes();
240 PROCESS(viztool_process,
"Network Visualization Tool Process");
243 tcpip_handler(
void) CC_NON_BANKED
246 memset(buf, 0, VIZTOOL_MAX_PAYLOAD_LEN);
250 PRINTF(
"]:%u\n",
UIP_HTONS(UIP_UDP_BUF->srcport));
254 len = process_request();
256 server_conn->
rport = UIP_UDP_BUF->srcport;
258 uip_udp_packet_send(server_conn, buf, len);
259 PRINTF(
"Sent %u bytes\n", len);
264 server_conn->
rport = 0;
#define uip_create_unspecified(a)
set IP address a to unspecified
An entry in the routing table.
uint16_t rport
The remote port number in network byte order.
#define PROCESS_BEGIN()
Define the beginning of a process.
CCIF struct uip_udp_conn * udp_new(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
Create a new UDP connection.
#define uip_newdata()
Is new incoming data available?
#define NULL
The null pointer.
uip_eth_addr uip_lladdr_t
Ethernet address.
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
uip_ipaddr_t ripaddr
The IP address of the remote peer.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define UIP_IP_BUF
Pointer to IP header.
#define PROCESS_END()
Define the end of a process.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
#define PROCESS(name, strname)
Declare a process.
#define uip_datalen()
The length of any incoming data that is currently available (if available) in the uip_appdata buffer...
process_event_t tcpip_event
The uIP event.
Interface structure (contains all the interface variables)
#define PROCESS_YIELD()
Yield the currently running process.
#define udp_bind(conn, port)
Bind a UDP connection to a local port.
A set of debugging macros.
Representation of a uIP UDP connection.
An entry in the default router list.
uip_appdata
Pointer to the application data in the packet buffer.
An entry in the nbr cache.