Merge "Wiring message processing to deviceContext"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / device / listener / OpenflowProtocolListenerFullImpl.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.listener;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import com.google.common.util.concurrent.SettableFuture;
12 import java.util.Collection;
13 import javax.annotation.CheckForNull;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
16 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
17 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  *
34  */
35 public class OpenflowProtocolListenerFullImpl implements OpenflowProtocolListener, MultiMsgCollector {
36
37     private static final Logger LOG = LoggerFactory.getLogger(OpenflowProtocolListenerFullImpl.class);
38
39     private final ConnectionAdapter connectionAdapter;
40     private final DeviceReplyProcessor deviceReplyProcessor;
41     private final MultiMsgCollectorImpl multiMsgCollector;
42
43     /**
44      * @param connectionAdapter
45      * @param deviceReplyProcessor
46      */
47     public OpenflowProtocolListenerFullImpl(final ConnectionAdapter connectionAdapter, final DeviceReplyProcessor deviceReplyProcessor) {
48         this.connectionAdapter = connectionAdapter;
49         this.deviceReplyProcessor = deviceReplyProcessor;
50         multiMsgCollector = new MultiMsgCollectorImpl();
51         multiMsgCollector.setDeviceReplyProcessor(deviceReplyProcessor);
52     }
53
54     @Override
55     public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) {
56         LOG.debug("echo request received: {}", echoRequestMessage.getXid());
57         final EchoReplyInputBuilder builder = new EchoReplyInputBuilder();
58         builder.setVersion(echoRequestMessage.getVersion());
59         builder.setXid(echoRequestMessage.getXid());
60         builder.setData(echoRequestMessage.getData());
61
62         connectionAdapter.echoReply(builder.build());
63     }
64
65     @Override
66     public void onErrorMessage(final ErrorMessage notification) {
67         deviceReplyProcessor.processReply(notification);
68     }
69
70     @Override
71     public void onExperimenterMessage(final ExperimenterMessage notification) {
72         // TODO Auto-generated method stub
73
74     }
75
76     @Override
77     public void onFlowRemovedMessage(final FlowRemovedMessage notification) {
78         deviceReplyProcessor.processFlowRemovedMessage(notification);
79     }
80
81     @Override
82     public void onHelloMessage(final HelloMessage hello) {
83         // FIXME: invalid state - must disconnect and close all contexts
84     }
85
86     @Override
87     public void onMultipartReplyMessage(final MultipartReplyMessage notification) {
88         LOG.trace("Multipart Reply with XID: {}", notification.getXid());
89         multiMsgCollector.addMultipartMsg(notification);
90     }
91
92     @Override
93     public void onPacketInMessage(final PacketInMessage notification) {
94         deviceReplyProcessor.processPacketInMessage(notification);
95     }
96
97     @Override
98     public void onPortStatusMessage(final PortStatusMessage notification) {
99         deviceReplyProcessor.processPortStatusMessage(notification);
100     }
101
102     @Override
103     public ListenableFuture<Collection<MultipartReply>> registerMultipartMsg(final long xid) {
104         return multiMsgCollector.registerMultipartMsg(xid);
105     }
106
107     @Override
108     public void registerMultipartFutureMsg(final long xid, @CheckForNull final SettableFuture<Collection<MultipartReply>> future) {
109         multiMsgCollector.registerMultipartFutureMsg(xid, future);
110     }
111
112     @Override
113     public void addMultipartMsg(@Nonnull final MultipartReply reply) {
114         multiMsgCollector.addMultipartMsg(reply);
115     }
116 }