如何在Omnet ++中将传入流量重定向到模块到其简单子模块?

时间:2019-05-14 11:53:32

标签: c++ omnet++ inet

我有这段代码,其中扩展WirelessHost模块的模块由一个称为node的简单模块组成: 运行模拟时,只有移动性事件,没有通信事件显示。我认为这是由于没有 将Drone gates模块与接收传入流量的Gates链接起来。我该怎么办?


                            SaaS.ned

import inet.node.inet.WirelessHost;
import inet.visualizer.integrated.IntegratedVisualizer;
import inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator;
import inet.physicallayer.unitdisk.UnitDiskRadioMedium;

simple Node
{
    gates:
        input in[];
        output out[];
}

module Drone extends WirelessHost
{                 
        gates:
            input in[];
            output out[];

         submodules:
            myNode: Node;

        connections allowunconnected:    
            for i=0..sizeof(in)-1 {
                in++ -->  myNode.in++;
            }
            for i=0..sizeof(out)-1 {
                out++ <--  myNode.out++;
            }
}

network SaaS
{
    parameters:
        int numDrones;

    submodules:
        visualizer: IntegratedVisualizer {
            @display("p=94.376,433.728");
        }

        configurator: Ipv4NetworkConfigurator {
            parameters:
                config = xml("<config><interface hosts='*' address='145.236.x.x' netmask='255.255.0.0'/></config>");
                @display("p=94.376,56.224;is=s");
        }

        radioMedium: UnitDiskRadioMedium {
            @display("p=94.376,178.71199");
        }

        drone[numDrones]: Drone {
            @display("i=misc/node_vs");
        }
}

                           Node.cc

#include <string.h>
#include <omnetpp.h>

using namespace omnetpp;

class Node : public cSimpleModule
{
     protected:
      // The following redefined virtual function holds the algorithm.
      virtual void initialize() override;
      virtual void handleMessage(cMessage *msg) override;
};

// The module class needs to be registered with OMNeT++
Define_Module(Node);
using namespace std;

void Node::initialize()
{
    int n = gateSize("out");
    cMessage *msg = new cMessage("tictocMessage");
    for (int i = 0; i < n ; i++)
            send(msg, "out", i);
}

void Node::handleMessage(cMessage *msg)
{
    int n = gateSize("out");
    for (int i = 0; i < n ; i++)
        send(msg, "out", i);
}

1 个答案:

答案 0 :(得分:1)

这不是应该如何配置INET中的WirelessHost

您应该实现UDP应用程序模块,并且必须配置要在WirelessHost中使用的应用程序。

*.drone[0].numApps = 1
*.drone[0].app[0].typename = "MyUDPApp"

无需扩展WirelessHost,因为它已经包含名为app的模块矢量,可以使用各种应用程序模块对其进行配置。您应该检查各种示例,如何在其中配置应用程序。