1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-13 16:18:38 +08:00

实现从配置文件中读取邻接信息和名称前缀信息;实现将配置文件中的名称前缀信息插入NameLsa;实现LSDB中ScheduleAdjLsaBuild

This commit is contained in:
free will
2022-06-03 15:46:44 +08:00
parent bd40bc3e48
commit 4846c362ea
6 changed files with 131 additions and 27 deletions
+6 -2
View File
@@ -260,6 +260,8 @@ func (c *MlsrConfig) Init() {
c.NeighborsConfig.AdjLsaBuildInterval = 10 * 1000 // 5-30,构建间隔,范围5秒到30秒。默认10秒钟
c.NeighborsConfig.LogicFaceDatasetFetchRetries = 3 // 1-10,次数
c.NeighborsConfig.LogicFaceDatasetFetchInterval = 60 * 60 * 1000 // 30*60-90*60,半小时到一个半小时。默认1小时
// 邻接链路信息
c.neighbors = []NeighborConfig{}
// 将邻居链路信息存储到配置文件中 todo:用于测试
neighborConfig1 := NeighborConfig{
NeighborName: "/routerB",
@@ -274,14 +276,16 @@ func (c *MlsrConfig) Init() {
//neighborsJsonString, _ := parseNeighborConfigToJsonString(
// []NeighborConfig{neighborConfig1,neighborConfig2})
//c.NeighborsConfig.NeighborsInfo=neighborsJsonString
c.neighbors = []NeighborConfig{neighborConfig1, neighborConfig2}
c.neighbors = append(c.neighbors, neighborConfig1)
c.neighbors = append(c.neighbors, neighborConfig2)
// 5. FIB更新配置参数
c.FibConfig.MaxLogicFacesPerPrefix = 0 // 0-60,个数,最多有多少个下一跳。置0表示保留所有计算出的下一跳
c.FibConfig.RoutingCalcInterval = 15 * 1000 // 0-15,路由计算间隔。默认15秒计算一次
// 6. 广播本地前缀配置参数
c.AdvertisingConfig.Prefixs = []string{"/videos", "/files", "voices"} // todo:用于测试
// c.AdvertisingConfig.Prefixs = []string{} // 非测试状态
c.AdvertisingConfig.Prefixs = []string{"/videos", "/files", "/voices"} // todo:用于测试
}
//
+54 -5
View File
@@ -10,6 +10,7 @@
package common
import (
common2 "minlib/common"
"minlib/component"
"mlsr/lsa"
"strconv"
@@ -358,13 +359,61 @@ func (mcp *MlsrConfigParameters) GetMaxFacesPerPrefix() int {
return mcp.mlsrconf.MaxLogicFacesPerPrefix
}
func (mcp *MlsrConfigParameters) GetAdjacencyList() *lsa.AdjLsaAdjacenctList {
// todo
return nil
//
// GetAdjacencyList
// @Description: 从配置文件中获取邻接信息列表
// @receiver mcp
// @return []*lsa.AdjLsaAdjacencyInfo
//
func (mcp *MlsrConfigParameters) GetAdjacencyList() []*lsa.AdjLsaAdjacencyInfo {
adjInfos := []*lsa.AdjLsaAdjacencyInfo{}
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)
// 加入信息列表
adjInfos = append(adjInfos, adjInfo)
}
return adjInfos
}
func (mcp *MlsrConfigParameters) GetNamePrefixList() {
// todo
//
// GetNamePrefixList
// @Description: 从配置文件中获取名称前缀信息列表
// @receiver mcp
// @return []*lsa.NameLsaNamePrefixInfo
//
func (mcp *MlsrConfigParameters) GetNamePrefixList() []*lsa.NameLsaNamePrefixInfo {
infos := []*lsa.NameLsaNamePrefixInfo{}
// 从配置文件读取广播前缀
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("")
// 将该名称前缀信息加入切片
infos = append(infos, namePrefixInfo)
}
return infos
}
func (mcp *MlsrConfigParameters) GetKeyChain() {
+11
View File
@@ -61,6 +61,17 @@ func TestMlsrConfigParameters(t *testing.T) {
fmt.Println(mlsrConfig.ParametersToString())
fmt.Println("!!!", mlsrConfig.MlsrConfigParameters.GetSyncUserPrefix().ToUri()+"00000")
fmt.Println("end")
// 打印邻接列表
adjs := mlsrConfig.GetAdjacencyList()
for i := 0; i < len(adjs); i++ {
fmt.Println(adjs[i].ToString())
}
fmt.Println("#########################################################")
// 打印名称前缀表
prefixs := mlsrConfig.GetNamePrefixList()
for i := 0; i < len(prefixs); i++ {
fmt.Println(prefixs[i].ToString())
}
}
//
+26 -9
View File
@@ -22,6 +22,23 @@ type NameLsaNamePrefixList struct {
lsaNamePrefixs LsaNamePrefixContainer
}
//
// InsertNamePrefixList
// @Description: 插入一张名称前缀信息列表
// @receiver l
// @param list
// @return bool 如果成功插入任何一条信息,即返回true
//
func (l *NameLsaNamePrefixList) InsertNamePrefixList(list []*NameLsaNamePrefixInfo) bool {
b := false
for i := 0; i < len(list); i++ {
if l.InsertNamePrefixInfo(list[i]) {
b = true
}
}
return b
}
//
// GetIndex
// @Description: 获取指定名称前缀在列表中的索引值
@@ -46,11 +63,11 @@ func (l *NameLsaNamePrefixList) GetIndex(namePrefix *component.Identifier) int {
// @return bool 只要能插入Info中的任何一个source,即返回true
//
func (l *NameLsaNamePrefixList) InsertNamePrefixInfo(info *NameLsaNamePrefixInfo) bool {
b:=false
for i:=0;i<len(info.Sources);i++{
tmpBool:=l.Insert(info.NamePrefix,info.Sources[i])
if tmpBool{
b=true
b := false
for i := 0; i < len(info.Sources); i++ {
tmpBool := l.Insert(info.NamePrefix, info.Sources[i])
if tmpBool {
b = true
}
}
return b
@@ -179,10 +196,10 @@ func (l *NameLsaNamePrefixList) IsEqualTo(list *NameLsaNamePrefixList) bool {
//
func (l *NameLsaNamePrefixList) ToString() string {
var res = "{ "
for i:=0;i<len(l.lsaNamePrefixs);i++{
res+=l.lsaNamePrefixs[i].ToString()
if i<(len(l.lsaNamePrefixs)-1){
res+="; "
for i := 0; i < len(l.lsaNamePrefixs); i++ {
res += l.lsaNamePrefixs[i].ToString()
if i < (len(l.lsaNamePrefixs) - 1) {
res += "; "
}
}
res += " }"
+13 -10
View File
@@ -84,11 +84,12 @@ func (l *Lsdb) Init(mc *common.MlsrConfig, ms *MlsrScheduler,
l.adjBuildCount = 0
// 在LSDB初始化之前,对配置文件中的本机路由器进行拉式前缀注册(即监听该前缀)
lsaPrefix := l.mlsrConfig.GetLsaPrefix()
err := l.face.RegisterPullIdentifier(lsaPrefix, 2000)
if err != nil {
common2.LogFatal("Lsdb Init error, because face register, ", err.Error())
}
// todo: 为了在Windows上单独测试,暂时注释掉face注册前缀这一步骤
//lsaPrefix := l.mlsrConfig.GetLsaPrefix()
//err := l.face.RegisterPullIdentifier(lsaPrefix, 2000)
//if err != nil {
// common2.LogFatal("Lsdb Init error, because of face register, ", err.Error())
//}
// 构建并安装自己的名称LSA
l.BuildAndInstallOwnNameLsa()
@@ -114,12 +115,14 @@ func (l *Lsdb) DoesLsaExist(routerIdentifier *component.Identifier, lsaType int)
func (l *Lsdb) BuildAndInstallOwnNameLsa() {
// 根据配置文件,构造本机的名称LSA
nlsa := new(lsa.NameLsa)
nlsa.SetOriginRouter(l.thisRouterPrefix)
nlsa.SetSeqNo(l.sequencingManager.GetNameLsaSeq() + 1)
l.getLsaExpirationTimePoint()
nlsa.SetLsaExpirationTime(uint64(l.getLsaExpirationTimePoint().UnixMilli()))
nlsa.SetOriginRouter(l.thisRouterPrefix) // 源路由
nlsa.SetSeqNo(l.sequencingManager.GetNameLsaSeq() + 1) // 序列号
nlsa.SetLsaExpirationTime(uint64(l.getLsaExpirationTimePoint().UnixMilli())) // 超期时间
nlsa.NameLsaNamePrefixList.InsertNamePrefixList(l.mlsrConfig.GetNamePrefixList()) // 名称前缀列表
// 刷新序列号管理器中的名称LSA序列号
l.sequencingManager.IncreaseNameLsaSeq()
// todo 使用sync通知路由更新
// todo: 使用sync通知路由更新
// 安装lsa到LSDB
l.InstallLsa(nlsa)
+21 -1
View File
@@ -8,7 +8,27 @@
package lsdb
import "testing"
import (
"fmt"
"minlib/logicface"
"mlsr/common"
"testing"
)
const testConfigPath = "D:\\" + common.DefaultConfFileName
func TestLsdb_Init(t *testing.T) {
// 配置文件初始化
mlsrConfig, err := common.ParseConfig(testConfigPath)
if err != nil {
fmt.Println("配置文件解析错误")
}
// 调度器初始化
sche := new(MlsrScheduler)
sche.Init()
// LogicFace初始化(假设初始化,暂时用不到)
face := new(logicface.LogicFace)
// LSDB初始化
lsdb := new(Lsdb)
lsdb.Init(mlsrConfig, sche, face)
}