Search in sources :

Example 6 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class NuageVspGuestNetworkGuruTest method testCanHandle.

@Test
public void testCanHandle() {
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getIsPersistent()).thenReturn(false);
    when(_configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(false);
    when(_networkOfferingServiceMapDao.canProviderSupportServiceInNetworkOffering(NETWORK_ID, Service.Connectivity, Network.Provider.NuageVsp)).thenReturn(true);
    when(_networkOfferingServiceMapDao.canProviderSupportServiceInNetworkOffering(NETWORK_ID, Service.SourceNat, Network.Provider.NuageVsp)).thenReturn(true);
    when(_networkModel.getNetworkOfferingServiceProvidersMap(NETWORK_ID)).thenReturn(ImmutableMap.of(Service.Connectivity, Sets.newSet(Network.Provider.NuageVsp), Service.SourceNat, Sets.newSet(Network.Provider.NuageVsp)));
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    assertThat(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Advanced, physnet), is(true));
    // Not supported TrafficType != Guest
    when(offering.getTrafficType()).thenReturn(TrafficType.Management);
    assertThat(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Advanced, physnet), is(false));
    // Supported: GuestType Shared
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Shared);
    assertThat(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Advanced, physnet), is(true));
    // Not supported: Basic networking
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    assertThat(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Basic, physnet), is(false));
    // Not supported: IsolationMethod != STT
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList("VLAN"));
    assertThat(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Basic, physnet), is(false));
    // Not supported: Non-persistent VPC tier
    when(_configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(true);
    assertFalse(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Advanced, physnet));
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 7 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class NuageVspGuestNetworkGuruTest method testDesignNoElementOnPhysicalNetwork.

@Test
public void testDesignNoElementOnPhysicalNetwork() {
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList("STT"));
    when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NuageVspDeviceVO>emptyList());
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    final DeploymentPlan plan = mock(DeploymentPlan.class);
    final Network network = mock(Network.class);
    final Account account = mock(Account.class);
    final Network designednetwork = _nuageVspGuestNetworkGuru.design(offering, plan, network, account);
    assertTrue(designednetwork == null);
}
Also used : Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) DeploymentPlan(com.cloud.deploy.DeploymentPlan) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 8 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class NuageVspGuestNetworkGuruTest method testImplementNetwork.

@Test
public void testImplementNetwork() throws URISyntaxException, InsufficientVirtualNetworkCapacityException {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getUuid()).thenReturn("aaaaaa");
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(network.getAccountId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(network.getState()).thenReturn(com.cloud.network.Network.State.Implementing);
    when(network.getTrafficType()).thenReturn(TrafficType.Guest);
    when(network.getMode()).thenReturn(Mode.Static);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vsp);
    when(network.getBroadcastUri()).thenReturn(new URI("vsp://aaaaaa-aavvv/10.1.1.1"));
    when(network.getGateway()).thenReturn("10.1.1.1");
    when(network.getCidr()).thenReturn("10.1.1.0/24");
    when(network.getName()).thenReturn("iso");
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getTags()).thenReturn("aaaa");
    when(offering.getEgressDefaultPolicy()).thenReturn(true);
    when(_networkModel.findPhysicalNetworkId(NETWORK_ID, "aaa", TrafficType.Guest)).thenReturn(NETWORK_ID);
    final ReservationContext reserveContext = mock(ReservationContext.class);
    final Domain domain = mock(Domain.class);
    when(domain.getId()).thenReturn(NETWORK_ID);
    when(reserveContext.getDomain()).thenReturn(domain);
    when(domain.getName()).thenReturn("aaaaa");
    final Account account = mock(Account.class);
    when(account.getId()).thenReturn(NETWORK_ID);
    when(account.getAccountId()).thenReturn(NETWORK_ID);
    when(reserveContext.getAccount()).thenReturn(account);
    final DomainVO domainVo = mock(DomainVO.class);
    when(_domainDao.findById(NETWORK_ID)).thenReturn(domainVo);
    final AccountVO accountVo = mock(AccountVO.class);
    when(_accountDao.findById(NETWORK_ID)).thenReturn(accountVo);
    when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
    when(_nuageVspManager.getDnsDetails(network.getDataCenterId())).thenReturn(new ArrayList<String>());
    when(_nuageVspManager.getGatewaySystemIds()).thenReturn(new ArrayList<String>());
    final DataCenter dc = mock(DataCenter.class);
    when(dc.getId()).thenReturn(NETWORK_ID);
    final DeployDestination deployDest = mock(DeployDestination.class);
    when(deployDest.getDataCenter()).thenReturn(dc);
    _nuageVspGuestNetworkGuru.implement(network, offering, deployDest, reserveContext);
}
Also used : Account(com.cloud.user.Account) DomainVO(com.cloud.domain.DomainVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) Domain(com.cloud.domain.Domain) URI(java.net.URI) AccountVO(com.cloud.user.AccountVO) ReservationContext(com.cloud.vm.ReservationContext) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 9 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class VpcNetworkHelperImpl method reallocateRouterNetworks.

@Override
public void reallocateRouterNetworks(final RouterDeploymentDefinition vpcRouterDeploymentDefinition, final VirtualRouter router, final VMTemplateVO template, final HypervisorType hType) throws ConcurrentOperationException, InsufficientCapacityException {
    final TreeSet<String> publicVlans = new TreeSet<String>();
    publicVlans.add(vpcRouterDeploymentDefinition.getSourceNatIP().getVlanTag());
    //1) allocate nic for control and source nat public ip
    final LinkedHashMap<Network, List<? extends NicProfile>> networks = configureDefaultNics(vpcRouterDeploymentDefinition);
    final Long vpcId = vpcRouterDeploymentDefinition.getVpc().getId();
    //2) allocate nic for private gateways if needed
    final List<PrivateGateway> privateGateways = vpcMgr.getVpcPrivateGateways(vpcId);
    if (privateGateways != null && !privateGateways.isEmpty()) {
        for (final PrivateGateway privateGateway : privateGateways) {
            final NicProfile privateNic = nicProfileHelper.createPrivateNicProfileForGateway(privateGateway, router);
            final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
            networks.put(privateNetwork, new ArrayList<NicProfile>(Arrays.asList(privateNic)));
        }
    }
    //3) allocate nic for guest gateway if needed
    final List<? extends Network> guestNetworks = vpcMgr.getVpcNetworks(vpcId);
    for (final Network guestNetwork : guestNetworks) {
        if (_networkModel.isPrivateGateway(guestNetwork.getId())) {
            continue;
        }
        if (guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup) {
            final NicProfile guestNic = nicProfileHelper.createGuestNicProfileForVpcRouter(vpcRouterDeploymentDefinition, guestNetwork);
            networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
        }
    }
    //4) allocate nic for additional public network(s)
    final List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(vpcId, false);
    final List<NicProfile> publicNics = new ArrayList<NicProfile>();
    Network publicNetwork = null;
    for (final IPAddressVO ip : ips) {
        final PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
        if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) && vpcMgr.isIpAllocatedToVpc(ip) && !publicVlans.contains(publicIp.getVlanTag())) {
            s_logger.debug("Allocating nic for router in vlan " + publicIp.getVlanTag());
            final NicProfile publicNic = new NicProfile();
            publicNic.setDefaultNic(false);
            publicNic.setIPv4Address(publicIp.getAddress().addr());
            publicNic.setIPv4Gateway(publicIp.getGateway());
            publicNic.setIPv4Netmask(publicIp.getNetmask());
            publicNic.setMacAddress(publicIp.getMacAddress());
            publicNic.setBroadcastType(BroadcastDomainType.Vlan);
            publicNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag()));
            publicNic.setIsolationUri(IsolationType.Vlan.toUri(publicIp.getVlanTag()));
            final NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
            if (publicNetwork == null) {
                final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(s_systemAccount, publicOffering, vpcRouterDeploymentDefinition.getPlan(), null, null, false);
                publicNetwork = publicNetworks.get(0);
            }
            publicNics.add(publicNic);
            publicVlans.add(publicIp.getVlanTag());
        }
    }
    if (publicNetwork != null) {
        if (networks.get(publicNetwork) != null) {
            @SuppressWarnings("unchecked") final List<NicProfile> publicNicProfiles = (List<NicProfile>) networks.get(publicNetwork);
            publicNicProfiles.addAll(publicNics);
            networks.put(publicNetwork, publicNicProfiles);
        } else {
            networks.put(publicNetwork, publicNics);
        }
    }
    final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(vpcRouterDeploymentDefinition.getServiceOfferingId());
    _itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, vpcRouterDeploymentDefinition.getPlan(), hType);
}
Also used : PublicIp(com.cloud.network.addr.PublicIp) NetworkOffering(com.cloud.offering.NetworkOffering) ArrayList(java.util.ArrayList) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) PrivateGateway(com.cloud.network.vpc.PrivateGateway) TreeSet(java.util.TreeSet) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 10 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class NetworkHelperImpl method configurePublicNic.

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;
}
Also used : PublicIp(com.cloud.network.addr.PublicIp) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

NetworkOffering (com.cloud.offering.NetworkOffering)94 Network (com.cloud.network.Network)51 Account (com.cloud.user.Account)41 Test (org.junit.Test)34 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)27 ArrayList (java.util.ArrayList)24 DataCenter (com.cloud.dc.DataCenter)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)23 NetworkVO (com.cloud.network.dao.NetworkVO)22 DeployDestination (com.cloud.deploy.DeployDestination)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 HostVO (com.cloud.host.HostVO)17 ReservationContext (com.cloud.vm.ReservationContext)17 Domain (com.cloud.domain.Domain)16 IPAddressVO (com.cloud.network.dao.IPAddressVO)13 List (java.util.List)13 NicProfile (com.cloud.vm.NicProfile)12 DeploymentPlan (com.cloud.deploy.DeploymentPlan)11 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)11 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)11