Browse code

Refactor driverapi, sandbox pkgs

- Move SanboxInfo and Interface structures in sandbox package
(changed it to Info as per golint)
- Move UUID to new internal pkg types
- Updated .gitignore to ignore IDE project files

Signed-off-by: Alessandro Boch <aboch@docker.com>

Alessandro Boch authored on 2015/04/21 00:44:06
Showing 10 changed files
... ...
@@ -26,3 +26,6 @@ _testmain.go
26 26
 # Coverage
27 27
 *.tmp
28 28
 *.coverprofile
29
+
30
+# IDE files
31
+.project
... ...
@@ -2,9 +2,9 @@ package driverapi
2 2
 
3 3
 import (
4 4
 	"errors"
5
-	"net"
6 5
 
7
-	"github.com/docker/libnetwork/netutils"
6
+	"github.com/docker/libnetwork/sandbox"
7
+	"github.com/docker/libnetwork/types"
8 8
 )
9 9
 
10 10
 var (
... ...
@@ -16,9 +16,6 @@ var (
16 16
 	ErrNoEndpoint = errors.New("No endpoint exists")
17 17
 )
18 18
 
19
-// UUID represents a globally unique ID of various resources like network and endpoint
20
-type UUID string
21
-
22 19
 // Driver is an interface that every plugin driver needs to implement.
23 20
 type Driver interface {
24 21
 	// Push driver specific config to the driver
... ...
@@ -27,136 +24,19 @@ type Driver interface {
27 27
 	// CreateNetwork invokes the driver method to create a network passing
28 28
 	// the network id and network specific config. The config mechanism will
29 29
 	// eventually be replaced with labels which are yet to be introduced.
30
-	CreateNetwork(nid UUID, config interface{}) error
30
+	CreateNetwork(nid types.UUID, config interface{}) error
31 31
 
32 32
 	// DeleteNetwork invokes the driver method to delete network passing
33 33
 	// the network id.
34
-	DeleteNetwork(nid UUID) error
34
+	DeleteNetwork(nid types.UUID) error
35 35
 
36 36
 	// CreateEndpoint invokes the driver method to create an endpoint
37 37
 	// passing the network id, endpoint id, sandbox key and driver
38 38
 	// specific config. The config mechanism will eventually be replaced
39 39
 	// with labels which are yet to be introduced.
40
-	CreateEndpoint(nid, eid UUID, key string, config interface{}) (*SandboxInfo, error)
40
+	CreateEndpoint(nid, eid types.UUID, key string, config interface{}) (*sandbox.Info, error)
41 41
 
42 42
 	// DeleteEndpoint invokes the driver method to delete an endpoint
43 43
 	// passing the network id and endpoint id.
44
-	DeleteEndpoint(nid, eid UUID) error
45
-}
46
-
47
-// Interface represents the settings and identity of a network device. It is
48
-// used as a return type for Network.Link, and it is common practice for the
49
-// caller to use this information when moving interface SrcName from host
50
-// namespace to DstName in a different net namespace with the appropriate
51
-// network settings.
52
-type Interface struct {
53
-	// The name of the interface in the origin network namespace.
54
-	SrcName string
55
-
56
-	// The name that will be assigned to the interface once moves inside a
57
-	// network namespace.
58
-	DstName string
59
-
60
-	// IPv4 address for the interface.
61
-	Address *net.IPNet
62
-
63
-	// IPv6 address for the interface.
64
-	AddressIPv6 *net.IPNet
65
-}
66
-
67
-// SandboxInfo represents all possible information that
68
-// the driver wants to place in the sandbox which includes
69
-// interfaces, routes and gateway
70
-type SandboxInfo struct {
71
-	Interfaces []*Interface
72
-
73
-	// IPv4 gateway for the sandbox.
74
-	Gateway net.IP
75
-
76
-	// IPv6 gateway for the sandbox.
77
-	GatewayIPv6 net.IP
78
-
79
-	// TODO: Add routes and ip tables etc.
80
-}
81
-
82
-// GetCopy returns a copy of this Interface structure
83
-func (i *Interface) GetCopy() *Interface {
84
-	return &Interface{
85
-		SrcName:     i.SrcName,
86
-		DstName:     i.DstName,
87
-		Address:     netutils.GetIPNetCopy(i.Address),
88
-		AddressIPv6: netutils.GetIPNetCopy(i.AddressIPv6),
89
-	}
90
-}
91
-
92
-// Equal checks if this instance of Interface is equal to the passed one
93
-func (i *Interface) Equal(o *Interface) bool {
94
-	if i == o {
95
-		return true
96
-	}
97
-
98
-	if o == nil {
99
-		return false
100
-	}
101
-
102
-	if i.SrcName != o.SrcName || i.DstName != o.DstName {
103
-		return false
104
-	}
105
-
106
-	if !netutils.CompareIPNet(i.Address, o.Address) {
107
-		return false
108
-	}
109
-
110
-	if !netutils.CompareIPNet(i.AddressIPv6, o.AddressIPv6) {
111
-		return false
112
-	}
113
-
114
-	return true
115
-}
116
-
117
-// GetCopy returns a copy of this SandboxInfo structure
118
-func (s *SandboxInfo) GetCopy() *SandboxInfo {
119
-	list := make([]*Interface, len(s.Interfaces))
120
-	for i, iface := range s.Interfaces {
121
-		list[i] = iface.GetCopy()
122
-	}
123
-	gw := netutils.GetIPCopy(s.Gateway)
124
-	gw6 := netutils.GetIPCopy(s.GatewayIPv6)
125
-
126
-	return &SandboxInfo{Interfaces: list, Gateway: gw, GatewayIPv6: gw6}
127
-}
128
-
129
-// Equal checks if this instance of SandboxInfo is equal to the passed one
130
-func (s *SandboxInfo) Equal(o *SandboxInfo) bool {
131
-	if s == o {
132
-		return true
133
-	}
134
-
135
-	if o == nil {
136
-		return false
137
-	}
138
-
139
-	if !s.Gateway.Equal(o.Gateway) {
140
-		return false
141
-	}
142
-
143
-	if !s.GatewayIPv6.Equal(o.GatewayIPv6) {
144
-		return false
145
-	}
146
-
147
-	if (s.Interfaces == nil && o.Interfaces != nil) ||
148
-		(s.Interfaces != nil && o.Interfaces == nil) ||
149
-		(len(s.Interfaces) != len(o.Interfaces)) {
150
-		return false
151
-	}
152
-
153
-	// Note: At the moment, the two lists must be in the same order
154
-	for i := 0; i < len(s.Interfaces); i++ {
155
-		if !s.Interfaces[i].Equal(o.Interfaces[i]) {
156
-			return false
157
-		}
158
-	}
159
-
160
-	return true
161
-
44
+	DeleteEndpoint(nid, eid types.UUID) error
162 45
 }
163 46
deleted file mode 100644
... ...
@@ -1,71 +0,0 @@
1
-package driverapi
2
-
3
-import (
4
-	"net"
5
-	"testing"
6
-)
7
-
8
-func TestInterfaceEqual(t *testing.T) {
9
-	list := getInterfaceList()
10
-
11
-	if !list[0].Equal(list[0]) {
12
-		t.Fatalf("Interface.Equal() returned false negative")
13
-	}
14
-
15
-	if list[0].Equal(list[1]) {
16
-		t.Fatalf("Interface.Equal() returned false positive")
17
-	}
18
-
19
-	if list[0].Equal(list[1]) != list[1].Equal(list[0]) {
20
-		t.Fatalf("Interface.Equal() failed commutative check")
21
-	}
22
-}
23
-
24
-func TestInterfaceCopy(t *testing.T) {
25
-	for _, iface := range getInterfaceList() {
26
-		cp := iface.GetCopy()
27
-
28
-		if !iface.Equal(cp) {
29
-			t.Fatalf("Failed to return a copy of Interface")
30
-		}
31
-
32
-		if iface == cp {
33
-			t.Fatalf("Failed to return a true copy of Interface")
34
-		}
35
-	}
36
-}
37
-
38
-func TestSandboxInfoCopy(t *testing.T) {
39
-	si := SandboxInfo{Interfaces: getInterfaceList(), Gateway: net.ParseIP("192.168.1.254"), GatewayIPv6: net.ParseIP("2001:2345::abcd:8889")}
40
-	cp := si.GetCopy()
41
-
42
-	if !si.Equal(cp) {
43
-		t.Fatalf("Failed to return a copy of SandboxInfo")
44
-	}
45
-
46
-	if &si == cp {
47
-		t.Fatalf("Failed to return a true copy of SanboxInfo")
48
-	}
49
-}
50
-
51
-func getInterfaceList() []*Interface {
52
-	_, netv4a, _ := net.ParseCIDR("192.168.30.1/24")
53
-	_, netv4b, _ := net.ParseCIDR("172.18.255.2/23")
54
-	_, netv6a, _ := net.ParseCIDR("2001:2345::abcd:8888/80")
55
-	_, netv6b, _ := net.ParseCIDR("2001:2345::abcd:8889/80")
56
-
57
-	return []*Interface{
58
-		&Interface{
59
-			SrcName:     "veth1234567",
60
-			DstName:     "eth0",
61
-			Address:     netv4a,
62
-			AddressIPv6: netv6a,
63
-		},
64
-		&Interface{
65
-			SrcName:     "veth7654321",
66
-			DstName:     "eth1",
67
-			Address:     netv4b,
68
-			AddressIPv6: netv6b,
69
-		},
70
-	}
71
-}
... ...
@@ -10,6 +10,8 @@ import (
10 10
 	"github.com/docker/libnetwork/netutils"
11 11
 	"github.com/docker/libnetwork/pkg/options"
12 12
 	"github.com/docker/libnetwork/portmapper"
13
+	"github.com/docker/libnetwork/sandbox"
14
+	"github.com/docker/libnetwork/types"
13 15
 	"github.com/vishvananda/netlink"
14 16
 )
15 17
 
... ...
@@ -40,13 +42,13 @@ type Configuration struct {
40 40
 }
41 41
 
42 42
 type bridgeEndpoint struct {
43
-	id          driverapi.UUID
43
+	id          types.UUID
44 44
 	addressIPv4 net.IP
45 45
 	addressIPv6 net.IP
46 46
 }
47 47
 
48 48
 type bridgeNetwork struct {
49
-	id driverapi.UUID
49
+	id types.UUID
50 50
 	// bridge interface points to the linux bridge and it's configuration
51 51
 	bridge   *bridgeInterface
52 52
 	endpoint *bridgeEndpoint
... ...
@@ -95,7 +97,7 @@ func (d *driver) Config(option interface{}) error {
95 95
 }
96 96
 
97 97
 // Create a new network using simplebridge plugin
98
-func (d *driver) CreateNetwork(id driverapi.UUID, option interface{}) error {
98
+func (d *driver) CreateNetwork(id types.UUID, option interface{}) error {
99 99
 
100 100
 	var (
101 101
 		err error
... ...
@@ -178,7 +180,7 @@ func (d *driver) CreateNetwork(id driverapi.UUID, option interface{}) error {
178 178
 	return nil
179 179
 }
180 180
 
181
-func (d *driver) DeleteNetwork(nid driverapi.UUID) error {
181
+func (d *driver) DeleteNetwork(nid types.UUID) error {
182 182
 	var err error
183 183
 	d.Lock()
184 184
 	n := d.network
... ...
@@ -211,7 +213,7 @@ func (d *driver) DeleteNetwork(nid driverapi.UUID) error {
211 211
 	return err
212 212
 }
213 213
 
214
-func (d *driver) CreateEndpoint(nid, eid driverapi.UUID, sboxKey string, epOption interface{}) (*driverapi.SandboxInfo, error) {
214
+func (d *driver) CreateEndpoint(nid, eid types.UUID, sboxKey string, epOption interface{}) (*sandbox.Info, error) {
215 215
 	var (
216 216
 		ipv6Addr *net.IPNet
217 217
 		ip6      net.IP
... ...
@@ -303,10 +305,10 @@ func (d *driver) CreateEndpoint(nid, eid driverapi.UUID, sboxKey string, epOptio
303 303
 		ipv6Addr = &net.IPNet{IP: ip6, Mask: n.bridge.bridgeIPv6.Mask}
304 304
 	}
305 305
 
306
-	var interfaces []*driverapi.Interface
307
-	sinfo := &driverapi.SandboxInfo{}
306
+	var interfaces []*sandbox.Interface
307
+	sinfo := &sandbox.Info{}
308 308
 
309
-	intf := &driverapi.Interface{}
309
+	intf := &sandbox.Interface{}
310 310
 	intf.SrcName = name2
311 311
 	intf.DstName = containerVeth
312 312
 	intf.Address = ipv4Addr
... ...
@@ -323,7 +325,7 @@ func (d *driver) CreateEndpoint(nid, eid driverapi.UUID, sboxKey string, epOptio
323 323
 	return sinfo, nil
324 324
 }
325 325
 
326
-func (d *driver) DeleteEndpoint(nid, eid driverapi.UUID) error {
326
+func (d *driver) DeleteEndpoint(nid, eid types.UUID) error {
327 327
 	var err error
328 328
 
329 329
 	d.Lock()
... ...
@@ -43,6 +43,8 @@ import (
43 43
 
44 44
 	"github.com/docker/docker/pkg/stringid"
45 45
 	"github.com/docker/libnetwork/driverapi"
46
+	"github.com/docker/libnetwork/sandbox"
47
+	"github.com/docker/libnetwork/types"
46 48
 )
47 49
 
48 50
 // NetworkController provides the interface for controller instance which manages
... ...
@@ -91,7 +93,7 @@ type Endpoint interface {
91 91
 	Network() string
92 92
 
93 93
 	// SandboxInfo returns the sandbox information for this endpoint.
94
-	SandboxInfo() *driverapi.SandboxInfo
94
+	SandboxInfo() *sandbox.Info
95 95
 
96 96
 	// Delete and detaches this endpoint from the network.
97 97
 	Delete() error
... ...
@@ -105,23 +107,23 @@ type NetworkDriver struct {
105 105
 
106 106
 type endpoint struct {
107 107
 	name        string
108
-	id          driverapi.UUID
108
+	id          types.UUID
109 109
 	network     *network
110
-	sandboxInfo *driverapi.SandboxInfo
110
+	sandboxInfo *sandbox.Info
111 111
 }
112 112
 
113 113
 type network struct {
114 114
 	ctrlr       *controller
115 115
 	name        string
116 116
 	networkType string
117
-	id          driverapi.UUID
117
+	id          types.UUID
118 118
 	driver      *NetworkDriver
119 119
 	endpoints   endpointTable
120 120
 	sync.Mutex
121 121
 }
122 122
 
123
-type networkTable map[driverapi.UUID]*network
124
-type endpointTable map[driverapi.UUID]*endpoint
123
+type networkTable map[types.UUID]*network
124
+type endpointTable map[types.UUID]*endpoint
125 125
 
126 126
 type controller struct {
127 127
 	networks networkTable
... ...
@@ -165,7 +167,7 @@ func (c *controller) NewNetwork(nd *NetworkDriver, name string, options interfac
165 165
 
166 166
 	network := &network{
167 167
 		name:   name,
168
-		id:     driverapi.UUID(stringid.GenerateRandomID()),
168
+		id:     types.UUID(stringid.GenerateRandomID()),
169 169
 		ctrlr:  c,
170 170
 		driver: nd}
171 171
 	network.endpoints = make(endpointTable)
... ...
@@ -237,7 +239,7 @@ func (n *network) Delete() error {
237 237
 
238 238
 func (n *network) CreateEndpoint(name string, sboxKey string, options interface{}) (Endpoint, error) {
239 239
 	ep := &endpoint{name: name}
240
-	ep.id = driverapi.UUID(stringid.GenerateRandomID())
240
+	ep.id = types.UUID(stringid.GenerateRandomID())
241 241
 	ep.network = n
242 242
 
243 243
 	d := n.driver.internalDriver
... ...
@@ -280,7 +282,7 @@ func (ep *endpoint) Network() string {
280 280
 	return ep.network.name
281 281
 }
282 282
 
283
-func (ep *endpoint) SandboxInfo() *driverapi.SandboxInfo {
283
+func (ep *endpoint) SandboxInfo() *sandbox.Info {
284 284
 	if ep.sandboxInfo == nil {
285 285
 		return nil
286 286
 	}
... ...
@@ -4,14 +4,13 @@ import (
4 4
 	"fmt"
5 5
 	"net"
6 6
 
7
-	"github.com/docker/libnetwork/driverapi"
8 7
 	"github.com/vishvananda/netlink"
9 8
 )
10 9
 
11
-func configureInterface(iface netlink.Link, settings *driverapi.Interface) error {
10
+func configureInterface(iface netlink.Link, settings *Interface) error {
12 11
 	ifaceName := iface.Attrs().Name
13 12
 	ifaceConfigurators := []struct {
14
-		Fn         func(netlink.Link, *driverapi.Interface) error
13
+		Fn         func(netlink.Link, *Interface) error
15 14
 		ErrMessage string
16 15
 	}{
17 16
 		{setInterfaceName, fmt.Sprintf("error renaming interface %q to %q", ifaceName, settings.DstName)},
... ...
@@ -34,16 +33,16 @@ func setGatewayIP(gw net.IP) error {
34 34
 	})
35 35
 }
36 36
 
37
-func setInterfaceIP(iface netlink.Link, settings *driverapi.Interface) error {
37
+func setInterfaceIP(iface netlink.Link, settings *Interface) error {
38 38
 	ipAddr := &netlink.Addr{IPNet: settings.Address, Label: ""}
39 39
 	return netlink.AddrAdd(iface, ipAddr)
40 40
 }
41 41
 
42
-func setInterfaceIPv6(iface netlink.Link, settings *driverapi.Interface) error {
42
+func setInterfaceIPv6(iface netlink.Link, settings *Interface) error {
43 43
 	ipAddr := &netlink.Addr{IPNet: settings.Address, Label: ""}
44 44
 	return netlink.AddrAdd(iface, ipAddr)
45 45
 }
46 46
 
47
-func setInterfaceName(iface netlink.Link, settings *driverapi.Interface) error {
47
+func setInterfaceName(iface netlink.Link, settings *Interface) error {
48 48
 	return netlink.LinkSetName(iface, settings.DstName)
49 49
 }
... ...
@@ -7,7 +7,6 @@ import (
7 7
 	"runtime"
8 8
 	"syscall"
9 9
 
10
-	"github.com/docker/libnetwork/driverapi"
11 10
 	"github.com/vishvananda/netlink"
12 11
 	"github.com/vishvananda/netns"
13 12
 )
... ...
@@ -17,7 +16,7 @@ import (
17 17
 // into it when called on method AddInterface or sets the gateway etc.
18 18
 type networkNamespace struct {
19 19
 	path  string
20
-	sinfo *driverapi.SandboxInfo
20
+	sinfo *Info
21 21
 }
22 22
 
23 23
 // NewSandbox provides a new sandbox instance created in an os specific way
... ...
@@ -74,7 +73,7 @@ func loopbackUp() error {
74 74
 	return netlink.LinkSetUp(iface)
75 75
 }
76 76
 
77
-func (n *networkNamespace) AddInterface(i *driverapi.Interface) error {
77
+func (n *networkNamespace) AddInterface(i *Interface) error {
78 78
 	runtime.LockOSThread()
79 79
 	defer runtime.UnlockOSThread()
80 80
 
... ...
@@ -139,7 +138,7 @@ func (n *networkNamespace) SetGatewayIPv6(gw net.IP) error {
139 139
 	return err
140 140
 }
141 141
 
142
-func (n *networkNamespace) Interfaces() []*driverapi.Interface {
142
+func (n *networkNamespace) Interfaces() []*Interface {
143 143
 	return n.sinfo.Interfaces
144 144
 }
145 145
 
... ...
@@ -3,7 +3,7 @@ package sandbox
3 3
 import (
4 4
 	"net"
5 5
 
6
-	"github.com/docker/libnetwork/driverapi"
6
+	"github.com/docker/libnetwork/netutils"
7 7
 )
8 8
 
9 9
 // Sandbox represents a network sandbox, identified by a specific key.  It
... ...
@@ -16,12 +16,12 @@ type Sandbox interface {
16 16
 	// method. Note that this doesn't incude network interfaces added in any
17 17
 	// other way (such as the default loopback interface which are automatically
18 18
 	// created on creation of a sandbox).
19
-	Interfaces() []*driverapi.Interface
19
+	Interfaces() []*Interface
20 20
 
21 21
 	// Add an existing Interface to this sandbox. The operation will rename
22 22
 	// from the Interface SrcName to DstName as it moves, and reconfigure the
23 23
 	// interface according to the specified settings.
24
-	AddInterface(*driverapi.Interface) error
24
+	AddInterface(*Interface) error
25 25
 
26 26
 	// Set default IPv4 gateway for the sandbox
27 27
 	SetGateway(gw net.IP) error
... ...
@@ -29,3 +29,120 @@ type Sandbox interface {
29 29
 	// Set default IPv6 gateway for the sandbox
30 30
 	SetGatewayIPv6(gw net.IP) error
31 31
 }
32
+
33
+// Info represents all possible information that
34
+// the driver wants to place in the sandbox which includes
35
+// interfaces, routes and gateway
36
+type Info struct {
37
+	Interfaces []*Interface
38
+
39
+	// IPv4 gateway for the sandbox.
40
+	Gateway net.IP
41
+
42
+	// IPv6 gateway for the sandbox.
43
+	GatewayIPv6 net.IP
44
+
45
+	// TODO: Add routes and ip tables etc.
46
+}
47
+
48
+// Interface represents the settings and identity of a network device. It is
49
+// used as a return type for Network.Link, and it is common practice for the
50
+// caller to use this information when moving interface SrcName from host
51
+// namespace to DstName in a different net namespace with the appropriate
52
+// network settings.
53
+type Interface struct {
54
+	// The name of the interface in the origin network namespace.
55
+	SrcName string
56
+
57
+	// The name that will be assigned to the interface once moves inside a
58
+	// network namespace.
59
+	DstName string
60
+
61
+	// IPv4 address for the interface.
62
+	Address *net.IPNet
63
+
64
+	// IPv6 address for the interface.
65
+	AddressIPv6 *net.IPNet
66
+}
67
+
68
+// GetCopy returns a copy of this Interface structure
69
+func (i *Interface) GetCopy() *Interface {
70
+	return &Interface{
71
+		SrcName:     i.SrcName,
72
+		DstName:     i.DstName,
73
+		Address:     netutils.GetIPNetCopy(i.Address),
74
+		AddressIPv6: netutils.GetIPNetCopy(i.AddressIPv6),
75
+	}
76
+}
77
+
78
+// Equal checks if this instance of Interface is equal to the passed one
79
+func (i *Interface) Equal(o *Interface) bool {
80
+	if i == o {
81
+		return true
82
+	}
83
+
84
+	if o == nil {
85
+		return false
86
+	}
87
+
88
+	if i.SrcName != o.SrcName || i.DstName != o.DstName {
89
+		return false
90
+	}
91
+
92
+	if !netutils.CompareIPNet(i.Address, o.Address) {
93
+		return false
94
+	}
95
+
96
+	if !netutils.CompareIPNet(i.AddressIPv6, o.AddressIPv6) {
97
+		return false
98
+	}
99
+
100
+	return true
101
+}
102
+
103
+// GetCopy returns a copy of this SandboxInfo structure
104
+func (s *Info) GetCopy() *Info {
105
+	list := make([]*Interface, len(s.Interfaces))
106
+	for i, iface := range s.Interfaces {
107
+		list[i] = iface.GetCopy()
108
+	}
109
+	gw := netutils.GetIPCopy(s.Gateway)
110
+	gw6 := netutils.GetIPCopy(s.GatewayIPv6)
111
+
112
+	return &Info{Interfaces: list, Gateway: gw, GatewayIPv6: gw6}
113
+}
114
+
115
+// Equal checks if this instance of SandboxInfo is equal to the passed one
116
+func (s *Info) Equal(o *Info) bool {
117
+	if s == o {
118
+		return true
119
+	}
120
+
121
+	if o == nil {
122
+		return false
123
+	}
124
+
125
+	if !s.Gateway.Equal(o.Gateway) {
126
+		return false
127
+	}
128
+
129
+	if !s.GatewayIPv6.Equal(o.GatewayIPv6) {
130
+		return false
131
+	}
132
+
133
+	if (s.Interfaces == nil && o.Interfaces != nil) ||
134
+		(s.Interfaces != nil && o.Interfaces == nil) ||
135
+		(len(s.Interfaces) != len(o.Interfaces)) {
136
+		return false
137
+	}
138
+
139
+	// Note: At the moment, the two lists must be in the same order
140
+	for i := 0; i < len(s.Interfaces); i++ {
141
+		if !s.Interfaces[i].Equal(o.Interfaces[i]) {
142
+			return false
143
+		}
144
+	}
145
+
146
+	return true
147
+
148
+}
... ...
@@ -1,6 +1,9 @@
1 1
 package sandbox
2 2
 
3
-import "testing"
3
+import (
4
+	"net"
5
+	"testing"
6
+)
4 7
 
5 8
 func TestSandboxCreate(t *testing.T) {
6 9
 	key, err := newKey(t)
... ...
@@ -19,3 +22,68 @@ func TestSandboxCreate(t *testing.T) {
19 19
 
20 20
 	verifySandbox(t, s)
21 21
 }
22
+
23
+func TestInterfaceEqual(t *testing.T) {
24
+	list := getInterfaceList()
25
+
26
+	if !list[0].Equal(list[0]) {
27
+		t.Fatalf("Interface.Equal() returned false negative")
28
+	}
29
+
30
+	if list[0].Equal(list[1]) {
31
+		t.Fatalf("Interface.Equal() returned false positive")
32
+	}
33
+
34
+	if list[0].Equal(list[1]) != list[1].Equal(list[0]) {
35
+		t.Fatalf("Interface.Equal() failed commutative check")
36
+	}
37
+}
38
+
39
+func TestInterfaceCopy(t *testing.T) {
40
+	for _, iface := range getInterfaceList() {
41
+		cp := iface.GetCopy()
42
+
43
+		if !iface.Equal(cp) {
44
+			t.Fatalf("Failed to return a copy of Interface")
45
+		}
46
+
47
+		if iface == cp {
48
+			t.Fatalf("Failed to return a true copy of Interface")
49
+		}
50
+	}
51
+}
52
+
53
+func TestSandboxInfoCopy(t *testing.T) {
54
+	si := Info{Interfaces: getInterfaceList(), Gateway: net.ParseIP("192.168.1.254"), GatewayIPv6: net.ParseIP("2001:2345::abcd:8889")}
55
+	cp := si.GetCopy()
56
+
57
+	if !si.Equal(cp) {
58
+		t.Fatalf("Failed to return a copy of Info")
59
+	}
60
+
61
+	if &si == cp {
62
+		t.Fatalf("Failed to return a true copy of Info")
63
+	}
64
+}
65
+
66
+func getInterfaceList() []*Interface {
67
+	_, netv4a, _ := net.ParseCIDR("192.168.30.1/24")
68
+	_, netv4b, _ := net.ParseCIDR("172.18.255.2/23")
69
+	_, netv6a, _ := net.ParseCIDR("2001:2345::abcd:8888/80")
70
+	_, netv6b, _ := net.ParseCIDR("2001:2345::abcd:8889/80")
71
+
72
+	return []*Interface{
73
+		&Interface{
74
+			SrcName:     "veth1234567",
75
+			DstName:     "eth0",
76
+			Address:     netv4a,
77
+			AddressIPv6: netv6a,
78
+		},
79
+		&Interface{
80
+			SrcName:     "veth7654321",
81
+			DstName:     "eth1",
82
+			Address:     netv4b,
83
+			AddressIPv6: netv6b,
84
+		},
85
+	}
86
+}
22 87
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+// Package types contains types that are common across libnetwork project
1
+package types
2
+
3
+// UUID represents a globally unique ID of various resources like network and endpoint
4
+type UUID string