use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor 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.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project genius by opendaylight.
the class AlivenessMonitorTest method testMonitorProfileCreateAlreadyExist.
@Test
public void testMonitorProfileCreateAlreadyExist() throws InterruptedException, ExecutionException {
MonitorProfileCreateInput input = new MonitorProfileCreateInputBuilder().setProfile(new ProfileBuilder().setFailureThreshold(10L).setMonitorInterval(10000L).setMonitorWindow(10L).setProtocolType(EtherTypes.Arp).build()).build();
@SuppressWarnings("unchecked") Optional<MonitorProfile> optionalProfile = mock(Optional.class);
CheckedFuture<Optional<MonitorProfile>, ReadFailedException> proFuture = Futures.immediateCheckedFuture(optionalProfile);
doReturn(true).when(optionalProfile).isPresent();
doReturn(proFuture).when(readWriteTx).read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)));
RpcResult<MonitorProfileCreateOutput> output = alivenessMonitor.monitorProfileCreate(input).get();
assertTrue("Monitor Profile Create result", output.isSuccessful());
assertThat(output.getErrors(), CoreMatchers.hasItem(hasErrorType(ErrorType.PROTOCOL)));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project genius by opendaylight.
the class AlivenessMonitorTest method testMonitorStart.
@Test
public void testMonitorStart() throws InterruptedException, ExecutionException {
Long profileId = createProfile();
MonitorStartInput input = new MonitorStartInputBuilder().setConfig(new ConfigBuilder().setDestination(new DestinationBuilder().setEndpointType(getInterface("10.0.0.1")).build()).setSource(new SourceBuilder().setEndpointType(getInterface("testInterface", "10.1.1.1")).build()).setMode(MonitoringMode.OneOne).setProfileId(profileId).build()).build();
Optional<MonitorProfile> optionalProfile = Optional.of(getTestMonitorProfile());
CheckedFuture<Optional<MonitorProfile>, ReadFailedException> proFuture = Futures.immediateCheckedFuture(optionalProfile);
when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)))).thenReturn(proFuture);
CheckedFuture<Optional<MonitoringInfo>, ReadFailedException> outFuture = Futures.immediateCheckedFuture(Optional.<MonitoringInfo>absent());
when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringInfo.class)))).thenReturn(outFuture);
RpcResult<MonitorStartOutput> output = alivenessMonitor.monitorStart(input).get();
verify(idManager, times(2)).allocateId(any(AllocateIdInput.class));
assertTrue("Monitor start output result", output.isSuccessful());
assertNotNull("Monitor start output", output.getResult().getMonitorId());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project bgpcep by opendaylight.
the class BmpDeployerImpl method updateBmpMonitor.
@SuppressWarnings("checkstyle:IllegalCatch")
private synchronized void updateBmpMonitor(final BmpMonitorConfig bmpConfig) {
final MonitorId monitorId = bmpConfig.getMonitorId();
final BmpMonitoringStationImpl oldService = bmpMonitorServices.remove(monitorId);
try {
if (oldService != null) {
oldService.closeServiceInstance().get(TIMEOUT_NS, TimeUnit.NANOSECONDS);
oldService.close();
}
final Server server = bmpConfig.getServer();
final InetSocketAddress inetAddress = Ipv4Util.toInetSocketAddress(server.getBindingAddress(), server.getBindingPort());
final BmpMonitoringStationImpl monitor = new BmpMonitoringStationImpl(domDataBroker, dispatcher, extensions, codecTree, singletonProvider, monitorId, inetAddress, bmpConfig.nonnullMonitoredRouter().values());
bmpMonitorServices.put(monitorId, monitor);
} catch (final Exception e) {
LOG.error("Failed to create Bmp Monitor {}.", monitorId, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor 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());
}
Aggregations