OPNFLWPLUG-1071 : Removal of javax.annotation.Nonnnull and replacement of javax.annot...
[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 org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
11 import org.opendaylight.openflowjava.protocol.api.extensibility.AlienMessageListener;
12 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
13 import org.opendaylight.openflowplugin.api.openflow.device.listener.OpenflowMessageListenerFacade;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 public class OpenflowProtocolListenerFullImpl implements AlienMessageListener, OpenflowMessageListenerFacade {
28
29     private static final Logger LOG = LoggerFactory.getLogger(OpenflowProtocolListenerFullImpl.class);
30
31     private final ConnectionAdapter connectionAdapter;
32     private final DeviceReplyProcessor deviceReplyProcessor;
33
34     /**
35      * Constructor.
36      *
37      * @param connectionAdapter - connection adapter
38      * @param deviceReplyProcessor - device replay processor
39      */
40     public OpenflowProtocolListenerFullImpl(final ConnectionAdapter connectionAdapter,
41                                             final DeviceReplyProcessor deviceReplyProcessor) {
42         this.connectionAdapter = connectionAdapter;
43         this.deviceReplyProcessor = deviceReplyProcessor;
44     }
45
46     @Override
47     public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) {
48         if (LOG.isDebugEnabled()) {
49             LOG.debug("echo request received: {}", echoRequestMessage.getXid());
50         }
51         final EchoReplyInputBuilder builder = new EchoReplyInputBuilder();
52         builder.setVersion(echoRequestMessage.getVersion());
53         builder.setXid(echoRequestMessage.getXid());
54         builder.setData(echoRequestMessage.getData());
55
56         connectionAdapter.echoReply(builder.build());
57     }
58
59     @Override
60     public void onErrorMessage(final ErrorMessage notification) {
61         deviceReplyProcessor.processReply(notification);
62     }
63
64     @Override
65     public void onExperimenterMessage(final ExperimenterMessage notification) {
66         LOG.trace("Received experiementer message: {}", notification.getClass());
67         deviceReplyProcessor.processExperimenterMessage(notification);
68     }
69
70     @Override
71     public void onFlowRemovedMessage(final FlowRemovedMessage notification) {
72         deviceReplyProcessor.processFlowRemovedMessage(notification);
73     }
74
75     @Override
76     public void onHelloMessage(final HelloMessage hello) {
77         LOG.warn("hello message received outside handshake phase -> dropping connection {}",
78                 connectionAdapter.getRemoteAddress());
79         connectionAdapter.disconnect();
80     }
81
82     @Override
83     public void onMultipartReplyMessage(final MultipartReplyMessage notification) {
84         if (LOG.isTraceEnabled()) {
85             LOG.trace("Multipart Reply with XID: {}", notification.getXid());
86         }
87         // multiMsgCollector.addMultipartMsg(notification);
88     }
89
90     @Override
91     public void onPacketInMessage(final PacketInMessage notification) {
92         deviceReplyProcessor.processPacketInMessage(notification);
93     }
94
95     @Override
96     public void onPortStatusMessage(final PortStatusMessage notification) {
97         deviceReplyProcessor.processPortStatusMessage(notification);
98     }
99
100     @Override
101     public boolean onAlienMessage(final OfHeader message) {
102         return deviceReplyProcessor.processAlienMessage(message);
103     }
104
105 }