net.clackrouter.component.base
Class ClackComponent

java.lang.Object
  extended by net.clackrouter.component.base.ClackComponent
All Implemented Interfaces:
Alarm
Direct Known Subclasses:
ARPDemux, ARPLookup, ARPRespond, Capture, Classifier, Counter, Delay, DNSHijacker, Ethereal, EtherEncap, EtherStrip, EtherSwitch, EvenOdd, ICMPDemux, ICMPEcho, ICMPPortUnreach, ICMPTTLExpired, Interface, IPEncap, IPHeaderCheck, IPRouteLookup, IPStrip, IPTTLDec, Level2Demux, Level3Demux, Loss, NAPT, OrderPackets, ProcessAck, ProcessSegment, PullToPush, Queue, ReceiveWindowCheck, Retransmitter, SendWindowCheck, SetChecksum, SIPRedirector, SockBuffer, SourceTracker1, TCB, TCP, TCPMonitor, TCPSeqMon, TCPSocket, Tee, Throttle, UDP, UDPSource, ValidateChecksum

public abstract class ClackComponent
extends java.lang.Object
implements Alarm

ClackComponent is the abstract base class for all component blocks that comprise router functionality.

Each ClackComponent has a collection of ClackPort objects, each of which represents either a packet input or output for the packet processing block. ClackPort objects handle the actual passing of packets between ClackComponents.

There are two main methods of transfering packets:

The first is "pushing" packets, where components receive packets via the acceptPacket(VNSPacket, int) method. Packets are pushed out ports using the ClackPort.pushOut(VNSPacket) method of ClackPort objects.

The second mechanism is "pulling" packets, in which a component uses the ClackPort.pullIn() to ask a connected component if it has a packet available for processing. ClackComponents respond to these queries using the handlePullRequest(int) method.

The ClackComponentListener class can be used to keep track of component events by registering as a listener to any class extending ClackComponent.


Nested Class Summary
protected  class ClackComponent.Waiter
           
 
Field Summary
protected  ComponentCell componentCell
          The JGraph component cell representing this ClackComponent
protected  boolean m_has_error
           
protected  javax.swing.JTextArea m_log
          Text log console visible from the components properties view Text is added by both the log() and error() methods
protected  java.lang.String m_name
          Component's name, unique within a single router
protected  int m_num_ports
          Number of ports used by this component
 int m_packetcount_in
          Total number of packets that have arrived at component input ports (modified by ClackPort object)
 int m_packetcount_out
          Total number of packets that have exited component output ports (modified by ClackPort object)
protected  ClackPort[] m_ports
          Contains all ports used by this components
protected  java.util.ArrayList mListeners
          List of components implementing the
protected  Router mRouter
          Router containing this component
protected  boolean pendingError
           
static int SIGNAL_ERROR_LEN_MSEC
           
static int UNIQUE_COUNT
          Unique counter
protected  ClackPaintable view
           
 
Constructor Summary
ClackComponent(Router r, java.lang.String name)
          Constructor, should be called by all sub-classes to set-up the component
 
Method Summary
 void acceptPacket(VNSPacket packet, int port_number)
          The starting point for packet-processing when packets are "pushed" to this component.
 ClackComponent createCopy()
          Clones the component using reflection to create a deep copy.
 void createInputPullPort(int port_num, java.lang.String descr, java.lang.Class type)
           
 void createInputPushPort(int port_num, java.lang.String descr, java.lang.Class type)
           
 void createOutputPullPort(int port_num, java.lang.String descr, java.lang.Class type)
           
 void createOutputPushPort(int port_num, java.lang.String descr, java.lang.Class type)
           
 void error(java.lang.String s)
          Writes an error message to the component console log and prints it to Standard Error
 void fireListeners(ClackComponentEvent e)
          for each reportable event, this calls the ClackComponentListener.componentEvent(ClackComponentEvent) method of each listener
 java.awt.Color getColor()
          The color this component should be rendered in, assuming a standard component rendering by the ComponentView.ComponentRenderer class.
 ComponentCell getComponentCell()
          Retrieve the ComponentCell object representing this component in the Router Graph
 ClackView getHierarchicalView()
          Supplies hierarchical view that implements ClackView if isHierarchical() is true
 javax.swing.JTextArea getLog()
          Get a reference to the console log of this component
 java.lang.String getName()
          Get component name, which is unique within a single router
 int getNumPorts()
          Get the total number of ports (input + output) for this component
 int getPacketCountIn()
          The total number of packets to have entered this component
 int getPacketCountOut()
          The total number of packets to leave this component
 boolean getPendingError()
           
 ClackPort getPort(int port_num)
          Get a reference to a specific port, by number
 javax.swing.JPanel getPropertiesView()
          Method for getting the properties view associated with this component Property views are used to display more detailed information about internal component state.
 Router getRouter()
          Get the router that contains this component
 java.util.Properties getSerializableProperties(boolean isTransient)
          Used to get all values the component would like to serialize to file.
 long getTime()
           
 java.lang.String getTypeName()
          The simple name that identifies this type of component.
static int getUniqueCount()
          Get an integer identifier unique for this type of component
 VertexView getView(JGraph graph, CellMapper mapper)
          Returns the View object used to render this component in the Router Graph.
 VNSPacket handlePullRequest(int port_number)
          Called when a neighboring component wishes to "pull" a packet from this component.
 boolean hasError()
          Tells GUI is this component recently experienced an error
 void initializeProperties(java.util.Properties props)
          Method used to initialize a component based on serialized properties values saved to a file.
 boolean isHierarchical()
          Tells whether this component is hierarchical, that is, capable of being zoomed into within a Clack Router.
 boolean isModifying()
          Reports whether this component modifies packets passed through it This value is used by the static checking algorithm used to make sure port connections are valid.
 void log(java.lang.String s)
          Writes a message to the log console
 void notifyAlarm()
          call-back method implemented by the code setting the alarm.
 void poll()
          Callback method to implement component functionality that is not initiated by a packet push.
 void registerListener(ClackComponentListener listener)
          Classes that want to be updated on component events implement the ClackComponentListener interface and send a reference of themselves to this method.
protected  void sendOutPort(VNSPacket p, int port_num)
          Conveniance method to push a packet out a particular port
 void setAlarm(long msecs_from_now)
          Sets a timer
 void setComponentCell(ComponentCell cell)
          Used to set the ComponentCell object representing this component in the Router Graph
 void setName(java.lang.String name)
          set component's name
 void setPendingError(boolean e)
           
protected  void setupPorts(int num_ports)
          Allocates an array of ClackPort objects to be used by this component
 void setView(ClackPaintable v)
          Set the view associate with this ClackComponent
 void showErrorDialog(java.lang.String e)
           
protected  void signalError()
           
 void try_repaint()
           
 void unregisterListener(ClackComponentListener listener)
          Removes component from list of objects receiving notifications about this component
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIQUE_COUNT

public static int UNIQUE_COUNT
Unique counter


SIGNAL_ERROR_LEN_MSEC

public static final int SIGNAL_ERROR_LEN_MSEC
See Also:
Constant Field Values

m_ports

protected ClackPort[] m_ports
Contains all ports used by this components


m_num_ports

protected int m_num_ports
Number of ports used by this component


m_name

protected java.lang.String m_name
Component's name, unique within a single router


view

protected ClackPaintable view

m_packetcount_in

public int m_packetcount_in
Total number of packets that have arrived at component input ports (modified by ClackPort object)


m_packetcount_out

public int m_packetcount_out
Total number of packets that have exited component output ports (modified by ClackPort object)


m_log

protected javax.swing.JTextArea m_log
Text log console visible from the components properties view Text is added by both the log() and error() methods


mRouter

protected Router mRouter
Router containing this component


componentCell

protected ComponentCell componentCell
The JGraph component cell representing this ClackComponent


mListeners

protected java.util.ArrayList mListeners
List of components implementing the

See Also:
method

m_has_error

protected boolean m_has_error

pendingError

protected boolean pendingError
Constructor Detail

ClackComponent

public ClackComponent(Router r,
                      java.lang.String name)
Constructor, should be called by all sub-classes to set-up the component

Parameters:
r - the router hosting this component
name - of the component, unique within the router
Method Detail

setupPorts

protected void setupPorts(int num_ports)
Allocates an array of ClackPort objects to be used by this component

Parameters:
num_ports - the number of ports to create

handlePullRequest

public VNSPacket handlePullRequest(int port_number)

Called when a neighboring component wishes to "pull" a packet from this component.

This function should only be valid for port numbers that are defined as pull ports. This is enforced by the ClackPort class. By default, we return nothing.

Parameters:
port_number - The port that a packet is being requested on
Returns:
A packet if available for pull, or null

acceptPacket

public void acceptPacket(VNSPacket packet,
                         int port_number)

The starting point for packet-processing when packets are "pushed" to this component.

The default implementation warns that the packet is being ignored.

Parameters:
packet - The pushed packet
port_number - The number of the port that this packet is arriving on

poll

public void poll()

Callback method to implement component functionality that is not initiated by a packet push.

The pull method is often used to implement a "pull" component, or to serve as a packet source. The Router calls poll() once per processing loop if the component has been registered using the Router.registerForPoll(ClackComponent) method.


setAlarm

public void setAlarm(long msecs_from_now)
Description copied from interface: Alarm
Sets a timer

Specified by:
setAlarm in interface Alarm
Parameters:
msecs_from_now - milliseconds later in "clack time" that the alarm will fire.

notifyAlarm

public void notifyAlarm()
Description copied from interface: Alarm
call-back method implemented by the code setting the alarm. notifies that the alarm has fired.

Specified by:
notifyAlarm in interface Alarm

getSerializableProperties

public java.util.Properties getSerializableProperties(boolean isTransient)

Used to get all values the component would like to serialize to file.

These values are stored as String -> String pairs in a Properties object. These properties will be passed to initializeProperties(Properties) when the Component is recreated.

Serialization can be transient or not, which determines whether all or just some of the internal component state is saved. Transient serialization means that some properties will be saved which may make this serialized file invalid for use on different network or router set-ups. For example, saving info specific to the IP addresses of a certain topology would only happen if transient serialization was used. However, it can be desireable to save these properties when setting up exact demonstrations.

By default we have no properties to serialize, so we return an empty object

Parameters:
isTransient - flag indicating if serialization is transient
Returns:
all property key-value pairs to serialize

initializeProperties

public void initializeProperties(java.util.Properties props)

Method used to initialize a component based on serialized properties values saved to a file.

By default, no action is performed

Parameters:
props - all property values serialized for this component

getPropertiesView

public javax.swing.JPanel getPropertiesView()
Method for getting the properties view associated with this component Property views are used to display more detailed information about internal component state. This method creates a default property view, and can be overriden to provide custom properties views

Returns:
this component's property view

registerListener

public void registerListener(ClackComponentListener listener)
Classes that want to be updated on component events implement the ClackComponentListener interface and send a reference of themselves to this method.

Parameters:
listener - listener to be added

unregisterListener

public void unregisterListener(ClackComponentListener listener)
Removes component from list of objects receiving notifications about this component

Parameters:
listener - listener to be removed

fireListeners

public void fireListeners(ClackComponentEvent e)
for each reportable event, this calls the ClackComponentListener.componentEvent(ClackComponentEvent) method of each listener

Parameters:
e - describing what kind of an event occured, which is passed to each listener

getNumPorts

public int getNumPorts()
Get the total number of ports (input + output) for this component


getPort

public ClackPort getPort(int port_num)
Get a reference to a specific port, by number

Parameters:
port_num -

isHierarchical

public boolean isHierarchical()
Tells whether this component is hierarchical, that is, capable of being zoomed into within a Clack Router.

Returns:
default value is false

getHierarchicalView

public ClackView getHierarchicalView()
Supplies hierarchical view that implements ClackView if isHierarchical() is true


setComponentCell

public void setComponentCell(ComponentCell cell)
Used to set the ComponentCell object representing this component in the Router Graph

Parameters:
cell - - the corresponding ComponentCell

getComponentCell

public ComponentCell getComponentCell()
Retrieve the ComponentCell object representing this component in the Router Graph


getView

public VertexView getView(JGraph graph,
                          CellMapper mapper)
Returns the View object used to render this component in the Router Graph. By default, we use a ComponentView, which renders the component as a simple colored box with the component type written inside of it. More advanced component sub-classes that wish to be displayed differently should override this method to return a custom VertexView sub-class

Parameters:
graph - the Router Graph
mapper - the CellMapper associated with this Router Graph
Returns:
the VertexView for rendering this component

createCopy

public ClackComponent createCopy()
Clones the component using reflection to create a deep copy. Transfers all non-transient serializable properties to the new component

Returns:
a copy of this component

error

public void error(java.lang.String s)
Writes an error message to the component console log and prints it to Standard Error

Parameters:
s - the error message to print

log

public void log(java.lang.String s)
Writes a message to the log console

Parameters:
s - the log message

isModifying

public boolean isModifying()
Reports whether this component modifies packets passed through it This value is used by the static checking algorithm used to make sure port connections are valid. Sub-classes that do not modify packets should override this method

Returns:
by default, we assume the component modifies packets

setName

public void setName(java.lang.String name)
set component's name


getUniqueCount

public static int getUniqueCount()
Get an integer identifier unique for this type of component


getName

public java.lang.String getName()
Get component name, which is unique within a single router


getRouter

public Router getRouter()
Get the router that contains this component

Specified by:
getRouter in interface Alarm
Returns:

getPacketCountIn

public int getPacketCountIn()
The total number of packets to have entered this component


getPacketCountOut

public int getPacketCountOut()
The total number of packets to leave this component


getLog

public javax.swing.JTextArea getLog()
Get a reference to the console log of this component


getColor

public java.awt.Color getColor()

The color this component should be rendered in, assuming a standard component rendering by the ComponentView.ComponentRenderer class.

Other renderers may ignore this value.

Returns:
the rendering color

getTypeName

public java.lang.String getTypeName()
The simple name that identifies this type of component.

default implementation is simply the class name with no package information

Returns:
the component's type name

hasError

public boolean hasError()
Tells GUI is this component recently experienced an error


signalError

protected void signalError()

try_repaint

public void try_repaint()

setView

public void setView(ClackPaintable v)
Set the view associate with this ClackComponent


createInputPushPort

public void createInputPushPort(int port_num,
                                java.lang.String descr,
                                java.lang.Class type)

createInputPullPort

public void createInputPullPort(int port_num,
                                java.lang.String descr,
                                java.lang.Class type)

createOutputPushPort

public void createOutputPushPort(int port_num,
                                 java.lang.String descr,
                                 java.lang.Class type)

createOutputPullPort

public void createOutputPullPort(int port_num,
                                 java.lang.String descr,
                                 java.lang.Class type)

showErrorDialog

public void showErrorDialog(java.lang.String e)

getTime

public long getTime()

getPendingError

public boolean getPendingError()

setPendingError

public void setPendingError(boolean e)

sendOutPort

protected void sendOutPort(VNSPacket p,
                           int port_num)
Conveniance method to push a packet out a particular port