mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix IPMask marshalling
Fix marshalling and add test Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
This commit is contained in:
parent
1bb664f689
commit
1fe48e8608
2 changed files with 42 additions and 9 deletions
|
@ -27,10 +27,12 @@ type peerEntry struct {
|
|||
}
|
||||
|
||||
func (p *peerEntry) MarshalDB() peerEntryDB {
|
||||
ones, bits := p.peerIPMask.Size()
|
||||
return peerEntryDB{
|
||||
eid: p.eid,
|
||||
vtep: p.vtep.String(),
|
||||
peerIPMask: p.peerIPMask.String(),
|
||||
peerIPMaskOnes: ones,
|
||||
peerIPMaskBits: bits,
|
||||
isLocal: p.isLocal,
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +43,8 @@ func (p *peerEntry) MarshalDB() peerEntryDB {
|
|||
type peerEntryDB struct {
|
||||
eid string
|
||||
vtep string
|
||||
peerIPMask string
|
||||
peerIPMaskOnes int
|
||||
peerIPMaskBits int
|
||||
isLocal bool
|
||||
}
|
||||
|
||||
|
@ -49,7 +52,7 @@ func (p *peerEntryDB) UnMarshalDB() peerEntry {
|
|||
return peerEntry{
|
||||
eid: p.eid,
|
||||
vtep: net.ParseIP(p.vtep),
|
||||
peerIPMask: net.IPMask(net.ParseIP(p.peerIPMask)),
|
||||
peerIPMask: net.CIDRMask(p.peerIPMaskOnes, p.peerIPMaskBits),
|
||||
isLocal: p.isLocal,
|
||||
}
|
||||
}
|
||||
|
|
30
libnetwork/drivers/overlay/peerdb_test.go
Normal file
30
libnetwork/drivers/overlay/peerdb_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package overlay
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
_ "github.com/docker/libnetwork/testutils"
|
||||
)
|
||||
|
||||
func TestPeerMarshal(t *testing.T) {
|
||||
_, ipNet, _ := net.ParseCIDR("192.168.0.1/24")
|
||||
p := &peerEntry{eid: "eid",
|
||||
isLocal: true,
|
||||
peerIPMask: ipNet.Mask,
|
||||
vtep: ipNet.IP}
|
||||
entryDB := p.MarshalDB()
|
||||
x := entryDB.UnMarshalDB()
|
||||
if x.eid != p.eid {
|
||||
t.Fatalf("Incorrect Unmarshalling for eid: %v != %v", x.eid, p.eid)
|
||||
}
|
||||
if x.isLocal != p.isLocal {
|
||||
t.Fatalf("Incorrect Unmarshalling for isLocal: %v != %v", x.isLocal, p.isLocal)
|
||||
}
|
||||
if x.peerIPMask.String() != p.peerIPMask.String() {
|
||||
t.Fatalf("Incorrect Unmarshalling for eid: %v != %v", x.peerIPMask, p.peerIPMask)
|
||||
}
|
||||
if x.vtep.String() != p.vtep.String() {
|
||||
t.Fatalf("Incorrect Unmarshalling for eid: %v != %v", x.vtep, p.vtep)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue