1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-15 19:24:47 +08:00

测试MlsrConfig,并将配置文件样例放置到项目根目录下

This commit is contained in:
free will
2022-06-02 17:37:45 +08:00
parent b1fe878eb5
commit 0dca6fd43f
3 changed files with 66 additions and 5 deletions
+3
View File
@@ -11,6 +11,7 @@ package common
import (
"encoding/json"
"gopkg.in/ini.v1"
common2 "minlib/common"
)
const DefaultConfFileName = "mlsrConf.ini"
@@ -225,6 +226,7 @@ func (c *MlsrConfig) Save() error {
func ParseConfig(configPath string) (*MlsrConfig, error) {
cfg, err := ini.Load(configPath)
if err != nil {
common2.LogFatal("ParseConfig error, load error, path is ", configPath, err.Error())
return nil, err
}
mlsrConfig := new(MlsrConfig)
@@ -233,6 +235,7 @@ func ParseConfig(configPath string) (*MlsrConfig, error) {
mlsrConfig.Init()
// 加载配置文件中的配置
if err = cfg.MapTo(&mlsrConfig); err != nil {
common2.LogFatal("ParseConfig error, mapTo error, path is ", configPath, err.Error())
return nil, err
}
if mlsrConfig.NeighborsInfo != "" {
+25 -5
View File
@@ -25,6 +25,23 @@ func getCurrentDirectory() string {
return dir
}
//
// TestCreatConfigFile
// @Description: 测试生成mlsrConfig文件
// @param t
//
func TestCreatConfigFile(t *testing.T) {
testPath := "D:"
testPath += "\\"
testPath += DefaultConfFileName
mlsrConfig := new(MlsrConfig)
mlsrConfig.mlsrConfigPath = testPath
mlsrConfig.Init()
mlsrConfig.MlsrConfigParameters.Init(mlsrConfig)
_ = mlsrConfig.Save()
}
//
// TestMlsrConfig_ParseConfigAndSave
// @Description: 测试配置文件解析和存储
@@ -34,15 +51,18 @@ func TestMlsrConfig_ParseConfigAndSave(t *testing.T) {
testPath := "D:"
testPath += "\\"
testPath += DefaultConfFileName
fmt.Println("test mlsr conf path: "+testPath)
mlsrConfig,_ := ParseConfig(testPath)
fmt.Println("test mlsr conf path: " + testPath)
mlsrConfig, err := ParseConfig(testPath)
if err != nil {
fmt.Println("配置文件加载错误")
}
// 存储
fmt.Println(mlsrConfig)
_ = mlsrConfig.Save()
// 取出
mlsrConfig2,_ := ParseConfig(testPath)
mlsrConfig2, _ := ParseConfig(testPath)
fmt.Println(mlsrConfig2)
// 解析neighbors
@@ -50,11 +70,11 @@ func TestMlsrConfig_ParseConfigAndSave(t *testing.T) {
fmt.Println(neighbors)
// 修改再存
ss:=NeighborConfig{
ss := NeighborConfig{
NeighborName: "nei",
LogicFaceUri: "uri",
LinkCost: 0,
}
mlsrConfig2.neighbors = append(mlsrConfig2.neighbors,ss)
mlsrConfig2.neighbors = append(mlsrConfig2.neighbors, ss)
_ = mlsrConfig2.Save()
}
+38
View File
@@ -0,0 +1,38 @@
[General]
Network = /min
Site = /pkusz
Router = /routerA
LsaRefreshTime = 1800
RouterDeadInterval = 3600
LsaInterestLifetime = 4
SyncProtocol = min-sync
SyncInterestLifetime = 60000
[Log]
LogLevel = INFO
ReportCaller = true
LogFormat = text
LogFilePath =
[Neighbors]
HelloRetries = 3
HelloTimeout = 1
HelloInterval = 60
AdjLsaBuildInterval = 10
LogicFaceDatasetFetchRetries = 3
LogicFaceDatasetFetchInterval = 3600
NeighborsInfo = [{"NeighborName":"/routerB","LogicFaceUri":"tcp://1.1.1.1","LinkCost":10},{"NeighborName":"/routerC","LogicFaceUri":"tcp://1.1.1.0","LinkCost":10},{"NeighborName":"nei","LogicFaceUri":"uri","LinkCost":0}]
[Hyperbolic]
[Fib]
MaxLogicFacesPerPrefix = 0
RoutingCalcInterval = 15
[Advertising]
Prefixs = /videos,/files,voices
[Security]
[MlsrConfigParameters]