Class RDTProtocol

java.lang.Object
  extended by RDTProtocol
Direct Known Subclasses:
AlternatingBitProtocol

public abstract class RDTProtocol
extends java.lang.Object

An RDTProtocol implements a reliable data transfer protocol on behalf of a TCP connection thread in the Transport layer. It operates within a context provided by a TCP entity object, which provides a sandbox environment that hides synchronization with the application layer above and the network layer below. Each RDTProtocol is associated with a specific socket on a specific host.

When created, a RDTProtocol is given a name. After setup, it has a partner, which is the RDTProtocol at the other end of the socket connection. In reality, of course, setup would only give it the host internet ID and port number of the partner.

Implementing Subclasses

To implement a reliable data transfer protocol, write a class that extends the RDTProtocol class. This class should provide three kinds of functionality:

Initialization is provided by declaring variables needed for receive and send side functionality and implementing the doInit() abstract method. The createPacket() and createTimer() methods can be used to construct packets and timers needed by the protocol. The setAcceptingNewSegments() and setPendingAcknowledgements() methods can be used to initalize the TCPEntity.

Receive side functionality is provided by implementing the following abstract methods.

In addition, the following methods may be overridden if the default implementation is not acceptable. All of these methods are invoked by the demultiplexer in the TCPEntity in response to received packets.

When a received segment is ready it can be sent to the reassembler in the TCPEntity using the reassemble() method. The terminate() method can be used to terminate the thread used by the protocol in response to a received close packet.

Send side functionality is provided by implementing the following abstract methods.

In addition, the following method may be overridden if the default implementation is not acceptable. The handleNewSegment() method is invoked by the segmenter in the TCPEntity in response to messages from the application layer. The handleTimedOutPacket() method is invoked by the TCPEntity in response to expiration of a timer. The initiateDisconnect() method is invoked by the TCPEntity in response to a close operation from the application layer.

The send() method can be used for passing packets to the transport layer multiplexer, which will send them to the other end of the connection. The setAcceptingNewSegments() method can be used to notify the TCPEntity whether or not new segments are being accepted. The setPendingAcknowledgements() method can be used to notify the TCPEntity whether or not there are packets that have been sent but not acknowledged. This controls when the TCPEntity will begin a disconnect.


Constructor Summary
RDTProtocol()
           
 
Method Summary
protected  Packet createPacket()
          createPacket() returns a new Packet that only requires setting its type, its identification number, and its sequence number before use.
protected  RDTTimer createTimer()
          createTimer() returns a new Timer that only requires setting its packet before use.
protected abstract  void doInit()
          doInit() is invoked to perform protocol-dependent initialization for this RDTProtocol.
abstract  void handleNewSegment(int id)
          rdtp.handleNewSegment(id) is invoked to get rdtp to handle a new segment with identification number id.
abstract  void handleReceivedAck(Packet pkt)
          rdtp.handleReceivedAck(pkt) is invoked to get rdtp to handle a ACK_TYPE packet received from its TCPEntity's connection partner.
 void handleReceivedClose(Packet pkt)
          rdtp.handleReceivedClose(pkt) is invoked to get rdtp to handle a CLOSE_TYPE packet received from its TCPEntity's connection partner.
abstract  void handleReceivedData(Packet pkt)
          rdtp.handleReceivedData(pkt) is invoked to get rdtp to handle a DATA_TYPE packet received from its TCPEntity's connection partner.
 void handleReceivedNack(Packet pkt)
          rdtp.handleReceivedNack(pkt) is invoked to get rdtp to handle a NACK_TYPE packet received from its TCPEntity's connection partner.
abstract  void handleTimedOutPacket(Packet pkt)
          rdtp.handleTimedOutPacket(pkt) is invoked to get rdtp to handle a packet acknowledgement timeout for pkt.
 void initialize(TCPEntity.Context cntxt)
          rdtp.initialize(cntxt) is invoked when a connection is set up using rdtp.
 void initiateDisconnect()
          rdtp.initiateDisconnect() is invoked to get rdtp to initate a disconnect sequence.
protected  void reassemble(int id)
          reassemble(id) sends id to the reassembler.
protected  void send(Packet pkt)
          send(pkt) sends pkt to the receiving end of the connection.
protected  void setAcceptingNewSegments(boolean acc)
          setAcceptingNewSegments(acc) informs the TCPEntity whether or not this RDTProtocol is accepting new segments.
protected  void setPendingAcknowledgements(boolean pa)
          setPendingAcknowledgements(pa) informs the TCPEntity whether or not this RDTProtocol has packets that have been sent but not yet acknowledged.
protected  void terminate()
          terminate() terminates the thread used by this RDTProtocol.
 java.lang.String toString()
          rdtp.toString() returns the name of rdtp, which is derived from its TCPEntity's name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RDTProtocol

public RDTProtocol()
Method Detail

createPacket

protected Packet createPacket()
createPacket() returns a new Packet that only requires setting its type, its identification number, and its sequence number before use.


createTimer

protected RDTTimer createTimer()
createTimer() returns a new Timer that only requires setting its packet before use.


setAcceptingNewSegments

protected void setAcceptingNewSegments(boolean acc)
setAcceptingNewSegments(acc) informs the TCPEntity whether or not this RDTProtocol is accepting new segments.

If the TCPEntity is not properly informed, the protocol may hang or behave unpredictably.


setPendingAcknowledgements

protected void setPendingAcknowledgements(boolean pa)
setPendingAcknowledgements(pa) informs the TCPEntity whether or not this RDTProtocol has packets that have been sent but not yet acknowledged.

If the TCPEntity is not properly informed, the protocol may close prematurely or not close at all.


reassemble

protected void reassemble(int id)
reassemble(id) sends id to the reassembler.


send

protected void send(Packet pkt)
send(pkt) sends pkt to the receiving end of the connection.


terminate

protected void terminate()
terminate() terminates the thread used by this RDTProtocol.


doInit

protected abstract void doInit()
doInit() is invoked to perform protocol-dependent initialization for this RDTProtocol.


handleNewSegment

public abstract void handleNewSegment(int id)
rdtp.handleNewSegment(id) is invoked to get rdtp to handle a new segment with identification number id. The identification number is just a stand-in for the real data in a segment. It is used by the Logger for recording purposes.


handleReceivedData

public abstract void handleReceivedData(Packet pkt)
rdtp.handleReceivedData(pkt) is invoked to get rdtp to handle a DATA_TYPE packet received from its TCPEntity's connection partner.


handleReceivedAck

public abstract void handleReceivedAck(Packet pkt)
rdtp.handleReceivedAck(pkt) is invoked to get rdtp to handle a ACK_TYPE packet received from its TCPEntity's connection partner.


handleTimedOutPacket

public abstract void handleTimedOutPacket(Packet pkt)
rdtp.handleTimedOutPacket(pkt) is invoked to get rdtp to handle a packet acknowledgement timeout for pkt. pkt may be null for protocols that use a single timer.


handleReceivedNack

public void handleReceivedNack(Packet pkt)
rdtp.handleReceivedNack(pkt) is invoked to get rdtp to handle a NACK_TYPE packet received from its TCPEntity's connection partner. The default implementation ignores NACK_TYPE packets.


handleReceivedClose

public void handleReceivedClose(Packet pkt)
rdtp.handleReceivedClose(pkt) is invoked to get rdtp to handle a CLOSE_TYPE packet received from its TCPEntity's connection partner. The default implementation terminates the connection. If pkt's sequence number is 0 then a CLOSE_TYPE packet with sequence number 1 is sent as acknowledgement before termination.


initiateDisconnect

public void initiateDisconnect()
rdtp.initiateDisconnect() is invoked to get rdtp to initate a disconnect sequence. The defualt implementation sends a CLOSE_TYPE packet with sequence number 0 to the partner.


initialize

public void initialize(TCPEntity.Context cntxt)
rdtp.initialize(cntxt) is invoked when a connection is set up using rdtp. Services from the TCPEntity are provided through cntxt.


toString

public java.lang.String toString()
rdtp.toString() returns the name of rdtp, which is derived from its TCPEntity's name.

Overrides:
toString in class java.lang.Object