예제 #1
0
void print_rt_table()
{
    char rt_buf[512], ifname[64];
    int len = 0;
    int i = 0;
    rt_table_t *entry;
    precursor_t *pr;
    struct timeval now;
    struct tm *time;

    gettimeofday(&now, NULL);
    time = localtime(&now.tv_sec);

    len +=
	sprintf(rt_buf, "# Time: %02d:%02d:%02d.%03ld IP: %s seqno: %u\n",
		time->tm_hour, time->tm_min, time->tm_sec,
		now.tv_usec / 1000, devs_ip_to_str(),
		this_host.seqno);
    len +=
	sprintf(rt_buf + len,
		"%-15s %-15s %-3s %-3s %-5s %-6s %-5s %-5s %-15s\n",
		"Destination", "Next hop", "HC", "LHC", "Seqno", "Expire",
		"Flags", "Iface", "Precursors");
    write(log_rt_fd, rt_buf, len);
    len = 0;

    for (i = 0; i < RT_TABLESIZE; i++) {
	entry = routing_table[i];
	while (entry != NULL) {
	    /* Printe routing table entries one by one... */
	    if (entry->precursors == NULL)
		len +=
		    sprintf(rt_buf + len,
			    "%-15s %-15s %-3d %-3d %-5u %-6ld %-5s %-5s\n",
			    ip_to_str(entry->dest_addr),
			    ip_to_str(entry->next_hop), entry->hcnt,
			    entry->last_hcnt, entry->dest_seqno,
			    ((entry->hcnt ==
			      255) ? 0 : timeval_diff(&entry->rt_timer.
						      timeout,
						      &now)) / 1000,
			    rt_flags_to_str(entry->flags), 
			    if_indextoname(entry->ifindex, ifname));
	    else {
		len +=
		    sprintf(rt_buf + len,
			    "%-15s %-15s %-3d %-3d %-5u %-6ld %-5s %-5s %-15s\n",
			    ip_to_str(entry->dest_addr),
			    ip_to_str(entry->next_hop), entry->hcnt,
			    entry->last_hcnt, entry->dest_seqno,
			    timeval_diff(&entry->rt_timer.timeout,
					 &now) / 1000,
			    rt_flags_to_str(entry->flags), 
			    if_indextoname(entry->ifindex, ifname),
			    ip_to_str(entry->precursors->neighbor));

		/* Print all precursors for the current routing entry */
		for (pr = entry->precursors->next; (pr != NULL);
		     pr = pr->next)
		    len +=
			sprintf(rt_buf + len, "%65s %-15s\n", "*",
				ip_to_str(pr->neighbor));
	    }
	    write(log_rt_fd, rt_buf, len);
	    len = 0;

	    entry = entry->next;
	}
    }
    /* Schedule a new printing of routing table... */
    timer_add_msec(&rt_timer, rt_log_interval);
}
예제 #2
0
void NS_CLASS print_rt_table(void *arg)
{
    char rt_buf[2048], ifname[64], seqno_str[11];
    int len = 0;
    int i = 0;
    rt_table_t *entry;
    precursor_t *pr;
    struct timeval now;
    struct tm *time;

    if (rt_tbl.num_entries == 0)
	goto schedule;

    gettimeofday(&now, NULL);

#ifdef NS_PORT
    time = gmtime(&now.tv_sec);
#else
    time = localtime(&now.tv_sec);
#endif

    len +=
	sprintf(rt_buf,
		"# Time: %02d:%02d:%02d.%03ld IP: %s seqno: %u entries/active: %u/%u\n",
		time->tm_hour, time->tm_min, time->tm_sec, now.tv_usec / 1000,
		devs_ip_to_str(), this_host.seqno, rt_tbl.num_entries,
		rt_tbl.num_active);
    len +=
	sprintf(rt_buf + len,
		"%-15s %-15s %-3s %-3s %-5s %-6s %-5s %-5s %-15s\n",
		"Destination", "Next hop", "HC", "St.", "Seqno", "Expire",
		"Flags", "Iface", "Precursors");

    write(log_rt_fd, rt_buf, len);
    len = 0;

    for (i = 0; i < RT_TABLESIZE; i++) {
	entry = rt_tbl.tbl[i];
	while (entry != NULL) {

	    if (entry->flags & RT_INV_SEQNO)
		sprintf(seqno_str, "-");
	    else
		sprintf(seqno_str, "%u", entry->dest_seqno);

	    /* Print routing table entries one by one... */
	    if (entry->precursors == NULL)
		len += sprintf(rt_buf + len,
			       "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s\n",
			       ip_to_str(entry->dest_addr),
			       ip_to_str(entry->next_hop), entry->hcnt,
			       state_to_str(entry->state), seqno_str,
			       (entry->hcnt == 255) ? 0 :
			       timeval_diff(&entry->rt_timer.timeout, &now),
			       rt_flags_to_str(entry->flags),
			       if_indextoname(entry->ifindex, ifname));

	    else {
		len += sprintf(rt_buf + len,
			       "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s %-15s\n",
			       ip_to_str(entry->dest_addr),
			       ip_to_str(entry->next_hop), entry->hcnt,
			       state_to_str(entry->state), seqno_str,
			       (entry->hcnt == 255) ? 0 :
			       timeval_diff(&entry->rt_timer.timeout, &now),
			       rt_flags_to_str(entry->flags),
			       if_indextoname(entry->ifindex, ifname),
			       ip_to_str(entry->precursors->neighbor));

		/* Print all precursors for the current routing entry */
		for (pr = entry->precursors->next; pr != NULL; pr = pr->next) {
		    len += sprintf(rt_buf + len, "%64s %-15s\n", "*",
				   ip_to_str(pr->neighbor));

		    /* Since the precursor list is grown dynamically
		     * the write buffer should be flushed for every
		     * entry to avoid buffer overflows */
		    write(log_rt_fd, rt_buf, len);
		    len = 0;

		}
	    }
	    if (len > 0) {
		write(log_rt_fd, rt_buf, len);
		len = 0;
	    }
	    entry = entry->next;
	}
    }
    /* Schedule a new printing of routing table... */
  schedule:
    timer_set_timeout(&rt_log_timer, rt_log_interval);
}