Example #1
0
int main(int ac, char *av[])
{
	char rpath[MAX_NAME_LEN];
	int status, *jstatus;
	simplequeue_t *outputQ, *workQ, *qtoa;
	pthread_t IGMP_broadcast_thread;

	// create separate thread for broadcasting IGMP group query messages
	pthread_create(&IGMP_broadcast_thread, NULL, IGMPBroadcast, NULL);

	// setup the program properties
	setupProgram(ac, av);
	// creates a PID file under router_name.pid in the current directory
	status = makePIDFile(rconfig.router_name, rpath);
	// shutdown the router on receiving SIGUSR1 or SIGUSR2
	redefineSignalHandler(SIGUSR1, shutdownRouter);
	redefineSignalHandler(SIGUSR2, shutdownRouter);

	outputQ = createSimpleQueue("outputQueue", INFINITE_Q_SIZE, 0, 1);
	workQ = createSimpleQueue("work Queue", INFINITE_Q_SIZE, 0, 1);

	GNETInit(&(rconfig.ghandler), rconfig.config_dir, rconfig.router_name, outputQ);
	ARPInit();
	IPInit();

	classifier = createClassifier();
	filter = createFilter(classifier, 0);

	pcore = createPacketCore(rconfig.router_name, outputQ, workQ);

	// add a default Queue.. the createClassifier has already added a rule with "default" tag
	// char *qname, char *dqisc, double qweight, double delay_us, int nslots);
	addPktCoreQueue(pcore, "default", "taildrop", 1.0, 2.0, 0);
	rconfig.scheduler = PktCoreSchedulerInit(pcore);
	rconfig.worker = PktCoreWorkerInit(pcore);

	infoInit(rconfig.config_dir, rconfig.router_name);
	addTarget("Output Queue", outputQ);
	qtoa = getCoreQueue(pcore, "default");
	if (qtoa != NULL)
		addTarget("Default Queue", qtoa);
	else
		printf("Error .. found null queue for default\n");

	// start the CLI..
	CLIInit(&(rconfig));

	wait4thread(rconfig.scheduler);
	wait4thread(rconfig.worker);
	wait4thread(rconfig.ghandler);
	wait4thread(IGMP_broadcast_thread);
}
Example #2
0
int main(int ac, char *av[])
{
	char rpath[MAX_NAME_LEN];
	int status, *jstatus;
	simplequeue_t *outputQ, *workQ, *qtoa;

	// setup the program properties
	setupProgram(ac, av);
	// creates a PID file under router_name.pid in the current directory
	status = makePIDFile(rconfig.router_name, rpath);
	// shutdown the router on receiving SIGUSR1 or SIGUSR2
	redefineSignalHandler(SIGUSR1, shutdownRouter);
	redefineSignalHandler(SIGUSR2, shutdownRouter);

	outputQ = createSimpleQueue("outputQueue", INFINITE_Q_SIZE, 0, 1);
	workQ = createSimpleQueue("work Queue", INFINITE_Q_SIZE, 0, 1);

	GNETInit(&(rconfig.ghandler), rconfig.config_dir, rconfig.router_name, outputQ);
	ARPInit();
	IPInit();
	init_ports();
	init_tcp();

	/*uint32_t dest_ip = 12319800;
	uint16_t dest_port = 123;
	uint16_t src_port = 456;
	char *data = "Hello";
	int len = 6;
	send_udp(dest_ip,dest_port,src_port,data,len);*/

	  /*
	   *Test udp_recv
	   *
	   */
	/*open_port(1, UDP_PROTOCOL);
	gpacket_t *packet = (gpacket_t *) malloc(sizeof(gpacket_t));
	ip_packet_t *ipPacket = (ip_packet_t *)(packet->data.data);
	ipPacket->ip_src = {0x1,0x1,0x1,0x1};
	ipPacket->ip_dst = {0x2,0x2,0x2,0x2};
	ipPacket->ip_cksum = 65535; 
	ipPacket->ip_pkt_len = ipPacket->ip_hdr_len;
	udphdr_t *udpHeader = (udphdr_t *)((uchar *)ipPacket + ipPacket->ip_hdr_len*4);
	udpHeader->source = 0;  // ports
	udpHeader->dest = 1;
	udpHeader->len = 0;	  // length of data in octets
	udpHeader->check = 65535; 
	udp_recv(packet);
    
	free(packet);
	free(ipPacket);
	free(udpHeader);*/
	/*
	 *
	 *
	 * End test udp_recv
	 *
	 */

	printf("dis router");
	
	classifier = createClassifier();
	filter = createFilter(classifier, 0);

	pcore = createPacketCore(rconfig.router_name, outputQ, workQ);

	// add a default Queue.. the createClassifier has already added a rule with "default" tag
	// char *qname, char *dqisc, double qweight, double delay_us, int nslots);
	addPktCoreQueue(pcore, "default", "taildrop", 1.0, 2.0, 0);
	rconfig.scheduler = PktCoreSchedulerInit(pcore);
	rconfig.worker = PktCoreWorkerInit(pcore);

	infoInit(rconfig.config_dir, rconfig.router_name);
	addTarget("Output Queue", outputQ);
	qtoa = getCoreQueue(pcore, "default");
	if (qtoa != NULL)
		addTarget("Default Queue", qtoa);
	else
		printf("Error .. found null queue for default\n");

	// start the CLI..
	CLIInit(&(rconfig));


	wait4thread(rconfig.scheduler);
	wait4thread(rconfig.worker);
	wait4thread(rconfig.ghandler);
}