Move TC/MID/HNA timings to global section (windows version is untested !)
authorHenning Rogge <hrogge@googlemail.com>
Sat, 8 Aug 2009 14:12:59 +0000 (16:12 +0200)
committerHenning Rogge <hrogge@googlemail.com>
Sat, 8 Aug 2009 14:12:59 +0000 (16:12 +0200)
src/build_msg.c
src/interfaces.c
src/interfaces.h
src/lq_packet.c
src/olsr_cfg.c
src/olsr_cfg.h
src/olsr_cfg_gen.c
src/unix/ifnet.c
src/win32/ifnet.c

index 69c1f86..7bb885a 100644 (file)
@@ -182,7 +182,7 @@ serialize_mid4(struct interface *ifp)
   /* Set main(first) address */
   m->v4.originator = olsr_cnf->router_id.v4.s_addr;
   m->v4.olsr_msgtype = MID_MESSAGE;
-  m->v4.olsr_vtime = ifp->valtimes.mid;
+  m->v4.olsr_vtime = reltime_to_me(olsr_cnf->mid_params.validity_time);
 
   addrs = m->v4.message.mid.mid_addr;
 
@@ -267,7 +267,8 @@ serialize_mid6(struct interface *ifp)
   m->v6.hopcnt = 0;
   m->v6.ttl = MAX_TTL;
   m->v6.olsr_msgtype = MID_MESSAGE;
-  m->v6.olsr_vtime = ifp->valtimes.mid;
+  m->v6.olsr_vtime = reltime_to_me(olsr_cnf->mid_params.validity_time);
+
   /* Set main(first) address */
   m->v6.originator = olsr_cnf->router_id.v6;
 
@@ -360,7 +361,7 @@ serialize_hna4(struct interface *ifp)
   m->v4.hopcnt = 0;
   m->v4.ttl = MAX_TTL;
   m->v4.olsr_msgtype = HNA_MESSAGE;
-  m->v4.olsr_vtime = ifp->valtimes.hna;
+  m->v4.olsr_vtime = reltime_to_me(olsr_cnf->hna_params.validity_time);
 
 
   pair = m->v4.message.hna.hna_net;
@@ -441,7 +442,7 @@ serialize_hna6(struct interface *ifp)
   m->v6.hopcnt = 0;
   m->v6.ttl = MAX_TTL;
   m->v6.olsr_msgtype = HNA_MESSAGE;
-  m->v6.olsr_vtime = ifp->valtimes.hna;
+  m->v6.olsr_vtime = reltime_to_me(olsr_cnf->hna_params.validity_time);
 
   pair6 = m->v6.message.hna.hna_net;
 
index 1a5cefd..a3cf37f 100644 (file)
@@ -277,7 +277,7 @@ remove_interface(struct interface **pinterf)
   /*
    * remember the IP for some time
    */
-  add_lost_interface_ip(&ifp->ip_addr, me_to_reltime(ifp->valtimes.hello));
+  add_lost_interface_ip(&ifp->ip_addr, me_to_reltime(ifp->hello_valtime));
 
   /*
    * Unlink from config.
index 3a1cd76..075d4cc 100644 (file)
@@ -105,13 +105,6 @@ struct if_gen_property {
 };
 #endif
 
-struct vtimes {
-  uint8_t hello;
-  uint8_t tc;
-  uint8_t mid;
-  uint8_t hna;
-};
-
 /*
  * Output buffer structure. This should actually be in net_olsr.h
  * but we have circular references then.
@@ -173,7 +166,7 @@ struct interface {
 #endif
 
   uint32_t hello_etime;
-  struct vtimes valtimes;
+  uint8_t hello_valtime;
 #if 0
   struct if_gen_property *gen_properties;       /* Generic interface properties */
 #endif
index 5352c94..fe7b9ff 100644 (file)
@@ -78,7 +78,7 @@ create_lq_hello(struct lq_hello_message *lq_hello, struct interface *outif)
   // initialize the static fields
 
   lq_hello->comm.type = olsr_get_Hello_MessageId();
-  lq_hello->comm.vtime = me_to_reltime(outif->valtimes.hello);
+  lq_hello->comm.vtime = me_to_reltime(outif->hello_valtime);
   lq_hello->comm.size = 0;
 
   lq_hello->comm.orig = olsr_cnf->router_id;
@@ -164,7 +164,7 @@ create_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
   // initialize the static fields
 
   lq_tc->comm.type = olsr_get_TC_MessageId();
-  lq_tc->comm.vtime = me_to_reltime(outif->valtimes.tc);
+  lq_tc->comm.vtime = me_to_reltime(olsr_cnf->tc_params.validity_time);
   lq_tc->comm.size = 0;
 
   lq_tc->comm.orig = olsr_cnf->router_id;
index 01520b1..a8447cd 100644 (file)
@@ -83,7 +83,14 @@ enum cfg_long_options {
   CFG_HTTPPORT,
   CFG_HTTPLIMIT,
   CFG_TXTPORT,
-  CFG_TXTLIMIT
+  CFG_TXTLIMIT,
+
+  CFG_HNA_HTIME,
+  CFG_HNA_VTIME,
+  CFG_MID_HTIME,
+  CFG_MID_VTIME,
+  CFG_TC_HTIME,
+  CFG_TC_VTIME,
 };
 
 /* remember which log severities have been explicitly set */
@@ -302,12 +309,6 @@ olsr_get_default_if_options(void)
   /* new_io->weight.value = 0; */
   new_io->hello_params.emission_interval = HELLO_INTERVAL;
   new_io->hello_params.validity_time = NEIGHB_HOLD_TIME;
-  new_io->tc_params.emission_interval = TC_INTERVAL;
-  new_io->tc_params.validity_time = TOP_HOLD_TIME;
-  new_io->mid_params.emission_interval = MID_INTERVAL;
-  new_io->mid_params.validity_time = MID_HOLD_TIME;
-  new_io->hna_params.emission_interval = HNA_INTERVAL;
-  new_io->hna_params.validity_time = HNA_HOLD_TIME;
   /* new_io->lq_mult = NULL; */
   new_io->autodetect_chg = true;
   new_io->mode = IF_MODE_MESH;
@@ -507,23 +508,17 @@ parse_cfg_interface(char *argstr, struct olsr_config *rcfg, char *rmsg)
             new_if->cnf->hello_params.validity_time = olsr_txt_to_milli(p_next[1]);
             PARSER_DEBUG_PRINTF("\tHELLO validity: %u ms\n", new_if->cnf->hello_params.validity_time);
           } else if (0 == strcasecmp("Tcinterval", p_next[0])) {
-            new_if->cnf->tc_params.emission_interval = olsr_txt_to_milli(p_next[1]);
-            PARSER_DEBUG_PRINTF("\tTC interval1: %u ms\n", new_if->cnf->tc_params.emission_interval);
+            PARSER_DEBUG_PRINTF("\tIgnore TC interval1: %s ms in interface\n", p_next[1]);
           } else if (0 == strcasecmp("TcValidityTime", p_next[0])) {
-            new_if->cnf->tc_params.validity_time = olsr_txt_to_milli(p_next[1]);
-            PARSER_DEBUG_PRINTF("\tTC validity: %u ms\n", new_if->cnf->tc_params.validity_time);
+            PARSER_DEBUG_PRINTF("\tIgnore TC validity: %s ms in interface\n", p_next[1]);
           } else if (0 == strcasecmp("Midinterval", p_next[0])) {
-            new_if->cnf->mid_params.emission_interval = olsr_txt_to_milli(p_next[1]);
-            PARSER_DEBUG_PRINTF("\tMID interval1: %u ms\n", new_if->cnf->mid_params.emission_interval);
+            PARSER_DEBUG_PRINTF("\tIgnore MID interval1: %s ms in interface\n", p_next[1]);
           } else if (0 == strcasecmp("MidValidityTime", p_next[0])) {
-            new_if->cnf->mid_params.validity_time = olsr_txt_to_milli(p_next[1]);
-            PARSER_DEBUG_PRINTF("\tMID validity: %u ms\n", new_if->cnf->mid_params.validity_time);
+            PARSER_DEBUG_PRINTF("\ttIgnore MID validity: %s ms in interface\n", p_next[1]);
           } else if (0 == strcasecmp("Hnainterval", p_next[0])) {
-            new_if->cnf->hna_params.emission_interval = olsr_txt_to_milli(p_next[1]);
-            PARSER_DEBUG_PRINTF("\tHNA interval1: %u ms\n", new_if->cnf->hna_params.emission_interval);
+            PARSER_DEBUG_PRINTF("\ttIgnore HNA interval1: %s ms in interface\n", p_next[1]);
           } else if (0 == strcasecmp("HnaValidityTime", p_next[0])) {
-            new_if->cnf->hna_params.validity_time = olsr_txt_to_milli(p_next[1]);
-            PARSER_DEBUG_PRINTF("\tHNA validity: %u ms\n", new_if->cnf->hna_params.validity_time);
+            PARSER_DEBUG_PRINTF("\ttIgnore HNA validity: %s ms in interface\n", p_next[1]);
           } else if (0 == strcasecmp("Weight", p_next[0])) {
             new_if->cnf->weight.fixed = true;
             PARSER_DEBUG_PRINTF("\tFixed willingness: %d\n", new_if->cnf->weight.value);
@@ -1107,6 +1102,31 @@ parse_cfg_option(const int optint, char *argstr, const int line, struct olsr_con
       PARSER_DEBUG_PRINTF("TXT connection limit: %d\n", rcfg->comport_txt_limit);
     }
     break;
+  case CFG_HNA_HTIME:
+    rcfg->hna_params.emission_interval = olsr_txt_to_milli(argstr);
+    PARSER_DEBUG_PRINTF("\tHNA interval1: %u ms\n", rcfg->hna_params.emission_interval);
+    break;
+  case CFG_HNA_VTIME:
+    rcfg->hna_params.validity_time = olsr_txt_to_milli(argstr);
+    PARSER_DEBUG_PRINTF("\tHNA validity: %u ms\n", rcfg->hna_params.validity_time);
+    break;
+  case CFG_MID_HTIME:
+    rcfg->mid_params.emission_interval = olsr_txt_to_milli(argstr);
+    PARSER_DEBUG_PRINTF("\tMID interval1: %u ms\n", rcfg->mid_params.emission_interval);
+    break;
+  case CFG_MID_VTIME:
+    rcfg->mid_params.validity_time = olsr_txt_to_milli(argstr);
+    PARSER_DEBUG_PRINTF("\tMID validity: %u ms\n", rcfg->mid_params.validity_time);
+    break;
+  case CFG_TC_HTIME:
+    rcfg->tc_params.emission_interval = olsr_txt_to_milli(argstr);
+    PARSER_DEBUG_PRINTF("\tTC interval1: %u ms\n", rcfg->tc_params.emission_interval);
+    break;
+  case CFG_TC_VTIME:
+    rcfg->tc_params.validity_time = olsr_txt_to_milli(argstr);
+    PARSER_DEBUG_PRINTF("\tTC validity: %u ms\n", rcfg->tc_params.validity_time);
+    break;
+
   default:
     sprintf(rmsg, "Unknown arg in line %d.\n", line);
     return CFG_ERROR;
@@ -1215,6 +1235,12 @@ olsr_parse_cfg(int argc, char *argv[], const char *file, char *rmsg, struct olsr
     {"HttpLimit",                required_argument, 0, CFG_HTTPLIMIT}, /* (i) */
     {"TxtPort",                  required_argument, 0, CFG_TXTPORT},   /* (i) */
     {"TxtLimit",                 required_argument, 0, CFG_TXTLIMIT},  /* (i) */
+    {"TcInterval",               required_argument, 0, CFG_TC_HTIME},  /* (f) */
+    {"TcValidityTime",           required_argument, 0, CFG_TC_VTIME},  /* (f) */
+    {"MidInterval",              required_argument, 0, CFG_MID_HTIME},  /* (f) */
+    {"MidValidityTime",          required_argument, 0, CFG_MID_VTIME},  /* (f) */
+    {"HnaInterval",              required_argument, 0, CFG_HNA_HTIME},  /* (f) */
+    {"HnaValidityTime",          required_argument, 0, CFG_HNA_VTIME},  /* (f) */
 
     {"IpcConnect",               required_argument, 0,  0 }, /* ignored */
     {"UseHysteresis",            required_argument, 0,  0 }, /* ignored */
@@ -1470,6 +1496,33 @@ olsr_sanity_check_cfg(struct olsr_config *cfg)
     return -1;
   }
 
+  /* TC interval */
+  if (cfg->tc_params.emission_interval < cfg->pollrate ||
+      cfg->tc_params.emission_interval > cfg->tc_params.validity_time) {
+    fprintf(stderr, "Bad TC parameters! (em: %u ms, vt: %u ms)\n",
+        cfg->tc_params.emission_interval,
+        cfg->tc_params.validity_time);
+    return -1;
+  }
+
+  /* MID interval */
+  if (cfg->mid_params.emission_interval < cfg->pollrate ||
+      cfg->mid_params.emission_interval > cfg->mid_params.validity_time) {
+    fprintf(stderr, "Bad MID parameters! (em: %u ms, vt: %u ms)\n",
+        cfg->mid_params.emission_interval,
+        cfg->mid_params.validity_time);
+    return -1;
+  }
+
+  /* HNA interval */
+  if (cfg->hna_params.emission_interval < cfg->pollrate ||
+      cfg->hna_params.emission_interval > cfg->hna_params.validity_time) {
+    fprintf(stderr, "Bad HNA parameters! (em: %u ms, vt: %u ms)\n",
+        cfg->hna_params.emission_interval,
+        cfg->hna_params.validity_time);
+    return -1;
+  }
+
   if (in == NULL) {
     fprintf(stderr, "No interfaces configured!\n");
     return -1;
@@ -1498,34 +1551,6 @@ olsr_sanity_check_cfg(struct olsr_config *cfg)
           io->hello_params.validity_time);
       return -1;
     }
-
-    /* TC interval */
-    if (io->tc_params.emission_interval < cfg->pollrate ||
-        io->tc_params.emission_interval > io->tc_params.validity_time) {
-      fprintf(stderr, "Bad TC parameters! (em: %u ms, vt: %u ms)\n",
-          io->tc_params.emission_interval,
-          io->tc_params.validity_time);
-      return -1;
-    }
-
-    /* MID interval */
-    if (io->mid_params.emission_interval < cfg->pollrate ||
-        io->mid_params.emission_interval > io->mid_params.validity_time) {
-      fprintf(stderr, "Bad MID parameters! (em: %u ms, vt: %u ms)\n",
-          io->mid_params.emission_interval,
-          io->mid_params.validity_time);
-      return -1;
-    }
-
-    /* HNA interval */
-    if (io->hna_params.emission_interval < cfg->pollrate ||
-        io->hna_params.emission_interval > io->hna_params.validity_time) {
-      fprintf(stderr, "Bad HNA parameters! (em: %u ms, vt: %u ms)\n",
-          io->hna_params.emission_interval,
-          io->hna_params.validity_time);
-      return -1;
-    }
-
     in = in->next;
   }
 
@@ -1661,6 +1686,14 @@ olsr_get_default_cfg(void)
   cfg->comport_txt        = DEF_TXTPORT;
   cfg->comport_txt_limit  = DEF_TXTLIMIT;
 
+
+  cfg->tc_params.emission_interval = TC_INTERVAL;
+  cfg->tc_params.validity_time = TOP_HOLD_TIME;
+  cfg->mid_params.emission_interval = MID_INTERVAL;
+  cfg->mid_params.validity_time = MID_HOLD_TIME;
+  cfg->hna_params.emission_interval = HNA_INTERVAL;
+  cfg->hna_params.validity_time = HNA_HOLD_TIME;
+
   assert(0 == memcmp(&all_zero, &cfg->router_id, sizeof(cfg->router_id)));
   assert(0 == cfg->source_ip_mode);
   cfg->will_int = 10 * HELLO_INTERVAL;
index 5e70af8..cf84bdf 100644 (file)
@@ -133,9 +133,6 @@ struct olsr_if_options {
   union olsr_ip_addr ipv6_multi_glbl;
   struct olsr_if_weight weight;
   struct olsr_msg_params hello_params;
-  struct olsr_msg_params tc_params;
-  struct olsr_msg_params mid_params;
-  struct olsr_msg_params hna_params;
   struct olsr_lq_mult *lq_mult;
   bool autodetect_chg;
   enum interface_mode mode;
@@ -218,6 +215,10 @@ struct olsr_config {
   uint16_t comport_txt;                /* communication port for txt connections */
   uint16_t comport_txt_limit;          /* maximum number of interactive connections */
 
+  struct olsr_msg_params tc_params;
+  struct olsr_msg_params mid_params;
+  struct olsr_msg_params hna_params;
+
   /*
    * Someone has added global variables to the config struct.
    * Because this saves binary link info we keep it that way.
index fd34aff..486d3c2 100644 (file)
@@ -183,6 +183,15 @@ olsr_write_cnf_buf(struct autobuf *abuf, struct olsr_config *cnf, bool write_mor
   }
   abuf_appendf(abuf, "\n");
 
+  append_reltime(abuf, "TcInterval", cnf->tc_params.emission_interval, TC_INTERVAL, true);
+  append_reltime(abuf, "TcValidityTime", cnf->tc_params.validity_time, TOP_HOLD_TIME, true);
+  append_reltime(abuf, "MidInterval", cnf->mid_params.emission_interval, MID_INTERVAL, true);
+  append_reltime(abuf, "MidValidityTime", cnf->mid_params.validity_time, MID_HOLD_TIME, true);
+  append_reltime(abuf, "HnaInterval", cnf->hna_params.emission_interval, HNA_INTERVAL, true);
+  append_reltime(abuf, "HnaValidityTime", cnf->hna_params.validity_time, HNA_HOLD_TIME, true);
+
+  abuf_puts(abuf, "\n");
+
   /* Interfaces */
   abuf_appendf(abuf, "# Interfaces\n"
                "# Multiple interfaces with the same configuration\n"
@@ -246,11 +255,6 @@ olsr_write_cnf_buf(struct autobuf *abuf, struct olsr_config *cnf, bool write_mor
       }
       append_reltime(abuf, "HelloInterval", in->cnf->hello_params.emission_interval, HELLO_INTERVAL, first);
       append_reltime(abuf, "HelloValidityTime", in->cnf->hello_params.validity_time, NEIGHB_HOLD_TIME, first);
-      append_reltime(abuf, "TcInterval", in->cnf->tc_params.emission_interval, TC_INTERVAL, first);
-      append_reltime(abuf, "TcValidityTime", in->cnf->tc_params.validity_time, TOP_HOLD_TIME, first);
-      append_reltime(abuf, "MidValidityTime", in->cnf->mid_params.validity_time, MID_HOLD_TIME, first);
-      append_reltime(abuf, "HnaInterval", in->cnf->hna_params.emission_interval, HNA_INTERVAL, first);
-      append_reltime(abuf, "HnaValidityTime", in->cnf->hna_params.validity_time, HNA_HOLD_TIME, first);
       if (in->cnf->lq_mult == NULL) {
         if (first) {
           abuf_appendf(abuf, "    #LinkQualityMult\tdefault 1.0\n");
index 18b6cdb..c1c5000 100644 (file)
@@ -525,7 +525,7 @@ chk_if_up(struct olsr_if_config *iface)
    */
   ifp->int_name = olsr_strdup(ifr_basename);
 
-  ifp->immediate_send_tc = iface->cnf->tc_params.emission_interval < iface->cnf->hello_params.emission_interval;
+  ifp->immediate_send_tc = olsr_cnf->tc_params.emission_interval < iface->cnf->hello_params.emission_interval;
 #if 0
   ifp->gen_properties = NULL;
 #endif
@@ -593,20 +593,17 @@ chk_if_up(struct olsr_if_config *iface)
     olsr_start_timer(iface->cnf->hello_params.emission_interval,
                      HELLO_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_hello, ifp, hello_gen_timer_cookie);
   ifp->tc_gen_timer =
-    olsr_start_timer(iface->cnf->tc_params.emission_interval,
+    olsr_start_timer(olsr_cnf->tc_params.emission_interval,
                      TC_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_tc, ifp, tc_gen_timer_cookie);
   ifp->mid_gen_timer =
-    olsr_start_timer(iface->cnf->mid_params.emission_interval,
+    olsr_start_timer(olsr_cnf->mid_params.emission_interval,
                      MID_JITTER, OLSR_TIMER_PERIODIC, &generate_mid, ifp, mid_gen_timer_cookie);
   ifp->hna_gen_timer =
-    olsr_start_timer(iface->cnf->hna_params.emission_interval,
+    olsr_start_timer(olsr_cnf->hna_params.emission_interval,
                      HNA_JITTER, OLSR_TIMER_PERIODIC, &generate_hna, ifp, hna_gen_timer_cookie);
 
   ifp->hello_etime = iface->cnf->hello_params.emission_interval;
-  ifp->valtimes.hello = reltime_to_me(iface->cnf->hello_params.validity_time);
-  ifp->valtimes.tc = reltime_to_me(iface->cnf->tc_params.validity_time);
-  ifp->valtimes.mid = reltime_to_me(iface->cnf->mid_params.validity_time);
-  ifp->valtimes.hna = reltime_to_me(iface->cnf->hna_params.validity_time);
+  ifp->hello_valtime = reltime_to_me(iface->cnf->hello_params.validity_time);
 
   ifp->mode = iface->cnf->mode;
 
index cf7963d..152b8d1 100644 (file)
@@ -644,7 +644,7 @@ chk_if_up(struct olsr_if_config *IntConf)
 
   New = olsr_cookie_malloc(interface_mem_cookie);
 
-  New->immediate_send_tc = (IntConf->cnf->tc_params.emission_interval < IntConf->cnf->hello_params.emission_interval);
+  New->immediate_send_tc = (olsr_cnf->tc_params.emission_interval < IntConf->cnf->hello_params.emission_interval);
 #if 0
   New->gen_properties = NULL;
 #endif
@@ -741,20 +741,17 @@ chk_if_up(struct olsr_if_config *IntConf)
     olsr_start_timer(IntConf->cnf->hello_params.emission_interval,
                      HELLO_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_hello, New, hello_gen_timer_cookie->ci_id);
   New->tc_gen_timer =
-    olsr_start_timer(IntConf->cnf->tc_params.emission_interval,
+    olsr_start_timer(olsr_cnf->tc_params.emission_interval,
                      TC_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_tc, New, tc_gen_timer_cookie->ci_id);
   New->mid_gen_timer =
-    olsr_start_timer(IntConf->cnf->mid_params.emission_interval,
+    olsr_start_timer(olsr_cnf->mid_params.emission_interval,
                      MID_JITTER, OLSR_TIMER_PERIODIC, &generate_mid, New, mid_gen_timer_cookie->ci_id);
   New->hna_gen_timer =
-    olsr_start_timer(IntConf->cnf->hna_params.emission_interval,
+    olsr_start_timer(olsr_cnf->hna_params.emission_interval,
                      HNA_JITTER, OLSR_TIMER_PERIODIC, &generate_hna, New, hna_gen_timer_cookie->ci_id);
 
   New->hello_etime = (uint32_t) (IntConf->cnf->hello_params.emission_interval);
-  New->valtimes.hello = reltime_to_me(IntConf->cnf->hello_params.validity_time);
-  New->valtimes.tc = reltime_to_me(IntConf->cnf->tc_params.validity_time);
-  New->valtimes.mid = reltime_to_me(IntConf->cnf->mid_params.validity_time);
-  New->valtimes.hna = reltime_to_me(IntConf->cnf->hna_params.validity_time);
+  New->hello_valtime = reltime_to_me(IntConf->cnf->hello_params.validity_time);
 
   New->mode = IntConf->cnf->mode;