mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-17 03:40:42 +08:00
461 lines
12 KiB
Go
461 lines
12 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 (
|
|
common2 "minlib/common"
|
|
"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_lsaRefreshTime time.Duration
|
|
m_lsaInterestLifetime time.Duration
|
|
m_routerDeadInterval time.Duration // 路由器死亡时间(经过了该时间,NameLsa将触发超时)
|
|
m_syncInterestLifetime time.Duration
|
|
|
|
// 时间:邻居路由器
|
|
m_helloTimeout time.Duration
|
|
m_helloInterval time.Duration
|
|
m_adjLsaBuildInterval time.Duration
|
|
m_faceDatasetFetchInterval time.Duration
|
|
|
|
// 时间:FIB更新
|
|
m_RoutingCalcInterval time.Duration
|
|
|
|
// 邻接信息列表
|
|
m_adjl *lsa.AdjLsaAdjacenctList
|
|
// 命名前缀列表
|
|
m_npl *lsa.NameLsaNamePrefixList
|
|
}
|
|
|
|
// MlsrConfig初始化
|
|
func (mcp *MlsrConfigParameters) Init(config *MlsrConfig) {
|
|
mcp.setMetaData(config)
|
|
// 依次构建各个名称前缀/名称标识
|
|
_ = mcp.build3Prefix()
|
|
_ = mcp.buildSyncAndLsaPrefix()
|
|
_ = mcp.buildRouterAndSyncUserPrefix()
|
|
// 构建时间间隔
|
|
mcp.genDurations()
|
|
// 构建邻接表和名称前缀表
|
|
mcp.InitAdjacencyList()
|
|
mcp.InitNamePrefixList()
|
|
}
|
|
|
|
//
|
|
// setMetaData
|
|
// @Description: 设置mlsrconfig
|
|
// @receiver mcp
|
|
// @param config
|
|
//
|
|
func (mcp *MlsrConfigParameters) setMetaData(config *MlsrConfig) {
|
|
mcp.mlsrconf = config
|
|
}
|
|
|
|
//
|
|
// genDurations
|
|
// @Description: 生成时间相关配置信息
|
|
// @receiver mcp
|
|
//
|
|
func (mcp *MlsrConfigParameters) genDurations() {
|
|
mcp.m_lsaRefreshTime =
|
|
time.Duration(mcp.mlsrconf.LsaRefreshTime) * time.Millisecond
|
|
mcp.m_lsaInterestLifetime =
|
|
time.Duration(mcp.mlsrconf.LsaInterestLifetime) * time.Millisecond
|
|
mcp.m_routerDeadInterval =
|
|
time.Duration(mcp.mlsrconf.RouterDeadInterval) * time.Millisecond
|
|
mcp.m_syncInterestLifetime =
|
|
time.Duration(mcp.mlsrconf.SyncInterestLifetime) * time.Millisecond
|
|
|
|
mcp.m_helloTimeout =
|
|
time.Duration(mcp.mlsrconf.HelloTimeout) * time.Millisecond
|
|
mcp.m_helloInterval =
|
|
time.Duration(mcp.mlsrconf.HelloInterval) * time.Millisecond
|
|
mcp.m_adjLsaBuildInterval =
|
|
time.Duration(mcp.mlsrconf.AdjLsaBuildInterval) * time.Millisecond
|
|
mcp.m_faceDatasetFetchInterval =
|
|
time.Duration(mcp.mlsrconf.LogicFaceDatasetFetchInterval) * time.Millisecond
|
|
|
|
mcp.m_RoutingCalcInterval =
|
|
time.Duration(mcp.mlsrconf.RoutingCalcInterval) * 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
|
|
}
|
|
|
|
//
|
|
// GetNetwork
|
|
// @Description: 网络定位符
|
|
// @receiver mcp
|
|
// @return *component.Identifier
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetNetwork() *component.Identifier {
|
|
return mcp.m_network
|
|
}
|
|
|
|
//
|
|
// GetSiteName
|
|
// @Description:网域定位符
|
|
// @receiver mcp
|
|
// @return *component.Identifier
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetSiteName() *component.Identifier {
|
|
return mcp.m_siteName
|
|
}
|
|
|
|
//
|
|
// GetRouterName
|
|
// @Description: 路由器定位符
|
|
// @receiver mcp
|
|
// @return *component.Identifier
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetRouterName() *component.Identifier {
|
|
return mcp.m_routerName
|
|
}
|
|
|
|
//
|
|
// GetRouterPrefix
|
|
// @Description: 路由器前缀
|
|
// @receiver mcp
|
|
// @return *component.Identifier
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetRouterPrefix() *component.Identifier {
|
|
return mcp.m_routerPrefix
|
|
}
|
|
|
|
//
|
|
// GetSyncUserPrefix
|
|
// @Description: 同步用户前缀
|
|
// @receiver mcp
|
|
// @return *component.Identifier
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetSyncUserPrefix() *component.Identifier {
|
|
return mcp.m_syncUserPrefix
|
|
}
|
|
|
|
//
|
|
// GetSyncPrefix
|
|
// @Description: 同步前缀
|
|
// @receiver mcp
|
|
// @return *component.Identifier
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetSyncPrefix() *component.Identifier {
|
|
return mcp.m_syncPrefix
|
|
}
|
|
|
|
//
|
|
// GetLsaPrefix
|
|
// @Description: LSA前缀
|
|
// @receiver mcp
|
|
// @return *component.Identifier
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetLsaPrefix() *component.Identifier {
|
|
return mcp.m_lsaPrefix
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetSyncProtocol() {
|
|
// todo
|
|
}
|
|
|
|
//
|
|
// GetLsaRefreshTime
|
|
// @Description: LSA刷新时间
|
|
// @receiver mcp
|
|
// @return time.Duration
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetLsaRefreshTime() time.Duration {
|
|
return mcp.m_lsaRefreshTime
|
|
}
|
|
|
|
//
|
|
// GetLsaInterestLifetime
|
|
// @Description: LSA兴趣包生命周期
|
|
// @receiver mcp
|
|
// @return time.Duration
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetLsaInterestLifetime() time.Duration {
|
|
return mcp.m_lsaInterestLifetime
|
|
}
|
|
|
|
//
|
|
// GetRouterDeadInterval
|
|
// @Description: 路由器死亡间隔
|
|
// @receiver mcp
|
|
// @return time.Duration
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetRouterDeadInterval() time.Duration {
|
|
return mcp.m_routerDeadInterval
|
|
}
|
|
|
|
//
|
|
// GetSyncInterestLifetime
|
|
// @Description: 同步兴趣包生命周期
|
|
// @receiver mcp
|
|
// @return time.Duration
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetSyncInterestLifetime() time.Duration {
|
|
return mcp.m_syncInterestLifetime
|
|
}
|
|
|
|
//
|
|
// GetAdjLsaBuildInterval
|
|
// @Description: 邻接LSA构建间隔
|
|
// @receiver mcp
|
|
// @return time.Duration
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetAdjLsaBuildInterval() time.Duration {
|
|
return mcp.m_adjLsaBuildInterval
|
|
}
|
|
|
|
//
|
|
// GetFaceDatasetFetchInterval
|
|
// @Description: LogicFace数据集请求间隔
|
|
// @receiver mcp
|
|
// @return time.Duration
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetFaceDatasetFetchInterval() time.Duration {
|
|
return mcp.m_faceDatasetFetchInterval
|
|
}
|
|
|
|
//
|
|
// GetRoutingCalcInterval
|
|
// @Description: 路由计算间隔
|
|
// @receiver mcp
|
|
// @return time.Duration
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetRoutingCalcInterval() time.Duration {
|
|
return mcp.m_RoutingCalcInterval
|
|
}
|
|
|
|
//
|
|
// GetFaceDatasetFetchTries
|
|
// @Description: LogicFace数据集请求次数
|
|
// @receiver mcp
|
|
// @return int
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetFaceDatasetFetchTries() uint32 {
|
|
return mcp.mlsrconf.LogicFaceDatasetFetchRetries
|
|
}
|
|
|
|
//
|
|
// GetHelloRetries
|
|
// @Description: hello兴趣包重传次数
|
|
// @receiver mcp
|
|
// @return int
|
|
//
|
|
func (mcp MlsrConfigParameters) GetHelloRetries() int {
|
|
return mcp.mlsrconf.HelloRetries
|
|
}
|
|
|
|
//
|
|
// GetHelloTimeout
|
|
// @Description: Hello超时时间
|
|
// @receiver mcp
|
|
// @return time.Duration
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetHelloTimeout() time.Duration {
|
|
return mcp.m_helloTimeout
|
|
}
|
|
|
|
//
|
|
// GetHelloInterval
|
|
// @Description: Hello重传间隔
|
|
// @receiver mcp
|
|
// @return time.Duration
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetHelloInterval() time.Duration {
|
|
return mcp.m_helloInterval
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetInterestRetryNumber() {
|
|
// todo
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetInterestResendTime() {
|
|
// todo
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetInfoInterestInterval() {
|
|
// todo
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetMaxFacesPerPrefix() int {
|
|
return mcp.mlsrconf.MaxLogicFacesPerPrefix
|
|
}
|
|
|
|
//
|
|
// InitAdjacencyList
|
|
// @Description: 从配置文件中初始化邻接信息列表
|
|
// @receiver mcp
|
|
//
|
|
func (mcp *MlsrConfigParameters) InitAdjacencyList() {
|
|
mcp.m_adjl = new(lsa.AdjLsaAdjacenctList)
|
|
neighborConfigs := mcp.mlsrconf.neighbors
|
|
for i := 0; i < len(neighborConfigs); i++ {
|
|
// 根据配置文件构造每条邻接链路信息
|
|
// 链路开销、URI及定位符均按照配置进行构造,
|
|
// FaceId缺省为0,兴趣包超时次数缺省为0,状态缺省为未激活
|
|
linkCost := lsa.AdjLsaLinkCost{}
|
|
linkCost.SetLinkCost(neighborConfigs[i].LinkCost)
|
|
faceUri := lsa.AdjLsaLogicFaceUri{}
|
|
faceUri.SetLogicFaceUri(neighborConfigs[i].LogicFaceUri)
|
|
iden, err := component.CreateIdentifierByString(neighborConfigs[i].NeighborName)
|
|
if err != nil {
|
|
common2.LogError("MlsrCOnfig GetAdjacencyList error, beacuse ", err.Error())
|
|
continue
|
|
}
|
|
faceId := lsa.AdjLsaLogicFaceId{}
|
|
faceId.SetLogicFaceId(0)
|
|
adjInfo := lsa.NewAdjLsaAdjacencyInfo(linkCost, faceUri, faceId, iden, 0, lsa.STATUS_INACTIVE)
|
|
// 加入信息列表
|
|
mcp.m_adjl.Insert(adjInfo)
|
|
}
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) InitNamePrefixList() {
|
|
mcp.m_npl = new(lsa.NameLsaNamePrefixList)
|
|
// 从配置文件读取广播前缀
|
|
adverPrefixs := mcp.mlsrconf.AdvertisingConfig.Prefixs
|
|
for i := 0; i < len(adverPrefixs); i++ {
|
|
// 为每个广播前缀构建一条名称前缀信息,其source为缺省的""
|
|
namePrefixInfo := new(lsa.NameLsaNamePrefixInfo)
|
|
iden, err := component.CreateIdentifierByString(adverPrefixs[i])
|
|
if err != nil {
|
|
common2.LogError("MlsrCOnfig GetNamePrefixList error, beacuse ", err.Error())
|
|
continue
|
|
}
|
|
namePrefixInfo.NamePrefix = iden
|
|
namePrefixInfo.InsertSource("")
|
|
// 将该名称前缀信息加入列表
|
|
mcp.m_npl.InsertNamePrefixInfo(namePrefixInfo)
|
|
}
|
|
}
|
|
|
|
//
|
|
// GetAdjacencyList
|
|
// @Description: 从配置文件中获取邻接信息列表
|
|
// @receiver mcp
|
|
// @return []*lsa.AdjLsaAdjacencyInfo
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetAdjacencyList() []*lsa.AdjLsaAdjacencyInfo {
|
|
return mcp.m_adjl.GetAdjList()
|
|
}
|
|
|
|
//
|
|
// GetAdjacencys
|
|
// @Description: 获取整体的邻接信息
|
|
// @receiver mcp
|
|
// @return *lsa.AdjLsaAdjacenctList
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetAdjacencys() *lsa.AdjLsaAdjacenctList {
|
|
return mcp.m_adjl
|
|
}
|
|
|
|
//
|
|
// GetNamePrefixList
|
|
// @Description: 从配置文件中获取名称前缀信息列表
|
|
// @receiver mcp
|
|
// @return []*lsa.NameLsaNamePrefixInfo
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetNamePrefixList() []*lsa.NameLsaNamePrefixInfo {
|
|
return mcp.m_npl.GetNamePrefixList()
|
|
}
|
|
|
|
//
|
|
// GetNamePrefixs
|
|
// @Description: 获取整体的名称前缀信息
|
|
// @receiver mcp
|
|
// @return *lsa.NameLsaNamePrefixList
|
|
//
|
|
func (mcp *MlsrConfigParameters) GetNamePrefixs() *lsa.NameLsaNamePrefixList {
|
|
return mcp.m_npl
|
|
}
|
|
|
|
func (mcp *MlsrConfigParameters) GetKeyChain() {
|
|
// todo
|
|
}
|