[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

No Subject



Wei,

You must have tried this, but did you re-build all modules?

Out of curiosity, why don't you add a new header instead of expanding
hdr_cmn?  It is often better not to add a specific functionality to a
general-purpose data structure.

Nader


>>> "Wei" == Wei Wang <[email protected]> writes:

Wei> I am wondering how I can put new fields into hdr_cmn.  The
Wei> following is the piece of code I added to "packet.h",

Wei> struct hdr_cmn { int ptype_; // packet type (see above) ...  int
Wei> marker_; // static int offset_; // offset for this header inline
Wei> static int& offset() { return offset_; } inline static hdr_cmn*
Wei> access(Packet* p) { return (hdr_cmn*) p->access(offset_); }
	
Wei> /* per-field member functions */ inline int& ptype() { return
Wei> (ptype_); } ...  inline int& marker() { return (marker_); } };

Wei> Here is how I try to access it in a new Connector,

Wei> void Marker::recv(Packet* pkt, Handler* h) { hdr_cmn* hdr =
Wei> (hdr_cmn*) pkt->access(off_cmn_); count_++; cout << "-- " <<
Wei> hdr->ptype() << "," << hdr->g_marker() << "," << hdr->size() <<
Wei> "," << hdr->uid() << "," << hdr->timestamp() << "," <<
Wei> hdr->ref_count() << endl;
hdr-> marker() = count_;
Wei> send(pkt, h); }

Wei> where count_ just records the number of packets pass by this
Wei> Connector.  The following is the output of the program,

Wei> -- 2,1953066341,500,0,800,0 -- 2,1881154670,500,1,840,0 --
Wei> 2,1633969266,500,2,880,0 -- 2,1,500,3,920,0 -- 2,2,500,4,960,0 --
Wei> 2,3,500,5,1000,0 -- 2,4,500,6,1040,0 -- 2,5,500,7,1080,0 --
Wei> 2,6,500,8,1120,0 -- 2,7,500,9,1160,0 -- 2,8,500,10,1200,0 --
Wei> 2,9,500,11,1240,0 -- 2,10,500,12,1280,0 -- 2,11,500,13,1320,0 --
Wei> 2,12,500,14,1360,0 -- 2,13,500,15,1400,0 -- 2,14,500,16,1440,0 --
Wei> 2,15,500,17,1480,0 -- 2,16,500,18,1520,0 -- 2,17,500,19,1560,0

Wei> It seems that the field I put there doesn't behaves as I
Wei> expected.  Even if I try to initialize marker_ in a constructor
Wei> of sturct hdr_cmn, it always gives me strange values like
Wei> "1953066341", "1881154670", and "1633969266" shown above. Then
Wei> sundenly everything becomes 1, 2, 3, ... which looks like the
Wei> packets get back after I changed the field marker_. Does this
Wei> mean in ns-2, there is some memory recycling modules try to use
Wei> some freed packets again? But even if that's the case, I don't
Wei> know why I cannot initialized the field to be zero.

Wei> Any helps are appreciated. Thanks in advance.

Wei> Wei.