Skip to content

Commit 2d90f18

Browse files
Merge pull request #788 from ekholabs/fix/iso_net-CLOUDSTACK-8814
CLOUDSTACK-8814 - Refactoring the configuration of Routers and VPC routers nicsHi there, I refactored the configureDefaultNics() method in order to split the implementations for Routers and VPC Routers. The following tests were executed: * test_vm_life_cycle * test_routers * test_vpc_router_nics * test_vpc_routers * test_vpc_offerings @remibergsma @bhaisaab @koushik-das @miguelaferreira @DaanHoogland @karuturi , could you please have a look/test this PR? Thanks in advance. Cheers, Wilder * pr/788: CLOUDSTACK-8814 - Refactoring the configuration of Routers and VPC routers nics Signed-off-by: wilderrodrigues <wrodrigues@schubergphilis.com>
2 parents 28d18dc + 5e9e9b8 commit 2d90f18

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

server/src/com/cloud/network/router/NetworkHelperImpl.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public class NetworkHelperImpl implements NetworkHelper {
109109
@Inject
110110
protected NicDao _nicDao;
111111
@Inject
112-
private NetworkDao _networkDao;
112+
protected NetworkDao _networkDao;
113113
@Inject
114114
protected DomainRouterDao _routerDao;
115115
@Inject
@@ -137,8 +137,6 @@ public class NetworkHelperImpl implements NetworkHelper {
137137
@Inject
138138
private UserIpv6AddressDao _ipv6Dao;
139139
@Inject
140-
private RouterControlHelper _routerControlHelper;
141-
@Inject
142140
protected NetworkOrchestrationService _networkMgr;
143141
@Inject
144142
private UserDao _userDao;
@@ -610,20 +608,22 @@ protected HypervisorType getClusterToStartDomainRouterForOvm(final long podId) {
610608
throw new CloudRuntimeException(errMsg);
611609
}
612610

613-
@Override
614-
public LinkedHashMap<Network, List<? extends NicProfile>> configureDefaultNics(final RouterDeploymentDefinition routerDeploymentDefinition) throws ConcurrentOperationException, InsufficientAddressCapacityException {
615-
616-
final LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
611+
protected LinkedHashMap<Network, List<? extends NicProfile>> configureControlNic(final RouterDeploymentDefinition routerDeploymentDefinition) {
612+
final LinkedHashMap<Network, List<? extends NicProfile>> controlConfig = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
617613

618-
// 1) Control network
619614
s_logger.debug("Adding nic for Virtual Router in Control network ");
620615
final List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
621616
final NetworkOffering controlOffering = offerings.get(0);
622-
final Network controlConfig = _networkMgr.setupNetwork(s_systemAccount, controlOffering, routerDeploymentDefinition.getPlan(), null, null, false).get(0);
617+
final Network controlNic = _networkMgr.setupNetwork(s_systemAccount, controlOffering, routerDeploymentDefinition.getPlan(), null, null, false).get(0);
623618

624-
networks.put(controlConfig, new ArrayList<NicProfile>());
619+
controlConfig.put(controlNic, new ArrayList<NicProfile>());
620+
621+
return controlConfig;
622+
}
623+
624+
protected LinkedHashMap<Network, List<? extends NicProfile>> configurePublicNic(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean hasGuestNic) {
625+
final LinkedHashMap<Network, List<? extends NicProfile>> publicConfig = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
625626

626-
// 2) Public network
627627
if (routerDeploymentDefinition.isPublicNetwork()) {
628628
s_logger.debug("Adding nic for Virtual Router in Public network ");
629629
// if source nat service is supported by the network, get the source
@@ -647,6 +647,11 @@ public LinkedHashMap<Network, List<? extends NicProfile>> configureDefaultNics(f
647647
defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag()));
648648
}
649649

650+
//If guest nic has already been added we will have 2 devices in the list.
651+
if (hasGuestNic) {
652+
defaultNic.setDeviceId(2);
653+
}
654+
650655
final NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
651656
final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(s_systemAccount, publicOffering, routerDeploymentDefinition.getPlan(), null, null, false);
652657
final String publicIp = defaultNic.getIPv4Address();
@@ -657,14 +662,29 @@ public LinkedHashMap<Network, List<? extends NicProfile>> configureDefaultNics(f
657662
s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress());
658663
defaultNic.setMacAddress(peerNic.getMacAddress());
659664
}
660-
networks.put(publicNetworks.get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic)));
665+
publicConfig.put(publicNetworks.get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic)));
661666
}
662667

663-
// 3) Guest Network
668+
return publicConfig;
669+
}
670+
671+
@Override
672+
public LinkedHashMap<Network, List<? extends NicProfile>> configureDefaultNics(final RouterDeploymentDefinition routerDeploymentDefinition) throws ConcurrentOperationException, InsufficientAddressCapacityException {
673+
674+
final LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
675+
676+
// 1) Guest Network
664677
final LinkedHashMap<Network, List<? extends NicProfile>> guestNic = configureGuestNic(routerDeploymentDefinition);
665-
// The guest nic has to be added after the Control and Public nics.
666678
networks.putAll(guestNic);
667679

680+
// 2) Control network
681+
final LinkedHashMap<Network, List<? extends NicProfile>> controlNic = configureControlNic(routerDeploymentDefinition);
682+
networks.putAll(controlNic);
683+
684+
// 3) Public network
685+
final LinkedHashMap<Network, List<? extends NicProfile>> publicNic = configurePublicNic(routerDeploymentDefinition, networks.size() > 1);
686+
networks.putAll(publicNic);
687+
668688
return networks;
669689
}
670690

server/src/com/cloud/network/router/VpcNetworkHelperImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import com.cloud.dc.dao.VlanDao;
3434
import com.cloud.exception.ConcurrentOperationException;
35+
import com.cloud.exception.InsufficientAddressCapacityException;
3536
import com.cloud.exception.InsufficientCapacityException;
3637
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3738
import com.cloud.network.IpAddress;
@@ -153,4 +154,24 @@ public void reallocateRouterNetworks(final RouterDeploymentDefinition vpcRouterD
153154

154155
_itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, vpcRouterDeploymentDefinition.getPlan(), hType);
155156
}
157+
158+
@Override
159+
public LinkedHashMap<Network, List<? extends NicProfile>> configureDefaultNics(final RouterDeploymentDefinition routerDeploymentDefinition) throws ConcurrentOperationException, InsufficientAddressCapacityException {
160+
161+
final LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
162+
163+
// 1) Control network
164+
final LinkedHashMap<Network, List<? extends NicProfile>> controlNic = configureControlNic(routerDeploymentDefinition);
165+
networks.putAll(controlNic);
166+
167+
// 2) Public network
168+
final LinkedHashMap<Network, List<? extends NicProfile>> publicNic = configurePublicNic(routerDeploymentDefinition, false);
169+
networks.putAll(publicNic);
170+
171+
// 3) Guest Network
172+
final LinkedHashMap<Network, List<? extends NicProfile>> guestNic = configureGuestNic(routerDeploymentDefinition);
173+
networks.putAll(guestNic);
174+
175+
return networks;
176+
}
156177
}

0 commit comments

Comments
 (0)