1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-03 15:56:13 +08:00

着手对邻接状态路由表计算器进行测试

This commit is contained in:
free will
2022-06-07 17:30:53 +08:00
parent d8143d3ad9
commit 3afa39df5f
+79 -2
View File
@@ -8,7 +8,84 @@
package route
import "testing"
import (
"fmt"
common2 "minlib/common"
"minlib/logicface"
"mlsr/common"
"mlsr/lsa"
"mlsr/lsdb"
"testing"
)
//
// TestLinkStateRoutingTableCalculator_CalculateOnePath
// @Description: 测试普通的路径计算
// @param t
//
func TestLinkStateRoutingTableCalculator_CalculateOnePath(t *testing.T) {
// 1. 构造邻接状态路由表计算器
rtc := new(LinkStateRoutingTableCalculator)
// 1.1 构造LSDB
// 配置文件初始化
mlsrConfig, err := common.ParseConfig(testConfigPath)
if err != nil {
fmt.Println("配置文件解析错误")
}
// 调度器初始化
sche := new(lsdb.MlsrScheduler)
sche.Init()
// LogicFace初始化(假设初始化,暂时用不到)
face := new(logicface.LogicFace)
// LSDB初始化
mlsdb := new(lsdb.Lsdb)
mlsdb.Init(mlsrConfig, sche, face)
// 安装本机adjlsa
mlsdb.BuildAndInstallOwnAdjLsa()
// todo 传入一些其它虚拟lsa,这些lsa与本机lsa共同形成一个小型路由拓扑
// 1.2 构造RouterMap
lsas, err := mlsdb.GetLSAsByType(lsa.LsaADJACENCYType)
if err != nil {
common2.LogError("Get Lsa in calculateLsRoutingTable error, ", err)
}
common2.LogInfo("邻接lsa数目: ", len(lsas))
rMap := new(RouterMap)
rMap.Init()
err = rMap.CreateFromAdjLsdb(lsas)
// 打印rm
common2.LogInfo(rMap.ToString())
// 1.3 根据RouterMap,和lsdb中的adjlsa,构造邻接矩阵
// 设置路由器数目
rtc.SetRouterNum(rMap.GetMapSize())
// 分配矩阵空间
rtc.allocateAdjMatrix()
// 初始化矩阵值
rtc.initMatrix()
// 构造矩阵
err = rtc.makeAdjMatrix(mlsdb, rMap)
if err != nil {
common2.LogError("邻接矩阵构造失败")
}
// 1.4 打印输出路由表计算器
fmt.Println(rtc.ToString())
fmt.Println("源路由器的邻接数目:", rtc.getNumOfLinkfromAdjMatrix(0))
fmt.Println("另一个路由器的邻接数目:", rtc.getNumOfLinkfromAdjMatrix(1))
// 2. 执行单源最短路径算法
rtc.doDijkstraPathCalculation(0)
// todo 查看执行结果
}
//
// TestLinkStateRoutingTableCalculator_CalculateMutilPath
// @Description: 测试多路径计算
// @param t
//
func TestLinkStateRoutingTableCalculator_CalculateMutilPath(t *testing.T) {
func TestLinkStateRoutingTableCalculator_CalculatePath(t *testing.T) {
}