mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-10-04 19:42:02 +08:00
增加名称前缀表的打印状态函数;更新Lsdb中关于触发更新的语句
This commit is contained in:
1 parent
7c5ecb3a92
commit
e2803e573a
4 files changed
+103
-7
No files matched your search
+42
-4
@@ -326,7 +326,6 @@ func (l *Lsdb) InstallLsa(lsa lsa.ILsa) {
|
||||
return
|
||||
}
|
||||
// 2. 触发LSDB更新LSA的动作信号 OnLsdbModified(lsa, LsdbUpdate::UPDATED, namesToAdd, namesToRemove);
|
||||
// todo 实现该方法:对比两个lsa,将其不同的部分取出来
|
||||
updated, namesToAdd, namesToRemove := l.compareTwoLsa(lsaInDb, lsa)
|
||||
if updated && !l.OnLsdbModified.IsEmpty() {
|
||||
l.OnLsdbModified.Emit(lsa, UPDATED, namesToAdd, namesToRemove)
|
||||
@@ -343,12 +342,51 @@ func (l *Lsdb) InstallLsa(lsa lsa.ILsa) {
|
||||
// @receiver l
|
||||
// @param lsaA
|
||||
// @param lsaB
|
||||
// @return bool
|
||||
// @return bool 如果有不同,就返回true
|
||||
// @return []*component.Identifier
|
||||
// @return []component.Identifier
|
||||
//
|
||||
func (l *Lsdb) compareTwoLsa(lsaA lsa.ILsa, lsaB lsa.ILsa) (bool, []*component.Identifier, []component.Identifier) {
|
||||
return true, nil, nil
|
||||
func (l *Lsdb) compareTwoLsa(lsaA lsa.ILsa, lsaB lsa.ILsa) (bool, []*component.Identifier, []*component.Identifier) {
|
||||
namesToAdd := []*component.Identifier{}
|
||||
namesToRemove := []*component.Identifier{}
|
||||
// 前置判断,确定两个都是名称Lsa
|
||||
if lsaA.GetType() != lsa.LsaNAMEType || lsaB.GetType() != lsa.LsaNAMEType {
|
||||
return false, namesToAdd, namesToRemove
|
||||
}
|
||||
// 转换为名称Lsa
|
||||
lsa1 := lsaA.(*lsa.NameLsa)
|
||||
lsa2 := lsaB.(*lsa.NameLsa)
|
||||
lsaPrefixs1 := lsa1.GetNamePrefixes()
|
||||
lsaPrefixs2 := lsa2.GetNamePrefixes()
|
||||
// lsa2有而lsa1没的,则为要添加的
|
||||
for i := 0; i < len(lsaPrefixs2); i++ {
|
||||
if !existsIdentifier(lsaPrefixs2[i], lsaPrefixs1) {
|
||||
namesToAdd = append(namesToAdd, lsaPrefixs2[i])
|
||||
}
|
||||
}
|
||||
// lsa1有而lsa2没的,则为要删除的
|
||||
for i := 0; i < len(lsaPrefixs1); i++ {
|
||||
if !existsIdentifier(lsaPrefixs1[i], lsaPrefixs2) {
|
||||
namesToRemove = append(namesToRemove, lsaPrefixs1[i])
|
||||
}
|
||||
}
|
||||
return true, namesToAdd, namesToRemove
|
||||
}
|
||||
|
||||
//
|
||||
// existsIdentifier
|
||||
// @Description: 判断是否有某个identifier
|
||||
// @param target
|
||||
// @param identifiers
|
||||
// @return bool
|
||||
//
|
||||
func existsIdentifier(target *component.Identifier, identifiers []*component.Identifier) bool {
|
||||
for i := 0; i < len(identifiers); i++ {
|
||||
if identifiers[i].ToUri() == target.ToUri() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
common2 "minlib/common"
|
||||
"minlib/component"
|
||||
"mlsr/lsa"
|
||||
@@ -38,6 +39,28 @@ type NamePrefixTable struct {
|
||||
// todo fib
|
||||
}
|
||||
|
||||
//
|
||||
// PrintSelf
|
||||
// @Description: 打印名称前缀表的状态。用于测试。
|
||||
// @receiver t
|
||||
//
|
||||
func (t *NamePrefixTable) PrintSelf() {
|
||||
fmt.Println("------------------- Name Prefix Table begin: " + t.m_ownRouterName.ToUri() + " -----------------")
|
||||
fmt.Println("-----------------" + " 1.路由表项池 begin " + "-----------------")
|
||||
fmt.Println("路由表项池大小:", len(t.m_rtpool))
|
||||
for _, rtpe := range t.m_rtpool {
|
||||
fmt.Println(rtpe.ToString())
|
||||
}
|
||||
fmt.Println("-----------------" + " 1.路由表项池 end " + "-----------------")
|
||||
fmt.Println("----------------" + " 2.名称前缀列表 start " + "----------------")
|
||||
for i := 0; i < len(t.nptEntryList); i++ {
|
||||
fmt.Println(t.nptEntryList[i].ToString())
|
||||
}
|
||||
fmt.Println("----------------" + " 2.名称前缀列表 end " + "----------------")
|
||||
t.m_routingTable.PrintSelf()
|
||||
fmt.Println("------------------- Name Prefix Table end: " + t.m_ownRouterName.ToUri() + " -----------------")
|
||||
}
|
||||
|
||||
//
|
||||
// Init
|
||||
// @Description: 名称前缀表初始化
|
||||
@@ -73,7 +96,7 @@ func (t *NamePrefixTable) Init(ownRouterName *component.Identifier,
|
||||
common2.LogInfo("NamePrefixTable bindLsdbModifiedFunc updateType: ", updateType)
|
||||
namesToAdd := []*component.Identifier{}
|
||||
namesToRemove := []*component.Identifier{}
|
||||
if updateType == lsdb.REMOVED {
|
||||
if updateType == lsdb.UPDATED {
|
||||
namesToAdd = args[2].([]*component.Identifier)
|
||||
namesToRemove = args[3].([]*component.Identifier)
|
||||
}
|
||||
|
||||
@@ -120,7 +120,42 @@ func TestNamePrefixTable_FinalTest(t *testing.T) {
|
||||
// @param t
|
||||
//
|
||||
func TestNamePrefixTable_AddEntry(t *testing.T) {
|
||||
// 1. 建立前置结构体(lsdb等)
|
||||
// 配置文件初始化
|
||||
mlsrConfig, err := common.ParseConfig(testConfigPath)
|
||||
if err != nil {
|
||||
common2.LogInfo("配置文件解析错误")
|
||||
}
|
||||
// 调度器初始化
|
||||
sche := new(lsdb.MlsrScheduler)
|
||||
sche.Init()
|
||||
// LogicFace初始化(假设初始化,暂时用不到)
|
||||
face := new(logicface.LogicFace)
|
||||
// LSDB初始化
|
||||
mlsdb := new(lsdb.Lsdb)
|
||||
mlsdb.Init(mlsrConfig, sche, face)
|
||||
|
||||
// 2. 打印lsdb中所有本机lsa
|
||||
lsas, _ := mlsdb.LsaContainer.GetLSAsByType(lsa.LsaADJACENCYType)
|
||||
for i := 0; i < len(lsas); i++ {
|
||||
common2.LogInfo(lsas[i].ToString())
|
||||
}
|
||||
lsas, _ = mlsdb.LsaContainer.GetLSAsByType(lsa.LsaNAMEType)
|
||||
for i := 0; i < len(lsas); i++ {
|
||||
common2.LogInfo(lsas[i].ToString())
|
||||
}
|
||||
fmt.Println("lsdb是否正在忙于构建lsdb: ", mlsdb.GetIsBuildAdjLsaScheduled())
|
||||
|
||||
// 3. 路由表初始化
|
||||
rt := new(RoutingTable)
|
||||
rt.Init(mlsrConfig, sche, mlsdb)
|
||||
|
||||
// 4. 名称前缀表初始化
|
||||
npt := new(NamePrefixTable)
|
||||
npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified)
|
||||
|
||||
// 5. 安装本机adjlsa => 将触发两个事件:A. 安排15s后做路由表计算;B.触发名称前缀表更新(本机lsa不做更新)
|
||||
mlsdb.BuildAndInstallOwnAdjLsa()
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -56,16 +56,16 @@ type RoutingTable struct {
|
||||
// @receiver t
|
||||
//
|
||||
func (t *RoutingTable) PrintSelf() {
|
||||
fmt.Println("----------- Table beg ---------")
|
||||
fmt.Println("----------- Routing Table begin ---------")
|
||||
fmt.Println("len: ", len(t.rTable))
|
||||
for i := 0; i < len(t.rTable); i++ {
|
||||
fmt.Println(t.rTable[i].ToString())
|
||||
}
|
||||
fmt.Println("----------- Table end ---------")
|
||||
fmt.Println("路由计算间隔: ", t.m_routingCalcInterval.String())
|
||||
fmt.Println("是否正在计算: ", t.m_isRoutingTableCalculating)
|
||||
fmt.Println("是否安排计算: ", t.m_isRouteCalculationScheduled)
|
||||
fmt.Println("本机路由器邻接lsa存在状态: ", t.m_ownAdjLsaExist)
|
||||
fmt.Println("----------- Routing Table end ---------")
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user