在運行CORE tutorial 3中的mobility示例時,出現如下錯誤:
當看到這個問題的時候,并沒有仔細去分析日志和現象,在core-daemon的進程打印界面只看了一下最后的出錯堆棧:
2024-06-27 10:43:48,614 - ERROR - _server:_call_behavior - Exception calling application: int() argument must be a string, a bytes-like object or a real number, not ‘NoneType’
Traceback (most recent call last):
File “/opt/core/venv/lib/python3.10/site-packages/grpc/_server.py”, line 494, in _call_behavior
response_or_iterator = behavior(argument, context)
File “/opt/core/venv/lib/python3.10/site-packages/core/api/grpc/server.py”, line 916, in MobilityAction
node.mobility.stop(move_initial=True)
File “/opt/core/venv/lib/python3.10/site-packages/core/location/mobility.py”, line 1095, in stop
super().stop(move_initial=move_initial)
File “/opt/core/venv/lib/python3.10/site-packages/core/location/mobility.py”, line 839, in stop
self.session.mobility.sendevent(self)
File “/opt/core/venv/lib/python3.10/site-packages/core/location/mobility.py”, line 209, in sendevent
end_time = int(model.endtime)
TypeError: int() argument must be a string, a bytes-like object or a real number, not ‘NoneType’
然而,從這里很難看出什么問題。在網上各種搜索關鍵字也是毫無收獲。還懷疑是python3.10的版本問題,準備退回python3.9再試試。最后都是無勞而返。
偶然又留意了一下core-daemon最開始出錯的打印,才發現如下日志:
2024-06-27 10:42:13,978 - INFO - mobility:update_config - ns-2 scripted mobility configured for WLAN 3 using file: /usr/share/core/examples/tutorials/tutorial3/movements1.txt
2024-06-27 10:42:13,979 - ERROR - mobility:startup - mobility startup error
Traceback (most recent call last):
File “/opt/core/venv/lib/python3.10/site-packages/core/location/mobility.py”, line 136, in startup
self.set_model(node, model, config)
File “/opt/core/venv/lib/python3.10/site-packages/core/config.py”, line 360, in set_model
node.setmodel(model_class, config)
File “/opt/core/venv/lib/python3.10/site-packages/core/nodes/network.py”, line 754, in setmodel
self.mobility.update_config(config)
File “/opt/core/venv/lib/python3.10/site-packages/core/location/mobility.py”, line 904, in update_config
self.readscriptfile()
File “/opt/core/venv/lib/python3.10/site-packages/core/location/mobility.py”, line 916, in readscriptfile
file_path = self.findfile(self.file)
File “/opt/core/venv/lib/python3.10/site-packages/core/location/mobility.py”, line 998, in findfile
raise CoreError(f"invalid file: {file_path}")
core.errors.CoreError: invalid file: /usr/share/core/examples/tutorials/tutorial3/movements1.txt
原來這一段才是出錯的根本原因。而且在日志中的原因也說明非常明白:movements1.txt有問題。我檢查了一下,原因是我的系統對應路徑不存在這個文件。于是重新修改了一下此文件對應的路徑,可以順利運行此示例程序了。
現在在回頭看這個問題出現時的現象,在wlan3 mobility player這個窗口上也顯示了movements1.txt的路徑信息,只是自己沒有留意或者在意,導致問題的根本原因未被及時發現。
總結此次教訓,產生的原因是未仔細查看所有的日志,未仔細觀察所有的現象和界面信息,太過于浮躁。