Explorar o código

Added maximum egress bandwidth qos for Windows

Signed-off-by: Darren Stahl <darst@microsoft.com>
Darren Stahl %!s(int64=9) %!d(string=hai) anos
pai
achega
5b3524af9f

+ 3 - 0
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"
 )

+ 34 - 0
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,10 +404,15 @@ 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 {

+ 5 - 0
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