HOWTO create a new type of protocol header or trailer

From Nsnam
Revision as of 13:16, 22 May 2009 by Jpelkey (Talk | contribs) (HOWTO create a new type of protocol header or trailer)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Main Page - Current Development - Developer FAQ - Tools - Related Projects - Project Ideas - Summer Projects

Installation - Troubleshooting - User FAQ - HOWTOs - Samples - Models - Education - Contributed Code - Papers

At some point you may wish to create a new or existing protocol which is currently not implemented in ns-3. This protocol will likely require a new type of header. Creating a new header or trailer for this protocol is relatively straightforward and requires subclassing the ns3::Header class described below.

HOWTO make and use a new application

The key is to implement a new subclass of the ns3::Header base class to represent your protocol header:

   class YHeader : public Header
     // must be implemented to become a valid new header.
     static TypeId GetTypeId (void);
     virtual TypeId GetInstanceTypeId (void) const;
     virtual uint32_t GetSerializedSize (void) const;
     virtual void Serialize (Buffer::Iterator start) const;
     virtual uint32_t Deserialize (Buffer::Iterator start);
     virtual void Print (std::ostream &os) const;
     // allow protocol-specific access to the header data.
     void SetData (uint32_t data);
     uint32_t GetData (void) const;
     uint32_t m_data;