当前位置: 首页>>代码示例>>C++>>正文


C++ PacketHdr类代码示例

本文整理汇总了C++中PacketHdr的典型用法代码示例。如果您正苦于以下问题:C++ PacketHdr类的具体用法?C++ PacketHdr怎么用?C++ PacketHdr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PacketHdr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

void *bcast(void *arg){

struct cShared *sh = (struct cShared *)arg;
//char *msg= (char *)msg1;
mySendingPort *my_send_port1 = sh-> my_send_port;

while(1){
  Packet *my_packet = new Packet();
  PacketHdr *hdr = my_packet->accessHeader();
  hdr->setOctet(ANNOUNCEMENT,0);

  cout<<"into thread"<<endl;
  list<int>::iterator p1 = list1.begin();
  while(p1 != list1.end()){
      
      hdr->setOctet((unsigned char)(*p1),1);
      cout<<"sending pkt "<<*p1<<endl;
      //my_send_port1->setACKflag(true);
      my_send_port1->sendPacket(my_packet);
      
      p1++;
      
  }

//  sem_wait(&mutex);
  pthread_mutex_lock(&lock);
 // cout<<msg<<endl;
  pthread_mutex_unlock(&lock);
//  sem_post(&mutex);
  sleep(10);
  }
return 0;

}
开发者ID:mJaiswal,项目名称:Communication-Network-2-CDN-Project,代码行数:34,代码来源:sender.cpp

示例2: while

void *MakeAnnouncementPacket(void *arg){
    cout << "Start: Make announcement function." <<endl;
    
    struct SPShared *sp = (struct SPShared *)arg;
    while(1){
        
        int i;
        Packet *packet = new Packet();
        PacketHdr *hdr;
        
        for(i = 0; i< ListOfContents.size(); i++){
            packet = new Packet();
            hdr = packet->accessHeader();
            hdr->setOctet('2',0);
            hdr->setOctet(ListOfContents.at(i),1);
            hdr->setOctet(0,2);
           
            sp->send_port->sendPacket(packet);
            //sp->send_port->setACKflag(true);
            //sp->send_port->timer_.startTimer(0);
        }

        usleep(10000000);
    }
}
开发者ID:priyankbharad,项目名称:ContentBasedNetwork,代码行数:25,代码来源:ping-client.cpp

示例3: Packet

Packet *Message::make_response_packet(int CID, int HID, const char *filename){
	Packet * response_packet;
	response_packet = new Packet();

	//get some info of the file
	//read file
	ifstream f1(filename);
	f1.seekg(0, ios::end);
	int len = (int)f1.tellg();
	f1.seekg(0, f1.beg);
	char *datachunk = new char[len];
	f1.read(datachunk, len);
	f1.close();

	//Header
	PacketHdr *hdr = response_packet->accessHeader();
	hdr->setOctet(TYPE_RESPONSE, POS_TYPE );
	hdr->setOctet(CID, POS_CID );
	hdr->setOctet(HID, POS_HID );
	hdr->setShortIntegerInfo(len, POS_SIZE);

	// fill payload by content...
	response_packet->fillPayload(len, datachunk);

	return response_packet;
}
开发者ID:telescreen,项目名称:commnet2-project3,代码行数:26,代码来源:message.cpp

示例4: forward_rxed_data_packet_to_port

int* Router::forward_rxed_data_packet_to_port(Packet* p){
	PacketHdr *hdr = p->accessHeader();
	char p_type = hdr->getOctet(PACKET_TYPE_INDEX);
	if(p_type != 'm'){ //check for packet type
		std::cout << "This function is supposed to be given DATA packet. This has another type !\n";
		exit(1);
	}
	//Extract necessary info for giving the forwarding decision
	char num_addr = hdr->getOctet(NUM_ADDR_INDEX);
	int int_num_addr = (int)(num_addr-'0');
	int* d_p = new int[int_num_addr];
	char dest_addrs_buffer[int_num_addr+1];
	for(int i=0; i < num_addr; i++){
		dest_addrs_buffer[i]=hdr->getOctet(NUM_ADDR_INDEX+i+1);
	}
	dest_addrs_buffer[num_addr] = (char)'/0';
	/*
	std::cout << "=============================================\n";
	std::cout << "int_num_addr: " << int_num_addr << " dest_addrs_buffer: " 
					  << dest_addrs_buffer << std::endl;
	std::cout << "=============================================\n";
	*/
	if(int_num_addr == 1){//unicast packet
		*d_p = ftf_p->forward_to_port(int_num_addr, (char*)dest_addrs_buffer, &d_p);
	}
	else{ //MC packet
		ftf_p->forward_to_port(int_num_addr, (char*)dest_addrs_buffer, &d_p);
	}	
	return d_p;
}
开发者ID:mfatihaktas,项目名称:comnet2,代码行数:30,代码来源:router.cpp

示例5: Packet

Packet* Router::create_control_packet(char p_type){
	Packet * my_packet = new Packet();
	PacketHdr *hdr = my_packet->accessHeader();
	
	if(p_type == 'd'){ //Packet is discovery type
		//Setting the specific header fields
		hdr->setOctet('d',0);
		hdr->setOctet(id,1);

		return my_packet;
	}
	else if(p_type == '1'){
		//Disc Ack packet type is '1'
		hdr->setOctet('1',0);
		hdr->setOctet(id,1);
		
		return my_packet;
	}
	else if(p_type == 'l'){ //Packet is LSP type
		hdr->setOctet('l',0);
		hdr->setOctet('8',1);//TTL
		hdr->setOctet(id,2); //src_addr = id
		hdr->setOctet(num_neighbors,3);
		for(int i=0; i<num_neighbors; i++){
			hdr->setOctet(nbr_tbl.at(i).id[0], 3+i+1);
		}
		++ls_seq_num; //inc for the next ls packet formation
		
		return my_packet;
	}
}
开发者ID:mfatihaktas,项目名称:comnet2,代码行数:31,代码来源:router.cpp

示例6: GetContent

/*!
   \brief Request a certain content by id

   Function to send a packet requesting content and to resend the request if not received on the receiving thread
 */
void GetContent(string contentId, struct res *args)
{
    Packet *req_packet;
    req_packet = new Packet();
    req_packet->setPayloadSize(0); //No Payload

    PacketHdr *rqhdr = req_packet->accessHeader();

    rqhdr->setHeaderSize(3); //Need 3 bytes for the header
    rqhdr->setOctet('0',0); //Request packet = type 0
    rqhdr->setOctet((char)host_id,2); //Setting host id

    int contentId_int = atoi(contentId.c_str());

    rqhdr->setOctet((char)contentId_int,1); //Setting content request message

    args->my_req_port->sendPacket(req_packet);
    args->my_req_port->lastPkt_ = req_packet;
    //cout<<"First octet "<<rqhdr->getOctet(0)<<"Second Octet "<<rqhdr->getOctet(1)<<"Third Octet "<<rqhdr->getOctet(2)<<endl;

    gettimeofday(&rtt, NULL);
    cout<<"Sent Request"<<endl;
    args->my_req_port->setACKflag(false);
    args->my_req_port->timer_.startTimer(5);

    while(!args->my_req_port->isACKed())
    {
        sleep(1);
        if(!args->my_req_port->isACKed())
        {
            sleep(3);
            if(!args->my_req_port->isACKed())
            {
                sleep(5);
                if(!args->my_req_port->isACKed())
                {
                    sleep(7);
                    if(!args->my_req_port->isACKed())
                    {
                        sleep(9);
                        if(!args->my_req_port->isACKed())
                        {
                            cout<<"Giving up.."<<endl;							
                            args->my_req_port->setACKflag(true);
                        }	
                    }
                }
            }
        } 
        else{return;}
    }
    return;
}
开发者ID:AishwaryaBabu,项目名称:content_based_network_winlab,代码行数:58,代码来源:client.cpp

示例7: Packet

/**
 * Create an ACK message
 */
Packet *Message::make_ack_packet(int seqNum){
	Packet *ack_packet;
	ack_packet = new Packet();
	ack_packet->setPayloadSize(0);

	//Header
	PacketHdr *hdr = ack_packet->accessHeader();
	hdr->setIntegerInfo(RECEIVER_ID, ID_POS);
	hdr->setShortIntegerInfo(ACK_MESSAGE_TYPE, TYPE_POS);
	hdr->setIntegerInfo(seqNum, SEQNUM_POS); // sequence number being ACKED

	return ack_packet;
}
开发者ID:viethnguyen,项目名称:commnet2-project2,代码行数:16,代码来源:message.cpp

示例8: MakeRequest

void MakeRequest(mySendingPort *my_port, unsigned char content_id){
    
    Packet *new_request_packet = new Packet();
    PacketHdr *hdr = new_request_packet->accessHeader();
    hdr->setOctet('0',0);
    hdr->setOctet(content_id,1);
    hdr->setOctet(HOST_ID,2);
    my_port->sendPacket(new_request_packet);
    cout<<"Packet Sent"<<endl;
    my_port->setACKflag(false);
    my_port->lastPkt_= new_request_packet;
    my_port->timer_.startTimer(10);
    ind->receive_ind = '0';
    ind->content_requested_id = content_id;
    
}
开发者ID:priyankbharad,项目名称:ContentBasedNetwork,代码行数:16,代码来源:ping-client.cpp

示例9: send_ls_to_outgoing_ports

void Router::send_ls_to_outgoing_ports(char* incoming_TxP, Packet* p){
	PacketHdr *hdr = p->accessHeader();
	std::cout << "LS packed rxed from node_id" << hdr->getOctet(2) << " is sent to outgoing ports" 
						<< " with TTL:" << hdr->getOctet(1) << std::endl;
	int counter = 0;
	for(int i=0; i<num_neighbors; i++){
		if(strcmp(nbr_tbl.at(i).TxP, incoming_TxP) != 0){ //Do not send it to incoming port
			try{
				++counter;
				txing_ports[i]->sendPacket(p);
			}catch(const char *reason){
				cerr << "Exception:" << reason << endl;
			}
		}
		std::cout << "Incoming LS packet is forwarded to " << counter
							<< " outgoin ports\n";
	}
}
开发者ID:mfatihaktas,项目名称:comnet2,代码行数:18,代码来源:router.cpp

示例10: extract_ls_info

void Router::extract_ls_info(Packet* lsp){
	PacketHdr *hdr = lsp->accessHeader();
	char id = hdr->getOctet(2);
	if(std::find(graph_name.begin(), graph_name.end(), id) != graph_name.end()){
		std::cout << "Connectivity info of node_id: " << id << " is already in graph_name\n";
		std::cout << "here comes the graph_name: ";
		for( std::vector<char>::const_iterator i = graph_name.begin(); i != graph_name.end(); ++i)
  	  std::cout << *i << '-';
		std::cout << std::endl;
		return;
	}
	graph_name.push_back(id);
	
	std::cout << "here comes the graph_name: ";
	for( std::vector<char>::const_iterator i = graph_name.begin(); i != graph_name.end(); ++i)
    std::cout << *i << '-';
	std::cout << std::endl;
	
	//Extract the connectivity info
	/*
	//Check the seq_num
	hdr->getOctet(1);
	*/
	int num_nhops = hdr->getOctet(3);
	char* nhops = new char[num_nhops+1];
	for(int i=0; i<num_nhops; i++){
		nhops[i] = hdr->getOctet(3+i+1);
	}
	nhops[num_nhops] = (char)'\0';
	netnode_nhops.insert (std::pair<char,char*>(id, nhops));
	
	
	if(graph_name.size() == num_of_total_nodes){
		std::cout << "CONNECTIVITY INFO FROM EACH NODE IS EXTRACTED YAY !\n";
		build_map();
	}
}	
开发者ID:mfatihaktas,项目名称:comnet2,代码行数:37,代码来源:router.cpp

示例11: send_data_packet

void Router::send_data_packet(Packet* p){
	//std::cout << "The following packet ll be sent:" << std::endl;
	//print_data_packet(p);
			
	PacketHdr *hdr = p->accessHeader();
	char num_addr = hdr->getOctet(NUM_ADDR_INDEX);
	int int_num_addr = (int)(num_addr-'0');
	
	
	if(int_num_addr == 1 && hdr->getOctet(NUM_ADDR_INDEX+1) == id){ //if the packet is uni and targeted to me
		std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
		std::cout << "DATA PACKET TARGETED TO ME IS RXED: \n";
		print_data_packet(p);
		std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
		return;
	}
	int* f_ports = forward_rxed_data_packet_to_port(p);
	//Use the "goodness" of at most 3 MC receivers
	std::vector <int> ports_done;
	std::vector <char> temp_dests;
	
	for(int i=0; i<int_num_addr; i++){
		int curr_port = f_ports[i];
		temp_dests.clear();
		if(std::find(ports_done.begin(), ports_done.end(), curr_port) == ports_done.end()){ //not contained
			temp_dests.push_back(hdr->getOctet(NUM_ADDR_INDEX+i+1));
			for(int j=i+1; j<int_num_addr; j++){
				if(curr_port == f_ports[j])
					temp_dests.push_back(hdr->getOctet(NUM_ADDR_INDEX+j+1));
			}
			char* dest_addrs = new char[temp_dests.size()+1];
			for(int k=0; k<temp_dests.size(); k++){
				dest_addrs[k] = temp_dests.at(k);
			}
			dest_addrs[temp_dests.size()] = (char)'\0';
			//hdr->getOctet(PAYLOAD_SIZE_INDEX(temp_dests.size()))
			int payload_size = strlen(p->getPayload());
			char* payload = new char[payload_size];
			strcpy(payload, p->getPayload());
			Packet* new_p = create_data_packet('m', (char)((int)(hdr->getOctet(TTL_INDEX)-'0')-1), 
																			hdr->getOctet(SRC_ADDR_INDEX),
																			'0'+temp_dests.size(), dest_addrs,
																			payload_size,	payload);
			send_packet_over_port(new_p, curr_port);
			//std::cout << "The following packet ll be sent over port:" << curr_port << std::endl;
			//print_data_packet(p);
			//
			ports_done.push_back(curr_port);
		}
	}
	
}
开发者ID:mfatihaktas,项目名称:comnet2,代码行数:52,代码来源:router.cpp

示例12: print_data_packet

void Router::print_data_packet(Packet* p){
	//First print the header
	PacketHdr *hdr = p->accessHeader();
	
	std::cout << "PRINT PACKET with Header size: " <<hdr->getSize() << "\n";
	std::cout << "packet_type: " <<hdr->getOctet(PACKET_TYPE_INDEX) << "\n";
	std::cout << "ttl: " << hdr->getOctet(TTL_INDEX) << "\n";
	std::cout << "src_addr: " << hdr->getOctet(SRC_ADDR_INDEX) << "\n";
	char num_addr = hdr->getOctet(NUM_ADDR_INDEX);
	std::cout << "num_addr: " << num_addr << "\n";
	
	int int_num_addr = (int)(num_addr-'0');
	char dest_addrs_buffer[int_num_addr+1];
	for(int i=0; i < int_num_addr; i++){
		dest_addrs_buffer[i]=hdr->getOctet(NUM_ADDR_INDEX+i+1);
	}
	dest_addrs_buffer[int_num_addr]='\0';
	std::cout << "dst_addrs: " << dest_addrs_buffer << "\n";
	//Second print the payload
	//std::cout << "payload_size: " << hdr->getOctet(PAYLOAD_SIZE_INDEX(int_num_addr)) << "\n";
	std::cout << "packet_payload: " << p->getPayload() << "\n\n";
}
开发者ID:mfatihaktas,项目名称:comnet2,代码行数:22,代码来源:router.cpp

示例13: get_packet_type

int Message::get_packet_type(Packet *p){
	PacketHdr *hdr = p->accessHeader();
	return (int) hdr->getOctet(POS_TYPE);
}
开发者ID:telescreen,项目名称:commnet2-project3,代码行数:4,代码来源:message.cpp

示例14: pthread_mutex_lock

void* Router::listen_on_port(void* thread_id){
	int* tid = (int *)(thread_id);
	pthread_mutex_lock( &mutex_lop );
	int tlocal_tid = *tid;
	pthread_mutex_unlock( &mutex_lop );
  cout<<endl<<"Starting to listen on port " << nbr_tbl.at(tlocal_tid).RxP<<"......\n";
  PacketHdr *hdr;

  while(1){
  	Packet* rxed_p = rxing_ports[tlocal_tid]->receivePacket();
  	hdr = rxed_p->accessHeader();
  	if(hdr->getOctet(0) == 'd'){ //Hello packet is rxed
  		cout << "Disc packet is rxed from node_id: " << hdr->getOctet(1)
  				 << " over rx_port:" << nbr_tbl.at(tlocal_tid).RxP << endl;
  		//Send Hello Ack
    	try{
	  		txing_ports[tlocal_tid]->sendPacket(create_control_packet('1'));
		  }catch(const char *reason){
  			cerr << "Exception:" << reason << endl;
  		}
  	}
  	else if(hdr->getOctet(0) == '1'){ //Hello Ack is rxed
  		cout << "Hello Ack is rxed from node_id: " << hdr->getOctet(1)
  				 << " over rx_port:" << nbr_tbl.at(tlocal_tid).RxP << endl;
  		//Set the nhop_hello_ack_rxed map correctly to indicate the ACK is rxed from the nhop
  		nhop_hello_ack_rxed.find(hdr->getOctet(1))->second = 1;
  		/*
  		//print nhop_hello_ack_rxed
  		std::map<char,int>::iterator it;
  		std::cout << "nhop_hello_ack_rxed:\n";
  		for (it=nhop_hello_ack_rxed.begin(); it!=nhop_hello_ack_rxed.end(); ++it){
			if(it->second == 0){
					std::cout << it->first << " -> " << it->second << std::endl;
				}
			}
			*/
  	}
  	else if(hdr->getOctet(0) == 'l'){ //LSP packet is rxed
  		cout << "LSP packet is rxed from node_id: " << hdr->getOctet(2)
  				 << " over rx_port:" << nbr_tbl.at(tlocal_tid).RxP << endl;
  		//Extract the connectivity info
  		extract_ls_info(rxed_p);
  		//Send it to outgoing ports
  		int ttl = (int)(hdr->getOctet(1)-'0');
  		
  		//std::cout << "----------------------------------------\n";
  		//std::cout << "LS TTL: " << hdr->getOctet(1) << std::endl;
  		if( ttl != 0){ //check ttl if it is 0 then discard:dont forward further
  			--ttl;
  			hdr->setOctet( (char)('0'+ttl),1);
  			//std::cout << "UPDATED LS TTL: " << hdr->getOctet(1) << std::endl;	
	  		send_ls_to_outgoing_ports(nbr_tbl.at(tlocal_tid).TxP, rxed_p);
	  	}
	  	//std::cout << "----------------------------------------\n";
	  	
		}
		else if(hdr->getOctet(0) == 'm'){ //Data packet is rxed
			cout << "\nDATA packet is rxed from node_id: " << hdr->getOctet(2)
  				 << " over rx_port:" << nbr_tbl.at(tlocal_tid).RxP << endl;
			forward_incoming_data_packet(rxed_p);
		}
  	else{
  		cout << "Some packet with unrecognized type is rxed\n";
  	}
  }
}
开发者ID:mfatihaktas,项目名称:comnet2,代码行数:66,代码来源:router.cpp

示例15: get_packet_size

int Message::get_packet_size(Packet *p){
	PacketHdr *hdr = p->accessHeader();
	return (int) hdr->getShortIntegerInfo(POS_SIZE);

}
开发者ID:telescreen,项目名称:commnet2-project3,代码行数:5,代码来源:message.cpp


注:本文中的PacketHdr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。