mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-03 15:56:13 +08:00
LSDB:增加查看某个lsa是否存在、查找lsa功能
This commit is contained in:
@@ -12,34 +12,32 @@ package extensions
|
||||
|
||||
const (
|
||||
// Lsa for MLSR
|
||||
TlvMlsrLsaAdjacency = 401 // 表示MIR之间邻接关系信息的LSA
|
||||
TlvMlsrLsaNamePrefix = 402 // 表示名称前缀(内容标识、身份标识等以前缀形式命名的标识)信息的LSA
|
||||
TlvMlsrLsaCoordinate = 403 // 表示坐标信息的LSA
|
||||
TlvMlsrLsaAdjacency = 401 // 表示MIR之间邻接关系信息的LSA
|
||||
TlvMlsrLsaName = 402 // 表示名称前缀(内容标识、身份标识等以前缀形式命名的标识)信息的LSA
|
||||
TlvMlsrLsaCoordinate = 403 // 表示坐标信息的LSA
|
||||
|
||||
// 所有类型Lsa的必需部分
|
||||
TlvMlsrLsaBase = 410 // 表示LSA最基本信息:源MIR、序列号、过期时间
|
||||
TlvMlsrLsaExpirationTime = 420 // LSA过期时间
|
||||
TlvMlsrLsaSequenceNumber = 421 // LSA序列号
|
||||
TlvMlsrLsaBase = 410 // 表示LSA最基本信息:源MIR、序列号、过期时间
|
||||
TlvMlsrLsaExpirationTime = 420 // LSA过期时间
|
||||
TlvMlsrLsaSequenceNumber = 421 // LSA序列号
|
||||
|
||||
// AdjLsa的组件
|
||||
TlvMlsrAdjLsaLogicFaceId = 422 // logicface Id
|
||||
TlvMlsrAdjLsaLinkCost = 423 // 链路开销
|
||||
TlvMlsrAdjLsaLogicFaceUri = 424 // LogicFace前缀
|
||||
TlvMlsrAdjLsaAdjacencyInfo = 425 // 单条邻接信息
|
||||
TlvMlsrAdjLsaAdjacencyList = 426 // 一个邻接LSA包含的所有邻接信息
|
||||
TlvMlsrAdjLsaLogicFaceId = 422 // logicface Id
|
||||
TlvMlsrAdjLsaLinkCost = 423 // 链路开销
|
||||
TlvMlsrAdjLsaLogicFaceUri = 424 // LogicFace前缀
|
||||
TlvMlsrAdjLsaAdjacencyInfo = 425 // 单条邻接信息
|
||||
TlvMlsrAdjLsaAdjacencyList = 426 // 一个邻接LSA包含的所有邻接信息
|
||||
|
||||
// NameLsa的组件
|
||||
TlvMlsrNameLsaNamePrefixSource = 427 // 名称前缀的来源
|
||||
TlvMlsrNameLsaNamePrefixInfo = 428 // 单条名称前缀信息
|
||||
TlvMlsrNameLsaNamePrefixList = 429 // 一个名称LSA包含的所有名称前缀信息
|
||||
TlvMlsrNameLsaNamePrefixSource = 427 // 名称前缀的来源
|
||||
TlvMlsrNameLsaNamePrefixInfo = 428 // 单条名称前缀信息
|
||||
TlvMlsrNameLsaNamePrefixList = 429 // 一个名称LSA包含的所有名称前缀信息
|
||||
|
||||
// route模块涉及到的组件
|
||||
TlvMlsrConnectingLogicFaceUri = 441
|
||||
TlvMlsrRouteCost = 442
|
||||
TlvMlsrNextHop = 443
|
||||
TlvMlsrNextHopList = 444
|
||||
TlvMlsrRoutingTableEntry = 445
|
||||
TlvMlsrRoutingTable = 446
|
||||
|
||||
TlvMlsrRouteCost = 442
|
||||
TlvMlsrNextHop = 443
|
||||
TlvMlsrNextHopList = 444
|
||||
TlvMlsrRoutingTableEntry = 445
|
||||
TlvMlsrRoutingTable = 446
|
||||
)
|
||||
|
||||
|
||||
+2
-2
@@ -213,7 +213,7 @@ func (n *NameLsa) WireEncode(encoder *encoding.Encoder) (int, error) {
|
||||
totalLength += tmpLen
|
||||
|
||||
// TLV-Type
|
||||
tmpLen, err = encoder.PrependVarNumber(extensions.TlvMlsrLsaNamePrefix)
|
||||
tmpLen, err = encoder.PrependVarNumber(extensions.TlvMlsrLsaName)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -231,7 +231,7 @@ func (n *NameLsa) WireEncode(encoder *encoding.Encoder) (int, error) {
|
||||
//
|
||||
func (n *NameLsa) WireDecode(block *encoding.Block) error {
|
||||
// 检查 TLV-TYPE 是否正确
|
||||
if err := encoding.ExpectType(block.GetType(), extensions.TlvMlsrLsaNamePrefix); err != nil {
|
||||
if err := encoding.ExpectType(block.GetType(), extensions.TlvMlsrLsaName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// Package buntdb
|
||||
// @Author: Wang Feng
|
||||
// @Description:
|
||||
// todo: 需要注意的是,根据对NLSR源代码的阅读,可以看出其通过originRouterName和lsaType可唯一确定一个LSA。
|
||||
// todo 这就意味着,序列号只区分同一路由器同一类型LSA的新和旧,并不是如邻接LSA分成多个LSA进行传播。
|
||||
// todo MLSR可参考其设计,也可通过originRouter和序列号来确定唯一LSA。
|
||||
// 需要注意的是,根据对NLSR源代码的阅读,可以看出其通过originRouterName和lsaType可唯一确定一个LSA。
|
||||
// 这就意味着,序列号只区分同一路由器同一类型LSA的新和旧,并不是分成多个LSA进行传播。
|
||||
// MLSR参考其设计,同一路由器在另一路由器的LSDB中,仅保留最新序列号的两个LSA:邻接LSA、名称LSA。
|
||||
// @Version: 0.1.0
|
||||
// @Date: 2022/4/6 17:49
|
||||
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
@@ -127,6 +127,53 @@ func newLsa(lsaType lsa.LsaType) (lsa.ILsa, error) {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Exists
|
||||
// @Description: 判断某个lsa是否在内存数据库里
|
||||
// @receiver bdb
|
||||
// @param lsa
|
||||
// @return bool
|
||||
//
|
||||
func (bdb *LsaContainer_BuntDB) Exists(lsa lsa.ILsa) bool {
|
||||
errRes := bdb.db.View(func(tx *buntdb.Tx) error {
|
||||
// 获取key
|
||||
key := getKeyFromNameAndType(lsa.GetOriginRouter(), lsa.GetType())
|
||||
|
||||
// 获取value
|
||||
_, err := tx.Get(key)
|
||||
if err != nil {
|
||||
common2.LogDebug("buntdb Exists get key no found, because of ", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if errRes == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (bdb *LsaContainer_BuntDB) ExistsRouterNameAndType(routerIdentifier *component.Identifier, lsaType lsa.LsaType) bool {
|
||||
errRes := bdb.db.View(func(tx *buntdb.Tx) error {
|
||||
// 获取key
|
||||
key := getKeyFromNameAndType(routerIdentifier, lsaType)
|
||||
|
||||
// 获取value
|
||||
_, err := tx.Get(key)
|
||||
if err != nil {
|
||||
common2.LogDebug("buntdb ExistsRouterNameAndType get key no found, because of ", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if errRes == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//
|
||||
// Emplace
|
||||
// @Description: 安装一个lsa到LsaContainer
|
||||
|
||||
@@ -62,6 +62,54 @@ func TestLsaContainer_BuntDB_Emplace(t *testing.T) {
|
||||
common2.LogInfo("lsaContainer存入名称lsa成功")
|
||||
}
|
||||
|
||||
//
|
||||
// TestLsaContainer_BuntDB_FindLsa
|
||||
// @Description: 测试查找lsa
|
||||
// @param t
|
||||
//
|
||||
func TestLsaContainer_BuntDB_FindLsa(t *testing.T) {
|
||||
// 构造NameLsa
|
||||
base := new(lsa.NameLsa)
|
||||
base.SetLsaExpirationTime(2000)
|
||||
base.SetLsaSequenceNumber(1234)
|
||||
base.LsaOriginRouterIdentifier, _ = component.CreateIdentifierByString("/min/pku")
|
||||
ident, _ := component.CreateIdentifierByString("/pku/routerfucker")
|
||||
base.Insert(ident, "/bind")
|
||||
base.Insert(ident, "/wechat")
|
||||
ident, _ = component.CreateIdentifierByString("/pku/router")
|
||||
base.Insert(ident, "/qq")
|
||||
common2.LogInfo("ToString: " + base.ToString())
|
||||
|
||||
// 构造LsaContainer
|
||||
lsaContainer := new(LsaContainer_BuntDB)
|
||||
err := lsaContainer.Init()
|
||||
if err != nil {
|
||||
common2.LogInfo("lsaContainer创建失败:", err.Error())
|
||||
}
|
||||
|
||||
// 将NameLsa插入lsaContainer
|
||||
err = lsaContainer.Emplace(base)
|
||||
if err != nil {
|
||||
common2.LogInfo("lsaContainer存入名称lsa失败:", err.Error())
|
||||
}
|
||||
common2.LogInfo("lsaContainer存入名称lsa成功")
|
||||
|
||||
// 查看某个lsa是否存在
|
||||
b := lsaContainer.Exists(base)
|
||||
common2.LogInfo("是否存在已插入的lsa:", b)
|
||||
b = lsaContainer.ExistsRouterNameAndType(base.GetOriginRouter(), base.GetType())
|
||||
common2.LogInfo("是否存在已插入的lsa:", b)
|
||||
// 构造一个新Lsa
|
||||
idenNew, _ := component.CreateIdentifierByString("/min/thu")
|
||||
namelsa := new(lsa.NameLsa)
|
||||
namelsa.SetOriginRouter(idenNew)
|
||||
// 查看是否存在
|
||||
b = lsaContainer.Exists(namelsa)
|
||||
common2.LogInfo("是否存在尚未插入的lsa:", b)
|
||||
b = lsaContainer.ExistsRouterNameAndType(idenNew, namelsa.GetType())
|
||||
common2.LogInfo("是否存在尚未插入的lsa:", b)
|
||||
}
|
||||
|
||||
//
|
||||
// TestLsaContainer_BuntDB_Emplace_Get_Erase_Adj_Lsa
|
||||
// @Description: 测试对邻接LSA进行增删改查
|
||||
|
||||
+19
-5
@@ -99,14 +99,25 @@ func (l *Lsdb) Init(mc *common.MlsrConfig, ms *MlsrScheduler,
|
||||
|
||||
//
|
||||
// DoesLsaExist
|
||||
// @Description: 返回LSDB是否存在某些LSA的查询结果
|
||||
// @Description: 返回LSDB是否存在某个LSA的查询结果
|
||||
// @receiver l
|
||||
// @param routerIdentifier
|
||||
// @param lsaType
|
||||
// @return bool
|
||||
//
|
||||
func (l *Lsdb) DoesLsaExist(routerIdentifier *component.Identifier, lsaType int) bool {
|
||||
panic("implement me")
|
||||
func (l *Lsdb) DoesLsaNameExist(routerIdentifier *component.Identifier, lsaType lsa.LsaType) bool {
|
||||
return l.ExistsRouterNameAndType(routerIdentifier, lsaType)
|
||||
}
|
||||
|
||||
//
|
||||
// DoesLsaExist
|
||||
// @Description: 返回LSDB是否存在某个LSA的查询结果
|
||||
// @receiver l
|
||||
// @param lsa
|
||||
// @return bool
|
||||
//
|
||||
func (l *Lsdb) DoesLsaExist(lsa lsa.ILsa) bool {
|
||||
return l.Exists(lsa)
|
||||
}
|
||||
|
||||
//
|
||||
@@ -210,8 +221,11 @@ func (l *Lsdb) GetSync() *communication.SyncLogicHandler {
|
||||
//
|
||||
func (l *Lsdb) FindLsa(routerIdentifier *component.Identifier,
|
||||
lsaType lsa.LsaType) lsa.ILsa {
|
||||
// todo
|
||||
return &lsa.NameLsa{}
|
||||
lsaGet, err := l.GetLSAByNameAndType(routerIdentifier, lsaType)
|
||||
if err != nil {
|
||||
lsaGet = nil
|
||||
}
|
||||
return lsaGet
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user