mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-06 13:09:27 +08:00
202 lines
4.1 KiB
Go
202 lines
4.1 KiB
Go
// 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++
|
|
} |