simnet
Class Node

java.lang.Object
  extended byjava.lang.Thread
      extended bysimnet.Node
All Implemented Interfaces:
Pluggable, java.lang.Runnable, SimnetWindowListener
Direct Known Subclasses:
Host, Router

public abstract class Node
extends java.lang.Thread
implements SimnetWindowListener, Pluggable

The abstract base class for all Nodes.


Field Summary
(package private)  java.util.Hashtable applications
          A Hashtable that holds all Application objects keyed by their unique IDs
(package private)  boolean default_plugins_loaded
          Whether or not the default plugins have been loaded.
(package private)  SimnetWindow frame
          The window frame
(package private)  boolean frozen
          Global state variable that is set when the Node is in frozen state.
 int id
          The unique ID of this Node (IP address)
protected  java.util.Hashtable in_filters
          A Hashtable that holds all incoming IPFilters keyed by their unique IDs
protected  java.util.Hashtable in_links
          A Hashtable that holds all incoming Links keyed by their unique IDs
(package private)  int ipid
          Global counter that keeps track of the value previously used for an IP packet' s IP ID field.
 boolean isNatted
           
(package private)  boolean keep_going
          When being plugged out, this will be set to false, so that this node's thread can stop running.
 java.lang.String name
          The name of this Node
(package private)  NATRouter natGW
           
(package private)  NodeStatistics ns
          Tracking packet statistics
protected  java.util.Hashtable out_filters
          A Hashtable that holds all outgoing IPFilters keyed by their unique IDs
protected  java.util.Hashtable out_links
          A Hashtable that holds all outgoing Links keyed by their unique IDs
(package private)  boolean pause
          Global state variable that is set when the Node is in pause state.
(package private)  LinkProcessor proc
          This Node' s LinkProcessor.
protected  java.util.Random random
          A random number generator
 Resolver resolver
          The resolver for this node.
(package private)  RoutingTable routing_table
          The routing table for this node.
(package private)  boolean running
          Global state variable that is set when the Node is in running state.
protected  Simulator sim
          The Simulator (Simulator.getSim())
(package private)  boolean sleeping
          Global state variable that is set when the Node is in sleeping state.
(package private)  java.util.Hashtable transports
          A Hashtable that holds all Transport objects keyed by their unique IDs
protected  UserInterface ui
          The User Interface (UserInterface.getUI())
(package private)  boolean win
          Keeps track of whether an output window has been opened
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Node()
           
 
Method Summary
 void addBPF(BPF bpf, int direction, int link_id)
          Adds the specified BPF rule to the IPFilter associated with the specified Link.
 void addLink(int direction, Link link)
          Adds the specified Link to this Node's link table.
 void addRule(Rule rule, int direction, int link_id)
          Adds the specified firewall rule to the IPFilter associated with the specified Link.
 void clear()
          Clears all of this Node' s stats
 void closeWindow()
          Close this node's window (if it is open).
 boolean command(java.lang.Object target, java.lang.String command, java.lang.Object[] args)
          Invoke the method command on the object target with the given arguments.
 boolean command(java.lang.String command, java.lang.Object[] args)
          Attempts to invoke the specified command with the specified arguments by searching through all this Node's Applications, Transports, Link Processor, Routing Table, Resolver, and the Node itself.
 void deleteRule(int rule_id, int direction, int link_id)
          Removes the specified firewall rule from the IPFilter associated with the specified Link.
 boolean empty(java.util.Hashtable link_table)
          Determines whether the specified Links are empty or not.
protected  void finalize()
          For debugging.
protected abstract  void forward(IP_Packet ip_packet)
          Forwards incoming IP packets to the appropriate transport protocol (after stripping the IP header).
 Application getApplication(int pid)
          Returns the Application with the specified (unique) Process ID.
 int getHostByName(java.lang.String host)
          Looks up the ip for this host using the resolver.
 Link getLink(int to_id)
          Returns the Link whose To node is specified by the given Node ID.
abstract  int getNodeClass()
          Returns the class of this Node (either Router or Host)
 int getPluginCount()
          Returns the number of plugins that are loaded on this node.
 java.lang.String getTitleString()
          Returns the title that currently describes the state of the node or application that this window is for.
 Transport getTransport(int tid)
          Returns the Transport with the specified unique ID.
 Transport getTransport(java.lang.String trans)
          Returns the Transport with the specified name.
 void initialize(int node_id, java.lang.String node_name)
          Initializes a new Node by setting its ID, name and a pointer to the Simulator, all to the specified values.
 void integrate()
          Integrate this node by enabling all of its links.
 void isolate()
          Isolate this node by disabling all of its links.
 void kill()
          Pauses this Node's thread
 java.lang.String lookup(int nid)
          Determines the name of the Node with the specified ID.
 int lookup(java.lang.String name)
          Determines the ID of the Node with the specified name.
 boolean out(int dest, Packet packet)
          Adds IP and Frame headers to outgoing Transport packets before enqueing them on the appropriate Link.
 boolean prePlugout(java.lang.Object replacement)
          To be replaced, stop our thread; to be removed, remove links and then stop the thread.
 void printout(int level, int src, java.lang.String msg)
          To make the old code compile (temporary)
 void printout(java.lang.String category, int level, int src, java.lang.String message)
          Prints the specified message if the current verbosity level is equal to or higher than the specified level and the specified category should be shown.
 void processWindowCommand(java.lang.String text)
          The command text has been input in the window.
 void removeBPF(BPF bpf, int direction, int link_id)
          Removes the specified BPF rule from the IPFilter associated with the specified Link.
 boolean removeLink(int direction, int other)
          Removes the specified Link in this Node's link table.
 void run()
          Wait for packets, and forward them.
 void setupNAT(NATRouter natGW)
          Set a flag so we know that we are natted, and a pointer to our gateway.
 void start()
          Starts this Node' s thread
 void stateful_kill()
          Starts this Node' s thread if it is not running.
 void stateful_start()
          Pauses this Node' s thread if it is running.
private  java.lang.String tabularize(java.lang.String string)
          Inserts tabs in a string (is this used?).
 java.lang.String toString()
          Returns a string with information about this Node.
 java.lang.String toString(int type)
          Returns a string with information about this Node The type determines the kind of information returned: 0 - all 1 - loaded plugins 2 - link information 3 - firewall rules
 void window()
          Starts an Individual Interface Window (IIW) associated with this node.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

id

public int id
The unique ID of this Node (IP address)


name

public java.lang.String name
The name of this Node


sim

protected Simulator sim
The Simulator (Simulator.getSim())


ui

protected UserInterface ui
The User Interface (UserInterface.getUI())


in_filters

protected java.util.Hashtable in_filters
A Hashtable that holds all incoming IPFilters keyed by their unique IDs


out_filters

protected java.util.Hashtable out_filters
A Hashtable that holds all outgoing IPFilters keyed by their unique IDs


in_links

protected java.util.Hashtable in_links
A Hashtable that holds all incoming Links keyed by their unique IDs


out_links

protected java.util.Hashtable out_links
A Hashtable that holds all outgoing Links keyed by their unique IDs


proc

LinkProcessor proc
This Node' s LinkProcessor. No more default.


routing_table

RoutingTable routing_table
The routing table for this node.


resolver

public Resolver resolver
The resolver for this node.


transports

java.util.Hashtable transports
A Hashtable that holds all Transport objects keyed by their unique IDs


applications

java.util.Hashtable applications
A Hashtable that holds all Application objects keyed by their unique IDs


random

protected java.util.Random random
A random number generator


ns

NodeStatistics ns
Tracking packet statistics


running

boolean running
Global state variable that is set when the Node is in running state.


pause

boolean pause
Global state variable that is set when the Node is in pause state.


sleeping

boolean sleeping
Global state variable that is set when the Node is in sleeping state.


frozen

boolean frozen
Global state variable that is set when the Node is in frozen state.


keep_going

transient boolean keep_going
When being plugged out, this will be set to false, so that this node's thread can stop running.


ipid

int ipid
Global counter that keeps track of the value previously used for an IP packet' s IP ID field.


isNatted

public boolean isNatted

natGW

NATRouter natGW

default_plugins_loaded

boolean default_plugins_loaded
Whether or not the default plugins have been loaded. Note that they will only be loaded when a node is first plugged in, rather then each time a node is replaced.


frame

SimnetWindow frame
The window frame


win

boolean win
Keeps track of whether an output window has been opened

Constructor Detail

Node

public Node()
Method Detail

getNodeClass

public abstract int getNodeClass()
Returns the class of this Node (either Router or Host)


setupNAT

public void setupNAT(NATRouter natGW)
Set a flag so we know that we are natted, and a pointer to our gateway.

Parameters:
natGW - The node who assigned us an ip.

initialize

public void initialize(int node_id,
                       java.lang.String node_name)
Initializes a new Node by setting its ID, name and a pointer to the Simulator, all to the specified values.

Parameters:
node_id - this Node's unique ID
node_name - this Node' s name

start

public void start()
Starts this Node' s thread


run

public void run()
Wait for packets, and forward them.

Specified by:
run in interface java.lang.Runnable

forward

protected abstract void forward(IP_Packet ip_packet)
Forwards incoming IP packets to the appropriate transport protocol (after stripping the IP header). This is an abstract class that must be implemented by every Host and Router.

Parameters:
ip_packet - incoming IP packet to be forwarded

getHostByName

public int getHostByName(java.lang.String host)
Looks up the ip for this host using the resolver. If no resolver is loaded, a timeout error is returned (but without the wait).


kill

public void kill()
Pauses this Node's thread


out

public boolean out(int dest,
                   Packet packet)
Adds IP and Frame headers to outgoing Transport packets before enqueing them on the appropriate Link.

Parameters:
dest - destination Node
packet - outgoing Transport packet

addLink

public void addLink(int direction,
                    Link link)
Adds the specified Link to this Node's link table.

Parameters:
direction - specifies whether the Link should be added to the incoming link table (Simnet.IN) or the outgoing link table (Simnet.OUT)
link - the Link object to add

removeLink

public boolean removeLink(int direction,
                          int other)
Removes the specified Link in this Node's link table.

Parameters:
direction - specifies whether the Link should be added to the incoming link table (Simnet.IN) or the outgoing link table (Simnet.OUT)
other - the id (IP) of the other end of the link to remove
Returns:
If the link was sucessfully removed (if the link did not exist, true is returned)

isolate

public void isolate()
Isolate this node by disabling all of its links.


integrate

public void integrate()
Integrate this node by enabling all of its links.


addRule

public void addRule(Rule rule,
                    int direction,
                    int link_id)
Adds the specified firewall rule to the IPFilter associated with the specified Link.

Parameters:
rule - the firewall rule to add
direction - specifies whether the link is incoming (Simnet.IN) or outgoing (Simnet.OUT)
link_id - specifies the ID of the Link to which the rule should be added

deleteRule

public void deleteRule(int rule_id,
                       int direction,
                       int link_id)
Removes the specified firewall rule from the IPFilter associated with the specified Link.

Parameters:
rule_id - the ID of the firewall rule to remove
direction - specifies whether the link is incoming (Simnet.IN) or outgoing (Simnet.OUT)
link_id - specifies the ID of the Link from which the rule should be removed

addBPF

public void addBPF(BPF bpf,
                   int direction,
                   int link_id)
Adds the specified BPF rule to the IPFilter associated with the specified Link.

Parameters:
bpf - the bpf rule to add
direction - specifies whether the link is incoming (Simnet.IN) or outgoing (Simnet.OUT)
link_id - the ID of the Link. Here the ID of the Link really refers to the ID of the Node it connects to (on the other end). This is confusing since Links actually have their own IDs...

removeBPF

public void removeBPF(BPF bpf,
                      int direction,
                      int link_id)
Removes the specified BPF rule from the IPFilter associated with the specified Link.

Parameters:
bpf - the ID of the firewall rule to remove
direction - specifies whether the link is incoming (Simnet.IN) or outgoing (Simnet.OUT)
link_id - ...

stateful_kill

public void stateful_kill()
Starts this Node' s thread if it is not running. When used in conjunction with stateful_start() the two methods will return the Node to its original pause/running state.


stateful_start

public void stateful_start()
Pauses this Node' s thread if it is running. When used in conjunction with stateful_start() the two methods will return the Node to its original pause/running state.


command

public boolean command(java.lang.String command,
                       java.lang.Object[] args)
Attempts to invoke the specified command with the specified arguments by searching through all this Node's Applications, Transports, Link Processor, Routing Table, Resolver, and the Node itself. A command in the form "xxx.command" will only invoke the command on the application with process id = xxx.

Parameters:
command - the command to invoke
args - the command' s arguments
Returns:
TRUE if the command was found and invoked; false otherwise

command

public boolean command(java.lang.Object target,
                       java.lang.String command,
                       java.lang.Object[] args)
Invoke the method command on the object target with the given arguments.

Returns:
true if the invocation was sucessful, false otherwise

getTransport

public Transport getTransport(int tid)
Returns the Transport with the specified unique ID.

Parameters:
tid - the Transport' s ID
Returns:
the Transport with the specified ID; null if it does not exist

getTransport

public Transport getTransport(java.lang.String trans)
Returns the Transport with the specified name.

Parameters:
trans - the Transport' s name
Returns:
the Transport with the specified name; null if it does not exist

getApplication

public Application getApplication(int pid)
Returns the Application with the specified (unique) Process ID.

Parameters:
pid - the Application's Process ID
Returns:
the Application with the specified PID; null if it does not exist

getLink

public Link getLink(int to_id)
Returns the Link whose To node is specified by the given Node ID.

Parameters:
to_id - the ID of the Link' s To Node
Returns:
the Link whose To node has the specified ID

lookup

public java.lang.String lookup(int nid)
Determines the name of the Node with the specified ID.

Parameters:
nid - the Node' s ID
Returns:
the name of the specified Node; null if it does not exist

lookup

public int lookup(java.lang.String name)
Determines the ID of the Node with the specified name.

Parameters:
name - the Node' s name
Returns:
the ID of the specified node; -1 if it does not exist.

clear

public void clear()
Clears all of this Node' s stats


empty

public boolean empty(java.util.Hashtable link_table)
Determines whether the specified Links are empty or not.

Parameters:
link_table - a link table
Returns:
TRUE if all Links in the specified table are empty; FALSE otherwise

window

public void window()
Starts an Individual Interface Window (IIW) associated with this node.


getTitleString

public java.lang.String getTitleString()
Returns the title that currently describes the state of the node or application that this window is for.

Specified by:
getTitleString in interface SimnetWindowListener

closeWindow

public void closeWindow()
Close this node's window (if it is open).

Specified by:
closeWindow in interface SimnetWindowListener

processWindowCommand

public void processWindowCommand(java.lang.String text)
The command text has been input in the window.

Specified by:
processWindowCommand in interface SimnetWindowListener

printout

public void printout(java.lang.String category,
                     int level,
                     int src,
                     java.lang.String message)
Prints the specified message if the current verbosity level is equal to or higher than the specified level and the specified category should be shown. If an IIW has been opened the message is output to the window, if not it is output to the UI.

Parameters:
category - the category of the message
level - the verbosity level of the message
src - the ID of the source Node of the message
message - the error message

printout

public void printout(int level,
                     int src,
                     java.lang.String msg)
To make the old code compile (temporary)


toString

public java.lang.String toString()
Returns a string with information about this Node. Same as toString(0);

Returns:
the complete string representation for this node

toString

public java.lang.String toString(int type)
Returns a string with information about this Node The type determines the kind of information returned: 0 - all 1 - loaded plugins 2 - link information 3 - firewall rules

Parameters:
type - determines the kind of information to return
Returns:
specific information about this node

tabularize

private java.lang.String tabularize(java.lang.String string)
Inserts tabs in a string (is this used?).

Parameters:
string - string to format
Returns:
a new string with tabs

getPluginCount

public int getPluginCount()
Returns the number of plugins that are loaded on this node.


prePlugout

public boolean prePlugout(java.lang.Object replacement)
To be replaced, stop our thread; to be removed, remove links and then stop the thread.

Specified by:
prePlugout in interface Pluggable
Returns:
if this object can now be removed (was the operation sucessful)

finalize

protected void finalize()
For debugging.