Omnetpp.ini - 如何为主机参数创建循环

Omnetpp.ini - How to create loop for the host parametres

我有 1000 台主机。我需要模拟host[0]按照一个时间表通过PingApp连接其他999台主机的情况。

例如

**.host[0]*.numPingApps = 999 #number of hosts

**.host[0]*.pingApp[*].typename = "PingApp"

**.host[0]*.pingApp[*].packetSize = 42 B

**.host[0]*.pingApp[*].sendInterval = 1 s

**.host[0]*.pingApp[*].srcAddr = "host[0]"

**.host[0]*.pingApp[0].destAddr = "host[1]" 

**.host[0]*.pingApp[0].startTime = 0 s

**.host[0]*.pingApp[0].stopTime = 5s

**.host[0]*.pingApp[1].destAddr = "host[2]" 

**.host[0]*.pingApp[1].startTime = 0.1 s

**.host[0]*.pingApp[1].stopTime = 5.1 s

**.host[0]*.pingApp[2].destAddr = "host[3]" 

**.host[0]*.pingApp[2].startTime = 0.2 s

**.host[0]*.pingApp[2].stopTime = 5.2 s

**.host[0]*.pingApp[3].destAddr = "host[4]" 

**.host[0]*.pingApp[3].startTime = 0.3 s

**.host[0]*.pingApp[3].stopTime = 5.3 s

等等...

如何创建用于自动更改参数的循环:startTime、stopTime、destAddr、pingApp 的数量? 我需要在 pingApp 数量和 destAddr 每增加一点时将 startTime 和 stopTime 增加 0.1s。

请帮帮我! 谢谢!

其实每一台主机应该只有一个Ping应用。为实现您的目标,您可以使用以下设置:

**.host[*].numApps = 1
**.host[*].app[0].typename = "PingApp"

**.host[999].app[0].destAddr = "host[0]"
**.host[*].app[0].destAddr = "host[" + string(parentIndex()+1) + "]"

**.host[*].app[0].startTime = replaceUnit (0.1*(parentIndex()), "s")
**.host[*].app[0].stopTime = replaceUnit (5 + 0.1*(parentIndex()), "s")

paretnIndex() returns 主机向量中主机的索引,参考 OMNeT++ Manual。对于最后一个节点(即host[999]destAddr是手工设置的,因为parentIndex()+1会return1000,没有host[1000].
第二个 NED 函数 - replaceUnit() - 用于 add the unit 计算结果。

这是另一个准解决方案: 来自 PingApp 的文档:

string destAddr = default(""); // destination address(es), separated by spaces, "*" means all IPv4/IPv6 interfaces in entire simulation

Specifying '*' allows pinging ALL configured network interfaces in the whole simulation. This is useful to check if a host can reach ALL other hosts in the network (i.e. routing tables were set up properly).

To specify the number of ping requests sent to a single destination address, use the 'count' parameter. After the specified number of ping requests was sent to a destination address, the application goes to sleep for 'sleepDuration'. Once the sleep timer has expired, the application switches to the next destination and starts pinging again. The application stops pinging once all destination addresses were tested or the simulation time reaches 'stopTime'.

因此,如果您在网络中只有这些主机,并且您不介意一开始主机也会 ping 自身,destAddr="*"count=1

我结合了@Rudi 和@JerzyD 的答案。并得到了可行的解决方案:

**.host[0]*.numPingApps = 999
**.host[0]*.pingApp[*].typename = "PingApp"
**.host[0]*.pingApp[*].sendInterval = 1 s
**.host[0]*.pingApp[*].packetSize = 42 B
**.host[0]*.pingApp[0..998].destAddr = "host[" + string(index()+1) + "]"
**.host[0]*.pingApp[0..998].startTime = replaceUnit (0.1 * (index()), "s")
**.host[0]*.pingApp[0..998].stopTime = replaceUnit (5 + 0.1 * (index()), "s")