mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-07 05:49:30 +08:00
106 lines
2.6 KiB
Go
106 lines
2.6 KiB
Go
// Package Calculator
|
|
// @Author: Wang Feng
|
|
// @Description:
|
|
// @Version: 0.1.0
|
|
// @Date: 2022/5/10 16:53
|
|
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
|
//
|
|
|
|
package route
|
|
|
|
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
|
|
// 配置文件初始化
|
|
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 := 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())
|
|
}
|
|
|
|
//
|
|
// TestRouterMap_Store
|
|
// @Description: 测试RouterMap
|
|
// @param t
|
|
//
|
|
func TestRouterMap_Store(t *testing.T) {
|
|
iden, _ := component.CreateIdentifierByString("/test/weforever")
|
|
iden1, _ := component.CreateIdentifierByString("/test/weforever1")
|
|
iden2, _ := component.CreateIdentifierByString("/test/weforever2")
|
|
// 存入
|
|
rmap := new(RouterMap)
|
|
rmap.Init()
|
|
rmap.Store(iden)
|
|
rmap.Store(iden1)
|
|
rmap.Store(iden2)
|
|
|
|
// 取出标识
|
|
index, b := rmap.GetMappingNoByRouterName(iden2)
|
|
fmt.Println(index, b)
|
|
|
|
// 取出一个同URI的标识
|
|
idenNew2, _ := component.CreateIdentifierByString("/test/weforever2")
|
|
index, b = rmap.GetMappingNoByRouterName(idenNew2)
|
|
fmt.Println(index, b)
|
|
|
|
// 取出Iden
|
|
idenCat, bb := rmap.GetRouterNameByMappingNo(0)
|
|
fmt.Println(idenCat.ToUri(), bb)
|
|
idenCat, bb = rmap.GetRouterNameByMappingNo(1)
|
|
fmt.Println(idenCat.ToUri(), bb)
|
|
idenCat, bb = rmap.GetRouterNameByMappingNo(2)
|
|
fmt.Println(idenCat.ToUri(), bb)
|
|
idenCat, bb = rmap.GetRouterNameByMappingNo(3)
|
|
fmt.Println(bb)
|
|
|
|
// 查看map大小
|
|
fmt.Println(rmap.GetMapSize())
|
|
|
|
// 删除后再查看
|
|
rmap.delete(iden)
|
|
rmap.delete(idenNew2)
|
|
fmt.Println(rmap.GetMapSize())
|
|
idenCat, bb = rmap.GetRouterNameByMappingNo(0)
|
|
fmt.Println(bb)
|
|
idenCat, bb = rmap.GetRouterNameByMappingNo(2)
|
|
fmt.Println(bb)
|
|
}
|