simulation lab [mahadi]

Upload: muhammad-mahadi-hasan

Post on 05-Apr-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Simulation Lab [MAHADI]

    1/41

    Daffodil International University

    Course Code: CSE413

    Course Title: Simulation and Modeling

    Submitted To:

    Muhammad Javed Morshed

    Lecturer of CSE

    Daffodil Internation University

    Submitted By:

    Muhammad Mahadi Hasan

    ID: 092-15-791 (L4T1)

    Department of CSE

    Daffodil International University

    Submission Date: 04/08/2012

  • 7/31/2019 Simulation Lab [MAHADI]

    2/41

    1. Creating a simulated network with tow nodes.

    Step 1: First I created a folder by the name lab_1 in samples folder.

    Step 2: There after I created a file by the name tictoc1.ned .As shown bellow.

    simple Txc1{

    gates:input in;output out;

    }

    //// Two instances (tic and toc) of Txc1 connected both ways.

    // Tic and toc will pass messages to one another.//

    network Tictoc1{

    submodules:tic: Txc1;toc: Txc1;

    connections:tic.out --> { delay = 100ms; } --> toc.in;tic.in

  • 7/31/2019 Simulation Lab [MAHADI]

    3/41

    void Txc1::initialize()

    {

    if (strcmp("tic", getName()) == 0){

    // create and send first message on gate "out". "tictocMsg" is an// arbitrary string which will be the name of the message object.cMessage *msg = new cMessage("tictocMsg");send(msg, "out");

    }

    }

    void Txc1::handleMessage(cMessage *msg){

    send(msg, "out");}

    Step 4: Creating another file by the name omnetpp.ini.

    [General]

    # nothing here

    [Config Tictoc1]

    network = Tictoc1

    Step 5: I wrote following commands which screen shorts have show bellow.

    1. cd samples/lab_1

  • 7/31/2019 Simulation Lab [MAHADI]

    4/41

    2. opp_makemake -f

    3. make

  • 7/31/2019 Simulation Lab [MAHADI]

    5/41

    4.lab_1

  • 7/31/2019 Simulation Lab [MAHADI]

    6/41

    Fig: A network with two nodes.

  • 7/31/2019 Simulation Lab [MAHADI]

    7/41

    2. Enhancing two does with Tic Toc

    Step 1: First I created a folder by the name lab_2 in samples folder.

    Step 2: There after I created a file by the name tictoc2.ned .As shown bellow.

    simple Txc2{

    parameters:@display("i=block/routing"); // add a default icon

    gates:input in;output out;

    }

    network Tictoc2{

    submodules:

    tic: Txc2 {parameters:

    @display("i=,green"); // do not change the icon (first arg of i=) just colorize it}toc: Txc2 {

    parameters:@display("i=,gold"); // here too

    }connections:

    tic.out --> { delay = 100ms; } --> toc.in;tic.in

  • 7/31/2019 Simulation Lab [MAHADI]

    8/41

    // The `ev' object works like `cout' in C++.EV getName() is name of the msg object, here it will be "tictocMsg".EV

  • 7/31/2019 Simulation Lab [MAHADI]

    9/41

    3. make

    4. lab_2

  • 7/31/2019 Simulation Lab [MAHADI]

    10/41

  • 7/31/2019 Simulation Lab [MAHADI]

    11/41

  • 7/31/2019 Simulation Lab [MAHADI]

    12/41

    int counter; // Note the counter here

    protected:virtual void initialize();virtual void handleMessage(cMessage *msg);

    };

    Define_Module(Txc3);

    void Txc3::initialize(){

    WATCH(counter);

    if (strcmp("tic", getName()) == 0){

    EV

  • 7/31/2019 Simulation Lab [MAHADI]

    13/41

    [Config Tictoc3]

    network = Tictoc3

    Step 5: I wrote following commands which screen shorts have show bellow.

    1. cd samples/lab_3

    2. opp_makemake -f

    3. make

    4. lab_3

  • 7/31/2019 Simulation Lab [MAHADI]

    14/41

  • 7/31/2019 Simulation Lab [MAHADI]

    15/41

    Fig: Count 10 times.

  • 7/31/2019 Simulation Lab [MAHADI]

    16/41

    4. Adding Parameters

    Step 1: First I created a folder by the name lab_4 in samples folder.

    Step 2: There after I created a file by the name tictoc4.ned .As shown bellow.

    simple Txc4{

    parameters:bool sendMsgOnInit = default(false); // whether the module should send out a

    message on initializationint limit = default(2); // another parameter with a default value@display("i=block/routing");

    gates:input in;

    output out;}

    //// Adding module parameters.//network Tictoc4{

    submodules:tic: Txc4 {

    parameters:

    sendMsgOnInit = true;@display("i=,cyan");

    }toc: Txc4 {

    parameters:sendMsgOnInit = false;@display("i=,gold");

    }connections:

    tic.out --> { delay = 100ms; } --> toc.in;tic.in

  • 7/31/2019 Simulation Lab [MAHADI]

    17/41

    Step 3: Then in the same way I created another file by the name txc4.cc .As showing bellow.

    class Txc4 : public cSimpleModule{

    private:int counter;

    protected:virtual void initialize();virtual void handleMessage(cMessage *msg);

    };

    Define_Module(Txc4);

    void Txc4::initialize(){

    // Initialize the counter with the "limit" module parameter, declared// in the NED file (tictoc4.ned).

    counter = par("limit");

    // we no longer depend on the name of the module to decide// whether to send an initial messageif (par("sendMsgOnInit").boolValue() == true){

    EV

  • 7/31/2019 Simulation Lab [MAHADI]

    18/41

    Step 4: Creating another file by the name omnetpp.ini.

    [General]

    # nothing here

    [Config Tictoc4]

    network = Tictoc4

    Step 5: I wrote following commands which screen shorts have show bellow.

    1. cd samples/lab_4

    2. opp_makemake -f

    3. make

    4. ./lab_4

  • 7/31/2019 Simulation Lab [MAHADI]

    19/41

  • 7/31/2019 Simulation Lab [MAHADI]

    20/41

    5. Using Inheritance

    Its implementation doesnt exist in the document

  • 7/31/2019 Simulation Lab [MAHADI]

    21/41

    6. Modeling Processing Delay

    Step 1: First I created a folder by the name lab_6 in samples folder.

    Step 2: There after I created a file by the name tictoc6.ned .As shown bellow.

    simple Txc6{

    parameters:@display("i=block/routing");

    gates:input in;output out;

    }

    network Tictoc6{

    submodules:tic: Txc6 {

    parameters:@display("i=,green");

    }toc: Txc6 {

    parameters:@display("i=,blue");

    }

    connections:tic.out --> { delay = 100ms; } --> toc.in;tic.in

  • 7/31/2019 Simulation Lab [MAHADI]

    22/41

    void Txc4::initialize(){

    // Initialize the counter with the "limit" module parameter, declared// in the NED file (tictoc4.ned).counter = par("limit");

    // we no longer depend on the name of the module to decide// whether to send an initial messageif (par("sendMsgOnInit").boolValue() == true){

    EV

  • 7/31/2019 Simulation Lab [MAHADI]

    23/41

    Step 5: The Final output is:

    7. Random number and parameters

    Step 1: First I created a folder by the name lab_8 in samples folder.

    Step 2: There after I created a file by the name tictoc8.ned .As shown bellow.

    simple Tic8{

    parameters:@display("i=block/routing");

    gates:input in;output out;

    }

  • 7/31/2019 Simulation Lab [MAHADI]

    24/41

    simple Toc8{

    parameters:@display("i=block/process");

    gates:

    input in;output out;}

    network Tictoc8{

    submodules:tic: Tic8 {

    parameters:@display("i=,cyan");

    }

    toc: Toc8 {parameters:@display("i=,gold");

    }connections:

    tic.out --> { delay = 100ms; } --> toc.in;tic.in

  • 7/31/2019 Simulation Lab [MAHADI]

    25/41

    virtual void handleMessage(cMessage *msg);};

    Define_Module(Txc7);

    Txc7::Txc7()

    {event = tictocMsg = NULL;

    }

    Txc7::~Txc7(){

    cancelAndDelete(event);delete tictocMsg;

    }

    void Txc7::initialize(){

    event = new cMessage("event");tictocMsg = NULL;

    if (strcmp("tic", getName()) == 0){

    EV

  • 7/31/2019 Simulation Lab [MAHADI]

    26/41

    EV

  • 7/31/2019 Simulation Lab [MAHADI]

    27/41

    8. Timeout, cancelling timer

    Step 1: First I created a folder by the name lab_8 in samples folder.

    Step 2: There after I created a file by the name tictoc8.ned .As shown bellow.

    simple Tic8{

    parameters:@display("i=block/routing");

    gates:input in;

    output out;}

    simple Toc8{

    parameters:@display("i=block/process");

    gates:input in;output out;

    }

    network Tictoc8{

    submodules:tic: Tic8 {

    parameters:@display("i=,cyan");

    }toc: Toc8 {

    parameters:@display("i=,gold");

    }connections:

    tic.out --> { delay = 100ms; } --> toc.in;tic.in

  • 7/31/2019 Simulation Lab [MAHADI]

    28/41

    Step 3: Then in the same way I created another file by the name txc7.cc .As showing bellow.

    #include #include #include

    class Tic8 : public cSimpleModule{

    private:simtime_t timeout; // timeoutcMessage *timeoutEvent; // holds pointer to the timeout self-message

    public:Tic8();virtual ~Tic8();

    protected:virtual void initialize();virtual void handleMessage(cMessage *msg);

    };Define_Module(Tic8);Tic8::Tic8(){

    timeoutEvent = NULL;}Tic8::~Tic8(){

    cancelAndDelete(timeoutEvent);}void Tic8::initialize(){

    // Initialize variables.

    timeout = 1.0;timeoutEvent = new cMessage("timeoutEvent");

    // Generate and send initial message.EV

  • 7/31/2019 Simulation Lab [MAHADI]

    29/41

    else // message arrived{

    // Acknowledgement received -- delete the stored message and cancel// the timeout event.EV

  • 7/31/2019 Simulation Lab [MAHADI]

    30/41

    Step 5: I wrote following commands which screen shorts have show bellow.

    1. cd samples/lab_timeout

    2. opp_makemake -f

    3. make

    4. lab_timeout

  • 7/31/2019 Simulation Lab [MAHADI]

    31/41

    10. Created a simulated network with six nodes.

    Step 1: First I created a folder by the name lab_sixnode in samples folder.

    Step 2: There after I created a file by the name tictoc10.ned .As shown bellow.

    simple Txc10{

    parameters:@display("i=block/routing");

    gates:input in[]; // declare in[] and out[] to be vector gatesoutput out[];

    }

    network Tictoc10{

    submodules:tic[6]: Txc10;

    connections:tic[0].out++ --> { delay = 100ms; } --> tic[1].in++;tic[0].in++ tic[2].in++;tic[1].in++ tic[4].in++;tic[1].in++ tic[4].in++;tic[3].in++ tic[5].in++;tic[4].in++

  • 7/31/2019 Simulation Lab [MAHADI]

    32/41

    class Txc10 : public cSimpleModule{

    protected:virtual void forwardMessage(cMessage *msg);virtual void initialize();virtual void handleMessage(cMessage *msg);

    };

    Define_Module(Txc10);

    void Txc10::initialize(){

    if (getIndex()==0){

    // Boot the process scheduling the initial message as a self-message.char msgname[20];sprintf(msgname, "tic-%d", getIndex());cMessage *msg = new cMessage(msgname);

    scheduleAt(0.0, msg);}

    }

    void Txc10::handleMessage(cMessage *msg){

    if (getIndex()==3){

    // Message arrived.EV

  • 7/31/2019 Simulation Lab [MAHADI]

    33/41

    Step 4: Creating another file by the name omnetpp.ini.

    [General]

    # nothing here

    [Config Tictoc10]

    network = Tictoc10

    Step 5: I wrote following commands which screen shorts have show bellow.

    1. cd samples/lab_sixnode

    2. opp_makemake -f

    3. make

    4. ./lab_10

  • 7/31/2019 Simulation Lab [MAHADI]

    34/41

    11. Channels and inner type definitions

    Step 1: First I created a folder by the name lab_inner in samples folder.

    Step 2: There after I created a file by the name tictoc11.ned .As shown bellow.

    simple Txc11{

    parameters:@display("i=block/routing");

    gates:input in[]; // declare in[] and out[] to be vector gatesoutput out[];

    }

    //// Using local channel type definition to reduce the redundancy// of connection definitions.//network Tictoc11

  • 7/31/2019 Simulation Lab [MAHADI]

    35/41

  • 7/31/2019 Simulation Lab [MAHADI]

    36/41

    char msgname[20];sprintf(msgname, "tic-%d", getIndex());cMessage *msg = new cMessage(msgname);scheduleAt(0.0, msg);

    }}

    void Txc11::handleMessage(cMessage *msg){

    if (getIndex()==3){

    // Message arrived.EV

  • 7/31/2019 Simulation Lab [MAHADI]

    37/41

    1. cd samples/lab_inner

    2. opp_makemake -f

    3. make

    4. ./lab_inner

  • 7/31/2019 Simulation Lab [MAHADI]

    38/41

    12. Using two ways connections

    Step 1: First I created a folder by the name lab_con in samples folder.

    Step 2: There after I created a file by the name tictoc12.ned .As shown bellow.

    simple Txc12{

    parameters:@display("i=block/routing");

    gates:inout gate[]; // declare two way connections

    }

    // using two way connections to further simplify the network definitionnetwork Tictoc12{

    types:channel Channel extends ned.DelayChannel {

    delay = 100ms;}

    submodules:tic[6]: Txc12;

    connections:tic[0].gate++ Channel tic[1].gate++;

    tic[1].gate++ Channel tic[2].gate++;tic[1].gate++ Channel tic[4].gate++;tic[3].gate++ Channel tic[4].gate++;tic[4].gate++ Channel tic[5].gate++;

    }

    Step 3: Then in the same way I created another file by the name txc12.cc .As showing bellow.

    #include #include #include

    class Txc12 : public cSimpleModule{

    protected:virtual void forwardMessage(cMessage *msg);virtual void initialize();virtual void handleMessage(cMessage *msg);

    };

  • 7/31/2019 Simulation Lab [MAHADI]

    39/41

    Define_Module(Txc12);

    void Txc12::initialize(){

    if (getIndex()==0)

    {// Boot the process scheduling the initial message as a self-message.char msgname[20];sprintf(msgname, "tic-%d", getIndex());cMessage *msg = new cMessage(msgname);scheduleAt(0.0, msg);

    }}

    void Txc12::handleMessage(cMessage *msg){

    if (getIndex()==3)

    {// Message arrived.EV

  • 7/31/2019 Simulation Lab [MAHADI]

    40/41

    network = Tictoc12

    Step 5: I wrote following commands which screen shorts have show bellow.

    1. cd samples/lab_con

    2. opp_makemake -f

    3. make

    4. ./lab_con

  • 7/31/2019 Simulation Lab [MAHADI]

    41/41