use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder in project genius by opendaylight.
the class IdManagerTest method testAllocateIdBlockFromReleasedIds.
@Test
public void testAllocateIdBlockFromReleasedIds() throws Exception {
CreateIdPoolInput createIdPoolInput = new CreateIdPoolInputBuilder().setHigh(ID_HIGH).setLow(ID_LOW).setPoolName(ID_POOL_NAME).build();
AllocateIdInput allocateIdInput = new AllocateIdInputBuilder().setIdKey(TEST_KEY2).setPoolName(ID_POOL_NAME).build();
idManagerService.createIdPool(createIdPoolInput);
idManagerService.allocateId(allocateIdInput);
coordinatorEventsWaiter.awaitEventsConsumption();
asyncEventsWaiter.awaitEventsConsumption();
String localPoolName = idUtils.getLocalPoolName(ID_POOL_NAME);
IdPool parentIdPool = new IdPoolBuilder().setPoolName(ID_POOL_NAME).setKey(new IdPoolKey(ID_POOL_NAME)).setAvailableIdsHolder(createAvailableIdHolder(ID_LOW, ID_HIGH, ID_HIGH + 1)).setReleasedIdsHolder(createReleaseIdHolder(Arrays.asList(1L, 2L, 3L))).build();
IdPool childPool = new IdPoolBuilder().setPoolName(localPoolName).setKey(new IdPoolKey(localPoolName)).setAvailableIdsHolder(createAvailableIdHolder(0L, 9L, 10L)).build();
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
tx.merge(LogicalDatastoreType.CONFIGURATION, getIdPoolIdentifier(ID_POOL_NAME), parentIdPool);
tx.merge(LogicalDatastoreType.CONFIGURATION, getIdPoolIdentifier(localPoolName), childPool);
tx.submit().get();
AllocateIdInput allocateIdInput2 = new AllocateIdInputBuilder().setIdKey(TEST_KEY1).setPoolName(ID_POOL_NAME).build();
assertEquals(idManagerService.allocateId(allocateIdInput2).get().getResult().getIdValue().longValue(), 1L);
coordinatorEventsWaiter.awaitEventsConsumption();
validateIdPools(ExpectedAllocateIdFromReleasedId.idPoolParent(), ExpectedAllocateIdFromReleasedId.idPoolChild());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder in project genius by opendaylight.
the class IdManagerTest method testAllocateId.
@Test
public void testAllocateId() throws Exception {
CreateIdPoolInput createIdPoolInput = new CreateIdPoolInputBuilder().setHigh(ID_HIGH).setLow(ID_LOW).setPoolName(ID_POOL_NAME).build();
AllocateIdInput allocateIdInput = new AllocateIdInputBuilder().setIdKey(TEST_KEY1).setPoolName(ID_POOL_NAME).build();
idManagerService.createIdPool(createIdPoolInput);
assertEquals(idManagerService.allocateId(allocateIdInput).get().getResult().getIdValue().longValue(), 0L);
coordinatorEventsWaiter.awaitEventsConsumption();
validateIdPools(ExpectedAllocateIdObjects.idPoolParent(), ExpectedAllocateIdObjects.idPoolChild());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder in project genius by opendaylight.
the class IdManagerTest method requestIdsConcurrently.
// OK as exceptionInExecutor can't be Exception & AssertionFailedError
@SuppressWarnings("checkstyle:IllegalThrows")
private void requestIdsConcurrently(boolean isSameKey) throws Throwable {
int numberOfTasks = 3;
CountDownLatch latch = new CountDownLatch(numberOfTasks);
Set<Long> idSet = Sets.newConcurrentHashSet();
ExecutorService executor = Executors.newCachedThreadPool("requestIdsConcurrently()", LOG);
AtomicReference<Throwable> exceptionInExecutorAtomic = new AtomicReference<>();
for (int i = 0; i < numberOfTasks; i++) {
final String idKey;
if (isSameKey) {
idKey = TEST_KEY1;
} else {
idKey = TEST_KEY1 + i;
}
executor.execute(() -> {
// Any exception thrown inside this background thread will not cause the test to fail
// so you cannot use assert* here but must set the exceptionInExecutor which is checked after
Future<RpcResult<AllocateIdOutput>> result;
result = idManagerService.allocateId(new AllocateIdInputBuilder().setPoolName(ID_POOL_NAME).setIdKey(idKey).build());
try {
if (result.get().isSuccessful()) {
Long idValue = result.get().getResult().getIdValue();
idSet.add(idValue);
if (idValue > ID_LOW + BLOCK_SIZE) {
exceptionInExecutorAtomic.set(new AssertionFailedError("idValue <= ID_LOW + BLOCK_SIZE"));
}
} else {
RpcError error = result.get().getErrors().iterator().next();
if (!error.getCause().getMessage().contains("Ids exhausted for pool : " + ID_POOL_NAME)) {
exceptionInExecutorAtomic.set(error.getCause());
}
}
} catch (InterruptedException | ExecutionException e) {
exceptionInExecutorAtomic.set(e);
} finally {
latch.countDown();
}
});
}
if (!latch.await(13, SECONDS)) {
fail("latch.await(13, SECONDS) timed out :(");
}
Throwable exceptionInExecutor = exceptionInExecutorAtomic.get();
if (exceptionInExecutor != null) {
throw exceptionInExecutor;
}
if (isSameKey) {
assertEquals(1, idSet.size());
} else {
assertEquals(numberOfTasks, idSet.size());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder in project genius by opendaylight.
the class ItmInternalTunnelAddTest method testBuild_all_tunnels_Boyhtype.
@Test
public void testBuild_all_tunnels_Boyhtype() {
AllocateIdInput getIdInput1 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME).setIdKey("1:phy0:100:192.168.56.101:192.168.56.102:VXLAN").build();
AllocateIdInput getIdInput2 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME).setIdKey("1:phy0:100:192.168.56.102:192.168.56.101:GRE").build();
doReturn(idOutputOptional1).when(idManagerService).allocateId(getIdInput1);
doReturn(idOutputOptional2).when(idManagerService).allocateId(getIdInput2);
trunkInterfaceName1 = ItmUtils.getTrunkInterfaceName(parentInterfaceName, tepIp1, tepIp2, tunnelType1.getName());
trunkInterfaceName2 = ItmUtils.getTrunkInterfaceName(parentInterfaceName, tepIp2, tepIp1, tunnelType2.getName());
internalTunnel1 = ItmUtils.buildInternalTunnel(dpId1, dpId2, tunnelType1, trunkInterfaceName1);
internalTunnel2 = ItmUtils.buildInternalTunnel(dpId2, dpId1, tunnelType2, trunkInterfaceName2);
itmInternalTunnelAddWorker.buildAllTunnels(mdsalApiManager, cfgdDpnListVxlan, meshDpnListGre);
verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION, internalTunnelIdentifierVxlan1, internalTunnel1, true);
verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION, internalTunnelIdentifierGre2, internalTunnel2, true);
verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION, dpnEndpointsIdentifier, dpnEndpointsVxlan);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder in project genius by opendaylight.
the class ItmExternalTunnelAddTest method setupMocks.
private void setupMocks() {
ipAddress1 = IpAddressBuilder.getDefaultInstance(tepIp1);
ipAddress2 = IpAddressBuilder.getDefaultInstance(tepIp2);
ipAddress3 = IpAddressBuilder.getDefaultInstance(tepIp3);
gtwyIp1 = IpAddressBuilder.getDefaultInstance(gwyIp1);
gtwyIp2 = IpAddressBuilder.getDefaultInstance(gwyIp2);
ipPrefixTest = IpPrefixBuilder.getDefaultInstance(subnetIp + "/24");
tunnelEndPointsVxlan = new TunnelEndPointsBuilder().setVLANID(vlanId).setPortname(portName1).setIpAddress(ipAddress3).setGwIpAddress(gtwyIp1).setInterfaceName(parentInterfaceName).setTzMembership(ItmUtils.createTransportZoneMembership(transportZone1)).setTunnelType(tunnelType1).setSubnetMask(ipPrefixTest).build();
tunnelEndPointsListVxlan.add(tunnelEndPointsVxlan);
dpntePsInfoVxlan = new DPNTEPsInfoBuilder().setDPNID(dpId1).setUp(true).setKey(new DPNTEPsInfoKey(dpId1)).setTunnelEndPoints(tunnelEndPointsListVxlan).build();
deviceVteps1 = new DeviceVtepsBuilder().setIpAddress(ipAddress1).setKey(new DeviceVtepsKey(ipAddress1, source)).setNodeId(source).setTopologyId("hwvtep:1").build();
deviceVteps2 = new DeviceVtepsBuilder().setIpAddress(ipAddress2).setKey(new DeviceVtepsKey(ipAddress2, destination)).setNodeId(destination).setTopologyId("hwvtep:1").build();
hwVtep1 = new HwVtep();
hwVtep1.setTransportZone(transportZone1);
hwVtep1.setGatewayIP(gtwyIp1);
hwVtep1.setHwIp(ipAddress1);
hwVtep1.setTunnelType(tunnelType1);
hwVtep1.setVlanID(vlanId);
hwVtep1.setTopoId("hwvtep:1");
hwVtep1.setNodeId(source);
hwVtep1.setIpPrefix(ipPrefixTest);
cfgdDpnListVxlan.add(dpntePsInfoVxlan);
cfgdHwVtepsList.add(hwVtep1);
bigIntegerList.add(dpId1);
deviceVtepsList.add(deviceVteps1);
deviceVtepsList.add(deviceVteps2);
vtepsTest = new VtepsBuilder().setDpnId(dpId1).setIpAddress(ipAddress3).setPortname(portName1).setKey(new VtepsKey(dpId1, portName1)).build();
vtepsList.add(vtepsTest);
dpnEndpointsVxlan = new DpnEndpointsBuilder().setDPNTEPsInfo(cfgdDpnListVxlan).build();
transportZone = new TransportZoneBuilder().setTunnelType(tunnelType1).setZoneName(transportZone1).setKey(new TransportZoneKey(transportZone1)).setSubnets(subnetsList).build();
idOutputOptional1 = RpcResultBuilder.success(expectedId1).buildFuture();
getIdInput1 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME).setIdKey("1:phy0:100:192.168.56.101:192.168.56.40:VXLAN").build();
doReturn(idOutputOptional1).when(idManagerService).allocateId(getIdInput1);
idOutputOptional2 = RpcResultBuilder.success(expectedId2).buildFuture();
getIdInput2 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME).setIdKey("1:phy0:100:192.168.56.101:192.168.56.30:VXLAN").build();
doReturn(idOutputOptional2).when(idManagerService).allocateId(getIdInput2);
idOutputOptional3 = RpcResultBuilder.success(expectedId3).buildFuture();
getIdInput3 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME).setIdKey("hwvtep:1:hwvtep://192.168.101.30:6640/physicalswitch/s3:192.168.56.30:192.168.56.101:VXLAN").build();
doReturn(idOutputOptional3).when(idManagerService).allocateId(getIdInput3);
idOutputOptional4 = RpcResultBuilder.success(expectedId4).buildFuture();
getIdInput4 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME).setIdKey("hwvtep:1:hwvtep://192.168.101.40:6640/physicalswitch/s4:192.168.56.40:192.168.56.101:VXLAN").build();
doReturn(idOutputOptional4).when(idManagerService).allocateId(getIdInput4);
idOutputOptional5 = RpcResultBuilder.success(expectedId5).buildFuture();
getIdInput5 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME).setIdKey("hwvtep:1:hwvtep://192.168.101.30:6640/physicalswitch/s3:192.168.56.30:192.168.56.40:VXLAN").build();
doReturn(idOutputOptional5).when(idManagerService).allocateId(getIdInput5);
idOutputOptional6 = RpcResultBuilder.success(expectedId6).buildFuture();
getIdInput6 = new AllocateIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME).setIdKey("hwvtep:1:hwvtep://192.168.101.40:6640/physicalswitch/s4:192.168.56.40:192.168.56.30:VXLAN").build();
doReturn(idOutputOptional6).when(idManagerService).allocateId(getIdInput6);
tunnelMonitorParams = new TunnelMonitorParamsBuilder().setEnabled(true).build();
tunnelMonitorInterval = new TunnelMonitorIntervalBuilder().setInterval(interval).build();
trunkInterfaceName = ItmUtils.getTrunkInterfaceName(parentInterfaceName, String.valueOf(tunnelEndPointsVxlan.getIpAddress().getValue()), String.valueOf(ipAddress2.getValue()), tunnelType1.getName());
interfaceIdentifier = ItmUtils.buildId(trunkInterfaceName);
externalTunnelIdentifier = InstanceIdentifier.create(ExternalTunnelList.class).child(ExternalTunnel.class, new ExternalTunnelKey(String.valueOf(ipAddress2.getValue()), dpId1.toString(), tunnelType1));
iface = ItmUtils.buildTunnelInterface(dpId1, trunkInterfaceName, String.format("%s %s", ItmUtils.convertTunnelTypetoString(tunnelType1), "Trunk Interface"), true, tunnelType1, ipAddress3, ipAddress2, gtwyIp1, tunnelEndPointsVxlan.getVLANID(), false, false, monitorProtocol, null, false, null);
externalTunnel = ItmUtils.buildExternalTunnel(dpId1.toString(), String.valueOf(ipAddress2.getValue()), tunnelType1, trunkInterfaceName);
subnets = new SubnetsBuilder().setGatewayIp(gtwyIp1).setVlanId(vlanId).setKey(new SubnetsKey(ipPrefixTest)).setVteps(vtepsList).setDeviceVteps(deviceVtepsList).build();
subnetsList.add(subnets);
doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
doReturn(mockWriteTx).when(dataBroker).newWriteOnlyTransaction();
doReturn(Futures.immediateCheckedFuture(null)).when(mockWriteTx).submit();
}
Aggregations