Ejemplo n.º 1
0
Archivo: tap.c Proyecto: sciyoshi/gini
void *toTapDev(void *arg)
{
	gpacket_t *inpkt = (gpacket_t *)arg;
	interface_t *iface;
	arp_packet_t *apkt;
	char tmpbuf[MAX_TMPBUF_LEN];
	int pkt_size;

	verbose(2, "[toTapDev]:: entering the function.. ");
	// find the outgoing interface and device...
	if ((iface = findInterface(inpkt->frame.dst_interface)) != NULL)
	{
		/* send IP packet or ARP reply */
		if (inpkt->data.header.prot == htons(ARP_PROTOCOL))
		{
			apkt = (arp_packet_t *) inpkt->data.data;
			COPY_MAC(apkt->src_hw_addr, iface->mac_addr);
			COPY_IP(apkt->src_ip_addr, gHtonl(tmpbuf, iface->ip_addr));
		}
		pkt_size = findPacketSize(&(inpkt->data));

		verbose(2, "[toTapDev]:: tap_sendto called for interface %d.. ", iface->interface_id);
		tap_sendto(iface->vpl_data, &(inpkt->data), pkt_size);
		free(inpkt);          // finally destroy the memory allocated to the packet..
	} else
		error("[toTapDev]:: ERROR!! Could not find outgoing interface ...");

	// this is just a dummy return -- return value not used.
	return arg;
}
Ejemplo n.º 2
0
void *toRawDev(void *arg)
{
	gpacket_t *inpkt = (gpacket_t *)arg;
	interface_t *iface;
	arp_packet_t *apkt;
	char tmpbuf[MAX_TMPBUF_LEN];
	int pkt_size;

	verbose(1, "[toRawDev]:: entering the function.. ");
	// find the outgoing interface and device...
	if ((iface = findInterface(inpkt->frame.dst_interface)) != NULL)
	{
		char tmp[40];
		memset(tmp, 0, sizeof(tmp));
		IP2Dot(tmp, inpkt->frame.src_ip_addr);
		/* The Amazon network has the prefix 172, so if a packet is sent to the raw interface and it does
		not begin with that prefix, we know that the packet has come from the local gini network instead.
		In this case we want to apply a SNAT, to make the packet seem as if it has come from the cRouter 
		so that Amazon machines will be able to respond (recognize the address). Note that the reverse
		NAT operation is performed in ip.c*/
		/*if(inpkt->data.header.prot != htons(ARP_PROTOCOL) && !(tmp[0] == '1' && tmp[1] == '7' && tmp[2] == '2')) {
			//printf("\n\n TRYING TO PING AMAZON CLOUD\n");				
			//printGPacket(inpkt, 3, "CONNOR PACKET");
			ip_packet_t *ipkt = (ip_packet_t *)(inpkt->data.data);
			ipkt->ip_hdr_len = 5;                                  // no IP header options!!
			icmphdr_t *icmphdr = (icmphdr_t *)((uchar *)ipkt + ipkt->ip_hdr_len*4);
			printf("\n\nICMP ID: %d\n", icmphdr->un.echo.id); 
			The IP address given to the SNAT function is the private ip address of the 
			Amazon instance that is running the cRouter in reverse 
			applySNAT("62.44.31.172", (ip_packet_t*)inpkt->data.data, icmphdr->un.echo.id);
			printNAT();	
		}*/
		/* send IP packet or ARP reply */
		if (inpkt->data.header.prot == htons(ARP_PROTOCOL))
		{
			printf("CONNORS DEBUG arp in toRawDev\n");
			apkt = (arp_packet_t *) inpkt->data.data;
			COPY_MAC(apkt->src_hw_addr, iface->mac_addr);
			COPY_IP(apkt->src_ip_addr, gHtonl(tmpbuf, iface->ip_addr));
		}
		if(inpkt->data.header.prot == htons(ICMP_PROTOCOL)){
			printf("\nICMP Request over raw\n");
		}		
		pkt_size = findPacketSize(&(inpkt->data));
		verbose(2, "[toRawDev]:: raw_sendto called for interface %d.. ", iface->interface_id);
		raw_sendto(iface->vpl_data, &(inpkt->data), pkt_size);
		free(inpkt);          // finally destroy the memory allocated to the packet..
	} else
		error("[toRawDev]:: ERROR!! Could not find outgoing interface ...");

	// this is just a dummy return -- return value not used.
	return arg;
}
Ejemplo n.º 3
0
void *toEthernetDev(void *arg)
{
        gpacket_t *inpkt = (gpacket_t *)arg;
	interface_t *iface;
	arp_packet_t *apkt;
        //ospf_packet_t *ospkt;
	char tmpbuf[MAX_TMPBUF_LEN];
	int pkt_size;

	verbose(2, "[toEthernetDev]:: entering the function.. ");
	// find the outgoing interface and device...
        if ((iface = findInterface(inpkt->frame.dst_interface)) != NULL)
	{
            /* send IP packet, ARP reply, or OSPF packet */
            if (inpkt->data.header.prot == htons(ARP_PROTOCOL)){
			apkt = (arp_packet_t *) inpkt->data.data;
			COPY_MAC(apkt->src_hw_addr, iface->mac_addr);
			COPY_IP(apkt->src_ip_addr, gHtonl(tmpbuf, iface->ip_addr));
            }
            else if (inpkt->data.header.prot == htons(IP_PROTOCOL))
	    {
                ip_packet_t *ip_pkt = (ip_packet_t *)inpkt->data.data;
                if(ip_pkt->ip_prot == OSPF_PROTOCOL){
                
                }
                //RECHECK determine if you're putting MAC address
                //into the right place
	    }
                pkt_size = findPacketSize(&(inpkt->data));
		verbose(2, "[toEthernetDev]:: vpl_sendto called for interface %d..%d bytes written ", iface->interface_id, pkt_size);
		int x = vpl_sendto(iface->vpl_data, &(inpkt->data), pkt_size);
                free(inpkt);          // finally destroy the memory allocated to the packet..
	} else{
            error("[toEthernetDev]:: ERROR!! Could not find outgoing interface ...");
        }
	// this is just a dummy return -- return value not used.
	return arg;
}
Ejemplo n.º 4
0
void *toEthernetDev(void *arg)
{

	gpacket_t *inpkt = (gpacket_t *)arg;
	interface_t *iface;
	arp_packet_t *apkt;
	char tmpbuf[MAX_TMPBUF_LEN];
	int pkt_size;

	verbose(2, "[toEthernetDev]:: entering the function.. ");
	// find the outgoing interface and device...
	if ((iface = findInterface(inpkt->frame.dst_interface)) != NULL)
	{
		/* send IP packet or ARP reply */
		if (inpkt->data.header.prot == htons(ARP_PROTOCOL))
		{
			apkt = (arp_packet_t *) inpkt->data.data;
			COPY_MAC(apkt->src_hw_addr, iface->mac_addr);
			COPY_IP(apkt->src_ip_addr, gHtonl(tmpbuf, iface->ip_addr));
		}


		pkt_size = findPacketSize(&(inpkt->data));



		//Printing packet values
/*			printf("\n=========== OUTGOING PACKET VALUES ================\n");
			printf("\n----------HEADER VALUES :");
			printf("\nSource MAC Address: %x : %x : %x : %x : %x : %x", inpkt->data.header.src[0],
					inpkt->data.header.src[1],inpkt->data.header.src[2],
					inpkt->data.header.src[3],inpkt->data.header.src[4],inpkt->data.header.src[5]);
			printf("\nDestination MAC Address: %x : %x : %x : %x : %x : %x", inpkt->data.header.dst[0],
					inpkt->data.header.dst[1],inpkt->data.header.dst[2],
					inpkt->data.header.dst[3],inpkt->data.header.dst[4],inpkt->data.header.dst[5]);

			printf("\nSource IP Address: %d.%d.%d.%d", inpkt->frame.src_ip_addr[0],
					inpkt->frame.src_ip_addr[1],inpkt->frame.src_ip_addr[2],
					inpkt->frame.src_ip_addr[3]);


			printf("\nProtocol is : %d",inpkt->data.header.prot);
			printf("\nDestination Interface is : %d",inpkt->frame.dst_interface);
			printf("\nARP BDST : %d",inpkt->frame.arp_bcast);
			printf("\narp_valid : %d",inpkt->frame.arp_valid);
			printf("\nSource Hardware Address: %d.%d.%d.%d.%d.%d", inpkt->frame.src_hw_addr[0],
					inpkt->frame.src_hw_addr[1],inpkt->frame.src_hw_addr[2],
					inpkt->frame.src_hw_addr[3],inpkt->frame.src_hw_addr[4],inpkt->frame.src_hw_addr[5]);


			printf("\nIngress Port is : %d",inpkt->frame.src_interface);
			printf("\nNXTH IP Destination: %d.%d.%d.%d", inpkt->frame.nxth_ip_addr[0],inpkt->frame.nxth_ip_addr[1],
					inpkt->frame.nxth_ip_addr[2],inpkt->frame.nxth_ip_addr[3]);

			printf("\n --- IP PACKET:");
			ip_packet_t *ip_pkt;
			ip_pkt = (ip_packet_t *) inpkt->data.data;

			printf("\Destination MAC Address: %x : %x : %x : %x : %x : %x", inpkt->data.header.dst[0], inpkt->data.header.dst[1],
					inpkt->data.header.dst[2],
					inpkt->data.header.dst[3],inpkt->data.header.dst[4],inpkt->data.header.dst[5]);
			printf("\Source MAC Address: %x : %x : %x : %x : %x : %x", inpkt->data.header.src[0],
					inpkt->data.header.src[1],inpkt->data.header.src[2],
					inpkt->data.header.src[3],inpkt->data.header.src[4],inpkt->data.header.src[5]);
			printf("\nIP Source: %d.%d.%d.%d", ip_pkt->ip_src[0],ip_pkt->ip_src[1],ip_pkt->ip_src[2],ip_pkt->ip_src[3]);
			printf("\nIP Destination: %d.%d.%d.%d", ip_pkt->ip_dst[0],ip_pkt->ip_dst[1],ip_pkt->ip_dst[2],ip_pkt->ip_dst[3]);
			printf("\nIP Protocol is : %d",ip_pkt->ip_prot);
			printf("\nIP TOS: %d\n",ip_pkt->ip_tos);
			printf("\nip_cksum: %d\n",ip_pkt->ip_cksum);
			printf("\nip_frag_off: %d\n",ip_pkt->ip_frag_off);
			printf("\nip_hdr_len: %d\n",ip_pkt->ip_hdr_len);
			printf("\nip_identifier: %d\n",ip_pkt->ip_identifier);
			printf("\nip_pkt_len: %d\n",ip_pkt->ip_pkt_len);
			printf("\nip_ttl: %d\n",ip_pkt->ip_ttl);
			printf("\nip_version: %d\n",ip_pkt->ip_version);*/



		verbose(2, "[toEthernetDev]:: vpl_sendto called for interface %d..%d bytes written ", iface->interface_id, pkt_size);
		vpl_sendto(iface->vpl_data, &(inpkt->data), pkt_size);

		free(inpkt);          // finally destroy the memory allocated to the packet..
	} else
		error("[toEthernetDev]:: ERROR!! Could not find outgoing interface ...");


	// this is just a dummy return -- return value not used.
	return arg;
}
Ejemplo n.º 5
0
// WCWeightFairQueuer: function called by the classifier to enqueue
// the packets..
// TODO: Debug this function...
void *weightedFairScheduler(void *pc)
{
	pktcore_t *pcore = (pktcore_t *)pc;
	List *keylst;
	int nextqid, qcount, rstatus, pktsize;
	char *nextqkey;
	gpacket_t *in_pkt;
	simplequeue_t *nextq;

	long queueSizes[100]; //Array to store bytes sent for each queue id
	int PacketsSent[10];
	int i, j;//To iterate through the queue length array
	long crtStarvedQid;
	double crtStarvedQidWeight;

	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
	while (1)
	{
		verbose(1, "[weightedFairScheduler]:: Weighted Fair Queue schedule processing... ");
		keylst = map_keys(pcore->queues);
		qcount = list_length(keylst);

		pthread_mutex_lock(&(pcore->qlock));
		if (pcore->packetcnt == 0)
			pthread_cond_wait(&(pcore->schwaiting), &(pcore->qlock));
		pthread_mutex_unlock(&(pcore->qlock));

		pthread_testcancel();

			 for(i = 0; i <qcount; i++)
			 {
				nextqkey = list_item(keylst, i);
				// get the queue..
				nextq = map_get(pcore->queues, nextqkey);			 	
			 	if(GetQueueSize(nextq) > 0)
			 	{
			 		crtStarvedQidWeight = (queueSizes[i] / (nextq->weight) ); //TODO
			 		crtStarvedQid = i;
			 		break;
			 	}
			 }

			 if(i == qcount)
			 {
			 	
			 	list_release(keylst);
				usleep(rconfig.schedcycle);
				continue;
			 }

			for(j = i; j < qcount; j++)
			{
				nextqkey = list_item(keylst, j);
				// get the queue..
				nextq = map_get(pcore->queues, nextqkey);
				if(( (queueSizes[j] / (nextq->weight)) < crtStarvedQidWeight) && (GetQueueSize(nextq) > 0)) //TODO
				{
					crtStarvedQid = j;
					crtStarvedQidWeight = queueSizes[j] / (nextq->weight) ; //TODO
				}
			}
			nextqid = crtStarvedQid;
			nextqkey = list_item(keylst, nextqid);
			// get the queue..
			nextq = map_get(pcore->queues, nextqkey);
			// read the queue..
			rstatus = readQueue(nextq, (void **)&in_pkt, &pktsize);//Here we get the packet size.
			
			
			if (rstatus == EXIT_SUCCESS)
			{
				writeQueue(pcore->workQ, in_pkt, pktsize);
				verbose(1, "[weightedFairScheduler---Just sent]:: Queue[%d] has now sent %lu bytes", nextqid, queueSizes[nextqid]);
				queueSizes[nextqid] = queueSizes[nextqid] + findPacketSize(&(in_pkt->data));//Storing updated data sent in array
				PacketsSent[nextqid]++;
				
			}
		
			for(i = 0; i <qcount; i++)	
			{
				nextqkey = list_item(keylst, i);
				// get the queue..
				nextq = map_get(pcore->queues, nextqkey);
				verbose(1, "Packets Queued[%d] = %d,  Bytes sent = %d, Packets Sent = %d", i, GetQueueSize(nextq), queueSizes[i], PacketsSent[i]);
			}
			list_release(keylst);

			pthread_mutex_lock(&(pcore->qlock));
			if (rstatus == EXIT_SUCCESS) 
			{
				(pcore->packetcnt)--;
			}
			pthread_mutex_unlock(&(pcore->qlock));
		
			usleep(rconfig.schedcycle);
	}
}