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