ELEC 6851

 

PROJECT

 

The objective of the project is to develop a simulation program for the nonpersistent CSMA protocol ( Ref: page 381 in the text). CSMA protocol functions as follows,

 

i) A user that has a packet to transmit senses the channel. If the channel is idle then it begins its transmission, otherwise  it schedules to resense the channel after a uniformly distributed  time within (0, W) where i is the number of the sensing.

 

ii) It is assumed that tp seconds after a user begins the transmission of its packet all the other users will sense that the channel is busy. 

 

iii) tp seconds is the collision window and during this interval other users sensing the channel will also decide that the channel is idle and will begin transmitting their packets. When the transmissions of two or more packets overlap, then, this results in a collision. All the users involved in a collision schedule to resense the channel  after a uniformly distributed time with (0, (0, W).

 

iv) Each user, that doesnot have a packet to transmit, generates a new packet to transmit after an exponentially distributed amount of time with parameter λ.

 

 

Assume that there are N users sharing the channel. The transmission rate is R bits per second. Packets have constant length of F bits.

 

 

Plot the average packet delay and throughput of the system as a function of the traffic load.

 

 

 

 

 

 

SIMULATION ORGANIZATION

 

This is a discrete event simulation model. The user should define the following event types,

 

Type 1.    Arrival event.

 

Type 2.    Sensing event

 

Type 3.   Packet transmission event.

 

Let us see how each event type is processed,

 

·        Type 1:  When an arrival occurs, the channel will be sensed immediately. If channel is idle a type 3. event will be scheduled else a type 2 event will be scheduled. Each time a type 3 event is scheduled it is checked whether a collision will take place and all the collided packets are flagged.

 

 

·        Type 2:   When the channel is sensed either a Type 3 or Type 2 event will be scheduled. Each time a type 3 event is scheduled it is checked whether a collision will take place and all the collided packets are flagged.

 

·        Type 3 :  When a Type 3 event occurs, it means the end of a packet transmission. If this transmission is successful, a Type 1 event is scheduled for that user else a Type 2 event is scheduled.

 

 

 

 

 

 

 

 

 

 

All the scheduled events are kept in a list which is always sorted according to the event times. These are the events that will occur in the future. The simulation time moves by processing the events in the list. The next event to be processed is always the event at the beginning of the list. When the processing of an event is completed, an event is removed from the list. New scheduled events are placed at the right place in the list. The simulation time advances from the present time to the time of the next event to be processed. The following table shows an instant of the simulation list,

 

List number

Event time

Event type

Packet No

1

25.45

2

3

2

30.35

3

1

3

40.64

1

2

4

55.45

2

4

 

 

 

 

 

                                               Table I. Event List

 

The simulation begins at time zero. Since all users are idled each will have a packet arrival scheduled in the list. Thus the program begins with the execution of the events in the list.

 

 

 

 

 

 

 

 

Note : An exponentially distributed random number may be generated using uniform distribution as follows,

 

 

(1)    ,      probability density function

 

(2)   ,   probability distribution function,

 

 

 

(3)          where

 

 

However, U(x) is uniformly distributed over the interval (0, 1). After generation of a uniformly distributed number and its substitution in equation (3),  results in exponentially distributed random variable x.

 

 

 

 

C++ code to generate a uniformly distributed number in the interval (0, N),

 

float u, r;

int n;

srand ( time( 0 ));

 

n = rand ( );

r = n % (N+1) ;          // the remainder will be in the range of    0 <= r   <= N   

 

u = r/N ;                      // u is uniformly distributed in the interval (0, N)