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