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

No Subject



I am wondering how I can put new fields into hdr_cmn.

The following is the piece of code I added to "packet.h",

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

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

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

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

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

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

Any helps are appreciated. Thanks in advance.

Wei.