Revision 92cc1e74 proto/rip/rip.c

View differences:

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

  

Also available in: Unified diff