Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

CyclopsSimulator Class Reference

Inheritance diagram for CyclopsSimulator::

Thread List of all members.

Public Methods

void run ()
 CyclopsSimulator ()
synchronized void simulate ()
synchronized void topologyUpdate ()
void startSimulation ()
void tracePackets (String start_name, String end_name)
void sendPacket ()
void addDummyPackets (int number, int time_to_live)
void stopSimulation ()
void endSimulation ()
void addNode (Node new_node)
Node findNode (String node_name)
Node deleteNode (String node_name)
int numberOfNodes ()
Node nodeAt (int index)
Line lineAt (int index)
int numberOfLines ()
void addLine (Line new_line)
Line deleteLine (String first_node, String second_node)
synchronized void paint (Graphics g, FontMetrics metrics, Color node_color, Color line_color, Color left_packet_color, Color right_packet_color, Color traced_packet_color, boolean show_line_capacity, boolean show_all_packets)

Protected Attributes

Vector node_list = new Vector()
Vector line_list = new Vector()
Node start_node = null
String start_node_name = null
Node end_node = null
String end_node_name = null
boolean trace_flag = false
boolean running = false
boolean destroy = false

Detailed Description

Base Cyclops simulator class. Preforms simulation.
Author(s):
Darko Vasić , Tomislav Petković , Zvonko Kostanjčar

Definition at line 21 of file CyclopsSimulator.java.


Constructor & Destructor Documentation

CyclopsSimulator::CyclopsSimulator ( ) [inline]
 

Empty constructor.

Definition at line 94 of file CyclopsSimulator.java.

00095     {
00096     }


Member Function Documentation

void CyclopsSimulator::addDummyPackets ( int number,
int time_to_live ) [inline]
 

Adds dummy packets. Packets with negative ttl will live forever.

Parameters:
number   Number of packets.
time_to_live   TTL.

Definition at line 210 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::addDummyPackets().

00211     {
00212         int i;
00213         int j;
00214         Node current_node;
00215         Packet packet;
00216         boolean running_flag;
00217 
00218         running_flag = running;
00219         running = false;
00220         /* Add dummy packets. */
00221         for (i=0, j=0; i<number; i++)
00222             {
00223                 packet = new Packet();
00224                 current_node = (Node)node_list.elementAt(j);
00225                 j++;
00226                 if (j >= node_list.size())
00227                     {
00228                         j = 0;
00229                     }
00230                 packet.setTimeToLive(time_to_live);
00231                 current_node.receive(packet);
00232             }
00233         running = running_flag;
00234     }

void CyclopsSimulator::addLine ( Line new_line ) [inline]
 

Adds line to network.

Parameters:
new_line   Line.

Definition at line 374 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::addLine().

00375     {
00376         line_list.addElement(new_line);
00377     }

void CyclopsSimulator::addNode ( Node new_node ) [inline]
 

Adds node to network.

Parameters:
new_node   Node.

Definition at line 259 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::addNode().

00260     {
00261         node_list.addElement(new_node);
00262     }

Line CyclopsSimulator::deleteLine ( String first_node,
String second_node ) [inline]
 

Deletes line from network.

Parameters:
first_node   First node name.
second_node   Second node name.
Returns:
Returns line reference.

Definition at line 386 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::deleteLine().

00387     {
00388         Node first;
00389         Node second;
00390         Line current_line;
00391         int i;
00392 
00393         first = findNode(first_node);
00394         second = findNode(second_node);
00395         if (null == first) return null;
00396         if (null == second) return null;
00397         current_line = null;
00398         for (i=0; i!=line_list.size(); i++)
00399             {
00400                 current_line = (Line)line_list.elementAt(i);
00401                 if (current_line.areEndingNodes(first, second))
00402                     {
00403                         current_line.delete();
00404                         line_list.removeElementAt(i);
00405                         break;
00406                     }
00407             }
00408         return current_line;
00409     }

Node CyclopsSimulator::deleteNode ( String node_name ) [inline]
 

Deletes node with given name.

Parameters:
node_name   Node name.
Returns:
Returns node reference.

Definition at line 294 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::deleteNode().

00295     {
00296         int i;
00297         String current_name;
00298         Node current_node = null;
00299         Line current_line;
00300 
00301         for (i=0; i!=node_list.size(); i++)
00302             {
00303                 current_node = (Node)node_list.elementAt(i);
00304                 current_name = current_node.getName();
00305                 if (current_name.equals(node_name))
00306                     {
00307                         current_node.delete();
00308                         node_list.removeElementAt(i);
00309                         break;
00310                     }
00311             }
00312         for (i=0; i!=line_list.size(); i++)
00313             {
00314                 current_line = (Line)line_list.elementAt(i);
00315                 if (current_line.isDisconnected())
00316                     {
00317                         line_list.removeElementAt(i);
00318                         /* Next element becomes current element, so i-- is required. */
00319                         i--;
00320                     }
00321             }
00322         return current_node;
00323     }

void CyclopsSimulator::endSimulation ( ) [inline]
 

Ends simulation.

Definition at line 249 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::endSimulation().

00250     {
00251         destroy = true;
00252     }

Node CyclopsSimulator::findNode ( String node_name ) [inline]
 

Finds node with given name.

Parameters:
node_name   Node name.
Returns:
Returns node reference.

Definition at line 270 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::addNode().

00271     {
00272         int i;
00273         String current_name;
00274         Node current_node;
00275 
00276         for (i=0; i!=node_list.size(); i++)
00277             {
00278                 current_node = (Node)node_list.elementAt(i);
00279                 current_name = current_node.getName();
00280                 if (current_name.equals(node_name))
00281                     {
00282                         return current_node;
00283                     }
00284             }
00285         return null;
00286     }

Line CyclopsSimulator::lineAt ( int index ) [inline]
 

Returns line at specified index. Index must be less then number returnd by getNumberOfLines().

Parameters:
index   Line index.
Returns:
Line reference.

Definition at line 354 of file CyclopsSimulator.java.

00355     {
00356         return (Line)line_list.elementAt(index);
00357     }

Node CyclopsSimulator::nodeAt ( int index ) [inline]
 

Returns node at specified index. Index must be less then number returnd by getNumberOfNodes().

Parameters:
index   Node index.
Returns:
Node reference.

Definition at line 342 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::mousePressed().

00343     {
00344         return (Node)node_list.elementAt(index);
00345     }

int CyclopsSimulator::numberOfLines ( ) [inline]
 

Gets number of lines.

Returns:
Number of lines.

Definition at line 364 of file CyclopsSimulator.java.

00365     {
00366         return line_list.size();
00367     }

int CyclopsSimulator::numberOfNodes ( ) [inline]
 

Gets number of nodes.

Returns:
Number of nodes.

Definition at line 330 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::mousePressed().

00331     {
00332         return node_list.size();
00333     }

synchronized void CyclopsSimulator::paint ( Graphics g,
FontMetrics metrics,
Color node_color,
Color line_color,
Color left_packet_color,
Color right_packet_color,
Color traced_packet_color,
boolean show_line_capacity,
boolean show_all_packets ) [inline]
 

Paints network on screen.

Parameters:
g   Graphics reference.
metric   Font metrics for displaying information.
node_color   Node color.
line_color   Line color.
left_packet_color   Color for packets traveling form left to right.
right_packet_color   Color for packets traveling form right to left.
traced_packet_color   Color for traced packets.
show_line_capacity   Capacity flag.
show_all_packets   Show all packets flag.

Definition at line 424 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::update().

00430     {
00431         int i;
00432         Line current_line;
00433         Node current_node;
00434 
00435         for (i=0; i!=line_list.size(); i++)
00436             {
00437                 current_line = (Line)line_list.elementAt(i);
00438                 current_line.paint(g, metrics,
00439                                    line_color, left_packet_color, right_packet_color,
00440                                    traced_packet_color,
00441                                    show_line_capacity, show_all_packets);
00442             }
00443         for (i=0; i!=node_list.size(); i++)
00444             {
00445                 current_node = (Node)node_list.elementAt(i);
00446                 current_node.paint(g, metrics, node_color);
00447             }
00448 
00449     }

void CyclopsSimulator::run ( ) [inline]
 

Run method.

Definition at line 54 of file CyclopsSimulator.java.

00055     {
00056         while (true)
00057             {
00058                 if (running)
00059                     {
00060                         simulate();
00061                         if (trace_flag)
00062                             {
00063                                 sendPacket();
00064                             }
00065                         try
00066                             {
00067                                 Thread.sleep(100);
00068                             }
00069                         catch (InterruptedException exception)
00070                             {
00071                             }
00072                     }
00073                 else
00074                     {
00075                         try
00076                             {
00077                                 Thread.sleep(100);
00078                             }
00079                         catch (InterruptedException exception)
00080                             {
00081                             }
00082                     }
00083                 if (destroy)
00084                     {
00085                         return;
00086                     }
00087             }
00088     }

void CyclopsSimulator::sendPacket ( ) [inline]
 

Sends packet from source to destination. Source and destination are start_node and end_node.

Definition at line 186 of file CyclopsSimulator.java.

00187     {
00188         Node temp;
00189 
00190         temp = findNode(start_node_name);
00191         if (temp != null)
00192             {
00193                 temp = findNode(end_node_name);
00194                 if (temp != null)
00195                     {
00196                         Packet traced = new Packet(120, start_node, end_node, 14);
00197                         traced.setDrawingFlag(true);
00198                         start_node.receive(traced);
00199                     }
00200             }
00201     }

synchronized void CyclopsSimulator::simulate ( ) [inline]
 

Main simulation method. Each simulation cycle is made of two subcycles. First all lines transmits theirs packets and then every node analysises packages and deternimes to which node it shoul be sent.

Definition at line 105 of file CyclopsSimulator.java.

00106     {
00107         int i;
00108         Line current_line;
00109         Node current_node;
00110 
00111         for (i=0; i<line_list.size(); i++)
00112             {
00113                 current_line = (Line)line_list.elementAt(i);
00114                 current_line.transmitAll();
00115             }
00116         for (i=0; i<node_list.size(); i++)
00117             {
00118                 current_node = (Node)node_list.elementAt(i);
00119                 current_node.transmitAll();
00120             }
00121         for (i=0; i<node_list.size(); i++)
00122             {
00123                 current_node = (Node)node_list.elementAt(i);
00124                 current_node.updateRoutingTable();
00125             }
00126     }

void CyclopsSimulator::startSimulation ( ) [inline]
 

Starts/resumes simulation.

Definition at line 148 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::startSimulation().

00149     {
00150         running = true;
00151     }

void CyclopsSimulator::stopSimulation ( ) [inline]
 

Stops/suspends simulation.

Definition at line 240 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::stopSimulation().

00241     {
00242         running = false;
00243     }

synchronized void CyclopsSimulator::topologyUpdate ( ) [inline]
 

Topology update.

Definition at line 132 of file CyclopsSimulator.java.

00133     {
00134         int i;
00135         Node current_node;
00136 
00137         for (i=0; i<node_list.size(); i++)
00138             {
00139                 current_node = (Node)node_list.elementAt(i);
00140                 current_node.updateRoutingTable();
00141             }
00142     }

void CyclopsSimulator::tracePackets ( String start_name,
String end_name ) [inline]
 

Trace packets from source to destination.

Parameters:
start_name   Name of a starting node (source).
end_name   Name of a ending node (destination).

Definition at line 159 of file CyclopsSimulator.java.

Referenced by NetworkSpacePanel::tracePackets().

00160     {
00161         Node start_temp;
00162         Node end_temp;
00163 
00164         start_temp = findNode(start_name);
00165         if (start_temp == null)
00166             {
00167                 return;
00168             }
00169         end_temp = findNode(end_name);
00170         if (end_temp == null)
00171             {
00172                 return;
00173             }
00174         start_node = start_temp;
00175         start_node_name = start_name;
00176         end_node = end_temp;
00177         end_node_name = end_name;
00178         trace_flag = true;
00179     }


Member Data Documentation

boolean CyclopsSimulator::destroy = false [protected]
 

Flag for destroying thread.

Definition at line 49 of file CyclopsSimulator.java.

Node CyclopsSimulator::end_node = null [protected]
 

Destination node.

Definition at line 37 of file CyclopsSimulator.java.

String CyclopsSimulator::end_node_name = null [protected]
 

Destination node name.

Definition at line 40 of file CyclopsSimulator.java.

Vector CyclopsSimulator::line_list = new Vector() [protected]
 

List of all lines in a network.

Definition at line 28 of file CyclopsSimulator.java.

Vector CyclopsSimulator::node_list = new Vector() [protected]
 

List of all nodes in a network.

Definition at line 25 of file CyclopsSimulator.java.

boolean CyclopsSimulator::running = false [protected]
 

Flag for stoping simulation.

Definition at line 46 of file CyclopsSimulator.java.

Node CyclopsSimulator::start_node = null [protected]
 

Source node.

Definition at line 31 of file CyclopsSimulator.java.

String CyclopsSimulator::start_node_name = null [protected]
 

Source node name.

Definition at line 34 of file CyclopsSimulator.java.

boolean CyclopsSimulator::trace_flag = false [protected]
 

Flag for packet tracing.

Definition at line 43 of file CyclopsSimulator.java.


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