simnet
Class UDP

java.lang.Object
  extended bysimnet.Transport
      extended bysimnet.UDP
All Implemented Interfaces:
Pluggable, PlugoutListener

public class UDP
extends Transport
implements Pluggable

An implementation of the UDP protocol.


Field Summary
 java.util.HashSet availablePorts
          Added for NAT purposes :-(
protected  int next_port
           
(package private)  java.util.Hashtable ports
           
(package private)  java.util.HashSet sockets
           
 
Fields inherited from class simnet.Transport
node, NODE_ID, sim
 
Constructor Summary
UDP()
           
 
Method Summary
 DatagramSocket createDatagramSocket(java.lang.Object consumer)
          Returns a new DatagramSocket using this transport.
 void dump_udp_state()
          Print out all UDP state information.
(package private)  int getNextFreePort()
          Return the next available port to bind to, or -1 if there is none.
 int getProtocol()
          Returns the protocol (id) of this Transport
 void in(int src, Packet packet)
          In UDP, rawIn does all the work.
 void initialize(Node parent_node)
          Initializes a new UDP object by setting its ID.
 boolean prePlugout(java.lang.Object replacement)
          To replace UDP, update all sockets; to remove UDP, close all sockets.
 void rawIn(IP_Packet ipp)
          Processes incoming packets from the IP stack and forwards the encapsulated data to the appropriate DatagramSocket.
protected  void registerSocket(DatagramSocket sock)
          When a DatagramSocket gets created, UDP needs to know about it.
(package private)  void unregisterSocket(DatagramSocket sock)
          When a DatagramSocket gets closed, UDP needs to know about it.
 
Methods inherited from class simnet.Transport
finalize, plugoutNotification
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sockets

java.util.HashSet sockets

ports

java.util.Hashtable ports

next_port

protected int next_port

availablePorts

public java.util.HashSet availablePorts
Added for NAT purposes :-(

Constructor Detail

UDP

public UDP()
Method Detail

initialize

public void initialize(Node parent_node)
Initializes a new UDP object by setting its ID.

Overrides:
initialize in class Transport
Parameters:
parent_node - the Node that owns this Transport

getProtocol

public int getProtocol()
Returns the protocol (id) of this Transport

Specified by:
getProtocol in class Transport

createDatagramSocket

public DatagramSocket createDatagramSocket(java.lang.Object consumer)
Returns a new DatagramSocket using this transport.


rawIn

public void rawIn(IP_Packet ipp)
Processes incoming packets from the IP stack and forwards the encapsulated data to the appropriate DatagramSocket.

Overrides:
rawIn in class Transport

in

public void in(int src,
               Packet packet)
In UDP, rawIn does all the work.

Specified by:
in in class Transport
Parameters:
src - the source of the incoing packet
packet - incoming packet

getNextFreePort

int getNextFreePort()
Return the next available port to bind to, or -1 if there is none.


registerSocket

protected void registerSocket(DatagramSocket sock)
When a DatagramSocket gets created, UDP needs to know about it.


unregisterSocket

void unregisterSocket(DatagramSocket sock)
When a DatagramSocket gets closed, UDP needs to know about it.


dump_udp_state

public void dump_udp_state()
Print out all UDP state information.


prePlugout

public boolean prePlugout(java.lang.Object replacement)
To replace UDP, update all sockets; to remove UDP, close all sockets.

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