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
08c9b220
Commit
08c9b220
authored
6 years ago
by
Daniel Czerwonk
Browse files
Options
Downloads
Patches
Plain Diff
added tests for new IP type
parent
3d25ad5d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
net/ip.go
+46
-0
46 additions, 0 deletions
net/ip.go
net/ip_test.go
+111
-0
111 additions, 0 deletions
net/ip_test.go
route/bgp_path.go
+2
-1
2 additions, 1 deletion
route/bgp_path.go
with
159 additions
and
1 deletion
net/ip.go
0 → 100644
+
46
−
0
View file @
08c9b220
package
net
// IP represents an IPv4 or IPv6 address
type
IP
struct
{
higher
uint64
lower
uint64
}
func
IPv4
(
val
uint32
)
IP
{
return
IP
{
lower
:
uint64
(
val
),
}
}
func
IPv6
(
higher
,
lower
uint64
)
IP
{
return
IP
{
higher
:
higher
,
lower
:
lower
,
}
}
// ToUint32 returns the uint32 representation of an IP address
func
(
ip
*
IP
)
ToUint32
()
uint32
{
return
uint32
(
^
uint64
(
0
)
>>
32
&
ip
.
lower
)
}
// Compare compares two IP addresses (returns 0 if equal, -1 if `ip` is smaller than `other`, 1 if `ip` is greater than `other`)
func
(
ip
*
IP
)
Compare
(
other
*
IP
)
int
{
if
ip
.
higher
==
other
.
higher
&&
ip
.
lower
==
other
.
lower
{
return
0
}
if
ip
.
higher
>
other
.
higher
{
return
1
}
if
ip
.
higher
<
other
.
higher
{
return
-
1
}
if
ip
.
lower
>
other
.
lower
{
return
1
}
return
-
1
}
This diff is collapsed.
Click to expand it.
net/ip_test.go
0 → 100644
+
111
−
0
View file @
08c9b220
package
net
import
(
"testing"
"github.com/stretchr/testify/assert"
)
func
TestToUint32
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
val
uint64
expected
uint32
}{
{
name
:
"IP: 172.24.5.1"
,
val
:
2887255297
,
expected
:
2887255297
,
},
{
name
:
"bigger than IPv4 address"
,
val
:
2887255295
+
17179869184
,
expected
:
2887255295
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
ip
:=
IP
{
lower
:
test
.
val
,
}
assert
.
Equal
(
t
,
test
.
expected
,
ip
.
ToUint32
())
})
}
}
func
TestCompare
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
ip
*
IP
other
*
IP
expected
int
}{
{
name
:
"equal"
,
ip
:
&
IP
{
lower
:
100
,
higher
:
200
,
},
other
:
&
IP
{
lower
:
100
,
higher
:
200
,
},
expected
:
0
,
},
{
name
:
"greater higher word"
,
ip
:
&
IP
{
lower
:
123
,
higher
:
200
,
},
other
:
&
IP
{
lower
:
456
,
higher
:
100
,
},
expected
:
1
,
},
{
name
:
"lesser higher word"
,
ip
:
&
IP
{
lower
:
123
,
higher
:
100
,
},
other
:
&
IP
{
lower
:
456
,
higher
:
200
,
},
expected
:
-
1
,
},
{
name
:
"equal higher word but lesser lower word"
,
ip
:
&
IP
{
lower
:
456
,
higher
:
100
,
},
other
:
&
IP
{
lower
:
123
,
higher
:
100
,
},
expected
:
1
,
},
{
name
:
"equal higher word but lesser lower word"
,
ip
:
&
IP
{
lower
:
123
,
higher
:
100
,
},
other
:
&
IP
{
lower
:
456
,
higher
:
100
,
},
expected
:
-
1
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
test
.
expected
,
test
.
ip
.
Compare
(
test
.
other
))
})
}
}
This diff is collapsed.
Click to expand it.
route/bgp_path.go
+
2
−
1
View file @
08c9b220
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
bnet
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/taktv6/tflow2/convert"
)
...
...
@@ -12,7 +13,7 @@ import (
// BGPPath represents a set of BGP path attributes
type
BGPPath
struct
{
PathIdentifier
uint32
NextHop
uint32
NextHop
bnet
.
IP
LocalPref
uint32
ASPath
packet
.
ASPath
ASPathLen
uint16
...
...
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