Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

Packet.java

Go to the documentation of this file.
00001 /* Cyclops
00002  * FER - SPVP
00003  * Fakultet elektrotehnike i racunarstva (http://www.fer.hr/)
00004  * Unska 3, 10000 Zagreb, Hrvatska
00005  * (c) 2001 FER, Zagreb.
00006  */
00007 
00008 package hr.fer.zesoi.cyclops;
00009 
00010 import java.awt.*;
00011 
00012 
00022 public class Packet
00023 {
00024 
00026     protected StringBuffer contents;
00027 
00029     protected int packet_length = 500;
00030 
00032     protected Node source_node = null;
00033 
00035     protected Node destination_node = null;
00036 
00038     protected int time_to_live = 40;
00039 
00041     protected boolean draw = false;
00042 
00046     public Packet ()
00047     {
00048         contents = new StringBuffer (packet_length);
00049     }
00050     /* Packet */
00051 
00056     public Packet (int length)
00057     {
00058         if(length < 0) length = 500;
00059         packet_length = length;
00060         contents = new StringBuffer(packet_length);
00061     }
00062     /* Packet */
00063 
00071     public Packet (int length, Node source, Node destination)
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     }
00079     /* Packet */
00080 
00089     public Packet (int length, Node source, Node destination, int ttl)
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     }
00098     /* Packet */
00099 
00104     public StringBuffer getContents ()
00105     {
00106         return contents;
00107     }
00108     /* getContents */
00109 
00114     public void setContents (StringBuffer contents)
00115     {
00116         this.contents.setLength(0);
00117         this.contents.append(contents);
00118         this.contents.setLength(packet_length);
00119     }
00120     /* setContents */
00121 
00126     public int getLength ()
00127     {
00128         return packet_length;
00129     }
00130     /* getLength */
00131 
00138     public void setTimeToLive (int time_to_live)
00139     {
00140         this.time_to_live = time_to_live;
00141     }
00142     /* setTimeToLive */
00143 
00148     public int hop ()
00149     {
00150         if (time_to_live > 0)
00151             {
00152                 time_to_live -= 1;
00153             }
00154         return time_to_live;
00155     }
00156     /* hop */
00157 
00162     public void setSourceNode (Node source_node)
00163     {
00164         this.source_node = source_node;
00165     }
00166     /* setSourceNode */
00167 
00172     public void setDestinationNode (Node destination_node)
00173     {
00174         this.destination_node = destination_node;
00175     }
00176     /* setDestinationNode */
00177 
00182     public Node getSourceNode ()
00183     {
00184         return source_node;
00185     }
00186     /* getSourceNode */
00187 
00192     public Node getDestinationNode ()
00193     {
00194         return destination_node;
00195     }
00196     /* getDestinationNode */
00197 
00204     public boolean getDrawingFlag ()
00205     {
00206         return draw;
00207     }
00208     /* getDrawingFlag */
00209 
00214     public void setDrawingFlag (boolean flag)
00215     {
00216         draw = flag;
00217     }
00218     /* setDrawingFlag */
00219 
00228     public void paint (Graphics g, FontMetrics metrics, Color fill_color, int x, int y)
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     }
00235     /* paint */
00236 
00237 }
00238 /* Packet */

Generated at Thu Jun 28 03:04:21 2001 for Cyclops Network Simulator by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001