use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring in project genius by opendaylight.
the class HwVtepTunnelsStateHandler method update.
@Override
public void update(@Nonnull Tunnels oldTunnelInfo, @Nonnull Tunnels updatedTunnelInfo) {
List<BfdStatus> oldBfdStatus = oldTunnelInfo.getBfdStatus();
List<BfdStatus> newBfdStatus = updatedTunnelInfo.getBfdStatus();
LivenessState oldTunnelOpState = getTunnelOpState(oldBfdStatus);
final LivenessState newTunnelOpState = getTunnelOpState(newBfdStatus);
if (oldTunnelOpState == newTunnelOpState) {
LOG.debug("Tunnel state of old tunnel {} and update tunnel {} are same", oldTunnelInfo, updatedTunnelInfo);
return;
}
updatedTunnelInfo.getTunnelUuid();
String interfaceName = "<TODO>";
// TODO: find out the corresponding interface using tunnelIdentifier or
// any attributes of tunnelInfo object
final String monitorKey = getBfdMonitorKey(interfaceName);
LOG.debug("Processing monitorKey: {} for received Tunnels update DCN", monitorKey);
final Semaphore lock = alivenessMonitor.getLock(monitorKey);
LOG.debug("Acquiring lock for monitor key : {} to process monitor DCN", monitorKey);
alivenessMonitor.acquireLock(lock);
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
ListenableFuture<Optional<MonitoringState>> stateResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
Futures.addCallback(stateResult, new FutureCallback<Optional<MonitoringState>>() {
@Override
public void onSuccess(@Nonnull Optional<MonitoringState> optState) {
if (optState.isPresent()) {
final MonitoringState currentState = optState.get();
if (currentState.getState() == newTunnelOpState) {
return;
}
final boolean stateChanged = true;
final MonitoringState state = new MonitoringStateBuilder().setMonitorKey(monitorKey).setState(newTunnelOpState).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), state);
ListenableFuture<Void> writeResult = tx.submit();
// WRITE Callback
Futures.addCallback(writeResult, new FutureCallback<Void>() {
@Override
public void onSuccess(Void arg0) {
alivenessMonitor.releaseLock(lock);
if (stateChanged) {
// send notifications
LOG.info("Sending notification for monitor Id : {} with Current State: {}", currentState.getMonitorId(), newTunnelOpState);
alivenessMonitor.publishNotification(currentState.getMonitorId(), newTunnelOpState);
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("Successful in writing monitoring state {} to ODS", state);
}
}
}
@Override
public void onFailure(@Nonnull Throwable error) {
alivenessMonitor.releaseLock(lock);
LOG.warn("Error in writing monitoring state : {} to Datastore", monitorKey, error);
if (LOG.isTraceEnabled()) {
LOG.trace("Error in writing monitoring state: {} to Datastore", state);
}
}
}, MoreExecutors.directExecutor());
} else {
LOG.warn("Monitoring State not available for key: {} to process the Packet received", monitorKey);
// Complete the transaction
tx.submit();
alivenessMonitor.releaseLock(lock);
}
}
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("Error when reading Monitoring State for key: {} to process the Packet received", monitorKey, error);
// FIXME: Not sure if the transaction status is valid to cancel
tx.cancel();
alivenessMonitor.releaseLock(lock);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring 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);
}
}
});
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring in project genius by opendaylight.
the class TepCommandHelper method showTeps.
@SuppressWarnings("checkstyle:RegexpSinglelineJava")
public void showTeps(boolean monitorEnabled, int monitorInterval, CommandSession session) throws TepException {
boolean flag = false;
InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
Optional<TransportZones> transportZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
if (transportZonesOptional.isPresent()) {
TransportZones transportZones = transportZonesOptional.get();
if (transportZones.getTransportZone() == null || transportZones.getTransportZone().isEmpty()) {
handleError("No teps configured", session);
return;
}
List<String> result = new ArrayList<>();
result.add(String.format("Tunnel Monitoring (for VXLAN tunnels): %s", monitorEnabled ? "On" : "Off"));
result.add(String.format("Tunnel Monitoring Interval (for VXLAN tunnels): %d", monitorInterval));
result.add(System.lineSeparator());
result.add(String.format("%-16s %-16s %-16s %-12s %-12s %-12s %-16s %-12s", "TransportZone", "TunnelType", "SubnetMask", "GatewayIP", "VlanID", "DpnID", "IPAddress", "PortName"));
result.add("---------------------------------------------------------------------------------------------" + "---------------------------------");
for (TransportZone tz : transportZones.getTransportZone()) {
if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
LOG.error("Transport Zone {} has no subnets", tz.getZoneName());
continue;
}
for (Subnets sub : tz.getSubnets()) {
if (sub.getVteps() == null || sub.getVteps().isEmpty()) {
LOG.error("Transport Zone {} subnet {} has no vteps", tz.getZoneName(), sub.getPrefix());
continue;
}
for (Vteps vtep : sub.getVteps()) {
flag = true;
String strTunnelType;
if (tz.getTunnelType().equals(TunnelTypeGre.class)) {
strTunnelType = ITMConstants.TUNNEL_TYPE_GRE;
} else {
strTunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
}
result.add(String.format("%-16s %-16s %-16s %-12s %-12s %-12s %-16s %-12s", tz.getZoneName(), strTunnelType, new String(sub.getPrefix().getValue()), new String(sub.getGatewayIp().getValue()), sub.getVlanId().toString(), vtep.getDpnId().toString(), new String(vtep.getIpAddress().getValue()), vtep.getPortname()));
}
}
}
if (session != null) {
if (flag) {
for (String print : result) {
System.out.println(print);
}
} else {
System.out.println("No teps to display");
}
}
} else if (session != null) {
System.out.println("No teps configured");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring in project genius by opendaylight.
the class InterfaceManagerConfigurationTest method newTunnelInterface.
@Ignore
@Test
public void newTunnelInterface() throws Exception {
// 3. Update DPN-ID of the bridge
OvsdbSouthboundTestUtil.updateBridge(dataBroker, "00:00:00:00:00:00:00:02");
waitTillOperationCompletes(coordinatorEventsWaiter, asyncEventsWaiter);
BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(DPN_ID_2);
InstanceIdentifier<BridgeRefEntry> bridgeRefEntryIid = InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
// Verify if DPN-ID is updated in corresponding DS and cache
BridgeRefEntry bridgeRefEntry = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeRefEntryIid, dataBroker).orNull();
assertEqualBeans(interfaceMetaUtils.getBridgeRefEntryFromCache(DPN_ID_2), bridgeRefEntry);
// 1. Given
// 2. When
// i) dpn-id specified above configuration comes in
// operational/network-topology
// ii) Vlan interface written to config/ietf-interfaces DS and
// corresponding parent-interface is not present
// in operational/ietf-interface-state
ParentRefs parentRefs = new ParentRefsBuilder().setDatapathNodeIdentifier(DPN_ID_2).build();
InterfaceManagerTestUtil.putInterfaceConfig(dataBroker, TUNNEL_INTERFACE_NAME, parentRefs, Tunnel.class);
Thread.sleep(5000);
// 3. Then
// a) check expected bridge-interface mapping in
// odl-interface-meta/config/bridge-interface-info was created
BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(DPN_ID_2);
BridgeInterfaceEntryKey bridgeInterfaceEntryKey = new BridgeInterfaceEntryKey(TUNNEL_INTERFACE_NAME);
InstanceIdentifier<BridgeInterfaceEntry> bridgeInterfaceEntryIid = InterfaceMetaUtils.getBridgeInterfaceEntryIdentifier(bridgeEntryKey, bridgeInterfaceEntryKey);
// TODO Later use nicer abstraction for DB access here.. see
// ElanServiceTest
assertEqualBeans(InterfaceMeta.newBridgeInterface(), dataBroker.newReadOnlyTransaction().read(CONFIGURATION, bridgeInterfaceEntryIid).checkedGet().get());
// Then
// a) check if termination end point is created in
// config/network-topology
final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> bridgeIid = OvsdbSouthboundTestUtil.createInstanceIdentifier("192.168.56.101", 6640, "s2");
InstanceIdentifier<TerminationPoint> tpIid = InterfaceManagerTestUtil.getTerminationPointId(bridgeIid, TUNNEL_INTERFACE_NAME);
assertEqualTerminationPoints(ExpectedTerminationPoint.newTerminationPoint(), db.syncRead(CONFIGURATION, tpIid));
// When termination end point is populated in network-topology
OvsdbSouthboundTestUtil.createTerminationPoint(dataBroker, TUNNEL_INTERFACE_NAME, InterfaceTypeVxlan.class, null);
InterfaceManagerTestUtil.createFlowCapableNodeConnector(dataBroker, TUNNEL_INTERFACE_NAME, Tunnel.class);
waitTillOperationCompletes(coordinatorEventsWaiter, asyncEventsWaiter);
Thread.sleep(3000);
TestableQueues.awaitEmpty(batchingUtils.getQueue(DEFAULT_OPERATIONAL), 1, MINUTES);
// Then
// a) check if operational/ietf-interfaces-state is populated for the tunnel interface
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifaceState = dataBroker.newReadOnlyTransaction().read(OPERATIONAL, IfmUtil.buildStateInterfaceId(TUNNEL_INTERFACE_NAME)).checkedGet().get();
assertEqualBeans(ExpectedInterfaceState.newInterfaceState(ifaceState.getIfIndex(), TUNNEL_INTERFACE_NAME, Interface.OperStatus.Up, Tunnel.class, DPN_ID_2.toString(), ifaceState.getStatistics().getDiscontinuityTime()), ifaceState);
// Test all RPCs related to tunnel interfaces
checkTunnelRpcs();
checkTunnelApis();
// Update test
// i) Enable Tunnel Monitoring
InterfaceManagerTestUtil.updateTunnelMonitoringAttributes(dataBroker, TUNNEL_INTERFACE_NAME);
InterfaceManagerTestUtil.waitTillOperationCompletes(coordinatorEventsWaiter, asyncEventsWaiter);
// Then verify if bfd attributes are updated in topology config DS
assertEqualTerminationPoints(ExpectedTerminationPoint.newBfdEnabledTerminationPoint(), db.syncRead(CONFIGURATION, tpIid));
// state modification tests
// 1. Make the operational state of port as DOWN
InterfaceManagerTestUtil.updateFlowCapableNodeConnectorState(dataBroker, TUNNEL_INTERFACE_NAME, Tunnel.class, false);
waitTillOperationCompletes(coordinatorEventsWaiter, asyncEventsWaiter);
ifaceState = dataBroker.newReadOnlyTransaction().read(OPERATIONAL, IfmUtil.buildStateInterfaceId(TUNNEL_INTERFACE_NAME)).checkedGet().get();
// Verify if operational/ietf-interface-state is still up
assertEqualBeans(ExpectedInterfaceState.newInterfaceState(ifaceState.getIfIndex(), TUNNEL_INTERFACE_NAME, Interface.OperStatus.Up, Tunnel.class, DPN_ID_2.toString(), ifaceState.getStatistics().getDiscontinuityTime()), ifaceState);
// 2. Make BFD staus of tunnel port as down
OvsdbSouthboundTestUtil.updateTerminationPoint(dataBroker, TUNNEL_INTERFACE_NAME, InterfaceTypeVxlan.class);
waitTillOperationCompletes(coordinatorEventsWaiter, asyncEventsWaiter);
ifaceState = dataBroker.newReadOnlyTransaction().read(OPERATIONAL, IfmUtil.buildStateInterfaceId(TUNNEL_INTERFACE_NAME)).checkedGet().get();
// Verify if operational/ietf-interface-state is marked down
assertEqualBeans(ExpectedInterfaceState.newInterfaceState(ifaceState.getIfIndex(), TUNNEL_INTERFACE_NAME, Interface.OperStatus.Down, Tunnel.class, DPN_ID_2.toString(), ifaceState.getStatistics().getDiscontinuityTime()), ifaceState);
// 2. Delete the Node
InterfaceManagerTestUtil.removeNode(dataBroker);
waitTillOperationCompletes(coordinatorEventsWaiter, asyncEventsWaiter);
ifaceState = dataBroker.newReadOnlyTransaction().read(OPERATIONAL, IfmUtil.buildStateInterfaceId(TUNNEL_INTERFACE_NAME)).checkedGet().get();
// Verify if operational/ietf-interface-state is marked unknown
assertEqualBeans(ExpectedInterfaceState.newInterfaceState(ifaceState.getIfIndex(), TUNNEL_INTERFACE_NAME, Interface.OperStatus.Unknown, Tunnel.class, DPN_ID_2.toString(), ifaceState.getStatistics().getDiscontinuityTime()), ifaceState);
// Re-create port to proceed with further tests
InterfaceManagerTestUtil.createFlowCapableNodeConnector(dataBroker, TUNNEL_INTERFACE_NAME, Tunnel.class);
waitTillOperationCompletes(coordinatorEventsWaiter, asyncEventsWaiter);
// 2. Delete the OF port
InterfaceManagerTestUtil.removeFlowCapableNodeConnectorState(dataBroker, Tunnel.class);
waitTillOperationCompletes(coordinatorEventsWaiter, asyncEventsWaiter);
// Verify if operational-states are deleted
Assert.assertEquals(Optional.absent(), dataBroker.newReadOnlyTransaction().read(OPERATIONAL, IfmUtil.buildStateInterfaceId(TUNNEL_INTERFACE_NAME)).get());
Assert.assertEquals(Optional.absent(), dataBroker.newReadOnlyTransaction().read(OPERATIONAL, IfmUtil.buildStateInterfaceId(TUNNEL_INTERFACE_NAME)).get());
// Delete test
// iii) tunnel interface is deleted from config/ietf-interfaces
InterfaceManagerTestUtil.deleteInterfaceConfig(dataBroker, TUNNEL_INTERFACE_NAME);
InterfaceManagerTestUtil.waitTillOperationCompletes(coordinatorEventsWaiter, asyncEventsWaiter);
// Then
// a) check if tunnel is deleted from bridge-interface-info
Assert.assertEquals(Optional.absent(), dataBroker.newReadOnlyTransaction().read(CONFIGURATION, bridgeInterfaceEntryIid).get());
// b) check if termination end point is deleted in
// config/network-topology
Assert.assertEquals(Optional.absent(), dataBroker.newReadOnlyTransaction().read(CONFIGURATION, tpIid).get());
waitTillOperationCompletes(coordinatorEventsWaiter, asyncEventsWaiter);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring in project genius by opendaylight.
the class AlivenessMonitorUtils method handleTunnelMonitorUpdates.
public void handleTunnelMonitorUpdates(Interface interfaceOld, Interface interfaceNew) {
String interfaceName = interfaceNew.getName();
IfTunnel ifTunnelNew = interfaceNew.getAugmentation(IfTunnel.class);
if (!lldpMonitoringEnabled(ifTunnelNew)) {
return;
}
LOG.debug("handling tunnel monitoring updates for interface {}", interfaceName);
stopLLDPMonitoring(ifTunnelNew, interfaceOld.getName());
if (ifTunnelNew.isMonitorEnabled()) {
startLLDPMonitoring(ifTunnelNew, interfaceName);
// Delete old profile from Aliveness Manager
IfTunnel ifTunnelOld = interfaceOld.getAugmentation(IfTunnel.class);
if (!ifTunnelNew.getMonitorInterval().equals(ifTunnelOld.getMonitorInterval())) {
LOG.debug("deleting older monitor profile for interface {}", interfaceName);
long profileId = allocateProfile(FAILURE_THRESHOLD, ifTunnelOld.getMonitorInterval(), MONITORING_WINDOW, EtherTypes.Lldp);
MonitorProfileDeleteInput profileDeleteInput = new MonitorProfileDeleteInputBuilder().setProfileId(profileId).build();
Future<RpcResult<Void>> future = alivenessMonitorService.monitorProfileDelete(profileDeleteInput);
ListenableFutures.addErrorLogging(JdkFutureAdapters.listenInPoolThread(future), LOG, "Delete monitor profile {}", interfaceName);
}
}
}
Aggregations