如何在 OMNeT++ 仿真期间更改网络配置?
How to change configuration of network during simulation in OMNeT++?
我想在OMNeT++中修改element的.ini文件的一些参数,比如一个节点的传输速率,在模拟过程中运行,例如当节点收到一些控制消息时。
我发现信息说可以以某种方式循环配置如下:some_variable = ${several values },但是 .ini 文件中没有条件子句,也无法将来自 C++ 函数的任何数据传递给这些文件(就我而言)。
我用的是INET,可能其他型号的用户已经被这个问题困扰了。
如果你想在模拟过程中改变一些值,你可以在你的 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++ User Manual
中的相关部分
虽然您当然可以手动更改 volatile parameters,但 OMNeT++(据我所知)不提供在运行时自动更改参数的集成支持。
但是,您可以编写一些模型代码 changes volatile parameters programatically。
I found information saying that it's possible to somehow loop the configuration stated as: some_variable = ${several values}, but there are no conditional clauses in .ini files and no way to pass to those files any data from C++ functions (as far as I'm concerned).
事实上,您可以使用 INI 文件中内置的 constraint 表达式。这将允许您为给定的配置创建运行,同时遵守指定的 constraint(条件)。
但是,此约束仅适用于 .ini 文件中指定的参数,即,如果您尝试更改的变量是作为代码的一部分动态计算的,这将无济于事
下面,我从 .ini 文件中为您提供一个相当复杂的 "code-snippet",它使用了您提到的许多内置函数(变量迭代、条件等)
# 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 #
上面的代码创建了 t0
到 t3
的所有可能的时间值组合,其中它们可以取 0.1
和 0.9
之间的值。
t0
和t3
分别是起点和终点。 t1
和 t2
取基于它们的值。
t1
将取 t0
和 t3
之间的值,每次递增 0.1
(请参阅上面的语法)。 t2
也是如此。
但是,我希望 t0
始终小于 t1
,t1
小于 t2
,t2
小于 t3
.我在 constraint
部分指定了这些条件。
我相信,通读手册的 this 部分将帮助您找到解决方案。
我想在OMNeT++中修改element的.ini文件的一些参数,比如一个节点的传输速率,在模拟过程中运行,例如当节点收到一些控制消息时。
我发现信息说可以以某种方式循环配置如下:some_variable = ${several values },但是 .ini 文件中没有条件子句,也无法将来自 C++ 函数的任何数据传递给这些文件(就我而言)。
我用的是INET,可能其他型号的用户已经被这个问题困扰了。
如果你想在模拟过程中改变一些值,你可以在你的 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++ User Manual
中的相关部分虽然您当然可以手动更改 volatile parameters,但 OMNeT++(据我所知)不提供在运行时自动更改参数的集成支持。
但是,您可以编写一些模型代码 changes volatile parameters programatically。
I found information saying that it's possible to somehow loop the configuration stated as: some_variable = ${several values}, but there are no conditional clauses in .ini files and no way to pass to those files any data from C++ functions (as far as I'm concerned).
事实上,您可以使用 INI 文件中内置的 constraint 表达式。这将允许您为给定的配置创建运行,同时遵守指定的 constraint(条件)。
但是,此约束仅适用于 .ini 文件中指定的参数,即,如果您尝试更改的变量是作为代码的一部分动态计算的,这将无济于事
下面,我从 .ini 文件中为您提供一个相当复杂的 "code-snippet",它使用了您提到的许多内置函数(变量迭代、条件等)
# 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 #
上面的代码创建了 t0
到 t3
的所有可能的时间值组合,其中它们可以取 0.1
和 0.9
之间的值。
t0
和t3
分别是起点和终点。 t1
和 t2
取基于它们的值。
t1
将取 t0
和 t3
之间的值,每次递增 0.1
(请参阅上面的语法)。 t2
也是如此。
但是,我希望 t0
始终小于 t1
,t1
小于 t2
,t2
小于 t3
.我在 constraint
部分指定了这些条件。
我相信,通读手册的 this 部分将帮助您找到解决方案。