2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.device.listener;
10 import com.google.common.util.concurrent.FutureCallback;
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.AlienMessageListener;
15 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
16 import org.opendaylight.openflowplugin.api.openflow.device.listener.OpenflowMessageListenerFacade;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyOutput;
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.MultipartReplyMessage;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class OpenflowProtocolListenerFullImpl implements AlienMessageListener, OpenflowMessageListenerFacade {
34 private static final Logger LOG = LoggerFactory.getLogger(OpenflowProtocolListenerFullImpl.class);
36 private final ConnectionAdapter connectionAdapter;
37 private final DeviceReplyProcessor deviceReplyProcessor;
42 * @param connectionAdapter - connection adapter
43 * @param deviceReplyProcessor - device replay processor
45 public OpenflowProtocolListenerFullImpl(final ConnectionAdapter connectionAdapter,
46 final DeviceReplyProcessor deviceReplyProcessor) {
47 this.connectionAdapter = connectionAdapter;
48 this.deviceReplyProcessor = deviceReplyProcessor;
52 public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) {
53 final var xid = echoRequestMessage.getXid();
54 LOG.debug("echo request received: {}", xid);
55 Futures.addCallback(connectionAdapter.echoReply(
56 new EchoReplyInputBuilder()
57 .setVersion(echoRequestMessage.getVersion())
59 .setData(echoRequestMessage.getData())
61 new FutureCallback<>() {
63 public void onSuccess(final RpcResult<EchoReplyOutput> result) {
64 LOG.debug("echo reply sent: {}", xid);
68 public void onFailure(final Throwable cause) {
69 LOG.debug("echo reply failed: {}", xid, cause);
71 }, MoreExecutors.directExecutor());
75 public void onErrorMessage(final ErrorMessage notification) {
76 deviceReplyProcessor.processReply(notification);
80 public void onExperimenterMessage(final ExperimenterMessage notification) {
81 LOG.trace("Received experiementer message: {}", notification.getClass());
82 deviceReplyProcessor.processExperimenterMessage(notification);
86 public void onFlowRemovedMessage(final FlowRemovedMessage notification) {
87 deviceReplyProcessor.processFlowRemovedMessage(notification);
91 public void onHelloMessage(final HelloMessage hello) {
92 LOG.warn("hello message received outside handshake phase -> dropping connection {}",
93 connectionAdapter.getRemoteAddress());
94 connectionAdapter.disconnect();
98 public void onMultipartReplyMessage(final MultipartReplyMessage notification) {
99 if (LOG.isTraceEnabled()) {
100 LOG.trace("Multipart Reply with XID: {}", notification.getXid());
102 // multiMsgCollector.addMultipartMsg(notification);
106 public void onPacketInMessage(final PacketInMessage notification) {
107 deviceReplyProcessor.processPacketInMessage(notification);
111 public void onPortStatusMessage(final PortStatusMessage notification) {
112 deviceReplyProcessor.processPortStatusMessage(notification);
116 public boolean onAlienMessage(final OfHeader message) {
117 return deviceReplyProcessor.processAlienMessage(message);