verinec.netsim.util.tables
Class SlidingWindowPacketBuffer

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractList
          extended by java.util.Vector
              extended by verinec.netsim.util.tables.SlidingWindowPacketBuffer
All Implemented Interfaces:
Serializable, Cloneable, Iterable, Collection, List, RandomAccess

public class SlidingWindowPacketBuffer
extends Vector

A sliding window buffer containing packets

Version:
$Revision: 47 $
Author:
Dominik Jungo
See Also:
Serialized Form

Field Summary
private  int ack
           
private  int capacity
           
private  Logger jlogger
           
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SlidingWindowPacketBuffer(int initialCapacity)
          Creates a new sliding window buffer.
 
Method Summary
private  void cleanUp()
           
 TCPPacket get()
          gets the first packet from the contiguous part of the window
 int getAck()
          gets the address of the last packet of the buffer that can be acknowledged
private  int getNextSeq(int seq)
           
private  TCPPacket getPacket(int seq)
          gets packet from the contiguous part of the window
private  int getSmallestSeq()
           
 int put(TCPPacket packet)
          writes a TCP Packet into the buffer
 void removePacket()
          removes the packet with the smallest sequence number
 void removePacket(int seq)
          removes a packet with a given sequence number from the buffer
private  void updateAck()
           
 int windowsize()
          gets the remaining window size
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Field Detail

capacity

private int capacity

ack

private int ack

jlogger

private Logger jlogger
Constructor Detail

SlidingWindowPacketBuffer

public SlidingWindowPacketBuffer(int initialCapacity)
Creates a new sliding window buffer.

Parameters:
initialCapacity - the window size (capacity of the buffer)
Method Detail

put

public int put(TCPPacket packet)
        throws NetSimException
writes a TCP Packet into the buffer

Parameters:
packet - a TCP Packet
Returns:
address of the last part of data in a contiguous part
Throws:
NetSimException - if there if no more spave left in buffer or the address is out of window range

cleanUp

private void cleanUp()

getAck

public int getAck()
gets the address of the last packet of the buffer that can be acknowledged

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

updateAck

private void updateAck()

getPacket

private TCPPacket getPacket(int seq)
                     throws NetSimException
gets packet from the contiguous part of the window

Parameters:
seq - the packets sequence number
Returns:
the requested packet
Throws:
NetSimException - if requested packet not in buffer or separated by missing part

getSmallestSeq

private int getSmallestSeq()

getNextSeq

private int getNextSeq(int seq)
                throws NetSimException
Throws:
NetSimException

get

public TCPPacket get()
              throws NetSimException
gets the first packet from the contiguous part of the window

Returns:
the first packet from the contiguous part of the window
Throws:
NetSimException - if requested element not in buffer or separated by missing part

removePacket

public void removePacket()
removes the packet with the smallest sequence number


removePacket

public void removePacket(int seq)
removes a packet with a given sequence number from the buffer

Parameters:
seq - a sequence number

windowsize

public int windowsize()
gets the remaining window size

Returns:
the window size

Copyright © 2005 Verinec, DIUF