uk.org.arlott.simon.hw.f24.lbsta
Class Bridge

java.lang.Object
  extended by uk.org.arlott.simon.hw.f24.lbsta.Bridge

public class Bridge
extends java.lang.Object

Represents a bridge on the network.


Nested Class Summary
 class Bridge.HostCacheEntry
          Host Cache Entry object.
 
Field Summary
private static boolean[] allIDs
          All the bridge IDs in use.
private  int forwardDelay
          Forward Delay set by root bridge in seconds.
private  int helloTime
          Hello Time set by root bridge in seconds.
private  int helloTimer
          Current Hello Time timer in milliseconds.
private static int holdTime
          The Hold Time.
private  java.util.HashMap<java.lang.Integer,Bridge.HostCacheEntry> hostCache
          The host cache.
private  int id
          Bridge's ID.
private  boolean inNetwork
          Whether or not this bridge is in the network.
private static int lastAssigned
          The last assigned bridge ID.
private  Log log
          The event log.
static int MAX_ID
          The maximum bridge ID.
static int MAX_PORTS
          The number of bridge ports to create.
private  int maxAge
          Max Age set by root bridge in seconds.
private static int MESSAGE_AGE_INCREMENT
          The message age increment per hop.
private  int myForwardDelay
          Bridge's set Forward Delay in seconds.
private  int myHelloTime
          Bridge's set Hello Time in seconds.
private  int myMaxAge
          Bridge's set Max Age in seconds.
private  Network network
          The network this bridge is on.
 BridgePort[] ports
          The bridge ports on this bridge
private  java.util.Vector<Packet> queuedPackets
          Packets queued to be added to the network.
private  int rootID
          Current root bridge's ID.
private  int rootPathCost
          Path cost to root.
private  BridgePort rootPort
          Root port.
static int TIME_INCREMENT
          The time increment per loop iteration.
private  boolean topologyChange
          The Topology Change flag.
private  boolean topologyChangeDetected
          The Topology Change Detected flag.
private  int topologyChangeNotificationTimer
          The Toplogy Change Notification timer.
private  int topologyChangeTimer
          The Topology Change timer.
 int x
          The X co-ordinate position of this bridge.
 int y
          The X co-ordinate position of this bridge.
 
Constructor Summary
Bridge(int x, int y, Network network)
          Creates a new Bridge.
 
Method Summary
private  void acknowledgeTopologyChange(BridgePort port)
           
 void addToNetwork()
          Adds this bridge to the network.
private  void becomeDesignatedPort(BridgePort bp)
           
private  void configBPDUGeneration()
           
private  void configurationUpdate()
           
private  boolean designatedForSomePort()
           
private  boolean designatedPort(BridgePort port)
           
private  void designatedPortSelection()
           
 void disablePort(BridgePort port)
           
 void enablePort(BridgePort port)
           
private static int findFreeID()
          Finds an unused bridge ID.
private  void forwardDelayTimerExpiry(BridgePort port)
           
 int getForwardDelay()
          Gets the bridge Forward Delay.
 int getHelloTime()
          Gets the bridge Hello Time.
 java.util.HashMap<java.lang.Integer,Bridge.HostCacheEntry> getHostCache()
          Gets the host cache.
 int getID()
          Gets the ID.
 java.lang.String[] getLog()
          Gets the log entries for this bridge.
 int getMaxAge()
          Gets the bridge Max Age.
 int getNetworkForwardDelay()
          Gets the network Forward Delay.
 int getNetworkHelloTime()
          Gets the network Hello Time.
 int getNetworkMaxAge()
          Gets the network Max Age.
 int getRootID()
          Gets the root ID.
private  void helloTimerExpiry()
           
private  void holdTimerExpiry(BridgePort port)
           
 void initialise()
           
private  void initialisePort(BridgePort port)
           
private  void makeBlocking(BridgePort port)
           
private  void makeForwarding(BridgePort port)
           
private  void messageAgeTimerExpiry(BridgePort port)
           
 void networkChanged()
          Indicates that the network has been modified.
private  void portStateSelection()
           
 java.util.Vector<Packet> processPacket(BridgePort port, Packet p)
          Processes a packet received by a bridge port.
private  void receivedConfigBPDU(BridgePort port, ConfigurationMessage config)
           
private  void receivedTCNBPDU(BridgePort port, TopologyChangeMessage tcn)
           
private  void recordConfigInformation(BridgePort port, ConfigurationMessage config)
           
private  void recordConfigTimeoutValues(ConfigurationMessage config)
           
 void removeFromNetwork()
          Removes this host from the network.
private  void reply(BridgePort port)
           
 void reset()
          Resets this bridge.
private  void rootSelection()
           
 void setForwardDelay(int forwardDelay)
          Sets the bridge Forward Delay.
 void setHelloTime(int helloTime)
          Sets the bridge Hello Time.
private  boolean setID(Bridge b, int newID)
          Sets the ID of a bridge.
 boolean setID(int newID)
          Sets the ID.
private static boolean setInNetwork(Bridge b, boolean inNetwork)
          Updates the in network state of a bridge.
 void setMaxAge(int maxAge)
          Sets the bridge Max Age.
 void setPathCost(BridgePort port, int pathCost)
           
private  boolean superSedesPortInfo(BridgePort port, ConfigurationMessage config)
           
 java.util.Vector<Packet> tick()
          Performs one network simulation iteration.
private  void topologyChangeAcknowledged()
           
private  void topologyChangeDetection()
           
private  void topologyChangeNotificationTimerExpiry()
           
private  void topologyChangeTimerExpiry()
           
private  void transmitConfig(BridgePort port)
           
private  void transmitTCN()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PORTS

public static final int MAX_PORTS
The number of bridge ports to create.

See Also:
Constant Field Values

MAX_ID

public static final int MAX_ID
The maximum bridge ID.

See Also:
Constant Field Values

TIME_INCREMENT

public static final int TIME_INCREMENT
The time increment per loop iteration.

See Also:
Constant Field Values

MESSAGE_AGE_INCREMENT

private static final int MESSAGE_AGE_INCREMENT
The message age increment per hop.

See Also:
Constant Field Values

ports

public BridgePort[] ports
The bridge ports on this bridge


x

public int x
The X co-ordinate position of this bridge.


y

public int y
The X co-ordinate position of this bridge.


log

private Log log
The event log.


network

private Network network
The network this bridge is on.


queuedPackets

private java.util.Vector<Packet> queuedPackets
Packets queued to be added to the network.


hostCache

private java.util.HashMap<java.lang.Integer,Bridge.HostCacheEntry> hostCache
The host cache.


allIDs

private static boolean[] allIDs
All the bridge IDs in use.


lastAssigned

private static int lastAssigned
The last assigned bridge ID.


inNetwork

private boolean inNetwork
Whether or not this bridge is in the network.


id

private int id
Bridge's ID.


rootID

private int rootID
Current root bridge's ID.


rootPathCost

private int rootPathCost
Path cost to root.


rootPort

private BridgePort rootPort
Root port.


helloTimer

private int helloTimer
Current Hello Time timer in milliseconds.


myHelloTime

private int myHelloTime
Bridge's set Hello Time in seconds.


helloTime

private int helloTime
Hello Time set by root bridge in seconds.


myMaxAge

private int myMaxAge
Bridge's set Max Age in seconds.


maxAge

private int maxAge
Max Age set by root bridge in seconds.


myForwardDelay

private int myForwardDelay
Bridge's set Forward Delay in seconds.


forwardDelay

private int forwardDelay
Forward Delay set by root bridge in seconds.


topologyChange

private boolean topologyChange
The Topology Change flag.


topologyChangeDetected

private boolean topologyChangeDetected
The Topology Change Detected flag.


topologyChangeTimer

private int topologyChangeTimer
The Topology Change timer.


topologyChangeNotificationTimer

private int topologyChangeNotificationTimer
The Toplogy Change Notification timer.


holdTime

private static final int holdTime
The Hold Time.

See Also:
Constant Field Values
Constructor Detail

Bridge

public Bridge(int x,
              int y,
              Network network)
Creates a new Bridge.

Parameters:
x - The X co-ordinate position.
y - The Y co-ordinate position.
network - The Network this bridge is on.
Method Detail

networkChanged

public void networkChanged()
Indicates that the network has been modified.


addToNetwork

public void addToNetwork()
                  throws TooManyBridgesException
Adds this bridge to the network.

Throws:
TooManyBridgesException - If there are too many bridges on the network already.

removeFromNetwork

public void removeFromNetwork()
Removes this host from the network.


setInNetwork

private static boolean setInNetwork(Bridge b,
                                    boolean inNetwork)
Updates the in network state of a bridge.

Parameters:
b - The Bridge to modify.
inNetwork - Whether or not the host is in the network or not.
Returns:
true if the action was successful.

findFreeID

private static int findFreeID()
Finds an unused bridge ID.

Returns:
The next free bridge ID.

getID

public int getID()
Gets the ID.

Returns:
This bridge's ID.

setID

public boolean setID(int newID)
Sets the ID.

Parameters:
newID - The new ID for the bridge.
Returns:
true if the ID is not already in use.

setID

private boolean setID(Bridge b,
                      int newID)
Sets the ID of a bridge.

Parameters:
b - The Bridge to modify.
newID - The new ID of the bridge.
Returns:
true if the ID is not already in use.

getRootID

public int getRootID()
Gets the root ID.

Returns:
The root ID as seen by this bridge.

getNetworkHelloTime

public int getNetworkHelloTime()
Gets the network Hello Time.

Returns:
The Hello Time in use by the network.

getHelloTime

public int getHelloTime()
Gets the bridge Hello Time.

Returns:
The Hello Time configured for this bridge.

setHelloTime

public void setHelloTime(int helloTime)
Sets the bridge Hello Time.

Parameters:
helloTime - The Hello Time configured for this bridge.

getNetworkMaxAge

public int getNetworkMaxAge()
Gets the network Max Age.

Returns:
The Max Age in use by the network.

getMaxAge

public int getMaxAge()
Gets the bridge Max Age.

Returns:
The Max Age configured for this bridge.

setMaxAge

public void setMaxAge(int maxAge)
Sets the bridge Max Age.

Parameters:
maxAge - The Max Age configured for this bridge.

getNetworkForwardDelay

public int getNetworkForwardDelay()
Gets the network Forward Delay.

Returns:
The Forward Delay in use by the network.

getForwardDelay

public int getForwardDelay()
Gets the bridge Forward Delay.

Returns:
The Forward Delay configured for this bridge.

setForwardDelay

public void setForwardDelay(int forwardDelay)
Sets the bridge Forward Delay.

Parameters:
forwardDelay - The Forward Delay configured for this bridge.

getHostCache

public java.util.HashMap<java.lang.Integer,Bridge.HostCacheEntry> getHostCache()
Gets the host cache.

Returns:
The current host cache.

getLog

public java.lang.String[] getLog()
Gets the log entries for this bridge.

Returns:
The log as an array of strings.

reset

public void reset()
Resets this bridge.


tick

public java.util.Vector<Packet> tick()
Performs one network simulation iteration.

Returns:
Any new packets that the processing caused.

processPacket

public java.util.Vector<Packet> processPacket(BridgePort port,
                                              Packet p)
Processes a packet received by a bridge port.

Parameters:
port - The BridgePort the packet was received on.
p - The Packet to process.
Returns:
Any new packets that the processing caused.

transmitConfig

private void transmitConfig(BridgePort port)

superSedesPortInfo

private boolean superSedesPortInfo(BridgePort port,
                                   ConfigurationMessage config)

recordConfigInformation

private void recordConfigInformation(BridgePort port,
                                     ConfigurationMessage config)

recordConfigTimeoutValues

private void recordConfigTimeoutValues(ConfigurationMessage config)

configBPDUGeneration

private void configBPDUGeneration()

designatedPort

private boolean designatedPort(BridgePort port)

reply

private void reply(BridgePort port)

transmitTCN

private void transmitTCN()

configurationUpdate

private void configurationUpdate()

rootSelection

private void rootSelection()

designatedPortSelection

private void designatedPortSelection()

becomeDesignatedPort

private void becomeDesignatedPort(BridgePort bp)

portStateSelection

private void portStateSelection()

makeForwarding

private void makeForwarding(BridgePort port)

makeBlocking

private void makeBlocking(BridgePort port)

topologyChangeDetection

private void topologyChangeDetection()

topologyChangeAcknowledged

private void topologyChangeAcknowledged()

acknowledgeTopologyChange

private void acknowledgeTopologyChange(BridgePort port)

receivedConfigBPDU

private void receivedConfigBPDU(BridgePort port,
                                ConfigurationMessage config)

receivedTCNBPDU

private void receivedTCNBPDU(BridgePort port,
                             TopologyChangeMessage tcn)

helloTimerExpiry

private void helloTimerExpiry()

messageAgeTimerExpiry

private void messageAgeTimerExpiry(BridgePort port)

forwardDelayTimerExpiry

private void forwardDelayTimerExpiry(BridgePort port)

designatedForSomePort

private boolean designatedForSomePort()

topologyChangeNotificationTimerExpiry

private void topologyChangeNotificationTimerExpiry()

topologyChangeTimerExpiry

private void topologyChangeTimerExpiry()

holdTimerExpiry

private void holdTimerExpiry(BridgePort port)

initialise

public void initialise()

initialisePort

private void initialisePort(BridgePort port)

enablePort

public void enablePort(BridgePort port)

disablePort

public void disablePort(BridgePort port)

setPathCost

public void setPathCost(BridgePort port,
                        int pathCost)