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.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;
35 public class OpenflowProtocolListenerFullImpl implements OpenflowProtocolListener, MultiMsgCollector {
37 private static final Logger LOG = LoggerFactory.getLogger(OpenflowProtocolListenerFullImpl.class);
39 private final ConnectionAdapter connectionAdapter;
40 private final DeviceReplyProcessor deviceReplyProcessor;
41 private final MultiMsgCollectorImpl multiMsgCollector;
44 * @param connectionAdapter
45 * @param deviceReplyProcessor
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);
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());
62 connectionAdapter.echoReply(builder.build());
66 public void onErrorMessage(final ErrorMessage notification) {
67 deviceReplyProcessor.processReply(notification);
71 public void onExperimenterMessage(final ExperimenterMessage notification) {
72 // TODO Auto-generated method stub
77 public void onFlowRemovedMessage(final FlowRemovedMessage notification) {
78 deviceReplyProcessor.processFlowRemovedMessage(notification);
82 public void onHelloMessage(final HelloMessage hello) {
83 // FIXME: invalid state - must disconnect and close all contexts
87 public void onMultipartReplyMessage(final MultipartReplyMessage notification) {
88 LOG.trace("Multipart Reply with XID: {}", notification.getXid());
89 multiMsgCollector.addMultipartMsg(notification);
93 public void onPacketInMessage(final PacketInMessage notification) {
94 deviceReplyProcessor.processPacketInMessage(notification);
98 public void onPortStatusMessage(final PortStatusMessage notification) {
99 deviceReplyProcessor.processPortStatusMessage(notification);
103 public ListenableFuture<Collection<MultipartReply>> registerMultipartMsg(final long xid) {
104 return multiMsgCollector.registerMultipartMsg(xid);
108 public void registerMultipartFutureMsg(final long xid, @CheckForNull final SettableFuture<Collection<MultipartReply>> future) {
109 multiMsgCollector.registerMultipartFutureMsg(xid, future);
113 public void addMultipartMsg(@Nonnull final MultipartReply reply) {
114 multiMsgCollector.addMultipartMsg(reply);