Skip to content
Snippets Groups Projects
Commit 12c07528 authored by Maximilian Wilhelm's avatar Maximilian Wilhelm
Browse files

Decode and store OriginatorID and ClusterList attributes.

parent 0b4d858e
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ const ( ...@@ -14,6 +14,7 @@ const (
NLRIMaxLen = 5 NLRIMaxLen = 5
CommunityLen = 4 CommunityLen = 4
LargeCommunityLen = 12 LargeCommunityLen = 12
ClusterIDLen = 4
OpenMsg = 1 OpenMsg = 1
UpdateMsg = 2 UpdateMsg = 2
...@@ -66,6 +67,8 @@ const ( ...@@ -66,6 +67,8 @@ const (
AtomicAggrAttr = 6 AtomicAggrAttr = 6
AggregatorAttr = 7 AggregatorAttr = 7
CommunitiesAttr = 8 CommunitiesAttr = 8
OriginatorIDAttr = 9
ClusterListAttr = 10
AS4PathAttr = 17 AS4PathAttr = 17
AS4AggregatorAttr = 18 AS4AggregatorAttr = 18
LargeCommunitiesAttr = 32 LargeCommunitiesAttr = 32
......
...@@ -99,6 +99,14 @@ func decodePathAttr(buf *bytes.Buffer, opt *types.Options) (pa *PathAttribute, c ...@@ -99,6 +99,14 @@ func decodePathAttr(buf *bytes.Buffer, opt *types.Options) (pa *PathAttribute, c
if err := pa.decodeCommunities(buf); err != nil { if err := pa.decodeCommunities(buf); err != nil {
return nil, consumed, fmt.Errorf("Failed to decode Community: %v", err) return nil, consumed, fmt.Errorf("Failed to decode Community: %v", err)
} }
case OriginatorIDAttr:
if err := pa.decodeOriginatorID(buf); err != nil {
return nil, consumed, fmt.Errorf("Failed to decode OriginatorID: %v", err)
}
case ClusterListAttr:
if err := pa.decodeClusterList(buf); err != nil {
return nil, consumed, fmt.Errorf("Failed to decode OriginatorID: %v", err)
}
case MultiProtocolReachNLRICode: case MultiProtocolReachNLRICode:
if err := pa.decodeMultiProtocolReachNLRI(buf); err != nil { if err := pa.decodeMultiProtocolReachNLRI(buf); err != nil {
return nil, consumed, fmt.Errorf("Failed to multi protocol reachable NLRI: %v", err) return nil, consumed, fmt.Errorf("Failed to multi protocol reachable NLRI: %v", err)
...@@ -364,6 +372,30 @@ func (pa *PathAttribute) decodeUint32(buf *bytes.Buffer, attrName string) error ...@@ -364,6 +372,30 @@ func (pa *PathAttribute) decodeUint32(buf *bytes.Buffer, attrName string) error
return nil return nil
} }
func (pa *PathAttribute) decodeOriginatorID(buf *bytes.Buffer) error {
return pa.decodeUint32(buf, "OriginatorID")
}
func (pa *PathAttribute) decodeClusterList(buf *bytes.Buffer) error {
if pa.Length%ClusterIDLen != 0 {
return fmt.Errorf("Unable to read ClusterList path attribute. Length %d is not divisible by %d", pa.Length, ClusterIDLen)
}
count := pa.Length / ClusterIDLen
cids := make([]uint32, count)
for i := uint16(0); i < count; i++ {
v, err := read4BytesAsUint32(buf)
if err != nil {
return err
}
cids[i] = v
}
pa.Value = cids
return nil
}
func (pa *PathAttribute) setLength(buf *bytes.Buffer) (int, error) { func (pa *PathAttribute) setLength(buf *bytes.Buffer) (int, error) {
bytesRead := 0 bytesRead := 0
if pa.ExtendedLength { if pa.ExtendedLength {
......
...@@ -293,6 +293,10 @@ func (s *establishedState) processAttributes(attrs *packet.PathAttribute, path * ...@@ -293,6 +293,10 @@ func (s *establishedState) processAttributes(attrs *packet.PathAttribute, path *
path.BGPPath.Communities = pa.Value.([]uint32) path.BGPPath.Communities = pa.Value.([]uint32)
case packet.LargeCommunitiesAttr: case packet.LargeCommunitiesAttr:
path.BGPPath.LargeCommunities = pa.Value.([]types.LargeCommunity) path.BGPPath.LargeCommunities = pa.Value.([]types.LargeCommunity)
case packet.OriginatorIDAttr:
path.BGPPath.OriginatorID = pa.Value.(uint32)
case packet.ClusterListAttr:
path.BGPPath.ClusterList = pa.Value.([]uint32)
default: default:
unknownAttr := s.processUnknownAttribute(pa) unknownAttr := s.processUnknownAttribute(pa)
if unknownAttr != nil { if unknownAttr != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment