From caab594ffb9ec2b17989aca00539f314813809b1 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Sat, 26 Sep 2015 10:12:20 -0700 Subject: [PATCH] Moved InterfaceStatistics from osl into types package Exposing osl package outside libnetwork is not neccessary and the InterfaceStatistics anyways belong to the types package. Signed-off-by: Madhu Venugopal --- libnetwork/libnetwork_test.go | 2 +- libnetwork/osl/interface_linux.go | 6 +++--- libnetwork/osl/sandbox.go | 20 +------------------- libnetwork/osl/sandbox_linux_test.go | 3 ++- libnetwork/sandbox.go | 6 +++--- libnetwork/types/types.go | 17 +++++++++++++++++ 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/libnetwork/libnetwork_test.go b/libnetwork/libnetwork_test.go index f4e33394ce..e41e946dd3 100644 --- a/libnetwork/libnetwork_test.go +++ b/libnetwork/libnetwork_test.go @@ -1172,7 +1172,7 @@ func (f *fakeSandbox) Labels() map[string]interface{} { return nil } -func (f *fakeSandbox) Statistics() (map[string]*osl.InterfaceStatistics, error) { +func (f *fakeSandbox) Statistics() (map[string]*types.InterfaceStatistics, error) { return nil, nil } diff --git a/libnetwork/osl/interface_linux.go b/libnetwork/osl/interface_linux.go index 0b0b0d9fa7..d57e7601b1 100644 --- a/libnetwork/osl/interface_linux.go +++ b/libnetwork/osl/interface_linux.go @@ -156,7 +156,7 @@ func (i *nwIface) Remove() error { } // Returns the sandbox's side veth interface statistics -func (i *nwIface) Statistics() (*InterfaceStatistics, error) { +func (i *nwIface) Statistics() (*types.InterfaceStatistics, error) { i.Lock() n := i.ns i.Unlock() @@ -165,7 +165,7 @@ func (i *nwIface) Statistics() (*InterfaceStatistics, error) { path := n.path n.Unlock() - s := &InterfaceStatistics{} + s := &types.InterfaceStatistics{} err := nsInvoke(path, func(nsFD int) error { return nil }, func(callerFD int) error { // For some reason ioutil.ReadFile(netStatsFile) reads the file in @@ -356,7 +356,7 @@ const ( base = "[ ]*%s:([ ]+[0-9]+){16}" ) -func scanInterfaceStats(data, ifName string, i *InterfaceStatistics) error { +func scanInterfaceStats(data, ifName string, i *types.InterfaceStatistics) error { var ( bktStr string bkt uint64 diff --git a/libnetwork/osl/sandbox.go b/libnetwork/osl/sandbox.go index 9e87f472b8..3a824ae6ad 100644 --- a/libnetwork/osl/sandbox.go +++ b/libnetwork/osl/sandbox.go @@ -2,7 +2,6 @@ package osl import ( - "fmt" "net" "github.com/docker/libnetwork/types" @@ -150,22 +149,5 @@ type Interface interface { Remove() error // 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) } diff --git a/libnetwork/osl/sandbox_linux_test.go b/libnetwork/osl/sandbox_linux_test.go index 63eb2156c0..f45b4ba251 100644 --- a/libnetwork/osl/sandbox_linux_test.go +++ b/libnetwork/osl/sandbox_linux_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/docker/libnetwork/netutils" + "github.com/docker/libnetwork/types" "github.com/vishvananda/netlink" "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" + "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 { t.Fatal(err) diff --git a/libnetwork/sandbox.go b/libnetwork/sandbox.go index 40fc7f6de6..9dce262cbb 100644 --- a/libnetwork/sandbox.go +++ b/libnetwork/sandbox.go @@ -28,7 +28,7 @@ type Sandbox interface { // Labels returns the sandbox's labels Labels() map[string]interface{} // 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, // re-joins all the endpoints without destroying the osl sandbox Refresh(options ...SandboxOption) error @@ -126,8 +126,8 @@ func (sb *sandbox) Labels() map[string]interface{} { 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 { return m, nil diff --git a/libnetwork/types/types.go b/libnetwork/types/types.go index 9df1af50b1..64f15e451b 100644 --- a/libnetwork/types/types.go +++ b/libnetwork/types/types.go @@ -278,6 +278,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 ******************************/