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

java.lang.Object
  extended by uk.org.arlott.simon.hw.f24.lbsta.BridgePort
All Implemented Interfaces:
PacketDestination, PacketTransport

public class BridgePort
extends java.lang.Object
implements PacketTransport, PacketDestination

Represents a bridge port on the network.


Field Summary
static int BLOCKING
          Bridge port blocking state.
private  Bridge bridge
          The bridge this port is part of.
private  java.util.HashSet<BridgePort> bridgePorts
          The bridge ports connected to this brigde port.
 boolean configPending
          Configuration message pending flag.
 int designatedBridge
          The designated bridge on the LAN.
 int designatedCost
          The designated cost on the LAN.
 int designatedPort
          The designated port on the LAN.
 int designatedRoot
          The designated root on the LAN.
static int DISABLED
          Bridge port disabled state.
 int forwardDelayTimer
          The forward delay timer.
static int FORWARDING
          Bridge port forwarding state.
 int holdTimer
          The hold timer.
static int HORIZONTAL_LEFT
          Bridge port is horizonal at the left of the bridge.
static int HORIZONTAL_RIGHT
          Bridge port is horizonal at the right of the bridge.
private  int id
          The ID of this bridge port.
private  java.util.HashSet<LAN> lans
          The LANs connected to this bridge port.
static int LEARNING
          Bridge port learning state.
static int LISTENING
          Bridge port listening state.
static int MAX_ID
          Maximum bridge port ID.
 int messageAgeTimer
          The message age timer.
private  java.util.HashSet<Packet> packets
          The packets on this bridge port.
private  int pathCost
          The path cost of this bridge port.
private  int state
          The state of this bridge port.
static java.lang.String[] STATES
          The port states as strings.
 boolean topologyChangeAcknowledge
          Topology change acknowledgement flag.
static int VERTICAL_BOTTOM
          Bridge port is vertical at the bottom of the bridge.
static int VERTICAL_TOP
          Bridge port is vertical at the top of the bridge.
private  int x
          The X co-ordinate position of this bridge port.
private  int y
          The Y co-ordinate position of this bridge port.
 
Constructor Summary
BridgePort(Bridge bridge, int x, int y)
          Creates a new BridgePort.
 
Method Summary
 void addPacket(Packet p)
          Adds a packet to this bridge port.
private  void checkConnect()
          Check if the bridge is connected to anything and enable the port if possible.
private  void checkDisconnect()
          Check if the bridge is connected to anything and disable the port if neccessary.
 void connect(BridgePort b)
          Connects to a bridge port.
 void connect(LAN l)
          Connects to LAN.
 void disable()
          Disable the port.
 void disconnect(BridgePort b)
          Disconnects from a bridge port.
 void disconnect(LAN l)
          Disconnects from a LAN.
 void disconnectAll()
          Disconnects from all LANs and bridge ports and removes all packets.
 void enable()
          Enable the port (only if it is connected to something).
 Bridge getBridge()
          Gets the bridge this port is connected to.
 java.util.Vector<BridgePort> getBridgePorts()
          Gets all bridge ports connected to this bridge port.
 int getID()
          Gets this bridge port's ID.
 java.util.HashSet<LAN> getLANs()
          Get all LANs connected to this bridge port.
 java.util.Vector<Packet> getPackets()
          Gets all the packets on this bridge port.
 int getPathCost()
          Gets the path cost of this bridge port.
 int getState()
          Gets the state of this bridge port.
 int getType()
          Gets the type of this port.
 int getX()
          Gets the X position of this port.
 int getXoffset()
          Gets the X offset position of this port.
 int getY()
          Gets the Y position of this port.
 int getYoffset()
          Gets the Y offset position of this port.
 boolean isConnected()
          Find out if this bridge port is connected to any LANs or bridge ports.
 boolean isConnectedTo(BridgePort b)
          Find out if this bridge port is connected to another bridge port.
 boolean isConnectedTo(LAN l)
          Find out if this bridge port is connected to a LAN.
 void presetID(int id)
          Presets this bridge port's ID (before it has been connected to anything).
 java.util.Vector<Packet> processPacket(Packet p)
          Processes a packet received by this bridge port.
 void removeAllPackets()
          Removes all packets from this bridge port.
 void removePacket(Packet p)
          Removes a packet from this bridge port.
 void setID(int id)
          Sets this bridge port's ID.
 void setPathCost(int pathCost)
          Sets the path cost of this bridge port.
 void setState(int newState)
          Sets the state of the bridge port.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HORIZONTAL_LEFT

public static final int HORIZONTAL_LEFT
Bridge port is horizonal at the left of the bridge.

See Also:
Constant Field Values

HORIZONTAL_RIGHT

public static final int HORIZONTAL_RIGHT
Bridge port is horizonal at the right of the bridge.

See Also:
Constant Field Values

VERTICAL_TOP

public static final int VERTICAL_TOP
Bridge port is vertical at the top of the bridge.

See Also:
Constant Field Values

VERTICAL_BOTTOM

public static final int VERTICAL_BOTTOM
Bridge port is vertical at the bottom of the bridge.

See Also:
Constant Field Values

DISABLED

public static final int DISABLED
Bridge port disabled state.

See Also:
Constant Field Values

LISTENING

public static final int LISTENING
Bridge port listening state.

See Also:
Constant Field Values

LEARNING

public static final int LEARNING
Bridge port learning state.

See Also:
Constant Field Values

FORWARDING

public static final int FORWARDING
Bridge port forwarding state.

See Also:
Constant Field Values

BLOCKING

public static final int BLOCKING
Bridge port blocking state.

See Also:
Constant Field Values

STATES

public static final java.lang.String[] STATES
The port states as strings.


MAX_ID

public static final int MAX_ID
Maximum bridge port ID.

See Also:
Constant Field Values

bridge

private Bridge bridge
The bridge this port is part of.


packets

private java.util.HashSet<Packet> packets
The packets on this bridge port.


lans

private java.util.HashSet<LAN> lans
The LANs connected to this bridge port.


bridgePorts

private java.util.HashSet<BridgePort> bridgePorts
The bridge ports connected to this brigde port.


x

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


y

private int y
The Y co-ordinate position of this bridge port.


id

private int id
The ID of this bridge port. Negative if not connected to anything.


state

private int state
The state of this bridge port.


pathCost

private int pathCost
The path cost of this bridge port.


messageAgeTimer

public int messageAgeTimer
The message age timer.


forwardDelayTimer

public int forwardDelayTimer
The forward delay timer.


holdTimer

public int holdTimer
The hold timer.


designatedRoot

public int designatedRoot
The designated root on the LAN.


designatedBridge

public int designatedBridge
The designated bridge on the LAN.


designatedPort

public int designatedPort
The designated port on the LAN.


designatedCost

public int designatedCost
The designated cost on the LAN.


topologyChangeAcknowledge

public boolean topologyChangeAcknowledge
Topology change acknowledgement flag.


configPending

public boolean configPending
Configuration message pending flag.

Constructor Detail

BridgePort

public BridgePort(Bridge bridge,
                  int x,
                  int y)
Creates a new BridgePort.

Parameters:
bridge - The Bridge this port is part of.
x - The X co-ordinate position of this port.
y - The Y co-ordinate position of this port.
Method Detail

getX

public int getX()
Gets the X position of this port.

Returns:
The X co-ordinate position of this port.

getY

public int getY()
Gets the Y position of this port.

Returns:
The Y co-ordinate position of this port.

getXoffset

public int getXoffset()
Gets the X offset position of this port.

Returns:
The X co-ordinate offset from the bridge.

getYoffset

public int getYoffset()
Gets the Y offset position of this port.

Returns:
The Y co-ordinate offset from the bridge.

getType

public int getType()
Gets the type of this port.

Returns:
The type (based on the position around the bridge) of this port.

getID

public int getID()
Gets this bridge port's ID.

Returns:
The port ID.

setID

public void setID(int id)
Sets this bridge port's ID.

Parameters:
id - The new ID.

presetID

public void presetID(int id)
Presets this bridge port's ID (before it has been connected to anything).

Parameters:
id - The new ID.

getState

public int getState()
Gets the state of this bridge port.

Returns:
The current state of the bridge port.

setState

public void setState(int newState)
Sets the state of the bridge port.

Parameters:
newState - The new state of the bridge port.

getPathCost

public int getPathCost()
Gets the path cost of this bridge port.

Returns:
The path cost of the bridge port.

setPathCost

public void setPathCost(int pathCost)
Sets the path cost of this bridge port.

Parameters:
pathCost - The new path cost of the bridge port.

getBridge

public Bridge getBridge()
Gets the bridge this port is connected to.

Returns:
The Bridge this port is on.

isConnected

public boolean isConnected()
Find out if this bridge port is connected to any LANs or bridge ports.

Returns:
true if connected to something.

getLANs

public java.util.HashSet<LAN> getLANs()
Get all LANs connected to this bridge port.

Returns:
All connected LANs.

connect

public void connect(LAN l)
Connects to LAN.

Parameters:
l - The LAN to connect to.

isConnectedTo

public boolean isConnectedTo(LAN l)
Find out if this bridge port is connected to a LAN.

Parameters:
l - The LAN.
Returns:
true if connected to l.

disconnect

public void disconnect(LAN l)
Disconnects from a LAN.

Parameters:
l - The LAN to disconnect from.

getBridgePorts

public java.util.Vector<BridgePort> getBridgePorts()
Gets all bridge ports connected to this bridge port.

Returns:
All connected bridge ports.

connect

public void connect(BridgePort b)
Connects to a bridge port.

Parameters:
b - The BridgePort to connect to.

isConnectedTo

public boolean isConnectedTo(BridgePort b)
Find out if this bridge port is connected to another bridge port.

Parameters:
b - The other BridgePort.
Returns:
true if connected to b.

disconnect

public void disconnect(BridgePort b)
Disconnects from a bridge port.

Parameters:
b - The BridgePort to disconnect from.

disconnectAll

public void disconnectAll()
Disconnects from all LANs and bridge ports and removes all packets.


addPacket

public void addPacket(Packet p)
Adds a packet to this bridge port.

Specified by:
addPacket in interface PacketTransport
Parameters:
p - The Packet to add.

removePacket

public void removePacket(Packet p)
Removes a packet from this bridge port.

Specified by:
removePacket in interface PacketTransport
Parameters:
p - The Packet to remove.

getPackets

public java.util.Vector<Packet> getPackets()
Gets all the packets on this bridge port.

Returns:
The packets on this bridge port.

removeAllPackets

public void removeAllPackets()
Removes all packets from this bridge port.


processPacket

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

Specified by:
processPacket in interface PacketDestination
Parameters:
p - The Packet to process.
Returns:
Any new packets that the processing caused.

checkConnect

private void checkConnect()
Check if the bridge is connected to anything and enable the port if possible.


checkDisconnect

private void checkDisconnect()
Check if the bridge is connected to anything and disable the port if neccessary.


enable

public void enable()
Enable the port (only if it is connected to something).


disable

public void disable()
Disable the port.