diff --git a/lsa/AdjLsa.go b/lsa/AdjLsa.go index 627d9c5..e86a853 100644 --- a/lsa/AdjLsa.go +++ b/lsa/AdjLsa.go @@ -19,6 +19,10 @@ type AdjLsa struct { AdjLsaAdjacenctList } +func (a *AdjLsa) GetType() LsaType { + return LsaADJACENCYType +} + // // GetAdjList // @Description: 获取邻接信息表 diff --git a/lsa/CoordinateLsa.go b/lsa/CoordinateLsa.go index e786ea5..2fb5738 100644 --- a/lsa/CoordinateLsa.go +++ b/lsa/CoordinateLsa.go @@ -23,18 +23,26 @@ type CoordinateLsa struct { HyperbolicAngles } +func (l *CoordinateLsa) GetType() LsaType { + return LsaCOORDINATEType +} + func (c *CoordinateLsa) IsEqualContent(lsa *CoordinateLsa) bool { - panic("") + // todo + return false } func (c *CoordinateLsa) ToString() string { - panic("") + // todo + return "" } func (c *CoordinateLsa) WireEncode(encoder *encoding.Encoder) (int,error) { - panic("") + // todo + return 0,nil } func (c *CoordinateLsa) WireDecode(block *encoding.Block) error { - panic("") + // todo + return nil } \ No newline at end of file diff --git a/lsa/ILsa.go b/lsa/ILsa.go index ac1e709..4e5c9d2 100644 --- a/lsa/ILsa.go +++ b/lsa/ILsa.go @@ -23,6 +23,8 @@ type ILsa interface { GetExpirationTime() uint64 SetExpirationTime(time uint64) + GetType() LsaType + WireEncode(encoder *encoding.Encoder) (int,error) WireDecode(block *encoding.Block) error } diff --git a/lsa/LsaBase.go b/lsa/LsaBase.go index d3a7aa5..e908fd9 100644 --- a/lsa/LsaBase.go +++ b/lsa/LsaBase.go @@ -17,6 +17,7 @@ import ( type LsaType int const ( + LsaBaseType LsaType = 0 LsaADJACENCYType LsaType = 1 LsaNAMEType LsaType = 2 LsaCOORDINATEType LsaType = 3 @@ -30,6 +31,10 @@ type LsaBase struct { LsaOriginRouterIdentifier *component.Identifier // 源路由 } +func (l *LsaBase) GetType() LsaType { + return LsaBaseType +} + // // GetSeqNo // @Description: 获取序列号 @@ -91,7 +96,8 @@ func (l LsaBase) SetExpirationTime(time uint64) { } func (l *LsaBase) ToString() string { - panic("") + // todo + return "" } // diff --git a/lsa/NameLsa.go b/lsa/NameLsa.go index bd77c49..f1cb01e 100644 --- a/lsa/NameLsa.go +++ b/lsa/NameLsa.go @@ -19,6 +19,10 @@ type NameLsa struct { NameLsaNamePrefixList } +func (n *NameLsa) GetType() LsaType { + return LsaNAMEType +} + // // GetNamePrefixList // @Description: 获取名称前缀信息表 @@ -40,11 +44,13 @@ func (n *NameLsa) AddNamePrefixInfo(info *NameLsaNamePrefixInfo) { } func (n *NameLsa) IsEqualContent(aLsa *AdjLsa) bool { - panic("") + // todo + return false } func (n *NameLsa) ToString() string { - panic("") + // todo + return "" } // diff --git a/lsdb/LsaContainer.go b/lsdb/LsaContainer/LsaContainer.go similarity index 65% rename from lsdb/LsaContainer.go rename to lsdb/LsaContainer/LsaContainer.go index 0f8ef6c..a2c0e80 100644 --- a/lsdb/LsaContainer.go +++ b/lsdb/LsaContainer/LsaContainer.go @@ -6,8 +6,14 @@ // @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 // -package lsdb +package LsaContainer +// +// LsaContainer +// @Description: +// 1. Unique索引键:GetOriginRouter()+Type() +// 2. 其它索引键:Type() +// type LsaContainer struct { } diff --git a/lsdb/LsaContainer/buntdb/LsaContainer_BuntDB.go b/lsdb/LsaContainer/buntdb/LsaContainer_BuntDB.go new file mode 100644 index 0000000..3e7079c --- /dev/null +++ b/lsdb/LsaContainer/buntdb/LsaContainer_BuntDB.go @@ -0,0 +1,75 @@ +// Package buntdb +// @Author: Wang Feng +// @Description: +// @Version: 0.1.0 +// @Date: 2022/4/6 17:49 +// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 +// + +package buntdb + +import ( + "github.com/tidwall/buntdb" + "minlib/component" + "mlsr/lsa" +) + +// +// LsaContainer_BuntDB +// @Description: 使用BuntDB存储各种类型的LSA +// 实现接口: +// emplace() 安装 +// erase() 删除 +// GetByName() 根据LSA名称进行索引,返回一个lsa +// GetByType() 根据LSA类型进行索引,返回一组lsa,或其在db中的一组键 +// +type LsaContainer_BuntDB struct { + db *buntdb.DB +} + +// +// Init +// @Description: 初始化buntdb数据库 +// @receiver bdb +// @return error 如果成功初始化,则返回nil +// +func (bdb *LsaContainer_BuntDB) Init() error { + db, err := buntdb.Open(":memory:") + if err != nil { + return err + } + bdb.db = db + return nil +} + +// +// Clear +// @Description: 关闭数据库 +// @receiver bdb +// @return error +// +func (bdb *LsaContainer_BuntDB) Clear() error { + return bdb.db.Close() +} + +func (bdb *LsaContainer_BuntDB) Emplace(lsa *lsa.ILsa) { + +} + +func (bdb *LsaContainer_BuntDB) Erase(lsa *lsa.ILsa) { +} + +func (bdb *LsaContainer_BuntDB) EraseByIndex(index int) { +} + +func (bdb *LsaContainer_BuntDB) GetLSAByNameAndType(routerIdentifier *component.Identifier, + lsaType lsa.LsaType) *lsa.ILsa { +} + +func (bdb *LsaContainer_BuntDB) GetLSAsByType(routerIdentifier *component.Identifier) []*lsa.ILsa { +} + +func (bdb *LsaContainer_BuntDB) GetLSAKeysByType(routerIdentifier *component.Identifier) []string { +} + + diff --git a/lsdb/Lsdb.go b/lsdb/Lsdb.go index 67668da..3ea8661 100644 --- a/lsdb/Lsdb.go +++ b/lsdb/Lsdb.go @@ -15,6 +15,7 @@ import ( "mlsr/common" "mlsr/communication" "mlsr/lsa" + "mlsr/lsdb/LsaContainer" "time" ) @@ -33,7 +34,7 @@ type Lsdb struct { sync *communication.SyncLogicHandler // LSA容器 - lsaContainer *LsaContainer + lsaContainer *LsaContainer.LsaContainer lsaRefreshTime *time.Duration // lsa刷新时间 adjLsaBuildInterval *time.Duration // 邻接LSA构建间隔