Browse Source

Merge pull request #565 from mavenugo/adb

Moved InterfaceStatistics from osl into types package
Jana Radhakrishnan 9 years ago
parent
commit
c74538c22e

+ 1 - 1
libnetwork/libnetwork_test.go

@@ -1148,7 +1148,7 @@ func (f *fakeSandbox) Labels() map[string]interface{} {
 	return nil
 	return nil
 }
 }
 
 
-func (f *fakeSandbox) Statistics() (map[string]*osl.InterfaceStatistics, error) {
+func (f *fakeSandbox) Statistics() (map[string]*types.InterfaceStatistics, error) {
 	return nil, nil
 	return nil, nil
 }
 }
 
 

+ 3 - 3
libnetwork/osl/interface_linux.go

@@ -156,7 +156,7 @@ func (i *nwIface) Remove() error {
 }
 }
 
 
 // Returns the sandbox's side veth interface statistics
 // Returns the sandbox's side veth interface statistics
-func (i *nwIface) Statistics() (*InterfaceStatistics, error) {
+func (i *nwIface) Statistics() (*types.InterfaceStatistics, error) {
 	i.Lock()
 	i.Lock()
 	n := i.ns
 	n := i.ns
 	i.Unlock()
 	i.Unlock()
@@ -165,7 +165,7 @@ func (i *nwIface) Statistics() (*InterfaceStatistics, error) {
 	path := n.path
 	path := n.path
 	n.Unlock()
 	n.Unlock()
 
 
-	s := &InterfaceStatistics{}
+	s := &types.InterfaceStatistics{}
 
 
 	err := nsInvoke(path, func(nsFD int) error { return nil }, func(callerFD int) error {
 	err := nsInvoke(path, func(nsFD int) error { return nil }, func(callerFD int) error {
 		// For some reason ioutil.ReadFile(netStatsFile) reads the file in
 		// For some reason ioutil.ReadFile(netStatsFile) reads the file in
@@ -356,7 +356,7 @@ const (
 	base         = "[ ]*%s:([ ]+[0-9]+){16}"
 	base         = "[ ]*%s:([ ]+[0-9]+){16}"
 )
 )
 
 
-func scanInterfaceStats(data, ifName string, i *InterfaceStatistics) error {
+func scanInterfaceStats(data, ifName string, i *types.InterfaceStatistics) error {
 	var (
 	var (
 		bktStr string
 		bktStr string
 		bkt    uint64
 		bkt    uint64

+ 1 - 19
libnetwork/osl/sandbox.go

@@ -2,7 +2,6 @@
 package osl
 package osl
 
 
 import (
 import (
-	"fmt"
 	"net"
 	"net"
 
 
 	"github.com/docker/libnetwork/types"
 	"github.com/docker/libnetwork/types"
@@ -150,22 +149,5 @@ type Interface interface {
 	Remove() error
 	Remove() error
 
 
 	// Statistics returns the statistics for this interface
 	// Statistics returns the statistics for this interface
-	Statistics() (*InterfaceStatistics, error)
-}
-
-// InterfaceStatistics represents the interface's statistics
-type InterfaceStatistics struct {
-	RxBytes   uint64
-	RxPackets uint64
-	RxErrors  uint64
-	RxDropped uint64
-	TxBytes   uint64
-	TxPackets uint64
-	TxErrors  uint64
-	TxDropped uint64
-}
-
-func (is *InterfaceStatistics) String() string {
-	return fmt.Sprintf("\nRxBytes: %d, RxPackets: %d, RxErrors: %d, RxDropped: %d, TxBytes: %d, TxPackets: %d, TxErrors: %d, TxDropped: %d",
-		is.RxBytes, is.RxPackets, is.RxErrors, is.RxDropped, is.TxBytes, is.TxPackets, is.TxErrors, is.TxDropped)
+	Statistics() (*types.InterfaceStatistics, error)
 }
 }

+ 2 - 1
libnetwork/osl/sandbox_linux_test.go

@@ -9,6 +9,7 @@ import (
 	"time"
 	"time"
 
 
 	"github.com/docker/libnetwork/netutils"
 	"github.com/docker/libnetwork/netutils"
+	"github.com/docker/libnetwork/types"
 	"github.com/vishvananda/netlink"
 	"github.com/vishvananda/netlink"
 	"github.com/vishvananda/netns"
 	"github.com/vishvananda/netns"
 )
 )
@@ -162,7 +163,7 @@ func TestScanStatistics(t *testing.T) {
 			"    lo:  783782    1853    0    0    0     0          0         0   783782    1853    0    0    0     0       0          0\n" +
 			"    lo:  783782    1853    0    0    0     0          0         0   783782    1853    0    0    0     0       0          0\n" +
 			"lxcbr0:       0       0    0    0    0     0          0         0     9006      61    0    0    0     0       0          0\n"
 			"lxcbr0:       0       0    0    0    0     0          0         0     9006      61    0    0    0     0       0          0\n"
 
 
-	i := &InterfaceStatistics{}
+	i := &types.InterfaceStatistics{}
 
 
 	if err := scanInterfaceStats(data, "wlan0", i); err != nil {
 	if err := scanInterfaceStats(data, "wlan0", i); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)

+ 3 - 3
libnetwork/sandbox.go

@@ -28,7 +28,7 @@ type Sandbox interface {
 	// Labels returns the sandbox's labels
 	// Labels returns the sandbox's labels
 	Labels() map[string]interface{}
 	Labels() map[string]interface{}
 	// Statistics retrieves the interfaces' statistics for the sandbox
 	// Statistics retrieves the interfaces' statistics for the sandbox
-	Statistics() (map[string]*osl.InterfaceStatistics, error)
+	Statistics() (map[string]*types.InterfaceStatistics, error)
 	// Refresh leaves all the endpoints, resets and re-apply the options,
 	// Refresh leaves all the endpoints, resets and re-apply the options,
 	// re-joins all the endpoints without destroying the osl sandbox
 	// re-joins all the endpoints without destroying the osl sandbox
 	Refresh(options ...SandboxOption) error
 	Refresh(options ...SandboxOption) error
@@ -126,8 +126,8 @@ func (sb *sandbox) Labels() map[string]interface{} {
 	return sb.config.generic
 	return sb.config.generic
 }
 }
 
 
-func (sb *sandbox) Statistics() (map[string]*osl.InterfaceStatistics, error) {
-	m := make(map[string]*osl.InterfaceStatistics)
+func (sb *sandbox) Statistics() (map[string]*types.InterfaceStatistics, error) {
+	m := make(map[string]*types.InterfaceStatistics)
 
 
 	if sb.osSbox == nil {
 	if sb.osSbox == nil {
 		return m, nil
 		return m, nil

+ 17 - 0
libnetwork/types/types.go

@@ -321,6 +321,23 @@ func (r *StaticRoute) GetCopy() *StaticRoute {
 	}
 	}
 }
 }
 
 
+// InterfaceStatistics represents the interface's statistics
+type InterfaceStatistics struct {
+	RxBytes   uint64
+	RxPackets uint64
+	RxErrors  uint64
+	RxDropped uint64
+	TxBytes   uint64
+	TxPackets uint64
+	TxErrors  uint64
+	TxDropped uint64
+}
+
+func (is *InterfaceStatistics) String() string {
+	return fmt.Sprintf("\nRxBytes: %d, RxPackets: %d, RxErrors: %d, RxDropped: %d, TxBytes: %d, TxPackets: %d, TxErrors: %d, TxDropped: %d",
+		is.RxBytes, is.RxPackets, is.RxErrors, is.RxDropped, is.TxBytes, is.TxPackets, is.TxErrors, is.TxDropped)
+}
+
 /******************************
 /******************************
  * Well-known Error Interfaces
  * Well-known Error Interfaces
  ******************************/
  ******************************/