mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-03 15:56:13 +08:00
78 lines
1.5 KiB
Go
78 lines
1.5 KiB
Go
// Package lsa
|
|
// @Author: Wang Feng
|
|
// @Description:
|
|
// @Version: 0.1.0
|
|
// @Date: 2022/3/10 10:39
|
|
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
|
//
|
|
|
|
package route
|
|
|
|
import (
|
|
"math"
|
|
"minlib/component"
|
|
"minlib/encoding"
|
|
"mlsr/extensions"
|
|
)
|
|
|
|
const (
|
|
DEFAULT_LINK_COST = 10
|
|
NON_ADJACENT_COST = math.MaxUint64
|
|
)
|
|
|
|
//
|
|
// RouteCost
|
|
// @Description: 链路开销
|
|
//
|
|
type RouteCost struct {
|
|
component.CommonUint64
|
|
}
|
|
|
|
//
|
|
// RouteCost
|
|
// @Description: 获取开销
|
|
// @receiver l
|
|
// @return uint64
|
|
//
|
|
func (l *RouteCost) Cost() uint64 {
|
|
return l.CommonUint64.Value()
|
|
}
|
|
|
|
//
|
|
// SetRouteCost
|
|
// @Description: 设置开销
|
|
// @receiver l
|
|
// @param linkCost
|
|
//
|
|
func (l *RouteCost) SetRouteCost(linkCost uint64) {
|
|
l.CommonUint64.SetValue(linkCost)
|
|
}
|
|
|
|
//
|
|
// WireEncode
|
|
// @Description: 线速编码
|
|
// @receiver l
|
|
// @param encoder
|
|
// @return int
|
|
// @return error
|
|
//
|
|
func (l *RouteCost) WireEncode(encoder *encoding.Encoder) (int, error) {
|
|
l.CommonUint64.SetTlvType(extensions.TlvMlsrRouteCost)
|
|
return l.CommonUint64.WireEncode(encoder)
|
|
}
|
|
|
|
//
|
|
// WireDecode
|
|
// @Description: 线速解码
|
|
// @receiver l
|
|
// @param block
|
|
// @return error
|
|
//
|
|
func (l *RouteCost) WireDecode(block *encoding.Block) error {
|
|
// 检查type是否正确
|
|
if err := encoding.ExpectType(block.GetType(), extensions.TlvMlsrRouteCost); err != nil {
|
|
return err
|
|
}
|
|
return l.CommonUint64.WireDecode(block)
|
|
}
|