bamboo.lss
Class UdpCC

java.lang.Object
  extended by bamboo.lss.UdpCC

public class UdpCC
extends Object

A TCP-friendly datagram layer.

Version:
$Id: UdpCC.java,v 1.51 2005/03/01 18:10:44 srhea Exp $
Author:
Sean C. Rhea

Nested Class Summary
protected  class UdpCC.BandwidthCB
           
protected  class UdpCC.Connection
          Keep track of all of the relavent information about another node we are talking to.
protected  class UdpCC.MyAckTimeoutCB
           
protected  class UdpCC.MySelectableCB
           
static interface UdpCC.SendCB
           
static interface UdpCC.Serializer
           
static interface UdpCC.Sink
           
protected static class UdpCC.SrcAndMsgId
           
protected  class UdpCC.StatsCB
           
static class UdpCC.TimeoutInfo
           
protected static class UdpCC.TimeoutInfoAndSeq
           
 
Field Summary
protected  UdpCC.MyAckTimeoutCB ack_timeout_cb
           
protected  ASyncCore acore
           
protected static long BW_STATS_PERIOD
           
protected  DatagramChannel channel
           
protected  boolean closed
           
protected  Map conns
           
protected  boolean DEBUG
           
protected  boolean DEBUG_MIN
           
protected  boolean DEBUG_RTT
           
protected  ASyncCore.TimerCB dup_track_cb
           
protected  long in_bytes
           
protected  long in_pkts
           
protected static boolean LOG_BAD_NETWORK_EVENTS
           
protected  org.apache.log4j.Logger logger
           
protected  Mac mac
           
protected static int MAX_MSG_SIZE
           
protected static int MAX_RECENTLY_SEEN_SIZE
           
protected static long MAX_RTO
           
protected static double MAX_WND
           
protected  InetSocketAddress my_addr
           
protected  long next_msg_id
           
protected  long out_bytes
           
protected  long out_pkts
           
protected  long received_duplicates
           
protected  long received_msgs
           
protected  LinkedList recently_seen_list
           
protected  HashSet recently_seen_set
           
protected static boolean REUSE
           
protected  ByteBuffer reuse_buf
           
protected  UdpCC.Connection rr_first
           
protected  UdpCC.Connection rr_last
           
protected  Map second_chance
           
protected  PriorityQueue second_chance_timeouts
           
protected  UdpCC.Serializer serializer
           
protected  UdpCC.Sink sink
           
protected  SelectionKey skey
           
protected  DatagramSocket sock
           
protected  int SOCKBUF_MAX
           
protected static long STATS_PERIOD
           
protected  double timeout_diff
           
protected  double timeout_factor
           
protected  long track_duplicates_period
           
protected  Map unacked
           
protected  boolean USE_DIRECT
           
 
Constructor Summary
UdpCC(ASyncCore core, InetSocketAddress address, UdpCC.Serializer slz, UdpCC.Sink snk)
          Construct a new UdpCC object with a UDP socket bound to address and start listening for messages.
 
Method Summary
protected  void add_to_rr(UdpCC.Connection conn)
           
protected  ByteBuffer alloc_bb(int sz)
           
protected  int attempt(long seq)
           
protected  void BUG(Exception e)
           
protected  void BUG(String msg)
           
 void close()
          Closes the socket associated with this object, removes its callbacks from ASyncCore, and causes it to stop responding to any outstanding timers it has registered--in other words, turns it off.
 int debug_level()
           
protected  void debugln(String msg)
           
protected  void handle_ack(Long seq)
           
protected  void handle_inb_msg(ByteBuffer bb, InetSocketAddress src)
           
protected  void handle_readable()
           
protected  void handle_writable()
           
protected  long inc_next_msg_id()
           
 long last_recv(InetSocketAddress peer)
          Returns the number of milliseconds since the epoch of the last time we received an acknowledgement from this peer, or 0 if we have yet to receive an acknowledgement from them.
 long last_send(InetSocketAddress peer)
          Returns the number of milliseconds since the epoch of the last time we sent a message to this peer, or 0 if we haven't sent a message to them at all.
 long latency_mean(InetSocketAddress peer)
          Returns the current estimate of the mean latency to this peer, or -1 if there is no current estimate.
protected  long make_seq(long msg_id, int attempt)
           
protected  long msg_id(long seq)
           
 int queued_msgs()
          Returns the number of messages waiting to be sent or currently in flight to all peers.
 int queued_msgs(InetSocketAddress peer)
          Returns the number of messages waiting to be sent or currently in flight to this peer.
protected  boolean recently_seen(InetSocketAddress src, long msg_id)
           
protected  boolean send_ack(UdpCC.Connection conn)
           
protected  boolean send_msg(UdpCC.Connection conn, boolean retry)
           
 void send_nocc(Object msg, InetSocketAddress dst)
          This is just a one-shot, minimal-delay send without an acknowledgement; Do not use this function unless you are providing some application-level congestion control.
protected  boolean send_probe(UdpCC.Connection conn)
           
 LinkedList send_q(InetSocketAddress peer)
          Don't use this function; I'm trying to figure out how to get rid of it.
 void send(Object msg, InetSocketAddress dst, long timeout_sec, UdpCC.SendCB cb, Object user_data)
          Send a congestion-controlled message to another host.
 void set_debug_level(int value)
           
 void set_mac_key(String keyfile)
           
 void set_sockbuf_size(int value)
           
 void set_timeout_diff(double value)
           
 void set_timeout_factor(double value)
           
 void track_duplicates(long period)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG_MIN

protected boolean DEBUG_MIN

DEBUG_RTT

protected boolean DEBUG_RTT

DEBUG

protected boolean DEBUG

track_duplicates_period

protected long track_duplicates_period

received_msgs

protected long received_msgs

received_duplicates

protected long received_duplicates

dup_track_cb

protected ASyncCore.TimerCB dup_track_cb

SOCKBUF_MAX

protected int SOCKBUF_MAX

logger

protected org.apache.log4j.Logger logger

mac

protected Mac mac

USE_DIRECT

protected boolean USE_DIRECT

MAX_RTO

protected static final long MAX_RTO
See Also:
Constant Field Values

BW_STATS_PERIOD

protected static final long BW_STATS_PERIOD
See Also:
Constant Field Values

STATS_PERIOD

protected static final long STATS_PERIOD
See Also:
Constant Field Values

MAX_WND

protected static final double MAX_WND
See Also:
Constant Field Values

MAX_MSG_SIZE

protected static final int MAX_MSG_SIZE
See Also:
Constant Field Values

LOG_BAD_NETWORK_EVENTS

protected static final boolean LOG_BAD_NETWORK_EVENTS
See Also:
Constant Field Values

REUSE

protected static final boolean REUSE
See Also:
Constant Field Values

timeout_factor

protected double timeout_factor

timeout_diff

protected double timeout_diff

closed

protected boolean closed

acore

protected ASyncCore acore

serializer

protected UdpCC.Serializer serializer

sink

protected UdpCC.Sink sink

ack_timeout_cb

protected UdpCC.MyAckTimeoutCB ack_timeout_cb

skey

protected SelectionKey skey

channel

protected DatagramChannel channel

sock

protected DatagramSocket sock

my_addr

protected InetSocketAddress my_addr

unacked

protected Map unacked

second_chance

protected Map second_chance

second_chance_timeouts

protected PriorityQueue second_chance_timeouts

next_msg_id

protected long next_msg_id

rr_first

protected UdpCC.Connection rr_first

rr_last

protected UdpCC.Connection rr_last

conns

protected Map conns

reuse_buf

protected ByteBuffer reuse_buf

in_bytes

protected long in_bytes

in_pkts

protected long in_pkts

out_bytes

protected long out_bytes

out_pkts

protected long out_pkts

recently_seen_set

protected HashSet recently_seen_set

recently_seen_list

protected LinkedList recently_seen_list

MAX_RECENTLY_SEEN_SIZE

protected static final int MAX_RECENTLY_SEEN_SIZE
See Also:
Constant Field Values
Constructor Detail

UdpCC

public UdpCC(ASyncCore core,
             InetSocketAddress address,
             UdpCC.Serializer slz,
             UdpCC.Sink snk)
Construct a new UdpCC object with a UDP socket bound to address and start listening for messages.

Method Detail

track_duplicates

public void track_duplicates(long period)

close

public void close()
Closes the socket associated with this object, removes its callbacks from ASyncCore, and causes it to stop responding to any outstanding timers it has registered--in other words, turns it off. There is no way to turn it back on; instead, just create a new one.


debug_level

public int debug_level()

set_debug_level

public void set_debug_level(int value)

set_sockbuf_size

public void set_sockbuf_size(int value)

set_timeout_factor

public void set_timeout_factor(double value)

set_timeout_diff

public void set_timeout_diff(double value)

set_mac_key

public void set_mac_key(String keyfile)
                 throws Exception
Throws:
Exception

send_nocc

public void send_nocc(Object msg,
                      InetSocketAddress dst)
This is just a one-shot, minimal-delay send without an acknowledgement; Do not use this function unless you are providing some application-level congestion control. Messages send with this function go into their own per-destination queue, separate from messages sent with send(java.lang.Object, java.net.InetSocketAddress, long, bamboo.lss.UdpCC.SendCB, java.lang.Object).


send

public void send(Object msg,
                 InetSocketAddress dst,
                 long timeout_sec,
                 UdpCC.SendCB cb,
                 Object user_data)
Send a congestion-controlled message to another host. Use this function, and your communtication will be TCP-friendly, which is good. Once the message is sent, or when tries timeouts have occurred while trying to send it, the give callback will be called.

Parameters:
msg - the message to send
dst - the message's destination host and port
tries - the number of attempts made to send the message
cb - the callback to call when the message is sent, or when the number of tries is exhausted
user_data - the application-specific data to call that callback with

last_send

public long last_send(InetSocketAddress peer)
Returns the number of milliseconds since the epoch of the last time we sent a message to this peer, or 0 if we haven't sent a message to them at all.


last_recv

public long last_recv(InetSocketAddress peer)
Returns the number of milliseconds since the epoch of the last time we received an acknowledgement from this peer, or 0 if we have yet to receive an acknowledgement from them.


latency_mean

public long latency_mean(InetSocketAddress peer)
Returns the current estimate of the mean latency to this peer, or -1 if there is no current estimate.


queued_msgs

public int queued_msgs(InetSocketAddress peer)
Returns the number of messages waiting to be sent or currently in flight to this peer.


queued_msgs

public int queued_msgs()
Returns the number of messages waiting to be sent or currently in flight to all peers.


send_q

public LinkedList send_q(InetSocketAddress peer)
Don't use this function; I'm trying to figure out how to get rid of it.


debugln

protected void debugln(String msg)

recently_seen

protected final boolean recently_seen(InetSocketAddress src,
                                      long msg_id)

inc_next_msg_id

protected final long inc_next_msg_id()

msg_id

protected final long msg_id(long seq)

attempt

protected final int attempt(long seq)

make_seq

protected final long make_seq(long msg_id,
                              int attempt)

BUG

protected void BUG(Exception e)

BUG

protected void BUG(String msg)

alloc_bb

protected final ByteBuffer alloc_bb(int sz)

handle_ack

protected final void handle_ack(Long seq)

handle_inb_msg

protected final void handle_inb_msg(ByteBuffer bb,
                                    InetSocketAddress src)

handle_readable

protected final void handle_readable()

send_ack

protected final boolean send_ack(UdpCC.Connection conn)

send_probe

protected final boolean send_probe(UdpCC.Connection conn)

send_msg

protected final boolean send_msg(UdpCC.Connection conn,
                                 boolean retry)

add_to_rr

protected final void add_to_rr(UdpCC.Connection conn)

handle_writable

protected void handle_writable()