diff --git a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
index e2d4d2798a4..8ea514b1f26 100644
--- a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
+++ b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
@@ -182,6 +182,10 @@
+
+
diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java
index be8c867ba9c..552d4211250 100755
--- a/server/src/com/cloud/network/element/VirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VirtualRouterElement.java
@@ -16,6 +16,23 @@
// under the License.
package com.cloud.network.element;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.command.admin.router.ConfigureOvsElementCmd;
+import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
+import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElementCmd;
+import org.apache.cloudstack.api.command.admin.router.ListOvsElementsCmd;
+import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.log4j.Logger;
+
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.DataCenter;
@@ -62,6 +79,7 @@ import com.cloud.network.rules.LoadBalancerContainer;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.network.rules.RulesManager;
import com.cloud.network.rules.StaticNat;
+import com.cloud.network.rules.VirtualNetworkApplianceFactory;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
@@ -85,21 +103,6 @@ import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.UserVmDao;
import com.google.gson.Gson;
-import org.apache.cloudstack.api.command.admin.router.ConfigureOvsElementCmd;
-import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
-import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElementCmd;
-import org.apache.cloudstack.api.command.admin.router.ListOvsElementsCmd;
-import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
-import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-import org.apache.log4j.Logger;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
@Local(value = {NetworkElement.class, FirewallServiceProvider.class,
DhcpServiceProvider.class, UserDataServiceProvider.class,
@@ -150,8 +153,10 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
OvsProviderDao _ovsProviderDao;
@Inject
IPAddressDao _ipAddressDao;
+ @Inject
+ protected VirtualNetworkApplianceFactory virtualNetworkApplianceFactory;
- protected boolean canHandle(Network network, Service service) {
+ protected boolean canHandle(final Network network, final Service service) {
Long physicalNetworkId = _networkMdl.getPhysicalNetworkId(network);
if (physicalNetworkId == null) {
return false;
@@ -181,7 +186,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException,
+ public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ResourceUnavailableException,
ConcurrentOperationException, InsufficientCapacityException {
if (offering.isSystemOnly()) {
@@ -198,7 +203,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
if (offering.getRedundantRouter()) {
routerCounts = 2;
}
- if ((routers == null) || (routers.size() < routerCounts)) {
+ if (routers == null || routers.size() < routerCounts) {
throw new ResourceUnavailableException("Can't find all necessary running routers!",
DataCenter.class, network.getDataCenterId());
}
@@ -207,7 +212,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
+ public boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (vm.getType() != VirtualMachine.Type.User || vm.getHypervisorType() == HypervisorType.BareMetal) {
return false;
@@ -230,14 +235,14 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
List routers =
_routerMgr.deployVirtualRouterInGuestNetwork(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(),
offering.getRedundantRouter());
- if ((routers == null) || (routers.size() == 0)) {
+ if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
}
return true;
}
@Override
- public boolean applyFWRules(Network config, List extends FirewallRule> rules) throws ResourceUnavailableException {
+ public boolean applyFWRules(final Network config, final List extends FirewallRule> rules) throws ResourceUnavailableException {
if (canHandle(config, Service.Firewall)) {
List routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
@@ -249,8 +254,9 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
if (rules != null && rules.size() == 1) {
// for VR no need to add default egress rule to DENY traffic
if (rules.get(0).getTrafficType() == FirewallRule.TrafficType.Egress && rules.get(0).getType() == FirewallRule.FirewallRuleType.System &&
- !_networkMdl.getNetworkEgressDefaultPolicy(config.getId()))
+ !_networkMdl.getNetworkEgressDefaultPolicy(config.getId())) {
return true;
+ }
}
if (!_routerMgr.applyFirewallRules(config, rules, routers)) {
@@ -268,15 +274,18 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
* number like 12 2) time or tablesize like 12h, 34m, 45k, 54m , here
* last character is non-digit but from known characters .
*/
- private static boolean containsOnlyNumbers(String str, String endChar) {
- if (str == null)
+ private static boolean containsOnlyNumbers(final String str, final String endChar) {
+ if (str == null) {
return false;
+ }
String number = str;
if (endChar != null) {
boolean matchedEndChar = false;
if (str.length() < 2)
+ {
return false; // atleast one numeric and one char. example:
+ }
// 3h
char strEnd = str.toCharArray()[str.length() - 1];
for (char c : endChar.toCharArray()) {
@@ -286,8 +295,9 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
break;
}
}
- if (!matchedEndChar)
+ if (!matchedEndChar) {
return false;
+ }
}
try {
Integer.parseInt(number);
@@ -297,7 +307,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
return true;
}
- public static boolean validateHAProxyLBRule(LoadBalancingRule rule) {
+ public static boolean validateHAProxyLBRule(final LoadBalancingRule rule) {
String timeEndChar = "dhms";
if (rule.getSourcePortStart() == NetUtils.HAPROXY_STATS_PORT) {
@@ -318,15 +328,17 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
for (Pair paramKV : paramsList) {
String key = paramKV.first();
String value = paramKV.second();
- if ("tablesize".equalsIgnoreCase(key))
+ if ("tablesize".equalsIgnoreCase(key)) {
tablesize = value;
- if ("expire".equalsIgnoreCase(key))
+ }
+ if ("expire".equalsIgnoreCase(key)) {
expire = value;
+ }
}
- if ((expire != null) && !containsOnlyNumbers(expire, timeEndChar)) {
+ if (expire != null && !containsOnlyNumbers(expire, timeEndChar)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: expire is not in timeformat: " + expire);
}
- if ((tablesize != null) && !containsOnlyNumbers(tablesize, "kmg")) {
+ if (tablesize != null && !containsOnlyNumbers(tablesize, "kmg")) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: tablesize is not in size format: " + tablesize);
}
@@ -337,16 +349,18 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
for (Pair paramKV : paramsList) {
String key = paramKV.first();
String value = paramKV.second();
- if ("length".equalsIgnoreCase(key))
+ if ("length".equalsIgnoreCase(key)) {
length = value;
- if ("holdtime".equalsIgnoreCase(key))
+ }
+ if ("holdtime".equalsIgnoreCase(key)) {
holdTime = value;
+ }
}
- if ((length != null) && (!containsOnlyNumbers(length, null))) {
+ if (length != null && !containsOnlyNumbers(length, null)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: length is not a number: " + length);
}
- if ((holdTime != null) && (!containsOnlyNumbers(holdTime, timeEndChar) && !containsOnlyNumbers(holdTime, null))) {
+ if (holdTime != null && !containsOnlyNumbers(holdTime, timeEndChar) && !containsOnlyNumbers(holdTime, null)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: holdtime is not in timeformat: " + holdTime);
}
}
@@ -355,7 +369,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean validateLBRule(Network network, LoadBalancingRule rule) {
+ public boolean validateLBRule(final Network network, final LoadBalancingRule rule) {
List rules = new ArrayList();
rules.add(rule);
if (canHandle(network, Service.Lb) && canHandleLbRules(rules)) {
@@ -369,7 +383,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean applyLBRules(Network network, List rules) throws ResourceUnavailableException {
+ public boolean applyLBRules(final Network network, final List rules) throws ResourceUnavailableException {
if (canHandle(network, Service.Lb)) {
if (!canHandleLbRules(rules)) {
return false;
@@ -392,7 +406,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public String[] applyVpnUsers(RemoteAccessVpn vpn, List extends VpnUser> users) throws ResourceUnavailableException {
+ public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List extends VpnUser> users) throws ResourceUnavailableException {
if (vpn.getNetworkId() == null) {
return null;
}
@@ -413,7 +427,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean startVpn(RemoteAccessVpn vpn) throws ResourceUnavailableException {
+ public boolean startVpn(final RemoteAccessVpn vpn) throws ResourceUnavailableException {
if (vpn.getNetworkId() == null) {
return false;
}
@@ -433,7 +447,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean stopVpn(RemoteAccessVpn vpn) throws ResourceUnavailableException {
+ public boolean stopVpn(final RemoteAccessVpn vpn) throws ResourceUnavailableException {
if (vpn.getNetworkId() == null) {
return false;
}
@@ -453,7 +467,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean applyIps(Network network, List extends PublicIpAddress> ipAddress, Set services) throws ResourceUnavailableException {
+ public boolean applyIps(final Network network, final List extends PublicIpAddress> ipAddress, final Set services) throws ResourceUnavailableException {
boolean canHandle = true;
for (Service service : services) {
if (!canHandle(network, service)) {
@@ -616,7 +630,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean applyStaticNats(Network config, List extends StaticNat> rules) throws ResourceUnavailableException {
+ public boolean applyStaticNats(final Network config, final List extends StaticNat> rules) throws ResourceUnavailableException {
if (canHandle(config, Service.StaticNat)) {
List routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
@@ -632,7 +646,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
+ public boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
return true;
@@ -644,7 +658,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
if (!result) {
s_logger.warn("Failed to stop virtual router element " + router + ", but would try to process clean up anyway.");
}
- result = (_routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null);
+ result = _routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null;
if (!result) {
s_logger.warn("Failed to clean up virtual router element " + router);
}
@@ -654,7 +668,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean destroy(Network config, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
+ public boolean destroy(final Network config, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
List routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
return true;
@@ -664,13 +678,13 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
// not caller account
Account callerAccount = _accountMgr.getAccount(context.getCaller().getAccountId());
for (DomainRouterVO router : routers) {
- result = result && (_routerMgr.destroyRouter(router.getId(), callerAccount, context.getCaller().getId()) != null);
+ result = result && _routerMgr.destroyRouter(router.getId(), callerAccount, context.getCaller().getId()) != null;
}
return result;
}
@Override
- public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException {
+ public boolean savePassword(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException {
if (!canHandle(network, null)) {
return false;
}
@@ -703,7 +717,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile vm, String sshPublicKey) throws ResourceUnavailableException {
+ public boolean saveSSHKey(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final String sshPublicKey) throws ResourceUnavailableException {
if (!canHandle(network, null)) {
return false;
}
@@ -720,7 +734,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException {
+ public boolean saveUserData(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException {
if (!canHandle(network, null)) {
return false;
}
@@ -746,7 +760,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public VirtualRouterProvider configure(ConfigureVirtualRouterElementCmd cmd) {
+ public VirtualRouterProvider configure(final ConfigureVirtualRouterElementCmd cmd) {
VirtualRouterProviderVO element = _vrProviderDao.findById(cmd.getId());
if (element == null || !(element.getType() == Type.VirtualRouter || element.getType() == Type.VPCVirtualRouter)) {
s_logger.debug("Can't find Virtual Router element with network service provider id " + cmd.getId());
@@ -760,7 +774,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public OvsProvider configure(ConfigureOvsElementCmd cmd) {
+ public OvsProvider configure(final ConfigureOvsElementCmd cmd) {
OvsProviderVO element = _ovsProviderDao.findById(cmd.getId());
if (element == null) {
s_logger.debug("Can't find Ovs element with network service provider id "
@@ -775,7 +789,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public VirtualRouterProvider addElement(Long nspId, Type providerType) {
+ public VirtualRouterProvider addElement(final Long nspId, final Type providerType) {
if (!(providerType == Type.VirtualRouter || providerType == Type.VPCVirtualRouter)) {
throw new InvalidParameterValueException("Element " + getName() + " supports only providerTypes: " + Type.VirtualRouter.toString() + " and " +
Type.VPCVirtualRouter);
@@ -791,7 +805,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean applyPFRules(Network network, List rules) throws ResourceUnavailableException {
+ public boolean applyPFRules(final Network network, final List rules) throws ResourceUnavailableException {
if (canHandle(network, Service.PortForwarding)) {
List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
@@ -811,7 +825,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean isReady(PhysicalNetworkServiceProvider provider) {
+ public boolean isReady(final PhysicalNetworkServiceProvider provider) {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), getVirtualRouterProvider());
if (element == null) {
return false;
@@ -820,7 +834,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException,
+ public boolean shutdownProviderInstances(final PhysicalNetworkServiceProvider provider, final ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), getVirtualRouterProvider());
if (element == null) {
@@ -831,7 +845,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
List routers = _routerDao.listByElementId(elementId);
boolean result = true;
for (DomainRouterVO router : routers) {
- result = result && (_routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null);
+ result = result && _routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null;
}
_vrProviderDao.remove(elementId);
@@ -843,13 +857,13 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
return true;
}
- public Long getIdByNspId(Long nspId) {
+ public Long getIdByNspId(final Long nspId) {
VirtualRouterProviderVO vr = _vrProviderDao.findByNspIdAndType(nspId, Type.VirtualRouter);
return vr.getId();
}
@Override
- public VirtualRouterProvider getCreatedElement(long id) {
+ public VirtualRouterProvider getCreatedElement(final long id) {
VirtualRouterProvider provider = _vrProviderDao.findById(id);
if (!(provider.getType() == Type.VirtualRouter || provider.getType() == Type.VPCVirtualRouter)) {
throw new InvalidParameterValueException("Unable to find provider by id");
@@ -858,13 +872,13 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException,
+ public boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException {
return true;
}
@Override
- public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
+ public boolean configDhcpSupportForSubnet(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(network, Service.Dhcp)) {
if (vm.getType() != VirtualMachine.Type.User) {
@@ -875,7 +889,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
List routers = getRouters(network, dest);
- if ((routers == null) || (routers.size() == 0)) {
+ if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
@@ -885,10 +899,10 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean removeDhcpSupportForSubnet(Network network) throws ResourceUnavailableException {
+ public boolean removeDhcpSupportForSubnet(final Network network) throws ResourceUnavailableException {
if (canHandle(network, Service.Dhcp)) {
List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
- if ((routers == null) || (routers.size() == 0)) {
+ if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
try {
@@ -901,7 +915,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
+ public boolean addDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(network, Service.Dhcp)) {
if (vm.getType() != VirtualMachine.Type.User) {
@@ -913,7 +927,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
List routers = getRouters(network, dest);
- if ((routers == null) || (routers.size() == 0)) {
+ if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
@@ -923,7 +937,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
+ public boolean addPasswordAndUserdata(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(network, Service.UserData)) {
if (vm.getType() != VirtualMachine.Type.User) {
@@ -940,7 +954,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
List routers = getRouters(network, dest);
- if ((routers == null) || (routers.size() == 0)) {
+ if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
@@ -949,7 +963,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
return false;
}
- protected List getRouters(Network network, DeployDestination dest) {
+ protected List getRouters(final Network network, final DeployDestination dest) {
boolean publicNetwork = false;
if (_networkMdl.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) {
publicNetwork = true;
@@ -985,7 +999,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public List extends VirtualRouterProvider> searchForVirtualRouterElement(ListVirtualRouterElementsCmd cmd) {
+ public List extends VirtualRouterProvider> searchForVirtualRouterElement(final ListVirtualRouterElementsCmd cmd) {
Long id = cmd.getId();
Long nspId = cmd.getNspId();
Boolean enabled = cmd.getEnabled();
@@ -1008,7 +1022,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public List extends OvsProvider> searchForOvsElement(ListOvsElementsCmd cmd) {
+ public List extends OvsProvider> searchForOvsElement(final ListOvsElementsCmd cmd) {
Long id = cmd.getId();
Long nspId = cmd.getNspId();
Boolean enabled = cmd.getEnabled();
@@ -1028,12 +1042,12 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean verifyServicesCombination(Set services) {
+ public boolean verifyServicesCombination(final Set services) {
return true;
}
@Override
- public IpDeployer getIpDeployer(Network network) {
+ public IpDeployer getIpDeployer(final Network network) {
return this;
}
@@ -1042,12 +1056,12 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public List updateHealthChecks(Network network, List lbrules) {
+ public List updateHealthChecks(final Network network, final List lbrules) {
// TODO Auto-generated method stub
return null;
}
- private boolean canHandleLbRules(List rules) {
+ private boolean canHandleLbRules(final List rules) {
Map lbCaps = getCapabilities().get(Service.Lb);
if (!lbCaps.isEmpty()) {
String schemeCaps = lbCaps.get(Capability.LbSchemes);
@@ -1064,7 +1078,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean prepareMigration(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) {
+ public boolean prepareMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) {
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
return true;
}
@@ -1081,7 +1095,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public void rollbackMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) {
+ public void rollbackMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst) {
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
return;
}
@@ -1097,7 +1111,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public void commitMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) {
+ public void commitMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst) {
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
return;
}
@@ -1113,10 +1127,10 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean prepareAggregatedExecution(Network network, DeployDestination dest) throws ResourceUnavailableException {
+ public boolean prepareAggregatedExecution(final Network network, final DeployDestination dest) throws ResourceUnavailableException {
List routers = getRouters(network, dest);
- if ((routers == null) || (routers.size() == 0)) {
+ if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
@@ -1124,10 +1138,10 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean completeAggregatedExecution(Network network, DeployDestination dest) throws ResourceUnavailableException {
+ public boolean completeAggregatedExecution(final Network network, final DeployDestination dest) throws ResourceUnavailableException {
List routers = getRouters(network, dest);
- if ((routers == null) || (routers.size() == 0)) {
+ if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
@@ -1135,7 +1149,7 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
}
@Override
- public boolean cleanupAggregatedExecution(Network network, DeployDestination dest) throws ResourceUnavailableException {
+ public boolean cleanupAggregatedExecution(final Network network, final DeployDestination dest) throws ResourceUnavailableException {
// The VR code already cleansup in the Finish routine using finally, lets not waste another command
return true;
}
diff --git a/server/src/com/cloud/network/router/RouterControlHelper.java b/server/src/com/cloud/network/router/RouterControlHelper.java
new file mode 100644
index 00000000000..2623119dddb
--- /dev/null
+++ b/server/src/com/cloud/network/router/RouterControlHelper.java
@@ -0,0 +1,54 @@
+package com.cloud.network.router;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.vm.DomainRouterVO;
+import com.cloud.vm.NicVO;
+import com.cloud.vm.dao.DomainRouterDao;
+import com.cloud.vm.dao.NicDao;
+
+public class RouterControlHelper {
+
+ private static final Logger logger = Logger.getLogger(RouterControlHelper.class);
+
+ @Inject
+ private DomainRouterDao routerDao = null;
+
+ @Inject
+ private NetworkDao networkDao;
+
+ @Inject
+ private NicDao nicDao;
+
+ public String getRouterControlIp(final long routerId) {
+ String routerControlIpAddress = null;
+ final List nics = nicDao.listByVmId(routerId);
+ for (final NicVO n : nics) {
+ final NetworkVO nc = networkDao.findById(n.getNetworkId());
+ if (nc != null && nc.getTrafficType() == TrafficType.Control) {
+ routerControlIpAddress = n.getIp4Address();
+ // router will have only one control ip
+ break;
+ }
+ }
+
+ if (routerControlIpAddress == null) {
+ logger.warn("Unable to find router's control ip in its attached NICs!. routerId: " + routerId);
+ final DomainRouterVO router = routerDao.findById(routerId);
+ return router.getPrivateIpAddress();
+ }
+
+ return routerControlIpAddress;
+ }
+
+ public String getRouterIpInNetwork(final long networkId, final long instanceId) {
+ return nicDao.getIpAddress(networkId, instanceId);
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/DhcpRules.java b/server/src/com/cloud/network/rules/DhcpRules.java
new file mode 100644
index 00000000000..149b738ab92
--- /dev/null
+++ b/server/src/com/cloud/network/rules/DhcpRules.java
@@ -0,0 +1,60 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import com.cloud.deploy.DeployDestination;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.VirtualMachineProfile;
+
+public class DhcpRules extends RuleApplier {
+
+ private final NicProfile nic;
+ private final VirtualMachineProfile profile;
+ private final DeployDestination destination;
+
+ public DhcpRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination destination) {
+ super(network);
+
+ this.nic = nic;
+ this.profile = profile;
+ this.destination = destination;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ return visitor.visit(this);
+ }
+
+ public NicProfile getNic() {
+ return nic;
+ }
+
+ public VirtualMachineProfile getProfile() {
+ return profile;
+ }
+
+ public DeployDestination getDestination() {
+ return destination;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/FirewallRules.java b/server/src/com/cloud/network/rules/FirewallRules.java
new file mode 100644
index 00000000000..7dd51ebb38b
--- /dev/null
+++ b/server/src/com/cloud/network/rules/FirewallRules.java
@@ -0,0 +1,99 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.dao.LoadBalancerDao;
+import com.cloud.network.dao.LoadBalancerVO;
+import com.cloud.network.lb.LoadBalancingRule;
+import com.cloud.network.lb.LoadBalancingRule.LbDestination;
+import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
+import com.cloud.network.lb.LoadBalancingRule.LbSslCert;
+import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
+import com.cloud.network.lb.LoadBalancingRulesManager;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.rules.FirewallRule.Purpose;
+import com.cloud.network.rules.LoadBalancerContainer.Scheme;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.utils.net.Ip;
+
+public class FirewallRules extends RuleApplier {
+
+ @Inject
+ NetworkModel _networkModel;
+
+ @Inject
+ LoadBalancingRulesManager _lbMgr;
+
+ @Inject
+ LoadBalancerDao _loadBalancerDao;
+
+ private final List extends FirewallRule> rules;
+ private List loadbalancingRules;
+
+ private Purpose purpose;
+
+ public FirewallRules(final Network network, final List extends FirewallRule> rules) {
+ super(network);
+ this.rules = rules;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ purpose = rules.get(0).getPurpose();
+
+ if (purpose == Purpose.LoadBalancing) {
+ // for load balancer we have to resend all lb rules for the network
+ final List lbs = _loadBalancerDao.listByNetworkIdAndScheme(network.getId(), Scheme.Public);
+ loadbalancingRules = new ArrayList();
+ for (final LoadBalancerVO lb : lbs) {
+ final List dstList = _lbMgr.getExistingDestinations(lb.getId());
+ final List policyList = _lbMgr.getStickinessPolicies(lb.getId());
+ final List hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
+ final LbSslCert sslCert = _lbMgr.getLbSslCert(lb.getId());
+ final Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
+ final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
+
+ loadbalancingRules.add(loadBalancing);
+ }
+ }
+
+ return visitor.visit(this);
+ }
+
+ public List extends FirewallRule> getRules() {
+ return rules;
+ }
+
+ public List getLoadbalancingRules() {
+ return loadbalancingRules;
+ }
+
+ public Purpose getPurpose() {
+ return purpose;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/IpAssociationRules.java b/server/src/com/cloud/network/rules/IpAssociationRules.java
new file mode 100644
index 00000000000..a002728704f
--- /dev/null
+++ b/server/src/com/cloud/network/rules/IpAssociationRules.java
@@ -0,0 +1,178 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.routing.IpAssocCommand;
+import com.cloud.agent.api.routing.NetworkElementCommand;
+import com.cloud.agent.api.to.IpAddressTO;
+import com.cloud.agent.manager.Commands;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.IpAddress;
+import com.cloud.network.Network;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.PublicIpAddress;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.utils.net.NetUtils;
+import com.cloud.vm.NicVO;
+import com.cloud.vm.dao.NicDao;
+
+public class IpAssociationRules extends RuleApplier {
+
+ @Inject
+ NicDao _nicDao;
+
+ @Inject
+ NetworkDao _networkDao;
+
+ @Inject
+ DataCenterDao _dcDao;
+
+ @Inject
+ NetworkModel _networkModel;
+
+ private final List extends PublicIpAddress> ipAddresses;
+
+ private Commands commands;
+
+ public IpAssociationRules(final Network network, final List extends PublicIpAddress> ipAddresses) {
+ super(network);
+ this.ipAddresses = ipAddresses;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ commands = new Commands(Command.OnError.Continue);
+ //
+ // Ensure that in multiple vlans case we first send all ip addresses of vlan1, then all ip addresses of vlan2, etc..
+ final Map> vlanIpMap = new HashMap>();
+ for (final PublicIpAddress ipAddress : ipAddresses) {
+ final String vlanTag = ipAddress.getVlanTag();
+ ArrayList ipList = vlanIpMap.get(vlanTag);
+ if (ipList == null) {
+ ipList = new ArrayList();
+ }
+ //domR doesn't support release for sourceNat IP address; so reset the state
+ if (ipAddress.isSourceNat() && ipAddress.getState() == IpAddress.State.Releasing) {
+ ipAddress.setState(IpAddress.State.Allocated);
+ }
+ ipList.add(ipAddress);
+ vlanIpMap.put(vlanTag, ipList);
+ }
+
+ final List nics = _nicDao.listByVmId(router.getId());
+ String baseMac = null;
+ for (final NicVO nic : nics) {
+ final NetworkVO nw = _networkDao.findById(nic.getNetworkId());
+ if (nw.getTrafficType() == TrafficType.Public) {
+ baseMac = nic.getMacAddress();
+ break;
+ }
+ }
+
+ for (final Map.Entry> vlanAndIp : vlanIpMap.entrySet()) {
+ final List ipAddrList = vlanAndIp.getValue();
+ // Source nat ip address should always be sent first
+ Collections.sort(ipAddrList, new Comparator() {
+ @Override
+ public int compare(final PublicIpAddress o1, final PublicIpAddress o2) {
+ final boolean s1 = o1.isSourceNat();
+ final boolean s2 = o2.isSourceNat();
+ return (s1 ^ s2) ? ((s1 ^ true) ? 1 : -1) : 0;
+ }
+ });
+
+ // Get network rate - required for IpAssoc
+ final Integer networkRate = _networkModel.getNetworkRate(ipAddrList.get(0).getNetworkId(), router.getId());
+ final Network network = _networkModel.getNetwork(ipAddrList.get(0).getNetworkId());
+
+ final IpAddressTO[] ipsToSend = new IpAddressTO[ipAddrList.size()];
+ int i = 0;
+ boolean firstIP = true;
+
+ for (final PublicIpAddress ipAddr : ipAddrList) {
+
+ final boolean add = (ipAddr.getState() == IpAddress.State.Releasing ? false : true);
+ boolean sourceNat = ipAddr.isSourceNat();
+ /* enable sourceNAT for the first ip of the public interface */
+ if (firstIP) {
+ sourceNat = true;
+ }
+ final String vlanId = ipAddr.getVlanTag();
+ final String vlanGateway = ipAddr.getGateway();
+ final String vlanNetmask = ipAddr.getNetmask();
+ String vifMacAddress = null;
+ // For non-source nat IP, set the mac to be something based on first public nic's MAC
+ // We cannot depends on first ip because we need to deal with first ip of other nics
+ if (!ipAddr.isSourceNat() && ipAddr.getVlanId() != 0) {
+ vifMacAddress = NetUtils.generateMacOnIncrease(baseMac, ipAddr.getVlanId());
+ } else {
+ vifMacAddress = ipAddr.getMacAddress();
+ }
+
+ final IpAddressTO ip =
+ new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress,
+ networkRate, ipAddr.isOneToOneNat());
+
+ ip.setTrafficType(network.getTrafficType());
+ ip.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(), network));
+ ipsToSend[i++] = ip;
+ /* send the firstIP = true for the first Add, this is to create primary on interface*/
+ if (!firstIP || add) {
+ firstIP = false;
+ }
+ }
+ final IpAssocCommand cmd = new IpAssocCommand(ipsToSend);
+ //cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
+ //cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(ipAddrList.get(0).getAssociatedWithNetworkId(), router.getId()));
+ cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
+ final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
+ cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
+
+ commands.addCommand("IPAssocCommand", cmd);
+ }
+ //
+
+ return visitor.visit(this);
+ }
+
+ public List extends PublicIpAddress> getIpAddresses() {
+ return ipAddresses;
+ }
+
+ public Commands getCommands() {
+ return commands;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/LoadBalancingRules.java b/server/src/com/cloud/network/rules/LoadBalancingRules.java
new file mode 100644
index 00000000000..bd61a0aa4d4
--- /dev/null
+++ b/server/src/com/cloud/network/rules/LoadBalancingRules.java
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import java.util.List;
+
+import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
+import com.cloud.agent.api.routing.NetworkElementCommand;
+import com.cloud.agent.api.to.LoadBalancerTO;
+import com.cloud.agent.manager.Commands;
+import com.cloud.configuration.Config;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.dao.LoadBalancerVO;
+import com.cloud.network.lb.LoadBalancingRule;
+import com.cloud.network.lb.LoadBalancingRule.LbDestination;
+import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
+import com.cloud.network.lb.LoadBalancingRule.LbSslCert;
+import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
+import com.cloud.network.router.RouterControlHelper;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.rules.LoadBalancerContainer.Scheme;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.utils.net.Ip;
+import com.cloud.vm.DomainRouterVO;
+import com.cloud.vm.Nic;
+import com.cloud.vm.NicProfile;
+
+public class LoadBalancingRules extends RuleApplier {
+
+ private final List rules;
+
+ protected RouterControlHelper routerControlHelper;
+
+ public LoadBalancingRules(final Network network, final List rules) {
+ super(network);
+ this.rules = rules;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ // For load balancer we have to resend all lb rules for the network
+ final List lbs = loadBalancerDao.listByNetworkIdAndScheme(network.getId(), Scheme.Public);
+
+ // We are cleaning it before because all the rules have to be sent to the router.
+ rules.clear();
+ for (final LoadBalancerVO lb : lbs) {
+ final List dstList = lbMgr.getExistingDestinations(lb.getId());
+ final List policyList = lbMgr.getStickinessPolicies(lb.getId());
+ final List hcPolicyList = lbMgr.getHealthCheckPolicies(lb.getId());
+ final LbSslCert sslCert = lbMgr.getLbSslCert(lb.getId());
+ final Ip sourceIp = networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
+ final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
+
+ rules.add(loadBalancing);
+ }
+
+ return visitor.visit(this);
+ }
+
+ public List getRules() {
+ return rules;
+ }
+
+ public void createApplyLoadBalancingRulesCommands(final List rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
+ final LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
+ int i = 0;
+ // We don't support VR to be inline currently
+ final boolean inline = false;
+ for (final LoadBalancingRule rule : rules) {
+ final boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
+ final String protocol = rule.getProtocol();
+ final String algorithm = rule.getAlgorithm();
+ final String uuid = rule.getUuid();
+
+ final String srcIp = rule.getSourceIp().addr();
+ final int srcPort = rule.getSourcePortStart();
+ final List destinations = rule.getDestinations();
+ final List stickinessPolicies = rule.getStickinessPolicies();
+ final LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, stickinessPolicies);
+ lbs[i++] = lb;
+ }
+ String routerPublicIp = null;
+
+ if (router instanceof DomainRouterVO) {
+ final DomainRouterVO domr = routerDao.findById(router.getId());
+ routerPublicIp = domr.getPublicIpAddress();
+ }
+
+ final Network guestNetwork = networkModel.getNetwork(guestNetworkId);
+ final Nic nic = nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId());
+ final NicProfile nicProfile =
+ new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(), networkModel.getNetworkRate(guestNetwork.getId(), router.getId()),
+ networkModel.isSecurityGroupSupportedInNetwork(guestNetwork), networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork));
+ final NetworkOffering offering = networkOfferingDao.findById(guestNetwork.getNetworkOfferingId());
+ String maxconn = null;
+ if (offering.getConcurrentConnections() == null) {
+ maxconn = configDao.getValue(Config.NetworkLBHaproxyMaxConn.key());
+ } else {
+ maxconn = offering.getConcurrentConnections().toString();
+ }
+
+ final LoadBalancerConfigCommand cmd =
+ new LoadBalancerConfigCommand(lbs, routerPublicIp, this.routerControlHelper.getRouterIpInNetwork(
+ guestNetworkId, router.getId()), router.getPrivateIpAddress(), itMgr.toNicTO(
+ nicProfile, router.getHypervisorType()), router.getVpcId(), maxconn, offering.isKeepAliveEnabled());
+
+ cmd.lbStatsVisibility = configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
+ cmd.lbStatsUri = configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
+ cmd.lbStatsAuth = configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key());
+ cmd.lbStatsPort = configDao.getValue(Config.NetworkLBHaproxyStatsPort.key());
+
+ cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, this.routerControlHelper.getRouterControlIp(router.getId()));
+ cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, this.routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
+ cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
+ final DataCenterVO dcVo = dcDao.findById(router.getDataCenterId());
+ cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
+ cmds.addCommand(cmd);
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/NetworkAclsRules.java b/server/src/com/cloud/network/rules/NetworkAclsRules.java
new file mode 100644
index 00000000000..bd30f61c0d6
--- /dev/null
+++ b/server/src/com/cloud/network/rules/NetworkAclsRules.java
@@ -0,0 +1,47 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import java.util.List;
+
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.network.vpc.NetworkACLItem;
+
+public class NetworkAclsRules extends RuleApplier {
+
+ private final List extends NetworkACLItem> rules;
+
+ public NetworkAclsRules(final Network network, final List extends NetworkACLItem> rules) {
+ super(network);
+ this.rules = rules;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ return visitor.visit(this);
+ }
+
+ public List extends NetworkACLItem> getRules() {
+ return rules;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/PasswordToRouterRules.java b/server/src/com/cloud/network/rules/PasswordToRouterRules.java
new file mode 100644
index 00000000000..6a756336324
--- /dev/null
+++ b/server/src/com/cloud/network/rules/PasswordToRouterRules.java
@@ -0,0 +1,53 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.VirtualMachineProfile;
+
+public class PasswordToRouterRules extends RuleApplier {
+
+ private final NicProfile nic;
+ private final VirtualMachineProfile profile;
+
+ public PasswordToRouterRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile) {
+ super(network);
+
+ this.nic = nic;
+ this.profile = profile;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ return visitor.visit(this);
+ }
+
+ public NicProfile getNic() {
+ return nic;
+ }
+
+ public VirtualMachineProfile getProfile() {
+ return profile;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/PrivateGatewayRules.java b/server/src/com/cloud/network/rules/PrivateGatewayRules.java
new file mode 100644
index 00000000000..b76880d428b
--- /dev/null
+++ b/server/src/com/cloud/network/rules/PrivateGatewayRules.java
@@ -0,0 +1,47 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import java.util.List;
+
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.network.vpc.NetworkACLItem;
+
+public class PrivateGatewayRules extends RuleApplier {
+
+ private final List extends NetworkACLItem> rules;
+
+ public PrivateGatewayRules(final Network network, final List extends NetworkACLItem> rules) {
+ super(network);
+ this.rules = rules;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ return visitor.visit(this);
+ }
+
+ public List extends NetworkACLItem> getRules() {
+ return rules;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/RuleApplier.java b/server/src/com/cloud/network/rules/RuleApplier.java
new file mode 100644
index 00000000000..3f3eda3bf19
--- /dev/null
+++ b/server/src/com/cloud/network/rules/RuleApplier.java
@@ -0,0 +1,71 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.dao.LoadBalancerDao;
+import com.cloud.network.lb.LoadBalancingRulesManager;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+import com.cloud.vm.VirtualMachineManager;
+import com.cloud.vm.dao.DomainRouterDao;
+import com.cloud.vm.dao.NicDao;
+
+public abstract class RuleApplier {
+
+ protected NetworkModel networkModel;
+
+ protected LoadBalancingRulesManager lbMgr;
+
+ protected LoadBalancerDao loadBalancerDao;
+
+ protected ConfigurationDao configDao;
+
+ protected NicDao nicDao;
+
+ protected NetworkOfferingDao networkOfferingDao = null;
+
+ protected DataCenterDao dcDao = null;
+
+ protected DomainRouterDao routerDao = null;
+
+ protected VirtualMachineManager itMgr;
+
+ protected Network network;
+ protected VirtualRouter router;
+
+ public RuleApplier(final Network network) {
+ this.network = network;
+ }
+
+ public abstract boolean accept(NetworkTopologyVisitor visitor, VirtualRouter router) throws ResourceUnavailableException;
+
+ public Network getNetwork() {
+ return network;
+ }
+
+ public VirtualRouter getRouter() {
+ return router;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/SshKeyToRouterRules.java b/server/src/com/cloud/network/rules/SshKeyToRouterRules.java
new file mode 100644
index 00000000000..889415ad6cd
--- /dev/null
+++ b/server/src/com/cloud/network/rules/SshKeyToRouterRules.java
@@ -0,0 +1,53 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.VirtualMachineProfile;
+
+public class SshKeyToRouterRules extends RuleApplier {
+
+ private final NicProfile nic;
+ private final VirtualMachineProfile profile;
+
+ public SshKeyToRouterRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile) {
+ super(network);
+
+ this.nic = nic;
+ this.profile = profile;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ return visitor.visit(this);
+ }
+
+ public NicProfile getNic() {
+ return nic;
+ }
+
+ public VirtualMachineProfile getProfile() {
+ return profile;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/StaticNatRules.java b/server/src/com/cloud/network/rules/StaticNatRules.java
new file mode 100644
index 00000000000..c6edd3afa01
--- /dev/null
+++ b/server/src/com/cloud/network/rules/StaticNatRules.java
@@ -0,0 +1,83 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import com.cloud.agent.api.routing.NetworkElementCommand;
+import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
+import com.cloud.agent.api.to.StaticNatRuleTO;
+import com.cloud.agent.manager.Commands;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.IpAddress;
+import com.cloud.network.Network;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+
+public class StaticNatRules extends RuleApplier {
+
+ @Inject
+ DataCenterDao _dcDao;
+
+ @Inject
+ NetworkModel _networkModel;
+
+ private final List extends StaticNat> rules;
+
+ public StaticNatRules(final Network network, final List extends StaticNat> rules) {
+ super(network);
+ this.rules = rules;
+ }
+
+ public List extends StaticNat> getRules() {
+ return rules;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+ return visitor.visit(this);
+ }
+
+ public void createApplyStaticNatCommands(final List extends StaticNat> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
+ List rulesTO = new ArrayList();
+ if (rules != null) {
+ for (final StaticNat rule : rules) {
+ final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
+ final StaticNatRuleTO ruleTO =
+ new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
+ rulesTO.add(ruleTO);
+ }
+ }
+
+ final SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, router.getVpcId());
+ //cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
+ //cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId()));
+ cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
+
+ final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
+ cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
+ cmds.addCommand(cmd);
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/UserdataPwdRules.java b/server/src/com/cloud/network/rules/UserdataPwdRules.java
new file mode 100644
index 00000000000..606b2398ce1
--- /dev/null
+++ b/server/src/com/cloud/network/rules/UserdataPwdRules.java
@@ -0,0 +1,60 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import com.cloud.deploy.DeployDestination;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.VirtualMachineProfile;
+
+public class UserdataPwdRules extends RuleApplier {
+
+ private final NicProfile nic;
+ private final VirtualMachineProfile profile;
+ private final DeployDestination destination;
+
+ public UserdataPwdRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination destination) {
+ super(network);
+
+ this.nic = nic;
+ this.profile = profile;
+ this.destination = destination;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ return visitor.visit(this);
+ }
+
+ public NicProfile getNic() {
+ return nic;
+ }
+
+ public VirtualMachineProfile getProfile() {
+ return profile;
+ }
+
+ public DeployDestination getDestination() {
+ return destination;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/UserdataToRouterRules.java b/server/src/com/cloud/network/rules/UserdataToRouterRules.java
new file mode 100644
index 00000000000..d6cb406ec07
--- /dev/null
+++ b/server/src/com/cloud/network/rules/UserdataToRouterRules.java
@@ -0,0 +1,67 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import com.cloud.agent.api.Command;
+import com.cloud.agent.manager.Commands;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.VirtualMachineProfile;
+
+public class UserdataToRouterRules extends RuleApplier {
+
+ private final NicProfile nic;
+ private final VirtualMachineProfile profile;
+
+ public UserdataToRouterRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile) {
+ super(network);
+
+ this.nic = nic;
+ this.profile = profile;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ // for basic zone, send vm data/password information only to the router in the same pod
+ final Commands cmds = new Commands(Command.OnError.Stop);
+ //final NicVO nicVo = _nicDao.findById(nic.getId());
+
+ //final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText();
+ //final String zoneName = _dcDao.findById(router.getDataCenterId()).getName();
+
+ // cmds.addCommand(
+ // "vmdata",
+ // generateVmDataCommand(router, nic.getIp4Address(), vm.getUserData(), serviceOffering, zoneName, nic.getIp4Address(), vm.getHostName(), vm.getInstanceName(),
+ // vm.getId(), vm.getUuid(), null, nic.getNetworkId()));
+
+ return visitor.visit(this);
+ }
+
+ public NicProfile getNic() {
+ return nic;
+ }
+
+ public VirtualMachineProfile getProfile() {
+ return profile;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java b/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java
new file mode 100644
index 00000000000..af1444f9059
--- /dev/null
+++ b/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java
@@ -0,0 +1,66 @@
+package com.cloud.network.rules;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.network.Network;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.dao.LoadBalancerDao;
+import com.cloud.network.lb.LoadBalancingRule;
+import com.cloud.network.lb.LoadBalancingRulesManager;
+import com.cloud.network.router.RouterControlHelper;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+import com.cloud.vm.dao.DomainRouterDao;
+import com.cloud.vm.dao.NicDao;
+
+public class VirtualNetworkApplianceFactory {
+
+ @Inject
+ protected NetworkModel networkModel;
+
+ @Inject
+ protected LoadBalancingRulesManager lbMgr;
+
+ @Inject
+ protected LoadBalancerDao loadBalancerDao;
+
+ @Inject
+ protected ConfigurationDao configDao;
+
+ @Inject
+ protected NicDao nicDao;
+
+ @Inject
+ protected NetworkOfferingDao networkOfferingDao;
+
+ @Inject
+ protected DataCenterDao dcDao;
+
+ @Inject
+ protected DomainRouterDao routerDao;
+
+ @Inject
+ protected RouterControlHelper routerControlHelper;
+
+
+ public LoadBalancingRules createLoadBalancingRules(final Network network,
+ final List rules) {
+ LoadBalancingRules lbRules = new LoadBalancingRules(network, rules);
+
+ lbRules.networkModel = this.networkModel;
+ lbRules.dcDao = this.dcDao;
+ lbRules.lbMgr = this.lbMgr;
+ lbRules.loadBalancerDao = this.loadBalancerDao;
+ lbRules.configDao = this.configDao;
+ lbRules.nicDao = this.nicDao;
+ lbRules.networkOfferingDao = this.networkOfferingDao;
+ lbRules.routerDao = this.routerDao;
+ lbRules.routerControlHelper = this.routerControlHelper;
+
+ return lbRules;
+ }
+}
diff --git a/server/src/com/cloud/network/rules/VpcIpAssociationRules.java b/server/src/com/cloud/network/rules/VpcIpAssociationRules.java
new file mode 100644
index 00000000000..eea4f6726f3
--- /dev/null
+++ b/server/src/com/cloud/network/rules/VpcIpAssociationRules.java
@@ -0,0 +1,47 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import java.util.List;
+
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.PublicIpAddress;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+
+public class VpcIpAssociationRules extends RuleApplier {
+
+ private final List extends PublicIpAddress> ipAddresses;
+
+ public VpcIpAssociationRules(final Network network, final List extends PublicIpAddress> ipAddresses) {
+ super(network);
+ this.ipAddresses = ipAddresses;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ return visitor.visit(this);
+ }
+
+ public List extends PublicIpAddress> getIpAddresses() {
+ return ipAddresses;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/rules/VpnRules.java b/server/src/com/cloud/network/rules/VpnRules.java
new file mode 100644
index 00000000000..15eac3f5cc5
--- /dev/null
+++ b/server/src/com/cloud/network/rules/VpnRules.java
@@ -0,0 +1,47 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.rules;
+
+import java.util.List;
+
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.topology.NetworkTopologyVisitor;
+import com.cloud.network.vpc.NetworkACLItem;
+
+public class VpnRules extends RuleApplier {
+
+ private final List extends NetworkACLItem> rules;
+
+ public VpnRules(final Network network, final List extends NetworkACLItem> rules) {
+ super(network);
+ this.rules = rules;
+ }
+
+ @Override
+ public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
+ this.router = router;
+
+ return visitor.visit(this);
+ }
+
+ public List extends NetworkACLItem> getRules() {
+ return rules;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/topology/AdvancedNetworkTopology.java b/server/src/com/cloud/network/topology/AdvancedNetworkTopology.java
new file mode 100644
index 00000000000..f899ae69941
--- /dev/null
+++ b/server/src/com/cloud/network/topology/AdvancedNetworkTopology.java
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.topology;
+
+import java.util.List;
+import java.util.Map;
+
+import com.cloud.dc.DataCenter;
+import com.cloud.deploy.DeployDestination;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.lb.LoadBalancingRule;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.rules.RuleApplier;
+import com.cloud.user.Account;
+import com.cloud.vm.DomainRouterVO;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.VirtualMachineProfile.Param;
+
+public class AdvancedNetworkTopology implements NetworkTopology {
+
+ @Override
+ public List findOrDeployVirtualRouterInGuestNetwork(
+ final Network guestNetwork, final DeployDestination dest, final Account owner,
+ final boolean isRedundant, final Map params)
+ throws ConcurrentOperationException, InsufficientCapacityException,
+ ResourceUnavailableException {
+ return null;
+ }
+
+ @Override
+ public StringBuilder createGuestBootLoadArgs(final NicProfile guestNic,
+ final String defaultDns1, final String defaultDns2, final DomainRouterVO router) {
+ return null;
+ }
+
+ @Override
+ public String retrieveGuestDhcpRange(final NicProfile guestNic,
+ final Network guestNetwork, final DataCenter dc) {
+ return null;
+ }
+
+ @Override
+ public NicProfile retrieveControlNic(final VirtualMachineProfile profile) {
+ return null;
+ }
+
+ @Override
+ public boolean configDhcpForSubnet(final Network network, final NicProfile nic,
+ final VirtualMachineProfile profile, final DeployDestination dest,
+ final List routers) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean applyDhcpEntry(final Network network, final NicProfile nic,
+ final VirtualMachineProfile profile, final DeployDestination dest,
+ final List routers) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean applyUserData(final Network network, final NicProfile nic,
+ final VirtualMachineProfile profile, final DeployDestination dest,
+ final List routers) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean applyRules(final Network network,
+ final List extends VirtualRouter> routers, final String typeString,
+ final boolean isPodLevelException, final Long podId,
+ final boolean failWhenDisconnect, final RuleApplier applier)
+ throws ResourceUnavailableException {
+
+ AdvancedNetworkVisitor visitor = new AdvancedNetworkVisitor(this);
+ applier.accept(visitor, null);
+
+ return false;
+ }
+
+ @Override
+ public boolean sendCommandsToRouter(VirtualRouter router,
+ List rules, long id) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/topology/AdvancedNetworkVisitor.java b/server/src/com/cloud/network/topology/AdvancedNetworkVisitor.java
new file mode 100644
index 00000000000..41738fe4780
--- /dev/null
+++ b/server/src/com/cloud/network/topology/AdvancedNetworkVisitor.java
@@ -0,0 +1,162 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.topology;
+
+import java.util.List;
+
+import com.cloud.agent.api.Command;
+import com.cloud.agent.manager.Commands;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.lb.LoadBalancingRule;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.rules.DhcpRules;
+import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.rules.FirewallRule.Purpose;
+import com.cloud.network.rules.FirewallRules;
+import com.cloud.network.rules.IpAssociationRules;
+import com.cloud.network.rules.LoadBalancingRules;
+import com.cloud.network.rules.NetworkAclsRules;
+import com.cloud.network.rules.PasswordToRouterRules;
+import com.cloud.network.rules.PrivateGatewayRules;
+import com.cloud.network.rules.SshKeyToRouterRules;
+import com.cloud.network.rules.StaticNat;
+import com.cloud.network.rules.StaticNatRules;
+import com.cloud.network.rules.UserdataPwdRules;
+import com.cloud.network.rules.UserdataToRouterRules;
+import com.cloud.network.rules.VpcIpAssociationRules;
+import com.cloud.network.rules.VpnRules;
+
+public class AdvancedNetworkVisitor extends NetworkTopologyVisitor {
+
+ public AdvancedNetworkVisitor(final NetworkTopology networkTopology) {
+ super(networkTopology);
+ }
+
+ @Override
+ public boolean visit(final StaticNatRules nat) throws ResourceUnavailableException {
+ Network network = nat.getNetwork();
+ VirtualRouter router = nat.getRouter();
+ List extends StaticNat> rules = nat.getRules();
+
+ final Commands cmds = new Commands(Command.OnError.Continue);
+ nat.createApplyStaticNatCommands(rules, router, cmds, network.getId());
+
+ //return sendCommandsToRouter(router, cmds);
+
+ return false;
+ }
+
+ @Override
+ public boolean visit(final LoadBalancingRules loadbalancing) throws ResourceUnavailableException {
+ Network network = loadbalancing.getNetwork();
+ VirtualRouter router = loadbalancing.getRouter();
+ List rules = loadbalancing.getRules();
+
+ final Commands cmds = new Commands(Command.OnError.Continue);
+ loadbalancing.createApplyLoadBalancingRulesCommands(rules, router, cmds, network.getId());
+
+ return networkTopology.sendCommandsToRouter(router, rules, network.getId());
+ }
+
+ @Override
+ public boolean visit(final FirewallRules firewall) throws ResourceUnavailableException {
+ Network network = firewall.getNetwork();
+ VirtualRouter router = firewall.getRouter();
+ List extends FirewallRule> rules = firewall.getRules();
+ List loadbalancingRules = firewall.getLoadbalancingRules();
+
+ Purpose purpose = firewall.getPurpose();
+
+ if (purpose == Purpose.LoadBalancing) {
+
+ //return sendLBRules(router, loadbalancingRules, network.getId());
+
+ } else if (purpose == Purpose.PortForwarding) {
+
+ //return sendPortForwardingRules(router, (List)rules, network.getId());
+
+ } else if (purpose == Purpose.StaticNat) {
+
+ //return sendStaticNatRules(router, (List)rules, network.getId());
+
+ } else if (purpose == Purpose.Firewall) {
+
+ //return sendFirewallRules(router, (List)rules, network.getId());
+
+ }
+ //s_logger.warn("Unable to apply rules of purpose: " + rules.get(0).getPurpose());
+
+ return false;
+ }
+
+ @Override
+ public boolean visit(final IpAssociationRules ipRules) throws ResourceUnavailableException {
+ VirtualRouter router = ipRules.getRouter();
+ Commands commands = ipRules.getCommands();
+
+ //return sendCommandsToRouter(router, commands);
+
+ return false;
+ }
+
+ @Override
+ public boolean visit(final UserdataPwdRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final DhcpRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final SshKeyToRouterRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final PasswordToRouterRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final NetworkAclsRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final VpcIpAssociationRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final UserdataToRouterRules userdata) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(PrivateGatewayRules userdata) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(VpnRules userdata) throws ResourceUnavailableException {
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/topology/BasicNetworkTopology.java b/server/src/com/cloud/network/topology/BasicNetworkTopology.java
new file mode 100644
index 00000000000..5d8a121df1b
--- /dev/null
+++ b/server/src/com/cloud/network/topology/BasicNetworkTopology.java
@@ -0,0 +1,102 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.topology;
+
+import java.util.List;
+import java.util.Map;
+
+import com.cloud.dc.DataCenter;
+import com.cloud.deploy.DeployDestination;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.lb.LoadBalancingRule;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.rules.RuleApplier;
+import com.cloud.user.Account;
+import com.cloud.vm.DomainRouterVO;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.VirtualMachineProfile.Param;
+
+public class BasicNetworkTopology implements NetworkTopology {
+
+ @Override
+ public List findOrDeployVirtualRouterInGuestNetwork(
+ final Network guestNetwork, final DeployDestination dest, final Account owner,
+ final boolean isRedundant, final Map params)
+ throws ConcurrentOperationException, InsufficientCapacityException,
+ ResourceUnavailableException {
+ return null;
+ }
+
+ @Override
+ public StringBuilder createGuestBootLoadArgs(final NicProfile guestNic,
+ final String defaultDns1, final String defaultDns2, final DomainRouterVO router) {
+ return null;
+ }
+
+ @Override
+ public String retrieveGuestDhcpRange(final NicProfile guestNic,
+ final Network guestNetwork, final DataCenter dc) {
+ return null;
+ }
+
+ @Override
+ public NicProfile retrieveControlNic(final VirtualMachineProfile profile) {
+ return null;
+ }
+
+ @Override
+ public boolean configDhcpForSubnet(final Network network, final NicProfile nic,
+ final VirtualMachineProfile profile, final DeployDestination dest,
+ final List routers) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean applyDhcpEntry(final Network network, final NicProfile nic,
+ final VirtualMachineProfile profile, final DeployDestination dest,
+ final List routers) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean applyUserData(final Network network, final NicProfile nic,
+ final VirtualMachineProfile profile, final DeployDestination dest,
+ final List routers) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean applyRules(final Network network,
+ final List extends VirtualRouter> routers, final String typeString,
+ final boolean isPodLevelException, final Long podId,
+ final boolean failWhenDisconnect, final RuleApplier applier)
+ throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean sendCommandsToRouter(VirtualRouter router,
+ List rules, long id) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/topology/BasicNetworkVisitor.java b/server/src/com/cloud/network/topology/BasicNetworkVisitor.java
new file mode 100644
index 00000000000..b648e678f42
--- /dev/null
+++ b/server/src/com/cloud/network/topology/BasicNetworkVisitor.java
@@ -0,0 +1,111 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.topology;
+
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.rules.DhcpRules;
+import com.cloud.network.rules.FirewallRules;
+import com.cloud.network.rules.IpAssociationRules;
+import com.cloud.network.rules.LoadBalancingRules;
+import com.cloud.network.rules.NetworkAclsRules;
+import com.cloud.network.rules.PasswordToRouterRules;
+import com.cloud.network.rules.PrivateGatewayRules;
+import com.cloud.network.rules.SshKeyToRouterRules;
+import com.cloud.network.rules.StaticNatRules;
+import com.cloud.network.rules.UserdataPwdRules;
+import com.cloud.network.rules.UserdataToRouterRules;
+import com.cloud.network.rules.VpcIpAssociationRules;
+import com.cloud.network.rules.VpnRules;
+
+public class BasicNetworkVisitor extends NetworkTopologyVisitor {
+
+ public BasicNetworkVisitor(final NetworkTopology networkTopology) {
+ super(networkTopology);
+ }
+
+ @Override
+ public boolean visit(final StaticNatRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final LoadBalancingRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final FirewallRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final IpAssociationRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final UserdataPwdRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final DhcpRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final SshKeyToRouterRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final PasswordToRouterRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final NetworkAclsRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final VpcIpAssociationRules nat) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(final UserdataToRouterRules userdata) throws ResourceUnavailableException {
+ Network network = userdata.getNetwork();
+ VirtualRouter router = userdata.getRouter();
+
+ //return sendCommandsToRouter(router, cmds);
+ return false;
+ }
+
+ @Override
+ public boolean visit(PrivateGatewayRules userdata) throws ResourceUnavailableException {
+ return false;
+ }
+
+ @Override
+ public boolean visit(VpnRules userdata) throws ResourceUnavailableException {
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/topology/NetworkTopology.java b/server/src/com/cloud/network/topology/NetworkTopology.java
new file mode 100644
index 00000000000..d262070c7de
--- /dev/null
+++ b/server/src/com/cloud/network/topology/NetworkTopology.java
@@ -0,0 +1,63 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.topology;
+
+import java.util.List;
+import java.util.Map;
+
+import com.cloud.dc.DataCenter;
+import com.cloud.deploy.DeployDestination;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.lb.LoadBalancingRule;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.rules.RuleApplier;
+import com.cloud.user.Account;
+import com.cloud.vm.DomainRouterVO;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.VirtualMachineProfile.Param;
+
+public interface NetworkTopology {
+
+ List findOrDeployVirtualRouterInGuestNetwork(final Network guestNetwork, final DeployDestination dest, Account owner, final boolean isRedundant,
+ final Map params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
+
+ StringBuilder createGuestBootLoadArgs(final NicProfile guestNic, final String defaultDns1, final String defaultDns2, DomainRouterVO router);
+
+ String retrieveGuestDhcpRange(final NicProfile guestNic, final Network guestNetwork, final DataCenter dc);
+
+ NicProfile retrieveControlNic(final VirtualMachineProfile profile);
+
+ boolean configDhcpForSubnet(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final List routers)
+ throws ResourceUnavailableException;
+
+ boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final List routers)
+ throws ResourceUnavailableException;
+
+ boolean applyUserData(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final List routers)
+ throws ResourceUnavailableException;
+
+ boolean applyRules(final Network network, final List extends VirtualRouter> routers, final String typeString, final boolean isPodLevelException, final Long podId,
+ final boolean failWhenDisconnect, final RuleApplier applier) throws ResourceUnavailableException;
+
+ boolean sendCommandsToRouter(VirtualRouter router,
+ List rules, long id);
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/topology/NetworkTopologyContext.java b/server/src/com/cloud/network/topology/NetworkTopologyContext.java
new file mode 100644
index 00000000000..6ba10ef553f
--- /dev/null
+++ b/server/src/com/cloud/network/topology/NetworkTopologyContext.java
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.topology;
+
+import java.util.Hashtable;
+
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.DataCenter.NetworkType;
+
+public final class NetworkTopologyContext {
+
+ private static NetworkTopologyContext instance;
+
+ static {
+ instance = new NetworkTopologyContext();
+ }
+
+ private final Hashtable flyweight;
+
+ private NetworkTopologyContext() {
+ flyweight = new Hashtable();
+ flyweight.put(NetworkType.Basic, new BasicNetworkTopology());
+ flyweight.put(NetworkType.Advanced, new AdvancedNetworkTopology());
+ }
+
+ public static NetworkTopologyContext getInstance() {
+ return instance;
+ }
+
+ public NetworkTopology retrieveNetworkTopology(final DataCenter dc) {
+ if (!flyweight.containsKey(dc.getNetworkType())) {
+ throw new IllegalArgumentException("The type given cannot be related to a NetworkTopology implementation. "
+ + "Please, give a correct type.");
+ }
+ return flyweight.get(dc.getNetworkType());
+ }
+}
\ No newline at end of file
diff --git a/server/src/com/cloud/network/topology/NetworkTopologyVisitor.java b/server/src/com/cloud/network/topology/NetworkTopologyVisitor.java
new file mode 100644
index 00000000000..46f68e4f4fe
--- /dev/null
+++ b/server/src/com/cloud/network/topology/NetworkTopologyVisitor.java
@@ -0,0 +1,60 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network.topology;
+
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.rules.DhcpRules;
+import com.cloud.network.rules.FirewallRules;
+import com.cloud.network.rules.IpAssociationRules;
+import com.cloud.network.rules.LoadBalancingRules;
+import com.cloud.network.rules.NetworkAclsRules;
+import com.cloud.network.rules.PasswordToRouterRules;
+import com.cloud.network.rules.PrivateGatewayRules;
+import com.cloud.network.rules.SshKeyToRouterRules;
+import com.cloud.network.rules.StaticNatRules;
+import com.cloud.network.rules.UserdataPwdRules;
+import com.cloud.network.rules.UserdataToRouterRules;
+import com.cloud.network.rules.VpcIpAssociationRules;
+import com.cloud.network.rules.VpnRules;
+
+public abstract class NetworkTopologyVisitor {
+
+ protected final NetworkTopology networkTopology;
+
+ public NetworkTopologyVisitor(final NetworkTopology networkTopology) {
+ this.networkTopology = networkTopology;
+ }
+
+ public abstract boolean visit(StaticNatRules nat) throws ResourceUnavailableException;
+ public abstract boolean visit(LoadBalancingRules loadbalancing) throws ResourceUnavailableException;
+ public abstract boolean visit(FirewallRules firewall) throws ResourceUnavailableException;
+ public abstract boolean visit(IpAssociationRules ipAddresses) throws ResourceUnavailableException;
+ public abstract boolean visit(UserdataPwdRules userdata) throws ResourceUnavailableException;
+ public abstract boolean visit(DhcpRules dhcp) throws ResourceUnavailableException;
+ public abstract boolean visit(SshKeyToRouterRules ssh) throws ResourceUnavailableException;
+ public abstract boolean visit(PasswordToRouterRules pwd) throws ResourceUnavailableException;
+ public abstract boolean visit(NetworkAclsRules acl) throws ResourceUnavailableException;
+ public abstract boolean visit(VpcIpAssociationRules vpcIp) throws ResourceUnavailableException;
+ public abstract boolean visit(UserdataToRouterRules userdata) throws ResourceUnavailableException;
+ public abstract boolean visit(VpnRules userdata) throws ResourceUnavailableException;
+ public abstract boolean visit(PrivateGatewayRules userdata) throws ResourceUnavailableException;
+
+ public NetworkTopology getNetworkTopology() {
+ return networkTopology;
+ }
+}
\ No newline at end of file