@Test public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { final Network network = mock(Network.class); when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch); when(network.getId()).thenReturn(NETWORK_ID); final NetworkOffering offering = mock(NetworkOffering.class); when(offering.getId()).thenReturn(NETWORK_ID); when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getGuestType()).thenReturn(GuestType.Isolated); mock(DeployDestination.class); final Domain dom = mock(Domain.class); when(dom.getName()).thenReturn("domain"); final Account acc = mock(Account.class); when(acc.getAccountName()).thenReturn("accountname"); final ReservationContext context = mock(ReservationContext.class); when(context.getDomain()).thenReturn(dom); when(context.getAccount()).thenReturn(acc); }
@Override public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")"); if (!canHandle(network, Network.Service.Connectivity)) { return false; } if (network.getBroadcastUri() == null) { s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); return false; } final List<NiciraNvpDeviceVO> devices = this.niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); final HostVO niciraNvpHost = this.hostDao.findById(niciraNvpDevice.getHostId()); this.hostDao.loadDetails(niciraNvpHost); final Account owner = context.getAccount(); if (this.networkModel.isProviderSupportServiceInNetwork(network.getId(), Network.Service.SourceNat, Network.Provider.NiciraNvp)) { s_logger.debug("Apparently we are supposed to provide SourceNat on this network"); final PublicIp sourceNatIp = this.ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network); final String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask()); final String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1]; String vtag = sourceNatIp.getVlanTag(); BroadcastDomainType tiep = null; try { tiep = BroadcastDomainType.getTypeOf(vtag); } catch (final URISyntaxException use) { throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use); } if (tiep == BroadcastDomainType.Vlan) { vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag)); } else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) { throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag); } final long vlanid = Vlan.UNTAGGED.equals(vtag) ? 0 : Long.parseLong(vtag); final CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName()); final CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) this.agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { s_logger.error("Failed to create Logical Router for network " + network.getDisplayText()); return false; } final NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId()); this.niciraNvpRouterMappingDao.persist(routermapping); } return true; }
NiciraNvpElement extends AdapterBase implements ConnectivityProvider, SourceNatServiceProvider, PortForwardingServiceProvider, StaticNatServiceProvider,
        NiciraNvpElementService, ResourceStateAdapter, IpDeployer { @Override public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")"); if (!canHandle(network, Network.Service.Connectivity)) { return false; } if (network.getBroadcastUri() == null) { s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); return false; } final List<NiciraNvpDeviceVO> devices = this.niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); final HostVO niciraNvpHost = this.hostDao.findById(niciraNvpDevice.getHostId()); this.hostDao.loadDetails(niciraNvpHost); final Account owner = context.getAccount(); if (this.networkModel.isProviderSupportServiceInNetwork(network.getId(), Network.Service.SourceNat, Network.Provider.NiciraNvp)) { s_logger.debug("Apparently we are supposed to provide SourceNat on this network"); final PublicIp sourceNatIp = this.ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network); final String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask()); final String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1]; String vtag = sourceNatIp.getVlanTag(); BroadcastDomainType tiep = null; try { tiep = BroadcastDomainType.getTypeOf(vtag); } catch (final URISyntaxException use) { throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use); } if (tiep == BroadcastDomainType.Vlan) { vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag)); } else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) { throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag); } final long vlanid = Vlan.UNTAGGED.equals(vtag) ? 0 : Long.parseLong(vtag); final CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName()); final CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) this.agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { s_logger.error("Failed to create Logical Router for network " + network.getDisplayText()); return false; } final NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId()); this.niciraNvpRouterMappingDao.persist(routermapping); } return true; } }
NiciraNvpElement extends AdapterBase implements ConnectivityProvider, SourceNatServiceProvider, PortForwardingServiceProvider, StaticNatServiceProvider,
        NiciraNvpElementService, ResourceStateAdapter, IpDeployer { @Override public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")"); if (!canHandle(network, Network.Service.Connectivity)) { return false; } if (network.getBroadcastUri() == null) { s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); return false; } final List<NiciraNvpDeviceVO> devices = this.niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); final HostVO niciraNvpHost = this.hostDao.findById(niciraNvpDevice.getHostId()); this.hostDao.loadDetails(niciraNvpHost); final Account owner = context.getAccount(); if (this.networkModel.isProviderSupportServiceInNetwork(network.getId(), Network.Service.SourceNat, Network.Provider.NiciraNvp)) { s_logger.debug("Apparently we are supposed to provide SourceNat on this network"); final PublicIp sourceNatIp = this.ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network); final String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask()); final String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1]; String vtag = sourceNatIp.getVlanTag(); BroadcastDomainType tiep = null; try { tiep = BroadcastDomainType.getTypeOf(vtag); } catch (final URISyntaxException use) { throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use); } if (tiep == BroadcastDomainType.Vlan) { vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag)); } else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) { throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag); } final long vlanid = Vlan.UNTAGGED.equals(vtag) ? 0 : Long.parseLong(vtag); final CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName()); final CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) this.agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { s_logger.error("Failed to create Logical Router for network " + network.getDisplayText()); return false; } final NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId()); this.niciraNvpRouterMappingDao.persist(routermapping); } return true; }  }
NiciraNvpElement extends AdapterBase implements ConnectivityProvider, SourceNatServiceProvider, PortForwardingServiceProvider, StaticNatServiceProvider,
        NiciraNvpElementService, ResourceStateAdapter, IpDeployer { @Override public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")"); if (!canHandle(network, Network.Service.Connectivity)) { return false; } if (network.getBroadcastUri() == null) { s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); return false; } final List<NiciraNvpDeviceVO> devices = this.niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); final HostVO niciraNvpHost = this.hostDao.findById(niciraNvpDevice.getHostId()); this.hostDao.loadDetails(niciraNvpHost); final Account owner = context.getAccount(); if (this.networkModel.isProviderSupportServiceInNetwork(network.getId(), Network.Service.SourceNat, Network.Provider.NiciraNvp)) { s_logger.debug("Apparently we are supposed to provide SourceNat on this network"); final PublicIp sourceNatIp = this.ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network); final String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask()); final String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1]; String vtag = sourceNatIp.getVlanTag(); BroadcastDomainType tiep = null; try { tiep = BroadcastDomainType.getTypeOf(vtag); } catch (final URISyntaxException use) { throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use); } if (tiep == BroadcastDomainType.Vlan) { vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag)); } else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) { throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag); } final long vlanid = Vlan.UNTAGGED.equals(vtag) ? 0 : Long.parseLong(vtag); final CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName()); final CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) this.agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { s_logger.error("Failed to create Logical Router for network " + network.getDisplayText()); return false; } final NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId()); this.niciraNvpRouterMappingDao.persist(routermapping); } return true; }  @Override Map<Network.Service, Map<Network.Capability, String>> getCapabilities(); @Override Network.Provider getProvider(); @Override boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context); @Override boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context); @Override boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context); @Override boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup); @Override boolean destroy(final Network network, final ReservationContext context); @Override boolean isReady(final PhysicalNetworkServiceProvider provider); @Override boolean shutdownProviderInstances(final PhysicalNetworkServiceProvider provider, final ReservationContext context); @Override boolean canEnableIndividualServices(); @Override boolean verifyServicesCombination(final Set<Network.Service> services); @Override boolean configure(final String name, final Map<String, Object> params); @Override List<Class<?>> getCommands(); @Override @DB NiciraNvpDeviceVO addNiciraNvpDevice(final AddNiciraNvpDeviceCmd cmd); @Override NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(final NiciraNvpDeviceVO niciraNvpDeviceVO); @Override boolean deleteNiciraNvpDevice(final DeleteNiciraNvpDeviceCmd cmd); @Override List<? extends Network> listNiciraNvpDeviceNetworks(final ListNiciraNvpDeviceNetworksCmd cmd); @Override List<NiciraNvpDeviceVO> listNiciraNvpDevices(final ListNiciraNvpDevicesCmd cmd); @Override HostVO createHostVOForConnectedAgent(final HostVO host, final StartupCommand[] cmd); @Override HostVO createHostVOForDirectConnectAgent(final HostVO host, final StartupCommand[] startup, final ServerResource resource, final Map<String, String> details, final
    List<String> hostTags); @Override DeleteHostAnswer deleteHost(final HostVO host, final boolean isForced, final boolean isForceDeleteStorage); @Override IpDeployer getIpDeployer(final Network network); @Override boolean applyIps(final Network network, final List<? extends PublicIpAddress> ipAddress, final Set<Network.Service> services); @Override boolean applyStaticNats(final Network network, final List<? extends StaticNat> rules); @Override boolean applyPFRules(final Network network, final List<PortForwardingRule> rules); }
NiciraNvpElement extends AdapterBase implements ConnectivityProvider, SourceNatServiceProvider, PortForwardingServiceProvider, StaticNatServiceProvider,
        NiciraNvpElementService, ResourceStateAdapter, IpDeployer { @Override public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")"); if (!canHandle(network, Network.Service.Connectivity)) { return false; } if (network.getBroadcastUri() == null) { s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); return false; } final List<NiciraNvpDeviceVO> devices = this.niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); final HostVO niciraNvpHost = this.hostDao.findById(niciraNvpDevice.getHostId()); this.hostDao.loadDetails(niciraNvpHost); final Account owner = context.getAccount(); if (this.networkModel.isProviderSupportServiceInNetwork(network.getId(), Network.Service.SourceNat, Network.Provider.NiciraNvp)) { s_logger.debug("Apparently we are supposed to provide SourceNat on this network"); final PublicIp sourceNatIp = this.ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network); final String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask()); final String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1]; String vtag = sourceNatIp.getVlanTag(); BroadcastDomainType tiep = null; try { tiep = BroadcastDomainType.getTypeOf(vtag); } catch (final URISyntaxException use) { throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use); } if (tiep == BroadcastDomainType.Vlan) { vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag)); } else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) { throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag); } final long vlanid = Vlan.UNTAGGED.equals(vtag) ? 0 : Long.parseLong(vtag); final CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName()); final CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) this.agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { s_logger.error("Failed to create Logical Router for network " + network.getDisplayText()); return false; } final NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId()); this.niciraNvpRouterMappingDao.persist(routermapping); } return true; }  @Override Map<Network.Service, Map<Network.Capability, String>> getCapabilities(); @Override Network.Provider getProvider(); @Override boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context); @Override boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context); @Override boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context); @Override boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup); @Override boolean destroy(final Network network, final ReservationContext context); @Override boolean isReady(final PhysicalNetworkServiceProvider provider); @Override boolean shutdownProviderInstances(final PhysicalNetworkServiceProvider provider, final ReservationContext context); @Override boolean canEnableIndividualServices(); @Override boolean verifyServicesCombination(final Set<Network.Service> services); @Override boolean configure(final String name, final Map<String, Object> params); @Override List<Class<?>> getCommands(); @Override @DB NiciraNvpDeviceVO addNiciraNvpDevice(final AddNiciraNvpDeviceCmd cmd); @Override NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(final NiciraNvpDeviceVO niciraNvpDeviceVO); @Override boolean deleteNiciraNvpDevice(final DeleteNiciraNvpDeviceCmd cmd); @Override List<? extends Network> listNiciraNvpDeviceNetworks(final ListNiciraNvpDeviceNetworksCmd cmd); @Override List<NiciraNvpDeviceVO> listNiciraNvpDevices(final ListNiciraNvpDevicesCmd cmd); @Override HostVO createHostVOForConnectedAgent(final HostVO host, final StartupCommand[] cmd); @Override HostVO createHostVOForDirectConnectAgent(final HostVO host, final StartupCommand[] startup, final ServerResource resource, final Map<String, String> details, final
    List<String> hostTags); @Override DeleteHostAnswer deleteHost(final HostVO host, final boolean isForced, final boolean isForceDeleteStorage); @Override IpDeployer getIpDeployer(final Network network); @Override boolean applyIps(final Network network, final List<? extends PublicIpAddress> ipAddress, final Set<Network.Service> services); @Override boolean applyStaticNats(final Network network, final List<? extends StaticNat> rules); @Override boolean applyPFRules(final Network network, final List<PortForwardingRule> rules);  }