mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-10-04 19:42:02 +08:00
增加lsdb中若干函数的测试:构建并安装namelsa 安装lsa 构建并安装本机adjlsa 对来源于其它路由器的lsa进行到期自动删除
This commit is contained in:
1 parent
30e5044896
commit
e315bc868d
2 files changed
+104
-6
No files matched your search
+1
-2
@@ -99,8 +99,7 @@ func (l *Lsdb) Init(mc *common.MlsrConfig, ms *MlsrScheduler,
|
||||
//}
|
||||
|
||||
// 构建并安装自己的名称LSA
|
||||
// todo 先测试其它项
|
||||
//l.BuildAndInstallOwnNameLsa()
|
||||
l.BuildAndInstallOwnNameLsa()
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
+103
-4
@@ -12,6 +12,7 @@ import (
|
||||
"fmt"
|
||||
common2 "minlib/common"
|
||||
"minlib/component"
|
||||
"minlib/encoding"
|
||||
"minlib/logicface"
|
||||
"mlsr/common"
|
||||
"mlsr/lsa"
|
||||
@@ -125,17 +126,80 @@ func TestLsdb_ScheduleLsaExpiration(t *testing.T) {
|
||||
for true {
|
||||
b := lsdb.DoesLsaExist(adjLsa)
|
||||
common2.LogInfo("是否存在:" + strconv.FormatBool(b))
|
||||
lsaCache := lsdb.FindLsa(adjLsa.GetOriginRouter(), adjLsa.GetType())
|
||||
if lsaCache != nil {
|
||||
common2.LogInfo(lsaCache.ToString())
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TestLsdb_InstallLsa
|
||||
// @Description: 测试安装lsa
|
||||
// TestLsab_InstallLsa
|
||||
// @Description: 测试安装lsa。安装lsa时会根据过期时间来设置多久后删除或更新该lsa
|
||||
// @param t
|
||||
//
|
||||
func TestLsdb_InstallLsa_DoesExist(t *testing.T) {
|
||||
func TestLsab_InstallLsa(t *testing.T) {
|
||||
// 1. 初始化LSDB
|
||||
// 配置文件初始化
|
||||
mlsrConfig, err := common.ParseConfig(testConfigPath)
|
||||
if err != nil {
|
||||
common2.LogInfo("配置文件解析错误")
|
||||
}
|
||||
// 调度器初始化
|
||||
sche := new(MlsrScheduler)
|
||||
sche.Init()
|
||||
// LogicFace初始化(假设初始化,暂时用不到)
|
||||
face := new(logicface.LogicFace)
|
||||
// LSDB初始化
|
||||
lsdb := new(Lsdb)
|
||||
lsdb.Init(mlsrConfig, sche, face)
|
||||
|
||||
// 2. 构建三秒后过期的时间戳,并将之设置到namelsa中
|
||||
timeExpire := uint64(time.Now().Add(3 * time.Second).UnixMilli())
|
||||
// 构造info
|
||||
namePrefixInfo := new(lsa.NameLsaNamePrefixInfo)
|
||||
namePrefixInfo.NamePrefix, _ = component.CreateIdentifierByString("/min/pku")
|
||||
namePrefixInfo.InsertSource("/wechat")
|
||||
namePrefixInfo.InsertSource("/qq")
|
||||
// 构造nameLSA
|
||||
nameLsa := new(lsa.NameLsa)
|
||||
nameLsa.LsaBase = lsa.LsaBase{
|
||||
SelfEncodingBase: encoding.SelfEncodingBase{},
|
||||
LsaExpirationTime: lsa.LsaExpirationTime{},
|
||||
LsaSequenceNumber: lsa.LsaSequenceNumber{},
|
||||
LsaOriginRouterIdentifier: nil,
|
||||
}
|
||||
nameLsa.SetLsaSequenceNumber(111)
|
||||
nameLsa.SetLsaExpirationTime(timeExpire)
|
||||
routerIdent, _ := component.CreateIdentifierByString("/pku/router")
|
||||
nameLsa.SetOriginRouter(routerIdent)
|
||||
nameLsa.InsertNamePrefixInfo(namePrefixInfo)
|
||||
|
||||
// 3. 安装到lsdb
|
||||
lsdb.InstallLsa(nameLsa)
|
||||
|
||||
// 4. 不断循环查询lsdb中是否存在该lsa
|
||||
i := 0
|
||||
for true {
|
||||
b := lsdb.DoesLsaExist(nameLsa)
|
||||
common2.LogInfo("是否存在:" + strconv.FormatBool(b))
|
||||
lsaCache := lsdb.FindLsa(nameLsa.GetOriginRouter(), nameLsa.GetType())
|
||||
if lsaCache != nil {
|
||||
common2.LogInfo(lsaCache.ToString())
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TestName_BuildAndInstallAdjLsa
|
||||
// @Description: 测试构建本机的adjlsa
|
||||
// @param t
|
||||
//
|
||||
func TestName_BuildAndInstallAdjLsa(t *testing.T) {
|
||||
// 1. 初始化LSDB
|
||||
// 配置文件初始化
|
||||
mlsrConfig, err := common.ParseConfig(testConfigPath)
|
||||
@@ -151,5 +215,40 @@ func TestLsdb_InstallLsa_DoesExist(t *testing.T) {
|
||||
lsdb := new(Lsdb)
|
||||
lsdb.Init(mlsrConfig, sche, face)
|
||||
|
||||
// 2.
|
||||
// 2. 安装本机adjlsa
|
||||
lsdb.BuildAndInstallOwnAdjLsa()
|
||||
|
||||
// 3. 打印lsdb中所有本机lsa
|
||||
lsas, _ := lsdb.LsaContainer.GetLSAsByType(lsa.LsaADJACENCYType)
|
||||
for i := 0; i < len(lsas); i++ {
|
||||
common2.LogInfo(lsas[i].ToString())
|
||||
}
|
||||
lsas, _ = lsdb.LsaContainer.GetLSAsByType(lsa.LsaNAMEType)
|
||||
for i := 0; i < len(lsas); i++ {
|
||||
common2.LogInfo(lsas[i].ToString())
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TestLsdb_InstallLsa
|
||||
// @Description: 测试安装lsa
|
||||
// @param t
|
||||
//
|
||||
func TestLsdb_InstallLsa_ScheduleAdjLsaBuild(t *testing.T) {
|
||||
// 1. 初始化LSDB
|
||||
// 配置文件初始化
|
||||
mlsrConfig, err := common.ParseConfig(testConfigPath)
|
||||
if err != nil {
|
||||
fmt.Println("配置文件解析错误")
|
||||
}
|
||||
// 调度器初始化
|
||||
sche := new(MlsrScheduler)
|
||||
sche.Init()
|
||||
// LogicFace初始化(假设初始化,暂时用不到)
|
||||
face := new(logicface.LogicFace)
|
||||
// LSDB初始化
|
||||
lsdb := new(Lsdb)
|
||||
lsdb.Init(mlsrConfig, sche, face)
|
||||
|
||||
// 2. todo 暂时不测,等linux机器上做实机测试
|
||||
}
|
||||
Reference in new issue
Block a user