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.annotations.VisibleForTesting;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
13 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
14 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
15 import org.opendaylight.openflowplugin.api.openflow.device.listener.OpenflowMessageListenerFacade;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
32 public class OpenflowProtocolListenerFullImpl implements OpenflowMessageListenerFacade {
34 private static final Logger LOG = LoggerFactory.getLogger(OpenflowProtocolListenerFullImpl.class);
36 private final ConnectionAdapter connectionAdapter;
37 private DeviceReplyProcessor deviceReplyProcessor;
38 private MultiMsgCollector multiMsgCollector;
41 * @param connectionAdapter
42 * @param deviceReplyProcessor
44 public OpenflowProtocolListenerFullImpl(final ConnectionAdapter connectionAdapter, final DeviceReplyProcessor deviceReplyProcessor) {
45 this.connectionAdapter = connectionAdapter;
46 this.deviceReplyProcessor = deviceReplyProcessor;
47 multiMsgCollector = new MultiMsgCollectorImpl();
48 multiMsgCollector.setDeviceReplyProcessor(deviceReplyProcessor);
52 public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) {
53 LOG.debug("echo request received: {}", echoRequestMessage.getXid());
54 final EchoReplyInputBuilder builder = new EchoReplyInputBuilder();
55 builder.setVersion(echoRequestMessage.getVersion());
56 builder.setXid(echoRequestMessage.getXid());
57 builder.setData(echoRequestMessage.getData());
59 connectionAdapter.echoReply(builder.build());
63 public void onErrorMessage(final ErrorMessage notification) {
64 deviceReplyProcessor.processReply(notification);
68 public void onExperimenterMessage(final ExperimenterMessage notification) {
69 // TODO Auto-generated method stub
74 public void onFlowRemovedMessage(final FlowRemovedMessage notification) {
75 deviceReplyProcessor.processFlowRemovedMessage(notification);
79 public void onHelloMessage(final HelloMessage hello) {
80 // FIXME: invalid state - must disconnect and close all contexts
84 public void onMultipartReplyMessage(final MultipartReplyMessage notification) {
85 LOG.trace("Multipart Reply with XID: {}", notification.getXid());
86 multiMsgCollector.addMultipartMsg(notification);
90 public void onPacketInMessage(final PacketInMessage notification) {
91 deviceReplyProcessor.processPacketInMessage(notification);
95 public void onPortStatusMessage(final PortStatusMessage notification) {
96 deviceReplyProcessor.processPortStatusMessage(notification);
100 public void registerMultipartXid(final long xid) {
101 multiMsgCollector.registerMultipartXid(xid);
105 public void addMultipartMsg(@Nonnull final MultipartReply reply) {
106 // NOOP (not delegated)
110 public void setDeviceReplyProcessor(final DeviceReplyProcessor deviceReplyProcessor) {
111 this.deviceReplyProcessor = deviceReplyProcessor;
115 void setMultiMsgCollector(MultiMsgCollector multiMsgCollector) {
116 this.multiMsgCollector = multiMsgCollector;