Skip to content

Commit 54eb6b8

Browse files
[AdvancedNetworkPolicy] MOC-SDK Changes for LNET and NIC (#332)
* Add support for sdn-optionality * Add missing inboundnatrule parsing * Update moc commit hash * add policy to lnet * Update go mod * Fix nil ptr issue * Update moc commit * Update moc commit * Update moc commit * Update moc release tag --------- Co-authored-by: NIJOS <nijos@microsoft.com>
1 parent 7f2fe3b commit 54eb6b8

File tree

8 files changed

+105
-6
lines changed

8 files changed

+105
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/Azure/go-autorest/autorest/date v0.3.0
99
github.com/google/go-cmp v0.6.0
1010
github.com/google/uuid v1.6.0
11-
github.com/microsoft/moc v0.35.1
11+
github.com/microsoft/moc v0.35.2
1212
google.golang.org/grpc v1.72.0
1313
k8s.io/klog v1.0.0
1414
sigs.k8s.io/controller-runtime v0.20.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
122122
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
123123
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
124124
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
125-
github.com/microsoft/moc v0.35.1 h1:Vy+VlRlVb56bl7trYJ2BsQUeOMZo7LUY12/Ml8KbrKE=
126-
github.com/microsoft/moc v0.35.1/go.mod h1:OZ1rc2/qs9AVRKCLfwY0N8R+ZXJlVz5UyWYS5vNH4m0=
125+
github.com/microsoft/moc v0.35.2 h1:/P/yuGmSWwEtmKHIgak4YiqkCt9MvLTe3ggJ/eDb/yA=
126+
github.com/microsoft/moc v0.35.2/go.mod h1:OZ1rc2/qs9AVRKCLfwY0N8R+ZXJlVz5UyWYS5vNH4m0=
127127
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
128128
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
129129
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

services/compute/virtualmachine/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,4 @@ func (c *VirtualMachineClient) GetHostNodeName(ctx context.Context, group string
410410

411411
func (c *VirtualMachineClient) GetHostNodeIpAddress(ctx context.Context, group string, name string) (*compute.VirtualMachineHostNodeIpAddress, error) {
412412
return c.internal.GetHostNodeIpAddress(ctx, group, name)
413-
}
413+
}

services/compute/virtualmachine/wssd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,4 @@ func (c *client) GetHostNodeIpAddress(ctx context.Context, group, name string) (
473473
}
474474

475475
return response, nil
476-
}
476+
}

services/network/common.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package network
2+
3+
import (
4+
wssdcommonproto "github.com/microsoft/moc/rpc/common"
5+
)
6+
7+
// Returns cloudagent representation of AdvancedNetworkPolicy from sdk representation
8+
func GetWssdAdvancedNetworkPolicies(policies *[]AdvancedNetworkPolicy) (wssdPolicies []*wssdcommonproto.AdvancedNetworkPolicy) {
9+
10+
if policies == nil || len(*policies) == 0 {
11+
return nil
12+
}
13+
14+
wssdPolicies = []*wssdcommonproto.AdvancedNetworkPolicy{}
15+
16+
for _, policy := range *policies {
17+
wssdPolicy := &wssdcommonproto.AdvancedNetworkPolicy{
18+
Type: getWssdPolicyType(policy.Type),
19+
Enabled: policy.Enabled,
20+
}
21+
wssdPolicies = append(wssdPolicies, wssdPolicy)
22+
}
23+
return wssdPolicies
24+
}
25+
26+
// Returns sdk representation of AdvancedNetworkPolicy from cloudagent representation
27+
func GetNetworkAdvancedNetworkPolicies(wssdPolicies []*wssdcommonproto.AdvancedNetworkPolicy) (policies []AdvancedNetworkPolicy) {
28+
29+
if len(wssdPolicies) == 0 {
30+
return nil
31+
}
32+
33+
policies = []AdvancedNetworkPolicy{}
34+
35+
for _, wssdPolicy := range wssdPolicies {
36+
policy := AdvancedNetworkPolicy{
37+
Type: getNetworkPolicyType(wssdPolicy.Type),
38+
Enabled: wssdPolicy.Enabled,
39+
}
40+
policies = append(policies, policy)
41+
}
42+
return policies
43+
}
44+
45+
// Converts policy type from sdk to cloudagent representation
46+
func getWssdPolicyType(policyType NetworkPolicyType) wssdcommonproto.NetworkPolicyType {
47+
switch policyType {
48+
case NetworkPolicyType_SDN:
49+
return wssdcommonproto.NetworkPolicyType_SDN
50+
default:
51+
return wssdcommonproto.NetworkPolicyType_INVALID
52+
}
53+
}
54+
55+
// Converts policy type from cloudagent to sdk representation
56+
func getNetworkPolicyType(wssdPolicyType wssdcommonproto.NetworkPolicyType) NetworkPolicyType {
57+
switch wssdPolicyType {
58+
case wssdcommonproto.NetworkPolicyType_SDN:
59+
return NetworkPolicyType_SDN
60+
default:
61+
return NetworkPolicyType_Invalid
62+
}
63+
}

services/network/logicalnetwork/logicalnetwork.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func getWssdLogicalNetwork(c *network.LogicalNetwork) (*wssdcloudnetwork.Logical
2121
if c.Location == nil || len(*c.Location) == 0 {
2222
return nil, errors.Wrapf(errors.InvalidInput, "Location is not specified")
2323
}
24+
2425
wssdnetwork := &wssdcloudnetwork.LogicalNetwork{
2526
Name: *c.Name,
2627
LocationName: *c.Location,
@@ -48,6 +49,10 @@ func getWssdLogicalNetwork(c *network.LogicalNetwork) (*wssdcloudnetwork.Logical
4849
if c.LogicalNetworkPropertiesFormat.NetworkVirtualizationEnabled != nil {
4950
wssdnetwork.NetworkVirtualizationEnabled = *c.LogicalNetworkPropertiesFormat.NetworkVirtualizationEnabled
5051
}
52+
53+
if c.LogicalNetworkPropertiesFormat.AdvancedNetworkPolicies != nil {
54+
wssdnetwork.AdvancedPolicies = network.GetWssdAdvancedNetworkPolicies(c.LogicalNetworkPropertiesFormat.AdvancedNetworkPolicies)
55+
}
5156
}
5257

5358
return wssdnetwork, nil
@@ -187,7 +192,10 @@ func getWssdNetworkRoutes(routetable *network.RouteTable) (wssdcloudroutes []*ws
187192

188193
// Conversion function from wssdcloudnetwork to network
189194
func getLogicalNetwork(c *wssdcloudnetwork.LogicalNetwork) *network.LogicalNetwork {
190-
return &network.LogicalNetwork{
195+
196+
advancedPolicies := network.GetNetworkAdvancedNetworkPolicies(c.AdvancedPolicies)
197+
198+
lnet := &network.LogicalNetwork{
191199
Name: &c.Name,
192200
Location: &c.LocationName,
193201
ID: &c.Id,
@@ -197,9 +205,13 @@ func getLogicalNetwork(c *wssdcloudnetwork.LogicalNetwork) *network.LogicalNetwo
197205
Statuses: status.GetStatuses(c.GetStatus()),
198206
MacPoolName: &c.MacPoolName,
199207
NetworkVirtualizationEnabled: &c.NetworkVirtualizationEnabled,
208+
AdvancedNetworkPolicies: &advancedPolicies,
200209
},
201210
Tags: tags.ProtoToMap(c.Tags),
202211
}
212+
213+
return lnet
214+
203215
}
204216

205217
func getNetworkSubnets(wssdsubnets []*wssdcloudnetwork.LogicalSubnet) *[]network.LogicalSubnet {

services/network/network.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,22 @@ type PrivateEndpoint struct {
893893
Tags map[string]*string `json:"tags"`
894894
}
895895

896+
type NetworkPolicyType string
897+
898+
const (
899+
NetworkPolicyType_Invalid NetworkPolicyType = "INVALID"
900+
// SDN Policy
901+
NetworkPolicyType_SDN NetworkPolicyType = "SDN"
902+
)
903+
904+
// Advanced Network Policy for LogicalNetwork and NetworkInterface
905+
type AdvancedNetworkPolicy struct {
906+
// NetworkPolicyType
907+
Type NetworkPolicyType `json:"type"`
908+
// Enabled - Enable or disable advanced network policy
909+
Enabled bool `json:"enabled"`
910+
}
911+
896912
// InterfacePropertiesFormat networkInterface properties.
897913
type InterfacePropertiesFormat struct {
898914
// VirtualMachine - READ-ONLY; The reference of a virtual machine.
@@ -921,6 +937,8 @@ type InterfacePropertiesFormat struct {
921937
EnableDHCPGuard *bool `json:"enableDHCPGuard,omitempty"`
922938
// EnableRouterAdvertisementGuard
923939
EnableRouterAdvertisementGuard *bool `json:"enableRouterAdvertisementGuard,omitempty"`
940+
// AdvancedNetworkPolicies
941+
AdvancedNetworkPolicies *[]AdvancedNetworkPolicy `json:"advancedNetworkPolicies,omitempty"`
924942
}
925943

926944
// VirtualNetwork defines the structure of a VNET
@@ -1098,6 +1116,8 @@ type LogicalNetworkPropertiesFormat struct {
10981116
Statuses map[string]*string `json:"statuses"`
10991117
// NetworkVirtualizationEnabled - Denotes if this lnet can be used as overlay for a vnet
11001118
NetworkVirtualizationEnabled *bool `json:"networkVirtualizationEnabled,omitempty"`
1119+
// AdvancedNetworkPolicies
1120+
AdvancedNetworkPolicies *[]AdvancedNetworkPolicy `json:"advancedNetworkPolicies,omitempty"`
11011121
}
11021122

11031123
// LogicalNetwork defines the structure of an LNET

services/network/networkinterface/networkinterface.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func getWssdNetworkInterface(c *network.Interface, group string) (*wssdcloudnetw
5252
GroupName: group,
5353
Dns: getDns(c.DNSSettings),
5454
Tags: tags.MapToProto(c.Tags),
55+
AdvancedPolicies: network.GetWssdAdvancedNetworkPolicies(c.AdvancedNetworkPolicies),
5556
}
5657

5758
if c.Version != nil {
@@ -191,6 +192,8 @@ func getNetworkInterface(server, group string, c *wssdcloudnetwork.NetworkInterf
191192
version = c.Status.Version.Number
192193
}
193194

195+
advancedPolicies := network.GetNetworkAdvancedNetworkPolicies(c.AdvancedPolicies)
196+
194197
vnetIntf := &network.Interface{
195198
Name: &c.Name,
196199
ID: &c.Id,
@@ -202,6 +205,7 @@ func getNetworkInterface(server, group string, c *wssdcloudnetwork.NetworkInterf
202205
Statuses: status.GetStatuses(c.GetStatus()),
203206
EnableAcceleratedNetworking: getIovSetting(c),
204207
DNSSettings: getWssdDNSSettings(c.Dns),
208+
AdvancedNetworkPolicies: &advancedPolicies,
205209
},
206210
Tags: tags.ProtoToMap(c.Tags),
207211
}

0 commit comments

Comments
 (0)