Search in sources :

Example 11 with MonitoringInfo

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

Example 12 with MonitoringInfo

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo in project genius by opendaylight.

the class AlivenessMonitorTest method testMonitorStop.

@Test
public void testMonitorStop() throws InterruptedException, ExecutionException {
    MonitorStopInput input = new MonitorStopInputBuilder().setMonitorId(2L).build();
    Optional<MonitoringInfo> optInfo = Optional.of(new MonitoringInfoBuilder().setSource(new SourceBuilder().setEndpointType(getInterface("testInterface", "10.1.1.1")).build()).build());
    CheckedFuture<Optional<MonitoringInfo>, ReadFailedException> outFuture = Futures.immediateCheckedFuture(optInfo);
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringInfo.class)))).thenReturn(outFuture);
    Optional<MonitoridKeyEntry> optMap = Optional.of(new MonitoridKeyEntryBuilder().setMonitorId(2L).setMonitorKey("Test monitor Key").build());
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoridKeyEntry.class)))).thenReturn(Futures.immediateCheckedFuture(optMap));
    Optional<MonitorProfile> optProfile = Optional.of(getTestMonitorProfile());
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)))).thenReturn(Futures.immediateCheckedFuture(optProfile));
    Optional<InterfaceMonitorEntry> optEntry = Optional.of(getInterfaceMonitorEntry());
    when(readWriteTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(InterfaceMonitorEntry.class)))).thenReturn(Futures.immediateCheckedFuture(optEntry));
    RpcResult<Void> result = alivenessMonitor.monitorStop(input).get();
    verify(idManager).releaseId(any(ReleaseIdInput.class));
    verify(writeTx, times(2)).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
    assertTrue("Monitor stop rpc result", result.isSuccessful());
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) MonitorStopInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStopInput) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) Optional(com.google.common.base.Optional) SourceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.params.SourceBuilder) MonitorStopInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStopInputBuilder) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) MonitoringInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder) MonitoridKeyEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder) InterfaceMonitorEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntry) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReleaseIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput) MonitoridKeyEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry) Test(org.junit.Test)

Example 13 with MonitoringInfo

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo in project genius by opendaylight.

the class AlivenessMonitorTest method testMonitorUnpause.

@Test
public void testMonitorUnpause() throws InterruptedException, ExecutionException {
    MonitorUnpauseInput input = new MonitorUnpauseInputBuilder().setMonitorId(2L).build();
    Optional<MonitoringState> optState = Optional.of(new MonitoringStateBuilder().setStatus(MonitorStatus.Paused).build());
    when(readWriteTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringState.class)))).thenReturn(Futures.immediateCheckedFuture(optState));
    Optional<MonitoringInfo> optInfo = Optional.of(new MonitoringInfoBuilder().setId(2L).setProfileId(1L).build());
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringInfo.class)))).thenReturn(Futures.immediateCheckedFuture(optInfo));
    Optional<MonitorProfile> optProfile = Optional.of(getTestMonitorProfile());
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)))).thenReturn(Futures.immediateCheckedFuture(optProfile));
    Optional<MonitoridKeyEntry> optMap = Optional.of(new MonitoridKeyEntryBuilder().setMonitorId(2L).setMonitorKey("Test monitor Key").build());
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoridKeyEntry.class)))).thenReturn(Futures.immediateCheckedFuture(optMap));
    RpcResult<Void> result = alivenessMonitor.monitorUnpause(input).get();
    verify(readWriteTx).merge(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringState.class)), stateCaptor.capture());
    assertEquals(MonitorStatus.Started, stateCaptor.getValue().getStatus());
    assertTrue("Monitor unpause rpc result", result.isSuccessful());
}
Also used : MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) 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) MonitoringInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder) MonitorUnpauseInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorUnpauseInputBuilder) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) MonitoridKeyEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder) MonitorUnpauseInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorUnpauseInput) MonitoridKeyEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry) Test(org.junit.Test)

Example 14 with MonitoringInfo

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo in project genius by opendaylight.

the class AlivenessMonitorTest method testMonitorPause.

@Test
public void testMonitorPause() throws InterruptedException, ExecutionException {
    MonitorPauseInput input = new MonitorPauseInputBuilder().setMonitorId(2L).build();
    Optional<MonitorProfile> optProfile = Optional.of(getTestMonitorProfile());
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)))).thenReturn(Futures.immediateCheckedFuture(optProfile));
    Optional<MonitoringInfo> optInfo = Optional.of(new MonitoringInfoBuilder().setId(2L).setProfileId(1L).build());
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringInfo.class)))).thenReturn(Futures.immediateCheckedFuture(optInfo));
    Optional<MonitoringState> optState = Optional.of(new MonitoringStateBuilder().setStatus(MonitorStatus.Started).build());
    when(readWriteTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringState.class)))).thenReturn(Futures.immediateCheckedFuture(optState));
    Optional<MonitoridKeyEntry> optMap = Optional.of(new MonitoridKeyEntryBuilder().setMonitorId(2L).setMonitorKey("Test monitor Key").build());
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoridKeyEntry.class)))).thenReturn(Futures.immediateCheckedFuture(optMap));
    alivenessMonitor.monitorPause(input).get();
    verify(readWriteTx).merge(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringState.class)), stateCaptor.capture());
    assertEquals(MonitorStatus.Paused, stateCaptor.getValue().getStatus());
}
Also used : MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) 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) MonitoringInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder) MonitorPauseInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorPauseInputBuilder) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) MonitorPauseInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorPauseInput) MonitoridKeyEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder) MonitoridKeyEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry) Test(org.junit.Test)

Aggregations

MonitorProfile (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile)12 MonitoringInfo (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo)8 Optional (com.google.common.base.Optional)7 EndpointType (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.EndpointType)6 EtherTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes)5 MonitoringInfoBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder)5 MonitoridKeyEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry)5 MonitoridKeyEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder)5 MonitoringState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState)5 MonitoringStateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder)5 FutureCallback (com.google.common.util.concurrent.FutureCallback)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 Nonnull (javax.annotation.Nonnull)4 Test (org.junit.Test)4 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 ExecutionException (java.util.concurrent.ExecutionException)3 MonitorPauseInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorPauseInput)3