mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-03 15:56:13 +08:00
测试通过了定时删除其他路由器的LSA
This commit is contained in:
@@ -252,7 +252,7 @@ func (c *MlsrConfig) Init() {
|
||||
c.GeneralConfig.SyncInterestLifetime = 60 * 1000 // 1000-120*1000,范围是1秒到2分钟。默认1分钟
|
||||
|
||||
// 2. Log
|
||||
c.LogConfig.LogLevel = "INFO"
|
||||
c.LogConfig.LogLevel = "ALL"
|
||||
c.LogConfig.ReportCaller = true
|
||||
c.LogConfig.LogFormat = "text"
|
||||
c.LogConfig.LogFilePath = ""
|
||||
|
||||
+35
-7
@@ -70,6 +70,11 @@ func (l *Lsdb) Init(mc *common.MlsrConfig, ms *MlsrScheduler,
|
||||
l.face = _face
|
||||
// 序列号管理器
|
||||
l.sequencingManager = GetInstance()
|
||||
// 存储器
|
||||
err := l.LsaContainer.Init()
|
||||
if err != nil {
|
||||
common2.LogFatal("lsdb.LsaContainer init error, ", err.Error())
|
||||
}
|
||||
|
||||
// todo 构造sync
|
||||
|
||||
@@ -94,7 +99,8 @@ func (l *Lsdb) Init(mc *common.MlsrConfig, ms *MlsrScheduler,
|
||||
//}
|
||||
|
||||
// 构建并安装自己的名称LSA
|
||||
l.BuildAndInstallOwnNameLsa()
|
||||
// todo 先测试其它项
|
||||
//l.BuildAndInstallOwnNameLsa()
|
||||
}
|
||||
|
||||
//
|
||||
@@ -235,7 +241,7 @@ func (l *Lsdb) FindLsa(routerIdentifier *component.Identifier,
|
||||
}
|
||||
|
||||
//
|
||||
// IsLsaNew
|
||||
// isLsaNew
|
||||
// @Description: 返回来自某个路由器的seq是否表示新的LSA。
|
||||
// @receiver l
|
||||
// @param routerIdentifier
|
||||
@@ -243,15 +249,37 @@ func (l *Lsdb) FindLsa(routerIdentifier *component.Identifier,
|
||||
// @param seqNo
|
||||
// @return bool
|
||||
//
|
||||
func (l *Lsdb) IsLsaNew(routerIdentifier *component.Identifier,
|
||||
func (l *Lsdb) isLsaNew(routerIdentifier *component.Identifier,
|
||||
lsaType lsa.LsaType, seqNo uint64) bool {
|
||||
iLsa := l.FindLsa(routerIdentifier, lsaType)
|
||||
if iLsa.GetSeqNo() >= seqNo {
|
||||
return false
|
||||
// 没找到,说明是最新的
|
||||
if iLsa == nil {
|
||||
return true
|
||||
}
|
||||
return true
|
||||
// 找到了,且LSDB中的该lsa序列号小于要查的lsa,说明是最新的
|
||||
if iLsa.GetSeqNo() < seqNo {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//
|
||||
// IsLsaNew
|
||||
// @Description: 返回来自某个路由器的seq是否表示新的LSA。
|
||||
// @receiver l
|
||||
// @param fLsa
|
||||
// @return bool
|
||||
//
|
||||
func (l *Lsdb) IsLsaNew(fLsa lsa.ILsa) bool {
|
||||
return l.isLsaNew(fLsa.GetOriginRouter(), fLsa.GetType(), fLsa.GetSeqNo())
|
||||
}
|
||||
|
||||
//
|
||||
// InstallLsa
|
||||
// @Description: 将LSA安装到lsdb中
|
||||
// @receiver l
|
||||
// @param lsa
|
||||
//
|
||||
func (l *Lsdb) InstallLsa(lsa lsa.ILsa) {
|
||||
timeToExpire := l.lsaRefreshTime
|
||||
|
||||
@@ -265,7 +293,7 @@ func (l *Lsdb) InstallLsa(lsa lsa.ILsa) {
|
||||
|
||||
// 查看数据库中是否已有该LSA源路由器所发出的LSA
|
||||
lsaInDb := l.FindLsa(lsa.GetOriginRouter(), lsa.GetType())
|
||||
if lsa == nil {
|
||||
if lsaInDb == nil {
|
||||
// 如果没有:
|
||||
common2.LogDebug("Adding Lsa ", lsa.ToString())
|
||||
// 1. 就插入该LSA
|
||||
|
||||
@@ -10,9 +10,14 @@ package lsdb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
common2 "minlib/common"
|
||||
"minlib/component"
|
||||
"minlib/logicface"
|
||||
"mlsr/common"
|
||||
"mlsr/lsa"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const testConfigPath = "D:\\" + common.DefaultConfFileName
|
||||
@@ -64,3 +69,87 @@ func TestUnixTime(t *testing.T) {
|
||||
timeTemplate := "2006-01-02 15:04:05" // 时间戳常规类型
|
||||
fmt.Println(lsdb.uintToTime(timeExpire).Format(timeTemplate))
|
||||
}
|
||||
|
||||
//
|
||||
// TestLsdb_ScheduleLsaExpiration
|
||||
// @Description: 测试安排LSA过期事件
|
||||
// @param t
|
||||
//
|
||||
func TestLsdb_ScheduleLsaExpiration(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. 生成一个邻接Lsa
|
||||
adjLsa := new(lsa.AdjLsa)
|
||||
adjLsa.SetLsaExpirationTime(2000)
|
||||
adjLsa.SetLsaSequenceNumber(1234)
|
||||
adjLsa.LsaOriginRouterIdentifier, _ = component.CreateIdentifierByString("/min/pku")
|
||||
// 构造邻接信息部分
|
||||
// 先构造一个info
|
||||
linkCost := lsa.AdjLsaLinkCost{}
|
||||
linkCost.SetLinkCost(100)
|
||||
faceUri := lsa.AdjLsaLogicFaceUri{}
|
||||
faceUri.SetLogicFaceUri("uri")
|
||||
faceId := lsa.AdjLsaLogicFaceId{}
|
||||
faceId.SetLogicFaceId(77)
|
||||
iden, _ := component.CreateIdentifierByString("/pku/router1")
|
||||
adjInfo := lsa.NewAdjLsaAdjacencyInfo(linkCost, faceUri, faceId, iden, 123, 1)
|
||||
adjLsa.Insert(adjInfo)
|
||||
|
||||
// 3. 插入Lsdb
|
||||
err = lsdb.Emplace(adjLsa)
|
||||
if err != nil {
|
||||
common2.LogInfo("插入错误")
|
||||
}
|
||||
common2.LogInfo("插入成功")
|
||||
|
||||
// 4. 设置自动删除任务【3s+10s=13s】
|
||||
timeDur := 3 * time.Second
|
||||
lsdb.ScheduleLsaExpiration(adjLsa, timeDur)
|
||||
common2.LogInfo("???")
|
||||
|
||||
// 5. 不断循环查询lsdb中是否存在该lsa
|
||||
i := 0
|
||||
for true {
|
||||
b := lsdb.DoesLsaExist(adjLsa)
|
||||
common2.LogInfo("是否存在:" + strconv.FormatBool(b))
|
||||
time.Sleep(time.Second)
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TestLsdb_InstallLsa
|
||||
// @Description: 测试安装lsa
|
||||
// @param t
|
||||
//
|
||||
func TestLsdb_InstallLsa_DoesExist(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.
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ SyncProtocol = min-sync
|
||||
SyncInterestLifetime = 60000
|
||||
|
||||
[Log]
|
||||
LogLevel = INFO
|
||||
LogLevel = ALL
|
||||
ReportCaller = true
|
||||
LogFormat = text
|
||||
LogFilePath =
|
||||
|
||||
Reference in New Issue
Block a user