Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

Node Class Reference

Inheritance diagram for Node::

GateWay List of all members.

Public Methods

 Node ()
 Node (String name)
void receive (Object packet)
void updateRoutingTable ()
void transmitAll ()
void attach (LineEnd line_end, Node other_node)
void detach (LineEnd line_end)
void delete ()
void detach (Node other_node)
RIPTable getRIPTable ()
void setCoordinates (int x, int y)
String getName ()
int getXCoordinate ()
int getYCoordinate ()
void setXCoordinate (int x)
void getYCoordinate (int y)
void paint (Graphics g, FontMetrics metrics, Color fill_color)

Public Attributes

RIPTable routing_table

Protected Attributes

String name
int x_position = 20
int y_position = 20
NodeQueue receive_buffer = new NodeQueue()
Vector connecting_lines = new Vector()
Vector connecting_nodes = new Vector()

Detailed Description

Node class. The Node class implements a generic network node..
Author(s):
Tomislav Petkoviæ

Definition at line 18 of file Node.java.


Constructor & Destructor Documentation

Node::Node ( ) [inline]
 

Empty constructor. Creates completly isolated node.

Definition at line 47 of file Node.java.

00048     {
00049         name = "Izolirani cvor";
00050         x_position = (int)(50 + 200 * Math.random());
00051         y_position = (int)(50 + 200 * Math.random());
00052         this.routing_table = new RIPTable(this);
00053     }

Node::Node ( String name ) [inline]
 

Normal constructor. Creates named node. All nodes should have differen names.

Parameters:
name   Node name.

Definition at line 61 of file Node.java.

00062     {
00063         x_position = (int)(50 + 200 * Math.random());
00064         y_position = (int)(50 + 200 * Math.random());
00065         this.name = name;
00066         this.routing_table = new RIPTable(this);
00067     }


Member Function Documentation

void Node::attach ( LineEnd line_end,
Node other_node ) [inline]
 

Attach line end.

Parameters:
line_end   Line end object.
other_node   Node at the other line end.

Definition at line 150 of file Node.java.

Referenced by Line::Line().

00151     {
00152         connecting_lines.addElement(line_end);
00153         connecting_nodes.addElement(other_node);
00154         routing_table.addElement(other_node, other_node, 1);
00155     }

void Node::delete ( ) [inline]
 

Deletes node.

Definition at line 181 of file Node.java.

Referenced by CyclopsSimulator::deleteNode().

00182     {
00183         int index;
00184 
00185         while (!connecting_lines.isEmpty())
00186             {
00187                 LineEnd line = (LineEnd)connecting_lines.lastElement();
00188                 line.delete();
00189             }
00190     }

void Node::detach ( Node other_node ) [inline]
 

Detach node.

Parameters:
other_node   Node object.

Definition at line 197 of file Node.java.

00198     {
00199         int index;
00200 
00201         index = connecting_nodes.indexOf(other_node);
00202         if (0 <= index)
00203             {
00204                 connecting_lines.removeElementAt(index);
00205                 connecting_nodes.removeElementAt(index);
00206                 routing_table.setCostToInfinity(other_node);
00207             }
00208     }

void Node::detach ( LineEnd line_end ) [inline]
 

Detach line end.

Parameters:
line_end   Line end object.

Definition at line 162 of file Node.java.

Referenced by Line::delete().

00163     {
00164         int index;
00165         Node node;
00166 
00167         index = connecting_lines.indexOf(line_end);
00168         if (0 <= index)
00169             {
00170                 connecting_lines.removeElementAt(index);
00171                 node = (Node)connecting_nodes.elementAt(index);
00172                 connecting_nodes.removeElementAt(index);
00173                 routing_table.setCostToInfinity(node);
00174             }
00175     }

String Node::getName ( ) [inline]
 

Gets node name.

Returns:
Returns node name.

Definition at line 237 of file Node.java.

Referenced by CyclopsSimulator::deleteNode(), and CyclopsSimulator::findNode().

00238     {
00239         return this.name;
00240     }

RIPTable Node::getRIPTable ( ) [inline]
 

Gets RIP table.

Returns:
Returns RIP table reference.

Definition at line 215 of file Node.java.

Referenced by RIPTable::updateTable().

00216     {
00217         return routing_table;
00218     }

int Node::getXCoordinate ( ) [inline]
 

Gets x cooridnate.

Returns:
x screen coordinate.

Definition at line 247 of file Node.java.

Referenced by NetworkSpacePanel::mousePressed(), and Line::paint().

00248     {
00249         return x_position;
00250     }

void Node::getYCoordinate ( int y ) [inline]
 

Sets y cooridnate.

Parameters:
y   y screen coordinate.

Definition at line 277 of file Node.java.

00278     {
00279         y_position = y;
00280     }

int Node::getYCoordinate ( ) [inline]
 

Gets y cooridnate.

Returns:
y screen coordinate.

Definition at line 257 of file Node.java.

Referenced by NetworkSpacePanel::mousePressed(), and Line::paint().

00258     {
00259         return y_position;
00260     }

void Node::paint ( Graphics g,
FontMetrics metrics,
Color fill_color ) [inline]
 

Draws node on screen.

Parameters:
g   Graphics reference.
metrics   Font metrics required for node name.
fill_color   Color.

Definition at line 289 of file Node.java.

Referenced by CyclopsSimulator::paint().

00290     {
00291         int w = metrics.stringWidth(this.name) + 10;
00292         int h = metrics.getHeight() + 4;
00293         g.setColor(fill_color);
00294         g.fillRect(x_position - w/2, y_position - h/2, w, h);
00295         g.setColor(Color.black);
00296         g.drawRect(x_position - w/2, y_position - h/2, w - 1, h - 1);
00297         g.drawString(this.name,
00298                      x_position - (w - 10) / 2,
00299                      y_position - (h - 4) / 2 + metrics.getAscent()
00300                      );
00301     }

void Node::receive ( Object packet ) [inline]
 

Receives one packet and stores it into a buffer.

Parameters:
packet   Packet object.

Definition at line 74 of file Node.java.

Referenced by CyclopsSimulator::addDummyPackets(), CyclopsSimulator::sendPacket(), and Line::transmitAll().

00075     {
00076         receive_buffer.put(packet);
00077     }

void Node::setCoordinates ( int x,
int y ) [inline]
 

Sets screen coordinates.

Parameters:
x   x screen coordinate.
y   y screen coordinate.

Definition at line 226 of file Node.java.

Referenced by NetworkSpacePanel::mouseDragged(), NetworkSpacePanel::mousePressed(), and NetworkSpacePanel::mouseReleased().

00227     {
00228         x_position = x;
00229         y_position = y;
00230     }

void Node::setXCoordinate ( int x ) [inline]
 

Sets x cooridnate.

Parameters:
x   x screen coordinate.

Definition at line 267 of file Node.java.

00268     {
00269         x_position = x;
00270     }

void Node::transmitAll ( ) [inline]
 

Transmits all packages currently stored in output buffer.

Definition at line 100 of file Node.java.

Referenced by CyclopsSimulator::simulate().

00101     {
00102         int i;
00103         Packet packet;
00104         Node destination;
00105         Node next_node;
00106         LineEnd line;
00107 
00108         while ( !receive_buffer.isEmpty() )
00109             {
00110                 packet = (Packet)receive_buffer.get();
00111                 destination = packet.getDestinationNode();
00112                 if (destination == this)
00113                     {
00114                         /* Discard packet. */
00115                     }
00116                 else if (packet.hop() != 0)
00117                     {
00118                         next_node = routing_table.findNextNodeForRouteTo(destination);
00119                         if (next_node == null)
00120                             {
00121                                 i = (int)(Math.random()*connecting_lines.size());
00122                                 if (!connecting_lines.isEmpty())
00123                                     {
00124                                         line = (LineEnd)connecting_lines.elementAt(i);
00125                                         line.receive(packet);
00126                                     }
00127                             }
00128                         else
00129                             {
00130                                 i = connecting_nodes.indexOf(next_node);
00131                                 if (i >= 0)
00132                                     {
00133                                         line = (LineEnd)connecting_lines.elementAt(i);
00134                                         line.receive(packet);
00135                                     }
00136                             }
00137                         /* else */
00138                     }
00139                 /* else if */
00140             }
00141         /* while */
00142     }

void Node::updateRoutingTable ( ) [inline]
 

Updates routing table.

Definition at line 83 of file Node.java.

Referenced by CyclopsSimulator::simulate(), and CyclopsSimulator::topologyUpdate().

00084     {
00085         int i;
00086         Node other_node;
00087 
00088         for (i=0; i<connecting_nodes.size(); i++)
00089             {
00090                 other_node = (Node)connecting_nodes.elementAt(i);
00091                 routing_table.updateTable(other_node);
00092             }
00093         routing_table.garbageCollect();
00094     }


Member Data Documentation

Vector Node::connecting_lines = new Vector() [protected]
 

List of all conecting lines.

Definition at line 37 of file Node.java.

Vector Node::connecting_nodes = new Vector() [protected]
 

List of all connecting nodes.

Definition at line 40 of file Node.java.

String Node::name [protected]
 

Node name. Every node should have one.

Definition at line 25 of file Node.java.

NodeQueue Node::receive_buffer = new NodeQueue() [protected]
 

Queue for all incoming packages.

Definition at line 34 of file Node.java.

RIPTable Node::routing_table
 

RIP table.

Definition at line 22 of file Node.java.

int Node::x_position = 20 [protected]
 

x screen coordinate.

Definition at line 28 of file Node.java.

int Node::y_position = 20 [protected]
 

y screen coordinate.

Definition at line 31 of file Node.java.


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