use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project lispflowmapping by opendaylight.
the class MappingServiceIntegrationTest method mapRequestSimple.
// ------------------------------- Simple Tests ---------------------------
public void mapRequestSimple() throws SocketTimeoutException {
cleanUP();
// We close and bind the socket on the correct port
if (socket != null) {
socket.close();
}
socket = MappingServiceIntegrationTestUtil.initSocket(56756);
sendPacket(mapRequestPacket);
MapReply reply = receiveMapReply();
assertEquals(4435248268955932168L, reply.getNonce().longValue());
restartSocket();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project genius by opendaylight.
the class AlivenessMonitor method sendMonitorPacket.
private void sendMonitorPacket(final MonitoringInfo monitoringInfo) {
// TODO: Handle interrupts
final Long monitorId = monitoringInfo.getId();
final String monitorKey = monitorIdKeyCache.getUnchecked(monitorId);
if (monitorKey == null) {
LOG.warn("No monitor Key associated with id {} to send the monitor packet", monitorId);
return;
} else {
LOG.debug("Sending monitoring packet for key: {}", monitorKey);
}
final MonitorProfile profile;
Optional<MonitorProfile> optProfile = getMonitorProfile(monitoringInfo.getProfileId());
if (optProfile.isPresent()) {
profile = optProfile.get();
} else {
LOG.warn("No monitor profile associated with id {}. " + "Could not send Monitor packet for monitor-id {}", monitoringInfo.getProfileId(), monitorId);
return;
}
final Semaphore lock = lockMap.get(monitorKey);
LOG.debug("Acquiring lock for monitor key : {} to send monitor packet", monitorKey);
acquireLock(lock);
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
ListenableFuture<Optional<MonitoringState>> readResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
ListenableFuture<Void> writeResult = Futures.transformAsync(readResult, optState -> {
if (optState.isPresent()) {
MonitoringState state = optState.get();
// Increase the request count
Long requestCount = state.getRequestCount() + 1;
// Check with the monitor window
LivenessState currentLivenessState = state.getState();
// Increase the pending response count
long responsePendingCount = state.getResponsePendingCount();
if (responsePendingCount < profile.getMonitorWindow()) {
responsePendingCount = responsePendingCount + 1;
}
// Check with the failure threshold
if (responsePendingCount >= profile.getFailureThreshold()) {
// Change the state to down and notify
if (currentLivenessState != LivenessState.Down) {
LOG.debug("Response pending Count: {}, Failure threshold: {} for monitorId {}", responsePendingCount, profile.getFailureThreshold(), state.getMonitorId());
LOG.info("Sending notification for monitor Id : {} with State: {}", state.getMonitorId(), LivenessState.Down);
publishNotification(monitorId, LivenessState.Down);
currentLivenessState = LivenessState.Down;
// Reset requestCount when state changes
// from UP to DOWN
requestCount = INITIAL_COUNT;
}
}
// Update the ODS with state
MonitoringState updatedState = new MonitoringStateBuilder().setMonitorKey(state.getMonitorKey()).setRequestCount(requestCount).setResponsePendingCount(responsePendingCount).setState(currentLivenessState).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(state.getMonitorKey()), updatedState);
return tx.submit();
} else {
// Close the transaction
tx.submit();
String errorMsg = String.format("Monitoring State associated with id %d is not present to send packet out.", monitorId);
return Futures.immediateFailedFuture(new RuntimeException(errorMsg));
}
}, callbackExecutorService);
Futures.addCallback(writeResult, new FutureCallback<Void>() {
@Override
public void onSuccess(Void noarg) {
// invoke packetout on protocol handler
AlivenessProtocolHandler<?> handler = alivenessProtocolHandlerRegistry.getOpt(profile.getProtocolType());
if (handler != null) {
LOG.debug("Sending monitoring packet {}", monitoringInfo);
handler.startMonitoringTask(monitoringInfo);
}
releaseLock(lock);
}
@Override
public void onFailure(Throwable error) {
LOG.warn("Updating monitoring state for key: {} failed. Monitoring packet is not sent", monitorKey, error);
releaseLock(lock);
}
}, callbackExecutorService);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project bgpcep by opendaylight.
the class PCEPCloseMessageParser method validate.
@Override
protected Close validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty() || !(objects.get(0) instanceof CClose)) {
throw new PCEPDeserializerException("Close message doesn't contain CLOSE object.");
}
final Object o = objects.get(0);
final CCloseMessage msg = new CCloseMessageBuilder().setCClose((CClose) o).build();
objects.remove(0);
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new CloseBuilder().setCCloseMessage(msg).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project controller by opendaylight.
the class TxchainBaWrite method executeList.
@Override
public void executeList() {
final TransactionChain chain = bindingDataBroker.createMergingTransactionChain(this);
final LogicalDatastoreType dsType = getDataStoreType();
WriteTransaction tx = chain.newWriteOnlyTransaction();
int txSubmitted = 0;
int writeCnt = 0;
for (OuterList element : this.list) {
InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, element.key());
if (oper == StartTestInput.Operation.PUT) {
tx.put(dsType, iid, element);
} else {
tx.merge(dsType, iid, element);
}
writeCnt++;
if (writeCnt == writesPerTx) {
txSubmitted++;
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
txOk++;
}
@Override
public void onFailure(final Throwable cause) {
LOG.error("Transaction failed", cause);
txError++;
}
}, MoreExecutors.directExecutor());
tx = chain.newWriteOnlyTransaction();
writeCnt = 0;
}
}
// We need to empty the transaction chain before closing it
try {
txSubmitted++;
tx.commit().get();
txOk++;
} catch (final InterruptedException | ExecutionException e) {
LOG.error("Transaction failed", e);
txError++;
}
try {
chain.close();
} catch (final IllegalStateException e) {
LOG.error("Transaction close failed,", e);
}
LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, txOk + txError);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Close in project bgpcep by opendaylight.
the class AppPeerTest method testAppPeer.
@Test
public void testAppPeer() throws ExecutionException, InterruptedException {
appPeer.start(rib, neighbor, null, peerGroupLoader, tableTypeRegistry);
verify(rib).getYangRibId();
verify(rib).getService();
verify(rib).createPeerDOMChain(any(DOMTransactionChainListener.class));
verify(rib, times(1)).getLocalTablesKeys();
appPeer.instantiateServiceInstance();
verify(rib, times(3)).getYangRibId();
verify(rib, times(2)).getRibSupportContext();
verify(rib, times(2)).getLocalTablesKeys();
verify(rib, times(2)).createPeerDOMChain(any(DOMTransactionChainListener.class));
verify(domTx).newWriteOnlyTransaction();
appPeer.closeServiceInstance();
verify(domTx, times(2)).close();
appPeer.stop().get();
appPeer.start(rib, appPeer.getCurrentConfiguration(), null, peerGroupLoader, tableTypeRegistry);
appPeer.instantiateServiceInstance();
verify(rib, times(6)).getYangRibId();
verify(rib, times(4)).getService();
verify(rib, times(4)).createPeerDOMChain(any(DOMTransactionChainListener.class));
verify(listener, times(2)).close();
assertTrue(appPeer.containsEqualConfiguration(neighbor));
assertFalse(appPeer.containsEqualConfiguration(new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2"))).build()));
appPeer.closeServiceInstance();
verify(domTx, times(4)).close();
appPeer.instantiateServiceInstance();
verify(rib, times(6)).createPeerDOMChain(any(DOMTransactionChainListener.class));
appPeer.closeServiceInstance();
verify(domTx, times(6)).close();
appPeer.stop().get();
}
Aggregations