X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Futil%2FDeviceInitializationUtils.java;h=52feaf74fe29b3ce8330bbcc1de882234a06c44e;hb=3077f0076078a7fff1c9a6539558a4448ad9ba17;hp=00ed2fb06af5d760a3978b1328250ec8b2fb64cb;hpb=e95857517f6d24a871f3811fc8c8c7f055e30267;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtils.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtils.java index 00ed2fb06a..52feaf74fe 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtils.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtils.java @@ -15,21 +15,20 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import java.math.BigInteger; -import java.net.Inet4Address; -import java.net.Inet6Address; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.concurrent.ExecutionException; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue; import org.opendaylight.openflowplugin.api.ConnectionException; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator; import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; @@ -39,8 +38,9 @@ import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey; import org.opendaylight.openflowplugin.impl.common.MultipartRequestInputFactory; import org.opendaylight.openflowplugin.impl.common.NodeStaticReplyTranslatorUtil; import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IetfInetUtil; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector; @@ -95,14 +95,16 @@ public class DeviceInitializationUtils { * * @param deviceContext * @param switchFeaturesMandatory + * @param convertorExecutor * @return future - recommended to have blocking call for this future */ - public static ListenableFuture initializeNodeInformation(final DeviceContext deviceContext, final boolean switchFeaturesMandatory) { + public static ListenableFuture initializeNodeInformation(final DeviceContext deviceContext, final boolean switchFeaturesMandatory, final ConvertorExecutor convertorExecutor) { Preconditions.checkArgument(deviceContext != null); final DeviceState deviceState = Preconditions.checkNotNull(deviceContext.getDeviceState()); + final DeviceInfo deviceInfo = deviceContext.getDeviceInfo(); final ConnectionContext connectionContext = Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext()); - final short version = deviceState.getVersion(); - LOG.trace("initalizeNodeInformation for node {}", deviceState.getNodeId()); + final short version = deviceInfo.getVersion(); + LOG.trace("initalizeNodeInformation for node {}", deviceInfo.getNodeId()); final SettableFuture returnFuture = SettableFuture.create(); addNodeToOperDS(deviceContext, returnFuture); final ListenableFuture>>> deviceFeaturesFuture; @@ -111,18 +113,18 @@ public class DeviceInitializationUtils { DeviceStateUtil.setDeviceStateBasedOnV10Capabilities(deviceState, capabilitiesV10); - deviceFeaturesFuture = createDeviceFeaturesForOF10(deviceContext, deviceState); + deviceFeaturesFuture = createDeviceFeaturesForOF10(deviceContext); // create empty tables after device description is processed chainTableTrunkWriteOF10(deviceContext, deviceFeaturesFuture); - final short ofVersion = deviceContext.getDeviceState().getVersion(); + final short ofVersion = deviceInfo.getVersion(); final TranslatorKey translatorKey = new TranslatorKey(ofVersion, PortGrouping.class.getName()); final MessageTranslator translator = deviceContext.oook() .lookupTranslator(translatorKey); - final BigInteger dataPathId = deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId(); + final BigInteger dataPathId = deviceContext.getDeviceInfo().getDatapathId(); for (final PortGrouping port : connectionContext.getFeatures().getPhyPort()) { - final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, deviceContext, null); + final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, deviceContext.getDeviceInfo(), null); final NodeConnectorId nodeConnectorId = NodeStaticReplyTranslatorUtil.nodeConnectorId( dataPathId.toString(), port.getPortNo(), ofVersion); @@ -131,21 +133,21 @@ public class DeviceInitializationUtils { ncBuilder.addAugmentation(FlowCapableNodeConnectorStatisticsData.class, new FlowCapableNodeConnectorStatisticsDataBuilder().build()); final NodeConnector connector = ncBuilder.build(); - final InstanceIdentifier connectorII = deviceState.getNodeInstanceIdentifier().child( + final InstanceIdentifier connectorII = deviceInfo.getNodeInstanceIdentifier().child( NodeConnector.class, connector.getKey()); try { deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, connectorII, connector); } catch (final Exception e) { - LOG.debug("Failed to write node {} to DS ", deviceContext.getDeviceState().getNodeId().toString(), + LOG.debug("initializeNodeInformation: Failed to write node {} to DS ", deviceInfo.getNodeId().toString(), e); } } } else if (OFConstants.OFP_VERSION_1_3 == version) { final Capabilities capabilities = connectionContext.getFeatures().getCapabilities(); - LOG.debug("Setting capabilities for device {}", deviceContext.getDeviceState().getNodeId()); + LOG.debug("Setting capabilities for device {}", deviceInfo.getNodeId()); DeviceStateUtil.setDeviceStateBasedOnV13Capabilities(deviceState, capabilities); - deviceFeaturesFuture = createDeviceFeaturesForOF13(deviceContext, deviceState, switchFeaturesMandatory); + deviceFeaturesFuture = createDeviceFeaturesForOF13(deviceContext, switchFeaturesMandatory, convertorExecutor); } else { deviceFeaturesFuture = Futures.immediateFailedFuture(new ConnectionException("Unsupported version " + version)); @@ -154,7 +156,7 @@ public class DeviceInitializationUtils { Futures.addCallback(deviceFeaturesFuture, new FutureCallback>>>() { @Override public void onSuccess(final List>> result) { - LOG.debug("All init data for node {} is in submited.", deviceState.getNodeId()); + LOG.debug("All init data for node {} is in submitted.", deviceInfo.getNodeId()); returnFuture.set(null); } @@ -163,7 +165,7 @@ public class DeviceInitializationUtils { // FIXME : remove session LOG.trace("Device capabilities gathering future failed."); LOG.trace("more info in exploration failure..", t); - LOG.debug("All init data for node {} was not submited correctly - connection has to go down.", deviceState.getNodeId()); + LOG.debug("All init data for node {} was not submited correctly - connection has to go down.", deviceInfo.getNodeId()); returnFuture.setException(t); } }); @@ -172,31 +174,30 @@ public class DeviceInitializationUtils { private static void addNodeToOperDS(final DeviceContext deviceContext, final SettableFuture future) { Preconditions.checkArgument(deviceContext != null); - final DeviceState deviceState = deviceContext.getDeviceState(); - final NodeBuilder nodeBuilder = new NodeBuilder().setId(deviceState.getNodeId()).setNodeConnector( + final NodeBuilder nodeBuilder = new NodeBuilder().setId(deviceContext.getDeviceInfo().getNodeId()).setNodeConnector( Collections.emptyList()); try { - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, deviceState.getNodeInstanceIdentifier(), + deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), nodeBuilder.build()); } catch (final Exception e) { - LOG.warn("Failed to write node {} to DS ", deviceState.getNodeId(), e); + LOG.warn("addNodeToOperDS: Failed to write node {} to DS ", deviceContext.getDeviceInfo().getNodeId(), e); future.cancel(true); } } private static ListenableFuture>>> createDeviceFeaturesForOF10( - final DeviceContext deviceContext, final DeviceState deviceState) { + final DeviceContext deviceContext) { final ListenableFuture>> replyDesc = getNodeStaticInfo(MultipartType.OFPMPDESC, - deviceContext, deviceState.getNodeInstanceIdentifier(), deviceState.getVersion()); + deviceContext, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), deviceContext.getDeviceInfo().getVersion()); return Futures.allAsList(Arrays.asList(replyDesc)); } private static ListenableFuture>>> createDeviceFeaturesForOF13( - final DeviceContext deviceContext, final DeviceState deviceState, final boolean switchFeaturesMandatory) { + final DeviceContext deviceContext, final boolean switchFeaturesMandatory, final ConvertorExecutor convertorExecutor) { final ListenableFuture>> replyDesc = getNodeStaticInfo(MultipartType.OFPMPDESC, - deviceContext, deviceState.getNodeInstanceIdentifier(), deviceState.getVersion()); + deviceContext, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), deviceContext.getDeviceInfo().getVersion()); //first process description reply, write data to DS and write consequent data if successful return Futures.transform(replyDesc, @@ -206,32 +207,32 @@ public class DeviceInitializationUtils { final RpcResult> rpcResult) throws Exception { translateAndWriteReply(MultipartType.OFPMPDESC, deviceContext, - deviceState.getNodeInstanceIdentifier(), rpcResult.getResult()); + deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), rpcResult.getResult(), convertorExecutor); final ListenableFuture>> replyMeterFeature = getNodeStaticInfo( MultipartType.OFPMPMETERFEATURES, deviceContext, - deviceState.getNodeInstanceIdentifier(), deviceState.getVersion()); + deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), deviceContext.getDeviceInfo().getVersion()); createSuccessProcessingCallback(MultipartType.OFPMPMETERFEATURES, deviceContext, - deviceState.getNodeInstanceIdentifier(), replyMeterFeature); + deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), replyMeterFeature, convertorExecutor); final ListenableFuture>> replyGroupFeatures = getNodeStaticInfo( MultipartType.OFPMPGROUPFEATURES, deviceContext, - deviceState.getNodeInstanceIdentifier(), deviceState.getVersion()); + deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), deviceContext.getDeviceInfo().getVersion()); createSuccessProcessingCallback(MultipartType.OFPMPGROUPFEATURES, deviceContext, - deviceState.getNodeInstanceIdentifier(), replyGroupFeatures); + deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), replyGroupFeatures, convertorExecutor); final ListenableFuture>> replyTableFeatures = getNodeStaticInfo( MultipartType.OFPMPTABLEFEATURES, deviceContext, - deviceState.getNodeInstanceIdentifier(), deviceState.getVersion()); + deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), deviceContext.getDeviceInfo().getVersion()); createSuccessProcessingCallback(MultipartType.OFPMPTABLEFEATURES, deviceContext, - deviceState.getNodeInstanceIdentifier(), replyTableFeatures); + deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), replyTableFeatures, convertorExecutor); final ListenableFuture>> replyPortDescription = getNodeStaticInfo( - MultipartType.OFPMPPORTDESC, deviceContext, deviceState.getNodeInstanceIdentifier(), - deviceState.getVersion()); + MultipartType.OFPMPPORTDESC, deviceContext, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), + deviceContext.getDeviceInfo().getVersion()); createSuccessProcessingCallback(MultipartType.OFPMPPORTDESC, deviceContext, - deviceState.getNodeInstanceIdentifier(), replyPortDescription); + deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), replyPortDescription, convertorExecutor); if (switchFeaturesMandatory) { return Futures.allAsList(Arrays.asList(replyMeterFeature, replyGroupFeatures, replyTableFeatures, replyPortDescription)); @@ -245,7 +246,8 @@ public class DeviceInitializationUtils { } static void translateAndWriteReply(final MultipartType type, final DeviceContext dContext, - final InstanceIdentifier nodeII, final Collection result) { + final InstanceIdentifier nodeII, final Collection result, + final ConvertorExecutor convertorExecutor) { try { for (final MultipartReply reply : result) { final MultipartReplyBody body = reply.getMultipartReplyBody(); @@ -264,7 +266,7 @@ public class DeviceInitializationUtils { final MultipartReplyTableFeatures tableFeaturesMP = ((MultipartReplyTableFeaturesCase) body) .getMultipartReplyTableFeatures(); final List tableFeatures = NodeStaticReplyTranslatorUtil - .nodeTableFeatureTranslator(tableFeaturesMP); + .nodeTableFeatureTranslator(tableFeaturesMP, dContext.getDeviceInfo().getVersion(), convertorExecutor); for (final TableFeatures tableFeature : tableFeatures) { final Short tableId = tableFeature.getTableId(); final KeyedInstanceIdentifier tableFeaturesII = @@ -314,11 +316,11 @@ public class DeviceInitializationUtils { final MultipartReplyPortDesc portDesc = ((MultipartReplyPortDescCase) body) .getMultipartReplyPortDesc(); for (final PortGrouping port : portDesc.getPorts()) { - final short ofVersion = dContext.getDeviceState().getVersion(); + final short ofVersion = dContext.getDeviceInfo().getVersion(); final TranslatorKey translatorKey = new TranslatorKey(ofVersion, PortGrouping.class.getName()); final MessageTranslator translator = dContext.oook() .lookupTranslator(translatorKey); - final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, dContext, null); + final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, dContext.getDeviceInfo(), null); final BigInteger dataPathId = dContext.getPrimaryConnectionContext().getFeatures() .getDatapathId(); @@ -343,18 +345,18 @@ public class DeviceInitializationUtils { } } } catch (final Exception e) { - LOG.debug("Failed to write node {} to DS ", dContext.getDeviceState().getNodeId().toString(), e); + LOG.debug("translateAndWriteReply: Failed to write node {} to DS ", dContext.getDeviceInfo().getNodeId().toString(), e); } } private static void createEmptyFlowCapableNodeInDs(final DeviceContext deviceContext) { final FlowCapableNodeBuilder flowCapableNodeBuilder = new FlowCapableNodeBuilder(); - final InstanceIdentifier fNodeII = deviceContext.getDeviceState().getNodeInstanceIdentifier() + final InstanceIdentifier fNodeII = deviceContext.getDeviceInfo().getNodeInstanceIdentifier() .augmentation(FlowCapableNode.class); try { deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, fNodeII, flowCapableNodeBuilder.build()); } catch (final Exception e) { - LOG.debug("Failed to write node {} to DS ", deviceContext.getDeviceState().getNodeId().toString(), e); + LOG.debug("createEmptyFlowCapableNodeInDs: Failed to write node {} to DS ", deviceContext.getDeviceInfo().getNodeId().toString(), e); } } @@ -365,7 +367,7 @@ public class DeviceInitializationUtils { if (remoteAddress == null) { LOG.warn("IP address of the node {} cannot be obtained. No connection with switch.", deviceContext - .getDeviceState().getNodeId()); + .getDeviceInfo().getNodeId()); return null; } LOG.info("IP address of switch is: {}", remoteAddress); @@ -387,7 +389,7 @@ public class DeviceInitializationUtils { try { dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableII, tableBuilder.build()); } catch (final Exception e) { - LOG.debug("Failed to write node {} to DS ", dContext.getDeviceState().getNodeId().toString(), e); + LOG.debug("makeEmptyTables: Failed to write node {} to DS ", dContext.getDeviceInfo().getNodeId().toString(), e); } } @@ -395,14 +397,15 @@ public class DeviceInitializationUtils { static void createSuccessProcessingCallback(final MultipartType type, final DeviceContext deviceContext, final InstanceIdentifier nodeII, - final ListenableFuture>> requestContextFuture) { + final ListenableFuture>> requestContextFuture, + final ConvertorExecutor convertorExecutor) { Futures.addCallback(requestContextFuture, new FutureCallback>>() { @Override public void onSuccess(final RpcResult> rpcResult) { final List result = rpcResult.getResult(); if (result != null) { - LOG.info("Static node {} info: {} collected", deviceContext.getDeviceState().getNodeId(), type); - translateAndWriteReply(type, deviceContext, nodeII, result); + LOG.info("Static node {} info: {} collected", deviceContext.getDeviceInfo().getNodeId(), type); + translateAndWriteReply(type, deviceContext, nodeII, result, convertorExecutor); } else { final Iterator rpcErrorIterator = rpcResult.getErrors().iterator(); while (rpcErrorIterator.hasNext()) { @@ -480,24 +483,23 @@ public class DeviceInitializationUtils { static void chainTableTrunkWriteOF10(final DeviceContext deviceContext, final ListenableFuture>>> deviceFeaturesFuture) { - Futures.addCallback(deviceFeaturesFuture, new FutureCallback>>>() { - @Override - public void onSuccess(final List>> results) { - boolean allSucceeded = true; - for (final RpcResult> rpcResult : results) { - allSucceeded &= rpcResult.isSuccessful(); - } - if (allSucceeded) { - createEmptyFlowCapableNodeInDs(deviceContext); - makeEmptyTables(deviceContext, deviceContext.getDeviceState().getNodeInstanceIdentifier(), - deviceContext.getDeviceState().getFeatures().getTables()); - } - } - @Override - public void onFailure(final Throwable t) { - //NOOP + try { + LOG.trace("Waiting for protocol version 1.0"); + List>> results = deviceFeaturesFuture.get(); + boolean allSucceeded = true; + for (final RpcResult> rpcResult : results) { + allSucceeded &= rpcResult.isSuccessful(); } - }); + if (allSucceeded) { + LOG.debug("Creating emtpy flow capable node: {}", deviceContext.getDeviceInfo().getNodeId().getValue()); + createEmptyFlowCapableNodeInDs(deviceContext); + LOG.debug("Creating emtpy tables for {}", deviceContext.getDeviceInfo().getNodeId().getValue()); + makeEmptyTables(deviceContext, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), + deviceContext.getPrimaryConnectionContext().getFeatures().getTables()); + } + } catch (InterruptedException | ExecutionException e) { + LOG.warn("Error occurred in preparation node {} for protocol 1.0", deviceContext.getDeviceInfo().getNodeId().getValue()); + } } }