File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,29 +27,32 @@ type peerEntry struct {
2727}
2828
2929func (p * peerEntry ) MarshalDB () peerEntryDB {
30+ ones , bits := p .peerIPMask .Size ()
3031 return peerEntryDB {
31- eid : p .eid ,
32- vtep : p .vtep .String (),
33- peerIPMask : p .peerIPMask .String (),
34- isLocal : p .isLocal ,
32+ eid : p .eid ,
33+ vtep : p .vtep .String (),
34+ peerIPMaskOnes : ones ,
35+ peerIPMaskBits : bits ,
36+ isLocal : p .isLocal ,
3537 }
3638}
3739
3840// This the structure saved into the set (SetMatrix), due to the implementation of it
3941// the value inserted in the set has to be Hashable so the []byte had to be converted into
4042// strings
4143type peerEntryDB struct {
42- eid string
43- vtep string
44- peerIPMask string
45- isLocal bool
44+ eid string
45+ vtep string
46+ peerIPMaskOnes int
47+ peerIPMaskBits int
48+ isLocal bool
4649}
4750
4851func (p * peerEntryDB ) UnMarshalDB () peerEntry {
4952 return peerEntry {
5053 eid : p .eid ,
5154 vtep : net .ParseIP (p .vtep ),
52- peerIPMask : net .IPMask ( net . ParseIP ( p . peerIPMask ) ),
55+ peerIPMask : net .CIDRMask ( p . peerIPMaskOnes , p . peerIPMaskBits ),
5356 isLocal : p .isLocal ,
5457 }
5558}
Original file line number Diff line number Diff line change 1+ package overlay
2+
3+ import (
4+ "net"
5+ "testing"
6+
7+ _ "github.com/docker/libnetwork/testutils"
8+ )
9+
10+ func TestPeerMarshal (t * testing.T ) {
11+ _ , ipNet , _ := net .ParseCIDR ("192.168.0.1/24" )
12+ p := & peerEntry {eid : "eid" ,
13+ isLocal : true ,
14+ peerIPMask : ipNet .Mask ,
15+ vtep : ipNet .IP }
16+ entryDB := p .MarshalDB ()
17+ x := entryDB .UnMarshalDB ()
18+ if x .eid != p .eid {
19+ t .Fatalf ("Incorrect Unmarshalling for eid: %v != %v" , x .eid , p .eid )
20+ }
21+ if x .isLocal != p .isLocal {
22+ t .Fatalf ("Incorrect Unmarshalling for isLocal: %v != %v" , x .isLocal , p .isLocal )
23+ }
24+ if x .peerIPMask .String () != p .peerIPMask .String () {
25+ t .Fatalf ("Incorrect Unmarshalling for eid: %v != %v" , x .peerIPMask , p .peerIPMask )
26+ }
27+ if x .vtep .String () != p .vtep .String () {
28+ t .Fatalf ("Incorrect Unmarshalling for eid: %v != %v" , x .vtep , p .vtep )
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments