Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

Packet Class Reference

Inheritance diagram for Packet::

IpPacket List of all members.

Public Methods

 Packet ()
 Packet (int length)
 Packet (int length, Node source, Node destination)
 Packet (int length, Node source, Node destination, int ttl)
StringBuffer getContents ()
void setContents (StringBuffer contents)
int getLength ()
void setTimeToLive (int time_to_live)
int hop ()
void setSourceNode (Node source_node)
void setDestinationNode (Node destination_node)
Node getSourceNode ()
Node getDestinationNode ()
boolean getDrawingFlag ()
void setDrawingFlag (boolean flag)
void paint (Graphics g, FontMetrics metrics, Color fill_color, int x, int y)

Protected Attributes

StringBuffer contents
int packet_length = 500
Node source_node = null
Node destination_node = null
int time_to_live = 40
boolean draw = false

Detailed Description

The Packet class implements a generic packet. Generic packet has a variable size storage for any data. Methods that are implemented are required by Line class to be able to destinguish packet direction.
Author(s):
Darko Vasić , Tomislav Petković , Zvonko Kostanjčar

Definition at line 22 of file Packet.java.


Constructor & Destructor Documentation

Packet::Packet ( ) [inline]
 

Default empty constructor. Constructs a 500 bytes package.

Definition at line 46 of file Packet.java.

00047     {
00048         contents = new StringBuffer (packet_length);
00049     }

Packet::Packet ( int length ) [inline]
 

Constructructs a packet with inital size specified by length argument.

Parameters:
length   Packet length.

Definition at line 56 of file Packet.java.

00057     {
00058         if(length < 0) length = 500;
00059         packet_length = length;
00060         contents = new StringBuffer(packet_length);
00061     }

Packet::Packet ( int length,
Node source,
Node destination ) [inline]
 

Constructructs a packet with inital size specified by length argument and sets source and destination node.

Parameters:
length   Packet length.
source   Source node.
destination   Destination node.

Definition at line 71 of file Packet.java.

00072     {
00073         if(length < 0) length = 500;
00074         packet_length = length;
00075         source_node = source;
00076         destination_node = destination;
00077         contents = new StringBuffer(packet_length);
00078     }

Packet::Packet ( int length,
Node source,
Node destination,
int ttl ) [inline]
 

Constructructs a packet with inital ttl specified by ttl argument and sets source and destination node.

Parameters:
length   Packet length.
source   Source node.
destination   Destination node.
ttl   Time to live.

Definition at line 89 of file Packet.java.

00090     {
00091         if(length < 0) length = 500;
00092         packet_length = length;
00093         source_node = source;
00094         destination_node = destination;
00095         contents = new StringBuffer(packet_length);
00096         time_to_live = ttl;
00097     }


Member Function Documentation

StringBuffer Packet::getContents ( ) [inline]
 

Gets packet contents.

Returns:
Packet contents.

Definition at line 104 of file Packet.java.

00105     {
00106         return contents;
00107     }

Node Packet::getDestinationNode ( ) [inline]
 

Gets destination node.

Returns:
Destination node.

Definition at line 192 of file Packet.java.

Referenced by Node::transmitAll().

00193     {
00194         return destination_node;
00195     }

boolean Packet::getDrawingFlag ( ) [inline]
 

Gets status of drawing flag. Drawing flag is used to distinguish important packets (packets that have the drawing flag set will always be drawn).

Returns:
Drawing flag.

Definition at line 204 of file Packet.java.

Referenced by Line::paint().

00205     {
00206         return draw;
00207     }

int Packet::getLength ( ) [inline]
 

Gets packet length.

Returns:
Packet length.

Definition at line 126 of file Packet.java.

00127     {
00128         return packet_length;
00129     }

Node Packet::getSourceNode ( ) [inline]
 

Gets source node.

Returns:
Source node.

Definition at line 182 of file Packet.java.

00183     {
00184         return source_node;
00185     }

int Packet::hop ( ) [inline]
 

Decreases TTL counter. When zero is hit, packet will be discarded.

Returns:
Returns TTL.

Definition at line 148 of file Packet.java.

Referenced by Node::transmitAll().

00149     {
00150         if (time_to_live > 0)
00151             {
00152                 time_to_live -= 1;
00153             }
00154         return time_to_live;
00155     }

void Packet::paint ( Graphics g,
FontMetrics metrics,
Color fill_color,
int x,
int y ) [inline]
 

Draws packet at location (x, y).

Parameters:
g   Graphics reference.
metrics   Font metrics.
fill_color   Packet color.
x   x coordinate.
y   y coordinate

Definition at line 228 of file Packet.java.

Referenced by Line::paint().

00229     {
00230         g.setColor(fill_color);
00231         g.fillOval(x, y, 8, 8);
00232         g.setColor(Color.black);
00233         g.drawOval(x, y, 8, 8);
00234     }

void Packet::setContents ( StringBuffer contents ) [inline]
 

Sets packet contents.

Parameters:
contents   New packet contetns.

Definition at line 114 of file Packet.java.

00115     {
00116         this.contents.setLength(0);
00117         this.contents.append(contents);
00118         this.contents.setLength(packet_length);
00119     }

void Packet::setDestinationNode ( Node destination_node ) [inline]
 

Sets destination node.

Parameters:
destinationNode   Destination node.

Definition at line 172 of file Packet.java.

00173     {
00174         this.destination_node = destination_node;
00175     }

void Packet::setDrawingFlag ( boolean flag ) [inline]
 

Sets drawing flag.

Parameters:
flag   Drawing flag.

Definition at line 214 of file Packet.java.

Referenced by CyclopsSimulator::sendPacket().

00215     {
00216         draw = flag;
00217     }

void Packet::setSourceNode ( Node source_node ) [inline]
 

Sets source node.

Parameters:
sourceNode   Source node.

Definition at line 162 of file Packet.java.

00163     {
00164         this.source_node = source_node;
00165     }

void Packet::setTimeToLive ( int time_to_live ) [inline]
 

Sets TTL counter. If the given time is negative, packet will live forever (or until simulation is terminated).

Parameters:
time_to_live   TTL.

Definition at line 138 of file Packet.java.

Referenced by CyclopsSimulator::addDummyPackets().

00139     {
00140         this.time_to_live = time_to_live;
00141     }


Member Data Documentation

StringBuffer Packet::contents [protected]
 

A varible size buffer for packet's contents.

Definition at line 26 of file Packet.java.

Node Packet::destination_node = null [protected]
 

Destination node. Set by first Node.

Definition at line 35 of file Packet.java.

boolean Packet::draw = false [protected]
 

Drawing flag.

Definition at line 41 of file Packet.java.

int Packet::packet_length = 500 [protected]
 

Packet length.

Definition at line 29 of file Packet.java.

Node Packet::source_node = null [protected]
 

Source node. Set by first Node.

Definition at line 32 of file Packet.java.

int Packet::time_to_live = 40 [protected]
 

Time to live.

Definition at line 38 of file Packet.java.


The documentation for this class was generated from the following file:
Generated at Thu Jun 28 03:04:24 2001 for Cyclops Network Simulator by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001