urv.olsr.data
Class SequenceNumber

java.lang.Object
  extended by urv.olsr.data.SequenceNumber
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, org.jgroups.util.Streamable

public class SequenceNumber
extends java.lang.Object
implements java.io.Serializable, org.jgroups.util.Streamable, java.lang.Comparable

Sequence numbers are used in OLSR with the purpose of discarding "old" information, i.e., messages received out of order. However with a limited number of bits for representing sequence numbers, wrap-around (that the sequence number is incremented from the maximum possible value to zero) will occur. To prevent this from interfering with the operation of the protocol, the following MUST be observed. The term MAXVALUE designates in the following the largest possible value for a sequence number. The sequence number S1 is said to be "greater than" the sequence number S2 if: S1 > S2 AND S1 - S2 <= MAXVALUE/2 OR S2 > S1 AND S2 - S1 > MAXVALUE/2 Thus when comparing two messages, it is possible - even in the presence of wrap-around - to determine which message contains the most recent information.

Author:
Gerard Paris Aixala
See Also:
Serialized Form

Constructor Summary
SequenceNumber(int seq)
           
 
Method Summary
 java.lang.Object clone()
           
 int compareTo(java.lang.Object obj)
          Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
 boolean equals(java.lang.Object obj)
           
 int hashCode()
           
 void increase()
          The message sequence number is increased by 1 (one) for each message originating from the node.
 void readFrom(java.io.DataInputStream in)
           
 java.lang.String toString()
           
 void writeTo(java.io.DataOutputStream out)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SequenceNumber

public SequenceNumber(int seq)
Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

compareTo

public int compareTo(java.lang.Object obj)
Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - A SequenceNumber object to be compared with this object.
Returns:

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

readFrom

public void readFrom(java.io.DataInputStream in)
              throws java.io.IOException,
                     java.lang.IllegalAccessException,
                     java.lang.InstantiationException
Specified by:
readFrom in interface org.jgroups.util.Streamable
Throws:
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

writeTo

public void writeTo(java.io.DataOutputStream out)
             throws java.io.IOException
Specified by:
writeTo in interface org.jgroups.util.Streamable
Throws:
java.io.IOException

increase

public void increase()
The message sequence number is increased by 1 (one) for each message originating from the node.