4b57aac794c2557a53778ba3dfe615fc3bcb65f1
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / ModelDrivenSwitchImpl.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.openflow.md.core.sal;
9
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Collections;
14 import java.util.List;
15 import java.util.concurrent.Future;
16 import java.util.concurrent.TimeUnit;
17
18 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
19 import org.opendaylight.controller.sal.common.util.Rpcs;
20 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
21 import org.opendaylight.openflowplugin.openflow.md.OFConstants;
22 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
25 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
26 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor;
27 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
28 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
29 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
30 import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
31 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
32 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
33 import org.opendaylight.openflowplugin.openflow.md.core.session.TransactionKey;
34 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
35 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAddedBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemovedBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdatedBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAddedBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemovedBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdatedBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCaseBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.MultipartRequestTableFeaturesBuilder;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutputBuilder;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutputBuilder;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutputBuilder;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutputBuilder;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutputBuilder;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
177 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
178 import org.opendaylight.yangtools.yang.common.RpcError;
179 import org.opendaylight.yangtools.yang.common.RpcResult;
180 import org.slf4j.Logger;
181
182 import com.google.common.base.Objects;
183 import com.google.common.util.concurrent.Futures;
184 import com.google.common.util.concurrent.JdkFutureAdapters;
185
186 /**
187  * RPC implementation of MD-switch
188  */
189 public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
190
191     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(ModelDrivenSwitchImpl.class);
192     private final NodeId nodeId;
193     private final IMessageDispatchService messageService;
194     private short version = 0;
195     private final SessionContext session;
196     NotificationProviderService rpcNotificationProviderService;
197     private OFRpcTaskHelper rpcTaskHelper;
198     
199     // TODO:read timeout from configSubsystem
200     protected long maxTimeout = 1000;
201     protected TimeUnit maxTimeoutUnit = TimeUnit.MILLISECONDS;
202     
203     protected ModelDrivenSwitchImpl(final NodeId nodeId, final InstanceIdentifier<Node> identifier, final SessionContext context) {
204         super(identifier, context);
205         this.nodeId = nodeId;
206         messageService = sessionContext.getMessageDispatchService();
207         version = context.getPrimaryConductor().getVersion();
208         this.session = context;
209         rpcNotificationProviderService = OFSessionUtil.getSessionManager().getNotificationProviderService();
210         rpcTaskHelper = new OFRpcTaskHelper(messageService, context, rpcNotificationProviderService);
211     }
212
213     @Override
214     public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
215         LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
216         // use primary connection
217         SwitchConnectionDistinguisher cookie = null;
218         
219         OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> task = 
220                 OFRpcTaskFactory.createAddFlowTask(maxTimeout, maxTimeoutUnit, rpcTaskHelper);
221         rpcTaskHelper.initTask(task, input, cookie);
222         OFSessionUtil.getSessionManager().getRpcPool().submit(task);
223         
224         return Futures.transform(JdkFutureAdapters.listenInPoolThread(task.getResult()), 
225                 OFRpcFutureResultTransformFactory.createForAddFlowOutput());
226     }
227
228
229     @Override
230     public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
231         LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
232         Long xId = null;
233
234         // use primary connection
235         SwitchConnectionDistinguisher cookie = null;
236         
237         if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
238             xId = session.getNextXid();
239             BarrierInputBuilder barrierInput = new BarrierInputBuilder();
240             barrierInput.setVersion(version);
241             barrierInput.setXid(xId);
242             @SuppressWarnings("unused")
243             Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
244         }
245
246         // Convert the AddGroupInput to GroupModInput
247         GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input, version, this.getSessionContext()
248                 .getFeatures().getDatapathId());
249         xId = session.getNextXid();
250         ofGroupModInput.setXid(xId);
251
252         if (null != rpcNotificationProviderService) {
253             GroupAddedBuilder groupMod = new GroupAddedBuilder(
254                     (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group) input);
255             groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
256             groupMod.setGroupRef(input.getGroupRef());
257             rpcNotificationProviderService.publish(groupMod.build());
258         }
259
260         Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie);
261         RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null;
262
263         try {
264             rpcResultFromOFLib = resultFromOFLib.get();
265         } catch (Exception ex) {
266             LOG.error(" Error while getting result for AddGroup RPC" + ex.getMessage());
267         }
268
269         UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult();
270
271         AddGroupOutputBuilder addGroupOutput = new AddGroupOutputBuilder();
272         addGroupOutput.setTransactionId(updateGroupOutput.getTransactionId());
273         AddGroupOutput result = addGroupOutput.build();
274
275         Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
276         RpcResult<AddGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
277
278         LOG.debug("Returning the Add Group RPC result to MD-SAL");
279         return Futures.immediateFuture(rpcResult);
280     }
281
282     @Override
283     public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
284         LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
285         Long xId = null;
286         // For Meter provisioning, the SwitchConnectionDistinguisher is set to
287         // null so
288         // the request can be routed through any connection to the switch
289
290         SwitchConnectionDistinguisher cookie = null;
291         if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
292             xId = session.getNextXid();
293             BarrierInputBuilder barrierInput = new BarrierInputBuilder();
294             barrierInput.setVersion(version);
295             barrierInput.setXid(xId);
296             @SuppressWarnings("unused")
297             Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
298         }
299
300         // Convert the AddMeterInput to MeterModInput
301         MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
302         xId = session.getNextXid();
303         ofMeterModInput.setXid(xId);
304
305         if (null != rpcNotificationProviderService) {
306             MeterAddedBuilder meterMod = new MeterAddedBuilder(
307                     (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter) input);
308             meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
309             meterMod.setMeterRef(input.getMeterRef());
310             rpcNotificationProviderService.publish(meterMod.build());
311         }
312
313         Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie);
314
315         RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null;
316
317         try {
318             rpcResultFromOFLib = resultFromOFLib.get();
319         } catch (Exception ex) {
320             LOG.error(" Error while getting result for AddMeter RPC" + ex.getMessage());
321         }
322
323         UpdateMeterOutput updateMeterOutput = rpcResultFromOFLib.getResult();
324
325         AddMeterOutputBuilder addMeterOutput = new AddMeterOutputBuilder();
326         addMeterOutput.setTransactionId(updateMeterOutput.getTransactionId());
327         AddMeterOutput result = addMeterOutput.build();
328
329         Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
330         RpcResult<AddMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
331
332         LOG.debug("Returning the Add Meter RPC result to MD-SAL");
333         return Futures.immediateFuture(rpcResult);
334     }
335
336     @Override
337     public Future<RpcResult<RemoveFlowOutput>> removeFlow(final RemoveFlowInput input) {
338         LOG.debug("Calling the removeFlow RPC method on MessageDispatchService");
339         Long xId = null;
340         // For Flow provisioning, the SwitchConnectionDistinguisher is set to
341         // null so
342         // the request can be routed through any connection to the switch
343
344         SwitchConnectionDistinguisher cookie = null;
345         if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
346             BarrierInputBuilder barrierInput = new BarrierInputBuilder();
347             xId = session.getNextXid();
348             barrierInput.setXid(xId);
349             barrierInput.setVersion(version);
350             @SuppressWarnings("unused")
351             Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
352         }
353
354         // Convert the RemoveFlowInput to FlowModInput
355         FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(input, version, this.getSessionContext()
356                 .getFeatures().getDatapathId());
357         xId = session.getNextXid();
358         ofFlowModInput.setXid(xId);
359
360         if (null != rpcNotificationProviderService) {
361             FlowRemovedBuilder removeFlow = new FlowRemovedBuilder(
362                     (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) input);
363             removeFlow.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
364             removeFlow.setFlowRef(input.getFlowRef());
365             rpcNotificationProviderService.publish(removeFlow.build());
366         }
367
368         Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = messageService.flowMod(ofFlowModInput.build(), cookie);
369
370         RpcResult<UpdateFlowOutput> rpcResultFromOFLib = null;
371
372         try {
373             rpcResultFromOFLib = resultFromOFLib.get();
374         } catch (Exception ex) {
375             LOG.error(" Error while getting result for remove Flow RPC" + ex.getMessage());
376         }
377
378         UpdateFlowOutput updateFlowOutput = rpcResultFromOFLib.getResult();
379
380         RemoveFlowOutputBuilder removeFlowOutput = new RemoveFlowOutputBuilder();
381         removeFlowOutput.setTransactionId(updateFlowOutput.getTransactionId());
382         RemoveFlowOutput result = removeFlowOutput.build();
383
384         Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
385         RpcResult<RemoveFlowOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
386
387         LOG.debug("Returning the Remove Flow RPC result to MD-SAL");
388         return Futures.immediateFuture(rpcResult);
389     }
390
391     @Override
392     public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
393         LOG.debug("Calling the Remove Group RPC method on MessageDispatchService");
394         Long xId = null;
395
396         // For Flow provisioning, the SwitchConnectionDistinguisher is set to
397         // null so
398         // the request can be routed through any connection to the switch
399
400         SwitchConnectionDistinguisher cookie = null;
401         if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
402             xId = session.getNextXid();
403             BarrierInputBuilder barrierInput = new BarrierInputBuilder();
404             barrierInput.setVersion(version);
405             barrierInput.setXid(xId);
406             @SuppressWarnings("unused")
407             Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
408         }
409
410         // Convert the RemoveGroupInput to GroupModInput
411         GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input, version, this.getSessionContext()
412                 .getFeatures().getDatapathId());
413         xId = session.getNextXid();
414         ofGroupModInput.setXid(xId);
415
416         if (null != rpcNotificationProviderService) {
417             GroupRemovedBuilder groupMod = new GroupRemovedBuilder(
418                     (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group) input);
419             groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
420             groupMod.setGroupRef(input.getGroupRef());
421             rpcNotificationProviderService.publish(groupMod.build());
422         }
423
424         Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie);
425
426         RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null;
427
428         try {
429             rpcResultFromOFLib = resultFromOFLib.get();
430         } catch (Exception ex) {
431             LOG.error(" Error while getting result for RemoveGroup RPC" + ex.getMessage());
432         }
433
434         UpdateGroupOutput updateGroupOutput = rpcResultFromOFLib.getResult();
435
436         RemoveGroupOutputBuilder removeGroupOutput = new RemoveGroupOutputBuilder();
437         removeGroupOutput.setTransactionId(updateGroupOutput.getTransactionId());
438         RemoveGroupOutput result = removeGroupOutput.build();
439
440         Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
441         RpcResult<RemoveGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
442
443         LOG.debug("Returning the Remove Group RPC result to MD-SAL");
444         return Futures.immediateFuture(rpcResult);
445     }
446
447     @Override
448     public Future<RpcResult<RemoveMeterOutput>> removeMeter(final RemoveMeterInput input) {
449         LOG.debug("Calling the Remove MeterMod RPC method on MessageDispatchService");
450         Long xId = null;
451
452         // For Meter provisioning, the SwitchConnectionDistinguisher is set to
453         // null so
454         // the request can be routed through any connection to the switch
455         SwitchConnectionDistinguisher cookie = null;
456         if (Objects.firstNonNull(input.isBarrier(), Boolean.FALSE)) {
457             xId = session.getNextXid();
458             BarrierInputBuilder barrierInput = new BarrierInputBuilder();
459             barrierInput.setVersion(version);
460             barrierInput.setXid(xId);
461             @SuppressWarnings("unused")
462             Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
463         }
464
465         // Convert the RemoveMeterInput to MeterModInput
466         MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input, version);
467         xId = session.getNextXid();
468         ofMeterModInput.setXid(xId);
469
470         if (null != rpcNotificationProviderService) {
471             MeterRemovedBuilder meterMod = new MeterRemovedBuilder(
472                     (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter) input);
473             meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
474             meterMod.setMeterRef(input.getMeterRef());
475             rpcNotificationProviderService.publish(meterMod.build());
476         }
477
478         Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie);
479
480         RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null;
481
482         try {
483             rpcResultFromOFLib = resultFromOFLib.get();
484         } catch (Exception ex) {
485             LOG.error(" Error while getting result for RemoveMeter RPC" + ex.getMessage());
486         }
487
488         UpdateMeterOutput updatemeterOutput = rpcResultFromOFLib.getResult();
489
490         RemoveMeterOutputBuilder removeMeterOutput = new RemoveMeterOutputBuilder();
491         removeMeterOutput.setTransactionId(updatemeterOutput.getTransactionId());
492         RemoveMeterOutput result = removeMeterOutput.build();
493
494         Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
495         RpcResult<RemoveMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
496
497         LOG.debug("Returning the Remove Meter RPC result to MD-SAL");
498         return Futures.immediateFuture(rpcResult);
499     }
500
501     @Override
502     public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) {
503         LOG.debug("TransmitPacket - {}", input);
504         // Convert TransmitPacket to PacketOutInput
505         PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, sessionContext.getNextXid(),
506                 sessionContext.getFeatures().getDatapathId());
507
508         // TODO VD NULL for yet - find how to translate cookie from
509         // TransmitPacketInput
510         // SwitchConnectionDistinguisher cookie = ( "what is need to do" )
511         // input.getCookie();
512         SwitchConnectionDistinguisher cookie = null;
513
514         LOG.debug("Calling the transmitPacket RPC method");
515         return messageService.packetOut(message, cookie);
516     }
517
518     private FlowModInputBuilder toFlowModInputBuilder(final Flow source) {
519         FlowModInputBuilder target = new FlowModInputBuilder();
520         target.setCookie(source.getCookie().getValue());
521         target.setIdleTimeout(source.getIdleTimeout());
522         target.setHardTimeout(source.getHardTimeout());
523         target.setMatch(toMatch(source.getMatch()));
524
525         return target;
526     }
527
528     private Match toMatch(final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
529         MatchBuilder target = new MatchBuilder();
530
531         target.setMatchEntries(toMatchEntries(match));
532
533         return null;
534     }
535
536     private List<MatchEntries> toMatchEntries(
537             final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match) {
538         List<MatchEntries> entries = new ArrayList<>();
539
540         return null;
541     }
542
543     @Override
544     public Future<RpcResult<UpdateFlowOutput>> updateFlow(final UpdateFlowInput input) {
545         LOG.debug("Calling the updateFlow RPC method on MessageDispatchService");
546         
547         // use primary connection
548         SwitchConnectionDistinguisher cookie = null;
549         
550         OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> task = 
551                 OFRpcTaskFactory.createUpdateFlowTask(maxTimeout, maxTimeoutUnit, rpcTaskHelper);
552         rpcTaskHelper.initTask(task, input, cookie);
553         OFSessionUtil.getSessionManager().getRpcPool().submit(task);
554         
555         return task.getResult();
556     }
557
558     @Override
559     public Future<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
560         LOG.debug("Calling the update Group Mod RPC method on MessageDispatchService");
561         Long xId = null;
562
563         // For Flow provisioning, the SwitchConnectionDistinguisher is set to
564         // null so
565         // the request can be routed through any connection to the switch
566
567         SwitchConnectionDistinguisher cookie = null;
568         if (Objects.firstNonNull(input.getUpdatedGroup().isBarrier(), Boolean.FALSE)) {
569             xId = session.getNextXid();
570             BarrierInputBuilder barrierInput = new BarrierInputBuilder();
571             barrierInput.setVersion(version);
572             barrierInput.setXid(xId);
573             @SuppressWarnings("unused")
574             Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
575         }
576
577         // Convert the UpdateGroupInput to GroupModInput
578         GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input.getUpdatedGroup(), version, this
579                 .getSessionContext().getFeatures().getDatapathId());
580         xId = session.getNextXid();
581         ofGroupModInput.setXid(xId);
582
583         if (null != rpcNotificationProviderService) {
584             GroupUpdatedBuilder groupMod = new GroupUpdatedBuilder(input.getUpdatedGroup());
585             groupMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
586             groupMod.setGroupRef(input.getGroupRef());
587             rpcNotificationProviderService.publish(groupMod.build());
588         }
589
590         Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = messageService.groupMod(ofGroupModInput.build(), cookie);
591
592         RpcResult<UpdateGroupOutput> rpcResultFromOFLib = null;
593
594         try {
595             rpcResultFromOFLib = resultFromOFLib.get();
596         } catch (Exception ex) {
597             LOG.error(" Error while getting result for updateGroup RPC" + ex.getMessage());
598         }
599
600         UpdateGroupOutput updateGroupOutputOFLib = rpcResultFromOFLib.getResult();
601
602         UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder();
603         updateGroupOutput.setTransactionId(updateGroupOutputOFLib.getTransactionId());
604         UpdateGroupOutput result = updateGroupOutput.build();
605
606         Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
607         RpcResult<UpdateGroupOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
608
609         LOG.debug("Returning the Update Group RPC result to MD-SAL");
610         return Futures.immediateFuture(rpcResult);
611     }
612
613     @Override
614     public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
615         LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
616         Long xId = null;
617
618         // For Meter provisioning, the SwitchConnectionDistinguisher is set to
619         // null so
620         // the request can be routed through any connection to the switch
621         SwitchConnectionDistinguisher cookie = null;
622         if (Objects.firstNonNull(input.getUpdatedMeter().isBarrier(), Boolean.FALSE)) {
623             xId = session.getNextXid();
624             BarrierInputBuilder barrierInput = new BarrierInputBuilder();
625             barrierInput.setVersion(version);
626             barrierInput.setXid(xId);
627             @SuppressWarnings("unused")
628             Future<RpcResult<BarrierOutput>> barrierOFLib = messageService.barrier(barrierInput.build(), cookie);
629         }
630
631         // Convert the UpdateMeterInput to MeterModInput
632         MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input.getUpdatedMeter(), version);
633         xId = session.getNextXid();
634         ofMeterModInput.setXid(xId);
635
636         if (null != rpcNotificationProviderService) {
637             MeterUpdatedBuilder meterMod = new MeterUpdatedBuilder(input.getUpdatedMeter());
638             meterMod.setTransactionId(new TransactionId(BigInteger.valueOf(xId.intValue())));
639             meterMod.setMeterRef(input.getMeterRef());
640             rpcNotificationProviderService.publish(meterMod.build());
641         }
642
643         Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = messageService.meterMod(ofMeterModInput.build(), cookie);
644
645         RpcResult<UpdateMeterOutput> rpcResultFromOFLib = null;
646
647         try {
648             rpcResultFromOFLib = resultFromOFLib.get();
649         } catch (Exception ex) {
650             LOG.error(" Error while getting result for UpdateMeter RPC" + ex.getMessage());
651         }
652
653         UpdateMeterOutput updateMeterOutputFromOFLib = rpcResultFromOFLib.getResult();
654
655         UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder();
656         updateMeterOutput.setTransactionId(updateMeterOutputFromOFLib.getTransactionId());
657         UpdateMeterOutput result = updateMeterOutput.build();
658
659         Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
660         RpcResult<UpdateMeterOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
661
662         LOG.debug("Returning the Update Meter RPC result to MD-SAL");
663         return Futures.immediateFuture(rpcResult);
664     }
665
666     @Override
667     public NodeId getNodeId() {
668         return nodeId;
669     }
670
671     /*
672      * Methods for requesting statistics from switch
673      */
674     @Override
675     public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(final GetAllGroupStatisticsInput input) {
676
677         GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder();
678         Collection<RpcError> errors = Collections.emptyList();
679
680         if (version == OFConstants.OFP_VERSION_1_0) {
681             output.setTransactionId(null);
682             output.setGroupStats(null);
683
684             RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
685             return Futures.immediateFuture(rpcResult);
686         }
687         // Generate xid to associate it with the request
688         Long xid = this.getSessionContext().getNextXid();
689
690         LOG.debug("Prepare statistics request for all the groups - Transaction id - {}", xid);
691
692         // Create multipart request header
693         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
694         mprInput.setType(MultipartType.OFPMPGROUP);
695         mprInput.setVersion(version);
696         mprInput.setXid(xid);
697         mprInput.setFlags(new MultipartRequestFlags(false));
698
699         // Create multipart request body for fetch all the group stats
700         MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
701         MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
702         mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue())));
703         caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
704
705         // Set request body to main multipart request
706         mprInput.setMultipartRequestBody(caseBuilder.build());
707
708         // Send the request, no cookies associated, use any connection
709         LOG.debug("Send group statistics request to the switch :{}", mprGroupBuild);
710         this.messageService.multipartRequest(mprInput.build(), null);
711
712         // Prepare rpc return output. Set xid and send it back.
713         LOG.debug("Return results and transaction id back to caller");
714         output.setTransactionId(generateTransactionId(xid));
715         output.setGroupStats(null);
716
717         RpcResult<GetAllGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
718         return Futures.immediateFuture(rpcResult);
719
720     }
721
722     @Override
723     public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(final GetGroupDescriptionInput input) {
724
725         GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder();
726         Collection<RpcError> errors = Collections.emptyList();
727
728         if (version == OFConstants.OFP_VERSION_1_0) {
729             output.setTransactionId(null);
730             output.setGroupDescStats(null);
731
732             RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
733             return Futures.immediateFuture(rpcResult);
734         }
735         // Generate xid to associate it with the request
736         Long xid = this.getSessionContext().getNextXid();
737
738         LOG.debug("Prepare group description statistics request - Transaction id - {}", xid);
739
740         // Create multipart request header
741         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
742         mprInput.setType(MultipartType.OFPMPGROUPDESC);
743         mprInput.setVersion(version);
744         mprInput.setXid(xid);
745         mprInput.setFlags(new MultipartRequestFlags(false));
746
747         // Create multipart request body for fetch all the group description
748         // stats
749         MultipartRequestGroupDescCaseBuilder mprGroupDescBuild = new MultipartRequestGroupDescCaseBuilder();
750
751         // Set request body to main multipart request
752         mprInput.setMultipartRequestBody(mprGroupDescBuild.build());
753
754         // Send the request, no cookies associated, use any connection
755         LOG.debug("Send group desciption statistics request to switch : {}", mprGroupDescBuild);
756         this.messageService.multipartRequest(mprInput.build(), null);
757
758         // Prepare rpc return output. Set xid and send it back.
759         LOG.debug("Return results and transaction id back to caller");
760         output.setTransactionId(generateTransactionId(xid));
761         output.setGroupDescStats(null);
762
763         RpcResult<GetGroupDescriptionOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
764         return Futures.immediateFuture(rpcResult);
765
766     }
767
768     @Override
769     public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(final GetGroupFeaturesInput input) {
770
771         GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder();
772         Collection<RpcError> errors = Collections.emptyList();
773
774         if (version == OFConstants.OFP_VERSION_1_0) {
775             output.setTransactionId(null);
776
777             RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
778             return Futures.immediateFuture(rpcResult);
779         }
780         // Generate xid to associate it with the request
781         Long xid = this.getSessionContext().getNextXid();
782
783         LOG.debug("Prepare group features statistics request - Transaction id - {}", xid);
784
785         // Create multipart request header
786         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
787         mprInput.setType(MultipartType.OFPMPGROUPFEATURES);
788         mprInput.setVersion(version);
789         mprInput.setXid(xid);
790         mprInput.setFlags(new MultipartRequestFlags(false));
791
792         // Create multipart request body for fetch all the group description
793         // stats
794         MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder();
795
796         // Set request body to main multipart request
797         mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
798
799         // Send the request, no cookies associated, use any connection
800         LOG.debug("Send group features statistics request :{}", mprGroupFeaturesBuild);
801         this.messageService.multipartRequest(mprInput.build(), null);
802
803         // Prepare rpc return output. Set xid and send it back.
804         LOG.debug("Return results and transaction id back to caller");
805         output.setTransactionId(generateTransactionId(xid));
806
807         RpcResult<GetGroupFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
808         return Futures.immediateFuture(rpcResult);
809     }
810
811     @Override
812     public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(final GetGroupStatisticsInput input) {
813
814         GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder();
815         Collection<RpcError> errors = Collections.emptyList();
816
817         if (version == OFConstants.OFP_VERSION_1_0) {
818             output.setTransactionId(null);
819             output.setGroupStats(null);
820
821             RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
822             return Futures.immediateFuture(rpcResult);
823         }
824         // Generate xid to associate it with the request
825         Long xid = this.getSessionContext().getNextXid();
826
827         LOG.debug("Prepare statistics request for node {} group ({}) - Transaction id - {}", input.getNode(),
828                 input.getGroupId(), xid);
829
830         // Create multipart request header
831         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
832         mprInput.setType(MultipartType.OFPMPGROUP);
833         mprInput.setVersion(version);
834         mprInput.setXid(xid);
835         mprInput.setFlags(new MultipartRequestFlags(false));
836
837         // Create multipart request body for fetch all the group stats
838         MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
839         MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
840         mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
841         caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
842
843         // Set request body to main multipart request
844         mprInput.setMultipartRequestBody(caseBuilder.build());
845
846         // Send the request, no cookies associated, use any connection
847         LOG.debug("Send group statistics request :{}", mprGroupBuild);
848         this.messageService.multipartRequest(mprInput.build(), null);
849
850         // Prepare rpc return output. Set xid and send it back.
851         LOG.debug("Return results and transaction id back to caller");
852         output.setTransactionId(generateTransactionId(xid));
853         output.setGroupStats(null);
854
855         RpcResult<GetGroupStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
856         return Futures.immediateFuture(rpcResult);
857     }
858
859     @Override
860     public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
861             final GetAllMeterConfigStatisticsInput input) {
862
863         GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder();
864         Collection<RpcError> errors = Collections.emptyList();
865
866         if (version == OFConstants.OFP_VERSION_1_0) {
867             output.setTransactionId(null);
868             output.setMeterConfigStats(null);
869
870             RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
871             return Futures.immediateFuture(rpcResult);
872
873         }
874         // Generate xid to associate it with the request
875         Long xid = this.getSessionContext().getNextXid();
876
877         LOG.debug("Prepare config request for all the meters - Transaction id - {}", xid);
878
879         // Create multipart request header
880         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
881         mprInput.setType(MultipartType.OFPMPMETERCONFIG);
882         mprInput.setVersion(version);
883         mprInput.setXid(xid);
884         mprInput.setFlags(new MultipartRequestFlags(false));
885
886         // Create multipart request body for fetch all the meter stats
887         MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder();
888         MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder();
889         mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
890         caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
891
892         // Set request body to main multipart request
893         mprInput.setMultipartRequestBody(caseBuilder.build());
894
895         // Send the request, no cookies associated, use any connection
896         LOG.debug("Send meter statistics request :{}", mprMeterConfigBuild);
897         this.messageService.multipartRequest(mprInput.build(), null);
898
899         // Prepare rpc return output. Set xid and send it back.
900         LOG.debug("Return results and transaction id back to caller");
901         output.setTransactionId(generateTransactionId(xid));
902         output.setMeterConfigStats(null);
903
904         RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
905         return Futures.immediateFuture(rpcResult);
906     }
907
908     @Override
909     public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(final GetAllMeterStatisticsInput input) {
910
911         GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder();
912         Collection<RpcError> errors = Collections.emptyList();
913
914         if (version == OFConstants.OFP_VERSION_1_0) {
915             output.setTransactionId(null);
916             output.setMeterStats(null);
917
918             RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
919             return Futures.immediateFuture(rpcResult);
920         }
921         // Generate xid to associate it with the request
922         Long xid = this.getSessionContext().getNextXid();
923
924         LOG.debug("Prepare statistics request for all the meters - Transaction id - {}", xid);
925
926         // Create multipart request header
927         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
928         mprInput.setType(MultipartType.OFPMPMETER);
929         mprInput.setVersion(version);
930         mprInput.setXid(xid);
931         mprInput.setFlags(new MultipartRequestFlags(false));
932
933         // Create multipart request body for fetch all the meter stats
934         MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
935         MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
936         mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
937         caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
938
939         // Set request body to main multipart request
940         mprInput.setMultipartRequestBody(caseBuilder.build());
941
942         // Send the request, no cookies associated, use any connection
943         LOG.debug("Send meter statistics request :{}", mprMeterBuild);
944         this.messageService.multipartRequest(mprInput.build(), null);
945
946         // Prepare rpc return output. Set xid and send it back.
947         LOG.debug("Return results and transaction id back to caller");
948         output.setTransactionId(generateTransactionId(xid));
949         output.setMeterStats(null);
950
951         RpcResult<GetAllMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
952         return Futures.immediateFuture(rpcResult);
953     }
954
955     @Override
956     public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(final GetMeterFeaturesInput input) {
957
958         GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder();
959         Collection<RpcError> errors = Collections.emptyList();
960
961         if (version == OFConstants.OFP_VERSION_1_0) {
962             output.setTransactionId(null);
963
964             RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
965             return Futures.immediateFuture(rpcResult);
966         }
967         // Generate xid to associate it with the request
968         Long xid = this.getSessionContext().getNextXid();
969
970         LOG.debug("Prepare features statistics request for all the meters - Transaction id - {}", xid);
971
972         // Create multipart request header
973         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
974         mprInput.setType(MultipartType.OFPMPMETERFEATURES);
975         mprInput.setVersion(version);
976         mprInput.setXid(xid);
977         mprInput.setFlags(new MultipartRequestFlags(false));
978
979         // Create multipart request body for fetch all the group description
980         // stats
981         MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder();
982
983         // Set request body to main multipart request
984         mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
985
986         // Send the request, no cookies associated, use any connection
987         LOG.debug("Send meter features statistics request :{}", mprMeterFeaturesBuild);
988         this.messageService.multipartRequest(mprInput.build(), null);
989
990         // Prepare rpc return output. Set xid and send it back.
991         LOG.debug("Return results and transaction id back to caller");
992         output.setTransactionId(generateTransactionId(xid));
993
994         RpcResult<GetMeterFeaturesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
995         return Futures.immediateFuture(rpcResult);
996     }
997
998     @Override
999     public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(final GetMeterStatisticsInput input) {
1000
1001         GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder();
1002         Collection<RpcError> errors = Collections.emptyList();
1003
1004         if (version == OFConstants.OFP_VERSION_1_0) {
1005             output.setTransactionId(null);
1006             output.setMeterStats(null);
1007
1008             RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1009             return Futures.immediateFuture(rpcResult);
1010
1011         }
1012         // Generate xid to associate it with the request
1013         Long xid = this.getSessionContext().getNextXid();
1014
1015         LOG.debug("Preprae statistics request for Meter ({}) - Transaction id - {}", input.getMeterId().getValue(), xid);
1016
1017         // Create multipart request header
1018         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1019         mprInput.setType(MultipartType.OFPMPMETER);
1020         mprInput.setVersion(version);
1021         mprInput.setXid(xid);
1022         mprInput.setFlags(new MultipartRequestFlags(false));
1023
1024         // Create multipart request body for fetch all the meter stats
1025         MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
1026         MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
1027         // Select specific meter
1028         mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
1029         caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
1030
1031         // Set request body to main multipart request
1032         mprInput.setMultipartRequestBody(caseBuilder.build());
1033
1034         // Send the request, no cookies associated, use any connection
1035         LOG.debug("Send meter statistics request :{}", mprMeterBuild);
1036         this.messageService.multipartRequest(mprInput.build(), null);
1037
1038         // Prepare rpc return output. Set xid and send it back.
1039         LOG.debug("Return results and transaction id back to caller");
1040         output.setTransactionId(generateTransactionId(xid));
1041         output.setMeterStats(null);
1042
1043         RpcResult<GetMeterStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1044         return Futures.immediateFuture(rpcResult);
1045     }
1046
1047     @Override
1048     public Future<RpcResult<GetAllNodeConnectorsStatisticsOutput>> getAllNodeConnectorsStatistics(
1049             final GetAllNodeConnectorsStatisticsInput arg0) {
1050
1051         // Generate xid to associate it with the request
1052         Long xid = this.getSessionContext().getNextXid();
1053
1054         LOG.debug("Prepare port statistics request for all ports of node {} - TrasactionId - {}", arg0.getNode()
1055                 .getValue(), xid);
1056
1057         // Create multipart request header
1058         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1059         mprInput.setType(MultipartType.OFPMPPORTSTATS);
1060         mprInput.setVersion(version);
1061         mprInput.setXid(xid);
1062         mprInput.setFlags(new MultipartRequestFlags(false));
1063
1064         // Create multipart request body to fetch stats for all the port of the
1065         // node
1066         MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
1067         MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
1068         // Select all ports
1069         mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
1070         caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1071
1072         // Set request body to main multipart request
1073         mprInput.setMultipartRequestBody(caseBuilder.build());
1074
1075         // Send the request, no cookies associated, use any connection
1076         LOG.debug("Send port statistics request :{}", mprPortStatsBuilder.build().toString());
1077         this.messageService.multipartRequest(mprInput.build(), null);
1078
1079         // Prepare rpc return output. Set xid and send it back.
1080         GetAllNodeConnectorsStatisticsOutputBuilder output = new GetAllNodeConnectorsStatisticsOutputBuilder();
1081         output.setTransactionId(generateTransactionId(xid));
1082
1083         Collection<RpcError> errors = Collections.emptyList();
1084         RpcResult<GetAllNodeConnectorsStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1085         return Futures.immediateFuture(rpcResult);
1086     }
1087
1088     @Override
1089     public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(
1090             final GetNodeConnectorStatisticsInput arg0) {
1091         // Generate xid to associate it with the request
1092         Long xid = this.getSessionContext().getNextXid();
1093
1094         LOG.debug("Prepare port statistics request for port {} of node {} - TrasactionId - {}",
1095                 arg0.getNodeConnectorId(), arg0.getNode().getValue(), xid);
1096
1097         // Create multipart request header
1098         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1099         mprInput.setType(MultipartType.OFPMPPORTSTATS);
1100         mprInput.setVersion(version);
1101         mprInput.setXid(xid);
1102         mprInput.setFlags(new MultipartRequestFlags(false));
1103
1104         // Create multipart request body to fetch stats for all the port of the
1105         // node
1106         MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
1107         MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
1108
1109         // Set specific port
1110         mprPortStatsBuilder
1111                 .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1112         caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
1113
1114         // Set request body to main multipart request
1115         mprInput.setMultipartRequestBody(caseBuilder.build());
1116
1117         // Send the request, no cookies associated, use any connection
1118         LOG.debug("Send port statistics request :{}", mprPortStatsBuilder.build().toString());
1119         this.messageService.multipartRequest(mprInput.build(), null);
1120
1121         // Prepare rpc return output. Set xid and send it back.
1122         GetNodeConnectorStatisticsOutputBuilder output = new GetNodeConnectorStatisticsOutputBuilder();
1123         output.setTransactionId(generateTransactionId(xid));
1124
1125         Collection<RpcError> errors = Collections.emptyList();
1126         RpcResult<GetNodeConnectorStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1127         return Futures.immediateFuture(rpcResult);
1128     }
1129
1130     private TransactionId generateTransactionId(final Long xid) {
1131         String stringXid = xid.toString();
1132         BigInteger bigIntXid = new BigInteger(stringXid);
1133         return new TransactionId(bigIntXid);
1134
1135     }
1136
1137     @Override
1138     public Future<RpcResult<UpdatePortOutput>> updatePort(final UpdatePortInput input) {
1139         PortModInput ofPortModInput = null;
1140         RpcResult<UpdatePortOutput> rpcResultFromOFLib = null;
1141
1142         // For Flow provisioning, the SwitchConnectionDistinguisher is set to
1143         // null so
1144         // the request can be routed through any connection to the switch
1145
1146         SwitchConnectionDistinguisher cookie = null;
1147
1148         // NSF sends a list of port and the ModelDrivenSwitch will
1149         // send one port at a time towards the switch ( mutiple RPCs calls)
1150         List<Port> inputPorts = input.getUpdatedPort().getPort().getPort();
1151
1152         // Get the Xid. The same Xid has to be sent in all the RPCs
1153         Long Xid = sessionContext.getNextXid();
1154
1155         for (Port inputPort : inputPorts) {
1156
1157             // Convert the UpdateGroupInput to GroupModInput
1158             ofPortModInput = PortConvertor.toPortModInput(inputPort, version);
1159
1160             // Insert the Xid ( transaction Id) before calling the RPC on the
1161             // OFLibrary
1162
1163             PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
1164             mdInput.setXid(Xid);
1165
1166             LOG.debug("Calling the PortMod RPC method on MessageDispatchService");
1167             Future<RpcResult<UpdatePortOutput>> resultFromOFLib = messageService.portMod(mdInput.build(), cookie);
1168
1169             try {
1170                 rpcResultFromOFLib = resultFromOFLib.get();
1171             } catch (Exception ex) {
1172                 LOG.error(" Error while getting result for updatePort RPC" + ex.getMessage());
1173             }
1174
1175             // The Future response value for all the RPCs except the last one is
1176             // ignored
1177
1178         }
1179         // Extract the Xid only from the Future for the last RPC and
1180         // send it back to the NSF
1181         UpdatePortOutput updatePortOutputOFLib = rpcResultFromOFLib.getResult();
1182
1183         UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder();
1184         updatePortOutput.setTransactionId(updatePortOutputOFLib.getTransactionId());
1185         UpdatePortOutput result = updatePortOutput.build();
1186
1187         Collection<RpcError> errors = rpcResultFromOFLib.getErrors();
1188         RpcResult<UpdatePortOutput> rpcResult = Rpcs.getRpcResult(true, result, errors);
1189
1190         LOG.debug("Returning the Update Group RPC result to MD-SAL");
1191         return Futures.immediateFuture(rpcResult);
1192
1193     }
1194
1195     @Override
1196     public Future<RpcResult<UpdateTableOutput>> updateTable(final UpdateTableInput input) {
1197
1198         // Get the Xid. The same Xid has to be sent in all the Multipart
1199         // requests
1200         Long xid = this.getSessionContext().getNextXid();
1201
1202         LOG.debug("Prepare the Multipart Table Mod requests for Transaction Id {} ", xid);
1203
1204         // Create multipart request header
1205         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1206         mprInput.setType(MultipartType.OFPMPTABLEFEATURES);
1207         mprInput.setVersion((short) 0x04);
1208         mprInput.setXid(xid);
1209
1210         // Convert the list of all MD-SAL table feature object into OF library
1211         // object
1212         List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input.getUpdatedTable());
1213
1214         MultipartRequestTableFeaturesCaseBuilder caseRequest = new MultipartRequestTableFeaturesCaseBuilder();
1215         MultipartRequestTableFeaturesBuilder tableFeaturesRequest = new MultipartRequestTableFeaturesBuilder();
1216
1217         mprInput.setFlags(new MultipartRequestFlags(false));
1218
1219         tableFeaturesRequest.setTableFeatures(ofTableFeatureList);
1220
1221         // Set request body to main multipart request
1222         caseRequest.setMultipartRequestTableFeatures(tableFeaturesRequest.build());
1223         mprInput.setMultipartRequestBody(caseRequest.build());
1224
1225         // Send the request, no cookies associated, use any connection
1226         LOG.debug("Send Table Feature request :{}", ofTableFeatureList);
1227         this.messageService.multipartRequest(mprInput.build(), null);
1228
1229         // Extract the Xid only from the Future for the last RPC and
1230         // send it back to the NSF
1231         LOG.debug("Returning the result and transaction id to NSF");
1232         LOG.debug("Return results and transaction id back to caller");
1233         UpdateTableOutputBuilder output = new UpdateTableOutputBuilder();
1234         output.setTransactionId(generateTransactionId(xid));
1235
1236         Collection<RpcError> errors = Collections.emptyList();
1237         RpcResult<UpdateTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1238         return Futures.immediateFuture(rpcResult);
1239     }
1240
1241     @Override
1242     public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
1243             final GetAllFlowStatisticsFromFlowTableInput arg0) {
1244
1245         // Generate xid to associate it with the request
1246         Long xid = this.getSessionContext().getNextXid();
1247
1248         LOG.debug("Prepare statistics request to get flow stats for switch tables {} - Transaction id - {}", arg0
1249                 .getTableId().getValue(), xid);
1250
1251         // Create multipart request header
1252         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1253         mprInput.setType(MultipartType.OFPMPFLOW);
1254         mprInput.setVersion(version);
1255         mprInput.setXid(xid);
1256         mprInput.setFlags(new MultipartRequestFlags(false));
1257
1258         // Create multipart request body for fetch all the group stats
1259         MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1260         MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1261         mprFlowRequestBuilder.setTableId(arg0.getTableId().getValue());
1262         mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1263         mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1264         mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1265         mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1266         FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
1267
1268         // Set request body to main multipart request
1269         multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1270         mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1271
1272         // Send the request, no cookies associated, use any connection
1273         LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1274         this.messageService.multipartRequest(mprInput.build(), null);
1275
1276         // Prepare rpc return output. Set xid and send it back.
1277         LOG.debug("Return results and transaction id back to caller");
1278         GetAllFlowStatisticsFromFlowTableOutputBuilder output = new GetAllFlowStatisticsFromFlowTableOutputBuilder();
1279         output.setTransactionId(generateTransactionId(xid));
1280         output.setFlowAndStatisticsMapList(null);
1281
1282         Collection<RpcError> errors = Collections.emptyList();
1283         RpcResult<GetAllFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1284         return Futures.immediateFuture(rpcResult);
1285     }
1286
1287     @Override
1288     public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
1289             final GetAllFlowsStatisticsFromAllFlowTablesInput arg0) {
1290
1291         // Generate xid to associate it with the request
1292         Long xid = this.getSessionContext().getNextXid();
1293
1294         LOG.debug("Prepare statistics request to get flow stats of all switch tables - Transaction id - {}", xid);
1295
1296         // Create multipart request header
1297         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1298         mprInput.setType(MultipartType.OFPMPFLOW);
1299         mprInput.setVersion(version);
1300         mprInput.setXid(xid);
1301         mprInput.setFlags(new MultipartRequestFlags(false));
1302
1303         // Create multipart request body for fetch all the group stats
1304         MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1305         MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1306         mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
1307         mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1308         mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1309         mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1310         mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1311         mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1312
1313         FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
1314
1315         // Set request body to main multipart request
1316         multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1317         mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1318
1319         // Send the request, no cookies associated, use any connection
1320         LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1321         this.messageService.multipartRequest(mprInput.build(), null);
1322
1323         // Prepare rpc return output. Set xid and send it back.
1324         GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder output = new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
1325         output.setTransactionId(generateTransactionId(xid));
1326         output.setFlowAndStatisticsMapList(null);
1327
1328         Collection<RpcError> errors = Collections.emptyList();
1329         RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult = Rpcs.getRpcResult(true, output.build(),
1330                 errors);
1331         return Futures.immediateFuture(rpcResult);
1332
1333     }
1334
1335     @Override
1336     public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
1337             final GetFlowStatisticsFromFlowTableInput arg0) {
1338         // Generate xid to associate it with the request
1339         Long xid = this.getSessionContext().getNextXid();
1340
1341         LOG.debug("Prepare statistics request to get stats for flow {} for switch tables {} - Transaction id - {}",
1342                 arg0.getMatch().toString(), arg0.getTableId(), xid);
1343
1344         // Create multipart request header
1345         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1346         mprInput.setType(MultipartType.OFPMPFLOW);
1347         mprInput.setVersion(version);
1348         mprInput.setXid(xid);
1349         mprInput.setFlags(new MultipartRequestFlags(false));
1350
1351         // Create multipart request body for fetch all the group stats
1352         MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
1353         MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
1354         mprFlowRequestBuilder.setTableId(arg0.getTableId());
1355
1356         if (arg0.getOutPort() != null)
1357             mprFlowRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1358         else
1359             mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1360
1361         if (arg0.getOutGroup() != null)
1362             mprFlowRequestBuilder.setOutGroup(arg0.getOutGroup());
1363         else
1364             mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1365
1366         if (arg0.getCookie() != null)
1367             mprFlowRequestBuilder.setCookie(arg0.getCookie().getValue());
1368         else
1369             mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1370
1371         if (arg0.getCookieMask() != null)
1372             mprFlowRequestBuilder.setCookieMask(arg0.getCookieMask().getValue());
1373         else
1374             mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1375
1376         // convert and inject match
1377         MatchReactor.getInstance().convert(arg0.getMatch(), version, mprFlowRequestBuilder,
1378                 this.getSessionContext().getFeatures().getDatapathId());
1379
1380         // Set request body to main multipart request
1381         multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
1382         mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
1383
1384         // Send the request, no cookies associated, use any connection
1385         LOG.debug("Send flow statistics request to the switch :{}", mprFlowRequestBuilder);
1386         this.messageService.multipartRequest(mprInput.build(), null);
1387
1388         // Prepare rpc return output. Set xid and send it back.
1389         GetFlowStatisticsFromFlowTableOutputBuilder output = new GetFlowStatisticsFromFlowTableOutputBuilder();
1390         output.setTransactionId(generateTransactionId(xid));
1391         output.setFlowAndStatisticsMapList(null);
1392
1393         Collection<RpcError> errors = Collections.emptyList();
1394         RpcResult<GetFlowStatisticsFromFlowTableOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1395         return Futures.immediateFuture(rpcResult);
1396     }
1397
1398     @Override
1399     public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
1400             final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput arg0) {
1401         // Generate xid to associate it with the request
1402         Long xid = this.getSessionContext().getNextXid();
1403
1404         LOG.debug(
1405                 "Prepare aggregate flow statistics request to get aggregate flow stats for all the flow installed on switch table {} - Transaction id - {}",
1406                 arg0.getTableId().getValue(), xid);
1407
1408         // Create multipart request header
1409         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1410         mprInput.setType(MultipartType.OFPMPAGGREGATE);
1411         mprInput.setVersion(version);
1412         mprInput.setXid(xid);
1413         mprInput.setFlags(new MultipartRequestFlags(false));
1414
1415         // Create multipart request body for fetch all the group stats
1416         MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1417         MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1418         mprAggregateRequestBuilder.setTableId(arg0.getTableId().getValue());
1419         mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
1420         mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1421         mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1422         mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1423
1424         FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
1425
1426         // Set request body to main multipart request
1427         multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1428         mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1429
1430         // Send the request, no cookies associated, use any connection
1431         LOG.debug("Send request to the switch :{}", multipartRequestAggregateCaseBuilder.build().toString());
1432         this.messageService.multipartRequest(mprInput.build(), null);
1433
1434         // Prepare rpc return output. Set xid and send it back.
1435         GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder output = new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder();
1436         output.setTransactionId(generateTransactionId(xid));
1437
1438         Collection<RpcError> errors = Collections.emptyList();
1439         RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = Rpcs.getRpcResult(true,
1440                 output.build(), errors);
1441         return Futures.immediateFuture(rpcResult);
1442     }
1443
1444     @Override
1445     public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
1446             final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput arg0) {
1447
1448         // Generate xid to associate it with the request
1449         Long xid = this.getSessionContext().getNextXid();
1450
1451         LOG.debug(
1452                 "Prepare aggregate statistics request to get aggregate stats for flows matching {} and installed in flow tables {} - Transaction id - {}",
1453                 arg0.getMatch().toString(), arg0.getTableId(), xid);
1454
1455         // Create multipart request header
1456         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1457         mprInput.setType(MultipartType.OFPMPAGGREGATE);
1458         mprInput.setVersion(version);
1459         mprInput.setXid(xid);
1460         mprInput.setFlags(new MultipartRequestFlags(false));
1461
1462         // Create multipart request body for fetch all the group stats
1463         MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
1464         MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
1465         mprAggregateRequestBuilder.setTableId(arg0.getTableId());
1466         mprAggregateRequestBuilder.setOutPort(arg0.getOutPort().longValue());
1467         mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
1468         mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
1469         mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
1470
1471         MatchReactor.getInstance().convert(arg0.getMatch(), version, mprAggregateRequestBuilder,
1472                 this.getSessionContext().getFeatures().getDatapathId());
1473         // TODO: repeating code
1474         if (version == OFConstants.OFP_VERSION_1_3) {
1475             mprAggregateRequestBuilder.setCookie(arg0.getCookie().getValue());
1476             mprAggregateRequestBuilder.setCookieMask(arg0.getCookieMask().getValue());
1477             mprAggregateRequestBuilder.setOutGroup(arg0.getOutGroup());
1478         }
1479
1480         // Set request body to main multipart request
1481         multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
1482         mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
1483
1484         // Send the request, no cookies associated, use any connection
1485         LOG.debug("Send request to the switch :{}", multipartRequestAggregateCaseBuilder.build().toString());
1486         this.messageService.multipartRequest(mprInput.build(), null);
1487
1488         // Prepare rpc return output. Set xid and send it back.
1489         GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder output = new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
1490         output.setTransactionId(generateTransactionId(xid));
1491
1492         Collection<RpcError> errors = Collections.emptyList();
1493         RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult = Rpcs.getRpcResult(true,
1494                 output.build(), errors);
1495         return Futures.immediateFuture(rpcResult);
1496     }
1497
1498     @Override
1499     public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(final GetFlowTablesStatisticsInput arg0) {
1500         // Generate xid to associate it with the request
1501         Long xid = this.getSessionContext().getNextXid();
1502
1503         LOG.debug("Prepare flow table statistics request to get flow table stats for all tables "
1504                 + "from node {}- Transaction id - {}", arg0.getNode(), xid);
1505
1506         // Create multipart request header
1507         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1508         mprInput.setType(MultipartType.OFPMPTABLE);
1509         mprInput.setVersion(version);
1510         mprInput.setXid(xid);
1511         mprInput.setFlags(new MultipartRequestFlags(false));
1512
1513         // Create multipart request body for fetch all the group stats
1514         MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
1515         MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
1516         multipartRequestTableBuilder.setEmpty(true);
1517         multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
1518
1519         // Set request body to main multipart request
1520         mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
1521
1522         // Send the request, no cookies associated, use any connection
1523         LOG.debug("Send request to the switch :{}", multipartRequestTableCaseBuilder.build().toString());
1524         this.messageService.multipartRequest(mprInput.build(), null);
1525
1526         // Prepare rpc return output. Set xid and send it back.
1527         GetFlowTablesStatisticsOutputBuilder output = new GetFlowTablesStatisticsOutputBuilder();
1528         output.setTransactionId(generateTransactionId(xid));
1529
1530         Collection<RpcError> errors = Collections.emptyList();
1531         RpcResult<GetFlowTablesStatisticsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1532         return Futures.immediateFuture(rpcResult);
1533     }
1534
1535     @Override
1536     public Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> getAllQueuesStatisticsFromAllPorts(
1537             final GetAllQueuesStatisticsFromAllPortsInput arg0) {
1538         // Generate xid to associate it with the request
1539         Long xid = this.getSessionContext().getNextXid();
1540
1541         LOG.debug(
1542                 "Prepare queue statistics request to collect stats for all queues attached to all the ports of node {} - TrasactionId - {}",
1543                 arg0.getNode().getValue(), xid);
1544
1545         // Create multipart request header
1546         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1547         mprInput.setType(MultipartType.OFPMPQUEUE);
1548         mprInput.setVersion(version);
1549         mprInput.setXid(xid);
1550         mprInput.setFlags(new MultipartRequestFlags(false));
1551
1552         // Create multipart request body to fetch stats for all the port of the
1553         // node
1554         MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1555         MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1556         // Select all ports
1557         mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
1558         // Select all the ports
1559         mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1560
1561         caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1562
1563         // Set request body to main multipart request
1564         mprInput.setMultipartRequestBody(caseBuilder.build());
1565
1566         // Send the request, no cookies associated, use any connection
1567         LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1568         this.messageService.multipartRequest(mprInput.build(), null);
1569
1570         // Prepare rpc return output. Set xid and send it back.
1571         GetAllQueuesStatisticsFromAllPortsOutputBuilder output = new GetAllQueuesStatisticsFromAllPortsOutputBuilder();
1572         output.setTransactionId(generateTransactionId(xid));
1573         output.setQueueIdAndStatisticsMap(null);
1574
1575         Collection<RpcError> errors = Collections.emptyList();
1576         RpcResult<GetAllQueuesStatisticsFromAllPortsOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1577         return Futures.immediateFuture(rpcResult);
1578     }
1579
1580     @Override
1581     public Future<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> getAllQueuesStatisticsFromGivenPort(
1582             final GetAllQueuesStatisticsFromGivenPortInput arg0) {
1583         // Generate xid to associate it with the request
1584         Long xid = this.getSessionContext().getNextXid();
1585
1586         LOG.debug("Prepare queue statistics request to collect stats for "
1587                 + "all queues attached to given port {} of node {} - TrasactionId - {}", arg0.getNodeConnectorId()
1588                 .toString(), arg0.getNode().getValue(), xid);
1589
1590         // Create multipart request header
1591         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1592         mprInput.setType(MultipartType.OFPMPQUEUE);
1593         mprInput.setVersion(version);
1594         mprInput.setXid(xid);
1595         mprInput.setFlags(new MultipartRequestFlags(false));
1596
1597         // Create multipart request body to fetch stats for all the port of the
1598         // node
1599         MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1600         MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1601         // Select all queues
1602         mprQueueBuilder.setQueueId(OFConstants.OFPQ_ANY);
1603         // Select specific port
1604         mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1605
1606         caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1607
1608         // Set request body to main multipart request
1609         mprInput.setMultipartRequestBody(caseBuilder.build());
1610
1611         // Send the request, no cookies associated, use any connection
1612         LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1613         this.messageService.multipartRequest(mprInput.build(), null);
1614
1615         // Prepare rpc return output. Set xid and send it back.
1616         GetAllQueuesStatisticsFromGivenPortOutputBuilder output = new GetAllQueuesStatisticsFromGivenPortOutputBuilder();
1617         output.setTransactionId(generateTransactionId(xid));
1618         output.setQueueIdAndStatisticsMap(null);
1619
1620         Collection<RpcError> errors = Collections.emptyList();
1621         RpcResult<GetAllQueuesStatisticsFromGivenPortOutput> rpcResult = Rpcs
1622                 .getRpcResult(true, output.build(), errors);
1623         return Futures.immediateFuture(rpcResult);
1624     }
1625
1626     @Override
1627     public Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> getQueueStatisticsFromGivenPort(
1628             final GetQueueStatisticsFromGivenPortInput arg0) {
1629         // Generate xid to associate it with the request
1630         Long xid = this.getSessionContext().getNextXid();
1631
1632         LOG.debug("Prepare queue statistics request to collect stats for "
1633                 + "given queue attached to given port {} of node {} - TrasactionId - {}", arg0.getQueueId().toString(),
1634                 arg0.getNodeConnectorId().toString(), arg0.getNode().getValue(), xid);
1635
1636         // Create multipart request header
1637         MultipartRequestInputBuilder mprInput = new MultipartRequestInputBuilder();
1638         mprInput.setType(MultipartType.OFPMPQUEUE);
1639         mprInput.setVersion(version);
1640         mprInput.setXid(xid);
1641         mprInput.setFlags(new MultipartRequestFlags(false));
1642
1643         // Create multipart request body to fetch stats for all the port of the
1644         // node
1645         MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
1646         MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
1647         // Select specific queue
1648         mprQueueBuilder.setQueueId(arg0.getQueueId().getValue());
1649         // Select specific port
1650         mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(arg0.getNodeConnectorId()));
1651
1652         caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
1653
1654         // Set request body to main multipart request
1655         mprInput.setMultipartRequestBody(caseBuilder.build());
1656
1657         // Send the request, no cookies associated, use any connection
1658         LOG.debug("Send queue statistics request :{}", mprQueueBuilder.build().toString());
1659         this.messageService.multipartRequest(mprInput.build(), null);
1660
1661         // Prepare rpc return output. Set xid and send it back.
1662         GetQueueStatisticsFromGivenPortOutputBuilder output = new GetQueueStatisticsFromGivenPortOutputBuilder();
1663         output.setTransactionId(generateTransactionId(xid));
1664         output.setQueueIdAndStatisticsMap(null);
1665
1666         Collection<RpcError> errors = Collections.emptyList();
1667         RpcResult<GetQueueStatisticsFromGivenPortOutput> rpcResult = Rpcs.getRpcResult(true, output.build(), errors);
1668         return Futures.immediateFuture(rpcResult);
1669     }
1670     
1671     /**
1672      * @param input
1673      * @param cookie
1674      * @param session
1675      * @param messageService 
1676      * @return barrier result
1677      */
1678     public static Future<RpcResult<BarrierOutput>> sendBarrier(
1679             SwitchConnectionDistinguisher cookie, SessionContext session, 
1680             IMessageDispatchService messageService) {
1681         BarrierInputBuilder barrierInput = new BarrierInputBuilder();
1682         barrierInput.setVersion(session.getFeatures().getVersion());
1683         barrierInput.setXid(session.getNextXid());
1684         return messageService.barrier(barrierInput.build(), cookie);
1685     }
1686
1687 }