use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo 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.configs.MonitoringInfo 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);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo in project genius by opendaylight.
the class AlivenessMonitor method stopMonitoringTask.
private boolean stopMonitoringTask(Long monitorId, boolean interruptTask) {
Optional<MonitoringInfo> optInfo = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
if (!optInfo.isPresent()) {
LOG.warn("There is no monitoring info present for monitor id {}", monitorId);
return false;
}
MonitoringInfo monitoringInfo = optInfo.get();
Optional<MonitorProfile> optProfile = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(monitoringInfo.getProfileId()));
EtherTypes protocolType = optProfile.get().getProtocolType();
if (protocolType == EtherTypes.Bfd) {
LOG.debug("disabling bfd for hwvtep tunnel montior id {}", monitorId);
((HwVtepTunnelsStateHandler) alivenessProtocolHandlerRegistry.get(protocolType)).resetMonitoringTask(false);
return true;
}
ScheduledFuture<?> scheduledFutureResult = monitoringTasks.get(monitorId);
if (scheduledFutureResult != null) {
scheduledFutureResult.cancel(interruptTask);
return true;
}
return false;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo 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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo 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);
}
}
Aggregations