+
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> createRemoveFlowTask(
+ OFRpcTaskContext taskContext, RemoveFlowInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> task =
+ new OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<UpdateFlowOutput>> call() {
+ ListenableFuture<RpcResult<UpdateFlowOutput>> result = SettableFuture.create();
+
+ Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), getInput().isBarrier(), getCookie());
+ if (!barrierErrors.isEmpty()) {
+ OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateFlowOutput>>) result), barrierErrors);
+ } else {
+ // Convert the AddFlowInput to FlowModInput
+ FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(getInput(),
+ getVersion(), getSession().getFeatures().getDatapathId());
+ final Long xId = getSession().getNextXid();
+ ofFlowModInput.setXid(xId);
+
+ Future<RpcResult<UpdateFlowOutput>> resultFromOFLib =
+ getMessageService().flowMod(ofFlowModInput.build(), getCookie());
+ result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ OFRpcTaskUtil.hookFutureNotification(this, result,
+ getRpcNotificationProviderService(), createFlowRemovedNotification(xId, getInput()));
+ }
+
+ return result;
+ }
+ };
+
+ return task;
+ }
+
+ /**
+ * @param xId
+ * @return
+ */
+ protected static NotificationComposer<FlowRemoved> createFlowRemovedNotification(
+ final Long xId, final RemoveFlowInput input) {
+ return new NotificationComposer<FlowRemoved>() {
+ @Override
+ public FlowRemoved compose() {
+ FlowRemovedBuilder removedFlow = new FlowRemovedBuilder((Flow) input);
+ removedFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+ removedFlow.setFlowRef(input.getFlowRef());
+ return removedFlow.build();
+ }
+ };
+ }
+
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> createRemoveGroupTask(
+ final OFRpcTaskContext taskContext, RemoveGroupInput input,
+ final SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> task =
+ new OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
+ ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();
+
+ Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), getInput().isBarrier(), getCookie());
+ if (!barrierErrors.isEmpty()) {
+ OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateGroupOutput>>) result), barrierErrors);
+ } else {
+ // Convert the AddGroupInput to GroupModInput
+ GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(),
+ getVersion(), getSession().getFeatures().getDatapathId());
+ final Long xId = getSession().getNextXid();
+ ofGroupModInput.setXid(xId);
+
+ Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
+ .groupMod(ofGroupModInput.build(), getCookie());
+ result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ OFRpcTaskUtil.hookFutureNotification(this, result,
+ getRpcNotificationProviderService(), createGroupRemovedNotification(xId, getInput()));
+ }
+
+ return result;
+ }
+ };
+
+ return task;
+ }
+
+ /**
+ * @param xId
+ * @param input
+ * @return
+ */
+ protected static NotificationComposer<GroupRemoved> createGroupRemovedNotification(
+ final Long xId, final RemoveGroupInput input) {
+ return new NotificationComposer<GroupRemoved>() {
+ @Override
+ public GroupRemoved compose() {
+ GroupRemovedBuilder removedGroup = new GroupRemovedBuilder((Group) input);
+ removedGroup.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+ removedGroup.setGroupRef(input.getGroupRef());
+ return removedGroup.build();
+ }
+ };
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> createRemoveMeterTask(
+ OFRpcTaskContext taskContext, RemoveMeterInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> task =
+ new OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
+ ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();
+
+ Collection<RpcError> barrierErrors = OFRpcTaskUtil.manageBarrier(getTaskContext(), getInput().isBarrier(), getCookie());
+ if (!barrierErrors.isEmpty()) {
+ OFRpcTaskUtil.wrapBarrierErrors(((SettableFuture<RpcResult<UpdateMeterOutput>>) result), barrierErrors);
+ } else {
+ // Convert the AddGroupInput to GroupModInput
+ MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
+ final Long xId = getSession().getNextXid();
+ ofMeterModInput.setXid(xId);
+
+ Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
+ .meterMod(ofMeterModInput.build(), getCookie());
+ result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ OFRpcTaskUtil.hookFutureNotification(this, result,
+ getRpcNotificationProviderService(), createMeterRemovedNotification(xId, getInput()));
+ }
+
+ return result;
+ }
+ };
+
+ return task;
+
+ }
+
+ /**
+ * @param xId
+ * @param input
+ * @return
+ */
+ protected static NotificationComposer<MeterRemoved> createMeterRemovedNotification(
+ final Long xId, final RemoveMeterInput input) {
+ return new NotificationComposer<MeterRemoved>() {
+ @Override
+ public MeterRemoved compose() {
+ MeterRemovedBuilder meterRemoved = new MeterRemovedBuilder((Meter) input);
+ meterRemoved.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
+ meterRemoved.setMeterRef(input.getMeterRef());
+ return meterRemoved.build();
+ }
+ };
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> createGetAllGroupStatisticsTask(
+ final OFRpcTaskContext taskContext, GetAllGroupStatisticsInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> task =
+ new OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetAllGroupStatisticsOutput>> call() {
+ final SettableFuture<RpcResult<GetAllGroupStatisticsOutput>> result = SettableFuture.create();
+
+ if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
+ Collection<RpcError> errors = Collections.emptyList();
+ RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true,
+ new GetAllGroupStatisticsOutputBuilder().build(), errors);
+
+ return Futures.immediateFuture(rpcResult);
+ } 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
+ 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())));
+ caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
+
+ // Create multipart request header
+ MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPGROUP,
+ taskContext);
+
+ // Set request body to main multipart request
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+
+ // Send the request, no cookies associated, use any connection
+
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetAllGroupStatisticsOutput>(result) {
+ @Override
+ public GetAllGroupStatisticsOutput createResult() {
+ GetAllGroupStatisticsOutputBuilder groupStatBuilder = new GetAllGroupStatisticsOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return groupStatBuilder.build();
+ }
+ });
+
+ return result;
+ }
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> createGetGroupDescriptionTask(
+ final OFRpcTaskContext taskContext, GetGroupDescriptionInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> task =
+ new OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetGroupDescriptionOutput>> call()
+ throws Exception {
+ final SettableFuture<RpcResult<GetGroupDescriptionOutput>> result = SettableFuture.create();
+
+ if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
+ Collection<RpcError> errors = Collections.emptyList();
+ RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true,
+ new GetGroupDescriptionOutputBuilder().build(), errors);
+ return Futures.immediateFuture(rpcResult);
+ } else {
+ final Long xid = taskContext.getSession().getNextXid();
+
+ MultipartRequestGroupDescCaseBuilder mprGroupDescCaseBuild =
+ new MultipartRequestGroupDescCaseBuilder();
+ MultipartRequestInputBuilder mprInput =
+ createMultipartHeader(MultipartType.OFPMPGROUPDESC, taskContext);
+ mprInput.setMultipartRequestBody(mprGroupDescCaseBuild.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetGroupDescriptionOutput>(result) {
+ @Override
+ public GetGroupDescriptionOutput createResult() {
+ GetGroupDescriptionOutputBuilder groupStatBuilder = new GetGroupDescriptionOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return groupStatBuilder.build();
+ }
+ });
+ return result;
+ }
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> createGetGroupFeaturesTask(
+ final OFRpcTaskContext taskContext, GetGroupFeaturesInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> task =
+ new OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetGroupFeaturesOutput>> call()
+ throws Exception {
+ final SettableFuture<RpcResult<GetGroupFeaturesOutput>> result = SettableFuture.create();
+
+ if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
+ Collection<RpcError> errors = Collections.emptyList();
+ RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true,
+ new GetGroupFeaturesOutputBuilder().build(), errors);
+ return Futures.immediateFuture(rpcResult);
+ } else {
+ final Long xid = taskContext.getSession().getNextXid();
+
+ MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild =
+ new MultipartRequestGroupFeaturesCaseBuilder();
+ MultipartRequestInputBuilder mprInput =
+ createMultipartHeader(MultipartType.OFPMPGROUPFEATURES, taskContext);
+ mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetGroupFeaturesOutput>(result) {
+ @Override
+ public GetGroupFeaturesOutput createResult() {
+ GetGroupFeaturesOutputBuilder groupFeatureBuilder = new GetGroupFeaturesOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return groupFeatureBuilder.build();
+ }
+ });
+ return result;
+ }
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> createGetGroupStatisticsTask(
+ final OFRpcTaskContext taskContext, final GetGroupStatisticsInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> task =
+ new OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetGroupStatisticsOutput>> call()
+ throws Exception {
+ final SettableFuture<RpcResult<GetGroupStatisticsOutput>> result = SettableFuture.create();
+
+ if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
+ Collection<RpcError> errors = Collections.emptyList();
+ RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true,
+ new GetGroupStatisticsOutputBuilder().build(), errors);
+ 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);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetGroupStatisticsOutput>(result) {
+ @Override
+ public GetGroupStatisticsOutput createResult() {
+ GetGroupStatisticsOutputBuilder groupStatisticsBuilder =
+ new GetGroupStatisticsOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return groupStatisticsBuilder.build();
+ }
+ });
+ return result;
+ }
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> createGetAllMeterConfigStatisticsTask(
+ final OFRpcTaskContext taskContext, final GetAllMeterConfigStatisticsInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> task =
+ new OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> call()
+ throws Exception {
+ final SettableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> result = SettableFuture.create();
+
+ if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
+ Collection<RpcError> errors = Collections.emptyList();
+ RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true,
+ new GetAllMeterConfigStatisticsOutputBuilder().build(), errors);
+ 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);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetAllMeterConfigStatisticsOutput>(result) {
+ @Override
+ public GetAllMeterConfigStatisticsOutput createResult() {
+ GetAllMeterConfigStatisticsOutputBuilder allMeterConfStatBuilder =
+ new GetAllMeterConfigStatisticsOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return allMeterConfStatBuilder.build();
+ }
+ });
+ return result;
+ }
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> createGetAllMeterStatisticsTask(
+ final OFRpcTaskContext taskContext, final GetAllMeterStatisticsInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> task =
+ new OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>> call()
+ throws Exception {
+ final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = SettableFuture.create();
+
+ if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
+ Collection<RpcError> errors = Collections.emptyList();
+ RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true,
+ new GetAllMeterStatisticsOutputBuilder().build(), errors);
+ 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);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetAllMeterStatisticsOutput>(result) {
+ @Override
+ public GetAllMeterStatisticsOutput createResult() {
+ GetAllMeterStatisticsOutputBuilder allMeterStatBuilder =
+ new GetAllMeterStatisticsOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return allMeterStatBuilder.build();
+ }
+ });
+ return result;
+ }
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> createGetMeterFeaturesTask(
+ final OFRpcTaskContext taskContext, final GetMeterFeaturesInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> task =
+ new OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetMeterFeaturesOutput>> call()
+ throws Exception {
+ final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = SettableFuture.create();
+
+ if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
+ Collection<RpcError> errors = Collections.emptyList();
+ RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true,
+ new GetMeterFeaturesOutputBuilder().build(), errors);
+ return Futures.immediateFuture(rpcResult);
+ } else {
+ final Long xid = taskContext.getSession().getNextXid();
+
+ MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild =
+ new MultipartRequestMeterFeaturesCaseBuilder();
+
+ MultipartRequestInputBuilder mprInput =
+ createMultipartHeader(MultipartType.OFPMPMETERFEATURES, taskContext);
+ mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetMeterFeaturesOutput>(result) {
+ @Override
+ public GetMeterFeaturesOutput createResult() {
+ GetMeterFeaturesOutputBuilder meterFeaturesBuilder =
+ new GetMeterFeaturesOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return meterFeaturesBuilder.build();
+ }
+ });
+ return result;
+ }
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> createGetMeterStatisticsTask(
+ final OFRpcTaskContext taskContext, final GetMeterStatisticsInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> task =
+ new OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetMeterStatisticsOutput>> call()
+ throws Exception {
+ final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = SettableFuture.create();
+
+ if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
+ Collection<RpcError> errors = Collections.emptyList();
+ RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true,
+ new GetMeterStatisticsOutputBuilder().build(), errors);
+ 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);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetMeterStatisticsOutput>(result) {
+ @Override
+ public GetMeterStatisticsOutput createResult() {
+ GetMeterStatisticsOutputBuilder meterStatBuilder =
+ new GetMeterStatisticsOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return meterStatBuilder.build();
+ }
+ });
+ return result;
+ }
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>>
+ createGetAllNodeConnectorsStatisticsTask(
+ final OFRpcTaskContext taskContext, final GetAllNodeConnectorsStatisticsInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>> task =
+ new OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> call()
+ throws Exception {
+ final SettableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> 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);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetAllNodeConnectorsStatisticsOutput>(result) {
+ @Override
+ public GetAllNodeConnectorsStatisticsOutput createResult() {
+ GetAllNodeConnectorsStatisticsOutputBuilder allNodeConnectorStatBuilder =
+ new GetAllNodeConnectorsStatisticsOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return allNodeConnectorStatBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>>
+ createGetNodeConnectorStatisticsTask(
+ final OFRpcTaskContext taskContext, final GetNodeConnectorStatisticsInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>> task =
+ new OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> call()
+ throws Exception {
+ final SettableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> 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);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetNodeConnectorStatisticsOutput>(result) {
+ @Override
+ public GetNodeConnectorStatisticsOutput createResult() {
+ GetNodeConnectorStatisticsOutputBuilder allNodeConnectorStatBuilder =
+ new GetNodeConnectorStatisticsOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return allNodeConnectorStatBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>>
+ createGetAllFlowStatisticsFromFlowTableTask(
+ final OFRpcTaskContext taskContext,
+ final GetAllFlowStatisticsFromFlowTableInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> task =
+ new OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> call() throws Exception {
+ final SettableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> 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);
+ mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetAllFlowStatisticsFromFlowTableOutput>(result) {
+ @Override
+ public GetAllFlowStatisticsFromFlowTableOutput createResult() {
+ GetAllFlowStatisticsFromFlowTableOutputBuilder allFlowStatsFromFlowTableBuilder =
+ new GetAllFlowStatisticsFromFlowTableOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return allFlowStatsFromFlowTableBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput, RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>>
+ createGetAllFlowsStatisticsFromAllFlowTablesTask(
+ final OFRpcTaskContext taskContext,
+ final GetAllFlowsStatisticsFromAllFlowTablesInput input,
+ SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput,
+ RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> task =
+ new OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput,
+ RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> call() throws Exception {
+ final SettableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> 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);
+ multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
+ mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetAllFlowsStatisticsFromAllFlowTablesOutput>(result) {
+ @Override
+ public GetAllFlowsStatisticsFromAllFlowTablesOutput createResult() {
+ GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder allFlowStatsFromAllFlowTableBuilder =
+ new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return allFlowStatsFromAllFlowTableBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>>
+ createGetFlowStatisticsFromFlowTableTask(
+ final OFRpcTaskContext taskContext,
+ final GetFlowStatisticsFromFlowTableInput input,SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>> task =
+ new OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> call() throws Exception {
+ final SettableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> 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);
+ mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetFlowStatisticsFromFlowTableOutput>(result) {
+ @Override
+ public GetFlowStatisticsFromFlowTableOutput createResult() {
+ GetFlowStatisticsFromFlowTableOutputBuilder flowStatsFromFlowTableBuilder =
+ new GetFlowStatisticsFromFlowTableOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return flowStatsFromFlowTableBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>>
+ createGetAggregateFlowStatisticsFromFlowTableForAllFlowsTask(
+ final OFRpcTaskContext taskContext,
+ final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input,SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> task =
+ new OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> call() throws Exception {
+ final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> result = SettableFuture.create();
+
+ final Long xid = taskContext.getSession().getNextXid();
+
+ // Create multipart request body for fetch all the group stats
+ MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
+ MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
+ mprAggregateRequestBuilder.setTableId(input.getTableId().getValue());
+ mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
+ mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
+ mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
+ mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
+
+ FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
+ .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
+
+ // Set request body to main multipart request
+ multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
+ MultipartRequestInputBuilder mprInput =
+ createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext);
+ mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>(result) {
+ @Override
+ public GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput createResult() {
+ GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder flowStatsFromFlowTableBuilder =
+ new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return flowStatsFromFlowTableBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>
+ createGetAggregateFlowStatisticsFromFlowTableForGivenMatchTask(
+ final OFRpcTaskContext taskContext,
+ final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input,SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> task =
+ new OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> call() throws Exception {
+ final SettableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> 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) {
+ mprAggregateRequestBuilder.setCookie(input.getCookie().getValue());
+ mprAggregateRequestBuilder.setCookieMask(input.getCookieMask().getValue());
+ mprAggregateRequestBuilder.setOutGroup(input.getOutGroup());
+ } else {
+ mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
+ mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
+ mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
+ }
+
+ MatchReactor.getInstance().convert(input.getMatch(), taskContext.getSession()
+ .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder,
+ taskContext.getSession().getFeatures().getDatapathId());
+
+ FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession()
+ .getPrimaryConductor().getVersion(), mprAggregateRequestBuilder);
+
+ // Set request body to main multipart request
+ multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
+ MultipartRequestInputBuilder mprInput =
+ createMultipartHeader(MultipartType.OFPMPAGGREGATE, taskContext);
+ mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>(result) {
+ @Override
+ public GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput createResult() {
+ GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder aggregFlowStatsFromFlowTableBuilder =
+ new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return aggregFlowStatsFromFlowTableBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> createGetFlowTablesStatisticsTask(
+ final OFRpcTaskContext taskContext, final GetFlowTablesStatisticsInput input,SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> task =
+ new OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> call() throws Exception {
+ final SettableFuture<RpcResult<GetFlowTablesStatisticsOutput>> result = SettableFuture.create();
+
+ final Long xid = taskContext.getSession().getNextXid();
+
+ // 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 =
+ createMultipartHeader(MultipartType.OFPMPTABLE, taskContext);
+ mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetFlowTablesStatisticsOutput>(result) {
+ @Override
+ public GetFlowTablesStatisticsOutput createResult() {
+ GetFlowTablesStatisticsOutputBuilder flowTableStatsBuilder =
+ new GetFlowTablesStatisticsOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return flowTableStatsBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> createGetAllQueuesStatisticsFromAllPortsTask(
+ final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromAllPortsInput input,SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> task =
+ new OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> call() throws Exception {
+ final SettableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> 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);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetAllQueuesStatisticsFromAllPortsOutput>(result) {
+ @Override
+ public GetAllQueuesStatisticsFromAllPortsOutput createResult() {
+ GetAllQueuesStatisticsFromAllPortsOutputBuilder allQueueStatsBuilder =
+ new GetAllQueuesStatisticsFromAllPortsOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return allQueueStatsBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> createGetAllQueuesStatisticsFromGivenPortTask(
+ final OFRpcTaskContext taskContext, final GetAllQueuesStatisticsFromGivenPortInput input,SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> task =
+ new OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> call() throws Exception {
+ final SettableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> 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);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetAllQueuesStatisticsFromGivenPortOutput>(result) {
+ @Override
+ public GetAllQueuesStatisticsFromGivenPortOutput createResult() {
+ GetAllQueuesStatisticsFromGivenPortOutputBuilder allQueueStatsBuilder =
+ new GetAllQueuesStatisticsFromGivenPortOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return allQueueStatsBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> createGetQueueStatisticsFromGivenPortTask(
+ final OFRpcTaskContext taskContext, final GetQueueStatisticsFromGivenPortInput input,SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> task =
+ new OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> call() throws Exception {
+ final SettableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> 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);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<GetQueueStatisticsFromGivenPortOutput>(result) {
+ @Override
+ public GetQueueStatisticsFromGivenPortOutput createResult() {
+ GetQueueStatisticsFromGivenPortOutputBuilder queueStatsFromPortBuilder =
+ new GetQueueStatisticsFromGivenPortOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return queueStatsFromPortBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+
+ static MultipartRequestInputBuilder createMultipartHeader(MultipartType multipart,
+ OFRpcTaskContext taskContext) {
+ MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
+ mprInput.setType(multipart);
+ mprInput.setVersion(taskContext.getSession().getPrimaryConductor().getVersion());
+ mprInput.setXid(taskContext.getSession().getNextXid());
+ mprInput.setFlags(new MultipartRequestFlags(false));
+ return mprInput;
+ }
+
+ private static abstract class ResultCallback<T> implements FutureCallback<RpcResult<Void>> {
+
+ private SettableFuture<RpcResult<T>> result;
+
+ /**
+ * @param result
+ */
+ public ResultCallback(SettableFuture<RpcResult<T>> result) {
+ this.result = result;
+ }
+
+ public abstract T createResult();
+
+ @Override
+ public void onSuccess(RpcResult<Void> resultArg) {
+ Collection<RpcError> errors = Collections.emptyList();
+ result.set(Rpcs.getRpcResult(true, createResult(), errors));
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ result.set(Rpcs.<T>getRpcResult(false,
+ Collections.singletonList(RpcErrors.getRpcError(OFConstants.APPLICATION_TAG,
+ OFConstants.ERROR_TAG_TIMEOUT,
+ "something wrong happened", ErrorSeverity.WARNING, "",
+ ErrorType.RPC, t))));
+ }
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> createUpdatePortTask(
+ final OFRpcTaskContext taskContext, final UpdatePortInput input,
+ final SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> task =
+ new OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<UpdatePortOutput>> call() {
+ ListenableFuture<RpcResult<UpdatePortOutput>> 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);
+
+ Future<RpcResult<UpdatePortOutput>> resultFromOFLib = getMessageService()
+ .portMod(mdInput.build(), cookie);
+ result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ return result;
+ }
+ };
+
+ return task;
+
+ }
+
+ /**
+ * @param taskContext
+ * @param input
+ * @param cookie
+ * @return task
+ */
+ public static OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> createUpdateTableTask(
+ final OFRpcTaskContext taskContext, final UpdateTableInput input,
+ final SwitchConnectionDistinguisher cookie) {
+ OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> task =
+ new OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>>(taskContext, cookie, input) {
+
+ @Override
+ public ListenableFuture<RpcResult<UpdateTableOutput>> call() {
+ final SettableFuture<RpcResult<UpdateTableOutput>> result = SettableFuture.create();
+
+ final Long xid = taskContext.getSession().getNextXid();
+
+ MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
+ MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
+ List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor
+ .toTableFeaturesRequest(input.getUpdatedTable());
+ requestBuilder.setTableFeatures(ofTableFeatureList);
+ caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());
+
+ // Set request body to main multipart request
+ MultipartRequestInputBuilder mprInput =
+ createMultipartHeader(MultipartType.OFPMPTABLEFEATURES, taskContext);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+
+ Future<RpcResult<Void>> resultFromOFLib = getMessageService()
+ .multipartRequest(mprInput.build(), getCookie());
+ ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
+
+ Futures.addCallback(resultLib, new ResultCallback<UpdateTableOutput>(result) {
+ @Override
+ public UpdateTableOutput createResult() {
+ UpdateTableOutputBuilder queueStatsFromPortBuilder =
+ new UpdateTableOutputBuilder()
+ .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
+ return queueStatsFromPortBuilder.build();
+ }
+ });
+ return result;
+ }
+ };
+ return task;
+ }
+