public class Receiver extends java.lang.Object implements TimedComponent
delayedACKtimer
and cumulativeACK
.Simulator
Modifier and Type | Field and Description |
---|---|
protected Segment |
cumulativeACK
The receiver may hold a cumulative acknowledgment
for in-order segments, to acknowledge several consecutive
segments at once.
There are two standard methods that can be used by TCP receivers to generate acknowledgments. |
protected int |
currentRcvWindow
Current receive window size, in bytes.
|
protected TimerSimulated |
delayedACKtimer
The timer for delayed (cumulative) acknowledgments.
Because of the way the simulator is implemented, it calls the receiver to process the received packets one by one. |
protected TimerSimulated |
delayedACKtimerHandle
Handle returned by the simulator, in case
delayedACKtimer
needs to be canceled. |
protected int |
lastByteRecvd
The field records the last byte received in-sequence.
|
(package private) Endpoint |
localEndpoint
Local endpoint that contains this receiver object.
|
protected int |
maxRcvWindowSize
Maximum receive window size, in bytes.
|
protected int |
nextByteExpected
The next byte currently expected from the sender.
|
protected java.util.ArrayList<Segment> |
rcvBuffer
The receiver buffer to buffer the segments that arrive
out-of-sequence.
|
Constructor and Description |
---|
Receiver(Endpoint localTCPendpoint_,
int rcvWindowSize_)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkBufferedSegments()
Helper method, checks if the newly received segment(s)
fill a gap for the segments that were previously
received out-of-sequence and are stored in a temporary
storage ("buffered").
|
int |
getRcvWindow()
Returns the receive window size for this receiver, in bytes.
|
void |
handle(Segment segment_)
Receives the segments from the sender, passes the
ones that arrived error-free and in-order to the application.
|
protected Segment |
handleOutOfSequenceSegment(Segment segment_)
Helper method to handle out-of-sequence segments.
|
protected void |
sendCumulativeAcknowledgement()
Helper method to transmit a cumulative acknowledgment.
The TCP specification suggests that at least every other acknowledgment should be sent. |
void |
timerExpired(int timerType_)
Callback method to call when a simulated timer expires.
|
protected Segment cumulativeACK
protected int currentRcvWindow
protected TimerSimulated delayedACKtimer
cumulativeACK
.protected TimerSimulated delayedACKtimerHandle
delayedACKtimer
needs to be canceled. Recall that, if the receiver receives
an out-of-order segment, it is obliged to send a (duplicate)
ACK immediately. However, if delayedACKtimer
has
not yet expired, it must be cancelled first.protected int lastByteRecvd
Endpoint localEndpoint
protected int maxRcvWindowSize
protected int nextByteExpected
protected java.util.ArrayList<Segment> rcvBuffer
checkBufferedSegments()
.public Receiver(Endpoint localTCPendpoint_, int rcvWindowSize_)
localTCPendpoint_
- The local TCP endpoint object that contains
this receiver.rcvWindowSize_
- The maximum receive window size, in bytes
— how much memory this receiver should allocate for buffering
out-of-order segments.protected void checkBufferedSegments()
public int getRcvWindow()
public void handle(Segment segment_)
The receiver returns cumulative acknowledgments, which means that if the newly received segment fills the gap created by out-of-sequence segments that were received earlier, the cumulative ACK will acknowledge those earlier segments, as well.
The value null
of the segments_
input
array element means that the corresponding segment was
lost in transport (i.e., at the Router).
segment_
- The received segments (with non-zero data payload).protected Segment handleOutOfSequenceSegment(Segment segment_)
rcvBuffer
.
The returned value will be a duplicate acknowledgment.segment_
- The segment that is currently being processed
(i.e., the seq. num. of the segment's last byte).protected void sendCumulativeAcknowledgement()
delayedACKtimer
time.public void timerExpired(int timerType_)
Currently, the receiver sets a timer for delayed (cumulative) acknowledgments. Any cumulative ACK that it may be holding will be transmitted now.
timerExpired
in interface TimedComponent
timerType_
- type of the timer set initially by the caller,
in case multiple timers are run by the same component.TimedComponent