Search in sources :

Example 6 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class VxlanGuestNetworkGuruTest method testDesign.

@Test
public void testDesign() {
    PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById(anyLong())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
    when(physnet.getId()).thenReturn(42L);
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(42L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    DeploymentPlan plan = mock(DeploymentPlan.class);
    Network network = mock(Network.class);
    Account account = mock(Account.class);
    Network designednetwork = guru.design(offering, plan, network, account);
    assertTrue(designednetwork != null);
    assertTrue(designednetwork.getBroadcastDomainType() == BroadcastDomainType.Vxlan);
}
Also used : Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeploymentPlan(com.cloud.deploy.DeploymentPlan) Test(org.junit.Test)

Example 7 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class VxlanGuestNetworkGuruTest method testImplement.

@Test
public void testImplement() throws InsufficientVirtualNetworkCapacityException {
    PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById(anyLong())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
    when(physnet.getId()).thenReturn(42L);
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(42L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(42L);
    DeployDestination dest = mock(DeployDestination.class);
    DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
    //TODO(VXLAN): doesn't support VNI specified
    //when(confsvr.getConfigValue((String) any(), (String) any(), anyLong())).thenReturn("true");
    when(dcdao.allocateVnet(anyLong(), anyLong(), anyLong(), (String) any(), eq(true))).thenReturn("42");
    doNothing().when(guru).allocateVnetComplete((Network) any(), (NetworkVO) any(), anyLong(), anyLong(), (String) any(), eq("42"));
    Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork != null);
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 8 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class GuestNetworkGuru method getVlanOffset.

public int getVlanOffset(final long physicalNetworkId, final int vlanTag) {
    final PhysicalNetworkVO pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (pNetwork == null) {
        throw new CloudRuntimeException("Could not find the physical Network " + physicalNetworkId + ".");
    }
    if (pNetwork.getVnet() == null) {
        throw new CloudRuntimeException("Could not find vlan range for physical Network " + physicalNetworkId + ".");
    }
    Integer lowestVlanTag = null;
    final List<Pair<Integer, Integer>> vnetList = pNetwork.getVnet();
    //finding the vlanrange in which the vlanTag lies.
    for (final Pair<Integer, Integer> vnet : vnetList) {
        if (vlanTag >= vnet.first() && vlanTag <= vnet.second()) {
            lowestVlanTag = vnet.first();
        }
    }
    if (lowestVlanTag == null) {
        throw new InvalidParameterValueException("The vlan tag does not belong to any of the existing vlan ranges");
    }
    return vlanTag - lowestVlanTag;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Pair(com.cloud.utils.Pair)

Example 9 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class OpenDaylightControllerResourceManagerImpl method deleteController.

@Override
public void deleteController(DeleteOpenDaylightControllerCmd cmd) throws InvalidParameterValueException {
    OpenDaylightControllerVO controller = openDaylightControllerMappingDao.findById(cmd.getId());
    if (controller == null) {
        throw new InvalidParameterValueException("No ODL Controller with id " + cmd.getId());
    }
    // Find the physical network we work for
    Long physicalNetworkId = controller.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork != null) {
        // Lets see if there are networks that use us
        List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
        if (networkList != null) {
            // Networks with broadcast type lswitch are ours
            for (NetworkVO network : networkList) {
                if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.OpenDaylight) {
                    if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
                        throw new CloudRuntimeException("This Controller can not be deleted as there are one or more logical networks provisioned by cloudstack.");
                    }
                }
            }
        }
    }
    HostVO host = hostDao.findById(controller.getHostId());
    Long hostId = host.getId();
    host.setResourceState(ResourceState.Maintenance);
    hostDao.update(hostId, host);
    resourceManager.deleteHost(hostId, false, false);
    openDaylightControllerMappingDao.remove(cmd.getId());
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO) HostVO(com.cloud.host.HostVO)

Example 10 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class ContrailManagerImpl method findSystemNetworks.

@Override
public List<NetworkVO> findSystemNetworks(List<TrafficType> types) {
    SearchBuilder<NetworkVO> searchBuilder = _networksDao.createSearchBuilder();
    searchBuilder.and("trafficType", searchBuilder.entity().getTrafficType(), Op.IN);
    SearchCriteria<NetworkVO> sc = searchBuilder.create();
    if (types == null || types.isEmpty()) {
        types = new ArrayList<TrafficType>();
        types.add(TrafficType.Control);
        types.add(TrafficType.Management);
        types.add(TrafficType.Public);
        types.add(TrafficType.Storage);
    }
    sc.setParameters("trafficType", types.toArray());
    List<NetworkVO> dbNets = _networksDao.search(sc, null);
    if (dbNets == null) {
        s_logger.debug("no system networks for the given traffic types: " + types.toString());
        dbNets = new ArrayList<NetworkVO>();
    }
    List<PhysicalNetworkVO> phys_list = _physicalNetworkDao.listAll();
    final String provider = Provider.JuniperContrailRouter.getName();
    for (Iterator<PhysicalNetworkVO> iter = phys_list.iterator(); iter.hasNext(); ) {
        PhysicalNetworkVO phys = iter.next();
        if (_physProviderDao.findByServiceProvider(phys.getId(), provider) != null) {
            List<NetworkVO> infraNets = new ArrayList<NetworkVO>();
            findInfrastructureNetworks(phys, infraNets);
            for (NetworkVO net : infraNets) {
                if (types == null || types.isEmpty()) {
                    if (!dbNets.contains(net)) {
                        dbNets.add(net);
                    }
                    continue;
                }
                for (TrafficType type : types) {
                    if (net.getTrafficType() == type) {
                        if (!dbNets.contains(net)) {
                            dbNets.add(net);
                        }
                        break;
                    }
                }
            }
        }
    }
    return dbNets;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList) TrafficType(com.cloud.network.Networks.TrafficType)

Aggregations

PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)112 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)50 ArrayList (java.util.ArrayList)40 NetworkVO (com.cloud.network.dao.NetworkVO)35 HostVO (com.cloud.host.HostVO)28 Test (org.junit.Test)28 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 Account (com.cloud.user.Account)25 DataCenter (com.cloud.dc.DataCenter)22 NetworkOffering (com.cloud.offering.NetworkOffering)22 Network (com.cloud.network.Network)18 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)18 Host (com.cloud.host.Host)15 DB (com.cloud.utils.db.DB)15 ConfigurationException (javax.naming.ConfigurationException)14 HashMap (java.util.HashMap)12 DataCenterVO (com.cloud.dc.DataCenterVO)11 Domain (com.cloud.domain.Domain)11 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)10