mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-10-04 19:42:02 +08:00
219 lines
5.6 KiB
Go
219 lines
5.6 KiB
Go
// Package common
|
|
// @Author: Wang Feng
|
|
// @Description: MlsrConfig的辅助类。MlsrConf中主要实现读写配置文件的操作,
|
|
// 本类则负责将配置参数转化为实际的结构体。
|
|
// @Version: 0.1.0
|
|
// @Date: 2022/5/12 15:29
|
|
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
|
//
|
|
|
|
package common
|
|
|
|
import (
|
|
"minlib/component"
|
|
"mlsr/lsa"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// 同步协议版本号
|
|
const SYNC_VERSION = 1
|
|
|
|
type MlsrConfigParameters struct {
|
|
// 元数据从配置文件中来
|
|
mlsrconf *MlsrConfig
|
|
|
|
// 名称前缀/名称标识
|
|
m_routerName *component.Identifier
|
|
m_siteName *component.Identifier
|
|
m_network *component.Identifier
|
|
m_routerPrefix *component.Identifier
|
|
m_syncUserPrefix *component.Identifier
|
|
m_syncPrefix *component.Identifier
|
|
m_lsaPrefix *component.Identifier
|
|
|
|
m_faceDatasetFetchInterval time.Duration
|
|
m_lsaInterestLifetime time.Duration
|
|
|
|
}
|
|
|
|
// MlsrConfig初始化
|
|
func (mcp *MlsrConfigParameters) Init(config *MlsrConfig) {
|
|
mcp.setMetaData(config)
|
|
// 依次构建各个名称前缀/名称标识
|
|
_ = mcp.build3Prefix()
|
|
_ = mcp.buildSyncAndLsaPrefix()
|
|
_ = mcp.buildRouterAndSyncUserPrefix()
|
|
}
|
|
|
|
//
|
|
// setMetaData
|
|
// @Description: 设置mlsrconfig
|
|
// @receiver mcp
|
|
// @param config
|
|
//
|
|
func (mcp *MlsrConfigParameters) setMetaData(config *MlsrConfig) {
|
|
mcp.mlsrconf = config
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) genDurations() {
|
|
mcp.m_faceDatasetFetchInterval =
|
|
time.Duration(mcp.mlsrconf.LogicFaceDatasetFetchInterval) * time.Millisecond
|
|
mcp.m_lsaInterestLifetime =
|
|
time.Duration(mcp.mlsrconf.LsaInterestLifetime) * time.Millisecond
|
|
}
|
|
|
|
//
|
|
// build3Prefix
|
|
// @Description: 构建了三个必要的名称组件,网络、网域/网站、路由器
|
|
// @receiver mcp
|
|
// @return error
|
|
//
|
|
func (mcp *MlsrConfigParameters) build3Prefix() error {
|
|
var err error
|
|
mcp.m_network,err = component.CreateIdentifierByString(mcp.mlsrconf.Network)
|
|
if err != nil{
|
|
return err
|
|
}
|
|
|
|
mcp.m_siteName,err = component.CreateIdentifierByString(mcp.mlsrconf.Site)
|
|
if err != nil{
|
|
return err
|
|
}
|
|
|
|
mcp.m_routerName,err = component.CreateIdentifierByString(mcp.mlsrconf.Router)
|
|
if err != nil{
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) buildSyncAndLsaPrefix() error {
|
|
// 同步前缀 = "/localhop" + 网络字段 + "/mlsr/sync" + SYNC版本号
|
|
syncPrefix := "/localhop"+mcp.mlsrconf.Network+"/mlsr/sync"+"/"+ strconv.Itoa(SYNC_VERSION)
|
|
var err error
|
|
mcp.m_syncPrefix,err = component.CreateIdentifierByString(syncPrefix)
|
|
if err != nil{
|
|
return err
|
|
}
|
|
|
|
// Lsa前缀 = "/localhop" + 网络字段 + "/sync/LSA"
|
|
lsaPrefix := "/localhop"+mcp.mlsrconf.Network+"/sync/LSA"
|
|
mcp.m_lsaPrefix,err = component.CreateIdentifierByString(lsaPrefix)
|
|
if err != nil{
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) buildRouterAndSyncUserPrefix() error {
|
|
// 路由器前缀 = 网络字段 + 网域字段 + 路由器字段
|
|
prefix := mcp.mlsrconf.Network+mcp.mlsrconf.Site+mcp.mlsrconf.Router
|
|
var err error
|
|
mcp.m_routerPrefix,err = component.CreateIdentifierByString(prefix)
|
|
if err != nil{
|
|
return err
|
|
}
|
|
|
|
// 同步用户前缀 = Lsa前缀 + 网域字段 + 路由器字段
|
|
syncUserPrefix := mcp.m_lsaPrefix.ToUri()+mcp.mlsrconf.Site+mcp.mlsrconf.Router
|
|
mcp.m_syncUserPrefix,err = component.CreateIdentifierByString(syncUserPrefix)
|
|
if err != nil{
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetNetwork() *component.Identifier {
|
|
return mcp.m_network
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetSiteName() *component.Identifier {
|
|
return mcp.m_siteName
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetRouterName() *component.Identifier {
|
|
return mcp.m_routerName
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetRouterPrefix() *component.Identifier {
|
|
return mcp.m_routerPrefix
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetSyncUserPrefix() *component.Identifier {
|
|
return mcp.m_syncUserPrefix
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetSyncPrefix() *component.Identifier {
|
|
return mcp.m_syncPrefix
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetLsaPrefix() *component.Identifier {
|
|
return mcp.m_lsaPrefix
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetSyncProtocol() {
|
|
// todo
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetLsaRefreshTime() uint32 {
|
|
return mcp.mlsrconf.LsaRefreshTime
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetLsaInterestLifetime() time.Duration {
|
|
return mcp.m_lsaInterestLifetime
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetAdjLsaBuildInterval() uint32 {
|
|
return mcp.mlsrconf.AdjLsaBuildInterval
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetRoutingCalcInterval() uint32 {
|
|
return mcp.mlsrconf.RoutingCalcInterval
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetRouterDeadInterval() uint32 {
|
|
return mcp.mlsrconf.RouterDeadInterval
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetFaceDatasetFetchTries() uint32 {
|
|
return mcp.mlsrconf.LogicFaceDatasetFetchRetries
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetFaceDatasetFetchInterval() time.Duration {
|
|
return mcp.m_faceDatasetFetchInterval
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetInterestRetryNumber() int {
|
|
return mcp.mlsrconf.HelloRetries
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetInterestResendTime() {
|
|
// todo
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetInfoInterestInterval() {
|
|
// todo
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetMaxFacesPerPrefix() int {
|
|
return mcp.mlsrconf.MaxLogicFacesPerPrefix
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetSyncInterestLifetime() uint32 {
|
|
return mcp.mlsrconf.SyncInterestLifetime
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetAdjacencyList() *lsa.AdjLsaAdjacenctList {
|
|
// todo
|
|
return nil
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetNamePrefixList() {
|
|
// todo
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetKeyChain() {
|
|
// todo
|
|
}
|