From: Kiran N Upadhyaya Date: Mon, 4 Apr 2016 13:22:12 +0000 (+0530) Subject: Tunnel monitoring changes X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=vpnservice.git;a=commitdiff_plain;h=ba0bcf1091bd912dc1fe8c7c6586f817def709cd Tunnel monitoring changes Code revision in Aliveness Monitor files related to fetching mac address from data store. Monitor profile creation for both the tunnel endpoints was fixed. Changes in JUNIT test cases related to tunnel monitoring. Change-Id: I0843ee855f854a3fd98d212516292d8b34a8409c Signed-off-by: Kiran N Upadhyaya --- diff --git a/alivenessmonitor/alivenessmonitor-api/src/main/yang/aliveness-monitor.yang b/alivenessmonitor/alivenessmonitor-api/src/main/yang/aliveness-monitor.yang index 134288f6..3d521bfb 100644 --- a/alivenessmonitor/alivenessmonitor-api/src/main/yang/aliveness-monitor.yang +++ b/alivenessmonitor/alivenessmonitor-api/src/main/yang/aliveness-monitor.yang @@ -65,6 +65,17 @@ module aliveness-monitor { } } + rpc monitor-profile-get { + input { + container profile { + uses monitor-profile-params; + } + } + output { + leaf profile-id { type uint32; } + } + } + rpc monitor-start { input { container config { diff --git a/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AbstractAlivenessProtocolHandler.java b/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AbstractAlivenessProtocolHandler.java index 9537a9f6..bfa25654 100644 --- a/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AbstractAlivenessProtocolHandler.java +++ b/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AbstractAlivenessProtocolHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -13,6 +13,7 @@ import java.util.concurrent.Future; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetNodeconnectorIdFromInterfaceInputBuilder; @@ -81,13 +82,22 @@ abstract class AbstractAlivenessProtocolHandler implements AlivenessProtocolHand return new NodeId(ncId.getValue().substring(0,ncId.getValue().lastIndexOf(":"))); } - protected byte[] getMacAddress(String interfaceName) { - InstanceIdentifier ncId = getNodeConnectorId(interfaceName); - if(ncId != null) { - String macAddress = inventoryReader.getMacAddress(ncId); - if(!Strings.isNullOrEmpty(macAddress)) { - return AlivenessMonitorUtil.parseMacAddress(macAddress); - } + protected org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceFromOperDS(String interfaceName){ + InstanceIdentifier.InstanceIdentifierBuilder idBuilder = + InstanceIdentifier.builder(InterfacesState.class).child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class, + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey(interfaceName)); + InstanceIdentifier id = idBuilder.build(); + Optional interfaceStateOptional = read(LogicalDatastoreType.OPERATIONAL, id); + if(interfaceStateOptional.isPresent()) { + return interfaceStateOptional.get(); + } + return null; + } + + protected byte[] getMacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState, String interfaceName) { + String macAddress = interfaceState.getPhysAddress().getValue(); + if(!Strings.isNullOrEmpty(macAddress)) { + return AlivenessMonitorUtil.parseMacAddress(macAddress); } return null; } diff --git a/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessMonitor.java b/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessMonitor.java index a00c7a64..fb24cdaf 100644 --- a/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessMonitor.java +++ b/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessMonitor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -52,6 +52,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.MonitorStopInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.MonitorUnpauseInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.MonitoringMode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.MonitorProfileGetInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.MonitorProfileGetOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.MonitorProfileGetOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629._interface.monitor.map.InterfaceMonitorEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629._interface.monitor.map.InterfaceMonitorEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629._interface.monitor.map.InterfaceMonitorEntryKey; @@ -555,10 +558,13 @@ public class AlivenessMonitor implements AlivenessMonitorService, PacketProcessi WriteTransaction tx = broker.newWriteOnlyTransaction(); 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); tx.put(LogicalDatastoreType.OPERATIONAL, getMonitorMapId(monitorId), mapEntry, CREATE_MISSING_PARENT); + LOG.debug("adding oper map entry {}", mapEntry); Futures.addCallback(tx.submit(), new FutureCallback() { @Override @@ -970,6 +976,36 @@ public class AlivenessMonitor implements AlivenessMonitorService, PacketProcessi return result; } + + @Override + public Future> monitorProfileGet(MonitorProfileGetInput input){ + LOG.debug("Monitor Profile Get operation for input profile- {}", input.getProfile()); + RpcResultBuilder rpcResultBuilder; + try{ + final Long profileId = getExistingProfileId(input); + + MonitorProfileGetOutputBuilder output = new MonitorProfileGetOutputBuilder().setProfileId(profileId); + rpcResultBuilder = RpcResultBuilder.success(); + rpcResultBuilder.withResult(output.build()); + }catch(Exception e){ + LOG.error("Retrieval of monitor profile ID for input {} failed due to {}" , input, e); + rpcResultBuilder = RpcResultBuilder.failed(); + } + return Futures.immediateFuture(rpcResultBuilder.build()); + } + + private Long getExistingProfileId(MonitorProfileGetInput input){ + org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.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.valueOf(getUniqueId(idKey))); + } + private String getUniqueProfileKey(Long failureThreshold,Long monitorInterval,Long monitorWindow,EtherTypes ethType) { return new StringBuilder().append(failureThreshold).append(AlivenessMonitorConstants.SEPERATOR) .append(monitorInterval).append(AlivenessMonitorConstants.SEPERATOR) diff --git a/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessProtocolHandlerLLDP.java b/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessProtocolHandlerLLDP.java index c1c045a4..1a4a42b7 100644 --- a/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessProtocolHandlerLLDP.java +++ b/alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessProtocolHandlerLLDP.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -23,6 +23,7 @@ import org.opendaylight.controller.liblldp.LLDPTLV; import org.opendaylight.controller.liblldp.LLDPTLV.TLVType; import org.opendaylight.controller.liblldp.Packet; import org.opendaylight.controller.liblldp.PacketException; +import org.opendaylight.vpnservice.interfacemgr.globals.IfmConstants; import org.opendaylight.vpnservice.mdsalutil.ActionInfo; import org.opendaylight.vpnservice.mdsalutil.ActionType; import org.opendaylight.vpnservice.mdsalutil.MDSALUtil; @@ -139,7 +140,8 @@ public class AlivenessProtocolHandlerLLDP extends AbstractAlivenessProtocolHandl } //Get Mac Address for the source interface - byte[] sourceMac = getMacAddress(sourceInterface); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = getInterfaceFromOperDS(sourceInterface); + byte[] sourceMac = getMacAddress(interfaceState, sourceInterface); if(sourceMac == null) { LOG.error("Could not read mac address for the source interface {} from the Inventory. " + "LLDP packet cannot be send.", sourceInterface); @@ -150,26 +152,19 @@ public class AlivenessProtocolHandlerLLDP extends AbstractAlivenessProtocolHandl long nodeId = -1, portNum = -1; try { - GetPortFromInterfaceInput input = new GetPortFromInterfaceInputBuilder().setIntfName(sourceInterface).build(); - Future> portOutput = interfaceService.getPortFromInterface(input); - RpcResult result = portOutput.get(); - if(result.isSuccessful()) { - GetPortFromInterfaceOutput output = result.getResult(); - nodeId = output.getDpid().longValue(); - portNum = output.getPortno(); - } else { - LOG.error("Could not retrieve port details for interface {}", sourceInterface); - return; - } - }catch(InterruptedException | ExecutionException e) { - LOG.error("Failed to retrieve interface service RPC Result ", e); + String lowerLayerIf = interfaceState.getLowerLayerIf().get(0); + NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf); + nodeId = Long.valueOf(getDpnFromNodeConnectorId(nodeConnectorId)); + portNum = Long.valueOf(getPortNoFromNodeConnectorId(nodeConnectorId)); + }catch(Exception e) { + LOG.error("Failed to retrieve node id and port number ", e); return; } Ethernet ethenetLLDPPacket = makeLLDPPacket(Long.toString(nodeId), portNum, 0, sourceMac, sourceInterface); try { - List actions = getInterfaceActions(sourceInterface, portNum); + List actions = getInterfaceActions(interfaceState, portNum); if(actions.isEmpty()) { LOG.error("No interface actions to send packet out over interface {}", sourceInterface); return; @@ -182,14 +177,27 @@ public class AlivenessProtocolHandlerLLDP extends AbstractAlivenessProtocolHandl } } - private List getInterfaceActions(String interfaceName, long portNum) throws InterruptedException, ExecutionException { + public static String getDpnFromNodeConnectorId(NodeConnectorId portId) { + /* + * NodeConnectorId is of form 'openflow:dpnid:portnum' + */ + String[] split = portId.getValue().split(IfmConstants.OF_URI_SEPARATOR); + return split[1]; + } + + public static String getPortNoFromNodeConnectorId(NodeConnectorId portId) { + /* + * NodeConnectorId is of form 'openflow:dpnid:portnum' + */ + String[] split = portId.getValue().split(IfmConstants.OF_URI_SEPARATOR); + return split[2]; + } + private List getInterfaceActions(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState,long portNum) throws InterruptedException, ExecutionException { Class intfType; - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface interfaceInfo = - getInterfaceFromConfigDS(interfaceName); - if(interfaceInfo != null) { - intfType = interfaceInfo.getType(); + if(interfaceState != null) { + intfType = interfaceState.getType(); } else { - LOG.error("Could not retrieve port type for interface {} to construct actions", interfaceName); + LOG.error("Could not retrieve port type for interface {} to construct actions", interfaceState.getName()); return Collections.emptyList(); } diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/AlivenessMonitorUtils.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/AlivenessMonitorUtils.java index 12992dc9..36d26ff9 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/AlivenessMonitorUtils.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/AlivenessMonitorUtils.java @@ -224,13 +224,37 @@ public class AlivenessMonitorUtils { if(rpcResult.isSuccessful()) { return rpcResult.getResult().getProfileId(); } else { - LOG.warn("RPC Call to Get Profile Id Id returned with Errors {}", rpcResult.getErrors()); + LOG.warn("RPC Call to Get Profile Id Id returned with Errors {}.. Trying to fetch existing profile ID", rpcResult.getErrors()); + try{ + Profile createProfile = monitorProfileCreateInput.getProfile(); + Future> existingProfile = alivenessMonitor.monitorProfileGet(buildMonitorGetProfile(createProfile.getMonitorInterval(), createProfile.getMonitorWindow(), createProfile.getFailureThreshold(), createProfile.getProtocolType())); + RpcResult rpcGetResult = existingProfile.get(); + if(rpcGetResult.isSuccessful()){ + return rpcGetResult.getResult().getProfileId(); + }else{ + LOG.warn("RPC Call to Get Existing Profile Id returned with Errors {}", rpcGetResult.getErrors()); + } + }catch(Exception e){ + LOG.warn("Exception when getting existing profile",e); + } } } catch (InterruptedException | ExecutionException e) { LOG.warn("Exception when allocating profile Id",e); } return 0; } + + private static MonitorProfileGetInput buildMonitorGetProfile(long monitorInterval, long monitorWindow, long failureThreshold, EtherTypes protocolType){ + MonitorProfileGetInputBuilder buildGetProfile = new MonitorProfileGetInputBuilder(); + org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.monitor.profile.get.input.ProfileBuilder profileBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.monitor.profile.get.input.ProfileBuilder(); + profileBuilder.setFailureThreshold(failureThreshold); + profileBuilder.setMonitorInterval(monitorInterval); + profileBuilder.setMonitorWindow(monitorWindow); + profileBuilder.setProtocolType(protocolType); + buildGetProfile.setProfile(profileBuilder.build()); + return (buildGetProfile.build()); + }; + public static long allocateProfile(AlivenessMonitorService alivenessMonitor, long FAILURE_THRESHOLD, long MONITORING_INTERVAL, long MONITORING_WINDOW, EtherTypes etherTypes) { MonitorProfileCreateInput input = new MonitorProfileCreateInputBuilder(). diff --git a/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/InterfaceManagerTestUtil.java b/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/InterfaceManagerTestUtil.java index 28bb7643..c3ca61c9 100644 --- a/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/InterfaceManagerTestUtil.java +++ b/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/InterfaceManagerTestUtil.java @@ -170,7 +170,7 @@ public class InterfaceManagerTestUtil { IpAddress remoteIp = new IpAddress(Ipv4Address.getDefaultInstance(remoteIpStr)); IpAddress localIp = new IpAddress(Ipv4Address.getDefaultInstance(localIpStr)); IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp).setTunnelGateway(localIp).setTunnelSource(localIp) - .setTunnelInterfaceType( tunType).setInternal(true).build(); + .setTunnelInterfaceType( tunType).setInternal(true).setMonitorEnabled(false).build(); builder.addAugmentation(IfTunnel.class, tunnel); return builder.build(); }