AODV网络中OMNeT++节点无法找到外部客户端静态路由求助
AODV仿真中外部通信路由缺失问题排查
我在AODV网络仿真里,想要让节点接收外部消息并返回,于是将某节点应用层设为UdpEchoApp,参考example/emulation/pinger的方法配置了mrt文件。节点eth0的IP地址为192.168.2.1,路由表中也存在对应静态路由,但向OMNeT++外部客户端发送消息时,提示无法找到192.168.2.2的路由,相关日志如下:
** Event #1457 t=4.898490315 Drone.host[19].ipv4.ip (Ipv4, id=927) on Ext-UDP--1 (inet::Packet, id=2651) INFO: Received (inet::Packet)Ext-UDP--1 (12 B) (inet::SequenceChunk) length = 12 B from upper layer. INFO (Aodv)Drone.host[19].aodv: Finding route for source <unspec> with destination 192.168.2.2 INFO (Aodv)Drone.host[19].aodv: Missing route for destination 192.168.2.2 DETAIL (Aodv)Drone.host[19].aodv: Queuing datagram, source <unspec>, destination 192.168.2.2 INFO (Aodv)Drone.host[19].aodv: Starting route discovery with originator 192.168.2.1 and destination 192.168.2.2 INFO (Aodv)Drone.host[19].aodv: Sending a Route Request with target 192.168.2.2 and TTL= 2
相关配置文件
run.sh
sudo ip link add veth0 type veth peer name veth1 sudo ip addr add 192.168.2.2 dev veth1 sudo ip link set veth0 up sudo ip link set veth1 up sudo ethtool --offload veth0 tx off rx off sudo ethtool --offload veth1 tx off rx off sudo route add -net 192.168.2.0 netmask 255.255.255.0 dev veth1 sudo route add -net 145.236.0.0 netmask 255.255.0.0 dev veth1 gateway 192.168.2.1
NED代码
package inet.examples.aodv.Drone; import inet.common.scenario.ScenarioManager; import inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator; import inet.networklayer.ipv4.RoutingTableRecorder; import inet.node.aodv.AodvRouter; import inet.physicallayer.wireless.unitdisk.UnitDiskRadioMedium; import inet.visualizer.common.IntegratedVisualizer; import inet.node.inet.Router; import inet.node.inet.StandardHost; network Drone { parameters: int numHosts; @display("bgb=944.376,745.56"); submodules: radioMedium: UnitDiskRadioMedium { parameters: @display("p=100,200;is=s"); } configurator: Ipv4NetworkConfigurator { parameters: config = xml("<config><interface hosts='*' address='145.236.x.x' netmask='255.255.x.x'/></config>"); @display("p=100,100;is=s"); } routingTableRecorder: RoutingTableRecorder { parameters: @display("p=100,300;is=s"); } visualizer: IntegratedVisualizer { parameters: @display("p=100,30"); } scenarioManager: ScenarioManager { parameters: script = default(xml("<scenario/>")); @display("p=100,400;is=s"); } host[numHosts]: AodvRouter { parameters: @display("i=device/pocketpc_s;r=,,#707070"); } connections allowunconnected: }
ini配置文件
[General] network = Drone scheduler-class = "inet::RealTimeScheduler" #realtimescheduler-scaling = 120 **.fcsMode = "computed" **.crcMode = "computed" *.numHosts = 20 num-rngs = 3 **.mobility.rng-0 = 1 #随机生成mobility模块的初始位置或速度 **.wlan[*].mac.rng-0 = 2 #生成所有WLAN接口的MAC地址。 # channel physical parameters **.wlan[*].typename = "AckingWirelessInterface" **.wlan[*].bitrate = 2Mbps **.wlan[*].mac.headerLength = 23B **.wlan[*].radio.typename = "UnitDiskRadio" **.wlan[*].radio.transmitter.headerLength = 96b **.wlan[*].radio.transmitter.communicationRange = 250m **.wlan[*].radio.transmitter.interferenceRange = 0m **.wlan[*].radio.transmitter.detectionRange = 0m **.wlan[*].radio.receiver.ignoreInterference = true *.host[19].numEthInterfaces = 1 *.host[19].eth[0].typename = "ExtLowerEthernetInterface" *.host[19].eth[0].device = "veth0" # mobility **.host[*].mobility.typename = "StationaryMobility" **.mobility.constraintAreaMinZ = 0m **.mobility.constraintAreaMaxZ = 0m **.mobility.constraintAreaMinX = 0m **.mobility.constraintAreaMinY = 0m **.mobility.constraintAreaMaxX = 600m **.mobility.constraintAreaMaxY = 600m # ping app (host[0] pinged by others) *.host[0].numApps = 2 *.host[0].app[0].typename = "PingApp" *.host[0].app[0].startTime = uniform(1s,5s) *.host[0].app[0].printPing = true *.host[0].app[1].typename = "UdpSink" *.host[0].app[1].localPort = 8000 *.host[19].ipv4.routingTable.routingFile = "peer.mrt" *.host[19].numApps=1 *.host[19].app[0].typename = "PingApp" *.host[19].app[0].destAddr = "192.168.2.2" # nic settings **.wlan[*].bitrate = 2Mbps # lifecycle **.hasStatus = true *.host[*].wlan[*].radio.transmitter.communicationRange = 250m *.host[0].app[0].destAddr = "host[1](ipv4)"
peer.mrt文件
ifconfig: # ethernet card (modelled by point-to-point link) 0 to router name: eth0 inet_addr: 192.168.2.1 Mask: 255.255.255.255 MTU: 1500 Metric: 1 POINTTOPOINT MULTICAST ifconfigend. route: #Destination Gateway Genmask Flags Metric Iface 0.0.0.0 * 0.0.0.0 G 0 eth0 192.168.2.2 * 255.255.255.255 H 1 eth0 routeend.
问题原因
- AODV路由优先级覆盖静态路由:
AodvRouter模块默认优先使用AODV协议路由表,即使配置了静态路由,AODV仍会尝试通过无线链路发现192.168.2.2的路由,而该地址属于外部物理网络,不在AODV无线拓扑内。 - 接口类型不匹配:peer.mrt中将eth0标记为
POINTTOPOINT,但veth是以太网广播接口,类型冲突导致静态路由无法被正确识别。 - 自动配置干扰:
Ipv4NetworkConfigurator会自动为所有主机分配145.236.x.x段地址,可能覆盖或干扰host[19]的eth0接口配置,导致静态路由条目被忽略。
解决方案
方案1:让AODV忽略外部子网
在ini文件中添加配置,告诉AODV模块不对192.168.2.0/24子网触发路由发现,直接使用静态路由:
*.host[19].aodv.ignoredDestPrefixes = "192.168.2.0/24"
方案2:修正peer.mrt接口配置
将peer.mrt中的接口类型改为广播型,同时统一子网掩码:
ifconfig: # ethernet card (modelled by point-to-point link) 0 to router name: eth0 inet_addr: 192.168.2.1 Mask: 255.255.255.0 MTU: 1500 Metric: 1 BROADCAST MULTICAST ifconfigend. route: #Destination Gateway Genmask Flags Metric Iface 192.168.2.0 * 255.255.255.0 N 0 eth0 192.168.2.2 * 255.255.255.255 H 1 eth0 routeend.
方案3:排除host[19]的自动配置
修改NED中Ipv4NetworkConfigurator的配置,避免其修改host[19]的接口和路由:
configurator: Ipv4NetworkConfigurator { parameters: config = xml("<config><interface hosts='*[!19]' address='145.236.x.x' netmask='255.255.x.x'/></config>"); @display("p=100,100;is=s"); }
方案4:验证veth链路连通性
启动仿真前,先测试veth链路是否正常:
ping 192.168.2.1 -I veth1
若不通,检查接口是否正常启动、权限是否足够,或是否有防火墙规则拦截。
内容的提问来源于stack exchange,提问作者frog
相关产品推荐
相关产品推荐

