Chinaunix首页 | 论坛 | 博客
  • 博客访问: 221339
  • 博文数量: 25
  • 博客积分: 4085
  • 博客等级: 上校
  • 技术积分: 585
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-30 02:09
文章分类

全部博文(25)

文章存档

2011年(1)

2009年(2)

2008年(22)

我的朋友

分类: 系统运维

2008-05-22 00:47:06

OMNeT++ Tutorial: An example of packet switching

<伊落丹> Illidan.modeler@gmail.com
Northern Capital, the Republic of Pandaria


0. Foreword
This tutorial, and another one, resemble two notorious tutorial examples from OpNet. One is "Packet Count", the other "Packet Switching". I think these two topics are proper ABC tutorials for an event-driven network simulatior, so I port them into OMNeT++ platform. For those who used to be OpNet users, this tutorial also recalls the first days learning using a network simulator.

In this tutorial we will cover the following topics:
Using random distribution
Record statistics
Using parameters
Using a packet format


1. Utility simple modules

1.1 SimpleSource
SimpleSource consistently generates packets according to given inter-arrival time (iaTime) and packet size (pkSize). (It resembles the simple_source.pr.m process model in OpNet.)

iaTime is a random variable. We'll have random numbers are used via this example.

(Using random distribution)

In omnetpp.ini, we have

pksw_net.**.iaTime = exponential(0.152)

pksw_net is the name of the network, which will be specified in NED files. Wild cards "**" matches the module names (like host.hostproc). iaTime is the attribute name, defined in NED files, for SimpleSource. Here in .ini file, the attribute value is provided, as a random variable complying to exponential distribution. In C++, we use the following code to load the value:

(Using parameters)
iaTime = par("iaTime");  //iaTime is a double C++ variable

In NED, we define the attribute as follows:

simple SimpleSource
    parameters:
        iaTime: numeric;
endsimple


In summary, the work flow to deal with a paramter is as follows:
NED (defines attribute)  -->  ini (assigns values)  --> C++ (loads values)

1.2 Sink
It resembles the sink.pr.m process model in OpNet. It sinks the packets and records packets' general statistic like 'end-to-end  delay'. The C++ for recording a vector statistic is as below :

(Record statistics)
In Sink.h,  declare a cOutVector instance:
cOutVector pkDelayVector
;

In Sink::handleMessage(), call cOutVector.record() :
 pkDelayVector.record(simTime() - pk->timestamp());


2. Nodes (compound modules)

2.1 Switch

It contains a SwitchProc simple module. In fact, since it only has one simple module, it can be substituted by a simple module. But it's scalable to be a compound, since you can add more simple modules within if needed.

SwitchProc will switch the incoming packets.

NED for Switch is as follows:

module Switch
    gates:
in: in[];
out: out[];
submodules:
switch_proc: SwitchProc;
gatesizes:
in[sizeof(in)],
out[sizeof(out)];
display: "p=80,48;i=block/switch";
connections:
for i=0..sizeof(in)-1 do
in[i] --> switch_proc.in[i];
out[i] <-- switch_proc.out[i];
endfor;
display: "b=141,89";
endmodule

2.2 Host

It contains the following simple modules:
SimpleSource: generating packets
Sink: receiving and destroying packets
HostProc: sending packets up to Sink or down to the network

NED is as follows:
module Host
gates:
out: out;
in: in; //
//
submodules:
sink: Sink;
display: "p=83,48;i=block/sink";
src: SimpleSource;
display: "p=43,96;i=block/source";
proc: HostProc;
display: "p=86,144;i=block/process";
connections:
src.out --> proc.from_hl;
sink.in <-- proc.to_hl;
proc.to_ll --> out;
proc.from_ll <-- in;
display: "b=110,185";
endmodule

3. Simple Module Implementation

3.1 SwitchProc

Packet's format is defined as (in packet.msg):

(Using a packet format)
message Packet
{
fields:
int destAddr;
}

Here, "Packet" is the name of the packet, just like "EthernetMAC" etc. It only has 1 field: destAddr.


It deals with the packets like this:

If the packet's "dest" field is 1, forwards the packet via port "1". Since we don't implement an addressing scheme here, we replace the switching fabric by this s implied logic. For a more complicated and realistic switching fabric, see Amnet's Tutorial.

The source code to implement our logic is as follows:

  dest = pk->getDestAddr();
  send(pk, "out", dest);


3.2 HostProc

SimpleSource only generates packets. Here we have to assign values to packets' header fields. Value of "destAddr" field is set to a random variable, in the same way we did for SimpleSource.

Since OMNeT++ doesn't have built-in link model, I implement a  simplied functionality to model transmission delay (or called store-and-forward delay).

double txDelay = (double)pk->length()/txRate;
scheduleAt(simulation.simTime()+txDelay, event );

4. Run simulation and view results

After the simulation run, we get the statistic for packets' end-to-end delay from source node to its destination, shown in the figure below:




5. Complete files











阅读(2730) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~