mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-10-04 19:42:02 +08:00
增加AdjLsaAdjacencyList的编解码函数
This commit is contained in:
1 parent
05bdc19554
commit
a1ca8bb19e
2 files changed
+70
-3
No files matched your search
@@ -23,5 +23,6 @@ const (
|
||||
TlvMlsrAdjLsaLinkCost = 423 // 链路开销
|
||||
TlvMlsrAdjLsaLogicFaceUri = 424 // LogicFace前缀
|
||||
TlvMlsrAdjLsaAdjacencyInfo = 425 // 单条邻接LSA信息
|
||||
TlvMlsrAdjLsaAdjacencyList = 426 // 一个邻接LSA包含的所有邻接信息
|
||||
)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"errors"
|
||||
"minlib/component"
|
||||
"minlib/encoding"
|
||||
"mlsr/extensions"
|
||||
)
|
||||
|
||||
// 为邻接信息的数组起一个别称
|
||||
@@ -335,11 +336,76 @@ func (l *AdjLsaAdjacenctList) getLogicFaceId(uri *AdjLsaLogicFaceUri) (uint64,er
|
||||
return -1,nil
|
||||
}
|
||||
|
||||
// todo:有待实现编码解码
|
||||
//
|
||||
// WireEncode
|
||||
// @Description: 线速编码
|
||||
// @receiver l
|
||||
// @param encoder
|
||||
// @return int
|
||||
// @return error
|
||||
//
|
||||
func (l *AdjLsaAdjacenctList) WireEncode(encoder *encoding.Encoder) (int,error) {
|
||||
panic("")
|
||||
// 判断列表长度,为0则抛出错误
|
||||
if len(l.lsaAdjacencys)==0 {
|
||||
return 0,errors.New("Invalid AdjLsaAdjacencyList, expect at least one AdjLsaAdjacencyInfo!")
|
||||
}
|
||||
totalLength := 0
|
||||
// 编码 TLV-VALUE
|
||||
// 反向遍历,可以保证解码的时候正向输出
|
||||
for i:=len(l.lsaAdjacencys)-1; i>=0; i-- {
|
||||
if l.lsaAdjacencys[i]==nil {
|
||||
continue
|
||||
}
|
||||
tmpLen,err := l.lsaAdjacencys[i].WireEncode(encoder)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
totalLength += tmpLen
|
||||
}
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmpLen, err := encoder.PrependVarNumber(encoding.VlInt(totalLength))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
totalLength += tmpLen
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmpLen, err = encoder.PrependVarNumber(extensions.TlvMlsrAdjLsaAdjacencyList)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
totalLength += tmpLen
|
||||
|
||||
return totalLength,nil
|
||||
}
|
||||
|
||||
//
|
||||
// WireDecode
|
||||
// @Description: 线速解码
|
||||
// @receiver l
|
||||
// @param block
|
||||
// @return error
|
||||
//
|
||||
func (l *AdjLsaAdjacenctList) WireDecode(block *encoding.Block) error {
|
||||
panic("")
|
||||
// 检查 TLV-TYPE 是否正确
|
||||
if err := encoding.ExpectType(block.GetType(), extensions.TlvMlsrAdjLsaAdjacencyList); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析子 TLV
|
||||
if err := block.ParseSubElements(); err != nil {
|
||||
return err
|
||||
}
|
||||
adjacencyContainer := make(LsaAdjacencyContainer, len(block.GetSubElements()))
|
||||
for index, element := range block.GetSubElements() {
|
||||
var newAdjacencyInfo *AdjLsaAdjacencyInfo
|
||||
err := newAdjacencyInfo.WireDecode(element)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
adjacencyContainer[index] = newAdjacencyInfo
|
||||
}
|
||||
l.lsaAdjacencys = adjacencyContainer
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user