Mac802_11 timer introduction (post) in NS2)

Source: Internet
Author: User

1. Introduction to mac802_11 timer related classes

The class diagram is as follows:

Http://120.img.pp.sohu.com/images/blog/2007/12/3/16/16/1173b4c9ccf.jpg

Figure 1 mac802_11 timer-related class structure in NS2.

PS: In ~ NS \ common \ timer-handler. [h, CC] defines a timerhandler class, which is a general timer in NS. However, it is not used in Mac. Instead, it defines some timer with similar functions and mechanisms.

Important class introduction (the following class definition positions are all in ~ NS \ Mac-timers. [h, CC]):

1. mactimer: Handler

Role Overview:

1) The common parent class of timer in mac802_11;

2) derived from the handler class, so the timer can be passed to the event scheduler as the handler * parameter in the Scheduler: Schedule (handler *, event *, double delay) method, as the event processor after timeout.

Important attributes/methods:

1) protected mac802_11 * MAC;

Timer calls the corresponding timeout Processing Method of Mac. The timer constructor takes the pointer of mac802_11 class instance as the parameter and assigns it to Mac.

2) Public Virtual void start (double time)
{
... // Set the timer status and record the time
S. Schedule (this, & intr, rtime );
// This is a reference of the timer; rtime is the timer duration of the timer; & intr is the event type, used to mark this timer event

}

Start () finally calls schedule (), so that the event scheduler notifies timer of processing timeout after rtime, so as to implement timed and time-out notifications, that is, the timer capability is actually implemented by the time-based event scheduler.

3) Public Virtual void stop ()

The schedcel: Cancel (& intr) method is called to cancel the timer event in the scheduler and reset the timer status.

4) Public inline double expire ()
{
Return (stime + rtime)-schedck: instance (). Clock ());
}

Unlike the general timer timerhandler: expire () of NS, this method is only used to return how long the timer has timed out.

2. backofftimer: mactimer

Description ):

Figure 1.2 Timing Mechanism

1) used for competitive Backoff Mechanism: after detecting that the media remains idle for a DIFs (DCF interframe space) or EIFS (Extended interframe space, if the site's Stas rollback timer backoff timer is zero at this time, Stas will generate a random rollback time instead of immediate access, thus reducing conflicts between multiple waiting Stas after simultaneous access to DIFs; if the value is not zero, the system continues to wait according to the rollback timer content.

2) backoff time = random () × aslottime;

3) random () -- returns a random integer between [0, cw], and CW indicates the current competitive window size;

4) after the DIFS or EIFS ends, the sta continues to detect the media. Each time an idle aslottime is detected, the timer will be reduced by one; if the system detects that the media is busy while the rollback timer is still working, the rollback timer is paused. After the media is idle again and DIFs or EIFS continues, the rollback timer continues.

5) when the rollback timer is reduced to zero, the channel usage starts immediately.

Important attributes/methods:

1) Public void handle (event * E)
{

... // Reset the timer status

Mac-> backoffhandler () // call the corresponding timeout Processing Method of mac802_11

}

The Processing Method of backofftimer timeout is to hand over the real backoff timeout processing to mac802_11.

2) Public void start (int cw, int idle)
{

...
Rtime = (random: Random () % cw) * Mac-> phymib _. getslottime (); // generate random rollback time

...
If (idle = 0)
Paused _ = 1; // if the current channel is not idle, The backofftimer is suspended and the pause () method is triggered.

Else {
Assert (rtime> = 0.0 );

S. Schedule (this, & intr, rtime); // If the channel is idle, start the rollback.

}
}

This method can be used to start a new rollback timer, or to "pause" the current rollback timer.

3) Public void pause ()
{
... // Calculate the number of remaining time slots for rollback

Rtime-= (slots * Mac-> phymib _. getslottime (); // modify the timeout value

S. Cancel (& intr); // cancel the scheduled event in the scheduler to pause the timer.

}

This method is used to pause the actual operation performed by backofftimer.

4) Public void resume (double DIFS)
{
...

Difs_wait = DIFs; // reset the DIFS interval.

S. Schedule (this, & intr, rtime + difs_wait); // resume rollback timing

}

This method is used to reset the DIFS interval and restore the time of backofftimer;

3. defertimer: mactimer

Description ):

1) used to indicate the delay time required for the access channel (excluding the rollback time)

2) When the sta listens to the channel and correctly receives information such as RTS/CTS, it will know the duration of the current channel, this length plus DIFs or EIFS is the time for delayed access.

4. navtimer: mactimer

Description ):

1) Nav is an indicator maintained by each base station. It indicates that the base station cannot initiate transmission in wireless media for a period of time, regardless of whether the base station detects that the media is busy;

2) MAC uses virtual carrier listeners (different from physical carrier listeners on the physical layer). Therefore, the nav and physical carrier listening results are required to jointly determine whether the media is idle or not;

3) Nav is like a counter that decreases at a constant rate. When the counter is not zero, the virtual carrier listener considers the media to be busy, and when it is zero, it considers it idle.

4) The STA updates the nav by receiving the duration/Id field in the frames sent by other Stas. When the value is greater than the nav value of the current Stas and the frame is not sent to the Stas, set nav with a new value.

5) Nav is used to implement virtual carrier monitoring. It focuses on the busy state of the media (it decreases when the media is busy), while backoff timer is used to implement the rollback mechanism to reduce conflicts, it focuses on the idle state of the media (it decreases when the media is idle ).
 

5. rxtimer: mactimer

Role Overview:

1) The timer defined by mac802_11 is used to simulate the receipt latency of a complete group;

2) When the group is started, mac802_11 enters the mac_recv status. If another group arrives before the timer times out, the Mac status is changed; after the timer times out, check the Mac status to check whether the group has been correctly received.

6. txtimer: mactimer

Role Overview:

1) The sender needs to get a response after sending a message, such as CTS/ack. The timer is used by the sender to time the reply information;

2) Start the mac802_11: transmit () method. After the timer times out, it indicates that no response has been received within the specified time. Call mac802_11: sendhandler () and then call mac802_11 :: send_timer (): determines whether to re-transmit or what type of message (RTS/CTS/data/ACK) based on the sending status ).

7. iftimer: mactimer

Role Overview:

1) The timer defined by mac802_11 is used to simulate the sending latency of sending a complete group;

2) Start in the mac802_11: transmit () method. When the timer times out, it indicates that the group has been successfully sent and mac802_11: txhandler () is called (), call the MAC layer trace object eottarget _-> Recv (eotpacket _, (handler *) 0), and set the Mac sending status tx_active _ to 0.

The attributes/methods of timer from 3 to 7 are simple and similar. The following is a uniform introduction:

1) Public void handle (event * E)
{

... // Reset the timer status

Mac-> xxxhandler () // call the corresponding timeout Processing Method of mac802_11. XXX is usually the timer name.

}
Xxxtimer timeout method. The actual timeout is handled by the mac802_11: xxxhandler () method.

Ii. Summary

The timer mechanism in NS is summarized as follows:

1. First, use the START (time) method of the timer to add an event with a delay of time To scheduler, and the processor of the event is timer itself;

2. After the delay time, scheduler schedules the handle () method of the timer, indicating that the timer times out and thus the timer times out;

3. Call the stop method of timer before timeout, and then call the schedcel: Cancel (e) method to cancel the timer event.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.