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);
}
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);
}
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;
}
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());
}
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;
}
Aggregations