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