X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2Fsal%2FOFRpcTaskFactory.java;h=371ed9e04820c2ac0b64a984dbd669c45119ddb5;hb=611180ac770b6038b526c54994701db16d1a8567;hp=5c5e9de7cc1558805b8699985773c4124c23a5ed;hpb=8081eb379aa0128eae6826d234b76ece66fcfbfd;p=openflowplugin.git diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java index 5c5e9de7cc..371ed9e048 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013-2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -37,6 +37,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.Remo import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder; 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.flow.update.OriginalFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow; 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; @@ -55,7 +57,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.G 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; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.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.group.service.rev130918.AddGroupInput; @@ -104,16 +106,21 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111. 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.meter.types.rev130918.Meter; +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.module.config.rev141015.SetConfigOutputBuilder; 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.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.SwitchConfigFlag; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; 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.PortModInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder; 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; @@ -173,46 +180,51 @@ import com.google.common.util.concurrent.SettableFuture; * */ public abstract class OFRpcTaskFactory { - protected static final Logger logger = LoggerFactory.getLogger(OFRpcTaskFactory.class); + protected static final Logger LOG = LoggerFactory.getLogger(OFRpcTaskFactory.class); + private OFRpcTaskFactory() { + // hiding implicit constructor + } + /** - * @param taskContext - * @param input - * @param cookie + * @param taskContext + * @param input + * @param cookie * @return UpdateFlow task */ public static OFRpcTask> createAddFlowTask( OFRpcTaskContext taskContext, AddFlowInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddFlowInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { ListenableFuture> result = SettableFuture.create(); - + // Convert the AddFlowInput to FlowModInput List ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput(), getVersion(), getSession().getFeatures().getDatapathId()); - - logger.debug("Number of flows to push to switch: {}", ofFlowModInputs.size()); - + LOG.debug("Number of flows to push to switch: {}", ofFlowModInputs.size()); result = chainFlowMods(ofFlowModInputs, 0, getTaskContext(), getCookie()); - - result = OFRpcTaskUtil.chainFutureBarrier(this, result); OFRpcTaskUtil.hookFutureNotification(this, result, - getRpcNotificationProviderService(), - createFlowAddedNotification(getInput())); + getRpcNotificationProviderService(), + createFlowAddedNotification(getInput())); return result; } - + @Override public Boolean isBarrier() { return getInput().isBarrier(); } - }; - return task; + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } /** @@ -224,29 +236,29 @@ public abstract class OFRpcTaskFactory { * the notification */ protected static ListenableFuture> chainFlowMods( - final List ofFlowModInputs, final int index, - final OFRpcTaskContext taskContext, final SwitchConnectionDistinguisher cookie) { + final List ofFlowModInputs, final int index, + final OFRpcTaskContext taskContext, final SwitchConnectionDistinguisher cookie) { Future> resultFromOFLib = - createResultForFlowMod(taskContext, ofFlowModInputs.get(index), cookie); + createResultForFlowMod(taskContext, ofFlowModInputs.get(index), cookie); - ListenableFuture> result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + ListenableFuture> result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - if(ofFlowModInputs.size() > index + 1) { + if (ofFlowModInputs.size() > index + 1) { // there are more flowmods to chain return Futures.transform(result, - new AsyncFunction, RpcResult>() { - @Override - public ListenableFuture> apply(RpcResult input) throws Exception { - if (input.isSuccessful()) { - return chainFlowMods(ofFlowModInputs, index + 1, taskContext, cookie); - } else { - logger.warn("Flowmod failed. Any chained flowmods are ignored. xid:{}", - ofFlowModInputs.get(index).getXid()); - return Futures.immediateFuture(input); + new AsyncFunction, RpcResult>() { + @Override + public ListenableFuture> apply(RpcResult input) throws Exception { + if (input.isSuccessful()) { + return chainFlowMods(ofFlowModInputs, index + 1, taskContext, cookie); + } else { + LOG.warn("Flowmod failed. Any chained flowmods are ignored. xid:{}", + ofFlowModInputs.get(index).getXid()); + return Futures.immediateFuture(input); + } } } - } ); } else { return result; @@ -254,8 +266,8 @@ public abstract class OFRpcTaskFactory { } private static Future> createResultForFlowMod( - OFRpcTaskContext taskContext, FlowModInputBuilder flowModInput, - SwitchConnectionDistinguisher cookie) { + OFRpcTaskContext taskContext, FlowModInputBuilder flowModInput, + SwitchConnectionDistinguisher cookie) { flowModInput.setXid(taskContext.getSession().getNextXid()); return taskContext.getMessageService().flowMod(flowModInput.build(), cookie); } @@ -279,63 +291,70 @@ public abstract class OFRpcTaskFactory { } /** - * @param taskContext - * @param input - * @param cookie + * @param taskContext + * @param input + * @param cookie * @return UpdateFlow task */ public static OFRpcTask> createUpdateFlowTask( - final OFRpcTaskContext taskContext, UpdateFlowInput input, + final OFRpcTaskContext taskContext, UpdateFlowInput input, SwitchConnectionDistinguisher cookie) { - - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + UpdateFlowInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { ListenableFuture> result = null; - - boolean updatedFlow = (getInput().getUpdatedFlow().getMatch().equals(getInput().getOriginalFlow().getMatch())) && - (getInput().getUpdatedFlow().getPriority().equals(getInput().getOriginalFlow().getPriority())); + + UpdateFlowInput in = getInput(); + UpdatedFlow updated = in.getUpdatedFlow(); + OriginalFlow original = in.getOriginalFlow(); + Short version = getVersion(); List allFlowMods = new ArrayList<>(); List ofFlowModInputs; - if (updatedFlow == false) { - // if neither match nor priority matches, then we would need to remove the flow and add it + if (!FlowCreatorUtil.canModifyFlow(original, updated, version)) { + // We would need to remove original and add updated. + //remove flow - RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(getInput().getOriginalFlow()); + RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original); List ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(), - getVersion(),getSession().getFeatures().getDatapathId()); + version, getSession().getFeatures().getDatapathId()); // remove flow should be the first allFlowMods.addAll(ofFlowRemoveInput); - AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(getInput().getUpdatedFlow()); + AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated); ofFlowModInputs = FlowConvertor.toFlowModInputs(addFlowInputBuilder.build(), - getVersion(), getSession().getFeatures().getDatapathId()); + version, getSession().getFeatures().getDatapathId()); } else { - ofFlowModInputs = FlowConvertor.toFlowModInputs(getInput().getUpdatedFlow(), - getVersion(), getSession().getFeatures().getDatapathId()); + ofFlowModInputs = FlowConvertor.toFlowModInputs(updated, + version, getSession().getFeatures().getDatapathId()); } allFlowMods.addAll(ofFlowModInputs); - logger.debug("Number of flows to push to switch: {}", allFlowMods.size()); + LOG.debug("Number of flows to push to switch: {}", allFlowMods.size()); result = chainFlowMods(allFlowMods, 0, getTaskContext(), getCookie()); result = OFRpcTaskUtil.chainFutureBarrier(this, result); OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(), - createFlowUpdatedNotification(getInput())); + createFlowUpdatedNotification(in)); return result; } - + @Override public Boolean isBarrier() { return getInput().getUpdatedFlow().isBarrier(); } - }; - return task; + } + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param xId @@ -353,7 +372,7 @@ public abstract class OFRpcTaskFactory { } }; } - + /** * @param taskContext * @param input @@ -361,17 +380,20 @@ public abstract class OFRpcTaskFactory { * @return update group task */ public static OFRpcTask> createAddGroupTask( - final OFRpcTaskContext taskContext, AddGroupInput input, + final OFRpcTaskContext taskContext, AddGroupInput input, final SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddGroupInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { ListenableFuture> result = SettableFuture.create(); - + // Convert the AddGroupInput to GroupModInput - GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(), + GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(), getVersion(), getSession().getFeatures().getDatapathId()); final Long xId = getSession().getNextXid(); ofGroupModInput.setXid(xId); @@ -381,21 +403,21 @@ public abstract class OFRpcTaskFactory { result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); result = OFRpcTaskUtil.chainFutureBarrier(this, result); - OFRpcTaskUtil.hookFutureNotification(this, result, + OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(), createGroupAddedNotification(getInput())); return result; } - + @Override public Boolean isBarrier() { return getInput().isBarrier(); } }; - - return task; + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param input @@ -423,37 +445,39 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createAddMeterTask( OFRpcTaskContext taskContext, AddMeterInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, AddMeterInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { ListenableFuture> result = SettableFuture.create(); - + // Convert the AddGroupInput to GroupModInput MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion()); final Long xId = getSession().getNextXid(); ofMeterModInput.setXid(xId); - + Future> resultFromOFLib = getMessageService() .meterMod(ofMeterModInput.build(), getCookie()); result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - + result = OFRpcTaskUtil.chainFutureBarrier(this, result); - OFRpcTaskUtil.hookFutureNotification(this, result, + OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(), createMeterAddedNotification(getInput())); return result; } - + @Override public Boolean isBarrier() { return getInput().isBarrier(); } }; - - return task; - + + return new OFRpcTaskImpl(taskContext, cookie, input); } /** @@ -472,23 +496,27 @@ public abstract class OFRpcTaskFactory { } }; } - + /** - * @param taskContext - * @param input - * @param cookie + * @param taskContext + * @param input + * @param cookie * @return UpdateFlow task */ public static OFRpcTask> createUpdateGroupTask( - OFRpcTaskContext taskContext, UpdateGroupInput input, + OFRpcTaskContext taskContext, UpdateGroupInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + UpdateGroupInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { ListenableFuture> result = null; - + // Convert the UpdateGroupInput to GroupModInput GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput( getInput().getUpdatedGroup(), getVersion(), @@ -496,20 +524,21 @@ public abstract class OFRpcTaskFactory { final Long xId = getSession().getNextXid(); ofGroupModInput.setXid(xId); - Future> resultFromOFLib = + Future> resultFromOFLib = getMessageService().groupMod(ofGroupModInput.build(), getCookie()); result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); result = OFRpcTaskUtil.chainFutureBarrier(this, result); - OFRpcTaskUtil.hookFutureNotification(this, result, + OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(), createGroupUpdatedNotification(getInput())); - + return result; } - }; - return task; + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param input * @return @@ -528,17 +557,21 @@ public abstract class OFRpcTaskFactory { } /** - * @param taskContext + * @param taskContext * @param input * @param cookie - * @return update meter task + * @return update meter task */ public static OFRpcTask> createUpdateMeterTask( OFRpcTaskContext taskContext, UpdateMeterInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + UpdateMeterInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { ListenableFuture> result = null; @@ -549,7 +582,7 @@ public abstract class OFRpcTaskFactory { final Long xId = getSession().getNextXid(); ofMeterModInput.setXid(xId); - Future> resultFromOFLib = + Future> resultFromOFLib = getMessageService().meterMod(ofMeterModInput.build(), getCookie()); result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); @@ -558,10 +591,11 @@ public abstract class OFRpcTaskFactory { getRpcNotificationProviderService(), createMeterUpdatedNotification(getInput())); return result; } - }; - return task; + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param input * @return @@ -578,8 +612,8 @@ public abstract class OFRpcTaskFactory { } }; } - - + + /** * @param taskContext * @param input @@ -589,34 +623,38 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createRemoveFlowTask( OFRpcTaskContext taskContext, RemoveFlowInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + RemoveFlowInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { ListenableFuture> result = SettableFuture.create(); // Convert the AddFlowInput to FlowModInput - FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput(), + FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput(), getVersion(), getSession().getFeatures().getDatapathId()); final Long xId = getSession().getNextXid(); ofFlowModInput.setXid(xId); - Future> resultFromOFLib = + Future> resultFromOFLib = getMessageService().flowMod(ofFlowModInput.build(), getCookie()); result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); result = OFRpcTaskUtil.chainFutureBarrier(this, result); - OFRpcTaskUtil.hookFutureNotification(this, result, + OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(), createFlowRemovedNotification(getInput())); return result; } - }; - - return task; + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param input * @return @@ -633,8 +671,8 @@ public abstract class OFRpcTaskFactory { } }; } - - + + /** * @param taskContext * @param input @@ -642,17 +680,21 @@ public abstract class OFRpcTaskFactory { * @return task */ public static OFRpcTask> createRemoveGroupTask( - final OFRpcTaskContext taskContext, RemoveGroupInput input, + final OFRpcTaskContext taskContext, RemoveGroupInput input, final SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + RemoveGroupInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { ListenableFuture> result = SettableFuture.create(); // Convert the AddGroupInput to GroupModInput - GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(), + GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(), getVersion(), getSession().getFeatures().getDatapathId()); final Long xId = getSession().getNextXid(); ofGroupModInput.setXid(xId); @@ -662,19 +704,19 @@ public abstract class OFRpcTaskFactory { result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); result = OFRpcTaskUtil.chainFutureBarrier(this, result); - OFRpcTaskUtil.hookFutureNotification(this, result, + OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(), createGroupRemovedNotification(getInput())); return result; } - }; + } - return task; + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param input - * @return + * @return */ protected static NotificationComposer createGroupRemovedNotification( final RemoveGroupInput input) { @@ -688,7 +730,7 @@ public abstract class OFRpcTaskFactory { } }; } - + /** * @param taskContext * @param input @@ -698,9 +740,14 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createRemoveMeterTask( OFRpcTaskContext taskContext, RemoveMeterInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + RemoveMeterInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { ListenableFuture> result = SettableFuture.create(); @@ -715,17 +762,17 @@ public abstract class OFRpcTaskFactory { result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); result = OFRpcTaskUtil.chainFutureBarrier(this, result); - OFRpcTaskUtil.hookFutureNotification(this, result, + OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(), createMeterRemovedNotification(getInput())); return result; } - }; - - return task; - + } + + return new OFRpcTaskImpl(taskContext, cookie, input); + } - + /** * @param input * @return @@ -742,7 +789,7 @@ public abstract class OFRpcTaskFactory { } }; } - + /** * @param taskContext * @param input @@ -752,60 +799,66 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createGetAllGroupStatisticsTask( final OFRpcTaskContext taskContext, GetAllGroupStatisticsInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetAllGroupStatisticsInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { final SettableFuture> result = SettableFuture.create(); - + if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { RpcResult rpcResult = RpcResultBuilder.success( new GetAllGroupStatisticsOutputBuilder().build()).build(); - + return Futures.immediateFuture(rpcResult); - } else { - - // Generate xid to associate it with the request + } else { + + // Generate xid to associate it with the request final Long xid = taskContext.getSession().getNextXid(); - - // Create multipart request body for fetch all the group stats + + // Create multipart request body for fetch all the group stats MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder(); MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder(); mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong( org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731 - .Group.OFPGALL.getIntValue()))); + .Group.OFPGALL.getIntValue()))); caseBuilder.setMultipartRequestGroup(mprGroupBuild.build()); - + // Create multipart request header - MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPGROUP, + MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPGROUP, taskContext, xid); - + // Set request body to main multipart request mprInput.setMultipartRequestBody(caseBuilder.build()); - + // Send the request, no cookies associated, use any connection - + Future> resultFromOFLib = getMessageService() .multipartRequest(mprInput.build(), getCookie()); ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - + Futures.addCallback(resultLib, new ResultCallback(result) { @Override public GetAllGroupStatisticsOutput createResult() { GetAllGroupStatisticsOutputBuilder groupStatBuilder = new GetAllGroupStatisticsOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); return groupStatBuilder.build(); } }); - + return result; } } - }; - return task; + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -815,45 +868,50 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createGetGroupDescriptionTask( final OFRpcTaskContext taskContext, GetGroupDescriptionInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + class OFRpcTaskImpl extends OFRpcTask> { - @Override - public ListenableFuture> call() - throws Exception { - final SettableFuture> result = SettableFuture.create(); - - if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { - RpcResult rpcResult = RpcResultBuilder.success( - new GetGroupDescriptionOutputBuilder().build()).build(); - return Futures.immediateFuture(rpcResult); - } else { - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestGroupDescCaseBuilder mprGroupDescCaseBuild = - new MultipartRequestGroupDescCaseBuilder(); - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPGROUPDESC, taskContext, xid); - mprInput.setMultipartRequestBody(mprGroupDescCaseBuild.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetGroupDescriptionOutput createResult() { - GetGroupDescriptionOutputBuilder groupStatBuilder = new GetGroupDescriptionOutputBuilder() + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetGroupDescriptionInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() + throws Exception { + final SettableFuture> result = SettableFuture.create(); + + if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { + RpcResult rpcResult = RpcResultBuilder.success( + new GetGroupDescriptionOutputBuilder().build()).build(); + return Futures.immediateFuture(rpcResult); + } else { + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestGroupDescCaseBuilder mprGroupDescCaseBuild = + new MultipartRequestGroupDescCaseBuilder(); + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPGROUPDESC, taskContext, xid); + mprInput.setMultipartRequestBody(mprGroupDescCaseBuild.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetGroupDescriptionOutput createResult() { + GetGroupDescriptionOutputBuilder groupStatBuilder = new GetGroupDescriptionOutputBuilder() .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return groupStatBuilder.build(); - } - }); - return result; + return groupStatBuilder.build(); } - } - }; - return task; + }); + return result; + } + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -863,45 +921,51 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createGetGroupFeaturesTask( final OFRpcTaskContext taskContext, GetGroupFeaturesInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + class OFRpcTaskImpl extends OFRpcTask> { - @Override - public ListenableFuture> call() - throws Exception { - final SettableFuture> result = SettableFuture.create(); - - if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { - RpcResult rpcResult = RpcResultBuilder.success( - new GetGroupFeaturesOutputBuilder().build()).build(); - return Futures.immediateFuture(rpcResult); - } else { - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = - new MultipartRequestGroupFeaturesCaseBuilder(); - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPGROUPFEATURES, taskContext, xid); - mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetGroupFeaturesOutput createResult() { - GetGroupFeaturesOutputBuilder groupFeatureBuilder = new GetGroupFeaturesOutputBuilder() + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetGroupFeaturesInput input) { + super(taskContext, cookie, input); + // TODO Auto-generated constructor stub + } + + @Override + public ListenableFuture> call() + throws Exception { + final SettableFuture> result = SettableFuture.create(); + + if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { + RpcResult rpcResult = RpcResultBuilder.success( + new GetGroupFeaturesOutputBuilder().build()).build(); + return Futures.immediateFuture(rpcResult); + } else { + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = + new MultipartRequestGroupFeaturesCaseBuilder(); + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPGROUPFEATURES, taskContext, xid); + mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetGroupFeaturesOutput createResult() { + GetGroupFeaturesOutputBuilder groupFeatureBuilder = new GetGroupFeaturesOutputBuilder() .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return groupFeatureBuilder.build(); - } - }); - return result; + return groupFeatureBuilder.build(); } - } - }; - return task; + }); + return result; + } + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -911,49 +975,55 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createGetGroupStatisticsTask( final OFRpcTaskContext taskContext, final GetGroupStatisticsInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - @Override - public ListenableFuture> call() - throws Exception { - final SettableFuture> result = SettableFuture.create(); - - if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { - RpcResult rpcResult = RpcResultBuilder.success( - new GetGroupStatisticsOutputBuilder().build()).build(); - return Futures.immediateFuture(rpcResult); - } else { - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder(); - MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder(); - mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue())); - caseBuilder.setMultipartRequestGroup(mprGroupBuild.build()); - - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPGROUP, taskContext, xid); - mprInput.setMultipartRequestBody(caseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetGroupStatisticsOutput createResult() { - GetGroupStatisticsOutputBuilder groupStatisticsBuilder = - new GetGroupStatisticsOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return groupStatisticsBuilder.build(); - } - }); - return result; + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetGroupStatisticsInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() + throws Exception { + final SettableFuture> result = SettableFuture.create(); + + if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { + RpcResult rpcResult = RpcResultBuilder.success( + new GetGroupStatisticsOutputBuilder().build()).build(); + return Futures.immediateFuture(rpcResult); + } else { + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder(); + MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder(); + mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue())); + caseBuilder.setMultipartRequestGroup(mprGroupBuild.build()); + + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPGROUP, taskContext, xid); + mprInput.setMultipartRequestBody(caseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetGroupStatisticsOutput createResult() { + GetGroupStatisticsOutputBuilder groupStatisticsBuilder = + new GetGroupStatisticsOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return groupStatisticsBuilder.build(); } - } - }; - return task; + }); + return result; + } + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -963,53 +1033,58 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createGetAllMeterConfigStatisticsTask( final OFRpcTaskContext taskContext, final GetAllMeterConfigStatisticsInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + class OFRpcTaskImpl extends OFRpcTask> { - @Override - public ListenableFuture> call() - throws Exception { - final SettableFuture> result = SettableFuture.create(); - - if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { - RpcResult rpcResult = RpcResultBuilder.success( - new GetAllMeterConfigStatisticsOutputBuilder().build()).build(); - return Futures.immediateFuture(rpcResult); - } else { - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestMeterConfigCaseBuilder caseBuilder = - new MultipartRequestMeterConfigCaseBuilder(); - MultipartRequestMeterConfigBuilder mprMeterConfigBuild = - new MultipartRequestMeterConfigBuilder(); - mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong( - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetAllMeterConfigStatisticsInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() + throws Exception { + final SettableFuture> result = SettableFuture.create(); + + if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { + RpcResult rpcResult = RpcResultBuilder.success( + new GetAllMeterConfigStatisticsOutputBuilder().build()).build(); + return Futures.immediateFuture(rpcResult); + } else { + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestMeterConfigCaseBuilder caseBuilder = + new MultipartRequestMeterConfigCaseBuilder(); + MultipartRequestMeterConfigBuilder mprMeterConfigBuild = + new MultipartRequestMeterConfigBuilder(); + mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong( + org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common .types.rev130731.Meter.OFPMALL.getIntValue()))); - caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build()); - - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPMETERCONFIG, taskContext, xid); - mprInput.setMultipartRequestBody(caseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetAllMeterConfigStatisticsOutput createResult() { - GetAllMeterConfigStatisticsOutputBuilder allMeterConfStatBuilder = - new GetAllMeterConfigStatisticsOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return allMeterConfStatBuilder.build(); - } - }); - return result; + caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build()); + + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPMETERCONFIG, taskContext, xid); + mprInput.setMultipartRequestBody(caseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetAllMeterConfigStatisticsOutput createResult() { + GetAllMeterConfigStatisticsOutputBuilder allMeterConfStatBuilder = + new GetAllMeterConfigStatisticsOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return allMeterConfStatBuilder.build(); } - } - }; - return task; + }); + return result; + } + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -1019,53 +1094,59 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createGetAllMeterStatisticsTask( final OFRpcTaskContext taskContext, final GetAllMeterStatisticsInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + class OFRpcTaskImpl extends OFRpcTask> { - @Override - public ListenableFuture> call() - throws Exception { - final SettableFuture> result = SettableFuture.create(); - - if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { - RpcResult rpcResult = RpcResultBuilder.success( - new GetAllMeterStatisticsOutputBuilder().build()).build(); - return Futures.immediateFuture(rpcResult); - } else { - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestMeterCaseBuilder caseBuilder = - new MultipartRequestMeterCaseBuilder(); - MultipartRequestMeterBuilder mprMeterBuild = - new MultipartRequestMeterBuilder(); - mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong( - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common - .types.rev130731.Meter.OFPMALL.getIntValue()))); - caseBuilder.setMultipartRequestMeter(mprMeterBuild.build()); - - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid); - mprInput.setMultipartRequestBody(caseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetAllMeterStatisticsOutput createResult() { - GetAllMeterStatisticsOutputBuilder allMeterStatBuilder = - new GetAllMeterStatisticsOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return allMeterStatBuilder.build(); - } - }); - return result; + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetAllMeterStatisticsInput input) { + super(taskContext, cookie, input); + // TODO Auto-generated constructor stub + } + + @Override + public ListenableFuture> call() + throws Exception { + final SettableFuture> result = SettableFuture.create(); + + if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { + RpcResult rpcResult = RpcResultBuilder.success( + new GetAllMeterStatisticsOutputBuilder().build()).build(); + return Futures.immediateFuture(rpcResult); + } else { + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestMeterCaseBuilder caseBuilder = + new MultipartRequestMeterCaseBuilder(); + MultipartRequestMeterBuilder mprMeterBuild = + new MultipartRequestMeterBuilder(); + mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong( + org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common + .types.rev130731.Meter.OFPMALL.getIntValue()))); + caseBuilder.setMultipartRequestMeter(mprMeterBuild.build()); + + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid); + mprInput.setMultipartRequestBody(caseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetAllMeterStatisticsOutput createResult() { + GetAllMeterStatisticsOutputBuilder allMeterStatBuilder = + new GetAllMeterStatisticsOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return allMeterStatBuilder.build(); } - } - }; - return task; + }); + return result; + } + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -1075,47 +1156,53 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createGetMeterFeaturesTask( final OFRpcTaskContext taskContext, final GetMeterFeaturesInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - @Override - public ListenableFuture> call() - throws Exception { - final SettableFuture> result = SettableFuture.create(); - - if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { - RpcResult rpcResult = RpcResultBuilder.success( - new GetMeterFeaturesOutputBuilder().build()).build(); - return Futures.immediateFuture(rpcResult); - } else { - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = - new MultipartRequestMeterFeaturesCaseBuilder(); - - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPMETERFEATURES, taskContext, xid); - mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetMeterFeaturesOutput createResult() { - GetMeterFeaturesOutputBuilder meterFeaturesBuilder = - new GetMeterFeaturesOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return meterFeaturesBuilder.build(); - } - }); - return result; + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetMeterFeaturesInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() + throws Exception { + final SettableFuture> result = SettableFuture.create(); + + if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { + RpcResult rpcResult = RpcResultBuilder.success( + new GetMeterFeaturesOutputBuilder().build()).build(); + return Futures.immediateFuture(rpcResult); + } else { + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = + new MultipartRequestMeterFeaturesCaseBuilder(); + + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPMETERFEATURES, taskContext, xid); + mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetMeterFeaturesOutput createResult() { + GetMeterFeaturesOutputBuilder meterFeaturesBuilder = + new GetMeterFeaturesOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return meterFeaturesBuilder.build(); } - } - }; - return task; + }); + return result; + } + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -1125,357 +1212,398 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createGetMeterStatisticsTask( final OFRpcTaskContext taskContext, final GetMeterStatisticsInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - @Override - public ListenableFuture> call() - throws Exception { - final SettableFuture> result = SettableFuture.create(); - - if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { - RpcResult rpcResult = RpcResultBuilder.success( - new GetMeterStatisticsOutputBuilder().build()).build(); - return Futures.immediateFuture(rpcResult); - } else { - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestMeterCaseBuilder caseBuilder = - new MultipartRequestMeterCaseBuilder(); - MultipartRequestMeterBuilder mprMeterBuild = - new MultipartRequestMeterBuilder(); - mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue())); - caseBuilder.setMultipartRequestMeter(mprMeterBuild.build()); - - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid); - mprInput.setMultipartRequestBody(caseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetMeterStatisticsOutput createResult() { - GetMeterStatisticsOutputBuilder meterStatBuilder = - new GetMeterStatisticsOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return meterStatBuilder.build(); - } - }); - return result; + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetMeterStatisticsInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() + throws Exception { + final SettableFuture> result = SettableFuture.create(); + + if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) { + RpcResult rpcResult = RpcResultBuilder.success( + new GetMeterStatisticsOutputBuilder().build()).build(); + return Futures.immediateFuture(rpcResult); + } else { + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestMeterCaseBuilder caseBuilder = + new MultipartRequestMeterCaseBuilder(); + MultipartRequestMeterBuilder mprMeterBuild = + new MultipartRequestMeterBuilder(); + mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue())); + caseBuilder.setMultipartRequestMeter(mprMeterBuild.build()); + + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPMETER, taskContext, xid); + mprInput.setMultipartRequestBody(caseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetMeterStatisticsOutput createResult() { + GetMeterStatisticsOutputBuilder meterStatBuilder = + new GetMeterStatisticsOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return meterStatBuilder.build(); } - } - }; - return task; + }); + return result; + } + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input * @param cookie * @return task */ - public static OFRpcTask> - createGetAllNodeConnectorsStatisticsTask( + public static OFRpcTask> + createGetAllNodeConnectorsStatisticsTask( final OFRpcTaskContext taskContext, final GetAllNodeConnectorsStatisticsInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetAllNodeConnectorsStatisticsInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() + throws Exception { + final SettableFuture> result = SettableFuture.create(); + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestPortStatsCaseBuilder caseBuilder = + new MultipartRequestPortStatsCaseBuilder(); + MultipartRequestPortStatsBuilder mprPortStatsBuilder = + new MultipartRequestPortStatsBuilder(); + // Select all ports + mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY); + caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build()); + + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid); + mprInput.setMultipartRequestBody(caseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { @Override - public ListenableFuture> call() - throws Exception { - final SettableFuture> result = SettableFuture.create(); - - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestPortStatsCaseBuilder caseBuilder = - new MultipartRequestPortStatsCaseBuilder(); - MultipartRequestPortStatsBuilder mprPortStatsBuilder = - new MultipartRequestPortStatsBuilder(); - // Select all ports - mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY); - caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build()); - - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid); - mprInput.setMultipartRequestBody(caseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetAllNodeConnectorsStatisticsOutput createResult() { - GetAllNodeConnectorsStatisticsOutputBuilder allNodeConnectorStatBuilder = - new GetAllNodeConnectorsStatisticsOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return allNodeConnectorStatBuilder.build(); - } - }); - return result; - } - }; - return task; + public GetAllNodeConnectorsStatisticsOutput createResult() { + GetAllNodeConnectorsStatisticsOutputBuilder allNodeConnectorStatBuilder = + new GetAllNodeConnectorsStatisticsOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return allNodeConnectorStatBuilder.build(); + } + }); + return result; + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input * @param cookie * @return task */ - public static OFRpcTask> - createGetNodeConnectorStatisticsTask( + public static OFRpcTask> + createGetNodeConnectorStatisticsTask( final OFRpcTaskContext taskContext, final GetNodeConnectorStatisticsInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - - @Override - public ListenableFuture> call() - throws Exception { - final SettableFuture> result = SettableFuture.create(); - - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestPortStatsCaseBuilder caseBuilder = - new MultipartRequestPortStatsCaseBuilder(); - MultipartRequestPortStatsBuilder mprPortStatsBuilder = - new MultipartRequestPortStatsBuilder(); - // Set specific port - mprPortStatsBuilder - .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId( - OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()), - input.getNodeConnectorId())); - caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build()); - - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid); - mprInput.setMultipartRequestBody(caseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetNodeConnectorStatisticsOutput createResult() { - GetNodeConnectorStatisticsOutputBuilder allNodeConnectorStatBuilder = - new GetNodeConnectorStatisticsOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return allNodeConnectorStatBuilder.build(); - } - }); - return result; + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetNodeConnectorStatisticsInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() + throws Exception { + final SettableFuture> result = SettableFuture.create(); + + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestPortStatsCaseBuilder caseBuilder = + new MultipartRequestPortStatsCaseBuilder(); + MultipartRequestPortStatsBuilder mprPortStatsBuilder = + new MultipartRequestPortStatsBuilder(); + // Set specific port + mprPortStatsBuilder + .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId( + OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()), + input.getNodeConnectorId())); + caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build()); + + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPPORTSTATS, taskContext, xid); + mprInput.setMultipartRequestBody(caseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetNodeConnectorStatisticsOutput createResult() { + GetNodeConnectorStatisticsOutputBuilder allNodeConnectorStatBuilder = + new GetNodeConnectorStatisticsOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return allNodeConnectorStatBuilder.build(); } - }; - return task; + }); + return result; + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input * @param cookie * @return task */ - public static OFRpcTask> - createGetAllFlowStatisticsFromFlowTableTask( - final OFRpcTaskContext taskContext, + public static OFRpcTask> + createGetAllFlowStatisticsFromFlowTableTask( + final OFRpcTaskContext taskContext, final GetAllFlowStatisticsFromFlowTableInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - - @Override - public ListenableFuture> call() throws Exception { - final SettableFuture> result = SettableFuture.create(); - - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); - MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); - mprFlowRequestBuilder.setTableId(input.getTableId().getValue()); - mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); - mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); - mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); - mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession() - .getPrimaryConductor().getVersion(), mprFlowRequestBuilder); - - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid); - mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetAllFlowStatisticsFromFlowTableOutput createResult() { - GetAllFlowStatisticsFromFlowTableOutputBuilder allFlowStatsFromFlowTableBuilder = - new GetAllFlowStatisticsFromFlowTableOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return allFlowStatsFromFlowTableBuilder.build(); - } - }); - return result; + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetAllFlowStatisticsFromFlowTableInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() throws Exception { + final SettableFuture> result = SettableFuture.create(); + + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); + mprFlowRequestBuilder.setTableId(input.getTableId().getValue()); + mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); + mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); + mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); + mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); + FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession() + .getPrimaryConductor().getVersion(), mprFlowRequestBuilder); + + MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); + multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); + + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid); + mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetAllFlowStatisticsFromFlowTableOutput createResult() { + GetAllFlowStatisticsFromFlowTableOutputBuilder allFlowStatsFromFlowTableBuilder = + new GetAllFlowStatisticsFromFlowTableOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return allFlowStatsFromFlowTableBuilder.build(); } - }; - return task; + }); + return result; + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input * @param cookie * @return task */ - public static OFRpcTask> - createGetAllFlowsStatisticsFromAllFlowTablesTask( - final OFRpcTaskContext taskContext, + public static OFRpcTask> + createGetAllFlowsStatisticsFromAllFlowTablesTask( + final OFRpcTaskContext taskContext, final GetAllFlowsStatisticsFromAllFlowTablesInput input, SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetAllFlowsStatisticsFromAllFlowTablesInput input) { + super(taskContext, cookie, input); + } @Override public ListenableFuture> call() throws Exception { final SettableFuture> result = SettableFuture.create(); - - final Long xid = taskContext.getSession().getNextXid(); - - // Create multipart request body for fetch all the group stats - MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = - new MultipartRequestFlowCaseBuilder(); - MultipartRequestFlowBuilder mprFlowRequestBuilder = - new MultipartRequestFlowBuilder(); - mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL); - mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); - mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); - mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); - mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession() - .getPrimaryConductor().getVersion(), mprFlowRequestBuilder); - - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid); - multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); - mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetAllFlowsStatisticsFromAllFlowTablesOutput createResult() { - GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder allFlowStatsFromAllFlowTableBuilder = - new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return allFlowStatsFromAllFlowTableBuilder.build(); - } - }); - return result; - } - }; - return task; + + final Long xid = taskContext.getSession().getNextXid(); + + // Create multipart request body for fetch all the group stats + MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = + new MultipartRequestFlowCaseBuilder(); + MultipartRequestFlowBuilder mprFlowRequestBuilder = + new MultipartRequestFlowBuilder(); + mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL); + mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); + mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); + mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); + mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); + FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession() + .getPrimaryConductor().getVersion(), mprFlowRequestBuilder); + + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid); + multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); + mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetAllFlowsStatisticsFromAllFlowTablesOutput createResult() { + GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder allFlowStatsFromAllFlowTableBuilder = + new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return allFlowStatsFromAllFlowTableBuilder.build(); + } + }); + return result; + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input * @param cookie * @return task */ - public static OFRpcTask> - createGetFlowStatisticsFromFlowTableTask( - final OFRpcTaskContext taskContext, - final GetFlowStatisticsFromFlowTableInput input,SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + public static OFRpcTask> + createGetFlowStatisticsFromFlowTableTask( + final OFRpcTaskContext taskContext, + final GetFlowStatisticsFromFlowTableInput input, SwitchConnectionDistinguisher cookie) { + + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetFlowStatisticsFromFlowTableInput input) { + super(taskContext, cookie, input); + } @Override public ListenableFuture> call() throws Exception { final SettableFuture> result = SettableFuture.create(); - - final Long xid = taskContext.getSession().getNextXid(); - - // Create multipart request body for fetch all the group stats - MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); - MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); - mprFlowRequestBuilder.setTableId(input.getTableId()); - - if (input.getOutPort() != null) - mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue()); - else - mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); - - if (input.getOutGroup() != null) - mprFlowRequestBuilder.setOutGroup(input.getOutGroup()); - else - mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); - - if (input.getCookie() != null) - mprFlowRequestBuilder.setCookie(input.getCookie().getValue()); - else - mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); - - if (input.getCookieMask() != null) - mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue()); - else - mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); - - // convert and inject match - MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession() - .getPrimaryConductor().getVersion(), mprFlowRequestBuilder, - taskContext.getSession().getFeatures().getDatapathId()); - // Set request body to main multipart request - multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid); - mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetFlowStatisticsFromFlowTableOutput createResult() { - GetFlowStatisticsFromFlowTableOutputBuilder flowStatsFromFlowTableBuilder = - new GetFlowStatisticsFromFlowTableOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return flowStatsFromFlowTableBuilder.build(); - } - }); - return result; + final Long xid = taskContext.getSession().getNextXid(); + + // Create multipart request body for fetch all the group stats + MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder(); + MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder(); + mprFlowRequestBuilder.setTableId(input.getTableId()); + + if (input.getOutPort() != null) { + mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue()); + } else { + mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY); } - }; - return task; + + if (input.getOutGroup() != null) { + mprFlowRequestBuilder.setOutGroup(input.getOutGroup()); + } else { + mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY); + } + + if (input.getCookie() != null) { + mprFlowRequestBuilder.setCookie(input.getCookie().getValue()); + } else { + mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); + } + + if (input.getCookieMask() != null) { + mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue()); + } else { + mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); + } + + // convert and inject match + MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession() + .getPrimaryConductor().getVersion(), mprFlowRequestBuilder, + taskContext.getSession().getFeatures().getDatapathId()); + + // Set request body to main multipart request + multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build()); + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPFLOW, taskContext, xid); + mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetFlowStatisticsFromFlowTableOutput createResult() { + GetFlowStatisticsFromFlowTableOutputBuilder flowStatsFromFlowTableBuilder = + new GetFlowStatisticsFromFlowTableOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return flowStatsFromFlowTableBuilder.build(); + } + }); + return result; + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input * @param cookie * @return task */ - public static OFRpcTask> - createGetAggregateFlowStatisticsFromFlowTableForAllFlowsTask( - final OFRpcTaskContext taskContext, - final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input,SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + public static OFRpcTask> + createGetAggregateFlowStatisticsFromFlowTableForAllFlowsTask( + final OFRpcTaskContext taskContext, + final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input, SwitchConnectionDistinguisher cookie) { + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() throws Exception { + final SettableFuture> result = SettableFuture.create(); - @Override - public ListenableFuture> call() throws Exception { - final SettableFuture> result = SettableFuture.create(); - final Long xid = taskContext.getSession().getNextXid(); - - // Create multipart request body for fetch all the group stats + + // Create multipart request body for fetch all the group stats MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder(); MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder(); mprAggregateRequestBuilder.setTableId(input.getTableId().getValue()); @@ -1489,54 +1617,59 @@ public abstract class OFRpcTaskFactory { // Set request body to main multipart request multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build()); - MultipartRequestInputBuilder mprInput = + MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext, xid); mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build()); Future> resultFromOFLib = getMessageService() .multipartRequest(mprInput.build(), getCookie()); ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - + Futures.addCallback(resultLib, new ResultCallback(result) { @Override public GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput createResult() { - GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder flowStatsFromFlowTableBuilder = + GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder flowStatsFromFlowTableBuilder = new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); return flowStatsFromFlowTableBuilder.build(); } }); return result; } - }; - return task; + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input * @param cookie * @return task */ - public static OFRpcTask> - createGetAggregateFlowStatisticsFromFlowTableForGivenMatchTask( - final OFRpcTaskContext taskContext, - final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input,SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + public static OFRpcTask> + createGetAggregateFlowStatisticsFromFlowTableForGivenMatchTask( + final OFRpcTaskContext taskContext, + final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input, SwitchConnectionDistinguisher cookie) { + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() throws Exception { + final SettableFuture> result = SettableFuture.create(); - @Override - public ListenableFuture> call() throws Exception { - final SettableFuture> result = SettableFuture.create(); - final Long xid = taskContext.getSession().getNextXid(); - + MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder(); MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder(); mprAggregateRequestBuilder.setTableId(input.getTableId()); mprAggregateRequestBuilder.setOutPort(input.getOutPort().longValue()); - // TODO: repeating code - if (taskContext.getSession().getPrimaryConductor().getVersion() == - OFConstants.OFP_VERSION_1_3) { + // TODO: repeating code + if (taskContext.getSession().getPrimaryConductor().getVersion() == + OFConstants.OFP_VERSION_1_3) { mprAggregateRequestBuilder.setCookie(input.getCookie().getValue()); mprAggregateRequestBuilder.setCookieMask(input.getCookieMask().getValue()); mprAggregateRequestBuilder.setOutGroup(input.getOutGroup()); @@ -1545,9 +1678,9 @@ public abstract class OFRpcTaskFactory { mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE); mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); } - + MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession() - .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder, + .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder, taskContext.getSession().getFeatures().getDatapathId()); FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession() @@ -1555,28 +1688,29 @@ public abstract class OFRpcTaskFactory { // Set request body to main multipart request multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build()); - MultipartRequestInputBuilder mprInput = + MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext, xid); mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build()); Future> resultFromOFLib = getMessageService() .multipartRequest(mprInput.build(), getCookie()); ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - + Futures.addCallback(resultLib, new ResultCallback(result) { @Override public GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput createResult() { - GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder aggregFlowStatsFromFlowTableBuilder = + GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder aggregFlowStatsFromFlowTableBuilder = new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); return aggregFlowStatsFromFlowTableBuilder.build(); } }); return result; } - }; - return task; + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -1584,45 +1718,51 @@ public abstract class OFRpcTaskFactory { * @return task */ public static OFRpcTask> createGetFlowTablesStatisticsTask( - final OFRpcTaskContext taskContext, final GetFlowTablesStatisticsInput input,SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + final OFRpcTaskContext taskContext, final GetFlowTablesStatisticsInput input, SwitchConnectionDistinguisher cookie) { + + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetFlowTablesStatisticsInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() throws Exception { + final SettableFuture> result = SettableFuture.create(); - @Override - public ListenableFuture> call() throws Exception { - final SettableFuture> result = SettableFuture.create(); - final Long xid = taskContext.getSession().getNextXid(); - - // Create multipart request body for fetch all the group stats + + // Create multipart request body for fetch all the group stats MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder(); MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder(); multipartRequestTableBuilder.setEmpty(true); multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build()); // Set request body to main multipart request - MultipartRequestInputBuilder mprInput = + MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPTABLE, taskContext, xid); mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build()); Future> resultFromOFLib = getMessageService() .multipartRequest(mprInput.build(), getCookie()); ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - + Futures.addCallback(resultLib, new ResultCallback(result) { @Override public GetFlowTablesStatisticsOutput createResult() { - GetFlowTablesStatisticsOutputBuilder flowTableStatsBuilder = + GetFlowTablesStatisticsOutputBuilder flowTableStatsBuilder = new GetFlowTablesStatisticsOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); return flowTableStatsBuilder.build(); } }); return result; } - }; - return task; + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -1630,47 +1770,53 @@ public abstract class OFRpcTaskFactory { * @return task */ public static OFRpcTask> createGetAllQueuesStatisticsFromAllPortsTask( - final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromAllPortsInput input,SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromAllPortsInput input, SwitchConnectionDistinguisher cookie) { - @Override - public ListenableFuture> call() throws Exception { - final SettableFuture> result = SettableFuture.create(); - - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder(); - MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder(); - // Select all ports - mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY); - // Select all the ports - mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY); - caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build()); - - // Set request body to main multipart request - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid); - mprInput.setMultipartRequestBody(caseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetAllQueuesStatisticsFromAllPortsOutput createResult() { - GetAllQueuesStatisticsFromAllPortsOutputBuilder allQueueStatsBuilder = - new GetAllQueuesStatisticsFromAllPortsOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return allQueueStatsBuilder.build(); - } - }); - return result; + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetAllQueuesStatisticsFromAllPortsInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() throws Exception { + final SettableFuture> result = SettableFuture.create(); + + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder(); + MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder(); + // Select all ports + mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY); + // Select all the ports + mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY); + caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build()); + + // Set request body to main multipart request + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid); + mprInput.setMultipartRequestBody(caseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetAllQueuesStatisticsFromAllPortsOutput createResult() { + GetAllQueuesStatisticsFromAllPortsOutputBuilder allQueueStatsBuilder = + new GetAllQueuesStatisticsFromAllPortsOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return allQueueStatsBuilder.build(); + } + }); + return result; + } } - }; - return task; + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -1678,49 +1824,55 @@ public abstract class OFRpcTaskFactory { * @return task */ public static OFRpcTask> createGetAllQueuesStatisticsFromGivenPortTask( - final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromGivenPortInput input,SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromGivenPortInput input, SwitchConnectionDistinguisher cookie) { - @Override - public ListenableFuture> call() throws Exception { - final SettableFuture> result = SettableFuture.create(); - - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder(); - MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder(); - // Select all queues - mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY); - // Select specific port - mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId( - OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()), - input.getNodeConnectorId())); - caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build()); - - // Set request body to main multipart request - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid); - mprInput.setMultipartRequestBody(caseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetAllQueuesStatisticsFromGivenPortOutput createResult() { - GetAllQueuesStatisticsFromGivenPortOutputBuilder allQueueStatsBuilder = - new GetAllQueuesStatisticsFromGivenPortOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return allQueueStatsBuilder.build(); - } - }); - return result; + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetAllQueuesStatisticsFromGivenPortInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() throws Exception { + final SettableFuture> result = SettableFuture.create(); + + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder(); + MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder(); + // Select all queues + mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY); + // Select specific port + mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId( + OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()), + input.getNodeConnectorId())); + caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build()); + + // Set request body to main multipart request + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid); + mprInput.setMultipartRequestBody(caseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetAllQueuesStatisticsFromGivenPortOutput createResult() { + GetAllQueuesStatisticsFromGivenPortOutputBuilder allQueueStatsBuilder = + new GetAllQueuesStatisticsFromGivenPortOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return allQueueStatsBuilder.build(); + } + }); + return result; + } } - }; - return task; + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -1728,51 +1880,57 @@ public abstract class OFRpcTaskFactory { * @return task */ public static OFRpcTask> createGetQueueStatisticsFromGivenPortTask( - final OFRpcTaskContext taskContext, final GetQueueStatisticsFromGivenPortInput input,SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { + final OFRpcTaskContext taskContext, final GetQueueStatisticsFromGivenPortInput input, SwitchConnectionDistinguisher cookie) { - @Override - public ListenableFuture> call() throws Exception { - final SettableFuture> result = SettableFuture.create(); - - final Long xid = taskContext.getSession().getNextXid(); - - MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder(); - MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder(); - // Select specific queue - mprQueueBuilder.setQueueId(input.getQueueId().getValue()); - // Select specific port - mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId( - OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()), - input.getNodeConnectorId())); - caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build()); - - // Set request body to main multipart request - MultipartRequestInputBuilder mprInput = - createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid); - mprInput.setMultipartRequestBody(caseBuilder.build()); - Future> resultFromOFLib = getMessageService() - .multipartRequest(mprInput.build(), getCookie()); - ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - - Futures.addCallback(resultLib, new ResultCallback(result) { - @Override - public GetQueueStatisticsFromGivenPortOutput createResult() { - GetQueueStatisticsFromGivenPortOutputBuilder queueStatsFromPortBuilder = - new GetQueueStatisticsFromGivenPortOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); - return queueStatsFromPortBuilder.build(); - } - }); - return result; + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + GetQueueStatisticsFromGivenPortInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() throws Exception { + final SettableFuture> result = SettableFuture.create(); + + final Long xid = taskContext.getSession().getNextXid(); + + MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder(); + MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder(); + // Select specific queue + mprQueueBuilder.setQueueId(input.getQueueId().getValue()); + // Select specific port + mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId( + OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()), + input.getNodeConnectorId())); + caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build()); + + // Set request body to main multipart request + MultipartRequestInputBuilder mprInput = + createMultipartHeader(MultipartType.OFPMPQUEUE, taskContext, xid); + mprInput.setMultipartRequestBody(caseBuilder.build()); + Future> resultFromOFLib = getMessageService() + .multipartRequest(mprInput.build(), getCookie()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public GetQueueStatisticsFromGivenPortOutput createResult() { + GetQueueStatisticsFromGivenPortOutputBuilder queueStatsFromPortBuilder = + new GetQueueStatisticsFromGivenPortOutputBuilder() + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return queueStatsFromPortBuilder.build(); + } + }); + return result; + } } - }; - return task; + + return new OFRpcTaskImpl(taskContext, cookie, input); } - - static MultipartRequestInputBuilder createMultipartHeader(MultipartType multipart, - OFRpcTaskContext taskContext, Long xid) { + + static MultipartRequestInputBuilder createMultipartHeader(MultipartType multipart, + OFRpcTaskContext taskContext, Long xid) { MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder(); mprInput.setType(multipart); mprInput.setVersion(taskContext.getSession().getPrimaryConductor().getVersion()); @@ -1780,9 +1938,9 @@ public abstract class OFRpcTaskFactory { mprInput.setFlags(new MultipartRequestFlags(false)); return mprInput; } - - private static abstract class ResultCallback implements FutureCallback> { - + + private abstract static class ResultCallback implements FutureCallback> { + private SettableFuture> result; /** @@ -1802,14 +1960,14 @@ public abstract class OFRpcTaskFactory { @Override public void onFailure(Throwable t) { result.set(RpcResultBuilder.failed().withWarning( - ErrorType.RPC, - OFConstants.ERROR_TAG_TIMEOUT, - "something wrong happened", - OFConstants.APPLICATION_TAG, - "", t).build()); + ErrorType.RPC, + OFConstants.ERROR_TAG_TIMEOUT, + "something wrong happened", + OFConstants.APPLICATION_TAG, + "", t).build()); } } - + /** * @param taskContext * @param input @@ -1819,33 +1977,37 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createUpdatePortTask( final OFRpcTaskContext taskContext, final UpdatePortInput input, final SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + UpdatePortInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { ListenableFuture> result = SettableFuture.create(); final Long xid = taskContext.getSession().getNextXid(); Port inputPort = input.getUpdatedPort().getPort().getPort().get(0); - - PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort, - taskContext.getSession().getPrimaryConductor().getVersion()); - PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput); - mdInput.setXid(xid); + PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort, + taskContext.getSession().getPrimaryConductor().getVersion()); - Future> resultFromOFLib = getMessageService() - .portMod(mdInput.build(), cookie); - result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); + PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput); + mdInput.setXid(xid); + + Future> resultFromOFLib = getMessageService() + .portMod(mdInput.build(), cookie); + result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); return result; } - }; - - return task; - + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - + /** * @param taskContext * @param input @@ -1855,44 +2017,87 @@ public abstract class OFRpcTaskFactory { public static OFRpcTask> createUpdateTableTask( final OFRpcTaskContext taskContext, final UpdateTableInput input, final SwitchConnectionDistinguisher cookie) { - OFRpcTask> task = - new OFRpcTask>(taskContext, cookie, input) { - + + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + UpdateTableInput input) { + super(taskContext, cookie, input); + } + @Override public ListenableFuture> call() { final SettableFuture> result = SettableFuture.create(); - + final Long xid = taskContext.getSession().getNextXid(); - + MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder(); MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder(); List ofTableFeatureList = TableFeaturesConvertor .toTableFeaturesRequest(input.getUpdatedTable()); requestBuilder.setTableFeatures(ofTableFeatureList); caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build()); - + // Set request body to main multipart request - MultipartRequestInputBuilder mprInput = + MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPTABLEFEATURES, taskContext, xid); mprInput.setMultipartRequestBody(caseBuilder.build()); - + Future> resultFromOFLib = getMessageService() .multipartRequest(mprInput.build(), getCookie()); ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib); - + Futures.addCallback(resultLib, new ResultCallback(result) { @Override public UpdateTableOutput createResult() { - UpdateTableOutputBuilder queueStatsFromPortBuilder = + UpdateTableOutputBuilder queueStatsFromPortBuilder = new UpdateTableOutputBuilder() - .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + .setTransactionId(new TransactionId(BigInteger.valueOf(xid))); return queueStatsFromPortBuilder.build(); } }); return result; } - }; - return task; + } + + return new OFRpcTaskImpl(taskContext, cookie, input); + } + + public static OFRpcTask> createSetNodeConfigTask(final OFRpcTaskContext taskContext, + final SetConfigInput input, + final SwitchConnectionDistinguisher cookie) { + class OFRpcTaskImpl extends OFRpcTask> { + + public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, + SetConfigInput input) { + super(taskContext, cookie, input); + } + + @Override + public ListenableFuture> call() throws Exception { + + final SettableFuture> result = SettableFuture.create(); + final Long xid = taskContext.getSession().getNextXid(); + + SetConfigInputBuilder builder = new SetConfigInputBuilder(); + SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag()); + builder.setXid(xid); + builder.setFlags(flag); + builder.setMissSendLen(input.getMissSearchLength()); + builder.setVersion(getVersion()); + ListenableFuture> resultLib = JdkFutureAdapters.listenInPoolThread(taskContext.getSession().getPrimaryConductor().getConnectionAdapter().setConfig(builder.build())); + Futures.addCallback(resultLib, new ResultCallback(result) { + @Override + public SetConfigOutput createResult() { + SetConfigOutputBuilder setConfigOutputBuilder = new SetConfigOutputBuilder(); + setConfigOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(xid))); + return setConfigOutputBuilder.build(); + } + }); + return result; + } + } + + return new OFRpcTaskImpl(taskContext, cookie, input); } - }