main content

packetized modem with data link layer -凯发k8网页登录

this example shows you how to implement a packetized modem with data link layer [ 1 ] using matlab® and communications toolbox™. the modem features a packet-based physical layer and an aloha-based data link layer. you can either simulate the system or run with radios using the .

required hardware and software

to simulate the system performance, you need the following software:

to measure system performance with radios, you also need the following hardware:

  • usrp® radios (b2xx, n2xx, or x3xx)

and the following software

for a full list of communications toolbox supported sdr platforms, refer to the supported hardware section of .

introduction

packetized wireless modems are communications systems that transmit information in bursts called packets through a wireless channel. each modem, also called a node, features a physical layer where packets are modulated, transmitted and received on a shared frequency band, and demodulated. since the same frequency band is used by all nodes, a medium access control (mac) algorithm is required to reduce the packet loss due to collisions (i.e. simultaneous transmissions). data link layer includes a mac sublayer and a logical link control sublayer to share the same channel and provides an error-free link between two nodes. data link layer is also called layer 2 and sits between network layer (layer 3) and physical layer (layer 1).

run the example

the example code creates three packetized modem node objects and connects them through a channel object. each node can send packets to the other two nodes. acktimeout determines the timeout duration before a node decides the data packet transmission was not successful. acktimeout must be greater than the round trip duration for a data-ack exchange, which is 0.21 seconds for this example. the simulation is time-based and simulates the full physical layer processing together with the data link layer.

set simulation parameters

runduration = 10;         % seconds
numpayloadbits = 19530;   % bits
packetarrivalrate = 0.2;  % packets per second
acktimeout = 0.25;        % ack time out in seconds
maxbackofftime = 10;      % maximum backoff time in acktimeout durations
mmaxdataretries = 5;      % maximum data retries
queuesize = 10;           % data link layer queue size in packets
samplesperframe = 2000;   % number of samples processed every iteration
verbose = true;           % print packet activity to command line
samplerate = 200e3;

fix random number generation seed for repeatable simulations.

rng(12345)

create packetized modem nodes by using the object.

node1 = helperpacketizedmodemnode('address',1, ...
    'destinationlist',[2, 3],'numpayloadbits',numpayloadbits, ...
    'packetarrivalrate',packetarrivalrate,'acktimeout',acktimeout, ...
    'maxbackofftime',maxbackofftime,'maxdataretries',mmaxdataretries, ...
    'queuesize',queuesize,'carrierdetectorthreshold',1e-5, ...
    'agcmaxpowergain',65,'samplesperframe',samplesperframe, ...
    'verbose',verbose,'samplerate',samplerate);
node2 = helperpacketizedmodemnode('address',2, ...
    'destinationlist',[1 3],'numpayloadbits',numpayloadbits, ...
    'packetarrivalrate',packetarrivalrate,'acktimeout',acktimeout, ...
    'maxbackofftime',maxbackofftime,'maxdataretries',mmaxdataretries, ...
    'queuesize',queuesize,'carrierdetectorthreshold',1e-5, ...
    'agcmaxpowergain',65,'samplesperframe',samplesperframe, ...
    'verbose',verbose,'samplerate',samplerate);
node3 = helperpacketizedmodemnode('address',3, ...
    'destinationlist',[1 2],'numpayloadbits',numpayloadbits, ...
    'packetarrivalrate',packetarrivalrate,'acktimeout',acktimeout, ...
    'maxbackofftime',maxbackofftime,'maxdataretries',mmaxdataretries, ...
    'queuesize',queuesize,'carrierdetectorthreshold',1e-5, ...
    'agcmaxpowergain',65,'samplesperframe',samplesperframe, ...
    'verbose',verbose,'samplerate',samplerate);

configure the propagation channel by using the object.

channel = helpermultiuserchannel( ...
    'numnodes',3,'enabletimingskew',true,'delaytype','triangle', ...
    'timingerror',20,'enablefrequencyoffset',true, ...
    'phaseoffset',47,'frequencyoffset',2000,'enableawgn',true, ...
    'ebno',25,'bitspersymbol',2,'samplespersymbol',4, ...
    'enablericianmultipath', true, ...
    'pathdelays',[0 node1.samplespersymbol/node1.samplerate], ...
    'averagepathgains',[15 0],'kfactor',15,'maximumdopplershift',10, ...
    'samplerate',node1.samplerate);

main simulation loop

radiotime = 0;
nodeinfo = info(node1);
frameduration = node1.samplesperframe/node1.samplerate;
[rcvd1,rcvd2,rcvd3] = deal(complex(zeros(node1.samplesperframe,1)));
while radiotime < runduration
    trans1 = node1(rcvd1, radiotime);
    trans2 = node2(rcvd2, radiotime);
    trans3 = node3(rcvd3, radiotime);
    % multi-user channel
    [rcvd1,rcvd2,rcvd3] = channel(trans1,trans2,trans3);
    % update radio time.
    radiotime = radiotime   frameduration;
end
|   time    |     link    |   action   |  seq #  | backoff (node 1)
-----------------------------------------------------------
|   time    |     link    |   action   |  seq #  | backoff (node 2)
-----------------------------------------------------------
|   time    |     link    |   action   |  seq #  | backoff (node 3)
-----------------------------------------------------------
| 4.46000 s |   3 ->>   1 |       data | #     0 |
| 4.67000 s |   1 <<-   3 |       data | #     0 |
| 4.67000 s |   1 ->>   3 |        ack | #     0 |
| 4.68000 s |   3 <<-   1 |        ack | #     0 |
| 5.04000 s |   1 ->>   3 |       data | #     0 |
| 5.16000 s |   2 ->>   3 |       data | #     0 |
| 5.30000 s |   1 ->>   3 |   back off | #     0 | 1.00000 s |
| 5.42000 s |   2 ->>   3 |   back off | #     0 | 1.00000 s |
| 6.31000 s |   1 ->>   3 |       data | #     0 |
| 6.43000 s |   2 ->>   3 |       data | #     0 |
| 6.57000 s |   1 ->>   3 |   back off | #     0 | 2.25000 s |
| 6.69000 s |   2 ->>   3 |   back off | #     0 | 1.75000 s |
| 8.45000 s |   2 ->>   3 |       data | #     0 |
| 8.66000 s |   3 <<-   2 |       data | #     0 |
| 8.66000 s |   3 ->>   2 |        ack | #     0 |
| 8.67000 s |   2 <<-   3 |        ack | #     0 |
| 8.83000 s |   1 ->>   3 |       data | #     0 |
| 9.09000 s |   1 ->>   3 |   back off | #     0 | 2.25000 s |
| 9.52000 s |   3 ->>   2 |       data | #     1 |
| 9.73000 s |   2 <<-   3 |       data | #     1 |
| 9.73000 s |   2 ->>   3 |        ack | #     1 |
| 9.74000 s |   3 <<-   2 |        ack | #     1 |

results

the packetized modem node objects collect statistics on the performance of the data link layer algorithm. call the info method of the node object to access these statistics. sample results for a 10 second simulated time with a packet arrival rate of 0.2 packets/second are shown here. each data packet is 200 msec long.

display statistics

nodeinfo(1) = info(node1);
nodeinfo(2) = info(node2);
nodeinfo(3) = info(node3);
for p=1:length(nodeinfo)
    fprintf('\nnode %d:\n', p);
    fprintf('\tnumgeneratedpackets: %d\n', nodeinfo(p).numgeneratedpackets)
    fprintf('\tnumreceivedpackets: %d\n', nodeinfo(p).numreceivedpackets)
    fprintf('\taverageretries: %f\n', nodeinfo(p).layer2.averageretries)
    fprintf('\taverageroundtriptime: %f\n', ...
        nodeinfo(p).layer2.averageroundtriptime)
    fprintf('\tnumdroppedpackets: %d\n', ...
        nodeinfo(p).layer2.numdroppedpackets)
    fprintf('\tnumdroppedpackets (max retries): %d\n', ...
        nodeinfo(p).layer2.numdroppedpacketsduetoretries)
    fprintf('\tthroughput: %d\n', ...
        numpayloadbits / nodeinfo(p).layer2.averageroundtriptime)
    fprintf('\tlatency: %d\n', nodeinfo(p).layer2.averagelatency)
end
node 1:
	numgeneratedpackets: 2
	numreceivedpackets: 1
	averageretries: nan
	averageroundtriptime: nan
	numdroppedpackets: 0
	numdroppedpackets (max retries): 0
	throughput: nan
	latency: inf
node 2:
	numgeneratedpackets: 1
	numreceivedpackets: 1
	averageretries: 2.000000
	averageroundtriptime: 3.509844
	numdroppedpackets: 0
	numdroppedpackets (max retries): 0
	throughput: 5.564350e 03
	latency: 2.104687e-01
node 3:
	numgeneratedpackets: 2
	numreceivedpackets: 1
	averageretries: 0.000000
	averageroundtriptime: 0.220254
	numdroppedpackets: 0
	numdroppedpackets (max retries): 0
	throughput: 8.867039e 04
	latency: 1.749922e 00

data link layer (layer 2)

this example implements a data link layer based on the aloha random access protocol [ 2 ]. the following flow diagram shows how the aloha protocol transmits and receives data packets.

when data link layer has a layer 3 packet to transmit, it starts a new session and sends the packet right away using a data packet. the algorithm waits for an acknowledgment (ack) packet. if an ack is not received before the timeout period, it backs off a random amount of time and sends the data packet again. if it fails to receive an ack after a number of retries, it drops the packet. if during this session, a new layer 3 packet is received, the layer 3 packet is put in a first-in-first-out (fifo) queue. if the fifo queue is full, packet is dropped.

the algorithm is implemented in the helper system object™. the helperpacketizedmodemdatalinklayer system object defines a state machine with three states: idle, ack_wait, and backoff. the following state machine describes how the data link layer algorithm is implemented in this object. statements in brackets, [...], and curly braces, {...}, are conditions and actions, respectively. small circles are passthrough states used to represent multiple conditions.

the original aloha protocol uses a hub/star topology. the uplink and downlink utilizes two separate frequency bands. the following example employs a mesh network topology where nodes transmit and receive using the same frequency band.

modem structure

the modem code structure executes these six main processing parts:

  1. source controller

  2. message generator

  3. phy decoder

  4. data link layer

  5. message parser

  6. phy encoder

the data link layer processes outputs of the message generator and phy decoder, so it must run after those two operations. the message parser and phy encoder process outputs of the data link layer. this sequence ensures that the modem can receive packets and respond to them in the same time interval. the object implements the modem.

source controller

the source controller generates an enable signal and a random destination address based on the user-selected packet arrival distribution.

message generator

the message generator starts creating layer 3 data packets when enabled by the source controller. the packets contain a digitized text message. if the message does not fit into one packet, the generator creates multiple packets. the packet structure is as follows:

  • to address: 8 bits

  • from address: 8 bits

  • packet number: 16 bits

  • payload: m bits

phy decoder

the phy decoder receives baseband i/q samples and creates layer 2 packets. phy decoder can correct for amplitude variations using an agc, frequency offsets with a frequency offset estimator and compensator, and timing skews and multipath using a fractionally spaced decision feedback equalizer (dfe). the block diagram of the physical layer (layer 1) receiver is as follows:

when data payload size is set to 19530 bits, the total packet length of the modem is 39956 samples. the modem processes samplesperframe samples, which is 2000 samples for this example, at each iteration. a smaller samplesperframe results in smaller latency but increases the overhead of the modem algorithm. an increased overhead may increase the processing time such that the modem does not run in real-time anymore.

data link layer

data link layer provides a link between two neighboring nodes. it employs the aloha-based protocol described in the data link layer (layer 2) section. the packet structure contains these fields:

  • type: 4 bits

  • version: 2 bits

  • reserved: 2 bits

  • to address: 8 bits

  • from address: 8 bits

  • sequence number: 8 bits

  • time stamp: 32 bits

  • payload: n ( = m 32) bits

the data link layer also collects these statistics:

  • number of successful packet transfers, which is defined as the number of successfully received ack packets

  • average retries

  • average round trip time in seconds

  • number of dropped packets due to layer 3 packet queue being full

  • number of dropped packets due to retries

  • throughput defined as successful data delivery rate in bits per second

  • average latency in seconds defined as the time between the generation of the layer 3 data packet and reception of it at the destination node

message parser

the message parser parses the received layer 2 payload and creates layer 3 packet. the message parser collects these statistics:

  • number of received packets

  • number of received duplicate packets

phy encoder

the phy encoder creates physical layer packets by modulating the layer 2 packets into baseband i/q samples. the packet structure is shown here.

the dummy symbols are used to train the agc and for carrier detection. the synchronization symbols are a modulated pn-sequence. the header has these fields:

  • payload length: 16 bits

  • crc: 16 bits

this image shows the block diagram of the physical layer (layer 1) transmitter.

channel model

this example simulates a three-node network but any number of nodes can be simulated. the output of each node is passed to the channel simulator. the channel adds baseband signals from all three nodes after imposing the these channel impairments:

  • timing skew

  • frequency offset

  • rician multipath

  • awgn

in addition to these impairments, the signals from neighboring nodes are applied a path loss of 20 db, while the self-interference is added directly.

running using radios

you can also run this example using radios instead of a simulated channel. the combination of an sdr hardware and a host computer that runs a matlab session comprises a node. the following steps show you how to set up a three-node network. this example uses usrp® b200 and b210 radios.

1) connect a usrp® radio to host computer a, which we will call node 1. follow the instruction in (communications toolbox support package for usrp radio) to install and setup your host computer for use with usrp® radios. start a matlab session.

2) set up node 1 as a transmitter for initialization. the initializes the connected usrp® radio. run helperpacketizedmodeminitializeradio('tx', platform, address, fc, rt), where platform is the type of the usrp® radio, address is the serial number or ip address, fc is the center frequency, and rt is run time in seconds. this example uses 915 mhz for the center frequency. assuming that your radio is a b200 with serial number 'abcde', the function call will be helperpacketizedmodeminitializeradio('tx', 'b200', 'abcde', 915e6, 120). this function will run the transmitter for 120 seconds. if you need more time to finish the initialization, rerun the command with a longer run time.

3) repeat step 1 for a second radio and host computer and call this node node 2.

4) set up node 2 as a receiver for initialization. run [cdt, maxgain, rxgain] = helperpacketizedmodeminitializeradio('rx', platform, address, fc, rt). assuming that your radio is a b210 with serial number '12345', the function call will be [cdt1, maxgain1, rxgain1] = helperpacketizedmodeminitializeradio('rx', 'b210', '12345', 915e6, 120). the function will run until it determines the best values for carrier detector threshold (cdt), maximum agc gain (maxgain), and radio receive gain (rxgain) or until rt seconds have elapsed. if the initialization algorithm cannot determine suitable parameters, it may suggest increasing or decreasing the transmitter power and retrying the initialization.

5) run the same experiment with node 1 as the receiver and node 2 as the transmitter to determine best receiver parameters for node 1. in most cases the channel should be dual and the parameters will be very close.

6) repeat steps 1-5 for all other pairs of radios, i.e. node 1 and node 3, node 3 and node 2. obtain cdt, maxgain, and rxgain values for each node. if you get different values for the same node while initializing for different links, choose the maximum values for maxgain and rxgain, and minimum of cdt.

7) start node 1 by running the helper function. use the command helperpacketizedmodemradio(p,ra,na,da,fc,cdt,maxg,rgain,d), where p is platform, ra is radio address, na is node address, da is destination address list, fc is center frequency, cdt is carrier detection threshold, maxg is maximum agc gain, rgain is radio receiver gain, and d is duration. for example, run as helperpacketizedmodemradio('b200','abcde',1,[2 3],915e6,cdt1,maxgain1,rxgain1,120).

8) start node 2 by running helperpacketizedmodemradio('b210','12345',2,[1 3],915e6,cdt2,maxgain2,rxgain2,120).

9) start node 3 by running helperpacketizedmodemradio('b200','a1b2c',3,[1 2],915e6,cdt3,maxgain3,rxgain3,120).

10) once the session ends, each node prints out its statistics.

a three network setup operated for two hours. each node generated packets at a rate of 0.2 packets/second according to a poisson distribution. the nodes were placed approximately equal distance. one of the links had line-of-sight while other two did not. the following are the results collected on all three nodes. since the round trip time of a data-ack exchange using the b2xx radios connected over usb can be as high as 800 msec, the average round trip time of the network is greater than 3 sec. the algorithm minimizes packet loss and provides a fair access to the shared channel to all nodes.

node 1:
 numgeneratedpackets: 1440
 numreceivedpackets: 1389
 averageretries: 0.533738
 averageroundtriptime: 3.725093
 numdroppedpackets: 95
 numdroppedpackets (max retries): 23
 throughput: 5.242823e 03
node 2:
 numgeneratedpackets: 1440
 numreceivedpackets: 1340
 averageretries: 0.473157
 averageroundtriptime: 3.290775
 numdroppedpackets: 31
 numdroppedpackets (max retries): 9
 throughput: 5.934772e 03
node 3:
 numgeneratedpackets: 1440
 numreceivedpackets: 1385
 averageretries: 0.516129
 averageroundtriptime: 3.558408
 numdroppedpackets: 107
 numdroppedpackets (max retries): 29
 throughput: 5.488410e 03

discussions

the simulation code from previous sections and the helper function both utilize the system object to implement the modem node. in this example, the same code is used to evaluate a system, first using a simulated channel, then using sdr hardware and over-the-air channels.

even though the code using simulated channels is time-based, the modem node object could be used to run an event-based simulation. this example does not provide an event-based simulation kernel.

further exploration

you can vary these parameters to investigate their effect on data link layer performance:

  • packetarrivalrate

  • acktimeout

  • maxbackofftime

  • maxdataretries

  • queuesize

you can also explore the helper functions for implementation details of the algorithms:

you can examine the physical layer only performance using the script.

selected bibliography

凯发官网入口首页 copyright notice

universal software radio peripheral® and usrp® are trademarks of national instruments® corp.

网站地图