diff --git a/server/src/com/cloud/network/router/NetworkHelperImpl.java b/server/src/com/cloud/network/router/NetworkHelperImpl.java index 62dd7893abc..01c48918c97 100644 --- a/server/src/com/cloud/network/router/NetworkHelperImpl.java +++ b/server/src/com/cloud/network/router/NetworkHelperImpl.java @@ -109,7 +109,7 @@ public class NetworkHelperImpl implements NetworkHelper { @Inject protected NicDao _nicDao; @Inject - private NetworkDao _networkDao; + protected NetworkDao _networkDao; @Inject protected DomainRouterDao _routerDao; @Inject @@ -137,8 +137,6 @@ public class NetworkHelperImpl implements NetworkHelper { @Inject private UserIpv6AddressDao _ipv6Dao; @Inject - private RouterControlHelper _routerControlHelper; - @Inject protected NetworkOrchestrationService _networkMgr; @Inject private UserDao _userDao; @@ -610,20 +608,22 @@ public class NetworkHelperImpl implements NetworkHelper { throw new CloudRuntimeException(errMsg); } - @Override - public LinkedHashMap> configureDefaultNics(final RouterDeploymentDefinition routerDeploymentDefinition) throws ConcurrentOperationException, InsufficientAddressCapacityException { + protected LinkedHashMap> configureControlNic(final RouterDeploymentDefinition routerDeploymentDefinition) { + final LinkedHashMap> controlConfig = new LinkedHashMap>(3); - final LinkedHashMap> networks = new LinkedHashMap>(3); - - // 1) Control network s_logger.debug("Adding nic for Virtual Router in Control network "); final List offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork); final NetworkOffering controlOffering = offerings.get(0); - final Network controlConfig = _networkMgr.setupNetwork(s_systemAccount, controlOffering, routerDeploymentDefinition.getPlan(), null, null, false).get(0); + final Network controlNic = _networkMgr.setupNetwork(s_systemAccount, controlOffering, routerDeploymentDefinition.getPlan(), null, null, false).get(0); - networks.put(controlConfig, new ArrayList()); + controlConfig.put(controlNic, new ArrayList()); + + return controlConfig; + } + + protected LinkedHashMap> configurePublicNic(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean hasGuestNic) { + final LinkedHashMap> publicConfig = new LinkedHashMap>(3); - // 2) Public network if (routerDeploymentDefinition.isPublicNetwork()) { s_logger.debug("Adding nic for Virtual Router in Public network "); // if source nat service is supported by the network, get the source @@ -647,6 +647,11 @@ public class NetworkHelperImpl implements NetworkHelper { defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); } + //If guest nic has already been added we will have 2 devices in the list. + if (hasGuestNic) { + defaultNic.setDeviceId(2); + } + final NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0); final List publicNetworks = _networkMgr.setupNetwork(s_systemAccount, publicOffering, routerDeploymentDefinition.getPlan(), null, null, false); final String publicIp = defaultNic.getIPv4Address(); @@ -657,14 +662,29 @@ public class NetworkHelperImpl implements NetworkHelper { s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress()); defaultNic.setMacAddress(peerNic.getMacAddress()); } - networks.put(publicNetworks.get(0), new ArrayList(Arrays.asList(defaultNic))); + publicConfig.put(publicNetworks.get(0), new ArrayList(Arrays.asList(defaultNic))); } - // 3) Guest Network + return publicConfig; + } + + @Override + public LinkedHashMap> configureDefaultNics(final RouterDeploymentDefinition routerDeploymentDefinition) throws ConcurrentOperationException, InsufficientAddressCapacityException { + + final LinkedHashMap> networks = new LinkedHashMap>(3); + + // 1) Guest Network final LinkedHashMap> guestNic = configureGuestNic(routerDeploymentDefinition); - // The guest nic has to be added after the Control and Public nics. networks.putAll(guestNic); + // 2) Control network + final LinkedHashMap> controlNic = configureControlNic(routerDeploymentDefinition); + networks.putAll(controlNic); + + // 3) Public network + final LinkedHashMap> publicNic = configurePublicNic(routerDeploymentDefinition, networks.size() > 1); + networks.putAll(publicNic); + return networks; } diff --git a/server/src/com/cloud/network/router/VpcNetworkHelperImpl.java b/server/src/com/cloud/network/router/VpcNetworkHelperImpl.java index f6f9ec46298..2b008bd28aa 100644 --- a/server/src/com/cloud/network/router/VpcNetworkHelperImpl.java +++ b/server/src/com/cloud/network/router/VpcNetworkHelperImpl.java @@ -32,6 +32,7 @@ import org.cloud.network.router.deployment.RouterDeploymentDefinition; import com.cloud.dc.dao.VlanDao; import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IpAddress; @@ -153,4 +154,24 @@ public class VpcNetworkHelperImpl extends NetworkHelperImpl { _itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, vpcRouterDeploymentDefinition.getPlan(), hType); } + + @Override + public LinkedHashMap> configureDefaultNics(final RouterDeploymentDefinition routerDeploymentDefinition) throws ConcurrentOperationException, InsufficientAddressCapacityException { + + final LinkedHashMap> networks = new LinkedHashMap>(3); + + // 1) Control network + final LinkedHashMap> controlNic = configureControlNic(routerDeploymentDefinition); + networks.putAll(controlNic); + + // 2) Public network + final LinkedHashMap> publicNic = configurePublicNic(routerDeploymentDefinition, false); + networks.putAll(publicNic); + + // 3) Guest Network + final LinkedHashMap> guestNic = configureGuestNic(routerDeploymentDefinition); + networks.putAll(guestNic); + + return networks; + } } \ No newline at end of file