1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-17 15:40:24 +08:00

测试RoutingTableEntry通过,准备测试RoutingTable

This commit is contained in:
free will
2022-06-17 12:15:24 +08:00
parent 3eb8fb51bb
commit cc433661f6
4 changed files with 219 additions and 3 deletions
+32 -3
View File
@@ -43,10 +43,39 @@ type RoutingTable struct {
m_hyperbolicState uint32
}
func (t *RoutingTable) Init() {
//
// Init
// @Description: 初始化
// @receiver t
// @param mc
// @param ms
// @param mlsdb
//
func (t *RoutingTable) Init(mc *common.MlsrConfig,
ms *lsdb.MlsrScheduler, mlsdb *lsdb.Lsdb) {
// 初始化任务调度器
t.scheduler = new(lsdb.MlsrScheduler)
t.scheduler.Init()
t.scheduler = ms
// 初始化配置项
t.mlsrConfig = mc
// 初始化lsdb
t.lsdb = mlsdb
// 路由计算间隔时间
t.m_routingCalcInterval = mc.GetRoutingCalcInterval()
// 路由计算状态
t.m_isRoutingTableCalculating = false
t.m_isRouteCalculationScheduled = false
// todo 事件监听:如果监听到了传来的删除本地邻接LSA操作
// todo 事件监听:如果监听到了传来的安装本地邻接LSA操作
t.m_ownAdjLsaExist = true
// todo 事件监听:如果监听到了传来的安装或更新本地邻接LSA操作
//err := t.ScheduleRoutingTableCalculation()
//if err != nil {
// common2.LogError("RoutingTable.Init ScheduleRoutingTableCalculation error.")
//}
}
//
+13
View File
@@ -23,6 +23,19 @@ type RoutingTableEntry struct {
NextHopList
}
//
// ToString
// @Description: 转string。用于测试
// @receiver e
// @return string
//
func (e *RoutingTableEntry) ToString() string {
res := ""
res += "目的路由器: " + e.m_destination.ToUri() + "\n"
res += e.NextHopList.ToString()
return res
}
//
// NewRoutingTableEntry
// @Description: 新建一个路由表条目
+105
View File
@@ -0,0 +1,105 @@
// Package route
// @Author: Wang Feng
// @Description:
// @Version: 0.1.0
// @Date: 2022/6/17 11:29
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
//
package route
import (
"fmt"
"minlib/component"
"minlib/encoding"
"testing"
)
//
// TestNewRoutingTableEntry
// @Description: 测试构造路由表项
// @param t
//
func TestNewRoutingTableEntry(t *testing.T) {
// 构造
iden, _ := component.CreateIdentifierByString("/pku/abc")
rte, err := NewRoutingTableEntry(iden)
if err != nil {
fmt.Println("构造路由表项失败")
}
// 打印
fmt.Println(rte.GetDestination().ToUri())
}
//
// TestRoutingTableEntry_WireEncode
// @Description: 测试编码
// @param t
//
func TestRoutingTableEntry_WireEncode(t *testing.T) {
// 构造三个下一跳
nthop1, _ := NewNextHop("/hop1", 10)
nthop2, _ := NewNextHop("/hop2", 20)
nthop3, _ := NewNextHop("/hop3", 30)
// 构造路由表项
iden, _ := component.CreateIdentifierByString("/pku/run")
hopList, _ := NewRoutingTableEntry(iden)
hopList.AddNextHop(nthop1)
hopList.AddNextHop(nthop2)
hopList.AddNextHop(nthop3)
// 编码
encoder := encoding.Encoder{}
err := encoder.EncoderReset(encoding.MaxPacketSize, 0)
if err != nil {
fmt.Println("RoutingTableEntry编码报错,", err.Error())
return
}
length, err := hopList.WireEncode(&encoder)
if err != nil {
t.Fatal("RoutingTableEntry编码失败", err.Error())
}
// 获取编码
buf, err := encoder.GetBuffer()
if err != nil {
t.Fatal("RoutingTableEntry获取buffer结果失败", err.Error())
}
// 打印编码结果。如果可以正确解码,则说明编码成功
fmt.Println(length)
for i := 0; i < len(buf); i++ {
fmt.Print(buf[i], ", ")
}
fmt.Println()
}
//
// TestRoutingTableEntry_WireDecode
// @Description: 测试解码
// @param t
//
func TestRoutingTableEntry_WireDecode(t *testing.T) {
// 由数组构建block
var buf = [80]byte{241, 1, 189, 76, 101, 16, 100, 2, 0, 47,
100, 4, 0, 112, 107, 117, 100, 4, 0, 114, 117, 110, 241,
1, 188, 54, 241, 1, 187, 14, 241, 1, 186, 1, 10, 241, 1,
185, 5, 47, 104, 111, 112, 49, 241, 1, 187, 14, 241, 1,
186, 1, 20, 241, 1, 185, 5, 47, 104, 111, 112, 50, 241,
1, 187, 14,
241, 1, 186, 1, 30, 241, 1, 185, 5, 47, 104, 111, 112, 51}
block, err := encoding.CreateBlockByBuffer(buf[:], true)
if err != nil {
fmt.Println("创建block失败 ", err.Error())
return
}
// 由Block构建结构体,并打印变量
base := new(RoutingTableEntry)
err = base.WireDecode(block)
if err != nil {
fmt.Println("线性解码失败 ", err.Error())
return
}
fmt.Println(base.ToString())
}
+69
View File
@@ -0,0 +1,69 @@
// Package route
// @Author: Wang Feng
// @Description:
// @Version: 0.1.0
// @Date: 2022/6/17 11:28
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
//
package route
import (
common2 "minlib/common"
"minlib/logicface"
"mlsr/common"
"mlsr/lsdb"
"testing"
)
//
// TestRoutingTable_Init
// @Description: 测试初始化
// @param t
//
func TestRoutingTable_Init(t *testing.T) {
// 1. 组件初始化
// 配置文件初始化
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. 路由表初始化
rt := new(RoutingTable)
rt.Init(mlsrConfig, sche, mlsdb)
}
//
// TestRoutingTable_AddNextHop
// @Description: 测试构造路由表及其拓扑
// @param t
//
func TestRoutingTable_AddNextHop(t *testing.T) {
}
//
// TestRoutingTable_Calculate
// @Description: 测试计算
// @param t
//
func TestRoutingTable_Calculate(t *testing.T) {
}
//
// TestRoutingTable_ScheduleRoutingTableCalculation
// @Description: 测试安排路由计算
// @param t
//
func TestRoutingTable_ScheduleRoutingTableCalculation(t *testing.T) {
}