回顾复习2023年8月的《★修改Exata6.2源码:〔修改Bellmanford最短路径路由的衡量标准从【路由跳数】改为【“路由器节点间的物理距离”】,并动画演示〕》,VS2015调试Exata,跟踪调试修改后的[ routing_bellmanford.cpp ]源码,确认修改版的[ routing_bellmanford.cpp ]源码,能够将”跳数度量”更改为”路由器节点之间的物理距离度量”,并根据[发送节点]与[目的节点]之间的距离进行路由:
★[跳数度量]更改为[距离度量]后的 routing_bellmanford 算法←Exata调试分析
修改的距离度量版[routing_bellmanford.cpp]中添加如下源码,用于计算两个路由器节点之间的物理距离(除以1000,得到㎞量纲)
计算两个路由器节点之间的物理距离(除以1000,得到㎞量纲)←修改的距离度量版[routing_bellmanford.cpp]源码
// C:\Scalable\Exata6.2Source__DEBUG_1\libraries\developer\src\routing_bellmanford.cpp #pragma region // JSLS添加:【步骤③】计算【[发送节点]与[接收节点]之间的物理距离】,用于 更新路由表中的路由距离// 需要用到《 C:\Scalable\Exata6.2Source__DEBUG_1\include\coordinates.h 》的 // 第493行:/*BOOL COORD_CalcDistance(int coordinateSystemType,const Coordinates* position1,const Coordinates* position2,CoordinateType* distance);*/double distanceBetweenTwoNodes; // 单位:米。后续需要转化为 ㎞ 千米。Coordinates sendNodePosition; // 发送节点 的 坐标位置Coordinates recvNodePosition; // 接收节点 的 坐标位置MOBILITY_ReturnCoordinates(sendNode, &sendNodePosition);MOBILITY_ReturnCoordinates(node, &recvNodePosition);printf("JSLS: sendNodePosition and recvNodePosition have been got! \n");COORD_CalcDistance(NODE_GetTerrainPtr(node)->getCoordinateSystem(),&sendNodePosition,&recvNodePosition,&distanceBetweenTwoNodes);printf("JSLS: The distance from [sendNodePosition] to [recvNodePosition] is %f \n", distanceBetweenTwoNodes);std::cout.flush(); // "stdio.h"// JSLS备注: [COORD_CalcDistance]计算出来的距离单位是 米 。后续作为【路由距离度量】时需要用 千米(㎞)int distance_in_km = 0;distance_in_km = (int)(distanceBetweenTwoNodes / 1000);if (0 == distance_in_km) //假如 两个节点之间距离【不够】 1㎞,设置为 1㎞。{distance_in_km = 1;}if (32767 < distance_in_km) //假如 两个节点之间距离【大于】 32767㎞,★这是 short 类型的 最大正数值★,设置为 -1㎞,表示越界。{distance_in_km = -1; // JSLS@2023年8月11日:暂且假设 两颗卫星路由器之间距离 小于3.2767万㎞ 。否则,设置为 -1 表示越界。}///// JSLS特别备注:★复用 Node->numAtmInterfaces 字段 ★ →→→ 用于存储[distance_in_km],即【路由距离度量(㎞)】// 表示 node接收节点 与 【(发送路由公告)的发送节点】之间的【路由距离度量(㎞)】///node->numAtmInterfaces = distance_in_km; // ★复用 Node->numAtmInterfaces 字段 ★ 表示【路由距离度量(㎞)】#pragma endregion // JSLS添加:【步骤③】计算【[发送节点]与[接收节点]之间的物理距离】,用于 更新路由表中的路由距离
调试跟踪修改的距离度量版[routing_bellmanford.cpp]源码,非常容易得到〔trace-bellmanford【Exata仿真工程】〕网络拓扑中各路由器节点之间的物理距离,从Exata输出日志另存为打包的《Exata仿真输出日志.txt.zip》文件中,可以提取到【Exata仿真日志:提取节点间距离(除以1000,得到【㎞】单位)】:
Exata仿真日志:提取节点间距离(除以1000,得到【㎞】单位)
JSLS: sendNodeID = 1 recvNodeID = 2
JSLS: sendNode = 0x577f5a60
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 58069.056091 JSLS: sendNodeID = 2 recvNodeID = 3
JSLS: sendNode = 0x5791b850
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 23872.837327 JSLS: sendNodeID = 2 recvNodeID = 5
JSLS: sendNode = 0x5791b850
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 61903.603888 JSLS: sendNodeID = 1 recvNodeID = 5
JSLS: sendNode = 0x577f5a60
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 35712.226169 JSLS: sendNodeID = 5 recvNodeID = 2
JSLS: sendNode = 0x575f3590
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 61903.603888 JSLS: sendNodeID = 5 recvNodeID = 6
JSLS: sendNode = 0x575f3590
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 43494.595698 JSLS: sendNodeID = 5 recvNodeID = 7
JSLS: sendNode = 0x575f3590
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 117848.625204 JSLS: sendNodeID = 1 recvNodeID = 7
JSLS: sendNode = 0x577f5a60
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 97778.188297 JSLS: sendNodeID = 7 recvNodeID = 6
JSLS: sendNode = 0x59b4c010
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 94036.093233 JSLS: sendNodeID = 7 recvNodeID = 4
JSLS: sendNode = 0x59b4c010
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 82296.332509 JSLS: sendNodeID = 3 recvNodeID = 4
JSLS: sendNode = 0x594e7830
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 38820.558196 JSLS: sendNodeID = 3 recvNodeID = 6
JSLS: sendNode = 0x594e7830
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 49675.286692 JSLS: sendNodeID = 6 recvNodeID = 4
JSLS: sendNode = 0x575f3ac0
JSLS: sendNodePosition and recvNodePosition have been got!
JSLS: The distance from [sendNodePosition] to [recvNodePosition] is 60472.108764
将各路由器节点之间的距离值,标注在Exata仿真工程的视图上,如下图所示:
一种确认上述距离值是否正确的一个非常简易的方法,是根据“Exata中的【顶部】和【左边】类似Word中标尺的X-Y坐标系、以及Exata菜单栏中实时显示当前光标所在的X-Y坐标值”进行手动计算。
例如下图中节点[5]和节点[1]之间距离的‘所见即所得’的粗略计算过程为:
得到节点[5]和节点[1]之间距离distance为 35757 米,即35㎞,结果正确!
禁用Exata源码调试断点,让Exata GUI界面显示CBR应用数据的网络路由方向和网络路由路径,可以得到如下的GIF动画图片:
这里值得说明的是,如果是默认的未修改的原版本的“路由跳数度量”的[routing_bellmanford.cpp]源码,上述GIF动画图片中,节点[1]到节点[4]的网络路由路径将是[1]→[7]→[4],只有2跳;而不是基于‘路径度量’最短路由的[1]→[2]→[3]→[4]。
仿真工程下载地址:
https://download.csdn.net/download/hardwork617s/89817081