public class Segment extends Packet implements java.lang.Comparable<Segment>
Modifier and Type | Field and Description |
---|---|
int |
ackSequenceNumber
Acknowledgment sequence number, in case this segment
also acknowledges received data.
|
int |
dataSequenceNumber
Sequence number of this segment, which is the sequence
number of the first byte of data carried in this
segment.
|
boolean |
isAck
A flag that informs whether or not this segment contains an ACK.
|
(package private) int |
ordinalNum
Ordinal number of this segment.
|
(package private) int |
ordinalNumAck
Similar to
ordinalNum |
int |
rcvWindow
The size of the currently available space in the receiver's buffer
(used mostly for buffering out-of-order segments).
|
int |
timestamp
The sending time of a segment (similar to the timestamp option in
the Options field of an actual TCP header).
|
dataPayload, destinationAddr, identifier, inError, length
Constructor and Description |
---|
Segment(NetworkElement destinationAddr_,
int rcvWindow_,
int ackSeqNum_)
Constructor for acknowledgment-only segments (zero data payload).
|
Segment(NetworkElement destinationAddr_,
int rcvWindow_,
int seqNum_,
byte[] dataPayload_)
Constructor for data-only segments.
|
Segment(NetworkElement destinationAddr_,
int rcvWindow_,
int seqNum_,
byte[] dataPayload_,
int ackSeqNum_)
Constructor for both data and acknowledgment segments,
i.e., an acknowledgment is piggybacked on a data segment
going to the same destination.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Segment anotherSegmentToCompareTo_)
This method is part of the java.lang.Comparable
|
void |
setAckSequenceNumber(int ackSequenceNumber_)
Attribute setter for the acknowledgment sequence number.
|
java.lang.String |
toString()
Prints out some basic information about this TCP segment.
|
public int ackSequenceNumber
isAck
flag is set isAck
.public int dataSequenceNumber
public boolean isAck
int ordinalNum
dataSequenceNumber
starts at zero.int ordinalNumAck
ordinalNum
public int rcvWindow
Receiver.rcvBuffer
public int timestamp
In fact, there should be two timestamps per segment, if acknowledgments are piggybacked on data segments, but in this simulator we assume that all acknowledgments are zero-data segments (i.e., they don't have any payload.
This field should be set to -1
if the segment is
a retransmitted segment, and no RTT estimation should be performed
for retransmitted segments.
public Segment(NetworkElement destinationAddr_, int rcvWindow_, int ackSeqNum_)
rcvWindow_
- the current receive window size of the sender of this segmentackSeqNum_
- the acknowledgment sequence number of this segmentpublic Segment(NetworkElement destinationAddr_, int rcvWindow_, int seqNum_, byte[] dataPayload_)
rcvWindow_
- the current receive window size of the sender of this segmentseqNum_
- the sequence number for the data payload.dataPayload_
- the data payload contained in this segmentpublic Segment(NetworkElement destinationAddr_, int rcvWindow_, int seqNum_, byte[] dataPayload_, int ackSeqNum_)
rcvWindow_
- the current receive window size of the sender of this segmentseqNum_
- the sequence number of this segmentdataPayload_
- the data payload, if anyackSeqNum_
- the acknowledgment sequence number, if anypublic int compareTo(Segment anotherSegmentToCompareTo_)
java.util.Collections.sort()
( and java.util.Arrays.sort()
).
Such capability is needed by the TCP receiver module when filling the gaps in the sequence numbers of received segments.
compareTo
in interface java.lang.Comparable<Segment>
Receiver.checkBufferedSegments()
public void setAckSequenceNumber(int ackSequenceNumber_)
Receiver.handle(Segment)
resets the ACK sequence number for cumulative ACKs,
but then we need to recompute ordinalNumAck
as well.ackSequenceNumber_
- the acknowledgment sequence number to set