mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-15 19:24:47 +08:00
增加支持日志记录功能
This commit is contained in:
+68
-50
@@ -20,18 +20,19 @@ const DefaultConfFileName = "mlsrConf.ini"
|
||||
// @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"`
|
||||
GeneralConfig `ini:"General"`
|
||||
LogConfig `ini:"Log"`
|
||||
NeighborsConfig `ini:"Neighbors"`
|
||||
HyperbolicConfig `ini:"Hyperbolic"`
|
||||
FibConfig `ini:"Fib"`
|
||||
AdvertisingConfig `ini:"Advertising"`
|
||||
SecurityConfig `ini:"Security"`
|
||||
|
||||
// 获取值的接口
|
||||
MlsrConfigParameters
|
||||
|
||||
mlsrConfigPath string // 配置文件所在路径
|
||||
neighbors []NeighborConfig // NeighborsConfig中的信息
|
||||
mlsrConfigPath string // 配置文件所在路径
|
||||
neighbors []NeighborConfig // NeighborsConfig中的信息
|
||||
}
|
||||
|
||||
//
|
||||
@@ -39,18 +40,29 @@ type MlsrConfig struct {
|
||||
// @Description: 最基础配置信息:LSA、同步协议
|
||||
//
|
||||
type GeneralConfig struct {
|
||||
Network string `ini:"Network"` // 所属网络
|
||||
Site string `ini:"Site"` // 所属站点
|
||||
Router string `ini:"Router"` // 所属路由器
|
||||
Network string `ini:"Network"` // 所属网络
|
||||
Site string `ini:"Site"` // 所属站点
|
||||
Router string `ini:"Router"` // 所属路由器
|
||||
|
||||
LsaRefreshTime uint32 `ini:"LsaRefreshTime"` // LSA刷新时间
|
||||
LsaRefreshTime uint32 `ini:"LsaRefreshTime"` // LSA刷新时间
|
||||
|
||||
RouterDeadInterval uint32 `ini:"RouterDeadInterval"` // 路由器判断死亡的时间间隔(必须大于LSA刷新时间)
|
||||
RouterDeadInterval uint32 `ini:"RouterDeadInterval"` // 路由器判断死亡的时间间隔(必须大于LSA刷新时间)
|
||||
|
||||
LsaInterestLifetime int `ini:"LsaInterestLifetime"` // LSA兴趣包生存周期。当使用推式包时,此值无效【单位:毫秒】
|
||||
LsaInterestLifetime int `ini:"LsaInterestLifetime"` // LSA兴趣包生存周期。当使用推式包时,此值无效【单位:毫秒】
|
||||
|
||||
SyncProtocol string `ini:"SyncProtocol"` // 同步协议
|
||||
SyncInterestLifetime uint32 `ini:"SyncInterestLifetime"` // 同步协议兴趣包生命周期
|
||||
SyncProtocol string `ini:"SyncProtocol"` // 同步协议
|
||||
SyncInterestLifetime uint32 `ini:"SyncInterestLifetime"` // 同步协议兴趣包生命周期
|
||||
}
|
||||
|
||||
//
|
||||
// LogConfig
|
||||
// @Description: 日志模块
|
||||
//
|
||||
type LogConfig struct {
|
||||
LogLevel string `ini:"LogLevel"` // 日志等级
|
||||
ReportCaller bool `ini:"ReportCaller"` // 日志输出时是否添加文件名和函数名
|
||||
LogFormat string `ini:"LogFormat"` // 输出日志的格式 "json" | "text"
|
||||
LogFilePath string `ini:"LogFilePath"` // 日志输出文件路径,为空则输出至控制台
|
||||
}
|
||||
|
||||
//
|
||||
@@ -58,23 +70,23 @@ type GeneralConfig struct {
|
||||
// @Description: 邻居路由器相关配置
|
||||
//
|
||||
type NeighborsConfig struct {
|
||||
HelloRetries int `ini:"HelloRetries"` // hello协议探测最大次数
|
||||
HelloTimeout uint32 `ini:"HelloTimeout"` // hello协议中的超时时间
|
||||
HelloInterval uint32 `ini:"HelloInterval"` // 两个hello包之间的间隔时间
|
||||
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 NeighborsJsonString `ini:"NeighborsInfo"` // 邻居路由器链路信息
|
||||
AdjLsaBuildInterval uint32 `ini:"AdjLsaBuildInterval"` // 邻接LSA构建的时间间隔
|
||||
LogicFaceDatasetFetchRetries uint32 `ini:"LogicFaceDatasetFetchRetries"` // 获取FaceStatus数据集的重试次数
|
||||
LogicFaceDatasetFetchInterval uint32 `ini:"LogicFaceDatasetFetchInterval"` // FaceStatus数据集获取尝试之间的间隔【单位:毫秒】
|
||||
|
||||
NeighborsInfo NeighborsJsonString `ini:"NeighborsInfo"` // 邻居路由器链路信息
|
||||
}
|
||||
|
||||
type NeighborsJsonString string
|
||||
|
||||
type NeighborConfig struct {
|
||||
NeighborName string `ini:"NeighborName"` // 邻居路由器的名称前缀
|
||||
LogicFaceUri string `ini:"LogicFaceUri"` // 连接该邻居路由器的LogicFace的URI
|
||||
LinkCost uint64 `ini:"LinkCost"` // 链路开销(用uint64还是double待决)
|
||||
NeighborName string `ini:"NeighborName"` // 邻居路由器的名称前缀
|
||||
LogicFaceUri string `ini:"LogicFaceUri"` // 连接该邻居路由器的LogicFace的URI
|
||||
LinkCost uint64 `ini:"LinkCost"` // 链路开销(用uint64还是double待决)
|
||||
}
|
||||
|
||||
//
|
||||
@@ -84,10 +96,10 @@ type NeighborConfig struct {
|
||||
// @return NeighborsJsonString
|
||||
// @return error
|
||||
//
|
||||
func parseNeighborConfigToJsonString(neighbors []NeighborConfig) (NeighborsJsonString,error) {
|
||||
bytes,err := json.Marshal(neighbors)
|
||||
if err!= nil{
|
||||
return "",err
|
||||
func parseNeighborConfigToJsonString(neighbors []NeighborConfig) (NeighborsJsonString, error) {
|
||||
bytes, err := json.Marshal(neighbors)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return NeighborsJsonString(bytes), nil
|
||||
}
|
||||
@@ -100,11 +112,11 @@ func parseNeighborConfigToJsonString(neighbors []NeighborConfig) (NeighborsJsonS
|
||||
// @return []NeighborConfig
|
||||
// @return error
|
||||
//
|
||||
func parseJsonStringToNeighbors(jsonString NeighborsJsonString) ([]NeighborConfig,error) {
|
||||
func parseJsonStringToNeighbors(jsonString NeighborsJsonString) ([]NeighborConfig, error) {
|
||||
var neighbors []NeighborConfig
|
||||
err := json.Unmarshal([]byte(jsonString), &neighbors)
|
||||
if err!= nil{
|
||||
return nil,err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return neighbors, nil
|
||||
}
|
||||
@@ -121,12 +133,12 @@ type HyperbolicConfig struct {
|
||||
// @Description: 路由计算相关配置
|
||||
//
|
||||
type FibConfig struct {
|
||||
MaxLogicFacesPerPrefix int `ini:"MaxLogicFacesPerPrefix"` // 每个前缀对应的下一跳face列表的最大数目
|
||||
RoutingCalcInterval uint32 `ini:"RoutingCalcInterval"` // 两次路由计算的时间间隔
|
||||
MaxLogicFacesPerPrefix int `ini:"MaxLogicFacesPerPrefix"` // 每个前缀对应的下一跳face列表的最大数目
|
||||
RoutingCalcInterval uint32 `ini:"RoutingCalcInterval"` // 两次路由计算的时间间隔
|
||||
}
|
||||
|
||||
type AdvertisingConfig struct {
|
||||
Prefixs []string `ini:"Prefixs"` // 需要广告给其他路由器的本机前缀
|
||||
Prefixs []string `ini:"Prefixs"` // 需要广告给其他路由器的本机前缀
|
||||
}
|
||||
|
||||
type SecurityConfig struct {
|
||||
@@ -137,24 +149,30 @@ type SecurityConfig struct {
|
||||
// @Description: 初始化配置,给所有的配置设置默认值
|
||||
// @receiver c
|
||||
//
|
||||
func (c *MlsrConfig) Init() {
|
||||
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.RouterDeadInterval = 2 * c.GeneralConfig.LsaRefreshTime
|
||||
c.GeneralConfig.LsaInterestLifetime = 4 // 4-60
|
||||
c.GeneralConfig.SyncProtocol = "min-sync"
|
||||
c.GeneralConfig.SyncInterestLifetime = 60000 // 1000-120000
|
||||
|
||||
// Log
|
||||
c.LogConfig.LogLevel = "INFO"
|
||||
c.LogConfig.ReportCaller = true
|
||||
c.LogConfig.LogFormat = "text"
|
||||
c.LogConfig.LogFilePath = ""
|
||||
|
||||
// 邻居路由器配置参数
|
||||
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
|
||||
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:用于测试
|
||||
neighborConfig1 := NeighborConfig{
|
||||
NeighborName: "/routerB",
|
||||
@@ -169,14 +187,14 @@ func (c *MlsrConfig) Init() {
|
||||
//neighborsJsonString, _ := parseNeighborConfigToJsonString(
|
||||
// []NeighborConfig{neighborConfig1,neighborConfig2})
|
||||
//c.NeighborsConfig.NeighborsInfo=neighborsJsonString
|
||||
c.neighbors=[]NeighborConfig{neighborConfig1,neighborConfig2}
|
||||
c.neighbors = []NeighborConfig{neighborConfig1, neighborConfig2}
|
||||
|
||||
// 路由计算配置参数
|
||||
c.FibConfig.MaxLogicFacesPerPrefix = 0 // 0-60 todo:为啥默认是0呢
|
||||
c.FibConfig.RoutingCalcInterval = 15 // 0-15
|
||||
|
||||
// 广播本地前缀配置参数
|
||||
c.AdvertisingConfig.Prefixs=[]string{"/videos","/files","voices"} // todo:用于测试
|
||||
c.AdvertisingConfig.Prefixs = []string{"/videos", "/files", "voices"} // todo:用于测试
|
||||
}
|
||||
|
||||
//
|
||||
@@ -187,10 +205,10 @@ func (c *MlsrConfig) Init() {
|
||||
//
|
||||
func (c *MlsrConfig) Save() error {
|
||||
cfg := ini.Empty()
|
||||
if len(c.neighbors)>0 {
|
||||
if len(c.neighbors) > 0 {
|
||||
c.NeighborsInfo, _ = parseNeighborConfigToJsonString(c.neighbors)
|
||||
}
|
||||
if err:= ini.ReflectFrom(cfg,c); err!= nil{
|
||||
if err := ini.ReflectFrom(cfg, c); err != nil {
|
||||
return err
|
||||
}
|
||||
return cfg.SaveTo(c.mlsrConfigPath)
|
||||
@@ -217,7 +235,7 @@ func ParseConfig(configPath string) (*MlsrConfig, error) {
|
||||
if err = cfg.MapTo(&mlsrConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mlsrConfig.NeighborsInfo!="" {
|
||||
if mlsrConfig.NeighborsInfo != "" {
|
||||
mlsrConfig.neighbors, _ = parseJsonStringToNeighbors(mlsrConfig.NeighborsInfo)
|
||||
}
|
||||
// 将配置中的参数进行初始化,以支持直接获取结构体形式的参数
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Package common
|
||||
// @Author: Wang Feng
|
||||
// @Description:
|
||||
// @Version: 0.1.0
|
||||
// @Date: 2022/5/16 17:03
|
||||
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
//
|
||||
|
||||
package common
|
||||
|
||||
import "minlib/common"
|
||||
|
||||
// InitLogger 日志模块初始化
|
||||
//
|
||||
// @Description:
|
||||
// @param config 配置文件
|
||||
//
|
||||
func InitLogger(config *MlsrConfig) {
|
||||
common.InitLogger(&common.LoggerParameters{
|
||||
ReportCaller: config.LogConfig.ReportCaller,
|
||||
LogLevel: config.LogConfig.LogLevel,
|
||||
LogFormat: config.LogConfig.LogFormat,
|
||||
LogFilePath: config.LogConfig.LogFilePath,
|
||||
})
|
||||
}
|
||||
+21
-6
@@ -44,8 +44,21 @@ type RoutingTable struct {
|
||||
// @Description: 计算网络中每个路由器的下一个跃点列表。
|
||||
// @receiver t
|
||||
//
|
||||
func (t *RoutingTable) Calculate() {
|
||||
func (t *RoutingTable) Calculate() {
|
||||
if !t.m_isRoutingTableCalculating {
|
||||
// 先将状态改为正在做路由计算
|
||||
t.m_isRoutingTableCalculating = true
|
||||
|
||||
// 做邻接路由计算
|
||||
t.calculateLsRoutingTable()
|
||||
|
||||
// 恢复计算状态
|
||||
t.m_isRouteCalculationScheduled = false
|
||||
t.m_isRoutingTableCalculating = false
|
||||
} else {
|
||||
// 安排指定时间之后执行一个路由计算
|
||||
t.ScheduleRoutingTableCalculation()
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -55,7 +68,7 @@ func (t *RoutingTable) Calculate() {
|
||||
// @param destRouter 要修改其RTE的目标路由器。
|
||||
// @param hop 要添加到RTE的下一个跃点。
|
||||
//
|
||||
func (t *RoutingTable) AddNextHop(destRouter *component.Identifier,hop *NextHop) {
|
||||
func (t *RoutingTable) AddNextHop(destRouter *component.Identifier, hop *NextHop) {
|
||||
|
||||
}
|
||||
|
||||
@@ -69,7 +82,7 @@ func (t *RoutingTable) FindRoutingTableEntry(destRouter *component.Identifier) *
|
||||
// @Description: 仅当尚未计划计算事件时,才在事件计划程序中计划计算事件。
|
||||
// @receiver t
|
||||
//
|
||||
func (t *RoutingTable) ScheduleRoutingTableCalculation() {
|
||||
func (t *RoutingTable) ScheduleRoutingTableCalculation() {
|
||||
|
||||
}
|
||||
|
||||
@@ -78,8 +91,10 @@ func (t *RoutingTable) ScheduleRoutingTableCalculation() {
|
||||
// @Description: 计算链路状态路由表。
|
||||
// @receiver t
|
||||
//
|
||||
func (t *RoutingTable) calculateLsRoutingTable() {
|
||||
func (t *RoutingTable) calculateLsRoutingTable() {
|
||||
if t.lsdb.GetIsBuildAdjLsaScheduled() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -87,7 +102,7 @@ func (t *RoutingTable) calculateLsRoutingTable() {
|
||||
// @Description: 清空路由表
|
||||
// @receiver t
|
||||
//
|
||||
func (t *RoutingTable) clearRoutingTable() {
|
||||
func (t *RoutingTable) clearRoutingTable() {
|
||||
|
||||
}
|
||||
|
||||
@@ -163,4 +178,4 @@ func (t *RoutingTable) WireDecode(block *encoding.Block) error {
|
||||
}
|
||||
t.rTable = tableEntries
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user