diff --git a/libnetwork/drivers/windows/labels.go b/libnetwork/drivers/windows/labels.go index bfc4d368cc..f1b77bf334 100644 --- a/libnetwork/drivers/windows/labels.go +++ b/libnetwork/drivers/windows/labels.go @@ -12,4 +12,7 @@ const ( // Interface of the network Interface = "com.docker.network.windowsshim.interface" + + // QosPolicies of the endpoint + QosPolicies = "com.docker.endpoint.windowsshim.qospolicies" ) diff --git a/libnetwork/drivers/windows/windows.go b/libnetwork/drivers/windows/windows.go index c3a478523e..95467a8615 100644 --- a/libnetwork/drivers/windows/windows.go +++ b/libnetwork/drivers/windows/windows.go @@ -42,6 +42,7 @@ type endpointConfiguration struct { MacAddress net.HardwareAddr PortBindings []types.PortBinding ExposedPorts []types.TransportPort + QosPolicies []types.QosPolicy } type hnsEndpoint struct { @@ -257,6 +258,26 @@ func (d *driver) DeleteNetwork(nid string) error { return nil } +func convertQosPolicies(qosPolicies []types.QosPolicy) ([]json.RawMessage, error) { + var qps []json.RawMessage + + // Enumerate through the qos policies specified by the user and convert + // them into the internal structure matching the JSON blob that can be + // understood by the HCS. + for _, elem := range qosPolicies { + encodedPolicy, err := json.Marshal(hcsshim.QosPolicy{ + Type: "QOS", + MaximumOutgoingBandwidthInBytes: elem.MaxEgressBandwidth, + }) + + if err != nil { + return nil, err + } + qps = append(qps, encodedPolicy) + } + return qps, nil +} + func convertPortBindings(portBindings []types.PortBinding) ([]json.RawMessage, error) { var pbs []json.RawMessage @@ -347,6 +368,14 @@ func parseEndpointOptions(epOptions map[string]interface{}) (*endpointConfigurat } } + if opt, ok := epOptions[QosPolicies]; ok { + if policies, ok := opt.([]types.QosPolicy); ok { + ec.QosPolicies = policies + } else { + return nil, fmt.Errorf("Invalid endpoint configuration") + } + } + return ec, nil } @@ -375,11 +404,16 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, } endpointStruct.Policies, err = convertPortBindings(ec.PortBindings) - if err != nil { return err } + qosPolicies, err := convertQosPolicies(ec.QosPolicies) + if err != nil { + return err + } + endpointStruct.Policies = append(endpointStruct.Policies, qosPolicies...) + configurationb, err := json.Marshal(endpointStruct) if err != nil { return err diff --git a/libnetwork/types/types.go b/libnetwork/types/types.go index 44ee563e69..28d33cacf5 100644 --- a/libnetwork/types/types.go +++ b/libnetwork/types/types.go @@ -12,6 +12,11 @@ import ( // UUID represents a globally unique ID of various resources like network and endpoint type UUID string +// QosPolicy represents a quality of service policy on an endpoint +type QosPolicy struct { + MaxEgressBandwidth uint64 +} + // TransportPort represent a local Layer 4 endpoint type TransportPort struct { Proto Protocol