OMnet++奮闘記2

以前OMnet++がとりあえず動かせるようになり、チュートリアルを済ませることにしました。
http://www.omnetpp.org/doc/tictoc-tutorial/part1.html
そしてとりあえずtictocを動かし、少し感動する。



そうこうしていろんなところを読むと、とりあえず
動作は.cc
モジュールは.ned
という理解に行き着く。


そしてそこから考えたのが、「ticとtocからなるモジュールとして理解して動かしたらどうなるだろうか」
それで作ったのがこれ。
txc1.ccは変更してません。

tictoc.ned

simple Txc1
  gates:
    in: in;
    out: out;
endsimple


次にtopology.ned(名前は何でもいい)

import "Txc1";
module topology
  submodules:
    tic: Txc1;
    toc: Txc1;
  connections:
    tic.out --> delay 100ms --> toc.in;
    tic.in <-- delay 100ms <-- toc.out;
endmodule


network Tictoc1: topology
endnetwork;

こんだけ。たぶん動くはず!

次にticとtocの間になんか中継点を入れようと思います。とりあえず続く。



っしゃー。
とりあえず思ったより快調に進んだので保存がてら…
中継点を、というものでしたが僕はin/outが2個ついてるやつを扱えるほどまだOMnet++を習熟していないのでとりあえず2個の中継点にし、何にも役割がないと可哀そうなんで申し訳程度に遅延にして作成。
作成したら遅延2個の位置が見事にかぶったので位置を勉強、カッコつけてアイコンも設定。
それが以下のソースになります。
ちなみにtxc1.ccとtictoc.nedは上記から変更なしです。新たにdelay.ccとdelay.nedを作りました。

delay.cc

#include
#include


class Delay : public cSimpleModule
{
 protected:
  virtual void handleMessage(cMessage *msg);
};

Define_Module(Delay);


void Delay::handleMessage(cMessage *msg)
{
  send(msg, "out");
}


delay.ned

simple Delay
  gates:
    in: in;
    out: out;
endsimple

topology.ned

import "Txc1" , "Delay";
module topology
  submodules:
    tic: Txc1;
      display:"p=0,0;i=block/routing";
    toc: Txc1;
      display:"p=100,100;i=block/routing";
    delay1: Delay;
      display:"p=0,100;i=block/opticaldelay_s";
    delay2: Delay;
      display:"p=100,0;i=block/opticaldelay_s";
  connections:
    tic.out --> delay 100ms --> delay1.in;
    toc.in <-- delay 100ms <-- delay1.out;
    delay2.out --> delay 100ms --> tic.in;
    delay2.in <-- delay 100ms <-- toc.out;
endmodule


network Tictoc1: topology
endnetwork;


こんな感じで。


次は遅延2個を一つにまとめてみたいと思います。

このゆっくりさが僕の進度を表してますw