mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-10-04 19:42:02 +08:00
基本实现MlsrConfig模块,即配置模块,以支持LSDB模块调用
This commit is contained in:
1 parent
a587f1701d
commit
91a6713311
4 files changed
+221
-1
No files matched your search
@@ -0,0 +1,172 @@
|
||||
// Package common
|
||||
// @Author: Wang Feng
|
||||
// @Description:
|
||||
// @Version: 0.1.0
|
||||
// @Date: 2022/3/29 11:10
|
||||
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
//
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
const DefaultConfFileName = "mlsrConf.ini"
|
||||
|
||||
//
|
||||
// MlsrConfig
|
||||
// @Description: MLSR 配置文件的配置。与mlsrConf.ini一一对应
|
||||
//
|
||||
type MlsrConfig struct {
|
||||
GeneralConfig `ini:"General"`
|
||||
NeighborsConfig `ini:"Neighbors"`
|
||||
HyperbolicConfig `ini:"Hyperbolic"`
|
||||
FibConfig `ini:"Fib"`
|
||||
AdvertisingConfig `ini:"Advertising"`
|
||||
SecurityConfig `ini:"Security"`
|
||||
|
||||
mlsrConfigPath string // 配置文件所在路径
|
||||
}
|
||||
|
||||
//
|
||||
// GeneralConfig
|
||||
// @Description: 最基础配置信息:LSA、同步协议
|
||||
//
|
||||
type GeneralConfig struct {
|
||||
Network string `ini:"Network"` // 所属网络
|
||||
Site string `ini:"Site"` // 所属站点
|
||||
Router string `ini:"Router"` // 所属路由器
|
||||
|
||||
LsaRefreshTime uint32 `ini:"LsaRefreshTime"` // LSA刷新时间
|
||||
|
||||
RouterDeadInterval uint32 `ini:"RouterDeadInterval"` // 路由器判断死亡的时间间隔(必须大于LSA刷新时间)
|
||||
|
||||
LsaInterestLifetime int `ini:"LsaInterestLifetime"` // LSA兴趣包生存周期。当使用推式包时,此值无效
|
||||
|
||||
SyncProtocol string `ini:"SyncProtocol"` // 同步协议
|
||||
SyncInterestLifetime uint32 `ini:"SyncInterestLifetime"` // 同步协议兴趣包生命周期
|
||||
}
|
||||
|
||||
//
|
||||
// NeighborsConfig
|
||||
// @Description: 邻居路由器相关配置
|
||||
//
|
||||
type NeighborsConfig struct {
|
||||
HelloRetries int `ini:"HelloRetries"` // hello协议探测最大次数
|
||||
HelloTimeout uint32 `ini:"HelloTimeout"` // hello协议中的超时时间
|
||||
HelloInterval uint32 `ini:"HelloInterval"` // 两个hello包之间的间隔时间
|
||||
|
||||
AdjLsaBuildInterval uint32 `ini:"AdjLsaBuildInterval"` // 邻接LSA构建的时间间隔
|
||||
LogicFaceDatasetFetchRetries uint32 `ini:"LogicFaceDatasetFetchRetries"` // 获取FaceStatus数据集的重试次数
|
||||
LogicFaceDatasetFetchInterval uint32 `ini:"LogicFaceDatasetFetchInterval"` // FaceStatus数据集获取尝试之间的间隔
|
||||
|
||||
NeighborsInfo []*NeighborConfig `ini:"NeighborsInfo"` // 邻居路由器链路信息
|
||||
}
|
||||
|
||||
type NeighborConfig struct {
|
||||
//NeighborName string `ini:"NeighborName"` // 邻居路由器的名称前缀
|
||||
//LogicFaceUri string `ini:"LogicFaceUri"` // 连接该邻居路由器的LogicFace的URI
|
||||
//LinkCost uint64 `ini:"LinkCost"` // 链路开销(用uint64还是double待决)
|
||||
|
||||
NeighborName string // 邻居路由器的名称前缀
|
||||
LogicFaceUri string // 连接该邻居路由器的LogicFace的URI
|
||||
LinkCost uint64 // 链路开销(用uint64还是double待决)
|
||||
}
|
||||
|
||||
//
|
||||
// HyperbolicConfig
|
||||
// @Description: 预留双曲坐标的接口
|
||||
//
|
||||
type HyperbolicConfig struct {
|
||||
}
|
||||
|
||||
//
|
||||
// FibConfig
|
||||
// @Description: 路由计算相关配置
|
||||
//
|
||||
type FibConfig struct {
|
||||
MaxLogicFacesPerPrefix int `ini:"MaxLogicFacesPerPrefix"` // 每个前缀对应的下一跳face列表的最大数目
|
||||
RoutingCalcInterval uint32 `ini:"RoutingCalcInterval"` // 两次路由计算的时间间隔
|
||||
}
|
||||
|
||||
type AdvertisingConfig struct {
|
||||
Prefixs []string `ini:"Prefixs"` // 需要广告给其他路由器的本机前缀
|
||||
}
|
||||
|
||||
type SecurityConfig struct {
|
||||
}
|
||||
|
||||
//
|
||||
// Init
|
||||
// @Description: 初始化配置,给所有的配置设置默认值
|
||||
// @receiver c
|
||||
//
|
||||
func (c *MlsrConfig) Init() {
|
||||
// 通用配置参数
|
||||
c.GeneralConfig.Network = "/min"
|
||||
c.GeneralConfig.Site = "/pkusz"
|
||||
c.GeneralConfig.Router = "/routerA"
|
||||
c.GeneralConfig.LsaRefreshTime = 1800 // 240-7200
|
||||
c.GeneralConfig.RouterDeadInterval = 2*c.GeneralConfig.LsaRefreshTime
|
||||
c.GeneralConfig.LsaInterestLifetime = 4 // 4-60
|
||||
c.GeneralConfig.SyncProtocol = "min-sync"
|
||||
c.GeneralConfig.SyncInterestLifetime = 60000 // 1000-120000
|
||||
|
||||
// 邻居路由器配置参数
|
||||
c.NeighborsConfig.HelloRetries = 3 // 1-15
|
||||
c.NeighborsConfig.HelloTimeout = 1 // 1-15
|
||||
c.NeighborsConfig.HelloInterval = 60 // 30-90
|
||||
c.NeighborsConfig.AdjLsaBuildInterval = 10 // 5-30
|
||||
c.NeighborsConfig.LogicFaceDatasetFetchRetries = 3 // 1-10
|
||||
c.NeighborsConfig.LogicFaceDatasetFetchInterval = 3600 // 1800-5400
|
||||
// todo: 下面这种记录方式,无法将邻居链路信息存储到配置文件中
|
||||
c.NeighborsConfig.NeighborsInfo=[]*NeighborConfig{
|
||||
{"/routerB","tcp://1.1.1.1",10},
|
||||
{"/routerC","udp://1.1.1.2",10}}
|
||||
|
||||
// 路由计算配置参数
|
||||
c.FibConfig.MaxLogicFacesPerPrefix = 0 // 0-60 todo:为啥默认是0呢
|
||||
c.FibConfig.RoutingCalcInterval = 15 // 0-15
|
||||
|
||||
// 广播本地前缀配置参数
|
||||
c.AdvertisingConfig.Prefixs=[]string{"/videos","/files","voices"} // todo:用于测试
|
||||
}
|
||||
|
||||
//
|
||||
// Save
|
||||
// @Description: 保存当前配置状态到配置文件当中
|
||||
// @receiver c
|
||||
// @return error
|
||||
//
|
||||
func (c *MlsrConfig) Save() error {
|
||||
cfg := ini.Empty()
|
||||
if err:= ini.ReflectFrom(cfg,c); err!= nil{
|
||||
return err
|
||||
}
|
||||
return cfg.SaveTo(c.mlsrConfigPath)
|
||||
}
|
||||
|
||||
//
|
||||
// ParseConfig
|
||||
// @Description: 从指定路径中解析配置文件
|
||||
// @receiver c
|
||||
// @param configPath
|
||||
// @return *MlsrConfig
|
||||
// @return error
|
||||
//
|
||||
func ParseConfig(configPath string) (*MlsrConfig, error) {
|
||||
cfg, err := ini.Load(configPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mlsrConfig := new(MlsrConfig)
|
||||
mlsrConfig.mlsrConfigPath = configPath
|
||||
// 初始化配置,给所有的配置项设置默认值
|
||||
mlsrConfig.Init()
|
||||
// 加载配置文件中的配置
|
||||
if err = cfg.MapTo(&mlsrConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mlsrConfig, nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Package common
|
||||
// @Author: Wang Feng
|
||||
// @Description:
|
||||
// @Version: 0.1.0
|
||||
// @Date: 2022/3/29 17:14
|
||||
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
//
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func getCurrentDirectory() string {
|
||||
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(dir)
|
||||
return dir
|
||||
}
|
||||
|
||||
//
|
||||
// TestMlsrConfig_ParseConfigAndSave
|
||||
// @Description: 测试配置文件解析和存储
|
||||
// @param t
|
||||
//
|
||||
func TestMlsrConfig_ParseConfigAndSave(t *testing.T) {
|
||||
testPath := "D:"
|
||||
testPath += "\\"
|
||||
testPath += DefaultConfFileName
|
||||
fmt.Println("test mlsr conf path: "+testPath)
|
||||
mlsrConfig,_ := ParseConfig(testPath)
|
||||
fmt.Println(mlsrConfig)
|
||||
_ = mlsrConfig.Save()
|
||||
mlsrConfig2,_ := ParseConfig(testPath)
|
||||
fmt.Println(mlsrConfig2)
|
||||
}
|
||||
@@ -2,6 +2,9 @@ module mlsr
|
||||
|
||||
go 1.16
|
||||
|
||||
require minlib v0.0.0
|
||||
require (
|
||||
gopkg.in/ini.v1 v1.62.0
|
||||
minlib v0.0.0
|
||||
)
|
||||
|
||||
replace minlib v0.0.0 => ../minlib
|
||||
@@ -28,5 +28,7 @@ github.com/zeebo/xxh3 v1.0.1/go.mod h1:8VHV24/3AZLn3b6Mlp/KuC33LWH687Wq6EnziEB+r
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
|
||||
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
Reference in new issue
Block a user