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