use of org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier in project controller by opendaylight.
the class RpcbenchmarkProvider method startTest.
@Override
public Future<RpcResult<StartTestOutput>> startTest(final StartTestInput input) {
LOG.debug("startTest {}", input);
final RTCClient client;
final List<RoutedRpcRegistration<?>> rpcRegs = new ArrayList<>();
switch(input.getOperation()) {
case ROUTEDRTC:
List<InstanceIdentifier<?>> routeIid = new ArrayList<>();
for (int i = 0; i < input.getNumServers().intValue(); i++) {
GlobalBindingRTCServer server = new GlobalBindingRTCServer();
RoutedRpcRegistration<RpcbenchPayloadService> routedReg = providerRegistry.addRoutedRpcImplementation(RpcbenchPayloadService.class, server);
KeyedInstanceIdentifier<RpcRoute, RpcRouteKey> iid = InstanceIdentifier.create(RpcbenchRpcRoutes.class).child(RpcRoute.class, new RpcRouteKey(Integer.toString(i)));
routeIid.add(iid);
routedReg.registerPath(NodeContext.class, iid);
rpcRegs.add(routedReg);
}
client = new RoutedBindingRTClient(providerRegistry, input.getPayloadSize().intValue(), routeIid);
break;
case GLOBALRTC:
client = new GlobalBindingRTCClient(providerRegistry, input.getPayloadSize().intValue());
break;
default:
LOG.error("Unsupported server/client type {}", input.getOperation());
throw new IllegalArgumentException("Unsupported server/client type" + input.getOperation());
}
try {
ExecutorService executor = Executors.newFixedThreadPool(input.getNumClients().intValue());
final Runnable testRun = () -> client.runTest(input.getIterations().intValue());
LOG.info("Test Started");
long startTime = System.nanoTime();
for (int i = 0; i < input.getNumClients().intValue(); i++) {
executor.submit(testRun);
}
executor.shutdown();
try {
executor.awaitTermination(testTimeout, TimeUnit.MINUTES);
} catch (final InterruptedException e) {
LOG.error("Out of time: test did not finish within the {} min deadline ", testTimeout);
}
long endTime = System.nanoTime();
LOG.info("Test Done");
long elapsedTime = endTime - startTime;
StartTestOutput output = new StartTestOutputBuilder().setRate((long) 0).setGlobalRtcClientError(client.getRpcError()).setGlobalRtcClientOk(client.getRpcOk()).setExecTime(TimeUnit.NANOSECONDS.toMillis(elapsedTime)).setRate((client.getRpcOk() + client.getRpcError()) * 1000000000 / elapsedTime).build();
return RpcResultBuilder.success(output).buildFuture();
} finally {
for (RoutedRpcRegistration<?> routedRpcRegistration : rpcRegs) {
routedRpcRegistration.close();
}
}
}
use of org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier in project bgpcep by opendaylight.
the class AddPathAbstractRouteEntry method updateBestPaths.
@Override
public void updateBestPaths(final RouteEntryDependenciesContainer entryDependencies, final Identifier routeKey, final WriteTransaction tx) {
final RIBSupport ribSupport = entryDependencies.getRibSupport();
final KeyedInstanceIdentifier<Tables, TablesKey> locRibTarget = entryDependencies.getLocRibTableTarget();
if (this.bestPathRemoved != null) {
this.bestPathRemoved.forEach(path -> {
final Identifier newRouteKey = ribSupport.createNewRouteKey(path.getPathId(), routeKey);
final InstanceIdentifier routeTarget = ribSupport.createRouteIdentifier(locRibTarget, newRouteKey);
LOG.debug("Delete route from LocRib {}", routeTarget);
tx.delete(LogicalDatastoreType.OPERATIONAL, routeTarget);
});
this.bestPathRemoved = null;
}
if (this.removedPaths != null) {
this.removedPaths.forEach(removedPath -> {
final Identifier routeKeyAddPath = ribSupport.createNewRouteKey(removedPath.getPathId(), routeKey);
final Identifier routeKeyNonAddPath = ribSupport.createNewRouteKey(NON_PATH_ID_VALUE, routeKey);
fillAdjRibsOut(true, null, null, null, routeKeyNonAddPath, routeKeyAddPath, RouterIds.createPeerId(removedPath.getRouteId()), entryDependencies.getLocalTablesKey(), entryDependencies, tx);
});
this.removedPaths = null;
}
if (this.newBestPathToBeAdvertised != null) {
this.newBestPathToBeAdvertised.forEach(path -> addPathToDataStore(entryDependencies, path, isFirstBestPath(this.bestPath.indexOf(path)), routeKey, tx));
this.newBestPathToBeAdvertised = null;
}
}
use of org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier in project bgpcep by opendaylight.
the class AddPathAbstractRouteEntry method addPathToDataStore.
private void addPathToDataStore(final RouteEntryDependenciesContainer entryDep, final AddPathBestPath path, final boolean isFirstBestPath, final Identifier routeKey, final WriteTransaction tx) {
final RIBSupport ribSup = entryDep.getRibSupport();
final Identifier routeKeyAddPath = ribSup.createNewRouteKey(path.getPathId(), routeKey);
final Identifier routeKeyAddNonPath = ribSup.createNewRouteKey(NON_PATH_ID_VALUE, routeKey);
final Route routeAddPath = createRoute(ribSup, routeKeyAddPath, path.getPathId(), path);
final Route routeNonAddPath = createRoute(ribSup, routeKeyAddNonPath, NON_PATH_ID_VALUE, path);
final KeyedInstanceIdentifier<Tables, TablesKey> locRibTarget = entryDep.getLocRibTableTarget();
final InstanceIdentifier routeTarget = ribSup.createRouteIdentifier(locRibTarget, routeKeyAddPath);
LOG.debug("Write route to LocRib {}", routeAddPath);
tx.put(LogicalDatastoreType.OPERATIONAL, routeTarget, routeAddPath);
fillAdjRibsOut(isFirstBestPath, path.getAttributes(), routeNonAddPath, routeAddPath, routeKeyAddNonPath, routeKeyAddPath, path.getPeerId(), entryDep.getLocalTablesKey(), entryDep, tx);
}
use of org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier in project bgpcep by opendaylight.
the class TopologyStatsProviderImpl method updatePcepStats.
private synchronized void updatePcepStats() {
final WriteTransaction tx = TopologyStatsProviderImpl.this.transactionChain.newWriteOnlyTransaction();
for (final Map.Entry<KeyedInstanceIdentifier<Node, NodeKey>, PcepSessionState> entry : this.statsMap.entrySet()) {
final PcepTopologyNodeStatsAug nodeStatsAug = new PcepTopologyNodeStatsAugBuilder().setPcepSessionState(new PcepSessionStateBuilder(entry.getValue()).build()).build();
final InstanceIdentifier<PcepTopologyNodeStatsAug> statId = entry.getKey().augmentation(PcepTopologyNodeStatsAug.class);
tx.put(LogicalDatastoreType.OPERATIONAL, statId, nodeStatsAug);
}
tx.submit();
}
use of org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier in project openflowplugin by opendaylight.
the class NodeConnectorRefToPortTranslator method fromNodeConnectorRef.
/**
* Gets port number from {@link NodeConnectorRef}.
* @param nodeConnectorRef Node connector reference
* @param version Openflow version
* @return port number
*/
@SuppressWarnings("unchecked")
@Nullable
public static Long fromNodeConnectorRef(@Nonnull NodeConnectorRef nodeConnectorRef, short version) {
Preconditions.checkNotNull(nodeConnectorRef);
Long port = null;
final InstanceIdentifier<?> value = nodeConnectorRef.getValue();
if (value instanceof KeyedInstanceIdentifier) {
KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey> identifier = (KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey>) value;
OpenflowVersion ofVersion = OpenflowVersion.get(version);
String nodeConnectorId = identifier.getKey().getId().getValue();
port = InventoryDataServiceUtil.portNumberfromNodeConnectorId(ofVersion, nodeConnectorId);
}
return port;
}
Aggregations