jist.swans.route
Class RouteDsr

java.lang.Object
  extended by jist.swans.route.RouteDsr
All Implemented Interfaces:
JistAPI.Proxiable, JistAPI.Timeless, NetInterface.NetHandler, RouteInterface, RouteInterface.Dsr

public class RouteDsr
extends java.lang.Object
implements RouteInterface.Dsr

An implementation of the Dynamic Source Routing protocol.

Since:
SWANS1.0
Version:
$Id: RouteDsr.java,v 1.30 2004/11/25 17:52:17 barr Exp $
Author:
Ben Viglietta, Rimon Barr <barr+jist@cs.cornell.edu>
See Also:
DSR Specification

Nested Class Summary
private  class RouteDsr.MaintenanceBufferEntry
          Entries in the Maintenance Buffer correspond to messages that have been sent and are currently waiting passive acknowledgement.
private  class RouteDsr.RouteReplyTableEntry
          An entry in the Gratuitous Route Reply Table.
private  class RouteDsr.RouteRequestTableEntry
          An entry in the Route Request Table.
 
Nested classes/interfaces inherited from interface jist.swans.route.RouteInterface.Dsr
RouteInterface.Dsr.BufferedPacket
 
Nested classes/interfaces inherited from interface jist.swans.route.RouteInterface
RouteInterface.Aodv, RouteInterface.Dsr, RouteInterface.Zrp
 
Field Summary
private  java.util.HashSet activeAcks
          Set of Shorts indicating outstanding acknowledgement requests.
private  java.util.HashSet activeRequests
          Set of NetAddresses of destinations of currently active Route Requests.
static long BROADCAST_JITTER
          The maximum amount of jitter before sending a packet.
static long GRAT_REPLY_HOLDOFF
          The minimum time between sending gratuitous Route Replies.
private  NetAddress localAddr
          The IP address of this node.
private static org.apache.log4j.Logger log
          DSR logger.
static long MAINT_PERIOD
          The timeout before retransmitting a packet using network-level acknowledgements.
private  java.util.Hashtable maintenanceBuffer
          Maintenance Buffer.
static int MAX_MAINT_REXMT
          The maximum number of times a packet will be retransmitted using network-level acknowledgements.
static long MAX_REQUEST_PERIOD
          The maximum timeout before retransmitting a Route Request.
static int MAX_REQUEST_TABLE_IDS
          The maximum number of ID values to store in a single Route Request Table entry.
static int MAX_SALVAGE_COUNT
          The maximum number of times a packet can be salvaged.
static byte MAX_TTL
          The maximum Time-To-Live for a DSR packet.
private  NetInterface netEntity
          The interface to the network layer.
private  short nextAckId
          The next ID number to use when sending an acknowledgement request.
private  short nextRequestId
          The next ID number to use when sending a route request.
static long PASSIVE_ACK_TIMEOUT
          The timeout before retransmitting a packet using passive acknowledgements.
static long REQUEST_PERIOD
          The initial timeout before retransmitting a Route Request.
private  java.util.Hashtable routeCache
          The route cache maps NetAddresses (destinations) to LinkedLists of arrays of NetAddresses (routes).
private  java.util.HashSet routeReplyTable
          The Gratuitous Route Reply Table is a set of RouteReplyTableEntrys indicating which nodes have recently triggered gratuitous Route Replies because of automatic route shortening.
private  java.util.Hashtable routeRequestTable
          The route request table maps NetAddresses(destinations) to RouteRequestTableEntrys, which are structures containing various information used when performing Route Discovery.
private  RouteInterface.Dsr self
          The proxy interface for this object.
static long SEND_BUFFER_TIMEOUT
          The maximum amount of time a packet can remain in the Send Buffer.
private  java.util.LinkedList sendBuffer
          List of BufferedPackets waiting to be sent.
static int TRY_PASSIVE_ACKS
          The number of times to try retransmission using passive ackknowledgments.
 
Constructor Summary
RouteDsr(NetAddress localAddr)
          Creates a new RouteDsr object.
 
Method Summary
private  void AddRequestId(NetAddress src, short id)
          Enters a new Route Request ID number into the Route Request Table.
 void AddRouteReplyEntry(NetAddress originator, NetAddress lastHop)
          Adds a new entry to the Gratuitous Route Reply Table.
private  void CheckBuffer(NetAddress dest)
          Searches the Send Buffer for any packets intended for the given destination and sends any that are found.
private  void CheckForPassiveAck(RouteDsrMsg msg, NetAddress src, NetAddress dest, short protocol, short id, short fragOffset)
          Checks the given message to see if it matches any of the messages in the Maintenance Buffer for which we are currently awaiting passive passive acknowledgements.
 void DeleteBuffer(RouteInterface.Dsr.BufferedPacket msg)
          Removes the given BufferedPacket from the Send Buffer.
 void DeleteRouteReplyEntry(NetAddress originator, NetAddress lastHop)
          Deletes an entry from the Gratuitous Route Reply Table.
 void DiscoverRoute(NetAddress dest, short requestId)
          Initiates a Route Discovery for the given address.
private  void ForwardPacket(RouteDsrMsg msg, RouteDsrMsg.OptionSourceRoute opt, byte[] optBuf, NetAddress src, NetAddress dest, short protocol, byte priority, byte ttl, short id, short fragOffset)
          Forwards a DSR packet containing a Source Route option to the next intended recipient.
private  void ForwardRequest(RouteDsrMsg msg, RouteDsrMsg.OptionRouteRequest opt, byte[] optBuf, NetAddress src, NetAddress dst, short protocol, byte priority, byte ttl, short id, short fragOffset)
          Propagates a Route Request to all nodes within range.
private  NetAddress[] GetCachedRoute(NetAddress dest)
          Retrieves a route from the Route Cache from here to the given node.
 RouteInterface.Dsr getProxy()
          Gets the proxy interface for this object.
private  RouteDsrMsg.OptionSourceRoute GetSourceRoute(RouteDsrMsg msg)
          Retrieves the Source Route option from the given DSR message, or null if none exists.
private  void HandleAck(RouteDsrMsg.OptionAck opt, NetAddress dest)
          Processes an incoming Acknowledgement option.
private  void HandleAckRequest(RouteDsrMsg msg, RouteDsrMsg.OptionAckRequest opt, NetAddress src, NetAddress dst, RouteDsrMsg.OptionSourceRoute sourceRoute)
          Processes an incoming Acknowledgement Request option.
private  void HandleError(RouteDsrMsg.OptionRouteError opt)
          Processes an incoming Route Error option.
private  void HandleReply(RouteDsrMsg msg, RouteDsrMsg.OptionRouteReply reply)
          Processes an incoming Route Reply.
private  void HandleRequest(RouteDsrMsg msg, RouteDsrMsg.OptionRouteRequest opt, byte[] optBuf, NetAddress src, NetAddress dst, short protocol, byte priority, byte ttl, short id, short fragOffset)
          Processes an incoming Route Request option.
private  void InitBuffer()
          Initializes the Send Buffer.
private  void InitMaintenanceBuffer()
          Initializes the Maintenance Buffer.
private  void InitRequestTable()
          Initializes the Route Request Table.
private  void InitRouteCache()
          Initializes the Route Cache.
private  void InitRouteReplyTable()
          Initializes the Gratuitous Route Reply Table.
 void InsertBuffer(NetMessage.Ip msg)
          Inserts a new packet into the Send Buffer, annotating it with the current system time.
 void InsertRouteCache(NetAddress dest, NetAddress[] route)
          Inserts a new route into the Route Cache.
private  NetAddress NextRecipient(RouteDsrMsg.OptionSourceRoute sourceRoute, NetAddress dst)
          Determines the intended next recipient of a packet with the given source route option and IP destination.
 void peek(NetMessage msg, MacAddress lastHop)
          If the given message uses the DSR protocol, the DSR header is examined to see if any actions need to be performed on this packet (such as forwarding it).
private  void PerformRouteShortening(RouteDsrMsg.OptionSourceRoute sourceRoute, NetAddress src, NetAddress dest)
          Checks to see if we know a shorter route from src to dest than the one given in sourceRoute.
private  NetAddress PrevRecipient(RouteDsrMsg.OptionSourceRoute sourceRoute, NetAddress src)
          Determines the previous recipient of a packet with the given source route option and IP source.
private  void ProcessOptions(RouteDsrMsg msg, NetAddress src, NetAddress dst, short protocol, byte priority, byte ttl, short id, short fragOffset)
          Handles each of the options in a given DSR header.
 void receive(Message msg, NetAddress src, MacAddress lastHop, byte macId, NetAddress dst, byte priority, byte ttl)
          Receives a message from the network.
private  void RemoveCachedLink(NetAddress addr1, NetAddress addr2)
          Removes every path in the cache that uses a direct link between addr1 and addr2.
private  boolean RouteReplyEntryExists(NetAddress originator, NetAddress lastHop)
          Determines whether there is an entry in the Gratuitous Route Reply Table corresponding to the given addresses.
private  boolean SeenRequestLately(NetAddress src, short id)
          Checks if we have recently seen the Route Request with the given id coming from the given source.
 void send(NetMessage msg)
          Sends the given message.
private  void SendGratuitousRouteReply(NetAddress src, RouteDsrMsg.OptionSourceRoute sourceRoute, NetAddress dest, int routeLength)
          Sends a gratuitous Route Reply to src.
private  void SendRouteError(RouteDsrMsg msg, NetAddress src, NetAddress dest)
          Sends a DSR message with a Route Error option to src indicating that the next hop in the intended route cannot be reached from this node.
private  void SendRouteReply(RouteDsrMsg.OptionRouteRequest opt, NetAddress src)
          Sends a Route Reply to a node that recently sent us a Route Request.
private  void SendWithRoute(NetMessage.Ip msg, NetAddress[] route)
          Sends the given message along the given route.
 void setNetEntity(NetInterface netEntity)
          Sets the interface to the network layer.
private  void Transmit(NetMessage.Ip msg)
          Sends the given message and looks for acknowledgement.
 void TransmitWithNetworkAck(NetMessage.Ip msg, java.lang.Short ackId, long timeout, int numRetransmits)
          Sends the given message.
 void TransmitWithPassiveAck(NetMessage.Ip msg, int numRetransmits)
          Sends the given message and waits for a passive acknowledgement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BROADCAST_JITTER

public static final long BROADCAST_JITTER
The maximum amount of jitter before sending a packet.

See Also:
Constant Field Values

SEND_BUFFER_TIMEOUT

public static final long SEND_BUFFER_TIMEOUT
The maximum amount of time a packet can remain in the Send Buffer.

See Also:
Constant Field Values

REQUEST_PERIOD

public static final long REQUEST_PERIOD
The initial timeout before retransmitting a Route Request.

See Also:
Constant Field Values

MAX_REQUEST_PERIOD

public static final long MAX_REQUEST_PERIOD
The maximum timeout before retransmitting a Route Request.

See Also:
Constant Field Values

MAX_MAINT_REXMT

public static final int MAX_MAINT_REXMT
The maximum number of times a packet will be retransmitted using network-level acknowledgements.

See Also:
Constant Field Values

MAINT_PERIOD

public static final long MAINT_PERIOD
The timeout before retransmitting a packet using network-level acknowledgements.

See Also:
Constant Field Values

GRAT_REPLY_HOLDOFF

public static final long GRAT_REPLY_HOLDOFF
The minimum time between sending gratuitous Route Replies.

See Also:
Constant Field Values

PASSIVE_ACK_TIMEOUT

public static final long PASSIVE_ACK_TIMEOUT
The timeout before retransmitting a packet using passive acknowledgements.

See Also:
Constant Field Values

TRY_PASSIVE_ACKS

public static final int TRY_PASSIVE_ACKS
The number of times to try retransmission using passive ackknowledgments.

See Also:
Constant Field Values

MAX_REQUEST_TABLE_IDS

public static final int MAX_REQUEST_TABLE_IDS
The maximum number of ID values to store in a single Route Request Table entry.

See Also:
Constant Field Values

MAX_TTL

public static final byte MAX_TTL
The maximum Time-To-Live for a DSR packet.

See Also:
Constant Field Values

MAX_SALVAGE_COUNT

public static final int MAX_SALVAGE_COUNT
The maximum number of times a packet can be salvaged.

See Also:
Constant Field Values

log

private static org.apache.log4j.Logger log
DSR logger.


routeReplyTable

private java.util.HashSet routeReplyTable
The Gratuitous Route Reply Table is a set of RouteReplyTableEntrys indicating which nodes have recently triggered gratuitous Route Replies because of automatic route shortening.


maintenanceBuffer

private java.util.Hashtable maintenanceBuffer
Maintenance Buffer. Only messages awaiting passive acknowledgement (not messages awaiting network-level acknowledgement) are stored in here. It maps MaintenanceBufferEntrys to Integers representing the Segments Left field of the Source Route option of the corresponding message.


netEntity

private NetInterface netEntity
The interface to the network layer.


localAddr

private NetAddress localAddr
The IP address of this node.


routeCache

private java.util.Hashtable routeCache
The route cache maps NetAddresses (destinations) to LinkedLists of arrays of NetAddresses (routes). Right now the route cache has no sophisticated timeout or replacement policies.


sendBuffer

private java.util.LinkedList sendBuffer
List of BufferedPackets waiting to be sent.


routeRequestTable

private java.util.Hashtable routeRequestTable
The route request table maps NetAddresses(destinations) to RouteRequestTableEntrys, which are structures containing various information used when performing Route Discovery.


nextRequestId

private short nextRequestId
The next ID number to use when sending a route request.


nextAckId

private short nextAckId
The next ID number to use when sending an acknowledgement request.


activeRequests

private java.util.HashSet activeRequests
Set of NetAddresses of destinations of currently active Route Requests.


activeAcks

private java.util.HashSet activeAcks
Set of Shorts indicating outstanding acknowledgement requests.


self

private RouteInterface.Dsr self
The proxy interface for this object.

Constructor Detail

RouteDsr

public RouteDsr(NetAddress localAddr)
Creates a new RouteDsr object.

Parameters:
localAddr - local node address
Method Detail

setNetEntity

public void setNetEntity(NetInterface netEntity)
Sets the interface to the network layer.

Parameters:
netEntity - the interface to the network layer

getProxy

public RouteInterface.Dsr getProxy()
Gets the proxy interface for this object.

Returns:
the proxy RouteInterface.Dsr interface for this object

SendRouteReply

private void SendRouteReply(RouteDsrMsg.OptionRouteRequest opt,
                            NetAddress src)
Sends a Route Reply to a node that recently sent us a Route Request.

Parameters:
opt - the Route Request option
src - the originator of the Route Request

ForwardRequest

private void ForwardRequest(RouteDsrMsg msg,
                            RouteDsrMsg.OptionRouteRequest opt,
                            byte[] optBuf,
                            NetAddress src,
                            NetAddress dst,
                            short protocol,
                            byte priority,
                            byte ttl,
                            short id,
                            short fragOffset)
Propagates a Route Request to all nodes within range.

Parameters:
msg - the message containing the Route Request
opt - the Route Request option
optBuf - the bytes of the Route Request option
src - the originator of the Route Request
dst - the destination of the Route Request (usually broadcast)
protocol - the IP protocol of the message
priority - the IP priority of the message
ttl - the IP time to live of the message
id - the IP identification of the message
fragOffset - the IP fragmentation offset of the message

HandleRequest

private void HandleRequest(RouteDsrMsg msg,
                           RouteDsrMsg.OptionRouteRequest opt,
                           byte[] optBuf,
                           NetAddress src,
                           NetAddress dst,
                           short protocol,
                           byte priority,
                           byte ttl,
                           short id,
                           short fragOffset)
Processes an incoming Route Request option. If this request has been seen recently, it is ignored. Otherwise, if this node knows a route to the desired destination, a Route Reply is sent to the originator of the request. Otherwise, the request is propagated to all nodes within range.

Parameters:
msg - the RouteDsrMsg containing the request
opt - the Route Request option
optBuf - the bytes of the Route Request option
src - the address of the originator of the Route Request
dst - the destination address of this request (usually broadcast)
protocol - the IP protocol of this Route Request (usually DSR)
priority - the IP priority of this Route Request
ttl - the IP time to live of this Route Request
id - the IP identification of this Route Request
fragOffset - the IP fragmentation offset of this Route Request

HandleReply

private void HandleReply(RouteDsrMsg msg,
                         RouteDsrMsg.OptionRouteReply reply)
Processes an incoming Route Reply. The new route is added to the Route Cache if it is useful and not already in the Route Cache.

Parameters:
msg - the RouteDsrMsg containing the Route Reply
reply - the Route Reply option

NextRecipient

private NetAddress NextRecipient(RouteDsrMsg.OptionSourceRoute sourceRoute,
                                 NetAddress dst)
Determines the intended next recipient of a packet with the given source route option and IP destination.

Parameters:
sourceRoute - the Source Route option (or null if none)
dst - the destination IP address
Returns:
the address of the next recipient of the message. If the Source Route option is invalid in some way, null can be returned.

PrevRecipient

private NetAddress PrevRecipient(RouteDsrMsg.OptionSourceRoute sourceRoute,
                                 NetAddress src)
Determines the previous recipient of a packet with the given source route option and IP source.

Parameters:
sourceRoute - the Source Route option (or null if none)
src - the source IP address
Returns:
the address of the previous recipient of this message. If the Source Route option is invalid in some way, null can be returned.

ForwardPacket

private void ForwardPacket(RouteDsrMsg msg,
                           RouteDsrMsg.OptionSourceRoute opt,
                           byte[] optBuf,
                           NetAddress src,
                           NetAddress dest,
                           short protocol,
                           byte priority,
                           byte ttl,
                           short id,
                           short fragOffset)
Forwards a DSR packet containing a Source Route option to the next intended recipient. An Acknowledgement Request option is added to the headers, and the packet is retransmitted if no acknowledgement is received before the allotted timeout elapses.

Parameters:
msg - the RouteDsrMsg to be forwarded
opt - the Source Route option
optBuf - the bytes of the Source Route option
src - the address of the originator of this packet
dest - the address of the ultimate destination of this packet
protocol - the IP protocol of this packet (usually DSR)
priority - the IP priority of this packet
ttl - the IP time to live of this packet
id - the IP identification of this packet
fragOffset - the IP fragmentation offset of this packet

PerformRouteShortening

private void PerformRouteShortening(RouteDsrMsg.OptionSourceRoute sourceRoute,
                                    NetAddress src,
                                    NetAddress dest)
Checks to see if we know a shorter route from src to dest than the one given in sourceRoute. If this is the case, we send a gratuitous Route Reply to src letting him know of the shorter route.

Parameters:
sourceRoute - the route that can potentially be shortened
src - the originator of the Source Route
dest - the destination of the Source Route

SendGratuitousRouteReply

private void SendGratuitousRouteReply(NetAddress src,
                                      RouteDsrMsg.OptionSourceRoute sourceRoute,
                                      NetAddress dest,
                                      int routeLength)
Sends a gratuitous Route Reply to src. That is, src hasn't sent out a Route Request, but we happen to know a shorter route than the one he's using, so we're letting him know.

Parameters:
src - the originator of the shortened Source Route
sourceRoute - the Source Route we know how to shorten
dest - the destination of the shortened Source Route
routeLength - the length of the new (shortened) Source Route

HandleAckRequest

private void HandleAckRequest(RouteDsrMsg msg,
                              RouteDsrMsg.OptionAckRequest opt,
                              NetAddress src,
                              NetAddress dst,
                              RouteDsrMsg.OptionSourceRoute sourceRoute)
Processes an incoming Acknowledgement Request option. If the packet containing the Acknowledgement Request is destined for this node, then a packet is returned containing an Acknowledgement option. No retransmission of the acknowledgement is performed.

Parameters:
msg - the RouteDsrMsg containing the Acknowledgement Request
opt - the Acknowledgement Request option
src - the originator of the Acknowledgement Request
dst - the destination of the Acknowledgement Request
sourceRoute - the Source Route option that came in the same message as the Acknowledgement Request. This parameter can be null if there was no Source Route option.

HandleAck

private void HandleAck(RouteDsrMsg.OptionAck opt,
                       NetAddress dest)
Processes an incoming Acknowledgement option. If this Acknowledgement was intended for this node, then the packet containing the corresponding Acknowledgement Request will not be retransmitted.

Parameters:
opt - the Acknowledgement option
dest - the destination of the Acknowledgement

HandleError

private void HandleError(RouteDsrMsg.OptionRouteError opt)
Processes an incoming Route Error option. If this error was intended for this node and indicates that a particular node is unreachable, then the Route Cache will be updated to no longer use the broken links, and new Route Discoveries may be initiated as a result. NODE_UNREACHABLE is the only kind of error that is currently handled.

Parameters:
opt - the Route Error option

ProcessOptions

private void ProcessOptions(RouteDsrMsg msg,
                            NetAddress src,
                            NetAddress dst,
                            short protocol,
                            byte priority,
                            byte ttl,
                            short id,
                            short fragOffset)
Handles each of the options in a given DSR header.

Parameters:
msg - the message containing the DSR header
src - the IP source address of the message
dst - the IP destination address of the message
protocol - the IP protocol of the message
priority - the IP priority of the message
ttl - the IP time to live of the message
id - the IP identification of the message
fragOffset - the IP fragmentation offset of the message

DiscoverRoute

public void DiscoverRoute(NetAddress dest,
                          short requestId)
Initiates a Route Discovery for the given address. Messages containing Route Request headers are broadcast to all nodes within range.

Specified by:
DiscoverRoute in interface RouteInterface.Dsr
Parameters:
dest - the address to which we desire a route
requestId - the ID number of the request to be performed. DiscoverRoute should always be invoked with a unique value in this parameter.

InitRouteCache

private void InitRouteCache()
Initializes the Route Cache.


InsertRouteCache

public void InsertRouteCache(NetAddress dest,
                             NetAddress[] route)
Inserts a new route into the Route Cache. All routes stored in the Route Cache are assumed to be routes from this node to another node.

Parameters:
dest - the destination of the route to be added
route - the sequence of nodes from here to dest. Neither the IP address of this node nor of the dest node should be included in the route array.

RemoveCachedLink

private void RemoveCachedLink(NetAddress addr1,
                              NetAddress addr2)
Removes every path in the cache that uses a direct link between addr1 and addr2.

Parameters:
addr1 - the first address in the link
addr2 - the second address in the link

GetCachedRoute

private NetAddress[] GetCachedRoute(NetAddress dest)
Retrieves a route from the Route Cache from here to the given node.

Parameters:
dest - the address of the node to find a route to
Returns:
An array of addresses denoting a route from here to dest. Neither the address of this node nor of dest is included in this array. If the Route Cache contains no route to dest, null is returned. If the Route Cache contains more than one route, the shortest is returned, with ties broken arbitrarily.

InitBuffer

private void InitBuffer()
Initializes the Send Buffer.


InsertBuffer

public void InsertBuffer(NetMessage.Ip msg)
Inserts a new packet into the Send Buffer, annotating it with the current system time.

Specified by:
InsertBuffer in interface RouteInterface.Dsr
Parameters:
msg - the message to insert into the buffer

DeleteBuffer

public void DeleteBuffer(RouteInterface.Dsr.BufferedPacket msg)
Removes the given BufferedPacket from the Send Buffer.

Specified by:
DeleteBuffer in interface RouteInterface.Dsr
Parameters:
msg - the packet to remove from the Send Buffer

CheckBuffer

private void CheckBuffer(NetAddress dest)
Searches the Send Buffer for any packets intended for the given destination and sends any that are found. This is typically called immediately after finding a route to dest.

Parameters:
dest - the destination we now have a route to

InitRouteReplyTable

private void InitRouteReplyTable()
Initializes the Gratuitous Route Reply Table.


RouteReplyEntryExists

private boolean RouteReplyEntryExists(NetAddress originator,
                                      NetAddress lastHop)
Determines whether there is an entry in the Gratuitous Route Reply Table corresponding to the given addresses.

Parameters:
originator - the originator of the shortened Source Route
lastHop - the most recent hop address of the shortened Source Route
Returns:
whether the entry exists in the table.

AddRouteReplyEntry

public void AddRouteReplyEntry(NetAddress originator,
                               NetAddress lastHop)
Adds a new entry to the Gratuitous Route Reply Table.

Specified by:
AddRouteReplyEntry in interface RouteInterface.Dsr
Parameters:
originator - the originator of the shortened Source Route
lastHop - the most recent hop address of the shortened Source Route

DeleteRouteReplyEntry

public void DeleteRouteReplyEntry(NetAddress originator,
                                  NetAddress lastHop)
Deletes an entry from the Gratuitous Route Reply Table.

Specified by:
DeleteRouteReplyEntry in interface RouteInterface.Dsr
Parameters:
originator - the originator of the shortened Source Route
lastHop - the most recent hop address of the shortened Source Route

InitMaintenanceBuffer

private void InitMaintenanceBuffer()
Initializes the Maintenance Buffer.


InitRequestTable

private void InitRequestTable()
Initializes the Route Request Table.


AddRequestId

private void AddRequestId(NetAddress src,
                          short id)
Enters a new Route Request ID number into the Route Request Table.

Parameters:
src - the address of the originator of the Route Request
id - the ID number of the Route Request

SeenRequestLately

private boolean SeenRequestLately(NetAddress src,
                                  short id)
Checks if we have recently seen the Route Request with the given id coming from the given source. "Recently" here means within the last MAX_REQUEST_TABLE_IDS Route Requests coming from src.

Parameters:
src - the source address of the Route Request
id - the ID number of the Route Request
Returns:
whether the given request has been seen recently.

SendRouteError

private void SendRouteError(RouteDsrMsg msg,
                            NetAddress src,
                            NetAddress dest)
Sends a DSR message with a Route Error option to src indicating that the next hop in the intended route cannot be reached from this node.

Parameters:
msg - the RouteDsrMsg containing the Source Route option that contains the broken link
src - the originator of msg
dest - the destination of msg

GetSourceRoute

private RouteDsrMsg.OptionSourceRoute GetSourceRoute(RouteDsrMsg msg)
Retrieves the Source Route option from the given DSR message, or null if none exists.

Parameters:
msg - the DSR message
Returns:
the Source Route option from msg, or null if none exists.

Transmit

private void Transmit(NetMessage.Ip msg)
Sends the given message and looks for acknowledgement. If no acknowledgement is forthcoming the message is retransmitted a limited number of times.

Parameters:
msg - the message to send. The payload of this IP packet should be a RouteDsrMsg, and it should not already contain an Acknowledgement Request.

TransmitWithPassiveAck

public void TransmitWithPassiveAck(NetMessage.Ip msg,
                                   int numRetransmits)
Sends the given message and waits for a passive acknowledgement. If no acknowledgement is heard, the message will be retransmitted up to TRY_PASSIVE_ACKS times.

Specified by:
TransmitWithPassiveAck in interface RouteInterface.Dsr
Parameters:
msg - the message to be sent
numRetransmits - the number of times this message has already been retransmitted. Callers should usually pass in zero for this.

TransmitWithNetworkAck

public void TransmitWithNetworkAck(NetMessage.Ip msg,
                                   java.lang.Short ackId,
                                   long timeout,
                                   int numRetransmits)
Sends the given message. The message should be a DSR packet containing an acknowledgement request with the given id. If no acknowledgement is received within the given timeout, the packet will be retransmitted up to MAX_MAINT_REXMT times.

Specified by:
TransmitWithNetworkAck in interface RouteInterface.Dsr
Parameters:
msg - the message to be sent
ackId - the ID number of the Acknowledgement Request
timeout - the number of clock ticks to wait before retransmitting the message
numRetransmits - the number of times this packet has already been transmitted. Callers should normally pass in zero for this.

CheckForPassiveAck

private void CheckForPassiveAck(RouteDsrMsg msg,
                                NetAddress src,
                                NetAddress dest,
                                short protocol,
                                short id,
                                short fragOffset)
Checks the given message to see if it matches any of the messages in the Maintenance Buffer for which we are currently awaiting passive passive acknowledgements. If this message matches a message in the Maintenance Buffer, that message will be removed from the buffer and will not be retransmitted.

Parameters:
msg - the message that has been overheard
src - the IP source of the message
dest - the IP destination of the message
protocol - the IP protocol of the message
id - the IP id number of the message
fragOffset - the IP fragmentation offset of the message

SendWithRoute

private void SendWithRoute(NetMessage.Ip msg,
                           NetAddress[] route)
Sends the given message along the given route. An Acknowledgement Request option is added to the message, and it is retransmitted if no acknowledgement is received before a timeout occurs.

Parameters:
msg - the RouteDsrMsg to be sent
route - the sequence of nodes to route the message along

peek

public void peek(NetMessage msg,
                 MacAddress lastHop)
If the given message uses the DSR protocol, the DSR header is examined to see if any actions need to be performed on this packet (such as forwarding it).

Specified by:
peek in interface RouteInterface
Parameters:
msg - the message to examine
lastHop - the MAC address of the node that sent this message

send

public void send(NetMessage msg)
Sends the given message. This method can be called because this node is originating a packet (in which case a DSR header is added to the packet and it is sent) or because this node is forwarding a packet (in which case this method actually does nothing, with all DSR header option processing being performed by peek.

Specified by:
send in interface RouteInterface
Parameters:
msg - the message to be sent

receive

public void receive(Message msg,
                    NetAddress src,
                    MacAddress lastHop,
                    byte macId,
                    NetAddress dst,
                    byte priority,
                    byte ttl)
Receives a message from the network. This method merely strips off the DSR header and hands the message off to the transport layer.

Specified by:
receive in interface NetInterface.NetHandler
Parameters:
msg - the message being received
src - the address of the originator of the message
lastHop - the MAC address of the most recent node to forward the message
macId - the ID of the MAC interface
dst - the address of the destination of the message (which should be the IP address of this node)
priority - the IP priority of the message
ttl - the IP time to live of the message