测试路由表添加表项

This commit is contained in:
free will committed 2022-07-01 11:56:45 +08:00
1 parent 261cbd72ec
commit cd7ec6bf55
3 files changed
+70 -1

No files matched your search

+10
View File
@@ -41,6 +41,16 @@ func NewNextHop(uri string, cost uint64) (*NextHop, error) {
return nextHop, nil
}
//
// Init
// @Description: 参数初始化
// @receiver l
//
func (l *NextHop) Init(faceUri string, cost uint64) {
l.SetLogicFaceUri(faceUri)
l.SetRouteCost(cost)
}
//
// WireEncode
// @Description: 线速编码
+22 -1
View File
@@ -10,6 +10,7 @@ package route
import (
"errors"
"fmt"
common2 "minlib/common"
"minlib/component"
"minlib/encoding"
@@ -49,6 +50,24 @@ type RoutingTable struct {
m_hyperbolicState uint32
}
//
// PrintSelf
// @Description: 打印状态,用于测试
// @receiver t
//
func (t *RoutingTable) PrintSelf() {
fmt.Println("----------- Table beg ---------")
fmt.Println("len: ", len(t.rTable))
for i := 0; i < len(t.rTable); i++ {
fmt.Println(t.rTable[i].ToString())
}
fmt.Println("----------- Table end ---------")
fmt.Println("路由计算间隔: ", t.m_routingCalcInterval.String())
fmt.Println("是否正在计算: ", t.m_isRoutingTableCalculating)
fmt.Println("是否安排计算: ", t.m_isRouteCalculationScheduled)
fmt.Println("本机路由器邻接lsa存在状态: ", t.m_ownAdjLsaExist)
}
//
// Init
// @Description: 初始化
@@ -79,6 +98,8 @@ func (t *RoutingTable) Init(mc *common.MlsrConfig,
// 获取四个参数
ilsa := args[0].(lsa.ILsa)
updateType := args[1].(lsdb.LsdbUpdate)
common2.LogInfo("RoutingTable.bindFunc: ",
ilsa.GetOriginRouter().ToUri(), " ", updateType)
//var namesToAdd []*component.Identifier
//var namesToRemove []*component.Identifier
//if updateType == lsdb.REMOVED {
@@ -172,11 +193,11 @@ func (t *RoutingTable) AddNextHop(destRouter *component.Identifier, hop *NextHop
// 如果没有这条表项,则构建并加入
if rte == nil {
rte = new(RoutingTableEntry)
rte.SetDestination(destRouter)
rte.AddNextHop(hop)
t.rTable = append(t.rTable, rte)
} else {
// 如果有,则直接编辑该条目,增加一个下一跳.
// todo: 这块需要测试,是否在go中可以直接根据引用进行表项的修改
rte.AddNextHop(hop)
}
}
+38
View File
@@ -10,6 +10,7 @@ package route
import (
common2 "minlib/common"
"minlib/component"
"minlib/logicface"
"mlsr/common"
"mlsr/lsdb"
@@ -48,6 +49,43 @@ func TestRoutingTable_Init(t *testing.T) {
// @param t
//
func TestRoutingTable_AddNextHop(t *testing.T) {
// 1. 组件初始化
// 配置文件初始化
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. 路由表初始化
rt := new(RoutingTable)
rt.Init(mlsrConfig, sche, mlsdb)
// 加入一个新的条目
iden, _ := component.CreateIdentifierByString("/pkuiswhat")
hop := new(NextHop)
hop.Init("tcp://1.1.1.1", 77)
rt.AddNextHop(iden, hop)
// 打印
rt.PrintSelf()
// 加入一个旧条目
hopOld := new(NextHop)
hopOld.Init("udp://1.1.1.12", 88)
rt.AddNextHop(iden, hopOld)
// 打印
rt.PrintSelf()
// 再加一遍
rt.AddNextHop(iden, hopOld)
// 打印
rt.PrintSelf()
}
//