2015-04-10 16:02:25 +00:00
|
|
|
package bridge
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-04-13 18:40:42 +00:00
|
|
|
"github.com/docker/libnetwork/driverapi"
|
2015-05-16 23:02:51 +00:00
|
|
|
"github.com/docker/libnetwork/netlabel"
|
2015-09-07 17:33:28 +00:00
|
|
|
"github.com/docker/libnetwork/testutils"
|
2015-04-10 16:02:25 +00:00
|
|
|
"github.com/vishvananda/netlink"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLinkCreate(t *testing.T) {
|
2015-09-07 17:33:28 +00:00
|
|
|
defer testutils.SetupTestOSContext(t)()
|
Make driver packages register themselves via DriverCallback
In the present code, each driver package provides a `New()` method
which constructs a driver of its type, which is then registered with
the controller.
However, this is not suitable for the `drivers/remote` package, since
it does not provide a (singleton) driver, but a mechanism for drivers
to be added dynamically. As a result, the implementation is oddly
dual-purpose, and a spurious `"remote"` driver is added to the
controller's list of available drivers.
Instead, it is better to provide the registration callback to each
package and let it register its own driver or drivers. That way, the
singleton driver packages can construct one and register it, and the
remote package can hook the callback up with whatever the dynamic
driver mechanism turns out to be.
NB there are some method signature changes; in particular to
controller.New, which can return an error if the built-in driver
packages fail to initialise.
Signed-off-by: Michael Bridgen <mikeb@squaremobius.net>
2015-05-11 12:46:29 +00:00
|
|
|
d := newDriver()
|
2015-04-10 16:02:25 +00:00
|
|
|
|
2015-09-18 21:00:36 +00:00
|
|
|
if err := d.configure(nil); err != nil {
|
2015-06-12 01:12:00 +00:00
|
|
|
t.Fatalf("Failed to setup driver config: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-04-23 20:39:41 +00:00
|
|
|
mtu := 1490
|
2015-05-22 17:56:36 +00:00
|
|
|
config := &networkConfiguration{
|
2015-04-10 16:02:25 +00:00
|
|
|
BridgeName: DefaultBridgeName,
|
2015-04-23 20:39:41 +00:00
|
|
|
Mtu: mtu,
|
2015-04-24 22:13:44 +00:00
|
|
|
EnableIPv6: true,
|
|
|
|
}
|
2015-05-01 00:57:06 +00:00
|
|
|
genericOption := make(map[string]interface{})
|
2015-05-06 04:19:57 +00:00
|
|
|
genericOption[netlabel.GenericData] = config
|
2015-04-15 05:25:42 +00:00
|
|
|
|
2016-06-28 03:42:50 +00:00
|
|
|
ipdList := getIPv4Data(t, "")
|
2016-04-19 02:55:39 +00:00
|
|
|
err := d.CreateNetwork("dummy", genericOption, nil, ipdList, nil)
|
2015-04-10 16:02:25 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create bridge: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-10-05 21:53:25 +00:00
|
|
|
te := newTestEndpoint(ipdList[0].Pool, 10)
|
2015-10-03 23:11:50 +00:00
|
|
|
err = d.CreateEndpoint("dummy", "", te.Interface(), nil)
|
2015-04-10 16:02:25 +00:00
|
|
|
if err != nil {
|
2015-04-20 11:23:04 +00:00
|
|
|
if _, ok := err.(InvalidEndpointIDError); !ok {
|
|
|
|
t.Fatalf("Failed with a wrong error :%s", err.Error())
|
|
|
|
}
|
|
|
|
} else {
|
2016-11-22 01:29:53 +00:00
|
|
|
t.Fatal("Failed to detect invalid config")
|
2015-04-20 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-23 20:39:41 +00:00
|
|
|
// Good endpoint creation
|
2015-10-03 23:11:50 +00:00
|
|
|
err = d.CreateEndpoint("dummy", "ep", te.Interface(), nil)
|
2015-05-14 06:23:45 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create a link: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
err = d.Join("dummy", "ep", "sbox", te, nil)
|
2015-04-20 11:23:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create a link: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
2015-04-23 20:39:41 +00:00
|
|
|
// Verify sbox endoint interface inherited MTU value from bridge config
|
2015-09-09 23:06:35 +00:00
|
|
|
sboxLnk, err := netlink.LinkByName(te.iface.srcName)
|
2015-04-23 20:39:41 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if mtu != sboxLnk.Attrs().MTU {
|
2016-11-22 01:29:53 +00:00
|
|
|
t.Fatal("Sandbox endpoint interface did not inherit bridge interface MTU config")
|
2015-04-23 20:39:41 +00:00
|
|
|
}
|
|
|
|
// TODO: if we could get peer name from (sboxLnk.(*netlink.Veth)).PeerName
|
|
|
|
// then we could check the MTU on hostLnk as well.
|
|
|
|
|
2015-10-05 21:53:25 +00:00
|
|
|
te1 := newTestEndpoint(ipdList[0].Pool, 11)
|
2015-10-03 23:11:50 +00:00
|
|
|
err = d.CreateEndpoint("dummy", "ep", te1.Interface(), nil)
|
2015-04-20 11:23:04 +00:00
|
|
|
if err == nil {
|
2016-11-22 01:29:53 +00:00
|
|
|
t.Fatal("Failed to detect duplicate endpoint id on same network")
|
2015-04-20 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
if te.iface.dstName == "" {
|
2015-04-10 16:02:25 +00:00
|
|
|
t.Fatal("Invalid Dstname returned")
|
|
|
|
}
|
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
_, err = netlink.LinkByName(te.iface.srcName)
|
2015-04-10 16:02:25 +00:00
|
|
|
if err != nil {
|
2015-09-09 23:06:35 +00:00
|
|
|
t.Fatalf("Could not find source link %s: %v", te.iface.srcName, err)
|
2015-04-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 21:00:36 +00:00
|
|
|
n, ok := d.networks["dummy"]
|
2015-05-21 20:13:19 +00:00
|
|
|
if !ok {
|
|
|
|
t.Fatalf("Cannot find network %s inside driver", "dummy")
|
|
|
|
}
|
2015-09-09 23:06:35 +00:00
|
|
|
ip := te.iface.addr.IP
|
2015-04-13 18:40:42 +00:00
|
|
|
if !n.bridge.bridgeIPv4.Contains(ip) {
|
|
|
|
t.Fatalf("IP %s is not a valid ip in the subnet %s", ip.String(), n.bridge.bridgeIPv4.String())
|
2015-04-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
ip6 := te.iface.addrv6.IP
|
2015-04-13 18:40:42 +00:00
|
|
|
if !n.bridge.bridgeIPv6.Contains(ip6) {
|
2015-04-10 16:02:25 +00:00
|
|
|
t.Fatalf("IP %s is not a valid ip in the subnet %s", ip6.String(), bridgeIPv6.String())
|
|
|
|
}
|
|
|
|
|
2015-05-14 06:23:45 +00:00
|
|
|
if !te.gw.Equal(n.bridge.bridgeIPv4.IP) {
|
2015-04-13 18:40:42 +00:00
|
|
|
t.Fatalf("Invalid default gateway. Expected %s. Got %s", n.bridge.bridgeIPv4.IP.String(),
|
2015-05-14 06:23:45 +00:00
|
|
|
te.gw.String())
|
2015-04-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 06:23:45 +00:00
|
|
|
if !te.gw6.Equal(n.bridge.bridgeIPv6.IP) {
|
2015-04-13 18:40:42 +00:00
|
|
|
t.Fatalf("Invalid default gateway for IPv6. Expected %s. Got %s", n.bridge.bridgeIPv6.IP.String(),
|
2015-05-14 06:23:45 +00:00
|
|
|
te.gw6.String())
|
2015-04-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLinkCreateTwo(t *testing.T) {
|
2015-09-07 17:33:28 +00:00
|
|
|
defer testutils.SetupTestOSContext(t)()
|
Make driver packages register themselves via DriverCallback
In the present code, each driver package provides a `New()` method
which constructs a driver of its type, which is then registered with
the controller.
However, this is not suitable for the `drivers/remote` package, since
it does not provide a (singleton) driver, but a mechanism for drivers
to be added dynamically. As a result, the implementation is oddly
dual-purpose, and a spurious `"remote"` driver is added to the
controller's list of available drivers.
Instead, it is better to provide the registration callback to each
package and let it register its own driver or drivers. That way, the
singleton driver packages can construct one and register it, and the
remote package can hook the callback up with whatever the dynamic
driver mechanism turns out to be.
NB there are some method signature changes; in particular to
controller.New, which can return an error if the built-in driver
packages fail to initialise.
Signed-off-by: Michael Bridgen <mikeb@squaremobius.net>
2015-05-11 12:46:29 +00:00
|
|
|
d := newDriver()
|
2015-04-10 16:02:25 +00:00
|
|
|
|
2015-09-18 21:00:36 +00:00
|
|
|
if err := d.configure(nil); err != nil {
|
2015-06-12 01:12:00 +00:00
|
|
|
t.Fatalf("Failed to setup driver config: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-05-22 17:56:36 +00:00
|
|
|
config := &networkConfiguration{
|
2015-04-10 16:02:25 +00:00
|
|
|
BridgeName: DefaultBridgeName,
|
|
|
|
EnableIPv6: true}
|
2015-05-01 00:57:06 +00:00
|
|
|
genericOption := make(map[string]interface{})
|
2015-05-06 04:19:57 +00:00
|
|
|
genericOption[netlabel.GenericData] = config
|
2015-04-15 05:25:42 +00:00
|
|
|
|
2016-06-28 03:42:50 +00:00
|
|
|
ipdList := getIPv4Data(t, "")
|
2016-04-19 02:55:39 +00:00
|
|
|
err := d.CreateNetwork("dummy", genericOption, nil, ipdList, nil)
|
2015-04-10 16:02:25 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create bridge: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-10-05 21:53:25 +00:00
|
|
|
te1 := newTestEndpoint(ipdList[0].Pool, 11)
|
2015-10-03 23:11:50 +00:00
|
|
|
err = d.CreateEndpoint("dummy", "ep", te1.Interface(), nil)
|
2015-04-10 16:02:25 +00:00
|
|
|
if err != nil {
|
2015-04-20 11:23:04 +00:00
|
|
|
t.Fatalf("Failed to create a link: %s", err.Error())
|
2015-04-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2015-10-05 21:53:25 +00:00
|
|
|
te2 := newTestEndpoint(ipdList[0].Pool, 12)
|
2015-10-03 23:11:50 +00:00
|
|
|
err = d.CreateEndpoint("dummy", "ep", te2.Interface(), nil)
|
2015-04-10 16:02:25 +00:00
|
|
|
if err != nil {
|
2015-05-14 21:56:15 +00:00
|
|
|
if _, ok := err.(driverapi.ErrEndpointExists); !ok {
|
|
|
|
t.Fatalf("Failed with a wrong error: %s", err.Error())
|
2015-04-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-11-22 01:29:53 +00:00
|
|
|
t.Fatal("Expected to fail while trying to add same endpoint twice")
|
2015-04-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLinkCreateNoEnableIPv6(t *testing.T) {
|
2015-09-07 17:33:28 +00:00
|
|
|
defer testutils.SetupTestOSContext(t)()
|
Make driver packages register themselves via DriverCallback
In the present code, each driver package provides a `New()` method
which constructs a driver of its type, which is then registered with
the controller.
However, this is not suitable for the `drivers/remote` package, since
it does not provide a (singleton) driver, but a mechanism for drivers
to be added dynamically. As a result, the implementation is oddly
dual-purpose, and a spurious `"remote"` driver is added to the
controller's list of available drivers.
Instead, it is better to provide the registration callback to each
package and let it register its own driver or drivers. That way, the
singleton driver packages can construct one and register it, and the
remote package can hook the callback up with whatever the dynamic
driver mechanism turns out to be.
NB there are some method signature changes; in particular to
controller.New, which can return an error if the built-in driver
packages fail to initialise.
Signed-off-by: Michael Bridgen <mikeb@squaremobius.net>
2015-05-11 12:46:29 +00:00
|
|
|
d := newDriver()
|
2015-04-10 16:02:25 +00:00
|
|
|
|
2015-09-18 21:00:36 +00:00
|
|
|
if err := d.configure(nil); err != nil {
|
2015-06-12 01:12:00 +00:00
|
|
|
t.Fatalf("Failed to setup driver config: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-05-22 17:56:36 +00:00
|
|
|
config := &networkConfiguration{
|
2015-04-10 16:02:25 +00:00
|
|
|
BridgeName: DefaultBridgeName}
|
2015-05-01 00:57:06 +00:00
|
|
|
genericOption := make(map[string]interface{})
|
2015-05-06 04:19:57 +00:00
|
|
|
genericOption[netlabel.GenericData] = config
|
2015-05-01 00:57:06 +00:00
|
|
|
|
2016-06-28 03:42:50 +00:00
|
|
|
ipdList := getIPv4Data(t, "")
|
2016-04-19 02:55:39 +00:00
|
|
|
err := d.CreateNetwork("dummy", genericOption, nil, ipdList, nil)
|
2015-04-10 16:02:25 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create bridge: %v", err)
|
|
|
|
}
|
2015-10-05 21:53:25 +00:00
|
|
|
te := newTestEndpoint(ipdList[0].Pool, 30)
|
2015-10-03 23:11:50 +00:00
|
|
|
err = d.CreateEndpoint("dummy", "ep", te.Interface(), nil)
|
2015-04-10 16:02:25 +00:00
|
|
|
if err != nil {
|
2015-04-20 11:23:04 +00:00
|
|
|
t.Fatalf("Failed to create a link: %s", err.Error())
|
2015-04-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
iface := te.iface
|
2015-10-03 23:11:50 +00:00
|
|
|
if iface.addrv6 != nil && iface.addrv6.IP.To16() != nil {
|
2015-09-09 23:06:35 +00:00
|
|
|
t.Fatalf("Expectd IPv6 address to be nil when IPv6 is not enabled. Got IPv6 = %s", iface.addrv6.String())
|
2015-04-14 01:36:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 06:23:45 +00:00
|
|
|
if te.gw6.To16() != nil {
|
|
|
|
t.Fatalf("Expected GatewayIPv6 to be nil when IPv6 is not enabled. Got GatewayIPv6 = %s", te.gw6.String())
|
2015-04-10 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-20 11:23:04 +00:00
|
|
|
|
|
|
|
func TestLinkDelete(t *testing.T) {
|
2015-09-07 17:33:28 +00:00
|
|
|
defer testutils.SetupTestOSContext(t)()
|
Make driver packages register themselves via DriverCallback
In the present code, each driver package provides a `New()` method
which constructs a driver of its type, which is then registered with
the controller.
However, this is not suitable for the `drivers/remote` package, since
it does not provide a (singleton) driver, but a mechanism for drivers
to be added dynamically. As a result, the implementation is oddly
dual-purpose, and a spurious `"remote"` driver is added to the
controller's list of available drivers.
Instead, it is better to provide the registration callback to each
package and let it register its own driver or drivers. That way, the
singleton driver packages can construct one and register it, and the
remote package can hook the callback up with whatever the dynamic
driver mechanism turns out to be.
NB there are some method signature changes; in particular to
controller.New, which can return an error if the built-in driver
packages fail to initialise.
Signed-off-by: Michael Bridgen <mikeb@squaremobius.net>
2015-05-11 12:46:29 +00:00
|
|
|
d := newDriver()
|
2015-04-20 11:23:04 +00:00
|
|
|
|
2015-09-18 21:00:36 +00:00
|
|
|
if err := d.configure(nil); err != nil {
|
2015-06-12 01:12:00 +00:00
|
|
|
t.Fatalf("Failed to setup driver config: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-05-22 17:56:36 +00:00
|
|
|
config := &networkConfiguration{
|
2015-04-20 11:23:04 +00:00
|
|
|
BridgeName: DefaultBridgeName,
|
|
|
|
EnableIPv6: true}
|
2015-05-01 00:57:06 +00:00
|
|
|
genericOption := make(map[string]interface{})
|
2015-05-06 04:19:57 +00:00
|
|
|
genericOption[netlabel.GenericData] = config
|
2015-05-01 00:57:06 +00:00
|
|
|
|
2016-06-28 03:42:50 +00:00
|
|
|
ipdList := getIPv4Data(t, "")
|
2016-04-19 02:55:39 +00:00
|
|
|
err := d.CreateNetwork("dummy", genericOption, nil, ipdList, nil)
|
2015-04-20 11:23:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create bridge: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-10-05 21:53:25 +00:00
|
|
|
te := newTestEndpoint(ipdList[0].Pool, 30)
|
2015-10-03 23:11:50 +00:00
|
|
|
err = d.CreateEndpoint("dummy", "ep1", te.Interface(), nil)
|
2015-04-20 11:23:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create a link: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
err = d.DeleteEndpoint("dummy", "")
|
|
|
|
if err != nil {
|
|
|
|
if _, ok := err.(InvalidEndpointIDError); !ok {
|
|
|
|
t.Fatalf("Failed with a wrong error :%s", err.Error())
|
|
|
|
}
|
|
|
|
} else {
|
2016-11-22 01:29:53 +00:00
|
|
|
t.Fatal("Failed to detect invalid config")
|
2015-04-20 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = d.DeleteEndpoint("dummy", "ep1")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|