[ns] Creating a new header in NS2

Eclipse612 Eclipse612 at hotmail.com
Fri Jul 17 07:36:02 PDT 2009




Eclipse612 wrote:
> 
> Hi everyone,
> 
> I'm trying to develop a p2p module for NS2, and I've included a new header
> and packet type into it. These are the things I did:
> 
> 1) I defined the new header in a couple of files ( a ".h" and a ".cc")
> using the struct and the mapping class as explained in tutorials, like
> this:
> 
> struct FakePayload
> {
> 	vector<string> payload_;
> };
> 
> //C++ p2p Header Structure
> 
> struct hdr_p2p
> {
> 	string headerType_;		// this is a p2p application packet
> 	static int offset_; 		//offset of the p2p header first bit in the packet
>         string aduType_;         	// Could be: exploratory packet,
> location_info, resource_confirmation,application_data
> 	string idFile_;         	//resource identifier, nonzero only if
> aduType_="application_data"
> 	int idPart_;			//part identifier, nonzero only if
> aduType_="application_data"
> 	FakePayload fakePayload_; 	//dummy payload, used to insert info that
> shouldn't be in the header. We avoid using Appdata as recommended by
> Teerawat.
> 	double timestamp_;		// time of the packet forwarding
> 
> 	//header access methods
> 
>         string& headerType() { return headerType_; }
> 	inline static int& offset() { return offset_; }
>         string& aduType() { return aduType_; }
> 	string& idFile() { return idFile_; }
>         int& idPart() { return idPart_; }
> 	double& timestamp() { return timestamp_; }
> 	FakePayload& fakePayload() {return fakePayload_;}
> 	inline static hdr_p2p* access (const Packet* p)
> 		{return (hdr_p2p*) p->access(offset_); }
> };
> 
> int hdr_p2p::offset_;
> 
> // C++ Header Mapping Class
> 
> static class p2pHeaderClass : public PacketHeaderClass
> {
> 	public:
> 	p2pHeaderClass(): PacketHeaderClass ("PacketHeader/p2p", sizeof(hdr_p2p))
> 		{ bind_offset(&hdr_p2p::offset_); }
> } class_p2phdr;
> 
> 2) I edited packet.h and ns-packet.tcl that way:
> 
> Added 
> 
> p2p     #In use for p2p downloading time optimization experiments
> 
> to the "foreach prot" cycle in ns-packet.tcl;
> 
> Added
> 
> " static const packet_t PT_P2P = 62; "
> 
> just before the NTYPE, and
> 
> " name_[PT_P2P]="p2p"; "
> 
> to packet.h.
> 
> 
> 
> I verified - using some puts - that the p2p header is added to the packet
> header when I allocate a packet, being the first header with offset_ = 0. 
> The problem raises when, on a freshly allocated packet, I try to access
> the p2p header. The call to hdr_p2p::access(p) seems to be succesful, but
> when I try to get one  of the data members of the hdr_p2p struct (by cout
> or by writing into them), I get a segmentation fault.
> If I try to access one of the other protocol specific headers on the same
> packet, everything is right and working.
> 
> What did I do wrong? It looks like the allocation procedure just reserves
> space for the new header, but actually doesn't create any hdr_p2p object,
> thus causing the segmentation fault. 
> 
> Thanks in advance for your help!
> 
> Stefano Vecchi 
> 
> 
> 
> 


I tried some debugging and found out that segmentation fault is caused only
by string types in the header. If I remove them, everything is right. Is
there any restriction using strings in a new header struct?
I hope someone can help...thank you very much in advance.

-- 
View this message in context: http://www.nabble.com/Creating-a-new-header-in-NS2-tp24478797p24535676.html
Sent from the ns-users mailing list archive at Nabble.com.



More information about the Ns-users mailing list