Search in sources :

Example 1 with LivenessState

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState in project netvirt by opendaylight.

the class ArpMonitorEventListener method onMonitorEvent.

@Override
public void onMonitorEvent(MonitorEvent notification) {
    Long monitorId = notification.getEventData().getMonitorId();
    MacEntry macEntry = AlivenessMonitorUtils.getMacEntryFromMonitorId(monitorId);
    if (macEntry == null) {
        LOG.debug("No MacEntry found associated with the monitor Id {}", monitorId);
        return;
    }
    LivenessState livenessState = notification.getEventData().getMonitorState();
    if (livenessState.equals(LivenessState.Down)) {
        String vpnName = macEntry.getVpnName();
        String learntIp = macEntry.getIpAddress().getHostAddress();
        LearntVpnVipToPort vpnVipToPort = VpnUtil.getLearntVpnVipToPort(dataBroker, vpnName, learntIp);
        if (vpnVipToPort != null && macEntry.getCreatedTime().equals(vpnVipToPort.getCreationTime())) {
            jobCoordinator.enqueueJob(ArpMonitoringHandler.buildJobKey(macEntry.getIpAddress().getHostAddress(), macEntry.getVpnName()), new ArpMonitorStopTask(macEntry, dataBroker, alivenessManager));
        }
    }
}
Also used : LivenessState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)

Example 2 with LivenessState

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState in project genius by opendaylight.

the class OvsInterfaceTopologyStateUpdateHelper method getTunnelOpState.

private static Interface.OperStatus getTunnelOpState(OvsdbTerminationPointAugmentation terminationPoint) {
    if (!SouthboundUtils.bfdMonitoringEnabled(terminationPoint.getInterfaceBfd())) {
        return Interface.OperStatus.Up;
    }
    Interface.OperStatus livenessState = Interface.OperStatus.Down;
    List<InterfaceBfdStatus> tunnelBfdStatus = terminationPoint.getInterfaceBfdStatus();
    if (tunnelBfdStatus != null && !tunnelBfdStatus.isEmpty()) {
        for (InterfaceBfdStatus bfdState : tunnelBfdStatus) {
            if (bfdState.getBfdStatusKey().equalsIgnoreCase(SouthboundUtils.BFD_OP_STATE)) {
                String bfdOpState = bfdState.getBfdStatusValue();
                livenessState = SouthboundUtils.BFD_STATE_UP.equalsIgnoreCase(bfdOpState) ? Interface.OperStatus.Up : Interface.OperStatus.Down;
                break;
            }
        }
    }
    return livenessState;
}
Also used : InterfaceBfdStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceBfdStatus) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)

Example 3 with LivenessState

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState 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);
}
Also used : Optional(com.google.common.base.Optional) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) Semaphore(java.util.concurrent.Semaphore) AlivenessProtocolHandler(org.opendaylight.genius.alivenessmonitor.protocols.AlivenessProtocolHandler) 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) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 4 with LivenessState

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState in project genius by opendaylight.

the class AlivenessMonitor method publishNotification.

void publishNotification(final Long monitorId, final LivenessState state) {
    LOG.debug("Sending notification for id {}  - state {}", monitorId, state);
    EventData data = new EventDataBuilder().setMonitorId(monitorId).setMonitorState(state).build();
    MonitorEvent event = new MonitorEventBuilder().setEventData(data).build();
    final ListenableFuture<?> eventFuture = notificationPublishService.offerNotification(event);
    Futures.addCallback(eventFuture, new FutureCallback<Object>() {

        @Override
        public void onFailure(Throwable error) {
            LOG.warn("Error in notifying listeners for id {} - state {}", monitorId, state, error);
        }

        @Override
        public void onSuccess(Object arg) {
            LOG.trace("Successful in notifying listeners for id {} - state {}", monitorId, state);
        }
    }, callbackExecutorService);
}
Also used : MonitorEvent(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorEvent) EventDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.event.EventDataBuilder) MonitorEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorEventBuilder) EventData(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.event.EventData)

Example 5 with LivenessState

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState 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)

Aggregations

LivenessState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState)3 Optional (com.google.common.base.Optional)2 Semaphore (java.util.concurrent.Semaphore)2 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)2 MonitoringState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState)2 MonitoringStateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Nonnull (javax.annotation.Nonnull)1 AlivenessProtocolHandler (org.opendaylight.genius.alivenessmonitor.protocols.AlivenessProtocolHandler)1 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)1 MonitorEvent (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorEvent)1 MonitorEventBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorEventBuilder)1 EventData (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.event.EventData)1 EventDataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.event.EventDataBuilder)1 MonitorProfile (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile)1 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)1 BfdStatus (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdStatus)1 InterfaceBfdStatus (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceBfdStatus)1