Revision 92cc1e74

View differences:

proto/rip/config.Y
57 57
  init_list(&RIP_CFG->patt_list);
58 58
  RIP_CFG->rip2 = $2;
59 59
  RIP_CFG->infinity = RIP_DEFAULT_INFINITY;
60
  RIP_CFG->min_timeout_time = 60;
61
  RIP_CFG->max_garbage_time = 60;
60
  RIP_CFG->min_timeout_time = 60 S_;
61
  RIP_CFG->max_garbage_time = 60 S_;
62 62
};
63 63

  
64 64
rip_proto_item:
......
147 147
 | SPLIT HORIZON bool	{ RIP_IFACE->split_horizon = $3; }
148 148
 | POISON REVERSE bool	{ RIP_IFACE->poison_reverse = $3; }
149 149
 | CHECK ZERO bool	{ RIP_IFACE->check_zero = $3; }
150
 | UPDATE TIME expr	{ RIP_IFACE->update_time = $3; if ($3<=0) cf_error("Update time must be positive"); }
151
 | TIMEOUT TIME expr	{ RIP_IFACE->timeout_time = $3; if ($3<=0) cf_error("Timeout time must be positive"); }
152
 | GARBAGE TIME expr	{ RIP_IFACE->garbage_time = $3; if ($3<=0) cf_error("Garbage time must be positive"); }
150
 | UPDATE TIME expr	{ RIP_IFACE->update_time = (btime) $3 S_; if ($3<=0) cf_error("Update time must be positive"); }
151
 | TIMEOUT TIME expr	{ RIP_IFACE->timeout_time = (btime) $3 S_; if ($3<=0) cf_error("Timeout time must be positive"); }
152
 | GARBAGE TIME expr	{ RIP_IFACE->garbage_time = (btime) $3 S_; if ($3<=0) cf_error("Garbage time must be positive"); }
153 153
 | ECMP WEIGHT expr	{ RIP_IFACE->ecmp_weight = $3 - 1; if (($3<1) || ($3>256)) cf_error("ECMP weight must be in range 1-256"); }
154 154
 | RX BUFFER expr	{ RIP_IFACE->rx_buffer = $3; if (($3<256) || ($3>65535)) cf_error("RX length must be in range 256-65535"); }
155 155
 | TX LENGTH expr	{ RIP_IFACE->tx_length = $3; if (($3<256) || ($3>65535)) cf_error("TX length must be in range 256-65535"); }
proto/rip/packets.c
434 434
  byte *max = rip_tx_buffer(ifa) + ifa->tx_plen -
435 435
    (rip_is_v2(p) ? RIP_BLOCK_LENGTH : 2*RIP_BLOCK_LENGTH);
436 436
  ip_addr last_next_hop = IPA_NONE;
437
  btime now_ = current_time();
437 438
  int send = 0;
438 439

  
439 440
  struct rip_packet *pkt = (void *) pos;
......
450 451

  
451 452
    /* Stale entries that should be removed */
452 453
    if ((en->valid == RIP_ENTRY_STALE) &&
453
	((en->changed + (bird_clock_t) ifa->cf->garbage_time) <= now))
454
	((en->changed + ifa->cf->garbage_time) <= now_))
454 455
      goto next_entry;
455 456

  
456 457
    /* Triggered updates */
......
540 541
 * activating the new one.
541 542
 */
542 543
void
543
rip_send_table(struct rip_proto *p, struct rip_iface *ifa, ip_addr addr, bird_clock_t changed)
544
rip_send_table(struct rip_proto *p, struct rip_iface *ifa, ip_addr addr, btime changed)
544 545
{
545 546
  DBG("RIP: Opening TX session to %I on %s\n", addr, ifa->iface->name);
546 547

  
......
591 592

  
592 593
  byte *pos = (byte *) pkt + sizeof(struct rip_packet);
593 594
  byte *end = (byte *) pkt + plen;
595
  btime now_ = current_time();
594 596

  
595 597
  for (; pos < end; pos += RIP_BLOCK_LENGTH)
596 598
  {
......
638 640
	.next_hop = ipa_nonzero(rte.next_hop) ? rte.next_hop : from->nbr->addr,
639 641
	.metric = rte.metric,
640 642
	.tag = rte.tag,
641
	.expires = now + ifa->cf->timeout_time
643
	.expires = now_ + ifa->cf->timeout_time
642 644
      };
643 645

  
644 646
      rip_update_rte(p, &rte.net, &new);
......
705 707
  if ((plen - sizeof(struct rip_packet)) % RIP_BLOCK_LENGTH)
706 708
    DROP("invalid length", plen);
707 709

  
708
  n->last_seen = now;
710
  n->last_seen = current_time();
709 711
  rip_update_bfd(p, n);
710 712

  
711 713
  switch (pkt->command)
proto/rip/rip.c
364 364
  /* Activate triggered updates */
365 365
  if (en->metric != old_metric)
366 366
  {
367
    en->changed = now;
367
    en->changed = current_time();
368 368
    rip_trigger_update(p);
369 369
  }
370 370
}
......
506 506

  
507 507
  TRACE(D_EVENTS, "Starting interface %s", ifa->iface->name);
508 508

  
509
  ifa->next_regular = now + (random() % ifa->cf->update_time) + 1;
510
  ifa->next_triggered = now;	/* Available immediately */
511
  ifa->want_triggered = 1;	/* All routes in triggered update */
512
  tm_start(ifa->timer, 1);	/* Or 100 ms */
509
  ifa->next_regular = current_time() + (random() % ifa->cf->update_time) + 100 MS;
510
  ifa->next_triggered = current_time();	/* Available immediately */
511
  ifa->want_triggered = 1;		/* All routes in triggered update */
512
  tm2_start(ifa->timer, 100 MS);
513 513
  ifa->up = 1;
514 514

  
515 515
  if (!ifa->cf->passive)
......
529 529
  WALK_LIST_FIRST(n, ifa->neigh_list)
530 530
    rip_remove_neighbor(p, n);
531 531

  
532
  tm_stop(ifa->timer);
532
  tm2_stop(ifa->timer);
533 533
  ifa->up = 0;
534 534
}
535 535

  
......
642 642

  
643 643
  add_tail(&p->iface_list, NODE ifa);
644 644

  
645
  ifa->timer = tm_new_set(p->p.pool, rip_iface_timer, ifa, 0, 0);
645
  ifa->timer = tm2_new_init(p->p.pool, rip_iface_timer, ifa, 0, 0);
646 646

  
647 647
  struct object_lock *lock = olock_new(p->p.pool);
648 648
  lock->type = OBJLOCK_UDP;
......
690 690

  
691 691
  rip_iface_update_buffers(ifa);
692 692

  
693
  if (ifa->next_regular > (now + (bird_clock_t) new->update_time))
694
    ifa->next_regular = now + (random() % new->update_time) + 1;
693
  if (ifa->next_regular > (current_time() + new->update_time))
694
    ifa->next_regular = current_time() + (random() % new->update_time) + 100 MS;
695 695

  
696 696
  if (new->check_link != old->check_link)
697 697
    rip_iface_update_state(ifa);
......
816 816
  struct rip_iface *ifa;
817 817
  struct rip_neighbor *n, *nn;
818 818
  struct fib_iterator fit;
819
  bird_clock_t next = now + MIN(cf->min_timeout_time, cf->max_garbage_time);
820
  bird_clock_t expires = 0;
819
  btime now_ = current_time();
820
  btime next = now_ + MIN(cf->min_timeout_time, cf->max_garbage_time);
821
  btime expires = 0;
821 822

  
822 823
  TRACE(D_EVENTS, "Main timer fired");
823 824

  
......
832 833
    /* Checking received routes for timeout and for dead neighbors */
833 834
    for (rp = &en->routes; rt = *rp; /* rp = &rt->next */)
834 835
    {
835
      if (!rip_valid_rte(rt) || (rt->expires <= now))
836
      if (!rip_valid_rte(rt) || (rt->expires <= now_))
836 837
      {
837 838
	rip_remove_rte(p, rp);
838 839
	changed = 1;
......
862 863
    {
863 864
      expires = en->changed + cf->max_garbage_time;
864 865

  
865
      if (expires <= now)
866
      if (expires <= now_)
866 867
      {
867 868
	// TRACE(D_EVENTS, "entry is too old: %N", en->n.addr);
868 869
	en->valid = 0;
......
890 891
      {
891 892
	expires = n->last_seen + n->ifa->cf->timeout_time;
892 893

  
893
	if (expires <= now)
894
	if (expires <= now_)
894 895
	  rip_remove_neighbor(p, n);
895 896
	else
896 897
	  next = MIN(next, expires);
897 898
      }
898 899

  
899
  tm_start(p->timer, MAX(next - now, 1));
900
  tm2_start(p->timer, MAX(next - now_, 100 MS));
900 901
}
901 902

  
902 903
static inline void
903 904
rip_kick_timer(struct rip_proto *p)
904 905
{
905
  if (p->timer->expires TO_S > (now + 1))
906
    tm_start(p->timer, 1);	/* Or 100 ms */
906
  if (p->timer->expires > (current_time() + 100 MS))
907
    tm2_start(p->timer, 100 MS);
907 908
}
908 909

  
909 910
/**
......
921 922
{
922 923
  struct rip_iface *ifa = t->data;
923 924
  struct rip_proto *p = ifa->rip;
924
  bird_clock_t period = ifa->cf->update_time;
925
  btime now_ = current_time();
926
  btime period = ifa->cf->update_time;
925 927

  
926 928
  if (ifa->cf->passive)
927 929
    return;
......
930 932

  
931 933
  if (ifa->tx_active)
932 934
  {
933
    if (now < (ifa->next_regular + period))
934
      { tm_start(ifa->timer, 1); return; }
935
    if (now_ < (ifa->next_regular + period))
936
    { tm2_start(ifa->timer, 100 MS); return; }
935 937

  
936 938
    /* We are too late, reset is done by rip_send_table() */
937 939
    log(L_WARN "%s: Too slow update on %s, resetting", p->p.name, ifa->iface->name);
938 940
  }
939 941

  
940
  if (now >= ifa->next_regular)
942
  if (now_ >= ifa->next_regular)
941 943
  {
942 944
    /* Send regular update, set timer for next period (or following one if necessay) */
943 945
    TRACE(D_EVENTS, "Sending regular updates for %s", ifa->iface->name);
944 946
    rip_send_table(p, ifa, ifa->addr, 0);
945
    ifa->next_regular += period * (1 + ((now - ifa->next_regular) / period));
947
    ifa->next_regular += period * (1 + ((now_ - ifa->next_regular) / period));
946 948
    ifa->want_triggered = 0;
947 949
    p->triggered = 0;
948 950
  }
949
  else if (ifa->want_triggered && (now >= ifa->next_triggered))
951
  else if (ifa->want_triggered && (now_ >= ifa->next_triggered))
950 952
  {
951 953
    /* Send triggered update, enforce interval between triggered updates */
952 954
    TRACE(D_EVENTS, "Sending triggered updates for %s", ifa->iface->name);
953 955
    rip_send_table(p, ifa, ifa->addr, ifa->want_triggered);
954
    ifa->next_triggered = now + MIN(5, period / 2 + 1);
956
    ifa->next_triggered = now_ + MIN(5 S, period / 2);
955 957
    ifa->want_triggered = 0;
956 958
    p->triggered = 0;
957 959
  }
958 960

  
959
  tm_start(ifa->timer, ifa->want_triggered ? 1 : (ifa->next_regular - now));
961
  tm2_start(ifa->timer, ifa->want_triggered ? (1 S) : (ifa->next_regular - now_));
960 962
}
961 963

  
962 964
static inline void
963 965
rip_iface_kick_timer(struct rip_iface *ifa)
964 966
{
965
  if (ifa->timer->expires TO_S > (now + 1))
966
    tm_start(ifa->timer, 1);	/* Or 100 ms */
967
  if (ifa->timer->expires > (current_time() + 100 MS))
968
    tm2_start(ifa->timer, 100 MS);
967 969
}
968 970

  
969 971
static void
......
984 986
      continue;
985 987

  
986 988
    TRACE(D_EVENTS, "Scheduling triggered updates for %s", ifa->iface->name);
987
    ifa->want_triggered = now;
989
    ifa->want_triggered = current_time();
988 990
    rip_iface_kick_timer(ifa);
989 991
  }
990 992

  
......
1109 1111
  fib_init(&p->rtable, P->pool, cf->rip2 ? NET_IP4 : NET_IP6,
1110 1112
	   sizeof(struct rip_entry), OFFSETOF(struct rip_entry, n), 0, NULL);
1111 1113
  p->rte_slab = sl_new(P->pool, sizeof(struct rip_rte));
1112
  p->timer = tm_new_set(P->pool, rip_timer, p, 0, 0);
1114
  p->timer = tm2_new_init(P->pool, rip_timer, p, 0, 0);
1113 1115

  
1114 1116
  p->rip2 = cf->rip2;
1115 1117
  p->ecmp = cf->ecmp;
......
1119 1121
  p->log_pkt_tbf = (struct tbf){ .rate = 1, .burst = 5 };
1120 1122
  p->log_rte_tbf = (struct tbf){ .rate = 4, .burst = 20 };
1121 1123

  
1122
  tm_start(p->timer, MIN(cf->min_timeout_time, cf->max_garbage_time));
1124
  tm2_start(p->timer, MIN(cf->min_timeout_time, cf->max_garbage_time));
1123 1125

  
1124 1126
  return PS_UP;
1125 1127
}
......
1194 1196
  }
1195 1197

  
1196 1198
  cli_msg(-1021, "%s:", p->p.name);
1197
  cli_msg(-1021, "%-10s %-6s %6s %6s %6s",
1199
  cli_msg(-1021, "%-10s %-6s %6s %6s %7s",
1198 1200
	  "Interface", "State", "Metric", "Nbrs", "Timer");
1199 1201

  
1200 1202
  WALK_LIST(ifa, p->iface_list)
......
1207 1209
      if (n->last_seen)
1208 1210
	nbrs++;
1209 1211

  
1210
    int timer = MAX(ifa->next_regular - now, 0);
1211
    cli_msg(-1021, "%-10s %-6s %6u %6u %6u",
1212
    btime now_ = current_time();
1213
    btime timer = (ifa->next_regular > now_) ? (ifa->next_regular - now_) : 0;
1214
    cli_msg(-1021, "%-10s %-6s %6u %6u %7t",
1212 1215
	    ifa->iface->name, (ifa->up ? "Up" : "Down"), ifa->cf->metric, nbrs, timer);
1213 1216
  }
1214 1217

  
......
1230 1233
  }
1231 1234

  
1232 1235
  cli_msg(-1022, "%s:", p->p.name);
1233
  cli_msg(-1022, "%-25s %-10s %6s %6s %6s",
1236
  cli_msg(-1022, "%-25s %-10s %6s %6s %7s",
1234 1237
	  "IP address", "Interface", "Metric", "Routes", "Seen");
1235 1238

  
1236 1239
  WALK_LIST(ifa, p->iface_list)
......
1243 1246
      if (!n->last_seen)
1244 1247
	continue;
1245 1248

  
1246
      int timer = now - n->last_seen;
1247
      cli_msg(-1022, "%-25I %-10s %6u %6u %6u",
1249
      btime timer = current_time() - n->last_seen;
1250
      cli_msg(-1022, "%-25I %-10s %6u %6u %7t",
1248 1251
	      n->nbr->addr, ifa->iface->name, ifa->cf->metric, n->uc, timer);
1249 1252
    }
1250 1253
  }
......
1262 1265
  i = 0;
1263 1266
  FIB_WALK(&p->rtable, struct rip_entry, en)
1264 1267
  {
1265
    debug("RIP: entry #%d: %N via %I dev %s valid %d metric %d age %d s\n",
1268
    debug("RIP: entry #%d: %N via %I dev %s valid %d metric %d age %t\n",
1266 1269
	  i++, en->n.addr, en->next_hop, en->iface->name,
1267
	  en->valid, en->metric, now - en->changed);
1270
	  en->valid, en->metric, current_time() - en->changed);
1268 1271
  }
1269 1272
  FIB_WALK_END;
1270 1273

  
proto/rip/rip.h
38 38

  
39 39
#define RIP_DEFAULT_ECMP_LIMIT	16
40 40
#define RIP_DEFAULT_INFINITY	16
41
#define RIP_DEFAULT_UPDATE_TIME	30
42
#define RIP_DEFAULT_TIMEOUT_TIME 180
43
#define RIP_DEFAULT_GARBAGE_TIME 120
41
#define RIP_DEFAULT_UPDATE_TIME	  (30 S_)
42
#define RIP_DEFAULT_TIMEOUT_TIME (180 S_)
43
#define RIP_DEFAULT_GARBAGE_TIME (120 S_)
44 44

  
45 45

  
46 46
struct rip_config
......
52 52
  u8 ecmp;				/* Maximum number of nexthops in ECMP route, or 0 */
53 53
  u8 infinity;				/* Maximum metric value, representing infinity */
54 54

  
55
  u32 min_timeout_time;			/* Minimum of interface timeout_time */
56
  u32 max_garbage_time;			/* Maximum of interface garbage_time */
55
  btime min_timeout_time;		/* Minimum of interface timeout_time */
56
  btime max_garbage_time;		/* Maximum of interface garbage_time */
57 57
};
58 58

  
59 59
struct rip_iface_config
......
78 78
  u16 tx_length;			/* TX packet length limit (including headers), 0 for MTU */
79 79
  int tx_tos;
80 80
  int tx_priority;
81
  u32 update_time;			/* Periodic update interval */
82
  u32 timeout_time;			/* Route expiration timeout */
83
  u32 garbage_time;			/* Unreachable entry GC timeout */
81
  btime update_time;			/* Periodic update interval */
82
  btime timeout_time;			/* Route expiration timeout */
83
  btime garbage_time;			/* Unreachable entry GC timeout */
84 84
  list *passwords;			/* Passwords for authentication */
85 85
};
86 86

  
......
120 120
  list neigh_list;			/* List of iface neighbors (struct rip_neighbor) */
121 121

  
122 122
  /* Update scheduling */
123
  bird_clock_t next_regular;		/* Next time when regular update should be called */
124
  bird_clock_t next_triggered;		/* Next time when triggerd update may be called */
125
  bird_clock_t want_triggered;		/* Nonzero if triggered update is scheduled */
123
  btime next_regular;			/* Next time when regular update should be called */
124
  btime next_triggered;			/* Next time when triggerd update may be called */
125
  btime want_triggered;			/* Nonzero if triggered update is scheduled */
126 126

  
127 127
  /* Active update */
128 128
  int tx_active;			/* Update session is active */
129 129
  ip_addr tx_addr;			/* Update session destination address */
130
  bird_clock_t tx_changed;		/* Minimal changed time for triggered update */
130
  btime tx_changed;			/* Minimal changed time for triggered update */
131 131
  struct fib_iterator tx_fit;		/* FIB iterator in RIP routing table (p.rtable) */
132 132
};
133 133

  
......
137 137
  struct rip_iface *ifa;		/* Associated interface, may be NULL if stale */
138 138
  struct neighbor *nbr;			/* Associaded core neighbor, may be NULL if stale */
139 139
  struct bfd_request *bfd_req;		/* BFD request, if BFD is used */
140
  bird_clock_t last_seen;		/* Time of last received and accepted message */
140
  btime last_seen;			/* Time of last received and accepted message */
141 141
  u32 uc;				/* Use count, number of routes linking the neighbor */
142 142
  u32 csn;				/* Last received crypto sequence number */
143 143
};
......
153 153
  struct iface *iface;			/* Outgoing route iface (for next hop) */
154 154
  ip_addr next_hop;			/* Outgoing route next hop */
155 155

  
156
  bird_clock_t changed;			/* Last time when the outgoing route metric changed */
156
  btime changed;			/* Last time when the outgoing route metric changed */
157 157

  
158 158
  struct fib_node n;
159 159
};
......
167 167
  u16 metric;				/* Route metric (after increase) */
168 168
  u16 tag;				/* Route tag */
169 169

  
170
  bird_clock_t expires;			/* Time of route expiration */
170
  btime expires;			/* Time of route expiration */
171 171
};
172 172

  
173 173

  
......
211 211

  
212 212
/* packets.c */
213 213
void rip_send_request(struct rip_proto *p, struct rip_iface *ifa);
214
void rip_send_table(struct rip_proto *p, struct rip_iface *ifa, ip_addr addr, bird_clock_t changed);
214
void rip_send_table(struct rip_proto *p, struct rip_iface *ifa, ip_addr addr, btime changed);
215 215
int rip_open_socket(struct rip_iface *ifa);
216 216

  
217 217

  

Also available in: Unified diff