Search in sources :

Example 16 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications in project lispflowmapping by opendaylight.

the class MappingServiceIntegrationTest method registerAddressAndQuery.

// takes an address, packs it in a MapRegister, sends it, returns the
// MapReply
private MapReply registerAddressAndQuery(Eid eid) throws SocketTimeoutException {
    mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
    sleepForSeconds(1);
    MapRegister mapRegister = MappingServiceIntegrationTestUtil.getDefaultMapRegisterBuilder(eid).build();
    LOG.trace("Sending Map-Register via socket: {}", mapRegister);
    sendMapRegister(mapRegister);
    MapNotify mapNotify = receiveMapNotify();
    LOG.trace("Received Map-Notify via socket: {}", mapNotify);
    assertEquals(8, mapNotify.getNonce().longValue());
    // wait for the notifications to propagate
    sleepForSeconds(1);
    MapRequest mapRequest = MappingServiceIntegrationTestUtil.getDefaultMapRequestBuilder(eid).build();
    sendMapRequest(mapRequest);
    return receiveMapReply();
}
Also used : MapRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest) GotMapNotify(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify) MapNotify(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify) MapRegister(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)

Example 17 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications in project genius by opendaylight.

the class AlivenessMonitor method processReceivedMonitorKey.

private void processReceivedMonitorKey(final String monitorKey) {
    Preconditions.checkNotNull(monitorKey, "Monitor Key required to process the state");
    LOG.debug("Processing monitorKey: {} for received packet", monitorKey);
    final Semaphore lock = lockMap.get(monitorKey);
    LOG.debug("Acquiring lock for monitor key : {} to process monitor packet", monitorKey);
    acquireLock(lock);
    final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
    ListenableFuture<Optional<MonitoringState>> stateResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
    // READ Callback
    Futures.addCallback(stateResult, new FutureCallback<Optional<MonitoringState>>() {

        @Override
        public void onSuccess(@Nonnull Optional<MonitoringState> optState) {
            if (optState.isPresent()) {
                final MonitoringState currentState = optState.get();
                if (LOG.isTraceEnabled()) {
                    LOG.trace("OnPacketReceived : Monitoring state from ODS : {} ", currentState);
                }
                // Long responsePendingCount = currentState.getResponsePendingCount();
                // 
                // Need to relook at the pending count logic to support N
                // out of M scenarios
                // if (currentState.getState() != LivenessState.Up) {
                // //Reset responsePendingCount when state changes from DOWN
                // to UP
                // responsePendingCount = INITIAL_COUNT;
                // }
                // 
                // if (responsePendingCount > INITIAL_COUNT) {
                // responsePendingCount =
                // currentState.getResponsePendingCount() - 1;
                // }
                Long responsePendingCount = INITIAL_COUNT;
                final boolean stateChanged = currentState.getState() == LivenessState.Down || currentState.getState() == LivenessState.Unknown;
                final MonitoringState state = new MonitoringStateBuilder().setMonitorKey(monitorKey).setState(LivenessState.Up).setResponsePendingCount(responsePendingCount).build();
                tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), state);
                ListenableFuture<Void> writeResult = tx.submit();
                // WRITE Callback
                Futures.addCallback(writeResult, new FutureCallback<Void>() {

                    @Override
                    public void onSuccess(Void noarg) {
                        releaseLock(lock);
                        if (stateChanged) {
                            // send notifications
                            if (LOG.isTraceEnabled()) {
                                LOG.trace("Sending notification for monitor Id : {} with Current State: {}", currentState.getMonitorId(), LivenessState.Up);
                            }
                            publishNotification(currentState.getMonitorId(), LivenessState.Up);
                        } else {
                            if (LOG.isTraceEnabled()) {
                                LOG.trace("Successful in writing monitoring state {} to ODS", state);
                            }
                        }
                    }

                    @Override
                    public void onFailure(Throwable error) {
                        releaseLock(lock);
                        LOG.warn("Error in writing monitoring state : {} to Datastore", monitorKey, error);
                        if (LOG.isTraceEnabled()) {
                            LOG.trace("Error in writing monitoring state: {} to Datastore", state);
                        }
                    }
                }, callbackExecutorService);
            } else {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Monitoring State not available for key: {} to process the Packet received", monitorKey);
                }
                // Complete the transaction
                tx.submit();
                releaseLock(lock);
            }
        }

        @Override
        public void onFailure(Throwable error) {
            LOG.error("Error when reading Monitoring State for key: {} to process the Packet received", monitorKey, error);
            // FIXME: Not sure if the transaction status is valid to cancel
            tx.cancel();
            releaseLock(lock);
        }
    }, callbackExecutorService);
}
Also used : Optional(com.google.common.base.Optional) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) Semaphore(java.util.concurrent.Semaphore) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 18 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications in project genius by opendaylight.

the class HwVtepTunnelsStateHandler method update.

@Override
public void update(@Nonnull Tunnels oldTunnelInfo, @Nonnull Tunnels updatedTunnelInfo) {
    List<BfdStatus> oldBfdStatus = oldTunnelInfo.getBfdStatus();
    List<BfdStatus> newBfdStatus = updatedTunnelInfo.getBfdStatus();
    LivenessState oldTunnelOpState = getTunnelOpState(oldBfdStatus);
    final LivenessState newTunnelOpState = getTunnelOpState(newBfdStatus);
    if (oldTunnelOpState == newTunnelOpState) {
        LOG.debug("Tunnel state of old tunnel {} and update tunnel {} are same", oldTunnelInfo, updatedTunnelInfo);
        return;
    }
    updatedTunnelInfo.getTunnelUuid();
    String interfaceName = "<TODO>";
    // TODO: find out the corresponding interface using tunnelIdentifier or
    // any attributes of tunnelInfo object
    final String monitorKey = getBfdMonitorKey(interfaceName);
    LOG.debug("Processing monitorKey: {} for received Tunnels update DCN", monitorKey);
    final Semaphore lock = alivenessMonitor.getLock(monitorKey);
    LOG.debug("Acquiring lock for monitor key : {} to process monitor DCN", monitorKey);
    alivenessMonitor.acquireLock(lock);
    final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
    ListenableFuture<Optional<MonitoringState>> stateResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
    Futures.addCallback(stateResult, new FutureCallback<Optional<MonitoringState>>() {

        @Override
        public void onSuccess(@Nonnull Optional<MonitoringState> optState) {
            if (optState.isPresent()) {
                final MonitoringState currentState = optState.get();
                if (currentState.getState() == newTunnelOpState) {
                    return;
                }
                final boolean stateChanged = true;
                final MonitoringState state = new MonitoringStateBuilder().setMonitorKey(monitorKey).setState(newTunnelOpState).build();
                tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), state);
                ListenableFuture<Void> writeResult = tx.submit();
                // WRITE Callback
                Futures.addCallback(writeResult, new FutureCallback<Void>() {

                    @Override
                    public void onSuccess(Void arg0) {
                        alivenessMonitor.releaseLock(lock);
                        if (stateChanged) {
                            // send notifications
                            LOG.info("Sending notification for monitor Id : {} with Current State: {}", currentState.getMonitorId(), newTunnelOpState);
                            alivenessMonitor.publishNotification(currentState.getMonitorId(), newTunnelOpState);
                        } else {
                            if (LOG.isTraceEnabled()) {
                                LOG.trace("Successful in writing monitoring state {} to ODS", state);
                            }
                        }
                    }

                    @Override
                    public void onFailure(@Nonnull Throwable error) {
                        alivenessMonitor.releaseLock(lock);
                        LOG.warn("Error in writing monitoring state : {} to Datastore", monitorKey, error);
                        if (LOG.isTraceEnabled()) {
                            LOG.trace("Error in writing monitoring state: {} to Datastore", state);
                        }
                    }
                }, MoreExecutors.directExecutor());
            } else {
                LOG.warn("Monitoring State not available for key: {} to process the Packet received", monitorKey);
                // Complete the transaction
                tx.submit();
                alivenessMonitor.releaseLock(lock);
            }
        }

        @Override
        public void onFailure(@Nonnull Throwable error) {
            LOG.error("Error when reading Monitoring State for key: {} to process the Packet received", monitorKey, error);
            // FIXME: Not sure if the transaction status is valid to cancel
            tx.cancel();
            alivenessMonitor.releaseLock(lock);
        }
    }, MoreExecutors.directExecutor());
}
Also used : Optional(com.google.common.base.Optional) Nonnull(javax.annotation.Nonnull) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) Semaphore(java.util.concurrent.Semaphore) BfdStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdStatus) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) LivenessState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 19 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications in project netvirt by opendaylight.

the class Ipv6ServiceInterfaceEventListener method add.

@Override
public void add(InstanceIdentifier<Interface> key, Interface add) {
    LOG.debug("Port add {}, {}", key, add);
    List<String> ofportIds = add.getLowerLayerIf();
    if (!L2vlan.class.equals(add.getType())) {
        return;
    }
    // In ipv6service, we are only interested in the notification for NeutronPort, so we skip other notifications
    if (ofportIds == null || ofportIds.isEmpty() || !isNeutronPort(add.getName())) {
        return;
    }
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface;
    iface = ipv6ServiceUtils.getInterface(add.getName());
    if (null != iface) {
        LOG.debug("Port {} is a Neutron port", iface.getName());
        NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
        Uint64 dpId = Ipv6ServiceUtils.getDpnIdFromNodeConnectorId(nodeConnectorId);
        if (!dpId.equals(Ipv6ServiceConstants.INVALID_DPID)) {
            Uuid portId = new Uuid(iface.getName());
            VirtualPort port = ifMgr.obtainV6Interface(portId);
            if (port == null) {
                LOG.info("Port {} does not include IPv6Address, skipping.", portId);
                return;
            }
            Long ofPort = MDSALUtil.getOfPortNumberFromPortName(nodeConnectorId);
            ifMgr.updateDpnInfo(portId, dpId, ofPort);
            if (!ipv6ServiceEosHandler.isClusterOwner()) {
                LOG.trace("Not a cluster Owner, skipping further IPv6 processing on this node.");
                return;
            }
            VirtualPort routerPort = ifMgr.getRouterV6InterfaceForNetwork(port.getNetworkID());
            if (routerPort == null) {
                LOG.info("Port {} is not associated to a Router, skipping.", portId);
                return;
            }
            // Check and program icmpv6 punt flows on the dpnID if its the first VM on the host.
            String jobKey = Ipv6ServiceUtils.buildIpv6MonitorJobKey(portId.getValue());
            jobCoordinator.enqueueJob(jobKey, () -> {
                ifMgr.handleInterfaceStateEvent(port, dpId, routerPort, add.getIfIndex().intValue(), Ipv6ServiceConstants.ADD_FLOW);
                if (!port.getServiceBindingStatus()) {
                    // Bind Service
                    Long elanTag = ifMgr.getNetworkElanTag(routerPort.getNetworkID());
                    ipv6ServiceUtils.bindIpv6Service(portId.getValue(), elanTag, NwConstants.IPV6_TABLE);
                    port.setServiceBindingStatus(true);
                }
                return Collections.emptyList();
            }, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
        }
    }
}
Also used : L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 20 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications in project controller by opendaylight.

the class MdsalLowLevelTestProvider method unsubscribeDtcl.

@Override
public ListenableFuture<RpcResult<UnsubscribeDtclOutput>> unsubscribeDtcl(final UnsubscribeDtclInput input) {
    LOG.info("In unsubscribeDtcl");
    if (idIntsListener == null || dtclReg == null) {
        return RpcResultBuilder.<UnsubscribeDtclOutput>failed().withError(ErrorType.RPC, "data-missing", "No prior listener was registered").buildFuture();
    }
    long timeout = 120L;
    try {
        idIntsListener.tryFinishProcessing().get(timeout, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOG.error("Unable to finish notification processing", e);
        return RpcResultBuilder.<UnsubscribeDtclOutput>failed().withError(ErrorType.APPLICATION, "Unable to finish notification processing in " + timeout + " seconds", e).buildFuture();
    }
    dtclReg.close();
    dtclReg = null;
    if (!idIntsListener.hasTriggered()) {
        return RpcResultBuilder.<UnsubscribeDtclOutput>failed().withError(ErrorType.APPLICATION, "operation-failed", "id-ints listener has not received any notifications.").buildFuture();
    }
    try (DOMDataTreeReadTransaction rTx = domDataBroker.newReadOnlyTransaction()) {
        final Optional<NormalizedNode> readResult = rTx.read(LogicalDatastoreType.CONFIGURATION, WriteTransactionsHandler.ID_INT_YID).get();
        if (!readResult.isPresent()) {
            return RpcResultBuilder.<UnsubscribeDtclOutput>failed().withError(ErrorType.APPLICATION, "data-missing", "No data read from id-ints list").buildFuture();
        }
        final boolean nodesEqual = idIntsListener.checkEqual(readResult.get());
        if (!nodesEqual) {
            LOG.error("Final read of id-int does not match IdIntsListener's copy. {}", idIntsListener.diffWithLocalCopy(readResult.get()));
        }
        return RpcResultBuilder.success(new UnsubscribeDtclOutputBuilder().setCopyMatches(nodesEqual)).buildFuture();
    } catch (final InterruptedException | ExecutionException e) {
        LOG.error("Final read of id-ints failed", e);
        return RpcResultBuilder.<UnsubscribeDtclOutput>failed().withError(ErrorType.APPLICATION, "Final read of id-ints failed", e).buildFuture();
    }
}
Also used : UnsubscribeDtclOutput(org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutput) ExecutionException(java.util.concurrent.ExecutionException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) UnsubscribeDtclOutputBuilder(org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutputBuilder) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ArrayList (java.util.ArrayList)6 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 Optional (com.google.common.base.Optional)3 Test (org.junit.Test)3 Notifications (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ByteBuf (io.netty.buffer.ByteBuf)2 Semaphore (java.util.concurrent.Semaphore)2 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 NotificationService (org.opendaylight.controller.sal.binding.api.NotificationService)2 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)2 UnsubscribeDtclOutput (org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutput)2 UnsubscribeDtclOutputBuilder (org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutputBuilder)2 L2vlan (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan)2 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)2 MonitoringState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState)2