📄 crc_main.cc
字号:
/* * Department of Systems and Computer Engineering * Carleton University, CANADA * Copyright (c) 2004 Liang Qin, Department of Systems and Computer Engineering, * Carleton University * 1. Porting CRC's OLSR with QoS support to XORP 1.0, this release enable OLSR * adds and deletes route entries to RIB in XORP, instead of to Linux kernel. * * 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 *//* Code Modified by Joe Macker and Ron Lee July (NRL) 2001 * the following was added * (1) hysteresis code for hellos * - added pending state and filter parameters * (2) parameterization of other setting * - hello intervals, * (3) added jitter functionality * (4) still don't like the polling routing used as an event handler * (5) changed gateway code so -g becomes enter a gateway address for stub * (6) added low delay TOS socket settings - oct 2001 * (7) added some extra debug output for map plots in nam use debug level 2 or greater * (8) improved jitter variance statistics - Macker - nov 2001 */ /* * 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. *//* * Copyright (c) 1983, 1988, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */char copyright[] = "@(#) Copyright (c) 2000, 2001\n" " INRIA-HIPERCOM. All rights reserved.\n";/* * From: @(#)main.c 5.23 (Berkeley) 7/1/91 * From: @(#)main.c 8.1 (Berkeley) 6/5/93 * From: @(#)main.c 1.7 (dholland Exp) 1997/05/19 */char main_rcsid[] = "$Id: main.c,v 1.2 2000/12/06 10:36:11 prima Exp $";/* * Routing Table Management Daemon */// modified by L.Qin, merged with XORP and changed it to C++ style// these two header files are in c style#include <sys/ioctl.h>#include <sys/file.h>#include <net/if.h>#include <errno.h>#include <signal.h>#include <syslog.h>#include <sys/utsname.h>#include <netinet/ip.h>#include <string>#include <vector>#include <sstream>// added by L.Qin#include "olsr_module.h"#include "libxorp/eventloop.hh"#include "libxorp/exceptions.hh"#include "libxipc/finder_server.hh"#include "libxipc/xrl_std_router.hh"#include "libxipc/xrl_pf_sudp.hh"#include "xrl_target6.hh"#include "xrl_rib_notifier.h"extern "C" { #include "defs.h" #include "version.h"}static const char* g_tgt_name = "olsr";//*****int num_of_interface=0; //added by Y.Gestruct sockaddr_in6 defgwIP; /* NRL-NRL: Address used as Default Gateway */struct olsr_ip_addr default_gateway; /* NRL-NRL: sin_addr.s_addr member of variable defgwIP */struct gateway saved_gateway;short hello_start=1;int rt_reset=0,refresh=0;//struct sockaddr_in6 addr; //commented by Y.Gestruct sockaddr_in6 addr[MAXIFACENUM]; /*addedd by Y.Ge, multiple interfaces. Address used as Originator Address */struct olsr_ip_addr addr_ip; /*home address*/ //Y.Ge: use this as main address//commented by L.Qin, already defined in defs.h//olsr_u16_t addr_ip_prefix; /*home address prefix*/struct olsr_ip_addr addr_coa; /*care of address*///struct olsr_ip_addr addr_manet; /*address propogated in hello message*/ //commented by Y.Gestruct olsr_ip_addr addr_manet[MAXIFACENUM]; //added by Y.Ge , my interface addressint olsr_if_index[MAXIFACENUM]; //added by Y.Ge, keep the "int_ifindex" of "struct interface" of all OLSR interfacesstruct olsr_ip_addr my_main_addr; /* added by Y.Ge, main address of this node */struct olsr_ip_addr multiaddr; /* multicast addr using in hello and tc msg*/ //struct sockaddr_in6 addrsock6; /* ipv6 address of daemon's socket */ //commented by Y.Gestruct sockaddr_in6 addrsock6[MAXIFACENUM]; //added by Y.Ge//int s6; //commented by Y.Geint s6[MAXIFACENUM]; //added by Y.Ge//int sd; //commented by Y.Geint sd[MAXIFACENUM]; //added by Y.Gechar packet[MAXPACKETSIZE+1];int outputsize = 0; /* current size of the output buffer (packet) */struct servent *sp;sigset_t sigSet, osigset, psigset;struct interf_name *interf_names = NULL; /* list of interface type on which olsr packets will be send */int supplier = 1; /* process should supply updates */int option_i = 0;int filter = 0;int gateway = 0; /* 1 if we are a gateway to parts beyond */int debug = 0;int debug_level = 0; /* NRL added debug levels .. TBD make this better if we keep using it*/int bufspace = 127*1024; /* max. input buffer size to request */struct olsr *msg = (struct olsr *)packet;//short hello_seqnum = 1; /* Hello packet counter which is use as unique identifier to HELLO PACKET */ /*commented by Y.Ge *///short tc_seqnum = 1; /* TC packet counter which is use as unique identifier to TC PACKET */ /*commented by Y.Ge *///short hna_seqnum = 1; /* HNA packet counter which is use as unique identifier to HNA PACKET */ /*commented by Y.Ge */ short pkt_seqnum[MAXIFACENUM]; /* added by Y.Ge, olsr packet counter *//**************** added by Y.Ge *******************/struct olsr_msg_seq msg_seqnum; //the unique message sequence number for each type of message/* store the message that should be forwarded */struct tc_message tcpacket_relay;struct mid_message midpacket_relay;struct hna_message hnapacket_relay;struct qos_tc_message qostcpacket_relay; //qos OLSR /* store the unknown message that should be relayed */char unknown_packet[MAXPACKETSIZE+1];/* store the message sequence number update when it has to be chunked */int hello_chunk[MAXIFACENUM];int tc_chunk[MAXIFACENUM];int mid_chunk[MAXIFACENUM];int hna_chunk[MAXIFACENUM];/* use hysteresis or not ? */int use_hyst = 0; //DEFAULT value/* for debug */FILE *y_file;/* qos OLSR */olsr_u32_t my_busy_time = 0;int use_qos = 0;double bw_update_threshold = 0.2;int default_busy_time = 100;/************** end of revision **********************/ short my_willingness = WILL_DEFAULT; /* added by Y.Ge, set willingness */ int role = MANETNODE; /*float hello_int = 0.25, hello_jitter = 0.05 , hello_int_wjit = 0.25, tc_int = 1.0, tc_jitter = 0.25, polling_int = 0.025, min_tc_int = 0.5;int neighbor_timeout_mult = 8;int topology_timeout_mult = 5;u_int8_t tos = 16;float topology_hold_time = 5.0 ;//topology_hold_time = tc_int*topology_timeout_mult;float neighbor_hold_time = 2.0;//neighbor_hold_time = hello_int*neighbor_timeout_mult;*/ //commented by Y.Ge/*************** added by Y.Ge ************//*** redefine the above value based on olsr_v11 ***/float hello_int = HELLO_INTERVAL, tc_int = TC_INTERVAL, min_tc_int = MIN_TC_INTERVAL;float mid_int = MID_INTERVAL;float hello_jitter = 0.05, hello_int_wjit = 0.25, tc_jitter = 0.25, mid_jitter = 0.25, hna_jitter = 0.25, polling_int = 0.025; //the jitter Should be changed laterfloat neighbor_hold_time = NEIGHB_HOLD_TIME, topology_hold_time = TOP_HOLD_TIME, mid_hold_time = MID_HOLD_TIME;float duplicate_hold_time = DUPLICATE_HOLD_TIME;int neighbor_timeout_mult = 3, topology_timeout_mult = 3;u_int8_t tos = 16;/**************** end of revision **********/int tos_bits = 0;int precedence = 0;int getsocket(int, int, struct sockaddr *);void process(int, int, int); //Y.Ge: add another int to record the interface indexint setmulticast(int, struct interface*);void init();// ***** added by L.Qin// this eventloop will be used for whole OLSR moduleEventLoop e;XrlStdRouter tgt_router(e, g_tgt_name /*, finder.addr(), finder.port()*/); string hostRole="gw";string wirelessCard="wlan0";string mAddr="ff05::11";int helloInter=10;int tcInter=10;int minitcInter=10;int neiborMulti=10;int topoMulti=10;int tosValue=10;int TCjitter=10;int HELLOjitter=10;int willing=2;int debugLEVEL=2;int numberofInterfaces=1;int hystEnabled=10;int qosEnabled=10;//*****/******************** the following is commented by Y.Ge ********************//* int main(int argc, char *argv[])*//***************** rewritten by Y.Ge *********************/int main(int argc, char *argv[]){ int n, nfd, tflags = 0; struct timeval *tvp, waittime; struct itimerval itval; fd_set ibits;// sigset_t sigset, osigset; //commented by L. Qin, already defined before struct tc_message tcpack; struct hello_message hellopack; struct interface *ifp; int iface_index=0; int main_addr_set = 0; int index; int i; struct interf_name *nt; /********** added by Y.Ge *********/ /* init message sequence number */ msg_seqnum.hello_seqnum = 1; msg_seqnum.tc_seqnum = 1; msg_seqnum.mid_seqnum = 1; msg_seqnum.hna_seqnum = 1; /* init packet sequence number */ for (i=0; i<MAXIFACENUM; i++) { pkt_seqnum[i] = 1; } midpacket_relay.mid_interface_address=NULL; tcpacket_relay.multipoint_relay_selector_address = NULL; hnapacket_relay.hna_net_addrs = NULL; qostcpacket_relay.multipoint_relay_selector_busy_time = NULL; /* init the chunk count array */ reset_chunk_count(hello_chunk); reset_chunk_count(tc_chunk); reset_chunk_count(mid_chunk); reset_chunk_count(hna_chunk); /* open my own trace file */ if ((y_file=fopen("olsr_debug","w"))==NULL) { printf("Error with creating ying's File.\n"); exit(0); } /********* end of revision ********/ init(); openlog("crcolsr6d", LOG_PID | LOG_ODELAY, LOG_DAEMON); setlogmask(LOG_UPTO(LOG_WARNING)); sp = (struct servent *) malloc( sizeof(*sp)); if (sp == 0) { printf("olsrd: out of memory\n"); exit(1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -