// $Id: RoutingTable.java,v 1.14 2007/11/08 07:14:17 zahorjan Exp $ import java.util.*; import org.jgrapht.graph.*; import org.jgrapht.traverse.*; /** * For simplicity, there is only one routing table class. It keeps * next-hop information, which they all do. It also keeps distance * to the destination, which not all need or do. *

* These routing tables can create a vector of changes made to them. * This is useful in sending 'diffs' around in update packets. */ public class RoutingTable { /** * A class encapsulated the notion of a routing table entry. */ public class Entry { public Node nextHop; public int dist; public Entry() { nextHop = null; dist = ConstAlg.INFINITY; } /** * Copy constructor. */ public Entry(Entry other) { this.nextHop = other.nextHop; this.dist = other.dist; } } /** * The actual routing table. */ protected Entry[] table; /** * A class representing a single log entry. */ class LogEntry { public Node dest; public int dist; public LogEntry(Node d) { dest = d; dist = table[dest.getUID()].dist; } } /** * The 'diff' log used to record changes to the table. */ protected Vector log; /** * Controls whether or not logging is performed. */ protected boolean doLog; /** * Indicates whether or not an entry has been written since * startLog() was called. */ private boolean[] changed; /** * Returns the number of entries in the routing table. */ public int size() { return table.length; } /** * Indicate that want to keep log of changes starting now. */ public void startLog() { log = null; // get rid of any old log for ( int n=0; n getLog() { // if the log doesn't exist, create it if ( log == null ) { log = new Vector(); for ( int n=0; n