From 98fa2bb6e6ef83c28ca737c3dcea6da20206f331 Mon Sep 17 00:00:00 2001 From: free will <2647778488@qq.com> Date: Fri, 25 Mar 2022 19:01:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A3=B0=E6=98=8Elsdb=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=9B=E5=A3=B0=E6=98=8E=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8F=B7=E7=AE=A1=E7=90=86=E5=99=A8=E7=9A=84=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E5=AE=9E=E7=8E=B0=E9=83=A8=E5=88=86=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=9B=E5=9C=A8baselsa=E4=B8=AD=E5=AE=9A=E4=B9=89lsa?= =?UTF-8?q?=E7=9A=84type=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lsa/LsaBase.go | 8 ++ lsdb/Lsdb.go | 72 ++++++++++++++ lsdb/SequencingManager.go | 202 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 282 insertions(+) create mode 100644 lsdb/Lsdb.go create mode 100644 lsdb/SequencingManager.go diff --git a/lsa/LsaBase.go b/lsa/LsaBase.go index ca0d34f..d3a7aa5 100644 --- a/lsa/LsaBase.go +++ b/lsa/LsaBase.go @@ -14,6 +14,14 @@ import ( "mlsr/extensions" ) +type LsaType int + +const ( + LsaADJACENCYType LsaType = 1 + LsaNAMEType LsaType = 2 + LsaCOORDINATEType LsaType = 3 +) + type LsaBase struct { encoding.SelfEncodingBase LsaExpirationTime // LSA超时时间 diff --git a/lsdb/Lsdb.go b/lsdb/Lsdb.go new file mode 100644 index 0000000..e777d53 --- /dev/null +++ b/lsdb/Lsdb.go @@ -0,0 +1,72 @@ +// Package lsdb +// @Author: Wang Feng +// @Description: +// @Version: 0.1.0 +// @Date: 2022/3/24 11:41 +// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 +// + +package lsdb + +import ( + "minlib/component" + "minlib/packet" +) + +const ( + INSTALLED = 0 + UPDATED = 1 + REMOVED = -1 +) + +type Lsdb struct { +} + +// +// DoesLsaExist +// @Description: 返回LSDB是否存在某些LSA的查询结果 +// @receiver l +// @param routerIdentifier +// @param lsaType +// @return bool +// +func (l *Lsdb) DoesLsaExist(routerIdentifier *component.Identifier,lsaType int) bool { + panic("implement me") +} + +// +// BuildAndInstallOwnNameLsa +// @Description: 构建一个属于本路由器的名称LSA,并安装它到LSDB。 +// @receiver l +// +func (l *Lsdb) BuildAndInstallOwnNameLsa() { +} + +// +// BuildAndInstallOwnCoordinateLsa +// @Description: 构建一个属于本路由器的坐标LSA,并安装它到LSDB +// @receiver l +// +func (l *Lsdb) BuildAndInstallOwnCoordinateLsa() { + panic("implement me") +} + +// +// ScheduleAdjLsaBuild +// @Description: 安排LSA的构建 +// @receiver l +// +func (l *Lsdb) ScheduleAdjLsaBuild() { +} + +// +// ProcessInterest +// @Description: 处理兴趣包。类似NDN的拉式传输 +// @receiver l +// @param interest +// +func (l *Lsdb) ProcessInterest(interest *packet.Interest) { +} + +func (l *Lsdb) ProcessGPPkt(pkt *packet.GPPkt) { +} \ No newline at end of file diff --git a/lsdb/SequencingManager.go b/lsdb/SequencingManager.go new file mode 100644 index 0000000..35319d3 --- /dev/null +++ b/lsdb/SequencingManager.go @@ -0,0 +1,202 @@ +// Package lsdb +// @Author: Wang Feng +// @Description: +// @Version: 0.1.0 +// @Date: 2022/3/24 17:40 +// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 +// + +package lsdb + +import ( + "errors" + "minlib/common" + "mlsr/lsa" + "strconv" + "sync" +) + +var once sync.Once // 用以保证SequencingManager的使用是单例模式 +var instance *SequencingManager // 单例模式的序列号管理器 + +var seqFileName string = "mlsrSeqNo.txt" // 保存序列号的文件名 + +type SequencingManager struct { + adjLsaSeq uint64 + nameLsaSeq uint64 + corLsaSeq uint64 + seqFileNameWithPath string +} + +// +// GetInstance +// @Description: 获取序列号管理器的单例。如果是第一次,则创建它 +// @param filePath 序列号同步到本地文件的文件位置 +// @return *SequencingManager +// +func GetInstance(filePath string) *SequencingManager { + once.Do(func() { + homePath, err := common.Home() + if err != nil { + common.LogFatal("Get current user home path failed!") + } + instance = &SequencingManager{0,0,0, + homePath+"/"+seqFileName} + _ = instance.SetSeqFileDirectory(filePath) + instance.InitiateSeqNoFromFile() + }) + return instance +} + +// +// SetSeqFileDirectory +// @Description: 设置序列号文件的保存路径 +// linux系统下,默认保存路径为home路径 +// @receiver s +// @param filePath +// +func (s *SequencingManager) SetSeqFileDirectory(filePath string) error { + //todo + return nil +} + +// +// InitiateSeqNoFromFile +// @Description: todo:从文件中初始化各种类型lsa的seq +// @receiver s +// +func (s *SequencingManager) InitiateSeqNoFromFile() { +} + +// +// WriteSeqNoToFile +// @Description: todo:将当前seq写入文件 +// @receiver s +// +func (s SequencingManager) WriteSeqNoToFile() { +} + +// +// SetLsaSeq +// @Description: 设置序列号 +// @receiver s +// @param seqNo +// @param lsaType +// +func (s *SequencingManager) SetLsaSeq(seqNo uint64,lsaType lsa.LsaType) { + switch lsaType { + case lsa.LsaADJACENCYType: + s.adjLsaSeq=seqNo + case lsa.LsaNAMEType: + s.nameLsaSeq=seqNo + case lsa.LsaCOORDINATEType: + s.corLsaSeq=seqNo + } +} + +// +// GetLsaSeq +// @Description: 查找指定类型LSA的当前序列号 +// @receiver s +// @param lsaType +// @return uint64 +// @return error +// +func (s *SequencingManager) GetLsaSeq(lsaType lsa.LsaType) (uint64,error) { + switch lsaType { + case lsa.LsaADJACENCYType: + return s.adjLsaSeq,nil + case lsa.LsaNAMEType: + return s.nameLsaSeq,nil + case lsa.LsaCOORDINATEType: + return s.corLsaSeq,nil + } + return 0,errors.New("no found the lsaType: "+ strconv.Itoa(int(lsaType))) +} + +// +// GetAdjLsaSeq +// @Description: 获取邻接Lsa序列号 +// @receiver s +// @return uint64 +// +func (s *SequencingManager) GetAdjLsaSeq() uint64 { + return s.adjLsaSeq +} + +// +// SetAdjLsaSeq +// @Description: 设置邻接Lsa序列号 +// @receiver s +// @param seq +// +func (s *SequencingManager) SetAdjLsaSeq(seq uint64) { + s.adjLsaSeq=seq +} + +// +// GetNameLsaSeq +// @Description: 获取名称LSA序列号 +// @receiver s +// @return uint64 +// +func (s *SequencingManager) GetNameLsaSeq() uint64 { + return s.nameLsaSeq +} + +// +// SetNameLsaSeq +// @Description: 设置名称LSA序列号 +// @receiver s +// @param seq +// +func (s *SequencingManager) SetNameLsaSeq(seq uint64) { + s.nameLsaSeq=seq +} + +// +// GetCorLsaSeq +// @Description: 获取坐标LSA序列号 +// @receiver s +// @return uint64 +// +func (s *SequencingManager) GetCorLsaSeq() uint64 { + return s.corLsaSeq +} + +// +// SetCorLsaSeq +// @Description: 设置坐标LSA序列号 +// @receiver s +// @param seq +// +func (s *SequencingManager) SetCorLsaSeq(seq uint64) { + s.corLsaSeq=seq +} + +// +// IncreaseAdjLsaSeq +// @Description: 邻接LSA序列号加一 +// @receiver s +// +func (s *SequencingManager) IncreaseAdjLsaSeq() { + s.adjLsaSeq++ +} + +// +// IncreaseNameLsaSeq +// @Description: 名称LSA序列号加一 +// @receiver s +// +func (s *SequencingManager) IncreaseNameLsaSeq() { + s.nameLsaSeq++ +} + +// +// IncreaseCorLsaSeq +// @Description: 坐标LSA序列号加一 +// @receiver s +// +func (s *SequencingManager) IncreaseCorLsaSeq() { + s.corLsaSeq++ +} \ No newline at end of file