在OMNeT++中,如何在模拟过程中更改网络配置

How to change configuration of network during simulation in OMNeT++?

本文关键字:网络 配置 过程中 OMNeT++ 模拟      更新时间:2023-10-16

我想在模拟运行期间,例如当节点接收到一些控制消息时,修改OMNeT++中元素的.ini文件的一些参数,比如节点的传输速率。

我发现有信息表明,可以以某种方式循环如下所述的配置:some_variable=${几个值},但.ini文件中没有条件子句,也没有办法将C++函数的任何数据传递给这些文件(就我而言)。

我使用INET,但可能其他一些型号的用户已经遇到了这样的问题。

我发现有信息表明,可以以某种方式循环如下所述的配置:some_variable=${几个值},,但.ini文件中没有条件子句,也没有办法将C++函数的任何数据传递给这些文件(就我而言)。

实际上,您可以在INI文件中使用内置的约束表达式。这将允许您为给定配置创建运行,同时遵守指定的约束(条件)。

但是,这个约束只适用于.ini文件中指定的参数,也就是说,如果您试图更改的变量是作为代码的一部分动态计算的,这对您没有帮助

下面,我从.ini文件中为您提供了一个相当复杂的"代码片段",它使用了您提到的许多内置函数(变量迭代、条件等)

# Parameter assignment using iteration loops and constrains #
# first define the static values on which the others depend #
scenario.node[*].application.ADVlowerBound = ${t0= 0.1}s
scenario.node[*].application.aggToServerUpperBound = ${t3= 0.9}s
#
## assign values to "dependent" parameters using variable names and loop iterations #
scenario.node[*].application.ADVupperBound = ${t1= ${t0}..${t3} step 0.1}s        # ADVupperBound == t1; t1 will take values starting from t0 to t3 (0.1 - 0.9) iterating 0.1
scenario.node[*].application.CMtoCHupperBound = ${t2= ${t0}..${t3} step 0.1}s
#
## connect "dependent" parameters to their "copies" -- this part of the snippet is only variable assignment.
scenario.node[*].application.CMtoCHlowerBound = ${t11 = ${t1}}s
scenario.node[*].application.joinToServerLowerBound = ${t12 = ${t1}}s
#
scenario.node[*].application.aggToServerLowerBound = ${t21 = ${t2}}s
scenario.node[*].application.joinToServerUpperBound = ${t22 = ${t2}}s
#
constraint = ($t0) < ($t1) && ($t1) < ($t2) && ($t2) < ($t3)
# END END END #

上面的代码创建了t0t3的所有可能的时间值组合,其中它们可以取0.10.9之间的值。

t0t3分别是起点和终点。CCD_ 7和CCD_。

t1每次递增0.1时将取t0t3之间的值(参见上面的语法)。t2也是如此。

但是,我希望t0总是小于t1t1小于t2t2小于t3。我在constraint部分中指定了这些条件。

我相信,仔细阅读本手册的这一部分,将有助于您找到解决方案。

如果你想在模拟过程中更改一些值,你可以在C++代码中这样做。类似于:

handleMessage(cMessage *msg){
if(msg->getKind() == yourKind){  // replace yourKind with the one you are using for these messages
transmission_rate = new_value;
}

您所指的some_variable=${几个值}可以用于使用不同的参数执行多次运行。例如,一次运行的速率为1s,一次为2s,另一次为10s。那就是:

transsmission_rate = ${1, 2, 10}s

有关如何使用此类值(如循环)的更多详细信息,请参阅OMNeT++用户手册中的相关章节

虽然您当然可以手动更改volatile参数,但OMNeT++(据我所知)不提供在运行时自动更改参数的集成支持。

但是,您可以编写一些模型代码,以编程方式更改volatile参数。