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=46eca4f7d94a9b062682108337afb114da9b3002;hb=832efcf1dbb26d66a2c01146c6dcc388ba0abb65;hp=2d8e3cae20db2ef8c16e55ac44708a2b7ded7ef5;hpb=814231b32b75c57ee7eb499938cf41dc8b27f41d;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 2d8e3cae20..46eca4f7d9 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 @@ -7,525 +7,257 @@ */ package org.opendaylight.openflowplugin.openflow.md.core.sal; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; import java.util.concurrent.Future; - -import org.opendaylight.controller.sal.common.util.Rpcs; -import org.opendaylight.openflowjava.protocol.api.util.BinContent; -import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher; -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.MatchConvertor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.OpenflowEnumConstant; -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.session.IMessageDispatchService; -import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; +import java.util.concurrent.TimeUnit; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor; +import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService; +import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; +import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext; +import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl; 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.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; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder; 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.group.service.rev130918.AddGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow; +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.group.service.rev130918.AddGroupInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput; 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; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder; 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.NodeId; 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.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; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder; 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.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.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.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.MultipartRequestInputBuilder; -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; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder; -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.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features.TableFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.ConnectionCookie; 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.GetAllNodeConnectorsStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput; +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.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.GetAllQueuesStatisticsFromGivenPortInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput; 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.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; -import com.google.common.util.concurrent.Futures; - /** * 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; + private OFRpcTaskContext rpcTaskContext; - protected ModelDrivenSwitchImpl(NodeId nodeId, - InstanceIdentifier identifier, SessionContext context) { - super(identifier, context); - this.nodeId = nodeId; - messageService = sessionContext.getMessageDispatchService() ; - version = context.getPrimaryConductor().getVersion(); - } - - @Override - public Future> addFlow(AddFlowInput input) { - // Convert the AddFlowInput to FlowModInput - FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, 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 ; - - 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()); - } + // TODO:read timeout from configSubsystem + protected long maxTimeout = 1000; + protected TimeUnit maxTimeoutUnit = TimeUnit.MILLISECONDS; - 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); + protected ModelDrivenSwitchImpl(final NodeId nodeId, final InstanceIdentifier identifier, + final SessionContext sessionContext) { + super(identifier, sessionContext); + this.nodeId = nodeId; + messageService = sessionContext.getMessageDispatchService(); + version = sessionContext.getPrimaryConductor().getVersion(); + final NotificationProviderService rpcNotificationProviderService = OFSessionUtil.getSessionManager().getNotificationProviderService(); - LOG.debug("Returning the Add Flow RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + rpcTaskContext = new OFRpcTaskContext(); + rpcTaskContext.setSession(sessionContext); + rpcTaskContext.setMessageService(messageService); + rpcTaskContext.setRpcNotificationProviderService(rpcNotificationProviderService); + rpcTaskContext.setMaxTimeout(maxTimeout); + rpcTaskContext.setMaxTimeoutUnit(maxTimeoutUnit); + rpcTaskContext.setRpcPool(OFSessionUtil.getSessionManager().getRpcPool()); + rpcTaskContext.setMessageSpy(OFSessionUtil.getSessionManager().getMessageSpy()); } @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 + public Future> addFlow(final AddFlowInput input) { + LOG.debug("Calling the FlowMod RPC method on MessageDispatchService"); + // use primary connection + SwitchConnectionDistinguisher cookie = null; - SwitchConnectionDistinguisher cookie = null ; + OFRpcTask> task = + OFRpcTaskFactory.createAddFlowTask(rpcTaskContext, input, cookie); + ListenableFuture> result = task.submit(); - LOG.debug("Calling the GroupMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ; - - RpcResult rpcResultFromOFLib = null ; - - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for AddGroup RPC" + ex.getMessage()); - } - - UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ; - - AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder() ; - addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ; - AddGroupOutput result = addGroupOutput.build(); - - Collection errors = rpcResultFromOFLib.getErrors() ; - RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); - - LOG.debug("Returning the Add Group RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + return Futures.transform(result, OFRpcFutureResultTransformFactory.createForAddFlowOutput()); } - @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 - - SwitchConnectionDistinguisher cookie = null ; - LOG.debug("Calling the MeterMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ; - - RpcResult rpcResultFromOFLib = null ; - - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for AddMeter RPC" + ex.getMessage()); - } - - UpdateMeterOutput updateMeterOutput = rpcResultFromOFLib.getResult() ; + @Override + public Future> addGroup(final AddGroupInput input) { + LOG.debug("Calling the GroupMod RPC method on MessageDispatchService"); - AddMeterOutputBuilder addMeterOutput = new AddMeterOutputBuilder() ; - addMeterOutput.setTransactionId(updateMeterOutput.getTransactionId()) ; - AddMeterOutput result = addMeterOutput.build(); + // use primary connection + SwitchConnectionDistinguisher cookie = null; - Collection errors = rpcResultFromOFLib.getErrors() ; - RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); + OFRpcTask> task = + OFRpcTaskFactory.createAddGroupTask(rpcTaskContext, input, cookie); + ListenableFuture> result = task.submit(); - LOG.debug("Returning the Add Meter RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + return Futures.transform(result, OFRpcFutureResultTransformFactory.createForAddGroupOutput()); } @Override - public Future> removeFlow(RemoveFlowInput input) { - // Convert the RemoveFlowInput to FlowModInput - FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input, 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 ; - - LOG.debug("Calling the FlowMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ; - - RpcResult rpcResultFromOFLib = null ; + public Future> addMeter(final AddMeterInput input) { + LOG.debug("Calling the MeterMod RPC method on MessageDispatchService"); - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for remove Flow RPC" + ex.getMessage()); - } + // use primary connection + SwitchConnectionDistinguisher cookie = null; - UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult() ; + OFRpcTask> task = + OFRpcTaskFactory.createAddMeterTask(rpcTaskContext, input, cookie); + ListenableFuture> result = task.submit(); - RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder() ; - removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId()) ; - RemoveFlowOutput result = removeFlowOutput.build(); - - Collection errors = rpcResultFromOFLib.getErrors() ; - RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); - - LOG.debug("Returning the Remove Flow RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + return Futures.transform(result, OFRpcFutureResultTransformFactory.createForAddMeterOutput()); } @Override - public Future> removeGroup( - RemoveGroupInput input) { - // Convert the RemoveGroupInput 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 - - SwitchConnectionDistinguisher cookie = null ; - - LOG.debug("Calling the GroupMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ; - - RpcResult rpcResultFromOFLib = null ; - - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for RemoveGroup RPC" + ex.getMessage()); - } - - UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult() ; - - RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder() ; - removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId()) ; - RemoveGroupOutput result = removeGroupOutput.build(); + public Future> removeFlow(final RemoveFlowInput input) { + LOG.debug("Calling the removeFlow RPC method on MessageDispatchService"); - Collection errors = rpcResultFromOFLib.getErrors() ; - RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); + // use primary connection + SwitchConnectionDistinguisher cookie = null; + OFRpcTask> task = + OFRpcTaskFactory.createRemoveFlowTask(rpcTaskContext, input, cookie); + ListenableFuture> result = task.submit(); - LOG.debug("Returning the Remove Group RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + return Futures.transform(result, OFRpcFutureResultTransformFactory.createForRemoveFlowOutput()); } @Override - public Future> removeMeter( - RemoveMeterInput input) { - // Convert the RemoveMeterInput to MeterModInput - MeterModInput ofMeterModInput = MeterConvertor.toMeterModInput(input, version); + public Future> removeGroup(final RemoveGroupInput input) { + LOG.debug("Calling the Remove Group RPC method on MessageDispatchService"); + SwitchConnectionDistinguisher cookie = null; + OFRpcTask> task = + OFRpcTaskFactory.createRemoveGroupTask(rpcTaskContext, input, cookie); + ListenableFuture> result = task.submit(); - // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch - - SwitchConnectionDistinguisher cookie = null ; - - LOG.debug("Calling the MeterMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ; - - RpcResult rpcResultFromOFLib = null ; - - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for RemoveMeter RPC" + ex.getMessage()); - } - - UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult() ; - - RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder() ; - removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId()) ; - RemoveMeterOutput result = removeMeterOutput.build(); - - Collection errors = rpcResultFromOFLib.getErrors() ; - RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); - - LOG.debug("Returning the Remove Meter RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + return Futures.transform(result, OFRpcFutureResultTransformFactory.createForRemoveGroupOutput()); } @Override - public Future> transmitPacket(TransmitPacketInput input) { - // TODO Auto-generated method stub - return null; - } + public Future> removeMeter(final RemoveMeterInput input) { + LOG.debug("Calling the Remove MeterMod RPC method on MessageDispatchService"); - private FlowModInputBuilder toFlowModInputBuilder(Flow source) { - FlowModInputBuilder target = new FlowModInputBuilder(); - target.setCookie(source.getCookie()); - target.setIdleTimeout(source.getIdleTimeout()); - target.setHardTimeout(source.getHardTimeout()); - target.setMatch(toMatch(source.getMatch())); + SwitchConnectionDistinguisher cookie = null; + OFRpcTask> task = + OFRpcTaskFactory.createRemoveMeterTask(rpcTaskContext, input, cookie); + ListenableFuture> result = task.submit(); - return target; + return Futures.transform(result, OFRpcFutureResultTransformFactory.createForRemoveMeterOutput()); } - private Match toMatch( - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) { - MatchBuilder target = new MatchBuilder(); - - target.setMatchEntries(toMatchEntries(match)); - - return null; - } + @Override + 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()); - private List toMatchEntries( - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) { - List entries = new ArrayList<>(); + SwitchConnectionDistinguisher cookie = null; + ConnectionCookie connectionCookie = input.getConnectionCookie(); + if (connectionCookie != null && connectionCookie.getValue() != null) { + cookie = new SwitchConnectionCookieOFImpl(connectionCookie.getValue()); + } - return null; + LOG.debug("Calling the transmitPacket RPC method"); + return messageService.packetOut(message, cookie); } @Override - public Future> updateFlow(UpdateFlowInput input) { - // Convert the UpdateFlowInput to FlowModInput - FlowModInput ofFlowModInput = FlowConvertor.toFlowModInput(input.getUpdatedFlow(), 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 ; - - LOG.debug("Calling the FlowMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.flowMod(ofFlowModInput, cookie) ; - - RpcResult rpcResultFromOFLib = null ; + public Future> updateFlow(final UpdateFlowInput input) { + LOG.debug("Calling the updateFlow RPC method on MessageDispatchService"); - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for UpdateFlow RPC" + ex.getMessage()); - } + // use primary connection + SwitchConnectionDistinguisher cookie = null; - UpdateFlowOutput updateFlowOutputOFLib = rpcResultFromOFLib.getResult() ; + OFRpcTask> task = + OFRpcTaskFactory.createUpdateFlowTask(rpcTaskContext, input, cookie); + ListenableFuture> result = task.submit(); - 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); + return result; } @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 - - SwitchConnectionDistinguisher cookie = null ; - - LOG.debug("Calling the GroupMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.groupMod(ofGroupModInput, cookie) ; - - RpcResult rpcResultFromOFLib = null ; - - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for updateGroup RPC" + ex.getMessage()); - } - - UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult() ; + public Future> updateGroup(final UpdateGroupInput input) { + LOG.debug("Calling the update Group Mod RPC method on MessageDispatchService"); - UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder() ; - updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId()) ; - UpdateGroupOutput result = updateGroupOutput.build(); + // use primary connection + SwitchConnectionDistinguisher cookie = null; - Collection errors = rpcResultFromOFLib.getErrors() ; - RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); + OFRpcTask> task = + OFRpcTaskFactory.createUpdateGroupTask(rpcTaskContext, input, cookie); + ListenableFuture> result = task.submit(); - LOG.debug("Returning the Update Group RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + return result; } @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"); + // use primary connection + SwitchConnectionDistinguisher cookie = null; - // For Meter provisioning, the SwitchConnectionDistinguisher is set to null so - // the request can be routed through any connection to the switch + OFRpcTask> task = + OFRpcTaskFactory.createUpdateMeterTask(rpcTaskContext, input, cookie); + ListenableFuture> result = task.submit(); - SwitchConnectionDistinguisher cookie = null ; - - LOG.debug("Calling the MeterMod RPC method on MessageDispatchService"); - Future> resultFromOFLib = messageService.meterMod(ofMeterModInput, cookie) ; - - RpcResult rpcResultFromOFLib = null ; - - try { - rpcResultFromOFLib = resultFromOFLib.get(); - } catch( Exception ex ) { - LOG.error( " Error while getting result for UpdateMeter RPC" + ex.getMessage()); - } - - UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult() ; - - UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder() ; - updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId()) ; - UpdateMeterOutput result = updateMeterOutput.build(); - - Collection errors = rpcResultFromOFLib.getErrors() ; - RpcResult rpcResult = Rpcs.getRpcResult(true, result, errors); - - LOG.debug("Returning the Update Meter RPC result to MD-SAL"); - return Futures.immediateFuture(rpcResult); + return result; } @Override @@ -533,768 +265,219 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { return nodeId; } - /* - * Methods for requesting statistics from switch - */ - @Override - public Future> getAllGroupStatistics(GetAllGroupStatisticsInput input) { - - //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); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPGROUP); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the group stats - MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder(); - MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder(); - mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue()))); - caseBuilder.setMultipartRequestGroup(mprGroupBuild.build()); - - //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); - 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> getAllGroupStatistics(final GetAllGroupStatisticsInput input) { + // use primary connection + LOG.debug("Calling the getAllGroupStatistics RPC method on MessageDispatchService"); + SwitchConnectionDistinguisher cookie = null; - //Generate xid to associate it with the request - Long xid = this.getSessionContext().getNextXid(); + OFRpcTask> task = + OFRpcTaskFactory.createGetAllGroupStatisticsTask(rpcTaskContext, input, cookie); + ListenableFuture> result = task.submit(); - LOG.debug("Prepare group description statistics request - Transaction id - {}",xid); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPGROUPDESC); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the group description stats - MultipartRequestGroupDescCaseBuilder mprGroupDescBuild = new MultipartRequestGroupDescCaseBuilder(); - - //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); - 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); + return result; } @Override - public Future> getGroupFeatures(GetGroupFeaturesInput input) { - - //Generate xid to associate it with the request - Long xid = this.getSessionContext().getNextXid(); - - LOG.debug("Prepare group features statistics request - Transaction id - {}",xid); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPGROUPFEATURES); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the group description stats - MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder(); + public Future> getGroupDescription(final GetGroupDescriptionInput input) { + LOG.debug("Calling the getGroupDescription RPC method on MessageDispatchService"); - //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); - this.messageService.multipartRequest(mprInput.build(), null); + OFRpcTask> task = + OFRpcTaskFactory.createGetGroupDescriptionTask(rpcTaskContext, input, null); + return task.submit(); + } - // 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)); + @Override + public Future> getGroupFeatures(final GetGroupFeaturesInput input) { + LOG.debug("Calling the getGroupFeatures RPC method on MessageDispatchService"); - Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); - return Futures.immediateFuture(rpcResult); + OFRpcTask> task = + OFRpcTaskFactory.createGetGroupFeaturesTask(rpcTaskContext, input, null); + return task.submit(); } @Override - public Future> getGroupStatistics(GetGroupStatisticsInput input) { - - //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); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPGROUP); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the group stats - MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder(); - MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder(); - mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue())); - caseBuilder.setMultipartRequestGroup(mprGroupBuild.build()); - - //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); - 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); + public Future> getGroupStatistics(final GetGroupStatisticsInput input) { + LOG.debug("Calling the getGroupStatistics RPC method on MessageDispatchService"); + + OFRpcTask> task = + OFRpcTaskFactory.createGetGroupStatisticsTask(rpcTaskContext, input, null); + return task.submit(); } @Override public Future> getAllMeterConfigStatistics( - GetAllMeterConfigStatisticsInput input) { - - //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); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPMETERCONFIG); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the meter stats - MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder(); - MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder(); - mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue()))); - caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build()); - - //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); - 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); - } + final GetAllMeterConfigStatisticsInput input) { + LOG.debug("Calling the getAllMeterConfigStatistics RPC method on MessageDispatchService"); - @Override - public Future> getAllMeterStatistics(GetAllMeterStatisticsInput input) { - - //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); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPMETER); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the meter stats - MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder(); - MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder(); - mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue()))); - caseBuilder.setMultipartRequestMeter(mprMeterBuild.build()); - - //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); - 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); + OFRpcTask> task = + OFRpcTaskFactory.createGetAllMeterConfigStatisticsTask(rpcTaskContext, input, null); + return task.submit(); } @Override - public Future> getMeterFeatures(GetMeterFeaturesInput input) { - - //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); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPMETERFEATURES); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the group description stats - MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder(); + public Future> getAllMeterStatistics( + final GetAllMeterStatisticsInput input) { + LOG.debug("Calling the getAllMeterStatistics RPC method on MessageDispatchService"); - //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); - this.messageService.multipartRequest(mprInput.build(), null); + OFRpcTask> task = + OFRpcTaskFactory.createGetAllMeterStatisticsTask(rpcTaskContext, input, null); + return task.submit(); + } - // 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)); + @Override + public Future> getMeterFeatures( + final GetMeterFeaturesInput input) { + LOG.debug("Calling the getMeterFeatures RPC method on MessageDispatchService"); - Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); - return Futures.immediateFuture(rpcResult); + OFRpcTask> task = + OFRpcTaskFactory.createGetMeterFeaturesTask(rpcTaskContext, input, null); + return task.submit(); } @Override - public Future> getMeterStatistics(GetMeterStatisticsInput input) { - //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); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPMETER); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the meter stats - MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder(); - MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder(); - //Select specific meter - mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue())); - caseBuilder.setMultipartRequestMeter(mprMeterBuild.build()); - - //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); - 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); + public Future> getMeterStatistics( + final GetMeterStatisticsInput input) { + LOG.debug("Calling the getMeterStatistics RPC method on MessageDispatchService"); + + OFRpcTask> task = + OFRpcTaskFactory.createGetMeterStatisticsTask(rpcTaskContext, input, null); + return task.submit(); } - private TransactionId generateTransactionId(Long xid){ - String stringXid =xid.toString(); - BigInteger bigIntXid = new BigInteger( stringXid ); - return new TransactionId(bigIntXid); + @Override + public Future> getAllNodeConnectorsStatistics( + final GetAllNodeConnectorsStatisticsInput input) { + LOG.debug("Calling the getAllNodeConnectorsStatistics RPC method on MessageDispatchService"); + OFRpcTask> task = + OFRpcTaskFactory.createGetAllNodeConnectorsStatisticsTask(rpcTaskContext, input, null); + return task.submit(); } @Override - public Future> getPort() { - // TODO Auto-generated method stub - return null; + public Future> getNodeConnectorStatistics( + final GetNodeConnectorStatisticsInput input) { + LOG.debug("Calling the getNodeConnectorStatistics RPC method on MessageDispatchService"); + + OFRpcTask> task = + OFRpcTaskFactory.createGetNodeConnectorStatisticsTask(rpcTaskContext, input, null); + return task.submit(); } - @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); + public Future> updatePort(final UpdatePortInput input) { + LOG.debug("Calling the updatePort RPC method on MessageDispatchService"); + OFRpcTask> task = + OFRpcTaskFactory.createUpdatePortTask(rpcTaskContext, input, null); + return task.submit(); } - + @Override - public Future> updateTable( - UpdateTableInput input) { - - // 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); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPTABLEFEATURES); - 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()) ; - int totalNoOfTableFeatureEntry = ofTableFeatureList.size(); - - MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder(); - MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder(); - - // Slice the multipart request based on the configuration parameter, which is the no. of TableFeatureList element - // to be put in one multipart message. Default is 5 - // This parameter must be set based on switch's Buffer capacity - - List tmpOfTableFeatureList = null ; - String tableFeatureListCount = System.getProperty( "of.tableFeaturesCountPerMultipart", "5") ; - int noOfEntriesInMPR = Integer.parseInt(tableFeatureListCount) ; - - int index = 0 ; - while(totalNoOfTableFeatureEntry-index > 0 ) { - if( (totalNoOfTableFeatureEntry-index) > noOfEntriesInMPR ) { - mprInput.setFlags(new MultipartRequestFlags(true)); - tmpOfTableFeatureList = ofTableFeatureList.subList(index, index + noOfEntriesInMPR); - } - else { - // Last multipart request - mprInput.setFlags(new MultipartRequestFlags(false)); - tmpOfTableFeatureList = ofTableFeatureList.subList(index, totalNoOfTableFeatureEntry ); - } - - tableFeaturesRequest.setTableFeatures(tmpOfTableFeatureList) ; - //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 :{}",tmpOfTableFeatureList); - this.messageService.multipartRequest(mprInput.build(), null); - index += noOfEntriesInMPR ; - tmpOfTableFeatureList = null ; // To avoid any corrupt data - } - - //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"); - UpdateTableOutputBuilder output = new UpdateTableOutputBuilder(); - output.setTransactionId(generateTransactionId(xid)); - - Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); - return Futures.immediateFuture(rpcResult); + public Future> updateTable(final UpdateTableInput input) { + LOG.debug("Calling the updateTable RPC method on MessageDispatchService"); + OFRpcTask> task = + OFRpcTaskFactory.createUpdateTableTask(rpcTaskContext, input, null); + return task.submit(); } @Override public Future> getAllFlowStatisticsFromFlowTable( - GetAllFlowStatisticsFromFlowTableInput arg0) { - - //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); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPFLOW); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the group stats - MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder (); - MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); - mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue()); - mprFlowRequestBuilder.setOutPort(OpenflowEnumConstant.OFPP_ANY); - mprFlowRequestBuilder.setOutGroup(OpenflowEnumConstant.OFPG_ANY); - mprFlowRequestBuilder.setCookie(OpenflowEnumConstant.DEFAULT_COOKIE); - mprFlowRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK); - if(version == OpenflowEnumConstant.OPENFLOW_V10){ - LOG.info("Target node is running openflow version 1.0"); - FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,false,false,false,false,false,false,false,false,false,false); - mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build()); - } - if(version == OpenflowEnumConstant.OPENFLOW_V13){ - LOG.info("Target node is running openflow version 1.3+"); - mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build()); - } - - - //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); - this.messageService.multipartRequest(mprInput.build(), null); + final GetAllFlowStatisticsFromFlowTableInput input) { + LOG.debug("Calling the getAllFlowStatisticsFromFlowTable RPC method on MessageDispatchService"); - // Prepare rpc return output. Set xid and send it back. - LOG.debug("Return results and transaction id back to caller"); - GetAllFlowStatisticsFromFlowTableOutputBuilder output = - new GetAllFlowStatisticsFromFlowTableOutputBuilder(); - output.setTransactionId(generateTransactionId(xid)); - output.setFlowAndStatisticsMapList(null); - - Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); - return Futures.immediateFuture(rpcResult); + OFRpcTask> task = + OFRpcTaskFactory.createGetAllFlowStatisticsFromFlowTableTask(rpcTaskContext, input, null); + return task.submit(); } @Override public Future> getAllFlowsStatisticsFromAllFlowTables( - 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); - - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPFLOW); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the group stats - MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); - MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); - mprFlowRequestBuilder.setTableId(OpenflowEnumConstant.OFPTT_ALL); - mprFlowRequestBuilder.setOutPort(OpenflowEnumConstant.OFPP_ANY); - mprFlowRequestBuilder.setOutGroup(OpenflowEnumConstant.OFPG_ANY); - mprFlowRequestBuilder.setCookie(OpenflowEnumConstant.DEFAULT_COOKIE); - mprFlowRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK); - mprFlowRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK); - - if(version == OpenflowEnumConstant.OPENFLOW_V10){ - FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,false,false,false,false,false,false,false,false,false,false); - mprFlowRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build()); - } - if(version == OpenflowEnumConstant.OPENFLOW_V13){ - mprFlowRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build()); - } - //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); - this.messageService.multipartRequest(mprInput.build(), null); - - // Prepare rpc return output. Set xid and send it back. - GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output = - new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder(); - output.setTransactionId(generateTransactionId(xid)); - output.setFlowAndStatisticsMapList(null); - - Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); - return Futures.immediateFuture(rpcResult); + final GetAllFlowsStatisticsFromAllFlowTablesInput input) { + LOG.debug("Calling the getAllFlowsStatisticsFromAllFlowTables RPC method on MessageDispatchService"); + OFRpcTask> task = + OFRpcTaskFactory.createGetAllFlowsStatisticsFromAllFlowTablesTask(rpcTaskContext, input, null); + return task.submit(); } @Override public Future> getFlowStatisticsFromFlowTable( - GetFlowStatisticsFromFlowTableInput arg0) { - //Generate xid to associate it with the request - Long xid = this.getSessionContext().getNextXid(); - - 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(); - mprInput.setType(MultipartType.OFPMPFLOW); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the group stats - MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); - MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); - mprFlowRequestBuilder.setTableId(arg0.getTableId()); - mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue()); - mprFlowRequestBuilder.setOutGroup(OpenflowEnumConstant.OFPG_ANY); - mprFlowRequestBuilder.setCookie(OpenflowEnumConstant.DEFAULT_COOKIE); - mprFlowRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK); - - - if(version == OpenflowEnumConstant.OPENFLOW_V10){ - mprFlowRequestBuilder.setMatchV10(MatchConvertor.toMatchV10(arg0.getMatch())); - } - if(version == OpenflowEnumConstant.OPENFLOW_V13){ - MatchBuilder matchBuilder = new MatchBuilder(); - matchBuilder.setMatchEntries(MatchConvertor.toMatch(arg0.getMatch())); - matchBuilder.setType(OxmMatchType.class); - mprFlowRequestBuilder.setMatch(matchBuilder.build()); - - mprFlowRequestBuilder.setCookie(arg0.getCookie()); - mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask()); - mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup()); - } - - //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); - this.messageService.multipartRequest(mprInput.build(), null); + final GetFlowStatisticsFromFlowTableInput input) { + LOG.debug("Calling the getFlowStatisticsFromFlowTable RPC method on MessageDispatchService"); - // Prepare rpc return output. Set xid and send it back. - GetFlowStatisticsFromFlowTableOutputBuilder output = - new GetFlowStatisticsFromFlowTableOutputBuilder(); - output.setTransactionId(generateTransactionId(xid)); - output.setFlowAndStatisticsMapList(null); - - Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); - return Futures.immediateFuture(rpcResult); + OFRpcTask> task = + OFRpcTaskFactory.createGetFlowStatisticsFromFlowTableTask(rpcTaskContext, input, null); + return task.submit(); } @Override public Future> getAggregateFlowStatisticsFromFlowTableForAllFlows( - GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) { - //Generate xid to associate it with the request - Long xid = this.getSessionContext().getNextXid(); - - 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(); - mprInput.setType(MultipartType.OFPMPAGGREGATE); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the group stats - MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder (); - MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder(); - mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue()); - mprAggregateRequestBuilder.setOutPort(OpenflowEnumConstant.OFPP_ANY); - mprAggregateRequestBuilder.setOutGroup(OpenflowEnumConstant.OFPG_ANY); - mprAggregateRequestBuilder.setCookie(OpenflowEnumConstant.DEFAULT_COOKIE); - mprAggregateRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK); - if(version == OpenflowEnumConstant.OPENFLOW_V10){ - FlowWildcardsV10 wildCard = new FlowWildcardsV10(true,false,false,false,false,false,false,false,false,false,false); - mprAggregateRequestBuilder.setMatchV10(new MatchV10Builder().setWildcards(wildCard).build()); - } - if(version == OpenflowEnumConstant.OPENFLOW_V13){ - mprAggregateRequestBuilder.setMatch(new MatchBuilder().setType(OxmMatchType.class).build()); - } - + final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { + LOG.debug("Calling the getAggregateFlowStatisticsFromFlowTableForAllFlows RPC method on MessageDispatchService"); - //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()); - this.messageService.multipartRequest(mprInput.build(), null); - - // Prepare rpc return output. Set xid and send it back. - GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output = - new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder(); - output.setTransactionId(generateTransactionId(xid)); - - Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); - return Futures.immediateFuture(rpcResult); + OFRpcTask> task = + OFRpcTaskFactory.createGetAggregateFlowStatisticsFromFlowTableForAllFlowsTask(rpcTaskContext, input, null); + return task.submit(); } @Override public Future> getAggregateFlowStatisticsFromFlowTableForGivenMatch( - GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) { - - //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); + final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { + LOG.debug("Calling the getAggregateFlowStatisticsFromFlowTableForGivenMatch RPC method on MessageDispatchService"); - // Create multipart request header - MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); - mprInput.setType(MultipartType.OFPMPAGGREGATE); - mprInput.setVersion(version); - mprInput.setXid(xid); - mprInput.setFlags(new MultipartRequestFlags(false)); - - // Create multipart request body for fetch all the group stats - MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder (); - MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder(); - mprAggregateRequestBuilder.setTableId(arg0.getTableId()); - mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue()); - mprAggregateRequestBuilder.setOutGroup(OpenflowEnumConstant.OFPG_ANY); - mprAggregateRequestBuilder.setCookie(OpenflowEnumConstant.DEFAULT_COOKIE); - mprAggregateRequestBuilder.setCookieMask(OpenflowEnumConstant.DEFAULT_COOKIE_MASK); - - - if(version == OpenflowEnumConstant.OPENFLOW_V10){ - mprAggregateRequestBuilder.setMatchV10(MatchConvertor.toMatchV10(arg0.getMatch())); - } - if(version == OpenflowEnumConstant.OPENFLOW_V13){ - MatchBuilder matchBuilder = new MatchBuilder(); - matchBuilder.setMatchEntries(MatchConvertor.toMatch(arg0.getMatch())); - matchBuilder.setType(OxmMatchType.class); - mprAggregateRequestBuilder.setMatch(matchBuilder.build()); - - mprAggregateRequestBuilder.setCookie(arg0.getCookie()); - mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask()); - mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup()); - } - - //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 for 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(); - output.setTransactionId(generateTransactionId(xid)); - - Collection errors = Collections.emptyList(); - RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); - return Futures.immediateFuture(rpcResult); + OFRpcTask> task = + OFRpcTaskFactory.createGetAggregateFlowStatisticsFromFlowTableForGivenMatchTask(rpcTaskContext, input, null); + return task.submit(); } @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; + public Future> getFlowTablesStatistics( + final GetFlowTablesStatisticsInput input) { + LOG.debug("Calling the getFlowTablesStatistics RPC method on MessageDispatchService"); + + OFRpcTask> task = + OFRpcTaskFactory.createGetFlowTablesStatisticsTask(rpcTaskContext, input, null); + return task.submit(); } @Override - public Future> getAllNodeConnectorStatistics( - GetAllNodeConnectorStatisticsInput arg0) { - // TODO Auto-generated method stub - return null; + public Future> getAllQueuesStatisticsFromAllPorts( + final GetAllQueuesStatisticsFromAllPortsInput input) { + LOG.debug("Calling the getAllQueuesStatisticsFromAllPorts RPC method on MessageDispatchService"); + + OFRpcTask> task = + OFRpcTaskFactory.createGetAllQueuesStatisticsFromAllPortsTask(rpcTaskContext, input, null); + return task.submit(); } @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; + public Future> getAllQueuesStatisticsFromGivenPort( + final GetAllQueuesStatisticsFromGivenPortInput input) { + LOG.debug("Calling the getAllQueuesStatisticsFromGivenPort RPC method on MessageDispatchService"); + + OFRpcTask> task = + OFRpcTaskFactory.createGetAllQueuesStatisticsFromGivenPortTask(rpcTaskContext, input, null); + return task.submit(); } @Override - public Future> getFlowTableStatistics(GetFlowTableStatisticsInput arg0) { - // TODO Auto-generated method stub - return null; + public Future> getQueueStatisticsFromGivenPort( + final GetQueueStatisticsFromGivenPortInput input) { + LOG.debug("Calling the getQueueStatisticsFromGivenPort RPC method on MessageDispatchService"); + + OFRpcTask> task = + OFRpcTaskFactory.createGetQueueStatisticsFromGivenPortTask(rpcTaskContext, input, null); + return task.submit(); } @Override - public Future> getNodeConnectorStatistics( - GetNodeConnectorStatisticsInput arg0) { - // TODO Auto-generated method stub - return null; + public Future> setConfig(SetConfigInput input) { + OFRpcTask> task = OFRpcTaskFactory.createSetNodeConfigTask(rpcTaskContext, input, null); + return task.submit(); } }