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
77e53a12
Commit
77e53a12
authored
6 years ago
by
Daniel Czerwonk
Browse files
Options
Downloads
Patches
Plain Diff
added community serialization
parent
f48a4b5a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
protocols/bgp/packet/path_attributes.go
+26
-0
26 additions, 0 deletions
protocols/bgp/packet/path_attributes.go
protocols/bgp/packet/path_attributes_test.go
+47
-0
47 additions, 0 deletions
protocols/bgp/packet/path_attributes_test.go
with
73 additions
and
0 deletions
protocols/bgp/packet/path_attributes.go
+
26
−
0
View file @
77e53a12
...
...
@@ -446,6 +446,8 @@ func (pa *PathAttribute) serialize(buf *bytes.Buffer) uint8 {
pathAttrLen
=
pa
.
serializeAtomicAggregate
(
buf
)
case
AggregatorAttr
:
pathAttrLen
=
pa
.
serializeAggregator
(
buf
)
case
CommunitiesAttr
:
pathAttrLen
=
pa
.
serializeCommunities
(
buf
)
case
LargeCommunityAttr
:
pathAttrLen
=
pa
.
serializeLargeCommunities
(
buf
)
}
...
...
@@ -543,6 +545,30 @@ func (pa *PathAttribute) serializeAggregator(buf *bytes.Buffer) uint8 {
return
5
}
func
(
pa
*
PathAttribute
)
serializeCommunities
(
buf
*
bytes
.
Buffer
)
uint8
{
coms
:=
pa
.
Value
.
([]
uint32
)
if
len
(
coms
)
==
0
{
return
0
}
attrFlags
:=
uint8
(
0
)
attrFlags
=
setOptional
(
attrFlags
)
attrFlags
=
setTransitive
(
attrFlags
)
attrFlags
=
setPartial
(
attrFlags
)
buf
.
WriteByte
(
attrFlags
)
buf
.
WriteByte
(
CommunitiesAttr
)
length
:=
uint8
(
CommunityLen
*
len
(
coms
))
buf
.
WriteByte
(
length
)
for
_
,
com
:=
range
coms
{
buf
.
Write
(
convert
.
Uint32Byte
(
com
))
}
return
length
}
func
(
pa
*
PathAttribute
)
serializeLargeCommunities
(
buf
*
bytes
.
Buffer
)
uint8
{
coms
:=
pa
.
Value
.
([]
LargeCommunity
)
if
len
(
coms
)
==
0
{
...
...
This diff is collapsed.
Click to expand it.
protocols/bgp/packet/path_attributes_test.go
+
47
−
0
View file @
77e53a12
...
...
@@ -1335,6 +1335,53 @@ func TestSerializeLargeCommunities(t *testing.T) {
}
}
func
TestSerializeCommunities
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
input
*
PathAttribute
expected
[]
byte
expectedLen
uint8
}{
{
name
:
"2 communities"
,
input
:
&
PathAttribute
{
TypeCode
:
LargeCommunityAttr
,
Value
:
[]
uint32
{
131080
,
16778241
,
},
},
expected
:
[]
byte
{
0xe0
,
// Attribute flags
8
,
// Type
8
,
// Length
0
,
2
,
0
,
8
,
1
,
0
,
4
,
1
,
// Communities (2,8), (256,1025)
},
expectedLen
:
8
,
},
{
name
:
"empty list of communities"
,
input
:
&
PathAttribute
{
TypeCode
:
CommunitiesAttr
,
Value
:
[]
uint32
{},
},
expected
:
[]
byte
{},
expectedLen
:
0
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
te
*
testing
.
T
)
{
buf
:=
bytes
.
NewBuffer
([]
byte
{})
n
:=
test
.
input
.
serializeCommunities
(
buf
)
if
n
!=
test
.
expectedLen
{
t
.
Fatalf
(
"Unexpected length for test %q: %d"
,
test
.
name
,
n
)
}
assert
.
Equal
(
t
,
test
.
expected
,
buf
.
Bytes
())
})
}
}
func
TestSerialize
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
...
...
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