diff --git a/communication/SyncLogicHandler.go b/communication/SyncLogicHandler.go index 188720f..f123b6e 100644 --- a/communication/SyncLogicHandler.go +++ b/communication/SyncLogicHandler.go @@ -189,14 +189,23 @@ func (s *SyncLogicHandler) ProcessUpdateFromSync(originRouter, updateName *compo // 发布更新时会这样做可以满足其他路由器的Sync兴趣包,让它们知道有同步更新可用 // func (s *SyncLogicHandler) PublishRoutingUpdate(t lsa.LsaType, seqNo uint64) { + var prefix *component.Identifier switch t { case lsa.LsaADJACENCYType: - s.SyncLogic.PublishUpdate(s.AdjLsaUserPrefix, seqNo) + prefix = s.AdjLsaUserPrefix + //s.SyncLogic.PublishUpdate(s.AdjLsaUserPrefix, seqNo) case lsa.LsaCOORDINATEType: - s.SyncLogic.PublishUpdate(s.CoorLsaUserPrefix, seqNo) + prefix = s.CoorLsaUserPrefix + //s.SyncLogic.PublishUpdate(s.CoorLsaUserPrefix, seqNo) case lsa.LsaNAMEType: - s.SyncLogic.PublishUpdate(s.NameLsaUserPrefix, seqNo) + prefix = s.NameLsaUserPrefix + //s.SyncLogic.PublishUpdate(s.NameLsaUserPrefix, seqNo) } + // 初次发布要先将前缀加入到MINSync + s.SyncLogic.AddUserNode(prefix) + + // 发布更新 + s.SyncLogic.PublishUpdate(prefix, seqNo) } // NewSyncLogicHandler SyncLogicHandler的工厂方法 diff --git a/communication/SyncProtocolAdapter.go b/communication/SyncProtocolAdapter.go index cd3c4e3..abd012e 100644 --- a/communication/SyncProtocolAdapter.go +++ b/communication/SyncProtocolAdapter.go @@ -78,7 +78,7 @@ func NewSyncProtocolAdapter(face *logicface.DummyClientLogicFace, if face == nil || syncPrefix == nil || userPrefix == nil || syncUpdateCallback == nil { return nil, errors.New("无效的输入参数") } - common.LogInfo("Using PSync") + common.LogInfo("Using MINSync") syncProtocolAdapter := new(SyncProtocolAdapter) syncProtocolAdapter.syncUpdateCallback = syncUpdateCallback diff --git a/lsdb/LsaContainer/buntdb/LsaContainer_BuntDB.go b/lsdb/LsaContainer/buntdb/LsaContainer_BuntDB.go index 3bee435..ab04e42 100644 --- a/lsdb/LsaContainer/buntdb/LsaContainer_BuntDB.go +++ b/lsdb/LsaContainer/buntdb/LsaContainer_BuntDB.go @@ -284,7 +284,7 @@ func (bdb *LsaContainer_BuntDB) GetLSAByNameAndType(routerIdentifier *component. lsaType lsa.LsaType) (lsa.ILsa, error) { glsa, err := newLsa(lsaType) // 要查找的lsa if err != nil { - common2.LogError("buntdb GetLSAByNameAndType new lsa error, because of ", err.Error()) + // common2.LogError("buntdb GetLSAByNameAndType new lsa error, because of ", err.Error()) return nil, err } @@ -295,14 +295,14 @@ func (bdb *LsaContainer_BuntDB) GetLSAByNameAndType(routerIdentifier *component. // 获取value value, err2 := tx.Get(key) if err2 != nil { - common2.LogError("buntdb GetLSAByNameAndType get key error, because of ", err2.Error()) + // common2.LogError("buntdb GetLSAByNameAndType get key error, because of ", err2.Error()) return err2 } // 将value转为lsa err2 = glsa.LoadFromJsonString([]byte(value)) if err2 != nil { - common2.LogError("buntdb GetLSAByNameAndType load from json error, because of ", err2.Error()) + // common2.LogError("buntdb GetLSAByNameAndType load from json error, because of ", err2.Error()) return err2 } diff --git a/lsdb/Lsdb.go b/lsdb/Lsdb.go index f6663ad..909f1e1 100644 --- a/lsdb/Lsdb.go +++ b/lsdb/Lsdb.go @@ -153,7 +153,7 @@ func (l *Lsdb) Init(mc *common.MlsrConfig, ms *MlsrScheduler, if args[2] != nil { originRouter, ok = args[2].(*component.Identifier) - if !ok { + if !ok || originRouter == nil { common2.LogError("originRouter conversion failed.") return } @@ -488,7 +488,7 @@ func (l *Lsdb) InstallLsa(lsa lsa.ILsa) { lsaInDb := l.FindLsa(lsa.GetOriginRouter(), lsa.GetType()) if lsaInDb == nil { // 如果没有: - common2.LogDebug("Adding Lsa ", lsa.ToString()) + common2.LogDebug("MINSync Adding Lsa ", lsa.ToString()) // 1. 就插入该LSA err := l.Emplace(lsa) if err != nil { @@ -826,7 +826,7 @@ func (l *Lsdb) ExpressInterest(interestName *component.Identifier, var ok bool if args[0] != nil { data, ok = args[0].(*packet.Data) - if !ok { + if !ok || data == nil { common2.LogError("data conversion failed.") return } @@ -858,7 +858,7 @@ func (l *Lsdb) ExpressInterest(interestName *component.Identifier, var ok bool if args[0] != nil { buffer, ok = args[0].([]byte) - if !ok { + if !ok || buffer == nil { common2.LogError("buffer conversion failed.") return } diff --git a/mlsrConf.ini b/mlsrConf.ini index ea784e7..c9e14b6 100644 --- a/mlsrConf.ini +++ b/mlsrConf.ini @@ -10,7 +10,7 @@ SyncInterestLifetime = 60000 [Log] LogLevel = ALL -ReportCaller = true +ReportCaller = false LogFormat = text LogFilePath = @@ -30,7 +30,7 @@ MaxLogicFacesPerPrefix = 0 RoutingCalcInterval = 15 [Advertising] -Prefixs = /videos,/files,voices +Prefixs = /videos,/files,/voices [Security] diff --git a/mlsrcmd/mlsr.go b/mlsrcmd/mlsr.go index 5765868..ab13b90 100644 --- a/mlsrcmd/mlsr.go +++ b/mlsrcmd/mlsr.go @@ -123,7 +123,11 @@ func (m *Mlsr) Init(face *logicface.DummyClientLogicFace, scheduler *lsdb.MlsrSc bindHelloFunc := func(args ...interface{}) { common2.LogInfo("Mlsr.bindHelloFunc") // Hello协议收到有效Data包,解析其参数为邻居 - neighbor := args[0].(*component.Identifier) + neighbor, ok := args[0].(*component.Identifier) + if !ok || neighbor == nil { + common2.LogError("Invalid Identifier") + return + } // 查看本机是否已知道此路由器 adjInfo := m.m_adjacencyList.FindAdjacencyByRouterIdentifier(neighbor) if adjInfo != nil { diff --git a/route/Fib.go b/route/Fib.go index 5b9add8..0cece85 100644 --- a/route/Fib.go +++ b/route/Fib.go @@ -258,7 +258,7 @@ func (f *Fib) Update(name *component.Identifier, allHops *NextHopList) error { // @Description: 清除MLSR注册的所有FIBEntry // func (f *Fib) Clean() { - f.table.Range(func(key, value interface{}) bool { + f.table.Range(func(key, value any) bool { // 获取新增的MLSR本地的FIB条目 entry := value.(*FibEntry) diff --git a/route/LinkStateRoutingTableCalculator.go b/route/LinkStateRoutingTableCalculator.go index bc9767e..fe169ab 100644 --- a/route/LinkStateRoutingTableCalculator.go +++ b/route/LinkStateRoutingTableCalculator.go @@ -46,7 +46,7 @@ func (c *LinkStateRoutingTableCalculator) ToString() string { str += strconv.Itoa(c.m_parent[i]) str += ")" } - str += "\n" + str += "]\n" str += "每个节点最佳路径的总开销:[" for i := 0; i < len(c.m_distance); i++ { str += "(" + strconv.Itoa(i) @@ -54,7 +54,7 @@ func (c *LinkStateRoutingTableCalculator) ToString() string { str += strconv.FormatUint(c.m_distance[i], 10) str += ")" } - str += "\n" + str += "]\n" return str } diff --git a/route/LinkStateRoutingTableCalculator_test.go b/route/LinkStateRoutingTableCalculator_test.go index 0daf229..ae25344 100644 --- a/route/LinkStateRoutingTableCalculator_test.go +++ b/route/LinkStateRoutingTableCalculator_test.go @@ -75,7 +75,8 @@ func TestLinkStateRoutingTableCalculator_CalculateOnePath(t *testing.T) { sche := new(lsdb.MlsrScheduler) sche.Init() // LogicFace初始化(假设初始化,暂时用不到) - face := new(logicface.DummyClientLogicFace) + // face := new(logicface.DummyClientLogicFace) + face := logicface.NewDummyClientLogicFaceByOptions("dummy://face1", "[]", logicface.NewDummyClientOptionsByParams(true, true)) // LSDB初始化 mlsdb := new(lsdb.Lsdb) mlsdb.Init(mlsrConfig, sche, face) @@ -142,10 +143,8 @@ func TestLinkStateRoutingTableCalculator_CalculateOnePath(t *testing.T) { } // 1.4 打印输出路由表计算器 - fmt.Println(rMap.ToString()) - fmt.Println(rtc.ToString()) - fmt.Println("源路由器的邻接数目:", rtc.getNumOfLinkfromAdjMatrix(0)) - fmt.Println("另一个路由器的邻接数目:", rtc.getNumOfLinkfromAdjMatrix(1)) + common2.LogInfo("源路由器的邻接数目:", rtc.getNumOfLinkfromAdjMatrix(0)) + common2.LogInfo("另一个路由器的邻接数目:", rtc.getNumOfLinkfromAdjMatrix(1)) // 2. 执行单源最短路径算法 rtc.allocateParent() @@ -153,17 +152,15 @@ func TestLinkStateRoutingTableCalculator_CalculateOnePath(t *testing.T) { rtc.doDijkstraPathCalculation(0) // 查看执行结果 // 计算器中的上一跳路径,以及开销 - fmt.Println(rtc.ToString()) + common2.LogInfo(rtc.ToString()) // 计算器获取的针对每个目的路由器的下一跳,及开销。 names, nexthops := rtc.addAllLsNextHopsToRoutingTable(mlsrConfig.GetAdjacencys(), rMap, 0) - for i := 0; i < len(names); i++ { - fmt.Println(names[i].ToUri() + " ") - } - fmt.Println("") for i := 0; i < len(nexthops); i++ { - fmt.Println(nexthops[i].LogicFaceUri() + "-" + - strconv.FormatUint(nexthops[i].RouteCost.Cost(), 10) + " ") + common2.LogInfo("NextHop: ", names[i].ToUri(), "\t FaceUri: ", nexthops[i].LogicFaceUri()+"\t - Link Cost: "+ + strconv.FormatUint(nexthops[i].RouteCost.Cost(), 10)+"\t ") } + + common2.LogInfo("将路由计算结果写入MIR...") } // @@ -185,7 +182,8 @@ func TestLinkStateRoutingTableCalculator_CalculateMutilPath(t *testing.T) { sche := new(lsdb.MlsrScheduler) sche.Init() // LogicFace初始化(假设初始化,暂时用不到) - face := new(logicface.DummyClientLogicFace) + // face := new(logicface.DummyClientLogicFace) + face := logicface.NewDummyClientLogicFaceByOptions("dummy://face1", "[]", logicface.NewDummyClientOptionsByParams(true, true)) // LSDB初始化 mlsdb := new(lsdb.Lsdb) mlsdb.Init(mlsrConfig, sche, face) diff --git a/route/NamePrefixTable.go b/route/NamePrefixTable.go index b84cd9d..3bb45d8 100644 --- a/route/NamePrefixTable.go +++ b/route/NamePrefixTable.go @@ -86,7 +86,11 @@ func (t *NamePrefixTable) Init(ownRouterName *component.Identifier, // 监听路由表的修改,触发NPT表修改 bindRoutingChangeFunc := func(args ...interface{}) { common2.LogInfo("NamePrefixTable bindRoutingChangeFunc.") - entrys := args[0].([]*RoutingTableEntry) + entrys, ok := args[0].([]*RoutingTableEntry) + if !ok || entrys == nil { + common2.LogError("NamePrefixTable Invalid Entry") + return + } t.UpdateWithNewRoute(entrys) } t.m_afterRoutingChangeConnection = afterRoutingChangeSignal.Connect(bindRoutingChangeFunc) @@ -96,14 +100,26 @@ func (t *NamePrefixTable) Init(ownRouterName *component.Identifier, common2.LogInfo("NamePrefixTable bindLsdbModifiedFunc.") // 获取四个参数 ilsa := args[0].(lsa.ILsa) + if ilsa == nil { + common2.LogError("Invalid lsa") + return + } updateType := args[1].(lsdb.LsdbUpdate) common2.LogInfo("NamePrefixTable bindLsdbModifiedFunc lsa: ", ilsa.GetOriginRouter().ToUri()) common2.LogInfo("NamePrefixTable bindLsdbModifiedFunc updateType: ", updateType) namesToAdd := []*component.Identifier{} namesToRemove := []*component.Identifier{} if updateType == lsdb.UPDATED { - namesToAdd = args[2].([]*component.Identifier) - namesToRemove = args[3].([]*component.Identifier) + namesToAdd, ok := args[2].([]*component.Identifier) + if !ok || namesToAdd == nil { + common2.LogError("Invalid namesToAdd") + return + } + namesToRemove, ok = args[3].([]*component.Identifier) + if !ok || namesToRemove == nil { + common2.LogError("Invalid namesToRemove") + return + } } // 执行更新操作 t.UpdateFromLsdb(ilsa, updateType, namesToAdd, namesToRemove) diff --git a/route/NamePrefixTable_test.go b/route/NamePrefixTable_test.go index 3ce7f12..a6e6988 100644 --- a/route/NamePrefixTable_test.go +++ b/route/NamePrefixTable_test.go @@ -63,7 +63,8 @@ func TestNamePrefixTable_FinalTest(t *testing.T) { // 4. 名称前缀表初始化 npt := new(NamePrefixTable) - npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified) + // todo: FIB 初始化 + npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified, nil) // 5. 安装本机adjlsa => 将触发两个事件:A. 安排15s后做路由表计算;B.触发名称前缀表更新(本机lsa不做更新) mlsdb.BuildAndInstallOwnAdjLsa() @@ -153,7 +154,8 @@ func TestNamePrefixTable_AddEntryAndRemoveEntry(t *testing.T) { // 4. 名称前缀表初始化 npt := new(NamePrefixTable) - npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified) + // todo: FIB初始化 + npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified, nil) // 5. 安装本机adjlsa => 将触发两个事件:A. 安排15s后做路由表计算;B.触发名称前缀表更新(本机lsa不做更新) mlsdb.BuildAndInstallOwnAdjLsa() @@ -279,7 +281,8 @@ func TestNamePrefixTable_UpdateFromLsdb(t *testing.T) { // 4. 名称前缀表初始化 npt := new(NamePrefixTable) - npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified) + // todo: FIB初始化 + npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified, nil) // 5. 安装本机adjlsa => 将触发两个事件:A. 安排15s后做路由表计算;B.触发名称前缀表更新(本机lsa不做更新) mlsdb.BuildAndInstallOwnAdjLsa() @@ -414,7 +417,8 @@ func TestNamePrefixTable_UpdateWithNewRoute(t *testing.T) { // 4. 名称前缀表初始化 npt := new(NamePrefixTable) - npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified) + // todo: FIB初始化 + npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified, nil) // 5. 安装本机adjlsa => 将触发两个事件:A. 安排15s后做路由表计算;B.触发名称前缀表更新(本机lsa不做更新) mlsdb.BuildAndInstallOwnAdjLsa() diff --git a/route/RouterMap_test.go b/route/RouterMap_test.go index 2940128..77639e5 100644 --- a/route/RouterMap_test.go +++ b/route/RouterMap_test.go @@ -19,7 +19,7 @@ import ( "testing" ) -const testConfigPath = "D:\\" + common.DefaultConfFileName +const testConfigPath = "../" + common.DefaultConfFileName func TestRouterMap_CreateFromAdjLsdb(t *testing.T) { // 1. 构造LSDB diff --git a/route/RoutingTable.go b/route/RoutingTable.go index 4c0a77e..1aff941 100644 --- a/route/RoutingTable.go +++ b/route/RoutingTable.go @@ -98,6 +98,10 @@ func (t *RoutingTable) Init(mc *common.MlsrConfig, bindFunc := func(args ...interface{}) { // 获取四个参数 ilsa := args[0].(lsa.ILsa) + if ilsa == nil { + common2.LogError("Invalid lsa") + return + } updateType := args[1].(lsdb.LsdbUpdate) common2.LogInfo("RoutingTable.bindFunc: ", ilsa.GetOriginRouter().ToUri(), " ", updateType)