X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2Fsal%2FModelDrivenSwitchImpl.java;h=4b36178d2038169b066d7e06c54c8c9ecd2e1ebc;hb=d4b81f43deae62aaea2f3ed2eb10652eabaa1a5c;hp=d667d52f0ff8004220280d2a10fd61dff2111163;hpb=f22a71b353463817693fa69c50456d02f20ece78;p=openflowplugin.git diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java index d667d52f0f..4b36178d20 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java @@ -13,8 +13,9 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; -import org.opendaylight.controller.sal.common.util.Arguments; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; import org.opendaylight.controller.sal.common.util.Rpcs; import org.opendaylight.openflowjava.protocol.api.util.BinContent; import org.opendaylight.openflowplugin.openflow.md.OFConstants; @@ -22,23 +23,24 @@ import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistingu import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor; import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService; +import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; +import org.opendaylight.openflowplugin.openflow.md.core.session.TransactionKey; +import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder; @@ -48,22 +50,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.G import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowTableStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowTableStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder; @@ -73,6 +65,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAddedBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemovedBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdatedBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder; @@ -91,13 +86,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111. import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAddedBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemovedBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdatedBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder; @@ -116,39 +112,24 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111. import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder; @@ -172,16 +153,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures; import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.GetPortOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllPortsStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllPortsStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllPortsStatisticsOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetPortStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetPortStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetPortStatisticsOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder; @@ -195,102 +175,105 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.Upd import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import com.google.common.base.Objects; import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.JdkFutureAdapters; /** * RPC implementation of MD-switch */ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { - private static final Logger LOG = org.slf4j.LoggerFactory - .getLogger(ModelDrivenSwitchImpl.class); + private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(ModelDrivenSwitchImpl.class); private final NodeId nodeId; - private final IMessageDispatchService messageService ; + private final IMessageDispatchService messageService; private short version = 0; - - protected ModelDrivenSwitchImpl(NodeId nodeId, - InstanceIdentifier identifier, SessionContext context) { + private final SessionContext session; + NotificationProviderService rpcNotificationProviderService; + private OFRpcTaskHelper rpcTaskHelper; + + // TODO:read timeout from configSubsystem + protected long maxTimeout = 1000; + protected TimeUnit maxTimeoutUnit = TimeUnit.MILLISECONDS; + + protected ModelDrivenSwitchImpl(final NodeId nodeId, final InstanceIdentifier identifier, final SessionContext context) { super(identifier, context); this.nodeId = nodeId; - messageService = sessionContext.getMessageDispatchService() ; + messageService = sessionContext.getMessageDispatchService(); version = context.getPrimaryConductor().getVersion(); + this.session = context; + rpcNotificationProviderService = OFSessionUtil.getSessionManager().getNotificationProviderService(); + rpcTaskHelper = new OFRpcTaskHelper(messageService, context, rpcNotificationProviderService); } - @Override - public Future> addFlow(AddFlowInput input) { - // Convert the AddFlowInput to FlowModInput - FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version); - BarrierInputBuilder barrierInput = new BarrierInputBuilder(); - barrierInput.setVersion(version); - - // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch - - SwitchConnectionDistinguisher cookie = null ; - if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) { - Future> barrierOFLib = messageService.barrier(barrierInput.build(), cookie); - } - - LOG.debug("Calling the FlowMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ; - - RpcResult rpcResultFromOFLib = null ; - - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for AddFlow RPC" + ex.getMessage()); - } - - UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ; - - AddFlowOutputBuilder addFlowOutput = new AddFlowOutputBuilder() ; - addFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ; - AddFlowOutput result = addFlowOutput.build(); - - Collection errors = rpcResultFromOFLib.getErrors() ; - RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); - - LOG.debug("Returning the Add Flow RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + public Future> addFlow(final AddFlowInput input) { + LOG.debug("Calling the FlowMod RPC method on MessageDispatchService"); + // use primary connection + SwitchConnectionDistinguisher cookie = null; + + OFRpcTask> task = + OFRpcTaskFactory.createAddFlowTask(maxTimeout, maxTimeoutUnit, rpcTaskHelper); + rpcTaskHelper.initTask(task, input, cookie); + OFSessionUtil.getSessionManager().getRpcPool().submit(task); + + return Futures.transform(JdkFutureAdapters.listenInPoolThread(task.getResult()), + OFRpcFutureResultTransformFactory.createForAddFlowOutput()); } - @Override - public Future> addGroup(AddGroupInput input) { - // Convert the AddGroupInput to GroupModInput - GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input, version); - - // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch + @Override + public Future> addGroup(final AddGroupInput input) { + LOG.debug("Calling the GroupMod RPC method on MessageDispatchService"); + Long xId = null; - SwitchConnectionDistinguisher cookie = null ; + // use primary connection + SwitchConnectionDistinguisher cookie = null; + + if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) { + xId = session.getNextXid(); + BarrierInputBuilder barrierInput = new BarrierInputBuilder(); + barrierInput.setVersion(version); + barrierInput.setXid(xId); + @SuppressWarnings("unused") + Future> barrierOFLib = messageService.barrier(barrierInput.build(), cookie); + } - LOG.debug("Calling the GroupMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ; + // Convert the AddGroupInput to GroupModInput + GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input, version, this.getSessionContext() + .getFeatures().getDatapathId()); + xId = session.getNextXid(); + ofGroupModInput.setXid(xId); + + if (null != rpcNotificationProviderService) { + GroupAddedBuilder groupMod = new GroupAddedBuilder( + (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group) input); + groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue()))); + groupMod.setGroupRef(input.getGroupRef()); + rpcNotificationProviderService.publish(groupMod.build()); + } - RpcResult rpcResultFromOFLib = null ; + session.getbulkTransactionCache().put(new TransactionKey(xId), input); + Future> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie); + RpcResult rpcResultFromOFLib = null; - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for AddGroup RPC" + ex.getMessage()); - } + try { + rpcResultFromOFLib = resultFromOFLib.get(); + } catch (Exception ex) { + LOG.error(" Error while getting result for AddGroup RPC" + ex.getMessage()); + } - UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ; + UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult(); - AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder() ; - addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ; - AddGroupOutput result = addGroupOutput.build(); + AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder(); + addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()); + AddGroupOutput result = addGroupOutput.build(); - Collection errors = rpcResultFromOFLib.getErrors() ; + Collection errors = rpcResultFromOFLib.getErrors(); RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); LOG.debug("Returning the Add Group RPC result to MD-SAL"); @@ -298,33 +281,54 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { } @Override - public Future> addMeter(AddMeterInput input) { - // Convert the AddMeterInput to MeterModInput - MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version); - - // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch + public Future> addMeter(final AddMeterInput input) { + LOG.debug("Calling the MeterMod RPC method on MessageDispatchService"); + Long xId = null; + // For Meter provisioning, the SwitchConnectionDistinguisher is set to + // null so + // the request can be routed through any connection to the switch + + SwitchConnectionDistinguisher cookie = null; + if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) { + xId = session.getNextXid(); + BarrierInputBuilder barrierInput = new BarrierInputBuilder(); + barrierInput.setVersion(version); + barrierInput.setXid(xId); + @SuppressWarnings("unused") + Future> barrierOFLib = messageService.barrier(barrierInput.build(), cookie); + } - SwitchConnectionDistinguisher cookie = null ; + // Convert the AddMeterInput to MeterModInput + MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input, version); + xId = session.getNextXid(); + ofMeterModInput.setXid(xId); + + if (null != rpcNotificationProviderService) { + MeterAddedBuilder meterMod = new MeterAddedBuilder( + (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter) input); + meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue()))); + meterMod.setMeterRef(input.getMeterRef()); + rpcNotificationProviderService.publish(meterMod.build()); + } - LOG.debug("Calling the MeterMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ; + session.getbulkTransactionCache().put(new TransactionKey(xId), input); + Future> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie); - RpcResult rpcResultFromOFLib = null ; + RpcResult rpcResultFromOFLib = null; - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for AddMeter RPC" + ex.getMessage()); - } + try { + rpcResultFromOFLib = resultFromOFLib.get(); + } catch (Exception ex) { + LOG.error(" Error while getting result for AddMeter RPC" + ex.getMessage()); + } - UpdateMeterOutput updateMeterOutput = rpcResultFromOFLib.getResult() ; + UpdateMeterOutput updateMeterOutput = rpcResultFromOFLib.getResult(); - AddMeterOutputBuilder addMeterOutput = new AddMeterOutputBuilder() ; - addMeterOutput.setTransactionId(updateMeterOutput.getTransactionId()) ; - AddMeterOutput result = addMeterOutput.build(); + AddMeterOutputBuilder addMeterOutput = new AddMeterOutputBuilder(); + addMeterOutput.setTransactionId(updateMeterOutput.getTransactionId()); + AddMeterOutput result = addMeterOutput.build(); - Collection errors = rpcResultFromOFLib.getErrors() ; + Collection errors = rpcResultFromOFLib.getErrors(); RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); LOG.debug("Returning the Add Meter RPC result to MD-SAL"); @@ -332,74 +336,112 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { } @Override - public Future> removeFlow(RemoveFlowInput input) { - // Convert the RemoveFlowInput to FlowModInput - FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, version); - BarrierInputBuilder barrierInput = new BarrierInputBuilder(); - barrierInput.setVersion(version); + public Future> removeFlow(final RemoveFlowInput input) { + LOG.debug("Calling the removeFlow RPC method on MessageDispatchService"); + Long xId = null; + // For Flow provisioning, the SwitchConnectionDistinguisher is set to + // null so + // the request can be routed through any connection to the switch + + SwitchConnectionDistinguisher cookie = null; + if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) { + BarrierInputBuilder barrierInput = new BarrierInputBuilder(); + xId = session.getNextXid(); + barrierInput.setXid(xId); + barrierInput.setVersion(version); + @SuppressWarnings("unused") + Future> barrierOFLib = messageService.barrier(barrierInput.build(), cookie); + } - // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch + // Convert the RemoveFlowInput to FlowModInput + FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(input, version, this.getSessionContext() + .getFeatures().getDatapathId()); + xId = session.getNextXid(); + ofFlowModInput.setXid(xId); + + if (null != rpcNotificationProviderService) { + FlowRemovedBuilder removeFlow = new FlowRemovedBuilder( + (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) input); + removeFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue()))); + removeFlow.setFlowRef(input.getFlowRef()); + rpcNotificationProviderService.publish(removeFlow.build()); + } - SwitchConnectionDistinguisher cookie = null ; - if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) { - Future> barrierOFLib = messageService.barrier(barrierInput.build(), cookie); - } - - LOG.debug("Calling the FlowMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ; + session.getbulkTransactionCache().put(new TransactionKey(xId), input); + Future> resultFromOFLib = messageService.flowMod(ofFlowModInput.build(), cookie); - RpcResult rpcResultFromOFLib = null ; + RpcResult rpcResultFromOFLib = null; - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for remove Flow RPC" + ex.getMessage()); - } + try { + rpcResultFromOFLib = resultFromOFLib.get(); + } catch (Exception ex) { + LOG.error(" Error while getting result for remove Flow RPC" + ex.getMessage()); + } - UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ; + UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult(); - RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder() ; - removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ; - RemoveFlowOutput result = removeFlowOutput.build(); + RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder(); + removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()); + RemoveFlowOutput result = removeFlowOutput.build(); - Collection errors = rpcResultFromOFLib.getErrors() ; + Collection errors = rpcResultFromOFLib.getErrors(); RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); - LOG.debug("Returning the Remove Flow RPC result to MD-SAL"); + LOG.debug("Returning the Remove Flow RPC result to MD-SAL"); return Futures.immediateFuture(rpcResult); } @Override - public Future> removeGroup( - RemoveGroupInput input) { - // Convert the RemoveGroupInput to GroupModInput - GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input, version); + public Future> removeGroup(final RemoveGroupInput input) { + LOG.debug("Calling the Remove Group RPC method on MessageDispatchService"); + Long xId = null; + // For Flow provisioning, the SwitchConnectionDistinguisher is set to + // null so + // the request can be routed through any connection to the switch - // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch + SwitchConnectionDistinguisher cookie = null; + if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) { + xId = session.getNextXid(); + BarrierInputBuilder barrierInput = new BarrierInputBuilder(); + barrierInput.setVersion(version); + barrierInput.setXid(xId); + @SuppressWarnings("unused") + Future> barrierOFLib = messageService.barrier(barrierInput.build(), cookie); + } - SwitchConnectionDistinguisher cookie = null ; + // Convert the RemoveGroupInput to GroupModInput + GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input, version, this.getSessionContext() + .getFeatures().getDatapathId()); + xId = session.getNextXid(); + ofGroupModInput.setXid(xId); + + if (null != rpcNotificationProviderService) { + GroupRemovedBuilder groupMod = new GroupRemovedBuilder( + (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group) input); + groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue()))); + groupMod.setGroupRef(input.getGroupRef()); + rpcNotificationProviderService.publish(groupMod.build()); + } - LOG.debug("Calling the GroupMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ; + session.getbulkTransactionCache().put(new TransactionKey(xId), input); + Future> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie); - RpcResult rpcResultFromOFLib = null ; + RpcResult rpcResultFromOFLib = null; - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for RemoveGroup RPC" + ex.getMessage()); - } + try { + rpcResultFromOFLib = resultFromOFLib.get(); + } catch (Exception ex) { + LOG.error(" Error while getting result for RemoveGroup RPC" + ex.getMessage()); + } - UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ; + UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult(); - RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder() ; - removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ; - RemoveGroupOutput result = removeGroupOutput.build(); + RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder(); + removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()); + RemoveGroupOutput result = removeGroupOutput.build(); - Collection errors = rpcResultFromOFLib.getErrors() ; + Collection errors = rpcResultFromOFLib.getErrors(); RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); LOG.debug("Returning the Remove Group RPC result to MD-SAL"); @@ -407,35 +449,54 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { } @Override - public Future> removeMeter( - RemoveMeterInput input) { - // Convert the RemoveMeterInput to MeterModInput - MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version); - - - // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch + public Future> removeMeter(final RemoveMeterInput input) { + LOG.debug("Calling the Remove MeterMod RPC method on MessageDispatchService"); + Long xId = null; + + // For Meter provisioning, the SwitchConnectionDistinguisher is set to + // null so + // the request can be routed through any connection to the switch + SwitchConnectionDistinguisher cookie = null; + if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) { + xId = session.getNextXid(); + BarrierInputBuilder barrierInput = new BarrierInputBuilder(); + barrierInput.setVersion(version); + barrierInput.setXid(xId); + @SuppressWarnings("unused") + Future> barrierOFLib = messageService.barrier(barrierInput.build(), cookie); + } - SwitchConnectionDistinguisher cookie = null ; + // Convert the RemoveMeterInput to MeterModInput + MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input, version); + xId = session.getNextXid(); + ofMeterModInput.setXid(xId); + + if (null != rpcNotificationProviderService) { + MeterRemovedBuilder meterMod = new MeterRemovedBuilder( + (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter) input); + meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue()))); + meterMod.setMeterRef(input.getMeterRef()); + rpcNotificationProviderService.publish(meterMod.build()); + } - LOG.debug("Calling the MeterMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ; + session.getbulkTransactionCache().put(new TransactionKey(xId), input); + Future> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie); - RpcResult rpcResultFromOFLib = null ; + RpcResult rpcResultFromOFLib = null; - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for RemoveMeter RPC" + ex.getMessage()); - } + try { + rpcResultFromOFLib = resultFromOFLib.get(); + } catch (Exception ex) { + LOG.error(" Error while getting result for RemoveMeter RPC" + ex.getMessage()); + } - UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult() ; + UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult(); - RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder() ; - removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId()) ; - RemoveMeterOutput result = removeMeterOutput.build(); + RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder(); + removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId()); + RemoveMeterOutput result = removeMeterOutput.build(); - Collection errors = rpcResultFromOFLib.getErrors() ; + Collection errors = rpcResultFromOFLib.getErrors(); RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); LOG.debug("Returning the Remove Meter RPC result to MD-SAL"); @@ -443,82 +504,25 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { } @Override - public Future> transmitPacket(TransmitPacketInput input) { - LOG.info("TransmitPacket - {}",input); - // Convert TransmitPacket to PacketOutInput - - // TODO VD create PacketConvertor and move convert logic there - - // Build Port ID from TransmitPacketInput.Ingress - PortNumber inPortNr = null; - - List inArgs = input.getIngress().getValue().getPath(); - if (inArgs.size() >= 3) { - InstanceIdentifier.IdentifiableItem item = Arguments.checkInstanceOf(inArgs.get(2), InstanceIdentifier.IdentifiableItem.class); - NodeConnectorKey key = Arguments.checkInstanceOf(item.getKey(), NodeConnectorKey.class); - String[] split = key.getId().getValue().split(":"); - Long port = Long.decode(split[split.length-1]); - inPortNr = new PortNumber(port); - } else { - // TODO Ed could by in this way or Exception or something else ? - inPortNr = new PortNumber(0xfffffffdL); - } - - // Build Buffer ID from TransmitPacketInput.Ingress - // TODO VD P! find how to fix PacketIn to add BufferID to augmetation - Long bufferId = OFConstants.OFP_NO_BUFFER; - - PortNumber outPort = null; - NodeConnectorRef outRef = input.getEgress(); - List outArgs = outRef.getValue().getPathArguments(); - if (outArgs.size() >= 3) { - InstanceIdentifier.IdentifiableItem item = Arguments.checkInstanceOf(outArgs.get(2), InstanceIdentifier.IdentifiableItem.class); - NodeConnectorKey key = Arguments.checkInstanceOf(item.getKey(), NodeConnectorKey.class); - String[] split = key.getId().getValue().split(":"); - Long port = Long.decode(split[split.length-1]); - outPort = new PortNumber(port); - } else { - new Exception("PORT NR not exist in Egress"); //TODO : P4 search for some normal exception - } - - // TODO VD P! wait for way to move Actions (e.g. augmentation) - - // TODO VD implementation for testing PacketIn (REMOVE IT) - List actions = new ArrayList(); - ActionsListBuilder asBuild = new ActionsListBuilder(); - ActionBuilder aBuild = new ActionBuilder(); - aBuild.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class); - PortActionBuilder paBuild = new PortActionBuilder(); - paBuild.setPort(outPort); - aBuild.addAugmentation(PortAction.class, paBuild.build()); - MaxLengthActionBuilder mlBuild = new MaxLengthActionBuilder(); - mlBuild.setMaxLength(0xffff); - aBuild.addAugmentation(MaxLengthAction.class, mlBuild.build()); - asBuild.setAction(aBuild.build()); - actions.add(asBuild.build()); - - PacketOutInputBuilder builder = new PacketOutInputBuilder(); - builder.setActionsList(actions); - builder.setData(input.getPayload()); - builder.setVersion(version); - builder.setXid(sessionContext.getNextXid()); - builder.setInPort(inPortNr); - builder.setBufferId(bufferId); - // -------------------------------------------------------- - - PacketOutInput message = builder.build(); - - // TODO VD NULL for yet - find how to translate cookie from TransmitPacketInput -// SwitchConnectionDistinguisher cookie = ( "what is need to do" ) input.getCookie(); - SwitchConnectionDistinguisher cookie = null ; - - LOG.debug("Calling the transmitPacket RPC method"); - return messageService.packetOut(message, cookie); + public Future> transmitPacket(final TransmitPacketInput input) { + LOG.debug("TransmitPacket - {}", input); + // Convert TransmitPacket to PacketOutInput + PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, sessionContext.getNextXid(), + sessionContext.getFeatures().getDatapathId()); + + // TODO VD NULL for yet - find how to translate cookie from + // TransmitPacketInput + // SwitchConnectionDistinguisher cookie = ( "what is need to do" ) + // input.getCookie(); + SwitchConnectionDistinguisher cookie = null; + + LOG.debug("Calling the transmitPacket RPC method"); + return messageService.packetOut(message, cookie); } - private FlowModInputBuilder toFlowModInputBuilder(Flow source) { + private FlowModInputBuilder toFlowModInputBuilder(final Flow source) { FlowModInputBuilder target = new FlowModInputBuilder(); - target.setCookie(source.getCookie()); + target.setCookie(source.getCookie().getValue()); target.setIdleTimeout(source.getIdleTimeout()); target.setHardTimeout(source.getHardTimeout()); target.setMatch(toMatch(source.getMatch())); @@ -526,8 +530,7 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { return target; } - private Match toMatch( - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) { + private Match toMatch(final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) { MatchBuilder target = new MatchBuilder(); target.setMatchEntries(toMatchEntries(match)); @@ -536,82 +539,77 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { } private List toMatchEntries( - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) { List entries = new ArrayList<>(); return null; } @Override - public Future> updateFlow(UpdateFlowInput input) { - // Convert the UpdateFlowInput to FlowModInput - FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input.getUpdatedFlow(), version); - BarrierInputBuilder barrierInput = new BarrierInputBuilder(); - barrierInput.setVersion(version); - // Call the RPC method on MessageDispatchService - - // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch - - SwitchConnectionDistinguisher cookie = null ; - if (Objects.firstNonNull(input.getUpdatedFlow().isBarrier(), Boolean.FALSE)) { - Future> barrierOFLib = messageService.barrier(barrierInput.build(), cookie); - } + public Future> updateFlow(final UpdateFlowInput input) { + LOG.debug("Calling the updateFlow RPC method on MessageDispatchService"); - LOG.debug("Calling the FlowMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ; - - RpcResult rpcResultFromOFLib = null ; - - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for UpdateFlow RPC" + ex.getMessage()); - } - - UpdateFlowOutput updateFlowOutputOFLib = rpcResultFromOFLib.getResult() ; - - UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder() ; - updateFlowOutput.setTransactionId(updateFlowOutputOFLib.getTransactionId()) ; - UpdateFlowOutput result = updateFlowOutput.build(); - - Collection errors = rpcResultFromOFLib.getErrors() ; - RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); - - LOG.debug("Returning the Update Flow RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + // use primary connection + SwitchConnectionDistinguisher cookie = null; + + OFRpcTask> task = + OFRpcTaskFactory.createUpdateFlowTask(maxTimeout, maxTimeoutUnit, rpcTaskHelper); + rpcTaskHelper.initTask(task, input, cookie); + OFSessionUtil.getSessionManager().getRpcPool().submit(task); + + return task.getResult(); } @Override - public Future> updateGroup( - UpdateGroupInput input) { - // Convert the UpdateGroupInput to GroupModInput - GroupModInput ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version); - - - // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch + public Future> updateGroup(final UpdateGroupInput input) { + LOG.debug("Calling the update Group Mod RPC method on MessageDispatchService"); + Long xId = null; + + // For Flow provisioning, the SwitchConnectionDistinguisher is set to + // null so + // the request can be routed through any connection to the switch + + SwitchConnectionDistinguisher cookie = null; + if (Objects.firstNonNull(input.getUpdatedGroup().isBarrier(), Boolean.FALSE)) { + xId = session.getNextXid(); + BarrierInputBuilder barrierInput = new BarrierInputBuilder(); + barrierInput.setVersion(version); + barrierInput.setXid(xId); + @SuppressWarnings("unused") + Future> barrierOFLib = messageService.barrier(barrierInput.build(), cookie); + } - SwitchConnectionDistinguisher cookie = null ; + // Convert the UpdateGroupInput to GroupModInput + GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version, this + .getSessionContext().getFeatures().getDatapathId()); + xId = session.getNextXid(); + ofGroupModInput.setXid(xId); + + if (null != rpcNotificationProviderService) { + GroupUpdatedBuilder groupMod = new GroupUpdatedBuilder(input.getUpdatedGroup()); + groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue()))); + groupMod.setGroupRef(input.getGroupRef()); + rpcNotificationProviderService.publish(groupMod.build()); + } - LOG.debug("Calling the GroupMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ; + session.getbulkTransactionCache().put(new TransactionKey(xId), input); + Future> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie); - RpcResult rpcResultFromOFLib = null ; + RpcResult rpcResultFromOFLib = null; - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for updateGroup RPC" + ex.getMessage()); - } + try { + rpcResultFromOFLib = resultFromOFLib.get(); + } catch (Exception ex) { + LOG.error(" Error while getting result for updateGroup RPC" + ex.getMessage()); + } - UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult() ; + UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult(); - UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder() ; - updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId()) ; - UpdateGroupOutput result = updateGroupOutput.build(); + UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder(); + updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId()); + UpdateGroupOutput result = updateGroupOutput.build(); - Collection errors = rpcResultFromOFLib.getErrors() ; + Collection errors = rpcResultFromOFLib.getErrors(); RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); LOG.debug("Returning the Update Group RPC result to MD-SAL"); @@ -619,35 +617,53 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { } @Override - public Future> updateMeter( - UpdateMeterInput input) { - // Convert the UpdateMeterInput to MeterModInput - MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input.getUpdatedMeter(), version); - + public Future> updateMeter(final UpdateMeterInput input) { + LOG.debug("Calling the MeterMod RPC method on MessageDispatchService"); + Long xId = null; + + // For Meter provisioning, the SwitchConnectionDistinguisher is set to + // null so + // the request can be routed through any connection to the switch + SwitchConnectionDistinguisher cookie = null; + if (Objects.firstNonNull(input.getUpdatedMeter().isBarrier(), Boolean.FALSE)) { + xId = session.getNextXid(); + BarrierInputBuilder barrierInput = new BarrierInputBuilder(); + barrierInput.setVersion(version); + barrierInput.setXid(xId); + @SuppressWarnings("unused") + Future> barrierOFLib = messageService.barrier(barrierInput.build(), cookie); + } - // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch + // Convert the UpdateMeterInput to MeterModInput + MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input.getUpdatedMeter(), version); + xId = session.getNextXid(); + ofMeterModInput.setXid(xId); - SwitchConnectionDistinguisher cookie = null ; + if (null != rpcNotificationProviderService) { + MeterUpdatedBuilder meterMod = new MeterUpdatedBuilder(input.getUpdatedMeter()); + meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue()))); + meterMod.setMeterRef(input.getMeterRef()); + rpcNotificationProviderService.publish(meterMod.build()); + } - LOG.debug("Calling the MeterMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ; + session.getbulkTransactionCache().put(new TransactionKey(xId), input); + Future> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie); - RpcResult rpcResultFromOFLib = null ; + RpcResult rpcResultFromOFLib = null; - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for UpdateMeter RPC" + ex.getMessage()); - } + try { + rpcResultFromOFLib = resultFromOFLib.get(); + } catch (Exception ex) { + LOG.error(" Error while getting result for UpdateMeter RPC" + ex.getMessage()); + } - UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult() ; + UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult(); - UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder() ; - updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId()) ; - UpdateMeterOutput result = updateMeterOutput.build(); + UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder(); + updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId()); + UpdateMeterOutput result = updateMeterOutput.build(); - Collection errors = rpcResultFromOFLib.getErrors() ; + Collection errors = rpcResultFromOFLib.getErrors(); RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); LOG.debug("Returning the Update Meter RPC result to MD-SAL"); @@ -663,12 +679,22 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { * Methods for requesting statistics from switch */ @Override - public Future> getAllGroupStatistics(GetAllGroupStatisticsInput input) { + public Future> getAllGroupStatistics(final GetAllGroupStatisticsInput input) { - //Generate xid to associate it with the request + GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder(); + Collection errors = Collections.emptyList(); + + if (version == OFConstants.OFP_VERSION_1_0) { + output.setTransactionId(null); + output.setGroupStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Prepare statistics request for all the groups - Transaction id - {}",xid); + LOG.debug("Prepare statistics request for all the groups - Transaction id - {}", xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -682,33 +708,41 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder(); mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue()))); caseBuilder.setMultipartRequestGroup(mprGroupBuild.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send group statistics request to the switch :{}",mprGroupBuild); + // Send the request, no cookies associated, use any connection + LOG.debug("Send group statistics request to the switch :{}", mprGroupBuild); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setGroupStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override - public Future> getGroupDescription(GetGroupDescriptionInput input) { + public Future> getGroupDescription(final GetGroupDescriptionInput input) { + + GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder(); + Collection errors = Collections.emptyList(); - //Generate xid to associate it with the request + if (version == OFConstants.OFP_VERSION_1_0) { + output.setTransactionId(null); + output.setGroupDescStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Prepare group description statistics request - Transaction id - {}",xid); + LOG.debug("Prepare group description statistics request - Transaction id - {}", xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -717,35 +751,43 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setXid(xid); mprInput.setFlags(new MultipartRequestFlags(false)); - // Create multipart request body for fetch all the group description stats + // Create multipart request body for fetch all the group description + // stats MultipartRequestGroupDescCaseBuilder mprGroupDescBuild = new MultipartRequestGroupDescCaseBuilder(); - //Set request body to main multipart request + // Set request body to main multipart request mprInput.setMultipartRequestBody(mprGroupDescBuild.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send group desciption statistics request to switch : {}",mprGroupDescBuild); + // Send the request, no cookies associated, use any connection + LOG.debug("Send group desciption statistics request to switch : {}", mprGroupDescBuild); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setGroupDescStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override - public Future> getGroupFeatures(GetGroupFeaturesInput input) { + public Future> getGroupFeatures(final GetGroupFeaturesInput input) { + + GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder(); + Collection errors = Collections.emptyList(); - //Generate xid to associate it with the request + if (version == OFConstants.OFP_VERSION_1_0) { + output.setTransactionId(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Prepare group features statistics request - Transaction id - {}",xid); + LOG.debug("Prepare group features statistics request - Transaction id - {}", xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -754,33 +796,43 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setXid(xid); mprInput.setFlags(new MultipartRequestFlags(false)); - // Create multipart request body for fetch all the group description stats + // Create multipart request body for fetch all the group description + // stats MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder(); - //Set request body to main multipart request + // Set request body to main multipart request mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send group features statistics request :{}",mprGroupFeaturesBuild); + // Send the request, no cookies associated, use any connection + LOG.debug("Send group features statistics request :{}", mprGroupFeaturesBuild); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override - public Future> getGroupStatistics(GetGroupStatisticsInput input) { + public Future> getGroupStatistics(final GetGroupStatisticsInput input) { - //Generate xid to associate it with the request + GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder(); + Collection errors = Collections.emptyList(); + + if (version == OFConstants.OFP_VERSION_1_0) { + output.setTransactionId(null); + output.setGroupStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Prepare statistics request for node {} group ({}) - Transaction id - {}",input.getNode(),input.getGroupId(),xid); + LOG.debug("Prepare statistics request for node {} group ({}) - Transaction id - {}", input.getNode(), + input.getGroupId(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -794,33 +846,42 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder(); mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue())); caseBuilder.setMultipartRequestGroup(mprGroupBuild.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send group statistics request :{}",mprGroupBuild); + // Send the request, no cookies associated, use any connection + LOG.debug("Send group statistics request :{}", mprGroupBuild); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setGroupStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override public Future> getAllMeterConfigStatistics( - GetAllMeterConfigStatisticsInput input) { + final GetAllMeterConfigStatisticsInput input) { + + GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder(); + Collection errors = Collections.emptyList(); - //Generate xid to associate it with the request + if (version == OFConstants.OFP_VERSION_1_0) { + output.setTransactionId(null); + output.setMeterConfigStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + + } + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Prepare config request for all the meters - Transaction id - {}",xid); + LOG.debug("Prepare config request for all the meters - Transaction id - {}", xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -834,32 +895,40 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder(); mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue()))); caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send meter statistics request :{}",mprMeterConfigBuild); + // Send the request, no cookies associated, use any connection + LOG.debug("Send meter statistics request :{}", mprMeterConfigBuild); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setMeterConfigStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override - public Future> getAllMeterStatistics(GetAllMeterStatisticsInput input) { + public Future> getAllMeterStatistics(final GetAllMeterStatisticsInput input) { + + GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder(); + Collection errors = Collections.emptyList(); + + if (version == OFConstants.OFP_VERSION_1_0) { + output.setTransactionId(null); + output.setMeterStats(null); - //Generate xid to associate it with the request + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Prepare statistics request for all the meters - Transaction id - {}",xid); + LOG.debug("Prepare statistics request for all the meters - Transaction id - {}", xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -873,32 +942,39 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder(); mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue()))); caseBuilder.setMultipartRequestMeter(mprMeterBuild.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send meter statistics request :{}",mprMeterBuild); + // Send the request, no cookies associated, use any connection + LOG.debug("Send meter statistics request :{}", mprMeterBuild); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setMeterStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override - public Future> getMeterFeatures(GetMeterFeaturesInput input) { + public Future> getMeterFeatures(final GetMeterFeaturesInput input) { + + GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder(); + Collection errors = Collections.emptyList(); - //Generate xid to associate it with the request + if (version == OFConstants.OFP_VERSION_1_0) { + output.setTransactionId(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}",xid); + LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}", xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -907,32 +983,43 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setXid(xid); mprInput.setFlags(new MultipartRequestFlags(false)); - // Create multipart request body for fetch all the group description stats + // Create multipart request body for fetch all the group description + // stats MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder(); - //Set request body to main multipart request + // Set request body to main multipart request mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send meter features statistics request :{}",mprMeterFeaturesBuild); + // Send the request, no cookies associated, use any connection + LOG.debug("Send meter features statistics request :{}", mprMeterFeaturesBuild); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override - public Future> getMeterStatistics(GetMeterStatisticsInput input) { - //Generate xid to associate it with the request + public Future> getMeterStatistics(final GetMeterStatisticsInput input) { + + GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder(); + Collection errors = Collections.emptyList(); + + if (version == OFConstants.OFP_VERSION_1_0) { + output.setTransactionId(null); + output.setMeterStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + + } + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}",input.getMeterId().getValue(),xid); + LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}", input.getMeterId().getValue(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -944,35 +1031,35 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { // Create multipart request body for fetch all the meter stats MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder(); MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder(); - //Select specific meter + // Select specific meter mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue())); caseBuilder.setMultipartRequestMeter(mprMeterBuild.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send meter statistics request :{}",mprMeterBuild); + // Send the request, no cookies associated, use any connection + LOG.debug("Send meter statistics request :{}", mprMeterBuild); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setMeterStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } - + @Override - public Future> getAllPortsStatistics(GetAllPortsStatisticsInput arg0) { + public Future> getAllNodeConnectorsStatistics( + final GetAllNodeConnectorsStatisticsInput arg0) { - //Generate xid to associate it with the request + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.info("Prepare port statistics request for all ports of node {} - TrasactionId - {}",arg0.getNode().getValue(),xid); + LOG.debug("Prepare port statistics request for all ports of node {} - TrasactionId - {}", arg0.getNode() + .getValue(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -981,35 +1068,38 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setXid(xid); mprInput.setFlags(new MultipartRequestFlags(false)); - // Create multipart request body to fetch stats for all the port of the node + // Create multipart request body to fetch stats for all the port of the + // node MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder(); MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder(); - //Select all ports + // Select all ports mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY); caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send port statistics request :{}",mprPortStatsBuilder.build().toString()); + // Send the request, no cookies associated, use any connection + LOG.debug("Send port statistics request :{}", mprPortStatsBuilder.build().toString()); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. - GetAllPortsStatisticsOutputBuilder output = new GetAllPortsStatisticsOutputBuilder(); + GetAllNodeConnectorsStatisticsOutputBuilder output = new GetAllNodeConnectorsStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override - public Future> getPortStatistics(GetPortStatisticsInput arg0) { - //Generate xid to associate it with the request + public Future> getNodeConnectorStatistics( + final GetNodeConnectorStatisticsInput arg0) { + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.info("Prepare port statistics request for port {} of node {} - TrasactionId - {}",arg0.getNodeConnectorId(), arg0.getNode().getValue(),xid); + LOG.debug("Prepare port statistics request for port {} of node {} - TrasactionId - {}", + arg0.getNodeConnectorId(), arg0.getNode().getValue(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -1018,145 +1108,132 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setXid(xid); mprInput.setFlags(new MultipartRequestFlags(false)); - // Create multipart request body to fetch stats for all the port of the node + // Create multipart request body to fetch stats for all the port of the + // node MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder(); MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder(); - //Set specific port - mprPortStatsBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId())); + // Set specific port + mprPortStatsBuilder + .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId())); caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send port statistics request :{}",mprPortStatsBuilder.build().toString()); + // Send the request, no cookies associated, use any connection + LOG.debug("Send port statistics request :{}", mprPortStatsBuilder.build().toString()); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. - GetPortStatisticsOutputBuilder output = new GetPortStatisticsOutputBuilder(); + GetNodeConnectorStatisticsOutputBuilder output = new GetNodeConnectorStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } - private TransactionId generateTransactionId(Long xid){ - String stringXid =xid.toString(); - BigInteger bigIntXid = new BigInteger( stringXid ); + private TransactionId generateTransactionId(final Long xid) { + String stringXid = xid.toString(); + BigInteger bigIntXid = new BigInteger(stringXid); return new TransactionId(bigIntXid); } @Override - public Future> getPort() { - // TODO Auto-generated method stub - return null; - } - + public Future> updatePort(final UpdatePortInput input) { + PortModInput ofPortModInput = null; + RpcResult rpcResultFromOFLib = null; - @Override - public Future> updatePort(UpdatePortInput input) { - PortModInput ofPortModInput = null ; - RpcResult rpcResultFromOFLib = null ; - - - // For Flow provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch - - SwitchConnectionDistinguisher cookie = null ; - - // NSF sends a list of port and the ModelDrivenSwitch will - // send one port at a time towards the switch ( mutiple RPCs calls) - List inputPorts = input.getUpdatedPort().getPort().getPort() ; - - // Get the Xid. The same Xid has to be sent in all the RPCs - Long Xid = sessionContext.getNextXid(); - - for( Port inputPort : inputPorts) { - - // Convert the UpdateGroupInput to GroupModInput - ofPortModInput = PortConvertor.toPortModInput(inputPort, version) ; - - // Insert the Xid ( transaction Id) before calling the RPC on the OFLibrary - - PortModInputBuilder mdInput = new PortModInputBuilder(); - mdInput.setXid(Xid); - mdInput.setVersion(ofPortModInput.getVersion()) ; - mdInput.setPortNo(ofPortModInput.getPortNo()) ; - mdInput.setMaskV10(ofPortModInput.getMaskV10()) ; - mdInput.setMask(ofPortModInput.getMask()) ; - mdInput.setHwAddress(ofPortModInput.getHwAddress()); - mdInput.setConfigV10(ofPortModInput.getConfigV10()) ; - mdInput.setConfig(ofPortModInput.getConfig()) ; - mdInput.setAdvertiseV10(ofPortModInput.getAdvertiseV10()) ; - mdInput.setAdvertise(ofPortModInput.getAdvertise()) ; - - LOG.debug("Calling the PortMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.portMod(ofPortModInput, cookie) ; - - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for updatePort RPC" + ex.getMessage()); - } - - // The Future response value for all the RPCs except the last one is ignored - - } - //Extract the Xid only from the Future for the last RPC and - // send it back to the NSF - UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult() ; - - UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder() ; - updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId()) ; - UpdatePortOutput result = updatePortOutput.build(); - - Collection errors = rpcResultFromOFLib.getErrors() ; - RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); - - LOG.debug("Returning the Update Group RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + // For Flow provisioning, the SwitchConnectionDistinguisher is set to + // null so + // the request can be routed through any connection to the switch + + SwitchConnectionDistinguisher cookie = null; + + // NSF sends a list of port and the ModelDrivenSwitch will + // send one port at a time towards the switch ( mutiple RPCs calls) + List inputPorts = input.getUpdatedPort().getPort().getPort(); + + // Get the Xid. The same Xid has to be sent in all the RPCs + Long Xid = sessionContext.getNextXid(); + + for (Port inputPort : inputPorts) { + + // Convert the UpdateGroupInput to GroupModInput + ofPortModInput = PortConvertor.toPortModInput(inputPort, version); + + // Insert the Xid ( transaction Id) before calling the RPC on the + // OFLibrary + + PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput); + mdInput.setXid(Xid); + + LOG.debug("Calling the PortMod RPC method on MessageDispatchService"); + Future> resultFromOFLib = messageService.portMod(mdInput.build(), cookie); + + try { + rpcResultFromOFLib = resultFromOFLib.get(); + } catch (Exception ex) { + LOG.error(" Error while getting result for updatePort RPC" + ex.getMessage()); + } + + // The Future response value for all the RPCs except the last one is + // ignored + + } + // Extract the Xid only from the Future for the last RPC and + // send it back to the NSF + UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult(); + + UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder(); + updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId()); + UpdatePortOutput result = updatePortOutput.build(); + + Collection errors = rpcResultFromOFLib.getErrors(); + RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); + + LOG.debug("Returning the Update Group RPC result to MD-SAL"); + return Futures.immediateFuture(rpcResult); } - + @Override - public Future> updateTable( - UpdateTableInput input) { + public Future> updateTable(final UpdateTableInput input) { - // Get the Xid. The same Xid has to be sent in all the Multipart requests + // Get the Xid. The same Xid has to be sent in all the Multipart + // requests Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Prepare the Multipart Table Mod requests for Transaction Id {} ",xid); + LOG.debug("Prepare the Multipart Table Mod requests for Transaction Id {} ", xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); mprInput.setType(MultipartType.OFPMPTABLEFEATURES); - mprInput.setVersion((short)0x04); + mprInput.setVersion((short) 0x04); mprInput.setXid(xid); - //Convert the list of all MD-SAL table feature object into OF library object - List ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input.getUpdatedTable()) ; - + // Convert the list of all MD-SAL table feature object into OF library + // object + List ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input.getUpdatedTable()); MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder(); MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder(); - mprInput.setFlags(new MultipartRequestFlags(true)); - - tableFeaturesRequest.setTableFeatures(ofTableFeatureList) ; - - //Set request body to main multipart request + mprInput.setFlags(new MultipartRequestFlags(false)); + + tableFeaturesRequest.setTableFeatures(ofTableFeatureList); + + // Set request body to main multipart request caseRequest.setMultipartRequestTableFeatures(tableFeaturesRequest.build()); mprInput.setMultipartRequestBody(caseRequest.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send Table Feature request :{}",ofTableFeatureList); + // Send the request, no cookies associated, use any connection + LOG.debug("Send Table Feature request :{}", ofTableFeatureList); this.messageService.multipartRequest(mprInput.build(), null); - - - //Extract the Xid only from the Future for the last RPC and + + // Extract the Xid only from the Future for the last RPC and // send it back to the NSF LOG.debug("Returning the result and transaction id to NSF"); LOG.debug("Return results and transaction id back to caller"); @@ -1170,13 +1247,13 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getAllFlowStatisticsFromFlowTable( - GetAllFlowStatisticsFromFlowTableInput arg0) { + final GetAllFlowStatisticsFromFlowTableInput arg0) { - //Generate xid to associate it with the request + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}" - ,arg0.getTableId().getValue(),xid); + LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}", arg0 + .getTableId().getValue(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -1186,37 +1263,26 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setFlags(new MultipartRequestFlags(false)); // Create multipart request body for fetch all the group stats - MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder (); + MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue()); mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - - if(version == OFConstants.OFP_VERSION_1_0){ - LOG.info("Target node is running openflow version 1.0"); - FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true); - mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build()); - } - if(version == OFConstants.OFP_VERSION_1_3){ - LOG.info("Target node is running openflow version 1.3+"); - mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build()); - } - + FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder); - //Set request body to main multipart request + // Set request body to main multipart request multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder); + // Send the request, no cookies associated, use any connection + LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetAllFlowStatisticsFromFlowTableOutputBuilder output = - new GetAllFlowStatisticsFromFlowTableOutputBuilder(); + GetAllFlowStatisticsFromFlowTableOutputBuilder output = new GetAllFlowStatisticsFromFlowTableOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setFlowAndStatisticsMapList(null); @@ -1227,12 +1293,12 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getAllFlowsStatisticsFromAllFlowTables( - GetAllFlowsStatisticsFromAllFlowTablesInput arg0) { - - //Generate xid to associate it with the request + final GetAllFlowsStatisticsFromAllFlowTablesInput arg0) { + + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.info("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}",xid); + LOG.debug("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}", xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -1242,7 +1308,7 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setFlags(new MultipartRequestFlags(false)); // Create multipart request body for fetch all the group stats - MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); + MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL); mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); @@ -1250,43 +1316,37 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - - //TODO: repeating code - if(version == OFConstants.OFP_VERSION_1_0){ - FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true); - mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build()); - } - if(version == OFConstants.OFP_VERSION_1_3){ - mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build()); - } - //Set request body to main multipart request + + FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder); + + // Set request body to main multipart request multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder); + // Send the request, no cookies associated, use any connection + LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. - GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output = - new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder(); + GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output = new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setFlowAndStatisticsMapList(null); Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), + errors); return Futures.immediateFuture(rpcResult); } @Override public Future> getFlowStatisticsFromFlowTable( - GetFlowStatisticsFromFlowTableInput arg0) { - //Generate xid to associate it with the request + final GetFlowStatisticsFromFlowTableInput arg0) { + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.info("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}" - ,arg0.getMatch().toString(),arg0.getTableId(),xid); + LOG.debug("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}", + arg0.getMatch().toString(), arg0.getTableId(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -1296,34 +1356,44 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setFlags(new MultipartRequestFlags(false)); // Create multipart request body for fetch all the group stats - MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); + MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); mprFlowRequestBuilder.setTableId(arg0.getTableId()); - mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue()); - mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); - mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); - mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - // convert and inject match - MatchReactor.getInstance().convert(arg0.getMatch(), version, mprFlowRequestBuilder); - //TODO: repeating code - if(version == OFConstants.OFP_VERSION_1_3){ - mprFlowRequestBuilder.setCookie(arg0.getCookie()); - mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask()); + if (arg0.getOutPort() != null) + mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue()); + else + mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); + + if (arg0.getOutGroup() != null) mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup()); - } + else + mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); + + if (arg0.getCookie() != null) + mprFlowRequestBuilder.setCookie(arg0.getCookie().getValue()); + else + mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); + + if (arg0.getCookieMask() != null) + mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask().getValue()); + else + mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); + + // convert and inject match + MatchReactor.getInstance().convert(arg0.getMatch(), version, mprFlowRequestBuilder, + this.getSessionContext().getFeatures().getDatapathId()); - //Set request body to main multipart request + // Set request body to main multipart request multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send flow statistics request to the switch :{}",mprFlowRequestBuilder); + // Send the request, no cookies associated, use any connection + LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. - GetFlowStatisticsFromFlowTableOutputBuilder output = - new GetFlowStatisticsFromFlowTableOutputBuilder(); + GetFlowStatisticsFromFlowTableOutputBuilder output = new GetFlowStatisticsFromFlowTableOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setFlowAndStatisticsMapList(null); @@ -1334,12 +1404,13 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getAggregateFlowStatisticsFromFlowTableForAllFlows( - GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) { - //Generate xid to associate it with the request + final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) { + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.info("Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}" - ,arg0.getTableId().getValue(),xid); + LOG.debug( + "Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}", + arg0.getTableId().getValue(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -1349,51 +1420,44 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setFlags(new MultipartRequestFlags(false)); // Create multipart request body for fetch all the group stats - MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder (); + MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder(); MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder(); mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue()); mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY); mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - - //TODO: repeating code - if(version == OFConstants.OFP_VERSION_1_0){ - FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,true,true,true,true,true,true,true,true,true); - mprAggregateRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build()); - } - if(version == OFConstants.OFP_VERSION_1_3){ - mprAggregateRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build()); - } + FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder); - //Set request body to main multipart request + // Set request body to main multipart request multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build()); mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString()); + // Send the request, no cookies associated, use any connection + LOG.debug("Send request to the switch :{}", multipartRequestAggregateCaseBuilder.build().toString()); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. - GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output = - new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder(); + GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output = new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + RpcResult rpcResult = Rpcs.getRpcResult(true, + output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override public Future> getAggregateFlowStatisticsFromFlowTableForGivenMatch( - GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) { + final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) { - //Generate xid to associate it with the request + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.debug("Prepare agregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}" - ,arg0.getMatch().toString(),arg0.getTableId(),xid); + LOG.debug( + "Prepare aggregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}", + arg0.getMatch().toString(), arg0.getTableId(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -1403,7 +1467,7 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setFlags(new MultipartRequestFlags(false)); // Create multipart request body for fetch all the group stats - MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder (); + MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder(); MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder(); mprAggregateRequestBuilder.setTableId(arg0.getTableId()); mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue()); @@ -1411,40 +1475,40 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - - MatchReactor.getInstance().convert(arg0.getMatch(), version, mprAggregateRequestBuilder); - //TODO: repeating code - if(version == OFConstants.OFP_VERSION_1_3){ - mprAggregateRequestBuilder.setCookie(arg0.getCookie()); - mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask()); + MatchReactor.getInstance().convert(arg0.getMatch(), version, mprAggregateRequestBuilder, + this.getSessionContext().getFeatures().getDatapathId()); + // TODO: repeating code + if (version == OFConstants.OFP_VERSION_1_3) { + mprAggregateRequestBuilder.setCookie(arg0.getCookie().getValue()); + mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask().getValue()); mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup()); } - //Set request body to main multipart request + // Set request body to main multipart request multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build()); mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send request to the switch :{}",multipartRequestAggregateCaseBuilder.build().toString()); + // Send the request, no cookies associated, use any connection + LOG.debug("Send request to the switch :{}", multipartRequestAggregateCaseBuilder.build().toString()); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. - GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output = - new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder(); + GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output = new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + RpcResult rpcResult = Rpcs.getRpcResult(true, + output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override - public Future> getFlowTablesStatistics(GetFlowTablesStatisticsInput arg0) { - //Generate xid to associate it with the request + public Future> getFlowTablesStatistics(final GetFlowTablesStatisticsInput arg0) { + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.info("Prepare flow table statistics request to get flow table stats for all tables " + - "from node {}- Transaction id - {}",arg0.getNode(),xid); + LOG.debug("Prepare flow table statistics request to get flow table stats for all tables " + + "from node {}- Transaction id - {}", arg0.getNode(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -1454,16 +1518,16 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setFlags(new MultipartRequestFlags(false)); // Create multipart request body for fetch all the group stats - MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder (); + MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder(); MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder(); multipartRequestTableBuilder.setEmpty(true); multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send request to the switch :{}",multipartRequestTableCaseBuilder.build().toString()); + // Send the request, no cookies associated, use any connection + LOG.debug("Send request to the switch :{}", multipartRequestTableCaseBuilder.build().toString()); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. @@ -1477,11 +1541,13 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getAllQueuesStatisticsFromAllPorts( - GetAllQueuesStatisticsFromAllPortsInput arg0) { - //Generate xid to associate it with the request + final GetAllQueuesStatisticsFromAllPortsInput arg0) { + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.info("Prepare queue statistics request to collect stats for all queues attached to all the ports of node {} - TrasactionId - {}",arg0.getNode().getValue(),xid); + LOG.debug( + "Prepare queue statistics request to collect stats for all queues attached to all the ports of node {} - TrasactionId - {}", + arg0.getNode().getValue(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -1490,21 +1556,22 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setXid(xid); mprInput.setFlags(new MultipartRequestFlags(false)); - // Create multipart request body to fetch stats for all the port of the node + // Create multipart request body to fetch stats for all the port of the + // node MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder(); MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder(); - //Select all ports + // Select all ports mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY); - //Select all the ports + // Select all the ports mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY); - + caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString()); + // Send the request, no cookies associated, use any connection + LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString()); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. @@ -1519,12 +1586,13 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getAllQueuesStatisticsFromGivenPort( - GetAllQueuesStatisticsFromGivenPortInput arg0) { - //Generate xid to associate it with the request + final GetAllQueuesStatisticsFromGivenPortInput arg0) { + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.info("Prepare queue statistics request to collect stats for " + - "all queues attached to given port {} of node {} - TrasactionId - {}",arg0.getNodeConnectorId().toString(),arg0.getNode().getValue(),xid); + LOG.debug("Prepare queue statistics request to collect stats for " + + "all queues attached to given port {} of node {} - TrasactionId - {}", arg0.getNodeConnectorId() + .toString(), arg0.getNode().getValue(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -1533,21 +1601,22 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setXid(xid); mprInput.setFlags(new MultipartRequestFlags(false)); - // Create multipart request body to fetch stats for all the port of the node + // Create multipart request body to fetch stats for all the port of the + // node MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder(); MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder(); - //Select all queues + // Select all queues mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY); - //Select specific port + // Select specific port mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId())); - + caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString()); + // Send the request, no cookies associated, use any connection + LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString()); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. @@ -1556,18 +1625,20 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { output.setQueueIdAndStatisticsMap(null); Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + RpcResult rpcResult = Rpcs + .getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override public Future> getQueueStatisticsFromGivenPort( - GetQueueStatisticsFromGivenPortInput arg0) { - //Generate xid to associate it with the request + final GetQueueStatisticsFromGivenPortInput arg0) { + // Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); - LOG.info("Prepare queue statistics request to collect stats for " + - "given queue attached to given port {} of node {} - TrasactionId - {}",arg0.getQueueId().toString(),arg0.getNodeConnectorId().toString(),arg0.getNode().getValue(),xid); + LOG.debug("Prepare queue statistics request to collect stats for " + + "given queue attached to given port {} of node {} - TrasactionId - {}", arg0.getQueueId().toString(), + arg0.getNodeConnectorId().toString(), arg0.getNode().getValue(), xid); // Create multipart request header MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); @@ -1576,21 +1647,22 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { mprInput.setXid(xid); mprInput.setFlags(new MultipartRequestFlags(false)); - // Create multipart request body to fetch stats for all the port of the node + // Create multipart request body to fetch stats for all the port of the + // node MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder(); MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder(); - //Select specific queue + // Select specific queue mprQueueBuilder.setQueueId(arg0.getQueueId().getValue()); - //Select specific port + // Select specific port mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId())); - + caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build()); - - //Set request body to main multipart request + + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - //Send the request, no cookies associated, use any connection - LOG.debug("Send queue statistics request :{}",mprQueueBuilder.build().toString()); + // Send the request, no cookies associated, use any connection + LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString()); this.messageService.multipartRequest(mprInput.build(), null); // Prepare rpc return output. Set xid and send it back. @@ -1602,39 +1674,21 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } - - @Override - public Future> getAllFlowStatistics(GetAllFlowStatisticsInput arg0) { - //TODO: Depricated, need to clean it up. Sal-Compatibility layes is dependent on it. - // Once sal-compatibility layer is fixed this rpc call can be removed from yang file - return null; - } - - @Override - public Future> getAllNodeConnectorStatistics( - GetAllNodeConnectorStatisticsInput arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Future> getFlowStatistics(GetFlowStatisticsInput arg0) { - //TODO: Depricated, need to clean it up. Sal-Compatibility layes is dependent on it. - // Once sal-compatibility layer is fixed this rpc call can be removed from yang file - return null; - } - - @Override - public Future> getFlowTableStatistics(GetFlowTableStatisticsInput arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Future> getNodeConnectorStatistics( - GetNodeConnectorStatisticsInput arg0) { - // TODO Auto-generated method stub - return null; + + /** + * @param input + * @param cookie + * @param session + * @param messageService + * @return barrier result + */ + public static Future> sendBarrier( + SwitchConnectionDistinguisher cookie, SessionContext session, + IMessageDispatchService messageService) { + BarrierInputBuilder barrierInput = new BarrierInputBuilder(); + barrierInput.setVersion(session.getFeatures().getVersion()); + barrierInput.setXid(session.getNextXid()); + return messageService.barrier(barrierInput.build(), cookie); } }