net.clackrouter.router.core
Class Router

java.lang.Object
  extended by java.lang.Thread
      extended by net.clackrouter.router.core.Router
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable

public class Router
extends java.lang.Thread
implements java.io.Serializable

Main router class that contains all components representing a given host in a Clack topology and handles all packet receiving and transmission.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int DEFAULT_ROUTE_METRIC
           
static int ROUTER_ALERT_TIME
          Time between alerts for any host using this router's Alerter.
static int ROUTER_SLEEP_MSEC
          Time the router pauses during each iteration of the main processing loop in run().
 java.lang.String setup_routing_key
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Router(VNSProtocolManager proto_manager, TopologyModel model, boolean isGUI)
           
 
Method Summary
 boolean addComponent(ClackComponent comp)
          Add a component to this router's list.
 void addLocalLinkChangeListener(LocalLinkChangedListener l)
           
 void addLocalLinkInfo(java.net.InetAddress net, java.net.InetAddress mask, java.net.InetAddress nh, java.lang.String iface, boolean is_up, int metric, boolean is_routing_iface)
           
 void addNeedToNotify(Alarm a)
           
 void configureIPInterface(java.lang.String iface_name, java.net.InetAddress addr, java.net.InetAddress mask)
          Let's external entities set the IP address and subnet of a particular interface on the router This is a bit tricky, because they need to change both the input and output interfaces, and repaint them.
 void endTest()
          signals the end of the current test
 Alerter getAlerter()
          Get the router's Alerter for registering a one-time callback.
 ClackComponent[] getAllComponents()
          Get all components contained within the router.
 ClackComponent getComponent(java.lang.String component_name)
          Retrieve a component by name
 java.net.InetAddress getDefaultNextHop()
           
 java.lang.String getDefaultRouteIface()
           
 ClackDocument getDocument()
          Access the document this router is associated with
 java.lang.String getHost()
          Get this router's name within the topology
 InterfaceIn[] getInputInterfaces()
          Get an array of all Input Interfaces.
 Interface getInterfaceByName(java.lang.String devicename)
          Returns the input interface associated with the specified device.
 java.util.Hashtable getLocalLinkInfo()
           
 InterfaceOut[] getOutputInterfaces()
          Get an array of all output interfaces.
 boolean getPendingError()
           
 int getPort()
          Get the port this router is using to connect to the VNS server
 VNSProtocolManager getProtocolManager()
           
 RoutingTable getRoutingTable()
          Returns the routing table of the IPRouteLookup component in this router
 java.lang.String getServer()
          Get the VNS server name that this router is connected to
 TCP getTCPStack()
          Access the TCPStack of this router (may be null)
 TimeManager getTimeManager()
           
 int getTopology()
          Get the topology number for this router
 UDP getUDPStack()
          Access the UDPStack of this router (may be null)
 void handlePacket(VNSPacket packet)
          Handles packets that arrive at one of the router's input interfaces.
 boolean initializeNonVNSRouter(TopologyModel.Host host)
           
 boolean initializeVNSConnectedRouter()
          Reads interface hardware information from the ProtocolManager (must be called before Router is started).
 boolean isGUI()
          indicates whether this router is visible as a full router in the Clack Application
 boolean isLocalRouter()
          Find out if this router is local (ie: not connected to VNS) This must be tested before any checking any of getTopology(), getHost(), getPort() or getServer().
 void registerForPoll(ClackComponent comp)
          Used by components to register for a callback once per router processing loop.
 void removeComponent(ClackComponent comp)
          Removes the specified component from the router's list.
 void removeComponent(java.lang.String comp_name)
          Removes the named component from the Router's list.
 void removeFromPoll(ClackComponent comp)
          Unregisters a component from being polled.
 void removeLocalLinkChangeListener(LocalLinkChangedListener l)
           
 void run()
          Main processing loop for a Clack Router.
 void runTest(ClackRouterTest test, boolean disconnect)
          Run the specified test on this router.
 void sendOutgoingPacket(VNSEthernetPacket packet)
          Method used by InterfaceOut components to send packets to VNS .
 void setDefaultRouting(java.net.InetAddress next_hop, java.lang.String iface)
           
 void setDocument(ClackDocument doc)
          Set the document this router is associated with
 void setIfaceStatus(java.lang.String iface_name, boolean is_up)
           
 void setIPRouteLookup(IPRouteLookup iprl)
           
 void setPendingError(boolean e)
           
 void setRoutingTable(RoutingTable table)
          Sets the routing table for this router, overwriting all previous entries.
 void setTCPStack(TCP t)
           
 void setUDPStack(UDP u)
           
 void startEthereal()
           
 void stopEthereal()
           
 void stopRouterAndDisconnect()
          Signals the Router to end processing and disconnect from VNS.
 void updateLinkMetric(java.lang.String iface_str, int metric)
           
 void updateRouteTableStateInGUI()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ROUTER_ALERT_TIME

public static int ROUTER_ALERT_TIME
Time between alerts for any host using this router's Alerter.


ROUTER_SLEEP_MSEC

public static int ROUTER_SLEEP_MSEC

Time the router pauses during each iteration of the main processing loop in run().

Used so that the router does not eat up a majority of the CPU cycles on a computer by just spining in the processing loop


DEFAULT_ROUTE_METRIC

public static final int DEFAULT_ROUTE_METRIC
See Also:
Constant Field Values

setup_routing_key

public java.lang.String setup_routing_key
Constructor Detail

Router

public Router(VNSProtocolManager proto_manager,
              TopologyModel model,
              boolean isGUI)
Method Detail

initializeVNSConnectedRouter

public boolean initializeVNSConnectedRouter()
                                     throws java.lang.Exception
Reads interface hardware information from the ProtocolManager (must be called before Router is started).

Throws:
java.lang.Exception

initializeNonVNSRouter

public boolean initializeNonVNSRouter(TopologyModel.Host host)
                               throws java.lang.Exception
Throws:
java.lang.Exception

run

public void run()

Main processing loop for a Clack Router.

In each loop, we check if we need to exit, sleep, poll() each registered component, and then process a single piece of data from the protocol manager.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

handlePacket

public void handlePacket(VNSPacket packet)

Handles packets that arrive at one of the router's input interfaces.

The router checks that the packet info is valid and then hands it off to the correct InterfaceIn component. We also notify the topology link to let it know that a packet has arrived


sendOutgoingPacket

public void sendOutgoingPacket(VNSEthernetPacket packet)
Method used by InterfaceOut components to send packets to VNS .

Parameters:
packet - the Ethernet frame to be sent

stopRouterAndDisconnect

public void stopRouterAndDisconnect()
Signals the Router to end processing and disconnect from VNS.


registerForPoll

public void registerForPoll(ClackComponent comp)
Used by components to register for a callback once per router processing loop.

Parameters:
comp - component to be polled

removeFromPoll

public void removeFromPoll(ClackComponent comp)
Unregisters a component from being polled.

Parameters:
comp -

getComponent

public ClackComponent getComponent(java.lang.String component_name)
Retrieve a component by name


addComponent

public boolean addComponent(ClackComponent comp)
Add a component to this router's list.

Parameters:
comp - component to be added
Returns:
returns whether the addition was successful

removeComponent

public void removeComponent(java.lang.String comp_name)
Removes the named component from the Router's list.


removeComponent

public void removeComponent(ClackComponent comp)
Removes the specified component from the router's list.


getAllComponents

public ClackComponent[] getAllComponents()
Get all components contained within the router.


setRoutingTable

public void setRoutingTable(RoutingTable table)
                     throws java.lang.Exception
Sets the routing table for this router, overwriting all previous entries.

Throws:
java.lang.Exception

getRoutingTable

public RoutingTable getRoutingTable()
Returns the routing table of the IPRouteLookup component in this router

Returns:
the routing table, or null if not IPRouteLookup component is found.

setIPRouteLookup

public void setIPRouteLookup(IPRouteLookup iprl)

getInputInterfaces

public InterfaceIn[] getInputInterfaces()
Get an array of all Input Interfaces.


getOutputInterfaces

public InterfaceOut[] getOutputInterfaces()
Get an array of all output interfaces.


getInterfaceByName

public Interface getInterfaceByName(java.lang.String devicename)
Returns the input interface associated with the specified device.


getAlerter

public Alerter getAlerter()

Get the router's Alerter for registering a one-time callback.

The alerter is used any time a callback is needed. For example, we use this to implement flashing links. This is more light-weight than having each flash spawn its own thread


getProtocolManager

public VNSProtocolManager getProtocolManager()

setTCPStack

public void setTCPStack(TCP t)

getTCPStack

public TCP getTCPStack()
Access the TCPStack of this router (may be null)


setUDPStack

public void setUDPStack(UDP u)

getUDPStack

public UDP getUDPStack()
Access the UDPStack of this router (may be null)


isGUI

public boolean isGUI()
indicates whether this router is visible as a full router in the Clack Application


setDocument

public void setDocument(ClackDocument doc)
Set the document this router is associated with


getDocument

public ClackDocument getDocument()
Access the document this router is associated with


isLocalRouter

public boolean isLocalRouter()
Find out if this router is local (ie: not connected to VNS) This must be tested before any checking any of getTopology(), getHost(), getPort() or getServer().


getTopology

public int getTopology()
Get the topology number for this router


getHost

public java.lang.String getHost()
Get this router's name within the topology


getPort

public int getPort()
Get the port this router is using to connect to the VNS server


getServer

public java.lang.String getServer()
Get the VNS server name that this router is connected to


getTimeManager

public TimeManager getTimeManager()

runTest

public void runTest(ClackRouterTest test,
                    boolean disconnect)
Run the specified test on this router.

Parameters:
test - test to run
disconnect - flag indicated if router should disconnect from other routers and VNS for the test

endTest

public void endTest()
signals the end of the current test


addLocalLinkInfo

public void addLocalLinkInfo(java.net.InetAddress net,
                             java.net.InetAddress mask,
                             java.net.InetAddress nh,
                             java.lang.String iface,
                             boolean is_up,
                             int metric,
                             boolean is_routing_iface)

getLocalLinkInfo

public java.util.Hashtable getLocalLinkInfo()

addLocalLinkChangeListener

public void addLocalLinkChangeListener(LocalLinkChangedListener l)

removeLocalLinkChangeListener

public void removeLocalLinkChangeListener(LocalLinkChangedListener l)

getDefaultNextHop

public java.net.InetAddress getDefaultNextHop()

getDefaultRouteIface

public java.lang.String getDefaultRouteIface()

setDefaultRouting

public void setDefaultRouting(java.net.InetAddress next_hop,
                              java.lang.String iface)

updateRouteTableStateInGUI

public void updateRouteTableStateInGUI()

startEthereal

public void startEthereal()

stopEthereal

public void stopEthereal()

addNeedToNotify

public void addNeedToNotify(Alarm a)

setPendingError

public void setPendingError(boolean e)

getPendingError

public boolean getPendingError()

configureIPInterface

public void configureIPInterface(java.lang.String iface_name,
                                 java.net.InetAddress addr,
                                 java.net.InetAddress mask)
                          throws java.lang.Exception
Let's external entities set the IP address and subnet of a particular interface on the router This is a bit tricky, because they need to change both the input and output interfaces, and repaint them. We also need to alert anyone who is listening for changes to this configuration (e.g., a dynamic routing protocol).

Throws:
java.lang.Exception

setIfaceStatus

public void setIfaceStatus(java.lang.String iface_name,
                           boolean is_up)

updateLinkMetric

public void updateLinkMetric(java.lang.String iface_str,
                             int metric)