verinec.netsim.util.net.sockets
Class SocketImpl

java.lang.Object
  extended by java.net.SocketImpl
      extended by verinec.netsim.util.net.sockets.SocketImpl
All Implemented Interfaces:
Cloneable, SocketOptions

public class SocketImpl
extends SocketImpl
implements Cloneable

A socket implementation that redirects all traffic into the simulator instead of sending it to the systems network stack. Therefore it needs to know to which Layer (@link verinec.netsim.entities.layers.TransportLayer) the traffic is redirected. SocketImpl is not used directly. It us used by SocketImplFactory (@link java.net.SocketImplFactory) or (@link verinec.netsim.sockets.SimSocketImplFactory) which are used in the constructor of Socket (@link java.net.Socket).

Version:
$Revision: 795 $
Author:
Dominik Jungo

Field Summary
 SocketInputStream is
          the socket's input stream returned by #getInputStream()
private  Logger jlogger
           
private  TransportLayer layer
           
private  ILogger logger
           
 SocketOutputStream os
          the socket's output stream returned by #getOutputStream()
private  int seq
          running sequence number of send messages
private  int seq_ack
          last acknowledged sequence number, last received ack
private  FSMSocketImpl state
           
private  NetSimThread thread
           
 
Fields inherited from class java.net.SocketImpl
address, fd, localport, port
 
Fields inherited from interface java.net.SocketOptions
IP_MULTICAST_IF, IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS, SO_BINDADDR, SO_BROADCAST, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SO_TIMEOUT, TCP_NODELAY
 
Constructor Summary
SocketImpl()
          Constructs a new SocketImplementation the TransportLayer to which all the data is redirected
 
Method Summary
protected  void accept(SocketImpl s)
           
 void activate()
           
 void activate(SimTime st)
           
protected  int available()
           
protected  void bind(InetAddress host, int bport)
           
protected  void close()
           
protected  void connect(InetAddress address, int port)
           
protected  void connect(SocketAddress address, int timeout)
           
protected  void connect(String host, int port)
           
protected  void create(boolean stream)
           
 TCPPacket createTCPPacket()
          Creates a TCP Packet that is adressed with the adress of this port.
 InetAddress getAddress()
          gets the remote address of this Socket
 int getBuf()
          gets the address of the last part of the buffer that can be acknowledged
protected  InputStream getInputStream()
           
 int getLocalPort()
           
 ILogger getLogger()
          gets this Socket's Logger
 Object getOption(int optID)
           
protected  OutputStream getOutputStream()
           
 int getPort()
           
 int getSeq_ack()
          gets the last acknowledged sequence number
 int getSeq()
          gets the sequence number of this socket
 FSMSocketImpl getState()
          gets the state of this Socket
 NetSimThread getThread()
          gets the Thread using this socket
 TransportLayer getTransportLayer()
          gets the TransportLayer
private  TransportLayer guessLayer()
           
 void hold(SimTime time)
           
 void incrSeq()
          increases the sequence number of this socket by one
 boolean isConnectionReset()
           
protected  void listen(int backlog)
           
 void passivate()
           
 void proccessUp(Packet packet)
          Processes a packet
private  void send(TCPPacket packet, ILogger logger)
          sends a TCP Packet
 void send(Vector payload, ILogger logger)
          sends a packet down to the next layer
 void sendData(TCPPacket packet, ILogger logger)
          sends a TCP Packet
protected  void sendUrgentData(int data)
           
 void setAddress(InetAddress address)
          sets the Address of this Socket
 void setBacklog(int backlog)
          Sets the number of accpeting connections
 void setLayer(TransportLayer layer)
          sets the layer for this instance
 void setLocalPort(int localport)
          sets the Local Port of this Socket
 void setLogger(ILogger logger)
          sets the Logger in the InputStream Associated with this Socket
 void setOption(int optID, Object value)
           
 void setPort(int port)
          sets the Remote Port of this Socket
 void setSeq_ack(int seq_ack)
          sets the last acknowledged sequence number
 void setSeq(int seq)
          sets the sequence number of this socket
 void setState(FSMSocketImpl state)
          Sets the state of this socket
 void unbind()
          Un-binds this Socket and frees the used port
 
Methods inherited from class java.net.SocketImpl
getFileDescriptor, getInetAddress, setPerformancePreferences, shutdownInput, shutdownOutput, supportsUrgentData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

layer

private TransportLayer layer

thread

private NetSimThread thread

is

public SocketInputStream is
the socket's input stream returned by #getInputStream()


os

public SocketOutputStream os
the socket's output stream returned by #getOutputStream()


logger

private ILogger logger

jlogger

private Logger jlogger

state

private FSMSocketImpl state

seq

private int seq
running sequence number of send messages


seq_ack

private int seq_ack
last acknowledged sequence number, last received ack

Constructor Detail

SocketImpl

public SocketImpl()
           throws NetSimException
Constructs a new SocketImplementation the TransportLayer to which all the data is redirected

Throws:
NetSimException - if no layer is associated with this SocketImpl
Method Detail

guessLayer

private TransportLayer guessLayer()

available

protected int available()
                 throws IOException
Specified by:
available in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.available()

close

protected void close()
              throws IOException
Specified by:
close in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.close()

listen

protected void listen(int backlog)
               throws IOException
Specified by:
listen in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.listen(int)

sendUrgentData

protected void sendUrgentData(int data)
                       throws IOException
Specified by:
sendUrgentData in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.sendUrgentData(int)

create

protected void create(boolean stream)
               throws IOException
Specified by:
create in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.create(boolean)

getInputStream

protected InputStream getInputStream()
                              throws IOException
Specified by:
getInputStream in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.getInputStream()

getOutputStream

protected OutputStream getOutputStream()
                                throws IOException
Specified by:
getOutputStream in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.getOutputStream()

connect

protected void connect(String host,
                       int port)
                throws IOException
Specified by:
connect in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.connect(java.lang.String, int)

bind

protected void bind(InetAddress host,
                    int bport)
             throws IOException
Specified by:
bind in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.bind(java.net.InetAddress, int)

getLocalPort

public int getLocalPort()
Overrides:
getLocalPort in class SocketImpl
See Also:
SocketImpl.getLocalPort()

getPort

public int getPort()
Overrides:
getPort in class SocketImpl
See Also:
SocketImpl.getPort()

getAddress

public InetAddress getAddress()
gets the remote address of this Socket

Returns:
the remote address of this Socket

connect

protected void connect(InetAddress address,
                       int port)
                throws IOException
Specified by:
connect in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.connect(java.net.InetAddress, int)

connect

protected void connect(SocketAddress address,
                       int timeout)
                throws IOException
Specified by:
connect in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.connect(java.net.SocketAddress, int)

accept

protected void accept(SocketImpl s)
               throws IOException
Specified by:
accept in class SocketImpl
Throws:
IOException
See Also:
SocketImpl.accept(java.net.SocketImpl)

setPort

public void setPort(int port)
sets the Remote Port of this Socket

Parameters:
port - the Remote Port of this Socket

setLocalPort

public void setLocalPort(int localport)
sets the Local Port of this Socket

Parameters:
localport - the local port of this Socket

getOption

public Object getOption(int optID)
                 throws SocketException
Specified by:
getOption in interface SocketOptions
Throws:
SocketException
See Also:
SocketOptions.getOption(int)

setOption

public void setOption(int optID,
                      Object value)
               throws SocketException
Specified by:
setOption in interface SocketOptions
Throws:
SocketException
See Also:
SocketOptions.setOption(int, java.lang.Object)

isConnectionReset

public boolean isConnectionReset()
Returns:
true is the connection is reset, false otherwise

send

public void send(Vector payload,
                 ILogger logger)
sends a packet down to the next layer

Parameters:
payload - payload that is used as the tcp packets payload
logger - a logger

sendData

public void sendData(TCPPacket packet,
                     ILogger logger)
sends a TCP Packet

Parameters:
packet - a TCPPacket to be send
logger - the XML Logger that processes the logged sim events

send

private void send(TCPPacket packet,
                  ILogger logger)
sends a TCP Packet

Parameters:
packet - a TCPPacket to be send
logger - the XML Logger that processes the logged sim events

setLayer

public void setLayer(TransportLayer layer)
sets the layer for this instance

Parameters:
layer - a TransportLayer

setLogger

public void setLogger(ILogger logger)
sets the Logger in the InputStream Associated with this Socket

Parameters:
logger - a Logger

getTransportLayer

public TransportLayer getTransportLayer()
gets the TransportLayer

Returns:
the TransportLayer

setState

public void setState(FSMSocketImpl state)
Sets the state of this socket

Parameters:
state - a SocketImpl (state)

setBacklog

public void setBacklog(int backlog)
Sets the number of accpeting connections

Parameters:
backlog - the number of accpeting connections

createTCPPacket

public TCPPacket createTCPPacket()
                          throws NetSimException
Creates a TCP Packet that is adressed with the adress of this port.

Returns:
en empty packet but with correctly filled out socket address for this port and it's remote counterpart.
Throws:
NetSimException - if the Socket doesn't know where to send the packet to. This means to connection (or state to a connection) was etablished.

proccessUp

public void proccessUp(Packet packet)
Processes a packet

Parameters:
packet - a packet to be processed
See Also:
FSMSocketImpl.proccessUp(verinec.netsim.entities.packets.Packet)

setAddress

public void setAddress(InetAddress address)
sets the Address of this Socket

Parameters:
address - the Address of this Socket

passivate

public void passivate()
See Also:
NetSimThread.passivate()

hold

public void hold(SimTime time)
Parameters:
time - a Simulation Time interval for which the thread holds
See Also:
NetSimThread.hold(desmoj.core.simulator.SimTime)

activate

public void activate()
See Also:
NetSimThread.activate()

activate

public void activate(SimTime st)
Parameters:
st - simulation interval time until the threads activation
See Also:
NetSimThread.activate(desmoj.core.simulator.SimTime)

getBuf

public int getBuf()
gets the address of the last part of the buffer that can be acknowledged

Returns:
the address of the last part of the buffer that can be acknowledged

getSeq

public int getSeq()
gets the sequence number of this socket

Returns:
the sequence number of this socket

setSeq

public void setSeq(int seq)
sets the sequence number of this socket

Parameters:
seq - the new sequence number

incrSeq

public void incrSeq()
increases the sequence number of this socket by one


getSeq_ack

public int getSeq_ack()
gets the last acknowledged sequence number

Returns:
the last acknowledged sequence number

setSeq_ack

public void setSeq_ack(int seq_ack)
sets the last acknowledged sequence number

Parameters:
seq_ack - a sequence number

getState

public FSMSocketImpl getState()
gets the state of this Socket

Returns:
the state of this Socket

getThread

public NetSimThread getThread()
gets the Thread using this socket

Returns:
the Thread using this socket

unbind

public void unbind()
Un-binds this Socket and frees the used port


getLogger

public ILogger getLogger()
gets this Socket's Logger

Returns:
this Socket's Logger

Copyright © 2005 Verinec, DIUF