Search in sources :

Example 1 with EndpointType

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

the class AlivenessMonitor method releaseIdForMonitoringInfo.

private void releaseIdForMonitoringInfo(MonitoringInfo info) {
    Long monitorId = info.getId();
    EndpointType source = info.getSource().getEndpointType();
    String interfaceName = getInterfaceName(source);
    if (!Strings.isNullOrEmpty(interfaceName)) {
        Optional<MonitorProfile> optProfile = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(info.getProfileId()));
        if (optProfile.isPresent()) {
            EtherTypes ethType = optProfile.get().getProtocolType();
            EndpointType destination = info.getDestination() != null ? info.getDestination().getEndpointType() : null;
            String idKey = getUniqueKey(interfaceName, ethType.toString(), source, destination);
            releaseId(idKey);
        } else {
            LOG.warn("Could not release monitorId {}. No profile associated with it", monitorId);
        }
    }
}
Also used : MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) EndpointType(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.EndpointType) EtherTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes)

Example 2 with EndpointType

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

the class HwVtepTunnelsStateHandler method startMonitoringTask.

@Override
public void startMonitoringTask(MonitoringInfo monitorInfo) {
    EndpointType source = monitorInfo.getSource().getEndpointType();
    if (source instanceof Interface) {
        Interface intf = (Interface) source;
        intf.getInterfaceName();
    } else {
        LOG.warn("Invalid source endpoint. Could not retrieve source interface to configure BFD");
        return;
    }
    MonitorProfile profile;
    long profileId = monitorInfo.getProfileId();
    Optional<MonitorProfile> optProfile = alivenessMonitor.getMonitorProfile(profileId);
    if (optProfile.isPresent()) {
        profile = optProfile.get();
    } else {
        LOG.warn("No monitor profile associated with id {}. " + "Could not send Monitor packet for monitor-id {}", profileId, monitorInfo);
        return;
    }
    // TODO: get the corresponding hwvtep tunnel from the sourceInterface
    // once InterfaceMgr
    // Implements renderer for hwvtep VXLAN tunnels
    String tunnelLocalMacAddress = "<TODO>";
    String tunnelLocalIpAddress = "<TODO>";
    String tunnelRemoteMacAddress = "<TODO>";
    List<BfdParams> bfdParams = new ArrayList<>();
    fillBfdParams(bfdParams, profile);
    List<BfdLocalConfigs> bfdLocalConfigs = new ArrayList<>();
    fillBfdLocalConfigs(bfdLocalConfigs, tunnelLocalMacAddress, tunnelLocalIpAddress);
    List<BfdRemoteConfigs> bfdRemoteConfigs = new ArrayList<>();
    fillBfdRemoteConfigs(bfdRemoteConfigs, tunnelRemoteMacAddress);
    // tunnelKey is initialized to null and passed to setKey which FindBugs flags as a
    // "Load of known null value" violation. Not sure sure what the intent is...
    // TunnelsKey tunnelKey = null;
    Tunnels tunnelWithBfd = new TunnelsBuilder().setKey(/*tunnelKey*/
    null).setBfdParams(bfdParams).setBfdLocalConfigs(bfdLocalConfigs).setBfdRemoteConfigs(bfdRemoteConfigs).build();
    // TODO: get the following parameters from the interface and use it to
    // update hwvtep datastore
    // and not sure sure tunnels are creating immediately once interface mgr
    // writes termination point
    // into hwvtep datastore. if tunnels are not created during that time,
    // then start monitoring has to
    // be done as part of tunnel add DCN handling.
    String topologyId = "";
    String nodeId = "";
    MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, getTunnelIdentifier(topologyId, nodeId, new TunnelsKey(/*localRef*/
    null, /*remoteRef*/
    null)), tunnelWithBfd);
}
Also used : BfdLocalConfigs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdLocalConfigs) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) ArrayList(java.util.ArrayList) TunnelsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsBuilder) EndpointType(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.EndpointType) BfdRemoteConfigs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdRemoteConfigs) TunnelsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsKey) BfdParams(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdParams) Interface(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.Interface) Tunnels(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels)

Example 3 with EndpointType

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

the class AlivenessProtocolHandlerLLDP method startMonitoringTask.

@Override
public void startMonitoringTask(MonitoringInfo monitorInfo) {
    String sourceInterface;
    EndpointType source = monitorInfo.getSource().getEndpointType();
    if (source instanceof Interface) {
        Interface intf = (Interface) source;
        sourceInterface = intf.getInterfaceName();
    } else {
        LOG.warn("Invalid source endpoint. Could not retrieve source interface to send LLDP Packet");
        return;
    }
    // Get Mac Address for the source interface
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState;
    try {
        interfaceState = getInterfaceFromOperDS(sourceInterface);
    } catch (ReadFailedException e) {
        LOG.error("getInterfaceFromOperDS failed for sourceInterface: {}", sourceInterface, e);
        return;
    }
    Optional<byte[]> optSourceMac = getMacAddress(interfaceState);
    if (!optSourceMac.isPresent()) {
        LOG.error("Could not read mac address for the source interface {} from the Inventory. " + "LLDP packet cannot be send.", sourceInterface);
        return;
    }
    byte[] sourceMac = optSourceMac.get();
    String lowerLayerIf = interfaceState.getLowerLayerIf().get(0);
    NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
    long nodeId = Long.parseLong(getDpnFromNodeConnectorId(nodeConnectorId));
    long portNum = Long.parseLong(getPortNoFromNodeConnectorId(nodeConnectorId));
    Ethernet ethenetLLDPPacket = makeLLDPPacket(Long.toString(nodeId), portNum, sourceMac, sourceInterface);
    try {
        List<ActionInfo> actions = getInterfaceActions(interfaceState, portNum);
        if (actions.isEmpty()) {
            LOG.error("No interface actions to send packet out over interface {}", sourceInterface);
            return;
        }
        TransmitPacketInput transmitPacketInput = MDSALUtil.getPacketOut(actions, ethenetLLDPPacket.serialize(), nodeId, MDSALUtil.getNodeConnRef(BigInteger.valueOf(nodeId), "0xfffffffd"));
        addErrorLogging(packetProcessingService.transmitPacket(transmitPacketInput), LOG, "transmitPacket() failed: {}", transmitPacketInput);
    } catch (InterruptedException | ExecutionException | PacketException e) {
        LOG.error("Error while sending LLDP Packet", e);
    }
}
Also used : Collections(java.util.Collections) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) EndpointType(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.EndpointType) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) Interface(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.Interface)

Example 4 with EndpointType

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

the class AlivenessMonitor method monitorStart.

@Override
public Future<RpcResult<MonitorStartOutput>> monitorStart(MonitorStartInput input) {
    RpcResultBuilder<MonitorStartOutput> rpcResultBuilder;
    final Config in = input.getConfig();
    Long profileId = in.getProfileId();
    LOG.debug("Monitor Start invoked with Config: {}, Profile Id: {}", in, profileId);
    try {
        if (in.getMode() != MonitoringMode.OneOne) {
            throw new UnsupportedConfigException("Unsupported Monitoring mode. Currently one-one mode is supported");
        }
        Optional<MonitorProfile> optProfile = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId));
        final MonitorProfile profile;
        if (!optProfile.isPresent()) {
            String errMsg = String.format("No monitoring profile associated with Id: %d", profileId);
            LOG.error("Monitor start failed. {}", errMsg);
            throw new RuntimeException(errMsg);
        } else {
            profile = optProfile.get();
        }
        final EtherTypes ethType = profile.getProtocolType();
        String interfaceName = null;
        EndpointType srcEndpointType = in.getSource().getEndpointType();
        if (srcEndpointType instanceof Interface) {
            Interface endPoint = (Interface) srcEndpointType;
            interfaceName = endPoint.getInterfaceName();
        } else {
            throw new UnsupportedConfigException("Unsupported source Endpoint type. Only Interface Endpoint currently supported for monitoring");
        }
        if (Strings.isNullOrEmpty(interfaceName)) {
            throw new RuntimeException("Interface Name not defined in the source Endpoint");
        }
        // Initially the support is for one monitoring per interface.
        // Revisit the retrieving monitor id logic when the multiple
        // monitoring for same interface is needed.
        EndpointType destEndpointType = null;
        if (in.getDestination() != null) {
            destEndpointType = in.getDestination().getEndpointType();
        }
        String idKey = getUniqueKey(interfaceName, ethType.toString(), srcEndpointType, destEndpointType);
        final long monitorId = getUniqueId(idKey);
        Optional<MonitoringInfo> optKey = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
        final AlivenessProtocolHandler<?> handler;
        if (optKey.isPresent()) {
            String message = String.format("Monitoring for the interface %s with this configuration " + "is already registered.", interfaceName);
            LOG.warn("Monitoring for the interface {} with this configuration is already registered.", interfaceName);
            MonitorStartOutput output = new MonitorStartOutputBuilder().setMonitorId(monitorId).build();
            rpcResultBuilder = RpcResultBuilder.success(output).withWarning(ErrorType.APPLICATION, "config-exists", message);
            return Futures.immediateFuture(rpcResultBuilder.build());
        } else {
            // Construct the monitor key
            final MonitoringInfo monitoringInfo = new MonitoringInfoBuilder().setId(monitorId).setMode(in.getMode()).setProfileId(profileId).setDestination(in.getDestination()).setSource(in.getSource()).build();
            // Construct the initial monitor state
            handler = alivenessProtocolHandlerRegistry.get(ethType);
            final String monitoringKey = handler.getUniqueMonitoringKey(monitoringInfo);
            MonitoringStateBuilder monitoringStateBuilder = new MonitoringStateBuilder().setMonitorKey(monitoringKey).setMonitorId(monitorId).setState(LivenessState.Unknown).setStatus(MonitorStatus.Started);
            if (ethType != EtherTypes.Bfd) {
                monitoringStateBuilder.setRequestCount(INITIAL_COUNT).setResponsePendingCount(INITIAL_COUNT);
            }
            MonitoringState monitoringState = monitoringStateBuilder.build();
            Futures.addCallback(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
                tx.put(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId), monitoringInfo, CREATE_MISSING_PARENT);
                LOG.debug("adding oper monitoring info {}", monitoringInfo);
                tx.put(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitoringKey), monitoringState, CREATE_MISSING_PARENT);
                LOG.debug("adding oper monitoring state {}", monitoringState);
                MonitoridKeyEntry mapEntry = new MonitoridKeyEntryBuilder().setMonitorId(monitorId).setMonitorKey(monitoringKey).build();
                tx.put(LogicalDatastoreType.OPERATIONAL, getMonitorMapId(monitorId), mapEntry, CREATE_MISSING_PARENT);
                LOG.debug("adding oper map entry {}", mapEntry);
            }), new FutureCallback<Void>() {

                @Override
                public void onFailure(Throwable error) {
                    String errorMsg = String.format("Adding Monitoring info: %s in Datastore failed", monitoringInfo);
                    LOG.warn("Adding Monitoring info: {} in Datastore failed", monitoringInfo, error);
                    throw new RuntimeException(errorMsg, error);
                }

                @Override
                public void onSuccess(Void noarg) {
                    lockMap.put(monitoringKey, new Semaphore(1, true));
                    if (ethType == EtherTypes.Bfd) {
                        handler.startMonitoringTask(monitoringInfo);
                        return;
                    }
                    // Schedule task
                    LOG.debug("Scheduling monitor task for config: {}", in);
                    scheduleMonitoringTask(monitoringInfo, profile.getMonitorInterval());
                }
            }, callbackExecutorService);
        }
        associateMonitorIdWithInterface(monitorId, interfaceName);
        MonitorStartOutput output = new MonitorStartOutputBuilder().setMonitorId(monitorId).build();
        rpcResultBuilder = RpcResultBuilder.success(output);
    } catch (UnsupportedConfigException e) {
        LOG.error("Start Monitoring Failed. ", e);
        rpcResultBuilder = RpcResultBuilder.<MonitorStartOutput>failed().withError(ErrorType.APPLICATION, e.getMessage(), e);
    }
    return Futures.immediateFuture(rpcResultBuilder.build());
}
Also used : IpAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.IpAddress) LoadingCache(com.google.common.cache.LoadingCache) EventData(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.event.EventData) PacketInReason(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInReason) EventDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.event.EventDataBuilder) Future(java.util.concurrent.Future) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) Optional(com.google.common.base.Optional) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) CreateIdPoolInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput) ReleaseIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) InterfaceMonitorEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntry) ErrorType(org.opendaylight.yangtools.yang.common.RpcError.ErrorType) AlivenessProtocolHandler(org.opendaylight.genius.alivenessmonitor.protocols.AlivenessProtocolHandler) Executors(java.util.concurrent.Executors) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) MonitorProfileCreateOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput) Predicate(com.google.common.base.Predicate) AlivenessMonitorService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.AlivenessMonitorService) MonitorUnpauseInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorUnpauseInput) InterfaceMonitorEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryKey) InterfaceMonitorEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryBuilder) MonitorProfileGetOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileGetOutput) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) Interface(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.Interface) MonitorProfileDeleteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) AllocateIdOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput) MonitorStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStatus) ArrayList(java.util.ArrayList) AlivenessProtocolHandlerRegistry(org.opendaylight.genius.alivenessmonitor.protocols.AlivenessProtocolHandlerRegistry) Strings(com.google.common.base.Strings) MonitorProfileCreateOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutputBuilder) MonitorEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorEventBuilder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MonitorPauseInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorPauseInput) EtherTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes) AlivenessMonitorUtil.getInterfaceMonitorMapId(org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitorUtil.getInterfaceMonitorMapId) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) MonitorStopInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStopInput) Futures(com.google.common.util.concurrent.Futures) MonitorStartInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartInput) MonitoringMode(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitoringMode) Preconditions(com.google.common.base.Preconditions) MonitorProfileGetInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileGetInput) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) AlivenessMonitorUtil.getMonitorProfileId(org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitorUtil.getMonitorProfileId) MonitorProfileCreateInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ScheduledFuture(java.util.concurrent.ScheduledFuture) MonitoridKeyEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry) LoggerFactory(org.slf4j.LoggerFactory) NotificationPublishService(org.opendaylight.controller.md.sal.binding.api.NotificationPublishService) SettableFuture(com.google.common.util.concurrent.SettableFuture) MonitorEvent(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorEvent) ThreadFactoryProvider(org.opendaylight.infrautils.utils.concurrent.ThreadFactoryProvider) PreDestroy(javax.annotation.PreDestroy) MonitoringInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) AlivenessMonitorUtil.getMonitoringInfoId(org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitorUtil.getMonitoringInfoId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Packet(org.opendaylight.openflowplugin.libraries.liblldp.Packet) AlivenessMonitorUtil.getMonitorMapId(org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitorUtil.getMonitorMapId) AllocateIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) EndpointType(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.EndpointType) CacheBuilder(com.google.common.cache.CacheBuilder) MonitorStartOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartOutputBuilder) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) PacketProcessingListener(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener) LivenessState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState) MonitorProfileGetOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileGetOutputBuilder) Singleton(javax.inject.Singleton) JdkFutureAdapters(com.google.common.util.concurrent.JdkFutureAdapters) NetUtils(org.opendaylight.openflowplugin.libraries.liblldp.NetUtils) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) SendToController(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.SendToController) CreateIdPoolInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder) Profile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) Config(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.start.input.Config) Nonnull(javax.annotation.Nonnull) ExecutorService(java.util.concurrent.ExecutorService) MonitoridKeyEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) MonitorStartOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartOutput) ReleaseIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) TimeUnit(java.util.concurrent.TimeUnit) MonitorProfileBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfileBuilder) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) AllocateIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder) Collections(java.util.Collections) AlivenessMonitorUtil.getMonitorStateId(org.opendaylight.genius.alivenessmonitor.internal.AlivenessMonitorUtil.getMonitorStateId) Config(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.start.input.Config) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) MonitoringInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder) Semaphore(java.util.concurrent.Semaphore) EtherTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) MonitorStartOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartOutputBuilder) EndpointType(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.EndpointType) MonitorStartOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartOutput) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) MonitoridKeyEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder) Interface(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.Interface) MonitoridKeyEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry)

Example 5 with EndpointType

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

the class AlivenessProtocolHandlerARP method startMonitoringTask.

@Override
public void startMonitoringTask(MonitoringInfo monitorInfo) {
    if (arpService == null) {
        LOG.debug("ARP Service not available to send the packet");
        return;
    }
    EndpointType source = monitorInfo.getSource().getEndpointType();
    final String sourceInterface = Preconditions.checkNotNull(getInterfaceName(source), "Source interface is required to send ARP Packet for monitoring");
    final String srcIp = Preconditions.checkNotNull(getIpAddress(source), "Source Ip address is required to send ARP Packet for monitoring");
    final Optional<PhysAddress> srcMacAddressOptional = getMacAddress(source);
    if (srcMacAddressOptional.isPresent()) {
        PhysAddress srcMacAddress = srcMacAddressOptional.get();
        EndpointType target = monitorInfo.getDestination().getEndpointType();
        final String targetIp = Preconditions.checkNotNull(getIpAddress(target), "Target Ip address is required to send ARP Packet for monitoring");
        if (LOG.isTraceEnabled()) {
            LOG.trace("sendArpRequest interface {}, senderIPAddress {}, targetAddress {}", sourceInterface, srcIp, targetIp);
        }
        InterfaceAddressBuilder interfaceAddressBuilder = new InterfaceAddressBuilder().setInterface(sourceInterface).setIpAddress(IpAddressBuilder.getDefaultInstance(srcIp));
        if (srcMacAddress != null) {
            interfaceAddressBuilder.setMacaddress(srcMacAddress);
        }
        List<InterfaceAddress> addresses = Collections.singletonList(interfaceAddressBuilder.build());
        SendArpRequestInput input = new SendArpRequestInputBuilder().setInterfaceAddress(addresses).setIpaddress(IpAddressBuilder.getDefaultInstance(targetIp)).build();
        Future<RpcResult<Void>> future = arpService.sendArpRequest(input);
        final String msgFormat = String.format("Send ARP Request on interface %s to destination %s", sourceInterface, targetIp);
        Futures.addCallback(JdkFutureAdapters.listenInPoolThread(future), new FutureCallback<RpcResult<Void>>() {

            @Override
            public void onFailure(Throwable error) {
                LOG.error("Error - {}", msgFormat, error);
            }

            @Override
            public void onSuccess(RpcResult<Void> result) {
                if (result != null && !result.isSuccessful()) {
                    LOG.warn("Rpc call to {} failed {}", msgFormat, getErrorText(result.getErrors()));
                } else {
                    LOG.debug("Successful RPC Result - {}", msgFormat);
                }
            }
        });
    }
}
Also used : SendArpRequestInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpRequestInput) InterfaceAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddress) SendArpRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpRequestInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) InterfaceAddressBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddressBuilder) EndpointType(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.EndpointType) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)

Aggregations

EndpointType (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.EndpointType)5 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 ExecutionException (java.util.concurrent.ExecutionException)2 Interface (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.Interface)2 MonitorProfile (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 Optional (com.google.common.base.Optional)1 Preconditions (com.google.common.base.Preconditions)1 Predicate (com.google.common.base.Predicate)1 Strings (com.google.common.base.Strings)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1