• 大小: 616KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-07
  • 语言: 其他
  • 标签: omnet++  

资源简介

提供利用omnet++对无线传感器网络仿真的实例,对100个节点之间路由协议的仿真可以使初学者更好掌握omnet++技巧

资源截图

代码片段和文件信息

//
// This file is part of an OMNeT++/OMNEST simulation example.
//
// Copyright (C) 1992-2005 Andras Varga
//
// This file is distributed WITHOUT ANY WARRANTY. See the file
// ‘license‘ for details on this and other legal matters.
//

#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif

#include 
#include 
#include “packet_m.h“


/**
 * Generates traffic for the network.
 */
class App : public cSimpleModule
{
  private:
    // configuration:
    int myAddress;
    double iatime;
    long pkCounter;

    std::vector destAddresses;
    cMessage *generatePacket;

    // statistics:
    cLongHistogram hopCounts;
    int pkReceived;

  public:
    App();
    virtual ~App();

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

Define_Module(App);


App::App()
{
    generatePacket = NULL;
}

App::~App()
{
    cancelAndDelete(generatePacket);
}

void App::initialize()
{
    myAddress = parentModule()->par(“address“);
    iatime = 1.0;
    pkCounter = 0;
    pkReceived = 0;

    WATCH(pkCounter);
    WATCH(myAddress);
    WATCH(iatime);
    WATCH(pkReceived);

    const char *destAddressesPar = par(“destAddresses“);
    cStringTokenizer tokenizer(destAddressesPar);
    const char *token;
    while ((token = tokenizer.nextToken())!=NULL)
        destAddresses.push_back(atoi(token));

    hopCounts.setName(“hopCounts“);
    hopCounts.setRangeAutoUpper(0201.5);
    hopCounts.setNumCells(1000);

    generatePacket = new cMessage(“nextPacket“);
    scheduleAt(exponential(iatime) generatePacket);
}

void App::handleMessage(cMessage *msg)
{
    if (msg == generatePacket)
    {
        // Sending packet
        int destAddress = destAddresses[intuniform(0 destAddresses.size()-1)];

        char pkname[40];
        sprintf(pkname“pk-%d-to-%d-#%ld“ myAddress destAddress pkCounter++);
        ev << “generating packet “ << pkname << endl;

        Packet *pk = new Packet(pkname);
        pk->setSrcAddr(myAddress);
        pk->setDestAddr(destAddress);
        send(pk“out“);

        scheduleAt(simTime()+exponential(iatime) generatePacket);
        if (ev.isGUI()) parentModule()->bubble(“Generating packet...“);
    }
    else
    {
        // Handle incoming packet
        Packet *pk = check_and_cast(msg);
        ev << “received packet “ << pk->name() << “ after “ << pk->getHopCount() << “hops“ << endl;
        hopCounts.collect(pk->getHopCount());
        pkReceived++;
        delete pk;

        if (ev.isGUI())
        {
            parentModule()->displayString().setTagArg(“i“1“green“);
            parentModule()->bubble(“Arrived!“);
        }
    }
}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1233  2008-07-09 09:25  routing\.tkenvrc

     文件       2792  2006-10-21 21:35  routing\app.cpp

     文件       3599  2006-10-21 21:35  routing\Makefile.vc

     文件       7325  2006-10-21 21:35  routing\net60.ned

     文件        803  2006-10-21 21:35  routing\networks\fullgraph.ned

     文件       1153  2006-10-21 21:35  routing\networks\mesh.ned

     文件       7908  2006-10-21 21:35  routing\networks\net60a.ned

     文件        858  2006-10-21 21:35  routing\networks\omnetpp.ini

     文件        578  2006-10-21 21:35  routing\networks\README.txt

     文件       1345  2006-10-21 21:35  routing\node.ned

     文件         96  2006-10-21 21:35  routing\omnetpp.ini

     文件        386  2006-10-21 21:35  routing\packet.msg

     文件       8785  2008-07-06 21:03  routing\packet_m.cpp

     文件       1607  2008-07-06 21:03  routing\packet_m.h

     文件       1570  2006-10-21 21:35  routing\README.txt

     文件       2880  2006-10-21 21:35  routing\routing.cpp

     文件       9713  2008-07-06 21:01  routing\routing.dsp

     文件       9607  2006-10-21 21:35  routing\routing.dsp.in

     文件        539  2006-10-21 21:35  routing\routing.dsw

     文件    1855488  2008-07-06 21:04  routing\routing.exe

     文件     331604  2008-07-06 21:04  routing\routing.exp

     文件     547314  2008-07-06 21:04  routing\routing.lib

     文件      58368  2008-07-15 11:05  routing\routing.ncb

     文件      49664  2008-07-15 11:05  routing\routing.opt

     文件        256  2008-07-09 10:41  routing\routing.plg

    ..A..H.      6656  2008-07-08 14:42  routing\routing.suo

     目录          0  2008-07-06 21:01  routing\networks

     目录          0  2008-07-06 21:04  routing\release

     目录          0  2008-07-15 11:05  routing

----------- ---------  ---------- -----  ----

............此处省略3个文件信息

评论

共有 条评论