mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-10-04 19:42:02 +08:00
测试ExpressInterest方法
This commit is contained in:
1 parent
b628dcf26c
commit
f2486d771b
6 files changed
+171
-144
No files matched your search
@@ -3,7 +3,7 @@ module mlsr
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/smartystreets/goconvey v1.7.2 // indirect
|
||||
github.com/tidwall/btree v1.2.1 // indirect
|
||||
github.com/tidwall/buntdb v1.2.9
|
||||
|
||||
@@ -57,5 +57,3 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
|
||||
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
|
||||
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -47,8 +47,8 @@ var adjacentList *lsa.AdjLsaAdjacenctList
|
||||
// @param interestNamePrefix
|
||||
// @param seconds
|
||||
//
|
||||
func (h *HelloProtocol) ExpressInterest(interestName *component.Identifier, seconds uint32) {
|
||||
logrus.Debug("Expressing Interest:%v", interestName)
|
||||
func (h *HelloProtocol) ExpressInterest(interestName *component.Identifier, seconds uint32) error {
|
||||
logrus.Debug("Expressing Interest: ", interestName)
|
||||
var interest *packet.Interest
|
||||
interest.SetName(interestName) //设置兴趣包的名字
|
||||
interest.SetInterestLifeTime(uint64(seconds)) //设置兴趣包的生命周期
|
||||
@@ -61,6 +61,7 @@ func (h *HelloProtocol) ExpressInterest(interestName *component.Identifier, seco
|
||||
} else {
|
||||
fmt.Println("Express unseccessfully!")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendHelloInterest
|
||||
@@ -91,7 +92,7 @@ func (h *HelloProtocol) SendHelloInterest(neighbor *component.Identifier) {
|
||||
interestName.Append(info1) //在兴趣包名字后面添加“INFO”
|
||||
interestName.Append(thisRouterPrefix) //在兴趣包名字后面添加本路由器的前缀
|
||||
h.ExpressInterest(interestName, h.mlsrConfig.HelloTimeout) //将兴趣包传出去
|
||||
logrus.Debug("Sending Hello Interest:%v", interestName) //日志记录
|
||||
logrus.Debug("Sending Hello Interest:", interestName) //日志记录
|
||||
}
|
||||
//使用调度器循环调度上面事件,调度器里传入两个参数:一个是间隔时间,一个是event,意思是每隔HelloInterval时间就调用一次event事件
|
||||
//h.scheduler.scheduler(h.mlsrConfig.HelloInterval,{h.SendHelloInterest(this.neighbor)})
|
||||
|
||||
+15
-131
@@ -8,148 +8,32 @@
|
||||
package hello
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"minlib/component"
|
||||
"minlib/packet"
|
||||
"mlsr/lsa"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var h = new(HelloProtocol)
|
||||
|
||||
//
|
||||
// TestExpressInterest
|
||||
// @Description: 测试“发送一个Hello兴趣包”
|
||||
// @param t
|
||||
//
|
||||
func (h *HelloProtocol) TestExpressInterest(t *testing.T) {
|
||||
func TestExpressInterest(t *testing.T) {
|
||||
//构建*identifier
|
||||
var interestName *component.Identifier
|
||||
var str = "/min"
|
||||
interestName.BuildIdentifierByString(str)
|
||||
//声明并初始化一个生命周期
|
||||
var seconds uint32 = 10
|
||||
//测试这个方法
|
||||
h.ExpressInterest(interestName, seconds)
|
||||
}
|
||||
|
||||
//
|
||||
// TestSendHelloInterest
|
||||
// @Description: 测试发送hello兴趣包给一个邻居
|
||||
// @receiver h
|
||||
// @param t
|
||||
//
|
||||
func (h *HelloProtocol) TestSendHelloInterest(t *testing.T) {
|
||||
//构建*identifier
|
||||
var neighbor *component.Identifier
|
||||
var str = "/min/MLSR/INFO/router1"
|
||||
neighbor.BuildIdentifierByString(str)
|
||||
//构建*AdjLsaAdjacencyInfo
|
||||
var info *lsa.AdjLsaAdjacencyInfo
|
||||
info.SetLinkCost(1)
|
||||
info.SetNeighborRouterIdentifier(neighbor)
|
||||
info.SetLogicFaceId(182828)
|
||||
//构建adjacentList
|
||||
adjacentList.Insert(info)
|
||||
//测试该方法,本方法中最后一步是ExpressInterest,若发送成功则输出“Express successfully”,否则输出“Express unsuccessfully”
|
||||
h.SendHelloInterest(neighbor)
|
||||
}
|
||||
|
||||
//
|
||||
// TestProcessInterest
|
||||
// @Description: 测试处理来自邻居的Hello兴趣包
|
||||
// @receiver h
|
||||
// @param t
|
||||
//
|
||||
func (h *HelloProtocol) TestProcessInterest(t *testing.T) {
|
||||
//构建interest
|
||||
var interest *packet.Interest
|
||||
var interestName *component.Identifier
|
||||
var str = "/min/MLSR/INFO/router1"
|
||||
interestName.BuildIdentifierByString(str)
|
||||
interest.SetName(interestName)
|
||||
interest.SetInterestLifeTime(10)
|
||||
interest.SetCanBePrefix(true)
|
||||
interest.SetMustBeRefresh(true)
|
||||
interest.SetNonce(1234)
|
||||
interest.SetHopLimit(1234)
|
||||
interest.SetCongestionLevel(1234)
|
||||
interest.SetTtl(1234)
|
||||
interest.Payload.SetValue(RandString(7000))
|
||||
//构建*AdjLsaAdjacencyInfo
|
||||
var info *lsa.AdjLsaAdjacencyInfo
|
||||
info.SetLinkCost(1)
|
||||
info.SetNeighborRouterIdentifier(interestName)
|
||||
info.SetLogicFaceId(182828)
|
||||
//构建adjacentList
|
||||
adjacentList.Insert(info)
|
||||
//测试该方法
|
||||
h.ProcessInterest(interest)
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// TestProcessInterestTimeOut
|
||||
// @Description: 测试重连
|
||||
// @receiver h
|
||||
// @param t
|
||||
//
|
||||
func (h *HelloProtocol) TestProcessInterestTimeOut(t *testing.T) {
|
||||
//构建interest
|
||||
var interest *packet.Interest
|
||||
var interestName *component.Identifier
|
||||
var str = "/min/MLSR/INFO/router1"
|
||||
interestName.BuildIdentifierByString(str)
|
||||
interest.SetName(interestName)
|
||||
interest.SetInterestLifeTime(10)
|
||||
interest.SetCanBePrefix(true)
|
||||
interest.SetMustBeRefresh(true)
|
||||
interest.SetNonce(1234)
|
||||
interest.SetHopLimit(1234)
|
||||
interest.SetCongestionLevel(1234)
|
||||
interest.SetTtl(1234)
|
||||
interest.Payload.SetValue(RandString(7000))
|
||||
//构建*AdjLsaAdjacencyInfo
|
||||
var info *lsa.AdjLsaAdjacencyInfo
|
||||
info.SetLinkCost(1)
|
||||
info.SetNeighborRouterIdentifier(interestName)
|
||||
info.SetLogicFaceId(182828)
|
||||
//构建adjacentList
|
||||
adjacentList.Insert(info)
|
||||
//测试该方法
|
||||
h.ProcessInterestTimeOut(interest)
|
||||
|
||||
}
|
||||
|
||||
func (h *HelloProtocol) TestOnContent(t *testing.T) {
|
||||
//构建data
|
||||
data := new(packet.Data)
|
||||
data.FreshnessPeriod.SetFreshnessPeriod(02346345465453)
|
||||
data.Payload.SetValue([]byte{132, 221, 223, 25})
|
||||
data.CongestionMark.SetCongestionLevel(1190919)
|
||||
name, _ := component.CreateIdentifierByString("/min/MLSR/INFO/router1/1")
|
||||
data.SetName(name)
|
||||
//测试该方法
|
||||
h.OnContent(data)
|
||||
|
||||
}
|
||||
|
||||
func (h *HelloProtocol) TestOnContentValidated(t *testing.T) {
|
||||
//构建data
|
||||
data := new(packet.Data)
|
||||
data.FreshnessPeriod.SetFreshnessPeriod(02346345465453)
|
||||
data.Payload.SetValue([]byte{132, 221, 223, 25})
|
||||
data.CongestionMark.SetCongestionLevel(1190919)
|
||||
name, _ := component.CreateIdentifierByString("/min/MLSR/INFO/router1/1")
|
||||
data.SetName(name)
|
||||
//测试该方法
|
||||
h.OnContentValidated(data)
|
||||
}
|
||||
func RandString(len int) []byte {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
bytes := make([]byte, len)
|
||||
for i := 0; i < len; i++ {
|
||||
b := r.Intn(26) + 65
|
||||
bytes[i] = byte(b)
|
||||
if interestName != nil {
|
||||
interestName.BuildIdentifierByString(str)
|
||||
//声明并初始化一个生命周期
|
||||
var seconds uint32 = 10
|
||||
//测试这个方法
|
||||
//fmt.Println(h.ExpressInterest())
|
||||
//if h.ExpressInterest(interestName, seconds) != nil {
|
||||
// fmt.Println("Success!")
|
||||
//}
|
||||
if h != nil {
|
||||
h.ExpressInterest(interestName, seconds)
|
||||
}
|
||||
}
|
||||
return bytes
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
//package hello
|
||||
//@Author: Pei Xinyuan
|
||||
//@Description:
|
||||
//@Version: 0.1.0
|
||||
//@Date: 2022/5/5 17:04:00
|
||||
//@Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
|
||||
package hello
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"minlib/component"
|
||||
"minlib/packet"
|
||||
"mlsr/lsa"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
//
|
||||
// TestSendHelloInterest
|
||||
// @Description: 测试发送hello兴趣包给一个邻居
|
||||
// @receiver h
|
||||
// @param t
|
||||
//
|
||||
func TestSendHelloInterest(t *testing.T) {
|
||||
//构建*identifier
|
||||
var neighbor *component.Identifier
|
||||
var str = "/min/MLSR/INFO/router1"
|
||||
neighbor.BuildIdentifierByString(str)
|
||||
//构建*AdjLsaAdjacencyInfo
|
||||
var info *lsa.AdjLsaAdjacencyInfo
|
||||
info.SetLinkCost(1)
|
||||
info.SetNeighborRouterIdentifier(neighbor)
|
||||
info.SetLogicFaceId(182828)
|
||||
//构建adjacentList
|
||||
adjacentList.Insert(info)
|
||||
//测试该方法,本方法中最后一步是ExpressInterest,若发送成功则输出“Express successfully”,否则输出“Express unsuccessfully”
|
||||
//var h HelloProtocol
|
||||
//h.SendHelloInterest(neighbor)
|
||||
}
|
||||
|
||||
//
|
||||
// TestProcessInterest
|
||||
// @Description: 测试处理来自邻居的Hello兴趣包
|
||||
// @receiver h
|
||||
// @param t
|
||||
//
|
||||
func TestProcessInterest(t *testing.T) {
|
||||
//构建interest
|
||||
var interest *packet.Interest
|
||||
var interestName *component.Identifier
|
||||
var str = "/min/MLSR/INFO/router1"
|
||||
interestName.BuildIdentifierByString(str)
|
||||
interest.SetName(interestName)
|
||||
interest.SetInterestLifeTime(10)
|
||||
interest.SetCanBePrefix(true)
|
||||
interest.SetMustBeRefresh(true)
|
||||
interest.SetNonce(1234)
|
||||
interest.SetHopLimit(1234)
|
||||
interest.SetCongestionLevel(1234)
|
||||
interest.SetTtl(1234)
|
||||
interest.Payload.SetValue(RandString(7000))
|
||||
//构建*AdjLsaAdjacencyInfo
|
||||
var info *lsa.AdjLsaAdjacencyInfo
|
||||
info.SetLinkCost(1)
|
||||
info.SetNeighborRouterIdentifier(interestName)
|
||||
info.SetLogicFaceId(182828)
|
||||
//构建adjacentList
|
||||
adjacentList.Insert(info)
|
||||
//测试该方法
|
||||
var h *HelloProtocol
|
||||
h.ProcessInterest(interest)
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// TestProcessInterestTimeOut
|
||||
// @Description: 测试重连
|
||||
// @receiver h
|
||||
// @param t
|
||||
//
|
||||
func TestProcessInterestTimeOut(t *testing.T) {
|
||||
//构建interest
|
||||
var interest *packet.Interest
|
||||
var interestName *component.Identifier
|
||||
var str = "/min/MLSR/INFO/router1"
|
||||
interestName.BuildIdentifierByString(str)
|
||||
interest.SetName(interestName)
|
||||
interest.SetInterestLifeTime(10)
|
||||
interest.SetCanBePrefix(true)
|
||||
interest.SetMustBeRefresh(true)
|
||||
interest.SetNonce(1234)
|
||||
interest.SetHopLimit(1234)
|
||||
interest.SetCongestionLevel(1234)
|
||||
interest.SetTtl(1234)
|
||||
interest.Payload.SetValue(RandString(7000))
|
||||
//构建*AdjLsaAdjacencyInfo
|
||||
var info *lsa.AdjLsaAdjacencyInfo
|
||||
info.SetLinkCost(1)
|
||||
info.SetNeighborRouterIdentifier(interestName)
|
||||
info.SetLogicFaceId(182828)
|
||||
//构建adjacentList
|
||||
adjacentList.Insert(info)
|
||||
//测试该方法
|
||||
var h *HelloProtocol
|
||||
h.ProcessInterestTimeOut(interest)
|
||||
|
||||
}
|
||||
|
||||
func TestOnContent(t *testing.T) {
|
||||
//构建data
|
||||
data := new(packet.Data)
|
||||
data.FreshnessPeriod.SetFreshnessPeriod(02346345465453)
|
||||
data.Payload.SetValue([]byte{132, 221, 223, 25})
|
||||
data.CongestionMark.SetCongestionLevel(1190919)
|
||||
name, _ := component.CreateIdentifierByString("/min/MLSR/INFO/router1/1")
|
||||
data.SetName(name)
|
||||
//测试该方法
|
||||
var h *HelloProtocol
|
||||
h.OnContent(data)
|
||||
|
||||
}
|
||||
|
||||
func TestOnContentValidated(t *testing.T) {
|
||||
//构建data
|
||||
data := new(packet.Data)
|
||||
data.FreshnessPeriod.SetFreshnessPeriod(02346345465453)
|
||||
data.Payload.SetValue([]byte{132, 221, 223, 25})
|
||||
data.CongestionMark.SetCongestionLevel(1190919)
|
||||
name, _ := component.CreateIdentifierByString("/min/MLSR/INFO/router1/1")
|
||||
data.SetName(name)
|
||||
//测试该方法
|
||||
var h *HelloProtocol
|
||||
h.OnContentValidated(data)
|
||||
}
|
||||
func RandString(len int) []byte {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
bytes := make([]byte, len)
|
||||
for i := 0; i < len; i++ {
|
||||
b := r.Intn(26) + 65
|
||||
bytes[i] = byte(b)
|
||||
}
|
||||
return bytes
|
||||
}
|
||||
+7
-7
@@ -24,8 +24,8 @@ import (
|
||||
func TestLsaBase_GetType(t *testing.T) {
|
||||
base := new(LsaBase)
|
||||
fmt.Println(base.GetType())
|
||||
if base.GetType() != 0{
|
||||
log.Fatal("base type error: ",base.GetType())
|
||||
if base.GetType() != 0 {
|
||||
log.Fatal("base type error: ", base.GetType())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestLsaBase_WireEncode(t *testing.T) {
|
||||
base := new(LsaBase)
|
||||
base.SetLsaExpirationTime(2000)
|
||||
base.SetLsaSequenceNumber(1234)
|
||||
base.LsaOriginRouterIdentifier,_ = component.CreateIdentifierByString("/min/pku")
|
||||
base.LsaOriginRouterIdentifier, _ = component.CreateIdentifierByString("/min/pku")
|
||||
|
||||
// 构造编码器
|
||||
encoder := encoding.Encoder{}
|
||||
@@ -61,8 +61,8 @@ func TestLsaBase_WireEncode(t *testing.T) {
|
||||
return
|
||||
}
|
||||
fmt.Println(cnt)
|
||||
for i:=0;i < len(res);i++{
|
||||
fmt.Print(res[i],", ")
|
||||
for i := 0; i < len(res); i++ {
|
||||
fmt.Print(res[i], ", ")
|
||||
}
|
||||
fmt.Println()
|
||||
// 34 [241 1 154 30 101 16 100 2 0 47 100 4 0 109 105 110 100 4 0 112 107 117 241 1 165 2 4 210 241 1 164 2 7 208]
|
||||
@@ -90,6 +90,6 @@ func TestLsaBase_WireDecode(t *testing.T) {
|
||||
fmt.Println("线性解码失败 ", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println(base.LsaExpirationTime.LsaExpirationTime()," ",base.LsaSequenceNumber.LsaSequenceNumber(),
|
||||
" ",base.LsaOriginRouterIdentifier.ToUri())
|
||||
fmt.Println(base.LsaExpirationTime.LsaExpirationTime(), " ", base.LsaSequenceNumber.LsaSequenceNumber(),
|
||||
" ", base.LsaOriginRouterIdentifier.ToUri())
|
||||
}
|
||||
Reference in new issue
Block a user