Skip to content
Snippets Groups Projects
Commit fa2b211e authored by Oliver Herms's avatar Oliver Herms
Browse files

Add convenience functions for AS Paths

parent 4cd42e2f
Branches aspath/convenience
No related tags found
No related merge requests found
...@@ -44,12 +44,54 @@ func (a *ASPath) Compare(b *ASPath) bool { ...@@ -44,12 +44,54 @@ func (a *ASPath) Compare(b *ASPath) bool {
return true return true
} }
// GetFirstSequenceSegment gets the first sequence of an AS path
func (a *ASPath) GetFirstSequenceSegment() *ASPathSegment {
for _, seg := range *a {
if seg.Type == ASSequence {
return &seg
}
}
return nil
}
// GetLastSequenceSegment gets the last sequence of an AS path
func (a *ASPath) GetLastSequenceSegment() *ASPathSegment {
for i := len(*a) - 1; i >= 0; i-- {
if (*a)[i].Type == ASSequence {
return &(*a)[i]
}
}
return nil
}
// ASPathSegment represents an AS Path Segment (RFC4271) // ASPathSegment represents an AS Path Segment (RFC4271)
type ASPathSegment struct { type ASPathSegment struct {
Type uint8 Type uint8
ASNs []uint32 ASNs []uint32
} }
// GetFirstASN returns the first ASN of an AS path segment
func (s ASPathSegment) GetFirstASN() *uint32 {
if len(s.ASNs) == 0 {
return nil
}
ret := s.ASNs[0]
return &ret
}
// GetLastASN returns the last ASN of an AS path segment
func (s ASPathSegment) GetLastASN() *uint32 {
if len(s.ASNs) == 0 {
return nil
}
ret := s.ASNs[len(s.ASNs)-1]
return &ret
}
// Compare checks if ASPathSegments are the same // Compare checks if ASPathSegments are the same
func (s ASPathSegment) Compare(t ASPathSegment) bool { func (s ASPathSegment) Compare(t ASPathSegment) bool {
if s.Type != t.Type { if s.Type != t.Type {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment