}
}
+ rpc monitor-profile-get {
+ input {
+ container profile {
+ uses monitor-profile-params;
+ }
+ }
+ output {
+ leaf profile-id { type uint32; }
+ }
+ }
+
rpc monitor-start {
input {
container config {
/*
- * 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,
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;
return new NodeId(ncId.getValue().substring(0,ncId.getValue().lastIndexOf(":")));
}
- protected byte[] getMacAddress(String interfaceName) {
- InstanceIdentifier<NodeConnector> 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<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> 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<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> id = idBuilder.build();
+ Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> 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;
}
/*
- * 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,
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;
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<Void>() {
@Override
return result;
}
+
+ @Override
+ public Future<RpcResult<MonitorProfileGetOutput>> monitorProfileGet(MonitorProfileGetInput input){
+ LOG.debug("Monitor Profile Get operation for input profile- {}", input.getProfile());
+ RpcResultBuilder<MonitorProfileGetOutput> 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)
/*
- * 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,
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;
}
//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);
long nodeId = -1, portNum = -1;
try {
- GetPortFromInterfaceInput input = new GetPortFromInterfaceInputBuilder().setIntfName(sourceInterface).build();
- Future<RpcResult<GetPortFromInterfaceOutput>> portOutput = interfaceService.getPortFromInterface(input);
- RpcResult<GetPortFromInterfaceOutput> 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<ActionInfo> actions = getInterfaceActions(sourceInterface, portNum);
+ List<ActionInfo> actions = getInterfaceActions(interfaceState, portNum);
if(actions.isEmpty()) {
LOG.error("No interface actions to send packet out over interface {}", sourceInterface);
return;
}
}
- private List<ActionInfo> 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<ActionInfo> 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<? extends InterfaceType> 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();
}
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<RpcResult<MonitorProfileGetOutput>> existingProfile = alivenessMonitor.monitorProfileGet(buildMonitorGetProfile(createProfile.getMonitorInterval(), createProfile.getMonitorWindow(), createProfile.getFailureThreshold(), createProfile.getProtocolType()));
+ RpcResult<MonitorProfileGetOutput> 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().
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();
}