diff --git a/hcn/hcn.go b/hcn/hcn.go index 9050d87deb..4b5df009ad 100644 --- a/hcn/hcn.go +++ b/hcn/hcn.go @@ -179,6 +179,15 @@ func AclSupportForProtocol252Supported() error { return platformDoesNotSupportError("HNS ACL Policies to support protocol 252 for VXLAN") } +// SessionAffinitySupported returns an error if the HCN version does not support Session Affinity. +func SessionAffinitySupported() error { + supported := GetSupportedFeatures() + if supported.SessionAffinity { + return nil + } + return platformDoesNotSupportError("Session Affinity") +} + // RequestType are the different operations performed to settings. // Used to update the settings of Endpoint/Namespace objects. type RequestType string diff --git a/hcn/hcnglobals.go b/hcn/hcnglobals.go index 0dc7939992..5852ed9185 100644 --- a/hcn/hcnglobals.go +++ b/hcn/hcnglobals.go @@ -49,6 +49,8 @@ var ( VersionRange{MinVersion: Version{Major: 9, Minor: 3}, MaxVersion: Version{Major: 9, Minor: math.MaxInt32}}, VersionRange{MinVersion: Version{Major: 10, Minor: 4}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}, } + // HNS 11.10 allows for session affinity for loadbalancing + SessionAffinityVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 11, Minor: 10}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}} ) // GetGlobals returns the global properties of the HCN Service. diff --git a/hcn/hcnloadbalancer.go b/hcn/hcnloadbalancer.go index 898e02a801..9ed59a669a 100644 --- a/hcn/hcnloadbalancer.go +++ b/hcn/hcnloadbalancer.go @@ -10,10 +10,11 @@ import ( // LoadBalancerPortMapping is associated with HostComputeLoadBalancer type LoadBalancerPortMapping struct { - Protocol uint32 `json:",omitempty"` // EX: TCP = 6, UDP = 17 - InternalPort uint16 `json:",omitempty"` - ExternalPort uint16 `json:",omitempty"` - Flags LoadBalancerPortMappingFlags `json:",omitempty"` + Protocol uint32 `json:",omitempty"` // EX: TCP = 6, UDP = 17 + InternalPort uint16 `json:",omitempty"` + ExternalPort uint16 `json:",omitempty"` + DistributionType LoadBalancerDistribution `json:",omitempty"` // EX: Distribute per connection = 0, distribute traffic of the same protocol per client IP = 1, distribute per client IP = 2 + Flags LoadBalancerPortMappingFlags `json:",omitempty"` } // HostComputeLoadBalancer represents software load balancer. @@ -53,6 +54,18 @@ var ( LoadBalancerPortMappingFlagsPreserveDIP LoadBalancerPortMappingFlags = 8 ) +// LoadBalancerDistribution specifies how the loadbalancer distributes traffic. +type LoadBalancerDistribution uint32 + +var ( + // LoadBalancerDistributionNone is the default and loadbalances each connection to the same pod. + LoadBalancerDistributionNone LoadBalancerDistribution + // LoadBalancerDistributionSourceIPProtocol loadbalances all traffic of the same protocol from a client IP to the same pod. + LoadBalancerDistributionSourceIPProtocol LoadBalancerDistribution = 1 + // LoadBalancerDistributionSourceIP loadbalances all traffic from a client IP to the same pod. + LoadBalancerDistributionSourceIP LoadBalancerDistribution = 2 +) + func getLoadBalancer(loadBalancerGuid guid.GUID, query string) (*HostComputeLoadBalancer, error) { // Open loadBalancer. var ( diff --git a/hcn/hcnsupport.go b/hcn/hcnsupport.go index 55675bb409..777e0c507a 100644 --- a/hcn/hcnsupport.go +++ b/hcn/hcnsupport.go @@ -13,6 +13,7 @@ type SupportedFeatures struct { DSR bool `json:"DSR"` Slash32EndpointPrefixes bool `json:"Slash32EndpointPrefixes"` AclSupportForProtocol252 bool `json:"AclSupportForProtocol252"` + SessionAffinity bool `json:"SessionAffinity"` } // AclFeatures are the supported ACL possibilities. @@ -57,6 +58,7 @@ func GetSupportedFeatures() SupportedFeatures { features.DSR = isFeatureSupported(globals.Version, DSRVersion) features.Slash32EndpointPrefixes = isFeatureSupported(globals.Version, Slash32EndpointPrefixesVersion) features.AclSupportForProtocol252 = isFeatureSupported(globals.Version, AclSupportForProtocol252Version) + features.SessionAffinity = isFeatureSupported(globals.Version, SessionAffinityVersion) return features } diff --git a/hcn/hcnsupport_test.go b/hcn/hcnsupport_test.go index 1e45fcff1e..d8ac2397c4 100644 --- a/hcn/hcnsupport_test.go +++ b/hcn/hcnsupport_test.go @@ -83,6 +83,17 @@ func TestAclSupportForProtocol252Support(t *testing.T) { } } +func TestSessionAffinitySupport(t *testing.T) { + supportedFeatures := GetSupportedFeatures() + err := SessionAffinitySupported() + if supportedFeatures.SessionAffinity && err != nil { + t.Fatal(err) + } + if !supportedFeatures.SessionAffinity && err == nil { + t.Fatal(err) + } +} + func TestIsFeatureSupported(t *testing.T) { // HNSVersion1803 testing (single range tests) if isFeatureSupported(Version{Major: 0, Minor: 0}, HNSVersion1803) {