⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crc_main.cc

📁 OLSR Implementation for XORP
💻 CC
📖 第 1 页 / 共 3 页
字号:
	}	sp->s_name = "olsr";	sp->s_aliases = NULL;	sp->s_port = htons(OLSRPORT);	sp->s_proto = "udp";	 	/*	 * Process olsrd options. 	 */	 // ***** modefied by L.Qin	// when merge OLSR into XORP, we cannot provide parameters in 	// command line, now, fix some in the program, and may make 	// change to be flexible in the future// added by L.Qin, start the OLSR target module  *****	xlog_init(argv[0], 0);    	xlog_set_verbose(XLOG_VERBOSE_HIGH);    	xlog_add_default_output();    	xlog_start();        	XrlOlsrTarget tgt_target(&tgt_router);    	printf("*-*-*- start running olsr target\n");   	bool timeout = false;    	XorpTimer t = e.set_flag_after_ms(2000, &timeout);    	while (timeout == false && tgt_router.ready() == false)		e.run();        //wait for while 	bool tout=false;	t = e.set_flag_after_ms(10000, &tout);	while (!tout){		e.run();	}	 //read number of interfaces value from user's setting:	 tgt_target.olsr_3_0_get_interface_number(numberofInterfaces);         printf("When from Target, the number of interfaces becomes %d\n", numberofInterfaces);		/*	 * To specify the name of an interface to be used by olsrd.	 * Is required if more than one interface have configuured.	 *///        string wirelessCard;        int len;        tgt_target.olsr_3_0_get_interface_name(wirelessCard);	if(numberofInterfaces==1){		//if the node only has one wireless interface        	len=wirelessCard.length();        	char *winterface=new char[len+1];        	wirelessCard.copy(winterface,len,0);        	winterface[len]=0;        	printf("*********___\n");        	printf(" The interface name is %s %d\n",wirelessCard.c_str(),len);	//        const char *winterface=wirelessCard.data();        	printf (" The interface to the ifchoice %s\n",winterface);		option_i=1;		ifchoice(winterface);	 }         else{		// if we have more than one interface, we have specify in the 		//configure file in a format like "eth1 eth2 eth3"		//so that we can get all the interface name here		string buf; //have a buffer string		stringstream ss(wirelessCard); //insert the string into a stream		vector<string> tokens; //creat vector to hold the interface names		while (ss >> buf){			tokens.push_back(buf);		}		option_i=1;	//assign each interface		for(int ifNO=0;ifNO<numberofInterfaces;ifNO++){			len=tokens[ifNO].length();			char *winterface=new char[len+1];        		tokens[ifNO].copy(winterface,len,0);        		winterface[len]=0;//	        	printf(" The interface name is %s %d\n",wirelessCard.c_str(),len);		        printf (" The interface to the ifchoice %s\n",winterface);			ifchoice(winterface);		}	}	/*	 * To specify the host role in the networt, it can be	 * gateway, mobilenode or manetnode	 */         tgt_target.olsr_3_0_get_host_role(hostRole);	 if(hostRole=="gw"){		role=GATEWAY;		hello_start=1;	 }	 if(hostRole=="mb"){		role=MOBILENODE;	 }	 if(hostRole=="mn"){		role=MANETNODE;		hello_start=1;	 }	 printf(" The host role is %d\n",role);	/*	 * To specify the multicast address to be used by olsrd.	 * Is required 	 */         tgt_target.olsr_3_0_get_multicast_addr(mAddr);         len=mAddr.length();         char *multicastAdd=new char[len+1];         mAddr.copy(multicastAdd,len,0);	 multicastAdd[len]=0;	 printf(" The multicast address is %s\n",multicastAdd);                  if(inet_pton(AF_INET6, multicastAdd, &multiaddr)<0){		printf("Error: No multicast address!");	        exit(1);         }         //read hello interval from user's setting:	 tgt_target.olsr_3_0_get_hello_interval(helloInter);         printf("When from target,hello interval becomes %d\n", helloInter);	 hello_int=helloInter;         //read TC interval from user's setting:	 tgt_target.olsr_3_0_get_tc_interval(tcInter);         printf("When from target,it becomes %d\n", tcInter);	 tc_int=tcInter;         //read minimum TC interval from user's setting:	 tgt_target.olsr_3_0_get_mini_tc_interval(minitcInter);         printf("When from Target, mini tc interval becomes %d\n", minitcInter);	 min_tc_int=minitcInter;		 //read neighbor timeout mult from user's setting:	 tgt_target.olsr_3_0_get_neighbor_timeout_mult(neiborMulti);         printf("When from Target, neighbor timeout multi becomes %d\n", neiborMulti);         neighbor_timeout_mult=neiborMulti;	 //read topo timeout mult from user's setting:	 tgt_target.olsr_3_0_get_topo_timeout_mult(topoMulti);         printf("When from Target, topo timeout multi becomes %d\n", topoMulti);         topology_timeout_mult=topoMulti;	 //read tos value from user's setting:	 tgt_target.olsr_3_0_get_tos(tosValue);         printf("When from Target, tos becomes %d\n", tosValue);         tos=tosValue;	 //read TC jitter value from user's setting:	 tgt_target.olsr_3_0_get_tc_jitter(TCjitter);         printf("When from Target, TC jitter becomes %d\n", TCjitter);	// convert it to float         tc_jitter=TCjitter*0.01;	 //read Hello jitter value from user's setting:	 tgt_target.olsr_3_0_get_hello_jitter(HELLOjitter);         printf("When from Target, Hello jitter becomes %d\n", HELLOjitter);	// convert it to float         hello_jitter=HELLOjitter*0.01;	 //read node willingness value from user's setting:	 tgt_target.olsr_3_0_get_willingness(willing);         printf("When from Target, node willingness becomes %d\n", willing);	 my_willingness=willing;	 //read debug level value from user's setting:	 tgt_target.olsr_3_0_get_debug_level(debugLEVEL);         printf("When from Target, debug level becomes %d\n", debugLEVEL);	 debug_level=debugLEVEL;	 //read hysteresis value from user's setting, actually it's boolean         //then we treated value other than 0 as enabled:	 tgt_target.olsr_3_0_get_hyst_enabled(hystEnabled);         printf("When from Target, hyst becomes %d\n", hystEnabled);	 if(hystEnabled!=0){		use_hyst = 1;	 }	 printf("do we use hyst? %d\n",use_hyst);	 //read QoS value from user's setting, actually it's boolean         //then we treated value other than 0 as enabled:	 tgt_target.olsr_3_0_get_qos_enabled(qosEnabled);         printf("When from Target, QoS becomes %d\n", qosEnabled);	 if(qosEnabled!=0){		use_qos = 1;	 }	// *****		/* update values for hold_time after input values are read */	neighbor_hold_time = hello_int * neighbor_timeout_mult;	topology_hold_time = tc_int * topology_timeout_mult;	mid_hold_time = topology_hold_time; //added by Y.Ge	mid_int = tc_int; //added by Y.Ge	hello_int_wjit = hello_int;	/* printout settings */	printf("CRCOLSR: CRC IPv6 HNA Version %s \n\		OLSR6d Parameters are: \n\		hello interval = %f \n\		hello jitter = %f \n\		tc interval = %f \n\		tc jitter = %f \n\		polling interval = %f \n\		neighbor_hold_time = %f \n\		topology_hold_time = %f \n\		neighbor_timeout_mult = %d \n\		topology_timeout_mult = %d \n\		tos setting = %d \n\		", VERSION, hello_int, hello_jitter, \		tc_int, tc_jitter, polling_int, \		neighbor_hold_time, topology_hold_time, \		neighbor_timeout_mult, topology_timeout_mult, tos);	/*itval.it_interval.tv_sec = TIMER_RATE;	itval.it_value.tv_sec = TIMER_RATE; */ 	itval.it_interval.tv_sec = (int) polling_int;	itval.it_value.tv_sec = (int) polling_int;		itval.it_interval.tv_usec = (int) ((polling_int-itval.it_interval.tv_sec) * 1000000);	itval.it_value.tv_usec = (int) ((polling_int-itval.it_interval.tv_sec) * 1000000);	printf("	Polling interval in secs is %d\n", itval.it_interval.tv_sec);	printf("	Polling interval in usecs is %d\n", itval.it_interval.tv_usec);		printf("        Node's WILLINGNESS is: %d\n", my_willingness);		if(role==MANETNODE)		printf("	A MANET NODE \n");	if(role==MOBILENODE)		printf("	A MOBILE NODE \n");	if(role==GATEWAY)		printf("	A GATEWAY NODE \n");			for (nt = interf_names; nt != NULL; nt = nt->next)	{		printf ("----- interface name: %s\n", nt->name);	}		/* CRC v4->v6 chg */	ifinit();	(void) gettimeofday(&now,(struct timezone *)NULL);	/* Choice of the Originator address. In this version ifnet contain one interface */	/* v4->v6, we use the site address as a interface's ipv6 address*/	//v4->v6 add		for (index = 0; index <MAXIFACENUM; index++)	{		memset(&addr[index], 0, sizeof (addr));	}				for (ifp = ifnet; ifp; ifp = ifp->int_next) 	{		printf ("...now look at inteface: %s\n",ifp->int_name);		printf ("   this interface address is: %s\n", convert_address_to_string(&ifp->int6_site_addr));				memset(&addrsock6[ifp->my_index], 0, sizeof (struct sockaddr_in6));		addrsock6[ifp->my_index].sin6_family = AF_INET6;		addrsock6[ifp->my_index].sin6_port = sp->s_port;				//memcpy(&(addrsock6[ifp->my_index].sin6_addr.s6_addr), &(ifp->int6_site_addr), sizeof(struct olsr_ip_addr));				//printf (" now looking at index: %d\n", ifp->my_index);		//printf (" port is: %d\n", addrsock6[ifp->my_index].sin6_port);						if((s6[ifp->my_index] = getsocket(AF_INET6, SOCK_DGRAM, (struct sockaddr *)&addrsock6[ifp->my_index]))<0)		{			printf("getsocket error\n");			exit(1);		}				/* bind to interface. WHY??? */		if((setsockopt(s6[ifp->my_index], SOL_SOCKET, SO_BINDTODEVICE, ifp->int_name, strlen(ifp->int_name)+1)) < 0)		{	  		perror("setsockopt(SO_BINDTODEVICE) error");	  		exit(1);		}		/* CRC v4->v6 add 		 Enable the multicast for all interface and set the mulitcast group		 For the time being it is ok because we have only one interface. if we		 have multiple interface, can the setsockopt still be used?*/				if(setmulticast(s6[ifp->my_index], ifp)<0)		{			printf("Error: set multicast address. \n");			exit(1);		}		// set tos from MDP code 	 	// v4->v6 I am not sure if those socket options are support by ipv6		precedence = IPTOS_PREC(tos);		if (setsockopt(s6[ifp->my_index], SOL_SOCKET, SO_PRIORITY, (char*)&precedence, sizeof(precedence)) < 0)           		{     			perror("UdpSocket: setsockopt(SO_PRIORITY) error");		}                          		tos_bits = IPTOS_TOS(tos);		if (setsockopt(s6[ifp->my_index], SOL_IP, IP_TOS, (char*)&tos_bits, sizeof(tos_bits)) < 0)    		{            			perror("UdpSocket: setsockopt(IP_TOS) error");		}		// end of tos 					printf("	Interface name:%s\n",ifp->int_name);		printf("	Interface num:%d\n",ifp->int_ifindex);		printf("	Interface index:%d\n", ifp->my_index);		printf("	s6 is: %d\n", s6[ifp->my_index]);				if (ifp->int_flags & IFF_PASSIVE )		{			printf (" continue!\n");			continue;		}				/* choose the main address */		if (!main_addr_set) 		{			memcpy(&addr_ip,&(ifp->int6_site_addr),sizeof(struct olsr_ip_addr));			addr_ip_prefix = ifp->int6_site_prefix;			memcpy(&my_main_addr, &addr_ip, sizeof(struct olsr_ip_addr)); //added by Y.Ge			main_addr_set = 1; //added by Y.Ge		}				memcpy(&addr_manet[iface_index], &(ifp->int6_site_addr), sizeof(struct olsr_ip_addr)); //added by Y.Ge			//CRC hna added		if((sd[ifp->my_index]=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMP))<0)		{					perror("socket");			syslog(LOG_ERR, "socket: %m");			return (-1);		}		if(role==MOBILENODE)		{			if(ioctl(sd[ifp->my_index],SIOCSHNA,(void*)ifp->int_name)<0)			{				perror("ioctl");				syslog(LOG_ERR, "ioctl: %m");				return (-1);			}	    			//close(sd);		}		addr[iface_index].sin6_family = AF_INET6;		addr[iface_index].sin6_port = htons(OLSRPORT);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -