jist.swans.mac
Class Mac802_11

java.lang.Object
  extended by jist.swans.mac.Mac802_11
All Implemented Interfaces:
JistAPI.Proxiable, JistAPI.Timeless, MacInterface, MacInterface.Mac802_11

public class Mac802_11
extends java.lang.Object
implements MacInterface.Mac802_11

Implementation of IEEE 802_11b. Please refer to the standards document. For consistency, many of the variable names, constants and equations are taken directly from the specification.

Since:
SWANS1.0
Version:
$Id: Mac802_11.java,v 1.62 2005/02/10 16:52:28 barr Exp $
Author:
Rimon Barr <barr+jist@cs.cornell.edu>

Nested Class Summary
private static class Mac802_11.SeqEntry
          Local class to used manage sequence number records.
 
Nested classes/interfaces inherited from interface jist.swans.mac.MacInterface
MacInterface.Mac802_11
 
Field Summary
protected  int bandwidth
          link bandwidth (units: bytes/second).
protected  long bo
          backoff time remaining.
protected  long boStart
          backoff start time.
protected  short cw
          current contention window size.
static short CW_MAX
          Maximum collision window (for backoff).
static short CW_MIN
          Minimum collision window (for backoff).
static long DIFS
          Distributed inter frame space.
static boolean DSSS
          Physical specification constant: 802_11b-1999 Supplement 2_4GHz Direct Sequence.
static long EIFS
          Extended inter frame space.
static boolean FHSS
          Physical specification constant: 802_11b-1999 2_4GHz Frequency Hopping.
protected  MacAddress localAddr
          mac address of this interface.
protected  byte longRetry
          long retry counter.
static byte MAC_MODE_DIFS
          mac mode: waiting for difs or eifs timer.
static byte MAC_MODE_SBO
          mac mode: waiting for backoff.
static byte MAC_MODE_SIDLE
          mac mode: idle.
static byte MAC_MODE_SNAV
          mac mode: waiting for virtual carrier sense.
static byte MAC_MODE_SNAV_RTS
          mac mode: waiting for virtual carrier sense to RTS.
static byte MAC_MODE_SWFACK
          mac mode: waiting for ACK packet.
static byte MAC_MODE_SWFCTS
          mac mode: waiting for CTS packet.
static byte MAC_MODE_SWFDATA
          mac mode: waiting for DATA packet.
static byte MAC_MODE_XACK
          mac mode: transmitting ACK packet.
static byte MAC_MODE_XBROADCAST
          mac mode: transmitting broadcast DATA packet.
static byte MAC_MODE_XCTS
          mac mode: transmitting CTS packet.
static byte MAC_MODE_XRTS
          mac mode: transmitting RTS packet.
static byte MAC_MODE_XUNICAST
          mac mode: transmitting unicast DATA packet.
protected  byte mode
          current mac mode.
protected  long nav
          virtual carrier sense; next time when network available.
protected  boolean needEifs
          whether last reception had an error.
protected  NetInterface netEntity
          Network upcall entity interface.
protected  byte netId
          network interface number.
protected  Message packet
          packet currently being transmitted.
protected  MacAddress packetNextHop
          next hop of packet current being transmitted.
static long PIFS
          Point coordination inter frame space.
static long PLCP_HEADER
          Length of PLCP Header at 1Mb/s.
static long PREAMBLE
          Length of PHY preamble.
protected  boolean promisc
          whether mac is in promiscuous mode.
static long PROPAGATION
          Air propagation delay.
protected  RadioInterface radioEntity
          Radio downcall entity reference.
protected  byte radioMode
          radio mode used for carrier sense.
static byte RETRY_LIMIT_LONG
          Retransmissions attempted for long packets (those with RTS).
static byte RETRY_LIMIT_SHORT
          Retransmissions attempted for short packets (those without RTS).
static long RX_TX_TURNAROUND
          Receive-Transmit turnaround time.
protected  MacInterface.Mac802_11 self
          Self-referencing mac entity reference.
protected  short seq
          sequence number counter.
static short SEQ_CACHE_SIZE
          Sequence number cache size.
static short SEQ_INVALID
          Invalid sequence number.
protected  Mac802_11.SeqEntry seqCache
          received sequence number cache list.
protected  byte seqCacheSize
          size of received sequence number cache list.
protected  byte shortRetry
          short retry counter.
static long SIFS
          Short interframe space.
static long SLOT_TIME
          Minimum time to sense medium.
static long SYNCHRONIZATION
          PHY synchronization time.
static int THRESHOLD_FRAGMENT
          Threshold packet size for fragmentation.
static int THRESHOLD_RTS
          Threshold packet size to activate RTS.
protected  byte timerId
          timer identifier.
static long TX_DIFS
          Transmit start DIFS.
static long TX_SIFS
          Transmit start SIFS.
 
Constructor Summary
Mac802_11(MacAddress addr, RadioInfo radioInfo)
          Instantiate new 802_11b entity.
 
Method Summary
private  void backoff()
          Perform backoff.
private  void cancelTimer()
          Cancel timer event, by incrementing the timer identifer.
 void cfDone(boolean backoff, boolean delPacket)
          Collision free send sequence complete.
private  void clearBackoff()
          Reset backoff counter to zero.
private  void decCW()
          Decrease Collision Windows.
private  void doDifs()
           
static java.lang.String getModeString(byte mode)
           
 MacInterface.Mac802_11 getProxy()
          Return proxy entity of this mac.
private  short getSeqEntry(MacAddress from)
          Return latest seen sequence number from given address.
private  boolean hasBackoff()
          Return whether there is a backoff.
 boolean hasPacket()
          Return whether mac currently has a packet to send.
private  void idle()
           
private  void incCW()
          Increase Collision Window.
private  short incSeq()
          Increment local sequence counter.
 boolean isAwaitingResponse()
          Return whether the mac is currently waiting for a response.
private  boolean isBroadcast()
          Return whether current packet is to be broadcast.
private  boolean isCarrierIdle()
          Determine whether channel is idle according to both physical and virtual carrier sense.
private  boolean isRadioIdle()
           
 boolean isTransmitting()
          Return whether the mac is currently transmitting.
private  void pauseBackoff()
          Pause the current backoff (invoked when the channel becomes busy).
 void peek(Message msg)
          Radio has locked onto a packet signal; mac may have a peek.
private  void radioBusy()
           
private  void radioIdle()
           
 void receive(Message msg)
          Radio has received a packet for mac to process.
private  void receiveAck(MacMessage.Ack ack)
           
private  void receiveCts(MacMessage.Cts cts)
           
private  void receiveData(MacMessage.Data msg)
           
private  void receiveForeign(MacMessage msg)
           
private  void receivePacket(MacMessage msg)
           
private  void receiveRts(MacMessage.Rts rts)
           
private  void resetNav()
          Clear the virtual carrier sense (network allocation vector).
private  void retry()
           
private  void retryNo()
           
private  void retryYes()
           
 void send(Message msg, MacAddress nextHop)
          Network layer would like to send the following packet.
private  void sendAck(MacMessage.Data data)
           
private  void sendCts(MacMessage.Rts rts)
           
private  void sendData(boolean afterCts)
           
private  void sendDataBroadcast()
           
private  void sendDataUnicast(boolean afterCts)
           
private  void sendPacket()
           
private  void sendRts()
           
private  void setBackoff()
          Set new random backoff, if current backoff timer has elapsed.
private  void setMode(byte mode)
          Set the current mac mode.
 void setNetEntity(NetInterface net, byte netid)
          Hook up with the network entity.
 void setPromiscuous(boolean promisc)
          Set promiscuous mode (whether to pass all packets through).
 void setRadioEntity(RadioInterface radio)
          Hook up with the radio entity.
 void setRadioMode(byte mode)
          Update mac regarding new mode of its radio.
private  boolean shouldFragment()
          Return whether current packet requires fragmentation.
private  boolean shouldRTS()
          Return whether current packet large enough to require RTS.
 void startTimer(long delay, byte mode)
          Initiate a timer event.
 void timeout(int timerId)
          Process mac timeout.
private  long transmitTime(Message msg)
          Compute packet transmission time at current bandwidth.
private  void updateSeqEntry(MacAddress from, short seq)
          Update latest sequence number entry for given address.
private  boolean waitingNav()
          Return whether the virtual carrier sense (network allocation vector) indicates that the channel is reserved.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DSSS

public static final boolean DSSS
Physical specification constant: 802_11b-1999 Supplement 2_4GHz Direct Sequence.

See Also:
Constant Field Values

FHSS

public static final boolean FHSS
Physical specification constant: 802_11b-1999 2_4GHz Frequency Hopping.

See Also:
Constant Field Values

PREAMBLE

public static final long PREAMBLE
Length of PHY preamble.

See Also:
Constant Field Values

PLCP_HEADER

public static final long PLCP_HEADER
Length of PLCP Header at 1Mb/s.

See Also:
Constant Field Values

SYNCHRONIZATION

public static final long SYNCHRONIZATION
PHY synchronization time.

See Also:
Constant Field Values

RX_TX_TURNAROUND

public static final long RX_TX_TURNAROUND
Receive-Transmit turnaround time.

See Also:
Constant Field Values

PROPAGATION

public static final long PROPAGATION
Air propagation delay.

See Also:
Constant Field Values

SLOT_TIME

public static final long SLOT_TIME
Minimum time to sense medium.


SIFS

public static final long SIFS
Short interframe space. Minimum wait time between two frames in the same communication session.


PIFS

public static final long PIFS
Point coordination inter frame space. Wait used by the access point (point coordinator) to gain access to the medium before any of the stations.


DIFS

public static final long DIFS
Distributed inter frame space. Wait used by stations to gain access to the medium.


TX_SIFS

public static final long TX_SIFS
Transmit start SIFS.


TX_DIFS

public static final long TX_DIFS
Transmit start DIFS.


EIFS

public static final long EIFS
Extended inter frame space. Wait used by stations to gain access to the medium after an error.


THRESHOLD_RTS

public static final int THRESHOLD_RTS
Threshold packet size to activate RTS. Default=3000. Broadcast packets never use RTS. Set to zero to always use RTS.

See Also:
Constant Field Values

THRESHOLD_FRAGMENT

public static final int THRESHOLD_FRAGMENT
Threshold packet size for fragmentation. Default=2346. Broadcast packets are not fragmented.

See Also:
Constant Field Values

RETRY_LIMIT_SHORT

public static final byte RETRY_LIMIT_SHORT
Retransmissions attempted for short packets (those without RTS).

See Also:
Constant Field Values

RETRY_LIMIT_LONG

public static final byte RETRY_LIMIT_LONG
Retransmissions attempted for long packets (those with RTS).

See Also:
Constant Field Values

CW_MIN

public static final short CW_MIN
Minimum collision window (for backoff).


CW_MAX

public static final short CW_MAX
Maximum collision window (for backoff).

See Also:
Constant Field Values

SEQ_INVALID

public static final short SEQ_INVALID
Invalid sequence number.

See Also:
Constant Field Values

SEQ_CACHE_SIZE

public static final short SEQ_CACHE_SIZE
Sequence number cache size.

See Also:
Constant Field Values

MAC_MODE_SIDLE

public static final byte MAC_MODE_SIDLE
mac mode: idle.

See Also:
Constant Field Values

MAC_MODE_DIFS

public static final byte MAC_MODE_DIFS
mac mode: waiting for difs or eifs timer.

See Also:
Constant Field Values

MAC_MODE_SBO

public static final byte MAC_MODE_SBO
mac mode: waiting for backoff.

See Also:
Constant Field Values

MAC_MODE_SNAV

public static final byte MAC_MODE_SNAV
mac mode: waiting for virtual carrier sense.

See Also:
Constant Field Values

MAC_MODE_SNAV_RTS

public static final byte MAC_MODE_SNAV_RTS
mac mode: waiting for virtual carrier sense to RTS.

See Also:
Constant Field Values

MAC_MODE_SWFCTS

public static final byte MAC_MODE_SWFCTS
mac mode: waiting for CTS packet.

See Also:
Constant Field Values

MAC_MODE_SWFDATA

public static final byte MAC_MODE_SWFDATA
mac mode: waiting for DATA packet.

See Also:
Constant Field Values

MAC_MODE_SWFACK

public static final byte MAC_MODE_SWFACK
mac mode: waiting for ACK packet.

See Also:
Constant Field Values

MAC_MODE_XRTS

public static final byte MAC_MODE_XRTS
mac mode: transmitting RTS packet.

See Also:
Constant Field Values

MAC_MODE_XCTS

public static final byte MAC_MODE_XCTS
mac mode: transmitting CTS packet.

See Also:
Constant Field Values

MAC_MODE_XUNICAST

public static final byte MAC_MODE_XUNICAST
mac mode: transmitting unicast DATA packet.

See Also:
Constant Field Values

MAC_MODE_XBROADCAST

public static final byte MAC_MODE_XBROADCAST
mac mode: transmitting broadcast DATA packet.

See Also:
Constant Field Values

MAC_MODE_XACK

public static final byte MAC_MODE_XACK
mac mode: transmitting ACK packet.

See Also:
Constant Field Values

self

protected final MacInterface.Mac802_11 self
Self-referencing mac entity reference.


radioEntity

protected RadioInterface radioEntity
Radio downcall entity reference.


netEntity

protected NetInterface netEntity
Network upcall entity interface.


netId

protected byte netId
network interface number.


bandwidth

protected final int bandwidth
link bandwidth (units: bytes/second).


localAddr

protected MacAddress localAddr
mac address of this interface.


promisc

protected boolean promisc
whether mac is in promiscuous mode.


mode

protected byte mode
current mac mode.


radioMode

protected byte radioMode
radio mode used for carrier sense.


needEifs

protected boolean needEifs
whether last reception had an error.


timerId

protected byte timerId
timer identifier.


bo

protected long bo
backoff time remaining.


boStart

protected long boStart
backoff start time.


cw

protected short cw
current contention window size.


nav

protected long nav
virtual carrier sense; next time when network available.


seq

protected short seq
sequence number counter.


seqCache

protected Mac802_11.SeqEntry seqCache
received sequence number cache list.


seqCacheSize

protected byte seqCacheSize
size of received sequence number cache list.


shortRetry

protected byte shortRetry
short retry counter.


longRetry

protected byte longRetry
long retry counter.


packet

protected Message packet
packet currently being transmitted.


packetNextHop

protected MacAddress packetNextHop
next hop of packet current being transmitted.

Constructor Detail

Mac802_11

public Mac802_11(MacAddress addr,
                 RadioInfo radioInfo)
Instantiate new 802_11b entity.

Parameters:
addr - local mac address
radioInfo - radio properties
Method Detail

getModeString

public static java.lang.String getModeString(byte mode)

getProxy

public MacInterface.Mac802_11 getProxy()
Return proxy entity of this mac.

Returns:
self-referencing proxy entity.

setRadioEntity

public void setRadioEntity(RadioInterface radio)
Hook up with the radio entity.

Parameters:
radio - radio entity

setNetEntity

public void setNetEntity(NetInterface net,
                         byte netid)
Hook up with the network entity.

Parameters:
net - network entity
netid - network interface number

setPromiscuous

public void setPromiscuous(boolean promisc)
Set promiscuous mode (whether to pass all packets through).

Parameters:
promisc - promiscuous flag

setMode

private void setMode(byte mode)
Set the current mac mode.

Parameters:
mode - new mac mode

isAwaitingResponse

public boolean isAwaitingResponse()
Return whether the mac is currently waiting for a response.

Returns:
whether mac waiting for response

isTransmitting

public boolean isTransmitting()
Return whether the mac is currently transmitting.

Returns:
whether mac is currently transmitting

hasPacket

public boolean hasPacket()
Return whether mac currently has a packet to send.

Returns:
whether mac has packet to send.

isBroadcast

private boolean isBroadcast()
Return whether current packet is to be broadcast.

Returns:
whether current packet is to be broadcast.

shouldRTS

private boolean shouldRTS()
Return whether current packet large enough to require RTS.

Returns:
does current packet require RTS.

shouldFragment

private boolean shouldFragment()
Return whether current packet requires fragmentation.

Returns:
does current packet require fragmentation.

transmitTime

private long transmitTime(Message msg)
Compute packet transmission time at current bandwidth.

Parameters:
msg - packet to transmit
Returns:
time to transmit given packet at current bandwidth

hasBackoff

private boolean hasBackoff()
Return whether there is a backoff.

Returns:
whether backoff non-zero.

clearBackoff

private void clearBackoff()
Reset backoff counter to zero.


setBackoff

private void setBackoff()
Set new random backoff, if current backoff timer has elapsed.


pauseBackoff

private void pauseBackoff()
Pause the current backoff (invoked when the channel becomes busy).


backoff

private void backoff()
Perform backoff.


incCW

private void incCW()
Increase Collision Window.


decCW

private void decCW()
Decrease Collision Windows.


waitingNav

private boolean waitingNav()
Return whether the virtual carrier sense (network allocation vector) indicates that the channel is reserved.

Returns:
virtual carrier sense

resetNav

private void resetNav()
Clear the virtual carrier sense (network allocation vector).


isCarrierIdle

private boolean isCarrierIdle()
Determine whether channel is idle according to both physical and virtual carrier sense.

Returns:
physical and virtual carrier sense

incSeq

private short incSeq()
Increment local sequence counter.

Returns:
new sequence number.

getSeqEntry

private short getSeqEntry(MacAddress from)
Return latest seen sequence number from given address.

Parameters:
from - source address
Returns:
latest sequence number from given address

updateSeqEntry

private void updateSeqEntry(MacAddress from,
                            short seq)
Update latest sequence number entry for given address.

Parameters:
from - source address
seq - latest sequence number

send

public void send(Message msg,
                 MacAddress nextHop)
Description copied from interface: MacInterface
Network layer would like to send the following packet. Should be called only after Mac has notified that it is wants a packet.

Specified by:
send in interface MacInterface
Parameters:
msg - packet to send
nextHop - destination mac

doDifs

private void doDifs()

cfDone

public void cfDone(boolean backoff,
                   boolean delPacket)
Description copied from interface: MacInterface.Mac802_11
Collision free send sequence complete.

Specified by:
cfDone in interface MacInterface.Mac802_11
Parameters:
backoff - is a backoff required
delPacket - is processing for this packet complete

sendPacket

private void sendPacket()

sendRts

private void sendRts()

sendCts

private void sendCts(MacMessage.Rts rts)

sendData

private void sendData(boolean afterCts)

sendDataBroadcast

private void sendDataBroadcast()

sendDataUnicast

private void sendDataUnicast(boolean afterCts)

sendAck

private void sendAck(MacMessage.Data data)

retry

private void retry()

retryYes

private void retryYes()

retryNo

private void retryNo()

peek

public void peek(Message msg)
Description copied from interface: MacInterface
Radio has locked onto a packet signal; mac may have a peek.

Specified by:
peek in interface MacInterface
Parameters:
msg - packet currently in flight

receive

public void receive(Message msg)
Description copied from interface: MacInterface
Radio has received a packet for mac to process.

Specified by:
receive in interface MacInterface
Parameters:
msg - packet received

receivePacket

private void receivePacket(MacMessage msg)

receiveRts

private void receiveRts(MacMessage.Rts rts)

receiveCts

private void receiveCts(MacMessage.Cts cts)

receiveAck

private void receiveAck(MacMessage.Ack ack)

receiveData

private void receiveData(MacMessage.Data msg)

receiveForeign

private void receiveForeign(MacMessage msg)

setRadioMode

public void setRadioMode(byte mode)
Description copied from interface: MacInterface
Update mac regarding new mode of its radio.

Specified by:
setRadioMode in interface MacInterface
Parameters:
mode - new radio mode

isRadioIdle

private boolean isRadioIdle()

radioBusy

private void radioBusy()

radioIdle

private void radioIdle()

startTimer

public void startTimer(long delay,
                       byte mode)
Description copied from interface: MacInterface.Mac802_11
Initiate a timer event. Note that only one timer event can be active at a given time.

Specified by:
startTimer in interface MacInterface.Mac802_11
Parameters:
delay - timer duration
mode - new mode

cancelTimer

private void cancelTimer()
Cancel timer event, by incrementing the timer identifer.


idle

private void idle()

timeout

public void timeout(int timerId)
Description copied from interface: MacInterface.Mac802_11
Process mac timeout.

Specified by:
timeout in interface MacInterface.Mac802_11
Parameters:
timerId - timer identifier