1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-18 09:10:25 +08:00
Files
mlsr/hello/HelloProtocol_test.go
2022-09-11 19:31:03 +08:00

92 lines
2.5 KiB
Go

// Package hello
// @Author: Wang Feng
// @Description:
// @Version: 0.1.0
// @Date: 2022/7/29 21:14
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
//
package hello
import (
common2 "minlib/common"
"minlib/component"
"minlib/logicface"
"minlib/security"
"mlsr/common"
"mlsr/lsdb"
"mlsr/route"
"testing"
)
const testConfigPath = "D:\\" + common.DefaultConfFileName
//
// TestHelloProtocol_Init
// @Description: 初始化
// @param t
//
func TestHelloProtocol_Init(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.DummyClientLogicFace)
keychain := new(security.KeyChain)
// LSDB初始化
mlsdb := new(lsdb.Lsdb)
mlsdb.Init(mlsrConfig, sche, face)
rt := new(route.RoutingTable)
rt.Init(mlsrConfig, sche, mlsdb)
// 名称前缀表初始化
npt := new(route.NamePrefixTable)
// todo: fib 初始化
npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified, nil)
// 2. 初始化hello协议
hp := new(HelloProtocol)
hp.Init(face, sche, keychain, mlsrConfig, rt, mlsdb)
}
//
// TestHelloProtocol_SendHelloInterest
// @Description: todo 需要真机测试,看对端是否能接收到该探测包
// @param t
//
func TestHelloProtocol_SendHelloInterest(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.DummyClientLogicFace)
keychain := new(security.KeyChain)
// LSDB初始化
mlsdb := new(lsdb.Lsdb)
mlsdb.Init(mlsrConfig, sche, face)
rt := new(route.RoutingTable)
rt.Init(mlsrConfig, sche, mlsdb)
// 名称前缀表初始化
npt := new(route.NamePrefixTable)
// todo: fib 初始化
npt.Init(mlsrConfig.GetRouterPrefix(), rt, rt.AfterRoutingChange, mlsdb.OnLsdbModified, nil)
// 2. 初始化hello协议
hp := new(HelloProtocol)
hp.Init(face, sche, keychain, mlsrConfig, rt, mlsdb)
iden, _ := component.CreateIdentifierByString("/min/pku/testHello")
hp.SendHelloInterest(iden)
}