From e315bc868dc47e4c323604d8ed355dbe54354458 Mon Sep 17 00:00:00 2001 From: free will <2647778488@qq.com> Date: Mon, 6 Jun 2022 17:46:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0lsdb=E4=B8=AD=E8=8B=A5?= =?UTF-8?q?=E5=B9=B2=E5=87=BD=E6=95=B0=E7=9A=84=E6=B5=8B=E8=AF=95=EF=BC=9A?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=B9=B6=E5=AE=89=E8=A3=85namelsa=20?= =?UTF-8?q?=E5=AE=89=E8=A3=85lsa=20=E6=9E=84=E5=BB=BA=E5=B9=B6=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E6=9C=AC=E6=9C=BAadjlsa=20=E5=AF=B9=E6=9D=A5=E6=BA=90?= =?UTF-8?q?=E4=BA=8E=E5=85=B6=E5=AE=83=E8=B7=AF=E7=94=B1=E5=99=A8=E7=9A=84?= =?UTF-8?q?lsa=E8=BF=9B=E8=A1=8C=E5=88=B0=E6=9C=9F=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lsdb/Lsdb.go | 3 +- lsdb/Lsdb_test.go | 107 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 6 deletions(-) diff --git a/lsdb/Lsdb.go b/lsdb/Lsdb.go index f928c97..7bcc44b 100644 --- a/lsdb/Lsdb.go +++ b/lsdb/Lsdb.go @@ -99,8 +99,7 @@ func (l *Lsdb) Init(mc *common.MlsrConfig, ms *MlsrScheduler, //} // 构建并安装自己的名称LSA - // todo 先测试其它项 - //l.BuildAndInstallOwnNameLsa() + l.BuildAndInstallOwnNameLsa() } // diff --git a/lsdb/Lsdb_test.go b/lsdb/Lsdb_test.go index 8a25ffc..f1a3855 100644 --- a/lsdb/Lsdb_test.go +++ b/lsdb/Lsdb_test.go @@ -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机器上做实机测试 }