DeviceContext proposal
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / device / DeviceManagerImpl.java
1 /**
2  * Copyright (c) 2015 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.impl.device;
9
10 import java.util.concurrent.ExecutionException;
11
12 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
14 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
15 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
16 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextReadyHandler;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCaseBuilder;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import com.google.common.util.concurrent.Futures;
27 import com.google.common.util.concurrent.ListenableFuture;
28
29 /**
30  * 
31  */
32 public class DeviceManagerImpl implements DeviceManager {
33     
34     private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
35     
36     private Xid xid;
37
38     @Override
39     public void deviceConnected(ConnectionContext connectionContext) {
40         xid = new Xid(0L);
41         DeviceContextImpl deviceContextImpl = new DeviceContextImpl();
42
43         try {
44             FlowCapableNode description = queryDescription(connectionContext, xid.getNextValue()).get();
45             
46         } catch (InterruptedException | ExecutionException e) {
47             // TODO Auto-generated catch block
48             LOG.info("Failed to retrieve node static info: {}", e.getMessage());
49         }
50     }
51
52     /**
53      * @param connectionContext 
54      * @param nextXid 
55      */
56     private static ListenableFuture<FlowCapableNode> queryDescription(ConnectionContext connectionContext, long nextXid) {
57         MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
58         builder.setType(MultipartType.OFPMPDESC);
59         builder.setVersion(connectionContext.getFeatures().getVersion());
60         builder.setFlags(new MultipartRequestFlags(false));
61         builder.setMultipartRequestBody(new MultipartRequestDescCaseBuilder()
62                 .build());
63         builder.setXid(nextXid);
64         connectionContext.getConnectionAdapter().multipartRequest(builder.build());
65         
66         //TODO: involve general wait-for-answer mechanism and return future with complete value
67         //TODO: translate message
68         return Futures.immediateFuture(null); 
69     }
70
71     @Override
72     public void sendMessage(DataObject dataObject, RequestContext requestContext) {
73         // TODO Auto-generated method stub
74
75     }
76
77     @Override
78     public Xid sendRequest(DataObject dataObject, RequestContext requestContext) {
79         // TODO Auto-generated method stub
80         return null;
81     }
82
83     @Override
84     public void addRequestContextReadyHandler(DeviceContextReadyHandler deviceContextReadyHandler) {
85         // TODO Auto-generated method stub
86
87     }
88
89 }