Skip to content

Commit 09745b5

Browse files
Pearl1594nvazquez
andcommitted
Phase4 - Add support for Source NAT, Static NAT and Port Forwarding (#19)
* Run moodifyvxlan script if broadcast domain type is Netris * Add Netris NAT offerings * Add support to add Source nat rules for Natted offering * fix api params while creating Netris source NAT rule * Add support to add and delete source nat rule on netris * Add support to create /32 NAT subnet * Add support to add and delete Static NAT rules in Netris (#23) * Add support to add and delete Static NAT rules in Netris * fix static nat creation on netris & removal of subnet on deletion of static nat rule * remove nat subnet after deltion of the static nat rule * add check to see if subnet already exists and add license header * Add port forwarding rules as DNAT rules in Netris (#24) * Add port forwarding rules as DNAT rules in Netris * Fixes * Allow removing DNAT rules * Fixes * Fix subnet search * Fix update SNAT only for SNAT rules * Address comments * Fix * Fix netris pom xml * Fix SNAT rule creation * Fix IP and port placements (#27) * Fix IP and port placements * fix dnat to IP for PF rules * change dnatport --------- Co-authored-by: Nicolas Vazquez <[email protected]>
1 parent 2fd983c commit 09745b5

File tree

27 files changed

+1434
-510
lines changed

27 files changed

+1434
-510
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.network;
18+
19+
import java.util.List;
20+
21+
public class SDNProviderNetworkRule {
22+
23+
private long domainId;
24+
private long accountId;
25+
private long zoneId;
26+
private Long networkResourceId;
27+
private String networkResourceName;
28+
private boolean isVpcResource;
29+
private long vmId;
30+
private long ruleId;
31+
private String publicIp;
32+
private String vmIp;
33+
private String publicPort;
34+
private String privatePort;
35+
private String protocol;
36+
private String algorithm;
37+
private List<String> sourceCidrList;
38+
private List<String> destinationCidrList;
39+
private Integer icmpCode;
40+
41+
private Integer icmpType;
42+
private String trafficType;
43+
private Network.Service service;
44+
45+
public long getDomainId() {
46+
return domainId;
47+
}
48+
49+
public void setDomainId(long domainId) {
50+
this.domainId = domainId;
51+
}
52+
53+
public long getAccountId() {
54+
return accountId;
55+
}
56+
57+
public void setAccountId(long accountId) {
58+
this.accountId = accountId;
59+
}
60+
61+
public long getZoneId() {
62+
return zoneId;
63+
}
64+
65+
public void setZoneId(long zoneId) {
66+
this.zoneId = zoneId;
67+
}
68+
69+
public Long getNetworkResourceId() {
70+
return networkResourceId;
71+
}
72+
73+
public void setNetworkResourceId(Long networkResourceId) {
74+
this.networkResourceId = networkResourceId;
75+
}
76+
77+
public String getNetworkResourceName() {
78+
return networkResourceName;
79+
}
80+
81+
public void setNetworkResourceName(String networkResourceName) {
82+
this.networkResourceName = networkResourceName;
83+
}
84+
85+
public boolean isVpcResource() {
86+
return isVpcResource;
87+
}
88+
89+
public void setVpcResource(boolean vpcResource) {
90+
isVpcResource = vpcResource;
91+
}
92+
93+
public long getVmId() {
94+
return vmId;
95+
}
96+
97+
public void setVmId(long vmId) {
98+
this.vmId = vmId;
99+
}
100+
101+
public long getRuleId() {
102+
return ruleId;
103+
}
104+
105+
public void setRuleId(long ruleId) {
106+
this.ruleId = ruleId;
107+
}
108+
109+
public String getPublicIp() {
110+
return publicIp;
111+
}
112+
113+
public void setPublicIp(String publicIp) {
114+
this.publicIp = publicIp;
115+
}
116+
117+
public String getVmIp() {
118+
return vmIp;
119+
}
120+
121+
public void setVmIp(String vmIp) {
122+
this.vmIp = vmIp;
123+
}
124+
125+
public String getPublicPort() {
126+
return publicPort;
127+
}
128+
129+
public void setPublicPort(String publicPort) {
130+
this.publicPort = publicPort;
131+
}
132+
133+
public String getPrivatePort() {
134+
return privatePort;
135+
}
136+
137+
public void setPrivatePort(String privatePort) {
138+
this.privatePort = privatePort;
139+
}
140+
141+
public String getProtocol() {
142+
return protocol;
143+
}
144+
145+
public void setProtocol(String protocol) {
146+
this.protocol = protocol;
147+
}
148+
149+
public void setAlgorithm(String algorithm) {
150+
this.algorithm = algorithm;
151+
}
152+
153+
public String getAlgorithm() {
154+
return algorithm;
155+
}
156+
157+
public Network.Service getService() {
158+
return service;
159+
}
160+
161+
public void setService(Network.Service service) {
162+
this.service = service;
163+
}
164+
165+
public Integer getIcmpCode() {
166+
return icmpCode;
167+
}
168+
169+
public void setIcmpCode(Integer icmpCode) {
170+
this.icmpCode = icmpCode;
171+
}
172+
173+
public Integer getIcmpType() {
174+
return icmpType;
175+
}
176+
177+
public void setIcmpType(Integer icmpType) {
178+
this.icmpType = icmpType;
179+
}
180+
181+
public List<String> getSourceCidrList() {
182+
return sourceCidrList;
183+
}
184+
185+
public void setSourceCidrList(List<String> sourceCidrList) {
186+
this.sourceCidrList = sourceCidrList;
187+
}
188+
189+
public List<String> getDestinationCidrList() {
190+
return destinationCidrList;
191+
}
192+
193+
public void setDestinationCidrList(List<String> destinationCidrList) {
194+
this.destinationCidrList = destinationCidrList;
195+
}
196+
197+
public String getTrafficType() {
198+
return trafficType;
199+
}
200+
201+
public void setTrafficType(String trafficType) {
202+
this.trafficType = trafficType;
203+
}
204+
}

api/src/main/java/com/cloud/network/element/PortForwardingServiceProvider.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,40 @@
1717
package com.cloud.network.element;
1818

1919
import java.util.List;
20+
import java.util.Objects;
2021

2122
import com.cloud.exception.ResourceUnavailableException;
2223
import com.cloud.network.Network;
24+
import com.cloud.network.rules.FirewallRule;
2325
import com.cloud.network.rules.PortForwardingRule;
26+
import com.cloud.network.vpc.NetworkACLItem;
2427

2528
public interface PortForwardingServiceProvider extends NetworkElement, IpDeployingRequester {
29+
30+
static String getPublicPortRange(PortForwardingRule rule) {
31+
return Objects.equals(rule.getSourcePortStart(), rule.getSourcePortEnd()) ?
32+
String.valueOf(rule.getSourcePortStart()) :
33+
String.valueOf(rule.getSourcePortStart()).concat("-").concat(String.valueOf(rule.getSourcePortEnd()));
34+
}
35+
36+
static String getPrivatePFPortRange(PortForwardingRule rule) {
37+
return rule.getDestinationPortStart() == rule.getDestinationPortEnd() ?
38+
String.valueOf(rule.getDestinationPortStart()) :
39+
String.valueOf(rule.getDestinationPortStart()).concat("-").concat(String.valueOf(rule.getDestinationPortEnd()));
40+
}
41+
42+
static String getPrivatePortRange(FirewallRule rule) {
43+
return Objects.equals(rule.getSourcePortStart(), rule.getSourcePortEnd()) ?
44+
String.valueOf(rule.getSourcePortStart()) :
45+
String.valueOf(rule.getSourcePortStart()).concat("-").concat(String.valueOf(rule.getSourcePortEnd()));
46+
}
47+
48+
static String getPrivatePortRangeForACLRule(NetworkACLItem rule) {
49+
return Objects.equals(rule.getSourcePortStart(), rule.getSourcePortEnd()) ?
50+
String.valueOf(rule.getSourcePortStart()) :
51+
String.valueOf(rule.getSourcePortStart()).concat("-").concat(String.valueOf(rule.getSourcePortEnd()));
52+
}
53+
2654
/**
2755
* Apply rules
2856
* @param network

api/src/main/java/com/cloud/network/netris/NetrisService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@
1616
// under the License.
1717
package com.cloud.network.netris;
1818

19+
import com.cloud.network.IpAddress;
20+
import com.cloud.network.SDNProviderNetworkRule;
1921
import com.cloud.network.vpc.Vpc;
2022

2123
public interface NetrisService {
2224
boolean createVpcResource(long zoneId, long accountId, long domainId, Long vpcId, String vpcName, boolean sourceNatEnabled, String cidr, boolean isVpcNetwork);
2325
boolean deleteVpcResource(long zoneId, long accountId, long domainId, Vpc vpc);
2426
boolean createVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr);
2527
boolean deleteVnetResource(long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr);
28+
boolean createSnatRule(long zoneId, long accountId, long domainId, String vpcName, long vpcId, String networkName, long networkId, boolean isForVpc, String vpcCidr, String sourceNatIp);
29+
boolean createPortForwardingRule(long zoneId, long accountId, long domainId, String vpcName, long vpcId, String networkName, Long networkId, boolean isForVpc, String vpcCidr, SDNProviderNetworkRule networkRule);
30+
boolean deletePortForwardingRule(long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, boolean isForVpc, String vpcCidr, SDNProviderNetworkRule networkRule);
31+
boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address);
32+
boolean createStaticNatRule(long zoneId, long accountId, long domainId, String networkResourceName, Long networkResourceId, boolean isForVpc, String vpcCidr, String staticNatIp, String vmIp);
33+
boolean deleteStaticNatRule(long zoneId, long accountId, long domainId, String networkResourceName, Long networkResourceId, boolean isForVpc, String staticNatIp);
2634
}

api/src/main/java/com/cloud/network/vpc/VpcOffering.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public enum State {
3333
public static final String DEFAULT_VPC_NAT_NSX_OFFERING_NAME = "VPC offering with NSX - NAT Mode";
3434
public static final String DEFAULT_VPC_ROUTE_NSX_OFFERING_NAME = "VPC offering with NSX - Route Mode";
3535
public static final String DEFAULT_VPC_ROUTE_NETRIS_OFFERING_NAME = "VPC offering with Netris - Route Mode";
36+
public static final String DEFAULT_VPC_NAT_NETRIS_OFFERING_NAME = "VPC offering with Netris - NAT Mode";
3637

3738
/**
3839
*

api/src/main/java/com/cloud/offering/NetworkOffering.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ enum RoutingMode {
6565
public static final String DEFAULT_NAT_NSX_OFFERING_FOR_VPC_WITH_ILB = "DefaultNATNSXNetworkOfferingForVpcWithInternalLB";
6666
public static final String DEFAULT_ROUTED_NSX_OFFERING_FOR_VPC = "DefaultRoutedNSXNetworkOfferingForVpc";
6767
public static final String DEFAULT_ROUTED_NETRIS_OFFERING_FOR_VPC = "DefaultRoutedNetrisNetworkOfferingForVpc";
68+
public static final String DEFAULT_NAT_NETRIS_OFFERING_FOR_VPC = "DefaultNATNetrisNetworkOfferingForVpc";
6869
public static final String DEFAULT_NAT_NSX_OFFERING = "DefaultNATNSXNetworkOffering";
6970
public static final String DEFAULT_ROUTED_NSX_OFFERING = "DefaultRoutedNSXNetworkOffering";
7071
public final static String QuickCloudNoServices = "QuickCloudNoServices";

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,27 +561,27 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
561561
if (_networkOfferingDao.findByUniqueName(NetworkOffering.QuickCloudNoServices) == null) {
562562
offering = _configMgr.createNetworkOffering(NetworkOffering.QuickCloudNoServices, "Offering for QuickCloud with no services", TrafficType.Guest, null, true,
563563
Availability.Optional, null, new HashMap<Network.Service, Set<Network.Provider>>(), true, Network.GuestType.Shared, false, null, true, null, true,
564-
false, null, false, null, true, false, false, false, null, null, null, true, null, null, false);
564+
false, null, false, null, true, false, false, false, false,null, null, null, true, null, null, false);
565565
}
566566

567567
//#2 - SG enabled network offering
568568
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOfferingWithSGService) == null) {
569569
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks",
570570
TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true,
571-
null, true, false, null, false, null, true, false, false, false, null, null, null, true, null, null, false);
571+
null, true, false, null, false, null, true, false, false, false, false,null, null, null, true, null, null, false);
572572
}
573573

574574
//#3 - shared network offering with no SG service
575575
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) {
576576
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true,
577577
Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false, null, false,
578-
null, true, false, false, false, null,null, null, true, null, null, false);
578+
null, true, false, false, false, false,null,null, null, true, null, null, false);
579579
}
580580

581581
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DEFAULT_TUNGSTEN_SHARED_NETWORK_OFFERING_WITH_SGSERVICE) == null) {
582582
offering = _configMgr.createNetworkOffering(NetworkOffering.DEFAULT_TUNGSTEN_SHARED_NETWORK_OFFERING_WITH_SGSERVICE, "Offering for Tungsten Shared Security group enabled networks",
583583
TrafficType.Guest, null, true, Availability.Optional, null, defaultTungstenSharedSGEnabledNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true,
584-
null, true, false, null, false, null, true, false, true, false, null, null,null, true, null, null, false);
584+
null, true, false, null, false, null, true, false, true, false, false,null, null,null, true, null, null, false);
585585
offering.setState(NetworkOffering.State.Enabled);
586586
_networkOfferingDao.update(offering.getId(), offering);
587587
}
@@ -591,14 +591,14 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
591591
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService,
592592
"Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Required, null,
593593
defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false, false, null, false, null,
594-
true, false, false, false, null, null,null, true, null, null, false);
594+
true, false, false, false, false,null, null,null, true, null, null, false);
595595
}
596596

597597
//#5 - default vpc offering with LB service
598598
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks) == null) {
599599
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks,
600600
"Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Optional, null,
601-
defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, false, null, null, null,true, null, null, false);
601+
defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, false, false,null, null, null,true, null, null, false);
602602
}
603603

604604
//#6 - default vpc offering with no LB service
@@ -607,14 +607,14 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
607607
defaultVPCOffProviders.remove(Service.Lb);
608608
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB,
609609
"Offering for Isolated VPC networks with Source Nat service enabled and LB service disabled", TrafficType.Guest, null, false, Availability.Optional,
610-
null, defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, false, null, null, null,true, null, null, false);
610+
null, defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, false, false,null, null, null,true, null, null, false);
611611
}
612612

613613
//#7 - isolated offering with source nat disabled
614614
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) {
615615
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service",
616616
TrafficType.Guest, null, true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null,
617-
true, null, true, false, null, false, null, true, false, false, false, null, null, null, true, null, null, false);
617+
true, null, true, false, null, false, null, true, false, false, false, false,null, null, null, true, null, null, false);
618618
}
619619

620620
//#8 - network offering with internal lb service
@@ -636,7 +636,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
636636
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB) == null) {
637637
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB,
638638
"Offering for Isolated VPC networks with Internal Lb support", TrafficType.Guest, null, false, Availability.Optional, null, internalLbOffProviders,
639-
true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, false, null, null, null, true, null, null, false);
639+
true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, false, false,null, null, null, true, null, null, false);
640640
offering.setInternalLb(true);
641641
offering.setPublicLb(false);
642642
_networkOfferingDao.update(offering.getId(), offering);
@@ -667,7 +667,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
667667
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) {
668668
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering,
669669
"Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true, Availability.Optional, null,
670-
netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false, null, false, null, true, false, false, false, null, null, null, true, null, null, false);
670+
netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false, null, false, null, true, false, false, false,false, null, null, null, true, null, null, false);
671671
offering.setDedicatedLB(false);
672672
_networkOfferingDao.update(offering.getId(), offering);
673673
}

0 commit comments

Comments
 (0)