测试adjInfo

This commit is contained in:
free will committed 2022-04-27 16:33:17 +08:00
1 parent c4e0396d36
commit f826b85e2b
4 files changed
+208 -4

No files matched your search

+54 -4
View File
@@ -12,6 +12,7 @@ import (
"minlib/component"
"minlib/encoding"
"mlsr/extensions"
"strconv"
)
const (
@@ -41,13 +42,37 @@ type AdjLsaAdjacencyInfo struct {
// @return *AdjLsaAdjacencyInfo
//
func NewAdjLsaAdjacencyInfo(adjLsaLinkCost AdjLsaLinkCost, adjLsaLogicFaceUri AdjLsaLogicFaceUri,
m_lsaNeighborRouterIdentifier *component.Identifier, m_interestTimedOutNo uint32,
m_status int) *AdjLsaAdjacencyInfo {
faceId AdjLsaLogicFaceId, m_lsaNeighborRouterIdentifier *component.Identifier,
m_interestTimedOutNo uint32, m_status int) *AdjLsaAdjacencyInfo {
return &AdjLsaAdjacencyInfo{AdjLsaLinkCost: adjLsaLinkCost, AdjLsaLogicFaceUri: adjLsaLogicFaceUri,
lsaNeighborRouterIdentifier: m_lsaNeighborRouterIdentifier,
AdjLsaLogicFaceId: faceId,lsaNeighborRouterIdentifier: m_lsaNeighborRouterIdentifier,
InterestTimedOutNo: m_interestTimedOutNo, Status: m_status}
}
//
// NewAdjLsaAdjacencyInfoByInstance
// @Description: 根据已有的结构体实例,创建邻接信息结构体
// @param adjLsaLinkCost
// @param adjLsaLogicFaceUri
// @param faceId
// @param m_lsaNeighborRouterIdentifier
// @param m_interestTimedOutNo
// @param m_status
// @return *AdjLsaAdjacencyInfo
//
func NewAdjLsaAdjacencyInfoByInstance(adjLsaLinkCost *AdjLsaLinkCost, adjLsaLogicFaceUri *AdjLsaLogicFaceUri,
faceId *AdjLsaLogicFaceId, m_lsaNeighborRouterIdentifier *component.Identifier,
m_interestTimedOutNo uint32, m_status int) *AdjLsaAdjacencyInfo {
adjRes := AdjLsaAdjacencyInfo{}
adjRes.SetLinkCost(adjLsaLinkCost.LinkCost())
adjRes.setLogicFaceUri(adjLsaLogicFaceUri.LogicFaceUri())
adjRes.SetLogicFaceId(faceId.LogicFaceId())
adjRes.SetNeighborRouterIdentifier(m_lsaNeighborRouterIdentifier)
adjRes.InterestTimedOutNo = m_interestTimedOutNo
adjRes.Status = m_status
return &adjRes
}
//
// GetNeighborRouterIdentidier
// @Description: 获取相邻路由器的标识
@@ -126,6 +151,29 @@ func (l *AdjLsaAdjacencyInfo) CompareLogicFaceId(faceId uint64) bool {
return false
}
//
// ToString
// @Description: 转string
// @receiver l
//
func (l *AdjLsaAdjacencyInfo) ToString() string {
var resString string
resString += "{ LinkCost: "
resString += strconv.FormatUint(l.LinkCost(), 10)
resString += ", LogicFaceUri: "
resString += l.LogicFaceUri()
resString += ", LogicFaceId: "
resString += strconv.FormatUint(l.LogicFaceId(),10)
resString += ", NeighborRouterIdentifier: "
resString += l.lsaNeighborRouterIdentifier.ToUri()
resString += ", InterestTimedOutNo: "
resString += strconv.Itoa(int(l.InterestTimedOutNo))
resString += ", Status: "
resString += strconv.Itoa(l.Status)
resString += " }"
return resString
}
//
// WireEncode
// @Description: 线速编码
@@ -193,9 +241,11 @@ func (l *AdjLsaAdjacencyInfo) WireDecode(block *encoding.Block) error {
for _, parameter := range block.GetSubElements(){
switch parameter.GetType() {
case encoding.TlvIdentifier:
if err:= l.lsaNeighborRouterIdentifier.WireDecode(parameter); err != nil {
iden:=component.Identifier{}
if err:= iden.WireDecode(parameter); err != nil {
return err
}
l.lsaNeighborRouterIdentifier = &iden
case extensions.TlvMlsrAdjLsaLogicFaceUri:
if err:= l.AdjLsaLogicFaceUri.WireDecode(parameter); err != nil {
return err
+130
View File
@@ -0,0 +1,130 @@
// 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())
}
+15
View File
@@ -0,0 +1,15 @@
// Package lsa
// @Author: Wang Feng
// @Description:
// @Version: 0.1.0
// @Date: 2022/4/22 0:15
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
//
package lsa
import "testing"
func TestAdjLsaAdjacenctList_GetAdjList(t *testing.T) {
}
+9
View File
@@ -0,0 +1,9 @@
// Package lsa
// @Author: Wang Feng
// @Description:
// @Version: 0.1.0
// @Date: 2022/4/22 11:01
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
//
package lsa