protected LinkedHashMap<Network, List<? extends NicProfile>> configurePublicNic( final RouterDeploymentDefinition routerDeploymentDefinition, final boolean hasGuestNic) { final LinkedHashMap<Network, List<? extends NicProfile>> publicConfig = new LinkedHashMap<Network, List<? extends NicProfile>>(3); 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 // nat ip address final NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); final PublicIp sourceNatIp = routerDeploymentDefinition.getSourceNatIP(); defaultNic.setIPv4Address(sourceNatIp.getAddress().addr()); defaultNic.setIPv4Gateway(sourceNatIp.getGateway()); defaultNic.setIPv4Netmask(sourceNatIp.getNetmask()); defaultNic.setMacAddress(sourceNatIp.getMacAddress()); // get broadcast from public network final Network pubNet = _networkDao.findById(sourceNatIp.getNetworkId()); if (pubNet.getBroadcastDomainType() == BroadcastDomainType.Vxlan) { defaultNic.setBroadcastType(BroadcastDomainType.Vxlan); defaultNic.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag())); defaultNic.setIsolationUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag())); } else { defaultNic.setBroadcastType(BroadcastDomainType.Vlan); defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); 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<? extends Network> publicNetworks = _networkMgr.setupNetwork( s_systemAccount, publicOffering, routerDeploymentDefinition.getPlan(), null, null, false); final String publicIp = defaultNic.getIPv4Address(); // We want to use the identical MAC address for RvR on public // interface if possible final NicVO peerNic = _nicDao.findByIp4AddressAndNetworkId(publicIp, publicNetworks.get(0).getId()); if (peerNic != null) { s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress()); defaultNic.setMacAddress(peerNic.getMacAddress()); } publicConfig.put(publicNetworks.get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic))); } return publicConfig; }
@Override @DB public NicProfile createPrivateNicProfileForGateway( final VpcGateway privateGateway, final VirtualRouter router) { final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId()); PrivateIpVO ipVO = _privateIpDao.allocateIpAddress( privateNetwork.getDataCenterId(), privateNetwork.getId(), privateGateway.getIp4Address()); final Long vpcId = privateGateway.getVpcId(); final Vpc activeVpc = _vpcMgr.getActiveVpc(vpcId); if (activeVpc.isRedundant() && ipVO == null) { ipVO = _privateIpDao.findByIpAndVpcId(vpcId, privateGateway.getIp4Address()); } Nic privateNic = null; if (ipVO != null) { privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId()); } NicProfile privateNicProfile = new NicProfile(); if (privateNic != null) { privateNicProfile = new NicProfile( privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate(privateNetwork.getId(), router.getId()), _networkModel.isSecurityGroupSupportedInNetwork(privateNetwork), _networkModel.getNetworkTag(router.getHypervisorType(), privateNetwork)); if (router.getIsRedundantRouter()) { String newMacAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())); privateNicProfile.setMacAddress(newMacAddress); } } else { final String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr()); final PrivateIpAddress ip = new PrivateIpAddress( ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask, NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()))); final URI netUri = BroadcastDomainType.fromString(ip.getBroadcastUri()); privateNicProfile.setIPv4Address(ip.getIpAddress()); privateNicProfile.setIPv4Gateway(ip.getGateway()); privateNicProfile.setIPv4Netmask(ip.getNetmask()); privateNicProfile.setIsolationUri(netUri); privateNicProfile.setBroadcastUri(netUri); // can we solve this in setBroadcastUri()??? // or more plugable construct is desirable privateNicProfile.setBroadcastType(BroadcastDomainType.getSchemeValue(netUri)); privateNicProfile.setFormat(AddressFormat.Ip4); privateNicProfile.setReservationId(String.valueOf(ip.getBroadcastUri())); privateNicProfile.setMacAddress(ip.getMacAddress()); } return privateNicProfile; }