diff --git a/route/RouterMap.go b/route/RouterMap.go index a2f6719..58d30f2 100644 --- a/route/RouterMap.go +++ b/route/RouterMap.go @@ -10,8 +10,10 @@ package route import ( + "encoding/json" "minlib/component" "mlsr/lsa" + "strconv" "sync" ) @@ -34,6 +36,26 @@ type RouterMap struct { mapLock *sync.RWMutex } +// +// ToString +// @Description: 转string,便于测试查看map的状态 +// @receiver m +// @return string +// +func (m *RouterMap) ToString() string { + s := "" + s += "MappingIndex:" + strconv.Itoa(m.mappingIndex) + " " + // 第一个map + dataType, _ := json.Marshal(m.routerToNumberMap) + dataString := string(dataType) + s += dataString + " " + // 第二个map + dataType, _ = json.Marshal(m.routerToNumberMap) + dataString = string(dataType) + s += dataString + " " + return s +} + // // Store // @Description: 存入一个路由器标识 diff --git a/route/RouterMap_test.go b/route/RouterMap_test.go index 118c83f..824de3b 100644 --- a/route/RouterMap_test.go +++ b/route/RouterMap_test.go @@ -12,24 +12,48 @@ import ( "fmt" common2 "minlib/common" "minlib/component" + "minlib/logicface" + "mlsr/common" "mlsr/lsa" "mlsr/lsdb" "testing" ) +const testConfigPath = "D:\\" + common.DefaultConfFileName + func TestRouterMap_CreateFromAdjLsdb(t *testing.T) { // 1. 构造LSDB - mLsdb := new(lsdb.Lsdb) + // 配置文件初始化 + mlsrConfig, err := common.ParseConfig(testConfigPath) + if err != nil { + fmt.Println("配置文件解析错误") + } + // 调度器初始化 + sche := new(lsdb.MlsrScheduler) + sche.Init() + // LogicFace初始化(假设初始化,暂时用不到) + face := new(logicface.LogicFace) + // LSDB初始化 + lsdb := new(lsdb.Lsdb) + lsdb.Init(mlsrConfig, sche, face) + // 强行构建邻接lsa + lsdb.BuildAndInstallOwnAdjLsa() // 2. 取出LSDB中的邻接LSA - lsas, err := mLsdb.GetLSAsByType(lsa.LsaADJACENCYType) + lsas, err := lsdb.GetLSAsByType(lsa.LsaADJACENCYType) if err != nil { common2.LogError("Get Lsa in calculateLsRoutingTable error, ", err) } + common2.LogInfo("邻接lsa数目: ", len(lsas)) + // 3. 构造RouterMap rMap := new(RouterMap) rMap.Init() err = rMap.CreateFromAdjLsdb(lsas) + + // 4. 打印RouterMap状态 + common2.LogInfo(rMap) + common2.LogInfo(rMap.ToString()) } //