Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions hcn/hnsv1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,39 @@ func TestEndpointGetAll(t *testing.T) {
}
}

func TestEndpointStatsAll(t *testing.T) {
network, err := CreateTestNetwork()
if err != nil {
t.Fatal(err)
}

Endpoint := &hcsshim.HNSEndpoint{
Name: NatTestEndpointName,
}

Endpoint, err = network.CreateEndpoint(Endpoint)
if err != nil {
t.Fatal(err)
}

epList, err := hcsshim.HNSListEndpointRequest()
if err != nil {
t.Fatal(err)
}

for _, e := range epList {
_, err := hcsshim.GetHNSEndpointStats(e.Id)
if err != nil {
t.Fatal(err)
}
}

_, err = network.Delete()
if err != nil {
t.Fatal(err)
}
}

func TestNetworkGetAll(t *testing.T) {
_, err := hcsshim.HNSListNetworkRequest("GET", "", "")
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions hnsendpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
// HNSEndpoint represents a network endpoint in HNS
type HNSEndpoint = hns.HNSEndpoint

// HNSEndpointStats represent the stats for an networkendpoint in HNS
type HNSEndpointStats = hns.EndpointStats

// Namespace represents a Compartment.
type Namespace = hns.Namespace

Expand Down Expand Up @@ -108,3 +111,8 @@ func GetHNSEndpointByID(endpointID string) (*HNSEndpoint, error) {
func GetHNSEndpointByName(endpointName string) (*HNSEndpoint, error) {
return hns.GetHNSEndpointByName(endpointName)
}

// GetHNSEndpointStats gets the endpoint stats by ID
func GetHNSEndpointStats(endpointName string) (*HNSEndpointStats, error) {
return hns.GetHNSEndpointStats(endpointName)
}
29 changes: 29 additions & 0 deletions internal/hns/hnsendpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type HNSEndpoint struct {
EnableLowMetric bool `json:",omitempty"`
Namespace *Namespace `json:",omitempty"`
EncapOverhead uint16 `json:",omitempty"`
SharedContainers []string `json:",omitempty"`
}

//SystemType represents the type of the system on which actions are done
Expand Down Expand Up @@ -57,6 +58,18 @@ type EndpointResquestResponse struct {
Error string
}

// EndpointStats is the object that has stats for a given endpoint
type EndpointStats struct {
BytesReceived uint64 `json:"BytesReceived"`
BytesSent uint64 `json:"BytesSent"`
DroppedPacketsIncoming uint64 `json:"DroppedPacketsIncoming"`
DroppedPacketsOutgoing uint64 `json:"DroppedPacketsOutgoing"`
EndpointID string `json:"EndpointId"`
InstanceID string `json:"InstanceId"`
PacketsReceived uint64 `json:"PacketsReceived"`
PacketsSent uint64 `json:"PacketsSent"`
}

// HNSEndpointRequest makes a HNS call to modify/query a network endpoint
func HNSEndpointRequest(method, path, request string) (*HNSEndpoint, error) {
endpoint := &HNSEndpoint{}
Expand All @@ -79,11 +92,27 @@ func HNSListEndpointRequest() ([]HNSEndpoint, error) {
return endpoint, nil
}

// hnsEndpointStatsRequest makes a HNS call to query the stats for a given endpoint ID
func hnsEndpointStatsRequest(id string) (*EndpointStats, error) {
var stats EndpointStats
err := hnsCall("GET", "/endpointstats/"+id, "", &stats)
if err != nil {
return nil, err
}

return &stats, nil
}

// GetHNSEndpointByID get the Endpoint by ID
func GetHNSEndpointByID(endpointID string) (*HNSEndpoint, error) {
return HNSEndpointRequest("GET", endpointID, "")
}

// GetHNSEndpointStats get the stats for a n Endpoint by ID
func GetHNSEndpointStats(endpointID string) (*EndpointStats, error) {
return hnsEndpointStatsRequest(endpointID)
}

// GetHNSEndpointByName gets the endpoint filtered by Name
func GetHNSEndpointByName(endpointName string) (*HNSEndpoint, error) {
hnsResponse, err := HNSListEndpointRequest()
Expand Down