mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-10-04 19:42:02 +08:00
试图消除BUG:未运行任何测试
This commit is contained in:
1 parent
0ebdc4e51d
commit
1e6b81c3c6
3 files changed
+128
-6
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"mlsr/lsa"
|
||||
"mlsr/lsdb"
|
||||
"mlsr/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
//
|
||||
@@ -47,13 +48,13 @@ type NamePrefixTable struct {
|
||||
func (t *NamePrefixTable) PrintSelf() {
|
||||
fmt.Println("------------------- Name Prefix Table begin: " + t.m_ownRouterName.ToUri() + " -----------------")
|
||||
fmt.Println("-----------------" + " 1.路由表项池 begin " + "-----------------")
|
||||
fmt.Println("路由表项池大小:", len(t.m_rtpool))
|
||||
fmt.Println("路由表项池大小:" + strconv.Itoa(len(t.m_rtpool)))
|
||||
for _, rtpe := range t.m_rtpool {
|
||||
fmt.Println(rtpe.ToString())
|
||||
}
|
||||
fmt.Println("-----------------" + " 1.路由表项池 end " + "-----------------")
|
||||
fmt.Println("----------------" + " 2.名称前缀列表 start " + "----------------")
|
||||
fmt.Println("名称前缀列表大小:", len(t.nptEntryList))
|
||||
fmt.Println("名称前缀列表大小:" + strconv.Itoa(len(t.nptEntryList)))
|
||||
for i := 0; i < len(t.nptEntryList); i++ {
|
||||
fmt.Println(t.nptEntryList[i].ToString())
|
||||
}
|
||||
|
||||
@@ -231,7 +231,127 @@ func TestNamePrefixTable_AddEntry(t *testing.T) {
|
||||
// @param t
|
||||
//
|
||||
func TestNamePrefixTable_RemoveEntry(t *testing.T) {
|
||||
// 1. 建立前置结构体(lsdb等)
|
||||
// 配置文件初始化
|
||||
mlsrConfig, err := common.ParseConfig(testConfigPath)
|
||||
if err != nil {
|
||||
common2.LogInfo("配置文件解析错误")
|
||||
}
|
||||
// 调度器初始化
|
||||
sche := new(lsdb.MlsrScheduler)
|
||||
sche.Init()
|
||||
// LogicFace初始化(假设初始化,暂时用不到)
|
||||
face := new(logicface.LogicFace)
|
||||
// LSDB初始化
|
||||
mlsdb := new(lsdb.Lsdb)
|
||||
mlsdb.Init(mlsrConfig, sche, face)
|
||||
|
||||
// 2. 打印lsdb中所有本机lsa
|
||||
lsas, _ := mlsdb.LsaContainer.GetLSAsByType(lsa.LsaADJACENCYType)
|
||||
for i := 0; i < len(lsas); i++ {
|
||||
common2.LogInfo(lsas[i].ToString())
|
||||
}
|
||||
lsas, _ = mlsdb.LsaContainer.GetLSAsByType(lsa.LsaNAMEType)
|
||||
for i := 0; i < len(lsas); i++ {
|
||||
common2.LogInfo(lsas[i].ToString())
|
||||
}
|
||||
fmt.Println("lsdb是否正在忙于构建lsdb: ", mlsdb.GetIsBuildAdjLsaScheduled())
|
||||
|
||||
// 3. 路由表初始化
|
||||
rt := new(RoutingTable)
|
||||
rt.Init(mlsrConfig, sche, mlsdb)
|
||||
|
||||
// 4. 名称前缀表初始化
|
||||
npt := new(NamePrefixTable)
|
||||
npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified)
|
||||
|
||||
// 5. 安装本机adjlsa => 将触发两个事件:A. 安排15s后做路由表计算;B.触发名称前缀表更新(本机lsa不做更新)
|
||||
mlsdb.BuildAndInstallOwnAdjLsa()
|
||||
// 看看npt
|
||||
fmt.Println("光秃秃啥也没有:")
|
||||
//npt.PrintSelf()
|
||||
|
||||
// 6. 插入一个条目:目的路由器没有在路由表中
|
||||
name, _ := component.CreateIdentifierByString("/someSourceNames")
|
||||
route, _ := component.CreateIdentifierByString("/routeAAA")
|
||||
npt.AddEntry(name, route)
|
||||
fmt.Println("加了一个虚空资源")
|
||||
//npt.PrintSelf()
|
||||
|
||||
// 7. 加入五星拓扑
|
||||
// 安装其它路由器的邻接lsa => A. 安排15s后做路由表计算;B.触发名称前缀表更新(邻接lsa只单单加入一个条目)
|
||||
// 传入一些其它虚拟lsa,这些lsa与本机lsa共同形成一个小型路由拓扑
|
||||
// 路由器B
|
||||
adjLsaB := testCreateAdjLsa("/routerB")
|
||||
adjInfoBA := testCreateAdjInfo(10, "/min/pkusz/routerA")
|
||||
adjInfoBE := testCreateAdjInfo(50, "/routerE")
|
||||
adjLsaB.Insert(adjInfoBA)
|
||||
adjLsaB.Insert(adjInfoBE)
|
||||
// 路由器C
|
||||
adjLsaC := testCreateAdjLsa("/routerC")
|
||||
adjInfoCA := testCreateAdjInfo(100, "/min/pkusz/routerA")
|
||||
adjInfoCE := testCreateAdjInfo(10, "/routerE")
|
||||
adjInfoCD := testCreateAdjInfo(60, "/routerD")
|
||||
adjLsaC.Insert(adjInfoCA)
|
||||
adjLsaC.Insert(adjInfoCD)
|
||||
adjLsaC.Insert(adjInfoCE)
|
||||
// 路由器E
|
||||
adjLsaE := testCreateAdjLsa("/routerE")
|
||||
adjInfoEB := testCreateAdjInfo(50, "/routerB")
|
||||
adjInfoEC := testCreateAdjInfo(10, "/routerC")
|
||||
adjInfoED := testCreateAdjInfo(20, "/routerD")
|
||||
adjLsaE.Insert(adjInfoEB)
|
||||
adjLsaE.Insert(adjInfoEC)
|
||||
adjLsaE.Insert(adjInfoED)
|
||||
// 路由器D
|
||||
adjLsaD := testCreateAdjLsa("/routerD")
|
||||
adjInfoDA := testCreateAdjInfo(30, "/min/pkusz/routerA")
|
||||
adjInfoDC := testCreateAdjInfo(60, "/routerC")
|
||||
adjInfoDE := testCreateAdjInfo(20, "/routerE")
|
||||
adjLsaD.Insert(adjInfoDA)
|
||||
adjLsaD.Insert(adjInfoDC)
|
||||
adjLsaD.Insert(adjInfoDE)
|
||||
mlsdb.InstallLsa(adjLsaB)
|
||||
mlsdb.InstallLsa(adjLsaC)
|
||||
mlsdb.InstallLsa(adjLsaD)
|
||||
mlsdb.InstallLsa(adjLsaE)
|
||||
for i := 0; i < 15; i++ {
|
||||
time.Sleep(time.Second)
|
||||
fmt.Println(i+1, " seconds later...")
|
||||
}
|
||||
fmt.Println("五星拓扑构建完成.")
|
||||
|
||||
// 8. 加入一个拓扑之上的资源
|
||||
nameC, _ := component.CreateIdentifierByString("/realSourcesInRouterC")
|
||||
routeC, _ := component.CreateIdentifierByString("/routerC")
|
||||
npt.AddEntry(nameC, routeC)
|
||||
fmt.Println("加了一个真实资源在路由器C上")
|
||||
//npt.PrintSelf()
|
||||
|
||||
// 9. 加入一个拓扑之上的资源,该资源被允许存在在两个路由器之上
|
||||
routeB, _ := component.CreateIdentifierByString("/routerB")
|
||||
npt.AddEntry(nameC, routeB)
|
||||
fmt.Println("将路由C之上的真实资源同时加在路由器B上")
|
||||
npt.PrintSelf()
|
||||
fmt.Println("")
|
||||
|
||||
// 10.1 删除一个虚空资源
|
||||
fmt.Println("111")
|
||||
npt.RemoveEntry(name, route)
|
||||
fmt.Println("222")
|
||||
fmt.Println("---------- 删除一个虚空资源 -----------")
|
||||
npt.PrintSelf()
|
||||
|
||||
// 10.2 删除一个在两个路由器上的资源标识,只删除某个路由器上的该资源
|
||||
npt.RemoveEntry(nameC, routeB)
|
||||
fmt.Println("--------------- 删除一个在两个路由器上的资源标识 ------------------")
|
||||
npt.PrintSelf()
|
||||
|
||||
// 10.3 删除一个路由器标识
|
||||
routeE, _ := component.CreateIdentifierByString("/routerE")
|
||||
npt.RemoveEntry(routeE, routeE)
|
||||
fmt.Println("---------- 删除一个路由器标识: routerE -----------")
|
||||
npt.PrintSelf()
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"mlsr/lsa"
|
||||
"mlsr/lsdb"
|
||||
"mlsr/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -57,13 +58,13 @@ type RoutingTable struct {
|
||||
//
|
||||
func (t *RoutingTable) PrintSelf() {
|
||||
fmt.Println("----------- Routing Table begin ---------")
|
||||
fmt.Println("len: ", len(t.rTable))
|
||||
fmt.Println("len: " + strconv.Itoa(len(t.rTable)))
|
||||
for i := 0; i < len(t.rTable); i++ {
|
||||
fmt.Println(t.rTable[i].ToString())
|
||||
}
|
||||
fmt.Println("路由计算间隔: ", t.m_routingCalcInterval.String())
|
||||
fmt.Println("是否正在计算: ", t.m_isRoutingTableCalculating)
|
||||
fmt.Println("是否安排计算: ", t.m_isRouteCalculationScheduled)
|
||||
fmt.Println("路由计算间隔: " + t.m_routingCalcInterval.String())
|
||||
fmt.Println("是否正在计算: " + strconv.FormatBool(t.m_isRoutingTableCalculating))
|
||||
fmt.Println("是否安排计算: " + strconv.FormatBool(t.m_isRouteCalculationScheduled))
|
||||
fmt.Println("本机路由器邻接lsa存在状态: ", t.m_ownAdjLsaExist)
|
||||
fmt.Println("----------- Routing Table end ---------")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user