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