mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-18 13:27:12 +08:00
113 lines
2.6 KiB
Go
113 lines
2.6 KiB
Go
// 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
|
|
}
|
|
|
|
const testConfigPath = "D:\\" + DefaultConfFileName
|
|
|
|
//
|
|
// 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()
|
|
}
|
|
|
|
//
|
|
// TestMlsrConfigParameters
|
|
// @Description: 测试配置项所有参数
|
|
// @param t
|
|
//
|
|
func TestMlsrConfigParameters(t *testing.T) {
|
|
// 1、从指定目录解析配置文件
|
|
mlsrConfig, err := ParseConfig(testConfigPath)
|
|
if err != nil {
|
|
fmt.Println("配置文件解析错误")
|
|
}
|
|
// 2、打印配置中的普通字符串信息
|
|
fmt.Println(mlsrConfig.ToString())
|
|
// 3、打印配置中的特殊参数信息
|
|
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())
|
|
}
|
|
}
|
|
|
|
//
|
|
// TestMlsrConfig_ParseConfigAndSave
|
|
// @Description: 测试配置文件解析和存储
|
|
// @param t
|
|
//
|
|
func TestMlsrConfig_ParseConfigAndSave(t *testing.T) {
|
|
testPath := "D:"
|
|
testPath += "\\"
|
|
testPath += DefaultConfFileName
|
|
fmt.Println("test mlsr conf path: " + testPath)
|
|
mlsrConfig, err := ParseConfig(testPath)
|
|
if err != nil {
|
|
fmt.Println("配置文件加载错误")
|
|
}
|
|
|
|
// 存储
|
|
fmt.Println(mlsrConfig)
|
|
_ = mlsrConfig.Save()
|
|
|
|
// 取出
|
|
mlsrConfig2, _ := ParseConfig(testPath)
|
|
fmt.Println(mlsrConfig2)
|
|
|
|
// 解析neighbors
|
|
neighbors := mlsrConfig2.neighbors
|
|
fmt.Println(neighbors)
|
|
|
|
// 修改再存
|
|
ss := NeighborConfig{
|
|
NeighborName: "nei",
|
|
LogicFaceUri: "uri",
|
|
LinkCost: 0,
|
|
}
|
|
mlsrConfig2.neighbors = append(mlsrConfig2.neighbors, ss)
|
|
_ = mlsrConfig2.Save()
|
|
}
|