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