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 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.handlers.MultiMsgCollector;
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.MultipartReply;
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.OpenflowProtocolListener;
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 import javax.annotation.Nonnull;
31 public class OpenflowProtocolListenerFullImpl implements OpenflowProtocolListener, MultiMsgCollector {
33 private static final Logger LOG = LoggerFactory.getLogger(OpenflowProtocolListenerFullImpl.class);
35 private final ConnectionAdapter connectionAdapter;
36 private DeviceReplyProcessor deviceReplyProcessor;
37 private final MultiMsgCollectorImpl multiMsgCollector;
40 * @param connectionAdapter
41 * @param deviceReplyProcessor
43 public OpenflowProtocolListenerFullImpl(final ConnectionAdapter connectionAdapter, final DeviceReplyProcessor deviceReplyProcessor) {
44 this.connectionAdapter = connectionAdapter;
45 this.deviceReplyProcessor = deviceReplyProcessor;
46 multiMsgCollector = new MultiMsgCollectorImpl();
47 multiMsgCollector.setDeviceReplyProcessor(deviceReplyProcessor);
51 public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) {
52 LOG.debug("echo request received: {}", echoRequestMessage.getXid());
53 final EchoReplyInputBuilder builder = new EchoReplyInputBuilder();
54 builder.setVersion(echoRequestMessage.getVersion());
55 builder.setXid(echoRequestMessage.getXid());
56 builder.setData(echoRequestMessage.getData());
58 connectionAdapter.echoReply(builder.build());
62 public void onErrorMessage(final ErrorMessage notification) {
63 deviceReplyProcessor.processReply(notification);
67 public void onExperimenterMessage(final ExperimenterMessage notification) {
68 // TODO Auto-generated method stub
73 public void onFlowRemovedMessage(final FlowRemovedMessage notification) {
74 deviceReplyProcessor.processFlowRemovedMessage(notification);
78 public void onHelloMessage(final HelloMessage hello) {
79 // FIXME: invalid state - must disconnect and close all contexts
83 public void onMultipartReplyMessage(final MultipartReplyMessage notification) {
84 LOG.trace("Multipart Reply with XID: {}", notification.getXid());
85 multiMsgCollector.addMultipartMsg(notification);
89 public void onPacketInMessage(final PacketInMessage notification) {
90 deviceReplyProcessor.processPacketInMessage(notification);
94 public void onPortStatusMessage(final PortStatusMessage notification) {
95 deviceReplyProcessor.processPortStatusMessage(notification);
99 public void registerMultipartXid(final long xid) {
100 multiMsgCollector.registerMultipartXid(xid);
104 public void addMultipartMsg(@Nonnull final MultipartReply reply) {
105 multiMsgCollector.addMultipartMsg(reply);
109 public void setDeviceReplyProcessor(final DeviceReplyProcessor deviceReplyProcessor) {
110 this.deviceReplyProcessor = deviceReplyProcessor;