Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

RIPTable Class Reference

List of all members.

Public Methods

 RIPTable (Node owner)
void addElement (Node destination, Node next_node, float cost)
Node findNextNodeForRouteTo (Node destination_node)
void updateTable (Node node)
void updateTable (RIPTable another_table)
void garbageCollect ()
void setCostToInfinity (Node node)
void setCost (Node destination, float cost)
RIPTableElement elementAt (int index)
int findEntry (Node destination_node)
int size ()

Private Attributes

Vector table = new Vector()
Node owner_node

Detailed Description

Routing table. Based on somewhat simplified RIP protocol.
Author(s):
Tomislav Petkoviæ

Definition at line 18 of file RIPTable.java.


Constructor & Destructor Documentation

RIPTable::RIPTable ( Node owner ) [inline]
 

Default constructor.

Parameters:
owner   Reference of owner node.

Definition at line 31 of file RIPTable.java.

00032     {
00033         this.owner_node = owner;
00034     }


Member Function Documentation

void RIPTable::addElement ( Node destination,
Node next_node,
float cost ) [inline]
 

Adds element to the table.

Parameters:
destination_node   Reference of destination node or network.
next_node   Reference of next node along a path to destination.
cost   Cost of a route.

Definition at line 43 of file RIPTable.java.

Referenced by Node::attach(), and updateTable().

00044     {
00045         RIPTableElement new_element = new RIPTableElement(destination, next_node, cost);
00046         table.addElement(new_element);
00047     }

RIPTableElement RIPTable::elementAt ( int index ) [inline]
 

Gets element at index i.

Parameters:
index   Index of element.
Returns:
Returns element reference.

Definition at line 331 of file RIPTable.java.

Referenced by updateTable().

00332     {
00333         return (RIPTableElement)table.elementAt(index);
00334     }

int RIPTable::findEntry ( Node destination_node ) [inline]
 

Finds table entry with given destination node or network.

Parameters:
destination_node   Reference of destination node or network.
Returns:
Returns index of table entry if one exists, -1 otherwise.

Definition at line 342 of file RIPTable.java.

Referenced by updateTable().

00343     {
00344         int i;
00345         RIPTableElement element;
00346 
00347         for (i=0; i<table.size(); i++)
00348             {
00349                 element = (RIPTableElement)table.elementAt(i);
00350                 if (element.destination_node == destination_node)
00351                     {
00352                         return i;
00353                     }
00354             }
00355         return -1;
00356     }

Node RIPTable::findNextNodeForRouteTo ( Node destination_node ) [inline]
 

Finds next node along a path to destination.

Parameters:
destination_node   Reference of destination node or network.
Returns:
Returns null if no apropriate route is found and next node along a path is appropriate route is found.

Definition at line 56 of file RIPTable.java.

Referenced by Node::transmitAll().

00057     {
00058         int i;
00059         RIPTableElement element;
00060         Node next_node;
00061 
00062         next_node = null;
00063         for (i=0; i<table.size(); i++)
00064             {
00065                 element = (RIPTableElement)table.elementAt(i);
00066                 /* Route is valid only if cost is less than infinity (16). */
00067                 if (destination_node == element.destination_node)
00068                     {
00069                         next_node = element.next_node;
00070                         if (element.cost < 16)
00071                             {
00072                                 return next_node;
00073                             }
00074                     }
00075                 /* if */
00076             }
00077         /* for */
00078         return next_node;
00079     }

void RIPTable::garbageCollect ( ) [inline]
 

Decreases all timers and removes expired entries.

Definition at line 240 of file RIPTable.java.

Referenced by Node::updateRoutingTable().

00241     {
00242         int i;
00243         RIPTableElement element;
00244 
00245         for (i=0; i<table.size(); i++)
00246             {
00247                 element = (RIPTableElement)table.elementAt(i);
00248                 if (!element.route_change_flag)
00249                     {
00250                         if (element.route_timeout>0)
00251                             {
00252                                 element.route_timeout -= 1;
00253                             }
00254                         else if (element.garbage_timeout>0)
00255                             {
00256                                 element.cost = 16;
00257                                 element.garbage_timeout -= 1;
00258                             }
00259                         else
00260                             {
00261                                 /* Entry expired, will be terminated. */
00262                                 table.removeElementAt(i);
00263                                 i--;
00264                             }
00265                     }
00266                 /* if */
00267             }
00268         /* for */
00269     }

void RIPTable::setCost ( Node destination,
float cost ) [inline]
 

Sets cost to given value.

Parameters:
destination   Destination node. Used to find table entry.
cost   Path cost.

Definition at line 305 of file RIPTable.java.

00306     {
00307         int i;
00308         RIPTableElement element;
00309 
00310         for (i=0; i<table.size(); i++)
00311             {
00312                 element = (RIPTableElement)table.elementAt(i);
00313                 if (element.destination_node == destination)
00314                     {
00315                         element.cost = cost;
00316                         element.route_change_flag = true;
00317                         element.route_timeout = 5;
00318                         element.garbage_timeout = 5;
00319                     }
00320                 /* if */
00321             }
00322         /* for */
00323     }

void RIPTable::setCostToInfinity ( Node node ) [inline]
 

Sets destination cost to infinity. Used when line or node is erased/disconnected.

Parameters:
node   Unreachable node. Used to find table entry.

Definition at line 277 of file RIPTable.java.

Referenced by Node::detach().

00278     {
00279         int i;
00280         RIPTableElement element;
00281 
00282         for (i=0; i<table.size(); i++)
00283             {
00284                 element = (RIPTableElement)table.elementAt(i);
00285                 if ((element.next_node == node) ||
00286                     (element.destination_node == node)
00287                     )
00288                     {
00289                         element.cost = 16;
00290                         element.route_change_flag = true;
00291                         element.route_timeout = 5;
00292                         element.garbage_timeout = 5;
00293                     }
00294                 /* if */
00295             }
00296         /* for */
00297     }

int RIPTable::size ( ) [inline]
 

Gets table size.

Returns:
Returns number of elements in a table.

Definition at line 363 of file RIPTable.java.

Referenced by updateTable().

00364     {
00365         return table.size();
00366     }

void RIPTable::updateTable ( RIPTable another_table ) [inline]
 

Updates the table.

Parameters:
another_table   Received RIP table.

Definition at line 187 of file RIPTable.java.

00188     {
00189         int i;
00190         int j;
00191         RIPTableElement old_element;
00192         RIPTableElement new_element;
00193 
00194         for (i=0; i<another_table.size(); i++)
00195             {
00196                 new_element = another_table.elementAt(i);
00197                 j = findEntry(new_element.destination_node);
00198                 if (j != -1)
00199                     {
00200                         old_element = (RIPTableElement)table.elementAt(j);
00201                         if (old_element.cost > new_element.cost + 1)
00202                             {
00203                                 /* Better route exists. */
00204                                 old_element.cost = new_element.cost + 1;
00205                                 old_element.next_node = new_element.next_node;
00206                                 old_element.route_change_flag = true;
00207                                 old_element.route_timeout = 5;
00208                                 old_element.garbage_timeout = 5;
00209                             }
00210                         else if (old_element.next_node == new_element.next_node)
00211                             {
00212                                 /* Update if required. */
00213                                 old_element.cost = new_element.cost + 1;
00214                                 old_element.route_change_flag = true;
00215                                 old_element.route_timeout = 5;
00216                                 old_element.garbage_timeout = 5;
00217                             }
00218                         else
00219                             {
00220                                 old_element.route_change_flag = false;
00221                             }
00222                     }
00223             
00224                 else
00225                     {
00226                         /* Create new table element. */
00227                         addElement(new_element.destination_node, new_element.next_node,
00228                                    new_element.cost + 1
00229                                    );
00230                     }
00231                 /* else */
00232             }
00233         /* for */ /* Process all elements. */
00234     }

void RIPTable::updateTable ( Node node ) [inline]
 

Updates the table. Instead of sending updates as packets through the network, every node will update table directly (for simplicity).

Parameters:
node   Node from whom to take the RIP table.

Definition at line 88 of file RIPTable.java.

Referenced by Node::updateRoutingTable().

00089     {
00090         int i;
00091         int j;
00092         RIPTable another_table = node.getRIPTable();
00093         RIPTableElement old_element;
00094         RIPTableElement new_element;
00095 
00096         /* Metric update for node. */
00097         j = findEntry(node);
00098         if (j >= 0)
00099             {
00100                 old_element = (RIPTableElement)table.elementAt(j);
00101                 old_element.cost = 1;
00102                 old_element.next_node = node;
00103                 old_element.route_change_flag = true;
00104                 old_element.route_timeout = 5;
00105                 old_element.garbage_timeout = 5;
00106             }
00107         /* Metric update. */
00108         for (i=0; i<another_table.size(); i++)
00109             {
00110                 new_element = another_table.elementAt(i);
00111                 j = findEntry(new_element.destination_node);
00112                 if ((j >= 0) &&
00113                     (new_element.destination_node != owner_node)
00114                     )
00115                     {
00116                         old_element = (RIPTableElement)table.elementAt(j);
00117                         if (new_element.next_node == owner_node)
00118                             {
00119                                 /* Split horizon with poisoned reverse. Cost is 16. */
00120                                 if (old_element.cost >= 16)
00121                                     {
00122                                         /* Better route exists. */
00123                                         old_element.cost = 16;
00124                                         old_element.next_node = node;
00125                                         old_element.route_change_flag = true;
00126                                         old_element.route_timeout = 5;
00127                                         old_element.garbage_timeout = 5;
00128                                     }
00129                                 else if (old_element.next_node == node)
00130                                     {
00131                                         /* Update is required. */
00132                                         old_element.cost = 16;
00133                                         old_element.route_change_flag = true;
00134                                         old_element.route_timeout = 5;
00135                                         old_element.garbage_timeout = 5;
00136                                     }
00137                                 else
00138                                     {
00139                                         old_element.route_change_flag = false;
00140                                     }
00141 
00142                             }
00143                         else
00144                             {
00145                                 /* Normal update. */
00146                                 if (old_element.cost >= new_element.cost + 1)
00147                                     {
00148                                         /* Better route exists. */
00149                                         old_element.cost = new_element.cost + 1;
00150                                         old_element.next_node = node;
00151                                         old_element.route_change_flag = true;
00152                                         old_element.route_timeout = 5;
00153                                         old_element.garbage_timeout = 5;
00154                                     }
00155                                 else if (old_element.next_node == node)
00156                                     {
00157                                         /* Update is required. */
00158                                         old_element.cost = new_element.cost + 1;
00159                                         old_element.route_change_flag = true;
00160                                         old_element.route_timeout = 5;
00161                                         old_element.garbage_timeout = 5;
00162                                     }
00163                                 else
00164                                     {
00165                                         old_element.route_change_flag = false;
00166                                     }
00167                             }
00168                         /* else */
00169                     }
00170                 else if(new_element.destination_node != owner_node)
00171                     {
00172                         /* Create new table element. */
00173                         addElement(new_element.destination_node, node,
00174                                    new_element.cost + 1
00175                                    );
00176                     }
00177                 /* else */
00178             }
00179         /* for */ /* Process all elements. */
00180     }


Member Data Documentation

Node RIPTable::owner_node [private]
 

Owner node.

Definition at line 25 of file RIPTable.java.

Vector RIPTable::table = new Vector() [private]
 

RIP table.

Definition at line 22 of file RIPTable.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