1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-06 03:59:27 +08:00

测试HelloProtocol文件

This commit is contained in:
pxy
2022-05-05 20:55:06 +08:00
parent f2486d771b
commit bce7f4839a
3 changed files with 173 additions and 165 deletions
+21 -17
View File
@@ -230,11 +230,13 @@ func (h *HelloProtocol) ProcessInterestTimeOut(interest *packet.Interest) {
func (h *HelloProtocol) OnContent(data *packet.Data) { func (h *HelloProtocol) OnContent(data *packet.Data) {
logrus.Debug("Received data for name:v%", data.GetName()) logrus.Debug("Received data for name:v%", data.GetName())
Sig, _ := data.GetSignature(0) //获取指定位置的签名 Sig, _ := data.GetSignature(0) //获取指定位置的签名
kl := Sig.SigInfo.GetKeyLocator() if Sig != nil {
if kl != nil { kl := Sig.SigInfo.GetKeyLocator()
if h.keychain.VerifyData(data) != nil { if kl != nil {
fmt.Println("Data signed with:v%", kl.GetIdentifier()) if h.keychain.VerifyData(data) != nil {
logrus.Debug("Data signed with:v%", kl.GetIdentifier()) fmt.Println("Data signed with:v%", kl.GetIdentifier())
logrus.Debug("Data signed with:v%", kl.GetIdentifier())
}
} }
} }
@@ -254,19 +256,21 @@ func (h *HelloProtocol) OnContentValidated(data *packet.Data) {
neighborPrefix, _ := dataName.Get(0) //*identifierComponent neighborPrefix, _ := dataName.Get(0) //*identifierComponent
var neighbor *component.Identifier var neighbor *component.Identifier
//neighbor.WireDecode(neighborPrefix.Raw()) //neighbor.WireDecode(neighborPrefix.Raw())
neighbor.BuildIdentifierByString(neighborPrefix.ToString()) if neighbor != nil {
neighbor.BuildIdentifierByString(neighborPrefix.ToString())
oldStatus, _ := adjacentList.GetStatusOfNeighbor(neighbor) //*identifier oldStatus, _ := adjacentList.GetStatusOfNeighbor(neighbor) //*identifier
adjacentList.SetStatusOfNeighbor(neighbor, 1) //邻居路由器的状态:未知-1、未激活0、激活1 adjacentList.SetStatusOfNeighbor(neighbor, 1) //邻居路由器的状态:未知-1、未激活0、激活1
adjacentList.SetTimedOutInterestCount(neighbor, 0) adjacentList.SetTimedOutInterestCount(neighbor, 0)
newStatus, _ := adjacentList.GetStatusOfNeighbor(neighbor) newStatus, _ := adjacentList.GetStatusOfNeighbor(neighbor)
fmt.Println("Neighbor:v%", neighbor) fmt.Println("Neighbor:v%", neighbor)
fmt.Println("Old status:v%,New status:v%", oldStatus, newStatus) fmt.Println("Old status:v%,New status:v%", oldStatus, newStatus)
logrus.Debug("Neighbor:v%", neighbor) logrus.Debug("Neighbor:v%", neighbor)
logrus.Debug("Old status:v%,New status:v%", oldStatus, newStatus) logrus.Debug("Old status:v%,New status:v%", oldStatus, newStatus)
// change in Adjacency list // change in Adjacency list
if oldStatus != newStatus { if oldStatus != newStatus {
h.ScheduleAdjLsaBuild() h.ScheduleAdjLsaBuild()
}
} }
} }
+152 -4
View File
@@ -8,8 +8,12 @@
package hello package hello
import ( import (
"math/rand"
"minlib/component" "minlib/component"
"minlib/packet"
"mlsr/lsa"
"testing" "testing"
"time"
) )
var h = new(HelloProtocol) var h = new(HelloProtocol)
@@ -28,12 +32,156 @@ func TestExpressInterest(t *testing.T) {
//声明并初始化一个生命周期 //声明并初始化一个生命周期
var seconds uint32 = 10 var seconds uint32 = 10
//测试这个方法 //测试这个方法
//fmt.Println(h.ExpressInterest())
//if h.ExpressInterest(interestName, seconds) != nil {
// fmt.Println("Success!")
//}
if h != nil { if h != nil {
h.ExpressInterest(interestName, seconds) h.ExpressInterest(interestName, seconds)
} }
} }
} }
//
// TestSendHelloInterest
// @Description: 测试发送hello兴趣包给一个邻居
// @receiver h
// @param t
//
func TestSendHelloInterest(t *testing.T) {
//构建*identifier
var neighbor *component.Identifier
var str = "/min/MLSR/INFO/router1"
if neighbor != nil {
neighbor.BuildIdentifierByString(str)
//构建*AdjLsaAdjacencyInfo
var info *lsa.AdjLsaAdjacencyInfo
info.SetLinkCost(1)
info.SetNeighborRouterIdentifier(neighbor)
info.SetLogicFaceId(182828)
//构建adjacentList
adjacentList.Insert(info)
if h != nil {
//测试该方法,本方法中最后一步是ExpressInterest,若发送成功则输出“Express successfully”,否则输出“Express unsuccessfully”
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"
if interest != nil {
if interestName != nil {
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.Payload.SetValue(RandString(7000))
//构建*AdjLsaAdjacencyInfo
var info *lsa.AdjLsaAdjacencyInfo
info.SetLinkCost(1)
info.SetNeighborRouterIdentifier(interestName)
info.SetLogicFaceId(182828)
//构建adjacentList
adjacentList.Insert(info)
//测试该方法
if h != nil {
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"
if interest != nil {
if interestName != nil {
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.Payload.SetValue(RandString(7000))
//构建*AdjLsaAdjacencyInfo
var info *lsa.AdjLsaAdjacencyInfo
info.SetLinkCost(1)
info.SetNeighborRouterIdentifier(interestName)
info.SetLogicFaceId(182828)
//构建adjacentList
adjacentList.Insert(info)
if h != nil {
//测试该方法
h.ProcessInterestTimeOut(interest)
}
}
}
}
func TestOnContent(t *testing.T) {
//构建data
data := new(packet.Data)
if data != nil {
data.FreshnessPeriod.SetFreshnessPeriod(02346345465453)
data.Payload.SetValue([]byte{132, 221, 223, 25})
data.CongestionMark.SetCongestionLevel(1190919)
name, _ := component.CreateIdentifierByString("/min/MLSR/INFO/router1/1")
if name != nil {
data.SetName(name)
if h != nil {
//测试该方法
h.OnContent(data)
}
}
}
}
func TestOnContentValidated(t *testing.T) {
//构建data
data := new(packet.Data)
if data != nil {
data.FreshnessPeriod.SetFreshnessPeriod(02346345465453)
data.Payload.SetValue([]byte{132, 221, 223, 25})
data.CongestionMark.SetCongestionLevel(1190919)
name, _ := component.CreateIdentifierByString("/min/MLSR/INFO/router1/1")
if name != nil {
data.SetName(name)
if h != nil {
//测试该方法
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
}
-144
View File
@@ -1,144 +0,0 @@
//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
}