Merge remote-tracking branch 'origin/local'

This commit is contained in:
free will committed 2022-09-18 23:31:32 +08:00
commit 341458bfd3
13 files changed
+73 -38

No files matched your search

+12 -3
View File
@@ -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的工厂方法
+1 -1
View File
@@ -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
@@ -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
}
+4 -4
View File
@@ -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
}
+2 -2
View File
@@ -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]
+5 -1
View File
@@ -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 {
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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
}
+11 -13
View File
@@ -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)
+19 -3
View File
@@ -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)
+8 -4
View File
@@ -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()
+1 -1
View File
@@ -19,7 +19,7 @@ import (
"testing"
)
const testConfigPath = "D:\\" + common.DefaultConfFileName
const testConfigPath = "../" + common.DefaultConfFileName
func TestRouterMap_CreateFromAdjLsdb(t *testing.T) {
// 1. 构造LSDB
+4
View File
@@ -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)