mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-06 15:49:28 +08:00
131 lines
3.7 KiB
Go
131 lines
3.7 KiB
Go
// Package lsa
|
|
// @Author: Wang Feng
|
|
// @Description:
|
|
// @Version: 0.1.0
|
|
// @Date: 2022/4/22 11:01
|
|
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
|
//
|
|
|
|
package lsa
|
|
|
|
import (
|
|
"fmt"
|
|
"minlib/component"
|
|
"minlib/encoding"
|
|
"testing"
|
|
)
|
|
|
|
//
|
|
// TestNewAdjLsaAdjacencyInfo
|
|
// @Description: 测试构造一条邻接信息
|
|
// @param t
|
|
//
|
|
func TestNewAdjLsaAdjacencyInfo(t *testing.T) {
|
|
linkCost := AdjLsaLinkCost{}
|
|
linkCost.SetLinkCost(100)
|
|
faceUri := AdjLsaLogicFaceUri{}
|
|
faceUri.SetLogicFaceUri("uri")
|
|
faceId := AdjLsaLogicFaceId{}
|
|
faceId.SetLogicFaceId(77)
|
|
iden, _ := component.CreateIdentifierByString("/pku/router")
|
|
adjInfo := NewAdjLsaAdjacencyInfo(linkCost, faceUri, faceId, iden, 123, 1)
|
|
fmt.Println("cost: ", adjInfo.LinkCost())
|
|
fmt.Println("uri: ", adjInfo.LogicFaceUri())
|
|
fmt.Println("id: ", adjInfo.LogicFaceId())
|
|
fmt.Println("identifier: ", iden.ToUri())
|
|
fmt.Println(adjInfo.ToString())
|
|
}
|
|
|
|
//
|
|
// TestAdjLsaAdjacencyInfo_Compare
|
|
// @Description: 测试一些比较函数
|
|
// @param t
|
|
//
|
|
func TestAdjLsaAdjacencyInfo_Compare(t *testing.T) {
|
|
// 先构造
|
|
linkCost := AdjLsaLinkCost{}
|
|
linkCost.SetLinkCost(100)
|
|
faceUri := AdjLsaLogicFaceUri{}
|
|
faceUri.SetLogicFaceUri("uri")
|
|
faceId := AdjLsaLogicFaceId{}
|
|
faceId.SetLogicFaceId(77)
|
|
iden, _ := component.CreateIdentifierByString("/pku/router")
|
|
adjInfo := NewAdjLsaAdjacencyInfo(linkCost, faceUri, faceId, iden, 123, 1)
|
|
// 再测试:全部为true则pass
|
|
iden2, _ := component.CreateIdentifierByString("/pku/router")
|
|
fmt.Println(adjInfo.Compare(iden2))
|
|
fmt.Println(adjInfo.CompareLogicFaceId(77))
|
|
fmt.Println(adjInfo.CompareLogicFaceUriString("uri"))
|
|
fmt.Println(adjInfo.CompareLogicFaceUri(&faceUri))
|
|
}
|
|
|
|
//
|
|
// TestAdjLsaAdjacencyInfo_WireEncode
|
|
// @Description: 测试编码
|
|
// @param t
|
|
//
|
|
func TestAdjLsaAdjacencyInfo_WireEncode(t *testing.T) {
|
|
// 先构造
|
|
linkCost := AdjLsaLinkCost{}
|
|
linkCost.SetLinkCost(100)
|
|
faceUri := AdjLsaLogicFaceUri{}
|
|
faceUri.SetLogicFaceUri("uri")
|
|
faceId := AdjLsaLogicFaceId{}
|
|
faceId.SetLogicFaceId(77)
|
|
iden, _ := component.CreateIdentifierByString("/pku/router")
|
|
adjInfo := NewAdjLsaAdjacencyInfo(linkCost, faceUri, faceId, iden, 123, 1)
|
|
|
|
// 构造编码器
|
|
encoder := encoding.Encoder{}
|
|
err := encoder.EncoderReset(encoding.MaxPacketSize, 0)
|
|
if err != nil {
|
|
fmt.Println("encoder reset失败 ", err.Error())
|
|
return
|
|
}
|
|
|
|
// 编码并打印
|
|
cnt, err := adjInfo.WireEncode(&encoder)
|
|
if err != nil {
|
|
fmt.Println("AdjInfo 线速编码失败 ", err.Error())
|
|
return
|
|
}
|
|
res, err := encoder.GetBuffer()
|
|
if err != nil {
|
|
fmt.Println("获取编码结果失败 ", err.Error())
|
|
return
|
|
}
|
|
fmt.Println(cnt)
|
|
for i := 0; i < len(res); i++ {
|
|
fmt.Print(res[i], ", ")
|
|
}
|
|
fmt.Println()
|
|
// 241, 1, 169, 33, 101, 19, 100, 2, 0, 47, 100, 4, 0, 112, 107, 117, 100, 7, 0, 114, 111, 117, 116, 101, 114, 241, 1, 168, 3, 117, 114, 105, 241, 1, 167, 1, 100,
|
|
}
|
|
|
|
//
|
|
// TestAdjLsaAdjacencyInfo_WireDecode
|
|
// @Description: 测试线速解码
|
|
// 注意,编码解码目前只作用于三个信息项目:链路开销、faceuri、邻接路预期标识符三个信息项
|
|
// @param t
|
|
//
|
|
func TestAdjLsaAdjacencyInfo_WireDecode(t *testing.T) {
|
|
// 由数组构建block
|
|
var buf = [37]byte{241, 1, 169, 33, 101, 19, 100, 2, 0, 47, 100, 4, 0, 112, 107,
|
|
117, 100, 7, 0, 114, 111, 117, 116,
|
|
101, 114, 241, 1, 168, 3, 117, 114, 105, 241, 1, 167, 1, 100}
|
|
block, err := encoding.CreateBlockByBuffer(buf[:], true)
|
|
if err != nil {
|
|
fmt.Println("创建block失败 ", err.Error())
|
|
return
|
|
}
|
|
|
|
// 由Block构建结构体,并打印变量
|
|
adjInfo := new(AdjLsaAdjacencyInfo)
|
|
err = adjInfo.WireDecode(block)
|
|
if err != nil {
|
|
fmt.Println("线性解码失败 ", err.Error())
|
|
return
|
|
}
|
|
fmt.Println(adjInfo.ToString())
|
|
}
|