📄 timer.c
字号:
/* * Copyright (c) 2004 Ying Ge, Communication Research Center Canada. * * Copyright (c) 2002, 2003 Maoyu Wang, Communication Research Center Canada. * * By Ying Ge: * 1. Change the OLSR packet format and message processing procedure based * on the OLSR RFC. * 2. Add support of multiple interfaces to OLSR, including MID message * creating and processing procedure as specified in the OLSR RFC. * 3. Add QoS Support to OLSR * * By Maoyu Wang: * 1. Ported OLSR from IPv4 to IPv6. * 2. Added the Host and Network Association (HNA) functionality into OLSR. * 3. Added the default gateway functionality into OLSR by extending the HNA * message usage. The default gateway functionality supported the mobility * by cooperating with Mobile IPv6 for a mobile node as well as supported * Internet access for MANET nodes. * * DISTRIBUTED WITH NO WARRANTY, EXPRESS OR IMPLIED. * See the GNU Library General Public License (file COPYING in the distribution) * for conditions of use and redistribution *//* * This Copyright notice is in French. An English summary is given * but the referee text is the French one. * * Copyright (c) 2000, 2001 Adokoe.Plakoo@inria.fr, INRIA Rocquencourt, * Anis.Laouiti@inria.fr, INRIA Rocquencourt. * * Ce logiciel informatique est disponible aux conditions * usuelles dans la recherche, c'est-à-dire qu'il peut * être utilisé, copié, modifié, distribué à l'unique * condition que ce texte soit conservé afin que * l'origine de ce logiciel soit reconnue. * Le nom de l'Institut National de Recherche en Informatique * et en Automatique (INRIA), ou d'une personne morale * ou physique ayant participé à l'élaboration de ce logiciel ne peut * être utilisé sans son accord préalable explicite. * * Ce logiciel est fourni tel quel sans aucune garantie, * support ou responsabilité d'aucune sorte. * Certaines parties de ce logiciel sont dérivées de sources developpees par * University of California, Berkeley et ses contributeurs couvertes * par des copyrights. * This software is available with usual "research" terms * with the aim of retain credits of the software. * Permission to use, copy, modify and distribute this software for any * purpose and without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, * and the name of INRIA, or any contributor not be used in advertising * or publicity pertaining to this material without the prior explicit * permission. The software is provided "as is" without any * warranties, support or liabilities of any kind. * This product includes software developed by the University of * California, Berkeley and its contributors protected by copyrights. */char timer_rcsid[] = "$Id: timer.c,v 1.2 2000/12/06 10:36:12 prima Exp $";/* * Routing Table Management Daemon */#include "defs.h"float sincelast_tc = 0.0; /* Time last since we send last TC packet */float sincelast_hello = 0.0; /* Time last since we send last HELLO packetc */float sincelast_mid = 0.0; /* added by Y.Ge, Time last since we send last MID packet */float sincelast_hello_poll = 0.0; /* Need to keep average hellos consistent */float tc_jit_result = 0.0, hello_jit_result = 0.0;float mid_jit_result = 0.0; //added by Y.Gefloat hna_jit_result = 0.0; //added by Y.Gefloat tc_relay_jitter = 0.0; //added by Y.Gefloat mid_relay_jitter = 0.0; //added by Y.Gefloat hna_relay_jitter = 0.0; //added by Y.Gefloat tc_relay_interval = 0.0; //added by Y.Gefloat mid_relay_interval = 0.0; //added by Y.Gefloat hna_relay_interval = 0.0; //added by Y.Ge/* qos OLSR */int current_busy_time = 10; //added by Y.Ge/* for QoS debug */float since_last_busy_update = 0.0;float busy_update_interval = 5.0;//CRC HNA add/*-----------------------------------------------------------------*/float sincelast_hna = 0.0; /* TIme last since we send last HNA packet*//*-----------------------------------------------------------------*//******************** added by Y.Ge ***************//* reset the chunk count array */void reset_chunk_count(int *array){ int i; for (i=0; i<num_of_interface; i++) { array[i]=0; }}int check_chunk_count (int *array){ int i; for (i=1; i<num_of_interface; i++) { if (array[i] != array[0]) { return 0; // something is wrong, the chunked number should be same } } return 1; }/* qos OLSR */int read_busy_time(){ FILE *proc_fp = NULL; char text_to_print[150]; int rcvd_idle; int rcvd_tx_busy; int rcvd_rx_busy; if (proc_fp == NULL) proc_fp = fopen("/proc/net/av_bw_algo_ath0", "r"); if (proc_fp < 0) { printf ("XXXXXXX Error in opening /proc XXXXXXXXX\n"); exit(1); } /* read sequence number */ if (NULL==fgets(text_to_print, 20, proc_fp)) { printf ("XXXXXXX Error in reading sequence number XXXXXXXXX\n"); exit(1); } else text_to_print[strlen(text_to_print)-1] = (char)NULL; /* read idle time */ if (NULL==fgets(text_to_print, 20, proc_fp)) { printf ("XXXXXXX Error in reading idle time XXXXXXXXX\n"); exit(1); } else { sscanf(text_to_print, "%d", &rcvd_idle); if (debug_level > 6) { printf ("current idle time: %d\n", rcvd_idle); fprintf (y_file, "current idle time: %d\n", rcvd_idle); } /* strcpy(text_to_print+strlen(text_to_print)-1, "%"); */ } /* read Busy tx */ if (NULL==fgets(text_to_print, 20, proc_fp)) { printf ("XXXXXXX Error in reading busy tx XXXXXXXXX\n"); exit(1); } else { sscanf(text_to_print, "%d", &rcvd_tx_busy); if (debug_level > 6) { printf ("current idle time: %d\n", rcvd_tx_busy); fprintf (y_file, "current idle time: %d\n", rcvd_tx_busy); } /* strcpy(text_to_print+strlen(text_to_print)-1, "%"); */ } /* read Busy rx */ if (NULL==fgets(text_to_print, 20, proc_fp)) { printf ("XXXXXXX Error in reading busy rx XXXXXXXXX\n"); exit(1); } else { sscanf(text_to_print, "%d", &rcvd_rx_busy); if (debug_level > 6) { printf ("current idle time: %d\n", rcvd_rx_busy); fprintf (y_file, "current idle time: %d\n", rcvd_rx_busy); } /* strcpy(text_to_print+strlen(text_to_print)-1, "%"); */ } if (proc_fp != NULL) { fclose(proc_fp); proc_fp = NULL; } return (rcvd_tx_busy + rcvd_rx_busy); }/******************* end of revision *************//* * Timer routine. Performs neighbor and topology information supply * duties and manages timers on all tables' entries. */void timer(int signum){ struct itimerval itval; struct hello_message hellopacket; struct tc_message tcpacket; struct mid_message midpacket; //added by Y.Ge struct qos_tc_message qostcpacket; //added by Y.Ge struct interface *ifp; //added by Y.Ge struct mid_iface_addr *mid_addresses, *prev_mid_addresses; //added by Y.Ge struct tc_mpr_addr *mprs, *prev_mprs; //added by Y.Ge int mid_built_finished = 0, tc_built_finished = 0, hna_built_finished = 0; //added by Y.Ge, only need to build MID and TC once FOR all interfaces int hna_sent = 0;//added by Y.Ge int timetobroadcast_hello, timetobroadcast_tc, timetoreset_hello, timetobroadcast_hna, timetobroadcast_mid; int timetorelay_tc=0, timetorelay_mid=0, timetorelay_hna=0; //added by Y.Ge int send_tc_seperately=0, send_mid_seperately=0; //added by Y.Ge tcpacket.multipoint_relay_selector_address = (struct tc_mpr_addr *)NULL; hellopacket.neighbors = (struct hello_neighbor *)NULL; midpacket.mid_interface_address = (struct mid_iface_addr *)NULL; //added by Y.Ge (void)signum; (void) gettimeofday(&now, (struct timezone *)NULL); nowtm = gmtime(&now.tv_sec); sincelast_hello += polling_int; sincelast_hello_poll += polling_int; sincelast_tc += polling_int; sincelast_hna += polling_int; sincelast_mid += polling_int; //added by Y.Ge timetoreset_hello = supplier && sincelast_hello_poll >= hello_int; timetobroadcast_hello = supplier && sincelast_hello >= hello_int_wjit; timetobroadcast_tc = changes ? supplier && sincelast_tc >= min_tc_int : supplier && sincelast_tc >= tc_int; //CRC HNA modify timetobroadcast_hna = supplier && sincelast_hna >= HNA_INTERVAL; timetobroadcast_mid = supplier && sincelast_mid >= mid_int; //added by Y.Ge /*timetobroadcast_mid = timetobroadcast_hello; timetobroadcast_hna = timetobroadcast_hello; timetobroadcast_tc = timetobroadcast_hello; */ /* qos OLSR debug */ since_last_busy_update += polling_int; /*if (since_last_busy_update >= busy_update_interval) { //randondom_busy +=2; current_busy_time += 2; since_last_busy_update = 0; printf ("\n\n------------------ updating busy time! new busy time is: %d ----------\n", current_busy_time); }*/ /******************** added by Y.Ge ****************/ /************ busy time updating *******/ /* qos OLSR */ if (use_qos) { current_busy_time = read_busy_time(); if (abs(current_busy_time - my_busy_time) > (my_busy_time * bw_update_threshold)) { if (debug_level > 3) { printf ("\n\n------------------ updating busy time! old busy time is: %d, new busy time is: %d ----------\n", my_busy_time, current_busy_time); fprintf (y_file, "\n\n------------------ updating busy time! old busy time is: %d, new busy time is: %d ----------\n", my_busy_time, current_busy_time); } my_busy_time = current_busy_time; } } if (tc_to_relay) { if (debug_level > 3) { printf ("----- should relay tc!\n"); printf ("--- interval:%f, jitter:%f\n", tc_relay_interval, tc_relay_jitter); fprintf (y_file,"----- should relay tc!\n"); fprintf (y_file,"--- interval:%f, jitter:%f\n", tc_relay_interval, tc_relay_jitter); } tc_relay_interval += polling_int; timetorelay_tc = tc_relay_interval >= tc_relay_jitter; if (tc_relay_size ==0) { printf ("XXXXXXXXX something wrong with the tc relay size! xxxxxxxxx\n"); exit(1); } } if (mid_to_relay) { if (debug_level > 3) { printf ("----- should relay mid!\n"); printf ("--- interval:%f, jitter:%f\n", mid_relay_interval, mid_relay_jitter); fprintf (y_file, "----- should relay mid!\n"); fprintf (y_file, "--- interval:%f, jitter:%f\n", mid_relay_interval, mid_relay_jitter); } mid_relay_interval += polling_int; timetorelay_mid = mid_relay_interval > mid_relay_jitter; if (mid_relay_size ==0) { printf ("XXXXXXXXX something wrong with the mid relay size! xxxxxxxxx\n"); exit(1); } } if (hna_to_relay) { if (debug_level > 3) { printf ("----- should relay hna!\n"); printf ("--- interval:%f, jitter:%f\n", hna_relay_interval, hna_relay_jitter); fprintf (y_file, "----- should relay hna!\n"); fprintf (y_file, "--- interval:%f, jitter:%f\n", hna_relay_interval, hna_relay_jitter); } hna_relay_interval += polling_int; timetorelay_hna = hna_relay_interval > hna_relay_jitter; if (hna_relay_size ==0) { printf ("XXXXXXXXX something wrong with the mid relay size! xxxxxxxxx\n"); exit(1); } } /* decide if the relayed TC/MID/HNA should be sent out seperately */ if (timetorelay_tc) { /* the two or three messages could be relayed in one packets */ /* but the message should NOT be trucked */ /* as it will cause the confusion of packet sequence number */ /* so check the message size to make sure the messages are not chunked */ if (timetorelay_mid && timetorelay_hna) { if (debug_level > 3) { printf ("********* there are relayed TC, MID, HNA together ************\n"); printf ("tc relay size: %d, mid relay size: %d, hna relay size: %d\n", tc_relay_size, mid_relay_size, hna_relay_size); fprintf (y_file,"********* there are relayed TC, MID, HNA together ************\n"); fprintf (y_file,"tc relay size: %d, mid relay size: %d, hna relay size: %d\n", tc_relay_size, mid_relay_size, hna_relay_size); } if (tc_relay_size + mid_relay_size < MAXPACKETSIZE) { if (tc_relay_size + hna_relay_size + mid_relay_size > MAXPACKETSIZE) { send_mid_seperately = 1; if (debug_level > 3) { printf ("----- send TC and MID together!\n"); fprintf (y_file,"----- send TC and MID together!\n"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -