at.jku.fim.datalinksimulation.genericdevices
Class InterlinkingDevice

java.lang.Object
  extended by at.jku.fim.datalinksimulation.genericdevices.HardwareComponent
      extended by at.jku.fim.datalinksimulation.genericdevices.InterlinkingDevice
All Implemented Interfaces:
WireConnector
Direct Known Subclasses:
Hub

public abstract class InterlinkingDevice
extends HardwareComponent
implements WireConnector

Title: OSI Simulation Framework

Copyright: (c) 2004-05

Company: FIM@JKU, www.fim.uni-linz.ac.at

Version:
$Id: InterlinkingDevice.java,v 1.1 2005/10/27 13:10:07 aputzinger Exp $
Author:
Andreas Putzinger

Field Summary
private  Wire[] connectedWires
          reference to all connected wires, indexed by port number
private  java.lang.String identifier
          internal identifier
protected  Logger logger
          each interlinking device has its own log
protected  NetworkStack networkStack
          each interlinking device has it's own network stack
protected  int numberOfPorts
          the number of available ports
 
Fields inherited from class at.jku.fim.datalinksimulation.genericdevices.HardwareComponent
networkComponentId
 
Constructor Summary
InterlinkingDevice(java.lang.String identifier, int numberOfPorts)
          Constructor
 
Method Summary
 void bePlugged(Wire wire, int portNr)
          This method should only be called by Wires, which inform this WireConnector that they are connected.
 void beUnplugged(Wire wire, int portNr)
          This method should only be called by Wires, which inform this WireConnector that they are disconnected
 java.util.List getConnectedWires()
           
protected abstract  IncomingNetworkStackConfiguration getIncomingNetworkStackConfiguration()
          This method must be overriden in subclasses.
 int getNextFreePort()
           
 int getNumberOfFreePorts()
           
 int getNumberOfTotalPorts()
           
protected abstract  OutgoingNetworkStackConfiguration getOutgoingNetworkStackConfiguration()
          This method must be overriden in subclasses.
 int getPortOfWire(Wire wire)
           
 Wire getWireInPort(int portNr)
           
 void informAboutDataOnWire(Wire sender, RawData data)
          This method is called whenever a data package is received by a subscribed wire.
 boolean isPortFree(int portNr)
           
 boolean isWireConnected(Wire wireToTest)
          Checks, if a specified wire is connected or not
 java.lang.String toString()
           
 
Methods inherited from class at.jku.fim.datalinksimulation.genericdevices.HardwareComponent
getNetworkComponentId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected final Logger logger
each interlinking device has its own log


networkStack

protected final NetworkStack networkStack
each interlinking device has it's own network stack


numberOfPorts

protected final int numberOfPorts
the number of available ports


connectedWires

private Wire[] connectedWires
reference to all connected wires, indexed by port number


identifier

private java.lang.String identifier
internal identifier

Constructor Detail

InterlinkingDevice

public InterlinkingDevice(java.lang.String identifier,
                          int numberOfPorts)
Constructor

Parameters:
identifier - Identifier for log
numberOfPorts - Number of ports of device
Method Detail

getNumberOfTotalPorts

public final int getNumberOfTotalPorts()

getNumberOfFreePorts

public final int getNumberOfFreePorts()
Returns:
Returns the number of free and therefore available ports

getNextFreePort

public final int getNextFreePort()
Returns:
Returns the port number of the next available port or -1, if no more port is available

getConnectedWires

public final java.util.List getConnectedWires()
Returns:
Returns an iterator with all connected wires

isPortFree

public final boolean isPortFree(int portNr)
Parameters:
portNr - The identifying port number
Returns:
Returns, wheter a port is free (no cable is plugged) or not free (cable is plugged)

getWireInPort

public final Wire getWireInPort(int portNr)
Parameters:
portNr - The identifying port number
Returns:
Returns a reference to the wire which is plugged in a specified port, or null, if no cable is currently plugged in this port

getPortOfWire

public final int getPortOfWire(Wire wire)
Parameters:
wire - The cable
Returns:
Returns the (first) port number, to which a cable is connected or -1, if cable is not connected at all

isWireConnected

public final boolean isWireConnected(Wire wireToTest)
Checks, if a specified wire is connected or not

Parameters:
wireToTest - Wire to test
Returns:
Returns, if wire is connected

getIncomingNetworkStackConfiguration

protected abstract IncomingNetworkStackConfiguration getIncomingNetworkStackConfiguration()
This method must be overriden in subclasses. The configuration for the incoming network stack must be returned.

Returns:
The incoming network stack configuration

getOutgoingNetworkStackConfiguration

protected abstract OutgoingNetworkStackConfiguration getOutgoingNetworkStackConfiguration()
This method must be overriden in subclasses. The configuration for the outgoing network stack must be returned.

Returns:
The outgoing network stack configuration

bePlugged

public final void bePlugged(Wire wire,
                            int portNr)
                     throws WiringException
Description copied from interface: WireConnector
This method should only be called by Wires, which inform this WireConnector that they are connected.

Specified by:
bePlugged in interface WireConnector
Parameters:
wire - Connected wire
Throws:
WiringException - May be thrown to veto against this wiring

beUnplugged

public final void beUnplugged(Wire wire,
                              int portNr)
                       throws WiringException
Description copied from interface: WireConnector
This method should only be called by Wires, which inform this WireConnector that they are disconnected

Specified by:
beUnplugged in interface WireConnector
Parameters:
wire - Disconnected wire
Throws:
WiringException - May be thrown on any error or veto

informAboutDataOnWire

public final void informAboutDataOnWire(Wire sender,
                                        RawData data)
Description copied from interface: WireConnector
This method is called whenever a data package is received by a subscribed wire.

Specified by:
informAboutDataOnWire in interface WireConnector
Parameters:
sender - If the sender is a Wire, sender contains the reference to the wire which received the packet.
data - The received data on the wire

toString

public java.lang.String toString()
Overrides:
toString in class HardwareComponent