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