Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bio-rd
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
bio-rd
Commits
fa2b211e
Commit
fa2b211e
authored
4 years ago
by
Oliver Herms
Browse files
Options
Downloads
Patches
Plain Diff
Add convenience functions for AS Paths
parent
4cd42e2f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
protocols/bgp/types/as_path.go
+42
-0
42 additions, 0 deletions
protocols/bgp/types/as_path.go
with
42 additions
and
0 deletions
protocols/bgp/types/as_path.go
+
42
−
0
View file @
fa2b211e
...
...
@@ -44,12 +44,54 @@ func (a *ASPath) Compare(b *ASPath) bool {
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)
type
ASPathSegment
struct
{
Type
uint8
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
func
(
s
ASPathSegment
)
Compare
(
t
ASPathSegment
)
bool
{
if
s
.
Type
!=
t
.
Type
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment