Changes between Version 22 and Version 23 of CSMAMAC


Ignore:
Timestamp:
Feb 8, 2008, 12:47:43 AM (16 years ago)
Author:
chunter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CSMAMAC

    v22 v23  
    263263=== Packet Type ===
    264264
     265For this MAC algorithm, only two types of packets can be loaded into the [http://warp.rice.edu/WARP_API/struct_macframe.html#o0 Macframe] and understood by the receiver: DATA or ACK. The data packet flag tells the receiving node that a payload is present in this packet and must be delivered via Ethernet to some computer. If it is an ACK, the node must have been in a timeout waiting on the acknowledgment. It should clear the timeout and return to the idle state.
     266
    265267----
    266268
    267269=== Clear TIMEOUT ===
    268270
     271To halt and clear the timeout (and hence keep the timer expiration states from executing), the following function is called:
     272
     273{{{
     274#!c
     275warpmac_clearTimer(TIMEOUT);
     276}}}
     277
    269278----
    270279
    271280=== Deliver Packet to Sink ===
    272281
     282For the reference design, the sink is the Ethernet MAC. The function
     283
     284{{{
     285#!c
     286warpmac_sendEthernet(-);
     287}}}
     288
     289pushes the received packet over Ethernet.
     290
    273291----
    274292
    275293=== Timer Expired ===
    276294
     295This state begins the timer expiration states.
     296
    277297----
    278298
    279299=== Timer Type ===
    280300
     301In this system, there are two types of timers: timeouts and backoffs. A timeout timer expiring means that no acknowledgment was received in time, so the system should enter a backoff period before attempting to retransmit the packet. If a backoff timer expires, the channel is known to be idle for a DIFS period so transmission via the OFDM PHY can be initiated.
     302
     303----
     304
     305=== Maximum Resends ===
     306
     307To keep the system from hanging forever trying to send the same packet, a maximum number of retransmissions is specified in the main function with
     308
     309{{{
     310#!c
     311warpmac_setMaxResend(-);
     312}}}
     313
     314This switch state returns a boolean output: Either the maximum number of retransmissions have occurred, or they have not.
     315----
     316
     317=== Drop Packet ===
     318
     319If the maximum number of retransmissions have occurred, the packet is dropped.
     320
     321----
     322
     323=== Increment Resend Counter ===
     324
     325The internal counter keeping track of the number of retransmissions is incremented. The function used is
     326
     327
     328= Carrier-Sense Medium Access Reference Design (CSMAMAC) =
     329
     330The CSMAMAC is serves as the user-level MAC layer in [wiki:OFDMReferenceDesign reference design]. The basic algorithm is simple:
     331
     332 * Do I have a packet to send?
     333       * If the medium is idle, send it, enter a timeout, and wait for an acknowledgment from the destination
     334       * If the medium is busy, enter a backoff period and wait for the medium to become idle
     335 * Did I receive a data packet?
     336       * If the packet pass checksum and is addressed to me, send an acknowledgment
     337 * Did no know acknowledgment happen during a timeout period?
     338       * If the maximum number of retransmits has not occurred, enter a backoff and try retransmitting
     339       * If the maximum number of retransmits has occurred, drop the packet
     340 * Did I wait through a backoff period?
     341       * If the medium is busy, retransmit, increment the total number of resends, enter a timeout, and wait for an acknowledgment from the destination
     342       * If the medium is busy, enter a backoff period and wait for the medium to become idle
     343
     344This simple algorithm encompasses much of the behavior in commercial 802.11 MAC/PHY chipsets. This algorithm lends itself nicely to a state diagram, which in turn, translates into C-code that can be executed in the PowerPC of the FPGA on WARP. In the following section, we track the "Life of a Packet" as it might journey through these states.
     345
     346
     347
     348
     349== Life of a Packet ==
     350
     351Below is the state-machine representation of the above algorithm. Each state can be "clicked" and is described in detail in the accompanying link. The up-to-date code can be found here: [source:/ResearchApps/MAC/CSMAMAC/csmaMac.c@L csmaMac.c]. The API documentation for the code can be found here: [http://warp.rice.edu/WARP_API/csma_mac_8c.html CSMAMAC API]
     352
     353{{{
     354#!html
     355<map name="GraffleExport">
     356        <area shape=poly coords="106,224,154,250,106,276,59,250,106,224" href="#MediumState">
     357        <area shape=poly coords="681,414,728,440,681,466,633,440,681,414" href="#MaximumResends">
     358        <area shape=poly coords="681,318,728,344,681,370,634,344,681,318" href="#MediumState">
     359        <area shape=rect coords="690,508,784,545" href="#DropPacket">
     360        <area shape=rect coords="577,592,671,630" href="#IncrementResendCounter">
     361        <area shape=rect coords="577,508,671,546" href="#TransmitPacketviaPHY">
     362        <area shape=rect coords="319,508,414,545" href="#TransmitPacketviaPHY">
     363        <area shape=rect coords="3,326,97,364" href="#TransmitPacketviaPHY">
     364        <area shape=rect coords="691,130,785,168" href="#TimerExpired">
     365        <area shape=rect coords="375,131,470,168" href="#ReceivedPacketviaPHY">
     366        <area shape=rect coords="60,130,155,168" href="#AcceptedPacketfromSource">
     367        <area shape=rect coords="320,592,414,630" href="#DeliverPackettoSink">
     368        <area shape=rect coords="747,419,842,457" href="#SetBACKOFFTimer">
     369        <area shape=rect coords="577,677,671,715" href="#SetTIMEOUTTimer">
     370        <area shape=rect coords="116,326,210,364" href="#SetBACKOFFTimer">
     371        <area shape=poly coords="738,225,785,250,738,276,691,250,738,225" href="#TimerType">
     372        <area shape=rect coords="432,508,527,546" href="#ClearTIMEOUT">
     373        <area shape=poly coords="423,413,470,439,423,465,376,439,423,413" href="#PacketType">
     374        <area shape=rect coords="3,412,97,450" href="#SetTIMEOUTTimer">
     375        <area shape=poly coords="423,319,470,345,423,371,376,345,423,319" href="$DestinationAddress">
     376        <area shape=poly coords="423,225,470,250,423,276,376,250,423,225" href="#Checksum">
     377        <area shape=poly coords="393,45,453,45,465,62,453,79,393,79,380,62,393,45" href="#Idle">
     378</map>
     379
     380
     381
     382<img src="/trac/attachment/wiki/CSMAMAC/files/csmaMac_state.png?format=raw" usemap="#GraffleExport" align=left/>
     383
     384}}}
     385
     386----
     387
     388Note: Through all of the following descriptions, a "-" is used in place of arguments to functions when those arguments are not important to the overall purpose of the description. Howeverm, that is not to say that these arguments can be changed to ''anything'' and have the code still compile and run successfully. Care must be taken in modifying the reference design.
     389
     390=== Idle ===
     391
     392There are two purposes of this state: At startup must initialize the framework and WARP hardware, and in the steady state it must sit and wait for an event to take place. This state maps to the
     393
     394{{{
     395#!c
     396int main()
     397}}}
     398
     399function of [source:/ResearchApps/MAC/CSMAMAC/csmaMac.c@L csmaMac.c].
     400
     401==== Startup ====
     402This block of code calls the following [http://warp.rice.edu/WARP_API/warpmac_8c.html WARPMAC] functions:
     403
     404{{{
     405#!c
     406warpmac_getMyId();
     407}}}
     408
     409This function reads the current setting on the [wiki:HardwareUsersGuides/FPGABoard_v1.2/UserIO#DIPSwitch Dip Switches]. The value is used simply to identify the node in the network. For the purposes of the Reference Design, one node must be identified as "0" and the other as "1."
     410
     411{{{
     412#!c
     413warpmac_init()
     414}}}
     415
     416This function sets reasonable default values for many of the parameters of the MAC, configures interrupts and exceptions, configures Ethernet, and finally initializes the custom peripherals such as the radio controller, the PHY, the packet detector, and the automatic gain control block.
     417
     418{{{
     419#!c
     420warpmac_setMacAddr(-);
     421}}}
     422
     423This function sets the wireless MAC address of the node.
     424
     425{{{
     426#!c
     427warpmac_setMaxResend(-);
     428warpmac_setMaxCW(-);
     429warpmac_setTimeout(-);
     430warpmac_setSlotTime(-);
     431}}}
     432
     433These function set up internal parameters of the MAC. The maximum number of resends is the maximum number of times that a packet should be retransmitted, in the event of not receiving an acknowledgment. The maximum contention window defines "how random" backoffs should be in the worst case. The timeout time is the amount of time that the MAC should wait on an acknowledgment before retransmitting. Finally, the slot time is a length of the minimum contention window.
     434
     435{{{
     436#!c
     437warpmac_setRxBuffer(-,0);
     438warpmac_setTxBuffer(1);
     439}}}
     440
     441The newest version of the [wiki:OFDM OFDM PHY] supports a large chunk of memory that can be used to queue multiple packets. By default, the system is configured with enough memory to support 4 full-size packets. This block of code instructs the framework to use the first 1/4th of memory to receive packets into, and the second 1/4th of memory to send from. In principle, these functions can be used to help juggle packets in the event of a busy wireless medium. For example, one can receive into a separate piece of memory in order to avoid overwriting a packet that has not been processed by higher layers yet.
     442
     443
     444{{{
     445#!c
     446warpmac_setGoodPacketHandler(receiveGoodPacket);
     447warpmac_setBadPacketHandler(receiveBadPacket);
     448warpmac_setTimerHandler(timerExpire);
     449warpmac_setEmacHandler(ethernet_callback);
     450}}}
     451
     452This block of code attaches user-level callbacks to interrupt service routines. These functions perform the behaviors that they sound like: receiving a packet that passes checksum, receiving a packet that fails checksum, processing a timer expiration, and handling Ethernet activity respectively.
     453
     454{{{
     455#!c
     456warpmac_setChannel(-, -);
     457}}}
     458
     459This function sets the center frequency of the radio in either the 2.4 or 5 GHz spectrum.
     460
     461{{{
     462#!c
     463warpmac_setBaseRate(-)
     464}}}
     465
     466Finally, the base rate modulation order is set. This rate must be agreed upon by all nodes in the network ''a priori.'' Within the base rate symbols is a field that specifies the modulation order of the rest of the packet (i.e. the full rate symbols). This enables dynamic modulation for autorate systems.
     467
     468==== Steady State ====
     469
     470The steady state behavior of the "Idle" state is very simple: it's nothing. At the bottom of the main function is a while loop that spins in place, waiting for an interrupt service routine to be called by a hardware event.
     471
     472
     473
     474----
     475
     476
     477
     478=== Accepted Packet from Source ===
     479
     480This state is entered if a higher layer has a packet it needs transmitted. For the reference design, this means a packet has arrived via Ethernet and needs processing.
     481
    281482----
    282483
    283484=== Medium State ===
    284485
     486The purpose of this state is to check to see if the medium has been idle for a DIFS period.
     487
     488{{{
     489#!c
     490warpmac_carrierSense(-);
     491}}}
     492
     493Is called and returns a 1 if the medium is idle (and hence the medium can be contented for) and a 0 if the medium is busy (and hence the node must wait).
     494
     495----
     496
     497=== Transmit Packet via PHY ===
     498
     499To transmit a packet over-the-air via the OFDM physical layer, the MAC calls
     500
     501{{{
     502#!c
     503warpmac_sendOfdm(&txBuffer);
     504}}}
     505
     506The argument of this function is the [http://warp.rice.edu/WARP_API/struct_macframe.html#o0 Macframe] containing the packet's header information. Note, the payload is already sitting inside the OFDM PHY's packet buffer thanks to the Ethernet MAC's built-in DMA engine. The particular packet buffer was designated back in the main function by
     507
     508{{{
     509#!c
     510warpmac_setTxBuffer(-);
     511}}}
     512
     513----
     514
     515=== Set TIMEOUT Timer ===
     516
     517This state starts the time located on the FPGA fabric in a deterministic countdown mode to wait for an acknowledgment. The framework function called is
     518
     519{{{
     520#!c
     521warpmac_setTimer(TIMEOUT);
     522}}}
     523
     524The length of the timeout period was specified back in the main function by
     525
     526{{{
     527#!c
     528warpmac_setTimeout(-);
     529}}}
     530
     531
     532----
     533
     534=== Set BACKOFF Timer ===
     535
     536This state starts the time located on the FPGA fabric in a channel-dependent countdown mode. The hardware automatically supports automatic pausing of this counter in the event of a busy medium and automatic resumption of the timer during idle periods. The purpose of this function is to wait for a random idle time before attempting to use the medium again. The framework function called is
     537
     538{{{
     539#!c
     540warpmac_setTimer(BACKOFF);
     541}}}
     542
     543The length of the backoff period is a function of the current resend count, the slot size, and the maximum contention window size. These parameters were specified back in the main function.
     544
     545
     546----
     547
     548=== Received Packet via PHY ===
     549
     550This state kick-starts the receive states.
     551----
     552
     553=== Checksum ===
     554
     555Either
     556
     557{{{
     558#!c
     559int receiveGoodPacket(-)
     560}}}
     561
     562is called in the event of receiving a packet that passes checksum or
     563
     564{{{
     565#!c
     566int receiveGoodPacket(-)
     567}}}
     568
     569in the event of receiving a packet that fails checksum.
     570
     571
     572
     573
     574----
     575
     576=== Destination Address ===
     577
     578In the received packet's [http://warp.rice.edu/WARP_API/struct_macframe.html#o0 Macframe] is a field that corresponds to the destination MAC address of packet. This field can be compared manually to the node's self address, or framework function
     579
     580{{{
     581#!c
     582warpmac_addressedToMe(-)
     583}}}
     584
     585can be used to perform this task.
     586
     587----
     588
     589=== Packet Type ===
     590
     591For this MAC algorithm, only two types of packets can be loaded into the [http://warp.rice.edu/WARP_API/struct_macframe.html#o0 Macframe] and understood by the receiver: DATA or ACK. The data packet flag tells the receiving node that a payload is present in this packet and must be delivered via Ethernet to some computer. If it is an ACK, the node must have been in a timeout waiting on the acknowledgment. It should clear the timeout and return to the idle state.
     592
     593----
     594
     595=== Clear TIMEOUT ===
     596
     597To halt and clear the timeout (and hence keep the timer expiration states from executing), the following function is called:
     598
     599{{{
     600#!c
     601warpmac_clearTimer(TIMEOUT);
     602}}}
     603
     604----
     605
     606=== Deliver Packet to Sink ===
     607
     608For the reference design, the sink is the Ethernet MAC. The function
     609
     610{{{
     611#!c
     612warpmac_sendEthernet(-);
     613}}}
     614
     615pushes the received packet over Ethernet.
     616
     617----
     618
     619=== Timer Expired ===
     620
     621This state begins the timer expiration states.
     622
     623----
     624
     625=== Timer Type ===
     626
     627In this system, there are two types of timers: timeouts and backoffs. A timeout timer expiring means that no acknowledgment was received in time, so the system should enter a backoff period before attempting to retransmit the packet. If a backoff timer expires, the channel is known to be idle for a DIFS period so transmission via the OFDM PHY can be initiated.
     628
    285629----
    286630
    287631=== Maximum Resends ===
    288632
    289 ----
    290 
    291 === Drop Packet ===
    292 
    293 ----
    294 
    295 === Increment Resend Counter ===
    296 
    297 
    298 
    299 
     633To keep the system from hanging forever trying to send the same packet, a maximum number of retransmissions is specified in the main function with
     634
     635{{{
     636#!c
     637warpmac_incrementResend(-);
     638}}}
     639
     640
     641
     642