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
9 changes: 9 additions & 0 deletions hcn/hcn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions hcn/hcnglobals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 17 additions & 4 deletions hcn/hcnloadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions hcn/hcnsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 11 additions & 0 deletions hcn/hcnsupport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down