NiciraNvpGuestNetworkGuru extends GuestNetworkGuru { @Override public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) { final PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId()); final DataCenter dc = _dcDao.findById(plan.getDataCenterId()); if (!canHandle(offering, dc.getNetworkType(), physnet)) { s_logger.debug("Refusing to design this network"); return null; } final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(physnet.getId()); if (devices.isEmpty()) { s_logger.error("No NiciraNvp Controller on physical network " + physnet.getName()); return null; } final NiciraNvpDeviceVO niciraNvpDeviceVO = devices.get(0); s_logger.debug("Nicira Nvp " + niciraNvpDeviceVO.getUuid() + " found on physical network " + physnet.getId()); checkThatLogicalSwitchExists(userSpecified, niciraNvpDeviceVO); s_logger.debug("Physical isolation type is supported, asking GuestNetworkGuru to design this network"); final NetworkVO networkObject = (NetworkVO) super.design(offering, plan, userSpecified, owner); if (networkObject == null) { return null; } networkObject.setBroadcastDomainType(BroadcastDomainType.Lswitch); return networkObject; } NiciraNvpGuestNetworkGuru(); @Override Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner); @Override Network implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context); @Override void reserve(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context); @Override boolean release(final NicProfile nic, final VirtualMachineProfile vm, final String reservationId); @Override void shutdown(final NetworkProfile profile, final NetworkOffering offering); @Override boolean trash(final Network network, final NetworkOffering offering);  }
@Test public void testDesign() { final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); when(physnetdao.findById((Long)any())).thenReturn(physnet); when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] {"STT", "VXLAN"})); when(physnet.getId()).thenReturn(NETWORK_ID); final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class); when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] {device})); when(device.getId()).thenReturn(1L); final NetworkOffering offering = mock(NetworkOffering.class); when(offering.getId()).thenReturn(NETWORK_ID); when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getGuestType()).thenReturn(GuestType.Isolated); when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(true); final DeploymentPlan plan = mock(DeploymentPlan.class); final Network network = mock(Network.class); final Account account = mock(Account.class); final Network designednetwork = guru.design(offering, plan, network, account); assertTrue(designednetwork != null); assertTrue(designednetwork.getBroadcastDomainType() == BroadcastDomainType.Lswitch); }
@Test public void testDesignNoElementOnPhysicalNetwork() { final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); when(physnetdao.findById((Long)any())).thenReturn(physnet); when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] {"STT", "VXLAN"})); when(physnet.getId()).thenReturn(NETWORK_ID); mock(NiciraNvpDeviceVO.class); when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NiciraNvpDeviceVO> 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 = guru.design(offering, plan, network, account); assertTrue(designednetwork == null); }
@Test public void testDesignNoIsolationMethodSTT() { final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); when(physnetdao.findById((Long)any())).thenReturn(physnet); when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] {"VLAN"})); when(physnet.getId()).thenReturn(NETWORK_ID); mock(NiciraNvpDeviceVO.class); when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NiciraNvpDeviceVO> 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 = guru.design(offering, plan, network, account); assertTrue(designednetwork == null); }
@Test public void testDesignNoConnectivityInOffering() { final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); when(physnetdao.findById((Long)any())).thenReturn(physnet); when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] {"STT", "VXLAN"})); when(physnet.getId()).thenReturn(NETWORK_ID); final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class); when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] {device})); when(device.getId()).thenReturn(1L); final NetworkOffering offering = mock(NetworkOffering.class); when(offering.getId()).thenReturn(NETWORK_ID); when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getGuestType()).thenReturn(GuestType.Isolated); when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false); final DeploymentPlan plan = mock(DeploymentPlan.class); final Network network = mock(Network.class); final Account account = mock(Account.class); final Network designednetwork = guru.design(offering, plan, network, account); assertTrue(designednetwork == null); }