mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-18 13:27:12 +08:00
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
// Package lsa
|
|
// @Author: Wang Feng
|
|
// @Description:
|
|
// @Version: 0.1.0
|
|
// @Date: 2022/3/25 22:29
|
|
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
|
//
|
|
|
|
package lsa
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"minlib/encoding"
|
|
"testing"
|
|
)
|
|
|
|
//
|
|
// TestAdjLsaLinkCost_SetLinkCost
|
|
// @Description: 测试设置属性
|
|
// @param t
|
|
//
|
|
func TestAdjLsaLinkCost_SetLinkCost(t *testing.T) {
|
|
lsaSequenceNumber:=AdjLsaLinkCost{}
|
|
lsaSequenceNumber.SetLinkCost(77)
|
|
if lsaSequenceNumber.LinkCost()!=77{
|
|
t.Fatal("AdjLsaLinkCost设置失败")
|
|
}
|
|
}
|
|
|
|
//
|
|
// TestAdjLsaLinkCost_WireEncode
|
|
// @Description: 测试编码
|
|
// @param t
|
|
//
|
|
func TestAdjLsaLinkCost_WireEncode(t *testing.T) {
|
|
linkCost :=AdjLsaLinkCost{}
|
|
linkCost.SetLinkCost(1234)
|
|
|
|
encoder := encoding.Encoder{}
|
|
encoder.EncoderReset(encoding.MaxPacketSize, 0)
|
|
length, err := linkCost.WireEncode(&encoder)
|
|
if err != nil {
|
|
t.Fatal("AdjLsaLinkCost编码失败", err.Error())
|
|
}
|
|
|
|
buf, err := encoder.GetBuffer()
|
|
if err != nil {
|
|
t.Fatal("AdjLsaLinkCost获取buffer结果失败", err.Error())
|
|
}
|
|
|
|
res := []byte{241, 1, 167, 2, 4, 210}
|
|
if length != 6 || !bytes.Equal(buf, res) {
|
|
fmt.Println("buf: ",buf)
|
|
fmt.Println("res: ",res)
|
|
t.Fatal("AdjLsaLinkCost编码内容错误", length, buf)
|
|
}
|
|
}
|
|
|
|
//
|
|
// TestAdjLsaLinkCost_WireDecode
|
|
// @Description: 测试解码
|
|
// @param t
|
|
//
|
|
func TestAdjLsaLinkCost_WireDecode(t *testing.T) {
|
|
var buf [6]byte = [6]byte{241, 1, 167, 2, 4, 210}
|
|
block, err := encoding.CreateBlockByBuffer(buf[:], true)
|
|
if err != nil {
|
|
t.Fatal("AdjLsaLinkCost创建Block失败", err.Error())
|
|
}
|
|
|
|
linkCost := AdjLsaLinkCost{}
|
|
err = linkCost.WireDecode(block)
|
|
if err != nil {
|
|
t.Fatal("AdjLsaLinkCost解码失败", err.Error())
|
|
}
|
|
|
|
if linkCost.LinkCost() != 1234 {
|
|
t.Fatal("AdjLsaLinkCost解码内容错误", linkCost.LinkCost())
|
|
}
|
|
}
|