Beispiel #1
0
void sr_handlepacket(struct sr_instance* sr,
        uint8_t * packet/* lent */,
        unsigned int len,
        char* interface/* lent */)
{
  /* REQUIRES */
	assert(sr);
	assert(packet);
	assert(interface);
	printf("*** -> Received packet of length %d \n",len);
	
	//print_hex2(packet, len);
	EthernetFrame * frame = new EthernetFrame(packet, len);
	switch(frame->GetType())
	{
		case ARP_PACKET:
		{
			sr_arpcache_insert(&sr->cache, frame->GetSrcAddress(), flip_ip(get_int(frame->GetPayload()+12)));
			handle_arp_packet(sr, frame, interface);
			break;
		}
		case IP_PACKET:
		{
			//
			sr_arpcache_insert(&sr->cache, frame->GetSrcAddress(), flip_ip(get_int(frame->GetPayload()+12)));
			handle_ip_packet(sr, frame, interface);
		}
		break;
		default:
			cerr << "Not a packet" << endl;
	}
	delete frame;
}/* end sr_ForwardPacket */
Beispiel #2
0
// for debugging and profiling
void rotate_core(int dim, pixel *src, pixel *dst, int D) 
{
    if (dim < 256)
    {
#if DEBUG_PRINT
        log("doing improved naive rotate");
#endif
        new_rotate(dim, src, dst, D*2, D/2);
    }
    else
    {
#if DEBUG_PRINT
        log("doing 2 step rotate on input size %d", dim);
#endif

#if DEBUG_PROFILE_TIME
        clock_t test, start, middle, end;
        
        test = clock();
        copy_block(dim, src, dst, D);
        start = clock();
#elif DEBUG_PROFILE_TIMES
        unsigned test, start, middle, end;
        
        test = get_seconds();
        copy_block(dim, src, dst, D);
        start = get_seconds();
#endif

        // transpose the image in src and store
        transpose_block(dim, src, dst, D);

#if DEBUG_PROFILE_TIME
        middle = clock();
#elif DEBUG_PROFILE_TIMES
        middle = get_seconds();
#endif

        // perform row exchange on the transposed image
        flip_ip(dim, dst);

#if DEBUG_PROFILE_TIME
        end = clock();
        log("test took %u transpose took %u and flip took %u", (float)start - (float)test, (float)middle - (float)start, (float)end - (float)middle);
#elif DEBUG_PROFILE_TIMES
        end = get_seconds();
        log("test took %u transpose took %u and flip took %u", start - test, middle - start, end - middle);
#endif
    }
}