声明lsdb部分函数;声明序列号管理器的函数,实现部分函数;在baselsa中定义lsa的type值

This commit is contained in:
free will committed 2022-03-25 19:01:23 +08:00
1 parent 97515d0969
commit 98fa2bb6e6
3 files changed
+282

No files matched your search

+8
View File
@@ -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超时时间
+72
View File
@@ -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) {
}
+202
View File
@@ -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++
}