Stores and gets IP address of a flow capable node
[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.net.Inet4Address;
11 import java.net.Inet6Address;
12 import java.net.InetAddress;
13 import java.net.InetSocketAddress;
14 import java.util.concurrent.Future;
15 import java.util.concurrent.TimeUnit;
16
17 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
18 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor;
20 import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
21 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
22 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
23 import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.GetNodeIpAddressInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.GetNodeIpAddressOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.GetNodeIpAddressOutputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.ConnectionCookie;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
95 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
96 import org.opendaylight.yangtools.yang.common.RpcResult;
97 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
98 import org.slf4j.Logger;
99
100 import com.google.common.util.concurrent.Futures;
101 import com.google.common.util.concurrent.ListenableFuture;
102
103 /**
104  * RPC implementation of MD-switch
105  */
106 public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch {
107
108     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(ModelDrivenSwitchImpl.class);
109     private final NodeId nodeId;
110     private final IMessageDispatchService messageService;
111     private short version = 0;
112     private NotificationProviderService rpcNotificationProviderService;
113     private OFRpcTaskContext rpcTaskContext;
114     
115     // TODO:read timeout from configSubsystem
116     protected long maxTimeout = 1000;
117     protected TimeUnit maxTimeoutUnit = TimeUnit.MILLISECONDS;
118     
119     protected ModelDrivenSwitchImpl(final NodeId nodeId, final InstanceIdentifier<Node> identifier, 
120             final SessionContext sessionContext) {
121         super(identifier, sessionContext);
122         this.nodeId = nodeId;
123         messageService = sessionContext.getMessageDispatchService();
124         version = sessionContext.getPrimaryConductor().getVersion();
125         rpcNotificationProviderService = OFSessionUtil.getSessionManager().getNotificationProviderService();
126         
127         rpcTaskContext = new OFRpcTaskContext();
128         rpcTaskContext.setSession(sessionContext);
129         rpcTaskContext.setMessageService(messageService);
130         rpcTaskContext.setRpcNotificationProviderService(rpcNotificationProviderService);
131         rpcTaskContext.setMaxTimeout(maxTimeout);
132         rpcTaskContext.setMaxTimeoutUnit(maxTimeoutUnit);
133         rpcTaskContext.setRpcPool(OFSessionUtil.getSessionManager().getRpcPool());
134         rpcTaskContext.setMessageSpy(OFSessionUtil.getSessionManager().getMessageSpy());
135     }
136
137     @Override
138     public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
139         LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
140         // use primary connection
141         SwitchConnectionDistinguisher cookie = null;
142         
143         OFRpcTask<AddFlowInput, RpcResult<UpdateFlowOutput>> task = 
144                 OFRpcTaskFactory.createAddFlowTask(rpcTaskContext, input, cookie);
145         ListenableFuture<RpcResult<UpdateFlowOutput>> result = task.submit();
146         
147         return Futures.transform(result, OFRpcFutureResultTransformFactory.createForAddFlowOutput());
148     }
149
150
151     @Override
152     public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
153         LOG.debug("Calling the GroupMod RPC method on MessageDispatchService");
154         
155         // use primary connection
156         SwitchConnectionDistinguisher cookie = null;
157         
158         OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> task = 
159                 OFRpcTaskFactory.createAddGroupTask(rpcTaskContext, input, cookie);
160         ListenableFuture<RpcResult<UpdateGroupOutput>> result = task.submit();
161         
162         return Futures.transform(result, OFRpcFutureResultTransformFactory.createForAddGroupOutput());
163     }
164
165     @Override
166     public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
167         LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
168         
169         // use primary connection
170         SwitchConnectionDistinguisher cookie = null;
171         
172         OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> task = 
173                 OFRpcTaskFactory.createAddMeterTask(rpcTaskContext, input, cookie);
174         ListenableFuture<RpcResult<UpdateMeterOutput>> result = task.submit();
175         
176         return Futures.transform(result, OFRpcFutureResultTransformFactory.createForAddMeterOutput());
177     }
178
179     @Override
180     public Future<RpcResult<RemoveFlowOutput>> removeFlow(final RemoveFlowInput input) {
181         LOG.debug("Calling the removeFlow RPC method on MessageDispatchService");
182         
183         // use primary connection
184         SwitchConnectionDistinguisher cookie = null;
185         OFRpcTask<RemoveFlowInput, RpcResult<UpdateFlowOutput>> task = 
186                 OFRpcTaskFactory.createRemoveFlowTask(rpcTaskContext, input, cookie);
187         ListenableFuture<RpcResult<UpdateFlowOutput>> result = task.submit();
188
189         return Futures.transform(result, OFRpcFutureResultTransformFactory.createForRemoveFlowOutput());
190     }
191
192     @Override
193     public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
194         LOG.debug("Calling the Remove Group RPC method on MessageDispatchService");
195
196         SwitchConnectionDistinguisher cookie = null;
197         OFRpcTask<RemoveGroupInput, RpcResult<UpdateGroupOutput>> task = 
198                 OFRpcTaskFactory.createRemoveGroupTask(rpcTaskContext, input, cookie);
199         ListenableFuture<RpcResult<UpdateGroupOutput>> result = task.submit();
200         
201         return Futures.transform(result, OFRpcFutureResultTransformFactory.createForRemoveGroupOutput());
202     }
203
204     @Override
205     public Future<RpcResult<RemoveMeterOutput>> removeMeter(final RemoveMeterInput input) {
206         LOG.debug("Calling the Remove MeterMod RPC method on MessageDispatchService");
207
208         SwitchConnectionDistinguisher cookie = null;
209         OFRpcTask<RemoveMeterInput, RpcResult<UpdateMeterOutput>> task = 
210                 OFRpcTaskFactory.createRemoveMeterTask(rpcTaskContext, input, cookie);
211         ListenableFuture<RpcResult<UpdateMeterOutput>> result = task.submit();
212         
213         return Futures.transform(result, OFRpcFutureResultTransformFactory.createForRemoveMeterOutput());
214     }
215
216     @Override
217     public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) {
218         LOG.debug("TransmitPacket - {}", input);
219         // Convert TransmitPacket to PacketOutInput
220         PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, sessionContext.getNextXid(),
221                 sessionContext.getFeatures().getDatapathId());
222
223         SwitchConnectionDistinguisher cookie = null;
224         ConnectionCookie connectionCookie = input.getConnectionCookie();
225         if (connectionCookie != null && connectionCookie.getValue() != null) {
226             cookie = new SwitchConnectionCookieOFImpl(connectionCookie.getValue());
227         }
228
229         LOG.debug("Calling the transmitPacket RPC method");
230         return messageService.packetOut(message, cookie);
231     }
232
233     @Override
234     public Future<RpcResult<UpdateFlowOutput>> updateFlow(final UpdateFlowInput input) {
235         LOG.debug("Calling the updateFlow RPC method on MessageDispatchService");
236         
237         // use primary connection
238         SwitchConnectionDistinguisher cookie = null;
239         
240         OFRpcTask<UpdateFlowInput, RpcResult<UpdateFlowOutput>> task = 
241                 OFRpcTaskFactory.createUpdateFlowTask(rpcTaskContext, input, cookie);
242         ListenableFuture<RpcResult<UpdateFlowOutput>> result = task.submit();
243         
244         return result;
245     }
246
247     @Override
248     public Future<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
249         LOG.debug("Calling the update Group Mod RPC method on MessageDispatchService");
250         
251         // use primary connection
252         SwitchConnectionDistinguisher cookie = null;
253         
254         OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> task = 
255                 OFRpcTaskFactory.createUpdateGroupTask(rpcTaskContext, input, cookie);
256         ListenableFuture<RpcResult<UpdateGroupOutput>> result = task.submit();
257         
258         return result;
259     }
260
261     @Override
262     public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
263         LOG.debug("Calling the MeterMod RPC method on MessageDispatchService");
264         
265         // use primary connection
266         SwitchConnectionDistinguisher cookie = null;
267         
268         OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> task = 
269                 OFRpcTaskFactory.createUpdateMeterTask(rpcTaskContext, input, cookie);
270         ListenableFuture<RpcResult<UpdateMeterOutput>> result = task.submit();
271         
272         return result;
273     }
274
275     @Override
276     public NodeId getNodeId() {
277         return nodeId;
278     }
279
280     
281     @Override
282     public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(final GetAllGroupStatisticsInput input) {
283      // use primary connection
284         LOG.debug("Calling the getAllGroupStatistics RPC method on MessageDispatchService");
285         SwitchConnectionDistinguisher cookie = null;
286         
287         OFRpcTask<GetAllGroupStatisticsInput, RpcResult<GetAllGroupStatisticsOutput>> task = 
288                 OFRpcTaskFactory.createGetAllGroupStatisticsTask(rpcTaskContext, input, cookie);
289         ListenableFuture<RpcResult<GetAllGroupStatisticsOutput>> result = task.submit();
290         
291         return result;
292
293     }
294
295     @Override
296     public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(final GetGroupDescriptionInput input) {
297         LOG.debug("Calling the getGroupDescription RPC method on MessageDispatchService");
298         SwitchConnectionDistinguisher cookie = null;
299         
300         OFRpcTask<GetGroupDescriptionInput, RpcResult<GetGroupDescriptionOutput>> task = 
301                 OFRpcTaskFactory.createGetGroupDescriptionTask(rpcTaskContext, input, cookie);
302         ListenableFuture<RpcResult<GetGroupDescriptionOutput>> result = task.submit();
303         return result;
304     }
305     
306     @Override
307     public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(final GetGroupFeaturesInput input) {
308         LOG.debug("Calling the getGroupFeatures RPC method on MessageDispatchService");
309         SwitchConnectionDistinguisher cookie = null;
310         
311         OFRpcTask<GetGroupFeaturesInput, RpcResult<GetGroupFeaturesOutput>> task = 
312                 OFRpcTaskFactory.createGetGroupFeaturesTask(rpcTaskContext, input, cookie);
313         ListenableFuture<RpcResult<GetGroupFeaturesOutput>> result = task.submit();
314         return result;
315     }
316     
317     @Override
318     public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(final GetGroupStatisticsInput input) {
319         LOG.debug("Calling the getGroupStatistics RPC method on MessageDispatchService");
320         SwitchConnectionDistinguisher cookie = null;
321         
322         OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> task = 
323                 OFRpcTaskFactory.createGetGroupStatisticsTask(rpcTaskContext, input, cookie);
324         ListenableFuture<RpcResult<GetGroupStatisticsOutput>> result = task.submit();
325         return result;
326     }
327
328     @Override
329     public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
330             final GetAllMeterConfigStatisticsInput input) {
331         LOG.debug("Calling the getAllMeterConfigStatistics RPC method on MessageDispatchService");
332         SwitchConnectionDistinguisher cookie = null;
333         
334         OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> task = 
335                 OFRpcTaskFactory.createGetAllMeterConfigStatisticsTask(rpcTaskContext, input, cookie);
336         ListenableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> result = task.submit();
337         return result;
338     }
339     
340     @Override
341     public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(
342             final GetAllMeterStatisticsInput input) {
343         LOG.debug("Calling the getAllMeterStatistics RPC method on MessageDispatchService");
344         SwitchConnectionDistinguisher cookie = null;
345         
346         OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> task = 
347                 OFRpcTaskFactory.createGetAllMeterStatisticsTask(rpcTaskContext, input, cookie);
348         ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = task.submit();
349         return result;
350     }
351     
352     @Override
353     public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(
354             final GetMeterFeaturesInput input) {
355         LOG.debug("Calling the getMeterFeatures RPC method on MessageDispatchService");
356         SwitchConnectionDistinguisher cookie = null;
357         
358         OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> task = 
359                 OFRpcTaskFactory.createGetMeterFeaturesTask(rpcTaskContext, input, cookie);
360         ListenableFuture<RpcResult<GetMeterFeaturesOutput>> result = task.submit();
361         return result;
362     }
363     
364     @Override
365     public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(
366             final GetMeterStatisticsInput input) {
367         LOG.debug("Calling the getMeterStatistics RPC method on MessageDispatchService");
368         SwitchConnectionDistinguisher cookie = null;
369         
370         OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> task = 
371                 OFRpcTaskFactory.createGetMeterStatisticsTask(rpcTaskContext, input, cookie);
372         ListenableFuture<RpcResult<GetMeterStatisticsOutput>> result = task.submit();
373         return result;
374     }
375     
376     @Override
377     public Future<RpcResult<GetAllNodeConnectorsStatisticsOutput>> getAllNodeConnectorsStatistics(
378             final GetAllNodeConnectorsStatisticsInput input) {
379         LOG.debug("Calling the getAllNodeConnectorsStatistics RPC method on MessageDispatchService");
380         SwitchConnectionDistinguisher cookie = null;
381         
382         OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>> task = 
383                 OFRpcTaskFactory.createGetAllNodeConnectorsStatisticsTask(rpcTaskContext, input, cookie);
384         ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> result = task.submit();
385         return result;
386     }
387     
388     @Override
389     public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(
390             final GetNodeConnectorStatisticsInput input) {
391         LOG.debug("Calling the getNodeConnectorStatistics RPC method on MessageDispatchService");
392         SwitchConnectionDistinguisher cookie = null;
393         
394         OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>> task = 
395                 OFRpcTaskFactory.createGetNodeConnectorStatisticsTask(rpcTaskContext, input, cookie);
396         ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> result = task.submit();
397         return result;
398     }
399     
400     @Override
401     public Future<RpcResult<UpdatePortOutput>> updatePort(final UpdatePortInput input) {
402         LOG.debug("Calling the updatePort RPC method on MessageDispatchService");
403         
404         // use primary connection
405         SwitchConnectionDistinguisher cookie = null;
406         
407         OFRpcTask<UpdatePortInput, RpcResult<UpdatePortOutput>> task = 
408                 OFRpcTaskFactory.createUpdatePortTask(rpcTaskContext, input, cookie);
409         ListenableFuture<RpcResult<UpdatePortOutput>> result = task.submit();
410         
411         return result;
412     }
413
414     @Override
415     public Future<RpcResult<UpdateTableOutput>> updateTable(final UpdateTableInput input) {
416         LOG.debug("Calling the updateTable RPC method on MessageDispatchService");
417         
418         SwitchConnectionDistinguisher cookie = null;
419         
420         OFRpcTask<UpdateTableInput, RpcResult<UpdateTableOutput>> task = 
421                 OFRpcTaskFactory.createUpdateTableTask(rpcTaskContext, input, cookie);
422         ListenableFuture<RpcResult<UpdateTableOutput>> result = task.submit();
423         
424         return result;
425     }
426
427     @Override
428     public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
429             final GetAllFlowStatisticsFromFlowTableInput input) {
430         LOG.debug("Calling the getAllFlowStatisticsFromFlowTable RPC method on MessageDispatchService");
431         SwitchConnectionDistinguisher cookie = null;
432         
433         OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> task = 
434                 OFRpcTaskFactory.createGetAllFlowStatisticsFromFlowTableTask(rpcTaskContext, input, cookie);
435         ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> result = task.submit();
436         return result;
437     }
438     
439     @Override
440     public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
441             final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
442         LOG.debug("Calling the getAllFlowsStatisticsFromAllFlowTables RPC method on MessageDispatchService");
443         SwitchConnectionDistinguisher cookie = null;
444         
445         OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput, RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> task = 
446                 OFRpcTaskFactory.createGetAllFlowsStatisticsFromAllFlowTablesTask(rpcTaskContext, input, cookie);
447         ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> result = task.submit();
448         return result;
449     }
450     
451     @Override
452     public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
453             final GetFlowStatisticsFromFlowTableInput input) {
454         LOG.debug("Calling the getFlowStatisticsFromFlowTable RPC method on MessageDispatchService");
455         SwitchConnectionDistinguisher cookie = null;
456         
457         OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>> task = 
458                 OFRpcTaskFactory.createGetFlowStatisticsFromFlowTableTask(rpcTaskContext, input, cookie);
459         ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> result = task.submit();
460         return result;
461     }
462     
463     @Override
464     public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
465             final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
466         LOG.debug("Calling the getAggregateFlowStatisticsFromFlowTableForAllFlows RPC method on MessageDispatchService");
467         SwitchConnectionDistinguisher cookie = null;
468         
469         OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> task = 
470                 OFRpcTaskFactory.createGetAggregateFlowStatisticsFromFlowTableForAllFlowsTask(rpcTaskContext, input, cookie);
471         ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> result = task.submit();
472         return result;
473     }
474     
475     @Override
476     public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
477             final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
478         LOG.debug("Calling the getAggregateFlowStatisticsFromFlowTableForGivenMatch RPC method on MessageDispatchService");
479         SwitchConnectionDistinguisher cookie = null;
480         
481         OFRpcTask<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> task = 
482                 OFRpcTaskFactory.createGetAggregateFlowStatisticsFromFlowTableForGivenMatchTask(rpcTaskContext, input, cookie);
483         ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> result = task.submit();
484         return result;
485     }
486     
487     @Override
488     public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(
489             final GetFlowTablesStatisticsInput input) {
490         LOG.debug("Calling the getFlowTablesStatistics RPC method on MessageDispatchService");
491         SwitchConnectionDistinguisher cookie = null;
492         
493         OFRpcTask<GetFlowTablesStatisticsInput, RpcResult<GetFlowTablesStatisticsOutput>> task = 
494                 OFRpcTaskFactory.createGetFlowTablesStatisticsTask(rpcTaskContext, input, cookie);
495         ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> result = task.submit();
496         return result;
497     }
498     
499     @Override
500     public Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> getAllQueuesStatisticsFromAllPorts(
501             final GetAllQueuesStatisticsFromAllPortsInput input) {
502         LOG.debug("Calling the getAllQueuesStatisticsFromAllPorts RPC method on MessageDispatchService");
503         SwitchConnectionDistinguisher cookie = null;
504         
505         OFRpcTask<GetAllQueuesStatisticsFromAllPortsInput, RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> task = 
506                 OFRpcTaskFactory.createGetAllQueuesStatisticsFromAllPortsTask(rpcTaskContext, input, cookie);
507         ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> result = task.submit();
508         return result;
509     }
510     
511     @Override
512     public Future<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> getAllQueuesStatisticsFromGivenPort(
513             final GetAllQueuesStatisticsFromGivenPortInput input) {
514         LOG.debug("Calling the getAllQueuesStatisticsFromGivenPort RPC method on MessageDispatchService");
515         SwitchConnectionDistinguisher cookie = null;
516         
517         OFRpcTask<GetAllQueuesStatisticsFromGivenPortInput, RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> task = 
518                 OFRpcTaskFactory.createGetAllQueuesStatisticsFromGivenPortTask(rpcTaskContext, input, cookie);
519         ListenableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> result = task.submit();
520         return result;
521     }
522     
523     @Override
524     public Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> getQueueStatisticsFromGivenPort(
525             final GetQueueStatisticsFromGivenPortInput input) {
526         LOG.debug("Calling the getQueueStatisticsFromGivenPort RPC method on MessageDispatchService");
527         SwitchConnectionDistinguisher cookie = null;
528         
529         OFRpcTask<GetQueueStatisticsFromGivenPortInput, RpcResult<GetQueueStatisticsFromGivenPortOutput>> task = 
530                 OFRpcTaskFactory.createGetQueueStatisticsFromGivenPortTask(rpcTaskContext, input, cookie);
531         ListenableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> result = task.submit();
532         return result;
533     }
534
535     @Override
536     public Future<RpcResult<GetNodeIpAddressOutput>> getNodeIpAddress(GetNodeIpAddressInput input) {
537         if (!sessionContext.isValid()) {
538             return Futures.immediateFuture(RpcResultBuilder
539                     .<GetNodeIpAddressOutput> failed()
540                     .withError(org.opendaylight.yangtools.yang.common.RpcError.ErrorType.TRANSPORT,
541                             "Session is not valid.").build());
542         }
543         InetSocketAddress remoteAddress = sessionContext.getPrimaryConductor().getConnectionAdapter()
544                 .getRemoteAddress();
545         if (remoteAddress == null) {
546             return Futures.immediateFuture(RpcResultBuilder
547                     .<GetNodeIpAddressOutput> failed()
548                     .withError(org.opendaylight.yangtools.yang.common.RpcError.ErrorType.TRANSPORT,
549                             "No connection with switch.").build());
550         }
551         IpAddress ipAddress = resolveIpAddress(remoteAddress.getAddress());
552         GetNodeIpAddressOutput result = new GetNodeIpAddressOutputBuilder().setIpAddress(ipAddress).build();
553         return Futures.immediateFuture(RpcResultBuilder.<GetNodeIpAddressOutput> success(result).build());
554     }
555
556     private static IpAddress resolveIpAddress(InetAddress address) {
557         String hostAddress = address.getHostAddress();
558         if (address instanceof Inet4Address) {
559             return new IpAddress(new Ipv4Address(hostAddress));
560         }
561         if (address instanceof Inet6Address) {
562             return new IpAddress(new Ipv6Address(hostAddress));
563         }
564         throw new IllegalArgumentException("Unsupported IP address type!");
565     }
566 }