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
d4120b75
Commit
d4120b75
authored
6 years ago
by
Daniel Czerwonk
Browse files
Options
Downloads
Plain Diff
Merge branch 'bgp_large_community_support' into feature/community_support
parents
cfaa1796
d26b4573
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
protocols/bgp/packet/path_attributes.go
+23
-62
23 additions, 62 deletions
protocols/bgp/packet/path_attributes.go
protocols/bgp/packet/path_attributes_test.go
+3
-3
3 additions, 3 deletions
protocols/bgp/packet/path_attributes_test.go
with
26 additions
and
65 deletions
protocols/bgp/packet/path_attributes.go
+
23
−
62
View file @
d4120b75
...
...
@@ -180,41 +180,15 @@ func (pa *PathAttribute) decodeASPath(buf *bytes.Buffer) error {
}
func
(
pa
*
PathAttribute
)
decodeNextHop
(
buf
*
bytes
.
Buffer
)
error
{
addr
:=
[
4
]
byte
{}
p
:=
uint16
(
0
)
n
,
err
:=
buf
.
Read
(
addr
[
:
])
if
err
!=
nil
{
return
err
}
if
n
!=
4
{
return
fmt
.
Errorf
(
"Unable to read next hop: buf.Read read %d bytes"
,
n
)
}
pa
.
Value
=
fourBytesToUint32
(
addr
)
p
+=
4
return
dumpNBytes
(
buf
,
pa
.
Length
-
p
)
return
pa
.
decodeUint32
(
buf
,
"next hop"
)
}
func
(
pa
*
PathAttribute
)
decodeMED
(
buf
*
bytes
.
Buffer
)
error
{
med
,
err
:=
pa
.
decodeUint32
(
buf
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to decode MED: %v"
,
err
)
}
pa
.
Value
=
uint32
(
med
)
return
nil
return
pa
.
decodeUint32
(
buf
,
"MED"
)
}
func
(
pa
*
PathAttribute
)
decodeLocalPref
(
buf
*
bytes
.
Buffer
)
error
{
lpref
,
err
:=
pa
.
decodeUint32
(
buf
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to decode local pref: %v"
,
err
)
}
pa
.
Value
=
uint32
(
lpref
)
return
nil
return
pa
.
decodeUint32
(
buf
,
"local pref"
)
}
func
(
pa
*
PathAttribute
)
decodeAggregator
(
buf
*
bytes
.
Buffer
)
error
{
...
...
@@ -252,7 +226,7 @@ func (pa *PathAttribute) decodeCommunities(buf *bytes.Buffer) error {
coms
:=
make
([]
uint32
,
count
)
for
i
:=
uint16
(
0
);
i
<
count
;
i
++
{
v
,
err
:=
read4BytesAsUin32
(
buf
)
v
,
err
:=
read4BytesAsUin
t
32
(
buf
)
if
err
!=
nil
{
return
err
}
...
...
@@ -274,19 +248,19 @@ func (pa *PathAttribute) decodeLargeCommunities(buf *bytes.Buffer) error {
for
i
:=
uint16
(
0
);
i
<
count
;
i
++
{
com
:=
LargeCommunity
{}
v
,
err
:=
read4BytesAsUin32
(
buf
)
v
,
err
:=
read4BytesAsUin
t
32
(
buf
)
if
err
!=
nil
{
return
err
}
com
.
GlobalAdministrator
=
v
v
,
err
=
read4BytesAsUin32
(
buf
)
v
,
err
=
read4BytesAsUin
t
32
(
buf
)
if
err
!=
nil
{
return
err
}
com
.
DataPart1
=
v
v
,
err
=
read4BytesAsUin32
(
buf
)
v
,
err
=
read4BytesAsUin
t
32
(
buf
)
if
err
!=
nil
{
return
err
}
...
...
@@ -300,22 +274,27 @@ func (pa *PathAttribute) decodeLargeCommunities(buf *bytes.Buffer) error {
}
func
(
pa
*
PathAttribute
)
decodeAS4Path
(
buf
*
bytes
.
Buffer
)
error
{
as4Path
,
err
:=
pa
.
decodeUint32
(
buf
)
return
pa
.
decodeUint32
(
buf
,
"AS4Path"
)
}
func
(
pa
*
PathAttribute
)
decodeAS4Aggregator
(
buf
*
bytes
.
Buffer
)
error
{
return
pa
.
decodeUint32
(
buf
,
"AS4Aggregator"
)
}
func
(
pa
*
PathAttribute
)
decodeUint32
(
buf
*
bytes
.
Buffer
,
attrName
string
)
error
{
v
,
err
:=
read4BytesAsUint32
(
buf
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to decode
AS4Path: %v"
,
err
)
return
fmt
.
Errorf
(
"Unable to decode
%s: %v"
,
attrName
,
err
)
}
pa
.
Value
=
as4Path
return
nil
}
pa
.
Value
=
v
func
(
pa
*
PathAttribute
)
decodeAS4Aggregator
(
buf
*
bytes
.
Buffer
)
error
{
as4Aggregator
,
err
:
=
pa
.
decodeUint32
(
buf
)
p
:=
uint16
(
4
)
err
=
dumpNBytes
(
buf
,
pa
.
Length
-
p
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"
Unable to decode AS4Aggregator
: %v"
,
err
)
return
fmt
.
Errorf
(
"
dumpNBytes failed
: %v"
,
err
)
}
pa
.
Value
=
as4Aggregator
return
nil
}
...
...
@@ -339,24 +318,6 @@ func (pa *PathAttribute) setLength(buf *bytes.Buffer) (int, error) {
return
bytesRead
,
nil
}
func
(
pa
*
PathAttribute
)
decodeUint32
(
buf
*
bytes
.
Buffer
)
(
uint32
,
error
)
{
var
v
uint32
p
:=
uint16
(
0
)
err
:=
decode
(
buf
,
[]
interface
{}{
&
v
})
if
err
!=
nil
{
return
0
,
err
}
p
+=
4
err
=
dumpNBytes
(
buf
,
pa
.
Length
-
p
)
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"dumpNBytes failed: %v"
,
err
)
}
return
v
,
nil
}
func
(
pa
*
PathAttribute
)
ASPathString
()
(
ret
string
)
{
for
_
,
p
:=
range
pa
.
Value
.
(
ASPath
)
{
if
p
.
Type
==
ASSet
{
...
...
@@ -722,14 +683,14 @@ func fourBytesToUint32(address [4]byte) uint32 {
return
uint32
(
address
[
0
])
<<
24
+
uint32
(
address
[
1
])
<<
16
+
uint32
(
address
[
2
])
<<
8
+
uint32
(
address
[
3
])
}
func
read4BytesAsUin32
(
buf
*
bytes
.
Buffer
)
(
uint32
,
error
)
{
func
read4BytesAsUin
t
32
(
buf
*
bytes
.
Buffer
)
(
uint32
,
error
)
{
b
:=
[
4
]
byte
{}
n
,
err
:=
buf
.
Read
(
b
[
:
])
if
err
!=
nil
{
return
0
,
err
}
if
n
!=
4
{
return
0
,
fmt
.
Errorf
(
"Unable to read as uint32
: buf.Read read %d bytes
"
,
n
)
return
0
,
fmt
.
Errorf
(
"Unable to read as uint32
. Expected 4 bytes but got only %d
"
,
n
)
}
return
fourBytesToUint32
(
b
),
nil
...
...
This diff is collapsed.
Click to expand it.
protocols/bgp/packet/path_attributes_test.go
+
3
−
3
View file @
d4120b75
...
...
@@ -783,7 +783,7 @@ func TestSetLength(t *testing.T) {
}
}
func
Test
Decode
Uint32
(
t
*
testing
.
T
)
{
func
Test
Read4BytesAs
Uint32
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
input
[]
byte
...
...
@@ -822,7 +822,7 @@ func TestDecodeUint32(t *testing.T) {
pa
:=
&
PathAttribute
{
Length
:
l
,
}
res
,
err
:=
pa
.
decodeUint32
(
bytes
.
NewBuffer
(
test
.
input
))
err
:=
pa
.
decodeUint32
(
bytes
.
NewBuffer
(
test
.
input
)
,
"test"
)
if
test
.
wantFail
{
if
err
!=
nil
{
...
...
@@ -837,7 +837,7 @@ func TestDecodeUint32(t *testing.T) {
continue
}
assert
.
Equal
(
t
,
test
.
expected
,
res
)
assert
.
Equal
(
t
,
test
.
expected
,
pa
.
Value
)
}
}
...
...
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