1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-18 05:50:25 +08:00
Files
mlsr/hello/HelloProtocol_backup_test.go
2022-07-14 14:49:11 +08:00

189 lines
4.9 KiB
Go

package hello
////@Author: Pei Xinyuan
////@Description:
////@Version: 0.1.0
////@Date: 2022/5/5 12:29:00
////@Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
//
//package hello
//
//import (
// "math/rand"
// "minlib/component"
// "minlib/packet"
// "mlsr/lsa"
// "testing"
// "time"
//)
//
//var h = new(HelloProtocol)
//
////
//// TestExpressInterest
//// @Description: 测试“发送一个Hello兴趣包”
//// @param t
////
//func TestExpressInterest(t *testing.T) {
// //构建*identifier
// var interestName *component.Identifier
// var str = "/min"
// if interestName != nil {
// interestName.BuildIdentifierByString(str)
// //声明并初始化一个生命周期
// var seconds uint32 = 10
// //测试这个方法
// if h != nil {
// 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
//}