Changes between Version 23 and Version 24 of CSMAMAC


Ignore:
Timestamp:
Feb 8, 2008, 12:48:54 AM (15 years ago)
Author:
chunter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CSMAMAC

    v23 v24  
    325325The internal counter keeping track of the number of retransmissions is incremented. The function used is
    326326
    327 
    328 = Carrier-Sense Medium Access Reference Design (CSMAMAC) =
    329 
    330 The 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 
    344 This 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 
    351 Below 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 
    388 Note: 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 
    392 There 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
    396 int main()
    397 }}}
    398 
    399 function of [source:/ResearchApps/MAC/CSMAMAC/csmaMac.c@L csmaMac.c].
    400 
    401 ==== Startup ====
    402 This block of code calls the following [http://warp.rice.edu/WARP_API/warpmac_8c.html WARPMAC] functions:
    403 
    404 {{{
    405 #!c
    406 warpmac_getMyId();
    407 }}}
    408 
    409 This 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
    413 warpmac_init()
    414 }}}
    415 
    416 This 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
    420 warpmac_setMacAddr(-);
    421 }}}
    422 
    423 This function sets the wireless MAC address of the node.
    424 
    425 {{{
    426 #!c
    427 warpmac_setMaxResend(-);
    428 warpmac_setMaxCW(-);
    429 warpmac_setTimeout(-);
    430 warpmac_setSlotTime(-);
    431 }}}
    432 
    433 These 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
    437 warpmac_setRxBuffer(-,0);
    438 warpmac_setTxBuffer(1);
    439 }}}
    440 
    441 The 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
    446 warpmac_setGoodPacketHandler(receiveGoodPacket);
    447 warpmac_setBadPacketHandler(receiveBadPacket);
    448 warpmac_setTimerHandler(timerExpire);
    449 warpmac_setEmacHandler(ethernet_callback);
    450 }}}
    451 
    452 This 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
    456 warpmac_setChannel(-, -);
    457 }}}
    458 
    459 This function sets the center frequency of the radio in either the 2.4 or 5 GHz spectrum.
    460 
    461 {{{
    462 #!c
    463 warpmac_setBaseRate(-)
    464 }}}
    465 
    466 Finally, 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 
    470 The 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 
    480 This 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 
    482 ----
    483 
    484 === Medium State ===
    485 
    486 The purpose of this state is to check to see if the medium has been idle for a DIFS period.
    487 
    488 {{{
    489 #!c
    490 warpmac_carrierSense(-);
    491 }}}
    492 
    493 Is 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 
    499 To transmit a packet over-the-air via the OFDM physical layer, the MAC calls
    500 
    501 {{{
    502 #!c
    503 warpmac_sendOfdm(&txBuffer);
    504 }}}
    505 
    506 The 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
    510 warpmac_setTxBuffer(-);
    511 }}}
    512 
    513 ----
    514 
    515 === Set TIMEOUT Timer ===
    516 
    517 This 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
    521 warpmac_setTimer(TIMEOUT);
    522 }}}
    523 
    524 The length of the timeout period was specified back in the main function by
    525 
    526 {{{
    527 #!c
    528 warpmac_setTimeout(-);
    529 }}}
    530 
    531 
    532 ----
    533 
    534 === Set BACKOFF Timer ===
    535 
    536 This 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
    540 warpmac_setTimer(BACKOFF);
    541 }}}
    542 
    543 The 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 
    550 This state kick-starts the receive states.
    551 ----
    552 
    553 === Checksum ===
    554 
    555 Either
    556 
    557 {{{
    558 #!c
    559 int receiveGoodPacket(-)
    560 }}}
    561 
    562 is called in the event of receiving a packet that passes checksum or
    563 
    564 {{{
    565 #!c
    566 int receiveGoodPacket(-)
    567 }}}
    568 
    569 in the event of receiving a packet that fails checksum.
    570 
    571 
    572 
    573 
    574 ----
    575 
    576 === Destination Address ===
    577 
    578 In 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
    582 warpmac_addressedToMe(-)
    583 }}}
    584 
    585 can be used to perform this task.
    586 
    587 ----
    588 
    589 === Packet Type ===
    590 
    591 For 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 
    597 To halt and clear the timeout (and hence keep the timer expiration states from executing), the following function is called:
    598 
    599 {{{
    600 #!c
    601 warpmac_clearTimer(TIMEOUT);
    602 }}}
    603 
    604 ----
    605 
    606 === Deliver Packet to Sink ===
    607 
    608 For the reference design, the sink is the Ethernet MAC. The function
    609 
    610 {{{
    611 #!c
    612 warpmac_sendEthernet(-);
    613 }}}
    614 
    615 pushes the received packet over Ethernet.
    616 
    617 ----
    618 
    619 === Timer Expired ===
    620 
    621 This state begins the timer expiration states.
    622 
    623 ----
    624 
    625 === Timer Type ===
    626 
    627 In 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 
    629 ----
    630 
    631 === Maximum Resends ===
    632 
    633 To 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 
    635327{{{
    636328#!c