use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.
the class NiciraNvpElementTest method implementSharedNetworkUuidVlanIdTest.
@Test
public void implementSharedNetworkUuidVlanIdTest() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
// SHARED NETWORKS CASE 1: LOGICAL ROUTER'S UUID AS VLAN ID
final Network network = mock(Network.class);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getGuestType()).thenReturn(GuestType.Shared);
when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
HostVO niciraNvpHost = mock(HostVO.class);
when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
final NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Shared);
final DeployDestination dest = 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);
//SHARED NETWORKS CASE 1
when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(true);
when(network.getCidr()).thenReturn(NETWORK_CIDR);
when(network.getGateway()).thenReturn(NETWORK_GATEWAY);
NiciraNvpRouterMappingVO mapping = mock(NiciraNvpRouterMappingVO.class);
when(mapping.getLogicalRouterUuid()).thenReturn("xxxx-xxxx-xxxx");
when(niciraNvpRouterMappingDao.findByNetworkId(NETWORK_ID)).thenReturn(mapping);
final ConfigureSharedNetworkUuidAnswer answer = mock(ConfigureSharedNetworkUuidAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NICIRA_NVP_HOST_ID), (Command) any())).thenReturn(answer);
assertTrue(element.implement(network, offering, dest, context));
}
use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.
the class NiciraNvpElementTest method applyIpTest.
@Test
public void applyIpTest() throws ResourceUnavailableException {
final Network network = mock(Network.class);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getPhysicalNetworkId()).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);
final List<PublicIpAddress> ipAddresses = new ArrayList<PublicIpAddress>();
final PublicIpAddress pipReleased = mock(PublicIpAddress.class);
final PublicIpAddress pipAllocated = mock(PublicIpAddress.class);
final Ip ipReleased = new Ip("42.10.10.10");
final Ip ipAllocated = new Ip("10.10.10.10");
when(pipAllocated.getState()).thenReturn(IpAddress.State.Allocated);
when(pipAllocated.getAddress()).thenReturn(ipAllocated);
when(pipAllocated.getNetmask()).thenReturn("255.255.255.0");
when(pipReleased.getState()).thenReturn(IpAddress.State.Releasing);
when(pipReleased.getAddress()).thenReturn(ipReleased);
when(pipReleased.getNetmask()).thenReturn("255.255.255.0");
ipAddresses.add(pipAllocated);
ipAddresses.add(pipReleased);
final Set<Service> services = new HashSet<Service>();
services.add(Service.SourceNat);
services.add(Service.StaticNat);
services.add(Service.PortForwarding);
final List<NiciraNvpDeviceVO> deviceList = new ArrayList<NiciraNvpDeviceVO>();
final NiciraNvpDeviceVO nndVO = mock(NiciraNvpDeviceVO.class);
final NiciraNvpRouterMappingVO nnrmVO = mock(NiciraNvpRouterMappingVO.class);
when(niciraNvpRouterMappingDao.findByNetworkId(NETWORK_ID)).thenReturn(nnrmVO);
when(nnrmVO.getLogicalRouterUuid()).thenReturn("abcde");
when(nndVO.getHostId()).thenReturn(NETWORK_ID);
final HostVO hvo = mock(HostVO.class);
when(hvo.getId()).thenReturn(NETWORK_ID);
when(hvo.getDetail("l3gatewayserviceuuid")).thenReturn("abcde");
when(hostDao.findById(NETWORK_ID)).thenReturn(hvo);
deviceList.add(nndVO);
when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(deviceList);
final ConfigurePublicIpsOnLogicalRouterAnswer answer = mock(ConfigurePublicIpsOnLogicalRouterAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), any(ConfigurePublicIpsOnLogicalRouterCommand.class))).thenReturn(answer);
assertTrue(element.applyIps(network, ipAddresses, services));
verify(agentManager, atLeast(1)).easySend(eq(NETWORK_ID), argThat(new ArgumentMatcher<ConfigurePublicIpsOnLogicalRouterCommand>() {
@Override
public boolean matches(final Object argument) {
final ConfigurePublicIpsOnLogicalRouterCommand command = (ConfigurePublicIpsOnLogicalRouterCommand) argument;
if (command.getPublicCidrs().size() == 1)
return true;
return false;
}
}));
}
use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.
the class NiciraNvpGuestNetworkGuru method finalizeNetworkDesign.
@Override
public void finalizeNetworkDesign(long networkId, String vlanIdAsUUID) {
if (vlanIdAsUUID == null)
return;
NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(vlanIdAsUUID, networkId);
niciraNvpRouterMappingDao.persist(routermapping);
}
use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.
the class NiciraNvpElement method sharedNetworkSupportUUIDVlanId.
private boolean sharedNetworkSupportUUIDVlanId(Network network, String lSwitchUuid, String ownerName, HostVO niciraNvpHost) {
String networkCidr = network.getCidr();
String vlanGateway = network.getGateway();
String portIpAddress = createLogicalRouterPortIpAddress(networkCidr, vlanGateway);
NiciraNvpRouterMappingVO mapRouterNetwork = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
String lRouterUuid = mapRouterNetwork.getLogicalRouterUuid();
ConfigureSharedNetworkUuidCommand cmd = new ConfigureSharedNetworkUuidCommand(lRouterUuid, lSwitchUuid, portIpAddress, ownerName, network.getId());
ConfigureSharedNetworkUuidAnswer answer = (ConfigureSharedNetworkUuidAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer.getResult() == false) {
s_logger.error("Failed to configure Logical Router for Shared network " + network.getDisplayText());
return false;
}
return true;
}
use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.
the class NiciraNvpElement method applyStaticNats.
/**
* From interface StaticNatServiceProvider
*/
@Override
public boolean applyStaticNats(Network network, List<? extends StaticNat> rules) throws ResourceUnavailableException {
if (!canHandle(network, Service.StaticNat)) {
return false;
}
List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
if (routermapping == null) {
s_logger.error("No logical router uuid found for network " + network.getDisplayText());
return false;
}
List<StaticNatRuleTO> staticNatRules = new ArrayList<StaticNatRuleTO>();
for (StaticNat rule : rules) {
IpAddress sourceIp = networkModel.getIp(rule.getSourceIpAddressId());
// Force the nat rule into the StaticNatRuleTO, no use making a new TO object
// we only need the source and destination ip. Unfortunately no mention if a rule
// is new.
StaticNatRuleTO ruleTO = new StaticNatRuleTO(1, sourceIp.getAddress().addr(), MIN_PORT, MAX_PORT, rule.getDestIpAddress(), MIN_PORT, MAX_PORT, "any", rule.isForRevoke(), false);
staticNatRules.add(ruleTO);
}
ConfigureStaticNatRulesOnLogicalRouterCommand cmd = new ConfigureStaticNatRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), staticNatRules);
ConfigureStaticNatRulesOnLogicalRouterAnswer answer = (ConfigureStaticNatRulesOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
return answer.getResult();
}
Aggregations