コード例 #1
0
ファイル: fillpack.c プロジェクト: YuZhang/fastrace
char *fill_ppk_icmpecho(const struct probing_info *pi, int *size)
{
    char *packet = new_packet(IPPROTO_ICMP, pi->option, size);

    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_ICMP, pi->src, pi->dst);
    fill_icmphdr((struct icmphdr *) (packet + sizeof(struct iphdr)),
                 *size - sizeof(struct iphdr), ICMP_ECHO, 0, _pID, _SEQ);
    return packet;
}
コード例 #2
0
ファイル: fillpack.c プロジェクト: YuZhang/fastrace
char *fill_ppk_udpbigport(const struct probing_info *pi, int *size)
{
    char *packet = new_packet(IPPROTO_UDP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_UDP, pi->src, pi->dst);
    fill_udphdr((struct udphdr *) (packet + sizeof(struct iphdr)),
                *size - sizeof(struct iphdr), _SEQ, pi->dport,
                *size - sizeof(struct iphdr), pi->src, pi->dst);
    return packet;
}
コード例 #3
0
ファイル: test_server_2way.cpp プロジェクト: thibugio/obor
bool set_pnumber(std::vector<uint8_t> data) {
    int num = decode_be(data);
    if (num > (int)packets.size()) {
        if (debug_) printf("failed to set packet number=%d\n", num);
        return false;
    }
    pnum = num;
    if (debug_) printf("set packet number=%d\n", num);
    if (num == (int)packets.size()) 
        new_packet();
    return true;
}
コード例 #4
0
ファイル: fillpack.c プロジェクト: YuZhang/fastrace
char *fill_ppk_ack(const struct probing_info *pi, int *size)
{
    int win = GET_RAND_WIN();
    uint32_t ack_seq = (_pID << 16) + _SEQ;
    char *packet = new_packet(IPPROTO_TCP, pi->option, size);

    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_TCP, pi->src, pi->dst);
    fill_tcphdr((struct tcphdr *) (packet + sizeof(struct iphdr)),
                *size - sizeof(struct iphdr), pi->sport, pi->dport,
                ack_seq, ack_seq, 0, win, 0, 0, 0, 0, 1, 0, pi->src, pi->dst);
    return packet;
}
コード例 #5
0
ファイル: reliable.c プロジェクト: charleschengxu/TCP_Reno
void sendRead(rel_t *s){
	if (s && s->inputEOF == 0) {
		int size = s->recvWindows;
		if(size > s->cwndSize){
			size = s->cwndSize;
		}
		size = (size > 9) ? 9 : size;
		while (sizeOfQueue(s->senderBuff) < size) {
			packetQueue* tempPack = new_packet();
			int dataIn = conn_input(s->c, tempPack->packet->data, 1000);
			if (dataIn == 0) {
				break;
			}
			if(dataIn > 0){
				tempPack->packet->cksum = 0;
				tempPack->packet->len = htons((16 + dataIn));
				tempPack->packet->seqno = htonl(s->seqOut);
				s->seqOut++;
				tempPack->packet->rwnd = htonl(s->recvWindows - sizeOfQueue(s->receiverBuff));
				tempPack->packet->ackno = htonl(s->seqIn);
				tempPack->packet->cksum = cksum(tempPack->packet, (16 + dataIn));
				addToQueue(&(s->senderBuff), tempPack);
				conn_sendpkt(s->c, tempPack->packet, (16 + dataIn));
			}
			else{
				s->inputEOF = 1;
				s->seqLast = s->seqOut;
				dataIn = 0;
				tempPack->packet->cksum = 0;
				tempPack->packet->len = htons((16 + dataIn));
				tempPack->packet->seqno = htonl(s->seqOut);
				s->seqOut++;
				tempPack->packet->rwnd = htonl(s->recvWindows - sizeOfQueue(s->receiverBuff));
				tempPack->packet->ackno = htonl(s->seqIn);
				tempPack->packet->cksum = cksum(tempPack->packet, (16 + dataIn));
				addToQueue(&(s->senderBuff), tempPack);
				conn_sendpkt(s->c, tempPack->packet, (16 + dataIn));
			}
		}
		return;
	}
	rel_destroy (s);
	return;
}
コード例 #6
0
void send_response(response_t *res, enum cmd_t cmd)
{
  packet_t* packet = new_packet(T_RESPONSE, cmd);
  if (packet == NULL)
    return;
  packet->body_len = 2 * sizeof(int) + res->data_len;
  packet->body = malloc(packet->body_len);
  if (packet->body)
  {
    memcpy(packet->body, (char *)res, 2 * sizeof(int));
    if (res->data_len > 0 && res->data != NULL)
      memcpy(packet->body + 2 * sizeof(int), res->data, res->data_len);
    packet->checksum = calc_checksum(packet);
    size_t size = sizeof(packet_t) - sizeof(char *) + packet->body_len;
    transmit(STDOUT, (char *)packet, size, NULL);
  }

  free_packet(packet);
}
コード例 #7
0
ファイル: Signal.cpp プロジェクト: gllort/extrae-online
/**
 * Serializes the signal object through the given MRNet stream. Used in the CPs.
 *
 * @param OutputStreamID The stream identifier.
 * @return An MRNet packet that contains the signal serialized.
 */
PACKET_PTR Signal::Serialize(int OutputStreamID )
{
  spectral_time_t  *Times  = NULL;
  spectral_time_t  *Deltas = NULL;
  spectral_value_t *Values = NULL;
  int SignalSize = 0;

  Spectral_CompressSignal( &SpectralSignal, 10000 );

  SignalSize = Spectral_SerializeSignal( SpectralSignal, &Times, &Deltas, &Values);

  PACKET_PTR new_packet( new Packet( OutputStreamID, REDUCE_SIGNAL, SIGNAL_XMIT_FORMAT,
    Times,  SignalSize,
    Deltas, SignalSize,
    Values, SignalSize ) );
  new_packet->set_DestroyData(true);

  return new_packet;
}
コード例 #8
0
ファイル: reliable.c プロジェクト: charleschengxu/TCP_Reno
void recvRead (rel_t *s){
	if (s->inputEOF != 1) {
		s->seqLast = s->seqOut;
		packetQueue *eofpacket = new_packet();
		memset(eofpacket, 0, sizeof(packetQueue));

		eofpacket->packet->len = htons(16);
		eofpacket->packet->seqno = htonl(s->seqOut);
		s->seqOut = s->seqOut + 1;
		eofpacket->packet->rwnd = htonl(s->recvWindows - sizeOfQueue(s->receiverBuff));
		eofpacket->packet->ackno = htonl(s->seqIn);
		uint16_t checksum = cksum(eofpacket->packet, 16);
		eofpacket->packet->cksum = checksum;

		conn_sendpkt(s->c, eofpacket->packet, 16);
		addToQueue(&(s->senderBuff), eofpacket);
		s->inputEOF = 1;
		return;
	}
	return;
}
コード例 #9
0
ファイル: reliable.c プロジェクト: charleschengxu/TCP_Reno
void processData (rel_t *r, packet_t *pkt, int length){
	if ( r->beginTime.tv_sec == 0 && r->beginTime.tv_usec == 0 ) {
		gettimeofday(&r->beginTime, NULL);
	}
	if (ntohl(pkt->seqno) >= 1) {
		packetQueue* newPkt = new_packet();
		memcpy(newPkt->packet, pkt, length);
		if (ntohl(pkt->seqno) == r->seqIn) {
			r->seqIn = r->seqIn + 1;
		}
		ack(r, r->seqIn);
		processAck(r, (struct ack_packet*) pkt);
		orderlyInsert(&(r->receiverBuff), newPkt);
		if (length == 16) {
			fprintf(stderr, "GET EOF\n");
			r->pairEOFed = 1;
		}
		rel_output(r);
	}
	else{
		fprintf(stderr, " wrong seqno %d \n", ntohl(pkt->seqno));
		return;
	}
}
コード例 #10
0
void TreeInit(std::vector< MRN::PacketPtr >& packets_in,
              std::vector< MRN::PacketPtr >& packets_out,
              std::vector< MRN::PacketPtr >& /* packets_out_reverse */,
              void ** /* client data */,
		        MRN::PacketPtr& /* params */,
              const MRN::TopologyLocalInfo& t)
{
   const MRN::Network* net = t.get_Network();
   network = net;
   MRN::NetworkTopology* nTop = net->get_NetworkTopology();

   MRN::NetworkTopology::Node* thisNode = nTop->find_Node(t.get_Rank());
   const std::set<MRN::NetworkTopology::Node*> children = thisNode->get_Children();
   std::set<MRN::NetworkTopology::Node*>::iterator cIt = children.begin();
  
   //int r;
   hostname[1023] = '\0';
   gethostname(hostname, 1023);
   double minPoints, eps;
   double decay, delthresh;
   double xMin, xMax, yMin, yMax;
   double axMin, axMax, ayMin, ayMax;
   unsigned int resStream;
   packets_in[0]->unpack(TreeInit_format_string,
                         &eps,
                         &minPoints,
                         &decay,
                         &delthresh,
                         &xMin, &xMax,
                         &yMin, &yMax,
                         &r,
                         &axMin, &axMax,
                         &ayMin, &ayMax,
                         &resStream);

   int nChildren = thisNode->get_NumChildren();
   
   // If message isn't intended for this node, ignore it!
   if (r == (int)t.get_Rank()){
      std::cout << "internal node successfully obtained initialization on: " << hostname << "\n";
      //std::cout << "(" << r << ") Internal node got an init packet (Parent = " << net->is_LocalNodeParent() << ", Backend = " << net->is_LocalNodeBackEnd() << ")!\n";
      // If this node is a parent, send assignments to children
      if (net->is_LocalNodeParent()) {
         // Make a packet for each child
         double mins[2], maxes[2], aMins[2], aMaxes[2];
         
         mins[0] = xMin;
         mins[1] = yMin;
         maxes[0] = xMax;
         maxes[1] = yMax;
         aMins[0] = axMin;
         aMins[1] = ayMin;
         aMaxes[0] = axMax;
         aMaxes[1] = ayMax;


         double caMins[nChildren * 2], caMaxes[nChildren * 2];

         internalNode = new InternalNode(
            2, 
            nChildren, 
            eps, 
            minPoints, 
            delthresh, 
            decay, 
            1, 
            &mins[0], &maxes[0], 
            &aMins[0], &aMaxes[0], 
            &fakeReqFunc, &fakeResFunc, 
            &caMins[0], &caMaxes[0]
         );
         
         char assignFilename[80];
         snprintf(assignFilename, 80, "/u/s/t/sturdeva/public/736/736_p2/mrnet/results/internal_assigns_%d", r);
         FILE* aFile;
         aFile = fopen(assignFilename, "w");
         internalNode->snapshot(aFile);
         fclose(aFile);//*/
         
         unsigned int cnum = 0;
         for (; cIt != children.end(); cIt++) {
            // Assign placeholder values until InternalNode's assignment
            // code is done.
            int cr = ((int)(*cIt)->get_Rank());
            
            // This is quite a packet!
            MRN::PacketPtr new_packet(
               new MRN::Packet(packets_in[0]->get_StreamId(),
               packets_in[0]->get_Tag(),
               TreeInit_format_string, 
               eps, 
               minPoints,
               decay, 
               delthresh, 
               xMin, xMax, yMin, yMax, 
               cr, 
               caMins[cnum * 2 + 0], caMaxes[cnum * 2 + 0],
               caMins[cnum * 2 + 1], caMaxes[cnum * 2 + 1],
               resStream)
            );

            packets_out.push_back(new_packet);
            cnum++;
         }
      }

      if (net->is_LocalNodeBackEnd()) {
         isLeaf = true;
         fflush(stdout);

         // Just send whatever we got to the backend code
         std::vector<MRN::PacketPtr>::iterator it = packets_in.begin();
         packets_out.push_back(*it);
      }
       
   }
}
コード例 #11
0
ファイル: Message.C プロジェクト: bwelton/mrnet
int Message::recv( XPlat_Socket sock_fd, std::list< PacketPtr > &packets_in,
                   Rank iinlet_rank )
{
    Timer t1;
    t1.start();
    ssize_t retval;
    size_t buf_len;
    uint64_t *packet_sizes;
    char *buf = NULL;
    XPlat::SocketUtils::NCBuf* ncbufs;
    uint64_t len;
    unsigned int i, j;
    int rc = 0;
    ssize_t total_bytes = 0;
    uint32_t num_packets = 0, num_buffers;
    PDR pdrs;
    enum pdr_op op = PDR_DECODE;
    bool using_prealloc = true;
    int pkt_size;
    PacketPtr pkt; 
    Stream * strm;
    std::list< PacketPtr >::iterator piter;

    retval = MRN_recv( sock_fd, _packet_count_buf, size_t(_packet_count_buf_len + 1));
    if( retval != (ssize_t)_packet_count_buf_len + 1 ) {
        mrn_dbg( 3, mrn_printf(FLF, stderr, "MRN_recv() %" PRIsszt" of %" PRIszt" bytes received\n", 
                               retval, _packet_count_buf_len));
        return -1;
    }

    pdrmem_create( &pdrs, &(_packet_count_buf[1]), _packet_count_buf_len, op, (pdr_byteorder)_packet_count_buf[0] );

    if( ! pdr_uint32(&pdrs, &num_packets) ) {
        mrn_dbg( 1, mrn_printf(FLF, stderr, "pdr_uint32() failed\n") );
        return -1;
    }
    
    num_buffers = num_packets * 2;

    //
    // packet size vector
    //

    // buf_len's value is hardcoded, breaking pdr encapsulation barrier :(
    buf_len = (sizeof(uint64_t) * num_buffers) + 1;  // 1 byte pdr overhead
           
    if( num_buffers < _ncbuf_len ) {
        buf = _packet_sizes_buf;
        packet_sizes = _packet_sizes;
        ncbufs = _ncbuf;
        memset( (void *)_ncbuf, 0, sizeof(_ncbuf) );
    }
    else {
        using_prealloc = false;
        buf = (char*) malloc( buf_len );
        packet_sizes = (uint64_t*) malloc( sizeof(uint64_t) * num_buffers );
        ncbufs = new XPlat::SocketUtils::NCBuf[num_buffers];
        memset( (void*)ncbufs, 0,
                 num_buffers * sizeof(XPlat::SocketUtils::NCBuf) );
    }

    retval = MRN_recv( sock_fd, buf, buf_len );
    if( retval != (ssize_t)buf_len ) {
        mrn_dbg( 3, mrn_printf(FLF, stderr, "MRN_recv() %" PRIsszt" of %" PRIsszt" bytes received\n", 
                               retval, buf_len ));
        rc = -1;
        goto recv_cleanup_return;
    }

    pdrmem_create( &pdrs, buf, buf_len, op, pdrmem_getbo() );

    if( ! pdr_vector(&pdrs, (char*)packet_sizes, num_buffers,
                     sizeof(uint64_t), (pdrproc_t)pdr_uint64) ) {
        mrn_dbg( 1, mrn_printf(FLF, stderr, "pdr_vector() failed\n" ));
        rc = -1;
        goto recv_cleanup_return;
    }


    /* NOTE: we tell users that packet header and data buffers will have similar
             alignment characteristics to malloc, so if we ever stop using malloc
             we will need to make sure that the buffers are properly aligned */
    for( i = 0; i < num_buffers; i++ ) {
        len = packet_sizes[i];
        ncbufs[i].buf = (char*) malloc( size_t(len) );
        ncbufs[i].len = size_t(len);
        total_bytes += size_t(len);
    }

    retval = XPlat::SocketUtils::Recv( sock_fd, ncbufs, num_buffers );
    if( retval != total_bytes ) {
        mrn_dbg( 1, mrn_printf(FLF, stderr, "SocketUtils::Recv %" PRIsszt" of %" PRIsszt" bytes received\n", 
                               retval, total_bytes) );
        rc = -1;
        goto recv_cleanup_return;
    }

    //
    // post-processing
    //

    for( i = 0, j = 0; j < num_packets; i += 2, j++ ) {
        PacketPtr new_packet( new Packet((unsigned int)ncbufs[i].len,
                                         ncbufs[i].buf,
                                         ncbufs[i+1].len,
                                         ncbufs[i+1].buf,
                                         iinlet_rank) );

        if( new_packet->has_Error() ) {
            mrn_dbg( 1, mrn_printf(FLF, stderr, "packet creation failed\n") );
            rc = -1;
            goto recv_cleanup_return;
        }
        packets_in.push_back( new_packet );
        ncbufs[i].buf = NULL;
        ncbufs[i+1].buf = NULL;        
    }

    t1.stop();
    pkt_size = (int) packets_in.size();
    piter = packets_in.begin();
    for( ; piter != packets_in.end(); piter++ ) {
        pkt = *piter;
        strm =  _net->get_Stream( pkt->get_StreamId() );
        if( strm != NULL ) {
            // Time for packet at this point in time.
            if( strm->get_PerfData()->is_Enabled(PERFDATA_MET_ELAPSED_SEC, 
                        PERFDATA_CTX_PKT_RECV) ) {
                pkt->set_Timer(PERFDATA_PKT_TIMERS_RECV, t1);
            }
            pkt->start_Timer(PERFDATA_PKT_TIMERS_RECV_TO_FILTER);
            pkt->set_IncomingPktCount(pkt_size);
        }
    }
 recv_cleanup_return:

    if( -1 == rc ) {
        for( unsigned u = 0; u < num_buffers; u++ ) {
            if( NULL != ncbufs[u].buf )
                free( (void*)(ncbufs[u].buf) );
        }
    }

    if( ! using_prealloc ) {
        free( buf );
        free( packet_sizes );
        delete[] ncbufs;
    }

    mrn_dbg_func_end();
    return rc;
}