]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
- fix async warning in resource queue
authorsdhsdh <sdhsdh>
Wed, 19 Aug 2009 17:08:59 +0000 (17:08 +0000)
committersdhsdh <sdhsdh>
Wed, 19 Aug 2009 17:08:59 +0000 (17:08 +0000)
 - fix UDP fragmentation bug
 - add sequence number to RAs and support for rebuilding DAG

14 files changed:
support/sdk/c/blip/driver/config.c
support/sdk/c/blip/driver/radvd-1.0/send.c
support/sdk/c/blip/driver/radvd-wrapper.c
support/sdk/c/blip/driver/routing.c
support/sdk/c/blip/driver/routing.h
support/sdk/c/blip/driver/serial_tun.c
support/sdk/c/blip/driver/tun_dev.c
support/sdk/c/blip/lib6lowpan/lib6lowpanIP.c
tos/lib/net/blip/ICMP.h
tos/lib/net/blip/ICMPResponderP.nc
tos/lib/net/blip/IPDispatchP.nc
tos/lib/net/blip/IPRoutingP.nc
tos/lib/net/blip/UdpP.nc
tos/lib/net/blip/interfaces/IPRouting.nc

index 3c8260806fd8023e2209f2faff9dc182a0936a69..54e46f39549c3f33efa0556b266ad76e57ac1cc1 100644 (file)
@@ -96,7 +96,9 @@ int config_parse(const char *file, struct config *c) {
   if (gotargs != 3) return 1;
 
   info("Read config from '%s'\r\n", file);
-  info("Proxying neighbor advertisements to %s\r\n", c->proxy_dev);
+  if (strncmp(c->proxy_dev, "lo", 3) != 0) {
+    info("Proxying neighbor advertisements to %s\r\n", c->proxy_dev);
+  }
   info("Using channel %i\r\n", c->channel);
   info("Retries: %i\r\n", c->retries);
   lastconfig = c;
index 43145f8d064a7b8b3eb0ef1b99a43897f6354dc7..2a96d04cc7b036391e850e4e9f1f489471248422 100644 (file)
 #include <includes.h>
 #include <radvd.h>
 
+
+uint16_t routing_get_seqno();
+
+#define ICMP_EXT_TYPE_BEACON 17
+
+/* SDH : copied from ICMP.h */
+struct AdvMetric {
+  uint8_t type;
+  uint8_t length;
+  uint16_t metric;
+  uint16_t seqno;
+  uint8_t pad[2];
+};
+
+
 void
 send_ra(int sock, struct Interface *iface, struct in6_addr *dest)
 {
@@ -291,6 +306,19 @@ send_ra(int sock, struct Interface *iface, struct in6_addr *dest)
                memcpy(buff + len, &ha_info, sizeof(ha_info));
                len += sizeof(ha_info);
        }
+
+  {
+    /* add routing metric */
+    struct AdvMetric metric;
+    metric.type = ICMP_EXT_TYPE_BEACON;
+    metric.length = 1;
+    metric.metric = htons(0);
+    metric.seqno = htons(routing_get_seqno());
+    memset(metric.pad, 0, sizeof(metric.pad));
+
+    memcpy(buff + len, &metric, sizeof(struct AdvMetric));
+    len += sizeof(struct AdvMetric);
+  }
        
        iov.iov_len  = len;
        iov.iov_base = (caddr_t) buff;
index 73e605961904aabffbd56eb813343e10f5df1e68..795abd0337bff15cb057a22c9c942d77c8d70044 100644 (file)
@@ -73,6 +73,19 @@ void radvd_timer_handler(void *data) {
   set_timer(&iface->tm, next);
 }
 
+void radvd_reset_adverts(void) {
+  if (iface->AdvSendAdvert) {
+    /* send an initial advertisement */
+    send_ra(sock, iface, NULL);
+    
+    iface->init_racount = 0;
+
+    set_timer(&iface->tm,
+              min(MAX_INITIAL_RTR_ADVERT_INTERVAL,
+                  iface->MaxRtrAdvInterval));
+  }
+}
+
 
 void radvd_kickoff_adverts(void) {
   init_timer(&iface->tm, radvd_timer_handler, (void *) iface);
index 11059e14f597a4c55d34022d434a1cd2d9f2f5ec..d2efc8e2903f3aaeddb257316102edc75a470b49 100644 (file)
@@ -40,6 +40,7 @@
 #include "netlink.h"
 
 static ieee154_saddr_t my_short_addr;
+static uint16_t current_seqno;
 extern struct in6_addr  __my_address;
 
 char proxy_dev[IFNAMSIZ], tun_dev[IFNAMSIZ];
@@ -81,6 +82,13 @@ int routing_init(struct config *c, char *tun_name) {
     fclose(fd);
   }
 
+  if ((fd = fopen("/var/run/ip-driver.seq", "r")) != NULL) {
+    if (fscanf(fd, "%hi\n", &current_seqno) != 1) {
+      current_seqno = 0;
+    }
+    fclose(fd);
+  }
+
   return (mcast_sock >= 0) ? 0 : -1;
 }
 
@@ -398,3 +406,17 @@ ieee154_saddr_t routing_get_nexthop(struct split_ip_msg *msg) {
 
   return ret;
 }
+
+uint16_t routing_get_seqno() {
+  return current_seqno;
+}
+
+uint16_t routing_incr_seqno() {
+  FILE *fd;
+  ++current_seqno;
+  if ((fd = fopen("/var/run/ip-driver.seq", "w")) != NULL) {
+    fprintf(fd, "%hi\n", current_seqno);
+    fclose(fd);
+  }
+  return current_seqno;
+}
index c9c3eb453cb9d2c80d1ddfc32be56b230afc3a63..1c1ac2363d78067fd045082db1abb0daab384a66 100644 (file)
@@ -82,5 +82,9 @@ ieee154_saddr_t routing_get_nexthop(struct split_ip_msg *msg);
  */
 int routing_add_report(node_id_t reporter, struct tlv_hdr *tlv);
 
+uint16_t routing_get_seqno();
+
+uint16_t routing_incr_seqno();
 
 #endif 
index 53381e1591d4570040f844636858a7c635124103..95a751c35315c51b8771b9f3743f6646891020f3 100644 (file)
@@ -93,6 +93,7 @@ int opt_listenonly = 0, opt_trackflows = 0;
 
 int radvd_init(char *ifname, struct config *c);
 void radvd_process();
+void radvd_reset_adverts(void);
 
 #ifndef SF_SRC
 serial_source ser_src;
@@ -163,7 +164,7 @@ void print_ip_packet(struct split_ip_msg *msg) {
   struct generic_header *g_hdr;
   if (log_getlevel() > LOGLVL_DEBUG) return;
 
-  printf("  nxthdr: 0x%x hlim: 0x%x\n", msg->hdr.nxt_hdr, msg->hdr.hlim);
+  printf("  nxthdr: 0x%x hlim: 0x%x plen: %i\n", msg->hdr.nxt_hdr, msg->hdr.hlim, ntohs(msg->hdr.plen));
   printf("  src: ");
   for (i = 0; i < 16; i++) printf("0x%x ", msg->hdr.ip6_src.s6_addr[i]);
   printf("\n");
@@ -1147,6 +1148,7 @@ void print_help(int fd, int argc, char **argv) {
   VTY_printf("  links          : print link detail\r\n");
   VTY_printf("  routes         : print routes\r\n");
   VTY_printf("  newroutes      : recalculate routes\r\n");
+  VTY_printf("  rebuild        : initiate a DAG recomputation\r\n");
   VTY_printf("  controller <n> : add a new controller\r\n");
 #ifdef CENTRALIZED_ROUTING
   VTY_printf("  install <HOP | SRC> <n1> <n2> [reverse]: install a route between n1 and n2\r\n");
@@ -1264,6 +1266,14 @@ void sh_controller(int fd, int argc, char **argv) {
   VTY_flush();
 }
 
+void sh_incr_seqno(int fd, int argc, char **argv) {
+  VTY_HEAD;
+  VTY_printf("DAG seqno now %i\r\n", routing_incr_seqno());
+  radvd_reset_adverts();
+
+  VTY_flush();
+}
+
 struct vty_cmd vty_cmd_list[] = {{"help", print_help},
                                  {"stats",  print_stats},
                                  {"links", nw_print_links},
@@ -1275,6 +1285,7 @@ struct vty_cmd vty_cmd_list[] = {{"help", print_help},
                                  {"log", sh_loglevel},
                                  {"dot", sh_dotfile},
                                  {"chan", sh_chan},
+                                 {"rebuild", sh_incr_seqno},
 #ifdef CENTRALIZED_ROUTING
                                  {"install", sh_install},
                                  {"uninstall", sh_uninstall},
@@ -1328,7 +1339,7 @@ int serial_tunnel(int tun_fd) {
     }
     usecs_remain -= (KEEPALIVE_TIMEOUT - tv.tv_usec);
     if (usecs_remain <= 0) {
-      if (keepalive_needed) {
+      if (keepalive_needed && !opt_listenonly) {
         configure_setparms(&driver_config, CONFIG_KEEPALIVE);
       } else keepalive_needed = 1;
 
@@ -1374,6 +1385,7 @@ int main(int argc, char **argv) {
       break;
     case 'l':
       opt_listenonly = 1;
+      info("Listen Only: will not attach to interface device\n");
       break;
     case 't':
       info("TrackFlows: will insert flow id on outgoing packets\n");
@@ -1385,9 +1397,9 @@ int main(int argc, char **argv) {
     }
   }
 
-  if (argc - optind != 2) {
+  if (argc - optind != 2 && !opt_listenonly) {
 #ifndef SF_SRC
-    fatal("usage: %s [-c config] [-n] <device> <rate>\n", argv[0]);
+    fatal("usage: %s [-c config] [-l] <device> <rate>\n", argv[0]);
 #else
     fatal("usage: %s [-c config] <host> <port>\n", argv[0]);
 #endif
index 3caf41f8ec200fe613f57f2639787722c4e81c15..f4b82177b66c30e41a2043606ac5d30bd01904bb 100644 (file)
@@ -148,7 +148,7 @@ int tun_setup(char *dev, struct in6_addr *addr) {
   }
 
   ifr6.ifr6_ifindex = ifr.ifr_ifindex;
-  ifr6.ifr6_prefixlen = 128;
+  ifr6.ifr6_prefixlen = 64;//128;
   if (ioctl(fd, SIOCSIFADDR, &ifr6) < 0) {
     log_fatal_perror("SIOCSIFADDR (global)");
     return -1;
index 9fb8cea3aeff883114e0a570a04b73514f89236c..54a70e89e5627dc71ce25b4759ab0c08c8483392 100644 (file)
@@ -192,12 +192,11 @@ static inline int decompressAddress(uint8_t dispatch, uint16_t src, uint8_t addr
 
 void adjustPlen(struct ip6_hdr *ip, unpack_info_t *u_info) {
   uint16_t adjust_amt = u_info->payload_offset;
-  /*
-  switch (u_info->nxt_hdr) {
+  
+  switch (ip->nxt_hdr) {
   case IANA_UDP:
     adjust_amt -= sizeof(struct udp_hdr); break;
   }
-  */
   ip->plen = htons(ntohs(ip->plen) - adjust_amt);
 }
 
@@ -334,7 +333,7 @@ uint8_t *unpackHeaders(packed_lowmsg_t *pkt, unpack_info_t *u_info,
       dest += sizeof(struct udp_hdr);
 
       u_info->nxt_hdr = IANA_UDP;
-      // u_info->payload_offset += sizeof(struct udp_hdr);
+      u_info->payload_offset += sizeof(struct udp_hdr);
       u_info->transport_ptr = (uint8_t *)udp;
 
     } else {
index 293cd8fada732898dd2c882ca6916d9ba94455e0..eac35a62c2e7511dffee47f98e22e46f6bf2b2f2 100644 (file)
@@ -93,7 +93,8 @@ typedef nx_struct {
   nx_uint8_t type;
   nx_uint8_t length;
   nx_uint16_t metric;
-  nx_uint8_t pad[4];
+  nx_uint16_t seqno;
+  nx_uint8_t pad[2];
 } rqual_t;
 
 struct icmp_stats {
index 4ac2b31cb2c82b99854705c044ebf4107944e1a9..556cd6215343fd8dcc13cc032b19e442f299e306 100644 (file)
@@ -53,6 +53,7 @@ module ICMPResponderP {
   icmp_statistics_t stats;
   uint32_t solicitation_period;
   uint32_t advertisement_period;
+  uint16_t nd_seqno = 0;
 
   uint16_t ping_seq, ping_n, ping_rcv, ping_ident;
   struct in6_addr ping_dest;
@@ -77,6 +78,8 @@ module ICMPResponderP {
   }
 
   command void ICMP.sendAdvertisements() {
+
+
     uint16_t jitter = (call Random.rand16()) % TRICKLE_JITTER;
     CHECK_NODE_ID;
     if (call Advertisement.isRunning()) return;
@@ -216,18 +219,25 @@ module ICMPResponderP {
     
     radv_t *r = (radv_t *)payload;
     pfx_t  *pfx = (pfx_t *)(r->options);
-    uint16_t cost = 0;
     rqual_t *beacon = (rqual_t *)(pfx + 1);
 
     if (len > sizeof(radv_t) + sizeof(pfx_t) && 
         beacon->type == ICMP_EXT_TYPE_BEACON) {
-      cost = beacon->metric;
+
+      if (beacon->seqno > nd_seqno || (nd_seqno > 0 && beacon->seqno == 0)) {
+        call IPRouting.reset();
+      }
+
+      nd_seqno = beacon->seqno;
+      call IPRouting.reportAdvertisement(meta->sender, r->hlim,
+                                         meta->lqi, beacon->metric);
+
+
+
       dbg("ICMPResponder", " * beacon cost: 0x%x\n", cost);
-    } else 
+    } else {
         dbg("ICMPResponder", " * no beacon cost\n");
-
-    call IPRouting.reportAdvertisement(meta->sender, r->hlim,
-                                       meta->lqi, cost);
+    }
 
     if (pfx->type != ICMP_EXT_TYPE_PREFIX) return;
 
index a83eee85125b084c72cc9d7feb420c1d3bdd42e4..8d4932809aedd89f09a421ecb4e2bc6ab850eb00 100644 (file)
@@ -659,6 +659,8 @@ module IPDispatchP {
     packed_lowmsg_t lowmsg;
 
     printfUART("p1: %p p2: %p\n", msg_payload, call Packet.getPayload(msg, 0));
+    printfUART("l1: %i l2: %i\n", len, call Packet.payloadLength(msg));
+
     // set up the ip message structaddFragment
     lowmsg.data = msg_payload;
     lowmsg.len  = len;
index e2780fdcb8a7657ede1dc41b24ad8f489a7da899..ebec62152686945b6a6a9c17fd2add83d2bb55aa 100644 (file)
@@ -59,8 +59,6 @@ module IPRoutingP {
   uint8_t last_hops;
   uint16_t reportSeqno;
 
-  uint8_t num_low_neigh;
-
   bool soliciting;
 
   // pointer into the neighbor table of the current entry that is our
@@ -158,8 +156,9 @@ module IPRoutingP {
 
   }
 
-  event void Boot.booted() {
+  command void IPRouting.reset() {
     int i;
+    printfUART("ROUTING RESET\n");
 
     for (i = 0; i < N_NEIGH; i++) {
       neigh_table[i].flags = 0;
@@ -174,7 +173,10 @@ module IPRoutingP {
 #endif
 
     // current_epoch = 0;
-    soliciting = FALSE;
+    if (!soliciting) {
+      call ICMP.sendSolicitations();
+      soliciting = TRUE;
+    }
     //reRouting = FALSE;
     default_route_failures = 0;
     default_route = &neigh_table[0];
@@ -182,14 +184,18 @@ module IPRoutingP {
     // associated from us when it gets the first packet.
     last_qual = 0xffff;
     last_hops = 0xff;
-    num_low_neigh = 0;
+
+    traffic_sent = FALSE;
+    restartTrafficGen();
+  }
+
+  event void Boot.booted() {
+    call IPRouting.reset();
     reportSeqno = call Random.rand16();
 
     call Statistics.clear();
     call SortTimer.startPeriodic(1024L * 60);
 
-    traffic_sent = FALSE;
-    restartTrafficGen();
   }
   
   command bool IPRouting.isForMe(struct ip6_hdr *hdr) {
@@ -911,8 +917,7 @@ module IPRoutingP {
     //bool recount = FALSE;
     struct neigh_entry *neigh_slot =  NULL;
     dbg("IPRouting", "report adv: 0x%x 0x%x 0x%x 0x%x\n", neigh, hops, lqi, cost);
-    dbg("IPRouting", "my Cost: 0x%x, num_low_neigh: 0x%x, N_LOW_NEIGH: 0x%x\n", 
-               getMetric(&(neigh_table[0])), num_low_neigh, N_LOW_NEIGH);
+    dbg("IPRouting", "my Cost: 0x%x\n", getMetric(&(neigh_table[0])));
    
     // If neighbor does not exist in table 
     if ((neigh_slot = getNeighEntry(neigh)) == NULL) {
index 47ecb0d53177f88c3511be9cab97cbf8c210c8c3..fa43a549e1655631d60db89e09c25230ed0ed086 100644 (file)
@@ -117,7 +117,7 @@ module UdpP {
       printfUART("rx cksum: %x calc: %x\n", rx_cksum, my_cksum);
       if (rx_cksum != my_cksum) {
         BLIP_STATS_INCR(cksum);
-        return;
+        // return;
       }
     }
 
index 873280abe7625d32d0ad73e862b8fd44ade96c86..e352ab151533f56430a68878f1620f96c2ff255f 100644 (file)
@@ -80,6 +80,8 @@ interface IPRouting {
 
   command struct ip6_route *insertRoutingHeader(struct split_ip_msg *msg);
   
+  command void reset();
+
 #ifdef CENTRALIZED_ROUTING
   // command error_t installFlowEntry(struct rinstall_header* rih, bool isMine);