c++ - 在 OMNeT++ 中通过无线 channel 连接两个 UDP 模块

标签 c++ udp omnet++

我有一个模拟,其中两个模块 UDPBasicApp(客户端和服务器)通过以太网链接连接在一起。相反,我希望它们通过无线 channel 连接在一起。网络由以下 NED 文件定义:

package udpbasic;

import inet.networklayer.autorouting.ipv4.IPv4NetworkConfigurator;
import inet.nodes.ethernet.Eth10M;
import inet.nodes.inet.StandardHost;

network ClientServer
{
    @display("bgb=380,247");
    submodules:
        client: StandardHost 
        {
            @display("p=84,100");
        }
        server: StandardHost 
        {
            @display("p=278,100");
        }
        configurator: IPv4NetworkConfigurator 
        {
            @display("p=181,188");
        }
    connections:
        client.ethg++ <--> Eth10M <--> server.ethg++;
}

我知道我必须换行

client.ethg++ <--> Eth10M <--> server.ethg++;

定义以太网链接的地方。我可以连接客户端和服务器槽吗 无线链接?显然,我正在寻找最基本的配置。 我是 OMNeT++ 和 INET 的新手;我已经搜索了 INET API 引用,但没有 帮助很大。我会感谢任何建议。

最佳答案

我建议阅读 INET 3.0 中的无线教程。 https://github.com/inet-framework/inet/blob/master/tutorials/wireless/omnetpp.ini

Ini 文件:

[General]
# Some global configuration to make the model simpler

# At this point you should take a look at the NED files corresponding to this Ini file. 
# They are rather simple. The only interesting thing is that they are using parametrized types
# (i.e. like) so we will be able to change the type of the different modules from the Ini file.
# This allows us go through the tutorial only by changing parameter values in this file. 

# Limit the simulation to 25s 
sim-time-limit = 25s

# Let's configure ARP
# ARP in the real world is used to figure out the MAC address of a node from its IPv4 address.
# We do not want to use it in this wireless tutorial as it just adds some uninteresting 
# message exchanges before the real communication between the nodes can start. We will use 
# the GlobalARP module instead that can automatically provide all the MAC-IP assocoations 
# for the nodes out of band. 
**.arpType = "GlobalARP"

# Now we are ready to jump into the tutorial

[Config Wireless01] 
description = Two nodes communicating via UDP 
network = WirelessA

# Configure an application for hostA that sends a constant
# UDP traffic around 800Kbps (+ protocol overhead) 
*.hostA.numUdpApps = 1
*.hostA.udpApp[0].typename = "UDPBasicApp"
*.hostA.udpApp[0].destAddresses = "hostB"
*.hostA.udpApp[0].destPort = 5000
*.hostA.udpApp[0].messageLength = 1000B
*.hostA.udpApp[0].sendInterval = exponential(10ms)

# Configure an app that receives the USP traffic (and simply drops the data)
*.hostB.numUdpApps = 1
*.hostB.udpApp[0].typename = "UDPSink"
*.hostB.udpApp[0].localPort = 5000

# Configure the hosts to have a single "ideal" wireless NIC. An IdealWirelessNic
# can be configured with a maximum communication range. All packets withing range
# are always received successfully while out of range messages are never received.
# This is useful if we are not interested how the actual messages get to their destination,
# we just want to be sure that they get there once the nodes are in range.
*.host*.wlan[*].typename = "IdealWirelessNic"

# All radios and MACs should run on 1Mbps in our examples
**.bitrate = 1Mbps

# Mandatory physical layer parameters
*.host*.wlan[*].radio.transmitter.maxCommunicationRange = 500m

# Simplify the IdealWirelessNic even further. We do not care even if there are
# transmission collisions. Any number of nodes in range can transmit at the same time
# and the packets will be still successfully delivered.
*.host*.wlan[*].radio.receiver.ignoreInterference = true

# Result: HostA can send data to hostB using almost the whole 1Mbps bandwidth.

对应的NED文件:

package inet.tutorials.wireless;

import inet.networklayer.configurator.ipv4.IPv4NetworkConfigurator;
import inet.node.inet.INetworkNode;
import inet.physicallayer.contract.packetlevel.IRadioMedium;


// - create a network and specify the size to 500x500
// - drop an IPv4NetworkConfigurator and rename it to "configurator"
// - drop an IdealRadioMedium module and rename to "radioMedium"
// - drop two standardhosts at the 100,100 and 400,400 position and
//   rename them to hostA and hostB
network WirelessA
{
    @display("bgb=500,500");
    @figure[thruputInstrument](type=gauge; pos=370,90; size=120,120; maxValue=2500; tickSize=500; colorStrip=green 0.75 yellow 0.9 red;label=Number of packets received; moduleName=hostB.udpApp[0]; signalName=rcvdPk);
    string hostType = default("WirelessHost");
    string mediumType = default("IdealRadioMedium");
    submodules:
        configurator: IPv4NetworkConfigurator {
            @display("p=149,29");
        }
        radioMedium: <mediumType> like IRadioMedium {
            @display("p=309,24");
        }
        hostA: <hostType> like INetworkNode {
            @display("p=50,250");
        }
        hostB: <hostType> like INetworkNode {
            @display("p=450,250");
        }
}

关于c++ - 在 OMNeT++ 中通过无线 channel 连接两个 UDP 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31107430/

相关文章:

c++ - 尝试在 C++ OpenGL 中打印但返回一个整数?

c++ - 代码位于多个目录但目录结构相同的项目的 Makefile

c - 从服务器向客户端发送 UDP 消息

c++ - 在其他模块中通过 cPar 更改模型参数

omnet++ - 计算 Veins-LTE 中 SimpleServerApp 的端到端延迟

由自定义缓冲区支持的 C++ 固定大小 vector

c++ - istringstream 不在变量中存储任何内容

c# - C#中具有多个网络的UDP组播

networking - UDP 客户端 - 打开端口?

c++ - 如何在 omnet++ 中的模块上单独调用 finish()