Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

NpPacket Class Reference

An NP packet contains (in this order): -------------------------------------- Version Number (4 bits) Packet Type (4 bits) Length (2 bytes) VCN (4 bytes). More...

#include <NpPacket.h>

Inheritance diagram for NpPacket::

Packet BasicObject ConnectionPacket DiscoveryPacket FinPacket ImHerePacket List of all members.

Public Methods

 NpPacket ()
 Create a default packet. More...

 NpPacket (NpType type, unsigned int vcn)
 Used to create control packets. More...

 NpPacket (TpPacket *packet, unsigned int vcn)
 data packets. More...

 NpPacket (unsigned char *rawData)
 Parse the raw packet. More...

virtual ~NpPacket ()
int getVersionNumber ()
unsigned int getVcn ()
unsigned char * getData ()
unsigned int getDataLength () const
virtual unsigned char * getRawData ()
 Used by the Node.writePacket function right before sending over network. More...

unsigned int getRawLength () const
 Return the length of the entire packet, including headers. More...

NpType getPacketType () const
 Return the type of packet. More...

bool isControlPacket () const
 Return true if this packet is anything but a data packet. More...

virtual unsigned int getHeaderLength ()
 Return the length of the header, in bytes. More...

void setVersionNumber (int)
void setVcn (unsigned int vcn)
void setPacketType (NpType type)
int write (ConnectionInterface *)
 Write the specified packet to the Connection. More...

virtual void toStream (std::ostream &)
 Gets the length of the whole packet and makes sure the length makes sense. More...

void dumpHeader (std::ostream &out)
 Dumps hex output of the packet header. More...

void dumpData (std::ostream &out)
 Dumps hex output of the data portion of the packet. More...

char * getControlTypeString () const
 Return a string that describes the packet type. More...


Static Public Methods

NpPacket * createPacket (NpType)
 Use this function to create any type of packet you want. More...

NpPacket * decode (unsigned char *rawData, NpType packetType)
 Creates the correct type of packet from the rawData. More...

unsigned int getHeaderLength (NpType packetType)
int parseMiniHeader (unsigned char *rawData, unsigned int *rawLength, int *versionNumber, NpType *packetType)
 This function decodes and checks the packet type and length. More...

NpPacket * read (ConnectionInterface *)
 Read a packet from the Connection. More...


Protected Attributes

NpType m_controlType
 packet type. More...

unsigned short m_length
 the payload length; header length is fixed. More...

unsigned int m_vcn
 Source VCN of requester. More...

unsigned char * m_data
 The data portion of the packet. More...

unsigned char * m_rawData
 the entire packet, including the header. More...

unsigned int m_headerLength
 length of the packet header (not variable). More...

int m_versionNumber
 Version number. More...


Detailed Description

An NP packet contains (in this order): -------------------------------------- Version Number (4 bits) Packet Type (4 bits) Length (2 bytes) VCN (4 bytes).

Definition at line 12 of file NpPacket.h.


Constructor & Destructor Documentation

NpPacket::NpPacket
 

Create a default packet.

Definition at line 17 of file NpPacket.cpp.

Referenced by createPacket(), and decode().

NpPacket::NpPacket NpType type,
unsigned int vcn
 

Used to create control packets.

Parameters:
type   The type of control packet.
vci   The Virtual Circuit that this packet will be sent out on.

Definition at line 34 of file NpPacket.cpp.

NpPacket::NpPacket TpPacket * data,
unsigned int vcn
 

data packets.

Definition at line 49 of file NpPacket.cpp.

NpPacket::NpPacket unsigned char * rawData
 

Parse the raw packet.

Todo:
sanity checks

Definition at line 65 of file NpPacket.cpp.

NpPacket::~NpPacket [virtual]
 

Definition at line 198 of file NpPacket.cpp.


Member Function Documentation

NpPacket * NpPacket::createPacket NpType packetType [static]
 

Use this function to create any type of packet you want.

This uses the Factory Method design pattern. This is a static function.

Definition at line 93 of file NpPacket.cpp.

NpPacket * NpPacket::decode unsigned char * rawData,
NpType packetType
[static]
 

Creates the correct type of packet from the rawData.

This method is somewhat similiar to a Factory Method. This is a static function.

Parameters:
rawData   Raw packet data.
packetType   The type of packet.
Returns:
The decoded packet (which must be cast to the appropriate type in order to be used).

Definition at line 129 of file NpPacket.cpp.

Referenced by read().

void NpPacket::dumpData std::ostream & out
 

Dumps hex output of the data portion of the packet.

Definition at line 394 of file NpPacket.cpp.

Referenced by NetworkLayer::handleControlPacket().

void NpPacket::dumpHeader std::ostream & out
 

Dumps hex output of the packet header.

Definition at line 377 of file NpPacket.cpp.

char * NpPacket::getControlTypeString const
 

Return a string that describes the packet type.

Definition at line 411 of file NpPacket.cpp.

Referenced by decode(), NetworkLayer::forwardPacket(), LinkLayerInterface::pollAllSocketsImpl(), read(), LinkLayerInterface::sendPacket(), and toStream().

unsigned char * NpPacket::getData
 

Definition at line 229 of file NpPacket.cpp.

Referenced by ServiceTable::handleDataPacket().

unsigned int NpPacket::getDataLength const
 

Definition at line 236 of file NpPacket.cpp.

Referenced by ServiceTable::handleDataPacket().

unsigned int NpPacket::getHeaderLength NpType packetType [static]
 

Parameters:
packetType   The type of packet you want the header length of.
Returns:
The length of the header in bytes.

Definition at line 322 of file NpPacket.cpp.

unsigned int NpPacket::getHeaderLength [virtual]
 

Return the length of the header, in bytes.

Definition at line 312 of file NpPacket.cpp.

Referenced by parseMiniHeader().

NpPacket::NpType NpPacket::getPacketType const
 

Return the type of packet.

Definition at line 292 of file NpPacket.cpp.

Referenced by NetworkLayer::handleControlPacket().

unsigned char * NpPacket::getRawData [virtual]
 

Used by the Node.writePacket function right before sending over network.

Make sure m_length and m_headerLength are set correctly before calling this because this is how it knows how much memory to allocate. This function creates the raw data on the fly.

Reimplemented in ConnectionPacket, DiscoveryPacket, FinPacket, and ImHerePacket.

Definition at line 248 of file NpPacket.cpp.

Referenced by dumpHeader(), ImHerePacket::getRawData(), FinPacket::getRawData(), DiscoveryPacket::getRawData(), ConnectionPacket::getRawData(), and write().

unsigned int NpPacket::getRawLength const
 

Return the length of the entire packet, including headers.

Definition at line 282 of file NpPacket.cpp.

Referenced by NetworkLayer::connectForward(), NetworkLayer::handleDiscoveryPacket(), NetworkLayer::handleEstablishedPacket(), NetworkLayer::handleImHerePacket(), NetworkLayer::handlePingPacket(), and write().

unsigned int NpPacket::getVcn
 

Definition at line 211 of file NpPacket.cpp.

Referenced by NetworkLayer::connectForward(), NetworkLayer::connectTerminate(), NetworkLayer::forwardPacket(), NetworkLayer::handleConnectPacket(), NetworkLayer::handleControlPacket(), NetworkLayer::handleDataPacket(), NetworkLayer::handleEstablishedPacket(), NetworkLayer::handleFinPacket(), VirtualCircuitTable::isThisPacketForMe(), NetworkLayer::isThisPacketForMe(), LinkLayerInterface::pollAllSocketsImpl(), and LinkLayerInterface::sendPacket().

int NpPacket::getVersionNumber
 

Reimplemented in ImHerePacket.

bool NpPacket::isControlPacket const
 

Return true if this packet is anything but a data packet.

Definition at line 302 of file NpPacket.cpp.

Referenced by NpPacket(), and NetworkLayer::processPacketsImpl().

int NpPacket::parseMiniHeader unsigned char * rawData,
unsigned int * rawLength,
int * versionNumber,
NpType * packetType
[static]
 

This function decodes and checks the packet type and length.

From this information you can get the total length of the packet.

Returns:
rawLength (the same as the second argument) on success or -1 if there was an error

Definition at line 164 of file NpPacket.cpp.

Referenced by read().

NpPacket * NpPacket::read ConnectionInterface * connection [static]
 

Read a packet from the Connection.

Returns:
The number of bytes read, or a negative value if there is an error.

Definition at line 451 of file NpPacket.cpp.

Referenced by LinkLayerInterface::pollAllSocketsImpl().

void NpPacket::setPacketType NpType type
 

Definition at line 223 of file NpPacket.cpp.

Referenced by NetworkLayer::handlePingPacket(), and NetworkLayer::ping().

void NpPacket::setVcn unsigned int vcn
 

Definition at line 217 of file NpPacket.cpp.

Referenced by NetworkLayer::connectForward(), NetworkLayer::destroyVc(), NetworkLayer::destroyVcsTo(), NetworkLayer::forwardPacket(), NetworkLayer::handleEstablishedPacket(), and NetworkLayer::makeVc().

void NpPacket::setVersionNumber int
 

void NpPacket::toStream std::ostream & out [virtual]
 

Gets the length of the whole packet and makes sure the length makes sense.

Returns:
< 0 if the length is invalid

Reimplemented from BasicObject.

Reimplemented in ConnectionPacket, DiscoveryPacket, FinPacket, and ImHerePacket.

Definition at line 365 of file NpPacket.cpp.

Referenced by ImHerePacket::toStream(), FinPacket::toStream(), DiscoveryPacket::toStream(), and ConnectionPacket::toStream().

int NpPacket::write ConnectionInterface * connection
 

Write the specified packet to the Connection.

Returns:
Number of bytes written, or the error code from system-level "send".

Definition at line 511 of file NpPacket.cpp.

Referenced by LinkLayerInterface::broadcast(), and LinkLayerInterface::sendPacket().


Member Data Documentation

NpType NpPacket::m_controlType [protected]
 

packet type.

Definition at line 136 of file NpPacket.h.

unsigned char* NpPacket::m_data [protected]
 

The data portion of the packet.

Definition at line 145 of file NpPacket.h.

unsigned int NpPacket::m_headerLength [protected]
 

length of the packet header (not variable).

Definition at line 151 of file NpPacket.h.

unsigned short NpPacket::m_length [protected]
 

the payload length; header length is fixed.

Definition at line 139 of file NpPacket.h.

unsigned char* NpPacket::m_rawData [protected]
 

the entire packet, including the header.

Definition at line 148 of file NpPacket.h.

unsigned int NpPacket::m_vcn [protected]
 

Source VCN of requester.

Definition at line 142 of file NpPacket.h.

int NpPacket::m_versionNumber [protected]
 

Version number.

Reimplemented in ImHerePacket.

Definition at line 154 of file NpPacket.h.


The documentation for this class was generated from the following files:
Generated at Thu Jul 11 13:31:57 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001