1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-06 12:29:27 +08:00

测试routermap从lsdb中构建uri到int的映射

This commit is contained in:
free will
2022-06-06 18:05:28 +08:00
parent e315bc868d
commit 925ad0e7c8
2 changed files with 48 additions and 2 deletions
+22
View File
@@ -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: 存入一个路由器标识
+26 -2
View File
@@ -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())
}
//