use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile in project netvirt by opendaylight.
the class AlivenessMonitorUtils method startArpMonitoring.
public static void startArpMonitoring(MacEntry macEntry, Long arpMonitorProfileId, AlivenessMonitorService alivenessMonitorService, DataBroker dataBroker, INeutronVpnManager neutronVpnService, IInterfaceManager interfaceManager) {
if (interfaceManager.isExternalInterface(macEntry.getInterfaceName())) {
LOG.debug("ARP monitoring is currently not supported through external interfaces," + "skipping ARP monitoring from interface {} for IP {} (last known MAC {})", macEntry.getInterfaceName(), macEntry.getIpAddress().getHostAddress(), macEntry.getMacAddress());
return;
}
Optional<IpAddress> gatewayIpOptional = VpnUtil.getGatewayIpAddressFromInterface(macEntry.getInterfaceName(), neutronVpnService);
if (!gatewayIpOptional.isPresent()) {
LOG.error("Error while retrieving GatewayIp for interface{}", macEntry.getInterfaceName());
return;
}
final IpAddress gatewayIp = gatewayIpOptional.get();
Optional<String> gatewayMacOptional = VpnUtil.getGWMacAddressFromInterface(macEntry, gatewayIp, dataBroker);
if (!gatewayMacOptional.isPresent()) {
LOG.error("Error while retrieving GatewayMac for interface{}", macEntry.getInterfaceName());
return;
}
final PhysAddress gatewayMac = new PhysAddress(gatewayMacOptional.get());
if (arpMonitorProfileId == null || arpMonitorProfileId.equals(0L)) {
Optional<Long> profileIdOptional = allocateProfile(alivenessMonitorService, ArpConstants.FAILURE_THRESHOLD, ArpConstants.ARP_CACHE_TIMEOUT_MILLIS, ArpConstants.MONITORING_WINDOW, EtherTypes.Arp);
if (!profileIdOptional.isPresent()) {
LOG.error("Error while allocating Profile Id for alivenessMonitorService");
return;
}
arpMonitorProfileId = profileIdOptional.get();
}
IpAddress targetIp = new IpAddress(new Ipv4Address(macEntry.getIpAddress().getHostAddress()));
MonitorStartInput arpMonitorInput = new MonitorStartInputBuilder().setConfig(new ConfigBuilder().setSource(new SourceBuilder().setEndpointType(getSourceEndPointType(macEntry.getInterfaceName(), gatewayIp, gatewayMac)).build()).setDestination(new DestinationBuilder().setEndpointType(getEndPointIpAddress(targetIp)).build()).setMode(MonitoringMode.OneOne).setProfileId(arpMonitorProfileId).build()).build();
try {
Future<RpcResult<MonitorStartOutput>> result = alivenessMonitorService.monitorStart(arpMonitorInput);
RpcResult<MonitorStartOutput> rpcResult = result.get();
long monitorId;
if (rpcResult.isSuccessful()) {
monitorId = rpcResult.getResult().getMonitorId();
createOrUpdateInterfaceMonitorIdMap(monitorId, macEntry);
LOG.trace("Started ARP monitoring with id {}", monitorId);
} else {
LOG.warn("RPC Call to start monitoring returned with Errors {}", rpcResult.getErrors());
}
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Exception when starting monitoring", e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile in project genius by opendaylight.
the class AlivenessMonitorTest method testMonitorProfileCreate.
@Test
public void testMonitorProfileCreate() throws InterruptedException, ExecutionException {
MonitorProfileCreateInput input = new MonitorProfileCreateInputBuilder().setProfile(new ProfileBuilder().setFailureThreshold(10L).setMonitorInterval(10000L).setMonitorWindow(10L).setProtocolType(EtherTypes.Arp).build()).build();
doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(readWriteTx).read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)));
doReturn(Futures.immediateCheckedFuture(null)).when(readWriteTx).submit();
RpcResult<MonitorProfileCreateOutput> output = alivenessMonitor.monitorProfileCreate(input).get();
assertTrue("Monitor Profile Create result", output.isSuccessful());
assertNotNull("Monitor Profile Output", output.getResult().getProfileId());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile 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.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile in project genius by opendaylight.
the class AlivenessMonitor method getExistingProfileId.
private Long getExistingProfileId(MonitorProfileGetInput input) {
org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.get.input.Profile profile = input.getProfile();
final Long failureThreshold = profile.getFailureThreshold();
final Long monitorInterval = profile.getMonitorInterval();
final Long monitorWindow = profile.getMonitorWindow();
final EtherTypes ethType = profile.getProtocolType();
LOG.debug("getExistingProfileId for profile : {}", input.getProfile());
String idKey = getUniqueProfileKey(failureThreshold, monitorInterval, monitorWindow, ethType);
LOG.debug("Obtained existing profile ID for profile : {}", input.getProfile());
return (long) getUniqueId(idKey);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile in project genius by opendaylight.
the class AlivenessMonitor method monitorProfileGet.
@Override
public Future<RpcResult<MonitorProfileGetOutput>> monitorProfileGet(MonitorProfileGetInput input) {
LOG.debug("Monitor Profile Get operation for input profile- {}", input.getProfile());
RpcResultBuilder<MonitorProfileGetOutput> rpcResultBuilder;
final Long profileId = getExistingProfileId(input);
MonitorProfileGetOutputBuilder output = new MonitorProfileGetOutputBuilder().setProfileId(profileId);
rpcResultBuilder = RpcResultBuilder.success();
rpcResultBuilder.withResult(output.build());
return Futures.immediateFuture(rpcResultBuilder.build());
}
Aggregations