All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class network.Router

java.lang.Object
   |
   +----timer.TimerClient
           |
           +----network.Router

public class Router
extends TimerClient
implements Node, Runnable
The implementation of a router. Routers connect to multiple links (either point-to-point or broadcast), and forward packets between them.

The basic implementation provided maintains a FIFO queue of packets to be dealt with, and forwards packets to all network links other than the one they arrived on. If the queue overflows then packets are dropped. This implementation also names each router so that debug messages can make sense.

You will need to add code to enable routers, by cooperating with each other and with the RoutedNetworkEdges at the edges of the network, to discover the network topology and route packets more efficiently (at the very least your routers should forward packets out only one link, and maintain the property that they make it to their destinations.

You will most likely need to modify run to handle forwarding, and either PacketArrived or run to deal with packets for your topology discovery. If you need to add fields to packets (you will) you should modify the class NetworkPacket.

See Also:
Node, RoutedNetworkEdge, NetworkPacket, Link

Constructor Index

 o Router(String, int)
Create a new node.

Method Index

 o AddLink(Link)
Connect a link
 o ConnectedLinks()
Get an enumeration of the currently connected links.
 o PacketArrived(LinkPacket, Link)
The callback for new packets.
 o RemoveLink(Link)
Disconnect a link
 o run()
The forwarding thread.
 o toString()
String representation is name plus type:

Constructors

 o Router
 public Router(String name,
               int queueLen)
Create a new node.

Parameters:
name - the name of this router
queueLen - the number of packets to queue, in packets

Methods

 o PacketArrived
 public void PacketArrived(LinkPacket p,
                           Link l)
The callback for new packets. Appends the new packet to the queue if there is space, otherwise the packet is dropped.

See Also:
PacketArrived
 o run
 public void run()
The forwarding thread. Continually gets packets from the front of the queue and fowards them.

The provided algorithm forwards packets to all other links, and also implements a time-to-live field, which limits the number of hops. This field is added in NetworkPacket, and a constructor is used there to set the default ttl to 10 hops.

See Also:
NetworkPacket
 o ConnectedLinks
 protected Enumeration ConnectedLinks()
Get an enumeration of the currently connected links.

Returns:
an enumeration of the links
See Also:
Enumeration
 o AddLink
 public void AddLink(Link l)
Connect a link

See Also:
AddLink
 o RemoveLink
 public void RemoveLink(Link l)
Disconnect a link

See Also:
RemoveLink
 o toString
 public String toString()
String representation is name plus type:

Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index