From 0d942e8fb70b2c21f97eea3ed8904336ab5c54a4 Mon Sep 17 00:00:00 2001 From: Michal Polkorab Date: Tue, 10 Dec 2013 10:29:24 +0100 Subject: [PATCH] Copyright update Signed-off-by: Michal Polkorab Change-Id: I44fde82346500c0c054b51b0eb21ef56a97be022 --- .../api/connection/ConnectionAdapter.java | 9 +- .../connection/ConnectionConfiguration.java | 9 +- .../connection/ConnectionReadyListener.java | 9 +- .../connection/ListeningStatusProvider.java | 4 +- .../connection/SwitchConnectionHandler.java | 9 +- .../protocol/api/util/BinContent.java | 57 +- .../protocol/api/util/BinContentTest.java | 9 +- .../protocol/impl/connection/Activator.java | 9 +- .../connection/ConnectionAdapterFactory.java | 9 +- .../connection/ConnectionAdapterImpl.java | 9 +- .../impl/connection/ConnectionFacade.java | 33 +- .../impl/connection/MessageConsumer.java | 9 +- .../impl/connection/OnlineProvider.java | 9 +- .../impl/connection/RpcResponseKey.java | 9 +- .../impl/connection/ServerFacade.java | 9 +- .../impl/connection/ShutdownProvider.java | 9 +- .../SwitchConnectionProviderImpl.java | 9 +- .../impl/core/DelegatingInboundHandler.java | 135 +- .../protocol/impl/core/IdleHandler.java | 9 +- .../protocol/impl/core/OFDecoder.java | 115 +- .../protocol/impl/core/OFEncoder.java | 99 +- .../protocol/impl/core/OFFrameDecoder.java | 9 +- .../protocol/impl/core/OFVersionDetector.java | 9 +- .../core/PublishingChannelInitializer.java | 9 +- .../protocol/impl/core/SslContextFactory.java | 9 +- .../protocol/impl/core/SslKeyStore.java | 9 +- .../impl/core/SslTrustManagerFactory.java | 9 +- .../protocol/impl/core/TcpHandler.java | 9 +- .../protocol/impl/core/TlsDetector.java | 9 +- .../impl/core/VersionMessageWrapper.java | 87 +- .../impl/deserialization/DecoderTable.java | 281 +- .../DeserializationFactory.java | 87 +- .../deserialization/MessageTypeCodeKey.java | 133 +- .../impl/deserialization/OFDeserializer.java | 59 +- .../factories/BarrierReplyMessageFactory.java | 9 +- .../factories/EchoReplyMessageFactory.java | 97 +- .../factories/EchoRequestMessageFactory.java | 89 +- .../factories/ErrorMessageFactory.java | 503 ++-- .../factories/ExperimenterMessageFactory.java | 9 +- .../FeaturesReplyMessageFactory.java | 141 +- .../factories/FlowRemovedMessageFactory.java | 9 +- .../GetAsyncReplyMessageFactory.java | 275 +- .../GetConfigReplyMessageFactory.java | 9 +- .../factories/HelloMessageFactory.java | 177 +- .../MultipartReplyMessageFactory.java | 1601 +++++------ .../factories/OF10ErrorMessageFactory.java | 309 ++- .../OF10FeaturesReplyMessageFactory.java | 325 +-- .../OF10FlowRemovedMessageFactory.java | 139 +- .../factories/OF10HelloMessageFactory.java | 93 +- .../factories/OF10PacketInMessageFactory.java | 109 +- .../OF10PortStatusMessageFactory.java | 217 +- ...OF10QueueGetConfigReplyMessageFactory.java | 195 +- .../OF10StatsReplyMessageFactory.java | 549 ++-- .../factories/OF10VendorMessageFactory.java | 95 +- .../factories/PacketInMessageFactory.java | 9 +- .../factories/PortStatusMessageFactory.java | 9 +- .../QueueGetConfigReplyMessageFactory.java | 225 +- .../factories/RoleReplyMessageFactory.java | 105 +- .../impl/serialization/EncoderTable.java | 271 +- .../impl/serialization/MessageTypeKey.java | 153 +- .../impl/serialization/OFSerializer.java | 77 +- .../serialization/SerializationFactory.java | 75 +- .../factories/BarrierInputMessageFactory.java | 107 +- .../factories/EchoInputMessageFactory.java | 127 +- .../EchoReplyInputMessageFactory.java | 127 +- .../ExperimenterInputMessageFactory.java | 135 +- .../factories/FlowModInputMessageFactory.java | 177 +- .../GetAsyncRequestMessageFactory.java | 107 +- .../GetConfigInputMessageFactory.java | 111 +- .../GetFeaturesInputMessageFactory.java | 111 +- .../GetQueueConfigInputMessageFactory.java | 9 +- .../GroupModInputMessageFactory.java | 195 +- .../factories/HelloInputMessageFactory.java | 233 +- .../MeterModInputMessageFactory.java | 227 +- .../MultipartRequestInputFactory.java | 1037 +++---- .../OF10BarrierInputMessageFactory.java | 105 +- .../OF10FlowModInputMessageFactory.java | 157 +- .../OF10HelloInputMessageFactory.java | 103 +- .../OF10PacketOutInputMessageFactory.java | 137 +- .../OF10PortModInputMessageFactory.java | 207 +- ...OF10QueueGetConfigInputMessageFactory.java | 113 +- .../OF10StatsRequestInputFactory.java | 361 +-- .../OF10VendorInputMessageFactory.java | 131 +- .../PacketOutInputMessageFactory.java | 145 +- .../factories/PortModInputMessageFactory.java | 217 +- .../RoleRequestInputMessageFactory.java | 119 +- .../SetAsyncInputMessageFactory.java | 263 +- .../factories/SetConfigMessageFactory.java | 115 +- .../TableModInputMessageFactory.java | 141 +- .../impl/util/ActionsDeserializer.java | 615 ++-- .../protocol/impl/util/ActionsSerializer.java | 561 ++-- .../protocol/impl/util/ByteBufUtils.java | 443 +-- .../protocol/impl/util/EncodeConstants.java | 83 +- .../impl/util/InstructionsDeserializer.java | 275 +- .../impl/util/InstructionsSerializer.java | 285 +- .../protocol/impl/util/MatchDeserializer.java | 1101 ++++---- .../protocol/impl/util/MatchSerializer.java | 1285 ++++----- .../impl/util/OF10ActionsDeserializer.java | 559 ++-- .../impl/util/OF10ActionsSerializer.java | 473 ++-- .../impl/util/OF10MatchDeserializer.java | 205 +- .../impl/util/OF10MatchSerializer.java | 159 +- .../protocol/impl/core/DummyDecoder.java | 65 +- .../impl/core/OFFrameDecoderTest.java | 209 +- .../impl/core/OFVersionDetectorTest.java | 149 +- .../protocol/impl/core/TlsDetectorTest.java | 93 +- .../BarrierReplyMessageFactoryTest.java | 85 +- .../EchoReplyMessageFactoryTest.java | 147 +- .../EchoRequestMessageFactoryTest.java | 147 +- .../factories/ErrorMessageFactoryTest.java | 9 +- .../ExperimenterMessageFactoryTest.java | 69 +- .../FeaturesReplyMessageFactoryTest.java | 79 +- .../FlowRemovedMessageFactoryTest.java | 89 +- .../GetAsyncReplyMessageFactoryTest.java | 225 +- .../GetConfigReplyMessageFactoryTest.java | 69 +- .../factories/HelloMessageFactoryTest.java | 135 +- .../MultipartReplyMessageFactoryTest.java | 2469 +++++++++-------- .../OF10ErrorMessageFactoryTest.java | 175 +- .../OF10FeaturesReplyMessageFactoryTest.java | 195 +- .../OF10FlowRemovedMessageFactoryTest.java | 83 +- .../OF10HelloMessageFactoryTest.java | 101 +- .../OF10PacketInMessageFactoryTest.java | 67 +- .../OF10PortStatusMessageFactoryTest.java | 109 +- ...QueueGetConfigReplyMessageFactoryTest.java | 113 +- .../OF10VendorMessageFactoryTest.java | 63 +- .../factories/PacketInMessageFactoryTest.java | 93 +- .../PortStatusMessageFactoryTest.java | 139 +- ...GetConfigReplyMessageFactoryMultiTest.java | 183 +- ...QueueGetConfigReplyMessageFactoryTest.java | 131 +- .../RoleReplyMessageFactoryTest.java | 67 +- .../BarrierInputMessageFactoryTest.java | 85 +- .../EchoInputMessageFactoryTest.java | 117 +- .../EchoReplyInputMessageFactoryTest.java | 117 +- .../ExperimenterInputMessageFactoryTest.java | 109 +- .../FlowModInputMessageFactoryTest.java | 333 +-- .../GetConfigInputMessageFactoryTest.java | 117 +- .../GetFeaturesInputMessageFactoryTest.java | 115 +- ...GetQueueConfigInputMessageFactoryTest.java | 9 +- .../GetaAsyncRequestMessageFactoryTest.java | 83 +- .../GroupModInputMessageFactoryTest.java | 175 +- .../HelloInputMessageFactoryTest.java | 337 +-- .../MeterModInputMessageFactoryTest.java | 243 +- .../MultipartRequestInputFactoryTest.java | 1085 ++++---- .../OF10BarrierInputMessageFactoryTest.java | 79 +- .../OF10FlowModInputMessageFactoryTest.java | 281 +- .../OF10HelloInputMessageFactoryTest.java | 79 +- .../OF10PacketOutInputMessageFactoryTest.java | 179 +- .../OF10PortModInputMessageFactoryTest.java | 121 +- ...QueueGetConfigInputMessageFactoryTest.java | 89 +- .../OF10VendorInputMessageFactoryTest.java | 93 +- .../PacketOutInputMessageFactoryTest.java | 171 +- .../PortModInputMessageFactoryTest.java | 199 +- .../RoleRequestInputMessageFactoryTest.java | 107 +- .../SetAsyncInputMessageFactoryTest.java | 253 +- .../SetConfigMessageFactoryTest.java | 139 +- .../TableModInputMessageFactoryTest.java | 101 +- .../protocol/impl/util/BufferHelper.java | 331 +-- .../protocol/impl/util/ByteBufUtilsTest.java | 421 +-- .../impl/util/MatchSerializerTest.java | 421 +-- .../impl/util/OF10MatchDeserializerTest.java | 157 +- .../impl/util/OF10MatchSerializerTest.java | 235 +- .../impl/integration/IntegrationTest.java | 295 +- .../protocol/impl/integration/MockPlugin.java | 463 ++-- .../integration/TestingConnConfigImpl.java | 137 +- .../connection/SwitchConnectionProvider.java | 9 +- .../protocol/impl/clients/ClientEvent.java | 9 +- .../impl/clients/ScenarioFactory.java | 9 +- .../impl/clients/ScenarioHandler.java | 9 +- .../protocol/impl/clients/SendEvent.java | 9 +- .../protocol/impl/clients/SimpleClient.java | 9 +- .../impl/clients/SimpleClientFramer.java | 9 +- .../impl/clients/SimpleClientHandler.java | 143 +- .../impl/clients/SimpleClientInitializer.java | 9 +- .../protocol/impl/clients/SleepEvent.java | 9 +- .../impl/clients/WaitForMessageEvent.java | 9 +- 174 files changed, 16255 insertions(+), 15044 deletions(-) diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java index 74a9bdcc..cb3edd1f 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.api.connection; diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionConfiguration.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionConfiguration.java index a42b000c..c5ca795c 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionConfiguration.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionConfiguration.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.api.connection; diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionReadyListener.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionReadyListener.java index 215acef6..55152fb7 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionReadyListener.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionReadyListener.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.api.connection; /** diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ListeningStatusProvider.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ListeningStatusProvider.java index 761a74eb..6de6675b 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ListeningStatusProvider.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ListeningStatusProvider.java @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/SwitchConnectionHandler.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/SwitchConnectionHandler.java index 532bfa9f..82dd0f0e 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/SwitchConnectionHandler.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/SwitchConnectionHandler.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.api.connection; diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/util/BinContent.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/util/BinContent.java index 6227070f..171a684d 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/util/BinContent.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/util/BinContent.java @@ -1,25 +1,32 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.api.util; - -/** - * @author michal.polkorab - * - */ -public abstract class BinContent { - - /** - * @param value - * @return int part wrapped in long - */ - public static long intToUnsignedLong(int value) { - return value & 0x00000000ffffffffL; - } - - /** - * @param value - * @return long cut into int - */ - public static int longToSignedInt(long value) { - return (int) value; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.api.util; + +/** + * @author michal.polkorab + * + */ +public abstract class BinContent { + + /** + * @param value + * @return int part wrapped in long + */ + public static long intToUnsignedLong(int value) { + return value & 0x00000000ffffffffL; + } + + /** + * @param value + * @return long cut into int + */ + public static int longToSignedInt(long value) { + return (int) value; + } +} diff --git a/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/util/BinContentTest.java b/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/util/BinContentTest.java index 18ec2269..af09e0cb 100644 --- a/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/util/BinContentTest.java +++ b/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/util/BinContentTest.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.api.util; import junit.framework.Assert; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/Activator.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/Activator.java index 5bd98c6e..f028d787 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/Activator.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/Activator.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.connection; import java.util.Hashtable; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java index 754a2d9d..241d1298 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.connection; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java index 7fe138c4..e3822dd6 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.connection; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionFacade.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionFacade.java index 3e72d786..fc6d9e92 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionFacade.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionFacade.java @@ -1,13 +1,20 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ - -package org.opendaylight.openflowjava.protocol.impl.connection; - -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; - -/** - * @author michal.polkorab - */ -public interface ConnectionFacade extends MessageConsumer, ConnectionAdapter { - - // empty unifying superinterface -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + + +package org.opendaylight.openflowjava.protocol.impl.connection; + +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; + +/** + * @author michal.polkorab + */ +public interface ConnectionFacade extends MessageConsumer, ConnectionAdapter { + + // empty unifying superinterface +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java index 8a80ff57..fe833311 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.connection; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/OnlineProvider.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/OnlineProvider.java index e189920c..e828d9ae 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/OnlineProvider.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/OnlineProvider.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.connection; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/RpcResponseKey.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/RpcResponseKey.java index 71e1df1f..a01098d4 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/RpcResponseKey.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/RpcResponseKey.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.connection; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ServerFacade.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ServerFacade.java index 1d089921..84c84df7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ServerFacade.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ServerFacade.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.connection; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ShutdownProvider.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ShutdownProvider.java index 58d4c271..21870cc4 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ShutdownProvider.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ShutdownProvider.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.connection; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java index 3547db2a..d9e9f64e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.connection; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/DelegatingInboundHandler.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/DelegatingInboundHandler.java index e0daecb2..4279bcbb 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/DelegatingInboundHandler.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/DelegatingInboundHandler.java @@ -1,64 +1,71 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.core; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; - -import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionAdapterImpl; -import org.opendaylight.openflowjava.protocol.impl.connection.MessageConsumer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Holds reference to {@link ConnectionAdapterImpl} and passes messages for further processing. - * Also informs on switch disconnection. - * @author michal.polkorab - */ -public class DelegatingInboundHandler extends ChannelInboundHandlerAdapter { - - private static final Logger LOGGER = LoggerFactory.getLogger(DelegatingInboundHandler.class); - - protected MessageConsumer consumer; - private boolean inactiveMessageSent = false; - - /** - * Constructs class + creates and sets MessageConsumer - * @param connectionAdapter reference for adapter communicating with upper layers outside library - */ - public DelegatingInboundHandler(MessageConsumer connectionAdapter) { - LOGGER.debug("Creating DelegatingInboundHandler"); - consumer = connectionAdapter; - } - - @Override - public void channelRead(ChannelHandlerContext ctx, final Object msg) - throws Exception { - LOGGER.debug("Reading"); - consumer.consume((DataObject) msg); - } - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - LOGGER.info("Channel inactive"); - if (!inactiveMessageSent) { - DisconnectEventBuilder builder = new DisconnectEventBuilder(); - builder.setInfo("Channel inactive"); - consumer.consume(builder.build()); - inactiveMessageSent = true; - } - } - - @Override - public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { - LOGGER.info("Channel unregistered"); - if (!inactiveMessageSent) { - DisconnectEventBuilder builder = new DisconnectEventBuilder(); - builder.setInfo("Channel unregistered"); - consumer.consume(builder.build()); - inactiveMessageSent = true; - } - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.core; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; + +import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionAdapterImpl; +import org.opendaylight.openflowjava.protocol.impl.connection.MessageConsumer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Holds reference to {@link ConnectionAdapterImpl} and passes messages for further processing. + * Also informs on switch disconnection. + * @author michal.polkorab + */ +public class DelegatingInboundHandler extends ChannelInboundHandlerAdapter { + + private static final Logger LOGGER = LoggerFactory.getLogger(DelegatingInboundHandler.class); + + protected MessageConsumer consumer; + private boolean inactiveMessageSent = false; + + /** + * Constructs class + creates and sets MessageConsumer + * @param connectionAdapter reference for adapter communicating with upper layers outside library + */ + public DelegatingInboundHandler(MessageConsumer connectionAdapter) { + LOGGER.debug("Creating DelegatingInboundHandler"); + consumer = connectionAdapter; + } + + @Override + public void channelRead(ChannelHandlerContext ctx, final Object msg) + throws Exception { + LOGGER.debug("Reading"); + consumer.consume((DataObject) msg); + } + + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + LOGGER.info("Channel inactive"); + if (!inactiveMessageSent) { + DisconnectEventBuilder builder = new DisconnectEventBuilder(); + builder.setInfo("Channel inactive"); + consumer.consume(builder.build()); + inactiveMessageSent = true; + } + } + + @Override + public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { + LOGGER.info("Channel unregistered"); + if (!inactiveMessageSent) { + DisconnectEventBuilder builder = new DisconnectEventBuilder(); + builder.setInfo("Channel unregistered"); + consumer.consume(builder.build()); + inactiveMessageSent = true; + } + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/IdleHandler.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/IdleHandler.java index 8d5ca853..65af2516 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/IdleHandler.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/IdleHandler.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.core; import java.util.concurrent.TimeUnit; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoder.java index d0d39962..af04a525 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoder.java @@ -1,54 +1,61 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.core; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageDecoder; - -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Transforms OpenFlow Protocol messages to POJOs - * @author michal.polkorab - */ -public class OFDecoder extends MessageToMessageDecoder { - - private static final Logger LOGGER = LoggerFactory.getLogger(OFDecoder.class); - - /** - * Constructor of class - */ - public OFDecoder() { - LOGGER.debug("Creating OF 1.3 Decoder"); - } - - @Override - protected void decode(ChannelHandlerContext ctx, VersionMessageWrapper msg, - List out) throws Exception { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("VersionMessageWrapper received"); - LOGGER.debug("buffer size: " + msg.getMessageBuffer().readableBytes()); - LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(msg.getMessageBuffer())); - } - DataObject dataObject = null; - try { - dataObject = DeserializationFactory.bufferToMessage(msg.getMessageBuffer(), - msg.getVersion()); - } catch(Exception e) { - LOGGER.error("Message deserialization failed"); - LOGGER.error(e.getMessage(), e); - return; - } - if (dataObject == null) { - LOGGER.warn("Translated POJO is null"); - return; - } - msg.getMessageBuffer().release(); - out.add(dataObject); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.core; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToMessageDecoder; + +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Transforms OpenFlow Protocol messages to POJOs + * @author michal.polkorab + */ +public class OFDecoder extends MessageToMessageDecoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(OFDecoder.class); + + /** + * Constructor of class + */ + public OFDecoder() { + LOGGER.debug("Creating OF 1.3 Decoder"); + } + + @Override + protected void decode(ChannelHandlerContext ctx, VersionMessageWrapper msg, + List out) throws Exception { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("VersionMessageWrapper received"); + LOGGER.debug("buffer size: " + msg.getMessageBuffer().readableBytes()); + LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(msg.getMessageBuffer())); + } + DataObject dataObject = null; + try { + dataObject = DeserializationFactory.bufferToMessage(msg.getMessageBuffer(), + msg.getVersion()); + } catch(Exception e) { + LOGGER.error("Message deserialization failed"); + LOGGER.error(e.getMessage(), e); + return; + } + if (dataObject == null) { + LOGGER.warn("Translated POJO is null"); + return; + } + msg.getMessageBuffer().release(); + out.add(dataObject); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java index 9a0cdbb1..3c77e64e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java @@ -1,46 +1,53 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.core; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; - -import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Transforms OpenFlow Protocol messages to POJOs - * @author michal.polkorab - * @author timotej.kubas - */ -public class OFEncoder extends MessageToByteEncoder { - - private static final Logger LOGGER = LoggerFactory.getLogger(OFEncoder.class); - - /** Constructor of class */ - public OFEncoder() { - LOGGER.debug("Creating OF13Encoder"); - } - - @Override - protected void encode(ChannelHandlerContext ctx, OfHeader msg, ByteBuf out) - throws Exception { - LOGGER.debug("Encoding"); - try { - SerializationFactory.messageToBuffer(msg.getVersion(), out, msg); - } catch(Exception e) { - LOGGER.error("Message serialization failed"); - LOGGER.error(e.getMessage(), e); - return; - } - if (out.readableBytes() > 0) { - out.retain(); - ctx.writeAndFlush(out); - } else { - LOGGER.warn("Translated buffer is empty"); - } - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.core; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; + +import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Transforms OpenFlow Protocol messages to POJOs + * @author michal.polkorab + * @author timotej.kubas + */ +public class OFEncoder extends MessageToByteEncoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(OFEncoder.class); + + /** Constructor of class */ + public OFEncoder() { + LOGGER.debug("Creating OF13Encoder"); + } + + @Override + protected void encode(ChannelHandlerContext ctx, OfHeader msg, ByteBuf out) + throws Exception { + LOGGER.debug("Encoding"); + try { + SerializationFactory.messageToBuffer(msg.getVersion(), out, msg); + } catch(Exception e) { + LOGGER.error("Message serialization failed"); + LOGGER.error(e.getMessage(), e); + return; + } + if (out.readableBytes() > 0) { + out.retain(); + ctx.writeAndFlush(out); + } else { + LOGGER.warn("Translated buffer is empty"); + } + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java index c342e9d5..7a3e105a 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.core; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetector.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetector.java index 9026dcc6..671b8dd9 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetector.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetector.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.core; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java index 5e481dc0..1fd9cb9c 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.core; import io.netty.channel.Channel; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslContextFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslContextFactory.java index 1f795362..08272188 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslContextFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslContextFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.core; import java.security.KeyStore; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslKeyStore.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslKeyStore.java index 8d4e2374..3868e734 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslKeyStore.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslKeyStore.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.core; import java.io.InputStream; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslTrustManagerFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslTrustManagerFactory.java index 36e1fdaf..69f2db68 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslTrustManagerFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SslTrustManagerFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.core; import javax.net.ssl.ManagerFactoryParameters; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandler.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandler.java index 3c74cf30..941518d6 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandler.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandler.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.core; import io.netty.bootstrap.ServerBootstrap; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TlsDetector.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TlsDetector.java index 2ce089ba..93b296d0 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TlsDetector.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TlsDetector.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.core; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/VersionMessageWrapper.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/VersionMessageWrapper.java index fc41b8e7..f04ae92d 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/VersionMessageWrapper.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/VersionMessageWrapper.java @@ -1,40 +1,47 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.core; - -import io.netty.buffer.ByteBuf; - -/** - * Wraps received messages (includes version) - * @author michal.polkorab - */ -public class VersionMessageWrapper { - - private short version; - private ByteBuf messageBuffer; - - /** - * Constructor - * @param version version decoded in {@link OFVersionDetector} - * @param messageBuffer message received from {@link OFFrameDecoder} - */ - public VersionMessageWrapper(short version, ByteBuf messageBuffer) { - this.version = version; - this.messageBuffer = messageBuffer; - } - - /** - * @return the version version decoded in {@link OFVersionDetector} - */ - public short getVersion() { - return version; - } - - /** - * @return the messageBuffer message received from {@link OFFrameDecoder} - */ - public ByteBuf getMessageBuffer() { - return messageBuffer; - } - - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.core; + +import io.netty.buffer.ByteBuf; + +/** + * Wraps received messages (includes version) + * @author michal.polkorab + */ +public class VersionMessageWrapper { + + private short version; + private ByteBuf messageBuffer; + + /** + * Constructor + * @param version version decoded in {@link OFVersionDetector} + * @param messageBuffer message received from {@link OFFrameDecoder} + */ + public VersionMessageWrapper(short version, ByteBuf messageBuffer) { + this.version = version; + this.messageBuffer = messageBuffer; + } + + /** + * @return the version version decoded in {@link OFVersionDetector} + */ + public short getVersion() { + return version; + } + + /** + * @return the messageBuffer message received from {@link OFFrameDecoder} + */ + public ByteBuf getMessageBuffer() { + return messageBuffer; + } + + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DecoderTable.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DecoderTable.java index 0013b433..e1734405 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DecoderTable.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DecoderTable.java @@ -1,137 +1,144 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization; - -import java.util.HashMap; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.BarrierReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ErrorMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ExperimenterMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FlowRemovedMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetAsyncReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetConfigReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10ErrorMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FeaturesReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FlowRemovedMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10HelloMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PacketInMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PortStatusMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10QueueGetConfigReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10StatsReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10VendorMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PacketInMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PortStatusMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.QueueGetConfigReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.RoleReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; - -/** - * Stores and provides correct decoders for received messages - * @author michal.polkorab - * - *
         
- *  Type   Message
- *   0: HELLO
- *   1: ERROR
- *   2: ECHO_REQUEST
- *   3: ECHO_REPLY
- *   4: EXPERIMENTER
- *   5: FEATURES_REQUEST
- *   6: FEATURES_REPLY
- *   7: GET_CONFIG_REQUEST
- *   8: GET_CONFIG_REPLY
- *   9: SET_CONFIG
- *   10: PACKET_IN
- *   11: FLOW_REMOVED
- *   12: PORT_STATUS
- *   13: PACKET_OUT
- *   14: FLOW_MOD
- *   15: GROUP_MOD
- *   16: PORT_MOD
- *   17: TABLE_MOD
- *   18: MULTIPART_REQUEST
- *   19: MULTIPART_REPLY
- *   20: BARRIER_REQUEST
- *   21: BARRIER_REPLY
- *   22: QUEUE_GET_CONFIG_REQUEST
- *   23: QUEUE_GET_CONFIG_REPLY
- *   24: ROLE_REQUEST
- *   25: ROLE_REPLY    
- *   26: GET_ASYNC_REQUEST
- *   27: GET_ASYNC_REPLY
- *   28: SET_ASYNC
- *   29: METER_MOD
- *   
- */ -public class DecoderTable { - - private static final short OF10 = EncodeConstants.OF10_VERSION_ID; - private static final short OF13 = EncodeConstants.OF13_VERSION_ID; - private Map> table; - private static DecoderTable instance; - - - private DecoderTable() { - // do nothing - } - - /** - * @return singleton instance - */ - public static synchronized DecoderTable getInstance() { - if (instance == null) { - instance = new DecoderTable(); - instance.init(); - } - return instance; - } - - /** - * Decoder table provisioning - */ - public void init() { - table = new HashMap<>(); - table.put(new MessageTypeCodeKey(OF10, (short) 0), OF10HelloMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 1), OF10ErrorMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 2), EchoRequestMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 3), EchoReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 4), OF10VendorMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 6), OF10FeaturesReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 8), GetConfigReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 10), OF10PacketInMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 11), OF10FlowRemovedMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 12), OF10PortStatusMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 16), OF10StatsReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 18), BarrierReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF10, (short) 20), OF10QueueGetConfigReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 0), HelloMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 1), ErrorMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 2), EchoRequestMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 3), EchoReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 4), ExperimenterMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 6), FeaturesReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 8), GetConfigReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 10), PacketInMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 11), FlowRemovedMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 12), PortStatusMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 19), MultipartReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 21), BarrierReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 23), QueueGetConfigReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 25), RoleReplyMessageFactory.getInstance()); - table.put(new MessageTypeCodeKey(OF13, (short) 27), GetAsyncReplyMessageFactory.getInstance()); - } - - /** - * @param msgTypeKey - * @return decoder for given message types - */ - public OFDeserializer getDecoder(MessageTypeCodeKey msgTypeKey) { - return table.get(msgTypeKey); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.BarrierReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ErrorMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ExperimenterMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FlowRemovedMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetAsyncReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetConfigReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10ErrorMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FeaturesReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FlowRemovedMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10HelloMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PacketInMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PortStatusMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10QueueGetConfigReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10StatsReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10VendorMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PacketInMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PortStatusMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.QueueGetConfigReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.RoleReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; + +/** + * Stores and provides correct decoders for received messages + * @author michal.polkorab + * + *
         
+ *  Type   Message
+ *   0: HELLO
+ *   1: ERROR
+ *   2: ECHO_REQUEST
+ *   3: ECHO_REPLY
+ *   4: EXPERIMENTER
+ *   5: FEATURES_REQUEST
+ *   6: FEATURES_REPLY
+ *   7: GET_CONFIG_REQUEST
+ *   8: GET_CONFIG_REPLY
+ *   9: SET_CONFIG
+ *   10: PACKET_IN
+ *   11: FLOW_REMOVED
+ *   12: PORT_STATUS
+ *   13: PACKET_OUT
+ *   14: FLOW_MOD
+ *   15: GROUP_MOD
+ *   16: PORT_MOD
+ *   17: TABLE_MOD
+ *   18: MULTIPART_REQUEST
+ *   19: MULTIPART_REPLY
+ *   20: BARRIER_REQUEST
+ *   21: BARRIER_REPLY
+ *   22: QUEUE_GET_CONFIG_REQUEST
+ *   23: QUEUE_GET_CONFIG_REPLY
+ *   24: ROLE_REQUEST
+ *   25: ROLE_REPLY    
+ *   26: GET_ASYNC_REQUEST
+ *   27: GET_ASYNC_REPLY
+ *   28: SET_ASYNC
+ *   29: METER_MOD
+ *   
+ */ +public class DecoderTable { + + private static final short OF10 = EncodeConstants.OF10_VERSION_ID; + private static final short OF13 = EncodeConstants.OF13_VERSION_ID; + private Map> table; + private static DecoderTable instance; + + + private DecoderTable() { + // do nothing + } + + /** + * @return singleton instance + */ + public static synchronized DecoderTable getInstance() { + if (instance == null) { + instance = new DecoderTable(); + instance.init(); + } + return instance; + } + + /** + * Decoder table provisioning + */ + public void init() { + table = new HashMap<>(); + table.put(new MessageTypeCodeKey(OF10, (short) 0), OF10HelloMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 1), OF10ErrorMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 2), EchoRequestMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 3), EchoReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 4), OF10VendorMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 6), OF10FeaturesReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 8), GetConfigReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 10), OF10PacketInMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 11), OF10FlowRemovedMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 12), OF10PortStatusMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 16), OF10StatsReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 18), BarrierReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF10, (short) 20), OF10QueueGetConfigReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 0), HelloMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 1), ErrorMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 2), EchoRequestMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 3), EchoReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 4), ExperimenterMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 6), FeaturesReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 8), GetConfigReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 10), PacketInMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 11), FlowRemovedMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 12), PortStatusMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 19), MultipartReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 21), BarrierReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 23), QueueGetConfigReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 25), RoleReplyMessageFactory.getInstance()); + table.put(new MessageTypeCodeKey(OF13, (short) 27), GetAsyncReplyMessageFactory.getInstance()); + } + + /** + * @param msgTypeKey + * @return decoder for given message types + */ + public OFDeserializer getDecoder(MessageTypeCodeKey msgTypeKey) { + return table.get(msgTypeKey); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java index a6b9b8f7..4daadffc 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java @@ -1,40 +1,47 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public abstract class DeserializationFactory { - - private static final Logger LOGGER = LoggerFactory - .getLogger(DeserializationFactory.class); - - /** - * Transforms ByteBuf into correct POJO message - * @param rawMessage - * @param version version decoded from OpenFlow protocol message - * @return correct POJO as DataObject - */ - public static DataObject bufferToMessage(ByteBuf rawMessage, short version) { - DataObject dataObject = null; - short type = rawMessage.readUnsignedByte(); - rawMessage.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - - MessageTypeCodeKey msgTypeCodeKey = new MessageTypeCodeKey(version, type); - OFDeserializer decoder = DecoderTable.getInstance().getDecoder(msgTypeCodeKey); - if (decoder != null) { - dataObject = decoder.bufferToMessage(rawMessage, version); - } else { - LOGGER.warn("No correct decoder found in DecoderTable for arguments: " + msgTypeCodeKey.toString()); - } - return dataObject; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public abstract class DeserializationFactory { + + private static final Logger LOGGER = LoggerFactory + .getLogger(DeserializationFactory.class); + + /** + * Transforms ByteBuf into correct POJO message + * @param rawMessage + * @param version version decoded from OpenFlow protocol message + * @return correct POJO as DataObject + */ + public static DataObject bufferToMessage(ByteBuf rawMessage, short version) { + DataObject dataObject = null; + short type = rawMessage.readUnsignedByte(); + rawMessage.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + + MessageTypeCodeKey msgTypeCodeKey = new MessageTypeCodeKey(version, type); + OFDeserializer decoder = DecoderTable.getInstance().getDecoder(msgTypeCodeKey); + if (decoder != null) { + dataObject = decoder.bufferToMessage(rawMessage, version); + } else { + LOGGER.warn("No correct decoder found in DecoderTable for arguments: " + msgTypeCodeKey.toString()); + } + return dataObject; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageTypeCodeKey.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageTypeCodeKey.java index dd71c4a2..96fb3e70 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageTypeCodeKey.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageTypeCodeKey.java @@ -1,63 +1,70 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization; - - -/** - * Class used as a key in {@link DecoderTable} - * @author michal.polkorab - * @author timotej.kubas - */ -public class MessageTypeCodeKey { - - private final short msgType; - private final short msgVersion; - - /** - * @param msgVersion protocol version - * @param msgType type code of message - */ - public MessageTypeCodeKey(short msgVersion, short msgType) { - this.msgType = msgType; - this.msgVersion = msgVersion; - } - - /** - * @return the msgType - */ - public short getMsgType() { - return msgType; - } - - /** - * @return the msgVersion - */ - public short getMsgVersion() { - return msgVersion; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + msgType; - result = prime * result + msgVersion; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - MessageTypeCodeKey other = (MessageTypeCodeKey) obj; - if (msgType != other.msgType) - return false; - if (msgVersion != other.msgVersion) - return false; - return true; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization; + + +/** + * Class used as a key in {@link DecoderTable} + * @author michal.polkorab + * @author timotej.kubas + */ +public class MessageTypeCodeKey { + + private final short msgType; + private final short msgVersion; + + /** + * @param msgVersion protocol version + * @param msgType type code of message + */ + public MessageTypeCodeKey(short msgVersion, short msgType) { + this.msgType = msgType; + this.msgVersion = msgVersion; + } + + /** + * @return the msgType + */ + public short getMsgType() { + return msgType; + } + + /** + * @return the msgVersion + */ + public short getMsgVersion() { + return msgVersion; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + msgType; + result = prime * result + msgVersion; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MessageTypeCodeKey other = (MessageTypeCodeKey) obj; + if (msgType != other.msgType) + return false; + if (msgVersion != other.msgVersion) + return false; + return true; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/OFDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/OFDeserializer.java index 8f64ed3d..c4df5df0 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/OFDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/OFDeserializer.java @@ -1,26 +1,33 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization; - -import org.opendaylight.yangtools.yang.binding.DataObject; - -import io.netty.buffer.ByteBuf; - -/** - * Uniform interface for deserializing factories - * @author michal.polkorab - * @author timotej.kubas - * @param message code type - */ -public interface OFDeserializer { - - /** - * Transforms byte message into POJO/DTO (of type E). - * Assumes that input ByteBuf's readerIndex is pointing on length in OpenFlow header - * - * @param rawMessage message as bytes in ByteBuf - * @param version version of used OF Protocol - * @return HelloMessage as DataObject - */ - public abstract E bufferToMessage(ByteBuf rawMessage, short version); - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization; + +import org.opendaylight.yangtools.yang.binding.DataObject; + +import io.netty.buffer.ByteBuf; + +/** + * Uniform interface for deserializing factories + * @author michal.polkorab + * @author timotej.kubas + * @param message code type + */ +public interface OFDeserializer { + + /** + * Transforms byte message into POJO/DTO (of type E). + * Assumes that input ByteBuf's readerIndex is pointing on length in OpenFlow header + * + * @param rawMessage message as bytes in ByteBuf + * @param version version of used OF Protocol + * @return HelloMessage as DataObject + */ + public abstract E bufferToMessage(ByteBuf rawMessage, short version); + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java index e2402b47..51c305cf 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java index 0c591bb5..c5d5ab79 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactory.java @@ -1,45 +1,52 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder; - -/** - * Translates EchoReply messages (both OpenFlow v1.0 and OpenFlow v1.3) - * @author michal.polkorab - * @author timotej.kubas - */ -public class EchoReplyMessageFactory implements OFDeserializer { - - private static EchoReplyMessageFactory instance; - - private EchoReplyMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized EchoReplyMessageFactory getInstance() { - if (instance == null) { - instance = new EchoReplyMessageFactory(); - } - return instance; - } - - @Override - public EchoOutput bufferToMessage(ByteBuf rawMessage, short version) { - EchoOutputBuilder builder = new EchoOutputBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - int remainingBytes = rawMessage.readableBytes(); - if (remainingBytes > 0) { - builder.setData(rawMessage.readBytes(remainingBytes).array()); - } - return builder.build(); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder; + +/** + * Translates EchoReply messages (both OpenFlow v1.0 and OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public class EchoReplyMessageFactory implements OFDeserializer { + + private static EchoReplyMessageFactory instance; + + private EchoReplyMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized EchoReplyMessageFactory getInstance() { + if (instance == null) { + instance = new EchoReplyMessageFactory(); + } + return instance; + } + + @Override + public EchoOutput bufferToMessage(ByteBuf rawMessage, short version) { + EchoOutputBuilder builder = new EchoOutputBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + int remainingBytes = rawMessage.readableBytes(); + if (remainingBytes > 0) { + builder.setData(rawMessage.readBytes(remainingBytes).array()); + } + return builder.build(); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java index 5ff67d7f..2ba5884d 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactory.java @@ -1,41 +1,48 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder; - -/** - * Translates EchoRequest messages (both OpenFlow v1.0 and OpenFlow v1.3) - * @author michal.polkorab - * @author timotej.kubas - */ -public class EchoRequestMessageFactory implements OFDeserializer{ - - private static EchoRequestMessageFactory instance; - - private EchoRequestMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized EchoRequestMessageFactory getInstance() { - if (instance == null) { - instance = new EchoRequestMessageFactory(); - } - return instance; - } - - @Override - public EchoRequestMessage bufferToMessage(ByteBuf rawMessage, short version) { - EchoRequestMessageBuilder builder = new EchoRequestMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); - return builder.build(); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder; + +/** + * Translates EchoRequest messages (both OpenFlow v1.0 and OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public class EchoRequestMessageFactory implements OFDeserializer{ + + private static EchoRequestMessageFactory instance; + + private EchoRequestMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized EchoRequestMessageFactory getInstance() { + if (instance == null) { + instance = new EchoRequestMessageFactory(); + } + return instance; + } + + @Override + public EchoRequestMessage bufferToMessage(ByteBuf rawMessage, short version) { + EchoRequestMessageBuilder builder = new EchoRequestMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java index 3463855b..09ec1088 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java @@ -1,248 +1,255 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterError; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterErrorBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadActionCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadInstructionCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadMatchCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadRequestCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFailedCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupModFailedCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloFailedCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterModFailedCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortModFailedCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueOpFailedCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.RoleRequestFailedCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFailedCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesFailedCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableModFailedCode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder; - -/** - * Translates Error messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class ErrorMessageFactory implements OFDeserializer { - - private static final String UNKNOWN_CODE = "UNKNOWN_CODE"; - private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE"; - - private static ErrorMessageFactory instance; - - private ErrorMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized ErrorMessageFactory getInstance() { - if (instance == null) { - instance = new ErrorMessageFactory(); - } - return instance; - } - - @Override - public ErrorMessage bufferToMessage(ByteBuf rawMessage, short version) { - ErrorMessageBuilder builder = new ErrorMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - int type = rawMessage.readUnsignedShort(); - ErrorType errorType = ErrorType.forValue(type); - decodeType(builder, errorType, type); - decodeCode(rawMessage, builder, errorType); - if (rawMessage.readableBytes() > 0) { - builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); - } - return builder.build(); - } - - private static void decodeType(ErrorMessageBuilder builder, ErrorType type, int readValue) { - if (type != null) { - builder.setType(type.getIntValue()); - builder.setTypeString(type.name()); - } else { - builder.setType(readValue); - builder.setTypeString(UNKNOWN_TYPE); - } - } - - private static void decodeCode(ByteBuf rawMessage, ErrorMessageBuilder builder, - ErrorType type) { - int code = rawMessage.readUnsignedShort(); - if (type != null) { - switch (type) { - case HELLOFAILED: - { - HelloFailedCode errorCode = HelloFailedCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case BADREQUEST: - { - BadRequestCode errorCode = BadRequestCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case BADACTION: - { - BadActionCode errorCode = BadActionCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case BADINSTRUCTION: - { - BadInstructionCode errorCode = BadInstructionCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case BADMATCH: - { - BadMatchCode errorCode = BadMatchCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case FLOWMODFAILED: - { - FlowModFailedCode errorCode = FlowModFailedCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case GROUPMODFAILED: - { - GroupModFailedCode errorCode = GroupModFailedCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case PORTMODFAILED: - { - PortModFailedCode errorCode = PortModFailedCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case TABLEMODFAILED: - { - TableModFailedCode errorCode = TableModFailedCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case QUEUEOPFAILED: - { - QueueOpFailedCode errorCode = QueueOpFailedCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case SWITCHCONFIGFAILED: - { - SwitchConfigFailedCode errorCode = SwitchConfigFailedCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case ROLEREQUESTFAILED: - { - RoleRequestFailedCode errorCode = RoleRequestFailedCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case METERMODFAILED: - { - MeterModFailedCode errorCode = MeterModFailedCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case TABLEFEATURESFAILED: - { - TableFeaturesFailedCode errorCode = TableFeaturesFailedCode.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case EXPERIMENTER: - ExperimenterErrorBuilder expBuilder = new ExperimenterErrorBuilder(); - expBuilder.setExpType(code); - expBuilder.setExperimenter(rawMessage.readUnsignedInt()); - builder.addAugmentation(ExperimenterError.class, expBuilder.build()); - break; - default: - setUnknownCode(builder, code); - break; - } - } else { - setUnknownCode(builder, code); - } - } - - private static void setUnknownCode(ErrorMessageBuilder builder, int readValue) { - builder.setCode(readValue); - builder.setCodeString(UNKNOWN_CODE); - } - - private static void setCode(ErrorMessageBuilder builder, int code, String codeString) { - builder.setCode(code); - builder.setCodeString(codeString); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterError; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterErrorBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadActionCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadInstructionCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadMatchCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadRequestCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFailedCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupModFailedCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloFailedCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterModFailedCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortModFailedCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueOpFailedCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.RoleRequestFailedCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFailedCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesFailedCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableModFailedCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder; + +/** + * Translates Error messages + * @author michal.polkorab + * @author timotej.kubas + */ +public class ErrorMessageFactory implements OFDeserializer { + + private static final String UNKNOWN_CODE = "UNKNOWN_CODE"; + private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE"; + + private static ErrorMessageFactory instance; + + private ErrorMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized ErrorMessageFactory getInstance() { + if (instance == null) { + instance = new ErrorMessageFactory(); + } + return instance; + } + + @Override + public ErrorMessage bufferToMessage(ByteBuf rawMessage, short version) { + ErrorMessageBuilder builder = new ErrorMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + int type = rawMessage.readUnsignedShort(); + ErrorType errorType = ErrorType.forValue(type); + decodeType(builder, errorType, type); + decodeCode(rawMessage, builder, errorType); + if (rawMessage.readableBytes() > 0) { + builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); + } + return builder.build(); + } + + private static void decodeType(ErrorMessageBuilder builder, ErrorType type, int readValue) { + if (type != null) { + builder.setType(type.getIntValue()); + builder.setTypeString(type.name()); + } else { + builder.setType(readValue); + builder.setTypeString(UNKNOWN_TYPE); + } + } + + private static void decodeCode(ByteBuf rawMessage, ErrorMessageBuilder builder, + ErrorType type) { + int code = rawMessage.readUnsignedShort(); + if (type != null) { + switch (type) { + case HELLOFAILED: + { + HelloFailedCode errorCode = HelloFailedCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case BADREQUEST: + { + BadRequestCode errorCode = BadRequestCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case BADACTION: + { + BadActionCode errorCode = BadActionCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case BADINSTRUCTION: + { + BadInstructionCode errorCode = BadInstructionCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case BADMATCH: + { + BadMatchCode errorCode = BadMatchCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case FLOWMODFAILED: + { + FlowModFailedCode errorCode = FlowModFailedCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case GROUPMODFAILED: + { + GroupModFailedCode errorCode = GroupModFailedCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case PORTMODFAILED: + { + PortModFailedCode errorCode = PortModFailedCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case TABLEMODFAILED: + { + TableModFailedCode errorCode = TableModFailedCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case QUEUEOPFAILED: + { + QueueOpFailedCode errorCode = QueueOpFailedCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case SWITCHCONFIGFAILED: + { + SwitchConfigFailedCode errorCode = SwitchConfigFailedCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case ROLEREQUESTFAILED: + { + RoleRequestFailedCode errorCode = RoleRequestFailedCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case METERMODFAILED: + { + MeterModFailedCode errorCode = MeterModFailedCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case TABLEFEATURESFAILED: + { + TableFeaturesFailedCode errorCode = TableFeaturesFailedCode.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case EXPERIMENTER: + ExperimenterErrorBuilder expBuilder = new ExperimenterErrorBuilder(); + expBuilder.setExpType(code); + expBuilder.setExperimenter(rawMessage.readUnsignedInt()); + builder.addAugmentation(ExperimenterError.class, expBuilder.build()); + break; + default: + setUnknownCode(builder, code); + break; + } + } else { + setUnknownCode(builder, code); + } + } + + private static void setUnknownCode(ErrorMessageBuilder builder, int readValue) { + builder.setCode(readValue); + builder.setCodeString(UNKNOWN_CODE); + } + + private static void setCode(ErrorMessageBuilder builder, int code, String codeString) { + builder.setCode(code); + builder.setCodeString(codeString); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactory.java index f1298591..f6dc0ea1 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java index 8ab3ae80..c9cef55a 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java @@ -1,67 +1,74 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.math.BigInteger; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; - -/** - * Translates FeaturesReply messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class FeaturesReplyMessageFactory implements OFDeserializer{ - - private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2; - - private static FeaturesReplyMessageFactory instance; - - private FeaturesReplyMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized FeaturesReplyMessageFactory getInstance() { - if (instance == null) { - instance = new FeaturesReplyMessageFactory(); - } - return instance; - } - - @Override - public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) { - GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - byte[] datapathId = new byte[Long.SIZE/Byte.SIZE]; - rawMessage.readBytes(datapathId); - builder.setDatapathId(new BigInteger(datapathId)); - builder.setBuffers(rawMessage.readUnsignedInt()); - builder.setTables(rawMessage.readUnsignedByte()); - builder.setAuxiliaryId(rawMessage.readUnsignedByte()); - rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER); - builder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt())); - builder.setReserved(rawMessage.readUnsignedInt()); - return builder.build(); - } - - private static Capabilities createCapabilities(long input) { - final Boolean FLOW_STATS = (input & (1 << 0)) != 0; - final Boolean TABLE_STATS = (input & (1 << 1)) != 0; - final Boolean PORT_STATS = (input & (1 << 2)) != 0; - final Boolean GROUP_STATS = (input & (1 << 3)) != 0; - final Boolean IP_REASM = (input & (1 << 5)) != 0; - final Boolean QUEUE_STATS = (input & (1 << 6)) != 0; - final Boolean PORT_BLOCKED = (input & (1 << 8)) != 0; - return new Capabilities(FLOW_STATS, GROUP_STATS, IP_REASM, - PORT_BLOCKED, PORT_STATS, QUEUE_STATS, TABLE_STATS); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.math.BigInteger; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; + +/** + * Translates FeaturesReply messages + * @author michal.polkorab + * @author timotej.kubas + */ +public class FeaturesReplyMessageFactory implements OFDeserializer{ + + private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2; + + private static FeaturesReplyMessageFactory instance; + + private FeaturesReplyMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized FeaturesReplyMessageFactory getInstance() { + if (instance == null) { + instance = new FeaturesReplyMessageFactory(); + } + return instance; + } + + @Override + public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) { + GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + byte[] datapathId = new byte[Long.SIZE/Byte.SIZE]; + rawMessage.readBytes(datapathId); + builder.setDatapathId(new BigInteger(datapathId)); + builder.setBuffers(rawMessage.readUnsignedInt()); + builder.setTables(rawMessage.readUnsignedByte()); + builder.setAuxiliaryId(rawMessage.readUnsignedByte()); + rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER); + builder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt())); + builder.setReserved(rawMessage.readUnsignedInt()); + return builder.build(); + } + + private static Capabilities createCapabilities(long input) { + final Boolean FLOW_STATS = (input & (1 << 0)) != 0; + final Boolean TABLE_STATS = (input & (1 << 1)) != 0; + final Boolean PORT_STATS = (input & (1 << 2)) != 0; + final Boolean GROUP_STATS = (input & (1 << 3)) != 0; + final Boolean IP_REASM = (input & (1 << 5)) != 0; + final Boolean QUEUE_STATS = (input & (1 << 6)) != 0; + final Boolean PORT_BLOCKED = (input & (1 << 8)) != 0; + return new Capabilities(FLOW_STATS, GROUP_STATS, IP_REASM, + PORT_BLOCKED, PORT_STATS, QUEUE_STATS, TABLE_STATS); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java index 24f15ff1..7df6835c 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java index 30584823..2f482cf7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactory.java @@ -1,134 +1,141 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder; - -/** - * Translates GetAsyncReply messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class GetAsyncReplyMessageFactory implements OFDeserializer { - - private static GetAsyncReplyMessageFactory instance; - private static final byte SEPARATE_ROLES = 2; - - private GetAsyncReplyMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized GetAsyncReplyMessageFactory getInstance() { - if (instance == null) { - instance = new GetAsyncReplyMessageFactory(); - } - return instance; - } - - @Override - public GetAsyncOutput bufferToMessage(ByteBuf rawMessage, short version) { - GetAsyncOutputBuilder builder = new GetAsyncOutputBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - builder.setPacketInMask(decodePacketInMask(rawMessage)); - builder.setPortStatusMask(decodePortStatusMask(rawMessage)); - builder.setFlowRemovedMask(decodeFlowRemovedMask(rawMessage)); - return builder.build(); - } - - private static List decodePacketInMask(ByteBuf input) { - List inMasks = new ArrayList<>(); - PacketInMaskBuilder maskBuilder; - for (int i = 0; i < SEPARATE_ROLES; i++) { - maskBuilder = new PacketInMaskBuilder(); - maskBuilder.setMask(decodePacketInReasons(input.readUnsignedInt())); - inMasks.add(maskBuilder.build()); - } - return inMasks; - } - - private static List decodePortStatusMask(ByteBuf input) { - List inMasks = new ArrayList<>(); - PortStatusMaskBuilder maskBuilder; - for (int i = 0; i < SEPARATE_ROLES; i++) { - maskBuilder = new PortStatusMaskBuilder(); - maskBuilder.setMask(decodePortReasons(input.readUnsignedInt())); - inMasks.add(maskBuilder.build()); - } - return inMasks; - } - - private static List decodeFlowRemovedMask(ByteBuf input) { - List inMasks = new ArrayList<>(); - FlowRemovedMaskBuilder maskBuilder; - for (int i = 0; i < SEPARATE_ROLES; i++) { - maskBuilder = new FlowRemovedMaskBuilder(); - maskBuilder.setMask(decodeFlowRemovedReasons(input.readUnsignedInt())); - inMasks.add(maskBuilder.build()); - } - return inMasks; - } - - private static List decodePacketInReasons(long input) { - List reasons = new ArrayList<>(); - if ((input & (1 << 0)) != 0) { - reasons.add(PacketInReason.OFPRNOMATCH); - } - if ((input & (1 << 1)) != 0) { - reasons.add(PacketInReason.OFPRACTION); - } - if ((input & (1 << 2)) != 0) { - reasons.add(PacketInReason.OFPRINVALIDTTL); - } - return reasons; - } - - private static List decodePortReasons(long input) { - List reasons = new ArrayList<>(); - if ((input & (1 << 0)) != 0) { - reasons.add(PortReason.OFPPRADD); - } - if ((input & (1 << 1)) != 0) { - reasons.add(PortReason.OFPPRDELETE); - } - if ((input & (1 << 2)) != 0) { - reasons.add(PortReason.OFPPRMODIFY); - } - return reasons; - } - - private static List decodeFlowRemovedReasons(long input) { - List reasons = new ArrayList<>(); - if ((input & (1 << 0)) != 0) { - reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT); - } - if ((input & (1 << 1)) != 0) { - reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT); - } - if ((input & (1 << 2)) != 0) { - reasons.add(FlowRemovedReason.OFPRRDELETE); - } - if ((input & (1 << 3)) != 0) { - reasons.add(FlowRemovedReason.OFPRRGROUPDELETE); - } - return reasons; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder; + +/** + * Translates GetAsyncReply messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class GetAsyncReplyMessageFactory implements OFDeserializer { + + private static GetAsyncReplyMessageFactory instance; + private static final byte SEPARATE_ROLES = 2; + + private GetAsyncReplyMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized GetAsyncReplyMessageFactory getInstance() { + if (instance == null) { + instance = new GetAsyncReplyMessageFactory(); + } + return instance; + } + + @Override + public GetAsyncOutput bufferToMessage(ByteBuf rawMessage, short version) { + GetAsyncOutputBuilder builder = new GetAsyncOutputBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setPacketInMask(decodePacketInMask(rawMessage)); + builder.setPortStatusMask(decodePortStatusMask(rawMessage)); + builder.setFlowRemovedMask(decodeFlowRemovedMask(rawMessage)); + return builder.build(); + } + + private static List decodePacketInMask(ByteBuf input) { + List inMasks = new ArrayList<>(); + PacketInMaskBuilder maskBuilder; + for (int i = 0; i < SEPARATE_ROLES; i++) { + maskBuilder = new PacketInMaskBuilder(); + maskBuilder.setMask(decodePacketInReasons(input.readUnsignedInt())); + inMasks.add(maskBuilder.build()); + } + return inMasks; + } + + private static List decodePortStatusMask(ByteBuf input) { + List inMasks = new ArrayList<>(); + PortStatusMaskBuilder maskBuilder; + for (int i = 0; i < SEPARATE_ROLES; i++) { + maskBuilder = new PortStatusMaskBuilder(); + maskBuilder.setMask(decodePortReasons(input.readUnsignedInt())); + inMasks.add(maskBuilder.build()); + } + return inMasks; + } + + private static List decodeFlowRemovedMask(ByteBuf input) { + List inMasks = new ArrayList<>(); + FlowRemovedMaskBuilder maskBuilder; + for (int i = 0; i < SEPARATE_ROLES; i++) { + maskBuilder = new FlowRemovedMaskBuilder(); + maskBuilder.setMask(decodeFlowRemovedReasons(input.readUnsignedInt())); + inMasks.add(maskBuilder.build()); + } + return inMasks; + } + + private static List decodePacketInReasons(long input) { + List reasons = new ArrayList<>(); + if ((input & (1 << 0)) != 0) { + reasons.add(PacketInReason.OFPRNOMATCH); + } + if ((input & (1 << 1)) != 0) { + reasons.add(PacketInReason.OFPRACTION); + } + if ((input & (1 << 2)) != 0) { + reasons.add(PacketInReason.OFPRINVALIDTTL); + } + return reasons; + } + + private static List decodePortReasons(long input) { + List reasons = new ArrayList<>(); + if ((input & (1 << 0)) != 0) { + reasons.add(PortReason.OFPPRADD); + } + if ((input & (1 << 1)) != 0) { + reasons.add(PortReason.OFPPRDELETE); + } + if ((input & (1 << 2)) != 0) { + reasons.add(PortReason.OFPPRMODIFY); + } + return reasons; + } + + private static List decodeFlowRemovedReasons(long input) { + List reasons = new ArrayList<>(); + if ((input & (1 << 0)) != 0) { + reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT); + } + if ((input & (1 << 1)) != 0) { + reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT); + } + if ((input & (1 << 2)) != 0) { + reasons.add(FlowRemovedReason.OFPRRDELETE); + } + if ((input & (1 << 3)) != 0) { + reasons.add(FlowRemovedReason.OFPRRGROUPDELETE); + } + return reasons; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java index 011e5ba4..95329132 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactory.java index 1523159f..eeb9893e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactory.java @@ -1,85 +1,92 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import java.util.ArrayList; -import java.util.List; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder; - -/** - * Translates Hello messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class HelloMessageFactory implements OFDeserializer { - - private static HelloMessageFactory instance; - - private HelloMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized HelloMessageFactory getInstance() { - if (instance == null) { - instance = new HelloMessageFactory(); - } - return instance; - } - - @Override - public HelloMessage bufferToMessage(ByteBuf rawMessage, short version) { - HelloMessageBuilder builder = new HelloMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - if (rawMessage.readableBytes() > 0) { - builder.setElements(readElement(rawMessage)); - } - return builder.build(); - } - - private static List readElement(ByteBuf input) { - List elementsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - ElementsBuilder elementsBuilder = new ElementsBuilder(); - int type = input.readUnsignedShort(); - int elementLength = input.readUnsignedShort(); - if (type == HelloElementType.VERSIONBITMAP.getIntValue()) { - elementsBuilder.setType(HelloElementType.forValue(type)); - int[] versionBitmap = new int[(elementLength - HelloInputMessageFactory.HELLO_ELEMENT_HEADER_SIZE) / 4]; - for (int i = 0; i < versionBitmap.length; i++) { - versionBitmap[i] = (int) input.readUnsignedInt(); - } - elementsBuilder.setVersionBitmap(readVersionBitmap(versionBitmap)); - int paddingRemainder = elementLength % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - input.readBytes(EncodeConstants.PADDING - paddingRemainder); - } - } - elementsList.add(elementsBuilder.build()); - } - return elementsList; - } - - private static List readVersionBitmap(int[] input){ - List versionBitmapList = new ArrayList<>(); - for (int i = 0; i < input.length; i++) { - int mask = input[i]; - for (int j = 0; j < Integer.SIZE; j++) { - versionBitmapList.add((mask & (1< { + + private static HelloMessageFactory instance; + + private HelloMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized HelloMessageFactory getInstance() { + if (instance == null) { + instance = new HelloMessageFactory(); + } + return instance; + } + + @Override + public HelloMessage bufferToMessage(ByteBuf rawMessage, short version) { + HelloMessageBuilder builder = new HelloMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + if (rawMessage.readableBytes() > 0) { + builder.setElements(readElement(rawMessage)); + } + return builder.build(); + } + + private static List readElement(ByteBuf input) { + List elementsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + ElementsBuilder elementsBuilder = new ElementsBuilder(); + int type = input.readUnsignedShort(); + int elementLength = input.readUnsignedShort(); + if (type == HelloElementType.VERSIONBITMAP.getIntValue()) { + elementsBuilder.setType(HelloElementType.forValue(type)); + int[] versionBitmap = new int[(elementLength - HelloInputMessageFactory.HELLO_ELEMENT_HEADER_SIZE) / 4]; + for (int i = 0; i < versionBitmap.length; i++) { + versionBitmap[i] = (int) input.readUnsignedInt(); + } + elementsBuilder.setVersionBitmap(readVersionBitmap(versionBitmap)); + int paddingRemainder = elementLength % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + input.readBytes(EncodeConstants.PADDING - paddingRemainder); + } + } + elementsList.add(elementsBuilder.build()); + } + return elementsList; + } + + private static List readVersionBitmap(int[] input){ + List versionBitmapList = new ArrayList<>(); + for (int i = 0; i < input.length; i++) { + int mask = input[i]; + for (int j = 0; j < Integer.SIZE; j++) { + versionBitmapList.add((mask & (1< { - - private static final byte PADDING_IN_MULTIPART_REPLY_HEADER = 4; - private static final int DESC_STR_LEN = 256; - private static final int SERIAL_NUM_LEN = 32; - private static final byte PADDING_IN_FLOW_STATS_HEADER_01 = 1; - private static final byte PADDING_IN_FLOW_STATS_HEADER_02 = 4; - private static final byte PADDING_IN_AGGREGATE_HEADER = 4; - private static final byte PADDING_IN_TABLE_HEADER = 3; - private static final byte PADDING_IN_MULTIPART_REPLY_TABLE_FEATURES = 5; - private static final byte MAX_TABLE_NAME_LENGTH = 32; - private static final byte MULTIPART_REPLY_TABLE_FEATURES_STRUCTURE_LENGTH = 64; - private static final byte COMMON_PROPERTY_LENGTH = 4; - private static final byte PADDING_IN_PORT_STATS_HEADER = 4; - private static final byte PADDING_IN_GROUP_HEADER_01 = 2; - private static final byte PADDING_IN_GROUP_HEADER_02 = 4; - private static final byte BUCKET_COUNTER_LENGTH = 16; - private static final byte GROUP_BODY_LENGTH = 40; - private static final byte PADDING_IN_METER_FEATURES_HEADER = 2; - private static final byte PADDING_IN_METER_STATS_HEADER = 6; - private static final byte METER_BAND_STATS_LENGTH = 16; - private static final byte METER_BODY_LENGTH = 40; - private static final byte METER_CONFIG_LENGTH = 8; - private static final byte PADDING_IN_METER_BAND_DROP_HEADER = 4; - private static final byte PADDING_IN_METER_BAND_DSCP_HEADER = 3; - private static final byte PADDING_IN_PORT_DESC_HEADER_01 = 4; - private static final byte PADDING_IN_PORT_DESC_HEADER_02 = 2; - private static final byte MAX_PORT_NAME_LEN = 16; - private static final int GROUP_TYPES = 4; - private static final byte PADDING_IN_GROUP_DESC_HEADER = 1; - private static final byte PADDING_IN_BUCKETS_HEADER = 4; - private static final byte GROUP_DESC_HEADER_LENGTH = 8; - private static final byte BUCKETS_HEADER_LENGTH = 16; - - - private static MultipartReplyMessageFactory instance; - - private MultipartReplyMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized MultipartReplyMessageFactory getInstance() { - if (instance == null){ - instance = new MultipartReplyMessageFactory(); - } - return instance; - } - - @Override - public MultipartReplyMessage bufferToMessage(ByteBuf rawMessage, short version) { - MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - int type = rawMessage.readUnsignedShort(); - builder.setType(MultipartType.forValue(type)); - builder.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) != 0)); - rawMessage.skipBytes(PADDING_IN_MULTIPART_REPLY_HEADER); - - switch (type) { - case 0: builder.setMultipartReplyBody(setDesc(rawMessage)); - break; - case 1: builder.setMultipartReplyBody(setFlow(rawMessage)); - break; - case 2: builder.setMultipartReplyBody(setAggregate(rawMessage)); - break; - case 3: builder.setMultipartReplyBody(setTable(rawMessage)); - break; - case 4: builder.setMultipartReplyBody(setPortStats(rawMessage)); - break; - case 5: builder.setMultipartReplyBody(setQueue(rawMessage)); - break; - case 6: builder.setMultipartReplyBody(setGroup(rawMessage)); - break; - case 7: builder.setMultipartReplyBody(setGroupDesc(rawMessage)); - break; - case 8: builder.setMultipartReplyBody(setGroupFeatures(rawMessage)); - break; - case 9: builder.setMultipartReplyBody(setMeter(rawMessage)); - break; - case 10: builder.setMultipartReplyBody(setMeterConfig(rawMessage)); - break; - case 11: builder.setMultipartReplyBody(setMeterFeatures(rawMessage)); - break; - case 12: builder.setMultipartReplyBody(setTableFeatures(rawMessage)); - break; - case 13: builder.setMultipartReplyBody(setPortDesc(rawMessage)); - break; - case 0xFFFF: builder.setMultipartReplyBody(setExperimenter(rawMessage)); - break; - default: - break; - } - - return builder.build(); - } - - private static MultipartReplyDesc setDesc(ByteBuf input) { - MultipartReplyDescBuilder descBuilder = new MultipartReplyDescBuilder(); - byte[] mfrDescBytes = new byte[DESC_STR_LEN]; - input.readBytes(mfrDescBytes); - String mfrDesc = new String(mfrDescBytes); - descBuilder.setMfrDesc(mfrDesc.trim()); - byte[] hwDescBytes = new byte[DESC_STR_LEN]; - input.readBytes(hwDescBytes); - String hwDesc = new String(hwDescBytes); - descBuilder.setHwDesc(hwDesc.trim()); - byte[] swDescBytes = new byte[DESC_STR_LEN]; - input.readBytes(swDescBytes); - String swDesc = new String(swDescBytes); - descBuilder.setSwDesc(swDesc.trim()); - byte[] serialNumBytes = new byte[SERIAL_NUM_LEN]; - input.readBytes(serialNumBytes); - String serialNum = new String(serialNumBytes); - descBuilder.setSerialNum(serialNum.trim()); - byte[] dpDescBytes = new byte[DESC_STR_LEN]; - input.readBytes(dpDescBytes); - String dpDesc = new String(dpDescBytes); - descBuilder.setDpDesc(dpDesc.trim()); - return descBuilder.build(); - } - - private static MultipartReplyFlow setFlow(ByteBuf input) { - MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder(); - List flowStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder(); - input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - flowStatsBuilder.setTableId(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01); - flowStatsBuilder.setDurationSec(input.readUnsignedInt()); - flowStatsBuilder.setDurationNsec(input.readUnsignedInt()); - flowStatsBuilder.setPriority(input.readUnsignedShort()); - flowStatsBuilder.setIdleTimeout(input.readUnsignedShort()); - flowStatsBuilder.setHardTimeout(input.readUnsignedShort()); - flowStatsBuilder.setFlags(createFlowModFlagsFromBitmap(input.readShort())); - input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02); - byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(cookie); - flowStatsBuilder.setCookie(new BigInteger(cookie)); - byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(packetCount); - flowStatsBuilder.setPacketCount(new BigInteger(packetCount)); - byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(byteCount); - flowStatsBuilder.setByteCount(new BigInteger(byteCount)); - flowStatsBuilder.setMatch(MatchDeserializer.createMatch(input)); - flowStatsBuilder.setInstructions(InstructionsDeserializer.createInstructions(input, input.readableBytes())); - flowStatsList.add(flowStatsBuilder.build()); - } - flowBuilder.setFlowStats(flowStatsList); - return flowBuilder.build(); - } - - private static FlowModFlags createFlowModFlagsFromBitmap(short input){ - final Boolean _oFPFFSENDFLOWREM = (input & (1 << 0)) != 0; - final Boolean _oFPFFCHECKOVERLAP = (input & (1 << 1)) != 0; - final Boolean _oFPFFRESETCOUNTS = (input & (1 << 2)) != 0; - final Boolean _oFPFFNOPKTCOUNTS = (input & (1 << 3)) != 0; - final Boolean _oFPFFNOBYTCOUNTS = (input & (1 << 4)) != 0; - return new FlowModFlags(_oFPFFCHECKOVERLAP, _oFPFFNOBYTCOUNTS, _oFPFFNOPKTCOUNTS, _oFPFFRESETCOUNTS, _oFPFFSENDFLOWREM); - } - - private static MultipartReplyAggregate setAggregate(ByteBuf input) { - MultipartReplyAggregateBuilder builder = new MultipartReplyAggregateBuilder(); - byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(packetCount); - builder.setPacketCount(new BigInteger(packetCount)); - byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(byteCount); - builder.setByteCount(new BigInteger(byteCount)); - builder.setFlowCount(input.readUnsignedInt()); - input.skipBytes(PADDING_IN_AGGREGATE_HEADER); - return builder.build(); - } - - private static MultipartReplyTable setTable(ByteBuf input) { - MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder(); - List tableStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - TableStatsBuilder tableStatsBuilder = new TableStatsBuilder(); - tableStatsBuilder.setTableId(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_TABLE_HEADER); - tableStatsBuilder.setActiveCount(input.readUnsignedInt()); - byte[] lookupCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(lookupCount); - tableStatsBuilder.setLookupCount(new BigInteger(lookupCount)); - byte[] matchedCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(matchedCount); - tableStatsBuilder.setMatchedCount(new BigInteger(matchedCount)); - tableStatsList.add(tableStatsBuilder.build()); - } - builder.setTableStats(tableStatsList); - return builder.build(); - } - - private static MultipartReplyTableFeatures setTableFeatures(ByteBuf input) { - MultipartReplyTableFeaturesBuilder builder = new MultipartReplyTableFeaturesBuilder(); - List features = new ArrayList<>(); - while (input.readableBytes() > 0) { - TableFeaturesBuilder featuresBuilder = new TableFeaturesBuilder(); - int length = input.readUnsignedShort(); - featuresBuilder.setTableId(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_MULTIPART_REPLY_TABLE_FEATURES); - featuresBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString()); - byte[] metadataMatch = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; - input.readBytes(metadataMatch); - featuresBuilder.setMetadataMatch(metadataMatch); - byte[] metadataWrite = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; - input.readBytes(metadataWrite); - featuresBuilder.setMetadataWrite(metadataWrite); - featuresBuilder.setConfig(createTableConfig(input.readUnsignedInt())); - featuresBuilder.setMaxEntries(input.readUnsignedInt()); - featuresBuilder.setTableFeatureProperties(createTableFeaturesProperties(input, - length - MULTIPART_REPLY_TABLE_FEATURES_STRUCTURE_LENGTH)); - features.add(featuresBuilder.build()); - } - builder.setTableFeatures(features); - return builder.build(); - } - - private static TableConfig createTableConfig(long input) { - boolean deprecated = (input & 3) != 0; - return new TableConfig(deprecated); - } - - private static List createTableFeaturesProperties(ByteBuf input, int length) { - List properties = new ArrayList<>(); - int tableFeaturesLength = length; - while (tableFeaturesLength > 0) { - TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder(); - TableFeaturesPropType type = TableFeaturesPropType.forValue(input.readUnsignedShort()); - builder.setType(type); - int propertyLength = input.readUnsignedShort(); - tableFeaturesLength -= propertyLength; - if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS) - || type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) { - InstructionRelatedTableFeaturePropertyBuilder insBuilder = new InstructionRelatedTableFeaturePropertyBuilder(); - insBuilder.setInstructions(InstructionsDeserializer.createInstructions(input, propertyLength - COMMON_PROPERTY_LENGTH)); - builder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insBuilder.build()); - } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES) - || type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS)) { - propertyLength -= COMMON_PROPERTY_LENGTH; - NextTableRelatedTableFeaturePropertyBuilder tableBuilder = new NextTableRelatedTableFeaturePropertyBuilder(); - List ids = new ArrayList<>(); - while (propertyLength > 0) { - NextTableIdsBuilder nextTableIdsBuilder = new NextTableIdsBuilder(); - nextTableIdsBuilder.setTableId(input.readUnsignedByte()); - ids.add(nextTableIdsBuilder.build()); - } - tableBuilder.setNextTableIds(ids); - builder.addAugmentation(NextTableRelatedTableFeatureProperty.class, tableBuilder.build()); - } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONS) - || type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS) - || type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONS) - || type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS)) { - ActionRelatedTableFeaturePropertyBuilder actionBuilder = new ActionRelatedTableFeaturePropertyBuilder(); - actionBuilder.setActionsList(ActionsDeserializer.createActionsList(input, propertyLength - COMMON_PROPERTY_LENGTH)); - builder.addAugmentation(ActionRelatedTableFeatureProperty.class, actionBuilder.build()); - } else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH) - || type.equals(TableFeaturesPropType.OFPTFPTWILDCARDS) - || type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELD) - || type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS) - || type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD) - || type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) { - OxmRelatedTableFeaturePropertyBuilder oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); - oxmBuilder.setMatchEntries(MatchDeserializer.createMatchEntries(input, propertyLength - COMMON_PROPERTY_LENGTH)); - builder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); - } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER) - || type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) { - final byte EXPERIMENTER_PROPERTY_LENGTH = 12; - ExperimenterRelatedTableFeaturePropertyBuilder expBuilder = new ExperimenterRelatedTableFeaturePropertyBuilder(); - expBuilder.setExperimenter(input.readUnsignedInt()); - expBuilder.setExpType(input.readUnsignedInt()); - byte[] data = new byte[propertyLength - EXPERIMENTER_PROPERTY_LENGTH]; - input.readBytes(data); - expBuilder.setData(data); - builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, expBuilder.build()); - } - properties.add(builder.build()); - } - return properties; - } - - private static MultipartReplyPortStats setPortStats(ByteBuf input) { - MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder(); - List portStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - PortStatsBuilder portStatsBuilder = new PortStatsBuilder(); - portStatsBuilder.setPortNo(input.readUnsignedInt()); - input.skipBytes(PADDING_IN_PORT_STATS_HEADER); - byte[] rxPackets = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxPackets); - portStatsBuilder.setRxPackets(new BigInteger(rxPackets)); - byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txPackets); - portStatsBuilder.setTxPackets(new BigInteger(txPackets)); - byte[] rxBytes = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxBytes); - portStatsBuilder.setRxBytes(new BigInteger(rxBytes)); - byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txBytes); - portStatsBuilder.setTxBytes(new BigInteger(txBytes)); - byte[] rxDropped = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxDropped); - portStatsBuilder.setRxDropped(new BigInteger(rxDropped)); - byte[] txDropped = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txDropped); - portStatsBuilder.setTxDropped(new BigInteger(txDropped)); - byte[] rxErrors = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxErrors); - portStatsBuilder.setRxErrors(new BigInteger(rxErrors)); - byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txErrors); - portStatsBuilder.setTxErrors(new BigInteger(txErrors)); - byte[] rxFrameErr = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxFrameErr); - portStatsBuilder.setRxFrameErr(new BigInteger(rxFrameErr)); - byte[] rxOverErr = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxOverErr); - portStatsBuilder.setRxOverErr(new BigInteger(rxOverErr)); - byte[] rxCrcErr = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxCrcErr); - portStatsBuilder.setRxCrcErr(new BigInteger(rxCrcErr)); - byte[] collisions = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(collisions); - portStatsBuilder.setCollisions(new BigInteger(collisions)); - portStatsBuilder.setDurationSec(input.readUnsignedInt()); - portStatsBuilder.setDurationNsec(input.readUnsignedInt()); - portStatsList.add(portStatsBuilder.build()); - } - builder.setPortStats(portStatsList); - return builder.build(); - } - - private static MultipartReplyQueue setQueue(ByteBuf input) { - MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder(); - List queueStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder(); - queueStatsBuilder.setPortNo(input.readUnsignedInt()); - queueStatsBuilder.setQueueId(input.readUnsignedInt()); - byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txBytes); - queueStatsBuilder.setTxBytes(new BigInteger(txBytes)); - byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txPackets); - queueStatsBuilder.setTxPackets(new BigInteger(txPackets)); - byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txErrors); - queueStatsBuilder.setTxErrors(new BigInteger(txErrors)); - queueStatsBuilder.setDurationSec(input.readUnsignedInt()); - queueStatsBuilder.setDurationNsec(input.readUnsignedInt()); - queueStatsList.add(queueStatsBuilder.build()); - } - builder.setQueueStats(queueStatsList); - return builder.build(); - } - - private static MultipartReplyGroup setGroup(ByteBuf input) { - MultipartReplyGroupBuilder builder = new MultipartReplyGroupBuilder(); - List groupStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - GroupStatsBuilder groupStatsBuilder = new GroupStatsBuilder(); - int bodyLength = input.readUnsignedShort(); - input.skipBytes(PADDING_IN_GROUP_HEADER_01); - groupStatsBuilder.setGroupId(new GroupId(input.readUnsignedInt())); - groupStatsBuilder.setRefCount(input.readUnsignedInt()); - input.skipBytes(PADDING_IN_GROUP_HEADER_02); - byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(packetCount); - groupStatsBuilder.setPacketCount(new BigInteger(packetCount)); - byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(byteCount); - groupStatsBuilder.setByteCount(new BigInteger(byteCount)); - groupStatsBuilder.setDurationSec(input.readUnsignedInt()); - groupStatsBuilder.setDurationNsec(input.readUnsignedInt()); - int actualLength = GROUP_BODY_LENGTH; - List bucketStatsList = new ArrayList<>(); - while (actualLength < bodyLength) { - BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder(); - byte[] packetCountBucket = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(packetCountBucket); - bucketStatsBuilder.setPacketCount(new BigInteger(packetCountBucket)); - byte[] byteCountBucket = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(byteCountBucket); - bucketStatsBuilder.setByteCount(new BigInteger(byteCountBucket)); - bucketStatsList.add(bucketStatsBuilder.build()); - actualLength += BUCKET_COUNTER_LENGTH; - } - groupStatsBuilder.setBucketStats(bucketStatsList); - groupStatsList.add(groupStatsBuilder.build()); - } - builder.setGroupStats(groupStatsList); - return builder.build(); - } - - private static MultipartReplyMeterFeatures setMeterFeatures(ByteBuf input) { - MultipartReplyMeterFeaturesBuilder builder = new MultipartReplyMeterFeaturesBuilder(); - builder.setMaxMeter(input.readUnsignedInt()); - builder.setBandTypes(createMeterBandsBitmap(input.readUnsignedInt())); - builder.setCapabilities(createMeterFlags(input.readUnsignedInt())); - builder.setMaxBands(input.readUnsignedByte()); - builder.setMaxColor(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_METER_FEATURES_HEADER); - return builder.build(); - } - - private static MeterFlags createMeterFlags(long input){ - final Boolean _oFPMFKBPS = (input & (1 << 0)) != 0; - final Boolean _oFPMFPKTPS = (input & (1 << 1)) != 0; - final Boolean _oFPMFBURST = (input & (1 << 2)) != 0; - final Boolean _oFPMFSTATS = (input & (1 << 3)) != 0; - return new MeterFlags(_oFPMFBURST, _oFPMFKBPS, _oFPMFPKTPS, _oFPMFSTATS); - } - - private static MeterBandTypeBitmap createMeterBandsBitmap(long input) { - final Boolean _oFPMBTDROP = (input & (1 << 0)) != 0; - final Boolean _oFPMBTDSCPREMARK = (input & (1 << 1)) != 0; - return new MeterBandTypeBitmap(_oFPMBTDROP, _oFPMBTDSCPREMARK); - } - - private static MultipartReplyMeter setMeter(ByteBuf input) { - MultipartReplyMeterBuilder builder = new MultipartReplyMeterBuilder(); - List meterStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder(); - meterStatsBuilder.setMeterId(new MeterId(input.readUnsignedInt())); - int meterStatsBodyLength = input.readUnsignedShort(); - input.skipBytes(PADDING_IN_METER_STATS_HEADER); - meterStatsBuilder.setFlowCount(input.readUnsignedInt()); - byte[] packetInCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(packetInCount); - meterStatsBuilder.setPacketInCount(new BigInteger(packetInCount)); - byte[] byteInCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(byteInCount); - meterStatsBuilder.setByteInCount(new BigInteger(byteInCount)); - meterStatsBuilder.setDurationSec(input.readUnsignedInt()); - meterStatsBuilder.setDurationNsec(input.readUnsignedInt()); - int actualLength = METER_BODY_LENGTH; - List meterBandStatsList = new ArrayList<>(); - while (actualLength < meterStatsBodyLength) { - MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder(); - byte[] packetBandCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(packetBandCount); - meterBandStatsBuilder.setPacketBandCount(new BigInteger(packetBandCount)); - byte[] byteBandCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(byteBandCount); - meterBandStatsBuilder.setByteBandCount(new BigInteger(byteBandCount)); - meterBandStatsList.add(meterBandStatsBuilder.build()); - actualLength += METER_BAND_STATS_LENGTH; - } - meterStatsBuilder.setMeterBandStats(meterBandStatsList); - meterStatsList.add(meterStatsBuilder.build()); - } - builder.setMeterStats(meterStatsList); - return builder.build(); - } - - private static MultipartReplyMeterConfig setMeterConfig(ByteBuf input) { - MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder(); - List meterConfigList = new ArrayList<>(); - while (input.readableBytes() > 0) { - MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder(); - int meterConfigBodyLength = input.readUnsignedShort(); - meterConfigBuilder.setFlags(createMeterFlags(input.readUnsignedShort())); - meterConfigBuilder.setMeterId(new MeterId(input.readUnsignedInt())); - int actualLength = METER_CONFIG_LENGTH; - List bandsList = new ArrayList<>(); - while (actualLength < meterConfigBodyLength) { - BandsBuilder bandsBuilder = new BandsBuilder(); - int bandType = input.readUnsignedShort(); - switch (bandType) { - case 1: - MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder(); - bandDropBuilder.setType(MeterBandType.forValue(bandType)); - actualLength += input.readUnsignedShort(); - bandDropBuilder.setRate(input.readUnsignedInt()); - bandDropBuilder.setBurstSize(input.readUnsignedInt()); - input.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER); - bandsBuilder.setMeterBand(bandDropBuilder.build()); - break; - case 2: - MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder(); - bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType)); - actualLength += input.readUnsignedShort(); - bandDscpRemarkBuilder.setRate(input.readUnsignedInt()); - bandDscpRemarkBuilder.setBurstSize(input.readUnsignedInt()); - bandDscpRemarkBuilder.setPrecLevel(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER); - bandsBuilder.setMeterBand(bandDscpRemarkBuilder.build()); - break; - case 0xFFFF: - MeterBandExperimenterBuilder bandExperimenterBuilder = new MeterBandExperimenterBuilder(); - bandExperimenterBuilder.setType(MeterBandType.forValue(bandType)); - actualLength += input.readUnsignedShort(); - bandExperimenterBuilder.setRate(input.readUnsignedInt()); - bandExperimenterBuilder.setBurstSize(input.readUnsignedInt()); - bandExperimenterBuilder.setExperimenter(input.readUnsignedInt()); - bandsBuilder.setMeterBand(bandExperimenterBuilder.build()); - break; - default: - break; - } - bandsList.add(bandsBuilder.build()); - } - meterConfigBuilder.setBands(bandsList); - meterConfigList.add(meterConfigBuilder.build()); - } - builder.setMeterConfig(meterConfigList); - return builder.build(); - } - - private static MultipartReplyExperimenter setExperimenter(ByteBuf input) { - MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder(); - builder.setExperimenter(input.readUnsignedInt()); - builder.setExpType(input.readUnsignedInt()); - byte[] data = new byte[input.readableBytes()]; - input.readBytes(data); - builder.setData(data); - return builder.build(); - } - - private static MultipartReplyPortDesc setPortDesc(ByteBuf input) { - MultipartReplyPortDescBuilder builder = new MultipartReplyPortDescBuilder(); - List portsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - PortsBuilder portsBuilder = new PortsBuilder(); - portsBuilder.setPortNo(input.readUnsignedInt()); - input.skipBytes(PADDING_IN_PORT_DESC_HEADER_01); - byte[] hwAddress = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - input.readBytes(hwAddress); - portsBuilder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(hwAddress))); - input.skipBytes(PADDING_IN_PORT_DESC_HEADER_02); - byte[] portNameBytes = new byte[MAX_PORT_NAME_LEN]; - input.readBytes(portNameBytes); - String portName = new String(portNameBytes); - portsBuilder.setName(portName.trim()); - portsBuilder.setConfig(createPortConfig(input.readUnsignedInt())); - portsBuilder.setState(createPortState(input.readUnsignedInt())); - portsBuilder.setCurrentFeatures(createPortFeatures(input.readUnsignedInt())); - portsBuilder.setAdvertisedFeatures(createPortFeatures(input.readUnsignedInt())); - portsBuilder.setSupportedFeatures(createPortFeatures(input.readUnsignedInt())); - portsBuilder.setPeerFeatures(createPortFeatures(input.readUnsignedInt())); - portsBuilder.setCurrSpeed(input.readUnsignedInt()); - portsBuilder.setMaxSpeed(input.readUnsignedInt()); - portsList.add(portsBuilder.build()); - } - builder.setPorts(portsList); - return builder.build(); - } - - private static PortConfig createPortConfig(long input){ - final Boolean _portDown = ((input) & (1<<0)) != 0; - final Boolean _noRecv = ((input) & (1<<2)) != 0; - final Boolean _noFwd = ((input) & (1<<5)) != 0; - final Boolean _noPacketIn = ((input) & (1<<6)) != 0; - return new PortConfig(_noFwd, _noPacketIn, _noRecv, _portDown); - } - - private static PortState createPortState(long input){ - final Boolean _linkDown = ((input) & (1<<0)) != 0; - final Boolean _blocked = ((input) & (1<<1)) != 0; - final Boolean _live = ((input) & (1<<2)) != 0; - return new PortState(_blocked, _linkDown, _live); - } - - private static PortFeatures createPortFeatures(long input){ - final Boolean _10mbHd = ((input) & (1<<0)) != 0; - final Boolean _10mbFd = ((input) & (1<<1)) != 0; - final Boolean _100mbHd = ((input) & (1<<2)) != 0; - final Boolean _100mbFd = ((input) & (1<<3)) != 0; - final Boolean _1gbHd = ((input) & (1<<4)) != 0; - final Boolean _1gbFd = ((input) & (1<<5)) != 0; - final Boolean _10gbFd = ((input) & (1<<6)) != 0; - final Boolean _40gbFd = ((input) & (1<<7)) != 0; - final Boolean _100gbFd = ((input) & (1<<8)) != 0; - final Boolean _1tbFd = ((input) & (1<<9)) != 0; - final Boolean _other = ((input) & (1<<10)) != 0; - final Boolean _copper = ((input) & (1<<11)) != 0; - final Boolean _fiber = ((input) & (1<<12)) != 0; - final Boolean _autoneg = ((input) & (1<<13)) != 0; - final Boolean _pause = ((input) & (1<<14)) != 0; - final Boolean _pauseAsym = ((input) & (1<<15)) != 0; - return new PortFeatures(_10mbHd, _10mbFd, _100mbHd, _100mbFd, _1gbHd, _1gbFd, _10gbFd, - _40gbFd, _100gbFd, _1tbFd, _other, _copper, _fiber, _autoneg, _pause, _pauseAsym); - } - - private static MultipartReplyBody setGroupFeatures(ByteBuf rawMessage) { - MultipartReplyGroupFeaturesBuilder featuresBuilder = new MultipartReplyGroupFeaturesBuilder(); - featuresBuilder.setTypes(createGroupType(rawMessage.readUnsignedInt())); - featuresBuilder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt())); - List maxGroupsList = new ArrayList<>(); - for (int i = 0; i < GROUP_TYPES ; i++) { - maxGroupsList.add(rawMessage.readUnsignedInt()); - } - featuresBuilder.setMaxGroups(maxGroupsList); - List actionBitmaps = new ArrayList<>(); - for (int i = 0; i < GROUP_TYPES ; i++) { - actionBitmaps.add(createActionBitmap(rawMessage.readUnsignedInt())); - } - featuresBuilder.setActionsBitmap(actionBitmaps); - return featuresBuilder.build(); - } - - private static ActionType createActionBitmap(long input) { - final Boolean OFPAT_OUTPUT = ((input) & (1<<0)) != 0; - final Boolean OFPAT_COPY_TTL_OUT = ((input) & (1<<1)) != 0; - final Boolean OFPAT_COPY_TTL_IN = ((input) & (1<<2)) != 0; - final Boolean OFPAT_SET_MPLS_TTL = ((input) & (1<<3)) != 0; - final Boolean OFPAT_DEC_MPLS_TTL = ((input) & (1<<4)) != 0; - final Boolean OFPAT_PUSH_VLAN = ((input) & (1<<5)) != 0; - final Boolean OFPAT_POP_VLAN = ((input) & (1<<6)) != 0; - final Boolean OFPAT_PUSH_MPLS = ((input) & (1<<7)) != 0; - final Boolean OFPAT_POP_MPLS = ((input) & (1<<8)) != 0; - final Boolean OFPAT_SET_QUEUE = ((input) & (1<<9)) != 0; - final Boolean OFPAT_GROUP = ((input) & (1<<10)) != 0; - final Boolean OFPAT_SET_NW_TTL = ((input) & (1<<11)) != 0; - final Boolean OFPAT_DEC_NW_TTL = ((input) & (1<<12)) != 0; - final Boolean OFPAT_SET_FIELD = ((input) & (1<<13)) != 0; - final Boolean OFPAT_PUSH_PBB = ((input) & (1<<14)) != 0; - final Boolean OFPAT_POP_PBB = ((input) & (1<<15)) != 0; - final Boolean OFPAT_EXPERIMENTER = ((input) & (1<<16)) != 0; - return new ActionType(OFPAT_COPY_TTL_IN, OFPAT_COPY_TTL_OUT, OFPAT_DEC_MPLS_TTL, - OFPAT_DEC_NW_TTL, OFPAT_EXPERIMENTER, OFPAT_GROUP, OFPAT_OUTPUT, OFPAT_POP_MPLS, - OFPAT_POP_PBB, OFPAT_POP_VLAN, OFPAT_PUSH_MPLS, OFPAT_PUSH_PBB, OFPAT_PUSH_VLAN, - OFPAT_SET_FIELD, OFPAT_SET_MPLS_TTL, OFPAT_SET_NW_TTL, OFPAT_SET_QUEUE); - } - - private static GroupCapabilities createCapabilities(long input) { - final Boolean OFOFPGFC_SELECT_WEIGHT = ((input) & (1<<0)) != 0; - final Boolean OFPGFC_SELECT_LIVENESS = ((input) & (1<<1)) != 0; - final Boolean OFPGFC_CHAINING = ((input) & (1<<2)) != 0; - final Boolean OFPGFC_CHAINING_CHECKS = ((input) & (1<<3)) != 0; - return new GroupCapabilities(OFPGFC_CHAINING, OFPGFC_CHAINING_CHECKS, OFPGFC_SELECT_LIVENESS, OFOFPGFC_SELECT_WEIGHT); - } - - private static GroupTypes createGroupType(long input) { - final Boolean OFPGT_ALL = ((input) & (1<<0)) != 0; - final Boolean OFPGT_SELECT = ((input) & (1<<1)) != 0; - final Boolean OFPGT_INDIRECT = ((input) & (1<<2)) != 0; - final Boolean OFPGT_FF = ((input) & (1<<3)) != 0; - return new GroupTypes(OFPGT_ALL, OFPGT_FF, OFPGT_INDIRECT, OFPGT_SELECT); - } - - private static MultipartReplyGroupDesc setGroupDesc(ByteBuf input) { - MultipartReplyGroupDescBuilder builder = new MultipartReplyGroupDescBuilder(); - List groupDescsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - GroupDescBuilder groupDescBuilder = new GroupDescBuilder(); - int bodyLength = input.readUnsignedShort(); - groupDescBuilder.setType(GroupType.forValue(input.readUnsignedByte())); - input.skipBytes(PADDING_IN_GROUP_DESC_HEADER); - groupDescBuilder.setGroupId(new GroupId(input.readUnsignedInt())); - int actualLength = GROUP_DESC_HEADER_LENGTH; - List bucketsList = new ArrayList<>(); - while (actualLength < bodyLength) { - BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); - int bucketsLength = input.readUnsignedShort(); - bucketsBuilder.setWeight(input.readUnsignedShort()); - bucketsBuilder.setWatchPort(new PortNumber(input.readUnsignedInt())); - bucketsBuilder.setWatchGroup(input.readUnsignedInt()); - input.skipBytes(PADDING_IN_BUCKETS_HEADER); - List actionsList = ActionsDeserializer - .createActionsList(input, bucketsLength - BUCKETS_HEADER_LENGTH); - bucketsBuilder.setActionsList(actionsList); - bucketsList.add(bucketsBuilder.build()); - actualLength += bucketsLength; - } - groupDescBuilder.setBucketsList(bucketsList); - groupDescsList.add(groupDescBuilder.build()); - } - builder.setGroupDesc(groupDescsList); - return builder.build(); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.InstructionsDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIdsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.MultipartReplyBody; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow.FlowStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow.FlowStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.GroupStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.GroupStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc.GroupDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc.GroupDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.group.stats.BucketStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.group.stats.BucketStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.MeterStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.MeterStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config.MeterConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config.MeterConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config.meter.config.Bands; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config.meter.config.BandsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.meter.stats.MeterBandStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.meter.stats.MeterBandStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc.Ports; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc.PortsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats.PortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats.PortStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue.QueueStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue.QueueStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.TableStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.TableStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features.TableFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features.TableFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeatureProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeaturePropertiesBuilder; + +/** + * Translates MultipartReply messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class MultipartReplyMessageFactory implements OFDeserializer { + + private static final byte PADDING_IN_MULTIPART_REPLY_HEADER = 4; + private static final int DESC_STR_LEN = 256; + private static final int SERIAL_NUM_LEN = 32; + private static final byte PADDING_IN_FLOW_STATS_HEADER_01 = 1; + private static final byte PADDING_IN_FLOW_STATS_HEADER_02 = 4; + private static final byte PADDING_IN_AGGREGATE_HEADER = 4; + private static final byte PADDING_IN_TABLE_HEADER = 3; + private static final byte PADDING_IN_MULTIPART_REPLY_TABLE_FEATURES = 5; + private static final byte MAX_TABLE_NAME_LENGTH = 32; + private static final byte MULTIPART_REPLY_TABLE_FEATURES_STRUCTURE_LENGTH = 64; + private static final byte COMMON_PROPERTY_LENGTH = 4; + private static final byte PADDING_IN_PORT_STATS_HEADER = 4; + private static final byte PADDING_IN_GROUP_HEADER_01 = 2; + private static final byte PADDING_IN_GROUP_HEADER_02 = 4; + private static final byte BUCKET_COUNTER_LENGTH = 16; + private static final byte GROUP_BODY_LENGTH = 40; + private static final byte PADDING_IN_METER_FEATURES_HEADER = 2; + private static final byte PADDING_IN_METER_STATS_HEADER = 6; + private static final byte METER_BAND_STATS_LENGTH = 16; + private static final byte METER_BODY_LENGTH = 40; + private static final byte METER_CONFIG_LENGTH = 8; + private static final byte PADDING_IN_METER_BAND_DROP_HEADER = 4; + private static final byte PADDING_IN_METER_BAND_DSCP_HEADER = 3; + private static final byte PADDING_IN_PORT_DESC_HEADER_01 = 4; + private static final byte PADDING_IN_PORT_DESC_HEADER_02 = 2; + private static final byte MAX_PORT_NAME_LEN = 16; + private static final int GROUP_TYPES = 4; + private static final byte PADDING_IN_GROUP_DESC_HEADER = 1; + private static final byte PADDING_IN_BUCKETS_HEADER = 4; + private static final byte GROUP_DESC_HEADER_LENGTH = 8; + private static final byte BUCKETS_HEADER_LENGTH = 16; + + + private static MultipartReplyMessageFactory instance; + + private MultipartReplyMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized MultipartReplyMessageFactory getInstance() { + if (instance == null){ + instance = new MultipartReplyMessageFactory(); + } + return instance; + } + + @Override + public MultipartReplyMessage bufferToMessage(ByteBuf rawMessage, short version) { + MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + int type = rawMessage.readUnsignedShort(); + builder.setType(MultipartType.forValue(type)); + builder.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) != 0)); + rawMessage.skipBytes(PADDING_IN_MULTIPART_REPLY_HEADER); + + switch (type) { + case 0: builder.setMultipartReplyBody(setDesc(rawMessage)); + break; + case 1: builder.setMultipartReplyBody(setFlow(rawMessage)); + break; + case 2: builder.setMultipartReplyBody(setAggregate(rawMessage)); + break; + case 3: builder.setMultipartReplyBody(setTable(rawMessage)); + break; + case 4: builder.setMultipartReplyBody(setPortStats(rawMessage)); + break; + case 5: builder.setMultipartReplyBody(setQueue(rawMessage)); + break; + case 6: builder.setMultipartReplyBody(setGroup(rawMessage)); + break; + case 7: builder.setMultipartReplyBody(setGroupDesc(rawMessage)); + break; + case 8: builder.setMultipartReplyBody(setGroupFeatures(rawMessage)); + break; + case 9: builder.setMultipartReplyBody(setMeter(rawMessage)); + break; + case 10: builder.setMultipartReplyBody(setMeterConfig(rawMessage)); + break; + case 11: builder.setMultipartReplyBody(setMeterFeatures(rawMessage)); + break; + case 12: builder.setMultipartReplyBody(setTableFeatures(rawMessage)); + break; + case 13: builder.setMultipartReplyBody(setPortDesc(rawMessage)); + break; + case 0xFFFF: builder.setMultipartReplyBody(setExperimenter(rawMessage)); + break; + default: + break; + } + + return builder.build(); + } + + private static MultipartReplyDesc setDesc(ByteBuf input) { + MultipartReplyDescBuilder descBuilder = new MultipartReplyDescBuilder(); + byte[] mfrDescBytes = new byte[DESC_STR_LEN]; + input.readBytes(mfrDescBytes); + String mfrDesc = new String(mfrDescBytes); + descBuilder.setMfrDesc(mfrDesc.trim()); + byte[] hwDescBytes = new byte[DESC_STR_LEN]; + input.readBytes(hwDescBytes); + String hwDesc = new String(hwDescBytes); + descBuilder.setHwDesc(hwDesc.trim()); + byte[] swDescBytes = new byte[DESC_STR_LEN]; + input.readBytes(swDescBytes); + String swDesc = new String(swDescBytes); + descBuilder.setSwDesc(swDesc.trim()); + byte[] serialNumBytes = new byte[SERIAL_NUM_LEN]; + input.readBytes(serialNumBytes); + String serialNum = new String(serialNumBytes); + descBuilder.setSerialNum(serialNum.trim()); + byte[] dpDescBytes = new byte[DESC_STR_LEN]; + input.readBytes(dpDescBytes); + String dpDesc = new String(dpDescBytes); + descBuilder.setDpDesc(dpDesc.trim()); + return descBuilder.build(); + } + + private static MultipartReplyFlow setFlow(ByteBuf input) { + MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder(); + List flowStatsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + flowStatsBuilder.setTableId(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01); + flowStatsBuilder.setDurationSec(input.readUnsignedInt()); + flowStatsBuilder.setDurationNsec(input.readUnsignedInt()); + flowStatsBuilder.setPriority(input.readUnsignedShort()); + flowStatsBuilder.setIdleTimeout(input.readUnsignedShort()); + flowStatsBuilder.setHardTimeout(input.readUnsignedShort()); + flowStatsBuilder.setFlags(createFlowModFlagsFromBitmap(input.readShort())); + input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02); + byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(cookie); + flowStatsBuilder.setCookie(new BigInteger(cookie)); + byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(packetCount); + flowStatsBuilder.setPacketCount(new BigInteger(packetCount)); + byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(byteCount); + flowStatsBuilder.setByteCount(new BigInteger(byteCount)); + flowStatsBuilder.setMatch(MatchDeserializer.createMatch(input)); + flowStatsBuilder.setInstructions(InstructionsDeserializer.createInstructions(input, input.readableBytes())); + flowStatsList.add(flowStatsBuilder.build()); + } + flowBuilder.setFlowStats(flowStatsList); + return flowBuilder.build(); + } + + private static FlowModFlags createFlowModFlagsFromBitmap(short input){ + final Boolean _oFPFFSENDFLOWREM = (input & (1 << 0)) != 0; + final Boolean _oFPFFCHECKOVERLAP = (input & (1 << 1)) != 0; + final Boolean _oFPFFRESETCOUNTS = (input & (1 << 2)) != 0; + final Boolean _oFPFFNOPKTCOUNTS = (input & (1 << 3)) != 0; + final Boolean _oFPFFNOBYTCOUNTS = (input & (1 << 4)) != 0; + return new FlowModFlags(_oFPFFCHECKOVERLAP, _oFPFFNOBYTCOUNTS, _oFPFFNOPKTCOUNTS, _oFPFFRESETCOUNTS, _oFPFFSENDFLOWREM); + } + + private static MultipartReplyAggregate setAggregate(ByteBuf input) { + MultipartReplyAggregateBuilder builder = new MultipartReplyAggregateBuilder(); + byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(packetCount); + builder.setPacketCount(new BigInteger(packetCount)); + byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(byteCount); + builder.setByteCount(new BigInteger(byteCount)); + builder.setFlowCount(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_AGGREGATE_HEADER); + return builder.build(); + } + + private static MultipartReplyTable setTable(ByteBuf input) { + MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder(); + List tableStatsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + TableStatsBuilder tableStatsBuilder = new TableStatsBuilder(); + tableStatsBuilder.setTableId(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_TABLE_HEADER); + tableStatsBuilder.setActiveCount(input.readUnsignedInt()); + byte[] lookupCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(lookupCount); + tableStatsBuilder.setLookupCount(new BigInteger(lookupCount)); + byte[] matchedCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(matchedCount); + tableStatsBuilder.setMatchedCount(new BigInteger(matchedCount)); + tableStatsList.add(tableStatsBuilder.build()); + } + builder.setTableStats(tableStatsList); + return builder.build(); + } + + private static MultipartReplyTableFeatures setTableFeatures(ByteBuf input) { + MultipartReplyTableFeaturesBuilder builder = new MultipartReplyTableFeaturesBuilder(); + List features = new ArrayList<>(); + while (input.readableBytes() > 0) { + TableFeaturesBuilder featuresBuilder = new TableFeaturesBuilder(); + int length = input.readUnsignedShort(); + featuresBuilder.setTableId(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_MULTIPART_REPLY_TABLE_FEATURES); + featuresBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString()); + byte[] metadataMatch = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + input.readBytes(metadataMatch); + featuresBuilder.setMetadataMatch(metadataMatch); + byte[] metadataWrite = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + input.readBytes(metadataWrite); + featuresBuilder.setMetadataWrite(metadataWrite); + featuresBuilder.setConfig(createTableConfig(input.readUnsignedInt())); + featuresBuilder.setMaxEntries(input.readUnsignedInt()); + featuresBuilder.setTableFeatureProperties(createTableFeaturesProperties(input, + length - MULTIPART_REPLY_TABLE_FEATURES_STRUCTURE_LENGTH)); + features.add(featuresBuilder.build()); + } + builder.setTableFeatures(features); + return builder.build(); + } + + private static TableConfig createTableConfig(long input) { + boolean deprecated = (input & 3) != 0; + return new TableConfig(deprecated); + } + + private static List createTableFeaturesProperties(ByteBuf input, int length) { + List properties = new ArrayList<>(); + int tableFeaturesLength = length; + while (tableFeaturesLength > 0) { + TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder(); + TableFeaturesPropType type = TableFeaturesPropType.forValue(input.readUnsignedShort()); + builder.setType(type); + int propertyLength = input.readUnsignedShort(); + tableFeaturesLength -= propertyLength; + if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS) + || type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) { + InstructionRelatedTableFeaturePropertyBuilder insBuilder = new InstructionRelatedTableFeaturePropertyBuilder(); + insBuilder.setInstructions(InstructionsDeserializer.createInstructions(input, propertyLength - COMMON_PROPERTY_LENGTH)); + builder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insBuilder.build()); + } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES) + || type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS)) { + propertyLength -= COMMON_PROPERTY_LENGTH; + NextTableRelatedTableFeaturePropertyBuilder tableBuilder = new NextTableRelatedTableFeaturePropertyBuilder(); + List ids = new ArrayList<>(); + while (propertyLength > 0) { + NextTableIdsBuilder nextTableIdsBuilder = new NextTableIdsBuilder(); + nextTableIdsBuilder.setTableId(input.readUnsignedByte()); + ids.add(nextTableIdsBuilder.build()); + } + tableBuilder.setNextTableIds(ids); + builder.addAugmentation(NextTableRelatedTableFeatureProperty.class, tableBuilder.build()); + } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONS) + || type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS) + || type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONS) + || type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS)) { + ActionRelatedTableFeaturePropertyBuilder actionBuilder = new ActionRelatedTableFeaturePropertyBuilder(); + actionBuilder.setActionsList(ActionsDeserializer.createActionsList(input, propertyLength - COMMON_PROPERTY_LENGTH)); + builder.addAugmentation(ActionRelatedTableFeatureProperty.class, actionBuilder.build()); + } else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH) + || type.equals(TableFeaturesPropType.OFPTFPTWILDCARDS) + || type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELD) + || type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS) + || type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD) + || type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) { + OxmRelatedTableFeaturePropertyBuilder oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); + oxmBuilder.setMatchEntries(MatchDeserializer.createMatchEntries(input, propertyLength - COMMON_PROPERTY_LENGTH)); + builder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); + } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER) + || type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) { + final byte EXPERIMENTER_PROPERTY_LENGTH = 12; + ExperimenterRelatedTableFeaturePropertyBuilder expBuilder = new ExperimenterRelatedTableFeaturePropertyBuilder(); + expBuilder.setExperimenter(input.readUnsignedInt()); + expBuilder.setExpType(input.readUnsignedInt()); + byte[] data = new byte[propertyLength - EXPERIMENTER_PROPERTY_LENGTH]; + input.readBytes(data); + expBuilder.setData(data); + builder.addAugmentation(ExperimenterRelatedTableFeatureProperty.class, expBuilder.build()); + } + properties.add(builder.build()); + } + return properties; + } + + private static MultipartReplyPortStats setPortStats(ByteBuf input) { + MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder(); + List portStatsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + PortStatsBuilder portStatsBuilder = new PortStatsBuilder(); + portStatsBuilder.setPortNo(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_PORT_STATS_HEADER); + byte[] rxPackets = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxPackets); + portStatsBuilder.setRxPackets(new BigInteger(rxPackets)); + byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txPackets); + portStatsBuilder.setTxPackets(new BigInteger(txPackets)); + byte[] rxBytes = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxBytes); + portStatsBuilder.setRxBytes(new BigInteger(rxBytes)); + byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txBytes); + portStatsBuilder.setTxBytes(new BigInteger(txBytes)); + byte[] rxDropped = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxDropped); + portStatsBuilder.setRxDropped(new BigInteger(rxDropped)); + byte[] txDropped = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txDropped); + portStatsBuilder.setTxDropped(new BigInteger(txDropped)); + byte[] rxErrors = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxErrors); + portStatsBuilder.setRxErrors(new BigInteger(rxErrors)); + byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txErrors); + portStatsBuilder.setTxErrors(new BigInteger(txErrors)); + byte[] rxFrameErr = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxFrameErr); + portStatsBuilder.setRxFrameErr(new BigInteger(rxFrameErr)); + byte[] rxOverErr = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxOverErr); + portStatsBuilder.setRxOverErr(new BigInteger(rxOverErr)); + byte[] rxCrcErr = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxCrcErr); + portStatsBuilder.setRxCrcErr(new BigInteger(rxCrcErr)); + byte[] collisions = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(collisions); + portStatsBuilder.setCollisions(new BigInteger(collisions)); + portStatsBuilder.setDurationSec(input.readUnsignedInt()); + portStatsBuilder.setDurationNsec(input.readUnsignedInt()); + portStatsList.add(portStatsBuilder.build()); + } + builder.setPortStats(portStatsList); + return builder.build(); + } + + private static MultipartReplyQueue setQueue(ByteBuf input) { + MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder(); + List queueStatsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder(); + queueStatsBuilder.setPortNo(input.readUnsignedInt()); + queueStatsBuilder.setQueueId(input.readUnsignedInt()); + byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txBytes); + queueStatsBuilder.setTxBytes(new BigInteger(txBytes)); + byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txPackets); + queueStatsBuilder.setTxPackets(new BigInteger(txPackets)); + byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txErrors); + queueStatsBuilder.setTxErrors(new BigInteger(txErrors)); + queueStatsBuilder.setDurationSec(input.readUnsignedInt()); + queueStatsBuilder.setDurationNsec(input.readUnsignedInt()); + queueStatsList.add(queueStatsBuilder.build()); + } + builder.setQueueStats(queueStatsList); + return builder.build(); + } + + private static MultipartReplyGroup setGroup(ByteBuf input) { + MultipartReplyGroupBuilder builder = new MultipartReplyGroupBuilder(); + List groupStatsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + GroupStatsBuilder groupStatsBuilder = new GroupStatsBuilder(); + int bodyLength = input.readUnsignedShort(); + input.skipBytes(PADDING_IN_GROUP_HEADER_01); + groupStatsBuilder.setGroupId(new GroupId(input.readUnsignedInt())); + groupStatsBuilder.setRefCount(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_GROUP_HEADER_02); + byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(packetCount); + groupStatsBuilder.setPacketCount(new BigInteger(packetCount)); + byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(byteCount); + groupStatsBuilder.setByteCount(new BigInteger(byteCount)); + groupStatsBuilder.setDurationSec(input.readUnsignedInt()); + groupStatsBuilder.setDurationNsec(input.readUnsignedInt()); + int actualLength = GROUP_BODY_LENGTH; + List bucketStatsList = new ArrayList<>(); + while (actualLength < bodyLength) { + BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder(); + byte[] packetCountBucket = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(packetCountBucket); + bucketStatsBuilder.setPacketCount(new BigInteger(packetCountBucket)); + byte[] byteCountBucket = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(byteCountBucket); + bucketStatsBuilder.setByteCount(new BigInteger(byteCountBucket)); + bucketStatsList.add(bucketStatsBuilder.build()); + actualLength += BUCKET_COUNTER_LENGTH; + } + groupStatsBuilder.setBucketStats(bucketStatsList); + groupStatsList.add(groupStatsBuilder.build()); + } + builder.setGroupStats(groupStatsList); + return builder.build(); + } + + private static MultipartReplyMeterFeatures setMeterFeatures(ByteBuf input) { + MultipartReplyMeterFeaturesBuilder builder = new MultipartReplyMeterFeaturesBuilder(); + builder.setMaxMeter(input.readUnsignedInt()); + builder.setBandTypes(createMeterBandsBitmap(input.readUnsignedInt())); + builder.setCapabilities(createMeterFlags(input.readUnsignedInt())); + builder.setMaxBands(input.readUnsignedByte()); + builder.setMaxColor(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_METER_FEATURES_HEADER); + return builder.build(); + } + + private static MeterFlags createMeterFlags(long input){ + final Boolean _oFPMFKBPS = (input & (1 << 0)) != 0; + final Boolean _oFPMFPKTPS = (input & (1 << 1)) != 0; + final Boolean _oFPMFBURST = (input & (1 << 2)) != 0; + final Boolean _oFPMFSTATS = (input & (1 << 3)) != 0; + return new MeterFlags(_oFPMFBURST, _oFPMFKBPS, _oFPMFPKTPS, _oFPMFSTATS); + } + + private static MeterBandTypeBitmap createMeterBandsBitmap(long input) { + final Boolean _oFPMBTDROP = (input & (1 << 0)) != 0; + final Boolean _oFPMBTDSCPREMARK = (input & (1 << 1)) != 0; + return new MeterBandTypeBitmap(_oFPMBTDROP, _oFPMBTDSCPREMARK); + } + + private static MultipartReplyMeter setMeter(ByteBuf input) { + MultipartReplyMeterBuilder builder = new MultipartReplyMeterBuilder(); + List meterStatsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder(); + meterStatsBuilder.setMeterId(new MeterId(input.readUnsignedInt())); + int meterStatsBodyLength = input.readUnsignedShort(); + input.skipBytes(PADDING_IN_METER_STATS_HEADER); + meterStatsBuilder.setFlowCount(input.readUnsignedInt()); + byte[] packetInCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(packetInCount); + meterStatsBuilder.setPacketInCount(new BigInteger(packetInCount)); + byte[] byteInCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(byteInCount); + meterStatsBuilder.setByteInCount(new BigInteger(byteInCount)); + meterStatsBuilder.setDurationSec(input.readUnsignedInt()); + meterStatsBuilder.setDurationNsec(input.readUnsignedInt()); + int actualLength = METER_BODY_LENGTH; + List meterBandStatsList = new ArrayList<>(); + while (actualLength < meterStatsBodyLength) { + MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder(); + byte[] packetBandCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(packetBandCount); + meterBandStatsBuilder.setPacketBandCount(new BigInteger(packetBandCount)); + byte[] byteBandCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(byteBandCount); + meterBandStatsBuilder.setByteBandCount(new BigInteger(byteBandCount)); + meterBandStatsList.add(meterBandStatsBuilder.build()); + actualLength += METER_BAND_STATS_LENGTH; + } + meterStatsBuilder.setMeterBandStats(meterBandStatsList); + meterStatsList.add(meterStatsBuilder.build()); + } + builder.setMeterStats(meterStatsList); + return builder.build(); + } + + private static MultipartReplyMeterConfig setMeterConfig(ByteBuf input) { + MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder(); + List meterConfigList = new ArrayList<>(); + while (input.readableBytes() > 0) { + MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder(); + int meterConfigBodyLength = input.readUnsignedShort(); + meterConfigBuilder.setFlags(createMeterFlags(input.readUnsignedShort())); + meterConfigBuilder.setMeterId(new MeterId(input.readUnsignedInt())); + int actualLength = METER_CONFIG_LENGTH; + List bandsList = new ArrayList<>(); + while (actualLength < meterConfigBodyLength) { + BandsBuilder bandsBuilder = new BandsBuilder(); + int bandType = input.readUnsignedShort(); + switch (bandType) { + case 1: + MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder(); + bandDropBuilder.setType(MeterBandType.forValue(bandType)); + actualLength += input.readUnsignedShort(); + bandDropBuilder.setRate(input.readUnsignedInt()); + bandDropBuilder.setBurstSize(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER); + bandsBuilder.setMeterBand(bandDropBuilder.build()); + break; + case 2: + MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder(); + bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType)); + actualLength += input.readUnsignedShort(); + bandDscpRemarkBuilder.setRate(input.readUnsignedInt()); + bandDscpRemarkBuilder.setBurstSize(input.readUnsignedInt()); + bandDscpRemarkBuilder.setPrecLevel(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER); + bandsBuilder.setMeterBand(bandDscpRemarkBuilder.build()); + break; + case 0xFFFF: + MeterBandExperimenterBuilder bandExperimenterBuilder = new MeterBandExperimenterBuilder(); + bandExperimenterBuilder.setType(MeterBandType.forValue(bandType)); + actualLength += input.readUnsignedShort(); + bandExperimenterBuilder.setRate(input.readUnsignedInt()); + bandExperimenterBuilder.setBurstSize(input.readUnsignedInt()); + bandExperimenterBuilder.setExperimenter(input.readUnsignedInt()); + bandsBuilder.setMeterBand(bandExperimenterBuilder.build()); + break; + default: + break; + } + bandsList.add(bandsBuilder.build()); + } + meterConfigBuilder.setBands(bandsList); + meterConfigList.add(meterConfigBuilder.build()); + } + builder.setMeterConfig(meterConfigList); + return builder.build(); + } + + private static MultipartReplyExperimenter setExperimenter(ByteBuf input) { + MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder(); + builder.setExperimenter(input.readUnsignedInt()); + builder.setExpType(input.readUnsignedInt()); + byte[] data = new byte[input.readableBytes()]; + input.readBytes(data); + builder.setData(data); + return builder.build(); + } + + private static MultipartReplyPortDesc setPortDesc(ByteBuf input) { + MultipartReplyPortDescBuilder builder = new MultipartReplyPortDescBuilder(); + List portsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + PortsBuilder portsBuilder = new PortsBuilder(); + portsBuilder.setPortNo(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_PORT_DESC_HEADER_01); + byte[] hwAddress = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + input.readBytes(hwAddress); + portsBuilder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(hwAddress))); + input.skipBytes(PADDING_IN_PORT_DESC_HEADER_02); + byte[] portNameBytes = new byte[MAX_PORT_NAME_LEN]; + input.readBytes(portNameBytes); + String portName = new String(portNameBytes); + portsBuilder.setName(portName.trim()); + portsBuilder.setConfig(createPortConfig(input.readUnsignedInt())); + portsBuilder.setState(createPortState(input.readUnsignedInt())); + portsBuilder.setCurrentFeatures(createPortFeatures(input.readUnsignedInt())); + portsBuilder.setAdvertisedFeatures(createPortFeatures(input.readUnsignedInt())); + portsBuilder.setSupportedFeatures(createPortFeatures(input.readUnsignedInt())); + portsBuilder.setPeerFeatures(createPortFeatures(input.readUnsignedInt())); + portsBuilder.setCurrSpeed(input.readUnsignedInt()); + portsBuilder.setMaxSpeed(input.readUnsignedInt()); + portsList.add(portsBuilder.build()); + } + builder.setPorts(portsList); + return builder.build(); + } + + private static PortConfig createPortConfig(long input){ + final Boolean _portDown = ((input) & (1<<0)) != 0; + final Boolean _noRecv = ((input) & (1<<2)) != 0; + final Boolean _noFwd = ((input) & (1<<5)) != 0; + final Boolean _noPacketIn = ((input) & (1<<6)) != 0; + return new PortConfig(_noFwd, _noPacketIn, _noRecv, _portDown); + } + + private static PortState createPortState(long input){ + final Boolean _linkDown = ((input) & (1<<0)) != 0; + final Boolean _blocked = ((input) & (1<<1)) != 0; + final Boolean _live = ((input) & (1<<2)) != 0; + return new PortState(_blocked, _linkDown, _live); + } + + private static PortFeatures createPortFeatures(long input){ + final Boolean _10mbHd = ((input) & (1<<0)) != 0; + final Boolean _10mbFd = ((input) & (1<<1)) != 0; + final Boolean _100mbHd = ((input) & (1<<2)) != 0; + final Boolean _100mbFd = ((input) & (1<<3)) != 0; + final Boolean _1gbHd = ((input) & (1<<4)) != 0; + final Boolean _1gbFd = ((input) & (1<<5)) != 0; + final Boolean _10gbFd = ((input) & (1<<6)) != 0; + final Boolean _40gbFd = ((input) & (1<<7)) != 0; + final Boolean _100gbFd = ((input) & (1<<8)) != 0; + final Boolean _1tbFd = ((input) & (1<<9)) != 0; + final Boolean _other = ((input) & (1<<10)) != 0; + final Boolean _copper = ((input) & (1<<11)) != 0; + final Boolean _fiber = ((input) & (1<<12)) != 0; + final Boolean _autoneg = ((input) & (1<<13)) != 0; + final Boolean _pause = ((input) & (1<<14)) != 0; + final Boolean _pauseAsym = ((input) & (1<<15)) != 0; + return new PortFeatures(_10mbHd, _10mbFd, _100mbHd, _100mbFd, _1gbHd, _1gbFd, _10gbFd, + _40gbFd, _100gbFd, _1tbFd, _other, _copper, _fiber, _autoneg, _pause, _pauseAsym); + } + + private static MultipartReplyBody setGroupFeatures(ByteBuf rawMessage) { + MultipartReplyGroupFeaturesBuilder featuresBuilder = new MultipartReplyGroupFeaturesBuilder(); + featuresBuilder.setTypes(createGroupType(rawMessage.readUnsignedInt())); + featuresBuilder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt())); + List maxGroupsList = new ArrayList<>(); + for (int i = 0; i < GROUP_TYPES ; i++) { + maxGroupsList.add(rawMessage.readUnsignedInt()); + } + featuresBuilder.setMaxGroups(maxGroupsList); + List actionBitmaps = new ArrayList<>(); + for (int i = 0; i < GROUP_TYPES ; i++) { + actionBitmaps.add(createActionBitmap(rawMessage.readUnsignedInt())); + } + featuresBuilder.setActionsBitmap(actionBitmaps); + return featuresBuilder.build(); + } + + private static ActionType createActionBitmap(long input) { + final Boolean OFPAT_OUTPUT = ((input) & (1<<0)) != 0; + final Boolean OFPAT_COPY_TTL_OUT = ((input) & (1<<1)) != 0; + final Boolean OFPAT_COPY_TTL_IN = ((input) & (1<<2)) != 0; + final Boolean OFPAT_SET_MPLS_TTL = ((input) & (1<<3)) != 0; + final Boolean OFPAT_DEC_MPLS_TTL = ((input) & (1<<4)) != 0; + final Boolean OFPAT_PUSH_VLAN = ((input) & (1<<5)) != 0; + final Boolean OFPAT_POP_VLAN = ((input) & (1<<6)) != 0; + final Boolean OFPAT_PUSH_MPLS = ((input) & (1<<7)) != 0; + final Boolean OFPAT_POP_MPLS = ((input) & (1<<8)) != 0; + final Boolean OFPAT_SET_QUEUE = ((input) & (1<<9)) != 0; + final Boolean OFPAT_GROUP = ((input) & (1<<10)) != 0; + final Boolean OFPAT_SET_NW_TTL = ((input) & (1<<11)) != 0; + final Boolean OFPAT_DEC_NW_TTL = ((input) & (1<<12)) != 0; + final Boolean OFPAT_SET_FIELD = ((input) & (1<<13)) != 0; + final Boolean OFPAT_PUSH_PBB = ((input) & (1<<14)) != 0; + final Boolean OFPAT_POP_PBB = ((input) & (1<<15)) != 0; + final Boolean OFPAT_EXPERIMENTER = ((input) & (1<<16)) != 0; + return new ActionType(OFPAT_COPY_TTL_IN, OFPAT_COPY_TTL_OUT, OFPAT_DEC_MPLS_TTL, + OFPAT_DEC_NW_TTL, OFPAT_EXPERIMENTER, OFPAT_GROUP, OFPAT_OUTPUT, OFPAT_POP_MPLS, + OFPAT_POP_PBB, OFPAT_POP_VLAN, OFPAT_PUSH_MPLS, OFPAT_PUSH_PBB, OFPAT_PUSH_VLAN, + OFPAT_SET_FIELD, OFPAT_SET_MPLS_TTL, OFPAT_SET_NW_TTL, OFPAT_SET_QUEUE); + } + + private static GroupCapabilities createCapabilities(long input) { + final Boolean OFOFPGFC_SELECT_WEIGHT = ((input) & (1<<0)) != 0; + final Boolean OFPGFC_SELECT_LIVENESS = ((input) & (1<<1)) != 0; + final Boolean OFPGFC_CHAINING = ((input) & (1<<2)) != 0; + final Boolean OFPGFC_CHAINING_CHECKS = ((input) & (1<<3)) != 0; + return new GroupCapabilities(OFPGFC_CHAINING, OFPGFC_CHAINING_CHECKS, OFPGFC_SELECT_LIVENESS, OFOFPGFC_SELECT_WEIGHT); + } + + private static GroupTypes createGroupType(long input) { + final Boolean OFPGT_ALL = ((input) & (1<<0)) != 0; + final Boolean OFPGT_SELECT = ((input) & (1<<1)) != 0; + final Boolean OFPGT_INDIRECT = ((input) & (1<<2)) != 0; + final Boolean OFPGT_FF = ((input) & (1<<3)) != 0; + return new GroupTypes(OFPGT_ALL, OFPGT_FF, OFPGT_INDIRECT, OFPGT_SELECT); + } + + private static MultipartReplyGroupDesc setGroupDesc(ByteBuf input) { + MultipartReplyGroupDescBuilder builder = new MultipartReplyGroupDescBuilder(); + List groupDescsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + GroupDescBuilder groupDescBuilder = new GroupDescBuilder(); + int bodyLength = input.readUnsignedShort(); + groupDescBuilder.setType(GroupType.forValue(input.readUnsignedByte())); + input.skipBytes(PADDING_IN_GROUP_DESC_HEADER); + groupDescBuilder.setGroupId(new GroupId(input.readUnsignedInt())); + int actualLength = GROUP_DESC_HEADER_LENGTH; + List bucketsList = new ArrayList<>(); + while (actualLength < bodyLength) { + BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); + int bucketsLength = input.readUnsignedShort(); + bucketsBuilder.setWeight(input.readUnsignedShort()); + bucketsBuilder.setWatchPort(new PortNumber(input.readUnsignedInt())); + bucketsBuilder.setWatchGroup(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_BUCKETS_HEADER); + List actionsList = ActionsDeserializer + .createActionsList(input, bucketsLength - BUCKETS_HEADER_LENGTH); + bucketsBuilder.setActionsList(actionsList); + bucketsList.add(bucketsBuilder.build()); + actualLength += bucketsLength; + } + groupDescBuilder.setBucketsList(bucketsList); + groupDescsList.add(groupDescBuilder.build()); + } + builder.setGroupDesc(groupDescsList); + return builder.build(); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactory.java index e9e37284..5d3f874f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactory.java @@ -1,151 +1,158 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadActionCodeV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadRequestCodeV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorTypeV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFailedCodeV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloFailedCodeV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortModFailedCodeV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueOpFailedCodeV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder; - -/** - * Translates Error messages (OpenFlow v1.0) - * @author michal.polkorab - */ -public class OF10ErrorMessageFactory implements OFDeserializer { - - private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE"; - private static final String UNKNOWN_CODE = "UNKNOWN_CODE"; - - private static OF10ErrorMessageFactory instance; - - private OF10ErrorMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10ErrorMessageFactory getInstance() { - if (instance == null) { - instance = new OF10ErrorMessageFactory(); - } - return instance; - } - - @Override - public ErrorMessage bufferToMessage(ByteBuf rawMessage, short version) { - ErrorMessageBuilder builder = new ErrorMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - int type = rawMessage.readUnsignedShort(); - ErrorTypeV10 errorType = ErrorTypeV10.forValue(type); - decodeType(builder, errorType, type); - decodeCode(rawMessage, builder, errorType); - if (rawMessage.readableBytes() > 0) { - builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); - } - return builder.build(); - } - - private static void decodeType(ErrorMessageBuilder builder, ErrorTypeV10 type, int readValue) { - if (type != null) { - builder.setType(type.getIntValue()); - builder.setTypeString(type.name()); - } else { - builder.setType(readValue); - builder.setTypeString(UNKNOWN_TYPE); - } - } - - private static void decodeCode(ByteBuf rawMessage, ErrorMessageBuilder builder, - ErrorTypeV10 type) { - int code = rawMessage.readUnsignedShort(); - if (type != null) { - switch (type) { - case HELLOFAILED: - { - HelloFailedCodeV10 errorCode = HelloFailedCodeV10.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case BADREQUEST: - { - BadRequestCodeV10 errorCode = BadRequestCodeV10.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case BADACTION: - { - BadActionCodeV10 errorCode = BadActionCodeV10.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case FLOWMODFAILED: - { - FlowModFailedCodeV10 errorCode = FlowModFailedCodeV10.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case PORTMODFAILED: - { - PortModFailedCodeV10 errorCode = PortModFailedCodeV10.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - case QUEUEOPFAILED: - { - QueueOpFailedCodeV10 errorCode = QueueOpFailedCodeV10.forValue(code); - if (errorCode != null) { - setCode(builder, errorCode.getIntValue(), errorCode.name()); - } else { - setUnknownCode(builder, code); - } - break; - } - default: - setUnknownCode(builder, code); - break; - } - } else { - setUnknownCode(builder, code); - } - } - - private static void setUnknownCode(ErrorMessageBuilder builder, int readValue) { - builder.setCode(readValue); - builder.setCodeString(UNKNOWN_CODE); - } - - private static void setCode(ErrorMessageBuilder builder, int code, String codeString) { - builder.setCode(code); - builder.setCodeString(codeString); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadActionCodeV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.BadRequestCodeV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorTypeV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFailedCodeV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloFailedCodeV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortModFailedCodeV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueOpFailedCodeV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder; + +/** + * Translates Error messages (OpenFlow v1.0) + * @author michal.polkorab + */ +public class OF10ErrorMessageFactory implements OFDeserializer { + + private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE"; + private static final String UNKNOWN_CODE = "UNKNOWN_CODE"; + + private static OF10ErrorMessageFactory instance; + + private OF10ErrorMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10ErrorMessageFactory getInstance() { + if (instance == null) { + instance = new OF10ErrorMessageFactory(); + } + return instance; + } + + @Override + public ErrorMessage bufferToMessage(ByteBuf rawMessage, short version) { + ErrorMessageBuilder builder = new ErrorMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + int type = rawMessage.readUnsignedShort(); + ErrorTypeV10 errorType = ErrorTypeV10.forValue(type); + decodeType(builder, errorType, type); + decodeCode(rawMessage, builder, errorType); + if (rawMessage.readableBytes() > 0) { + builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); + } + return builder.build(); + } + + private static void decodeType(ErrorMessageBuilder builder, ErrorTypeV10 type, int readValue) { + if (type != null) { + builder.setType(type.getIntValue()); + builder.setTypeString(type.name()); + } else { + builder.setType(readValue); + builder.setTypeString(UNKNOWN_TYPE); + } + } + + private static void decodeCode(ByteBuf rawMessage, ErrorMessageBuilder builder, + ErrorTypeV10 type) { + int code = rawMessage.readUnsignedShort(); + if (type != null) { + switch (type) { + case HELLOFAILED: + { + HelloFailedCodeV10 errorCode = HelloFailedCodeV10.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case BADREQUEST: + { + BadRequestCodeV10 errorCode = BadRequestCodeV10.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case BADACTION: + { + BadActionCodeV10 errorCode = BadActionCodeV10.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case FLOWMODFAILED: + { + FlowModFailedCodeV10 errorCode = FlowModFailedCodeV10.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case PORTMODFAILED: + { + PortModFailedCodeV10 errorCode = PortModFailedCodeV10.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + case QUEUEOPFAILED: + { + QueueOpFailedCodeV10 errorCode = QueueOpFailedCodeV10.forValue(code); + if (errorCode != null) { + setCode(builder, errorCode.getIntValue(), errorCode.name()); + } else { + setUnknownCode(builder, code); + } + break; + } + default: + setUnknownCode(builder, code); + break; + } + } else { + setUnknownCode(builder, code); + } + } + + private static void setUnknownCode(ErrorMessageBuilder builder, int readValue) { + builder.setCode(readValue); + builder.setCodeString(UNKNOWN_CODE); + } + + private static void setCode(ErrorMessageBuilder builder, int code, String codeString) { + builder.setCode(code); + builder.setCodeString(codeString); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java index 7c6dc262..6c511783 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java @@ -1,159 +1,166 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder; - -/** - * Translates FeaturesReply messages (OpenFlow v1.0) - * @author michal.polkorab - */ -public class OF10FeaturesReplyMessageFactory implements OFDeserializer { - - private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 3; - - private static OF10FeaturesReplyMessageFactory instance; - - private OF10FeaturesReplyMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10FeaturesReplyMessageFactory getInstance() { - if (instance == null) { - instance = new OF10FeaturesReplyMessageFactory(); - } - return instance; - } - - @Override - public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) { - GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - byte[] datapathId = new byte[Long.SIZE/Byte.SIZE]; - rawMessage.readBytes(datapathId); - builder.setDatapathId(new BigInteger(datapathId)); - builder.setBuffers(rawMessage.readUnsignedInt()); - builder.setTables(rawMessage.readUnsignedByte()); - rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER); - builder.setCapabilitiesV10(createCapabilitiesV10(rawMessage.readUnsignedInt())); - builder.setActionsV10(createActionsV10(rawMessage.readUnsignedInt())); - List ports = new ArrayList<>(); - while (rawMessage.readableBytes() > 0) { - ports.add(deserializePort(rawMessage)); - } - builder.setPhyPort(ports); - return builder.build(); - } - - private static CapabilitiesV10 createCapabilitiesV10(long input) { - final Boolean FLOW_STATS = (input & (1 << 0)) != 0; - final Boolean TABLE_STATS = (input & (1 << 1)) != 0; - final Boolean PORT_STATS = (input & (1 << 2)) != 0; - final Boolean STP = (input & (1 << 3)) != 0; - final Boolean RESERVED = (input & (1 << 4)) != 0; - final Boolean IP_REASM = (input & (1 << 5)) != 0; - final Boolean QUEUE_STATS = (input & (1 << 6)) != 0; - final Boolean ARP_MATCH_IP = (input & (1 << 7)) != 0; - return new CapabilitiesV10(ARP_MATCH_IP, FLOW_STATS, IP_REASM, - PORT_STATS, QUEUE_STATS, RESERVED, STP, TABLE_STATS); - } - - private static ActionTypeV10 createActionsV10(long input) { - final Boolean OUTPUT = (input & (1 << 0)) != 0; - final Boolean SET_VLAN_VID = (input & (1 << 1)) != 0; - final Boolean SET_VLAN_PCP = (input & (1 << 2)) != 0; - final Boolean STRIP_VLAN = (input & (1 << 3)) != 0; - final Boolean SET_DL_SRC = (input & (1 << 4)) != 0; - final Boolean SET_DL_DST = (input & (1 << 5)) != 0; - final Boolean SET_NW_SRC = (input & (1 << 6)) != 0; - final Boolean SET_NW_DST = (input & (1 << 7)) != 0; - final Boolean SET_NW_TOS = (input & (1 << 8)) != 0; - final Boolean SET_TP_SRC = (input & (1 << 9)) != 0; - final Boolean SET_TP_DST = (input & (1 << 10)) != 0; - final Boolean ENQUEUE = (input & (1 << 11)) != 0; - final Boolean VENDOR = (input & (1 << 12)) != 0; - return new ActionTypeV10(ENQUEUE, OUTPUT, SET_DL_DST, SET_DL_SRC, - SET_NW_DST, SET_NW_SRC, SET_NW_TOS, SET_TP_DST, SET_TP_SRC, - SET_VLAN_PCP, SET_VLAN_VID, STRIP_VLAN, VENDOR); - } - - private static PhyPort deserializePort(ByteBuf rawMessage) { - PhyPortBuilder builder = new PhyPortBuilder(); - builder.setPortNo((long) rawMessage.readUnsignedShort()); - byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - rawMessage.readBytes(address); - builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address))); - builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH)); - builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt())); - builder.setStateV10(createPortState(rawMessage.readUnsignedInt())); - builder.setCurrentFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - builder.setAdvertisedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - builder.setSupportedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - builder.setPeerFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - return builder.build(); - } - - - - private static PortStateV10 createPortState(long input){ - final Boolean _linkDown = ((input) & (1<<0)) != 0; - final Boolean _blocked = ((input) & (1<<1)) != 0; - final Boolean _live = ((input) & (1<<2)) != 0; - final Boolean _stpListen = ((input) & (0<<8)) != 0; - final Boolean _stpLearn = ((input) & (1<<8)) != 0; - final Boolean _stpForward = ((input) & (1<<9)) != 0; // equals 2 << 8 - final Boolean _stpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8 - final Boolean _stpMask = ((input) & (1<<10)) != 0; // equals 4 << 8 - return new PortStateV10(_blocked, _linkDown, _live, _stpBlock, _stpForward, _stpLearn, _stpListen, _stpMask); - } - - private static PortConfigV10 createPortConfig(long input){ - final Boolean _portDown = ((input) & (1<<0)) != 0; - final Boolean _noStp = ((input) & (1<<1)) != 0; - final Boolean _noRecv = ((input) & (1<<2)) != 0; - final Boolean _noRecvStp = ((input) & (1<<3)) != 0; - final Boolean _noFlood = ((input) & (1<<4)) != 0; - final Boolean _noFwd = ((input) & (1<<5)) != 0; - final Boolean _noPacketIn = ((input) & (1<<6)) != 0; - return new PortConfigV10(_noFlood, _noFwd, _noPacketIn, _noRecv, _noRecvStp, _noStp, _portDown); - } - - private static PortFeaturesV10 createPortFeatures(long input){ - final Boolean _10mbHd = ((input) & (1<<0)) != 0; - final Boolean _10mbFd = ((input) & (1<<1)) != 0; - final Boolean _100mbHd = ((input) & (1<<2)) != 0; - final Boolean _100mbFd = ((input) & (1<<3)) != 0; - final Boolean _1gbHd = ((input) & (1<<4)) != 0; - final Boolean _1gbFd = ((input) & (1<<5)) != 0; - final Boolean _10gbFd = ((input) & (1<<6)) != 0; - final Boolean _copper = ((input) & (1<<7)) != 0; - final Boolean _fiber = ((input) & (1<<8)) != 0; - final Boolean _autoneg = ((input) & (1<<9)) != 0; - final Boolean _pause = ((input) & (1<<10)) != 0; - final Boolean _pauseAsym = ((input) & (1<<11)) != 0; - return new PortFeaturesV10(_100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, - _1gbFd, _1gbHd, _autoneg, _copper, _fiber, _pause, _pauseAsym); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder; + +/** + * Translates FeaturesReply messages (OpenFlow v1.0) + * @author michal.polkorab + */ +public class OF10FeaturesReplyMessageFactory implements OFDeserializer { + + private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 3; + + private static OF10FeaturesReplyMessageFactory instance; + + private OF10FeaturesReplyMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10FeaturesReplyMessageFactory getInstance() { + if (instance == null) { + instance = new OF10FeaturesReplyMessageFactory(); + } + return instance; + } + + @Override + public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) { + GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + byte[] datapathId = new byte[Long.SIZE/Byte.SIZE]; + rawMessage.readBytes(datapathId); + builder.setDatapathId(new BigInteger(datapathId)); + builder.setBuffers(rawMessage.readUnsignedInt()); + builder.setTables(rawMessage.readUnsignedByte()); + rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER); + builder.setCapabilitiesV10(createCapabilitiesV10(rawMessage.readUnsignedInt())); + builder.setActionsV10(createActionsV10(rawMessage.readUnsignedInt())); + List ports = new ArrayList<>(); + while (rawMessage.readableBytes() > 0) { + ports.add(deserializePort(rawMessage)); + } + builder.setPhyPort(ports); + return builder.build(); + } + + private static CapabilitiesV10 createCapabilitiesV10(long input) { + final Boolean FLOW_STATS = (input & (1 << 0)) != 0; + final Boolean TABLE_STATS = (input & (1 << 1)) != 0; + final Boolean PORT_STATS = (input & (1 << 2)) != 0; + final Boolean STP = (input & (1 << 3)) != 0; + final Boolean RESERVED = (input & (1 << 4)) != 0; + final Boolean IP_REASM = (input & (1 << 5)) != 0; + final Boolean QUEUE_STATS = (input & (1 << 6)) != 0; + final Boolean ARP_MATCH_IP = (input & (1 << 7)) != 0; + return new CapabilitiesV10(ARP_MATCH_IP, FLOW_STATS, IP_REASM, + PORT_STATS, QUEUE_STATS, RESERVED, STP, TABLE_STATS); + } + + private static ActionTypeV10 createActionsV10(long input) { + final Boolean OUTPUT = (input & (1 << 0)) != 0; + final Boolean SET_VLAN_VID = (input & (1 << 1)) != 0; + final Boolean SET_VLAN_PCP = (input & (1 << 2)) != 0; + final Boolean STRIP_VLAN = (input & (1 << 3)) != 0; + final Boolean SET_DL_SRC = (input & (1 << 4)) != 0; + final Boolean SET_DL_DST = (input & (1 << 5)) != 0; + final Boolean SET_NW_SRC = (input & (1 << 6)) != 0; + final Boolean SET_NW_DST = (input & (1 << 7)) != 0; + final Boolean SET_NW_TOS = (input & (1 << 8)) != 0; + final Boolean SET_TP_SRC = (input & (1 << 9)) != 0; + final Boolean SET_TP_DST = (input & (1 << 10)) != 0; + final Boolean ENQUEUE = (input & (1 << 11)) != 0; + final Boolean VENDOR = (input & (1 << 12)) != 0; + return new ActionTypeV10(ENQUEUE, OUTPUT, SET_DL_DST, SET_DL_SRC, + SET_NW_DST, SET_NW_SRC, SET_NW_TOS, SET_TP_DST, SET_TP_SRC, + SET_VLAN_PCP, SET_VLAN_VID, STRIP_VLAN, VENDOR); + } + + private static PhyPort deserializePort(ByteBuf rawMessage) { + PhyPortBuilder builder = new PhyPortBuilder(); + builder.setPortNo((long) rawMessage.readUnsignedShort()); + byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + rawMessage.readBytes(address); + builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address))); + builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH)); + builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt())); + builder.setStateV10(createPortState(rawMessage.readUnsignedInt())); + builder.setCurrentFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); + builder.setAdvertisedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); + builder.setSupportedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); + builder.setPeerFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); + return builder.build(); + } + + + + private static PortStateV10 createPortState(long input){ + final Boolean _linkDown = ((input) & (1<<0)) != 0; + final Boolean _blocked = ((input) & (1<<1)) != 0; + final Boolean _live = ((input) & (1<<2)) != 0; + final Boolean _stpListen = ((input) & (0<<8)) != 0; + final Boolean _stpLearn = ((input) & (1<<8)) != 0; + final Boolean _stpForward = ((input) & (1<<9)) != 0; // equals 2 << 8 + final Boolean _stpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8 + final Boolean _stpMask = ((input) & (1<<10)) != 0; // equals 4 << 8 + return new PortStateV10(_blocked, _linkDown, _live, _stpBlock, _stpForward, _stpLearn, _stpListen, _stpMask); + } + + private static PortConfigV10 createPortConfig(long input){ + final Boolean _portDown = ((input) & (1<<0)) != 0; + final Boolean _noStp = ((input) & (1<<1)) != 0; + final Boolean _noRecv = ((input) & (1<<2)) != 0; + final Boolean _noRecvStp = ((input) & (1<<3)) != 0; + final Boolean _noFlood = ((input) & (1<<4)) != 0; + final Boolean _noFwd = ((input) & (1<<5)) != 0; + final Boolean _noPacketIn = ((input) & (1<<6)) != 0; + return new PortConfigV10(_noFlood, _noFwd, _noPacketIn, _noRecv, _noRecvStp, _noStp, _portDown); + } + + private static PortFeaturesV10 createPortFeatures(long input){ + final Boolean _10mbHd = ((input) & (1<<0)) != 0; + final Boolean _10mbFd = ((input) & (1<<1)) != 0; + final Boolean _100mbHd = ((input) & (1<<2)) != 0; + final Boolean _100mbFd = ((input) & (1<<3)) != 0; + final Boolean _1gbHd = ((input) & (1<<4)) != 0; + final Boolean _1gbFd = ((input) & (1<<5)) != 0; + final Boolean _10gbFd = ((input) & (1<<6)) != 0; + final Boolean _copper = ((input) & (1<<7)) != 0; + final Boolean _fiber = ((input) & (1<<8)) != 0; + final Boolean _autoneg = ((input) & (1<<9)) != 0; + final Boolean _pause = ((input) & (1<<10)) != 0; + final Boolean _pauseAsym = ((input) & (1<<11)) != 0; + return new PortFeaturesV10(_100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, + _1gbFd, _1gbHd, _autoneg, _copper, _fiber, _pause, _pauseAsym); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactory.java index b25b993a..76ac6e1d 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactory.java @@ -1,66 +1,73 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.math.BigInteger; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder; - -/** - * Translates FlowRemoved messages (OpenFlow v1.0) - * @author michal.polkorab - */ -public class OF10FlowRemovedMessageFactory implements OFDeserializer { - - private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE = 1; - private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE_2 = 2; - - - private static OF10FlowRemovedMessageFactory instance; - - private OF10FlowRemovedMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10FlowRemovedMessageFactory getInstance(){ - if(instance == null){ - instance = new OF10FlowRemovedMessageFactory(); - } - return instance; - } - - @Override - public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) { - FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - builder.setMatchV10(OF10MatchDeserializer.createMatchV10(rawMessage)); - byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; - rawMessage.readBytes(cookie); - builder.setCookie(new BigInteger(cookie)); - builder.setPriority(rawMessage.readUnsignedShort()); - builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte())); - rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE); - builder.setDurationSec(rawMessage.readUnsignedInt()); - builder.setDurationNsec(rawMessage.readUnsignedInt()); - builder.setIdleTimeout(rawMessage.readUnsignedShort()); - rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE_2); - byte[] packet_count = new byte[Long.SIZE/Byte.SIZE]; - rawMessage.readBytes(packet_count); - builder.setPacketCount(new BigInteger(packet_count)); - byte[] byte_count = new byte[Long.SIZE/Byte.SIZE]; - rawMessage.readBytes(byte_count); - builder.setByteCount(new BigInteger(byte_count)); - return builder.build(); - } - - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.math.BigInteger; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder; + +/** + * Translates FlowRemoved messages (OpenFlow v1.0) + * @author michal.polkorab + */ +public class OF10FlowRemovedMessageFactory implements OFDeserializer { + + private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE = 1; + private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE_2 = 2; + + + private static OF10FlowRemovedMessageFactory instance; + + private OF10FlowRemovedMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10FlowRemovedMessageFactory getInstance(){ + if(instance == null){ + instance = new OF10FlowRemovedMessageFactory(); + } + return instance; + } + + @Override + public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) { + FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setMatchV10(OF10MatchDeserializer.createMatchV10(rawMessage)); + byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; + rawMessage.readBytes(cookie); + builder.setCookie(new BigInteger(cookie)); + builder.setPriority(rawMessage.readUnsignedShort()); + builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte())); + rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE); + builder.setDurationSec(rawMessage.readUnsignedInt()); + builder.setDurationNsec(rawMessage.readUnsignedInt()); + builder.setIdleTimeout(rawMessage.readUnsignedShort()); + rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE_2); + byte[] packet_count = new byte[Long.SIZE/Byte.SIZE]; + rawMessage.readBytes(packet_count); + builder.setPacketCount(new BigInteger(packet_count)); + byte[] byte_count = new byte[Long.SIZE/Byte.SIZE]; + rawMessage.readBytes(byte_count); + builder.setByteCount(new BigInteger(byte_count)); + return builder.build(); + } + + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactory.java index 0301b803..cefb7f1a 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactory.java @@ -1,43 +1,50 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder; - -/** - * Translates Hello messages (OpenFlow v1.0) - * @author michal.polkorab - */ -public class OF10HelloMessageFactory implements OFDeserializer { - -private static OF10HelloMessageFactory instance; - - private OF10HelloMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10HelloMessageFactory getInstance() { - if (instance == null) { - instance = new OF10HelloMessageFactory(); - } - return instance; - } - - @Override - public HelloMessage bufferToMessage(ByteBuf rawMessage, short version) { - HelloMessageBuilder builder = new HelloMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - if (rawMessage.readableBytes() > 0) { - rawMessage.skipBytes(rawMessage.readableBytes()); - } - return builder.build(); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder; + +/** + * Translates Hello messages (OpenFlow v1.0) + * @author michal.polkorab + */ +public class OF10HelloMessageFactory implements OFDeserializer { + +private static OF10HelloMessageFactory instance; + + private OF10HelloMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10HelloMessageFactory getInstance() { + if (instance == null) { + instance = new OF10HelloMessageFactory(); + } + return instance; + } + + @Override + public HelloMessage bufferToMessage(ByteBuf rawMessage, short version) { + HelloMessageBuilder builder = new HelloMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + if (rawMessage.readableBytes() > 0) { + rawMessage.skipBytes(rawMessage.readableBytes()); + } + return builder.build(); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactory.java index e7d5c6ea..814bd502 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactory.java @@ -1,51 +1,58 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder; - -/** - * Translates PacketIn messages (OpenFlow v1.0) - * @author michal.polkorab - */ -public class OF10PacketInMessageFactory implements OFDeserializer { - - private static final byte PADDING_IN_PACKET_IN_HEADER = 1; - - private static OF10PacketInMessageFactory instance; - - private OF10PacketInMessageFactory() { - // Singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10PacketInMessageFactory getInstance(){ - if(instance == null){ - instance = new OF10PacketInMessageFactory(); - } - return instance; - } - - @Override - public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) { - PacketInMessageBuilder builder = new PacketInMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - builder.setBufferId(rawMessage.readUnsignedInt()); - builder.setTotalLen(rawMessage.readUnsignedShort()); - builder.setInPort(rawMessage.readUnsignedShort()); - builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte())); - rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER); - int remainingBytes = rawMessage.readableBytes(); - if (remainingBytes > 0) { - builder.setData(rawMessage.readBytes(remainingBytes).array()); - } - return builder.build(); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder; + +/** + * Translates PacketIn messages (OpenFlow v1.0) + * @author michal.polkorab + */ +public class OF10PacketInMessageFactory implements OFDeserializer { + + private static final byte PADDING_IN_PACKET_IN_HEADER = 1; + + private static OF10PacketInMessageFactory instance; + + private OF10PacketInMessageFactory() { + // Singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10PacketInMessageFactory getInstance(){ + if(instance == null){ + instance = new OF10PacketInMessageFactory(); + } + return instance; + } + + @Override + public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) { + PacketInMessageBuilder builder = new PacketInMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setBufferId(rawMessage.readUnsignedInt()); + builder.setTotalLen(rawMessage.readUnsignedShort()); + builder.setInPort(rawMessage.readUnsignedShort()); + builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte())); + rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER); + int remainingBytes = rawMessage.readableBytes(); + if (remainingBytes > 0) { + builder.setData(rawMessage.readBytes(remainingBytes).array()); + } + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactory.java index 9958effc..5d6036ad 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactory.java @@ -1,105 +1,112 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder; - -/** - * Translates PortStatus messages (OpenFlow v1.0) - * @author michal.polkorab - */ -public class OF10PortStatusMessageFactory implements OFDeserializer { - - private static final byte PADDING_IN_PORT_STATUS_HEADER = 7; - - private static OF10PortStatusMessageFactory instance; - - private OF10PortStatusMessageFactory() { - // Singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10PortStatusMessageFactory getInstance(){ - if(instance == null){ - instance = new OF10PortStatusMessageFactory(); - } - return instance; - } - - @Override - public PortStatusMessage bufferToMessage(ByteBuf rawMessage, short version) { - PortStatusMessageBuilder builder = new PortStatusMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - builder.setReason(PortReason.forValue(rawMessage.readUnsignedByte())); - rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER); - deserializePort(rawMessage, builder); - return builder.build(); - } - - private static PortStateV10 createPortState(long input){ - final Boolean _linkDown = ((input) & (1<<0)) != 0; - final Boolean _blocked = ((input) & (1<<1)) != 0; - final Boolean _live = ((input) & (1<<2)) != 0; - final Boolean _stpListen = ((input) & (0<<8)) != 0; - final Boolean _stpLearn = ((input) & (1<<8)) != 0; - final Boolean _stpForward = ((input) & (1<<9)) != 0; // equals 2 << 8 - final Boolean _stpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8 - final Boolean _stpMask = ((input) & (1<<10)) != 0; // equals 4 << 8 - return new PortStateV10(_blocked, _linkDown, _live, _stpBlock, _stpForward, _stpLearn, _stpListen, _stpMask); - } - - private static PortConfigV10 createPortConfig(long input){ - final Boolean _portDown = ((input) & (1<<0)) != 0; - final Boolean _noStp = ((input) & (1<<1)) != 0; - final Boolean _noRecv = ((input) & (1<<2)) != 0; - final Boolean _noRecvStp = ((input) & (1<<3)) != 0; - final Boolean _noFlood = ((input) & (1<<4)) != 0; - final Boolean _noFwd = ((input) & (1<<5)) != 0; - final Boolean _noPacketIn = ((input) & (1<<6)) != 0; - return new PortConfigV10(_noFlood, _noFwd, _noPacketIn, _noRecv, _noRecvStp, _noStp, _portDown); - } - - private static PortFeaturesV10 createPortFeatures(long input){ - final Boolean _10mbHd = ((input) & (1<<0)) != 0; - final Boolean _10mbFd = ((input) & (1<<1)) != 0; - final Boolean _100mbHd = ((input) & (1<<2)) != 0; - final Boolean _100mbFd = ((input) & (1<<3)) != 0; - final Boolean _1gbHd = ((input) & (1<<4)) != 0; - final Boolean _1gbFd = ((input) & (1<<5)) != 0; - final Boolean _10gbFd = ((input) & (1<<6)) != 0; - final Boolean _copper = ((input) & (1<<7)) != 0; - final Boolean _fiber = ((input) & (1<<8)) != 0; - final Boolean _autoneg = ((input) & (1<<9)) != 0; - final Boolean _pause = ((input) & (1<<10)) != 0; - final Boolean _pauseAsym = ((input) & (1<<11)) != 0; - return new PortFeaturesV10(_100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, - _1gbFd, _1gbHd, _autoneg, _copper, _fiber, _pause, _pauseAsym); - } - - private static void deserializePort(ByteBuf rawMessage, PortStatusMessageBuilder builder) { - builder.setPortNo((long) rawMessage.readUnsignedShort()); - byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - rawMessage.readBytes(address); - builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address))); - builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH)); - builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt())); - builder.setStateV10(createPortState(rawMessage.readUnsignedInt())); - builder.setCurrentFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - builder.setAdvertisedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - builder.setSupportedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - builder.setPeerFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder; + +/** + * Translates PortStatus messages (OpenFlow v1.0) + * @author michal.polkorab + */ +public class OF10PortStatusMessageFactory implements OFDeserializer { + + private static final byte PADDING_IN_PORT_STATUS_HEADER = 7; + + private static OF10PortStatusMessageFactory instance; + + private OF10PortStatusMessageFactory() { + // Singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10PortStatusMessageFactory getInstance(){ + if(instance == null){ + instance = new OF10PortStatusMessageFactory(); + } + return instance; + } + + @Override + public PortStatusMessage bufferToMessage(ByteBuf rawMessage, short version) { + PortStatusMessageBuilder builder = new PortStatusMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setReason(PortReason.forValue(rawMessage.readUnsignedByte())); + rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER); + deserializePort(rawMessage, builder); + return builder.build(); + } + + private static PortStateV10 createPortState(long input){ + final Boolean _linkDown = ((input) & (1<<0)) != 0; + final Boolean _blocked = ((input) & (1<<1)) != 0; + final Boolean _live = ((input) & (1<<2)) != 0; + final Boolean _stpListen = ((input) & (0<<8)) != 0; + final Boolean _stpLearn = ((input) & (1<<8)) != 0; + final Boolean _stpForward = ((input) & (1<<9)) != 0; // equals 2 << 8 + final Boolean _stpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8 + final Boolean _stpMask = ((input) & (1<<10)) != 0; // equals 4 << 8 + return new PortStateV10(_blocked, _linkDown, _live, _stpBlock, _stpForward, _stpLearn, _stpListen, _stpMask); + } + + private static PortConfigV10 createPortConfig(long input){ + final Boolean _portDown = ((input) & (1<<0)) != 0; + final Boolean _noStp = ((input) & (1<<1)) != 0; + final Boolean _noRecv = ((input) & (1<<2)) != 0; + final Boolean _noRecvStp = ((input) & (1<<3)) != 0; + final Boolean _noFlood = ((input) & (1<<4)) != 0; + final Boolean _noFwd = ((input) & (1<<5)) != 0; + final Boolean _noPacketIn = ((input) & (1<<6)) != 0; + return new PortConfigV10(_noFlood, _noFwd, _noPacketIn, _noRecv, _noRecvStp, _noStp, _portDown); + } + + private static PortFeaturesV10 createPortFeatures(long input){ + final Boolean _10mbHd = ((input) & (1<<0)) != 0; + final Boolean _10mbFd = ((input) & (1<<1)) != 0; + final Boolean _100mbHd = ((input) & (1<<2)) != 0; + final Boolean _100mbFd = ((input) & (1<<3)) != 0; + final Boolean _1gbHd = ((input) & (1<<4)) != 0; + final Boolean _1gbFd = ((input) & (1<<5)) != 0; + final Boolean _10gbFd = ((input) & (1<<6)) != 0; + final Boolean _copper = ((input) & (1<<7)) != 0; + final Boolean _fiber = ((input) & (1<<8)) != 0; + final Boolean _autoneg = ((input) & (1<<9)) != 0; + final Boolean _pause = ((input) & (1<<10)) != 0; + final Boolean _pauseAsym = ((input) & (1<<11)) != 0; + return new PortFeaturesV10(_100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, + _1gbFd, _1gbHd, _autoneg, _copper, _fiber, _pause, _pauseAsym); + } + + private static void deserializePort(ByteBuf rawMessage, PortStatusMessageBuilder builder) { + builder.setPortNo((long) rawMessage.readUnsignedShort()); + byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + rawMessage.readBytes(address); + builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address))); + builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH)); + builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt())); + builder.setStateV10(createPortState(rawMessage.readUnsignedInt())); + builder.setCurrentFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); + builder.setAdvertisedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); + builder.setSupportedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); + builder.setPeerFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactory.java index 72943a14..10e34d8e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactory.java @@ -1,95 +1,102 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder; - -/** - * Translates QueueGetConfigReply messages (OpenFlow v1.0) - * @author michal.polkorab - */ -public class OF10QueueGetConfigReplyMessageFactory implements OFDeserializer { - - private static final byte PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER = 6; - private static final byte PADDING_IN_PACKET_QUEUE_HEADER = 2; - private static final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4; - private static final byte PADDING_IN_RATE_QUEUE_PROPERTY = 6; - private static final byte PACKET_QUEUE_HEADER_LENGTH = 8; - - private static OF10QueueGetConfigReplyMessageFactory instance; - - private OF10QueueGetConfigReplyMessageFactory() { - // singleton - } - - /** - * - * @return singleton factory - */ - public static synchronized OF10QueueGetConfigReplyMessageFactory getInstance(){ - - if(instance == null){ - instance = new OF10QueueGetConfigReplyMessageFactory(); - } - return instance; - } - - @Override - public GetQueueConfigOutput bufferToMessage(ByteBuf rawMessage, short version) { - GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder(); - builder.setVersion(version); - builder.setXid((rawMessage.readUnsignedInt())); - builder.setPort(new PortNumber((long) rawMessage.readUnsignedShort())); - rawMessage.skipBytes(PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER); - builder.setQueues(createQueuesList(rawMessage)); - return builder.build(); - } - - private static List createQueuesList(ByteBuf input){ - List queuesList = new ArrayList<>(); - while (input.readableBytes() > 0) { - QueuesBuilder queueBuilder = new QueuesBuilder(); - queueBuilder.setQueueId(new QueueId(input.readUnsignedInt())); - int length = input.readUnsignedShort(); - input.skipBytes(PADDING_IN_PACKET_QUEUE_HEADER); - queueBuilder.setQueueProperty(createPropertiesList(input, length - PACKET_QUEUE_HEADER_LENGTH)); - queuesList.add(queueBuilder.build()); - } - return queuesList; - } - - private static List createPropertiesList(ByteBuf input, int length){ - int propertiesLength = length; - List propertiesList = new ArrayList<>(); - while (propertiesLength > 0) { - QueuePropertyBuilder propertiesBuilder = new QueuePropertyBuilder(); - QueueProperties property = QueueProperties.forValue(input.readUnsignedShort()); - propertiesBuilder.setProperty(property); - propertiesLength -= input.readUnsignedShort(); - input.skipBytes(PADDING_IN_QUEUE_PROPERTY_HEADER); - if (property.equals(QueueProperties.OFPQTMINRATE)) { - RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder(); - rateBuilder.setRate(input.readUnsignedShort()); - propertiesBuilder.addAugmentation(RateQueueProperty.class, rateBuilder.build()); - input.skipBytes(PADDING_IN_RATE_QUEUE_PROPERTY); - } - propertiesList.add(propertiesBuilder.build()); - } - return propertiesList; - } +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder; + +/** + * Translates QueueGetConfigReply messages (OpenFlow v1.0) + * @author michal.polkorab + */ +public class OF10QueueGetConfigReplyMessageFactory implements OFDeserializer { + + private static final byte PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER = 6; + private static final byte PADDING_IN_PACKET_QUEUE_HEADER = 2; + private static final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4; + private static final byte PADDING_IN_RATE_QUEUE_PROPERTY = 6; + private static final byte PACKET_QUEUE_HEADER_LENGTH = 8; + + private static OF10QueueGetConfigReplyMessageFactory instance; + + private OF10QueueGetConfigReplyMessageFactory() { + // singleton + } + + /** + * + * @return singleton factory + */ + public static synchronized OF10QueueGetConfigReplyMessageFactory getInstance(){ + + if(instance == null){ + instance = new OF10QueueGetConfigReplyMessageFactory(); + } + return instance; + } + + @Override + public GetQueueConfigOutput bufferToMessage(ByteBuf rawMessage, short version) { + GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder(); + builder.setVersion(version); + builder.setXid((rawMessage.readUnsignedInt())); + builder.setPort(new PortNumber((long) rawMessage.readUnsignedShort())); + rawMessage.skipBytes(PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER); + builder.setQueues(createQueuesList(rawMessage)); + return builder.build(); + } + + private static List createQueuesList(ByteBuf input){ + List queuesList = new ArrayList<>(); + while (input.readableBytes() > 0) { + QueuesBuilder queueBuilder = new QueuesBuilder(); + queueBuilder.setQueueId(new QueueId(input.readUnsignedInt())); + int length = input.readUnsignedShort(); + input.skipBytes(PADDING_IN_PACKET_QUEUE_HEADER); + queueBuilder.setQueueProperty(createPropertiesList(input, length - PACKET_QUEUE_HEADER_LENGTH)); + queuesList.add(queueBuilder.build()); + } + return queuesList; + } + + private static List createPropertiesList(ByteBuf input, int length){ + int propertiesLength = length; + List propertiesList = new ArrayList<>(); + while (propertiesLength > 0) { + QueuePropertyBuilder propertiesBuilder = new QueuePropertyBuilder(); + QueueProperties property = QueueProperties.forValue(input.readUnsignedShort()); + propertiesBuilder.setProperty(property); + propertiesLength -= input.readUnsignedShort(); + input.skipBytes(PADDING_IN_QUEUE_PROPERTY_HEADER); + if (property.equals(QueueProperties.OFPQTMINRATE)) { + RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder(); + rateBuilder.setRate(input.readUnsignedShort()); + propertiesBuilder.addAugmentation(RateQueueProperty.class, rateBuilder.build()); + input.skipBytes(PADDING_IN_RATE_QUEUE_PROPERTY); + } + propertiesList.add(propertiesBuilder.build()); + } + return propertiesList; + } } \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java index bbff2e37..b8887656 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java @@ -1,271 +1,278 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregate; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDesc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStats; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow.FlowStats; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow.FlowStatsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats.PortStats; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats.PortStatsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue.QueueStats; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue.QueueStatsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.TableStats; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.TableStatsBuilder; - -/** - * Translates StatsReply messages (OpenFlow v1.0) - * @author michal.polkorab - */ -public class OF10StatsReplyMessageFactory implements OFDeserializer { - - private static final int DESC_STR_LEN = 256; - private static final int SERIAL_NUM_LEN = 32; - private static final byte PADDING_IN_FLOW_STATS_HEADER = 1; - private static final byte PADDING_IN_FLOW_STATS_HEADER_02 = 6; - private static final byte PADDING_IN_AGGREGATE_HEADER = 4; - private static final byte PADDING_IN_TABLE_HEADER = 3; - private static final byte MAX_TABLE_NAME_LENGTH = 32; - private static final byte PADDING_IN_PORT_STATS_HEADER = 6; - private static final byte PADDING_IN_QUEUE_HEADER = 2; - - private static OF10StatsReplyMessageFactory instance; - - private OF10StatsReplyMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10StatsReplyMessageFactory getInstance() { - if (instance == null){ - instance = new OF10StatsReplyMessageFactory(); - } - return instance; - } - - @Override - public MultipartReplyMessage bufferToMessage(ByteBuf rawMessage, short version) { - MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - int type = rawMessage.readUnsignedShort(); - builder.setType(MultipartType.forValue(type)); - builder.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) != 0)); - switch (type) { - case 0: builder.setMultipartReplyBody(setDesc(rawMessage)); - break; - case 1: builder.setMultipartReplyBody(setFlow(rawMessage)); - break; - case 2: builder.setMultipartReplyBody(setAggregate(rawMessage)); - break; - case 3: builder.setMultipartReplyBody(setTable(rawMessage)); - break; - case 4: builder.setMultipartReplyBody(setPortStats(rawMessage)); - break; - case 5: builder.setMultipartReplyBody(setQueue(rawMessage)); - break; - case 0xFFFF: builder.setMultipartReplyBody(setExperimenter(rawMessage)); - break; - default: - break; - } - return builder.build(); - } - - private static MultipartReplyDesc setDesc(ByteBuf input) { - MultipartReplyDescBuilder descBuilder = new MultipartReplyDescBuilder(); - byte[] mfrDescBytes = new byte[DESC_STR_LEN]; - input.readBytes(mfrDescBytes); - String mfrDesc = new String(mfrDescBytes); - descBuilder.setMfrDesc(mfrDesc.trim()); - byte[] hwDescBytes = new byte[DESC_STR_LEN]; - input.readBytes(hwDescBytes); - String hwDesc = new String(hwDescBytes); - descBuilder.setHwDesc(hwDesc.trim()); - byte[] swDescBytes = new byte[DESC_STR_LEN]; - input.readBytes(swDescBytes); - String swDesc = new String(swDescBytes); - descBuilder.setSwDesc(swDesc.trim()); - byte[] serialNumBytes = new byte[SERIAL_NUM_LEN]; - input.readBytes(serialNumBytes); - String serialNum = new String(serialNumBytes); - descBuilder.setSerialNum(serialNum.trim()); - byte[] dpDescBytes = new byte[DESC_STR_LEN]; - input.readBytes(dpDescBytes); - String dpDesc = new String(dpDescBytes); - descBuilder.setDpDesc(dpDesc.trim()); - return descBuilder.build(); - } - - private static MultipartReplyFlow setFlow(ByteBuf input) { - MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder(); - List flowStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder(); - input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - flowStatsBuilder.setTableId(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_FLOW_STATS_HEADER); - flowStatsBuilder.setMatchV10(OF10MatchDeserializer.createMatchV10(input)); - flowStatsBuilder.setDurationSec(input.readUnsignedInt()); - flowStatsBuilder.setDurationNsec(input.readUnsignedInt()); - flowStatsBuilder.setPriority(input.readUnsignedShort()); - flowStatsBuilder.setIdleTimeout(input.readUnsignedShort()); - flowStatsBuilder.setHardTimeout(input.readUnsignedShort()); - input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02); - byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(cookie); - flowStatsBuilder.setCookie(new BigInteger(cookie)); - byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(packetCount); - flowStatsBuilder.setPacketCount(new BigInteger(packetCount)); - byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(byteCount); - flowStatsBuilder.setByteCount(new BigInteger(byteCount)); - flowStatsBuilder.setActionsList(OF10ActionsDeserializer.createActionsList(input)); - flowStatsList.add(flowStatsBuilder.build()); - } - flowBuilder.setFlowStats(flowStatsList); - return flowBuilder.build(); - } - - private static MultipartReplyAggregate setAggregate(ByteBuf input) { - MultipartReplyAggregateBuilder builder = new MultipartReplyAggregateBuilder(); - byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(packetCount); - builder.setPacketCount(new BigInteger(packetCount)); - byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(byteCount); - builder.setByteCount(new BigInteger(byteCount)); - builder.setFlowCount(input.readUnsignedInt()); - input.skipBytes(PADDING_IN_AGGREGATE_HEADER); - return builder.build(); - } - - private static MultipartReplyTable setTable(ByteBuf input) { - MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder(); - List tableStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - TableStatsBuilder tableStatsBuilder = new TableStatsBuilder(); - tableStatsBuilder.setTableId(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_TABLE_HEADER); - tableStatsBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString()); - tableStatsBuilder.setActiveCount(input.readUnsignedInt()); - byte[] lookupCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(lookupCount); - tableStatsBuilder.setLookupCount(new BigInteger(lookupCount)); - byte[] matchedCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(matchedCount); - tableStatsBuilder.setMatchedCount(new BigInteger(matchedCount)); - tableStatsList.add(tableStatsBuilder.build()); - } - builder.setTableStats(tableStatsList); - return builder.build(); - } - - private static MultipartReplyPortStats setPortStats(ByteBuf input) { - MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder(); - List portStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - PortStatsBuilder portStatsBuilder = new PortStatsBuilder(); - portStatsBuilder.setPortNo((long) input.readUnsignedShort()); - input.skipBytes(PADDING_IN_PORT_STATS_HEADER); - byte[] rxPackets = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxPackets); - portStatsBuilder.setRxPackets(new BigInteger(rxPackets)); - byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txPackets); - portStatsBuilder.setTxPackets(new BigInteger(txPackets)); - byte[] rxBytes = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxBytes); - portStatsBuilder.setRxBytes(new BigInteger(rxBytes)); - byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txBytes); - portStatsBuilder.setTxBytes(new BigInteger(txBytes)); - byte[] rxDropped = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxDropped); - portStatsBuilder.setRxDropped(new BigInteger(rxDropped)); - byte[] txDropped = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txDropped); - portStatsBuilder.setTxDropped(new BigInteger(txDropped)); - byte[] rxErrors = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxErrors); - portStatsBuilder.setRxErrors(new BigInteger(rxErrors)); - byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txErrors); - portStatsBuilder.setTxErrors(new BigInteger(txErrors)); - byte[] rxFrameErr = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxFrameErr); - portStatsBuilder.setRxFrameErr(new BigInteger(rxFrameErr)); - byte[] rxOverErr = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxOverErr); - portStatsBuilder.setRxOverErr(new BigInteger(rxOverErr)); - byte[] rxCrcErr = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(rxCrcErr); - portStatsBuilder.setRxCrcErr(new BigInteger(rxCrcErr)); - byte[] collisions = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(collisions); - portStatsBuilder.setCollisions(new BigInteger(collisions)); - } - builder.setPortStats(portStatsList); - return builder.build(); - } - - private static MultipartReplyQueue setQueue(ByteBuf input) { - MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder(); - List queueStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder(); - queueStatsBuilder.setPortNo((long) input.readUnsignedShort()); - input.skipBytes(PADDING_IN_QUEUE_HEADER); - queueStatsBuilder.setQueueId(input.readUnsignedInt()); - byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txBytes); - queueStatsBuilder.setTxBytes(new BigInteger(txBytes)); - byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txPackets); - queueStatsBuilder.setTxPackets(new BigInteger(txPackets)); - byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(txErrors); - queueStatsBuilder.setTxErrors(new BigInteger(txErrors)); - queueStatsList.add(queueStatsBuilder.build()); - } - builder.setQueueStats(queueStatsList); - return builder.build(); - } - - private static MultipartReplyExperimenter setExperimenter(ByteBuf input) { - MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder(); - builder.setExperimenter(input.readUnsignedInt()); - byte[] data = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(data); - builder.setData(data); - return builder.build(); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow.FlowStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow.FlowStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats.PortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats.PortStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue.QueueStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue.QueueStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.TableStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.TableStatsBuilder; + +/** + * Translates StatsReply messages (OpenFlow v1.0) + * @author michal.polkorab + */ +public class OF10StatsReplyMessageFactory implements OFDeserializer { + + private static final int DESC_STR_LEN = 256; + private static final int SERIAL_NUM_LEN = 32; + private static final byte PADDING_IN_FLOW_STATS_HEADER = 1; + private static final byte PADDING_IN_FLOW_STATS_HEADER_02 = 6; + private static final byte PADDING_IN_AGGREGATE_HEADER = 4; + private static final byte PADDING_IN_TABLE_HEADER = 3; + private static final byte MAX_TABLE_NAME_LENGTH = 32; + private static final byte PADDING_IN_PORT_STATS_HEADER = 6; + private static final byte PADDING_IN_QUEUE_HEADER = 2; + + private static OF10StatsReplyMessageFactory instance; + + private OF10StatsReplyMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10StatsReplyMessageFactory getInstance() { + if (instance == null){ + instance = new OF10StatsReplyMessageFactory(); + } + return instance; + } + + @Override + public MultipartReplyMessage bufferToMessage(ByteBuf rawMessage, short version) { + MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + int type = rawMessage.readUnsignedShort(); + builder.setType(MultipartType.forValue(type)); + builder.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) != 0)); + switch (type) { + case 0: builder.setMultipartReplyBody(setDesc(rawMessage)); + break; + case 1: builder.setMultipartReplyBody(setFlow(rawMessage)); + break; + case 2: builder.setMultipartReplyBody(setAggregate(rawMessage)); + break; + case 3: builder.setMultipartReplyBody(setTable(rawMessage)); + break; + case 4: builder.setMultipartReplyBody(setPortStats(rawMessage)); + break; + case 5: builder.setMultipartReplyBody(setQueue(rawMessage)); + break; + case 0xFFFF: builder.setMultipartReplyBody(setExperimenter(rawMessage)); + break; + default: + break; + } + return builder.build(); + } + + private static MultipartReplyDesc setDesc(ByteBuf input) { + MultipartReplyDescBuilder descBuilder = new MultipartReplyDescBuilder(); + byte[] mfrDescBytes = new byte[DESC_STR_LEN]; + input.readBytes(mfrDescBytes); + String mfrDesc = new String(mfrDescBytes); + descBuilder.setMfrDesc(mfrDesc.trim()); + byte[] hwDescBytes = new byte[DESC_STR_LEN]; + input.readBytes(hwDescBytes); + String hwDesc = new String(hwDescBytes); + descBuilder.setHwDesc(hwDesc.trim()); + byte[] swDescBytes = new byte[DESC_STR_LEN]; + input.readBytes(swDescBytes); + String swDesc = new String(swDescBytes); + descBuilder.setSwDesc(swDesc.trim()); + byte[] serialNumBytes = new byte[SERIAL_NUM_LEN]; + input.readBytes(serialNumBytes); + String serialNum = new String(serialNumBytes); + descBuilder.setSerialNum(serialNum.trim()); + byte[] dpDescBytes = new byte[DESC_STR_LEN]; + input.readBytes(dpDescBytes); + String dpDesc = new String(dpDescBytes); + descBuilder.setDpDesc(dpDesc.trim()); + return descBuilder.build(); + } + + private static MultipartReplyFlow setFlow(ByteBuf input) { + MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder(); + List flowStatsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + flowStatsBuilder.setTableId(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_FLOW_STATS_HEADER); + flowStatsBuilder.setMatchV10(OF10MatchDeserializer.createMatchV10(input)); + flowStatsBuilder.setDurationSec(input.readUnsignedInt()); + flowStatsBuilder.setDurationNsec(input.readUnsignedInt()); + flowStatsBuilder.setPriority(input.readUnsignedShort()); + flowStatsBuilder.setIdleTimeout(input.readUnsignedShort()); + flowStatsBuilder.setHardTimeout(input.readUnsignedShort()); + input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02); + byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(cookie); + flowStatsBuilder.setCookie(new BigInteger(cookie)); + byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(packetCount); + flowStatsBuilder.setPacketCount(new BigInteger(packetCount)); + byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(byteCount); + flowStatsBuilder.setByteCount(new BigInteger(byteCount)); + flowStatsBuilder.setActionsList(OF10ActionsDeserializer.createActionsList(input)); + flowStatsList.add(flowStatsBuilder.build()); + } + flowBuilder.setFlowStats(flowStatsList); + return flowBuilder.build(); + } + + private static MultipartReplyAggregate setAggregate(ByteBuf input) { + MultipartReplyAggregateBuilder builder = new MultipartReplyAggregateBuilder(); + byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(packetCount); + builder.setPacketCount(new BigInteger(packetCount)); + byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(byteCount); + builder.setByteCount(new BigInteger(byteCount)); + builder.setFlowCount(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_AGGREGATE_HEADER); + return builder.build(); + } + + private static MultipartReplyTable setTable(ByteBuf input) { + MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder(); + List tableStatsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + TableStatsBuilder tableStatsBuilder = new TableStatsBuilder(); + tableStatsBuilder.setTableId(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_TABLE_HEADER); + tableStatsBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString()); + tableStatsBuilder.setActiveCount(input.readUnsignedInt()); + byte[] lookupCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(lookupCount); + tableStatsBuilder.setLookupCount(new BigInteger(lookupCount)); + byte[] matchedCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(matchedCount); + tableStatsBuilder.setMatchedCount(new BigInteger(matchedCount)); + tableStatsList.add(tableStatsBuilder.build()); + } + builder.setTableStats(tableStatsList); + return builder.build(); + } + + private static MultipartReplyPortStats setPortStats(ByteBuf input) { + MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder(); + List portStatsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + PortStatsBuilder portStatsBuilder = new PortStatsBuilder(); + portStatsBuilder.setPortNo((long) input.readUnsignedShort()); + input.skipBytes(PADDING_IN_PORT_STATS_HEADER); + byte[] rxPackets = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxPackets); + portStatsBuilder.setRxPackets(new BigInteger(rxPackets)); + byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txPackets); + portStatsBuilder.setTxPackets(new BigInteger(txPackets)); + byte[] rxBytes = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxBytes); + portStatsBuilder.setRxBytes(new BigInteger(rxBytes)); + byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txBytes); + portStatsBuilder.setTxBytes(new BigInteger(txBytes)); + byte[] rxDropped = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxDropped); + portStatsBuilder.setRxDropped(new BigInteger(rxDropped)); + byte[] txDropped = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txDropped); + portStatsBuilder.setTxDropped(new BigInteger(txDropped)); + byte[] rxErrors = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxErrors); + portStatsBuilder.setRxErrors(new BigInteger(rxErrors)); + byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txErrors); + portStatsBuilder.setTxErrors(new BigInteger(txErrors)); + byte[] rxFrameErr = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxFrameErr); + portStatsBuilder.setRxFrameErr(new BigInteger(rxFrameErr)); + byte[] rxOverErr = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxOverErr); + portStatsBuilder.setRxOverErr(new BigInteger(rxOverErr)); + byte[] rxCrcErr = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(rxCrcErr); + portStatsBuilder.setRxCrcErr(new BigInteger(rxCrcErr)); + byte[] collisions = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(collisions); + portStatsBuilder.setCollisions(new BigInteger(collisions)); + } + builder.setPortStats(portStatsList); + return builder.build(); + } + + private static MultipartReplyQueue setQueue(ByteBuf input) { + MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder(); + List queueStatsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder(); + queueStatsBuilder.setPortNo((long) input.readUnsignedShort()); + input.skipBytes(PADDING_IN_QUEUE_HEADER); + queueStatsBuilder.setQueueId(input.readUnsignedInt()); + byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txBytes); + queueStatsBuilder.setTxBytes(new BigInteger(txBytes)); + byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txPackets); + queueStatsBuilder.setTxPackets(new BigInteger(txPackets)); + byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(txErrors); + queueStatsBuilder.setTxErrors(new BigInteger(txErrors)); + queueStatsList.add(queueStatsBuilder.build()); + } + builder.setQueueStats(queueStatsList); + return builder.build(); + } + + private static MultipartReplyExperimenter setExperimenter(ByteBuf input) { + MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder(); + builder.setExperimenter(input.readUnsignedInt()); + byte[] data = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(data); + builder.setData(data); + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactory.java index e0fbe7aa..4c817198 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactory.java @@ -1,44 +1,51 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder; - -/** - * Translates Vendor messages (OpenFlow v1.0) - * @author michal.polkorab - */ -public class OF10VendorMessageFactory implements OFDeserializer { - -private static OF10VendorMessageFactory instance; - - private OF10VendorMessageFactory() { - //singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10VendorMessageFactory getInstance(){ - if (instance == null){ - instance = new OF10VendorMessageFactory(); - } - return instance; - } - - @Override - public ExperimenterMessage bufferToMessage(ByteBuf rawMessage, short version) { - ExperimenterMessageBuilder builder = new ExperimenterMessageBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - builder.setExperimenter(rawMessage.readUnsignedInt()); - int remainingBytes = rawMessage.readableBytes(); - if (remainingBytes > 0) { - builder.setData(rawMessage.readBytes(remainingBytes).array()); - } - return builder.build(); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder; + +/** + * Translates Vendor messages (OpenFlow v1.0) + * @author michal.polkorab + */ +public class OF10VendorMessageFactory implements OFDeserializer { + +private static OF10VendorMessageFactory instance; + + private OF10VendorMessageFactory() { + //singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10VendorMessageFactory getInstance(){ + if (instance == null){ + instance = new OF10VendorMessageFactory(); + } + return instance; + } + + @Override + public ExperimenterMessage bufferToMessage(ByteBuf rawMessage, short version) { + ExperimenterMessageBuilder builder = new ExperimenterMessageBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setExperimenter(rawMessage.readUnsignedInt()); + int remainingBytes = rawMessage.readableBytes(); + if (remainingBytes > 0) { + builder.setData(rawMessage.readBytes(remainingBytes).array()); + } + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java index 0a45ef73..fec07001 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java index da8b5e57..1252e4eb 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java index 3cccbe51..b442a49a 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java @@ -1,109 +1,116 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterQueuePropertyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder; - -/** - * Translates QueueGetConfigReply messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class QueueGetConfigReplyMessageFactory implements OFDeserializer { - - private static final byte PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER = 4; - private static final byte PADDING_IN_PACKET_QUEUE_HEADER = 6; - private static final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4; - private static final int PADDING_IN_RATE_QUEUE_PROPERTY = 6; - private static final int PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY = 4; - private static final byte PACKET_QUEUE_LENGTH = 16; - - private static QueueGetConfigReplyMessageFactory instance; - - private QueueGetConfigReplyMessageFactory() { - // singleton - } - - /** - * - * @return singleton factory - */ - public static synchronized QueueGetConfigReplyMessageFactory getInstance(){ - - if(instance == null){ - instance = new QueueGetConfigReplyMessageFactory(); - } - return instance; - } - - @Override - public GetQueueConfigOutput bufferToMessage(ByteBuf rawMessage, short version) { - GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder(); - builder.setVersion(version); - builder.setXid((rawMessage.readUnsignedInt())); - builder.setPort(new PortNumber(rawMessage.readUnsignedInt())); - rawMessage.skipBytes(PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER); - builder.setQueues(createQueuesList(rawMessage)); - return builder.build(); - } - - private static List createQueuesList(ByteBuf input){ - List queuesList = new ArrayList<>(); - while (input.readableBytes() > 0) { - QueuesBuilder queueBuilder = new QueuesBuilder(); - queueBuilder.setQueueId(new QueueId(input.readUnsignedInt())); - queueBuilder.setPort(new PortNumber(input.readUnsignedInt())); - int length = input.readUnsignedShort(); - input.skipBytes(PADDING_IN_PACKET_QUEUE_HEADER); - queueBuilder.setQueueProperty(createPropertiesList(input, length - PACKET_QUEUE_LENGTH)); - queuesList.add(queueBuilder.build()); - } - return queuesList; - } - - private static List createPropertiesList(ByteBuf input, int length){ - int propertiesLength = length; - List propertiesList = new ArrayList<>(); - while (propertiesLength > 0) { - QueuePropertyBuilder propertiesBuilder = new QueuePropertyBuilder(); - QueueProperties property = QueueProperties.forValue(input.readUnsignedShort()); - propertiesBuilder.setProperty(property); - int currentPropertyLength = input.readUnsignedShort(); - propertiesLength -= currentPropertyLength; - input.skipBytes(PADDING_IN_QUEUE_PROPERTY_HEADER); - if (property.equals(QueueProperties.OFPQTMINRATE) || property.equals(QueueProperties.OFPQTMAXRATE)) { - RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder(); - rateBuilder.setRate(input.readUnsignedShort()); - propertiesBuilder.addAugmentation(RateQueueProperty.class, rateBuilder.build()); - input.skipBytes(PADDING_IN_RATE_QUEUE_PROPERTY); - } else if (property.equals(QueueProperties.OFPQTEXPERIMENTER)) { - ExperimenterQueuePropertyBuilder expBuilder = new ExperimenterQueuePropertyBuilder(); - expBuilder.setExperimenter(input.readUnsignedInt()); - input.skipBytes(PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY); - expBuilder.setData(input.readBytes(currentPropertyLength - - EncodeConstants.SIZE_OF_INT_IN_BYTES - PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY).array()); - propertiesBuilder.addAugmentation(RateQueueProperty.class, expBuilder.build()); - } - propertiesList.add(propertiesBuilder.build()); - } - return propertiesList; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterQueuePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder; + +/** + * Translates QueueGetConfigReply messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class QueueGetConfigReplyMessageFactory implements OFDeserializer { + + private static final byte PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER = 4; + private static final byte PADDING_IN_PACKET_QUEUE_HEADER = 6; + private static final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4; + private static final int PADDING_IN_RATE_QUEUE_PROPERTY = 6; + private static final int PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY = 4; + private static final byte PACKET_QUEUE_LENGTH = 16; + + private static QueueGetConfigReplyMessageFactory instance; + + private QueueGetConfigReplyMessageFactory() { + // singleton + } + + /** + * + * @return singleton factory + */ + public static synchronized QueueGetConfigReplyMessageFactory getInstance(){ + + if(instance == null){ + instance = new QueueGetConfigReplyMessageFactory(); + } + return instance; + } + + @Override + public GetQueueConfigOutput bufferToMessage(ByteBuf rawMessage, short version) { + GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder(); + builder.setVersion(version); + builder.setXid((rawMessage.readUnsignedInt())); + builder.setPort(new PortNumber(rawMessage.readUnsignedInt())); + rawMessage.skipBytes(PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER); + builder.setQueues(createQueuesList(rawMessage)); + return builder.build(); + } + + private static List createQueuesList(ByteBuf input){ + List queuesList = new ArrayList<>(); + while (input.readableBytes() > 0) { + QueuesBuilder queueBuilder = new QueuesBuilder(); + queueBuilder.setQueueId(new QueueId(input.readUnsignedInt())); + queueBuilder.setPort(new PortNumber(input.readUnsignedInt())); + int length = input.readUnsignedShort(); + input.skipBytes(PADDING_IN_PACKET_QUEUE_HEADER); + queueBuilder.setQueueProperty(createPropertiesList(input, length - PACKET_QUEUE_LENGTH)); + queuesList.add(queueBuilder.build()); + } + return queuesList; + } + + private static List createPropertiesList(ByteBuf input, int length){ + int propertiesLength = length; + List propertiesList = new ArrayList<>(); + while (propertiesLength > 0) { + QueuePropertyBuilder propertiesBuilder = new QueuePropertyBuilder(); + QueueProperties property = QueueProperties.forValue(input.readUnsignedShort()); + propertiesBuilder.setProperty(property); + int currentPropertyLength = input.readUnsignedShort(); + propertiesLength -= currentPropertyLength; + input.skipBytes(PADDING_IN_QUEUE_PROPERTY_HEADER); + if (property.equals(QueueProperties.OFPQTMINRATE) || property.equals(QueueProperties.OFPQTMAXRATE)) { + RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder(); + rateBuilder.setRate(input.readUnsignedShort()); + propertiesBuilder.addAugmentation(RateQueueProperty.class, rateBuilder.build()); + input.skipBytes(PADDING_IN_RATE_QUEUE_PROPERTY); + } else if (property.equals(QueueProperties.OFPQTEXPERIMENTER)) { + ExperimenterQueuePropertyBuilder expBuilder = new ExperimenterQueuePropertyBuilder(); + expBuilder.setExperimenter(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY); + expBuilder.setData(input.readBytes(currentPropertyLength + - EncodeConstants.SIZE_OF_INT_IN_BYTES - PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY).array()); + propertiesBuilder.addAugmentation(RateQueueProperty.class, expBuilder.build()); + } + propertiesList.add(propertiesBuilder.build()); + } + return propertiesList; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java index d09aa7a1..9f9fec9a 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactory.java @@ -1,49 +1,56 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.math.BigInteger; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder; - -/** - * Translates RoleReply messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class RoleReplyMessageFactory implements OFDeserializer{ - private static RoleReplyMessageFactory instance; - private static final byte PADDING_IN_ROLE_REPLY_HEADER = 4; - - private RoleReplyMessageFactory() { - // singleton - } - - /** - * - * @return singleton factory - */ - public static synchronized RoleReplyMessageFactory getInstance(){ - if(instance == null){ - instance = new RoleReplyMessageFactory(); - } - return instance; - } - - @Override - public RoleRequestOutput bufferToMessage(ByteBuf rawMessage, short version) { - RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - builder.setRole(ControllerRole.forValue((int) rawMessage.readUnsignedInt())); - rawMessage.skipBytes(PADDING_IN_ROLE_REPLY_HEADER); - byte[] generationID = new byte[8]; - rawMessage.readBytes(generationID); - builder.setGenerationId(new BigInteger(generationID)); - return builder.build(); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.math.BigInteger; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder; + +/** + * Translates RoleReply messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class RoleReplyMessageFactory implements OFDeserializer{ + private static RoleReplyMessageFactory instance; + private static final byte PADDING_IN_ROLE_REPLY_HEADER = 4; + + private RoleReplyMessageFactory() { + // singleton + } + + /** + * + * @return singleton factory + */ + public static synchronized RoleReplyMessageFactory getInstance(){ + if(instance == null){ + instance = new RoleReplyMessageFactory(); + } + return instance; + } + + @Override + public RoleRequestOutput bufferToMessage(ByteBuf rawMessage, short version) { + RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder(); + builder.setVersion(version); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setRole(ControllerRole.forValue((int) rawMessage.readUnsignedInt())); + rawMessage.skipBytes(PADDING_IN_ROLE_REPLY_HEADER); + byte[] generationID = new byte[8]; + rawMessage.readBytes(generationID); + builder.setGenerationId(new BigInteger(generationID)); + return builder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/EncoderTable.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/EncoderTable.java index b26d4257..3a1e0d06 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/EncoderTable.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/EncoderTable.java @@ -1,132 +1,139 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization; - -import java.util.HashMap; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.BarrierInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoReplyInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.ExperimenterInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.FlowModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetAsyncRequestMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetConfigInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetFeaturesInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetQueueConfigInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GroupModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MeterModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10BarrierInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FlowModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10HelloInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PacketOutInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PortModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10QueueGetConfigInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10VendorInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PacketOutInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PortModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.RoleRequestInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetAsyncInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetConfigMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.serialization.factories.TableModInputMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput; -import org.opendaylight.yangtools.yang.binding.DataObject; - -/** - * Stores and provides correct encoders for received messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class EncoderTable { - - private static final short OF10 = EncodeConstants.OF10_VERSION_ID; - private static final short OF13 = EncodeConstants.OF13_VERSION_ID; - private static EncoderTable instance; - private Map, OFSerializer> table; - - - private EncoderTable() { - // do nothing - } - - /** - * @return singleton instance - */ - public static synchronized EncoderTable getInstance() { - if (instance == null) { - instance = new EncoderTable(); - instance.init(); - } - return instance; - } - - /** - * Encoder table provisioning - */ - public void init() { - table = new HashMap<>(); - table.put(new MessageTypeKey<>(OF10, BarrierInput.class), OF10BarrierInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, EchoInput.class), EchoInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, EchoReplyInput.class), EchoReplyInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, ExperimenterInput.class), OF10VendorInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, FlowModInput.class), OF10FlowModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, GetConfigInput.class), GetConfigInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, GetFeaturesInput.class), GetFeaturesInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, GetQueueConfigInput.class), OF10QueueGetConfigInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, HelloInput.class), OF10HelloInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, MultipartRequestInput.class), OF10StatsRequestInputFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, PacketOutInput.class), OF10PacketOutInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, PortModInput.class), OF10PortModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF10, SetConfigInput.class), SetConfigMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, BarrierInput.class), BarrierInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, EchoInput.class), EchoInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, EchoReplyInput.class), EchoReplyInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, ExperimenterInput.class), ExperimenterInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, FlowModInput.class), FlowModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, GetAsyncInput.class), GetAsyncRequestMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, GetConfigInput.class), GetConfigInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, GetFeaturesInput.class), GetFeaturesInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, GetQueueConfigInput.class), GetQueueConfigInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, GroupModInput.class), GroupModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, HelloInput.class), HelloInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, MeterModInput.class), MeterModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, MultipartRequestInput.class), MultipartRequestInputFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, PacketOutInput.class), PacketOutInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, PortModInput.class), PortModInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, RoleRequestInput.class), RoleRequestInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, SetAsyncInput.class), SetAsyncInputMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, SetConfigInput.class), SetConfigMessageFactory.getInstance()); - table.put(new MessageTypeKey<>(OF13, TableModInput.class), TableModInputMessageFactory.getInstance()); - } - - /** - * @param msgTypeKey - * @return encoder for current type of message (msgTypeKey) - */ - @SuppressWarnings("unchecked") - public OFSerializer getEncoder(MessageTypeKey msgTypeKey) { - return (OFSerializer) table.get(msgTypeKey); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.BarrierInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoReplyInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.ExperimenterInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.FlowModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetAsyncRequestMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetConfigInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetFeaturesInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetQueueConfigInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GroupModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MeterModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10BarrierInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FlowModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10HelloInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PacketOutInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PortModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10QueueGetConfigInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10VendorInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PacketOutInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PortModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.RoleRequestInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetAsyncInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetConfigMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.serialization.factories.TableModInputMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * Stores and provides correct encoders for received messages + * @author michal.polkorab + * @author timotej.kubas + */ +public class EncoderTable { + + private static final short OF10 = EncodeConstants.OF10_VERSION_ID; + private static final short OF13 = EncodeConstants.OF13_VERSION_ID; + private static EncoderTable instance; + private Map, OFSerializer> table; + + + private EncoderTable() { + // do nothing + } + + /** + * @return singleton instance + */ + public static synchronized EncoderTable getInstance() { + if (instance == null) { + instance = new EncoderTable(); + instance.init(); + } + return instance; + } + + /** + * Encoder table provisioning + */ + public void init() { + table = new HashMap<>(); + table.put(new MessageTypeKey<>(OF10, BarrierInput.class), OF10BarrierInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, EchoInput.class), EchoInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, EchoReplyInput.class), EchoReplyInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, ExperimenterInput.class), OF10VendorInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, FlowModInput.class), OF10FlowModInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, GetConfigInput.class), GetConfigInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, GetFeaturesInput.class), GetFeaturesInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, GetQueueConfigInput.class), OF10QueueGetConfigInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, HelloInput.class), OF10HelloInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, MultipartRequestInput.class), OF10StatsRequestInputFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, PacketOutInput.class), OF10PacketOutInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, PortModInput.class), OF10PortModInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF10, SetConfigInput.class), SetConfigMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, BarrierInput.class), BarrierInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, EchoInput.class), EchoInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, EchoReplyInput.class), EchoReplyInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, ExperimenterInput.class), ExperimenterInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, FlowModInput.class), FlowModInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, GetAsyncInput.class), GetAsyncRequestMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, GetConfigInput.class), GetConfigInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, GetFeaturesInput.class), GetFeaturesInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, GetQueueConfigInput.class), GetQueueConfigInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, GroupModInput.class), GroupModInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, HelloInput.class), HelloInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, MeterModInput.class), MeterModInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, MultipartRequestInput.class), MultipartRequestInputFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, PacketOutInput.class), PacketOutInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, PortModInput.class), PortModInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, RoleRequestInput.class), RoleRequestInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, SetAsyncInput.class), SetAsyncInputMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, SetConfigInput.class), SetConfigMessageFactory.getInstance()); + table.put(new MessageTypeKey<>(OF13, TableModInput.class), TableModInputMessageFactory.getInstance()); + } + + /** + * @param msgTypeKey + * @return encoder for current type of message (msgTypeKey) + */ + @SuppressWarnings("unchecked") + public OFSerializer getEncoder(MessageTypeKey msgTypeKey) { + return (OFSerializer) table.get(msgTypeKey); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageTypeKey.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageTypeKey.java index 56a1661b..38cdcda9 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageTypeKey.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageTypeKey.java @@ -1,73 +1,80 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization; - -import org.opendaylight.yangtools.yang.binding.DataObject; - -/** - * Class used as a key in {@link EncoderTable} - * @author michal.polkorab - * @author timotej.kubas - * @param message type (class) - */ -public class MessageTypeKey { - - private final Class msgType; - private final short msgVersion; - - /** - * @param msgVersion protocol version - * @param msgType type of message - */ - public MessageTypeKey(short msgVersion, Class msgType) { - super(); - this.msgType = msgType; - this.msgVersion = msgVersion; - } - - /** - * @return msgVersion - */ - public short getMsgVersion() { - return msgVersion; - } - - /** - * @return the msgType - */ - public Class getMsgType() { - return msgType; - } - - @Override - public String toString() { - return "msgVersion: " + msgVersion + " msgType: " + msgType.getName(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + msgVersion; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - MessageTypeKey other = (MessageTypeKey) obj; - if (msgType == null) { - if (other.msgType != null) - return false; - } else if (!other.msgType.isAssignableFrom(msgType)) - return false; - if (msgVersion != other.msgVersion) - return false; - return true; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization; + +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * Class used as a key in {@link EncoderTable} + * @author michal.polkorab + * @author timotej.kubas + * @param message type (class) + */ +public class MessageTypeKey { + + private final Class msgType; + private final short msgVersion; + + /** + * @param msgVersion protocol version + * @param msgType type of message + */ + public MessageTypeKey(short msgVersion, Class msgType) { + super(); + this.msgType = msgType; + this.msgVersion = msgVersion; + } + + /** + * @return msgVersion + */ + public short getMsgVersion() { + return msgVersion; + } + + /** + * @return the msgType + */ + public Class getMsgType() { + return msgType; + } + + @Override + public String toString() { + return "msgVersion: " + msgVersion + " msgType: " + msgType.getName(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + msgVersion; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MessageTypeKey other = (MessageTypeKey) obj; + if (msgType == null) { + if (other.msgType != null) + return false; + } else if (!other.msgType.isAssignableFrom(msgType)) + return false; + if (msgVersion != other.msgVersion) + return false; + return true; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/OFSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/OFSerializer.java index 2c88d0a0..f514f140 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/OFSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/OFSerializer.java @@ -1,35 +1,42 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.yangtools.yang.binding.DataObject; - -/** - * Uniform interface for serializing factories - * @author michal.polkorab - * @author timotej.kubas - * @param message type - */ -public interface OFSerializer { - - /** - * Transforms POJO/DTO into byte message (ByteBuf). - * @param version version of used OF Protocol - * @param out ByteBuf used for output - * @param message message that will be transformed into ByteBuf - */ - public abstract void messageToBuffer(short version, ByteBuf out, E message); - - /** - * Compute length of received message - * @param message - * @return computed length - */ - public abstract int computeLength(E message); - - /** - * @return message code type - */ - public byte getMessageType(); -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * Uniform interface for serializing factories + * @author michal.polkorab + * @author timotej.kubas + * @param message type + */ +public interface OFSerializer { + + /** + * Transforms POJO/DTO into byte message (ByteBuf). + * @param version version of used OF Protocol + * @param out ByteBuf used for output + * @param message message that will be transformed into ByteBuf + */ + public abstract void messageToBuffer(short version, ByteBuf out, E message); + + /** + * Compute length of received message + * @param message + * @return computed length + */ + public abstract int computeLength(E message); + + /** + * @return message code type + */ + public byte getMessageType(); +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactory.java index 6ed701a9..18449f70 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactory.java @@ -1,34 +1,41 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class SerializationFactory { - - private static final Logger LOGGER = LoggerFactory - .getLogger(SerializationFactory.class); - /** - * Transforms POJO message into ByteBuf - * @param version version used for encoding received message - * @param out ByteBuf for storing and sending transformed message - * @param message POJO message - */ - public static void messageToBuffer(short version, ByteBuf out, E message) { - @SuppressWarnings("unchecked") - MessageTypeKey msgTypeKey = new MessageTypeKey<>(version, (Class) message.getClass()); - OFSerializer encoder = EncoderTable.getInstance().getEncoder(msgTypeKey); - if (encoder != null) { - encoder.messageToBuffer(version, out, message); - } else { - LOGGER.warn("No correct encoder found in EncoderTable for arguments: " + msgTypeKey.toString()); - } - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class SerializationFactory { + + private static final Logger LOGGER = LoggerFactory + .getLogger(SerializationFactory.class); + /** + * Transforms POJO message into ByteBuf + * @param version version used for encoding received message + * @param out ByteBuf for storing and sending transformed message + * @param message POJO message + */ + public static void messageToBuffer(short version, ByteBuf out, E message) { + @SuppressWarnings("unchecked") + MessageTypeKey msgTypeKey = new MessageTypeKey<>(version, (Class) message.getClass()); + OFSerializer encoder = EncoderTable.getInstance().getEncoder(msgTypeKey); + if (encoder != null) { + encoder.messageToBuffer(version, out, message); + } else { + LOGGER.warn("No correct encoder found in EncoderTable for arguments: " + msgTypeKey.toString()); + } + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java index 9253410d..def00142 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java @@ -1,50 +1,57 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; - -/** - * Translates BarrierRequest messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class BarrierInputMessageFactory implements OFSerializer { - - /** Code type of BarrierRequest message */ - public static final byte MESSAGE_TYPE = 20; - private static BarrierInputMessageFactory instance; - private static final int MESSAGE_LENGTH = 8; - - private BarrierInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized BarrierInputMessageFactory getInstance() { - if (instance == null) { - instance = new BarrierInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, BarrierInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - } - - @Override - public int computeLength(BarrierInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; + +/** + * Translates BarrierRequest messages + * @author michal.polkorab + * @author timotej.kubas + */ +public class BarrierInputMessageFactory implements OFSerializer { + + /** Code type of BarrierRequest message */ + public static final byte MESSAGE_TYPE = 20; + private static BarrierInputMessageFactory instance; + private static final int MESSAGE_LENGTH = 8; + + private BarrierInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized BarrierInputMessageFactory getInstance() { + if (instance == null) { + instance = new BarrierInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, BarrierInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + } + + @Override + public int computeLength(BarrierInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java index ef83d5c4..9e1cfa5b 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java @@ -1,60 +1,67 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput; - -/** - * Translates EchoRequest messages (both OpenFlow v1.0 and OpenFlow v1.3) - * @author michal.polkorab - * @author timotej.kubas - */ -public class EchoInputMessageFactory implements OFSerializer { - - /** Code type of EchoRequest message */ - public static final byte MESSAGE_TYPE = 2; - private static EchoInputMessageFactory instance; - private static final int MESSAGE_LENGTH = 8; - - private EchoInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized EchoInputMessageFactory getInstance() { - if (instance == null) { - instance = new EchoInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, EchoInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - byte[] data = message.getData(); - if (data != null) { - out.writeBytes(data); - } - } - - @Override - public int computeLength(EchoInput message) { - int length = MESSAGE_LENGTH; - byte[] data = message.getData(); - if (data != null) { - length += data.length; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput; + +/** + * Translates EchoRequest messages (both OpenFlow v1.0 and OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public class EchoInputMessageFactory implements OFSerializer { + + /** Code type of EchoRequest message */ + public static final byte MESSAGE_TYPE = 2; + private static EchoInputMessageFactory instance; + private static final int MESSAGE_LENGTH = 8; + + private EchoInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized EchoInputMessageFactory getInstance() { + if (instance == null) { + instance = new EchoInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, EchoInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + byte[] data = message.getData(); + if (data != null) { + out.writeBytes(data); + } + } + + @Override + public int computeLength(EchoInput message) { + int length = MESSAGE_LENGTH; + byte[] data = message.getData(); + if (data != null) { + length += data.length; + } + return length; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java index 2c8effbe..3e76f8c0 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java @@ -1,60 +1,67 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; - -/** - * Translates EchoReply messages (both OpenFlow v1.0 and OpenFlow v1.3) - * @author michal.polkorab - * @author timotej.kubas - */ -public class EchoReplyInputMessageFactory implements OFSerializer{ - - /** Code type of EchoReply message */ - public static final byte MESSAGE_TYPE = 3; - private static final int MESSAGE_LENGTH = 8; - private static EchoReplyInputMessageFactory instance; - - private EchoReplyInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized EchoReplyInputMessageFactory getInstance() { - if (instance == null) { - instance = new EchoReplyInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - EchoReplyInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - byte[] data = message.getData(); - if (data != null) { - out.writeBytes(data); - } - } - - @Override - public int computeLength(EchoReplyInput message) { - int length = MESSAGE_LENGTH; - byte[] data = message.getData(); - if (data != null) { - length += data.length; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; + +/** + * Translates EchoReply messages (both OpenFlow v1.0 and OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public class EchoReplyInputMessageFactory implements OFSerializer{ + + /** Code type of EchoReply message */ + public static final byte MESSAGE_TYPE = 3; + private static final int MESSAGE_LENGTH = 8; + private static EchoReplyInputMessageFactory instance; + + private EchoReplyInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized EchoReplyInputMessageFactory getInstance() { + if (instance == null) { + instance = new EchoReplyInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + EchoReplyInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + byte[] data = message.getData(); + if (data != null) { + out.writeBytes(data); + } + } + + @Override + public int computeLength(EchoReplyInput message) { + int length = MESSAGE_LENGTH; + byte[] data = message.getData(); + if (data != null) { + length += data.length; + } + return length; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java index 60f116b8..ff24b6e0 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java @@ -1,64 +1,71 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; - -/** - * Translates Experimenter messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class ExperimenterInputMessageFactory implements OFSerializer{ - - /** Code type of Experimenter message */ - public static final byte MESSAGE_TYPE = 4; - private static final byte MESSAGE_LENGTH = 8; - private static ExperimenterInputMessageFactory instance; - - private ExperimenterInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized ExperimenterInputMessageFactory getInstance() { - if (instance == null) { - instance = new ExperimenterInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - ExperimenterInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getExperimenter().intValue()); - out.writeInt(message.getExpType().intValue()); - byte[] data = message.getData(); - if (data != null) { - out.writeBytes(data); - } - } - - @Override - public int computeLength(ExperimenterInput message) { - int length = MESSAGE_LENGTH + 2 * (EncodeConstants.SIZE_OF_INT_IN_BYTES); - byte[] data = message.getData(); - if (data != null) { - length += data.length; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; + +/** + * Translates Experimenter messages + * @author michal.polkorab + * @author timotej.kubas + */ +public class ExperimenterInputMessageFactory implements OFSerializer{ + + /** Code type of Experimenter message */ + public static final byte MESSAGE_TYPE = 4; + private static final byte MESSAGE_LENGTH = 8; + private static ExperimenterInputMessageFactory instance; + + private ExperimenterInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized ExperimenterInputMessageFactory getInstance() { + if (instance == null) { + instance = new ExperimenterInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + ExperimenterInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeInt(message.getExperimenter().intValue()); + out.writeInt(message.getExpType().intValue()); + byte[] data = message.getData(); + if (data != null) { + out.writeBytes(data); + } + } + + @Override + public int computeLength(ExperimenterInput message) { + int length = MESSAGE_LENGTH + 2 * (EncodeConstants.SIZE_OF_INT_IN_BYTES); + byte[] data = message.getData(); + if (data != null) { + length += data.length; + } + return length; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java index 511f1622..cb2a5f74 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java @@ -1,85 +1,92 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.HashMap; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; - -/** - * Translates FlowMod messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class FlowModInputMessageFactory implements OFSerializer { - private static final byte MESSAGE_TYPE = 14; - private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2; - private static final int MESSAGE_LENGTH = 48; - private static FlowModInputMessageFactory instance; - - private FlowModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized FlowModInputMessageFactory getInstance() { - if(instance == null) { - instance = new FlowModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, FlowModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeLong(message.getCookie().longValue()); - out.writeLong(message.getCookieMask().longValue()); - out.writeByte(message.getTableId().getValue().byteValue()); - out.writeByte(message.getCommand().getIntValue()); - out.writeShort(message.getIdleTimeout().intValue()); - out.writeShort(message.getHardTimeout().intValue()); - out.writeShort(message.getPriority()); - out.writeInt(message.getBufferId().intValue()); - out.writeInt(message.getOutPort().getValue().intValue()); - out.writeInt(message.getOutGroup().intValue()); - out.writeShort(createFlowModFlagsBitmask(message.getFlags())); - ByteBufUtils.padBuffer(PADDING_IN_FLOW_MOD_MESSAGE, out); - MatchSerializer.encodeMatch(message.getMatch(), out); - InstructionsSerializer.encodeInstructions(message.getInstructions(), out); - } - - @Override - public int computeLength(FlowModInput message) { - return MESSAGE_LENGTH + MatchSerializer.computeMatchLength(message.getMatch()) - + InstructionsSerializer.computeInstructionsLength(message.getInstructions()); - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static int createFlowModFlagsBitmask(FlowModFlags flags) { - int flowModFlagBitmask = 0; - Map flowModFlagsMap = new HashMap<>(); - flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM()); - flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP()); - flowModFlagsMap.put(2, flags.isOFPFFRESETCOUNTS()); - flowModFlagsMap.put(3, flags.isOFPFFNOPKTCOUNTS()); - flowModFlagsMap.put(4, flags.isOFPFFNOBYTCOUNTS()); - - flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap); - return flowModFlagBitmask; - } - - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; + +/** + * Translates FlowMod messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class FlowModInputMessageFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 14; + private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2; + private static final int MESSAGE_LENGTH = 48; + private static FlowModInputMessageFactory instance; + + private FlowModInputMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized FlowModInputMessageFactory getInstance() { + if(instance == null) { + instance = new FlowModInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, FlowModInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeLong(message.getCookie().longValue()); + out.writeLong(message.getCookieMask().longValue()); + out.writeByte(message.getTableId().getValue().byteValue()); + out.writeByte(message.getCommand().getIntValue()); + out.writeShort(message.getIdleTimeout().intValue()); + out.writeShort(message.getHardTimeout().intValue()); + out.writeShort(message.getPriority()); + out.writeInt(message.getBufferId().intValue()); + out.writeInt(message.getOutPort().getValue().intValue()); + out.writeInt(message.getOutGroup().intValue()); + out.writeShort(createFlowModFlagsBitmask(message.getFlags())); + ByteBufUtils.padBuffer(PADDING_IN_FLOW_MOD_MESSAGE, out); + MatchSerializer.encodeMatch(message.getMatch(), out); + InstructionsSerializer.encodeInstructions(message.getInstructions(), out); + } + + @Override + public int computeLength(FlowModInput message) { + return MESSAGE_LENGTH + MatchSerializer.computeMatchLength(message.getMatch()) + + InstructionsSerializer.computeInstructionsLength(message.getInstructions()); + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + private static int createFlowModFlagsBitmask(FlowModFlags flags) { + int flowModFlagBitmask = 0; + Map flowModFlagsMap = new HashMap<>(); + flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM()); + flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP()); + flowModFlagsMap.put(2, flags.isOFPFFRESETCOUNTS()); + flowModFlagsMap.put(3, flags.isOFPFFNOPKTCOUNTS()); + flowModFlagsMap.put(4, flags.isOFPFFNOBYTCOUNTS()); + + flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap); + return flowModFlagBitmask; + } + + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetAsyncRequestMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetAsyncRequestMessageFactory.java index e1f3a8cc..a4a1a59e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetAsyncRequestMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetAsyncRequestMessageFactory.java @@ -1,50 +1,57 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput; - -/** - * Translates GetAsyncRequest messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class GetAsyncRequestMessageFactory implements OFSerializer { - private static final byte MESSAGE_TYPE = 26; - private static final int MESSAGE_LENGTH = 8; - private static GetAsyncRequestMessageFactory instance; - - private GetAsyncRequestMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized GetAsyncRequestMessageFactory getInstance() { - if (instance == null) { - instance = new GetAsyncRequestMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - GetAsyncInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - } - - @Override - public int computeLength(GetAsyncInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput; + +/** + * Translates GetAsyncRequest messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class GetAsyncRequestMessageFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 26; + private static final int MESSAGE_LENGTH = 8; + private static GetAsyncRequestMessageFactory instance; + + private GetAsyncRequestMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized GetAsyncRequestMessageFactory getInstance() { + if (instance == null) { + instance = new GetAsyncRequestMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + GetAsyncInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + } + + @Override + public int computeLength(GetAsyncInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java index bea1eeb6..23898ff8 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java @@ -1,52 +1,59 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput; - -/** - * Translates GetConfigRequest messages (both OpenFlow v1.0 and OpenFlow v1.3) - * @author michal.polkorab - * @author timotej.kubas - */ -public class GetConfigInputMessageFactory implements OFSerializer { - - /** Code type of GetConfigRequest message */ - public static final byte MESSAGE_TYPE = 7; - private static final int MESSAGE_LENGTH = 8; - private static GetConfigInputMessageFactory instance; - - private GetConfigInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized GetConfigInputMessageFactory getInstance() { - if (instance == null) { - instance = new GetConfigInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - GetConfigInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - } - - @Override - public int computeLength(GetConfigInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput; + +/** + * Translates GetConfigRequest messages (both OpenFlow v1.0 and OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public class GetConfigInputMessageFactory implements OFSerializer { + + /** Code type of GetConfigRequest message */ + public static final byte MESSAGE_TYPE = 7; + private static final int MESSAGE_LENGTH = 8; + private static GetConfigInputMessageFactory instance; + + private GetConfigInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized GetConfigInputMessageFactory getInstance() { + if (instance == null) { + instance = new GetConfigInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + GetConfigInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + } + + @Override + public int computeLength(GetConfigInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java index ff29f4d5..d1f82df2 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java @@ -1,52 +1,59 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput; - -/** - * Translates FeaturesRequest messages (both OpenFlow v1.0 and OpenFlow v1.3) - * @author michal.polkorab - * @author timotej.kubas - */ -public class GetFeaturesInputMessageFactory implements OFSerializer{ - - /** Code type of FeaturesRequest message */ - public static final byte MESSAGE_TYPE = 5; - private static final int MESSAGE_LENGTH = 8; - private static GetFeaturesInputMessageFactory instance; - - private GetFeaturesInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized GetFeaturesInputMessageFactory getInstance() { - if (instance == null) { - instance = new GetFeaturesInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - GetFeaturesInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - } - - @Override - public int computeLength(GetFeaturesInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput; + +/** + * Translates FeaturesRequest messages (both OpenFlow v1.0 and OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public class GetFeaturesInputMessageFactory implements OFSerializer{ + + /** Code type of FeaturesRequest message */ + public static final byte MESSAGE_TYPE = 5; + private static final int MESSAGE_LENGTH = 8; + private static GetFeaturesInputMessageFactory instance; + + private GetFeaturesInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized GetFeaturesInputMessageFactory getInstance() { + if (instance == null) { + instance = new GetFeaturesInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + GetFeaturesInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + } + + @Override + public int computeLength(GetFeaturesInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactory.java index d5c8d5b1..5a87ec36 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java index 0f9b09ee..a9a2c510 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java @@ -1,94 +1,101 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList; - -/** - * Translates GroupMod messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class GroupModInputMessageFactory implements OFSerializer { - private static final byte MESSAGE_TYPE = 15; - private static final int MESSAGE_LENGTH = 16; - private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1; - private static final byte LENGTH_OF_BUCKET_STRUCTURE = 16; - private static final byte PADDING_IN_BUCKET = 4; - private static GroupModInputMessageFactory instance; - - private GroupModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized GroupModInputMessageFactory getInstance() { - if (instance == null) { - instance = new GroupModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - GroupModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getCommand().getIntValue()); - out.writeByte(message.getType().getIntValue()); - ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, out); - out.writeInt(message.getGroupId().getValue().intValue()); - encodeBuckets(message.getBucketsList(), out); - } - - @Override - public int computeLength(GroupModInput message) { - return MESSAGE_LENGTH + computeLengthOfBuckets(message.getBucketsList()); - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static void encodeBuckets(List buckets, ByteBuf outBuffer) { - if (buckets != null) { - for (BucketsList currentBucket : buckets) { - outBuffer.writeShort(computeLengthOfBucket(currentBucket)); - outBuffer.writeShort(currentBucket.getWeight().shortValue()); - outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue()); - outBuffer.writeInt(currentBucket.getWatchGroup().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer); - ActionsSerializer.encodeActions(currentBucket.getActionsList(), outBuffer); - } - } - } - - private static int computeLengthOfBucket(BucketsList bucket) { - int lengthOfBuckets = 0; - if (bucket != null) { - lengthOfBuckets = LENGTH_OF_BUCKET_STRUCTURE + ActionsSerializer.computeLengthOfActions(bucket.getActionsList()); - } - return lengthOfBuckets; - } - - private static int computeLengthOfBuckets(List buckets) { - int lengthOfBuckets = 0; - if (buckets != null) { - for (BucketsList currentBucket : buckets) { - lengthOfBuckets += LENGTH_OF_BUCKET_STRUCTURE + ActionsSerializer.computeLengthOfActions(currentBucket.getActionsList()); - } - } - return lengthOfBuckets; - } - - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList; + +/** + * Translates GroupMod messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class GroupModInputMessageFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 15; + private static final int MESSAGE_LENGTH = 16; + private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1; + private static final byte LENGTH_OF_BUCKET_STRUCTURE = 16; + private static final byte PADDING_IN_BUCKET = 4; + private static GroupModInputMessageFactory instance; + + private GroupModInputMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized GroupModInputMessageFactory getInstance() { + if (instance == null) { + instance = new GroupModInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + GroupModInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeShort(message.getCommand().getIntValue()); + out.writeByte(message.getType().getIntValue()); + ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, out); + out.writeInt(message.getGroupId().getValue().intValue()); + encodeBuckets(message.getBucketsList(), out); + } + + @Override + public int computeLength(GroupModInput message) { + return MESSAGE_LENGTH + computeLengthOfBuckets(message.getBucketsList()); + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + private static void encodeBuckets(List buckets, ByteBuf outBuffer) { + if (buckets != null) { + for (BucketsList currentBucket : buckets) { + outBuffer.writeShort(computeLengthOfBucket(currentBucket)); + outBuffer.writeShort(currentBucket.getWeight().shortValue()); + outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue()); + outBuffer.writeInt(currentBucket.getWatchGroup().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer); + ActionsSerializer.encodeActions(currentBucket.getActionsList(), outBuffer); + } + } + } + + private static int computeLengthOfBucket(BucketsList bucket) { + int lengthOfBuckets = 0; + if (bucket != null) { + lengthOfBuckets = LENGTH_OF_BUCKET_STRUCTURE + ActionsSerializer.computeLengthOfActions(bucket.getActionsList()); + } + return lengthOfBuckets; + } + + private static int computeLengthOfBuckets(List buckets) { + int lengthOfBuckets = 0; + if (buckets != null) { + for (BucketsList currentBucket : buckets) { + lengthOfBuckets += LENGTH_OF_BUCKET_STRUCTURE + ActionsSerializer.computeLengthOfActions(currentBucket.getActionsList()); + } + } + return lengthOfBuckets; + } + + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java index 1a359328..a0ffc2dd 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java @@ -1,113 +1,120 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Translates Hello messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class HelloInputMessageFactory implements OFSerializer{ - - /** Code type of Hello message */ - private static final byte MESSAGE_TYPE = 0; - private static int MESSAGE_LENGTH = 8; - /** Size of hello element header (in bytes) */ - public static final byte HELLO_ELEMENT_HEADER_SIZE = 4; - private static HelloInputMessageFactory instance; - - private static final Logger LOGGER = LoggerFactory - .getLogger(HelloInputMessageFactory.class); - - - private HelloInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized HelloInputMessageFactory getInstance() { - if (instance == null) { - instance = new HelloInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, HelloInput message) { - int startWriterIndex = out.writerIndex(); - ByteBufUtils.writeOFHeader(instance, message, out); - encodeElementsList(message, out); - int endWriterIndex = out.writerIndex(); - int writtenBytesDiff = computeLength(message) - (endWriterIndex - startWriterIndex); - LOGGER.debug("writtenbytes: " + writtenBytesDiff); - ByteBufUtils.padBuffer(writtenBytesDiff, out); - } - - @Override - public int computeLength(HelloInput message) { - int length = MESSAGE_LENGTH; - List elements = message.getElements(); - if (elements != null) { - for (Elements element : elements) { - if (HelloElementType.VERSIONBITMAP.equals(element.getType())) { - int bitmapLength = computeVersionBitmapLength(element); - int paddingRemainder = bitmapLength % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - bitmapLength += EncodeConstants.PADDING - paddingRemainder; - } - length += bitmapLength; - } - } - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static void encodeElementsList(HelloInput message, ByteBuf output) { - int[] versionBitmap; - if (message.getElements() != null) { - for (Elements currElement : message.getElements()) { - output.writeShort(currElement.getType().getIntValue()); - if (currElement.getType().equals(HelloElementType.VERSIONBITMAP)) { - short bitmapLength = computeVersionBitmapLength(currElement); - output.writeShort(bitmapLength); - versionBitmap = ByteBufUtils.fillBitMaskFromList(currElement.getVersionBitmap()); - LOGGER.debug("vbs: " + versionBitmap.length); - LOGGER.debug("Version bitmap (below):"); - for (int i = 0; i < versionBitmap.length; i++) { - LOGGER.debug(Integer.toBinaryString(versionBitmap[i])); - output.writeInt(versionBitmap[i]); - } - int padding = bitmapLength - versionBitmap.length * 4 - HELLO_ELEMENT_HEADER_SIZE; - ByteBufUtils.padBuffer(padding , output); - } - } - } - } - - private static short computeVersionBitmapLength(Elements element) { - short elementlength = HELLO_ELEMENT_HEADER_SIZE; - if (!element.getVersionBitmap().isEmpty()) { - elementlength += ((element.getVersionBitmap().size() - 1) / Integer.SIZE + 1) * (EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - return elementlength; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Translates Hello messages + * @author michal.polkorab + * @author timotej.kubas + */ +public class HelloInputMessageFactory implements OFSerializer{ + + /** Code type of Hello message */ + private static final byte MESSAGE_TYPE = 0; + private static int MESSAGE_LENGTH = 8; + /** Size of hello element header (in bytes) */ + public static final byte HELLO_ELEMENT_HEADER_SIZE = 4; + private static HelloInputMessageFactory instance; + + private static final Logger LOGGER = LoggerFactory + .getLogger(HelloInputMessageFactory.class); + + + private HelloInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized HelloInputMessageFactory getInstance() { + if (instance == null) { + instance = new HelloInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, HelloInput message) { + int startWriterIndex = out.writerIndex(); + ByteBufUtils.writeOFHeader(instance, message, out); + encodeElementsList(message, out); + int endWriterIndex = out.writerIndex(); + int writtenBytesDiff = computeLength(message) - (endWriterIndex - startWriterIndex); + LOGGER.debug("writtenbytes: " + writtenBytesDiff); + ByteBufUtils.padBuffer(writtenBytesDiff, out); + } + + @Override + public int computeLength(HelloInput message) { + int length = MESSAGE_LENGTH; + List elements = message.getElements(); + if (elements != null) { + for (Elements element : elements) { + if (HelloElementType.VERSIONBITMAP.equals(element.getType())) { + int bitmapLength = computeVersionBitmapLength(element); + int paddingRemainder = bitmapLength % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + bitmapLength += EncodeConstants.PADDING - paddingRemainder; + } + length += bitmapLength; + } + } + } + return length; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + private static void encodeElementsList(HelloInput message, ByteBuf output) { + int[] versionBitmap; + if (message.getElements() != null) { + for (Elements currElement : message.getElements()) { + output.writeShort(currElement.getType().getIntValue()); + if (currElement.getType().equals(HelloElementType.VERSIONBITMAP)) { + short bitmapLength = computeVersionBitmapLength(currElement); + output.writeShort(bitmapLength); + versionBitmap = ByteBufUtils.fillBitMaskFromList(currElement.getVersionBitmap()); + LOGGER.debug("vbs: " + versionBitmap.length); + LOGGER.debug("Version bitmap (below):"); + for (int i = 0; i < versionBitmap.length; i++) { + LOGGER.debug(Integer.toBinaryString(versionBitmap[i])); + output.writeInt(versionBitmap[i]); + } + int padding = bitmapLength - versionBitmap.length * 4 - HELLO_ELEMENT_HEADER_SIZE; + ByteBufUtils.padBuffer(padding , output); + } + } + } + } + + private static short computeVersionBitmapLength(Elements element) { + short elementlength = HELLO_ELEMENT_HEADER_SIZE; + if (!element.getVersionBitmap().isEmpty()) { + elementlength += ((element.getVersionBitmap().size() - 1) / Integer.SIZE + 1) * (EncodeConstants.SIZE_OF_INT_IN_BYTES); + } + return elementlength; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactory.java index 30c91ab2..71e318c7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MeterModInputMessageFactory.java @@ -1,110 +1,117 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterBandCommons; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.MeterBand; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDrop; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemark; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands; - -/** - * Translates MeterMod messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class MeterModInputMessageFactory implements OFSerializer { - private static final byte MESSAGE_TYPE = 29; - private static final int MESSAGE_LENGTH = 16; - private static final short LENGTH_OF_METER_BANDS = 16; - private static final short PADDING_IN_METER_BAND_DROP = 4; - private static final short PADDING_IN_METER_BAND_DSCP_REMARK = 3; - private static MeterModInputMessageFactory instance; - - private MeterModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized MeterModInputMessageFactory getInstance() { - if (instance == null) { - instance = new MeterModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - MeterModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getCommand().getIntValue()); - out.writeShort(createMeterFlagsBitmask(message.getFlags())); - out.writeInt(message.getMeterId().getValue().intValue()); - encodeBands(message.getBands(), out); - } - - @Override - public int computeLength(MeterModInput message) { - int length = MESSAGE_LENGTH; - if (message.getBands() != null) { - length += message.getBands().size() * LENGTH_OF_METER_BANDS; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static int createMeterFlagsBitmask(MeterFlags flags) { - int meterFlagBitmask = 0; - Map meterModFlagsMap = new HashMap<>(); - meterModFlagsMap.put(0, flags.isOFPMFKBPS()); - meterModFlagsMap.put(1, flags.isOFPMFPKTPS()); - meterModFlagsMap.put(2, flags.isOFPMFBURST()); - meterModFlagsMap.put(3, flags.isOFPMFSTATS()); - - meterFlagBitmask = ByteBufUtils.fillBitMaskFromMap(meterModFlagsMap); - return meterFlagBitmask; - } - - private static void encodeBands(List bands, ByteBuf outBuffer) { - if (bands != null) { - for (Bands currentBand : bands) { - MeterBand meterBand = currentBand.getMeterBand(); - writeBandCommonFields((MeterBandCommons) meterBand, outBuffer); - if (meterBand instanceof MeterBandDrop) { - ByteBufUtils.padBuffer(PADDING_IN_METER_BAND_DROP, outBuffer); - } else if (meterBand instanceof MeterBandDscpRemark) { - MeterBandDscpRemark dscpRemarkBand = (MeterBandDscpRemark) meterBand; - outBuffer.writeByte(dscpRemarkBand.getPrecLevel()); - ByteBufUtils.padBuffer(PADDING_IN_METER_BAND_DSCP_REMARK, outBuffer); - } else if (meterBand instanceof MeterBandExperimenter) { - MeterBandExperimenter experimenterBand = (MeterBandExperimenter) meterBand; - outBuffer.writeInt(experimenterBand.getExperimenter().intValue()); - } - } - } - } - - private static void writeBandCommonFields(MeterBandCommons meterBand, ByteBuf outBuffer) { - outBuffer.writeShort(meterBand.getType().getIntValue()); - outBuffer.writeShort(LENGTH_OF_METER_BANDS); - outBuffer.writeInt(meterBand.getRate().intValue()); - outBuffer.writeInt(meterBand.getBurstSize().intValue()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterBandCommons; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.MeterBand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDrop; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemark; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands; + +/** + * Translates MeterMod messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class MeterModInputMessageFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 29; + private static final int MESSAGE_LENGTH = 16; + private static final short LENGTH_OF_METER_BANDS = 16; + private static final short PADDING_IN_METER_BAND_DROP = 4; + private static final short PADDING_IN_METER_BAND_DSCP_REMARK = 3; + private static MeterModInputMessageFactory instance; + + private MeterModInputMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized MeterModInputMessageFactory getInstance() { + if (instance == null) { + instance = new MeterModInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + MeterModInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeShort(message.getCommand().getIntValue()); + out.writeShort(createMeterFlagsBitmask(message.getFlags())); + out.writeInt(message.getMeterId().getValue().intValue()); + encodeBands(message.getBands(), out); + } + + @Override + public int computeLength(MeterModInput message) { + int length = MESSAGE_LENGTH; + if (message.getBands() != null) { + length += message.getBands().size() * LENGTH_OF_METER_BANDS; + } + return length; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + private static int createMeterFlagsBitmask(MeterFlags flags) { + int meterFlagBitmask = 0; + Map meterModFlagsMap = new HashMap<>(); + meterModFlagsMap.put(0, flags.isOFPMFKBPS()); + meterModFlagsMap.put(1, flags.isOFPMFPKTPS()); + meterModFlagsMap.put(2, flags.isOFPMFBURST()); + meterModFlagsMap.put(3, flags.isOFPMFSTATS()); + + meterFlagBitmask = ByteBufUtils.fillBitMaskFromMap(meterModFlagsMap); + return meterFlagBitmask; + } + + private static void encodeBands(List bands, ByteBuf outBuffer) { + if (bands != null) { + for (Bands currentBand : bands) { + MeterBand meterBand = currentBand.getMeterBand(); + writeBandCommonFields((MeterBandCommons) meterBand, outBuffer); + if (meterBand instanceof MeterBandDrop) { + ByteBufUtils.padBuffer(PADDING_IN_METER_BAND_DROP, outBuffer); + } else if (meterBand instanceof MeterBandDscpRemark) { + MeterBandDscpRemark dscpRemarkBand = (MeterBandDscpRemark) meterBand; + outBuffer.writeByte(dscpRemarkBand.getPrecLevel()); + ByteBufUtils.padBuffer(PADDING_IN_METER_BAND_DSCP_REMARK, outBuffer); + } else if (meterBand instanceof MeterBandExperimenter) { + MeterBandExperimenter experimenterBand = (MeterBandExperimenter) meterBand; + outBuffer.writeInt(experimenterBand.getExperimenter().intValue()); + } + } + } + } + + private static void writeBandCommonFields(MeterBandCommons meterBand, ByteBuf outBuffer) { + outBuffer.writeShort(meterBand.getType().getIntValue()); + outBuffer.writeShort(LENGTH_OF_METER_BANDS); + outBuffer.writeInt(meterBand.getRate().intValue()); + outBuffer.writeInt(meterBand.getBurstSize().intValue()); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java index 5a17239b..d982f3f4 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactory.java @@ -1,515 +1,522 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeatureProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregate; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDesc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroup; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDesc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortDesc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStats; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features.TableFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeatureProperties; - -/** - * Translates MultipartRequest messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class MultipartRequestInputFactory implements OFSerializer { - private static final byte MESSAGE_TYPE = 18; - private static final int MESSAGE_LENGTH = 16; - private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4; - private static final byte TABLE_FEAT_HEADER_LENGTH = 4; - private static MultipartRequestInputFactory instance; - private static final byte INSTRUCTIONS_CODE = 0; - private static final byte INSTRUCTIONS_MISS_CODE = 1; - private static final byte NEXT_TABLE_CODE = 2; - private static final byte NEXT_TABLE_MISS_CODE = 3; - private static final byte WRITE_ACTIONS_CODE = 4; - private static final byte WRITE_ACTIONS_MISS_CODE = 5; - private static final byte APPLY_ACTIONS_CODE = 6; - private static final byte APPLY_ACTIONS_MISS_CODE = 7; - private static final byte MATCH_CODE = 8; - private static final byte WILDCARDS_CODE = 10; - private static final byte WRITE_SETFIELD_CODE = 12; - private static final byte WRITE_SETFIELD_MISS_CODE = 13; - private static final byte APPLY_SETFIELD_CODE = 14; - private static final byte APPLY_SETFIELD_MISS_CODE = 15; - private static final int EXPERIMENTER_CODE = 65534; // 0xFFFE - private static final int EXPERIMENTER_MISS_CODE = 65535; // 0xFFFF - private static final byte FLOW_BODY_LENGTH = 32; - private static final byte AGGREGATE_BODY_LENGTH = 32; - private static final byte PORT_STATS_BODY_LENGTH = 8; - private static final byte QUEUE_BODY_LENGTH = 8; - private static final byte GROUP_BODY_LENGTH = 8; - private static final byte METER_BODY_LENGTH = 8; - private static final byte METER_CONFIG_BODY_LENGTH = 8; - private static final byte EXPERIMENTER_BODY_LENGTH = 8; - private static final byte TABLE_FEATURES_LENGTH = 64; - private static final byte STRUCTURE_HEADER_LENGTH = 4; - private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3; - private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4; - private static final byte PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01 = 3; - private static final byte PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02 = 4; - private static final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4; - private static final byte PADDING_IN_MULTIPART_REQUEST_GROUP_BODY = 4; - private static final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4; - private static final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4; - private static final byte PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY = 5; - - - - private MultipartRequestInputFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized MultipartRequestInputFactory getInstance() { - if (instance == null) { - instance = new MultipartRequestInputFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - MultipartRequestInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getType().getIntValue()); - out.writeShort(createMultipartRequestFlagsBitmask(message.getFlags())); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_MESSAGE, out); - - if (message.getMultipartRequestBody() instanceof MultipartRequestDesc ){ - encodeDescBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestFlow) { - encodeFlowBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregate) { - encodeAggregateBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestTable) { - encodeTableBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStats) { - encodePortStatsBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestQueue) { - encodeQueueBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroup) { - encodeGroupStatsBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupDesc) { - encodeGroupDescBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupFeatures) { - encodeGroupFeaturesBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeter) { - encodeMeterBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterConfig) { - encodeMeterConfigBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterFeatures) { - encodeMeterFeaturesBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestTableFeatures) { - encodeTableFeaturesBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortDesc) { - encodePortDescBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenter) { - encodeExperimenterBody(message.getMultipartRequestBody(), out); - } - } - - @Override - public int computeLength(MultipartRequestInput message) { - return MESSAGE_LENGTH + computeBodyLength(message); - } - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - /** - * - * @param message - * @return length of MultipartRequestMessage - */ - public int computeBodyLength(MultipartRequestInput message) { - int length = 0; - MultipartType type = message.getType(); - if (type.equals(MultipartType.OFPMPFLOW)) { - MultipartRequestFlow body = (MultipartRequestFlow) message.getMultipartRequestBody(); - length += FLOW_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch()); - } else if (type.equals(MultipartType.OFPMPAGGREGATE)) { - MultipartRequestAggregate body = (MultipartRequestAggregate) message.getMultipartRequestBody(); - length += AGGREGATE_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch()); - } else if (type.equals(MultipartType.OFPMPPORTSTATS)) { - length += PORT_STATS_BODY_LENGTH; - } else if (type.equals(MultipartType.OFPMPQUEUE)) { - length += QUEUE_BODY_LENGTH; - } else if (type.equals(MultipartType.OFPMPGROUP)) { - length += GROUP_BODY_LENGTH; - } else if (type.equals(MultipartType.OFPMPMETER)) { - length += METER_BODY_LENGTH; - } else if (type.equals(MultipartType.OFPMPMETERCONFIG)) { - length += METER_CONFIG_BODY_LENGTH; - } else if (type.equals(MultipartType.OFPMPTABLEFEATURES)) { - MultipartRequestTableFeatures body = (MultipartRequestTableFeatures) message.getMultipartRequestBody(); - length += computeTableFeaturesLength(body); - } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) { - MultipartRequestExperimenter body = (MultipartRequestExperimenter) message.getMultipartRequestBody(); - length += EXPERIMENTER_BODY_LENGTH; - if (body.getData() != null) { - length += body.getData().length; - } - } - return length; - } - - private static int computeTableFeaturesLength(MultipartRequestTableFeatures body) { - int length = 0; - if (body != null && body.getTableFeatures() != null) { - List tableFeatures = body.getTableFeatures(); - for (TableFeatures feature : tableFeatures) { - length += TABLE_FEATURES_LENGTH; - List featureProperties = feature.getTableFeatureProperties(); - if (featureProperties != null) { - for (TableFeatureProperties featProp : featureProperties) { - length += TABLE_FEAT_HEADER_LENGTH; - if (featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class) != null) { - InstructionRelatedTableFeatureProperty property = - featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class); - length += property.getInstructions().size() * STRUCTURE_HEADER_LENGTH; - } else if (featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class) != null) { - NextTableRelatedTableFeatureProperty property = - featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class); - length += property.getNextTableIds().size(); - } else if (featProp.getAugmentation(ActionRelatedTableFeatureProperty.class) != null) { - ActionRelatedTableFeatureProperty property = - featProp.getAugmentation(ActionRelatedTableFeatureProperty.class); - length += property.getActionsList().size() * STRUCTURE_HEADER_LENGTH; - } else if (featProp.getAugmentation(OxmRelatedTableFeatureProperty.class) != null) { - OxmRelatedTableFeatureProperty property = - featProp.getAugmentation(OxmRelatedTableFeatureProperty.class); - length += property.getMatchEntries().size() * STRUCTURE_HEADER_LENGTH; - } else if (featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class) != null) { - ExperimenterRelatedTableFeatureProperty property = - featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class); - length += 2 * (EncodeConstants.SIZE_OF_INT_IN_BYTES); - if (property.getData() != null) { - length += property.getData().length; - } - } - } - } - } - } - return length; - } - - private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) { - int multipartRequestFlagsBitmask = 0; - Map multipartRequestFlagsMap = new HashMap<>(); - multipartRequestFlagsMap.put(0, flags.isOFPMPFREQMORE()); - - multipartRequestFlagsBitmask = ByteBufUtils.fillBitMaskFromMap(multipartRequestFlagsMap); - return multipartRequestFlagsBitmask; - } - - /** - * @param multipartRequestBody - * @param output - */ - private void encodeDescBody(MultipartRequestBody multipartRequestBody, - ByteBuf output) { - // The body of MultiPartRequestDesc is empty - } - - /** - * @param multipartRequestBody - * @param out - */ - private void encodeTableBody(MultipartRequestBody multipartRequestBody, - ByteBuf out) { - // The body of MultiPartTable is empty - } - - /** - * @param multipartRequestBody - * @param out - */ - private void encodeGroupDescBody(MultipartRequestBody multipartRequestBody, - ByteBuf out) { - // The body of MultiPartRequestGroupDesc is empty - } - - /** - * @param multipartRequestBody - * @param out - */ - private void encodeGroupFeaturesBody( - MultipartRequestBody multipartRequestBody, ByteBuf out) { - // The body of MultiPartRequestGroupFeatures is empty - } - - /** - * @param multipartRequestBody - * @param out - */ - private void encodeMeterFeaturesBody( - MultipartRequestBody multipartRequestBody, ByteBuf out) { - // The body of MultiPartMeterFeatures is empty - } - - /** - * @param multipartRequestBody - * @param out - */ - private void encodePortDescBody(MultipartRequestBody multipartRequestBody, - ByteBuf out) { - // The body of MultiPartPortDesc is empty - } - - private static void encodeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestFlow flow = (MultipartRequestFlow) multipartRequestBody; - output.writeByte(flow.getTableId().byteValue()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01, output); - output.writeInt(flow.getOutPort().intValue()); - output.writeInt(flow.getOutGroup().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02, output); - output.writeLong(flow.getCookie().longValue()); - output.writeLong(flow.getCookieMask().longValue()); - MatchSerializer.encodeMatch(flow.getMatch(), output); - } - - private static void encodeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestAggregate aggregate = (MultipartRequestAggregate) multipartRequestBody; - output.writeByte(aggregate.getTableId().byteValue()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01, output); - output.writeInt(aggregate.getOutPort().intValue()); - output.writeInt(aggregate.getOutGroup().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02, output); - output.writeLong(aggregate.getCookie().longValue()); - output.writeLong(aggregate.getCookieMask().longValue()); - MatchSerializer.encodeMatch(aggregate.getMatch(), output); - } - - private static void encodePortStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestPortStats portstats = (MultipartRequestPortStats) multipartRequestBody; - output.writeInt(portstats.getPortNo().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY, output); - } - - private static void encodeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestQueue queue = (MultipartRequestQueue) multipartRequestBody; - output.writeInt(queue.getPortNo().intValue()); - output.writeInt(queue.getQueueId().intValue()); - } - - private static void encodeGroupStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestGroup groupStats = (MultipartRequestGroup) multipartRequestBody; - output.writeInt(groupStats.getGroupId().getValue().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY, output); - } - - private static void encodeMeterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestMeter meter = (MultipartRequestMeter) multipartRequestBody; - output.writeInt(meter.getMeterId().getValue().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_BODY, output); - } - - private static void encodeMeterConfigBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestMeterConfig meterConfig = (MultipartRequestMeterConfig) multipartRequestBody; - output.writeInt(meterConfig.getMeterId().getValue().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY, output); - } - - private static void encodeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestExperimenter experimenter = (MultipartRequestExperimenter) multipartRequestBody; - output.writeInt(experimenter.getExperimenter().intValue()); - output.writeInt(experimenter.getExpType().intValue()); - byte[] data = experimenter.getData(); - if (data != null) { - output.writeBytes(data); - } - } - - private static void encodeTableFeaturesBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - if (multipartRequestBody != null) { - MultipartRequestTableFeatures tableFeatures = (MultipartRequestTableFeatures) multipartRequestBody; - if(tableFeatures.getTableFeatures() != null) { - for (TableFeatures currTableFeature : tableFeatures.getTableFeatures()) { - output.writeByte(currTableFeature.getTableId()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY, output); - output.writeBytes(currTableFeature.getName().getBytes()); - ByteBufUtils.padBuffer((32 - currTableFeature.getName().getBytes().length), output); - output.writeLong(currTableFeature.getMetadataMatch().longValue()); - output.writeLong(currTableFeature.getMetadataWrite().longValue()); - output.writeInt(createTableConfigBitmask(currTableFeature.getConfig())); - output.writeInt(currTableFeature.getMaxEntries().intValue()); - writeTableFeatureProperties(output, currTableFeature.getTableFeatureProperties()); - } - } - } - } - - private static void writeTableFeatureProperties(ByteBuf output, List props) { - if (props != null) { - for (TableFeatureProperties property : props) { - TableFeaturesPropType type = property.getType(); - if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS)) { - writeInstructionRelatedTableProperty(output, property, INSTRUCTIONS_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) { - writeInstructionRelatedTableProperty(output, property, INSTRUCTIONS_MISS_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES)) { - writeNextTableRelatedTableProperty(output, property, NEXT_TABLE_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS)) { - writeNextTableRelatedTableProperty(output, property, NEXT_TABLE_MISS_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONS)) { - writeActionsRelatedTableProperty(output, property, WRITE_ACTIONS_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS)) { - writeActionsRelatedTableProperty(output, property, WRITE_ACTIONS_MISS_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONS)) { - writeActionsRelatedTableProperty(output, property, APPLY_ACTIONS_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS)) { - writeActionsRelatedTableProperty(output, property, APPLY_ACTIONS_MISS_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH)) { - writeOxmRelatedTableProperty(output, property, MATCH_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTWILDCARDS)) { - writeOxmRelatedTableProperty(output, property, WILDCARDS_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELD)) { - writeOxmRelatedTableProperty(output, property, WRITE_SETFIELD_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS)) { - writeOxmRelatedTableProperty(output, property, WRITE_SETFIELD_MISS_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD)) { - writeOxmRelatedTableProperty(output, property, APPLY_SETFIELD_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) { - writeOxmRelatedTableProperty(output, property, APPLY_SETFIELD_MISS_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)) { - writeExperimenterRelatedTableProperty(output, property, EXPERIMENTER_CODE); - } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) { - writeExperimenterRelatedTableProperty(output, property, EXPERIMENTER_MISS_CODE); - } - } - } - } - - private static void writeInstructionRelatedTableProperty(ByteBuf output, - TableFeatureProperties property, byte code) { - output.writeShort(code); - List instructions = property. - getAugmentation(InstructionRelatedTableFeatureProperty.class).getInstructions(); - int length = TABLE_FEAT_HEADER_LENGTH; - if (instructions != null) { - output.writeShort(InstructionsSerializer.computeInstructionsLength(instructions) - + TABLE_FEAT_HEADER_LENGTH); - InstructionsSerializer.encodeInstructions(instructions, output); - } else { - output.writeShort(length); - } - } - - private static void writeNextTableRelatedTableProperty(ByteBuf output, - TableFeatureProperties property, byte code) { - output.writeShort(code); - List nextTableIds = property. - getAugmentation(NextTableRelatedTableFeatureProperty.class).getNextTableIds(); - int length = TABLE_FEAT_HEADER_LENGTH; - if (nextTableIds != null) { - output.writeShort(length + nextTableIds.size()); - for (NextTableIds next : nextTableIds) { - output.writeByte(next.getTableId()); - } - } else { - output.writeShort(length); - } - } - - private static void writeActionsRelatedTableProperty(ByteBuf output, - TableFeatureProperties property, byte code) { - output.writeShort(code); - List actions = property. - getAugmentation(ActionRelatedTableFeatureProperty.class).getActionsList(); - int length = TABLE_FEAT_HEADER_LENGTH; - if (actions != null) { - output.writeShort(ActionsSerializer.computeLengthOfActions(actions) - + TABLE_FEAT_HEADER_LENGTH); - ActionsSerializer.encodeActions(actions, output); - } else { - output.writeShort(length); - } - } - - private static void writeOxmRelatedTableProperty(ByteBuf output, - TableFeatureProperties property, byte code) { - output.writeShort(code); - List entries = property. - getAugmentation(OxmRelatedTableFeatureProperty.class).getMatchEntries(); - int length = TABLE_FEAT_HEADER_LENGTH; - if (entries != null) { - output.writeShort(MatchSerializer.computeMatchEntriesLength(entries) - + TABLE_FEAT_HEADER_LENGTH); - MatchSerializer.encodeMatchEntries(entries, output); - } else { - output.writeShort(length); - } - } - - private static void writeExperimenterRelatedTableProperty(ByteBuf output, - TableFeatureProperties property, int code) { - output.writeShort(code); - ExperimenterRelatedTableFeatureProperty exp = property. - getAugmentation(ExperimenterRelatedTableFeatureProperty.class); - byte[] data = exp.getData(); - int length = TABLE_FEAT_HEADER_LENGTH + 2 * (EncodeConstants.SIZE_OF_INT_IN_BYTES); - if (data != null) { - output.writeShort(length + data.length); - output.writeInt(exp.getExperimenter().intValue()); - output.writeInt(exp.getExpType().intValue()); - output.writeBytes(data); - } else { - output.writeShort(length); - output.writeInt(exp.getExperimenter().intValue()); - output.writeInt(exp.getExpType().intValue()); - } - } - - private static int createTableConfigBitmask(TableConfig tableConfig) { - int tableConfigBitmask = 0; - Map tableConfigMap = new HashMap<>(); - tableConfigMap.put(3, tableConfig.isOFPTCDEPRECATEDMASK()); - - tableConfigBitmask = ByteBufUtils.fillBitMaskFromMap(tableConfigMap); - return tableConfigBitmask; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features.TableFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeatureProperties; + +/** + * Translates MultipartRequest messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class MultipartRequestInputFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 18; + private static final int MESSAGE_LENGTH = 16; + private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4; + private static final byte TABLE_FEAT_HEADER_LENGTH = 4; + private static MultipartRequestInputFactory instance; + private static final byte INSTRUCTIONS_CODE = 0; + private static final byte INSTRUCTIONS_MISS_CODE = 1; + private static final byte NEXT_TABLE_CODE = 2; + private static final byte NEXT_TABLE_MISS_CODE = 3; + private static final byte WRITE_ACTIONS_CODE = 4; + private static final byte WRITE_ACTIONS_MISS_CODE = 5; + private static final byte APPLY_ACTIONS_CODE = 6; + private static final byte APPLY_ACTIONS_MISS_CODE = 7; + private static final byte MATCH_CODE = 8; + private static final byte WILDCARDS_CODE = 10; + private static final byte WRITE_SETFIELD_CODE = 12; + private static final byte WRITE_SETFIELD_MISS_CODE = 13; + private static final byte APPLY_SETFIELD_CODE = 14; + private static final byte APPLY_SETFIELD_MISS_CODE = 15; + private static final int EXPERIMENTER_CODE = 65534; // 0xFFFE + private static final int EXPERIMENTER_MISS_CODE = 65535; // 0xFFFF + private static final byte FLOW_BODY_LENGTH = 32; + private static final byte AGGREGATE_BODY_LENGTH = 32; + private static final byte PORT_STATS_BODY_LENGTH = 8; + private static final byte QUEUE_BODY_LENGTH = 8; + private static final byte GROUP_BODY_LENGTH = 8; + private static final byte METER_BODY_LENGTH = 8; + private static final byte METER_CONFIG_BODY_LENGTH = 8; + private static final byte EXPERIMENTER_BODY_LENGTH = 8; + private static final byte TABLE_FEATURES_LENGTH = 64; + private static final byte STRUCTURE_HEADER_LENGTH = 4; + private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3; + private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4; + private static final byte PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01 = 3; + private static final byte PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02 = 4; + private static final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4; + private static final byte PADDING_IN_MULTIPART_REQUEST_GROUP_BODY = 4; + private static final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4; + private static final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4; + private static final byte PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY = 5; + + + + private MultipartRequestInputFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized MultipartRequestInputFactory getInstance() { + if (instance == null) { + instance = new MultipartRequestInputFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + MultipartRequestInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeShort(message.getType().getIntValue()); + out.writeShort(createMultipartRequestFlagsBitmask(message.getFlags())); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_MESSAGE, out); + + if (message.getMultipartRequestBody() instanceof MultipartRequestDesc ){ + encodeDescBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestFlow) { + encodeFlowBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregate) { + encodeAggregateBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestTable) { + encodeTableBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStats) { + encodePortStatsBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestQueue) { + encodeQueueBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroup) { + encodeGroupStatsBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupDesc) { + encodeGroupDescBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupFeatures) { + encodeGroupFeaturesBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeter) { + encodeMeterBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterConfig) { + encodeMeterConfigBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterFeatures) { + encodeMeterFeaturesBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestTableFeatures) { + encodeTableFeaturesBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortDesc) { + encodePortDescBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenter) { + encodeExperimenterBody(message.getMultipartRequestBody(), out); + } + } + + @Override + public int computeLength(MultipartRequestInput message) { + return MESSAGE_LENGTH + computeBodyLength(message); + } + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + /** + * + * @param message + * @return length of MultipartRequestMessage + */ + public int computeBodyLength(MultipartRequestInput message) { + int length = 0; + MultipartType type = message.getType(); + if (type.equals(MultipartType.OFPMPFLOW)) { + MultipartRequestFlow body = (MultipartRequestFlow) message.getMultipartRequestBody(); + length += FLOW_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch()); + } else if (type.equals(MultipartType.OFPMPAGGREGATE)) { + MultipartRequestAggregate body = (MultipartRequestAggregate) message.getMultipartRequestBody(); + length += AGGREGATE_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch()); + } else if (type.equals(MultipartType.OFPMPPORTSTATS)) { + length += PORT_STATS_BODY_LENGTH; + } else if (type.equals(MultipartType.OFPMPQUEUE)) { + length += QUEUE_BODY_LENGTH; + } else if (type.equals(MultipartType.OFPMPGROUP)) { + length += GROUP_BODY_LENGTH; + } else if (type.equals(MultipartType.OFPMPMETER)) { + length += METER_BODY_LENGTH; + } else if (type.equals(MultipartType.OFPMPMETERCONFIG)) { + length += METER_CONFIG_BODY_LENGTH; + } else if (type.equals(MultipartType.OFPMPTABLEFEATURES)) { + MultipartRequestTableFeatures body = (MultipartRequestTableFeatures) message.getMultipartRequestBody(); + length += computeTableFeaturesLength(body); + } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) { + MultipartRequestExperimenter body = (MultipartRequestExperimenter) message.getMultipartRequestBody(); + length += EXPERIMENTER_BODY_LENGTH; + if (body.getData() != null) { + length += body.getData().length; + } + } + return length; + } + + private static int computeTableFeaturesLength(MultipartRequestTableFeatures body) { + int length = 0; + if (body != null && body.getTableFeatures() != null) { + List tableFeatures = body.getTableFeatures(); + for (TableFeatures feature : tableFeatures) { + length += TABLE_FEATURES_LENGTH; + List featureProperties = feature.getTableFeatureProperties(); + if (featureProperties != null) { + for (TableFeatureProperties featProp : featureProperties) { + length += TABLE_FEAT_HEADER_LENGTH; + if (featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class) != null) { + InstructionRelatedTableFeatureProperty property = + featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class); + length += property.getInstructions().size() * STRUCTURE_HEADER_LENGTH; + } else if (featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class) != null) { + NextTableRelatedTableFeatureProperty property = + featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class); + length += property.getNextTableIds().size(); + } else if (featProp.getAugmentation(ActionRelatedTableFeatureProperty.class) != null) { + ActionRelatedTableFeatureProperty property = + featProp.getAugmentation(ActionRelatedTableFeatureProperty.class); + length += property.getActionsList().size() * STRUCTURE_HEADER_LENGTH; + } else if (featProp.getAugmentation(OxmRelatedTableFeatureProperty.class) != null) { + OxmRelatedTableFeatureProperty property = + featProp.getAugmentation(OxmRelatedTableFeatureProperty.class); + length += property.getMatchEntries().size() * STRUCTURE_HEADER_LENGTH; + } else if (featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class) != null) { + ExperimenterRelatedTableFeatureProperty property = + featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class); + length += 2 * (EncodeConstants.SIZE_OF_INT_IN_BYTES); + if (property.getData() != null) { + length += property.getData().length; + } + } + } + } + } + } + return length; + } + + private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) { + int multipartRequestFlagsBitmask = 0; + Map multipartRequestFlagsMap = new HashMap<>(); + multipartRequestFlagsMap.put(0, flags.isOFPMPFREQMORE()); + + multipartRequestFlagsBitmask = ByteBufUtils.fillBitMaskFromMap(multipartRequestFlagsMap); + return multipartRequestFlagsBitmask; + } + + /** + * @param multipartRequestBody + * @param output + */ + private void encodeDescBody(MultipartRequestBody multipartRequestBody, + ByteBuf output) { + // The body of MultiPartRequestDesc is empty + } + + /** + * @param multipartRequestBody + * @param out + */ + private void encodeTableBody(MultipartRequestBody multipartRequestBody, + ByteBuf out) { + // The body of MultiPartTable is empty + } + + /** + * @param multipartRequestBody + * @param out + */ + private void encodeGroupDescBody(MultipartRequestBody multipartRequestBody, + ByteBuf out) { + // The body of MultiPartRequestGroupDesc is empty + } + + /** + * @param multipartRequestBody + * @param out + */ + private void encodeGroupFeaturesBody( + MultipartRequestBody multipartRequestBody, ByteBuf out) { + // The body of MultiPartRequestGroupFeatures is empty + } + + /** + * @param multipartRequestBody + * @param out + */ + private void encodeMeterFeaturesBody( + MultipartRequestBody multipartRequestBody, ByteBuf out) { + // The body of MultiPartMeterFeatures is empty + } + + /** + * @param multipartRequestBody + * @param out + */ + private void encodePortDescBody(MultipartRequestBody multipartRequestBody, + ByteBuf out) { + // The body of MultiPartPortDesc is empty + } + + private static void encodeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestFlow flow = (MultipartRequestFlow) multipartRequestBody; + output.writeByte(flow.getTableId().byteValue()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01, output); + output.writeInt(flow.getOutPort().intValue()); + output.writeInt(flow.getOutGroup().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02, output); + output.writeLong(flow.getCookie().longValue()); + output.writeLong(flow.getCookieMask().longValue()); + MatchSerializer.encodeMatch(flow.getMatch(), output); + } + + private static void encodeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestAggregate aggregate = (MultipartRequestAggregate) multipartRequestBody; + output.writeByte(aggregate.getTableId().byteValue()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_01, output); + output.writeInt(aggregate.getOutPort().intValue()); + output.writeInt(aggregate.getOutGroup().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGREGGATE_BODY_02, output); + output.writeLong(aggregate.getCookie().longValue()); + output.writeLong(aggregate.getCookieMask().longValue()); + MatchSerializer.encodeMatch(aggregate.getMatch(), output); + } + + private static void encodePortStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestPortStats portstats = (MultipartRequestPortStats) multipartRequestBody; + output.writeInt(portstats.getPortNo().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY, output); + } + + private static void encodeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestQueue queue = (MultipartRequestQueue) multipartRequestBody; + output.writeInt(queue.getPortNo().intValue()); + output.writeInt(queue.getQueueId().intValue()); + } + + private static void encodeGroupStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestGroup groupStats = (MultipartRequestGroup) multipartRequestBody; + output.writeInt(groupStats.getGroupId().getValue().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY, output); + } + + private static void encodeMeterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestMeter meter = (MultipartRequestMeter) multipartRequestBody; + output.writeInt(meter.getMeterId().getValue().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_BODY, output); + } + + private static void encodeMeterConfigBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestMeterConfig meterConfig = (MultipartRequestMeterConfig) multipartRequestBody; + output.writeInt(meterConfig.getMeterId().getValue().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY, output); + } + + private static void encodeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestExperimenter experimenter = (MultipartRequestExperimenter) multipartRequestBody; + output.writeInt(experimenter.getExperimenter().intValue()); + output.writeInt(experimenter.getExpType().intValue()); + byte[] data = experimenter.getData(); + if (data != null) { + output.writeBytes(data); + } + } + + private static void encodeTableFeaturesBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + if (multipartRequestBody != null) { + MultipartRequestTableFeatures tableFeatures = (MultipartRequestTableFeatures) multipartRequestBody; + if(tableFeatures.getTableFeatures() != null) { + for (TableFeatures currTableFeature : tableFeatures.getTableFeatures()) { + output.writeByte(currTableFeature.getTableId()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY, output); + output.writeBytes(currTableFeature.getName().getBytes()); + ByteBufUtils.padBuffer((32 - currTableFeature.getName().getBytes().length), output); + output.writeLong(currTableFeature.getMetadataMatch().longValue()); + output.writeLong(currTableFeature.getMetadataWrite().longValue()); + output.writeInt(createTableConfigBitmask(currTableFeature.getConfig())); + output.writeInt(currTableFeature.getMaxEntries().intValue()); + writeTableFeatureProperties(output, currTableFeature.getTableFeatureProperties()); + } + } + } + } + + private static void writeTableFeatureProperties(ByteBuf output, List props) { + if (props != null) { + for (TableFeatureProperties property : props) { + TableFeaturesPropType type = property.getType(); + if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS)) { + writeInstructionRelatedTableProperty(output, property, INSTRUCTIONS_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) { + writeInstructionRelatedTableProperty(output, property, INSTRUCTIONS_MISS_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES)) { + writeNextTableRelatedTableProperty(output, property, NEXT_TABLE_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS)) { + writeNextTableRelatedTableProperty(output, property, NEXT_TABLE_MISS_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONS)) { + writeActionsRelatedTableProperty(output, property, WRITE_ACTIONS_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS)) { + writeActionsRelatedTableProperty(output, property, WRITE_ACTIONS_MISS_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONS)) { + writeActionsRelatedTableProperty(output, property, APPLY_ACTIONS_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS)) { + writeActionsRelatedTableProperty(output, property, APPLY_ACTIONS_MISS_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH)) { + writeOxmRelatedTableProperty(output, property, MATCH_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTWILDCARDS)) { + writeOxmRelatedTableProperty(output, property, WILDCARDS_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELD)) { + writeOxmRelatedTableProperty(output, property, WRITE_SETFIELD_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS)) { + writeOxmRelatedTableProperty(output, property, WRITE_SETFIELD_MISS_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD)) { + writeOxmRelatedTableProperty(output, property, APPLY_SETFIELD_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) { + writeOxmRelatedTableProperty(output, property, APPLY_SETFIELD_MISS_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)) { + writeExperimenterRelatedTableProperty(output, property, EXPERIMENTER_CODE); + } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) { + writeExperimenterRelatedTableProperty(output, property, EXPERIMENTER_MISS_CODE); + } + } + } + } + + private static void writeInstructionRelatedTableProperty(ByteBuf output, + TableFeatureProperties property, byte code) { + output.writeShort(code); + List instructions = property. + getAugmentation(InstructionRelatedTableFeatureProperty.class).getInstructions(); + int length = TABLE_FEAT_HEADER_LENGTH; + if (instructions != null) { + output.writeShort(InstructionsSerializer.computeInstructionsLength(instructions) + + TABLE_FEAT_HEADER_LENGTH); + InstructionsSerializer.encodeInstructions(instructions, output); + } else { + output.writeShort(length); + } + } + + private static void writeNextTableRelatedTableProperty(ByteBuf output, + TableFeatureProperties property, byte code) { + output.writeShort(code); + List nextTableIds = property. + getAugmentation(NextTableRelatedTableFeatureProperty.class).getNextTableIds(); + int length = TABLE_FEAT_HEADER_LENGTH; + if (nextTableIds != null) { + output.writeShort(length + nextTableIds.size()); + for (NextTableIds next : nextTableIds) { + output.writeByte(next.getTableId()); + } + } else { + output.writeShort(length); + } + } + + private static void writeActionsRelatedTableProperty(ByteBuf output, + TableFeatureProperties property, byte code) { + output.writeShort(code); + List actions = property. + getAugmentation(ActionRelatedTableFeatureProperty.class).getActionsList(); + int length = TABLE_FEAT_HEADER_LENGTH; + if (actions != null) { + output.writeShort(ActionsSerializer.computeLengthOfActions(actions) + + TABLE_FEAT_HEADER_LENGTH); + ActionsSerializer.encodeActions(actions, output); + } else { + output.writeShort(length); + } + } + + private static void writeOxmRelatedTableProperty(ByteBuf output, + TableFeatureProperties property, byte code) { + output.writeShort(code); + List entries = property. + getAugmentation(OxmRelatedTableFeatureProperty.class).getMatchEntries(); + int length = TABLE_FEAT_HEADER_LENGTH; + if (entries != null) { + output.writeShort(MatchSerializer.computeMatchEntriesLength(entries) + + TABLE_FEAT_HEADER_LENGTH); + MatchSerializer.encodeMatchEntries(entries, output); + } else { + output.writeShort(length); + } + } + + private static void writeExperimenterRelatedTableProperty(ByteBuf output, + TableFeatureProperties property, int code) { + output.writeShort(code); + ExperimenterRelatedTableFeatureProperty exp = property. + getAugmentation(ExperimenterRelatedTableFeatureProperty.class); + byte[] data = exp.getData(); + int length = TABLE_FEAT_HEADER_LENGTH + 2 * (EncodeConstants.SIZE_OF_INT_IN_BYTES); + if (data != null) { + output.writeShort(length + data.length); + output.writeInt(exp.getExperimenter().intValue()); + output.writeInt(exp.getExpType().intValue()); + output.writeBytes(data); + } else { + output.writeShort(length); + output.writeInt(exp.getExperimenter().intValue()); + output.writeInt(exp.getExpType().intValue()); + } + } + + private static int createTableConfigBitmask(TableConfig tableConfig) { + int tableConfigBitmask = 0; + Map tableConfigMap = new HashMap<>(); + tableConfigMap.put(3, tableConfig.isOFPTCDEPRECATEDMASK()); + + tableConfigBitmask = ByteBufUtils.fillBitMaskFromMap(tableConfigMap); + return tableConfigBitmask; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactory.java index aaac8561..e37adc61 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactory.java @@ -1,49 +1,56 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; - -/** - * Translates BarrierRequest messages - * @author michal.polkorab - */ -public class OF10BarrierInputMessageFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 18; - private static final int MESSAGE_LENGTH = 8; - - private static OF10BarrierInputMessageFactory instance; - - private OF10BarrierInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10BarrierInputMessageFactory getInstance() { - if (instance == null) { - instance = new OF10BarrierInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, BarrierInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - } - - @Override - public int computeLength(BarrierInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; + +/** + * Translates BarrierRequest messages + * @author michal.polkorab + */ +public class OF10BarrierInputMessageFactory implements OFSerializer { + + private static final byte MESSAGE_TYPE = 18; + private static final int MESSAGE_LENGTH = 8; + + private static OF10BarrierInputMessageFactory instance; + + private OF10BarrierInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10BarrierInputMessageFactory getInstance() { + if (instance == null) { + instance = new OF10BarrierInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, BarrierInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + } + + @Override + public int computeLength(BarrierInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java index 7821cd49..e4c1d583 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java @@ -1,75 +1,82 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.HashMap; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; - -/** - * Translates FlowMod messages - * @author michal.polkorab - */ -public class OF10FlowModInputMessageFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 14; - private static final int MESSAGE_LENGTH = 72; - - private static OF10FlowModInputMessageFactory instance; - - private OF10FlowModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10FlowModInputMessageFactory getInstance() { - if(instance == null) { - instance = new OF10FlowModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, FlowModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - OF10MatchSerializer.encodeMatchV10(out, message.getMatchV10()); - out.writeLong(message.getCookie().longValue()); - out.writeShort(message.getCommand().getIntValue()); - out.writeShort(message.getIdleTimeout().intValue()); - out.writeShort(message.getHardTimeout().intValue()); - out.writeShort(message.getPriority()); - out.writeInt(message.getBufferId().intValue()); - out.writeShort(message.getOutPort().getValue().intValue()); - out.writeShort(createFlowModFlagsBitmask(message.getFlagsV10())); - OF10ActionsSerializer.encodeActionsV10(out, message.getActionsList()); - } - - @Override - public int computeLength(FlowModInput message) { - return MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getActionsList()); - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static int createFlowModFlagsBitmask(FlowModFlagsV10 flags) { - int flowModFlagBitmask = 0; - Map flowModFlagsMap = new HashMap<>(); - flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM()); - flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP()); - flowModFlagsMap.put(2, flags.isOFPFFEMERG()); - flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap); - return flowModFlagBitmask; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; + +/** + * Translates FlowMod messages + * @author michal.polkorab + */ +public class OF10FlowModInputMessageFactory implements OFSerializer { + + private static final byte MESSAGE_TYPE = 14; + private static final int MESSAGE_LENGTH = 72; + + private static OF10FlowModInputMessageFactory instance; + + private OF10FlowModInputMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10FlowModInputMessageFactory getInstance() { + if(instance == null) { + instance = new OF10FlowModInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, FlowModInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + OF10MatchSerializer.encodeMatchV10(out, message.getMatchV10()); + out.writeLong(message.getCookie().longValue()); + out.writeShort(message.getCommand().getIntValue()); + out.writeShort(message.getIdleTimeout().intValue()); + out.writeShort(message.getHardTimeout().intValue()); + out.writeShort(message.getPriority()); + out.writeInt(message.getBufferId().intValue()); + out.writeShort(message.getOutPort().getValue().intValue()); + out.writeShort(createFlowModFlagsBitmask(message.getFlagsV10())); + OF10ActionsSerializer.encodeActionsV10(out, message.getActionsList()); + } + + @Override + public int computeLength(FlowModInput message) { + return MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getActionsList()); + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + private static int createFlowModFlagsBitmask(FlowModFlagsV10 flags) { + int flowModFlagBitmask = 0; + Map flowModFlagsMap = new HashMap<>(); + flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM()); + flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP()); + flowModFlagsMap.put(2, flags.isOFPFFEMERG()); + flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap); + return flowModFlagBitmask; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactory.java index 8ca94696..68f1a2d4 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactory.java @@ -1,48 +1,55 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; - -/** - * Translates Hello messages - * @author michal.polkorab - */ -public class OF10HelloInputMessageFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 0; - private static int MESSAGE_LENGTH = 8; - private static OF10HelloInputMessageFactory instance; - - private OF10HelloInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10HelloInputMessageFactory getInstance() { - if (instance == null) { - instance = new OF10HelloInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, HelloInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - } - - @Override - public int computeLength(HelloInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; + +/** + * Translates Hello messages + * @author michal.polkorab + */ +public class OF10HelloInputMessageFactory implements OFSerializer { + + private static final byte MESSAGE_TYPE = 0; + private static int MESSAGE_LENGTH = 8; + private static OF10HelloInputMessageFactory instance; + + private OF10HelloInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10HelloInputMessageFactory getInstance() { + if (instance == null) { + instance = new OF10HelloInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, HelloInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + } + + @Override + public int computeLength(HelloInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactory.java index d397f8a9..cf35ffff 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactory.java @@ -1,65 +1,72 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; - -/** - * Translates PacketOut messages - * @author michal.polkorab - */ -public class OF10PacketOutInputMessageFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 13; - private static final int MESSAGE_LENGTH = 16; - - private static OF10PacketOutInputMessageFactory instance; - - private OF10PacketOutInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10PacketOutInputMessageFactory getInstance() { - if (instance == null) { - instance = new OF10PacketOutInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - PacketOutInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getBufferId().intValue()); - out.writeShort(message.getInPort().getValue().intValue()); - out.writeShort(OF10ActionsSerializer.computeActionsLength(message.getActionsList())); - OF10ActionsSerializer.encodeActionsV10(out, message.getActionsList()); - byte[] data = message.getData(); - if (data != null) { - out.writeBytes(data); - } - } - - @Override - public int computeLength(PacketOutInput message) { - int length = MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getActionsList()); - byte[] data = message.getData(); - if (data != null) { - length += data.length; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; + +/** + * Translates PacketOut messages + * @author michal.polkorab + */ +public class OF10PacketOutInputMessageFactory implements OFSerializer { + + private static final byte MESSAGE_TYPE = 13; + private static final int MESSAGE_LENGTH = 16; + + private static OF10PacketOutInputMessageFactory instance; + + private OF10PacketOutInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10PacketOutInputMessageFactory getInstance() { + if (instance == null) { + instance = new OF10PacketOutInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + PacketOutInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeInt(message.getBufferId().intValue()); + out.writeShort(message.getInPort().getValue().intValue()); + out.writeShort(OF10ActionsSerializer.computeActionsLength(message.getActionsList())); + OF10ActionsSerializer.encodeActionsV10(out, message.getActionsList()); + byte[] data = message.getData(); + if (data != null) { + out.writeBytes(data); + } + } + + @Override + public int computeLength(PacketOutInput message) { + int length = MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getActionsList()); + byte[] data = message.getData(); + if (data != null) { + length += data.length; + } + return length; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java index ef53543c..6cb8606b 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java @@ -1,100 +1,107 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.HashMap; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; - -/** - * Translates PortMod messages - * @author michal.polkorab - */ -public class OF10PortModInputMessageFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 15; - private static final byte PADDING_IN_PORT_MOD_MESSAGE = 4; - private static final int MESSAGE_LENGTH = 32; - - private static OF10PortModInputMessageFactory instance; - - private OF10PortModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10PortModInputMessageFactory getInstance() { - if (instance == null) { - instance = new OF10PortModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, PortModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getPortNo().getValue().intValue()); - out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue())); - out.writeInt(createPortConfigBitmask(message.getConfigV10())); - out.writeInt(createPortConfigBitmask(message.getMaskV10())); - out.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10())); - ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE, out); - } - - @Override - public int computeLength(PortModInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - - /** - * @param config - * @return port config bitmask - */ - private static int createPortConfigBitmask(PortConfigV10 config) { - int configBitmask = 0; - Map portConfigMap = new HashMap<>(); - portConfigMap.put(0, config.isPortDown()); - portConfigMap.put(1, config.isNoStp()); - portConfigMap.put(2, config.isNoRecv()); - portConfigMap.put(3, config.isNoRecvStp()); - portConfigMap.put(4, config.isNoFlood()); - portConfigMap.put(5, config.isNoFwd()); - portConfigMap.put(6, config.isNoPacketIn()); - - configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap); - return configBitmask; - } - - private static int createPortFeaturesBitmask(PortFeaturesV10 feature) { - int configBitmask = 0; - Map portFeaturesMap = new HashMap<>(); - portFeaturesMap.put(0, feature.is_10mbHd()); - portFeaturesMap.put(1, feature.is_10mbFd()); - portFeaturesMap.put(2, feature.is_100mbHd()); - portFeaturesMap.put(3, feature.is_100mbFd()); - portFeaturesMap.put(4, feature.is_1gbHd()); - portFeaturesMap.put(5, feature.is_1gbFd()); - portFeaturesMap.put(6, feature.is_10gbFd()); - portFeaturesMap.put(7, feature.isCopper()); - portFeaturesMap.put(8, feature.isFiber()); - portFeaturesMap.put(9, feature.isAutoneg()); - portFeaturesMap.put(10, feature.isPause()); - portFeaturesMap.put(11, feature.isPauseAsym()); - configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap); - return configBitmask; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; + +/** + * Translates PortMod messages + * @author michal.polkorab + */ +public class OF10PortModInputMessageFactory implements OFSerializer { + + private static final byte MESSAGE_TYPE = 15; + private static final byte PADDING_IN_PORT_MOD_MESSAGE = 4; + private static final int MESSAGE_LENGTH = 32; + + private static OF10PortModInputMessageFactory instance; + + private OF10PortModInputMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10PortModInputMessageFactory getInstance() { + if (instance == null) { + instance = new OF10PortModInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, PortModInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeShort(message.getPortNo().getValue().intValue()); + out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue())); + out.writeInt(createPortConfigBitmask(message.getConfigV10())); + out.writeInt(createPortConfigBitmask(message.getMaskV10())); + out.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10())); + ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE, out); + } + + @Override + public int computeLength(PortModInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + + /** + * @param config + * @return port config bitmask + */ + private static int createPortConfigBitmask(PortConfigV10 config) { + int configBitmask = 0; + Map portConfigMap = new HashMap<>(); + portConfigMap.put(0, config.isPortDown()); + portConfigMap.put(1, config.isNoStp()); + portConfigMap.put(2, config.isNoRecv()); + portConfigMap.put(3, config.isNoRecvStp()); + portConfigMap.put(4, config.isNoFlood()); + portConfigMap.put(5, config.isNoFwd()); + portConfigMap.put(6, config.isNoPacketIn()); + + configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap); + return configBitmask; + } + + private static int createPortFeaturesBitmask(PortFeaturesV10 feature) { + int configBitmask = 0; + Map portFeaturesMap = new HashMap<>(); + portFeaturesMap.put(0, feature.is_10mbHd()); + portFeaturesMap.put(1, feature.is_10mbFd()); + portFeaturesMap.put(2, feature.is_100mbHd()); + portFeaturesMap.put(3, feature.is_100mbFd()); + portFeaturesMap.put(4, feature.is_1gbHd()); + portFeaturesMap.put(5, feature.is_1gbFd()); + portFeaturesMap.put(6, feature.is_10gbFd()); + portFeaturesMap.put(7, feature.isCopper()); + portFeaturesMap.put(8, feature.isFiber()); + portFeaturesMap.put(9, feature.isAutoneg()); + portFeaturesMap.put(10, feature.isPause()); + portFeaturesMap.put(11, feature.isPauseAsym()); + configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap); + return configBitmask; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactory.java index 5b83e7d8..462cbabf 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactory.java @@ -1,53 +1,60 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput; - -/** - * Translates QueueGetConfigRequest messages - * @author michal.polkorab - */ -public class OF10QueueGetConfigInputMessageFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 20; - private static final byte PADDING_IN_GET_QUEUE_CONFIG_MESSAGE = 2; - private static final int MESSAGE_LENGTH = 12; - - private static OF10QueueGetConfigInputMessageFactory instance; - - private OF10QueueGetConfigInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10QueueGetConfigInputMessageFactory getInstance(){ - if(instance == null){ - instance = new OF10QueueGetConfigInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, GetQueueConfigInput message){ - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getPort().getValue().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_GET_QUEUE_CONFIG_MESSAGE, out); - } - - @Override - public int computeLength(GetQueueConfigInput message){ - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput; + +/** + * Translates QueueGetConfigRequest messages + * @author michal.polkorab + */ +public class OF10QueueGetConfigInputMessageFactory implements OFSerializer { + + private static final byte MESSAGE_TYPE = 20; + private static final byte PADDING_IN_GET_QUEUE_CONFIG_MESSAGE = 2; + private static final int MESSAGE_LENGTH = 12; + + private static OF10QueueGetConfigInputMessageFactory instance; + + private OF10QueueGetConfigInputMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10QueueGetConfigInputMessageFactory getInstance(){ + if(instance == null){ + instance = new OF10QueueGetConfigInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, GetQueueConfigInput message){ + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeShort(message.getPort().getValue().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_GET_QUEUE_CONFIG_MESSAGE, out); + } + + @Override + public int computeLength(GetQueueConfigInput message){ + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactory.java index b0f81d66..85539b5d 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10StatsRequestInputFactory.java @@ -1,177 +1,184 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.HashMap; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregate; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDesc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStats; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTable; - -/** - * Translates StatsRequest messages - * @author michal.polkorab - */ -public class OF10StatsRequestInputFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 16; - private static final int MESSAGE_LENGTH = 12; - private static final byte FLOW_BODY_LENGTH = 44; - private static final byte AGGREGATE_BODY_LENGTH = 44; - private static final byte PORT_STATS_BODY_LENGTH = 8; - private static final byte QUEUE_BODY_LENGTH = 8; - private static final byte EXPERIMENTER_BODY_LENGTH = 4; - private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY = 1; - private static final byte PADDING_IN_MULTIPART_REQUEST_PORT_BODY = 6; - private static final byte PADING_IN_QUEUE_BODY = 2; - - private static OF10StatsRequestInputFactory instance; - - private OF10StatsRequestInputFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10StatsRequestInputFactory getInstance() { - if (instance == null) { - instance = new OF10StatsRequestInputFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - MultipartRequestInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getType().getIntValue()); - out.writeShort(createMultipartRequestFlagsBitmask(message.getFlags())); - if (message.getMultipartRequestBody() instanceof MultipartRequestDesc) { - encodeDescBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestFlow) { - encodeFlowBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregate) { - encodeAggregateBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestTable) { - encodeTableBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStats) { - encodePortBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestQueue) { - encodeQueueBody(message.getMultipartRequestBody(), out); - } else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenter) { - encodeExperimenterBody(message.getMultipartRequestBody(), out); - } - } - - @Override - public int computeLength(MultipartRequestInput message) { - return MESSAGE_LENGTH + computeBodyLength(message); - } - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - /** - * - * @param message - * @return length of MultipartRequestMessage - */ - public int computeBodyLength(MultipartRequestInput message) { - int length = 0; - MultipartType type = message.getType(); - if (type.equals(MultipartType.OFPMPFLOW)) { - length += FLOW_BODY_LENGTH; - } else if (type.equals(MultipartType.OFPMPAGGREGATE)) { - length += AGGREGATE_BODY_LENGTH; - } else if (type.equals(MultipartType.OFPMPPORTSTATS)) { - length += PORT_STATS_BODY_LENGTH; - } else if (type.equals(MultipartType.OFPMPQUEUE)) { - length += QUEUE_BODY_LENGTH; - } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) { - MultipartRequestExperimenter body = (MultipartRequestExperimenter) message.getMultipartRequestBody(); - length += EXPERIMENTER_BODY_LENGTH; - if (body.getData() != null) { - length += body.getData().length; - } - } - return length; - } - - private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) { - int multipartRequestFlagsBitmask = 0; - Map multipartRequestFlagsMap = new HashMap<>(); - multipartRequestFlagsMap.put(0, flags.isOFPMPFREQMORE()); - multipartRequestFlagsBitmask = ByteBufUtils.fillBitMaskFromMap(multipartRequestFlagsMap); - return multipartRequestFlagsBitmask; - } - - /** - * @param multipartRequestBody - * @param output - */ - private void encodeDescBody(MultipartRequestBody multipartRequestBody, - ByteBuf output) { - // The body of MultiPartRequestDesc is empty - } - - /** - * @param multipartRequestBody - * @param out - */ - private void encodeTableBody(MultipartRequestBody multipartRequestBody, - ByteBuf out) { - // The body of MultiPartTable is empty - } - - private static void encodeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - encodeFlowAndAggregateBody(multipartRequestBody, output); - } - - private static void encodeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - encodeFlowAndAggregateBody(multipartRequestBody, output); - } - - private static void encodeFlowAndAggregateBody( - MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestFlow flow = (MultipartRequestFlow) multipartRequestBody; - OF10MatchSerializer.encodeMatchV10(output, flow.getMatchV10()); - output.writeByte(flow.getTableId().shortValue()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY, output); - output.writeShort(flow.getOutPort().intValue()); - } - - private static void encodePortBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestPortStats portstats = (MultipartRequestPortStats) multipartRequestBody; - output.writeShort(portstats.getPortNo().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_PORT_BODY, output); - } - - private static void encodeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestQueue queue = (MultipartRequestQueue) multipartRequestBody; - output.writeShort(queue.getPortNo().intValue()); - ByteBufUtils.padBuffer(PADING_IN_QUEUE_BODY, output); - output.writeInt(queue.getQueueId().intValue()); - } - - private static void encodeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { - MultipartRequestExperimenter experimenter = (MultipartRequestExperimenter) multipartRequestBody; - output.writeInt(experimenter.getExperimenter().intValue()); - output.writeBytes(experimenter.getData()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTable; + +/** + * Translates StatsRequest messages + * @author michal.polkorab + */ +public class OF10StatsRequestInputFactory implements OFSerializer { + + private static final byte MESSAGE_TYPE = 16; + private static final int MESSAGE_LENGTH = 12; + private static final byte FLOW_BODY_LENGTH = 44; + private static final byte AGGREGATE_BODY_LENGTH = 44; + private static final byte PORT_STATS_BODY_LENGTH = 8; + private static final byte QUEUE_BODY_LENGTH = 8; + private static final byte EXPERIMENTER_BODY_LENGTH = 4; + private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY = 1; + private static final byte PADDING_IN_MULTIPART_REQUEST_PORT_BODY = 6; + private static final byte PADING_IN_QUEUE_BODY = 2; + + private static OF10StatsRequestInputFactory instance; + + private OF10StatsRequestInputFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10StatsRequestInputFactory getInstance() { + if (instance == null) { + instance = new OF10StatsRequestInputFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + MultipartRequestInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeShort(message.getType().getIntValue()); + out.writeShort(createMultipartRequestFlagsBitmask(message.getFlags())); + if (message.getMultipartRequestBody() instanceof MultipartRequestDesc) { + encodeDescBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestFlow) { + encodeFlowBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregate) { + encodeAggregateBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestTable) { + encodeTableBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStats) { + encodePortBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestQueue) { + encodeQueueBody(message.getMultipartRequestBody(), out); + } else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenter) { + encodeExperimenterBody(message.getMultipartRequestBody(), out); + } + } + + @Override + public int computeLength(MultipartRequestInput message) { + return MESSAGE_LENGTH + computeBodyLength(message); + } + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + /** + * + * @param message + * @return length of MultipartRequestMessage + */ + public int computeBodyLength(MultipartRequestInput message) { + int length = 0; + MultipartType type = message.getType(); + if (type.equals(MultipartType.OFPMPFLOW)) { + length += FLOW_BODY_LENGTH; + } else if (type.equals(MultipartType.OFPMPAGGREGATE)) { + length += AGGREGATE_BODY_LENGTH; + } else if (type.equals(MultipartType.OFPMPPORTSTATS)) { + length += PORT_STATS_BODY_LENGTH; + } else if (type.equals(MultipartType.OFPMPQUEUE)) { + length += QUEUE_BODY_LENGTH; + } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) { + MultipartRequestExperimenter body = (MultipartRequestExperimenter) message.getMultipartRequestBody(); + length += EXPERIMENTER_BODY_LENGTH; + if (body.getData() != null) { + length += body.getData().length; + } + } + return length; + } + + private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) { + int multipartRequestFlagsBitmask = 0; + Map multipartRequestFlagsMap = new HashMap<>(); + multipartRequestFlagsMap.put(0, flags.isOFPMPFREQMORE()); + multipartRequestFlagsBitmask = ByteBufUtils.fillBitMaskFromMap(multipartRequestFlagsMap); + return multipartRequestFlagsBitmask; + } + + /** + * @param multipartRequestBody + * @param output + */ + private void encodeDescBody(MultipartRequestBody multipartRequestBody, + ByteBuf output) { + // The body of MultiPartRequestDesc is empty + } + + /** + * @param multipartRequestBody + * @param out + */ + private void encodeTableBody(MultipartRequestBody multipartRequestBody, + ByteBuf out) { + // The body of MultiPartTable is empty + } + + private static void encodeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + encodeFlowAndAggregateBody(multipartRequestBody, output); + } + + private static void encodeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + encodeFlowAndAggregateBody(multipartRequestBody, output); + } + + private static void encodeFlowAndAggregateBody( + MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestFlow flow = (MultipartRequestFlow) multipartRequestBody; + OF10MatchSerializer.encodeMatchV10(output, flow.getMatchV10()); + output.writeByte(flow.getTableId().shortValue()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY, output); + output.writeShort(flow.getOutPort().intValue()); + } + + private static void encodePortBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestPortStats portstats = (MultipartRequestPortStats) multipartRequestBody; + output.writeShort(portstats.getPortNo().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_PORT_BODY, output); + } + + private static void encodeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestQueue queue = (MultipartRequestQueue) multipartRequestBody; + output.writeShort(queue.getPortNo().intValue()); + ByteBufUtils.padBuffer(PADING_IN_QUEUE_BODY, output); + output.writeInt(queue.getQueueId().intValue()); + } + + private static void encodeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) { + MultipartRequestExperimenter experimenter = (MultipartRequestExperimenter) multipartRequestBody; + output.writeInt(experimenter.getExperimenter().intValue()); + output.writeBytes(experimenter.getData()); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactory.java index d4c851e8..49363c9c 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactory.java @@ -1,62 +1,69 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; - -/** - * Translates Vendor messages - * @author michal.polkorab - */ -public class OF10VendorInputMessageFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 4; - private static final byte MESSAGE_LENGTH = 8; - - private static OF10VendorInputMessageFactory instance; - - private OF10VendorInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10VendorInputMessageFactory getInstance() { - if (instance == null) { - instance = new OF10VendorInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - ExperimenterInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getExperimenter().intValue()); - byte[] data = message.getData(); - if (data != null) { - out.writeBytes(data); - } - } - - @Override - public int computeLength(ExperimenterInput message) { - int length = MESSAGE_LENGTH + EncodeConstants.SIZE_OF_INT_IN_BYTES; - byte[] data = message.getData(); - if (data != null) { - length += data.length; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; + +/** + * Translates Vendor messages + * @author michal.polkorab + */ +public class OF10VendorInputMessageFactory implements OFSerializer { + + private static final byte MESSAGE_TYPE = 4; + private static final byte MESSAGE_LENGTH = 8; + + private static OF10VendorInputMessageFactory instance; + + private OF10VendorInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10VendorInputMessageFactory getInstance() { + if (instance == null) { + instance = new OF10VendorInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + ExperimenterInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeInt(message.getExperimenter().intValue()); + byte[] data = message.getData(); + if (data != null) { + out.writeBytes(data); + } + } + + @Override + public int computeLength(ExperimenterInput message) { + int length = MESSAGE_LENGTH + EncodeConstants.SIZE_OF_INT_IN_BYTES; + byte[] data = message.getData(); + if (data != null) { + length += data.length; + } + return length; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java index 02386440..4bdfec95 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java @@ -1,69 +1,76 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; - -/** - * Translates PacketOut messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class PacketOutInputMessageFactory implements OFSerializer{ - - /** Code type of PacketOut message */ - public static final byte MESSAGE_TYPE = 13; - private static final int MESSAGE_LENGTH = 24; - private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6; - private static PacketOutInputMessageFactory instance; - - private PacketOutInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized PacketOutInputMessageFactory getInstance() { - if (instance == null) { - instance = new PacketOutInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - PacketOutInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getBufferId().intValue()); - out.writeInt(message.getInPort().getValue().intValue()); - out.writeShort(ActionsSerializer.computeLengthOfActions(message.getActionsList())); - ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out); - ActionsSerializer.encodeActions(message.getActionsList(), out); - byte[] data = message.getData(); - if (data != null) { - out.writeBytes(data); - } - } - - @Override - public int computeLength(PacketOutInput message) { - int length = MESSAGE_LENGTH; - length += ActionsSerializer.computeLengthOfActions(message.getActionsList()); - byte[] data = message.getData(); - if (data != null) { - length += data.length; - } - return length; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; + +/** + * Translates PacketOut messages + * @author michal.polkorab + * @author timotej.kubas + */ +public class PacketOutInputMessageFactory implements OFSerializer{ + + /** Code type of PacketOut message */ + public static final byte MESSAGE_TYPE = 13; + private static final int MESSAGE_LENGTH = 24; + private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6; + private static PacketOutInputMessageFactory instance; + + private PacketOutInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized PacketOutInputMessageFactory getInstance() { + if (instance == null) { + instance = new PacketOutInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + PacketOutInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeInt(message.getBufferId().intValue()); + out.writeInt(message.getInPort().getValue().intValue()); + out.writeShort(ActionsSerializer.computeLengthOfActions(message.getActionsList())); + ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out); + ActionsSerializer.encodeActions(message.getActionsList(), out); + byte[] data = message.getData(); + if (data != null) { + out.writeBytes(data); + } + } + + @Override + public int computeLength(PacketOutInput message) { + int length = MESSAGE_LENGTH; + length += ActionsSerializer.computeLengthOfActions(message.getActionsList()); + byte[] data = message.getData(); + if (data != null) { + length += data.length; + } + return length; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactory.java index e83cdb7d..3a576660 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactory.java @@ -1,105 +1,112 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.HashMap; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; - -/** - * Translates PortMod messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class PortModInputMessageFactory implements OFSerializer { - private static final byte MESSAGE_TYPE = 16; - private static final byte PADDING_IN_PORT_MOD_MESSAGE_01 = 4; - private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2; - private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4; - private static final int MESSAGE_LENGTH = 40; - private static PortModInputMessageFactory instance; - - private PortModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized PortModInputMessageFactory getInstance() { - if (instance == null) { - instance = new PortModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, PortModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getPortNo().getValue().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_01, out); - out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue())); - ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_02, out); - out.writeInt(createPortConfigBitmask(message.getConfig())); - out.writeInt(createPortConfigBitmask(message.getMask())); - out.writeInt(createPortFeaturesBitmask(message.getAdvertise())); - ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_03, out); - } - - @Override - public int computeLength(PortModInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - - /** - * @param config - * @return port config bitmask - */ - private static int createPortConfigBitmask(PortConfig config) { - int configBitmask = 0; - Map portConfigMap = new HashMap<>(); - portConfigMap.put(0, config.isPortDown()); - portConfigMap.put(2, config.isNoRecv()); - portConfigMap.put(5, config.isNoFwd()); - portConfigMap.put(6, config.isNoPacketIn()); - - configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap); - return configBitmask; - } - - private static int createPortFeaturesBitmask(PortFeatures feature) { - int configBitmask = 0; - Map portFeaturesMap = new HashMap<>(); - portFeaturesMap.put(0, feature.is_10mbHd()); - portFeaturesMap.put(1, feature.is_10mbFd()); - portFeaturesMap.put(2, feature.is_100mbHd()); - portFeaturesMap.put(3, feature.is_100mbFd()); - portFeaturesMap.put(4, feature.is_1gbHd()); - portFeaturesMap.put(5, feature.is_1gbFd()); - portFeaturesMap.put(6, feature.is_10gbFd()); - portFeaturesMap.put(7, feature.is_40gbFd()); - portFeaturesMap.put(8, feature.is_100gbFd()); - portFeaturesMap.put(9, feature.is_1tbFd()); - portFeaturesMap.put(10, feature.isOther()); - portFeaturesMap.put(11, feature.isCopper()); - portFeaturesMap.put(12, feature.isFiber()); - portFeaturesMap.put(13, feature.isAutoneg()); - portFeaturesMap.put(14, feature.isPause()); - portFeaturesMap.put(15, feature.isPauseAsym()); - - configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap); - return configBitmask; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; + +/** + * Translates PortMod messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class PortModInputMessageFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 16; + private static final byte PADDING_IN_PORT_MOD_MESSAGE_01 = 4; + private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2; + private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4; + private static final int MESSAGE_LENGTH = 40; + private static PortModInputMessageFactory instance; + + private PortModInputMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized PortModInputMessageFactory getInstance() { + if (instance == null) { + instance = new PortModInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, PortModInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeInt(message.getPortNo().getValue().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_01, out); + out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue())); + ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_02, out); + out.writeInt(createPortConfigBitmask(message.getConfig())); + out.writeInt(createPortConfigBitmask(message.getMask())); + out.writeInt(createPortFeaturesBitmask(message.getAdvertise())); + ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_03, out); + } + + @Override + public int computeLength(PortModInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + + /** + * @param config + * @return port config bitmask + */ + private static int createPortConfigBitmask(PortConfig config) { + int configBitmask = 0; + Map portConfigMap = new HashMap<>(); + portConfigMap.put(0, config.isPortDown()); + portConfigMap.put(2, config.isNoRecv()); + portConfigMap.put(5, config.isNoFwd()); + portConfigMap.put(6, config.isNoPacketIn()); + + configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap); + return configBitmask; + } + + private static int createPortFeaturesBitmask(PortFeatures feature) { + int configBitmask = 0; + Map portFeaturesMap = new HashMap<>(); + portFeaturesMap.put(0, feature.is_10mbHd()); + portFeaturesMap.put(1, feature.is_10mbFd()); + portFeaturesMap.put(2, feature.is_100mbHd()); + portFeaturesMap.put(3, feature.is_100mbFd()); + portFeaturesMap.put(4, feature.is_1gbHd()); + portFeaturesMap.put(5, feature.is_1gbFd()); + portFeaturesMap.put(6, feature.is_10gbFd()); + portFeaturesMap.put(7, feature.is_40gbFd()); + portFeaturesMap.put(8, feature.is_100gbFd()); + portFeaturesMap.put(9, feature.is_1tbFd()); + portFeaturesMap.put(10, feature.isOther()); + portFeaturesMap.put(11, feature.isCopper()); + portFeaturesMap.put(12, feature.isFiber()); + portFeaturesMap.put(13, feature.isAutoneg()); + portFeaturesMap.put(14, feature.isPause()); + portFeaturesMap.put(15, feature.isPauseAsym()); + + configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap); + return configBitmask; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java index b60e1476..285932d2 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java @@ -1,56 +1,63 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput; - -/** - * Translates RoleRequest messages - * @author michal.polkorab - * @author timotej.kubas - */ -public class RoleRequestInputMessageFactory implements OFSerializer { - - /** Code type of RoleRequest message */ - public static final byte MESSAGE_TYPE = 24; - private static final int MESSAGE_LENGTH = 24; - private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4; - private static RoleRequestInputMessageFactory instance; - - private RoleRequestInputMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized RoleRequestInputMessageFactory getInstance() { - if (instance == null) { - instance = new RoleRequestInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - RoleRequestInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeInt(message.getRole().getIntValue()); - ByteBufUtils.padBuffer(PADDING_IN_ROLE_REQUEST_MESSAGE, out); - out.writeLong(message.getGenerationId().longValue()); - } - - @Override - public int computeLength(RoleRequestInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput; + +/** + * Translates RoleRequest messages + * @author michal.polkorab + * @author timotej.kubas + */ +public class RoleRequestInputMessageFactory implements OFSerializer { + + /** Code type of RoleRequest message */ + public static final byte MESSAGE_TYPE = 24; + private static final int MESSAGE_LENGTH = 24; + private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4; + private static RoleRequestInputMessageFactory instance; + + private RoleRequestInputMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized RoleRequestInputMessageFactory getInstance() { + if (instance == null) { + instance = new RoleRequestInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + RoleRequestInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeInt(message.getRole().getIntValue()); + ByteBufUtils.padBuffer(PADDING_IN_ROLE_REQUEST_MESSAGE, out); + out.writeLong(message.getGenerationId().longValue()); + } + + @Override + public int computeLength(RoleRequestInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java index e83c5899..c647aaf7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java @@ -1,129 +1,136 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask; - -/** - * Translates SetAsync messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class SetAsyncInputMessageFactory implements OFSerializer { - private static final byte MESSAGE_TYPE = 28; - private static final int MESSAGE_LENGTH = 32; - private static SetAsyncInputMessageFactory instance; - - - private SetAsyncInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized SetAsyncInputMessageFactory getInstance() { - if (instance == null) { - instance = new SetAsyncInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - SetAsyncInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - encodePacketInMask(message.getPacketInMask(), out); - encodePortStatusMask(message.getPortStatusMask(), out); - encodeFlowRemovedMask(message.getFlowRemovedMask(), out); - } - - @Override - public int computeLength(SetAsyncInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static void encodePacketInMask(List packetInMask, ByteBuf outBuffer) { - if (packetInMask != null) { - for (PacketInMask currentPacketMask : packetInMask) { - List mask = currentPacketMask.getMask(); - if (mask != null) { - Map packetInReasonMap = new HashMap<>(); - for (PacketInReason packetInReason : mask) { - if (PacketInReason.OFPRNOMATCH.equals(packetInReason)) { - packetInReasonMap.put(PacketInReason.OFPRNOMATCH.getIntValue(), true); - } else if (PacketInReason.OFPRACTION.equals(packetInReason)) { - packetInReasonMap.put(PacketInReason.OFPRACTION.getIntValue(), true); - } else if (PacketInReason.OFPRINVALIDTTL.equals(packetInReason)) { - packetInReasonMap.put(PacketInReason.OFPRINVALIDTTL.getIntValue(), true); - } - } - outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(packetInReasonMap)); - } - } - } - } - - private static void encodePortStatusMask(List portStatusMask, ByteBuf outBuffer) { - if (portStatusMask != null) { - for (PortStatusMask currentPortStatusMask : portStatusMask) { - List mask = currentPortStatusMask.getMask(); - if (mask != null) { - Map portStatusReasonMap = new HashMap<>(); - for (PortReason packetInReason : mask) { - if (PortReason.OFPPRADD.equals(packetInReason)) { - portStatusReasonMap.put(PortReason.OFPPRADD.getIntValue(), true); - } else if (PortReason.OFPPRDELETE.equals(packetInReason)) { - portStatusReasonMap.put(PortReason.OFPPRDELETE.getIntValue(), true); - } else if (PortReason.OFPPRMODIFY.equals(packetInReason)) { - portStatusReasonMap.put(PortReason.OFPPRMODIFY.getIntValue(), true); - } - } - outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(portStatusReasonMap)); - } - } - } - } - - private static void encodeFlowRemovedMask(List flowRemovedMask, ByteBuf outBuffer) { - if (flowRemovedMask != null) { - for (FlowRemovedMask currentFlowRemovedMask : flowRemovedMask) { - List mask = currentFlowRemovedMask.getMask(); - if (mask != null) { - Map flowRemovedReasonMap = new HashMap<>(); - for (FlowRemovedReason packetInReason : mask) { - if (FlowRemovedReason.OFPRRIDLETIMEOUT.equals(packetInReason)) { - flowRemovedReasonMap.put(FlowRemovedReason.OFPRRIDLETIMEOUT.getIntValue(), true); - } else if (FlowRemovedReason.OFPRRHARDTIMEOUT.equals(packetInReason)) { - flowRemovedReasonMap.put(FlowRemovedReason.OFPRRHARDTIMEOUT.getIntValue(), true); - } else if (FlowRemovedReason.OFPRRDELETE.equals(packetInReason)) { - flowRemovedReasonMap.put(FlowRemovedReason.OFPRRDELETE.getIntValue(), true); - } else if (FlowRemovedReason.OFPRRGROUPDELETE.equals(packetInReason)) { - flowRemovedReasonMap.put(FlowRemovedReason.OFPRRGROUPDELETE.getIntValue(), true); - } - } - outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(flowRemovedReasonMap)); - } - } - } - } - +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask; + +/** + * Translates SetAsync messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class SetAsyncInputMessageFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 28; + private static final int MESSAGE_LENGTH = 32; + private static SetAsyncInputMessageFactory instance; + + + private SetAsyncInputMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized SetAsyncInputMessageFactory getInstance() { + if (instance == null) { + instance = new SetAsyncInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + SetAsyncInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + encodePacketInMask(message.getPacketInMask(), out); + encodePortStatusMask(message.getPortStatusMask(), out); + encodeFlowRemovedMask(message.getFlowRemovedMask(), out); + } + + @Override + public int computeLength(SetAsyncInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + private static void encodePacketInMask(List packetInMask, ByteBuf outBuffer) { + if (packetInMask != null) { + for (PacketInMask currentPacketMask : packetInMask) { + List mask = currentPacketMask.getMask(); + if (mask != null) { + Map packetInReasonMap = new HashMap<>(); + for (PacketInReason packetInReason : mask) { + if (PacketInReason.OFPRNOMATCH.equals(packetInReason)) { + packetInReasonMap.put(PacketInReason.OFPRNOMATCH.getIntValue(), true); + } else if (PacketInReason.OFPRACTION.equals(packetInReason)) { + packetInReasonMap.put(PacketInReason.OFPRACTION.getIntValue(), true); + } else if (PacketInReason.OFPRINVALIDTTL.equals(packetInReason)) { + packetInReasonMap.put(PacketInReason.OFPRINVALIDTTL.getIntValue(), true); + } + } + outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(packetInReasonMap)); + } + } + } + } + + private static void encodePortStatusMask(List portStatusMask, ByteBuf outBuffer) { + if (portStatusMask != null) { + for (PortStatusMask currentPortStatusMask : portStatusMask) { + List mask = currentPortStatusMask.getMask(); + if (mask != null) { + Map portStatusReasonMap = new HashMap<>(); + for (PortReason packetInReason : mask) { + if (PortReason.OFPPRADD.equals(packetInReason)) { + portStatusReasonMap.put(PortReason.OFPPRADD.getIntValue(), true); + } else if (PortReason.OFPPRDELETE.equals(packetInReason)) { + portStatusReasonMap.put(PortReason.OFPPRDELETE.getIntValue(), true); + } else if (PortReason.OFPPRMODIFY.equals(packetInReason)) { + portStatusReasonMap.put(PortReason.OFPPRMODIFY.getIntValue(), true); + } + } + outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(portStatusReasonMap)); + } + } + } + } + + private static void encodeFlowRemovedMask(List flowRemovedMask, ByteBuf outBuffer) { + if (flowRemovedMask != null) { + for (FlowRemovedMask currentFlowRemovedMask : flowRemovedMask) { + List mask = currentFlowRemovedMask.getMask(); + if (mask != null) { + Map flowRemovedReasonMap = new HashMap<>(); + for (FlowRemovedReason packetInReason : mask) { + if (FlowRemovedReason.OFPRRIDLETIMEOUT.equals(packetInReason)) { + flowRemovedReasonMap.put(FlowRemovedReason.OFPRRIDLETIMEOUT.getIntValue(), true); + } else if (FlowRemovedReason.OFPRRHARDTIMEOUT.equals(packetInReason)) { + flowRemovedReasonMap.put(FlowRemovedReason.OFPRRHARDTIMEOUT.getIntValue(), true); + } else if (FlowRemovedReason.OFPRRDELETE.equals(packetInReason)) { + flowRemovedReasonMap.put(FlowRemovedReason.OFPRRDELETE.getIntValue(), true); + } else if (FlowRemovedReason.OFPRRGROUPDELETE.equals(packetInReason)) { + flowRemovedReasonMap.put(FlowRemovedReason.OFPRRGROUPDELETE.getIntValue(), true); + } + } + outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(flowRemovedReasonMap)); + } + } + } + } + } \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java index 2c6f3795..5e7e6283 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java @@ -1,54 +1,61 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput; - -/** - * Translates SetConfig messages (both OpenFlow v1.0 and OpenFlow v1.3) - * @author michal.polkorab - * @author timotej.kubas - */ -public class SetConfigMessageFactory implements OFSerializer { - - /** Code type of SetConfig message */ - public static final byte MESSAGE_TYPE = 9; - private static final int MESSAGE_LENGTH = 12; - private static SetConfigMessageFactory instance; - - private SetConfigMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized SetConfigMessageFactory getInstance() { - if (instance == null) { - instance = new SetConfigMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - SetConfigInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getFlags().getIntValue()); - out.writeShort(message.getMissSendLen()); - } - - @Override - public int computeLength(SetConfigInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput; + +/** + * Translates SetConfig messages (both OpenFlow v1.0 and OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public class SetConfigMessageFactory implements OFSerializer { + + /** Code type of SetConfig message */ + public static final byte MESSAGE_TYPE = 9; + private static final int MESSAGE_LENGTH = 12; + private static SetConfigMessageFactory instance; + + private SetConfigMessageFactory() { + // do nothing, just singleton + } + + /** + * @return singleton factory + */ + public static synchronized SetConfigMessageFactory getInstance() { + if (instance == null) { + instance = new SetConfigMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, + SetConfigInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeShort(message.getFlags().getIntValue()); + out.writeShort(message.getMissSendLen()); + } + + @Override + public int computeLength(SetConfigInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactory.java index 1255b159..9c4e3b24 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactory.java @@ -1,67 +1,74 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.HashMap; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput; - -/** - * Translates TableMod messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class TableModInputMessageFactory implements OFSerializer { - private static final byte MESSAGE_TYPE = 17; - private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3; - private static final int MESSAGE_LENGTH = 16; - private static TableModInputMessageFactory instance; - - private TableModInputMessageFactory() { - // just singleton - } - - /** - * @return singleton factory - */ - public static synchronized TableModInputMessageFactory getInstance() { - if(instance == null){ - instance = new TableModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, TableModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeByte(message.getTableId().getValue().byteValue()); - ByteBufUtils.padBuffer(PADDING_IN_TABLE_MOD_MESSAGE, out); - out.writeInt(createConfigBitmask(message.getConfig())); - } - - @Override - public int computeLength(TableModInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - /** - * @param tableConfig - * @return port config bitmask - */ - private static int createConfigBitmask(TableConfig tableConfig) { - Map portConfigMap = new HashMap<>(); - portConfigMap.put(3, tableConfig.isOFPTCDEPRECATEDMASK()); - int configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap); - return configBitmask; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput; + +/** + * Translates TableMod messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class TableModInputMessageFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 17; + private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3; + private static final int MESSAGE_LENGTH = 16; + private static TableModInputMessageFactory instance; + + private TableModInputMessageFactory() { + // just singleton + } + + /** + * @return singleton factory + */ + public static synchronized TableModInputMessageFactory getInstance() { + if(instance == null){ + instance = new TableModInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, TableModInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeByte(message.getTableId().getValue().byteValue()); + ByteBufUtils.padBuffer(PADDING_IN_TABLE_MOD_MESSAGE, out); + out.writeInt(createConfigBitmask(message.getConfig())); + } + + @Override + public int computeLength(TableModInput message) { + return MESSAGE_LENGTH; + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + /** + * @param tableConfig + * @return port config bitmask + */ + private static int createConfigBitmask(TableConfig tableConfig) { + Map portConfigMap = new HashMap<>(); + portConfigMap.put(3, tableConfig.isOFPTCDEPRECATEDMASK()); + int configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap); + return configBitmask; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java index bfa90f7f..287c34a8 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java @@ -1,304 +1,311 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; - -/** - * Deserializes ofp_actions (OpenFlow v1.3) - * @author timotej.kubas - * @author michal.polkorab - */ -public abstract class ActionsDeserializer { - - private static final byte ACTION_HEADER_LENGTH = 4; - private static final byte PADDING_IN_ACTIONS_HEADER = 4; - private static final byte PADDING_IN_OUTPUT_ACTIONS_HEADER = 6; - private static final byte PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER = 3; - private static final byte PADDING_IN_PUSH_VLAN_ACTIONS_HEADER = 2; - private static final byte PADDING_IN_NW_TTL_ACTIONS_HEADER = 3; - - /** - * Creates list of actions (OpenFlow v1.3) - * @param input input ByteBuf - * @param actionsLength length of buckets - * @return ActionsList - */ - public static List createActionsList(ByteBuf input, int actionsLength) { - ActionsListBuilder actionsListBuilder = new ActionsListBuilder(); - List actionsList = new ArrayList<>(); - int length = 0; - while (length < actionsLength) { - int currentActionLength = 0; - switch(input.readUnsignedShort()) { - case 0: currentActionLength = input.readUnsignedShort(); //outputActionLength - actionsList.add(createOutputAction(input, actionsListBuilder)); - break; - case 11: - currentActionLength = input.readUnsignedShort();//empty header length - actionsList.add(createCopyTtlOutAction(input, actionsListBuilder)); - break; - - case 12: - currentActionLength = input.readUnsignedShort();//empty header length - actionsList.add(createCopyTtlInAction(input, actionsListBuilder)); - break; - - case 15: - currentActionLength = input.readUnsignedShort();//empty header length - actionsList.add(createSetMplsTtlAction(input, actionsListBuilder)); - break; - - case 16: - currentActionLength = input.readUnsignedShort();//empty header length - actionsList.add(createDecMplsTtlOutAction(input, actionsListBuilder)); - break; - - case 17: - currentActionLength = input.readUnsignedShort(); - actionsList.add(createPushVlanAction(input, actionsListBuilder)); - break; - - case 18: - currentActionLength = input.readUnsignedShort();//empty header length - actionsList.add(createPopVlanAction(input, actionsListBuilder)); - break; - - case 19: - currentActionLength = input.readUnsignedShort();//8 - actionsList.add(createPushMplsAction(input, actionsListBuilder)); - break; - - case 20: - currentActionLength = input.readUnsignedShort();//8 - actionsList.add(createPopMplsAction(input, actionsListBuilder)); - break; - - case 21: - currentActionLength = input.readUnsignedShort(); - actionsList.add(createSetQueueAction(input, actionsListBuilder)); - break; - - case 22: - currentActionLength = input.readUnsignedShort();//8 - actionsList.add(createGroupAction(input, actionsListBuilder)); - break; - - case 23: - currentActionLength = input.readUnsignedShort();//8 - actionsList.add(createSetNwTtlAction(input, actionsListBuilder)); - break; - - case 24: - currentActionLength = input.readUnsignedShort();//empty header length - actionsList.add(createDecNwTtlAction(input, actionsListBuilder)); - break; - - case 25: - currentActionLength = input.readUnsignedShort();//8 - actionsList.add(createSetFieldAction(input, actionsListBuilder, currentActionLength)); - break; - case 26: - currentActionLength = input.readUnsignedShort();//8 - actionsList.add(createPushPbbAction(input, actionsListBuilder)); - break; - - case 27: - currentActionLength = input.readUnsignedShort();//empty header length - actionsList.add(createPopPbbAction(input, actionsListBuilder)); - break; - - case 0xFFFF: - currentActionLength = input.readUnsignedShort(); - actionsList.add(createExperimenterAction(input, actionsListBuilder)); - break; - default: - break; - } - length += currentActionLength; - } - return actionsList; - } - - private static ActionsList createEmptyHeader(Class action, - ByteBuf in, ActionsListBuilder actionsListBuilder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(action); - in.skipBytes(PADDING_IN_ACTIONS_HEADER); - actionsListBuilder.setAction(actionBuilder.build()); - return actionsListBuilder.build(); - } - - private static ActionsList createCopyTtlInAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - return createEmptyHeader(CopyTtlIn.class, in, actionsListBuilder); - } - - private static ActionsList createCopyTtlOutAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - return createEmptyHeader(CopyTtlOut.class, in, actionsListBuilder); - } - - private static ActionsList createDecMplsTtlOutAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - return createEmptyHeader(DecMplsTtl.class, in, actionsListBuilder); - } - - private static ActionsList createPopVlanAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - return createEmptyHeader(PopVlan.class, in, actionsListBuilder); - } - - private static ActionsList createDecNwTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - return createEmptyHeader(DecNwTtl.class, in, actionsListBuilder); - } - - private static ActionsList createPopPbbAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - return createEmptyHeader(PopPbb.class, in, actionsListBuilder); - } - - private static ActionsList createOutputAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(Output.class); - PortActionBuilder port = new PortActionBuilder(); - port.setPort(new PortNumber(in.readUnsignedInt())); - actionBuilder.addAugmentation(PortAction.class, port.build()); - MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); - maxLen.setMaxLength(in.readUnsignedShort()); - actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); - actionsListBuilder.setAction(actionBuilder.build()); - in.skipBytes(PADDING_IN_OUTPUT_ACTIONS_HEADER); - return actionsListBuilder.build(); - } - - private static ActionsList createSetMplsTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetMplsTtl.class); - MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder(); - mplsTtl.setMplsTtl(in.readUnsignedByte()); - actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtl.build()); - actionsListBuilder.setAction(actionBuilder.build()); - in.skipBytes(PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER); - return actionsListBuilder.build(); - } - - private static ActionsList createPushAction(Class action, - ByteBuf in, ActionsListBuilder actionsListBuilder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(action); - EthertypeActionBuilder etherType = new EthertypeActionBuilder(); - etherType.setEthertype(new EtherType(in.readUnsignedShort())); - actionBuilder.addAugmentation(EthertypeAction.class, etherType.build()); - actionsListBuilder.setAction(actionBuilder.build()); - in.skipBytes(PADDING_IN_PUSH_VLAN_ACTIONS_HEADER); - return actionsListBuilder.build(); - } - - private static ActionsList createPushVlanAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - return createPushAction(PushVlan.class, in, actionsListBuilder); - } - - private static ActionsList createPushMplsAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - return createPushAction(PushMpls.class, in, actionsListBuilder); - } - - private static ActionsList createPopMplsAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - return createPushAction(PopMpls.class, in, actionsListBuilder); - } - - private static ActionsList createPushPbbAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - return createPushAction(PushPbb.class, in, actionsListBuilder); - } - - private static ActionsList createSetQueueAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetQueue.class); - QueueIdActionBuilder queueId = new QueueIdActionBuilder(); - queueId.setQueueId(in.readUnsignedInt()); - actionBuilder.addAugmentation(QueueIdAction.class, queueId.build()); - actionsListBuilder.setAction(actionBuilder.build()); - return actionsListBuilder.build(); - } - - private static ActionsList createGroupAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(Group.class); - GroupIdActionBuilder group = new GroupIdActionBuilder(); - group.setGroupId(in.readUnsignedInt()); - actionBuilder.addAugmentation(GroupIdAction.class, group.build()); - actionsListBuilder.setAction(actionBuilder.build()); - return actionsListBuilder.build(); - } - - private static ActionsList createExperimenterAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(Experimenter.class); - ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder(); - experimenter.setExperimenter(in.readUnsignedInt()); - actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build()); - actionsListBuilder.setAction(actionBuilder.build()); - return actionsListBuilder.build(); - } - - private static ActionsList createSetNwTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetNwTtl.class); - NwTtlActionBuilder nwTtl = new NwTtlActionBuilder(); - nwTtl.setNwTtl(in.readUnsignedByte()); - actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build()); - actionsListBuilder.setAction(actionBuilder.build()); - in.skipBytes(PADDING_IN_NW_TTL_ACTIONS_HEADER); - return actionsListBuilder.build(); - } - - private static ActionsList createSetFieldAction(ByteBuf in, ActionsListBuilder actionsListBuilder, int actionLength) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetField.class); - OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder(); - matchEntries.setMatchEntries(MatchDeserializer.createMatchEntry(in, actionLength - ACTION_HEADER_LENGTH)); - actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build()); - actionsListBuilder.setAction(actionBuilder.build()); - return actionsListBuilder.build(); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; + +/** + * Deserializes ofp_actions (OpenFlow v1.3) + * @author timotej.kubas + * @author michal.polkorab + */ +public abstract class ActionsDeserializer { + + private static final byte ACTION_HEADER_LENGTH = 4; + private static final byte PADDING_IN_ACTIONS_HEADER = 4; + private static final byte PADDING_IN_OUTPUT_ACTIONS_HEADER = 6; + private static final byte PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER = 3; + private static final byte PADDING_IN_PUSH_VLAN_ACTIONS_HEADER = 2; + private static final byte PADDING_IN_NW_TTL_ACTIONS_HEADER = 3; + + /** + * Creates list of actions (OpenFlow v1.3) + * @param input input ByteBuf + * @param actionsLength length of buckets + * @return ActionsList + */ + public static List createActionsList(ByteBuf input, int actionsLength) { + ActionsListBuilder actionsListBuilder = new ActionsListBuilder(); + List actionsList = new ArrayList<>(); + int length = 0; + while (length < actionsLength) { + int currentActionLength = 0; + switch(input.readUnsignedShort()) { + case 0: currentActionLength = input.readUnsignedShort(); //outputActionLength + actionsList.add(createOutputAction(input, actionsListBuilder)); + break; + case 11: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(createCopyTtlOutAction(input, actionsListBuilder)); + break; + + case 12: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(createCopyTtlInAction(input, actionsListBuilder)); + break; + + case 15: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(createSetMplsTtlAction(input, actionsListBuilder)); + break; + + case 16: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(createDecMplsTtlOutAction(input, actionsListBuilder)); + break; + + case 17: + currentActionLength = input.readUnsignedShort(); + actionsList.add(createPushVlanAction(input, actionsListBuilder)); + break; + + case 18: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(createPopVlanAction(input, actionsListBuilder)); + break; + + case 19: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(createPushMplsAction(input, actionsListBuilder)); + break; + + case 20: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(createPopMplsAction(input, actionsListBuilder)); + break; + + case 21: + currentActionLength = input.readUnsignedShort(); + actionsList.add(createSetQueueAction(input, actionsListBuilder)); + break; + + case 22: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(createGroupAction(input, actionsListBuilder)); + break; + + case 23: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(createSetNwTtlAction(input, actionsListBuilder)); + break; + + case 24: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(createDecNwTtlAction(input, actionsListBuilder)); + break; + + case 25: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(createSetFieldAction(input, actionsListBuilder, currentActionLength)); + break; + case 26: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(createPushPbbAction(input, actionsListBuilder)); + break; + + case 27: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(createPopPbbAction(input, actionsListBuilder)); + break; + + case 0xFFFF: + currentActionLength = input.readUnsignedShort(); + actionsList.add(createExperimenterAction(input, actionsListBuilder)); + break; + default: + break; + } + length += currentActionLength; + } + return actionsList; + } + + private static ActionsList createEmptyHeader(Class action, + ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(action); + in.skipBytes(PADDING_IN_ACTIONS_HEADER); + actionsListBuilder.setAction(actionBuilder.build()); + return actionsListBuilder.build(); + } + + private static ActionsList createCopyTtlInAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(CopyTtlIn.class, in, actionsListBuilder); + } + + private static ActionsList createCopyTtlOutAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(CopyTtlOut.class, in, actionsListBuilder); + } + + private static ActionsList createDecMplsTtlOutAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(DecMplsTtl.class, in, actionsListBuilder); + } + + private static ActionsList createPopVlanAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(PopVlan.class, in, actionsListBuilder); + } + + private static ActionsList createDecNwTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(DecNwTtl.class, in, actionsListBuilder); + } + + private static ActionsList createPopPbbAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(PopPbb.class, in, actionsListBuilder); + } + + private static ActionsList createOutputAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Output.class); + PortActionBuilder port = new PortActionBuilder(); + port.setPort(new PortNumber(in.readUnsignedInt())); + actionBuilder.addAugmentation(PortAction.class, port.build()); + MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); + maxLen.setMaxLength(in.readUnsignedShort()); + actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); + actionsListBuilder.setAction(actionBuilder.build()); + in.skipBytes(PADDING_IN_OUTPUT_ACTIONS_HEADER); + return actionsListBuilder.build(); + } + + private static ActionsList createSetMplsTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetMplsTtl.class); + MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder(); + mplsTtl.setMplsTtl(in.readUnsignedByte()); + actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtl.build()); + actionsListBuilder.setAction(actionBuilder.build()); + in.skipBytes(PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER); + return actionsListBuilder.build(); + } + + private static ActionsList createPushAction(Class action, + ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(action); + EthertypeActionBuilder etherType = new EthertypeActionBuilder(); + etherType.setEthertype(new EtherType(in.readUnsignedShort())); + actionBuilder.addAugmentation(EthertypeAction.class, etherType.build()); + actionsListBuilder.setAction(actionBuilder.build()); + in.skipBytes(PADDING_IN_PUSH_VLAN_ACTIONS_HEADER); + return actionsListBuilder.build(); + } + + private static ActionsList createPushVlanAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createPushAction(PushVlan.class, in, actionsListBuilder); + } + + private static ActionsList createPushMplsAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createPushAction(PushMpls.class, in, actionsListBuilder); + } + + private static ActionsList createPopMplsAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createPushAction(PopMpls.class, in, actionsListBuilder); + } + + private static ActionsList createPushPbbAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createPushAction(PushPbb.class, in, actionsListBuilder); + } + + private static ActionsList createSetQueueAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetQueue.class); + QueueIdActionBuilder queueId = new QueueIdActionBuilder(); + queueId.setQueueId(in.readUnsignedInt()); + actionBuilder.addAugmentation(QueueIdAction.class, queueId.build()); + actionsListBuilder.setAction(actionBuilder.build()); + return actionsListBuilder.build(); + } + + private static ActionsList createGroupAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Group.class); + GroupIdActionBuilder group = new GroupIdActionBuilder(); + group.setGroupId(in.readUnsignedInt()); + actionBuilder.addAugmentation(GroupIdAction.class, group.build()); + actionsListBuilder.setAction(actionBuilder.build()); + return actionsListBuilder.build(); + } + + private static ActionsList createExperimenterAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Experimenter.class); + ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder(); + experimenter.setExperimenter(in.readUnsignedInt()); + actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build()); + actionsListBuilder.setAction(actionBuilder.build()); + return actionsListBuilder.build(); + } + + private static ActionsList createSetNwTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetNwTtl.class); + NwTtlActionBuilder nwTtl = new NwTtlActionBuilder(); + nwTtl.setNwTtl(in.readUnsignedByte()); + actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build()); + actionsListBuilder.setAction(actionBuilder.build()); + in.skipBytes(PADDING_IN_NW_TTL_ACTIONS_HEADER); + return actionsListBuilder.build(); + } + + private static ActionsList createSetFieldAction(ByteBuf in, ActionsListBuilder actionsListBuilder, int actionLength) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetField.class); + OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder(); + matchEntries.setMatchEntries(MatchDeserializer.createMatchEntry(in, actionLength - ACTION_HEADER_LENGTH)); + actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build()); + actionsListBuilder.setAction(actionBuilder.build()); + return actionsListBuilder.build(); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java index 69698c56..b6355678 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java @@ -1,277 +1,284 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; - -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; - -/** - * Serializes ofp_actions (OpenFlow v1.3) - * @author michal.polkorab - * @author timotej.kubas - */ -public abstract class ActionsSerializer { - - private static final byte OUTPUT_CODE = 0; - private static final byte COPY_TTL_OUT_CODE = 11; - private static final byte COPY_TTL_IN_CODE = 12; - private static final byte SET_MPLS_TTL_CODE = 15; - private static final byte DEC_MPLS_TTL_CODE = 16; - private static final byte PUSH_VLAN_CODE = 17; - private static final byte POP_VLAN_CODE = 18; - private static final byte PUSH_MPLS_CODE = 19; - private static final byte POP_MPLS_CODE = 20; - private static final byte SET_QUEUE_CODE = 21; - private static final byte GROUP_CODE = 22; - private static final byte SET_NW_TTL_CODE = 23; - private static final byte DEC_NW_TTL_CODE = 24; - private static final int SET_FIELD_CODE = 25; - private static final byte PUSH_PBB_CODE = 26; - private static final byte POP_PBB_CODE = 27; - private static final int EXPERIMENTER_CODE = 65535; // 0xFFFF - private static final byte OUTPUT_LENGTH = 16; - private static final byte SET_MPLS_TTL_LENGTH = 8; - private static final byte SET_QUEUE_LENGTH = 8; - private static final byte GROUP_LENGTH = 8; - private static final byte SET_NW_TTL_LENGTH = 8; - private static final byte EXPERIMENTER_LENGTH = 8; - private static final byte ACTION_HEADER_LENGTH = 8; - private static final byte LENGTH_OF_ETHERTYPE_ACTION = 8; - private static final byte LENGTH_OF_OTHER_ACTIONS = 8; - private static final byte SET_FIELD_HEADER_LENGTH = 4; // only type and length - private static final byte OUTPUT_PADDING = 6; - private static final byte SET_MPLS_TTL_PADDING = 3; - private static final byte SET_NW_TTL_PADDING = 3; - private static final byte PADDING_IN_ACTION_HEADER = 4; - private static final byte ETHERTYPE_ACTION_PADDING = 2; - - - /** - * Encodes actions to ByteBuf - * @param actionsList list of actions to be encoded - * @param outBuffer output ByteBuf - */ - public static void encodeActions(List actionsList, ByteBuf outBuffer) { - if (actionsList == null) { - return; - } - for (ActionsList list : actionsList) { - Action action = list.getAction(); - if (action.getType().isAssignableFrom(Output.class)) { - encodeOutputAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(CopyTtlOut.class)) { - encodeCopyTtlOutAction(outBuffer); - } else if (action.getType().isAssignableFrom(CopyTtlIn.class)) { - encodeCopyTtlInAction(outBuffer); - } else if (action.getType().isAssignableFrom(SetMplsTtl.class)) { - encodeSetMplsTtltAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(DecMplsTtl.class)) { - encodeDecMplsTtlAction(outBuffer); - } else if (action.getType().isAssignableFrom(PushVlan.class)) { - encodePushVlanAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(PopVlan.class)) { - encodePopVlanAction(outBuffer); - } else if (action.getType().isAssignableFrom(PushMpls.class)) { - encodePushMplsAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(PopMpls.class)) { - encodePopMplsAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(SetQueue.class)) { - encodeSetQueueAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(Group.class)) { - encodeGroupAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(SetNwTtl.class)) { - encodeSetNwTtlAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(DecNwTtl.class)) { - encodeDecNwTtlAction(outBuffer); - } else if (action.getType().isAssignableFrom(SetField.class)) { - encodeSetFieldAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(PushPbb.class)) { - encodePushPbbAction(action, outBuffer); - } else if (action.getType().isAssignableFrom(PopPbb.class)) { - encodePopPbbAction(outBuffer); - } else if (action.getType().isAssignableFrom(Experimenter.class)) { - encodeExperimenterAction(action, outBuffer); - } - } - } - - private static void encodeOutputAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(OUTPUT_CODE); - outBuffer.writeShort(OUTPUT_LENGTH); - PortAction port = action.getAugmentation(PortAction.class); - outBuffer.writeInt(port.getPort().getValue().intValue()); - MaxLengthAction maxlength = action.getAugmentation(MaxLengthAction.class); - outBuffer.writeShort(maxlength.getMaxLength()); - ByteBufUtils.padBuffer(OUTPUT_PADDING, outBuffer); - } - - private static void encodeCopyTtlOutAction(ByteBuf outBuffer) { - outBuffer.writeShort(COPY_TTL_OUT_CODE); - encodeRestOfActionHeader(outBuffer); - } - - private static void encodeCopyTtlInAction(ByteBuf outBuffer) { - outBuffer.writeShort(COPY_TTL_IN_CODE); - encodeRestOfActionHeader(outBuffer); - } - - private static void encodeSetMplsTtltAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(SET_MPLS_TTL_CODE); - outBuffer.writeShort(SET_MPLS_TTL_LENGTH); - MplsTtlAction mplsTtl = action.getAugmentation(MplsTtlAction.class); - outBuffer.writeByte(mplsTtl.getMplsTtl()); - ByteBufUtils.padBuffer(SET_MPLS_TTL_PADDING, outBuffer); - } - - private static void encodeDecMplsTtlAction(ByteBuf outBuffer) { - outBuffer.writeShort(DEC_MPLS_TTL_CODE); - encodeRestOfActionHeader(outBuffer); - } - - private static void encodePushVlanAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(PUSH_VLAN_CODE); - encodeCommonEthertype(action, outBuffer); - } - - private static void encodePopVlanAction(ByteBuf outBuffer) { - outBuffer.writeShort(POP_VLAN_CODE); - encodeRestOfActionHeader(outBuffer); - } - - private static void encodePushMplsAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(PUSH_MPLS_CODE); - encodeCommonEthertype(action, outBuffer); - } - - private static void encodePopMplsAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(POP_MPLS_CODE); - encodeCommonEthertype(action, outBuffer); - } - - private static void encodeSetQueueAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(SET_QUEUE_CODE); - outBuffer.writeShort(SET_QUEUE_LENGTH); - QueueIdAction queueId = action.getAugmentation(QueueIdAction.class); - outBuffer.writeInt(queueId.getQueueId().intValue()); - } - - private static void encodeGroupAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(GROUP_CODE); - outBuffer.writeShort(GROUP_LENGTH); - GroupIdAction groupId = action.getAugmentation(GroupIdAction.class); - outBuffer.writeInt(groupId.getGroupId().intValue()); - } - - private static void encodeSetNwTtlAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(SET_NW_TTL_CODE); - outBuffer.writeShort(SET_NW_TTL_LENGTH); - NwTtlAction nwTtl = action.getAugmentation(NwTtlAction.class); - outBuffer.writeByte(nwTtl.getNwTtl()); - ByteBufUtils.padBuffer(SET_NW_TTL_PADDING, outBuffer); - } - - private static void encodeDecNwTtlAction(ByteBuf outBuffer) { - outBuffer.writeShort(DEC_NW_TTL_CODE); - encodeRestOfActionHeader(outBuffer); - } - - private static void encodeSetFieldAction(Action action, ByteBuf outBuffer) { - OxmFieldsAction oxmField = action.getAugmentation(OxmFieldsAction.class); - int length = MatchSerializer.computeMatchEntriesLength(oxmField.getMatchEntries()) + SET_FIELD_HEADER_LENGTH; - outBuffer.writeShort(SET_FIELD_CODE); - int paddingRemainder = length % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - length += EncodeConstants.PADDING - paddingRemainder; - } - outBuffer.writeShort(length); - MatchSerializer.encodeMatchEntries(oxmField.getMatchEntries(), outBuffer); - ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, outBuffer); - } - - private static void encodePushPbbAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(PUSH_PBB_CODE); - encodeCommonEthertype(action, outBuffer); - } - - private static void encodePopPbbAction(ByteBuf outBuffer) { - outBuffer.writeShort(POP_PBB_CODE); - encodeRestOfActionHeader(outBuffer); - } - - private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(EXPERIMENTER_CODE); - outBuffer.writeShort(EXPERIMENTER_LENGTH); - ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); - outBuffer.writeInt(experimenter.getExperimenter().intValue()); - } - - private static void encodeRestOfActionHeader(ByteBuf outBuffer) { - outBuffer.writeShort(ACTION_HEADER_LENGTH); - ByteBufUtils.padBuffer(PADDING_IN_ACTION_HEADER, outBuffer); - } - - private static void encodeCommonEthertype(Action action, ByteBuf outBuffer) { - EthertypeAction ethertype = action.getAugmentation(EthertypeAction.class); - outBuffer.writeShort(LENGTH_OF_ETHERTYPE_ACTION); - outBuffer.writeShort(ethertype.getEthertype().getValue()); - ByteBufUtils.padBuffer(ETHERTYPE_ACTION_PADDING, outBuffer); - } - - /** - * Computes length of actions - * @param actionsList list of actions - * @return actions length - */ - public static int computeLengthOfActions(List actionsList) { - int lengthOfActions = 0; - if (actionsList != null) { - for (ActionsList list : actionsList) { - Action action = list.getAction(); - if (action.getType().isAssignableFrom(Output.class)) { - lengthOfActions += OUTPUT_LENGTH; - } else if (action.getType().isAssignableFrom(SetField.class)){ - List entries = action.getAugmentation(OxmFieldsAction.class).getMatchEntries(); - int actionLength = (2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES) + MatchSerializer.computeMatchEntriesLength(entries); - lengthOfActions += actionLength; - int paddingRemainder = actionLength % EncodeConstants.PADDING; - if ((paddingRemainder) != 0) { - lengthOfActions += EncodeConstants.PADDING - paddingRemainder; - } - } else { - lengthOfActions += LENGTH_OF_OTHER_ACTIONS; - } - } - } - return lengthOfActions; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; + +/** + * Serializes ofp_actions (OpenFlow v1.3) + * @author michal.polkorab + * @author timotej.kubas + */ +public abstract class ActionsSerializer { + + private static final byte OUTPUT_CODE = 0; + private static final byte COPY_TTL_OUT_CODE = 11; + private static final byte COPY_TTL_IN_CODE = 12; + private static final byte SET_MPLS_TTL_CODE = 15; + private static final byte DEC_MPLS_TTL_CODE = 16; + private static final byte PUSH_VLAN_CODE = 17; + private static final byte POP_VLAN_CODE = 18; + private static final byte PUSH_MPLS_CODE = 19; + private static final byte POP_MPLS_CODE = 20; + private static final byte SET_QUEUE_CODE = 21; + private static final byte GROUP_CODE = 22; + private static final byte SET_NW_TTL_CODE = 23; + private static final byte DEC_NW_TTL_CODE = 24; + private static final int SET_FIELD_CODE = 25; + private static final byte PUSH_PBB_CODE = 26; + private static final byte POP_PBB_CODE = 27; + private static final int EXPERIMENTER_CODE = 65535; // 0xFFFF + private static final byte OUTPUT_LENGTH = 16; + private static final byte SET_MPLS_TTL_LENGTH = 8; + private static final byte SET_QUEUE_LENGTH = 8; + private static final byte GROUP_LENGTH = 8; + private static final byte SET_NW_TTL_LENGTH = 8; + private static final byte EXPERIMENTER_LENGTH = 8; + private static final byte ACTION_HEADER_LENGTH = 8; + private static final byte LENGTH_OF_ETHERTYPE_ACTION = 8; + private static final byte LENGTH_OF_OTHER_ACTIONS = 8; + private static final byte SET_FIELD_HEADER_LENGTH = 4; // only type and length + private static final byte OUTPUT_PADDING = 6; + private static final byte SET_MPLS_TTL_PADDING = 3; + private static final byte SET_NW_TTL_PADDING = 3; + private static final byte PADDING_IN_ACTION_HEADER = 4; + private static final byte ETHERTYPE_ACTION_PADDING = 2; + + + /** + * Encodes actions to ByteBuf + * @param actionsList list of actions to be encoded + * @param outBuffer output ByteBuf + */ + public static void encodeActions(List actionsList, ByteBuf outBuffer) { + if (actionsList == null) { + return; + } + for (ActionsList list : actionsList) { + Action action = list.getAction(); + if (action.getType().isAssignableFrom(Output.class)) { + encodeOutputAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(CopyTtlOut.class)) { + encodeCopyTtlOutAction(outBuffer); + } else if (action.getType().isAssignableFrom(CopyTtlIn.class)) { + encodeCopyTtlInAction(outBuffer); + } else if (action.getType().isAssignableFrom(SetMplsTtl.class)) { + encodeSetMplsTtltAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(DecMplsTtl.class)) { + encodeDecMplsTtlAction(outBuffer); + } else if (action.getType().isAssignableFrom(PushVlan.class)) { + encodePushVlanAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(PopVlan.class)) { + encodePopVlanAction(outBuffer); + } else if (action.getType().isAssignableFrom(PushMpls.class)) { + encodePushMplsAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(PopMpls.class)) { + encodePopMplsAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(SetQueue.class)) { + encodeSetQueueAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(Group.class)) { + encodeGroupAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(SetNwTtl.class)) { + encodeSetNwTtlAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(DecNwTtl.class)) { + encodeDecNwTtlAction(outBuffer); + } else if (action.getType().isAssignableFrom(SetField.class)) { + encodeSetFieldAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(PushPbb.class)) { + encodePushPbbAction(action, outBuffer); + } else if (action.getType().isAssignableFrom(PopPbb.class)) { + encodePopPbbAction(outBuffer); + } else if (action.getType().isAssignableFrom(Experimenter.class)) { + encodeExperimenterAction(action, outBuffer); + } + } + } + + private static void encodeOutputAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(OUTPUT_CODE); + outBuffer.writeShort(OUTPUT_LENGTH); + PortAction port = action.getAugmentation(PortAction.class); + outBuffer.writeInt(port.getPort().getValue().intValue()); + MaxLengthAction maxlength = action.getAugmentation(MaxLengthAction.class); + outBuffer.writeShort(maxlength.getMaxLength()); + ByteBufUtils.padBuffer(OUTPUT_PADDING, outBuffer); + } + + private static void encodeCopyTtlOutAction(ByteBuf outBuffer) { + outBuffer.writeShort(COPY_TTL_OUT_CODE); + encodeRestOfActionHeader(outBuffer); + } + + private static void encodeCopyTtlInAction(ByteBuf outBuffer) { + outBuffer.writeShort(COPY_TTL_IN_CODE); + encodeRestOfActionHeader(outBuffer); + } + + private static void encodeSetMplsTtltAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(SET_MPLS_TTL_CODE); + outBuffer.writeShort(SET_MPLS_TTL_LENGTH); + MplsTtlAction mplsTtl = action.getAugmentation(MplsTtlAction.class); + outBuffer.writeByte(mplsTtl.getMplsTtl()); + ByteBufUtils.padBuffer(SET_MPLS_TTL_PADDING, outBuffer); + } + + private static void encodeDecMplsTtlAction(ByteBuf outBuffer) { + outBuffer.writeShort(DEC_MPLS_TTL_CODE); + encodeRestOfActionHeader(outBuffer); + } + + private static void encodePushVlanAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(PUSH_VLAN_CODE); + encodeCommonEthertype(action, outBuffer); + } + + private static void encodePopVlanAction(ByteBuf outBuffer) { + outBuffer.writeShort(POP_VLAN_CODE); + encodeRestOfActionHeader(outBuffer); + } + + private static void encodePushMplsAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(PUSH_MPLS_CODE); + encodeCommonEthertype(action, outBuffer); + } + + private static void encodePopMplsAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(POP_MPLS_CODE); + encodeCommonEthertype(action, outBuffer); + } + + private static void encodeSetQueueAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(SET_QUEUE_CODE); + outBuffer.writeShort(SET_QUEUE_LENGTH); + QueueIdAction queueId = action.getAugmentation(QueueIdAction.class); + outBuffer.writeInt(queueId.getQueueId().intValue()); + } + + private static void encodeGroupAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(GROUP_CODE); + outBuffer.writeShort(GROUP_LENGTH); + GroupIdAction groupId = action.getAugmentation(GroupIdAction.class); + outBuffer.writeInt(groupId.getGroupId().intValue()); + } + + private static void encodeSetNwTtlAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(SET_NW_TTL_CODE); + outBuffer.writeShort(SET_NW_TTL_LENGTH); + NwTtlAction nwTtl = action.getAugmentation(NwTtlAction.class); + outBuffer.writeByte(nwTtl.getNwTtl()); + ByteBufUtils.padBuffer(SET_NW_TTL_PADDING, outBuffer); + } + + private static void encodeDecNwTtlAction(ByteBuf outBuffer) { + outBuffer.writeShort(DEC_NW_TTL_CODE); + encodeRestOfActionHeader(outBuffer); + } + + private static void encodeSetFieldAction(Action action, ByteBuf outBuffer) { + OxmFieldsAction oxmField = action.getAugmentation(OxmFieldsAction.class); + int length = MatchSerializer.computeMatchEntriesLength(oxmField.getMatchEntries()) + SET_FIELD_HEADER_LENGTH; + outBuffer.writeShort(SET_FIELD_CODE); + int paddingRemainder = length % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + length += EncodeConstants.PADDING - paddingRemainder; + } + outBuffer.writeShort(length); + MatchSerializer.encodeMatchEntries(oxmField.getMatchEntries(), outBuffer); + ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, outBuffer); + } + + private static void encodePushPbbAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(PUSH_PBB_CODE); + encodeCommonEthertype(action, outBuffer); + } + + private static void encodePopPbbAction(ByteBuf outBuffer) { + outBuffer.writeShort(POP_PBB_CODE); + encodeRestOfActionHeader(outBuffer); + } + + private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(EXPERIMENTER_CODE); + outBuffer.writeShort(EXPERIMENTER_LENGTH); + ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); + outBuffer.writeInt(experimenter.getExperimenter().intValue()); + } + + private static void encodeRestOfActionHeader(ByteBuf outBuffer) { + outBuffer.writeShort(ACTION_HEADER_LENGTH); + ByteBufUtils.padBuffer(PADDING_IN_ACTION_HEADER, outBuffer); + } + + private static void encodeCommonEthertype(Action action, ByteBuf outBuffer) { + EthertypeAction ethertype = action.getAugmentation(EthertypeAction.class); + outBuffer.writeShort(LENGTH_OF_ETHERTYPE_ACTION); + outBuffer.writeShort(ethertype.getEthertype().getValue()); + ByteBufUtils.padBuffer(ETHERTYPE_ACTION_PADDING, outBuffer); + } + + /** + * Computes length of actions + * @param actionsList list of actions + * @return actions length + */ + public static int computeLengthOfActions(List actionsList) { + int lengthOfActions = 0; + if (actionsList != null) { + for (ActionsList list : actionsList) { + Action action = list.getAction(); + if (action.getType().isAssignableFrom(Output.class)) { + lengthOfActions += OUTPUT_LENGTH; + } else if (action.getType().isAssignableFrom(SetField.class)){ + List entries = action.getAugmentation(OxmFieldsAction.class).getMatchEntries(); + int actionLength = (2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES) + MatchSerializer.computeMatchEntriesLength(entries); + lengthOfActions += actionLength; + int paddingRemainder = actionLength % EncodeConstants.PADDING; + if ((paddingRemainder) != 0) { + lengthOfActions += EncodeConstants.PADDING - paddingRemainder; + } + } else { + lengthOfActions += LENGTH_OF_OTHER_ACTIONS; + } + } + } + return lengthOfActions; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtils.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtils.java index 2e633386..a1dced8f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtils.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtils.java @@ -1,218 +1,225 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ - -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; - -import com.google.common.base.Joiner; - -/** Class for common operations on ByteBuf - * @author michal.polkorab - * @author timotej.kubas - */ -public abstract class ByteBufUtils { - - /** - * Converts ByteBuf into String - * @param bb input ByteBuf - * @return String - */ - public static String byteBufToHexString(ByteBuf bb) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < bb.readableBytes(); i++) { - short b = bb.getUnsignedByte(i); - sb.append(String.format("%02x ", b)); - } - return sb.toString(); - } - - /** - * Converts String into byte[] - * @param hexSrc input String - * @return byte[] filled with input data - */ - public static byte[] hexStringToBytes(String hexSrc) { - return hexStringToBytes(hexSrc, true); - } - - /** - * Converts String into byte[] - * @param hexSrc input String - * @param withSpaces if there are spaces in string - * @return byte[] filled with input data - */ - public static byte[] hexStringToBytes(String hexSrc, boolean withSpaces ) { - String splitPattern = "\\s+"; - if (!withSpaces) { - splitPattern = "(?<=\\G.{2})"; - } - - String[] byteChips = hexSrc.split(splitPattern); - byte[] result = new byte[byteChips.length]; - for (int i = 0; i < byteChips.length; i++) { - result[i] = (byte) Short.parseShort(byteChips[i], 16); - } - return result; - } - - /** - * Creates ByteBuf filled with specified data - * @param hexSrc input String of bytes in hex format - * @return ByteBuf with specified hexString converted - */ - public static ByteBuf hexStringToByteBuf(String hexSrc) { - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - hexStringToByteBuf(hexSrc, out); - return out; - } - - /** - * Creates ByteBuf filled with specified data - * @param hexSrc input String of bytes in hex format - * @param out ByteBuf with specified hexString converted - */ - public static void hexStringToByteBuf(String hexSrc, ByteBuf out) { - out.writeBytes(hexStringToBytes(hexSrc)); - } - - /** - * Fills specified ByteBuf with 0 (zeros) of desired length, used for padding - * @param length - * @param out ByteBuf to be padded - */ - public static void padBuffer(int length, ByteBuf out) { - for (int i = 0; i < length; i++) { - out.writeByte(0); - } - } - - /** - * Create standard OF header - * @param factory serialization factory - * @param message POJO - * @param out writing buffer - */ - public static void writeOFHeader(OFSerializer factory, E message, ByteBuf out) { - out.writeByte(message.getVersion()); - out.writeByte(factory.getMessageType()); - out.writeShort(factory.computeLength(message)); - out.writeInt(message.getXid().intValue()); - - } - - /** - * Fills the bitmask from boolean map where key is bit position - * @param booleanMap bit to boolean mapping - * @return bit mask - */ - public static int fillBitMaskFromMap(Map booleanMap) { - int bitmask = 0; - - for (Entry iterator : booleanMap.entrySet()) { - if (iterator.getValue() != null && iterator.getValue().booleanValue()) { - bitmask |= 1 << iterator.getKey(); - } - } - return bitmask; - } - - /** - * Fills the bitmask from boolean list where key is bit position - * @param booleanList bit to boolean mapping - * @return bit mask - */ - public static int[] fillBitMaskFromList(List booleanList) { - int[] bitmask; - int index = 0; - int arrayIndex = 0; - if ((booleanList.size() % Integer.SIZE) != 0) { - bitmask = new int[booleanList.size() / Integer.SIZE + 1]; - } else { - bitmask = new int[booleanList.size() / Integer.SIZE]; - } - for (Boolean currElement : booleanList) { - if (currElement != null && currElement.booleanValue()) { - bitmask[arrayIndex] |= 1 << index; - } - index++; - arrayIndex = index / Integer.SIZE; - } - return bitmask; - } - - /** - * Converts byte array into String - * @param array input byte array - * @return String - */ - public static String bytesToHexString(byte[] array) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < array.length; i++) { - short b = array[i]; - sb.append(String.format("%02x ", b)); - } - return sb.toString(); - } - - /** - * Converts macAddress to byte array - * @param macAddress - * @return byte representation of mac address - * @see {@link MacAddress} - */ - public static byte[] macAddressToBytes(String macAddress) { - String[] sequences = macAddress.split(":"); - byte[] result = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - for (int i = 0; i < sequences.length; i++) { - result[i] = (byte) Short.parseShort(sequences[i], 16); - } - return result; - } - - /** - * Converts mac address represented in bytes to String - * @param address - * @return String representation of mac address - * @see {@link MacAddress} - */ - public static String macAddressToString(byte[] address) { - List groups = new ArrayList<>(); - for(int i=0; i < EncodeConstants.MAC_ADDRESS_LENGTH; i++){ - groups.add(String.format("%02X", address[i])); - } - Joiner joiner = Joiner.on(":"); - return joiner.join(groups); - } - - /** - * Reads and parses port name from ByteBuf - * @param rawMessage - * @param length maximal length of String - * @return String with name of port - */ - public static String decodeNullTerminatedString(ByteBuf rawMessage, int length) { - byte[] name = new byte[EncodeConstants.MAX_PORT_NAME_LENGTH]; - rawMessage.readBytes(name); - int index = 0; - for (int i = 0; i < name.length; i++) { - if (name[i] != 0) { - index++; - } else { - break; - } - } - byte[] correctName = Arrays.copyOf(name, index); - return new String(correctName); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; + +import com.google.common.base.Joiner; + +/** Class for common operations on ByteBuf + * @author michal.polkorab + * @author timotej.kubas + */ +public abstract class ByteBufUtils { + + /** + * Converts ByteBuf into String + * @param bb input ByteBuf + * @return String + */ + public static String byteBufToHexString(ByteBuf bb) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < bb.readableBytes(); i++) { + short b = bb.getUnsignedByte(i); + sb.append(String.format("%02x ", b)); + } + return sb.toString(); + } + + /** + * Converts String into byte[] + * @param hexSrc input String + * @return byte[] filled with input data + */ + public static byte[] hexStringToBytes(String hexSrc) { + return hexStringToBytes(hexSrc, true); + } + + /** + * Converts String into byte[] + * @param hexSrc input String + * @param withSpaces if there are spaces in string + * @return byte[] filled with input data + */ + public static byte[] hexStringToBytes(String hexSrc, boolean withSpaces ) { + String splitPattern = "\\s+"; + if (!withSpaces) { + splitPattern = "(?<=\\G.{2})"; + } + + String[] byteChips = hexSrc.split(splitPattern); + byte[] result = new byte[byteChips.length]; + for (int i = 0; i < byteChips.length; i++) { + result[i] = (byte) Short.parseShort(byteChips[i], 16); + } + return result; + } + + /** + * Creates ByteBuf filled with specified data + * @param hexSrc input String of bytes in hex format + * @return ByteBuf with specified hexString converted + */ + public static ByteBuf hexStringToByteBuf(String hexSrc) { + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + hexStringToByteBuf(hexSrc, out); + return out; + } + + /** + * Creates ByteBuf filled with specified data + * @param hexSrc input String of bytes in hex format + * @param out ByteBuf with specified hexString converted + */ + public static void hexStringToByteBuf(String hexSrc, ByteBuf out) { + out.writeBytes(hexStringToBytes(hexSrc)); + } + + /** + * Fills specified ByteBuf with 0 (zeros) of desired length, used for padding + * @param length + * @param out ByteBuf to be padded + */ + public static void padBuffer(int length, ByteBuf out) { + for (int i = 0; i < length; i++) { + out.writeByte(0); + } + } + + /** + * Create standard OF header + * @param factory serialization factory + * @param message POJO + * @param out writing buffer + */ + public static void writeOFHeader(OFSerializer factory, E message, ByteBuf out) { + out.writeByte(message.getVersion()); + out.writeByte(factory.getMessageType()); + out.writeShort(factory.computeLength(message)); + out.writeInt(message.getXid().intValue()); + + } + + /** + * Fills the bitmask from boolean map where key is bit position + * @param booleanMap bit to boolean mapping + * @return bit mask + */ + public static int fillBitMaskFromMap(Map booleanMap) { + int bitmask = 0; + + for (Entry iterator : booleanMap.entrySet()) { + if (iterator.getValue() != null && iterator.getValue().booleanValue()) { + bitmask |= 1 << iterator.getKey(); + } + } + return bitmask; + } + + /** + * Fills the bitmask from boolean list where key is bit position + * @param booleanList bit to boolean mapping + * @return bit mask + */ + public static int[] fillBitMaskFromList(List booleanList) { + int[] bitmask; + int index = 0; + int arrayIndex = 0; + if ((booleanList.size() % Integer.SIZE) != 0) { + bitmask = new int[booleanList.size() / Integer.SIZE + 1]; + } else { + bitmask = new int[booleanList.size() / Integer.SIZE]; + } + for (Boolean currElement : booleanList) { + if (currElement != null && currElement.booleanValue()) { + bitmask[arrayIndex] |= 1 << index; + } + index++; + arrayIndex = index / Integer.SIZE; + } + return bitmask; + } + + /** + * Converts byte array into String + * @param array input byte array + * @return String + */ + public static String bytesToHexString(byte[] array) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < array.length; i++) { + short b = array[i]; + sb.append(String.format("%02x ", b)); + } + return sb.toString(); + } + + /** + * Converts macAddress to byte array + * @param macAddress + * @return byte representation of mac address + * @see {@link MacAddress} + */ + public static byte[] macAddressToBytes(String macAddress) { + String[] sequences = macAddress.split(":"); + byte[] result = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + for (int i = 0; i < sequences.length; i++) { + result[i] = (byte) Short.parseShort(sequences[i], 16); + } + return result; + } + + /** + * Converts mac address represented in bytes to String + * @param address + * @return String representation of mac address + * @see {@link MacAddress} + */ + public static String macAddressToString(byte[] address) { + List groups = new ArrayList<>(); + for(int i=0; i < EncodeConstants.MAC_ADDRESS_LENGTH; i++){ + groups.add(String.format("%02X", address[i])); + } + Joiner joiner = Joiner.on(":"); + return joiner.join(groups); + } + + /** + * Reads and parses port name from ByteBuf + * @param rawMessage + * @param length maximal length of String + * @return String with name of port + */ + public static String decodeNullTerminatedString(ByteBuf rawMessage, int length) { + byte[] name = new byte[EncodeConstants.MAX_PORT_NAME_LENGTH]; + rawMessage.readBytes(name); + int index = 0; + for (int i = 0; i < name.length; i++) { + if (name[i] != 0) { + index++; + } else { + break; + } + } + byte[] correctName = Arrays.copyOf(name, index); + return new String(correctName); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/EncodeConstants.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/EncodeConstants.java index 74d7ce31..098ba8d9 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/EncodeConstants.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/EncodeConstants.java @@ -1,38 +1,45 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -/** - * Stores common constants - * @author michal.polkorab - */ -public abstract class EncodeConstants { - - /** Default OF padding (in bytes) */ - public static final byte PADDING = EncodeConstants.SIZE_OF_LONG_IN_BYTES; - /** OpenFlow v1.0 wire protocol number */ - public static final byte OF10_VERSION_ID = 0x01; - /** OpenFlow v1.0 wire protocol number */ - public static final byte OF13_VERSION_ID = 0x04; - - /** Length of mac address */ - public static final byte MAC_ADDRESS_LENGTH = 6; - /** Number of groups in ipv4 address */ - public static final byte GROUPS_IN_IPV4_ADDRESS = 4; - /** Number of groups in ipv6 address */ - public static final byte GROUPS_IN_IPV6_ADDRESS = 8; - /** Length of ipv6 address in bytes */ - public static final byte SIZE_OF_IPV6_ADDRESS_IN_BYTES = (8 * Short.SIZE) / Byte.SIZE; - - /** Length of long in bytes */ - public static final byte SIZE_OF_LONG_IN_BYTES = Long.SIZE / Byte.SIZE; - /** Length of int in bytes */ - public static final byte SIZE_OF_INT_IN_BYTES = Integer.SIZE / Byte.SIZE; - /** Length of short in bytes */ - public static final byte SIZE_OF_SHORT_IN_BYTES = Short.SIZE / Byte.SIZE; - /** Length of byte in bytes */ - public static final byte SIZE_OF_BYTE_IN_BYTES = Byte.SIZE / Byte.SIZE; - - - /** OF v1.0 maximal port name length */ - public static final byte MAX_PORT_NAME_LENGTH = 16; -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +/** + * Stores common constants + * @author michal.polkorab + */ +public abstract class EncodeConstants { + + /** Default OF padding (in bytes) */ + public static final byte PADDING = EncodeConstants.SIZE_OF_LONG_IN_BYTES; + /** OpenFlow v1.0 wire protocol number */ + public static final byte OF10_VERSION_ID = 0x01; + /** OpenFlow v1.0 wire protocol number */ + public static final byte OF13_VERSION_ID = 0x04; + + /** Length of mac address */ + public static final byte MAC_ADDRESS_LENGTH = 6; + /** Number of groups in ipv4 address */ + public static final byte GROUPS_IN_IPV4_ADDRESS = 4; + /** Number of groups in ipv6 address */ + public static final byte GROUPS_IN_IPV6_ADDRESS = 8; + /** Length of ipv6 address in bytes */ + public static final byte SIZE_OF_IPV6_ADDRESS_IN_BYTES = (8 * Short.SIZE) / Byte.SIZE; + + /** Length of long in bytes */ + public static final byte SIZE_OF_LONG_IN_BYTES = Long.SIZE / Byte.SIZE; + /** Length of int in bytes */ + public static final byte SIZE_OF_INT_IN_BYTES = Integer.SIZE / Byte.SIZE; + /** Length of short in bytes */ + public static final byte SIZE_OF_SHORT_IN_BYTES = Short.SIZE / Byte.SIZE; + /** Length of byte in bytes */ + public static final byte SIZE_OF_BYTE_IN_BYTES = Byte.SIZE / Byte.SIZE; + + + /** OF v1.0 maximal port name length */ + public static final byte MAX_PORT_NAME_LENGTH = 16; +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializer.java index 078b5d89..e77daca1 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsDeserializer.java @@ -1,134 +1,141 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.InstructionsBuilder; - -import io.netty.buffer.ByteBuf; - -/** - * Deserializes ofp_instruction (OpenFlow v1.3) structures - * @author michal.polkorab - * @author timotej.kubas - */ -public class InstructionsDeserializer { - - private static final byte WRITE_APPLY_CLEAR_ACTION_LENGTH = 8; - private static final byte EXPERIMENTER_HEADER_LENGTH = 8; - private static final byte GOTO_TABLE_PADDING = 3; - private static final byte WRITE_METADATA_PADDING = 4; - private static final byte ACTIONS_RELATED_INSTRUCTION_PADDING = 4; - - /** - * Creates list of instructions - * @param input - * @param length - * @return list of ofp_instruction - */ - public static List createInstructions(ByteBuf input, int length) { - List instructions = new ArrayList<>(); - if (input.readableBytes() != 0) { - int lengthOfInstructions = length; - while (lengthOfInstructions > 0) { - InstructionsBuilder builder = new InstructionsBuilder(); - int type = input.readUnsignedShort(); - int instructionLength = input.readUnsignedShort(); - lengthOfInstructions -= instructionLength; - switch (type) { - case 1: - createGotoTableInstruction(builder, input); - break; - case 2: - createMetadataInstruction(builder, input); - break; - case 3: - builder.setType(WriteActions.class); - createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH); - break; - case 4: - builder.setType(ApplyActions.class); - createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH); - break; - case 5: - builder.setType(ClearActions.class); - createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH); - break; - case 6: - builder.setType(Meter.class); - MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder(); - meterBuilder.setMeterId(input.readUnsignedInt()); - builder.addAugmentation(MeterIdInstruction.class, meterBuilder.build()); - break; - case 65535: - builder.setType(Experimenter.class); - ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder(); - expBuilder.setExperimenter(input.readUnsignedInt()); - int dataLength = instructionLength - EXPERIMENTER_HEADER_LENGTH; - if (dataLength > 0) { - byte[] data = new byte[dataLength]; - input.readBytes(data); - expBuilder.setData(data); - } - builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build()); - break; - default: - break; - } - instructions.add(builder.build()); - } - } - return instructions; - } - - private static void createGotoTableInstruction(InstructionsBuilder builder, - ByteBuf input) { - builder.setType(GotoTable.class); - TableIdInstructionBuilder tableBuilder = new TableIdInstructionBuilder(); - tableBuilder.setTableId(input.readUnsignedByte()); - builder.addAugmentation(TableIdInstruction.class, tableBuilder.build()); - input.skipBytes(GOTO_TABLE_PADDING); - } - - private static void createMetadataInstruction(InstructionsBuilder builder, - ByteBuf input) { - input.skipBytes(WRITE_METADATA_PADDING); - builder.setType(WriteMetadata.class); - MetadataInstructionBuilder metadataBuilder = new MetadataInstructionBuilder(); - byte[] metadata = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; - input.readBytes(metadata); - metadataBuilder.setMetadata(metadata); - byte[] metadata_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; - input.readBytes(metadata_mask); - metadataBuilder.setMetadata(metadata_mask); - builder.addAugmentation(MetadataInstruction.class, metadataBuilder.build()); - } - - private static void createActionRelatedInstruction(ByteBuf input, - InstructionsBuilder builder, int instructionLength) { - input.skipBytes(ACTIONS_RELATED_INSTRUCTION_PADDING); - ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder(); - actionsBuilder.setActionsList(ActionsDeserializer.createActionsList(input, instructionLength)); - builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.InstructionsBuilder; + +import io.netty.buffer.ByteBuf; + +/** + * Deserializes ofp_instruction (OpenFlow v1.3) structures + * @author michal.polkorab + * @author timotej.kubas + */ +public class InstructionsDeserializer { + + private static final byte WRITE_APPLY_CLEAR_ACTION_LENGTH = 8; + private static final byte EXPERIMENTER_HEADER_LENGTH = 8; + private static final byte GOTO_TABLE_PADDING = 3; + private static final byte WRITE_METADATA_PADDING = 4; + private static final byte ACTIONS_RELATED_INSTRUCTION_PADDING = 4; + + /** + * Creates list of instructions + * @param input + * @param length + * @return list of ofp_instruction + */ + public static List createInstructions(ByteBuf input, int length) { + List instructions = new ArrayList<>(); + if (input.readableBytes() != 0) { + int lengthOfInstructions = length; + while (lengthOfInstructions > 0) { + InstructionsBuilder builder = new InstructionsBuilder(); + int type = input.readUnsignedShort(); + int instructionLength = input.readUnsignedShort(); + lengthOfInstructions -= instructionLength; + switch (type) { + case 1: + createGotoTableInstruction(builder, input); + break; + case 2: + createMetadataInstruction(builder, input); + break; + case 3: + builder.setType(WriteActions.class); + createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH); + break; + case 4: + builder.setType(ApplyActions.class); + createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH); + break; + case 5: + builder.setType(ClearActions.class); + createActionRelatedInstruction(input, builder, instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH); + break; + case 6: + builder.setType(Meter.class); + MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder(); + meterBuilder.setMeterId(input.readUnsignedInt()); + builder.addAugmentation(MeterIdInstruction.class, meterBuilder.build()); + break; + case 65535: + builder.setType(Experimenter.class); + ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder(); + expBuilder.setExperimenter(input.readUnsignedInt()); + int dataLength = instructionLength - EXPERIMENTER_HEADER_LENGTH; + if (dataLength > 0) { + byte[] data = new byte[dataLength]; + input.readBytes(data); + expBuilder.setData(data); + } + builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build()); + break; + default: + break; + } + instructions.add(builder.build()); + } + } + return instructions; + } + + private static void createGotoTableInstruction(InstructionsBuilder builder, + ByteBuf input) { + builder.setType(GotoTable.class); + TableIdInstructionBuilder tableBuilder = new TableIdInstructionBuilder(); + tableBuilder.setTableId(input.readUnsignedByte()); + builder.addAugmentation(TableIdInstruction.class, tableBuilder.build()); + input.skipBytes(GOTO_TABLE_PADDING); + } + + private static void createMetadataInstruction(InstructionsBuilder builder, + ByteBuf input) { + input.skipBytes(WRITE_METADATA_PADDING); + builder.setType(WriteMetadata.class); + MetadataInstructionBuilder metadataBuilder = new MetadataInstructionBuilder(); + byte[] metadata = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + input.readBytes(metadata); + metadataBuilder.setMetadata(metadata); + byte[] metadata_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + input.readBytes(metadata_mask); + metadataBuilder.setMetadata(metadata_mask); + builder.addAugmentation(MetadataInstruction.class, metadataBuilder.build()); + } + + private static void createActionRelatedInstruction(ByteBuf input, + InstructionsBuilder builder, int instructionLength) { + input.skipBytes(ACTIONS_RELATED_INSTRUCTION_PADDING); + ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder(); + actionsBuilder.setActionsList(ActionsDeserializer.createActionsList(input, instructionLength)); + builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build()); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializer.java index e777525e..020a5efe 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/InstructionsSerializer.java @@ -1,139 +1,146 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; - -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Instruction; - -/** - * Serializes ofp_instruction (OpenFlow v 1.3) structure - * @author michal.polkorab - * @author timotej.kubas - */ -public abstract class InstructionsSerializer { - - private static final byte GOTO_TABLE_TYPE = 1; - private static final byte WRITE_METADATA_TYPE = 2; - private static final byte WRITE_ACTIONS_TYPE = 3; - private static final byte APPLY_ACTIONS_TYPE = 4; - private static final byte CLEAR_ACTIONS_TYPE = 5; - private static final byte METER_TYPE = 6; - private static final byte EXPERIMENTER_TYPE = 7; - private static final byte GOTO_TABLE_LENGTH = 8; - private static final byte WRITE_METADATA_LENGTH = 24; - private static final byte WRITE_ACTIONS_LENGTH = 8; - private static final byte APPLY_ACTIONS_LENGTH = 8; - private static final byte CLEAR_ACTIONS_LENGTH = 8; - private static final byte METER_LENGTH = 8; - private static final byte EXPERIMENTER_LENGTH = 8; - private static final byte PADDING_IN_GOTO_TABLE = 3; - private static final byte PADDING_IN_WRITE_METADATA = 4; - private static final byte PADDING_IN_CLEAR_ACTIONS = 4; - - /** - * Encodes instructions - * @param instructions List of instructions - * @param out output buffer - */ - public static void encodeInstructions(List instructions, ByteBuf out) { - if (instructions != null) { - for (Instructions instruction : instructions) { - Class type = instruction.getType(); - if (type.isAssignableFrom(GotoTable.class)) { - writeTypeAndLength(out, GOTO_TABLE_TYPE, GOTO_TABLE_LENGTH); - out.writeByte(instruction.getAugmentation(TableIdInstruction.class).getTableId()); - ByteBufUtils.padBuffer(PADDING_IN_GOTO_TABLE, out); - } else if (type.isAssignableFrom(WriteMetadata.class)) { - writeTypeAndLength(out, WRITE_METADATA_TYPE, WRITE_METADATA_LENGTH); - ByteBufUtils.padBuffer(PADDING_IN_WRITE_METADATA, out); - MetadataInstruction metadata = instruction.getAugmentation(MetadataInstruction.class); - out.writeBytes(metadata.getMetadata()); - out.writeBytes(metadata.getMetadataMask()); - } else if (type.isAssignableFrom(WriteActions.class)) { - writeActionsInstruction(out, instruction, WRITE_ACTIONS_TYPE); - } else if (type.isAssignableFrom(ApplyActions.class)) { - writeActionsInstruction(out, instruction, APPLY_ACTIONS_TYPE); - } else if (type.isAssignableFrom(ClearActions.class)) { - writeTypeAndLength(out, CLEAR_ACTIONS_TYPE, CLEAR_ACTIONS_LENGTH); - ByteBufUtils.padBuffer(PADDING_IN_CLEAR_ACTIONS, out); - } else if (type.isAssignableFrom(Meter.class)) { - writeTypeAndLength(out, METER_TYPE, METER_LENGTH); - out.writeInt(instruction.getAugmentation(MeterIdInstruction.class).getMeterId().intValue()); - } else if (type.isAssignableFrom(Experimenter.class)) { - ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); - byte[] data = experimenter.getData(); - writeTypeAndLength(out, EXPERIMENTER_TYPE, EXPERIMENTER_LENGTH + data.length); - out.writeInt(experimenter.getExperimenter().intValue()); - out.writeBytes(data); - } - } - } - - } - - private static void writeTypeAndLength(ByteBuf out, int type, int length) { - out.writeShort(type); - out.writeShort(length); - } - - private static void writeActionsInstruction(ByteBuf out, - Instructions instruction, int type) { - final byte ACTIONS_INSTRUCTION_LENGTH = 8; - final byte PADDING_IN_ACTIONS_INSTRUCTION = 4; - out.writeShort(type); - List actions = instruction.getAugmentation(ActionsInstruction.class).getActionsList(); - out.writeShort(ACTIONS_INSTRUCTION_LENGTH + ActionsSerializer.computeLengthOfActions(actions)); - ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out); - ActionsSerializer.encodeActions(actions, out); - } - - /** - * Computes length of instructions - * @param instructions List of instructions - * @return length of instructions (in bytes) - */ - public static int computeInstructionsLength(List instructions) { - int length = 0; - if (instructions != null) { - for (Instructions instruction : instructions) { - Class type = instruction.getType(); - if (type.isAssignableFrom(GotoTable.class)) { - length += GOTO_TABLE_LENGTH; - } else if (type.isAssignableFrom(WriteMetadata.class)) { - length += WRITE_METADATA_LENGTH; - } else if (type.isAssignableFrom(WriteActions.class)) { - length += WRITE_ACTIONS_LENGTH + ActionsSerializer.computeLengthOfActions( - instruction.getAugmentation(ActionsInstruction.class).getActionsList()); - } else if (type.isAssignableFrom(ApplyActions.class)) { - length += APPLY_ACTIONS_LENGTH + ActionsSerializer.computeLengthOfActions( - instruction.getAugmentation(ActionsInstruction.class).getActionsList()); - } else if (type.isAssignableFrom(ClearActions.class)) { - length += CLEAR_ACTIONS_LENGTH; - } else if (type.isAssignableFrom(Meter.class)) { - length += METER_LENGTH; - } else if (type.isAssignableFrom(Experimenter.class)) { - ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); - byte[] data = experimenter.getData(); - length += EXPERIMENTER_LENGTH + data.length; - } - } - } - return length; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Instruction; + +/** + * Serializes ofp_instruction (OpenFlow v 1.3) structure + * @author michal.polkorab + * @author timotej.kubas + */ +public abstract class InstructionsSerializer { + + private static final byte GOTO_TABLE_TYPE = 1; + private static final byte WRITE_METADATA_TYPE = 2; + private static final byte WRITE_ACTIONS_TYPE = 3; + private static final byte APPLY_ACTIONS_TYPE = 4; + private static final byte CLEAR_ACTIONS_TYPE = 5; + private static final byte METER_TYPE = 6; + private static final byte EXPERIMENTER_TYPE = 7; + private static final byte GOTO_TABLE_LENGTH = 8; + private static final byte WRITE_METADATA_LENGTH = 24; + private static final byte WRITE_ACTIONS_LENGTH = 8; + private static final byte APPLY_ACTIONS_LENGTH = 8; + private static final byte CLEAR_ACTIONS_LENGTH = 8; + private static final byte METER_LENGTH = 8; + private static final byte EXPERIMENTER_LENGTH = 8; + private static final byte PADDING_IN_GOTO_TABLE = 3; + private static final byte PADDING_IN_WRITE_METADATA = 4; + private static final byte PADDING_IN_CLEAR_ACTIONS = 4; + + /** + * Encodes instructions + * @param instructions List of instructions + * @param out output buffer + */ + public static void encodeInstructions(List instructions, ByteBuf out) { + if (instructions != null) { + for (Instructions instruction : instructions) { + Class type = instruction.getType(); + if (type.isAssignableFrom(GotoTable.class)) { + writeTypeAndLength(out, GOTO_TABLE_TYPE, GOTO_TABLE_LENGTH); + out.writeByte(instruction.getAugmentation(TableIdInstruction.class).getTableId()); + ByteBufUtils.padBuffer(PADDING_IN_GOTO_TABLE, out); + } else if (type.isAssignableFrom(WriteMetadata.class)) { + writeTypeAndLength(out, WRITE_METADATA_TYPE, WRITE_METADATA_LENGTH); + ByteBufUtils.padBuffer(PADDING_IN_WRITE_METADATA, out); + MetadataInstruction metadata = instruction.getAugmentation(MetadataInstruction.class); + out.writeBytes(metadata.getMetadata()); + out.writeBytes(metadata.getMetadataMask()); + } else if (type.isAssignableFrom(WriteActions.class)) { + writeActionsInstruction(out, instruction, WRITE_ACTIONS_TYPE); + } else if (type.isAssignableFrom(ApplyActions.class)) { + writeActionsInstruction(out, instruction, APPLY_ACTIONS_TYPE); + } else if (type.isAssignableFrom(ClearActions.class)) { + writeTypeAndLength(out, CLEAR_ACTIONS_TYPE, CLEAR_ACTIONS_LENGTH); + ByteBufUtils.padBuffer(PADDING_IN_CLEAR_ACTIONS, out); + } else if (type.isAssignableFrom(Meter.class)) { + writeTypeAndLength(out, METER_TYPE, METER_LENGTH); + out.writeInt(instruction.getAugmentation(MeterIdInstruction.class).getMeterId().intValue()); + } else if (type.isAssignableFrom(Experimenter.class)) { + ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); + byte[] data = experimenter.getData(); + writeTypeAndLength(out, EXPERIMENTER_TYPE, EXPERIMENTER_LENGTH + data.length); + out.writeInt(experimenter.getExperimenter().intValue()); + out.writeBytes(data); + } + } + } + + } + + private static void writeTypeAndLength(ByteBuf out, int type, int length) { + out.writeShort(type); + out.writeShort(length); + } + + private static void writeActionsInstruction(ByteBuf out, + Instructions instruction, int type) { + final byte ACTIONS_INSTRUCTION_LENGTH = 8; + final byte PADDING_IN_ACTIONS_INSTRUCTION = 4; + out.writeShort(type); + List actions = instruction.getAugmentation(ActionsInstruction.class).getActionsList(); + out.writeShort(ACTIONS_INSTRUCTION_LENGTH + ActionsSerializer.computeLengthOfActions(actions)); + ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out); + ActionsSerializer.encodeActions(actions, out); + } + + /** + * Computes length of instructions + * @param instructions List of instructions + * @return length of instructions (in bytes) + */ + public static int computeInstructionsLength(List instructions) { + int length = 0; + if (instructions != null) { + for (Instructions instruction : instructions) { + Class type = instruction.getType(); + if (type.isAssignableFrom(GotoTable.class)) { + length += GOTO_TABLE_LENGTH; + } else if (type.isAssignableFrom(WriteMetadata.class)) { + length += WRITE_METADATA_LENGTH; + } else if (type.isAssignableFrom(WriteActions.class)) { + length += WRITE_ACTIONS_LENGTH + ActionsSerializer.computeLengthOfActions( + instruction.getAugmentation(ActionsInstruction.class).getActionsList()); + } else if (type.isAssignableFrom(ApplyActions.class)) { + length += APPLY_ACTIONS_LENGTH + ActionsSerializer.computeLengthOfActions( + instruction.getAugmentation(ActionsInstruction.class).getActionsList()); + } else if (type.isAssignableFrom(ClearActions.class)) { + length += CLEAR_ACTIONS_LENGTH; + } else if (type.isAssignableFrom(Meter.class)) { + length += METER_LENGTH; + } else if (type.isAssignableFrom(Experimenter.class)) { + ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); + byte[] data = experimenter.getData(); + length += EXPERIMENTER_LENGTH + data.length; + } + } + } + return length; + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java index 9df9d17d..668d6e41 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java @@ -1,547 +1,554 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry.PseudoField; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Joiner; - -/** - * Deserializes ofp_match (OpenFlow v1.3) and its oxm_fields structures - * @author timotej.kubas - * @author michal.polkorab - */ -public abstract class MatchDeserializer { - - private static final Logger LOGGER = LoggerFactory.getLogger(MatchDeserializer.class); - - /** - * Creates match - * @param in input ByteBuf - * @return ofp_match (OpenFlow v1.3) - */ - public static Match createMatch(ByteBuf in) { - if (in.readableBytes() > 0) { - MatchBuilder builder = new MatchBuilder(); - int type = in.readUnsignedShort(); - int length = in.readUnsignedShort(); - switch (type) { - case 0: - builder.setType(StandardMatchType.class); - break; - case 1: - builder.setType(OxmMatchType.class); - break; - default: - break; - } - builder.setMatchEntries(createMatchEntries(in, length - 2 * (EncodeConstants.SIZE_OF_SHORT_IN_BYTES))); - int paddingRemainder = length % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - in.skipBytes(EncodeConstants.PADDING - paddingRemainder); - } - return builder.build(); - } - return null; - } - - /** - * Deserializes single match entry (oxm_field) - * @param in input ByteBuf - * @param matchLength length of match entry - * @return MatchEntriesList list containing one match entry - */ - public static List createMatchEntry(ByteBuf in, int matchLength) { - return createMatchEntriesInternal(in, matchLength, true); - } - - /** - * @param in input ByteBuf - * @param matchLength length of match entries - * @return MatchEntriesList list of match entries - */ - public static List createMatchEntries(ByteBuf in, int matchLength) { - return createMatchEntriesInternal(in, matchLength, false); - } - - private static List createMatchEntriesInternal(ByteBuf in, int matchLength, boolean oneEntry) { - List matchEntriesList = new ArrayList<>(); - int currLength = 0; - while(currLength < matchLength) { - MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); - switch (in.readUnsignedShort()) { - case 0x0000: - matchEntriesBuilder.setOxmClass(Nxm0Class.class); - break; - case 0x0001: - matchEntriesBuilder.setOxmClass(Nxm1Class.class); - break; - case 0x8000: - matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); - break; - case 0xFFFF: - matchEntriesBuilder.setOxmClass(ExperimenterClass.class); - break; - default: - break; - } - - int fieldAndMask = in.readUnsignedByte(); - boolean hasMask = (fieldAndMask & 1) != 0; - matchEntriesBuilder.setHasMask(hasMask); - int matchField = fieldAndMask >> 1; - int matchEntryLength = in.readUnsignedByte(); - currLength += EncodeConstants.SIZE_OF_SHORT_IN_BYTES + - (2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES) + matchEntryLength; - - switch(matchField) { - case 0: - matchEntriesBuilder.setOxmMatchField(InPort.class); - PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder(); - port.setPortNumber(new PortNumber(in.readUnsignedInt())); - matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build()); - break; - case 1: - matchEntriesBuilder.setOxmMatchField(InPhyPort.class); - PortNumberMatchEntryBuilder phyPort = new PortNumberMatchEntryBuilder(); - phyPort.setPortNumber(new PortNumber(in.readUnsignedInt())); - matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, phyPort.build()); - break; - case 2: - matchEntriesBuilder.setOxmMatchField(Metadata.class); - addMetadataAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } - break; - case 3: - matchEntriesBuilder.setOxmMatchField(EthDst.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } - break; - case 4: - matchEntriesBuilder.setOxmMatchField(EthSrc.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } - break; - case 5: - matchEntriesBuilder.setOxmMatchField(EthType.class); - EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder(); - ethertypeBuilder.setEthType(new EtherType(in.readUnsignedShort())); - matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build()); - break; - case 6: - matchEntriesBuilder.setOxmMatchField(VlanVid.class); - VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder(); - int vidEntryValue = in.readUnsignedShort(); - vlanVidBuilder.setCfiBit((vidEntryValue & (1 << 12)) != 0); // cfi is 13-th bit - vlanVidBuilder.setVlanVid(vidEntryValue & ((1 << 12) - 1)); // value without 13-th bit - matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build()); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } - break; - case 7: - matchEntriesBuilder.setOxmMatchField(VlanPcp.class); - VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder(); - vlanPcpBuilder.setVlanPcp(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build()); - break; - case 8: - matchEntriesBuilder.setOxmMatchField(IpDscp.class); - DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder(); - dscpBuilder.setDscp(new Dscp(in.readUnsignedByte())); - matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build()); - break; - case 9: - matchEntriesBuilder.setOxmMatchField(IpEcn.class); - EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder(); - ecnBuilder.setEcn(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build()); - break; - case 10: - matchEntriesBuilder.setOxmMatchField(IpProto.class); - ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder(); - protoNumberBuilder.setProtocolNumber(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build()); - break; - case 11: - matchEntriesBuilder.setOxmMatchField(Ipv4Src.class); - LOGGER.warn("IPV4address(ipv4src): received but possible wrong deserialization"); - addIpv4AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 12: - matchEntriesBuilder.setOxmMatchField(Ipv4Dst.class); - LOGGER.warn("IPV4address(ipv4dst): received but possible wrong deserialization"); - addIpv4AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 13: - matchEntriesBuilder.setOxmMatchField(TcpSrc.class); - addPortAugmentation(null, in); - break; - case 14: - matchEntriesBuilder.setOxmMatchField(TcpDst.class); - addPortAugmentation(null, in); - break; - case 15: - matchEntriesBuilder.setOxmMatchField(UdpSrc.class); - addPortAugmentation(null, in); - break; - case 16: - matchEntriesBuilder.setOxmMatchField(UdpDst.class); - addPortAugmentation(null, in); - break; - case 17: - matchEntriesBuilder.setOxmMatchField(SctpSrc.class); - addPortAugmentation(null, in); - break; - case 18: - matchEntriesBuilder.setOxmMatchField(SctpDst.class); - addPortAugmentation(null, in); - break; - case 19: - matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class); - Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder(); - icmpv4TypeBuilder.setIcmpv4Type(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build()); - break; - case 20: - matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class); - Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder(); - icmpv4CodeBuilder.setIcmpv4Code(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build()); - break; - case 21: - matchEntriesBuilder.setOxmMatchField(ArpOp.class); - OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder(); - opcodeBuilder.setOpCode(in.readUnsignedShort()); - matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build()); - break; - case 22: - matchEntriesBuilder.setOxmMatchField(ArpSpa.class); - LOGGER.warn("IPV4address(arpspa): received but possible wrong deserialization"); - addIpv4AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 23: - matchEntriesBuilder.setOxmMatchField(ArpTpa.class); - LOGGER.warn("IPV4address(arptpa): received but possible wrong deserialization"); - addIpv4AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 24: - matchEntriesBuilder.setOxmMatchField(ArpSha.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } - break; - case 25: - matchEntriesBuilder.setOxmMatchField(ArpTha.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } - break; - case 26: - matchEntriesBuilder.setOxmMatchField(Ipv6Src.class); - // TODO - ipv6address - check format with tests - LOGGER.warn("IPV6address(Ipv6Src): received but possible wrong deserialization"); - addIpv6AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } - break; - case 27: - matchEntriesBuilder.setOxmMatchField(Ipv6Dst.class); - // TODO - ipv6address - check format with tests - LOGGER.warn("IPV6address(Ipv6Dst): received but possible wrong deserialization"); - addIpv6AddressAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } - break; - case 28: - matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class); - Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder(); - ipv6FlabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(in.readUnsignedInt())); - matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build()); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 29: - matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class); - Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder(); - icmpv6TypeBuilder.setIcmpv6Type(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build()); - break; - case 30: - matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class); - Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder(); - icmpv6CodeBuilder.setIcmpv6Code(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build()); - break; - case 31: - matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class); - // TODO - ipv6address - check format with tests - LOGGER.warn("IPV6address(Ipv6NdTarget): received but possible wrong deserialization"); - addIpv6AddressAugmentation(matchEntriesBuilder, in); - break; - case 32: - matchEntriesBuilder.setOxmMatchField(Ipv6NdSll.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - break; - case 33: - matchEntriesBuilder.setOxmMatchField(Ipv6NdTll.class); - addMacAddressAugmentation(matchEntriesBuilder, in); - break; - case 34: - matchEntriesBuilder.setOxmMatchField(MplsLabel.class); - MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder(); - mplsLabelBuilder.setMplsLabel(in.readUnsignedInt()); - matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build()); - break; - case 35: - matchEntriesBuilder.setOxmMatchField(MplsTc.class); - TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder(); - tcBuilder.setTc(in.readUnsignedByte()); - matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build()); - break; - case 36: - matchEntriesBuilder.setOxmMatchField(MplsBos.class); - BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder(); - if (in.readUnsignedByte() != 0) { - bosBuilder.setBos(true); - } else { - bosBuilder.setBos(false); - } - matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build()); - break; - case 37: - matchEntriesBuilder.setOxmMatchField(PbbIsid.class); - IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder(); - isidBuilder.setIsid(in.readUnsignedInt()); - matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build()); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } - break; - case 38: - matchEntriesBuilder.setOxmMatchField(TunnelId.class); - addMetadataAugmentation(matchEntriesBuilder, in); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } - break; - case 39: - matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class); - PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder(); - int bitmap = in.readUnsignedShort(); - final Boolean NONEXT = ((bitmap) & (1<<0)) != 0; - final Boolean ESP = ((bitmap) & (1<<1)) != 0; - final Boolean AUTH = ((bitmap) & (1<<2)) != 0; - final Boolean DEST = ((bitmap) & (1<<3)) != 0; - final Boolean FRAG = ((bitmap) & (1<<4)) != 0; - final Boolean ROUTER = ((bitmap) & (1<<5)) != 0; - final Boolean HOP = ((bitmap) & (1<<6)) != 0; - final Boolean UNREP = ((bitmap) & (1<<7)) != 0; - final Boolean UNSEQ = ((bitmap) & (1<<8)) != 0; - pseudoBuilder.setPseudoField(new PseudoField(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ)); - matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build()); - if (hasMask) { - addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } - break; - default: - break; - } - matchEntriesList.add(matchEntriesBuilder.build()); - if (oneEntry) { - break; - } - } - if ((matchLength - currLength) > 0) { - in.skipBytes(matchLength - currLength); - } - return matchEntriesList; - } - - private static void addMaskAugmentation(MatchEntriesBuilder builder, ByteBuf in, int matchEntryLength) { - MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder(); - byte[] mask = new byte[matchEntryLength]; - in.readBytes(mask); - maskBuilder.setMask(mask); - builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); - } - - private static void addIpv6AddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) { - Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder(); - List groups = new ArrayList<>(); - for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV6_ADDRESS; i++) { - groups.add(String.format("X", in.readUnsignedShort())); - } - Joiner joiner = Joiner.on(":"); - ipv6AddressBuilder.setIpv6Address(new Ipv6Address(joiner.join(groups))); - builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build()); - } - - private static void addMetadataAugmentation(MatchEntriesBuilder builder, ByteBuf in) { - MetadataMatchEntryBuilder metadata = new MetadataMatchEntryBuilder(); - byte[] metadataBytes = new byte[Long.SIZE/Byte.SIZE]; - in.readBytes(metadataBytes); - metadata.setMetadata(metadataBytes); - builder.addAugmentation(MetadataMatchEntry.class, metadata.build()); - } - - private static void addIpv4AddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) { - Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder(); - List groups = new ArrayList<>(); - for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { - groups.add(Short.toString(in.readUnsignedByte())); - } - Joiner joiner = Joiner.on("."); - ipv4AddressBuilder.setIpv4Address(new Ipv4Address(joiner.join(groups))); - builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build()); - } - - private static void addMacAddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) { - MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder(); - byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - in.readBytes(address); - macAddress.setMacAddress(new MacAddress(ByteBufUtils.macAddressToString(address))); - builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build()); - } - - private static void addPortAugmentation(MatchEntriesBuilder builder, ByteBuf in) { - PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder(); - portBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params. - xml.ns.yang.ietf.inet.types.rev100924.PortNumber(in.readUnsignedShort())); - builder.addAugmentation(PortMatchEntry.class, portBuilder.build()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry.PseudoField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Joiner; + +/** + * Deserializes ofp_match (OpenFlow v1.3) and its oxm_fields structures + * @author timotej.kubas + * @author michal.polkorab + */ +public abstract class MatchDeserializer { + + private static final Logger LOGGER = LoggerFactory.getLogger(MatchDeserializer.class); + + /** + * Creates match + * @param in input ByteBuf + * @return ofp_match (OpenFlow v1.3) + */ + public static Match createMatch(ByteBuf in) { + if (in.readableBytes() > 0) { + MatchBuilder builder = new MatchBuilder(); + int type = in.readUnsignedShort(); + int length = in.readUnsignedShort(); + switch (type) { + case 0: + builder.setType(StandardMatchType.class); + break; + case 1: + builder.setType(OxmMatchType.class); + break; + default: + break; + } + builder.setMatchEntries(createMatchEntries(in, length - 2 * (EncodeConstants.SIZE_OF_SHORT_IN_BYTES))); + int paddingRemainder = length % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + in.skipBytes(EncodeConstants.PADDING - paddingRemainder); + } + return builder.build(); + } + return null; + } + + /** + * Deserializes single match entry (oxm_field) + * @param in input ByteBuf + * @param matchLength length of match entry + * @return MatchEntriesList list containing one match entry + */ + public static List createMatchEntry(ByteBuf in, int matchLength) { + return createMatchEntriesInternal(in, matchLength, true); + } + + /** + * @param in input ByteBuf + * @param matchLength length of match entries + * @return MatchEntriesList list of match entries + */ + public static List createMatchEntries(ByteBuf in, int matchLength) { + return createMatchEntriesInternal(in, matchLength, false); + } + + private static List createMatchEntriesInternal(ByteBuf in, int matchLength, boolean oneEntry) { + List matchEntriesList = new ArrayList<>(); + int currLength = 0; + while(currLength < matchLength) { + MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); + switch (in.readUnsignedShort()) { + case 0x0000: + matchEntriesBuilder.setOxmClass(Nxm0Class.class); + break; + case 0x0001: + matchEntriesBuilder.setOxmClass(Nxm1Class.class); + break; + case 0x8000: + matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); + break; + case 0xFFFF: + matchEntriesBuilder.setOxmClass(ExperimenterClass.class); + break; + default: + break; + } + + int fieldAndMask = in.readUnsignedByte(); + boolean hasMask = (fieldAndMask & 1) != 0; + matchEntriesBuilder.setHasMask(hasMask); + int matchField = fieldAndMask >> 1; + int matchEntryLength = in.readUnsignedByte(); + currLength += EncodeConstants.SIZE_OF_SHORT_IN_BYTES + + (2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES) + matchEntryLength; + + switch(matchField) { + case 0: + matchEntriesBuilder.setOxmMatchField(InPort.class); + PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder(); + port.setPortNumber(new PortNumber(in.readUnsignedInt())); + matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build()); + break; + case 1: + matchEntriesBuilder.setOxmMatchField(InPhyPort.class); + PortNumberMatchEntryBuilder phyPort = new PortNumberMatchEntryBuilder(); + phyPort.setPortNumber(new PortNumber(in.readUnsignedInt())); + matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, phyPort.build()); + break; + case 2: + matchEntriesBuilder.setOxmMatchField(Metadata.class); + addMetadataAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); + } + break; + case 3: + matchEntriesBuilder.setOxmMatchField(EthDst.class); + addMacAddressAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); + } + break; + case 4: + matchEntriesBuilder.setOxmMatchField(EthSrc.class); + addMacAddressAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); + } + break; + case 5: + matchEntriesBuilder.setOxmMatchField(EthType.class); + EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder(); + ethertypeBuilder.setEthType(new EtherType(in.readUnsignedShort())); + matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build()); + break; + case 6: + matchEntriesBuilder.setOxmMatchField(VlanVid.class); + VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder(); + int vidEntryValue = in.readUnsignedShort(); + vlanVidBuilder.setCfiBit((vidEntryValue & (1 << 12)) != 0); // cfi is 13-th bit + vlanVidBuilder.setVlanVid(vidEntryValue & ((1 << 12) - 1)); // value without 13-th bit + matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build()); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + } + break; + case 7: + matchEntriesBuilder.setOxmMatchField(VlanPcp.class); + VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder(); + vlanPcpBuilder.setVlanPcp(in.readUnsignedByte()); + matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build()); + break; + case 8: + matchEntriesBuilder.setOxmMatchField(IpDscp.class); + DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder(); + dscpBuilder.setDscp(new Dscp(in.readUnsignedByte())); + matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build()); + break; + case 9: + matchEntriesBuilder.setOxmMatchField(IpEcn.class); + EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder(); + ecnBuilder.setEcn(in.readUnsignedByte()); + matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build()); + break; + case 10: + matchEntriesBuilder.setOxmMatchField(IpProto.class); + ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder(); + protoNumberBuilder.setProtocolNumber(in.readUnsignedByte()); + matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build()); + break; + case 11: + matchEntriesBuilder.setOxmMatchField(Ipv4Src.class); + LOGGER.warn("IPV4address(ipv4src): received but possible wrong deserialization"); + addIpv4AddressAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } + break; + case 12: + matchEntriesBuilder.setOxmMatchField(Ipv4Dst.class); + LOGGER.warn("IPV4address(ipv4dst): received but possible wrong deserialization"); + addIpv4AddressAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } + break; + case 13: + matchEntriesBuilder.setOxmMatchField(TcpSrc.class); + addPortAugmentation(null, in); + break; + case 14: + matchEntriesBuilder.setOxmMatchField(TcpDst.class); + addPortAugmentation(null, in); + break; + case 15: + matchEntriesBuilder.setOxmMatchField(UdpSrc.class); + addPortAugmentation(null, in); + break; + case 16: + matchEntriesBuilder.setOxmMatchField(UdpDst.class); + addPortAugmentation(null, in); + break; + case 17: + matchEntriesBuilder.setOxmMatchField(SctpSrc.class); + addPortAugmentation(null, in); + break; + case 18: + matchEntriesBuilder.setOxmMatchField(SctpDst.class); + addPortAugmentation(null, in); + break; + case 19: + matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class); + Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder(); + icmpv4TypeBuilder.setIcmpv4Type(in.readUnsignedByte()); + matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build()); + break; + case 20: + matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class); + Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder(); + icmpv4CodeBuilder.setIcmpv4Code(in.readUnsignedByte()); + matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build()); + break; + case 21: + matchEntriesBuilder.setOxmMatchField(ArpOp.class); + OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder(); + opcodeBuilder.setOpCode(in.readUnsignedShort()); + matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build()); + break; + case 22: + matchEntriesBuilder.setOxmMatchField(ArpSpa.class); + LOGGER.warn("IPV4address(arpspa): received but possible wrong deserialization"); + addIpv4AddressAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } + break; + case 23: + matchEntriesBuilder.setOxmMatchField(ArpTpa.class); + LOGGER.warn("IPV4address(arptpa): received but possible wrong deserialization"); + addIpv4AddressAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } + break; + case 24: + matchEntriesBuilder.setOxmMatchField(ArpSha.class); + addMacAddressAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); + } + break; + case 25: + matchEntriesBuilder.setOxmMatchField(ArpTha.class); + addMacAddressAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); + } + break; + case 26: + matchEntriesBuilder.setOxmMatchField(Ipv6Src.class); + // TODO - ipv6address - check format with tests + LOGGER.warn("IPV6address(Ipv6Src): received but possible wrong deserialization"); + addIpv6AddressAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); + } + break; + case 27: + matchEntriesBuilder.setOxmMatchField(Ipv6Dst.class); + // TODO - ipv6address - check format with tests + LOGGER.warn("IPV6address(Ipv6Dst): received but possible wrong deserialization"); + addIpv6AddressAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); + } + break; + case 28: + matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class); + Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder(); + ipv6FlabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(in.readUnsignedInt())); + matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build()); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } + break; + case 29: + matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class); + Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder(); + icmpv6TypeBuilder.setIcmpv6Type(in.readUnsignedByte()); + matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build()); + break; + case 30: + matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class); + Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder(); + icmpv6CodeBuilder.setIcmpv6Code(in.readUnsignedByte()); + matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build()); + break; + case 31: + matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class); + // TODO - ipv6address - check format with tests + LOGGER.warn("IPV6address(Ipv6NdTarget): received but possible wrong deserialization"); + addIpv6AddressAugmentation(matchEntriesBuilder, in); + break; + case 32: + matchEntriesBuilder.setOxmMatchField(Ipv6NdSll.class); + addMacAddressAugmentation(matchEntriesBuilder, in); + break; + case 33: + matchEntriesBuilder.setOxmMatchField(Ipv6NdTll.class); + addMacAddressAugmentation(matchEntriesBuilder, in); + break; + case 34: + matchEntriesBuilder.setOxmMatchField(MplsLabel.class); + MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder(); + mplsLabelBuilder.setMplsLabel(in.readUnsignedInt()); + matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build()); + break; + case 35: + matchEntriesBuilder.setOxmMatchField(MplsTc.class); + TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder(); + tcBuilder.setTc(in.readUnsignedByte()); + matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build()); + break; + case 36: + matchEntriesBuilder.setOxmMatchField(MplsBos.class); + BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder(); + if (in.readUnsignedByte() != 0) { + bosBuilder.setBos(true); + } else { + bosBuilder.setBos(false); + } + matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build()); + break; + case 37: + matchEntriesBuilder.setOxmMatchField(PbbIsid.class); + IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder(); + isidBuilder.setIsid(in.readUnsignedInt()); + matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build()); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } + break; + case 38: + matchEntriesBuilder.setOxmMatchField(TunnelId.class); + addMetadataAugmentation(matchEntriesBuilder, in); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES); + } + break; + case 39: + matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class); + PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder(); + int bitmap = in.readUnsignedShort(); + final Boolean NONEXT = ((bitmap) & (1<<0)) != 0; + final Boolean ESP = ((bitmap) & (1<<1)) != 0; + final Boolean AUTH = ((bitmap) & (1<<2)) != 0; + final Boolean DEST = ((bitmap) & (1<<3)) != 0; + final Boolean FRAG = ((bitmap) & (1<<4)) != 0; + final Boolean ROUTER = ((bitmap) & (1<<5)) != 0; + final Boolean HOP = ((bitmap) & (1<<6)) != 0; + final Boolean UNREP = ((bitmap) & (1<<7)) != 0; + final Boolean UNSEQ = ((bitmap) & (1<<8)) != 0; + pseudoBuilder.setPseudoField(new PseudoField(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ)); + matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build()); + if (hasMask) { + addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + } + break; + default: + break; + } + matchEntriesList.add(matchEntriesBuilder.build()); + if (oneEntry) { + break; + } + } + if ((matchLength - currLength) > 0) { + in.skipBytes(matchLength - currLength); + } + return matchEntriesList; + } + + private static void addMaskAugmentation(MatchEntriesBuilder builder, ByteBuf in, int matchEntryLength) { + MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder(); + byte[] mask = new byte[matchEntryLength]; + in.readBytes(mask); + maskBuilder.setMask(mask); + builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); + } + + private static void addIpv6AddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) { + Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder(); + List groups = new ArrayList<>(); + for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV6_ADDRESS; i++) { + groups.add(String.format("X", in.readUnsignedShort())); + } + Joiner joiner = Joiner.on(":"); + ipv6AddressBuilder.setIpv6Address(new Ipv6Address(joiner.join(groups))); + builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build()); + } + + private static void addMetadataAugmentation(MatchEntriesBuilder builder, ByteBuf in) { + MetadataMatchEntryBuilder metadata = new MetadataMatchEntryBuilder(); + byte[] metadataBytes = new byte[Long.SIZE/Byte.SIZE]; + in.readBytes(metadataBytes); + metadata.setMetadata(metadataBytes); + builder.addAugmentation(MetadataMatchEntry.class, metadata.build()); + } + + private static void addIpv4AddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) { + Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder(); + List groups = new ArrayList<>(); + for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { + groups.add(Short.toString(in.readUnsignedByte())); + } + Joiner joiner = Joiner.on("."); + ipv4AddressBuilder.setIpv4Address(new Ipv4Address(joiner.join(groups))); + builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build()); + } + + private static void addMacAddressAugmentation(MatchEntriesBuilder builder, ByteBuf in) { + MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder(); + byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + in.readBytes(address); + macAddress.setMacAddress(new MacAddress(ByteBufUtils.macAddressToString(address))); + builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build()); + } + + private static void addPortAugmentation(MatchEntriesBuilder builder, ByteBuf in) { + PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder(); + portBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params. + xml.ns.yang.ietf.inet.types.rev100924.PortNumber(in.readUnsignedShort())); + builder.addAugmentation(PortMatchEntry.class, portBuilder.build()); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java index 557ff7bc..5ba7a187 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java @@ -1,639 +1,646 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry.PseudoField; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Serializes ofp_match (OpenFlow v1.3) and its oxm_fields structures - * @author michal.polkorab - * @author timotej.kubas - */ -public class MatchSerializer { - private static final Logger LOGGER = LoggerFactory.getLogger(MatchSerializer.class); - private static final byte STANDARD_MATCH_TYPE_CODE = 0; - private static final byte OXM_MATCH_TYPE_CODE = 1; - private static final int NXM0_CLASS_CODE = 0x0000; - private static final int NXM1_CLASS_CODE = 0x0001; - private static final int OPENFLOW_BASIC_CLASS_CODE = 0x8000; - private static final int EXPERIMENTER_CLASS_CODE = 0xFFFF; - private static final byte MATCH_TYPE_AND_LENGTH_SIZE = 4; - private static final byte MATCH_ENTRY_HEADER_LENGTH = 4; - - /** - * Encodes match (OpenFlow v1.3) - * @param match ofp_match object - * @param out output ByteBuf - */ - public static void encodeMatch(Match match, ByteBuf out) { - if (match == null) { - LOGGER.debug("Match is null"); - return; - } - encodeType(match, out); - // Length of ofp_match (excluding padding) - int length = computeMatchLengthInternal(match); - out.writeShort(length); - encodeMatchEntries(match.getMatchEntries(), out); - int paddingRemainder = length % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, out); - } - } - - private static void encodeType(Match match, ByteBuf out) { - if (match.getType().isAssignableFrom(StandardMatchType.class)) { - out.writeShort(STANDARD_MATCH_TYPE_CODE); - } else if (match.getType().isAssignableFrom(OxmMatchType.class)) { - out.writeShort(OXM_MATCH_TYPE_CODE); - } - } - - /** - * Encodes MatchEntries - * @param matchEntries list of match entries (oxm_fields) - * @param out output ByteBuf - */ - public static void encodeMatchEntries(List matchEntries, ByteBuf out) { - if (matchEntries == null) { - LOGGER.warn("Match entries are null"); - return; - } - for (MatchEntries entry : matchEntries) { - encodeClass(entry.getOxmClass(), out); - encodeRest(entry, out); - } - } - - private static void encodeClass(Class clazz, ByteBuf out) { - if (clazz.isAssignableFrom(Nxm0Class.class)) { - out.writeShort(NXM0_CLASS_CODE); - } else if (clazz.isAssignableFrom(Nxm1Class.class)) { - out.writeShort(NXM1_CLASS_CODE); - } else if (clazz.isAssignableFrom(OpenflowBasicClass.class)) { - out.writeShort(OPENFLOW_BASIC_CLASS_CODE); - } else if (clazz.isAssignableFrom(ExperimenterClass.class)) { - out.writeShort(EXPERIMENTER_CLASS_CODE); - } - } - - private static void encodeRest(MatchEntries entry, ByteBuf out) { - int fieldValue = 0; - Class field = entry.getOxmMatchField(); - if (field.isAssignableFrom(InPort.class)) { - fieldValue = 0; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_INT_IN_BYTES); - out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); - } else if (field.isAssignableFrom(InPhyPort.class)) { - fieldValue = 1; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_INT_IN_BYTES); - out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); - } else if (field.isAssignableFrom(Metadata.class)) { - fieldValue = 2; - writeMetadataRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(EthDst.class)) { - fieldValue = 3; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(EthSrc.class)) { - fieldValue = 4; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(EthType.class)) { - fieldValue = 5; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(EthTypeMatchEntry.class).getEthType().getValue().shortValue()); - } else if (field.isAssignableFrom(VlanVid.class)) { - fieldValue = 6; - fieldValue = fieldValue << 1; - VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class); - int vlanVidValue = vlanVid.getVlanVid(); - if (vlanVid.isCfiBit()) { - short cfi = 1 << 12; // 13-th bit - vlanVidValue = vlanVidValue | cfi; - } - if (entry.isHasMask()) { - fieldValue = fieldValue | 1; - out.writeByte(fieldValue); - byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); - out.writeByte(EncodeConstants.SIZE_OF_SHORT_IN_BYTES + mask.length); - out.writeShort(vlanVidValue); - out.writeBytes(mask); - } else { - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(vlanVidValue); - } - } else if (field.isAssignableFrom(VlanPcp.class)) { - fieldValue = 7; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(VlanPcpMatchEntry.class).getVlanPcp().byteValue()); - } else if (field.isAssignableFrom(IpDscp.class)) { - fieldValue = 8; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(DscpMatchEntry.class).getDscp().getValue()); - } else if (field.isAssignableFrom(IpEcn.class)) { - fieldValue = 9; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(EcnMatchEntry.class).getEcn()); - } else if (field.isAssignableFrom(IpProto.class)) { - fieldValue = 10; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(ProtocolNumberMatchEntry.class).getProtocolNumber()); - } else if (field.isAssignableFrom(Ipv4Src.class)) { - fieldValue = 11; - writeIpv4AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv4Dst.class)) { - fieldValue = 12; - writeIpv4AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(TcpSrc.class)) { - fieldValue = 13; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(TcpDst.class)) { - fieldValue = 14; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(UdpSrc.class)) { - fieldValue = 15; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(UdpDst.class)) { - fieldValue = 16; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(SctpSrc.class)) { - fieldValue = 17; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(SctpDst.class)) { - fieldValue = 18; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); - } else if (field.isAssignableFrom(Icmpv4Type.class)) { - fieldValue = 19; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(Icmpv4TypeMatchEntry.class).getIcmpv4Type()); - } else if (field.isAssignableFrom(Icmpv4Code.class)) { - fieldValue = 20; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(Icmpv4CodeMatchEntry.class).getIcmpv4Code()); - } else if (field.isAssignableFrom(ArpOp.class)) { - fieldValue = 21; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(entry.getAugmentation(OpCodeMatchEntry.class).getOpCode()); - } else if (field.isAssignableFrom(ArpSpa.class)) { - fieldValue = 22; - writeIpv4AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(ArpTpa.class)) { - fieldValue = 23; - writeIpv4AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(ArpSha.class)) { - fieldValue = 24; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(ArpTha.class)) { - fieldValue = 25; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6Src.class)) { - fieldValue = 26; - writeIpv6AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6Dst.class)) { - fieldValue = 27; - writeIpv6AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6Flabel.class)) { - fieldValue = 28; - fieldValue = fieldValue << 1; - if (entry.isHasMask()) { - fieldValue = fieldValue | 1; - out.writeByte(fieldValue); - byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); - out.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES + mask.length); // 20 b + mask [OF 1.3.2 spec] - LOGGER.warn("Ipv6Flabel match entry: possible wrong length written (wrote 4 - maybe must be 3)"); - out.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue()); - out.writeBytes(entry.getAugmentation(MaskMatchEntry.class).getMask()); - } else { - out.writeByte(fieldValue); - out.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES); // 20 b [OF 1.3.2 spec] - LOGGER.warn("Ipv6Flabel match entry: possible wrong length written (wrote 4 - maybe must be 3)"); - out.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue()); - } - } else if (field.isAssignableFrom(Icmpv6Type.class)) { - fieldValue = 29; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(Icmpv6TypeMatchEntry.class).getIcmpv6Type()); - } else if (field.isAssignableFrom(Icmpv6Code.class)) { - fieldValue = 30; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(Icmpv6CodeMatchEntry.class).getIcmpv6Code()); - } else if (field.isAssignableFrom(Ipv6NdTarget.class)) { - fieldValue = 31; - writeIpv6AddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6NdSll.class)) { - fieldValue = 32; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6NdTll.class)) { - fieldValue = 33; - writeMacAddressRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(MplsLabel.class)) { - fieldValue = 34; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_INT_IN_BYTES); - LOGGER.warn("MplsLabel match entry: possible wrong length written (wrote 4 - maybe must be 3)"); - out.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue()); - } else if (field.isAssignableFrom(MplsTc.class)) { - fieldValue = 35; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeByte(entry.getAugmentation(TcMatchEntry.class).getTc()); - } else if (field.isAssignableFrom(MplsBos.class)) { - fieldValue = 36; - writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - out.writeBoolean(entry.getAugmentation(BosMatchEntry.class).isBos().booleanValue()); - } else if (field.isAssignableFrom(PbbIsid.class)) { - fieldValue = 37; - fieldValue = fieldValue << 1; - if (entry.isHasMask()) { - fieldValue = fieldValue | 1; - out.writeByte(fieldValue); - byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); - out.writeByte(EncodeConstants.SIZE_OF_LONG_IN_BYTES + mask.length); - LOGGER.warn("PbbIsid match entry: possible wrong length written (wrote 4 - maybe must be 3)"); - out.writeInt(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue()); - out.writeBytes(mask); - } else { - out.writeByte(fieldValue); - out.writeByte(EncodeConstants.SIZE_OF_LONG_IN_BYTES); - LOGGER.warn("PbbIsid match entry: possible wrong length written (wrote 4 - maybe must be 3)"); - out.writeInt(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue()); - } - } else if (field.isAssignableFrom(TunnelId.class)) { - fieldValue = 38; - writeMetadataRelatedEntry(entry, out, fieldValue); - } else if (field.isAssignableFrom(Ipv6Exthdr.class)) { - fieldValue = 39; - fieldValue = fieldValue << 1; - PseudoField pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField(); - Map map = new HashMap<>(); - map.put(0, pseudoField.isNonext()); - map.put(1, pseudoField.isEsp()); - map.put(2, pseudoField.isAuth()); - map.put(3, pseudoField.isDest()); - map.put(4, pseudoField.isFrag()); - map.put(5, pseudoField.isRouter()); - map.put(6, pseudoField.isHop()); - map.put(7, pseudoField.isUnrep()); - map.put(8, pseudoField.isUnseq()); - int bitmap = ByteBufUtils.fillBitMaskFromMap(map); - if (entry.isHasMask()) { - fieldValue = fieldValue | 1; - out.writeByte(fieldValue); - byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); - out.writeByte(EncodeConstants.SIZE_OF_SHORT_IN_BYTES + mask.length); - out.writeShort(bitmap); - out.writeBytes(mask); - } else { - out.writeByte(fieldValue); - out.writeByte(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.writeShort(bitmap); - } - } - } - - private static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, int length) { - int fieldAndMask = fieldValue << 1; - out.writeByte(fieldAndMask); - out.writeByte(length); - } - - private static void writeMetadataRelatedEntry(MatchEntries entry, ByteBuf out, int value) { - int fieldValue = value << 1; - if (entry.isHasMask()) { - fieldValue = fieldValue | 1; - out.writeByte(fieldValue); - byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); - out.writeByte(EncodeConstants.SIZE_OF_LONG_IN_BYTES + mask.length); - out.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata()); - out.writeBytes(mask); - } else { - out.writeByte(fieldValue); - out.writeByte(EncodeConstants.SIZE_OF_LONG_IN_BYTES); - out.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata()); - } - } - - private static void writeMacAddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) { - int fieldValue = value << 1; - if (entry.isHasMask()) { - fieldValue = fieldValue | 1; - out.writeByte(fieldValue); - byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); - out.writeByte(EncodeConstants.MAC_ADDRESS_LENGTH + mask.length); // 48 b + mask [OF 1.3.2 spec] - String macAddress = entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue(); - out.writeBytes(ByteBufUtils.macAddressToBytes(macAddress)); - out.writeBytes(mask); - } else { - out.writeByte(fieldValue); - out.writeByte(EncodeConstants.MAC_ADDRESS_LENGTH); // 48 b [OF 1.3.2 spec] - String macAddress = entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue(); - out.writeBytes(ByteBufUtils.macAddressToBytes(macAddress)); - } - } - - private static void writeIpv4AddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) { - int fieldValue = value << 1; - if (entry.isHasMask()) { - fieldValue = fieldValue | 1; - out.writeByte(fieldValue); - byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); - out.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES + mask.length); - writeIpv4Address(entry, out); - out.writeBytes(mask); - } else { - out.writeByte(fieldValue); - out.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES); - writeIpv4Address(entry, out); - } - } - - private static void writeIpv4Address(MatchEntries entry, ByteBuf out) { - String[] addressGroups = entry.getAugmentation(Ipv4AddressMatchEntry.class).getIpv4Address().getValue().split("\\."); - for (int i = 0; i < addressGroups.length; i++) { - out.writeByte(Integer.parseInt(addressGroups[i])); - } - } - - private static void writeIpv6AddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) { - int fieldValue = value << 1; - String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue(); - String[] address; - if (textAddress.equals("::")) { - address = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; - Arrays.fill(address, "0"); - } else { - address = parseIpv6Address(textAddress.split(":")); - } - if (entry.isHasMask()) { - fieldValue = fieldValue | 1; - out.writeByte(fieldValue); - byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); - out.writeByte(EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES + mask.length); - for (int i = 0; i < address.length; i++) { - out.writeShort(Integer.parseInt(address[i], 16)); - } - out.writeBytes(mask); - } else { - out.writeByte(fieldValue); - out.writeByte(EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - for (int i = 0; i < address.length; i++) { - out.writeShort(Integer.parseInt(address[i], 16)); - } - } - } - - private static String[] parseIpv6Address(String[] addressGroups) { - int countEmpty = 0; - for (int i = 0; i < addressGroups.length; i++) { - if (addressGroups[i].equals("")){ - countEmpty++; - } - } - String[] ready = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; - switch (countEmpty) { - case 0: - ready = addressGroups; - break; - case 1: - int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.length + 1; - int index = 0; - for (int i = 0; i < addressGroups.length; i++) { - if (addressGroups[i].equals("")) { - for (int j = 0; j < zerosToBePushed; j++) { - ready[index] = "0"; - index++; - } - } else { - ready[index] = addressGroups[i]; - index++; - } - } - break; - case 2: - Arrays.fill(ready, "0"); - ready[ready.length - 1] = addressGroups[addressGroups.length - 1]; - break; - default: - throw new IllegalStateException("Incorrect ipv6 address"); - } - return ready; - } - - /** - * Computes length of match (in bytes) - * @param match - * @return length of ofp_match (excluding padding) - */ - public static int computeMatchLengthInternal(Match match) { - int length = 0; - if (match != null) { - length += MATCH_TYPE_AND_LENGTH_SIZE + computeMatchEntriesLength(match.getMatchEntries()); - } - return length; - } - - /** - * Computes length of match (in bytes) - * @param match - * @return length of ofp_match (excluding padding) - */ - public static int computeMatchLength(Match match) { - int length = computeMatchLengthInternal(match); - int paddingRemainder = length % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - length += EncodeConstants.PADDING - paddingRemainder; - } - return length; - } - - /** - * Computes length of MatchEntries (in bytes) - * @param matchEntries list of match entries (oxm_fields) - * @return length of MatchEntries - */ - public static int computeMatchEntriesLength(List matchEntries) { - int length = 0; - if (matchEntries != null) { - for (MatchEntries entry : matchEntries) { - length += MATCH_ENTRY_HEADER_LENGTH; - Class field = entry.getOxmMatchField(); - if (field.isAssignableFrom(InPort.class)) { - length += EncodeConstants.SIZE_OF_INT_IN_BYTES; - } else if (field.isAssignableFrom(InPhyPort.class)) { - length += EncodeConstants.SIZE_OF_INT_IN_BYTES; - } else if (field.isAssignableFrom(Metadata.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } else if (field.isAssignableFrom(EthDst.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(EthSrc.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(EthType.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(VlanVid.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } else if (field.isAssignableFrom(VlanPcp.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(IpDscp.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(IpEcn.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(IpProto.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(Ipv4Src.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(Ipv4Dst.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(TcpSrc.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(TcpDst.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(UdpSrc.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(UdpDst.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(SctpSrc.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(SctpDst.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(Icmpv4Type.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(Icmpv4Code.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(ArpOp.class)) { - length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; - } else if (field.isAssignableFrom(ArpSpa.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(ArpTpa.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(ArpSha.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(ArpTha.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(Ipv6Src.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6Dst.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6Flabel.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(Icmpv6Type.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(Icmpv6Code.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(Ipv6NdTarget.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6NdSll.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(Ipv6NdTll.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); - } else if (field.isAssignableFrom(MplsLabel.class)) { - length += EncodeConstants.SIZE_OF_INT_IN_BYTES; - } else if (field.isAssignableFrom(MplsTc.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(MplsBos.class)) { - length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; - } else if (field.isAssignableFrom(PbbIsid.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); - } else if (field.isAssignableFrom(TunnelId.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_LONG_IN_BYTES); - } else if (field.isAssignableFrom(Ipv6Exthdr.class)) { - length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - } - } - } - return length; - } - - private static int computePossibleMaskEntryLength(MatchEntries entry, int length) { - int entryLength = length; - if (entry.isHasMask()) { - entryLength *= 2; - } - return entryLength; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry.PseudoField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Serializes ofp_match (OpenFlow v1.3) and its oxm_fields structures + * @author michal.polkorab + * @author timotej.kubas + */ +public class MatchSerializer { + private static final Logger LOGGER = LoggerFactory.getLogger(MatchSerializer.class); + private static final byte STANDARD_MATCH_TYPE_CODE = 0; + private static final byte OXM_MATCH_TYPE_CODE = 1; + private static final int NXM0_CLASS_CODE = 0x0000; + private static final int NXM1_CLASS_CODE = 0x0001; + private static final int OPENFLOW_BASIC_CLASS_CODE = 0x8000; + private static final int EXPERIMENTER_CLASS_CODE = 0xFFFF; + private static final byte MATCH_TYPE_AND_LENGTH_SIZE = 4; + private static final byte MATCH_ENTRY_HEADER_LENGTH = 4; + + /** + * Encodes match (OpenFlow v1.3) + * @param match ofp_match object + * @param out output ByteBuf + */ + public static void encodeMatch(Match match, ByteBuf out) { + if (match == null) { + LOGGER.debug("Match is null"); + return; + } + encodeType(match, out); + // Length of ofp_match (excluding padding) + int length = computeMatchLengthInternal(match); + out.writeShort(length); + encodeMatchEntries(match.getMatchEntries(), out); + int paddingRemainder = length % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, out); + } + } + + private static void encodeType(Match match, ByteBuf out) { + if (match.getType().isAssignableFrom(StandardMatchType.class)) { + out.writeShort(STANDARD_MATCH_TYPE_CODE); + } else if (match.getType().isAssignableFrom(OxmMatchType.class)) { + out.writeShort(OXM_MATCH_TYPE_CODE); + } + } + + /** + * Encodes MatchEntries + * @param matchEntries list of match entries (oxm_fields) + * @param out output ByteBuf + */ + public static void encodeMatchEntries(List matchEntries, ByteBuf out) { + if (matchEntries == null) { + LOGGER.warn("Match entries are null"); + return; + } + for (MatchEntries entry : matchEntries) { + encodeClass(entry.getOxmClass(), out); + encodeRest(entry, out); + } + } + + private static void encodeClass(Class clazz, ByteBuf out) { + if (clazz.isAssignableFrom(Nxm0Class.class)) { + out.writeShort(NXM0_CLASS_CODE); + } else if (clazz.isAssignableFrom(Nxm1Class.class)) { + out.writeShort(NXM1_CLASS_CODE); + } else if (clazz.isAssignableFrom(OpenflowBasicClass.class)) { + out.writeShort(OPENFLOW_BASIC_CLASS_CODE); + } else if (clazz.isAssignableFrom(ExperimenterClass.class)) { + out.writeShort(EXPERIMENTER_CLASS_CODE); + } + } + + private static void encodeRest(MatchEntries entry, ByteBuf out) { + int fieldValue = 0; + Class field = entry.getOxmMatchField(); + if (field.isAssignableFrom(InPort.class)) { + fieldValue = 0; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_INT_IN_BYTES); + out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); + } else if (field.isAssignableFrom(InPhyPort.class)) { + fieldValue = 1; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_INT_IN_BYTES); + out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); + } else if (field.isAssignableFrom(Metadata.class)) { + fieldValue = 2; + writeMetadataRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(EthDst.class)) { + fieldValue = 3; + writeMacAddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(EthSrc.class)) { + fieldValue = 4; + writeMacAddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(EthType.class)) { + fieldValue = 5; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.writeShort(entry.getAugmentation(EthTypeMatchEntry.class).getEthType().getValue().shortValue()); + } else if (field.isAssignableFrom(VlanVid.class)) { + fieldValue = 6; + fieldValue = fieldValue << 1; + VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class); + int vlanVidValue = vlanVid.getVlanVid(); + if (vlanVid.isCfiBit()) { + short cfi = 1 << 12; // 13-th bit + vlanVidValue = vlanVidValue | cfi; + } + if (entry.isHasMask()) { + fieldValue = fieldValue | 1; + out.writeByte(fieldValue); + byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); + out.writeByte(EncodeConstants.SIZE_OF_SHORT_IN_BYTES + mask.length); + out.writeShort(vlanVidValue); + out.writeBytes(mask); + } else { + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.writeShort(vlanVidValue); + } + } else if (field.isAssignableFrom(VlanPcp.class)) { + fieldValue = 7; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + out.writeByte(entry.getAugmentation(VlanPcpMatchEntry.class).getVlanPcp().byteValue()); + } else if (field.isAssignableFrom(IpDscp.class)) { + fieldValue = 8; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + out.writeByte(entry.getAugmentation(DscpMatchEntry.class).getDscp().getValue()); + } else if (field.isAssignableFrom(IpEcn.class)) { + fieldValue = 9; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + out.writeByte(entry.getAugmentation(EcnMatchEntry.class).getEcn()); + } else if (field.isAssignableFrom(IpProto.class)) { + fieldValue = 10; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + out.writeByte(entry.getAugmentation(ProtocolNumberMatchEntry.class).getProtocolNumber()); + } else if (field.isAssignableFrom(Ipv4Src.class)) { + fieldValue = 11; + writeIpv4AddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(Ipv4Dst.class)) { + fieldValue = 12; + writeIpv4AddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(TcpSrc.class)) { + fieldValue = 13; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); + } else if (field.isAssignableFrom(TcpDst.class)) { + fieldValue = 14; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); + } else if (field.isAssignableFrom(UdpSrc.class)) { + fieldValue = 15; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); + } else if (field.isAssignableFrom(UdpDst.class)) { + fieldValue = 16; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); + } else if (field.isAssignableFrom(SctpSrc.class)) { + fieldValue = 17; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); + } else if (field.isAssignableFrom(SctpDst.class)) { + fieldValue = 18; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); + } else if (field.isAssignableFrom(Icmpv4Type.class)) { + fieldValue = 19; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + out.writeByte(entry.getAugmentation(Icmpv4TypeMatchEntry.class).getIcmpv4Type()); + } else if (field.isAssignableFrom(Icmpv4Code.class)) { + fieldValue = 20; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + out.writeByte(entry.getAugmentation(Icmpv4CodeMatchEntry.class).getIcmpv4Code()); + } else if (field.isAssignableFrom(ArpOp.class)) { + fieldValue = 21; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.writeShort(entry.getAugmentation(OpCodeMatchEntry.class).getOpCode()); + } else if (field.isAssignableFrom(ArpSpa.class)) { + fieldValue = 22; + writeIpv4AddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(ArpTpa.class)) { + fieldValue = 23; + writeIpv4AddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(ArpSha.class)) { + fieldValue = 24; + writeMacAddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(ArpTha.class)) { + fieldValue = 25; + writeMacAddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(Ipv6Src.class)) { + fieldValue = 26; + writeIpv6AddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(Ipv6Dst.class)) { + fieldValue = 27; + writeIpv6AddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(Ipv6Flabel.class)) { + fieldValue = 28; + fieldValue = fieldValue << 1; + if (entry.isHasMask()) { + fieldValue = fieldValue | 1; + out.writeByte(fieldValue); + byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); + out.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES + mask.length); // 20 b + mask [OF 1.3.2 spec] + LOGGER.warn("Ipv6Flabel match entry: possible wrong length written (wrote 4 - maybe must be 3)"); + out.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue()); + out.writeBytes(entry.getAugmentation(MaskMatchEntry.class).getMask()); + } else { + out.writeByte(fieldValue); + out.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES); // 20 b [OF 1.3.2 spec] + LOGGER.warn("Ipv6Flabel match entry: possible wrong length written (wrote 4 - maybe must be 3)"); + out.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue()); + } + } else if (field.isAssignableFrom(Icmpv6Type.class)) { + fieldValue = 29; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + out.writeByte(entry.getAugmentation(Icmpv6TypeMatchEntry.class).getIcmpv6Type()); + } else if (field.isAssignableFrom(Icmpv6Code.class)) { + fieldValue = 30; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + out.writeByte(entry.getAugmentation(Icmpv6CodeMatchEntry.class).getIcmpv6Code()); + } else if (field.isAssignableFrom(Ipv6NdTarget.class)) { + fieldValue = 31; + writeIpv6AddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(Ipv6NdSll.class)) { + fieldValue = 32; + writeMacAddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(Ipv6NdTll.class)) { + fieldValue = 33; + writeMacAddressRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(MplsLabel.class)) { + fieldValue = 34; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_INT_IN_BYTES); + LOGGER.warn("MplsLabel match entry: possible wrong length written (wrote 4 - maybe must be 3)"); + out.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue()); + } else if (field.isAssignableFrom(MplsTc.class)) { + fieldValue = 35; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + out.writeByte(entry.getAugmentation(TcMatchEntry.class).getTc()); + } else if (field.isAssignableFrom(MplsBos.class)) { + fieldValue = 36; + writeOxmFieldAndLength(out, fieldValue, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + out.writeBoolean(entry.getAugmentation(BosMatchEntry.class).isBos().booleanValue()); + } else if (field.isAssignableFrom(PbbIsid.class)) { + fieldValue = 37; + fieldValue = fieldValue << 1; + if (entry.isHasMask()) { + fieldValue = fieldValue | 1; + out.writeByte(fieldValue); + byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); + out.writeByte(EncodeConstants.SIZE_OF_LONG_IN_BYTES + mask.length); + LOGGER.warn("PbbIsid match entry: possible wrong length written (wrote 4 - maybe must be 3)"); + out.writeInt(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue()); + out.writeBytes(mask); + } else { + out.writeByte(fieldValue); + out.writeByte(EncodeConstants.SIZE_OF_LONG_IN_BYTES); + LOGGER.warn("PbbIsid match entry: possible wrong length written (wrote 4 - maybe must be 3)"); + out.writeInt(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue()); + } + } else if (field.isAssignableFrom(TunnelId.class)) { + fieldValue = 38; + writeMetadataRelatedEntry(entry, out, fieldValue); + } else if (field.isAssignableFrom(Ipv6Exthdr.class)) { + fieldValue = 39; + fieldValue = fieldValue << 1; + PseudoField pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField(); + Map map = new HashMap<>(); + map.put(0, pseudoField.isNonext()); + map.put(1, pseudoField.isEsp()); + map.put(2, pseudoField.isAuth()); + map.put(3, pseudoField.isDest()); + map.put(4, pseudoField.isFrag()); + map.put(5, pseudoField.isRouter()); + map.put(6, pseudoField.isHop()); + map.put(7, pseudoField.isUnrep()); + map.put(8, pseudoField.isUnseq()); + int bitmap = ByteBufUtils.fillBitMaskFromMap(map); + if (entry.isHasMask()) { + fieldValue = fieldValue | 1; + out.writeByte(fieldValue); + byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); + out.writeByte(EncodeConstants.SIZE_OF_SHORT_IN_BYTES + mask.length); + out.writeShort(bitmap); + out.writeBytes(mask); + } else { + out.writeByte(fieldValue); + out.writeByte(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.writeShort(bitmap); + } + } + } + + private static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, int length) { + int fieldAndMask = fieldValue << 1; + out.writeByte(fieldAndMask); + out.writeByte(length); + } + + private static void writeMetadataRelatedEntry(MatchEntries entry, ByteBuf out, int value) { + int fieldValue = value << 1; + if (entry.isHasMask()) { + fieldValue = fieldValue | 1; + out.writeByte(fieldValue); + byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); + out.writeByte(EncodeConstants.SIZE_OF_LONG_IN_BYTES + mask.length); + out.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata()); + out.writeBytes(mask); + } else { + out.writeByte(fieldValue); + out.writeByte(EncodeConstants.SIZE_OF_LONG_IN_BYTES); + out.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata()); + } + } + + private static void writeMacAddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) { + int fieldValue = value << 1; + if (entry.isHasMask()) { + fieldValue = fieldValue | 1; + out.writeByte(fieldValue); + byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); + out.writeByte(EncodeConstants.MAC_ADDRESS_LENGTH + mask.length); // 48 b + mask [OF 1.3.2 spec] + String macAddress = entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue(); + out.writeBytes(ByteBufUtils.macAddressToBytes(macAddress)); + out.writeBytes(mask); + } else { + out.writeByte(fieldValue); + out.writeByte(EncodeConstants.MAC_ADDRESS_LENGTH); // 48 b [OF 1.3.2 spec] + String macAddress = entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue(); + out.writeBytes(ByteBufUtils.macAddressToBytes(macAddress)); + } + } + + private static void writeIpv4AddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) { + int fieldValue = value << 1; + if (entry.isHasMask()) { + fieldValue = fieldValue | 1; + out.writeByte(fieldValue); + byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); + out.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES + mask.length); + writeIpv4Address(entry, out); + out.writeBytes(mask); + } else { + out.writeByte(fieldValue); + out.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES); + writeIpv4Address(entry, out); + } + } + + private static void writeIpv4Address(MatchEntries entry, ByteBuf out) { + String[] addressGroups = entry.getAugmentation(Ipv4AddressMatchEntry.class).getIpv4Address().getValue().split("\\."); + for (int i = 0; i < addressGroups.length; i++) { + out.writeByte(Integer.parseInt(addressGroups[i])); + } + } + + private static void writeIpv6AddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) { + int fieldValue = value << 1; + String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue(); + String[] address; + if (textAddress.equals("::")) { + address = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; + Arrays.fill(address, "0"); + } else { + address = parseIpv6Address(textAddress.split(":")); + } + if (entry.isHasMask()) { + fieldValue = fieldValue | 1; + out.writeByte(fieldValue); + byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask(); + out.writeByte(EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES + mask.length); + for (int i = 0; i < address.length; i++) { + out.writeShort(Integer.parseInt(address[i], 16)); + } + out.writeBytes(mask); + } else { + out.writeByte(fieldValue); + out.writeByte(EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); + for (int i = 0; i < address.length; i++) { + out.writeShort(Integer.parseInt(address[i], 16)); + } + } + } + + private static String[] parseIpv6Address(String[] addressGroups) { + int countEmpty = 0; + for (int i = 0; i < addressGroups.length; i++) { + if (addressGroups[i].equals("")){ + countEmpty++; + } + } + String[] ready = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; + switch (countEmpty) { + case 0: + ready = addressGroups; + break; + case 1: + int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.length + 1; + int index = 0; + for (int i = 0; i < addressGroups.length; i++) { + if (addressGroups[i].equals("")) { + for (int j = 0; j < zerosToBePushed; j++) { + ready[index] = "0"; + index++; + } + } else { + ready[index] = addressGroups[i]; + index++; + } + } + break; + case 2: + Arrays.fill(ready, "0"); + ready[ready.length - 1] = addressGroups[addressGroups.length - 1]; + break; + default: + throw new IllegalStateException("Incorrect ipv6 address"); + } + return ready; + } + + /** + * Computes length of match (in bytes) + * @param match + * @return length of ofp_match (excluding padding) + */ + public static int computeMatchLengthInternal(Match match) { + int length = 0; + if (match != null) { + length += MATCH_TYPE_AND_LENGTH_SIZE + computeMatchEntriesLength(match.getMatchEntries()); + } + return length; + } + + /** + * Computes length of match (in bytes) + * @param match + * @return length of ofp_match (excluding padding) + */ + public static int computeMatchLength(Match match) { + int length = computeMatchLengthInternal(match); + int paddingRemainder = length % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + length += EncodeConstants.PADDING - paddingRemainder; + } + return length; + } + + /** + * Computes length of MatchEntries (in bytes) + * @param matchEntries list of match entries (oxm_fields) + * @return length of MatchEntries + */ + public static int computeMatchEntriesLength(List matchEntries) { + int length = 0; + if (matchEntries != null) { + for (MatchEntries entry : matchEntries) { + length += MATCH_ENTRY_HEADER_LENGTH; + Class field = entry.getOxmMatchField(); + if (field.isAssignableFrom(InPort.class)) { + length += EncodeConstants.SIZE_OF_INT_IN_BYTES; + } else if (field.isAssignableFrom(InPhyPort.class)) { + length += EncodeConstants.SIZE_OF_INT_IN_BYTES; + } else if (field.isAssignableFrom(Metadata.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_LONG_IN_BYTES); + } else if (field.isAssignableFrom(EthDst.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); + } else if (field.isAssignableFrom(EthSrc.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); + } else if (field.isAssignableFrom(EthType.class)) { + length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } else if (field.isAssignableFrom(VlanVid.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + } else if (field.isAssignableFrom(VlanPcp.class)) { + length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } else if (field.isAssignableFrom(IpDscp.class)) { + length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } else if (field.isAssignableFrom(IpEcn.class)) { + length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } else if (field.isAssignableFrom(IpProto.class)) { + length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } else if (field.isAssignableFrom(Ipv4Src.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } else if (field.isAssignableFrom(Ipv4Dst.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } else if (field.isAssignableFrom(TcpSrc.class)) { + length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } else if (field.isAssignableFrom(TcpDst.class)) { + length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } else if (field.isAssignableFrom(UdpSrc.class)) { + length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } else if (field.isAssignableFrom(UdpDst.class)) { + length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } else if (field.isAssignableFrom(SctpSrc.class)) { + length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } else if (field.isAssignableFrom(SctpDst.class)) { + length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } else if (field.isAssignableFrom(Icmpv4Type.class)) { + length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } else if (field.isAssignableFrom(Icmpv4Code.class)) { + length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } else if (field.isAssignableFrom(ArpOp.class)) { + length += EncodeConstants.SIZE_OF_SHORT_IN_BYTES; + } else if (field.isAssignableFrom(ArpSpa.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } else if (field.isAssignableFrom(ArpTpa.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } else if (field.isAssignableFrom(ArpSha.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); + } else if (field.isAssignableFrom(ArpTha.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); + } else if (field.isAssignableFrom(Ipv6Src.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); + } else if (field.isAssignableFrom(Ipv6Dst.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); + } else if (field.isAssignableFrom(Ipv6Flabel.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } else if (field.isAssignableFrom(Icmpv6Type.class)) { + length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } else if (field.isAssignableFrom(Icmpv6Code.class)) { + length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } else if (field.isAssignableFrom(Ipv6NdTarget.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); + } else if (field.isAssignableFrom(Ipv6NdSll.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); + } else if (field.isAssignableFrom(Ipv6NdTll.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.MAC_ADDRESS_LENGTH); + } else if (field.isAssignableFrom(MplsLabel.class)) { + length += EncodeConstants.SIZE_OF_INT_IN_BYTES; + } else if (field.isAssignableFrom(MplsTc.class)) { + length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } else if (field.isAssignableFrom(MplsBos.class)) { + length += EncodeConstants.SIZE_OF_BYTE_IN_BYTES; + } else if (field.isAssignableFrom(PbbIsid.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_INT_IN_BYTES); + } else if (field.isAssignableFrom(TunnelId.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_LONG_IN_BYTES); + } else if (field.isAssignableFrom(Ipv6Exthdr.class)) { + length += computePossibleMaskEntryLength(entry, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + } + } + } + return length; + } + + private static int computePossibleMaskEntryLength(MatchEntries entry, int length) { + int entryLength = length; + if (entry.isHasMask()) { + entryLength *= 2; + } + return entryLength; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java index bef27a1c..96d74567 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsDeserializer.java @@ -1,276 +1,283 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yangtools.yang.binding.Augmentation; - -import com.google.common.base.Joiner; - -/** - * Deserializes ofp_action (OpenFlow v1.0) structures - * @author michal.polkorab - */ -public class OF10ActionsDeserializer { - - private static final byte PADDING_IN_SET_VLAN_VID_ACTION = 2; - private static final byte PADDING_IN_SET_VLAN_PCP_ACTION = 3; - private static final byte PADDING_IN_STRIP_VLAN_ACTION = 4; - private static final byte PADDING_IN_SET_DL_ACTION = 6; - private static final byte PADDING_IN_NW_TOS_ACTION = 3; - private static final byte PADDING_IN_TP_ACTION = 2; - private static final byte PADDING_IN_ENQUEUE_ACTION = 6; - - /** - * Creates list of actions (OpenFlow v1.0) from ofp_action structures - * @param input input ByteBuf - * @return ActionsList list of actions - */ - public static List createActionsList(ByteBuf input) { - List actions = new ArrayList<>(); - while (input.readableBytes() > 0) { - ActionsListBuilder actionsBuilder = new ActionsListBuilder(); - int type = input.readUnsignedShort(); - input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - switch(type) { - case 0: - actions.add(createOutputAction(input, actionsBuilder)); - break; - case 1: - actions.add(createSetVlanVidAction(input, actionsBuilder)); - break; - case 2: - actions.add(createVlanPcpAction(input, actionsBuilder)); - break; - case 3: - actions.add(createStripVlanAction(input, actionsBuilder)); - break; - case 4: - actions.add(createSetDlSrcAction(input, actionsBuilder)); - break; - case 5: - actions.add(createSetDlDstAction(input, actionsBuilder)); - break; - case 6: - actions.add(createSetNwSrcAction(input, actionsBuilder)); - break; - case 7: - actions.add(createSetNwDstAction(input, actionsBuilder)); - break; - case 8: - actions.add(createSetNwTosAction(input, actionsBuilder)); - break; - case 9: - actions.add(createSetTpSrcAction(input, actionsBuilder)); - break; - case 10: - actions.add(createSetTpDstAction(input, actionsBuilder)); - break; - case 11: - actions.add(createEnqueueAction(input, actionsBuilder)); - break; - case 0xFFFF: - actions.add(createExperimenterAction(input, actionsBuilder)); - break; - default: - break; - } - } - return actions; - } - - /** - * @param in input ByteBuf - * @param builder - * @return ActionList - */ - public static ActionsList createOutputAction(ByteBuf in, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(Output.class); - createPortAugmentation(in, actionBuilder); - MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); - maxLen.setMaxLength(in.readUnsignedShort()); - actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static ActionsList createSetVlanVidAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetVlanVid.class); - VlanVidActionBuilder vlanBuilder = new VlanVidActionBuilder(); - vlanBuilder.setVlanVid(input.readUnsignedShort()); - input.skipBytes(PADDING_IN_SET_VLAN_VID_ACTION); - actionBuilder.addAugmentation(VlanVidAction.class, vlanBuilder.build()); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static ActionsList createVlanPcpAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetVlanPcp.class); - VlanPcpActionBuilder vlanBuilder = new VlanPcpActionBuilder(); - vlanBuilder.setVlanPcp(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_SET_VLAN_PCP_ACTION); - actionBuilder.addAugmentation(VlanVidAction.class, vlanBuilder.build()); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static ActionsList createStripVlanAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(StripVlan.class); - input.skipBytes(PADDING_IN_STRIP_VLAN_ACTION); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static ActionsList createSetDlSrcAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetDlSrc.class); - actionBuilder.addAugmentation(DlAddressAction.class, createDlAugmentationAndPad(input)); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static ActionsList createSetDlDstAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetDlDst.class); - actionBuilder.addAugmentation(DlAddressAction.class, createDlAugmentationAndPad(input)); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static DlAddressAction createDlAugmentationAndPad(ByteBuf input) { - DlAddressActionBuilder dlBuilder = new DlAddressActionBuilder(); - byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - input.readBytes(address); - dlBuilder.setDlAddress(new MacAddress(ByteBufUtils.macAddressToString(address))); - input.skipBytes(PADDING_IN_SET_DL_ACTION); - return dlBuilder.build(); - } - - private static ActionsList createSetNwSrcAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetNwSrc.class); - actionBuilder.addAugmentation(IpAddressAction.class, createNwAddressAugmentationAndPad(input)); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static ActionsList createSetNwDstAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetNwDst.class); - actionBuilder.addAugmentation(IpAddressAction.class, createNwAddressAugmentationAndPad(input)); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static Augmentation createNwAddressAugmentationAndPad(ByteBuf input) { - IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder(); - List groups = new ArrayList<>(); - for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { - groups.add(Short.toString(input.readUnsignedByte())); - } - Joiner joiner = Joiner.on("."); - ipBuilder.setIpAddress(new Ipv4Address(joiner.join(groups))); - return ipBuilder.build(); - } - - private static ActionsList createSetNwTosAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetNwTos.class); - NwTosActionBuilder tosBuilder = new NwTosActionBuilder(); - tosBuilder.setNwTos(input.readUnsignedByte()); - actionBuilder.addAugmentation(NwTosAction.class, tosBuilder.build()); - input.skipBytes(PADDING_IN_NW_TOS_ACTION); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static ActionsList createSetTpSrcAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetTpSrc.class); - createPortAugmentation(input, actionBuilder); - input.skipBytes(PADDING_IN_TP_ACTION); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static ActionsList createSetTpDstAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetTpDst.class); - createPortAugmentation(input, actionBuilder); - input.skipBytes(PADDING_IN_TP_ACTION); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static void createPortAugmentation(ByteBuf input, ActionBuilder actionBuilder) { - PortActionBuilder portBuilder = new PortActionBuilder(); - portBuilder.setPort(new PortNumber((long) input.readUnsignedShort())); - actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); - } - - private static ActionsList createEnqueueAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(Enqueue.class); - createPortAugmentation(input, actionBuilder); - input.skipBytes(PADDING_IN_ENQUEUE_ACTION); - QueueIdActionBuilder queueBuilder = new QueueIdActionBuilder(); - queueBuilder.setQueueId(input.readUnsignedInt()); - actionBuilder.addAugmentation(QueueIdAction.class, queueBuilder.build()); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - private static ActionsList createExperimenterAction(ByteBuf input, ActionsListBuilder builder) { - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(Enqueue.class); - ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); - expBuilder.setExperimenter(input.readUnsignedInt()); - actionBuilder.addAugmentation(QueueIdAction.class, expBuilder.build()); - builder.setAction(actionBuilder.build()); - return builder.build(); - } - - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yangtools.yang.binding.Augmentation; + +import com.google.common.base.Joiner; + +/** + * Deserializes ofp_action (OpenFlow v1.0) structures + * @author michal.polkorab + */ +public class OF10ActionsDeserializer { + + private static final byte PADDING_IN_SET_VLAN_VID_ACTION = 2; + private static final byte PADDING_IN_SET_VLAN_PCP_ACTION = 3; + private static final byte PADDING_IN_STRIP_VLAN_ACTION = 4; + private static final byte PADDING_IN_SET_DL_ACTION = 6; + private static final byte PADDING_IN_NW_TOS_ACTION = 3; + private static final byte PADDING_IN_TP_ACTION = 2; + private static final byte PADDING_IN_ENQUEUE_ACTION = 6; + + /** + * Creates list of actions (OpenFlow v1.0) from ofp_action structures + * @param input input ByteBuf + * @return ActionsList list of actions + */ + public static List createActionsList(ByteBuf input) { + List actions = new ArrayList<>(); + while (input.readableBytes() > 0) { + ActionsListBuilder actionsBuilder = new ActionsListBuilder(); + int type = input.readUnsignedShort(); + input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + switch(type) { + case 0: + actions.add(createOutputAction(input, actionsBuilder)); + break; + case 1: + actions.add(createSetVlanVidAction(input, actionsBuilder)); + break; + case 2: + actions.add(createVlanPcpAction(input, actionsBuilder)); + break; + case 3: + actions.add(createStripVlanAction(input, actionsBuilder)); + break; + case 4: + actions.add(createSetDlSrcAction(input, actionsBuilder)); + break; + case 5: + actions.add(createSetDlDstAction(input, actionsBuilder)); + break; + case 6: + actions.add(createSetNwSrcAction(input, actionsBuilder)); + break; + case 7: + actions.add(createSetNwDstAction(input, actionsBuilder)); + break; + case 8: + actions.add(createSetNwTosAction(input, actionsBuilder)); + break; + case 9: + actions.add(createSetTpSrcAction(input, actionsBuilder)); + break; + case 10: + actions.add(createSetTpDstAction(input, actionsBuilder)); + break; + case 11: + actions.add(createEnqueueAction(input, actionsBuilder)); + break; + case 0xFFFF: + actions.add(createExperimenterAction(input, actionsBuilder)); + break; + default: + break; + } + } + return actions; + } + + /** + * @param in input ByteBuf + * @param builder + * @return ActionList + */ + public static ActionsList createOutputAction(ByteBuf in, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Output.class); + createPortAugmentation(in, actionBuilder); + MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); + maxLen.setMaxLength(in.readUnsignedShort()); + actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static ActionsList createSetVlanVidAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetVlanVid.class); + VlanVidActionBuilder vlanBuilder = new VlanVidActionBuilder(); + vlanBuilder.setVlanVid(input.readUnsignedShort()); + input.skipBytes(PADDING_IN_SET_VLAN_VID_ACTION); + actionBuilder.addAugmentation(VlanVidAction.class, vlanBuilder.build()); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static ActionsList createVlanPcpAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetVlanPcp.class); + VlanPcpActionBuilder vlanBuilder = new VlanPcpActionBuilder(); + vlanBuilder.setVlanPcp(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_SET_VLAN_PCP_ACTION); + actionBuilder.addAugmentation(VlanVidAction.class, vlanBuilder.build()); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static ActionsList createStripVlanAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(StripVlan.class); + input.skipBytes(PADDING_IN_STRIP_VLAN_ACTION); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static ActionsList createSetDlSrcAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetDlSrc.class); + actionBuilder.addAugmentation(DlAddressAction.class, createDlAugmentationAndPad(input)); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static ActionsList createSetDlDstAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetDlDst.class); + actionBuilder.addAugmentation(DlAddressAction.class, createDlAugmentationAndPad(input)); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static DlAddressAction createDlAugmentationAndPad(ByteBuf input) { + DlAddressActionBuilder dlBuilder = new DlAddressActionBuilder(); + byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + input.readBytes(address); + dlBuilder.setDlAddress(new MacAddress(ByteBufUtils.macAddressToString(address))); + input.skipBytes(PADDING_IN_SET_DL_ACTION); + return dlBuilder.build(); + } + + private static ActionsList createSetNwSrcAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetNwSrc.class); + actionBuilder.addAugmentation(IpAddressAction.class, createNwAddressAugmentationAndPad(input)); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static ActionsList createSetNwDstAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetNwDst.class); + actionBuilder.addAugmentation(IpAddressAction.class, createNwAddressAugmentationAndPad(input)); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static Augmentation createNwAddressAugmentationAndPad(ByteBuf input) { + IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder(); + List groups = new ArrayList<>(); + for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { + groups.add(Short.toString(input.readUnsignedByte())); + } + Joiner joiner = Joiner.on("."); + ipBuilder.setIpAddress(new Ipv4Address(joiner.join(groups))); + return ipBuilder.build(); + } + + private static ActionsList createSetNwTosAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetNwTos.class); + NwTosActionBuilder tosBuilder = new NwTosActionBuilder(); + tosBuilder.setNwTos(input.readUnsignedByte()); + actionBuilder.addAugmentation(NwTosAction.class, tosBuilder.build()); + input.skipBytes(PADDING_IN_NW_TOS_ACTION); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static ActionsList createSetTpSrcAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetTpSrc.class); + createPortAugmentation(input, actionBuilder); + input.skipBytes(PADDING_IN_TP_ACTION); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static ActionsList createSetTpDstAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetTpDst.class); + createPortAugmentation(input, actionBuilder); + input.skipBytes(PADDING_IN_TP_ACTION); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static void createPortAugmentation(ByteBuf input, ActionBuilder actionBuilder) { + PortActionBuilder portBuilder = new PortActionBuilder(); + portBuilder.setPort(new PortNumber((long) input.readUnsignedShort())); + actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); + } + + private static ActionsList createEnqueueAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Enqueue.class); + createPortAugmentation(input, actionBuilder); + input.skipBytes(PADDING_IN_ENQUEUE_ACTION); + QueueIdActionBuilder queueBuilder = new QueueIdActionBuilder(); + queueBuilder.setQueueId(input.readUnsignedInt()); + actionBuilder.addAugmentation(QueueIdAction.class, queueBuilder.build()); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + private static ActionsList createExperimenterAction(ByteBuf input, ActionsListBuilder builder) { + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Enqueue.class); + ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder(); + expBuilder.setExperimenter(input.readUnsignedInt()); + actionBuilder.addAugmentation(QueueIdAction.class, expBuilder.build()); + builder.setAction(actionBuilder.build()); + return builder.build(); + } + + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializer.java index 34cfa31b..29f42d86 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10ActionsSerializer.java @@ -1,233 +1,240 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; - -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action; - -/** - * Serializes ofp_action (OpenFlow v1.0) structures - * @author michal.polkorab - */ -public abstract class OF10ActionsSerializer { - - private static final byte OUTPUT_CODE = 0; - private static final byte SET_VLAN_VID_CODE = 1; - private static final byte SET_VLAN_PCP_CODE = 2; - private static final byte STRIP_VLAN_CODE = 3; - private static final byte SET_DL_SRC_CODE = 4; - private static final byte SET_DL_DST_CODE = 5; - private static final byte SET_NW_SRC_CODE = 6; - private static final byte SET_NW_DST_CODE = 7; - private static final byte SET_NW_TOS_CODE = 8; - private static final byte SET_TP_SRC_CODE = 9; - private static final byte SET_TP_DST_CODE = 10; - private static final byte ENQUEUE_CODE = 11; - private static final int EXPERIMENTER_CODE = 65535; // 0xFFFF - private static final byte GENERIC_ACTION_LENGTH = 8; - private static final byte PADDING_IN_GENERIC_ACTION = 4; - private static final byte OUTPUT_LENGTH = 8; - private static final byte SET_VLAN_VID_LENGTH = 8; - private static final byte PADDING_IN_SET_VLAN_VID_ACTION = 2; - private static final byte SET_VLAN_PCP_LENGTH = 8; - private static final byte PADDING_IN_SET_VLAN_PCP_ACTION = 3; - private static final byte DL_ADDRESS_ACTION_LENGTH = 16; - private static final byte PADDING_IN_DL_ADDRESS_ACTION = 6; - private static final byte SET_NW_TOS_LENGTH = 8; - private static final byte PADDING_IN_SET_NW_TOS_ACTION = 3; - private static final byte IP_ADDRESS_ACTION_LENGTH = 8; - private static final byte TP_PORT_ACTION_LENGTH = 8; - private static final byte PADDING_IN_TP_PORT_ACTION = 2; - private static final byte ENQUEUE_LENGTH = 16; - private static final byte PADDING_IN_ENQUEUE_ACTION = 6; - private static final byte EXPERIMENTER_LENGTH = 8; - - - /** - * Encodes ofp_action (OpenFlow v1.0) structures - * @param out output ByteBuf that actions will be written into - * @param actionsList actions to be encoded - */ - public static void encodeActionsV10(ByteBuf out, List actionsList) { - if (actionsList == null) { - return; - } - for (ActionsList list : actionsList) { - Action action = list.getAction(); - if (action.getType().equals(Output.class)) { - encodeOutputAction(action, out); - } else if (action.getType().equals(SetVlanVid.class)) { - encodeSetVlanVidAction(action, out); - } else if (action.getType().equals(SetVlanPcp.class)) { - encodeSetVlanPcpAction(action, out); - } else if (action.getType().equals(StripVlan.class)) { - encodeGenericAction(STRIP_VLAN_CODE, out); - } else if (action.getType().equals(SetDlSrc.class)) { - encodeDlAddressAction(action, out, SET_DL_SRC_CODE); - } else if (action.getType().equals(SetDlDst.class)) { - encodeDlAddressAction(action, out, SET_DL_DST_CODE); - } else if (action.getType().equals(SetNwSrc.class)) { - encodeIpAddressAction(action, out, SET_NW_SRC_CODE); - } else if (action.getType().equals(SetNwDst.class)) { - encodeIpAddressAction(action, out, SET_NW_DST_CODE); - } else if (action.getType().equals(SetNwTos.class)) { - encodeNwTosAction(action, out); - } else if (action.getType().equals(SetTpSrc.class)) { - encodeTpPortAction(action, out, SET_TP_SRC_CODE); - } else if (action.getType().equals(SetTpDst.class)) { - encodeTpPortAction(action, out, SET_TP_DST_CODE); - } else if (action.getType().equals(Enqueue.class)) { - encodeEnqueueAction(action, out); - } else if (action.getType().equals(Experimenter.class)) { - encodeExperimenterAction(action, out); - } - } - } - - private static void encodeGenericAction(byte code, ByteBuf out) { - out.writeShort(code); - out.writeShort(GENERIC_ACTION_LENGTH); - ByteBufUtils.padBuffer(PADDING_IN_GENERIC_ACTION, out); - } - - private static void encodeOutputAction(Action action, ByteBuf out) { - out.writeShort(OUTPUT_CODE); - out.writeShort(OUTPUT_LENGTH); - PortAction port = action.getAugmentation(PortAction.class); - out.writeShort(port.getPort().getValue().intValue()); - MaxLengthAction maxlength = action.getAugmentation(MaxLengthAction.class); - out.writeShort(maxlength.getMaxLength()); - } - - private static void encodeSetVlanVidAction(Action action, ByteBuf out) { - out.writeShort(SET_VLAN_VID_CODE); - out.writeShort(SET_VLAN_VID_LENGTH); - out.writeShort(action.getAugmentation(VlanVidAction.class).getVlanVid()); - ByteBufUtils.padBuffer(PADDING_IN_SET_VLAN_VID_ACTION, out); - } - - private static void encodeSetVlanPcpAction(Action action, ByteBuf out) { - out.writeShort(SET_VLAN_PCP_CODE); - out.writeShort(SET_VLAN_PCP_LENGTH); - out.writeByte(action.getAugmentation(VlanPcpAction.class).getVlanPcp()); - ByteBufUtils.padBuffer(PADDING_IN_SET_VLAN_PCP_ACTION, out); - } - - private static void encodeDlAddressAction(Action action, ByteBuf out, byte code) { - out.writeShort(code); - out.writeShort(DL_ADDRESS_ACTION_LENGTH); - out.writeBytes(action.getAugmentation(DlAddressAction.class) - .getDlAddress().getValue().getBytes()); - ByteBufUtils.padBuffer(PADDING_IN_DL_ADDRESS_ACTION, out); - } - - private static void encodeNwTosAction(Action action, ByteBuf out) { - out.writeShort(SET_NW_TOS_CODE); - out.writeShort(SET_NW_TOS_LENGTH); - out.writeByte(action.getAugmentation(NwTosAction.class).getNwTos()); - ByteBufUtils.padBuffer(PADDING_IN_SET_NW_TOS_ACTION, out); - } - - private static void encodeIpAddressAction(Action action, ByteBuf out, byte code) { - out.writeShort(code); - out.writeShort(IP_ADDRESS_ACTION_LENGTH); - String[] addressGroups = action. - getAugmentation(IpAddressAction.class).getIpAddress().getValue().split("\\."); - for (int i = 0; i < addressGroups.length; i++) { - out.writeByte(Integer.parseInt(addressGroups[i])); - } - } - - private static void encodeTpPortAction(Action action, ByteBuf out, byte code) { - out.writeShort(code); - out.writeShort(TP_PORT_ACTION_LENGTH); - PortAction port = action.getAugmentation(PortAction.class); - out.writeShort(port.getPort().getValue().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_TP_PORT_ACTION, out); - } - - private static void encodeEnqueueAction(Action action, ByteBuf out) { - out.writeShort(ENQUEUE_CODE); - out.writeShort(ENQUEUE_LENGTH); - PortAction port = action.getAugmentation(PortAction.class); - out.writeShort(port.getPort().getValue().intValue()); - ByteBufUtils.padBuffer(PADDING_IN_ENQUEUE_ACTION, out); - QueueIdAction queueId = action.getAugmentation(QueueIdAction.class); - out.writeShort(queueId.getQueueId().intValue()); - } - - private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) { - outBuffer.writeShort(EXPERIMENTER_CODE); - outBuffer.writeShort(EXPERIMENTER_LENGTH); - ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); - outBuffer.writeInt(experimenter.getExperimenter().intValue()); - } - - /** - * Computes length of actions - * @param actionsList - * @return length of actions (OpenFlow v1.0) - */ - public static int computeActionsLength(List actionsList) { - int length = 0; - if (actionsList != null) { - for (ActionsList list : actionsList) { - Action action = list.getAction(); - if (action.getType().equals(Output.class)) { - length += 8; - } else if (action.getType().equals(SetVlanVid.class)) { - length += 8; - } else if (action.getType().equals(SetVlanPcp.class)) { - length += 8; - } else if (action.getType().equals(StripVlan.class)) { - length += 8; - } else if (action.getType().equals(SetDlSrc.class)) { - length += 16; - } else if (action.getType().equals(SetDlDst.class)) { - length += 16; - } else if (action.getType().equals(SetNwSrc.class)) { - length += 8; - } else if (action.getType().equals(SetNwDst.class)) { - length += 8; - } else if (action.getType().equals(SetNwTos.class)) { - length += 8; - } else if (action.getType().equals(SetTpSrc.class)) { - length += 8; - } else if (action.getType().equals(SetTpDst.class)) { - length += 8; - } else if (action.getType().equals(Enqueue.class)) { - length += 16; - } else if (action.getType().equals(Experimenter.class)) { - length += 8; - } - } - } - return length; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action; + +/** + * Serializes ofp_action (OpenFlow v1.0) structures + * @author michal.polkorab + */ +public abstract class OF10ActionsSerializer { + + private static final byte OUTPUT_CODE = 0; + private static final byte SET_VLAN_VID_CODE = 1; + private static final byte SET_VLAN_PCP_CODE = 2; + private static final byte STRIP_VLAN_CODE = 3; + private static final byte SET_DL_SRC_CODE = 4; + private static final byte SET_DL_DST_CODE = 5; + private static final byte SET_NW_SRC_CODE = 6; + private static final byte SET_NW_DST_CODE = 7; + private static final byte SET_NW_TOS_CODE = 8; + private static final byte SET_TP_SRC_CODE = 9; + private static final byte SET_TP_DST_CODE = 10; + private static final byte ENQUEUE_CODE = 11; + private static final int EXPERIMENTER_CODE = 65535; // 0xFFFF + private static final byte GENERIC_ACTION_LENGTH = 8; + private static final byte PADDING_IN_GENERIC_ACTION = 4; + private static final byte OUTPUT_LENGTH = 8; + private static final byte SET_VLAN_VID_LENGTH = 8; + private static final byte PADDING_IN_SET_VLAN_VID_ACTION = 2; + private static final byte SET_VLAN_PCP_LENGTH = 8; + private static final byte PADDING_IN_SET_VLAN_PCP_ACTION = 3; + private static final byte DL_ADDRESS_ACTION_LENGTH = 16; + private static final byte PADDING_IN_DL_ADDRESS_ACTION = 6; + private static final byte SET_NW_TOS_LENGTH = 8; + private static final byte PADDING_IN_SET_NW_TOS_ACTION = 3; + private static final byte IP_ADDRESS_ACTION_LENGTH = 8; + private static final byte TP_PORT_ACTION_LENGTH = 8; + private static final byte PADDING_IN_TP_PORT_ACTION = 2; + private static final byte ENQUEUE_LENGTH = 16; + private static final byte PADDING_IN_ENQUEUE_ACTION = 6; + private static final byte EXPERIMENTER_LENGTH = 8; + + + /** + * Encodes ofp_action (OpenFlow v1.0) structures + * @param out output ByteBuf that actions will be written into + * @param actionsList actions to be encoded + */ + public static void encodeActionsV10(ByteBuf out, List actionsList) { + if (actionsList == null) { + return; + } + for (ActionsList list : actionsList) { + Action action = list.getAction(); + if (action.getType().equals(Output.class)) { + encodeOutputAction(action, out); + } else if (action.getType().equals(SetVlanVid.class)) { + encodeSetVlanVidAction(action, out); + } else if (action.getType().equals(SetVlanPcp.class)) { + encodeSetVlanPcpAction(action, out); + } else if (action.getType().equals(StripVlan.class)) { + encodeGenericAction(STRIP_VLAN_CODE, out); + } else if (action.getType().equals(SetDlSrc.class)) { + encodeDlAddressAction(action, out, SET_DL_SRC_CODE); + } else if (action.getType().equals(SetDlDst.class)) { + encodeDlAddressAction(action, out, SET_DL_DST_CODE); + } else if (action.getType().equals(SetNwSrc.class)) { + encodeIpAddressAction(action, out, SET_NW_SRC_CODE); + } else if (action.getType().equals(SetNwDst.class)) { + encodeIpAddressAction(action, out, SET_NW_DST_CODE); + } else if (action.getType().equals(SetNwTos.class)) { + encodeNwTosAction(action, out); + } else if (action.getType().equals(SetTpSrc.class)) { + encodeTpPortAction(action, out, SET_TP_SRC_CODE); + } else if (action.getType().equals(SetTpDst.class)) { + encodeTpPortAction(action, out, SET_TP_DST_CODE); + } else if (action.getType().equals(Enqueue.class)) { + encodeEnqueueAction(action, out); + } else if (action.getType().equals(Experimenter.class)) { + encodeExperimenterAction(action, out); + } + } + } + + private static void encodeGenericAction(byte code, ByteBuf out) { + out.writeShort(code); + out.writeShort(GENERIC_ACTION_LENGTH); + ByteBufUtils.padBuffer(PADDING_IN_GENERIC_ACTION, out); + } + + private static void encodeOutputAction(Action action, ByteBuf out) { + out.writeShort(OUTPUT_CODE); + out.writeShort(OUTPUT_LENGTH); + PortAction port = action.getAugmentation(PortAction.class); + out.writeShort(port.getPort().getValue().intValue()); + MaxLengthAction maxlength = action.getAugmentation(MaxLengthAction.class); + out.writeShort(maxlength.getMaxLength()); + } + + private static void encodeSetVlanVidAction(Action action, ByteBuf out) { + out.writeShort(SET_VLAN_VID_CODE); + out.writeShort(SET_VLAN_VID_LENGTH); + out.writeShort(action.getAugmentation(VlanVidAction.class).getVlanVid()); + ByteBufUtils.padBuffer(PADDING_IN_SET_VLAN_VID_ACTION, out); + } + + private static void encodeSetVlanPcpAction(Action action, ByteBuf out) { + out.writeShort(SET_VLAN_PCP_CODE); + out.writeShort(SET_VLAN_PCP_LENGTH); + out.writeByte(action.getAugmentation(VlanPcpAction.class).getVlanPcp()); + ByteBufUtils.padBuffer(PADDING_IN_SET_VLAN_PCP_ACTION, out); + } + + private static void encodeDlAddressAction(Action action, ByteBuf out, byte code) { + out.writeShort(code); + out.writeShort(DL_ADDRESS_ACTION_LENGTH); + out.writeBytes(action.getAugmentation(DlAddressAction.class) + .getDlAddress().getValue().getBytes()); + ByteBufUtils.padBuffer(PADDING_IN_DL_ADDRESS_ACTION, out); + } + + private static void encodeNwTosAction(Action action, ByteBuf out) { + out.writeShort(SET_NW_TOS_CODE); + out.writeShort(SET_NW_TOS_LENGTH); + out.writeByte(action.getAugmentation(NwTosAction.class).getNwTos()); + ByteBufUtils.padBuffer(PADDING_IN_SET_NW_TOS_ACTION, out); + } + + private static void encodeIpAddressAction(Action action, ByteBuf out, byte code) { + out.writeShort(code); + out.writeShort(IP_ADDRESS_ACTION_LENGTH); + String[] addressGroups = action. + getAugmentation(IpAddressAction.class).getIpAddress().getValue().split("\\."); + for (int i = 0; i < addressGroups.length; i++) { + out.writeByte(Integer.parseInt(addressGroups[i])); + } + } + + private static void encodeTpPortAction(Action action, ByteBuf out, byte code) { + out.writeShort(code); + out.writeShort(TP_PORT_ACTION_LENGTH); + PortAction port = action.getAugmentation(PortAction.class); + out.writeShort(port.getPort().getValue().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_TP_PORT_ACTION, out); + } + + private static void encodeEnqueueAction(Action action, ByteBuf out) { + out.writeShort(ENQUEUE_CODE); + out.writeShort(ENQUEUE_LENGTH); + PortAction port = action.getAugmentation(PortAction.class); + out.writeShort(port.getPort().getValue().intValue()); + ByteBufUtils.padBuffer(PADDING_IN_ENQUEUE_ACTION, out); + QueueIdAction queueId = action.getAugmentation(QueueIdAction.class); + out.writeShort(queueId.getQueueId().intValue()); + } + + private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) { + outBuffer.writeShort(EXPERIMENTER_CODE); + outBuffer.writeShort(EXPERIMENTER_LENGTH); + ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); + outBuffer.writeInt(experimenter.getExperimenter().intValue()); + } + + /** + * Computes length of actions + * @param actionsList + * @return length of actions (OpenFlow v1.0) + */ + public static int computeActionsLength(List actionsList) { + int length = 0; + if (actionsList != null) { + for (ActionsList list : actionsList) { + Action action = list.getAction(); + if (action.getType().equals(Output.class)) { + length += 8; + } else if (action.getType().equals(SetVlanVid.class)) { + length += 8; + } else if (action.getType().equals(SetVlanPcp.class)) { + length += 8; + } else if (action.getType().equals(StripVlan.class)) { + length += 8; + } else if (action.getType().equals(SetDlSrc.class)) { + length += 16; + } else if (action.getType().equals(SetDlDst.class)) { + length += 16; + } else if (action.getType().equals(SetNwSrc.class)) { + length += 8; + } else if (action.getType().equals(SetNwDst.class)) { + length += 8; + } else if (action.getType().equals(SetNwTos.class)) { + length += 8; + } else if (action.getType().equals(SetTpSrc.class)) { + length += 8; + } else if (action.getType().equals(SetTpDst.class)) { + length += 8; + } else if (action.getType().equals(Enqueue.class)) { + length += 16; + } else if (action.getType().equals(Experimenter.class)) { + length += 8; + } + } + } + return length; + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializer.java index 026474cd..e601d95a 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializer.java @@ -1,99 +1,106 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder; - -import com.google.common.base.Joiner; - -/** - * Deserializes ofp_match (OpenFlow v1.0) structure - * @author michal.polkorab - */ -public abstract class OF10MatchDeserializer { - - private static final byte PADDING_IN_MATCH = 1; - private static final byte PADDING_IN_MATCH_2 = 2; - private static final byte NW_SRC_BITS = 6; - private static final byte NW_SRC_SHIFT = 8; - private static final int NW_SRC_MASK = ((1 << NW_SRC_BITS) - 1) << NW_SRC_SHIFT; - private static final byte NW_DST_BITS = 6; - private static final byte NW_DST_SHIFT = 14; - private static final int NW_DST_MASK = ((1 << NW_DST_BITS) - 1) << NW_DST_SHIFT; - - /** - * Creates ofp_match (OpenFlow v1.0) structure - * @param rawMessage ByteBuf with input data - * @return ofp_match (OpenFlow v1.0) - */ - public static MatchV10 createMatchV10(ByteBuf rawMessage) { - MatchV10Builder builder = new MatchV10Builder(); - long wildcards = rawMessage.readUnsignedInt(); - builder.setWildcards(createWildcards(wildcards)); - builder.setNwSrcMask(decodeNwSrcMask(wildcards)); - builder.setNwDstMask(decodeNwDstMask(wildcards)); - builder.setInPort(rawMessage.readUnsignedShort()); - byte[] dlSrc = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - rawMessage.readBytes(dlSrc); - builder.setDlSrc(new MacAddress(ByteBufUtils.macAddressToString(dlSrc))); - byte[] dlDst = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - rawMessage.readBytes(dlDst); - builder.setDlDst(new MacAddress(ByteBufUtils.macAddressToString(dlDst))); - - builder.setDlVlan(rawMessage.readUnsignedShort()); - builder.setDlVlanPcp(rawMessage.readUnsignedByte()); - rawMessage.skipBytes(PADDING_IN_MATCH); - builder.setDlType(rawMessage.readUnsignedShort()); - builder.setNwTos(rawMessage.readUnsignedByte()); - builder.setNwProto(rawMessage.readUnsignedByte()); - rawMessage.skipBytes(PADDING_IN_MATCH_2); - List srcGroups = new ArrayList<>(); - for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { - srcGroups.add(Short.toString(rawMessage.readUnsignedByte())); - } - Joiner joiner = Joiner.on("."); - builder.setNwSrc(new Ipv4Address(joiner.join(srcGroups))); - List dstGroups = new ArrayList<>(); - for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { - dstGroups.add(Short.toString(rawMessage.readUnsignedByte())); - } - builder.setNwDst(new Ipv4Address(joiner.join(dstGroups))); - builder.setTpSrc(rawMessage.readUnsignedShort()); - builder.setTpDst(rawMessage.readUnsignedShort()); - return builder.build(); - } - - private static FlowWildcardsV10 createWildcards(long input) { - boolean _iNPORT = (input & (1 << 0)) != 0; - boolean _dLVLAN = (input & (1 << 1)) != 0; - boolean _dLSRC = (input & (1 << 2)) != 0; - boolean _dLDST = (input & (1 << 3)) != 0; - boolean _dLTYPE = (input & (1 << 4)) != 0; - boolean _nWPROTO = (input & (1 << 5)) != 0; - boolean _tPSRC = (input & (1 << 6)) != 0; - boolean _tPDST = (input & (1 << 7)) != 0; - boolean _dLVLANPCP = (input & (1 << 20)) != 0; - boolean _nWTOS = (input & (1 << 21)) != 0; - int allBits = (1 << 22) - 1; - boolean _aLL = (input & allBits) == allBits; - return new FlowWildcardsV10(_aLL, _dLDST, _dLSRC, _dLTYPE, _dLVLAN, - _dLVLANPCP, _iNPORT, _nWPROTO, _nWTOS, _tPDST, _tPSRC); - } - - private static short decodeNwSrcMask(long input) { - return (short) Math.max(32 - ((input & NW_SRC_MASK) >> NW_SRC_SHIFT), 0); - } - - private static short decodeNwDstMask(long input) { - return (short) Math.max(32 - ((input & NW_DST_MASK) >> NW_DST_SHIFT), 0); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder; + +import com.google.common.base.Joiner; + +/** + * Deserializes ofp_match (OpenFlow v1.0) structure + * @author michal.polkorab + */ +public abstract class OF10MatchDeserializer { + + private static final byte PADDING_IN_MATCH = 1; + private static final byte PADDING_IN_MATCH_2 = 2; + private static final byte NW_SRC_BITS = 6; + private static final byte NW_SRC_SHIFT = 8; + private static final int NW_SRC_MASK = ((1 << NW_SRC_BITS) - 1) << NW_SRC_SHIFT; + private static final byte NW_DST_BITS = 6; + private static final byte NW_DST_SHIFT = 14; + private static final int NW_DST_MASK = ((1 << NW_DST_BITS) - 1) << NW_DST_SHIFT; + + /** + * Creates ofp_match (OpenFlow v1.0) structure + * @param rawMessage ByteBuf with input data + * @return ofp_match (OpenFlow v1.0) + */ + public static MatchV10 createMatchV10(ByteBuf rawMessage) { + MatchV10Builder builder = new MatchV10Builder(); + long wildcards = rawMessage.readUnsignedInt(); + builder.setWildcards(createWildcards(wildcards)); + builder.setNwSrcMask(decodeNwSrcMask(wildcards)); + builder.setNwDstMask(decodeNwDstMask(wildcards)); + builder.setInPort(rawMessage.readUnsignedShort()); + byte[] dlSrc = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + rawMessage.readBytes(dlSrc); + builder.setDlSrc(new MacAddress(ByteBufUtils.macAddressToString(dlSrc))); + byte[] dlDst = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + rawMessage.readBytes(dlDst); + builder.setDlDst(new MacAddress(ByteBufUtils.macAddressToString(dlDst))); + + builder.setDlVlan(rawMessage.readUnsignedShort()); + builder.setDlVlanPcp(rawMessage.readUnsignedByte()); + rawMessage.skipBytes(PADDING_IN_MATCH); + builder.setDlType(rawMessage.readUnsignedShort()); + builder.setNwTos(rawMessage.readUnsignedByte()); + builder.setNwProto(rawMessage.readUnsignedByte()); + rawMessage.skipBytes(PADDING_IN_MATCH_2); + List srcGroups = new ArrayList<>(); + for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { + srcGroups.add(Short.toString(rawMessage.readUnsignedByte())); + } + Joiner joiner = Joiner.on("."); + builder.setNwSrc(new Ipv4Address(joiner.join(srcGroups))); + List dstGroups = new ArrayList<>(); + for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) { + dstGroups.add(Short.toString(rawMessage.readUnsignedByte())); + } + builder.setNwDst(new Ipv4Address(joiner.join(dstGroups))); + builder.setTpSrc(rawMessage.readUnsignedShort()); + builder.setTpDst(rawMessage.readUnsignedShort()); + return builder.build(); + } + + private static FlowWildcardsV10 createWildcards(long input) { + boolean _iNPORT = (input & (1 << 0)) != 0; + boolean _dLVLAN = (input & (1 << 1)) != 0; + boolean _dLSRC = (input & (1 << 2)) != 0; + boolean _dLDST = (input & (1 << 3)) != 0; + boolean _dLTYPE = (input & (1 << 4)) != 0; + boolean _nWPROTO = (input & (1 << 5)) != 0; + boolean _tPSRC = (input & (1 << 6)) != 0; + boolean _tPDST = (input & (1 << 7)) != 0; + boolean _dLVLANPCP = (input & (1 << 20)) != 0; + boolean _nWTOS = (input & (1 << 21)) != 0; + int allBits = (1 << 22) - 1; + boolean _aLL = (input & allBits) == allBits; + return new FlowWildcardsV10(_aLL, _dLDST, _dLSRC, _dLTYPE, _dLVLAN, + _dLVLANPCP, _iNPORT, _nWPROTO, _nWTOS, _tPDST, _tPSRC); + } + + private static short decodeNwSrcMask(long input) { + return (short) Math.max(32 - ((input & NW_SRC_MASK) >> NW_SRC_SHIFT), 0); + } + + private static short decodeNwDstMask(long input) { + return (short) Math.max(32 - ((input & NW_DST_MASK) >> NW_DST_SHIFT), 0); + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializer.java index 84023e24..aac14a3f 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializer.java @@ -1,76 +1,83 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import java.util.HashMap; -import java.util.Map; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; - -/** - * Serializes ofp_match (OpenFlow v1.0) structure - * @author michal.polkorab - */ -public abstract class OF10MatchSerializer { - - private static final byte PADDING_IN_MATCH = 1; - private static final byte PADDING_IN_MATCH_2 = 2; - private static final byte NW_SRC_SHIFT = 8; - private static final byte NW_DST_SHIFT = 14; - private static final int ALL = ((1 << 22) - 1); - - /** - * Encodes ofp_match (OpenFlow v1.0) - * @param out output ByteBuf that match will be written into - * @param match match to be encoded - */ - public static void encodeMatchV10(ByteBuf out, MatchV10 match) { - out.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask())); - out.writeShort(match.getInPort()); - out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlSrc().getValue())); - out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlDst().getValue())); - out.writeShort(match.getDlVlan()); - out.writeByte(match.getDlVlanPcp()); - ByteBufUtils.padBuffer(PADDING_IN_MATCH, out); - out.writeShort(match.getDlType()); - out.writeByte(match.getNwTos()); - out.writeByte(match.getNwProto()); - ByteBufUtils.padBuffer(PADDING_IN_MATCH_2, out); - String[] srcGroups = match.getNwSrc().getValue().split("\\."); - for (int i = 0; i < srcGroups.length; i++) { - out.writeByte(Integer.parseInt(srcGroups[i])); - } - String[] dstGroups = match.getNwDst().getValue().split("\\."); - for (int i = 0; i < dstGroups.length; i++) { - out.writeByte(Integer.parseInt(dstGroups[i])); - } - out.writeShort(match.getTpSrc()); - out.writeShort(match.getTpDst()); - } - - private static int encodeWildcards(FlowWildcardsV10 wildcards, short srcMask, short dstMask) { - int bitmask = 0; - if (wildcards.isALL()) { - bitmask |= ALL; - } else { - Map wildcardsMap = new HashMap<>(); - wildcardsMap.put(0, wildcards.isINPORT()); - wildcardsMap.put(1, wildcards.isDLVLAN()); - wildcardsMap.put(2, wildcards.isDLSRC()); - wildcardsMap.put(3, wildcards.isDLDST()); - wildcardsMap.put(4, wildcards.isDLTYPE()); - wildcardsMap.put(5, wildcards.isNWPROTO()); - wildcardsMap.put(6, wildcards.isTPSRC()); - wildcardsMap.put(7, wildcards.isTPDST()); - wildcardsMap.put(20, wildcards.isDLVLANPCP()); - wildcardsMap.put(21, wildcards.isNWTOS()); - bitmask = ByteBufUtils.fillBitMaskFromMap(wildcardsMap); - bitmask |= ((32 - srcMask) << NW_SRC_SHIFT); - bitmask |= ((32 - dstMask) << NW_DST_SHIFT); - } - return bitmask; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import java.util.HashMap; +import java.util.Map; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; + +/** + * Serializes ofp_match (OpenFlow v1.0) structure + * @author michal.polkorab + */ +public abstract class OF10MatchSerializer { + + private static final byte PADDING_IN_MATCH = 1; + private static final byte PADDING_IN_MATCH_2 = 2; + private static final byte NW_SRC_SHIFT = 8; + private static final byte NW_DST_SHIFT = 14; + private static final int ALL = ((1 << 22) - 1); + + /** + * Encodes ofp_match (OpenFlow v1.0) + * @param out output ByteBuf that match will be written into + * @param match match to be encoded + */ + public static void encodeMatchV10(ByteBuf out, MatchV10 match) { + out.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask())); + out.writeShort(match.getInPort()); + out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlSrc().getValue())); + out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlDst().getValue())); + out.writeShort(match.getDlVlan()); + out.writeByte(match.getDlVlanPcp()); + ByteBufUtils.padBuffer(PADDING_IN_MATCH, out); + out.writeShort(match.getDlType()); + out.writeByte(match.getNwTos()); + out.writeByte(match.getNwProto()); + ByteBufUtils.padBuffer(PADDING_IN_MATCH_2, out); + String[] srcGroups = match.getNwSrc().getValue().split("\\."); + for (int i = 0; i < srcGroups.length; i++) { + out.writeByte(Integer.parseInt(srcGroups[i])); + } + String[] dstGroups = match.getNwDst().getValue().split("\\."); + for (int i = 0; i < dstGroups.length; i++) { + out.writeByte(Integer.parseInt(dstGroups[i])); + } + out.writeShort(match.getTpSrc()); + out.writeShort(match.getTpDst()); + } + + private static int encodeWildcards(FlowWildcardsV10 wildcards, short srcMask, short dstMask) { + int bitmask = 0; + if (wildcards.isALL()) { + bitmask |= ALL; + } else { + Map wildcardsMap = new HashMap<>(); + wildcardsMap.put(0, wildcards.isINPORT()); + wildcardsMap.put(1, wildcards.isDLVLAN()); + wildcardsMap.put(2, wildcards.isDLSRC()); + wildcardsMap.put(3, wildcards.isDLDST()); + wildcardsMap.put(4, wildcards.isDLTYPE()); + wildcardsMap.put(5, wildcards.isNWPROTO()); + wildcardsMap.put(6, wildcards.isTPSRC()); + wildcardsMap.put(7, wildcards.isTPDST()); + wildcardsMap.put(20, wildcards.isDLVLANPCP()); + wildcardsMap.put(21, wildcards.isNWTOS()); + bitmask = ByteBufUtils.fillBitMaskFromMap(wildcardsMap); + bitmask |= ((32 - srcMask) << NW_SRC_SHIFT); + bitmask |= ((32 - dstMask) << NW_DST_SHIFT); + } + return bitmask; + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/DummyDecoder.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/DummyDecoder.java index 73d5c235..d22196a9 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/DummyDecoder.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/DummyDecoder.java @@ -1,29 +1,36 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.core; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author michal.polkorab - * - */ -public class DummyDecoder extends ByteToMessageDecoder { - - private static final Logger LOGGER = LoggerFactory - .getLogger(DummyDecoder.class); - - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, - List out) throws Exception { - LOGGER.debug("decoding"); - ctx.fireChannelReadComplete(); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.core; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author michal.polkorab + * + */ +public class DummyDecoder extends ByteToMessageDecoder { + + private static final Logger LOGGER = LoggerFactory + .getLogger(DummyDecoder.class); + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf in, + List out) throws Exception { + LOGGER.debug("decoding"); + ctx.fireChannelReadComplete(); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoderTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoderTest.java index 723ce1c9..d758ab8f 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoderTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoderTest.java @@ -1,102 +1,109 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.core; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; - -/** - * Testing class of {@link OFFrameDecoder} - * - * @author michal.polkorab - */ -@RunWith(MockitoJUnitRunner.class) -public class OFFrameDecoderTest { - - @Mock - ChannelHandlerContext channelHandlerContext; - - private OFFrameDecoder decoder; - private List list = new ArrayList<>(); - - /** - * Sets up tests - */ - @Before - public void setUp() { - list.clear(); - decoder = new OFFrameDecoder(); - } - - /** - * Test of decoding - * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} - * - * @throws Exception - */ - @Test - public void testDecode8BMessage() throws Exception { - decoder.decode(channelHandlerContext, - ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"), - list); - - Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes()); - } - - /** - * Test of decoding - * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} - * - * @throws Exception - */ - @Test - public void testDecode16BMessage() throws Exception { - decoder.decode(channelHandlerContext, - ByteBufUtils.hexStringToByteBuf("04 00 00 10 00 00 00 00 00 00 00 00 00 00 00 42"), - list); - - Assert.assertEquals(16, ((ByteBuf) list.get(0)).readableBytes()); - } - - /** - * Test of decoding - * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} - * - * @throws Exception - */ - @Test - public void testDecodeIncompleteMessage() throws Exception { - decoder.decode(channelHandlerContext, - ByteBufUtils.hexStringToByteBuf("04 00 00 08 00"), - list); - - Assert.assertEquals("List is not empty", 0, list.size()); - } - - /** - * Test of decoding - * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} - * - * @throws Exception - */ - @Test - public void testDecodeCompleteAndPartialMessage() throws Exception { - decoder.decode(channelHandlerContext, - ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01 04 00 00 08 00"), - list); - - Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes()); - Assert.assertEquals(1, list.size()); - } - +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.core; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; + +/** + * Testing class of {@link OFFrameDecoder} + * + * @author michal.polkorab + */ +@RunWith(MockitoJUnitRunner.class) +public class OFFrameDecoderTest { + + @Mock + ChannelHandlerContext channelHandlerContext; + + private OFFrameDecoder decoder; + private List list = new ArrayList<>(); + + /** + * Sets up tests + */ + @Before + public void setUp() { + list.clear(); + decoder = new OFFrameDecoder(); + } + + /** + * Test of decoding + * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} + * + * @throws Exception + */ + @Test + public void testDecode8BMessage() throws Exception { + decoder.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"), + list); + + Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes()); + } + + /** + * Test of decoding + * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} + * + * @throws Exception + */ + @Test + public void testDecode16BMessage() throws Exception { + decoder.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("04 00 00 10 00 00 00 00 00 00 00 00 00 00 00 42"), + list); + + Assert.assertEquals(16, ((ByteBuf) list.get(0)).readableBytes()); + } + + /** + * Test of decoding + * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} + * + * @throws Exception + */ + @Test + public void testDecodeIncompleteMessage() throws Exception { + decoder.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("04 00 00 08 00"), + list); + + Assert.assertEquals("List is not empty", 0, list.size()); + } + + /** + * Test of decoding + * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} + * + * @throws Exception + */ + @Test + public void testDecodeCompleteAndPartialMessage() throws Exception { + decoder.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01 04 00 00 08 00"), + list); + + Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes()); + Assert.assertEquals(1, list.size()); + } + } \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetectorTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetectorTest.java index bf862d1b..fb3369bf 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetectorTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetectorTest.java @@ -1,72 +1,79 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.core; - -import io.netty.channel.ChannelHandlerContext; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; - -/** - * - * @author michal.polkorab - */ -@RunWith(MockitoJUnitRunner.class) -public class OFVersionDetectorTest { - - @Mock - ChannelHandlerContext channelHandlerContext; - - private OFVersionDetector detector; - private List list = new ArrayList<>(); - - /** - * Sets up test environment - */ - @Before - public void setUp() { - list.clear(); - detector = new OFVersionDetector(); - } - - /** - * Test of decode - * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) - * } - * - * @throws Exception - */ - @Test - public void testDecode13ProtocolMessage() throws Exception { - detector.decode(channelHandlerContext, - ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"), - list); - - Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)) - .getMessageBuffer().readableBytes()); - } - - /** - * Test of decode - * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) - * } - * - * @throws Exception - */ - @Test - public void testDecodeNotSupportedVersionProtocolMessage() throws Exception { - detector.decode(channelHandlerContext, - ByteBufUtils.hexStringToByteBuf("02 00 00 08 00 00 00 01"), - list); - - Assert.assertEquals("List is not empty", 0, list.size()); - } - +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.core; + +import io.netty.channel.ChannelHandlerContext; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; + +/** + * + * @author michal.polkorab + */ +@RunWith(MockitoJUnitRunner.class) +public class OFVersionDetectorTest { + + @Mock + ChannelHandlerContext channelHandlerContext; + + private OFVersionDetector detector; + private List list = new ArrayList<>(); + + /** + * Sets up test environment + */ + @Before + public void setUp() { + list.clear(); + detector = new OFVersionDetector(); + } + + /** + * Test of decode + * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) + * } + * + * @throws Exception + */ + @Test + public void testDecode13ProtocolMessage() throws Exception { + detector.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"), + list); + + Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)) + .getMessageBuffer().readableBytes()); + } + + /** + * Test of decode + * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) + * } + * + * @throws Exception + */ + @Test + public void testDecodeNotSupportedVersionProtocolMessage() throws Exception { + detector.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("02 00 00 08 00 00 00 01"), + list); + + Assert.assertEquals("List is not empty", 0, list.size()); + } + } \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/TlsDetectorTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/TlsDetectorTest.java index f0d94116..32685846 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/TlsDetectorTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/TlsDetectorTest.java @@ -1,44 +1,51 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.core; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.embedded.EmbeddedChannel; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES; - -/** - * - * @author michal.polkorab - */ -public class TlsDetectorTest { - - private EmbeddedChannel embch; - - /** - * Sets up test environment - */ - @Before - public void setUp() { - TlsDetector tlsDetector = new TlsDetector(); - embch = new EmbeddedChannel(new DummyDecoder()); - embch.pipeline().addFirst(TcpHandler.COMPONENT_NAMES.TLS_DETECTOR.name(), tlsDetector); - } - - /** - * Test of decode {@link TlsDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) } - * @throws Exception - */ - @Test - public void testDecodeNotEncryptedMessage() throws Exception { - byte[] msgs = new byte[]{0x04, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01}; - ByteBuf writeObj = embch.alloc().buffer(64); - writeObj.writeBytes(msgs); - embch.writeInbound(writeObj); - - Assert.assertNull(embch.pipeline().get(COMPONENT_NAMES.TLS_DETECTOR.name())); - Assert.assertNull(embch.pipeline().get(COMPONENT_NAMES.SSL_HANDLER.name())); - } +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.core; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.embedded.EmbeddedChannel; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES; + +/** + * + * @author michal.polkorab + */ +public class TlsDetectorTest { + + private EmbeddedChannel embch; + + /** + * Sets up test environment + */ + @Before + public void setUp() { + TlsDetector tlsDetector = new TlsDetector(); + embch = new EmbeddedChannel(new DummyDecoder()); + embch.pipeline().addFirst(TcpHandler.COMPONENT_NAMES.TLS_DETECTOR.name(), tlsDetector); + } + + /** + * Test of decode {@link TlsDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) } + * @throws Exception + */ + @Test + public void testDecodeNotEncryptedMessage() throws Exception { + byte[] msgs = new byte[]{0x04, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01}; + ByteBuf writeObj = embch.alloc().buffer(64); + writeObj.writeBytes(msgs); + embch.writeInbound(writeObj); + + Assert.assertNull(embch.pipeline().get(COMPONENT_NAMES.TLS_DETECTOR.name())); + Assert.assertNull(embch.pipeline().get(COMPONENT_NAMES.SSL_HANDLER.name())); + } } \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java index 714e23c5..51c700e7 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java @@ -1,39 +1,46 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class BarrierReplyMessageFactoryTest { - - /** - * Testing of {@link BarrierReplyMessageFactory} for correct translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer(); - BarrierOutput builtByFactory = BufferHelper.decodeV13( - BarrierReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - } - - /** - * Testing of {@link BarrierReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testV10() { - ByteBuf bb = BufferHelper.buildBuffer(); - BarrierOutput builtByFactory = BufferHelper.decodeV10( - BarrierReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class BarrierReplyMessageFactoryTest { + + /** + * Testing of {@link BarrierReplyMessageFactory} for correct translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer(); + BarrierOutput builtByFactory = BufferHelper.decodeV13( + BarrierReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + } + + /** + * Testing of {@link BarrierReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testV10() { + ByteBuf bb = BufferHelper.buildBuffer(); + BarrierOutput builtByFactory = BufferHelper.decodeV10( + BarrierReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java index 0d648d01..b257d9d7 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java @@ -1,70 +1,77 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class EchoReplyMessageFactoryTest { - - /** - * Testing {@link EchoReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testWithEmptyDataField() { - ByteBuf bb = BufferHelper.buildBuffer(); - EchoOutput builtByFactory = BufferHelper.decodeV13( - EchoReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - } - - /** - * Testing {@link EchoReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testWithDataFieldSet() { - byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; - ByteBuf bb = BufferHelper.buildBuffer(data); - EchoOutput builtByFactory = BufferHelper.decodeV13( - EchoReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); - } - - /** - * Testing {@link EchoReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testWithEmptyDataFieldV10() { - ByteBuf bb = BufferHelper.buildBuffer(); - EchoOutput builtByFactory = BufferHelper.decodeV10( - EchoReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - } - - /** - * Testing {@link EchoReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testWithDataFieldSetV10() { - byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; - ByteBuf bb = BufferHelper.buildBuffer(data); - EchoOutput builtByFactory = BufferHelper.decodeV10( - EchoReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class EchoReplyMessageFactoryTest { + + /** + * Testing {@link EchoReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testWithEmptyDataField() { + ByteBuf bb = BufferHelper.buildBuffer(); + EchoOutput builtByFactory = BufferHelper.decodeV13( + EchoReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + } + + /** + * Testing {@link EchoReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testWithDataFieldSet() { + byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + ByteBuf bb = BufferHelper.buildBuffer(data); + EchoOutput builtByFactory = BufferHelper.decodeV13( + EchoReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); + } + + /** + * Testing {@link EchoReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testWithEmptyDataFieldV10() { + ByteBuf bb = BufferHelper.buildBuffer(); + EchoOutput builtByFactory = BufferHelper.decodeV10( + EchoReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + } + + /** + * Testing {@link EchoReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testWithDataFieldSetV10() { + byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + ByteBuf bb = BufferHelper.buildBuffer(data); + EchoOutput builtByFactory = BufferHelper.decodeV10( + EchoReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java index da5f60e8..bcb12534 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java @@ -1,70 +1,77 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class EchoRequestMessageFactoryTest { - - /** - * Testing {@link EchoRequestMessageFactory} for correct translation into POJO - */ - @Test - public void testWithEmptyDataField() { - ByteBuf bb = BufferHelper.buildBuffer(); - EchoRequestMessage builtByFactory = BufferHelper.decodeV13( - EchoRequestMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - } - - /** - * Testing {@link EchoRequestMessageFactory} for correct translation into POJO - */ - @Test - public void testWithDataFieldSet() { - byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; - ByteBuf bb = BufferHelper.buildBuffer(data); - EchoRequestMessage builtByFactory = BufferHelper.decodeV13( - EchoRequestMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); - } - - /** - * Testing {@link EchoRequestMessageFactory} for correct translation into POJO - */ - @Test - public void testWithEmptyDataFieldV10() { - ByteBuf bb = BufferHelper.buildBuffer(); - EchoRequestMessage builtByFactory = BufferHelper.decodeV10( - EchoRequestMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - } - - /** - * Testing {@link EchoRequestMessageFactory} for correct translation into POJO - */ - @Test - public void testWithDataFieldSetV10() { - byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; - ByteBuf bb = BufferHelper.buildBuffer(data); - EchoRequestMessage builtByFactory = BufferHelper.decodeV10( - EchoRequestMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class EchoRequestMessageFactoryTest { + + /** + * Testing {@link EchoRequestMessageFactory} for correct translation into POJO + */ + @Test + public void testWithEmptyDataField() { + ByteBuf bb = BufferHelper.buildBuffer(); + EchoRequestMessage builtByFactory = BufferHelper.decodeV13( + EchoRequestMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + } + + /** + * Testing {@link EchoRequestMessageFactory} for correct translation into POJO + */ + @Test + public void testWithDataFieldSet() { + byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + ByteBuf bb = BufferHelper.buildBuffer(data); + EchoRequestMessage builtByFactory = BufferHelper.decodeV13( + EchoRequestMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); + } + + /** + * Testing {@link EchoRequestMessageFactory} for correct translation into POJO + */ + @Test + public void testWithEmptyDataFieldV10() { + ByteBuf bb = BufferHelper.buildBuffer(); + EchoRequestMessage builtByFactory = BufferHelper.decodeV10( + EchoRequestMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + } + + /** + * Testing {@link EchoRequestMessageFactory} for correct translation into POJO + */ + @Test + public void testWithDataFieldSetV10() { + byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + ByteBuf bb = BufferHelper.buildBuffer(data); + EchoRequestMessage builtByFactory = BufferHelper.decodeV10( + EchoRequestMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java index 70e4cb98..e139a77a 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactoryTest.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java index 0c080a13..3f861bb9 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java @@ -1,31 +1,38 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; - -/** - * @author michal.polkorab - * - */ -public class ExperimenterMessageFactoryTest { - - /** - * Testing {@link ExperimenterMessageFactory} for correct translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer("01 02 03 04 01 02 03 04"); - ExperimenterMessage builtByFactory = BufferHelper.decodeV13( - ExperimenterMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong experimenter", 0x01020304L, builtByFactory.getExperimenter().longValue()); - Assert.assertEquals("Wrong expType", 0x01020304L, builtByFactory.getExpType().longValue()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; + +/** + * @author michal.polkorab + * + */ +public class ExperimenterMessageFactoryTest { + + /** + * Testing {@link ExperimenterMessageFactory} for correct translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("01 02 03 04 01 02 03 04"); + ExperimenterMessage builtByFactory = BufferHelper.decodeV13( + ExperimenterMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong experimenter", 0x01020304L, builtByFactory.getExperimenter().longValue()); + Assert.assertEquals("Wrong expType", 0x01020304L, builtByFactory.getExpType().longValue()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java index bf2bc82f..be6dc48c 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java @@ -1,36 +1,43 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class FeaturesReplyMessageFactoryTest { - - /** - * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00" - + " 00 01 41 00 01 02 03"); - GetFeaturesOutput builtByFactory = BufferHelper.decodeV13( - FeaturesReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue()); - Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue()); - Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue()); - Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue()); - Assert.assertEquals("Wrong capabilities", new Capabilities(true, false, false, true, false, true, false), builtByFactory.getCapabilities()); - Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class FeaturesReplyMessageFactoryTest { + + /** + * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00" + + " 00 01 41 00 01 02 03"); + GetFeaturesOutput builtByFactory = BufferHelper.decodeV13( + FeaturesReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue()); + Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue()); + Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue()); + Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue()); + Assert.assertEquals("Wrong capabilities", new Capabilities(true, false, false, true, false, true, false), builtByFactory.getCapabilities()); + Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java index 6e91cff9..4682c147 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java @@ -1,41 +1,48 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class FlowRemovedMessageFactoryTest { - - /** - * Testing {@link FlowRemovedMessageFactory} for correct translation into POJO - */ - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 03 02 04 00 00 00 02" - + " 00 00 00 05 00 01 00 03 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07"); - FlowRemovedMessage builtByFactory = BufferHelper.decodeV13(FlowRemovedMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - - Assert.assertTrue(builtByFactory.getCookie().longValue() == 0x0001020304050607L); - Assert.assertTrue(builtByFactory.getPriority() == 0x03); - Assert.assertEquals("Wrong reason", 0x02, builtByFactory.getReason().getIntValue()); - Assert.assertEquals("Wrong tableId", new TableId(4L), builtByFactory.getTableId()); - Assert.assertEquals("Wrong durationSec", 0x02L, builtByFactory.getDurationSec().longValue()); - Assert.assertEquals("Wrong durationNsec", 0x05L, builtByFactory.getDurationNsec().longValue()); - Assert.assertEquals("Wrong idleTimeout", 0x01, builtByFactory.getIdleTimeout().intValue()); - Assert.assertEquals("Wrong hardTimeout", 0x03, builtByFactory.getHardTimeout().intValue()); - Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue()); - Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class FlowRemovedMessageFactoryTest { + + /** + * Testing {@link FlowRemovedMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 03 02 04 00 00 00 02" + + " 00 00 00 05 00 01 00 03 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07"); + FlowRemovedMessage builtByFactory = BufferHelper.decodeV13(FlowRemovedMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + + Assert.assertTrue(builtByFactory.getCookie().longValue() == 0x0001020304050607L); + Assert.assertTrue(builtByFactory.getPriority() == 0x03); + Assert.assertEquals("Wrong reason", 0x02, builtByFactory.getReason().getIntValue()); + Assert.assertEquals("Wrong tableId", new TableId(4L), builtByFactory.getTableId()); + Assert.assertEquals("Wrong durationSec", 0x02L, builtByFactory.getDurationSec().longValue()); + Assert.assertEquals("Wrong durationNsec", 0x05L, builtByFactory.getDurationNsec().longValue()); + Assert.assertEquals("Wrong idleTimeout", 0x01, builtByFactory.getIdleTimeout().intValue()); + Assert.assertEquals("Wrong hardTimeout", 0x03, builtByFactory.getHardTimeout().intValue()); + Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue()); + Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java index 92a38f61..0326720d 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetAsyncReplyMessageFactoryTest.java @@ -1,109 +1,116 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder; - -/** - * @author timotej.kubas - * - */ -public class GetAsyncReplyMessageFactoryTest { - - - /** - * Testing {@link GetAsyncReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testGetAsyncReplyMessage() { - ByteBuf bb = BufferHelper.buildBuffer("00 00 00 06 "+ - "00 00 00 05 "+ - "00 00 00 07 "+ - "00 00 00 00 "+ - "00 00 00 03 "+ - "00 00 00 0A"); - GetAsyncOutput builtByFactory = BufferHelper.decodeV13(GetAsyncReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong packetInMask",createPacketInMask(), - builtByFactory.getPacketInMask()); - Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), - builtByFactory.getPortStatusMask()); - Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), - builtByFactory.getFlowRemovedMask()); - } - - private static List createPacketInMask() { - List inMasks = new ArrayList<>(); - PacketInMaskBuilder maskBuilder; - // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER - maskBuilder = new PacketInMaskBuilder(); - List reasons = new ArrayList<>(); - reasons.add(PacketInReason.OFPRACTION); - reasons.add(PacketInReason.OFPRINVALIDTTL); - maskBuilder.setMask(reasons); - inMasks.add(maskBuilder.build()); - // OFPCR_ROLE_SLAVE - maskBuilder = new PacketInMaskBuilder(); - reasons = new ArrayList<>(); - reasons.add(PacketInReason.OFPRNOMATCH); - reasons.add(PacketInReason.OFPRINVALIDTTL); - maskBuilder.setMask(reasons); - inMasks.add(maskBuilder.build()); - return inMasks; - } - - private static List createPortStatusMask() { - List inMasks = new ArrayList<>(); - PortStatusMaskBuilder maskBuilder; - // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER - maskBuilder = new PortStatusMaskBuilder(); - List reasons = new ArrayList<>(); - reasons.add(PortReason.OFPPRADD); - reasons.add(PortReason.OFPPRDELETE); - reasons.add(PortReason.OFPPRMODIFY); - inMasks.add(maskBuilder.setMask(reasons).build()); - // OFPCR_ROLE_SLAVE - maskBuilder = new PortStatusMaskBuilder(); - reasons = new ArrayList<>(); - maskBuilder.setMask(reasons); - inMasks.add(maskBuilder.build()); - return inMasks; - } - - private static List createFlowRemovedMask() { - List inMasks = new ArrayList<>(); - FlowRemovedMaskBuilder maskBuilder; - // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER - maskBuilder = new FlowRemovedMaskBuilder(); - List reasons = new ArrayList<>(); - reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT); - reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT); - maskBuilder.setMask(reasons); - inMasks.add(maskBuilder.build()); - // OFPCR_ROLE_SLAVE - maskBuilder = new FlowRemovedMaskBuilder(); - reasons = new ArrayList<>(); - reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT); - reasons.add(FlowRemovedReason.OFPRRGROUPDELETE); - maskBuilder.setMask(reasons); - inMasks.add(maskBuilder.build()); - return inMasks; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder; + +/** + * @author timotej.kubas + * + */ +public class GetAsyncReplyMessageFactoryTest { + + + /** + * Testing {@link GetAsyncReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testGetAsyncReplyMessage() { + ByteBuf bb = BufferHelper.buildBuffer("00 00 00 06 "+ + "00 00 00 05 "+ + "00 00 00 07 "+ + "00 00 00 00 "+ + "00 00 00 03 "+ + "00 00 00 0A"); + GetAsyncOutput builtByFactory = BufferHelper.decodeV13(GetAsyncReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong packetInMask",createPacketInMask(), + builtByFactory.getPacketInMask()); + Assert.assertEquals("Wrong portStatusMask",createPortStatusMask(), + builtByFactory.getPortStatusMask()); + Assert.assertEquals("Wrong flowRemovedMask",createFlowRemovedMask(), + builtByFactory.getFlowRemovedMask()); + } + + private static List createPacketInMask() { + List inMasks = new ArrayList<>(); + PacketInMaskBuilder maskBuilder; + // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER + maskBuilder = new PacketInMaskBuilder(); + List reasons = new ArrayList<>(); + reasons.add(PacketInReason.OFPRACTION); + reasons.add(PacketInReason.OFPRINVALIDTTL); + maskBuilder.setMask(reasons); + inMasks.add(maskBuilder.build()); + // OFPCR_ROLE_SLAVE + maskBuilder = new PacketInMaskBuilder(); + reasons = new ArrayList<>(); + reasons.add(PacketInReason.OFPRNOMATCH); + reasons.add(PacketInReason.OFPRINVALIDTTL); + maskBuilder.setMask(reasons); + inMasks.add(maskBuilder.build()); + return inMasks; + } + + private static List createPortStatusMask() { + List inMasks = new ArrayList<>(); + PortStatusMaskBuilder maskBuilder; + // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER + maskBuilder = new PortStatusMaskBuilder(); + List reasons = new ArrayList<>(); + reasons.add(PortReason.OFPPRADD); + reasons.add(PortReason.OFPPRDELETE); + reasons.add(PortReason.OFPPRMODIFY); + inMasks.add(maskBuilder.setMask(reasons).build()); + // OFPCR_ROLE_SLAVE + maskBuilder = new PortStatusMaskBuilder(); + reasons = new ArrayList<>(); + maskBuilder.setMask(reasons); + inMasks.add(maskBuilder.build()); + return inMasks; + } + + private static List createFlowRemovedMask() { + List inMasks = new ArrayList<>(); + FlowRemovedMaskBuilder maskBuilder; + // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER + maskBuilder = new FlowRemovedMaskBuilder(); + List reasons = new ArrayList<>(); + reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT); + reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT); + maskBuilder.setMask(reasons); + inMasks.add(maskBuilder.build()); + // OFPCR_ROLE_SLAVE + maskBuilder = new FlowRemovedMaskBuilder(); + reasons = new ArrayList<>(); + reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT); + reasons.add(FlowRemovedReason.OFPRRGROUPDELETE); + maskBuilder.setMask(reasons); + inMasks.add(maskBuilder.build()); + return inMasks; + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java index 8a8717dd..3e39ecb7 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java @@ -1,31 +1,38 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class GetConfigReplyMessageFactoryTest { - - /** - * Testing {@link GetConfigReplyMessageFactory} for correct translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer("00 01 00 03"); - GetConfigOutput builtByFactory = BufferHelper.decodeV13( - GetConfigReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong switchConfigFlag", 0x01, builtByFactory.getFlags().getIntValue()); - Assert.assertEquals("Wrong missSendLen", 0x03, builtByFactory.getMissSendLen().intValue()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class GetConfigReplyMessageFactoryTest { + + /** + * Testing {@link GetConfigReplyMessageFactory} for correct translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 00 03"); + GetConfigOutput builtByFactory = BufferHelper.decodeV13( + GetConfigReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong switchConfigFlag", 0x01, builtByFactory.getFlags().getIntValue()); + Assert.assertEquals("Wrong missSendLen", 0x03, builtByFactory.getMissSendLen().intValue()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java index b2433433..0ab67a9a 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java @@ -1,64 +1,71 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import java.util.ArrayList; -import java.util.List; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class HelloMessageFactoryTest { - - /** Number of currently supported version / codec */ - public static final Short VERSION_YET_SUPPORTED = 0x04; - - /** - * Testing {@link HelloMessageFactory} for correct translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer("00 01 " // type - + "00 0c " // length - + "00 00 00 11 " // bitmap 1 - + "00 00 00 00 " // bitmap 2 - + "00 00 00 00" // padding - ); - HelloMessage builtByFactory = BufferHelper.decodeV13( - HelloMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - List element = createElement(); - Assert.assertEquals("Wrong type", element.get(0).getType(), builtByFactory.getElements().get(0).getType()); - Assert.assertEquals("Wrong versionBitmap", element.get(0).getVersionBitmap(), builtByFactory.getElements().get(0).getVersionBitmap()); - } - - private static List createElement() { - ElementsBuilder elementsBuilder = new ElementsBuilder(); - List elementsList = new ArrayList<>(); - List booleanList = new ArrayList<>(); - booleanList.add(true); - booleanList.add(false); - booleanList.add(false); - booleanList.add(false); - booleanList.add(true); - for (int i = 1; i < 60; i++) { - booleanList.add(false); - } - elementsBuilder.setType(HelloElementType.forValue(1)); - elementsBuilder.setVersionBitmap(booleanList); - elementsList.add(elementsBuilder.build()); - - return elementsList; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import java.util.ArrayList; +import java.util.List; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class HelloMessageFactoryTest { + + /** Number of currently supported version / codec */ + public static final Short VERSION_YET_SUPPORTED = 0x04; + + /** + * Testing {@link HelloMessageFactory} for correct translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 " // type + + "00 0c " // length + + "00 00 00 11 " // bitmap 1 + + "00 00 00 00 " // bitmap 2 + + "00 00 00 00" // padding + ); + HelloMessage builtByFactory = BufferHelper.decodeV13( + HelloMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + List element = createElement(); + Assert.assertEquals("Wrong type", element.get(0).getType(), builtByFactory.getElements().get(0).getType()); + Assert.assertEquals("Wrong versionBitmap", element.get(0).getVersionBitmap(), builtByFactory.getElements().get(0).getVersionBitmap()); + } + + private static List createElement() { + ElementsBuilder elementsBuilder = new ElementsBuilder(); + List elementsList = new ArrayList<>(); + List booleanList = new ArrayList<>(); + booleanList.add(true); + booleanList.add(false); + booleanList.add(false); + booleanList.add(false); + booleanList.add(true); + for (int i = 1; i < 60; i++) { + booleanList.add(false); + } + elementsBuilder.setType(HelloElementType.forValue(1)); + elementsBuilder.setVersionBitmap(booleanList); + elementsList.add(elementsBuilder.build()); + + return elementsList; + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java index 4bf03079..821da87e 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java @@ -1,1231 +1,1238 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.math.BigInteger; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDrop; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemark; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregate; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDesc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroup; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDesc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDesc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStats; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class MultipartReplyMessageFactoryTest { - - private static final Logger LOGGER = LoggerFactory - .getLogger(MultipartReplyMessageFactoryTest.class); - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - *//* - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 01 02 03 04"); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - - Assert.assertEquals("Wrong type", 0x07, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - //Assert.assertArrayEquals("Wrong body", new byte[]{0x01, 0x02, 0x03, 0x04}, builtByFactory.getBody()); - }*/ - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyDescBody(){ - final int DESC_STR_LEN = 256; - final int SERIAL_NUM_LEN = 32; - ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 00 00 00"); - - String mfrDesc = "Manufacturer description"; - byte[] mfrDescBytes = new byte[256]; - mfrDescBytes = mfrDesc.getBytes(); - bb.writeBytes(mfrDescBytes); - ByteBufUtils.padBuffer((DESC_STR_LEN - mfrDescBytes.length), bb); - - String hwDesc = "Hardware description"; - byte[] hwDescBytes = new byte[256]; - hwDescBytes = hwDesc.getBytes(); - bb.writeBytes(hwDescBytes); - ByteBufUtils.padBuffer((DESC_STR_LEN - hwDescBytes.length), bb); - - String swDesc = "Software description"; - byte[] swDescBytes = new byte[256]; - swDescBytes = swDesc.getBytes(); - bb.writeBytes(swDescBytes); - ByteBufUtils.padBuffer((DESC_STR_LEN - swDescBytes.length), bb); - - String serialNum = "SN0123456789"; - byte[] serialNumBytes = new byte[32]; - serialNumBytes = serialNum.getBytes(); - bb.writeBytes(serialNumBytes); - ByteBufUtils.padBuffer((SERIAL_NUM_LEN - serialNumBytes.length), bb); - - String dpDesc = "switch3 in room 3120"; - byte[] dpDescBytes = new byte[256]; - dpDescBytes = dpDesc.getBytes(); - bb.writeBytes(dpDescBytes); - ByteBufUtils.padBuffer((DESC_STR_LEN - dpDescBytes.length), bb); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 0x00, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - MultipartReplyDesc message = (MultipartReplyDesc) builtByFactory.getMultipartReplyBody(); - Assert.assertEquals("Wrong mfrDesc", "Manufacturer description", message.getMfrDesc()); - Assert.assertEquals("Wrong hwDesc", "Hardware description", message.getHwDesc()); - Assert.assertEquals("Wrong swDesc", "Software description", message.getSwDesc()); - Assert.assertEquals("Wrong serialNum", "SN0123456789", message.getSerialNum()); - Assert.assertEquals("Wrong dpDesc", "switch3 in room 3120", message.getDpDesc()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyFlowBody(){ - ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00 "+ - "00 0C "+//length - "08 "+//tableId - "00 "+//pad_01 - "00 00 00 09 "+//durationSec - "00 00 00 07 "+//durationNsec - "00 0C "+//priority - "00 0E "+//idleTimeout - "00 0F "+//hardTimeout - "00 0B "+//flags - "00 00 00 00 "+//pad_02 - "00 01 01 01 01 01 01 01 "+//cookie - "00 01 01 01 01 01 01 01 "+//packetCount - "00 01 01 01 01 01 01 01"//byteCount - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - MultipartReplyFlow message = (MultipartReplyFlow) builtByFactory.getMultipartReplyBody(); - Assert.assertEquals("Wrong tableId", 8, message.getFlowStats().get(0).getTableId().intValue()); - Assert.assertEquals("Wrong durationSec", 9, message.getFlowStats().get(0).getDurationSec().intValue()); - Assert.assertEquals("Wrong durationNsec", 7, message.getFlowStats().get(0).getDurationNsec().intValue()); - Assert.assertEquals("Wrong priority", 12, message.getFlowStats().get(0).getPriority().intValue()); - Assert.assertEquals("Wrong idleTimeOut", 14, message.getFlowStats().get(0).getIdleTimeout().intValue()); - Assert.assertEquals("Wrong hardTimeOut", 15, message.getFlowStats().get(0).getHardTimeout().intValue()); - Assert.assertEquals("Wrong flags", new FlowModFlags(true, false, true, false, true), - message.getFlowStats().get(0).getFlags()); - Assert.assertEquals("Wrong cookie", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getFlowStats().get(0).getCookie()); - Assert.assertEquals("Wrong packetCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getFlowStats().get(0).getPacketCount()); - Assert.assertEquals("Wrong byteCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getFlowStats().get(0).getByteCount()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyAggregateBody(){ - ByteBuf bb = BufferHelper.buildBuffer("00 02 00 01 00 00 00 00 "+ - "00 01 01 01 01 01 01 01 "+//packetCount - "00 01 01 01 01 01 01 01 "+//byteCount - "00 00 00 08 "+//flowCount - "00 00 00 00"//pad - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 0x02, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - MultipartReplyAggregate message = (MultipartReplyAggregate) builtByFactory.getMultipartReplyBody(); - Assert.assertEquals("Wrong packetCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getPacketCount()); - Assert.assertEquals("Wrong byteCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getByteCount()); - Assert.assertEquals("Wrong flowCount", - 8, - message.getFlowCount().intValue()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyTableBody(){ - ByteBuf bb = BufferHelper.buildBuffer("00 03 00 01 00 00 00 00 "+ - "08 "+//tableId - "00 00 00 "+//pad - "00 00 00 10 "+//activeCount - "00 01 01 01 01 01 01 01 "+//lookupCount - "00 01 01 01 01 01 01 01"//matchedCount - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyTable message = (MultipartReplyTable) builtByFactory.getMultipartReplyBody(); - Assert.assertEquals("Wrong tableId", 8, message.getTableStats().get(0).getTableId().intValue()); - Assert.assertEquals("Wrong activeCount", 16, message.getTableStats().get(0).getActiveCount().longValue()); - Assert.assertEquals("Wrong lookupCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getTableStats().get(0).getLookupCount()); - Assert.assertEquals("Wrong matchedCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getTableStats().get(0).getMatchedCount()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyPortStatsBody(){ - ByteBuf bb = BufferHelper.buildBuffer("00 04 00 01 00 00 00 00 "+ - "00 00 00 FF "+//portNo - "00 00 00 00 "+//pad - "00 01 01 01 01 01 01 01 "+//rxPackets - "00 02 02 02 02 02 02 02 "+//txPackets - "00 02 03 02 03 02 03 02 "+//rxBytes - "00 02 03 02 03 02 03 02 "+//txBytes - "00 02 03 02 03 02 03 02 "+//rxDropped - "00 02 03 02 03 02 03 02 "+//txDropped - "00 02 03 02 03 02 03 02 "+//rxErrors - "00 02 03 02 03 02 03 02 "+//txErrors - "00 02 03 02 03 02 03 02 "+//rxFrameErr - "00 02 03 02 03 02 03 02 "+//rxOverErr - "00 02 03 02 03 02 03 02 "+//rxCrcErr - "00 02 03 02 03 02 03 02 "+//collisions - "00 00 00 02 "+//durationSec - "00 00 00 04"//durationNsec - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 0x04, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyPortStats message = (MultipartReplyPortStats) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong portNo", 255, message.getPortStats().get(0).getPortNo().intValue()); - Assert.assertEquals("Wrong rxPackets", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getPortStats().get(0).getRxPackets()); - Assert.assertEquals("Wrong txPackets", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getPortStats().get(0).getTxPackets()); - Assert.assertEquals("Wrong rxBytes", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getPortStats().get(0).getRxBytes()); - Assert.assertEquals("Wrong txBytes", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getPortStats().get(0).getTxBytes()); - Assert.assertEquals("Wrong rxDropped", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getPortStats().get(0).getRxDropped()); - Assert.assertEquals("Wrong txDropped", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getPortStats().get(0).getTxDropped()); - Assert.assertEquals("Wrong rxErrors", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getPortStats().get(0).getRxErrors()); - Assert.assertEquals("Wrong txErrors", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getPortStats().get(0).getTxErrors()); - Assert.assertEquals("Wrong rxFrameErr", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getPortStats().get(0).getRxFrameErr()); - Assert.assertEquals("Wrong rxOverErr", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getPortStats().get(0).getRxOverErr()); - Assert.assertEquals("Wrong rxCrcErr", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getPortStats().get(0).getRxCrcErr()); - Assert.assertEquals("Wrong collisions", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getPortStats().get(0).getCollisions()); - Assert.assertEquals("Wrong durationSec", 2, message.getPortStats().get(0).getDurationSec().intValue()); - Assert.assertEquals("Wrong durationNsec", 4, message.getPortStats().get(0).getDurationNsec().intValue()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyQueueBody(){ - ByteBuf bb = BufferHelper.buildBuffer("00 05 00 01 00 00 00 00 "+ - "00 00 00 FF "+//portNo - "00 00 00 10 "+//queueId - "00 02 03 02 03 02 03 02 "+//txBytes - "00 02 02 02 02 02 02 02 "+//txPackets - "00 02 03 02 03 02 03 02 "+//txErrors - "00 00 00 02 "+//durationSec - "00 00 00 04"//durationNsec - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 0x05, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyQueue message = (MultipartReplyQueue) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong portNo", 255, message.getQueueStats().get(0).getPortNo().intValue()); - Assert.assertEquals("Wrong queueId", 16, message.getQueueStats().get(0).getQueueId().intValue()); - Assert.assertEquals("Wrong txBytes", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getQueueStats().get(0).getTxBytes()); - Assert.assertEquals("Wrong txPackets", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getQueueStats().get(0).getTxPackets()); - Assert.assertEquals("Wrong txErrors", - new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), - message.getQueueStats().get(0).getTxErrors()); - Assert.assertEquals("Wrong durationSec", 2, message.getQueueStats().get(0).getDurationSec().intValue()); - Assert.assertEquals("Wrong durationNsec", 4, message.getQueueStats().get(0).getDurationNsec().intValue()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyGroupBody(){ - ByteBuf bb = BufferHelper.buildBuffer("00 06 00 01 00 00 00 00 "+ - "00 48 "+//length - "00 00 "+//pad1 - "00 00 00 10 "+//groupId - "00 00 00 12 "+//refCount - "00 00 00 00 "+//pad2 - "00 01 01 01 01 01 01 01 "+//packetCount - "00 01 01 01 01 01 01 01 "+//byteCount - "00 00 00 08 "+//durationSec - "00 00 00 09 "+//durationNsec - "00 01 01 01 01 01 01 01 "+//packetCountBucket - "00 01 01 01 01 01 01 01 "+//byteCountBucket - "00 02 02 02 02 02 02 02 "+//packetCountBucket_2 - "00 02 02 02 02 02 02 02 "+//byteCountBucket_2 - "00 48 "+//length_2 - "00 00 "+//pad1.2 - "00 00 00 10 "+//groupId_2 - "00 00 00 12 "+//refCount_2 - "00 00 00 00 "+//pad2.2 - "00 01 01 01 01 01 01 01 "+//packetCount_2 - "00 01 01 01 01 01 01 01 "+//byteCount_2 - "00 00 00 08 "+//durationSec_2 - "00 00 00 09 "+//durationNsec_2 - "00 01 01 01 01 01 01 01 "+//packetCountBucket_1.2 - "00 01 01 01 01 01 01 01 "+//byteCountBucket_1.2 - "00 02 02 02 02 02 02 02 "+//packetCountBucket_2.2 - "00 02 02 02 02 02 02 02"//byteCountBucket_2.2 - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 0x06, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyGroup message = (MultipartReplyGroup) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong groupId", 16, message.getGroupStats().get(0).getGroupId().getValue().intValue()); - Assert.assertEquals("Wrong refCount", 18, message.getGroupStats().get(0).getRefCount().intValue()); - Assert.assertEquals("Wrong packetCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getGroupStats().get(0).getPacketCount()); - Assert.assertEquals("Wrong byteCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getGroupStats().get(0).getByteCount()); - Assert.assertEquals("Wrong durationSec", 8, message.getGroupStats().get(0).getDurationSec().intValue()); - Assert.assertEquals("Wrong durationNsec", 9, message.getGroupStats().get(0).getDurationNsec().intValue()); - Assert.assertEquals("Wrong packetCountBucket", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getGroupStats().get(0).getBucketStats().get(0).getPacketCount()); - Assert.assertEquals("Wrong byteCountBucket", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getGroupStats().get(0).getBucketStats().get(0).getByteCount()); - Assert.assertEquals("Wrong packetCountBucket_2", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getGroupStats().get(0).getBucketStats().get(1).getPacketCount()); - Assert.assertEquals("Wrong byteCountBucket_2", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getGroupStats().get(0).getBucketStats().get(1).getByteCount()); - - Assert.assertEquals("Wrong groupId_2", 16, message.getGroupStats().get(1).getGroupId().getValue().intValue()); - Assert.assertEquals("Wrong refCount_2", 18, message.getGroupStats().get(1).getRefCount().intValue()); - Assert.assertEquals("Wrong packetCount_2", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getGroupStats().get(1).getPacketCount()); - Assert.assertEquals("Wrong byteCount_2", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getGroupStats().get(1).getByteCount()); - Assert.assertEquals("Wrong durationSec_2", 8, message.getGroupStats().get(1).getDurationSec().intValue()); - Assert.assertEquals("Wrong durationNsec_2", 9, message.getGroupStats().get(1).getDurationNsec().intValue()); - Assert.assertEquals("Wrong packetCountBucket_1.2", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getGroupStats().get(1).getBucketStats().get(0).getPacketCount()); - Assert.assertEquals("Wrong byteCountBucket_1.2", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getGroupStats().get(1).getBucketStats().get(0).getByteCount()); - Assert.assertEquals("Wrong packetCountBucket_2.2", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getGroupStats().get(1).getBucketStats().get(1).getPacketCount()); - Assert.assertEquals("Wrong byteCountBucket_2.2", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getGroupStats().get(1).getBucketStats().get(1).getByteCount()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyMeterFeaturesBody(){ - ByteBuf bb = BufferHelper.buildBuffer("00 0B 00 01 00 00 00 00 "+ - "00 00 00 09 "+//maxMeter - "00 00 00 01 "+//bandTypes - "00 00 00 03 "+//capabilities - "03 "+//maxBands - "04 "+//maxColor - "00 00"//pad - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 11, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyMeterFeatures message = (MultipartReplyMeterFeatures) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong maxMeter", 9, message.getMaxMeter().intValue()); - Assert.assertEquals("Wrong bandTypes", new MeterBandTypeBitmap(true, false), message.getBandTypes()); - Assert.assertEquals("Wrong capabilities", new MeterFlags(false, true, true, false), - message.getCapabilities()); - Assert.assertEquals("Wrong maxBands", 3, message.getMaxBands().intValue()); - Assert.assertEquals("Wrong maxColor", 4, message.getMaxColor().intValue()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyMeterBody(){ - ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+ - "00 00 00 09 "+//meterId - "00 58 "+//len - "00 00 00 00 00 00 "+//pad - "00 00 00 07 "+//flowCount - "00 01 01 01 01 01 01 01 "+//packetInCount - "00 01 01 01 01 01 01 01 "+//byteInCount - "00 00 00 05 "+//durationSec - "00 00 00 05 "+//durationNsec - "00 01 01 01 01 01 01 01 "+//packetBandCount_01 - "00 01 01 01 01 01 01 01 "+//byteBandCount_01 - "00 02 02 02 02 02 02 02 "+//packetBandCount_02 - "00 02 02 02 02 02 02 02 "+//byteBandCount_02 - "00 03 03 03 03 03 03 03 "+//packetBandCount_03 - "00 03 03 03 03 03 03 03"//byteBandCount_03 - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyMeter message = (MultipartReplyMeter) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong meterId", 9, - message.getMeterStats().get(0).getMeterId().getValue().intValue()); - Assert.assertEquals("Wrong flowCount", 7, - message.getMeterStats().get(0).getFlowCount().intValue()); - Assert.assertEquals("Wrong packetInCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(0).getPacketInCount()); - Assert.assertEquals("Wrong byteInCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(0).getByteInCount()); - Assert.assertEquals("Wrong durationSec", 5, - message.getMeterStats().get(0).getDurationSec().intValue()); - Assert.assertEquals("Wrong durationNsec", 5, - message.getMeterStats().get(0).getDurationNsec().intValue()); - Assert.assertEquals("Wrong packetBandCount_01", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount()); - Assert.assertEquals("Wrong byteBandCount_01", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount()); - Assert.assertEquals("Wrong packetBandCount_02", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount()); - Assert.assertEquals("Wrong byteBandCount_02", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount()); - Assert.assertEquals("Wrong packetBandCount_03", - new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), - message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount()); - Assert.assertEquals("Wrong byteBandCount_03", - new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), - message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyMeterBodyMulti(){ - ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+ - "00 00 00 09 "+//meterId_0 - "00 58 "+//len_0 - "00 00 00 00 00 00 "+//pad_0 - "00 00 00 07 "+//flowCount_0 - "00 01 01 01 01 01 01 01 "+//packetInCount_0 - "00 01 01 01 01 01 01 01 "+//byteInCount_0 - "00 00 00 05 "+//durationSec_0 - "00 00 00 05 "+//durationNsec_0 - "00 01 01 01 01 01 01 01 "+//packetBandCount_01 - "00 01 01 01 01 01 01 01 "+//byteBandCount_01 - "00 02 02 02 02 02 02 02 "+//packetBandCount_02 - "00 02 02 02 02 02 02 02 "+//byteBandCount_02 - "00 03 03 03 03 03 03 03 "+//packetBandCount_03 - "00 03 03 03 03 03 03 03 "+//byteBandCount_03 - "00 00 00 08 "+//meterId_1 - "00 58 "+//len_1 - "00 00 00 00 00 00 "+//pad_1 - "00 00 00 07 "+//flowCount_1 - "00 01 01 01 01 01 01 01 "+//packetInCount_1 - "00 01 01 01 01 01 01 01 "+//byteInCount_1 - "00 00 00 05 "+//durationSec_1 - "00 00 00 05 "+//durationNsec_1 - "00 01 01 01 01 01 01 01 "+//packetBandCount_11 - "00 01 01 01 01 01 01 01 "+//byteBandCount_11 - "00 02 02 02 02 02 02 02 "+//packetBandCount_12 - "00 02 02 02 02 02 02 02 "+//byteBandCount_12 - "00 03 03 03 03 03 03 03 "+//packetBandCount_13 - "00 03 03 03 03 03 03 03"//byteBandCount_13 - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyMeter message = (MultipartReplyMeter) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong meterId", 9, - message.getMeterStats().get(0).getMeterId().getValue().intValue()); - Assert.assertEquals("Wrong flowCount", 7, - message.getMeterStats().get(0).getFlowCount().intValue()); - Assert.assertEquals("Wrong packetInCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(0).getPacketInCount()); - Assert.assertEquals("Wrong byteInCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(0).getByteInCount()); - Assert.assertEquals("Wrong durationSec", 5, - message.getMeterStats().get(0).getDurationSec().intValue()); - Assert.assertEquals("Wrong durationNsec", 5, - message.getMeterStats().get(0).getDurationNsec().intValue()); - Assert.assertEquals("Wrong packetBandCount_01", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount()); - Assert.assertEquals("Wrong byteBandCount_01", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount()); - Assert.assertEquals("Wrong packetBandCount_02", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount()); - Assert.assertEquals("Wrong byteBandCount_02", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount()); - Assert.assertEquals("Wrong packetBandCount_03", - new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), - message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount()); - Assert.assertEquals("Wrong byteBandCount_03", - new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), - message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount()); - - Assert.assertEquals("Wrong meterId", 8, - message.getMeterStats().get(1).getMeterId().getValue().intValue()); - Assert.assertEquals("Wrong flowCount", 7, - message.getMeterStats().get(1).getFlowCount().intValue()); - Assert.assertEquals("Wrong packetInCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(1).getPacketInCount()); - Assert.assertEquals("Wrong byteInCount", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(1).getByteInCount()); - Assert.assertEquals("Wrong durationSec", 5, - message.getMeterStats().get(1).getDurationSec().intValue()); - Assert.assertEquals("Wrong durationNsec", 5, - message.getMeterStats().get(1).getDurationNsec().intValue()); - Assert.assertEquals("Wrong packetBandCount_01", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(1).getMeterBandStats().get(0).getPacketBandCount()); - Assert.assertEquals("Wrong byteBandCount_01", - new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), - message.getMeterStats().get(1).getMeterBandStats().get(0).getByteBandCount()); - Assert.assertEquals("Wrong packetBandCount_02", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getMeterStats().get(1).getMeterBandStats().get(1).getPacketBandCount()); - Assert.assertEquals("Wrong byteBandCount_02", - new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), - message.getMeterStats().get(1).getMeterBandStats().get(1).getByteBandCount()); - Assert.assertEquals("Wrong packetBandCount_03", - new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), - message.getMeterStats().get(1).getMeterBandStats().get(2).getPacketBandCount()); - Assert.assertEquals("Wrong byteBandCount_03", - new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), - message.getMeterStats().get(1).getMeterBandStats().get(2).getByteBandCount()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyMeterConfigBody(){ - ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 01 00 00 00 00 "+ - "00 38 "+//len - "00 0A "+//flags - "00 00 00 09 "+//meterId - "00 01 "+//meterBandDrop.type - "00 10 "+//meterBandDrop.len - "00 00 00 11 "+//meterBandDrop.rate - "00 00 00 20 "+//meterBandDrop.burstSize - "00 00 00 00 "+//meterBandDrop.pad - "00 02 "+//meterBandDscp.type - "00 10 "+//meterBandDscp.len - "00 00 00 11 "+//meterBandDscp.rate - "00 00 00 20 "+//meterBandDscp.burstSize - "04 "+//meterBandDscp.precLevel - "00 00 00 "+//meterBandDscp.pad - "FF FF "+//meterBandExperimenter.type - "00 10 "+//meterBandExperimenter.len - "00 00 00 11 "+//meterBandExperimenter.rate - "00 00 00 20 "+//meterBandExperimenter.burstSize - "00 00 00 04"//meterBandExperimenter.experimenter - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyMeterConfig message = (MultipartReplyMeterConfig) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong flags", new MeterFlags(false, false, true, true), - message.getMeterConfig().get(0).getFlags()); - Assert.assertEquals("Wrong meterId", 9, - message.getMeterConfig().get(0).getMeterId().getValue().intValue()); - - MeterBandDrop meterBandDrop = (MeterBandDrop) message.getMeterConfig().get(0).getBands().get(0).getMeterBand(); - Assert.assertEquals("Wrong meterBandDrop.type", 1, meterBandDrop.getType().getIntValue()); - Assert.assertEquals("Wrong meterBandDrop.rate", 17, meterBandDrop.getRate().intValue()); - Assert.assertEquals("Wrong meterBandDrop.burstSize", 32, meterBandDrop.getBurstSize().intValue()); - - MeterBandDscpRemark meterBandDscp = (MeterBandDscpRemark) message.getMeterConfig().get(0).getBands().get(1).getMeterBand(); - Assert.assertEquals("Wrong meterBandDscp.type", 2, meterBandDscp.getType().getIntValue()); - Assert.assertEquals("Wrong meterBandDscp.rate", 17, meterBandDscp.getRate().intValue()); - Assert.assertEquals("Wrong meterBandDscp.burstSize", 32, meterBandDscp.getBurstSize().intValue()); - Assert.assertEquals("Wrong meterBandDscp.precLevel", 4, meterBandDscp.getPrecLevel().intValue()); - - MeterBandExperimenter meterBandExperimenter = (MeterBandExperimenter) message.getMeterConfig().get(0).getBands().get(2).getMeterBand(); - Assert.assertEquals("Wrong meterBandExperimenter.type", 0xFFFF, meterBandExperimenter.getType().getIntValue()); - Assert.assertEquals("Wrong meterBandExperimenter.rate", 17, meterBandExperimenter.getRate().intValue()); - Assert.assertEquals("Wrong meterBandExperimenter.burstSize", 32, meterBandExperimenter.getBurstSize().intValue()); - Assert.assertEquals("Wrong meterBandExperimenter.experimenter", 4, meterBandExperimenter.getExperimenter().intValue()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyMeterConfigBodyMulti(){ - ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 01 00 00 00 00 "+ - "00 38 "+//len - "00 06 "+//flags - "00 00 00 09 "+//meterId - "00 01 "+//meterBandDrop.type - "00 10 "+//meterBandDrop.len - "00 00 00 11 "+//meterBandDrop.rate - "00 00 00 20 "+//meterBandDrop.burstSize - "00 00 00 00 "+//meterBandDrop.pad - "00 02 "+//meterBandDscp.type - "00 10 "+//meterBandDscp.len - "00 00 00 11 "+//meterBandDscp.rate - "00 00 00 20 "+//meterBandDscp.burstSize - "04 "+//meterBandDscp.precLevel - "00 00 00 "+//meterBandDscp.pad - "FF FF "+//meterBandExperimenter.type - "00 10 "+//meterBandExperimenter.len - "00 00 00 11 "+//meterBandExperimenter.rate - "00 00 00 20 "+//meterBandExperimenter.burstSize - "00 00 00 04 "+//meterBandExperimenter.experimenter - - "00 18 "+//len01 - "00 03 "+//flags01 - "00 00 00 07 "+//meterId01 - "00 02 "+//meterBandDscp01.type - "00 10 "+//meterBandDscp01.len - "00 00 00 11 "+//meterBandDscp01.rate - "00 00 00 20 "+//meterBandDscp01.burstSize - "04 "+//meterBandDscp01.precLevel - "00 00 00"//meterBandDscp01.pad - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyMeterConfig message = (MultipartReplyMeterConfig) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong flags", new MeterFlags(true, false, true, false), - message.getMeterConfig().get(0).getFlags()); - Assert.assertEquals("Wrong meterId", 9, - message.getMeterConfig().get(0).getMeterId().getValue().intValue()); - - MeterBandDrop meterBandDrop = (MeterBandDrop) message.getMeterConfig().get(0).getBands().get(0).getMeterBand(); - Assert.assertEquals("Wrong meterBandDrop.type", 1, meterBandDrop.getType().getIntValue()); - Assert.assertEquals("Wrong meterBandDrop.rate", 17, meterBandDrop.getRate().intValue()); - Assert.assertEquals("Wrong meterBandDrop.burstSize", 32, meterBandDrop.getBurstSize().intValue()); - - MeterBandDscpRemark meterBandDscp = (MeterBandDscpRemark) message.getMeterConfig().get(0).getBands().get(1).getMeterBand(); - Assert.assertEquals("Wrong meterBandDscp.type", 2, meterBandDscp.getType().getIntValue()); - Assert.assertEquals("Wrong meterBandDscp.rate", 17, meterBandDscp.getRate().intValue()); - Assert.assertEquals("Wrong meterBandDscp.burstSize", 32, meterBandDscp.getBurstSize().intValue()); - Assert.assertEquals("Wrong meterBandDscp.precLevel", 4, meterBandDscp.getPrecLevel().intValue()); - - MeterBandExperimenter meterBandExperimenter = (MeterBandExperimenter) message.getMeterConfig().get(0).getBands().get(2).getMeterBand(); - Assert.assertEquals("Wrong meterBandExperimenter.type", 0xFFFF, meterBandExperimenter.getType().getIntValue()); - Assert.assertEquals("Wrong meterBandExperimenter.rate", 17, meterBandExperimenter.getRate().intValue()); - Assert.assertEquals("Wrong meterBandExperimenter.burstSize", 32, meterBandExperimenter.getBurstSize().intValue()); - Assert.assertEquals("Wrong meterBandExperimenter.experimenter", 4, meterBandExperimenter.getExperimenter().intValue()); - - LOGGER.info(message.getMeterConfig().get(0).getFlags().toString()); - Assert.assertEquals("Wrong flags01", new MeterFlags(false, true, true, false), - message.getMeterConfig().get(1).getFlags()); - Assert.assertEquals("Wrong meterId01", 7, - message.getMeterConfig().get(1).getMeterId().getValue().intValue()); - - MeterBandDscpRemark meterBandDscp01 = (MeterBandDscpRemark) message.getMeterConfig().get(1).getBands().get(0).getMeterBand(); - Assert.assertEquals("Wrong meterBandDscp01.type", 2, meterBandDscp01.getType().getIntValue()); - Assert.assertEquals("Wrong meterBandDscp01.rate", 17, meterBandDscp01.getRate().intValue()); - Assert.assertEquals("Wrong meterBandDscp01.burstSize", 32, meterBandDscp01.getBurstSize().intValue()); - Assert.assertEquals("Wrong meterBandDscp01.precLevel", 4, meterBandDscp01.getPrecLevel().intValue()); - - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyExperimenterBody(){ - ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 "+ - "00 00 00 0F "+//experimenterId - "00 00 00 FF "+//expType - "00 00 01 01 00 00 01 01" - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 0xFFFF, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyExperimenter message = (MultipartReplyExperimenter) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong experimenterId", 15, message.getExperimenter().intValue()); - Assert.assertEquals("Wrong expType", 255, message.getExpType().intValue()); - Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01}, - message.getData()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testMultipartReplyPortDescBody(){ - final byte MAX_PORT_NAME_LEN = 16; - ByteBuf bb = BufferHelper.buildBuffer("00 0D 00 01 00 00 00 00 "+ - "00 01 02 03 "+ //portNo - "00 00 00 00 "+ //padding01 - "08 00 27 00 B0 EB " + //mac address - "00 00 "); //padding02 - //port name - String portName = "SampleText"; - byte[] portNameBytes = new byte[MAX_PORT_NAME_LEN]; - portNameBytes = portName.getBytes(); - bb.writeBytes(portNameBytes); - ByteBufUtils.padBuffer((MAX_PORT_NAME_LEN - portNameBytes.length), bb); - - ByteBuf bb2 = BufferHelper.buildBuffer("00 00 00 41 " + //port config - "00 00 00 05 " + //port state - "00 00 00 81 " + //current features - "00 00 00 81 " + //advertised features - "00 00 00 81 " + //supported features - "00 00 00 81 " + //peer features - "00 00 00 81 " + //curr speed - "00 00 00 80" //max speed - ); - bb.writeBytes(bb2.copy(4, bb2.readableBytes()-4));//excluding version and xid - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 13, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyPortDesc message = (MultipartReplyPortDesc) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong portNo", 66051L, message.getPorts().get(0).getPortNo().longValue()); - Assert.assertEquals("Wrong macAddress", new MacAddress("08:00:27:00:B0:EB"), - message.getPorts().get(0).getHwAddr()); - Assert.assertEquals("Wrong portName", "SampleText", - message.getPorts().get(0).getName()); - Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), - message.getPorts().get(0).getConfig()); - Assert.assertEquals("Wrong portState", new PortState(false, true, true), - message.getPorts().get(0).getState()); - Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false, - false, false, false, true, - false, false, false, false, - false, false, false, false), - message.getPorts().get(0).getCurrentFeatures()); - Assert.assertEquals("Wrong advertisedFeatures", - new PortFeatures(true, false, false, false, - false, false, false, true, - false, false, false, false, - false, false, false, false), - message.getPorts().get(0).getAdvertisedFeatures()); - Assert.assertEquals("Wrong supportedFeatures", - new PortFeatures(true, false, false, false, - false, false, false, true, - false, false, false, false, - false, false, false, false), - message.getPorts().get(0).getSupportedFeatures()); - Assert.assertEquals("Wrong peerFeatures", - new PortFeatures(true, false, false, false, - false, false, false, true, - false, false, false, false, - false, false, false, false), - message.getPorts().get(0).getPeerFeatures()); - Assert.assertEquals("Wrong currSpeed", 129L, message.getPorts().get(0).getCurrSpeed().longValue()); - Assert.assertEquals("Wrong maxSpeed", 128L, message.getPorts().get(0).getMaxSpeed().longValue()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - * Test covers bodies of actions Output, Copy TTL Out, Copy TTL In - */ - @Test - public void testMultipartReplyGroupDescBody01(){ - ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+ - "00 38 "+//len - "01 "+//type - "00 "+//pad - "00 00 00 08 "+//groupId - "00 30 "+//bucketLen - "00 06 "+//bucketWeight - "00 00 00 05 "+//bucketWatchPort - "00 00 00 04 "+//bucketWatchGroup - "00 00 00 00 "+//bucketPad - "00 00 "+//outputType - "00 10 "+//outputLen - "00 00 10 FF "+//outputPort - "FF FF "+//outputMaxLen - "00 00 00 00 00 00 "+//outputPad - "00 0B "+//copyTTLOutType - "00 08 "+//copyTTLOutLen - "00 00 00 00 "+//copyTTLOutPad - "00 0C "+//copyTTLIntType - "00 08 "+//copyTTLIntLen - "00 00 00 00"//copyTTLInPad - ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyGroupDesc message = (MultipartReplyGroupDesc) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong type", 1, - message.getGroupDesc().get(0).getType().getIntValue()); - Assert.assertEquals("Wrong groupId", 8, - message.getGroupDesc().get(0).getGroupId().getValue().intValue()); - Assert.assertEquals("Wrong bucketWeight", 6, - message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue()); - Assert.assertEquals("Wrong bucketWatchPort", 5, - message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort(). - getValue().intValue()); - Assert.assertEquals("Wrong bucketWatchGroup", 4, - message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue()); - - Assert.assertEquals("Wrong outputType", Output.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). - getAction().getType()); - - Assert.assertEquals("Wrong outputPort", 4351, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). - getAction().getAugmentation(PortAction.class). - getPort().getValue().intValue()); - - Assert.assertEquals("Wrong outputMaxLen", 65535, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). - getAction().getAugmentation(MaxLengthAction.class). - getMaxLength().intValue()); - - Assert.assertEquals("Wrong copyTtlOutType", CopyTtlOut.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). - getAction().getType()); - - Assert.assertEquals("Wrong copyTtlInType", CopyTtlIn.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). - getAction().getType()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - * Test covers bodies of actions Set MPLS TTL , Dec MPLS TTL, Push VLAN. Push MPLS, Push PBB - */ - @Test - public void testMultipartReplyGroupDescBody02(){ - ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+ - "00 40 "+//len - "01 "+//type - "00 "+//pad - "00 00 00 08 "+//groupId - "00 38 "+//bucketLen - "00 06 "+//bucketWeight - "00 00 00 05 "+//bucketWatchPort - "00 00 00 04 "+//bucketWatchGroup - "00 00 00 00 "+//bucketPad - "00 0F "+//setMplsTtlType - "00 08 "+//setMplsTtlLen - "09 "+//setMplsTtlMPLS_TTL - "00 00 00 "+//setMplsTtlPad - "00 10 "+//decMplsTtlType - "00 08 "+//decMplsTtlLen - "00 00 00 00 "+//decMplsTtlPad - "00 11 "+//pushVlanType - "00 08 "+//pushVlanLen - "00 20 "+//pushVlanEthertype - "00 00 "+//pushVlanPad - "00 13 "+//pushMplsType - "00 08 "+//pushMplsLen - "00 FF "+//pushMplsEthertype - "00 00 "+//pushMplsPad - "00 1A "+//pushPbbType - "00 08 "+//pushPbbLen - "0F FF "+//pushPbbEthertype - "00 00"//pushPbbPad - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyGroupDesc message = (MultipartReplyGroupDesc) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong type", 1, - message.getGroupDesc().get(0).getType().getIntValue()); - Assert.assertEquals("Wrong groupId", 8, - message.getGroupDesc().get(0).getGroupId().getValue().intValue()); - Assert.assertEquals("Wrong bucketWeight", 6, - message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue()); - Assert.assertEquals("Wrong bucketWatchPort", 5, - message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort(). - getValue().intValue()); - Assert.assertEquals("Wrong bucketWatchGroup", 4, - message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue()); - - - Assert.assertEquals("Wrong setMplsTtlType", SetMplsTtl.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). - getAction().getType()); - - Assert.assertEquals("Wrong setMplsTtlMPLS_TTL", 9, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). - getAction().getAugmentation(MplsTtlAction.class). - getMplsTtl().intValue()); - - Assert.assertEquals("Wrong decMplsTtlType", DecMplsTtl.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). - getAction().getType()); - - Assert.assertEquals("Wrong pushVlanType", PushVlan.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). - getAction().getType()); - - Assert.assertEquals("Wrong pushVlanEthertype", 32, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). - getAction().getAugmentation(EthertypeAction.class). - getEthertype().getValue().intValue()); - - Assert.assertEquals("Wrong pushMplsType", PushMpls.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(3). - getAction().getType()); - - Assert.assertEquals("Wrong pushMplsEthertype", 255, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(3). - getAction().getAugmentation(EthertypeAction.class). - getEthertype().getValue().intValue()); - - Assert.assertEquals("Wrong pushPbbType", PushPbb.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(4). - getAction().getType()); - - Assert.assertEquals("Wrong pushPbbEthertype", 4095, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(4). - getAction().getAugmentation(EthertypeAction.class). - getEthertype().getValue().intValue()); - - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - * Test covers bodies of actions Pop VLAN, Pop PBB, Pop MPLS, Group, Dec NW TTL - */ - @Test - public void testMultipartReplyGroupDescBody03(){ - ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+ - "00 48 "+//len - "01 "+//type - "00 "+//pad - "00 00 00 08 "+//groupId - "00 40 "+//bucketLen - "00 06 "+//bucketWeight - "00 00 00 05 "+//bucketWatchPort - "00 00 00 04 "+//bucketWatchGroup - "00 00 00 00 "+//bucketPad - "00 12 "+//popVlanType - "00 08 "+//popVlanLen - "00 00 00 00 "+//popVlanPad - "00 1B "+//popPbbType - "00 08 "+//popPbbLen - "00 00 00 00 "+//popPbbPad - "00 14 "+//popMplsType - "00 08 "+//popMplsLen - "00 CF "+//popMplsEthertype - "00 00 "+//popMplsPad - "00 15 "+//setQueueType - "00 08 "+//setQueueLen - "00 CF 00 00 "+//setQueueQueueId - "00 16 "+//groupType - "00 08 "+//groupLen - "00 CF 00 00 "+//groupGroupId - "00 18 "+//decNwTtlType - "00 08 "+//decNwTtlLen - "00 00 00 00"//decNwTtlPad - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyGroupDesc message = (MultipartReplyGroupDesc) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong type", 1, - message.getGroupDesc().get(0).getType().getIntValue()); - Assert.assertEquals("Wrong groupId", 8, - message.getGroupDesc().get(0).getGroupId().getValue().intValue()); - Assert.assertEquals("Wrong bucketWeight", 6, - message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue()); - Assert.assertEquals("Wrong bucketWatchPort", 5, - message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort(). - getValue().intValue()); - Assert.assertEquals("Wrong bucketWatchGroup", 4, - message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue()); - - Assert.assertEquals("Wrong popVlanType", PopVlan.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). - getAction().getType()); - - Assert.assertEquals("Wrong popPbbType", PopPbb.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). - getAction().getType()); - - Assert.assertEquals("Wrong popMplsType", PopMpls.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). - getAction().getType()); - - Assert.assertEquals("Wrong popMplsEthertype", 207, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). - getAction().getAugmentation(EthertypeAction.class). - getEthertype().getValue().intValue()); - - Assert.assertEquals("Wrong setQueueType", SetQueue.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(3). - getAction().getType()); - - Assert.assertEquals("Wrong setQueueQueueId", 13565952, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(3). - getAction().getAugmentation(QueueIdAction.class). - getQueueId().intValue()); - - Assert.assertEquals("Wrong groupType", Group.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(4). - getAction().getType()); - - Assert.assertEquals("Wrong groupGroupId", 13565952, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(4). - getAction().getAugmentation(GroupIdAction.class). - getGroupId().intValue()); - - Assert.assertEquals("Wrong decNwTtlType", DecNwTtl.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(5). - getAction().getType()); - } - - /** - * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO - * Test covers bodies of actions NW TTL, Experimenter - */ - @Test - public void testMultipartReplyGroupDescBody04(){ - ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+ - "00 30 "+//len - "01 "+//type - "00 "+//pad - "00 00 00 08 "+//groupId - "00 28 "+//bucketLen - "00 06 "+//bucketWeight - "00 00 00 05 "+//bucketWatchPort - "00 00 00 04 "+//bucketWatchGroup - "00 00 00 00 "+//bucketPad - "00 17 "+//nwTTlType - "00 08 "+//nwTTlLen - "0E "+//nwTTlnwTTL - "00 00 00 "+//nwTTlPad - "00 19 "+//setFieldType - "00 10 "+//setFieldLen - "80 00 "+//setFieldOXMClass - "00 "+//setFieldOXMField - "04 "+//setFieldOXMLength - "00 00 00 FF "+ //setFieldPort - "00 00 00 00" - ); - - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); - Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - - MultipartReplyGroupDesc message = (MultipartReplyGroupDesc) builtByFactory.getMultipartReplyBody(); - - Assert.assertEquals("Wrong type", 1, - message.getGroupDesc().get(0).getType().getIntValue()); - Assert.assertEquals("Wrong groupId", 8, - message.getGroupDesc().get(0).getGroupId().getValue().intValue()); - Assert.assertEquals("Wrong bucketWeight", 6, - message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue()); - Assert.assertEquals("Wrong bucketWatchPort", 5, - message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort(). - getValue().intValue()); - Assert.assertEquals("Wrong bucketWatchGroup", 4, - message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue()); - - Assert.assertEquals("Wrong nwTTlType", SetNwTtl.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). - getAction().getType()); - - Assert.assertEquals("Wrong nwTTlnwTTL", 14, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). - getAction().getAugmentation(NwTtlAction.class).getNwTtl().intValue()); - - Assert.assertEquals("Wrong setFieldType", SetField.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). - getAction().getType()); - - Assert.assertEquals("Wrong setFieldOXMClass", OpenflowBasicClass.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). - getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).getOxmClass()); - - Assert.assertEquals("Wrong setFieldOXMField", InPort.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). - getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).getOxmMatchField()); - - Assert.assertEquals("Wrong setFieldOXMValue", 255, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). - getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0). - getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.math.BigInteger; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDrop; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemark; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class MultipartReplyMessageFactoryTest { + + private static final Logger LOGGER = LoggerFactory + .getLogger(MultipartReplyMessageFactoryTest.class); + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + *//* + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 01 02 03 04"); + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + + Assert.assertEquals("Wrong type", 0x07, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + //Assert.assertArrayEquals("Wrong body", new byte[]{0x01, 0x02, 0x03, 0x04}, builtByFactory.getBody()); + }*/ + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyDescBody(){ + final int DESC_STR_LEN = 256; + final int SERIAL_NUM_LEN = 32; + ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 00 00 00"); + + String mfrDesc = "Manufacturer description"; + byte[] mfrDescBytes = new byte[256]; + mfrDescBytes = mfrDesc.getBytes(); + bb.writeBytes(mfrDescBytes); + ByteBufUtils.padBuffer((DESC_STR_LEN - mfrDescBytes.length), bb); + + String hwDesc = "Hardware description"; + byte[] hwDescBytes = new byte[256]; + hwDescBytes = hwDesc.getBytes(); + bb.writeBytes(hwDescBytes); + ByteBufUtils.padBuffer((DESC_STR_LEN - hwDescBytes.length), bb); + + String swDesc = "Software description"; + byte[] swDescBytes = new byte[256]; + swDescBytes = swDesc.getBytes(); + bb.writeBytes(swDescBytes); + ByteBufUtils.padBuffer((DESC_STR_LEN - swDescBytes.length), bb); + + String serialNum = "SN0123456789"; + byte[] serialNumBytes = new byte[32]; + serialNumBytes = serialNum.getBytes(); + bb.writeBytes(serialNumBytes); + ByteBufUtils.padBuffer((SERIAL_NUM_LEN - serialNumBytes.length), bb); + + String dpDesc = "switch3 in room 3120"; + byte[] dpDescBytes = new byte[256]; + dpDescBytes = dpDesc.getBytes(); + bb.writeBytes(dpDescBytes); + ByteBufUtils.padBuffer((DESC_STR_LEN - dpDescBytes.length), bb); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 0x00, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + MultipartReplyDesc message = (MultipartReplyDesc) builtByFactory.getMultipartReplyBody(); + Assert.assertEquals("Wrong mfrDesc", "Manufacturer description", message.getMfrDesc()); + Assert.assertEquals("Wrong hwDesc", "Hardware description", message.getHwDesc()); + Assert.assertEquals("Wrong swDesc", "Software description", message.getSwDesc()); + Assert.assertEquals("Wrong serialNum", "SN0123456789", message.getSerialNum()); + Assert.assertEquals("Wrong dpDesc", "switch3 in room 3120", message.getDpDesc()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyFlowBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00 "+ + "00 0C "+//length + "08 "+//tableId + "00 "+//pad_01 + "00 00 00 09 "+//durationSec + "00 00 00 07 "+//durationNsec + "00 0C "+//priority + "00 0E "+//idleTimeout + "00 0F "+//hardTimeout + "00 0B "+//flags + "00 00 00 00 "+//pad_02 + "00 01 01 01 01 01 01 01 "+//cookie + "00 01 01 01 01 01 01 01 "+//packetCount + "00 01 01 01 01 01 01 01"//byteCount + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + MultipartReplyFlow message = (MultipartReplyFlow) builtByFactory.getMultipartReplyBody(); + Assert.assertEquals("Wrong tableId", 8, message.getFlowStats().get(0).getTableId().intValue()); + Assert.assertEquals("Wrong durationSec", 9, message.getFlowStats().get(0).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec", 7, message.getFlowStats().get(0).getDurationNsec().intValue()); + Assert.assertEquals("Wrong priority", 12, message.getFlowStats().get(0).getPriority().intValue()); + Assert.assertEquals("Wrong idleTimeOut", 14, message.getFlowStats().get(0).getIdleTimeout().intValue()); + Assert.assertEquals("Wrong hardTimeOut", 15, message.getFlowStats().get(0).getHardTimeout().intValue()); + Assert.assertEquals("Wrong flags", new FlowModFlags(true, false, true, false, true), + message.getFlowStats().get(0).getFlags()); + Assert.assertEquals("Wrong cookie", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getFlowStats().get(0).getCookie()); + Assert.assertEquals("Wrong packetCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getFlowStats().get(0).getPacketCount()); + Assert.assertEquals("Wrong byteCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getFlowStats().get(0).getByteCount()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyAggregateBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 02 00 01 00 00 00 00 "+ + "00 01 01 01 01 01 01 01 "+//packetCount + "00 01 01 01 01 01 01 01 "+//byteCount + "00 00 00 08 "+//flowCount + "00 00 00 00"//pad + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 0x02, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + MultipartReplyAggregate message = (MultipartReplyAggregate) builtByFactory.getMultipartReplyBody(); + Assert.assertEquals("Wrong packetCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getPacketCount()); + Assert.assertEquals("Wrong byteCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getByteCount()); + Assert.assertEquals("Wrong flowCount", + 8, + message.getFlowCount().intValue()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyTableBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 03 00 01 00 00 00 00 "+ + "08 "+//tableId + "00 00 00 "+//pad + "00 00 00 10 "+//activeCount + "00 01 01 01 01 01 01 01 "+//lookupCount + "00 01 01 01 01 01 01 01"//matchedCount + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyTable message = (MultipartReplyTable) builtByFactory.getMultipartReplyBody(); + Assert.assertEquals("Wrong tableId", 8, message.getTableStats().get(0).getTableId().intValue()); + Assert.assertEquals("Wrong activeCount", 16, message.getTableStats().get(0).getActiveCount().longValue()); + Assert.assertEquals("Wrong lookupCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getTableStats().get(0).getLookupCount()); + Assert.assertEquals("Wrong matchedCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getTableStats().get(0).getMatchedCount()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyPortStatsBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 04 00 01 00 00 00 00 "+ + "00 00 00 FF "+//portNo + "00 00 00 00 "+//pad + "00 01 01 01 01 01 01 01 "+//rxPackets + "00 02 02 02 02 02 02 02 "+//txPackets + "00 02 03 02 03 02 03 02 "+//rxBytes + "00 02 03 02 03 02 03 02 "+//txBytes + "00 02 03 02 03 02 03 02 "+//rxDropped + "00 02 03 02 03 02 03 02 "+//txDropped + "00 02 03 02 03 02 03 02 "+//rxErrors + "00 02 03 02 03 02 03 02 "+//txErrors + "00 02 03 02 03 02 03 02 "+//rxFrameErr + "00 02 03 02 03 02 03 02 "+//rxOverErr + "00 02 03 02 03 02 03 02 "+//rxCrcErr + "00 02 03 02 03 02 03 02 "+//collisions + "00 00 00 02 "+//durationSec + "00 00 00 04"//durationNsec + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 0x04, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyPortStats message = (MultipartReplyPortStats) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong portNo", 255, message.getPortStats().get(0).getPortNo().intValue()); + Assert.assertEquals("Wrong rxPackets", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getPortStats().get(0).getRxPackets()); + Assert.assertEquals("Wrong txPackets", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getPortStats().get(0).getTxPackets()); + Assert.assertEquals("Wrong rxBytes", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getPortStats().get(0).getRxBytes()); + Assert.assertEquals("Wrong txBytes", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getPortStats().get(0).getTxBytes()); + Assert.assertEquals("Wrong rxDropped", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getPortStats().get(0).getRxDropped()); + Assert.assertEquals("Wrong txDropped", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getPortStats().get(0).getTxDropped()); + Assert.assertEquals("Wrong rxErrors", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getPortStats().get(0).getRxErrors()); + Assert.assertEquals("Wrong txErrors", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getPortStats().get(0).getTxErrors()); + Assert.assertEquals("Wrong rxFrameErr", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getPortStats().get(0).getRxFrameErr()); + Assert.assertEquals("Wrong rxOverErr", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getPortStats().get(0).getRxOverErr()); + Assert.assertEquals("Wrong rxCrcErr", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getPortStats().get(0).getRxCrcErr()); + Assert.assertEquals("Wrong collisions", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getPortStats().get(0).getCollisions()); + Assert.assertEquals("Wrong durationSec", 2, message.getPortStats().get(0).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec", 4, message.getPortStats().get(0).getDurationNsec().intValue()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyQueueBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 05 00 01 00 00 00 00 "+ + "00 00 00 FF "+//portNo + "00 00 00 10 "+//queueId + "00 02 03 02 03 02 03 02 "+//txBytes + "00 02 02 02 02 02 02 02 "+//txPackets + "00 02 03 02 03 02 03 02 "+//txErrors + "00 00 00 02 "+//durationSec + "00 00 00 04"//durationNsec + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 0x05, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyQueue message = (MultipartReplyQueue) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong portNo", 255, message.getQueueStats().get(0).getPortNo().intValue()); + Assert.assertEquals("Wrong queueId", 16, message.getQueueStats().get(0).getQueueId().intValue()); + Assert.assertEquals("Wrong txBytes", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getQueueStats().get(0).getTxBytes()); + Assert.assertEquals("Wrong txPackets", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getQueueStats().get(0).getTxPackets()); + Assert.assertEquals("Wrong txErrors", + new BigInteger(new byte[]{0x00, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02}), + message.getQueueStats().get(0).getTxErrors()); + Assert.assertEquals("Wrong durationSec", 2, message.getQueueStats().get(0).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec", 4, message.getQueueStats().get(0).getDurationNsec().intValue()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyGroupBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 06 00 01 00 00 00 00 "+ + "00 48 "+//length + "00 00 "+//pad1 + "00 00 00 10 "+//groupId + "00 00 00 12 "+//refCount + "00 00 00 00 "+//pad2 + "00 01 01 01 01 01 01 01 "+//packetCount + "00 01 01 01 01 01 01 01 "+//byteCount + "00 00 00 08 "+//durationSec + "00 00 00 09 "+//durationNsec + "00 01 01 01 01 01 01 01 "+//packetCountBucket + "00 01 01 01 01 01 01 01 "+//byteCountBucket + "00 02 02 02 02 02 02 02 "+//packetCountBucket_2 + "00 02 02 02 02 02 02 02 "+//byteCountBucket_2 + "00 48 "+//length_2 + "00 00 "+//pad1.2 + "00 00 00 10 "+//groupId_2 + "00 00 00 12 "+//refCount_2 + "00 00 00 00 "+//pad2.2 + "00 01 01 01 01 01 01 01 "+//packetCount_2 + "00 01 01 01 01 01 01 01 "+//byteCount_2 + "00 00 00 08 "+//durationSec_2 + "00 00 00 09 "+//durationNsec_2 + "00 01 01 01 01 01 01 01 "+//packetCountBucket_1.2 + "00 01 01 01 01 01 01 01 "+//byteCountBucket_1.2 + "00 02 02 02 02 02 02 02 "+//packetCountBucket_2.2 + "00 02 02 02 02 02 02 02"//byteCountBucket_2.2 + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 0x06, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyGroup message = (MultipartReplyGroup) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong groupId", 16, message.getGroupStats().get(0).getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong refCount", 18, message.getGroupStats().get(0).getRefCount().intValue()); + Assert.assertEquals("Wrong packetCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getGroupStats().get(0).getPacketCount()); + Assert.assertEquals("Wrong byteCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getGroupStats().get(0).getByteCount()); + Assert.assertEquals("Wrong durationSec", 8, message.getGroupStats().get(0).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec", 9, message.getGroupStats().get(0).getDurationNsec().intValue()); + Assert.assertEquals("Wrong packetCountBucket", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getGroupStats().get(0).getBucketStats().get(0).getPacketCount()); + Assert.assertEquals("Wrong byteCountBucket", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getGroupStats().get(0).getBucketStats().get(0).getByteCount()); + Assert.assertEquals("Wrong packetCountBucket_2", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getGroupStats().get(0).getBucketStats().get(1).getPacketCount()); + Assert.assertEquals("Wrong byteCountBucket_2", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getGroupStats().get(0).getBucketStats().get(1).getByteCount()); + + Assert.assertEquals("Wrong groupId_2", 16, message.getGroupStats().get(1).getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong refCount_2", 18, message.getGroupStats().get(1).getRefCount().intValue()); + Assert.assertEquals("Wrong packetCount_2", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getGroupStats().get(1).getPacketCount()); + Assert.assertEquals("Wrong byteCount_2", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getGroupStats().get(1).getByteCount()); + Assert.assertEquals("Wrong durationSec_2", 8, message.getGroupStats().get(1).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec_2", 9, message.getGroupStats().get(1).getDurationNsec().intValue()); + Assert.assertEquals("Wrong packetCountBucket_1.2", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getGroupStats().get(1).getBucketStats().get(0).getPacketCount()); + Assert.assertEquals("Wrong byteCountBucket_1.2", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getGroupStats().get(1).getBucketStats().get(0).getByteCount()); + Assert.assertEquals("Wrong packetCountBucket_2.2", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getGroupStats().get(1).getBucketStats().get(1).getPacketCount()); + Assert.assertEquals("Wrong byteCountBucket_2.2", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getGroupStats().get(1).getBucketStats().get(1).getByteCount()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyMeterFeaturesBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 0B 00 01 00 00 00 00 "+ + "00 00 00 09 "+//maxMeter + "00 00 00 01 "+//bandTypes + "00 00 00 03 "+//capabilities + "03 "+//maxBands + "04 "+//maxColor + "00 00"//pad + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 11, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyMeterFeatures message = (MultipartReplyMeterFeatures) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong maxMeter", 9, message.getMaxMeter().intValue()); + Assert.assertEquals("Wrong bandTypes", new MeterBandTypeBitmap(true, false), message.getBandTypes()); + Assert.assertEquals("Wrong capabilities", new MeterFlags(false, true, true, false), + message.getCapabilities()); + Assert.assertEquals("Wrong maxBands", 3, message.getMaxBands().intValue()); + Assert.assertEquals("Wrong maxColor", 4, message.getMaxColor().intValue()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyMeterBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+ + "00 00 00 09 "+//meterId + "00 58 "+//len + "00 00 00 00 00 00 "+//pad + "00 00 00 07 "+//flowCount + "00 01 01 01 01 01 01 01 "+//packetInCount + "00 01 01 01 01 01 01 01 "+//byteInCount + "00 00 00 05 "+//durationSec + "00 00 00 05 "+//durationNsec + "00 01 01 01 01 01 01 01 "+//packetBandCount_01 + "00 01 01 01 01 01 01 01 "+//byteBandCount_01 + "00 02 02 02 02 02 02 02 "+//packetBandCount_02 + "00 02 02 02 02 02 02 02 "+//byteBandCount_02 + "00 03 03 03 03 03 03 03 "+//packetBandCount_03 + "00 03 03 03 03 03 03 03"//byteBandCount_03 + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyMeter message = (MultipartReplyMeter) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong meterId", 9, + message.getMeterStats().get(0).getMeterId().getValue().intValue()); + Assert.assertEquals("Wrong flowCount", 7, + message.getMeterStats().get(0).getFlowCount().intValue()); + Assert.assertEquals("Wrong packetInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getPacketInCount()); + Assert.assertEquals("Wrong byteInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getByteInCount()); + Assert.assertEquals("Wrong durationSec", 5, + message.getMeterStats().get(0).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec", 5, + message.getMeterStats().get(0).getDurationNsec().intValue()); + Assert.assertEquals("Wrong packetBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyMeterBodyMulti(){ + ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+ + "00 00 00 09 "+//meterId_0 + "00 58 "+//len_0 + "00 00 00 00 00 00 "+//pad_0 + "00 00 00 07 "+//flowCount_0 + "00 01 01 01 01 01 01 01 "+//packetInCount_0 + "00 01 01 01 01 01 01 01 "+//byteInCount_0 + "00 00 00 05 "+//durationSec_0 + "00 00 00 05 "+//durationNsec_0 + "00 01 01 01 01 01 01 01 "+//packetBandCount_01 + "00 01 01 01 01 01 01 01 "+//byteBandCount_01 + "00 02 02 02 02 02 02 02 "+//packetBandCount_02 + "00 02 02 02 02 02 02 02 "+//byteBandCount_02 + "00 03 03 03 03 03 03 03 "+//packetBandCount_03 + "00 03 03 03 03 03 03 03 "+//byteBandCount_03 + "00 00 00 08 "+//meterId_1 + "00 58 "+//len_1 + "00 00 00 00 00 00 "+//pad_1 + "00 00 00 07 "+//flowCount_1 + "00 01 01 01 01 01 01 01 "+//packetInCount_1 + "00 01 01 01 01 01 01 01 "+//byteInCount_1 + "00 00 00 05 "+//durationSec_1 + "00 00 00 05 "+//durationNsec_1 + "00 01 01 01 01 01 01 01 "+//packetBandCount_11 + "00 01 01 01 01 01 01 01 "+//byteBandCount_11 + "00 02 02 02 02 02 02 02 "+//packetBandCount_12 + "00 02 02 02 02 02 02 02 "+//byteBandCount_12 + "00 03 03 03 03 03 03 03 "+//packetBandCount_13 + "00 03 03 03 03 03 03 03"//byteBandCount_13 + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyMeter message = (MultipartReplyMeter) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong meterId", 9, + message.getMeterStats().get(0).getMeterId().getValue().intValue()); + Assert.assertEquals("Wrong flowCount", 7, + message.getMeterStats().get(0).getFlowCount().intValue()); + Assert.assertEquals("Wrong packetInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getPacketInCount()); + Assert.assertEquals("Wrong byteInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getByteInCount()); + Assert.assertEquals("Wrong durationSec", 5, + message.getMeterStats().get(0).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec", 5, + message.getMeterStats().get(0).getDurationNsec().intValue()); + Assert.assertEquals("Wrong packetBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount()); + + Assert.assertEquals("Wrong meterId", 8, + message.getMeterStats().get(1).getMeterId().getValue().intValue()); + Assert.assertEquals("Wrong flowCount", 7, + message.getMeterStats().get(1).getFlowCount().intValue()); + Assert.assertEquals("Wrong packetInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(1).getPacketInCount()); + Assert.assertEquals("Wrong byteInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(1).getByteInCount()); + Assert.assertEquals("Wrong durationSec", 5, + message.getMeterStats().get(1).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec", 5, + message.getMeterStats().get(1).getDurationNsec().intValue()); + Assert.assertEquals("Wrong packetBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(1).getMeterBandStats().get(0).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(1).getMeterBandStats().get(0).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(1).getMeterBandStats().get(1).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(1).getMeterBandStats().get(1).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(1).getMeterBandStats().get(2).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(1).getMeterBandStats().get(2).getByteBandCount()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyMeterConfigBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 01 00 00 00 00 "+ + "00 38 "+//len + "00 0A "+//flags + "00 00 00 09 "+//meterId + "00 01 "+//meterBandDrop.type + "00 10 "+//meterBandDrop.len + "00 00 00 11 "+//meterBandDrop.rate + "00 00 00 20 "+//meterBandDrop.burstSize + "00 00 00 00 "+//meterBandDrop.pad + "00 02 "+//meterBandDscp.type + "00 10 "+//meterBandDscp.len + "00 00 00 11 "+//meterBandDscp.rate + "00 00 00 20 "+//meterBandDscp.burstSize + "04 "+//meterBandDscp.precLevel + "00 00 00 "+//meterBandDscp.pad + "FF FF "+//meterBandExperimenter.type + "00 10 "+//meterBandExperimenter.len + "00 00 00 11 "+//meterBandExperimenter.rate + "00 00 00 20 "+//meterBandExperimenter.burstSize + "00 00 00 04"//meterBandExperimenter.experimenter + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyMeterConfig message = (MultipartReplyMeterConfig) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong flags", new MeterFlags(false, false, true, true), + message.getMeterConfig().get(0).getFlags()); + Assert.assertEquals("Wrong meterId", 9, + message.getMeterConfig().get(0).getMeterId().getValue().intValue()); + + MeterBandDrop meterBandDrop = (MeterBandDrop) message.getMeterConfig().get(0).getBands().get(0).getMeterBand(); + Assert.assertEquals("Wrong meterBandDrop.type", 1, meterBandDrop.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandDrop.rate", 17, meterBandDrop.getRate().intValue()); + Assert.assertEquals("Wrong meterBandDrop.burstSize", 32, meterBandDrop.getBurstSize().intValue()); + + MeterBandDscpRemark meterBandDscp = (MeterBandDscpRemark) message.getMeterConfig().get(0).getBands().get(1).getMeterBand(); + Assert.assertEquals("Wrong meterBandDscp.type", 2, meterBandDscp.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandDscp.rate", 17, meterBandDscp.getRate().intValue()); + Assert.assertEquals("Wrong meterBandDscp.burstSize", 32, meterBandDscp.getBurstSize().intValue()); + Assert.assertEquals("Wrong meterBandDscp.precLevel", 4, meterBandDscp.getPrecLevel().intValue()); + + MeterBandExperimenter meterBandExperimenter = (MeterBandExperimenter) message.getMeterConfig().get(0).getBands().get(2).getMeterBand(); + Assert.assertEquals("Wrong meterBandExperimenter.type", 0xFFFF, meterBandExperimenter.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandExperimenter.rate", 17, meterBandExperimenter.getRate().intValue()); + Assert.assertEquals("Wrong meterBandExperimenter.burstSize", 32, meterBandExperimenter.getBurstSize().intValue()); + Assert.assertEquals("Wrong meterBandExperimenter.experimenter", 4, meterBandExperimenter.getExperimenter().intValue()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyMeterConfigBodyMulti(){ + ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 01 00 00 00 00 "+ + "00 38 "+//len + "00 06 "+//flags + "00 00 00 09 "+//meterId + "00 01 "+//meterBandDrop.type + "00 10 "+//meterBandDrop.len + "00 00 00 11 "+//meterBandDrop.rate + "00 00 00 20 "+//meterBandDrop.burstSize + "00 00 00 00 "+//meterBandDrop.pad + "00 02 "+//meterBandDscp.type + "00 10 "+//meterBandDscp.len + "00 00 00 11 "+//meterBandDscp.rate + "00 00 00 20 "+//meterBandDscp.burstSize + "04 "+//meterBandDscp.precLevel + "00 00 00 "+//meterBandDscp.pad + "FF FF "+//meterBandExperimenter.type + "00 10 "+//meterBandExperimenter.len + "00 00 00 11 "+//meterBandExperimenter.rate + "00 00 00 20 "+//meterBandExperimenter.burstSize + "00 00 00 04 "+//meterBandExperimenter.experimenter + + "00 18 "+//len01 + "00 03 "+//flags01 + "00 00 00 07 "+//meterId01 + "00 02 "+//meterBandDscp01.type + "00 10 "+//meterBandDscp01.len + "00 00 00 11 "+//meterBandDscp01.rate + "00 00 00 20 "+//meterBandDscp01.burstSize + "04 "+//meterBandDscp01.precLevel + "00 00 00"//meterBandDscp01.pad + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyMeterConfig message = (MultipartReplyMeterConfig) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong flags", new MeterFlags(true, false, true, false), + message.getMeterConfig().get(0).getFlags()); + Assert.assertEquals("Wrong meterId", 9, + message.getMeterConfig().get(0).getMeterId().getValue().intValue()); + + MeterBandDrop meterBandDrop = (MeterBandDrop) message.getMeterConfig().get(0).getBands().get(0).getMeterBand(); + Assert.assertEquals("Wrong meterBandDrop.type", 1, meterBandDrop.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandDrop.rate", 17, meterBandDrop.getRate().intValue()); + Assert.assertEquals("Wrong meterBandDrop.burstSize", 32, meterBandDrop.getBurstSize().intValue()); + + MeterBandDscpRemark meterBandDscp = (MeterBandDscpRemark) message.getMeterConfig().get(0).getBands().get(1).getMeterBand(); + Assert.assertEquals("Wrong meterBandDscp.type", 2, meterBandDscp.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandDscp.rate", 17, meterBandDscp.getRate().intValue()); + Assert.assertEquals("Wrong meterBandDscp.burstSize", 32, meterBandDscp.getBurstSize().intValue()); + Assert.assertEquals("Wrong meterBandDscp.precLevel", 4, meterBandDscp.getPrecLevel().intValue()); + + MeterBandExperimenter meterBandExperimenter = (MeterBandExperimenter) message.getMeterConfig().get(0).getBands().get(2).getMeterBand(); + Assert.assertEquals("Wrong meterBandExperimenter.type", 0xFFFF, meterBandExperimenter.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandExperimenter.rate", 17, meterBandExperimenter.getRate().intValue()); + Assert.assertEquals("Wrong meterBandExperimenter.burstSize", 32, meterBandExperimenter.getBurstSize().intValue()); + Assert.assertEquals("Wrong meterBandExperimenter.experimenter", 4, meterBandExperimenter.getExperimenter().intValue()); + + LOGGER.info(message.getMeterConfig().get(0).getFlags().toString()); + Assert.assertEquals("Wrong flags01", new MeterFlags(false, true, true, false), + message.getMeterConfig().get(1).getFlags()); + Assert.assertEquals("Wrong meterId01", 7, + message.getMeterConfig().get(1).getMeterId().getValue().intValue()); + + MeterBandDscpRemark meterBandDscp01 = (MeterBandDscpRemark) message.getMeterConfig().get(1).getBands().get(0).getMeterBand(); + Assert.assertEquals("Wrong meterBandDscp01.type", 2, meterBandDscp01.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandDscp01.rate", 17, meterBandDscp01.getRate().intValue()); + Assert.assertEquals("Wrong meterBandDscp01.burstSize", 32, meterBandDscp01.getBurstSize().intValue()); + Assert.assertEquals("Wrong meterBandDscp01.precLevel", 4, meterBandDscp01.getPrecLevel().intValue()); + + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyExperimenterBody(){ + ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 "+ + "00 00 00 0F "+//experimenterId + "00 00 00 FF "+//expType + "00 00 01 01 00 00 01 01" + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 0xFFFF, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyExperimenter message = (MultipartReplyExperimenter) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong experimenterId", 15, message.getExperimenter().intValue()); + Assert.assertEquals("Wrong expType", 255, message.getExpType().intValue()); + Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01}, + message.getData()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyPortDescBody(){ + final byte MAX_PORT_NAME_LEN = 16; + ByteBuf bb = BufferHelper.buildBuffer("00 0D 00 01 00 00 00 00 "+ + "00 01 02 03 "+ //portNo + "00 00 00 00 "+ //padding01 + "08 00 27 00 B0 EB " + //mac address + "00 00 "); //padding02 + //port name + String portName = "SampleText"; + byte[] portNameBytes = new byte[MAX_PORT_NAME_LEN]; + portNameBytes = portName.getBytes(); + bb.writeBytes(portNameBytes); + ByteBufUtils.padBuffer((MAX_PORT_NAME_LEN - portNameBytes.length), bb); + + ByteBuf bb2 = BufferHelper.buildBuffer("00 00 00 41 " + //port config + "00 00 00 05 " + //port state + "00 00 00 81 " + //current features + "00 00 00 81 " + //advertised features + "00 00 00 81 " + //supported features + "00 00 00 81 " + //peer features + "00 00 00 81 " + //curr speed + "00 00 00 80" //max speed + ); + bb.writeBytes(bb2.copy(4, bb2.readableBytes()-4));//excluding version and xid + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 13, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyPortDesc message = (MultipartReplyPortDesc) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong portNo", 66051L, message.getPorts().get(0).getPortNo().longValue()); + Assert.assertEquals("Wrong macAddress", new MacAddress("08:00:27:00:B0:EB"), + message.getPorts().get(0).getHwAddr()); + Assert.assertEquals("Wrong portName", "SampleText", + message.getPorts().get(0).getName()); + Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), + message.getPorts().get(0).getConfig()); + Assert.assertEquals("Wrong portState", new PortState(false, true, true), + message.getPorts().get(0).getState()); + Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false, + false, false, false, true, + false, false, false, false, + false, false, false, false), + message.getPorts().get(0).getCurrentFeatures()); + Assert.assertEquals("Wrong advertisedFeatures", + new PortFeatures(true, false, false, false, + false, false, false, true, + false, false, false, false, + false, false, false, false), + message.getPorts().get(0).getAdvertisedFeatures()); + Assert.assertEquals("Wrong supportedFeatures", + new PortFeatures(true, false, false, false, + false, false, false, true, + false, false, false, false, + false, false, false, false), + message.getPorts().get(0).getSupportedFeatures()); + Assert.assertEquals("Wrong peerFeatures", + new PortFeatures(true, false, false, false, + false, false, false, true, + false, false, false, false, + false, false, false, false), + message.getPorts().get(0).getPeerFeatures()); + Assert.assertEquals("Wrong currSpeed", 129L, message.getPorts().get(0).getCurrSpeed().longValue()); + Assert.assertEquals("Wrong maxSpeed", 128L, message.getPorts().get(0).getMaxSpeed().longValue()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + * Test covers bodies of actions Output, Copy TTL Out, Copy TTL In + */ + @Test + public void testMultipartReplyGroupDescBody01(){ + ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+ + "00 38 "+//len + "01 "+//type + "00 "+//pad + "00 00 00 08 "+//groupId + "00 30 "+//bucketLen + "00 06 "+//bucketWeight + "00 00 00 05 "+//bucketWatchPort + "00 00 00 04 "+//bucketWatchGroup + "00 00 00 00 "+//bucketPad + "00 00 "+//outputType + "00 10 "+//outputLen + "00 00 10 FF "+//outputPort + "FF FF "+//outputMaxLen + "00 00 00 00 00 00 "+//outputPad + "00 0B "+//copyTTLOutType + "00 08 "+//copyTTLOutLen + "00 00 00 00 "+//copyTTLOutPad + "00 0C "+//copyTTLIntType + "00 08 "+//copyTTLIntLen + "00 00 00 00"//copyTTLInPad + ); + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyGroupDesc message = (MultipartReplyGroupDesc) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong type", 1, + message.getGroupDesc().get(0).getType().getIntValue()); + Assert.assertEquals("Wrong groupId", 8, + message.getGroupDesc().get(0).getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong bucketWeight", 6, + message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue()); + Assert.assertEquals("Wrong bucketWatchPort", 5, + message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort(). + getValue().intValue()); + Assert.assertEquals("Wrong bucketWatchGroup", 4, + message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue()); + + Assert.assertEquals("Wrong outputType", Output.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). + getAction().getType()); + + Assert.assertEquals("Wrong outputPort", 4351, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). + getAction().getAugmentation(PortAction.class). + getPort().getValue().intValue()); + + Assert.assertEquals("Wrong outputMaxLen", 65535, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). + getAction().getAugmentation(MaxLengthAction.class). + getMaxLength().intValue()); + + Assert.assertEquals("Wrong copyTtlOutType", CopyTtlOut.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). + getAction().getType()); + + Assert.assertEquals("Wrong copyTtlInType", CopyTtlIn.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). + getAction().getType()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + * Test covers bodies of actions Set MPLS TTL , Dec MPLS TTL, Push VLAN. Push MPLS, Push PBB + */ + @Test + public void testMultipartReplyGroupDescBody02(){ + ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+ + "00 40 "+//len + "01 "+//type + "00 "+//pad + "00 00 00 08 "+//groupId + "00 38 "+//bucketLen + "00 06 "+//bucketWeight + "00 00 00 05 "+//bucketWatchPort + "00 00 00 04 "+//bucketWatchGroup + "00 00 00 00 "+//bucketPad + "00 0F "+//setMplsTtlType + "00 08 "+//setMplsTtlLen + "09 "+//setMplsTtlMPLS_TTL + "00 00 00 "+//setMplsTtlPad + "00 10 "+//decMplsTtlType + "00 08 "+//decMplsTtlLen + "00 00 00 00 "+//decMplsTtlPad + "00 11 "+//pushVlanType + "00 08 "+//pushVlanLen + "00 20 "+//pushVlanEthertype + "00 00 "+//pushVlanPad + "00 13 "+//pushMplsType + "00 08 "+//pushMplsLen + "00 FF "+//pushMplsEthertype + "00 00 "+//pushMplsPad + "00 1A "+//pushPbbType + "00 08 "+//pushPbbLen + "0F FF "+//pushPbbEthertype + "00 00"//pushPbbPad + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyGroupDesc message = (MultipartReplyGroupDesc) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong type", 1, + message.getGroupDesc().get(0).getType().getIntValue()); + Assert.assertEquals("Wrong groupId", 8, + message.getGroupDesc().get(0).getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong bucketWeight", 6, + message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue()); + Assert.assertEquals("Wrong bucketWatchPort", 5, + message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort(). + getValue().intValue()); + Assert.assertEquals("Wrong bucketWatchGroup", 4, + message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue()); + + + Assert.assertEquals("Wrong setMplsTtlType", SetMplsTtl.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). + getAction().getType()); + + Assert.assertEquals("Wrong setMplsTtlMPLS_TTL", 9, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). + getAction().getAugmentation(MplsTtlAction.class). + getMplsTtl().intValue()); + + Assert.assertEquals("Wrong decMplsTtlType", DecMplsTtl.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). + getAction().getType()); + + Assert.assertEquals("Wrong pushVlanType", PushVlan.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). + getAction().getType()); + + Assert.assertEquals("Wrong pushVlanEthertype", 32, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). + getAction().getAugmentation(EthertypeAction.class). + getEthertype().getValue().intValue()); + + Assert.assertEquals("Wrong pushMplsType", PushMpls.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(3). + getAction().getType()); + + Assert.assertEquals("Wrong pushMplsEthertype", 255, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(3). + getAction().getAugmentation(EthertypeAction.class). + getEthertype().getValue().intValue()); + + Assert.assertEquals("Wrong pushPbbType", PushPbb.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(4). + getAction().getType()); + + Assert.assertEquals("Wrong pushPbbEthertype", 4095, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(4). + getAction().getAugmentation(EthertypeAction.class). + getEthertype().getValue().intValue()); + + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + * Test covers bodies of actions Pop VLAN, Pop PBB, Pop MPLS, Group, Dec NW TTL + */ + @Test + public void testMultipartReplyGroupDescBody03(){ + ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+ + "00 48 "+//len + "01 "+//type + "00 "+//pad + "00 00 00 08 "+//groupId + "00 40 "+//bucketLen + "00 06 "+//bucketWeight + "00 00 00 05 "+//bucketWatchPort + "00 00 00 04 "+//bucketWatchGroup + "00 00 00 00 "+//bucketPad + "00 12 "+//popVlanType + "00 08 "+//popVlanLen + "00 00 00 00 "+//popVlanPad + "00 1B "+//popPbbType + "00 08 "+//popPbbLen + "00 00 00 00 "+//popPbbPad + "00 14 "+//popMplsType + "00 08 "+//popMplsLen + "00 CF "+//popMplsEthertype + "00 00 "+//popMplsPad + "00 15 "+//setQueueType + "00 08 "+//setQueueLen + "00 CF 00 00 "+//setQueueQueueId + "00 16 "+//groupType + "00 08 "+//groupLen + "00 CF 00 00 "+//groupGroupId + "00 18 "+//decNwTtlType + "00 08 "+//decNwTtlLen + "00 00 00 00"//decNwTtlPad + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyGroupDesc message = (MultipartReplyGroupDesc) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong type", 1, + message.getGroupDesc().get(0).getType().getIntValue()); + Assert.assertEquals("Wrong groupId", 8, + message.getGroupDesc().get(0).getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong bucketWeight", 6, + message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue()); + Assert.assertEquals("Wrong bucketWatchPort", 5, + message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort(). + getValue().intValue()); + Assert.assertEquals("Wrong bucketWatchGroup", 4, + message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue()); + + Assert.assertEquals("Wrong popVlanType", PopVlan.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). + getAction().getType()); + + Assert.assertEquals("Wrong popPbbType", PopPbb.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). + getAction().getType()); + + Assert.assertEquals("Wrong popMplsType", PopMpls.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). + getAction().getType()); + + Assert.assertEquals("Wrong popMplsEthertype", 207, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). + getAction().getAugmentation(EthertypeAction.class). + getEthertype().getValue().intValue()); + + Assert.assertEquals("Wrong setQueueType", SetQueue.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(3). + getAction().getType()); + + Assert.assertEquals("Wrong setQueueQueueId", 13565952, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(3). + getAction().getAugmentation(QueueIdAction.class). + getQueueId().intValue()); + + Assert.assertEquals("Wrong groupType", Group.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(4). + getAction().getType()); + + Assert.assertEquals("Wrong groupGroupId", 13565952, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(4). + getAction().getAugmentation(GroupIdAction.class). + getGroupId().intValue()); + + Assert.assertEquals("Wrong decNwTtlType", DecNwTtl.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(5). + getAction().getType()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + * Test covers bodies of actions NW TTL, Experimenter + */ + @Test + public void testMultipartReplyGroupDescBody04(){ + ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+ + "00 30 "+//len + "01 "+//type + "00 "+//pad + "00 00 00 08 "+//groupId + "00 28 "+//bucketLen + "00 06 "+//bucketWeight + "00 00 00 05 "+//bucketWatchPort + "00 00 00 04 "+//bucketWatchGroup + "00 00 00 00 "+//bucketPad + "00 17 "+//nwTTlType + "00 08 "+//nwTTlLen + "0E "+//nwTTlnwTTL + "00 00 00 "+//nwTTlPad + "00 19 "+//setFieldType + "00 10 "+//setFieldLen + "80 00 "+//setFieldOXMClass + "00 "+//setFieldOXMField + "04 "+//setFieldOXMLength + "00 00 00 FF "+ //setFieldPort + "00 00 00 00" + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyGroupDesc message = (MultipartReplyGroupDesc) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong type", 1, + message.getGroupDesc().get(0).getType().getIntValue()); + Assert.assertEquals("Wrong groupId", 8, + message.getGroupDesc().get(0).getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong bucketWeight", 6, + message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue()); + Assert.assertEquals("Wrong bucketWatchPort", 5, + message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort(). + getValue().intValue()); + Assert.assertEquals("Wrong bucketWatchGroup", 4, + message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue()); + + Assert.assertEquals("Wrong nwTTlType", SetNwTtl.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). + getAction().getType()); + + Assert.assertEquals("Wrong nwTTlnwTTL", 14, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). + getAction().getAugmentation(NwTtlAction.class).getNwTtl().intValue()); + + Assert.assertEquals("Wrong setFieldType", SetField.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). + getAction().getType()); + + Assert.assertEquals("Wrong setFieldOXMClass", OpenflowBasicClass.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). + getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).getOxmClass()); + + Assert.assertEquals("Wrong setFieldOXMField", InPort.class, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). + getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).getOxmMatchField()); + + Assert.assertEquals("Wrong setFieldOXMValue", 255, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). + getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0). + getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactoryTest.java index 31c73743..43e6d37d 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10ErrorMessageFactoryTest.java @@ -1,84 +1,91 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; - -/** - * @author michal.polkorab - */ -public class OF10ErrorMessageFactoryTest { - - /** - * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO - */ - @Test - public void testWithoutData() { - ByteBuf bb = BufferHelper.buildBuffer("00 01 00 02"); - ErrorMessage builtByFactory = BufferHelper.decodeV10( - OF10ErrorMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong type", 1, builtByFactory.getType().intValue()); - Assert.assertEquals("Wrong code", 2, builtByFactory.getCode().intValue()); - Assert.assertEquals("Wrong type string", "BADREQUEST", builtByFactory.getTypeString()); - Assert.assertEquals("Wrong code string", "BADSTAT", builtByFactory.getCodeString()); - Assert.assertNull("Data is not null", builtByFactory.getData()); - } - - /** - * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO - */ - @Test - public void testWithData() { - ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 01 02 03"); - ErrorMessage builtByFactory = BufferHelper.decodeV10( - OF10ErrorMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong type", 0, builtByFactory.getType().intValue()); - Assert.assertEquals("Wrong code", 1, builtByFactory.getCode().intValue()); - Assert.assertEquals("Wrong type string", "HELLOFAILED", builtByFactory.getTypeString()); - Assert.assertEquals("Wrong code string", "EPERM", builtByFactory.getCodeString()); - Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData()); - } - - /** - * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO - */ - @Test - public void testWithIncorrectTypeEnum() { - ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 05 00 01 02 03"); - ErrorMessage builtByFactory = BufferHelper.decodeV10( - OF10ErrorMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong type", 10, builtByFactory.getType().intValue()); - Assert.assertEquals("Wrong code", 5, builtByFactory.getCode().intValue()); - Assert.assertEquals("Wrong type string", "UNKNOWN_TYPE", builtByFactory.getTypeString()); - Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString()); - Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData()); - } - - /** - * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO - */ - @Test - public void testWithIncorrectCodeEnum() { - ByteBuf bb = BufferHelper.buildBuffer("00 03 00 06 00 01 02 03"); - ErrorMessage builtByFactory = BufferHelper.decodeV10( - OF10ErrorMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong type", 3, builtByFactory.getType().intValue()); - Assert.assertEquals("Wrong code", 6, builtByFactory.getCode().intValue()); - Assert.assertEquals("Wrong type string", "FLOWMODFAILED", builtByFactory.getTypeString()); - Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString()); - Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; + +/** + * @author michal.polkorab + */ +public class OF10ErrorMessageFactoryTest { + + /** + * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO + */ + @Test + public void testWithoutData() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 00 02"); + ErrorMessage builtByFactory = BufferHelper.decodeV10( + OF10ErrorMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong type", 1, builtByFactory.getType().intValue()); + Assert.assertEquals("Wrong code", 2, builtByFactory.getCode().intValue()); + Assert.assertEquals("Wrong type string", "BADREQUEST", builtByFactory.getTypeString()); + Assert.assertEquals("Wrong code string", "BADSTAT", builtByFactory.getCodeString()); + Assert.assertNull("Data is not null", builtByFactory.getData()); + } + + /** + * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO + */ + @Test + public void testWithData() { + ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 01 02 03"); + ErrorMessage builtByFactory = BufferHelper.decodeV10( + OF10ErrorMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong type", 0, builtByFactory.getType().intValue()); + Assert.assertEquals("Wrong code", 1, builtByFactory.getCode().intValue()); + Assert.assertEquals("Wrong type string", "HELLOFAILED", builtByFactory.getTypeString()); + Assert.assertEquals("Wrong code string", "EPERM", builtByFactory.getCodeString()); + Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData()); + } + + /** + * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO + */ + @Test + public void testWithIncorrectTypeEnum() { + ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 05 00 01 02 03"); + ErrorMessage builtByFactory = BufferHelper.decodeV10( + OF10ErrorMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong type", 10, builtByFactory.getType().intValue()); + Assert.assertEquals("Wrong code", 5, builtByFactory.getCode().intValue()); + Assert.assertEquals("Wrong type string", "UNKNOWN_TYPE", builtByFactory.getTypeString()); + Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString()); + Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData()); + } + + /** + * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO + */ + @Test + public void testWithIncorrectCodeEnum() { + ByteBuf bb = BufferHelper.buildBuffer("00 03 00 06 00 01 02 03"); + ErrorMessage builtByFactory = BufferHelper.decodeV10( + OF10ErrorMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong type", 3, builtByFactory.getType().intValue()); + Assert.assertEquals("Wrong code", 6, builtByFactory.getCode().intValue()); + Assert.assertEquals("Wrong type string", "FLOWMODFAILED", builtByFactory.getTypeString()); + Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString()); + Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactoryTest.java index 57f24eb8..bb955efd 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactoryTest.java @@ -1,94 +1,101 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort; - -/** - * @author michal.polkorab - * - */ -public class OF10FeaturesReplyMessageFactoryTest { - - /** - * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 " - + "00 00 00 8B 00 00 03 B5 " - + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 " - + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88"); - GetFeaturesOutput builtByFactory = BufferHelper.decodeV10( - OF10FeaturesReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue()); - Assert.assertEquals("Wrong n-buffers", 0x00010203L, builtByFactory.getBuffers().longValue()); - Assert.assertEquals("Wrong n-tables", 0x01, builtByFactory.getTables().shortValue()); - Assert.assertEquals("Wrong capabilities", new CapabilitiesV10(true, true, false, false, false, false, true, true), - builtByFactory.getCapabilitiesV10()); - Assert.assertEquals("Wrong actions", new ActionTypeV10(false, true, true, true, true, false, true, - false, true, true, false, false, false), builtByFactory.getActionsV10()); - PhyPort port = builtByFactory.getPhyPort().get(0); - Assert.assertEquals("Wrong port - port-no", 16, port.getPortNo().intValue()); - Assert.assertEquals("Wrong port - hw-addr", new MacAddress("01:01:05:01:04:02"), port.getHwAddr()); - Assert.assertEquals("Wrong port - name", new String("ALOHA"), port.getName()); - Assert.assertEquals("Wrong port - config", new PortConfigV10(true, false, false, true, false, false, true), - port.getConfigV10()); - Assert.assertEquals("Wrong port - state", new PortStateV10(false, true, false, false, false, true, false, false), - port.getStateV10()); - Assert.assertEquals("Wrong port - curr", new PortFeaturesV10(false, false, false, false, true, true, true, - false, false, false, false, false), port.getCurrentFeaturesV10()); - Assert.assertEquals("Wrong port - advertised", new PortFeaturesV10(false, false, true, true, false, false, - false, false, false, false, true, false), port.getAdvertisedFeaturesV10()); - Assert.assertEquals("Wrong port - supported", new PortFeaturesV10(true, true, false, false, false, false, - false, true, false, true, false, false), port.getSupportedFeaturesV10()); - Assert.assertEquals("Wrong port - peer", new PortFeaturesV10(true, false, false, false, false, false, false, - false, true, false, false, true), port.getPeerFeaturesV10()); - } - - /** - * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testWithNoPortsSet() { - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 " - + "00 00 00 8B 00 00 03 B5 " - + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 " - + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 " - + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 " - + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 "); - GetFeaturesOutput builtByFactory = BufferHelper.decodeV10( - OF10FeaturesReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong ports size", 2, builtByFactory.getPhyPort().size()); - } - - /** - * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testWithTwoPortsSet() { - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 " - + "00 00 00 8B 00 00 03 B5"); - GetFeaturesOutput builtByFactory = BufferHelper.decodeV10( - OF10FeaturesReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong ports size", 0, builtByFactory.getPhyPort().size()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort; + +/** + * @author michal.polkorab + * + */ +public class OF10FeaturesReplyMessageFactoryTest { + + /** + * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 " + + "00 00 00 8B 00 00 03 B5 " + + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 " + + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88"); + GetFeaturesOutput builtByFactory = BufferHelper.decodeV10( + OF10FeaturesReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue()); + Assert.assertEquals("Wrong n-buffers", 0x00010203L, builtByFactory.getBuffers().longValue()); + Assert.assertEquals("Wrong n-tables", 0x01, builtByFactory.getTables().shortValue()); + Assert.assertEquals("Wrong capabilities", new CapabilitiesV10(true, true, false, false, false, false, true, true), + builtByFactory.getCapabilitiesV10()); + Assert.assertEquals("Wrong actions", new ActionTypeV10(false, true, true, true, true, false, true, + false, true, true, false, false, false), builtByFactory.getActionsV10()); + PhyPort port = builtByFactory.getPhyPort().get(0); + Assert.assertEquals("Wrong port - port-no", 16, port.getPortNo().intValue()); + Assert.assertEquals("Wrong port - hw-addr", new MacAddress("01:01:05:01:04:02"), port.getHwAddr()); + Assert.assertEquals("Wrong port - name", new String("ALOHA"), port.getName()); + Assert.assertEquals("Wrong port - config", new PortConfigV10(true, false, false, true, false, false, true), + port.getConfigV10()); + Assert.assertEquals("Wrong port - state", new PortStateV10(false, true, false, false, false, true, false, false), + port.getStateV10()); + Assert.assertEquals("Wrong port - curr", new PortFeaturesV10(false, false, false, false, true, true, true, + false, false, false, false, false), port.getCurrentFeaturesV10()); + Assert.assertEquals("Wrong port - advertised", new PortFeaturesV10(false, false, true, true, false, false, + false, false, false, false, true, false), port.getAdvertisedFeaturesV10()); + Assert.assertEquals("Wrong port - supported", new PortFeaturesV10(true, true, false, false, false, false, + false, true, false, true, false, false), port.getSupportedFeaturesV10()); + Assert.assertEquals("Wrong port - peer", new PortFeaturesV10(true, false, false, false, false, false, false, + false, true, false, false, true), port.getPeerFeaturesV10()); + } + + /** + * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testWithNoPortsSet() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 " + + "00 00 00 8B 00 00 03 B5 " + + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 " + + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 " + + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 " + + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 "); + GetFeaturesOutput builtByFactory = BufferHelper.decodeV10( + OF10FeaturesReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong ports size", 2, builtByFactory.getPhyPort().size()); + } + + /** + * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testWithTwoPortsSet() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 " + + "00 00 00 8B 00 00 03 B5"); + GetFeaturesOutput builtByFactory = BufferHelper.decodeV10( + OF10FeaturesReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong ports size", 0, builtByFactory.getPhyPort().size()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactoryTest.java index ba41f512..3a9ec1a6 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FlowRemovedMessageFactoryTest.java @@ -1,38 +1,45 @@ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; - -/** - * @author michal.polkorab - */ -public class OF10FlowRemovedMessageFactoryTest { - - /** - * Testing {@link OF10FlowRemovedMessageFactory} for correct translation into POJO - */ - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 24 08 D1 00 20 AA BB CC DD EE FF " - + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "//36 - + "50 50 20 20 "// match - + "00 01 02 03 04 05 06 07 00 03 01 00 00 00 00 02 " - + "00 00 00 05 00 08 00 00 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07");//41 - FlowRemovedMessage builtByFactory = BufferHelper.decodeV10(OF10FlowRemovedMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue()); - Assert.assertEquals("Wrong priority", 0x03, builtByFactory.getPriority().intValue()); - Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue()); - Assert.assertEquals("Wrong durationSec", 0x00000002L, builtByFactory.getDurationSec().longValue()); - Assert.assertEquals("Wrong durationNsec", 0x00000005L, builtByFactory.getDurationNsec().longValue()); - Assert.assertEquals("Wrong idleTimeout", 0x08, builtByFactory.getIdleTimeout().intValue()); - Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue()); - Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; + +/** + * @author michal.polkorab + */ +public class OF10FlowRemovedMessageFactoryTest { + + /** + * Testing {@link OF10FlowRemovedMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("00 24 08 D1 00 20 AA BB CC DD EE FF " + + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "//36 + + "50 50 20 20 "// match + + "00 01 02 03 04 05 06 07 00 03 01 00 00 00 00 02 " + + "00 00 00 05 00 08 00 00 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07");//41 + FlowRemovedMessage builtByFactory = BufferHelper.decodeV10(OF10FlowRemovedMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue()); + Assert.assertEquals("Wrong priority", 0x03, builtByFactory.getPriority().intValue()); + Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue()); + Assert.assertEquals("Wrong durationSec", 0x00000002L, builtByFactory.getDurationSec().longValue()); + Assert.assertEquals("Wrong durationNsec", 0x00000005L, builtByFactory.getDurationNsec().longValue()); + Assert.assertEquals("Wrong idleTimeout", 0x08, builtByFactory.getIdleTimeout().intValue()); + Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue()); + Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactoryTest.java index d06b3701..5c08bf4d 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10HelloMessageFactoryTest.java @@ -1,47 +1,54 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; - -/** - * @author michal.polkorab - */ -public class OF10HelloMessageFactoryTest { - - /** - * Testing {@link OF10HelloMessageFactory} for correct translation into POJO - */ - @Test - public void testWithoutElements() { - ByteBuf bb = BufferHelper.buildBuffer(); - HelloMessage builtByFactory = BufferHelper.decodeV10( - OF10HelloMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertNull("Wrong elements", builtByFactory.getElements()); - } - - /** - * Testing {@link OF10HelloMessageFactory} for correct translation into POJO - */ - @Test - public void testWithElements() { - ByteBuf bb = BufferHelper.buildBuffer("00 01 " // type - + "00 0c " // length - + "00 00 00 11 " // bitmap 1 - + "00 00 00 00 " // bitmap 2 - + "00 00 00 00" // padding - ); - HelloMessage builtByFactory = BufferHelper.decodeV10( - OF10HelloMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertNull("Wrong elements", builtByFactory.getElements()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; + +/** + * @author michal.polkorab + */ +public class OF10HelloMessageFactoryTest { + + /** + * Testing {@link OF10HelloMessageFactory} for correct translation into POJO + */ + @Test + public void testWithoutElements() { + ByteBuf bb = BufferHelper.buildBuffer(); + HelloMessage builtByFactory = BufferHelper.decodeV10( + OF10HelloMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertNull("Wrong elements", builtByFactory.getElements()); + } + + /** + * Testing {@link OF10HelloMessageFactory} for correct translation into POJO + */ + @Test + public void testWithElements() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 " // type + + "00 0c " // length + + "00 00 00 11 " // bitmap 1 + + "00 00 00 00 " // bitmap 2 + + "00 00 00 00" // padding + ); + HelloMessage builtByFactory = BufferHelper.decodeV10( + OF10HelloMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertNull("Wrong elements", builtByFactory.getElements()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java index 11ec46b3..51f5cdcf 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactoryTest.java @@ -1,30 +1,37 @@ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; - -public class OF10PacketInMessageFactoryTest { - - /** - * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO - */ - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00 01 02 03 04"); - PacketInMessage builtByFactory = BufferHelper.decodeV10(OF10PacketInMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue()); - Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue()); - Assert.assertEquals("Wrong inPort", 0x0102, builtByFactory.getInPort().intValue()); - Assert.assertEquals("Wrong reason", PacketInReason.OFPRNOMATCH, builtByFactory.getReason()); - Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; + +public class OF10PacketInMessageFactoryTest { + + /** + * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00 01 02 03 04"); + PacketInMessage builtByFactory = BufferHelper.decodeV10(OF10PacketInMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue()); + Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue()); + Assert.assertEquals("Wrong inPort", 0x0102, builtByFactory.getInPort().intValue()); + Assert.assertEquals("Wrong reason", PacketInReason.OFPRNOMATCH, builtByFactory.getReason()); + Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactoryTest.java index 0e3ed52d..d4fa28bf 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PortStatusMessageFactoryTest.java @@ -1,51 +1,58 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; - -/** - * @author michal.polkorab - * - */ -public class OF10PortStatusMessageFactoryTest { - - /** - * Testing {@link OF10PortStatusMessageFactory} for correct translation into POJO - */ - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 00 00 00 00 00 00 00 " - + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 " - + "00 00 00 00 15 00 00 01 01 00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88"); - PortStatusMessage builtByFactory = BufferHelper.decodeV10(OF10PortStatusMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong reason", PortReason.OFPPRADD, builtByFactory.getReason()); - Assert.assertEquals("Wrong port - port-no", 16, builtByFactory.getPortNo().intValue()); - Assert.assertEquals("Wrong builtByFactory - hw-addr", new MacAddress("01:01:05:01:04:02"), builtByFactory.getHwAddr()); - Assert.assertEquals("Wrong builtByFactory - name", new String("ALOHA"), builtByFactory.getName()); - Assert.assertEquals("Wrong builtByFactory - config", new PortConfigV10(true, false, false, true, false, false, true), - builtByFactory.getConfigV10()); - Assert.assertEquals("Wrong builtByFactory - state", new PortStateV10(false, true, false, false, false, true, false, false), - builtByFactory.getStateV10()); - Assert.assertEquals("Wrong builtByFactory - curr", new PortFeaturesV10(false, false, false, false, true, true, true, - false, false, false, false, false), builtByFactory.getCurrentFeaturesV10()); - Assert.assertEquals("Wrong builtByFactory - advertised", new PortFeaturesV10(false, false, true, true, false, false, - false, false, false, false, true, false), builtByFactory.getAdvertisedFeaturesV10()); - Assert.assertEquals("Wrong builtByFactory - supbuiltByFactoryed", new PortFeaturesV10(true, true, false, false, false, false, - false, true, false, true, false, false), builtByFactory.getSupportedFeaturesV10()); - Assert.assertEquals("Wrong builtByFactory - peer", new PortFeaturesV10(true, false, false, false, false, false, false, - false, true, false, false, true), builtByFactory.getPeerFeaturesV10()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; + +/** + * @author michal.polkorab + * + */ +public class OF10PortStatusMessageFactoryTest { + + /** + * Testing {@link OF10PortStatusMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("00 00 00 00 00 00 00 00 " + + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 " + + "00 00 00 00 15 00 00 01 01 00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88"); + PortStatusMessage builtByFactory = BufferHelper.decodeV10(OF10PortStatusMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong reason", PortReason.OFPPRADD, builtByFactory.getReason()); + Assert.assertEquals("Wrong port - port-no", 16, builtByFactory.getPortNo().intValue()); + Assert.assertEquals("Wrong builtByFactory - hw-addr", new MacAddress("01:01:05:01:04:02"), builtByFactory.getHwAddr()); + Assert.assertEquals("Wrong builtByFactory - name", new String("ALOHA"), builtByFactory.getName()); + Assert.assertEquals("Wrong builtByFactory - config", new PortConfigV10(true, false, false, true, false, false, true), + builtByFactory.getConfigV10()); + Assert.assertEquals("Wrong builtByFactory - state", new PortStateV10(false, true, false, false, false, true, false, false), + builtByFactory.getStateV10()); + Assert.assertEquals("Wrong builtByFactory - curr", new PortFeaturesV10(false, false, false, false, true, true, true, + false, false, false, false, false), builtByFactory.getCurrentFeaturesV10()); + Assert.assertEquals("Wrong builtByFactory - advertised", new PortFeaturesV10(false, false, true, true, false, false, + false, false, false, false, true, false), builtByFactory.getAdvertisedFeaturesV10()); + Assert.assertEquals("Wrong builtByFactory - supbuiltByFactoryed", new PortFeaturesV10(true, true, false, false, false, false, + false, true, false, true, false, false), builtByFactory.getSupportedFeaturesV10()); + Assert.assertEquals("Wrong builtByFactory - peer", new PortFeaturesV10(true, false, false, false, false, false, false, + false, true, false, false, true), builtByFactory.getPeerFeaturesV10()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactoryTest.java index 3ce772de..216e5d37 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10QueueGetConfigReplyMessageFactoryTest.java @@ -1,53 +1,60 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; - -/** - * @author michal.polkorab - * - */ -public class OF10QueueGetConfigReplyMessageFactoryTest { - - /** - * Testing of {@link OF10QueueGetConfigReplyMessageFactory} for correct - * translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer("00 01 00 00 00 00 00 00 " - + "00 00 00 08 00 10 00 00 00 00 00 08 00 00 00 00 " - + "00 00 00 02 00 28 00 00 00 01 00 10 00 00 00 00 00 20 00 00 00 00 00 00 " - + "00 01 00 10 00 00 00 00 00 30 00 00 00 00 00 00"); - GetQueueConfigOutput builtByFactory = BufferHelper.decodeV10( - OF10QueueGetConfigReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong port", 1, builtByFactory.getPort().getValue().intValue()); - Assert.assertEquals("Wrong queues size", 2, builtByFactory.getQueues().size()); - Queues queue1 = builtByFactory.getQueues().get(0); - Queues queue2 = builtByFactory.getQueues().get(1); - Assert.assertEquals("Wrong queueId", 8, queue1.getQueueId().getValue().intValue()); - Assert.assertEquals("Wrong queue - # properties", 1, queue1.getQueueProperty().size()); - Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTNONE, - queue1.getQueueProperty().get(0).getProperty()); - Assert.assertEquals("Wrong queueId", 2, queue2.getQueueId().getValue().intValue()); - Assert.assertEquals("Wrong queue - # properties", 2, queue2.getQueueProperty().size()); - Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTMINRATE, - queue2.getQueueProperty().get(0).getProperty()); - Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTMINRATE, - queue2.getQueueProperty().get(1).getProperty()); - RateQueueProperty rate1 = queue2.getQueueProperty().get(0).getAugmentation(RateQueueProperty.class); - RateQueueProperty rate2 = queue2.getQueueProperty().get(1).getAugmentation(RateQueueProperty.class); - Assert.assertEquals("Wrong queue - wrong property rate", 32, rate1.getRate().intValue()); - Assert.assertEquals("Wrong queue - wrong property rate", 48, rate2.getRate().intValue()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; + +/** + * @author michal.polkorab + * + */ +public class OF10QueueGetConfigReplyMessageFactoryTest { + + /** + * Testing of {@link OF10QueueGetConfigReplyMessageFactory} for correct + * translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 00 00 00 00 00 00 " + + "00 00 00 08 00 10 00 00 00 00 00 08 00 00 00 00 " + + "00 00 00 02 00 28 00 00 00 01 00 10 00 00 00 00 00 20 00 00 00 00 00 00 " + + "00 01 00 10 00 00 00 00 00 30 00 00 00 00 00 00"); + GetQueueConfigOutput builtByFactory = BufferHelper.decodeV10( + OF10QueueGetConfigReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong port", 1, builtByFactory.getPort().getValue().intValue()); + Assert.assertEquals("Wrong queues size", 2, builtByFactory.getQueues().size()); + Queues queue1 = builtByFactory.getQueues().get(0); + Queues queue2 = builtByFactory.getQueues().get(1); + Assert.assertEquals("Wrong queueId", 8, queue1.getQueueId().getValue().intValue()); + Assert.assertEquals("Wrong queue - # properties", 1, queue1.getQueueProperty().size()); + Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTNONE, + queue1.getQueueProperty().get(0).getProperty()); + Assert.assertEquals("Wrong queueId", 2, queue2.getQueueId().getValue().intValue()); + Assert.assertEquals("Wrong queue - # properties", 2, queue2.getQueueProperty().size()); + Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTMINRATE, + queue2.getQueueProperty().get(0).getProperty()); + Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTMINRATE, + queue2.getQueueProperty().get(1).getProperty()); + RateQueueProperty rate1 = queue2.getQueueProperty().get(0).getAugmentation(RateQueueProperty.class); + RateQueueProperty rate2 = queue2.getQueueProperty().get(1).getAugmentation(RateQueueProperty.class); + Assert.assertEquals("Wrong queue - wrong property rate", 32, rate1.getRate().intValue()); + Assert.assertEquals("Wrong queue - wrong property rate", 48, rate2.getRate().intValue()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactoryTest.java index c68d8962..7dc2e863 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10VendorMessageFactoryTest.java @@ -1,28 +1,35 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; - -/** - * @author michal.polkorab - */ -public class OF10VendorMessageFactoryTest { - - /** - * Testing {@link OF10VendorMessageFactory} for correct translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer("01 02 03 04"); - ExperimenterMessage builtByFactory = BufferHelper.decodeV10( - OF10VendorMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV10(builtByFactory); - Assert.assertEquals("Wrong experimenter", 0x01020304L, builtByFactory.getExperimenter().longValue()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; + +/** + * @author michal.polkorab + */ +public class OF10VendorMessageFactoryTest { + + /** + * Testing {@link OF10VendorMessageFactory} for correct translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("01 02 03 04"); + ExperimenterMessage builtByFactory = BufferHelper.decodeV10( + OF10VendorMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV10(builtByFactory); + Assert.assertEquals("Wrong experimenter", 0x01020304L, builtByFactory.getExperimenter().longValue()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java index 63b813fa..6a3a35f0 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java @@ -1,43 +1,50 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author timotej.kubas - * - */ -public class PacketInMessageFactoryTest { - - private static final Logger LOGGER = LoggerFactory - .getLogger(PacketInMessageFactoryTest.class); - - /** - * Testing {@link PacketInMessageFactory} for correct translation into POJO - */ - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 04 00 01 02 03 04 05 06 07 00 01 00 0C" - + " 80 00 02 04 00 00 00 01 00 00 00 00 00 00 01 02 03 04"); - PacketInMessage builtByFactory = BufferHelper.decodeV13(PacketInMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - - Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue()); - Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue()); - Assert.assertEquals("Wrong reason", PacketInReason.OFPRACTION, builtByFactory.getReason()); - Assert.assertEquals("Wrong tableID", new TableId(4L), builtByFactory.getTableId()); - Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue()); - Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author timotej.kubas + * + */ +public class PacketInMessageFactoryTest { + + private static final Logger LOGGER = LoggerFactory + .getLogger(PacketInMessageFactoryTest.class); + + /** + * Testing {@link PacketInMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 04 00 01 02 03 04 05 06 07 00 01 00 0C" + + " 80 00 02 04 00 00 00 01 00 00 00 00 00 00 01 02 03 04"); + PacketInMessage builtByFactory = BufferHelper.decodeV13(PacketInMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + + Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue()); + Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue()); + Assert.assertEquals("Wrong reason", PacketInReason.OFPRACTION, builtByFactory.getReason()); + Assert.assertEquals("Wrong tableID", new TableId(4L), builtByFactory.getTableId()); + Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue()); + Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java index 967c9fd5..9d427381 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java @@ -1,66 +1,73 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ - -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class PortStatusMessageFactoryTest { - - /** - * Testing {@link PortStatusMessageFactory} for correct translation into POJO - */ - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("01 " + //reason - "00 00 00 00 00 00 00 " + //padding - "00 01 02 03 " + //port no - "00 00 00 00 " + //padding in ofp_port1 - "08 00 27 00 B0 EB " + //mac address - "00 00 " + //padding in ofp_port2 - "00 00 00 41 " + //port config - "00 00 00 05 " + //port state - "00 00 00 81 " + //current features - "00 00 00 81 " + //advertised features - "00 00 00 81 " + //supported features - "00 00 00 81 " + //peer features - "00 00 00 81 " + //curr speed - "00 00 00 80" //max speed - ); - - PortStatusMessage builtByFactory = BufferHelper.decodeV13(PortStatusMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue()); - Assert.assertEquals("Wrong portNumber", 66051L, builtByFactory.getPortNo().longValue()); - Assert.assertEquals("Wrong macAddress", new MacAddress("08:00:27:00:B0:EB"), builtByFactory.getHwAddr()); - Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), builtByFactory.getConfig()); - Assert.assertEquals("Wrong portState", new PortState(false, true, true), builtByFactory.getState()); - Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false, - false, false, false, true, false, false, false, false, - false, false, false, false), builtByFactory.getCurrentFeatures()); - Assert.assertEquals("Wrong advertisedFeatures", new PortFeatures(true, false, false, false, - false, false, false, true, false, false, false, false, - false, false, false, false), builtByFactory.getAdvertisedFeatures()); - Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(true, false, false, false, - false, false, false, true, false, false, false, false, - false, false, false, false), builtByFactory.getSupportedFeatures()); - Assert.assertEquals("Wrong peerFeatures", new PortFeatures(true, false, false, false, - false, false, false, true, false, false, false, false, - false, false, false, false), builtByFactory.getSupportedFeatures()); - Assert.assertEquals("Wrong currSpeed", 129L, builtByFactory.getCurrSpeed().longValue()); - Assert.assertEquals("Wrong maxSpeed", 128L, builtByFactory.getMaxSpeed().longValue()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class PortStatusMessageFactoryTest { + + /** + * Testing {@link PortStatusMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("01 " + //reason + "00 00 00 00 00 00 00 " + //padding + "00 01 02 03 " + //port no + "00 00 00 00 " + //padding in ofp_port1 + "08 00 27 00 B0 EB " + //mac address + "00 00 " + //padding in ofp_port2 + "00 00 00 41 " + //port config + "00 00 00 05 " + //port state + "00 00 00 81 " + //current features + "00 00 00 81 " + //advertised features + "00 00 00 81 " + //supported features + "00 00 00 81 " + //peer features + "00 00 00 81 " + //curr speed + "00 00 00 80" //max speed + ); + + PortStatusMessage builtByFactory = BufferHelper.decodeV13(PortStatusMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue()); + Assert.assertEquals("Wrong portNumber", 66051L, builtByFactory.getPortNo().longValue()); + Assert.assertEquals("Wrong macAddress", new MacAddress("08:00:27:00:B0:EB"), builtByFactory.getHwAddr()); + Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), builtByFactory.getConfig()); + Assert.assertEquals("Wrong portState", new PortState(false, true, true), builtByFactory.getState()); + Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false, + false, false, false, true, false, false, false, false, + false, false, false, false), builtByFactory.getCurrentFeatures()); + Assert.assertEquals("Wrong advertisedFeatures", new PortFeatures(true, false, false, false, + false, false, false, true, false, false, false, false, + false, false, false, false), builtByFactory.getAdvertisedFeatures()); + Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(true, false, false, false, + false, false, false, true, false, false, false, false, + false, false, false, false), builtByFactory.getSupportedFeatures()); + Assert.assertEquals("Wrong peerFeatures", new PortFeatures(true, false, false, false, + false, false, false, true, false, false, false, false, + false, false, false, false), builtByFactory.getSupportedFeatures()); + Assert.assertEquals("Wrong currSpeed", 129L, builtByFactory.getCurrSpeed().longValue()); + Assert.assertEquals("Wrong maxSpeed", 128L, builtByFactory.getMaxSpeed().longValue()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java index eb2cdc7c..4d8cb228 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java @@ -1,88 +1,95 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class QueueGetConfigReplyMessageFactoryMultiTest { - - /** - * Testing of {@link QueueGetConfigReplyMessageFactory} for correct - * translation into POJO - */ - @Test - public void test() { - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port - "00 00 00 00 " + // padding - "00 00 00 01 " + // queueId - "00 00 00 01 " + // port - "00 20 " + // length - "00 00 00 00 00 00 " + // pad - "00 02 " + // property - "00 10 " + // length - "00 00 00 00 " + // pad - "00 05 " + // rate - "00 00 00 00 00 00 " + // pad - "00 00 00 02 " + // queueId - "00 00 00 02 " + // port - "00 20 " + // length - "00 00 00 00 00 00 " + // pad - "00 02 " + // property - "00 10 " + // length - "00 00 00 00 " + // pad - "00 05 " + // rate - "00 00 00 00 00 00 " // pad - ); - - GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13( - QueueGetConfigReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue()); - Assert.assertEquals("Wrong queues", createQueuesList(), builtByFactory.getQueues()); - } - - private static List createQueuesList() { - List queuesList = new ArrayList<>(); - for (int i = 1; i < 3; i++) { - QueuesBuilder qb = new QueuesBuilder(); - qb.setQueueId(new QueueId((long) i)); - qb.setPort(new PortNumber((long) i)); - qb.setQueueProperty(createPropertiesList()); - queuesList.add(qb.build()); - } - return queuesList; - } - - private static List createPropertiesList() { - List propertiesList = new ArrayList<>(); - QueuePropertyBuilder pb = new QueuePropertyBuilder(); - pb.setProperty(QueueProperties.forValue(2)); - RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder(); - rateBuilder.setRate(5); - pb.addAugmentation(RateQueueProperty.class, rateBuilder.build()); - propertiesList.add(pb.build()); - return propertiesList; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class QueueGetConfigReplyMessageFactoryMultiTest { + + /** + * Testing of {@link QueueGetConfigReplyMessageFactory} for correct + * translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port + "00 00 00 00 " + // padding + "00 00 00 01 " + // queueId + "00 00 00 01 " + // port + "00 20 " + // length + "00 00 00 00 00 00 " + // pad + "00 02 " + // property + "00 10 " + // length + "00 00 00 00 " + // pad + "00 05 " + // rate + "00 00 00 00 00 00 " + // pad + "00 00 00 02 " + // queueId + "00 00 00 02 " + // port + "00 20 " + // length + "00 00 00 00 00 00 " + // pad + "00 02 " + // property + "00 10 " + // length + "00 00 00 00 " + // pad + "00 05 " + // rate + "00 00 00 00 00 00 " // pad + ); + + GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13( + QueueGetConfigReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue()); + Assert.assertEquals("Wrong queues", createQueuesList(), builtByFactory.getQueues()); + } + + private static List createQueuesList() { + List queuesList = new ArrayList<>(); + for (int i = 1; i < 3; i++) { + QueuesBuilder qb = new QueuesBuilder(); + qb.setQueueId(new QueueId((long) i)); + qb.setPort(new PortNumber((long) i)); + qb.setQueueProperty(createPropertiesList()); + queuesList.add(qb.build()); + } + return queuesList; + } + + private static List createPropertiesList() { + List propertiesList = new ArrayList<>(); + QueuePropertyBuilder pb = new QueuePropertyBuilder(); + pb.setProperty(QueueProperties.forValue(2)); + RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder(); + rateBuilder.setRate(5); + pb.addAugmentation(RateQueueProperty.class, rateBuilder.build()); + propertiesList.add(pb.build()); + return propertiesList; + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java index cf50b277..157e8d7f 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java @@ -1,62 +1,69 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class QueueGetConfigReplyMessageFactoryTest { - - /** - * Testing {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO - */ - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 00 00 03 00 00 00 00 00 00 00 01 00 00 00 03 00 20 00 00 00 00 00 00 00 02 00 10 00 00 00 00 00 05 00 00 00 00 00 00"); - GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(QueueGetConfigReplyMessageFactory.getInstance(), bb); - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong port", 3L, builtByFactory.getPort().getValue().longValue()); - Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList()); - } - - private static List createQueuesList(){ - List queuesList = new ArrayList<>(); - QueuesBuilder qb = new QueuesBuilder(); - qb.setQueueId(new QueueId(1L)); - qb.setPort(new PortNumber(3L)); - qb.setQueueProperty(createPropertiesList()); - queuesList.add(qb.build()); - - return queuesList; - } - - private static List createPropertiesList(){ - List propertiesList = new ArrayList<>(); - QueuePropertyBuilder pb = new QueuePropertyBuilder(); - pb.setProperty(QueueProperties.forValue(2)); - RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder(); - rateBuilder.setRate(5); - pb.addAugmentation(RateQueueProperty.class, rateBuilder.build()); - propertiesList.add(pb.build()); - return propertiesList; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class QueueGetConfigReplyMessageFactoryTest { + + /** + * Testing {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("00 00 00 03 00 00 00 00 00 00 00 01 00 00 00 03 00 20 00 00 00 00 00 00 00 02 00 10 00 00 00 00 00 05 00 00 00 00 00 00"); + GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(QueueGetConfigReplyMessageFactory.getInstance(), bb); + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong port", 3L, builtByFactory.getPort().getValue().longValue()); + Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList()); + } + + private static List createQueuesList(){ + List queuesList = new ArrayList<>(); + QueuesBuilder qb = new QueuesBuilder(); + qb.setQueueId(new QueueId(1L)); + qb.setPort(new PortNumber(3L)); + qb.setQueueProperty(createPropertiesList()); + queuesList.add(qb.build()); + + return queuesList; + } + + private static List createPropertiesList(){ + List propertiesList = new ArrayList<>(); + QueuePropertyBuilder pb = new QueuePropertyBuilder(); + pb.setProperty(QueueProperties.forValue(2)); + RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder(); + rateBuilder.setRate(5); + pb.addAugmentation(RateQueueProperty.class, rateBuilder.build()); + propertiesList.add(pb.build()); + return propertiesList; + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java index e24af652..2d7ff94e 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/RoleReplyMessageFactoryTest.java @@ -1,30 +1,37 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class RoleReplyMessageFactoryTest { - - /** - * Testing of {@link RoleReplyMessageFactory} for correct translation into POJO - */ - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 00 00 02 00 00 00 00 00 01 02 03 04 05 06 07"); - RoleRequestOutput builtByFactory = BufferHelper.decodeV13(RoleReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - - Assert.assertEquals("Wrong role", 0x02, builtByFactory.getRole().getIntValue()); - Assert.assertEquals("Wrong generationId", 0x01020304050607L, builtByFactory.getGenerationId().longValue()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class RoleReplyMessageFactoryTest { + + /** + * Testing of {@link RoleReplyMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + ByteBuf bb = BufferHelper.buildBuffer("00 00 00 02 00 00 00 00 00 01 02 03 04 05 06 07"); + RoleRequestOutput builtByFactory = BufferHelper.decodeV13(RoleReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + + Assert.assertEquals("Wrong role", 0x02, builtByFactory.getRole().getIntValue()); + Assert.assertEquals("Wrong generationId", 0x01020304050607L, builtByFactory.getGenerationId().longValue()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java index 7f1908e1..6f119eb3 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java @@ -1,39 +1,46 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class BarrierInputMessageFactoryTest { - - private static final byte BARRIER_REQUEST_MESSAGE_CODE_TYPE = BarrierInputMessageFactory.MESSAGE_TYPE; - - /** - * Testing of {@link BarrierInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void test() throws Exception { - BarrierInputBuilder bib = new BarrierInputBuilder(); - BufferHelper.setupHeader(bib, EncodeConstants.OF13_VERSION_ID); - BarrierInput bi = bib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - BarrierInputMessageFactory bimf = BarrierInputMessageFactory.getInstance(); - bimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, bi); - - BufferHelper.checkHeaderV13(out, BARRIER_REQUEST_MESSAGE_CODE_TYPE, 8); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class BarrierInputMessageFactoryTest { + + private static final byte BARRIER_REQUEST_MESSAGE_CODE_TYPE = BarrierInputMessageFactory.MESSAGE_TYPE; + + /** + * Testing of {@link BarrierInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() throws Exception { + BarrierInputBuilder bib = new BarrierInputBuilder(); + BufferHelper.setupHeader(bib, EncodeConstants.OF13_VERSION_ID); + BarrierInput bi = bib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + BarrierInputMessageFactory bimf = BarrierInputMessageFactory.getInstance(); + bimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, bi); + + BufferHelper.checkHeaderV13(out, BARRIER_REQUEST_MESSAGE_CODE_TYPE, 8); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java index 3c2faa64..bb2ee8e3 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java @@ -1,55 +1,62 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class EchoInputMessageFactoryTest { - - private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = EchoInputMessageFactory.MESSAGE_TYPE; - - /** - * Testing of {@link EchoInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testV13() throws Exception { - EchoInputBuilder eib = new EchoInputBuilder(); - BufferHelper.setupHeader(eib, EncodeConstants.OF13_VERSION_ID); - EchoInput ei = eib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance(); - eimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, ei); - - BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8); - } - - /** - * Testing of {@link EchoInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testV10() throws Exception { - EchoInputBuilder eib = new EchoInputBuilder(); - BufferHelper.setupHeader(eib, EncodeConstants.OF10_VERSION_ID); - EchoInput ei = eib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance(); - eimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, ei); - - BufferHelper.checkHeaderV10(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class EchoInputMessageFactoryTest { + + private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = EchoInputMessageFactory.MESSAGE_TYPE; + + /** + * Testing of {@link EchoInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testV13() throws Exception { + EchoInputBuilder eib = new EchoInputBuilder(); + BufferHelper.setupHeader(eib, EncodeConstants.OF13_VERSION_ID); + EchoInput ei = eib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance(); + eimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, ei); + + BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8); + } + + /** + * Testing of {@link EchoInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testV10() throws Exception { + EchoInputBuilder eib = new EchoInputBuilder(); + BufferHelper.setupHeader(eib, EncodeConstants.OF10_VERSION_ID); + EchoInput ei = eib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance(); + eimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, ei); + + BufferHelper.checkHeaderV10(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java index 0052488f..a5a504e1 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java @@ -1,55 +1,62 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class EchoReplyInputMessageFactoryTest { - - private static final byte ECHO_REPLY_MESSAGE_CODE_TYPE = EchoReplyInputMessageFactory.MESSAGE_TYPE; - - /** - * Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testV13() throws Exception { - EchoReplyInputBuilder erib = new EchoReplyInputBuilder(); - BufferHelper.setupHeader(erib, EncodeConstants.OF13_VERSION_ID); - EchoReplyInput eri = erib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance(); - eimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, eri); - - BufferHelper.checkHeaderV13(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8); - } - - /** - * Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testV10() throws Exception { - EchoReplyInputBuilder erib = new EchoReplyInputBuilder(); - BufferHelper.setupHeader(erib, EncodeConstants.OF10_VERSION_ID); - EchoReplyInput eri = erib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance(); - eimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, eri); - - BufferHelper.checkHeaderV10(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class EchoReplyInputMessageFactoryTest { + + private static final byte ECHO_REPLY_MESSAGE_CODE_TYPE = EchoReplyInputMessageFactory.MESSAGE_TYPE; + + /** + * Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testV13() throws Exception { + EchoReplyInputBuilder erib = new EchoReplyInputBuilder(); + BufferHelper.setupHeader(erib, EncodeConstants.OF13_VERSION_ID); + EchoReplyInput eri = erib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance(); + eimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, eri); + + BufferHelper.checkHeaderV13(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8); + } + + /** + * Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testV10() throws Exception { + EchoReplyInputBuilder erib = new EchoReplyInputBuilder(); + BufferHelper.setupHeader(erib, EncodeConstants.OF10_VERSION_ID); + EchoReplyInput eri = erib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance(); + eimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, eri); + + BufferHelper.checkHeaderV10(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java index b75c1c93..ebea1948 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java @@ -1,51 +1,58 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class ExperimenterInputMessageFactoryTest { - - private static final byte EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE = ExperimenterInputMessageFactory.MESSAGE_TYPE; - - /** - * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void test() throws Exception { - ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setExperimenter(0x0001020304L); - builder.setExpType(0x0001020304L); - builder.setData(new byte[] {0x01, 0x02, 0x03}); - ExperimenterInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - ExperimenterInputMessageFactory factory = ExperimenterInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, factory.computeLength(message)); - Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); - Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt()); - Assert.assertArrayEquals("Wrong data", message.getData(), readData(out)); - } - - private static byte[] readData(ByteBuf input) { - byte[] data = new byte[input.readableBytes()]; - input.readBytes(data); - return data; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class ExperimenterInputMessageFactoryTest { + + private static final byte EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE = ExperimenterInputMessageFactory.MESSAGE_TYPE; + + /** + * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() throws Exception { + ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setExperimenter(0x0001020304L); + builder.setExpType(0x0001020304L); + builder.setData(new byte[] {0x01, 0x02, 0x03}); + ExperimenterInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + ExperimenterInputMessageFactory factory = ExperimenterInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, factory.computeLength(message)); + Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); + Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt()); + Assert.assertArrayEquals("Wrong data", message.getData(), readData(out)); + } + + private static byte[] readData(ByteBuf input) { + byte[] data = new byte[input.readableBytes()]; + input.readBytes(data); + return data; + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactoryTest.java index 83cb7d28..6a9ee562 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactoryTest.java @@ -1,163 +1,170 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.InstructionsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class FlowModInputMessageFactoryTest { - private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2; - - /** - * @throws Exception - * Testing of {@link FlowModInputMessageFactory} for correct translation from POJO - */ - @Test - public void testFlowModInputMessageFactory() throws Exception { - FlowModInputBuilder builder = new FlowModInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - byte[] cookie = new byte[]{0x00, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01}; - builder.setCookie(new BigInteger(cookie)); - byte[] cookieMask = new byte[]{0x01, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30}; - builder.setCookieMask(new BigInteger(cookieMask)); - builder.setTableId(new TableId(65L)); - builder.setCommand(FlowModCommand.forValue(2)); - builder.setIdleTimeout(12); - builder.setHardTimeout(0); - builder.setPriority(126); - builder.setBufferId(2L); - builder.setOutPort(new PortNumber(4422L)); - builder.setOutGroup(98L); - builder.setFlags(new FlowModFlags(true, false, true, false, true)); - MatchBuilder matchBuilder = new MatchBuilder(); - matchBuilder.setType(OxmMatchType.class); - List entries = new ArrayList<>(); - MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(OpenflowBasicClass.class); - entriesBuilder.setOxmMatchField(InPhyPort.class); - entriesBuilder.setHasMask(false); - PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder(); - portNumberBuilder.setPortNumber(new PortNumber(42L)); - entriesBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build()); - entries.add(entriesBuilder.build()); - entriesBuilder.setOxmClass(Nxm0Class.class); - entriesBuilder.setOxmMatchField(IpEcn.class); - entriesBuilder.setHasMask(false); - EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder(); - ecnBuilder.setEcn((short) 4); - entriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build()); - entries.add(entriesBuilder.build()); - matchBuilder.setMatchEntries(entries); - builder.setMatch(matchBuilder.build()); - List instructions = new ArrayList<>(); - InstructionsBuilder insBuilder = new InstructionsBuilder(); - insBuilder.setType(GotoTable.class); - TableIdInstructionBuilder idBuilder = new TableIdInstructionBuilder(); - idBuilder.setTableId((short) 43); - insBuilder.addAugmentation(TableIdInstruction.class, idBuilder.build()); - instructions.add(insBuilder.build()); - insBuilder.setType(WriteMetadata.class); - MetadataInstructionBuilder metaBuilder = new MetadataInstructionBuilder(); - metaBuilder.setMetadata(cookie); - metaBuilder.setMetadataMask(cookieMask); - insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build()); - instructions.add(insBuilder.build()); - builder.setInstructions(instructions); - FlowModInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - FlowModInputMessageFactory factory = FlowModInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), out.readLong()); - Assert.assertEquals("Wrong cookieMask", message.getCookieMask().longValue(), out.readLong()); - Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readUnsignedByte()); - Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedByte()); - Assert.assertEquals("Wrong idleTimeOut", message.getIdleTimeout().intValue(), out.readShort()); - Assert.assertEquals("Wrong hardTimeOut", message.getHardTimeout().intValue(), out.readShort()); - Assert.assertEquals("Wrong priority", message.getPriority().intValue(), out.readUnsignedShort()); - Assert.assertEquals("Wrong bufferId", message.getBufferId().intValue(), out.readUnsignedInt()); - Assert.assertEquals("Wrong outPort", message.getOutPort().getValue().intValue(), out.readUnsignedInt()); - Assert.assertEquals("Wrong outGroup", message.getOutGroup().intValue(), out.readUnsignedInt()); - Assert.assertEquals("Wrong flags", message.getFlags(), createFlowModFlagsFromBitmap(out.readUnsignedShort())); - out.skipBytes(PADDING_IN_FLOW_MOD_MESSAGE); - Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort()); - out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort()); - short fieldAndMask = out.readUnsignedByte(); - Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); - Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1); - out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - Assert.assertEquals("Wrong oxm value", 42, out.readUnsignedInt()); - Assert.assertEquals("Wrong oxm class", 0, out.readUnsignedShort()); - fieldAndMask = out.readUnsignedByte(); - Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); - Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1); - out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - Assert.assertEquals("Wrong oxm value", 4, out.readUnsignedByte()); - out.skipBytes(7); - Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort()); - out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - Assert.assertEquals("Wrong instruction value", 43, out.readUnsignedByte()); - out.skipBytes(3); - Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort()); - out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - out.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES); - byte[] cookieRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; - out.readBytes(cookieRead); - byte[] cookieMaskRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; - out.readBytes(cookieMaskRead); - Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead); - Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead); - } - - private static FlowModFlags createFlowModFlagsFromBitmap(int input){ - final Boolean _oFPFFSENDFLOWREM = (input & (1 << 0)) > 0; - final Boolean _oFPFFCHECKOVERLAP = (input & (1 << 1)) > 0; - final Boolean _oFPFFRESETCOUNTS = (input & (1 << 2)) > 0; - final Boolean _oFPFFNOPKTCOUNTS = (input & (1 << 3)) > 0; - final Boolean _oFPFFNOBYTCOUNTS = (input & (1 << 4)) > 0; - return new FlowModFlags(_oFPFFCHECKOVERLAP, _oFPFFNOBYTCOUNTS, _oFPFFNOPKTCOUNTS, _oFPFFRESETCOUNTS, _oFPFFSENDFLOWREM); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.InstructionsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class FlowModInputMessageFactoryTest { + private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2; + + /** + * @throws Exception + * Testing of {@link FlowModInputMessageFactory} for correct translation from POJO + */ + @Test + public void testFlowModInputMessageFactory() throws Exception { + FlowModInputBuilder builder = new FlowModInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + byte[] cookie = new byte[]{0x00, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01}; + builder.setCookie(new BigInteger(cookie)); + byte[] cookieMask = new byte[]{0x01, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30}; + builder.setCookieMask(new BigInteger(cookieMask)); + builder.setTableId(new TableId(65L)); + builder.setCommand(FlowModCommand.forValue(2)); + builder.setIdleTimeout(12); + builder.setHardTimeout(0); + builder.setPriority(126); + builder.setBufferId(2L); + builder.setOutPort(new PortNumber(4422L)); + builder.setOutGroup(98L); + builder.setFlags(new FlowModFlags(true, false, true, false, true)); + MatchBuilder matchBuilder = new MatchBuilder(); + matchBuilder.setType(OxmMatchType.class); + List entries = new ArrayList<>(); + MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(InPhyPort.class); + entriesBuilder.setHasMask(false); + PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder(); + portNumberBuilder.setPortNumber(new PortNumber(42L)); + entriesBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build()); + entries.add(entriesBuilder.build()); + entriesBuilder.setOxmClass(Nxm0Class.class); + entriesBuilder.setOxmMatchField(IpEcn.class); + entriesBuilder.setHasMask(false); + EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder(); + ecnBuilder.setEcn((short) 4); + entriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build()); + entries.add(entriesBuilder.build()); + matchBuilder.setMatchEntries(entries); + builder.setMatch(matchBuilder.build()); + List instructions = new ArrayList<>(); + InstructionsBuilder insBuilder = new InstructionsBuilder(); + insBuilder.setType(GotoTable.class); + TableIdInstructionBuilder idBuilder = new TableIdInstructionBuilder(); + idBuilder.setTableId((short) 43); + insBuilder.addAugmentation(TableIdInstruction.class, idBuilder.build()); + instructions.add(insBuilder.build()); + insBuilder.setType(WriteMetadata.class); + MetadataInstructionBuilder metaBuilder = new MetadataInstructionBuilder(); + metaBuilder.setMetadata(cookie); + metaBuilder.setMetadataMask(cookieMask); + insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build()); + instructions.add(insBuilder.build()); + builder.setInstructions(instructions); + FlowModInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + FlowModInputMessageFactory factory = FlowModInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), out.readLong()); + Assert.assertEquals("Wrong cookieMask", message.getCookieMask().longValue(), out.readLong()); + Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readUnsignedByte()); + Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedByte()); + Assert.assertEquals("Wrong idleTimeOut", message.getIdleTimeout().intValue(), out.readShort()); + Assert.assertEquals("Wrong hardTimeOut", message.getHardTimeout().intValue(), out.readShort()); + Assert.assertEquals("Wrong priority", message.getPriority().intValue(), out.readUnsignedShort()); + Assert.assertEquals("Wrong bufferId", message.getBufferId().intValue(), out.readUnsignedInt()); + Assert.assertEquals("Wrong outPort", message.getOutPort().getValue().intValue(), out.readUnsignedInt()); + Assert.assertEquals("Wrong outGroup", message.getOutGroup().intValue(), out.readUnsignedInt()); + Assert.assertEquals("Wrong flags", message.getFlags(), createFlowModFlagsFromBitmap(out.readUnsignedShort())); + out.skipBytes(PADDING_IN_FLOW_MOD_MESSAGE); + Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort()); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort()); + short fieldAndMask = out.readUnsignedByte(); + Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); + Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + Assert.assertEquals("Wrong oxm value", 42, out.readUnsignedInt()); + Assert.assertEquals("Wrong oxm class", 0, out.readUnsignedShort()); + fieldAndMask = out.readUnsignedByte(); + Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); + Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + Assert.assertEquals("Wrong oxm value", 4, out.readUnsignedByte()); + out.skipBytes(7); + Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort()); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + Assert.assertEquals("Wrong instruction value", 43, out.readUnsignedByte()); + out.skipBytes(3); + Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort()); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + out.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES); + byte[] cookieRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + out.readBytes(cookieRead); + byte[] cookieMaskRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + out.readBytes(cookieMaskRead); + Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead); + Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead); + } + + private static FlowModFlags createFlowModFlagsFromBitmap(int input){ + final Boolean _oFPFFSENDFLOWREM = (input & (1 << 0)) > 0; + final Boolean _oFPFFCHECKOVERLAP = (input & (1 << 1)) > 0; + final Boolean _oFPFFRESETCOUNTS = (input & (1 << 2)) > 0; + final Boolean _oFPFFNOPKTCOUNTS = (input & (1 << 3)) > 0; + final Boolean _oFPFFNOBYTCOUNTS = (input & (1 << 4)) > 0; + return new FlowModFlags(_oFPFFCHECKOVERLAP, _oFPFFNOBYTCOUNTS, _oFPFFNOPKTCOUNTS, _oFPFFRESETCOUNTS, _oFPFFSENDFLOWREM); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java index 44bbe557..0c3c5a62 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java @@ -1,55 +1,62 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class GetConfigInputMessageFactoryTest { - - private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = GetConfigInputMessageFactory.MESSAGE_TYPE; - - /** - * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testV13() throws Exception { - GetConfigInputBuilder gcib = new GetConfigInputBuilder(); - BufferHelper.setupHeader(gcib, EncodeConstants.OF13_VERSION_ID); - GetConfigInput gci = gcib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance(); - gcimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, gci); - - BufferHelper.checkHeaderV13(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8); - } - - /** - * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testV10() throws Exception { - GetConfigInputBuilder gcib = new GetConfigInputBuilder(); - BufferHelper.setupHeader(gcib, EncodeConstants.OF10_VERSION_ID); - GetConfigInput gci = gcib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance(); - gcimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, gci); - - BufferHelper.checkHeaderV10(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class GetConfigInputMessageFactoryTest { + + private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = GetConfigInputMessageFactory.MESSAGE_TYPE; + + /** + * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testV13() throws Exception { + GetConfigInputBuilder gcib = new GetConfigInputBuilder(); + BufferHelper.setupHeader(gcib, EncodeConstants.OF13_VERSION_ID); + GetConfigInput gci = gcib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance(); + gcimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, gci); + + BufferHelper.checkHeaderV13(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8); + } + + /** + * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testV10() throws Exception { + GetConfigInputBuilder gcib = new GetConfigInputBuilder(); + BufferHelper.setupHeader(gcib, EncodeConstants.OF10_VERSION_ID); + GetConfigInput gci = gcib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance(); + gcimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, gci); + + BufferHelper.checkHeaderV10(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java index 7ebf9081..a99dab67 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java @@ -1,54 +1,61 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class GetFeaturesInputMessageFactoryTest { - - private static final byte FEATURES_REQUEST_MESSAGE_CODE_TYPE = GetFeaturesInputMessageFactory.MESSAGE_TYPE; - - /** - * Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testV13() throws Exception { - GetFeaturesInputBuilder gfib = new GetFeaturesInputBuilder(); - BufferHelper.setupHeader(gfib, EncodeConstants.OF13_VERSION_ID); - GetFeaturesInput gfi = gfib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance(); - gfimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, gfi); - - BufferHelper.checkHeaderV13(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8); - } - - /** - * Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testV10() throws Exception { - GetFeaturesInputBuilder gfib = new GetFeaturesInputBuilder(); - BufferHelper.setupHeader(gfib, EncodeConstants.OF10_VERSION_ID); - GetFeaturesInput gfi = gfib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance(); - gfimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, gfi); - - BufferHelper.checkHeaderV10(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class GetFeaturesInputMessageFactoryTest { + + private static final byte FEATURES_REQUEST_MESSAGE_CODE_TYPE = GetFeaturesInputMessageFactory.MESSAGE_TYPE; + + /** + * Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testV13() throws Exception { + GetFeaturesInputBuilder gfib = new GetFeaturesInputBuilder(); + BufferHelper.setupHeader(gfib, EncodeConstants.OF13_VERSION_ID); + GetFeaturesInput gfi = gfib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance(); + gfimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, gfi); + + BufferHelper.checkHeaderV13(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8); + } + + /** + * Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testV10() throws Exception { + GetFeaturesInputBuilder gfib = new GetFeaturesInputBuilder(); + BufferHelper.setupHeader(gfib, EncodeConstants.OF10_VERSION_ID); + GetFeaturesInput gfi = gfib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance(); + gfimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, gfi); + + BufferHelper.checkHeaderV10(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactoryTest.java index 974934fa..77ab3af6 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetQueueConfigInputMessageFactoryTest.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.serialization.factories; import io.netty.buffer.ByteBuf; diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetaAsyncRequestMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetaAsyncRequestMessageFactoryTest.java index ddc5ebd4..0f4fb9f4 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetaAsyncRequestMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetaAsyncRequestMessageFactoryTest.java @@ -1,38 +1,45 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInputBuilder; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class GetaAsyncRequestMessageFactoryTest { - private static final byte MESSAGE_TYPE = 26; - private static final int MESSAGE_LENGTH = 8; - - /** - * Testing of {@link GetAsyncRequestMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testGetAsyncReques() throws Exception { - GetAsyncInputBuilder builder = new GetAsyncInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - GetAsyncInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GetAsyncRequestMessageFactory factory = GetAsyncRequestMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInputBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class GetaAsyncRequestMessageFactoryTest { + private static final byte MESSAGE_TYPE = 26; + private static final int MESSAGE_LENGTH = 8; + + /** + * Testing of {@link GetAsyncRequestMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testGetAsyncReques() throws Exception { + GetAsyncInputBuilder builder = new GetAsyncInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + GetAsyncInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + GetAsyncRequestMessageFactory factory = GetAsyncRequestMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java index dbfada40..2e51815c 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java @@ -1,84 +1,91 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupModCommand; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsListBuilder; - -/** - * @author timotej.kubas - * - */ -public class GroupModInputMessageFactoryTest { - private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1; - - /** - * @throws Exception - * Testing of {@link GroupModInputMessageFactory} for correct translation from POJO - */ - @Test - public void testGroupModInputMessage() throws Exception { - GroupModInputBuilder builder = new GroupModInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setCommand(GroupModCommand.forValue(2)); - builder.setType(GroupType.forValue(3)); - builder.setGroupId(new GroupId(256L)); - List exp = createBucketsList(); - builder.setBucketsList(exp); - GroupModInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - GroupModInputMessageFactory factory = GroupModInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedShort()); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedByte()); - out.skipBytes(PADDING_IN_GROUP_MOD_MESSAGE); - Assert.assertEquals("Wrong groupId", message.getGroupId().getValue().intValue(), out.readUnsignedInt()); - List rec = createBucketsListFromBufer(out); - Assert.assertArrayEquals("Wrong bucketList", exp.toArray(), rec.toArray()); - } - - private static List createBucketsList(){ - List bucketsList = new ArrayList<>(); - BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); - BucketsList bucket; - bucketsBuilder.setWeight(10); - bucketsBuilder.setWatchPort(new PortNumber(65L)); - bucketsBuilder.setWatchGroup(22L); - bucket = bucketsBuilder.build(); - bucketsList.add(bucket); - return bucketsList; - } - - private static List createBucketsListFromBufer(ByteBuf out){ - List bucketsList = new ArrayList<>(); - BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); - BucketsList bucket; - out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - bucketsBuilder.setWeight(out.readUnsignedShort()); - bucketsBuilder.setWatchPort(new PortNumber(out.readUnsignedInt())); - bucketsBuilder.setWatchGroup(out.readUnsignedInt()); - out.skipBytes(4); - bucket = bucketsBuilder.build(); - bucketsList.add(bucket); - return bucketsList; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupModCommand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsListBuilder; + +/** + * @author timotej.kubas + * + */ +public class GroupModInputMessageFactoryTest { + private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1; + + /** + * @throws Exception + * Testing of {@link GroupModInputMessageFactory} for correct translation from POJO + */ + @Test + public void testGroupModInputMessage() throws Exception { + GroupModInputBuilder builder = new GroupModInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setCommand(GroupModCommand.forValue(2)); + builder.setType(GroupType.forValue(3)); + builder.setGroupId(new GroupId(256L)); + List exp = createBucketsList(); + builder.setBucketsList(exp); + GroupModInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + GroupModInputMessageFactory factory = GroupModInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedShort()); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedByte()); + out.skipBytes(PADDING_IN_GROUP_MOD_MESSAGE); + Assert.assertEquals("Wrong groupId", message.getGroupId().getValue().intValue(), out.readUnsignedInt()); + List rec = createBucketsListFromBufer(out); + Assert.assertArrayEquals("Wrong bucketList", exp.toArray(), rec.toArray()); + } + + private static List createBucketsList(){ + List bucketsList = new ArrayList<>(); + BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); + BucketsList bucket; + bucketsBuilder.setWeight(10); + bucketsBuilder.setWatchPort(new PortNumber(65L)); + bucketsBuilder.setWatchGroup(22L); + bucket = bucketsBuilder.build(); + bucketsList.add(bucket); + return bucketsList; + } + + private static List createBucketsListFromBufer(ByteBuf out){ + List bucketsList = new ArrayList<>(); + BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); + BucketsList bucket; + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + bucketsBuilder.setWeight(out.readUnsignedShort()); + bucketsBuilder.setWatchPort(new PortNumber(out.readUnsignedInt())); + bucketsBuilder.setWatchGroup(out.readUnsignedInt()); + out.skipBytes(4); + bucket = bucketsBuilder.build(); + bucketsList.add(bucket); + return bucketsList; + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java index aa2712b6..888476d4 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java @@ -1,165 +1,172 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author michal.polkorab - * - */ -public class HelloInputMessageFactoryTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(HelloInputMessageFactoryTest.class); - - /** - * Testing of {@link HelloInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testWithoutElementsSet() throws Exception { - HelloInputBuilder hib = new HelloInputBuilder(); - BufferHelper.setupHeader(hib, EncodeConstants.OF13_VERSION_ID); - HelloInput hi = hib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance(); - himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi); - - BufferHelper.checkHeaderV13(out, himf.getMessageType(), himf.computeLength(hi)); - } - - /** - * Testing of {@link HelloInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testWith4BitVersionBitmap() throws Exception { - int lengthOfBitmap = 4; - HelloInputBuilder builder = new HelloInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - List expectedElement = createElement(lengthOfBitmap); - builder.setElements(expectedElement); - HelloInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out)); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Elements element = readElement(out).get(0); - Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType()); - Elements comparation = createComparationElement(lengthOfBitmap).get(0); - Assert.assertArrayEquals("Wrong element bitmap", comparation.getVersionBitmap().toArray(), element.getVersionBitmap().toArray()); - } - - /** - * Testing of {@link HelloInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testWith64BitVersionBitmap() throws Exception { - int lengthOfBitmap = 64; - HelloInputBuilder builder = new HelloInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - List expectedElement = createElement(lengthOfBitmap); - builder.setElements(expectedElement); - HelloInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out)); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Elements element = readElement(out).get(0); - Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType()); - Elements comparation = createComparationElement(lengthOfBitmap).get(0); - Assert.assertArrayEquals("Wrong element bitmap", comparation.getVersionBitmap().toArray(), element.getVersionBitmap().toArray()); - } - - private static List createElement(int lengthOfBitmap) { - ElementsBuilder elementsBuilder = new ElementsBuilder(); - List elementsList = new ArrayList<>(); - List booleanList = new ArrayList<>(); - for (int i = 0; i < lengthOfBitmap; i++) { - booleanList.add(true); - } - elementsBuilder.setType(HelloElementType.forValue(1)); - elementsBuilder.setVersionBitmap(booleanList); - elementsList.add(elementsBuilder.build()); - return elementsList; - } - - private static List createComparationElement(int lengthOfBitmap) { - ElementsBuilder elementsBuilder = new ElementsBuilder(); - List elementsList = new ArrayList<>(); - List booleanList = new ArrayList<>(); - for (int i = 0; i < lengthOfBitmap; i++) { - booleanList.add(true); - } - if ((lengthOfBitmap % Integer.SIZE) != 0) { - for (int i = 0; i < (Integer.SIZE - (lengthOfBitmap % Integer.SIZE)); i++) { - booleanList.add(false); - } - } - LOGGER.debug("boolsize " + booleanList.size()); - elementsBuilder.setType(HelloElementType.forValue(1)); - elementsBuilder.setVersionBitmap(booleanList); - elementsList.add(elementsBuilder.build()); - return elementsList; - } - - private static List readElement(ByteBuf input) { - List elementsList = new ArrayList<>(); - while (input.readableBytes() > 0) { - ElementsBuilder elementsBuilder = new ElementsBuilder(); - int type = input.readUnsignedShort(); - int elementLength = input.readUnsignedShort(); - if (type == HelloElementType.VERSIONBITMAP.getIntValue()) { - elementsBuilder.setType(HelloElementType.forValue(type)); - int[] versionBitmap = new int[(elementLength - HelloInputMessageFactory.HELLO_ELEMENT_HEADER_SIZE) / 4]; - for (int i = 0; i < versionBitmap.length; i++) { - versionBitmap[i] = (int) input.readUnsignedInt(); - } - elementsBuilder.setVersionBitmap(readVersionBitmap(versionBitmap)); - int paddingRemainder = elementLength % EncodeConstants.PADDING; - if (paddingRemainder != 0) { - input.readBytes(EncodeConstants.PADDING - paddingRemainder); - } - } - elementsList.add(elementsBuilder.build()); - } - return elementsList; - } - - private static List readVersionBitmap(int[] input){ - List versionBitmapList = new ArrayList<>(); - for (int i = 0; i < input.length; i++) { - int mask = input[i]; - for (int j = 0; j < Integer.SIZE; j++) { - versionBitmapList.add((mask & (1< expectedElement = createElement(lengthOfBitmap); + builder.setElements(expectedElement); + HelloInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out)); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Elements element = readElement(out).get(0); + Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType()); + Elements comparation = createComparationElement(lengthOfBitmap).get(0); + Assert.assertArrayEquals("Wrong element bitmap", comparation.getVersionBitmap().toArray(), element.getVersionBitmap().toArray()); + } + + /** + * Testing of {@link HelloInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testWith64BitVersionBitmap() throws Exception { + int lengthOfBitmap = 64; + HelloInputBuilder builder = new HelloInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + List expectedElement = createElement(lengthOfBitmap); + builder.setElements(expectedElement); + HelloInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out)); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Elements element = readElement(out).get(0); + Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType()); + Elements comparation = createComparationElement(lengthOfBitmap).get(0); + Assert.assertArrayEquals("Wrong element bitmap", comparation.getVersionBitmap().toArray(), element.getVersionBitmap().toArray()); + } + + private static List createElement(int lengthOfBitmap) { + ElementsBuilder elementsBuilder = new ElementsBuilder(); + List elementsList = new ArrayList<>(); + List booleanList = new ArrayList<>(); + for (int i = 0; i < lengthOfBitmap; i++) { + booleanList.add(true); + } + elementsBuilder.setType(HelloElementType.forValue(1)); + elementsBuilder.setVersionBitmap(booleanList); + elementsList.add(elementsBuilder.build()); + return elementsList; + } + + private static List createComparationElement(int lengthOfBitmap) { + ElementsBuilder elementsBuilder = new ElementsBuilder(); + List elementsList = new ArrayList<>(); + List booleanList = new ArrayList<>(); + for (int i = 0; i < lengthOfBitmap; i++) { + booleanList.add(true); + } + if ((lengthOfBitmap % Integer.SIZE) != 0) { + for (int i = 0; i < (Integer.SIZE - (lengthOfBitmap % Integer.SIZE)); i++) { + booleanList.add(false); + } + } + LOGGER.debug("boolsize " + booleanList.size()); + elementsBuilder.setType(HelloElementType.forValue(1)); + elementsBuilder.setVersionBitmap(booleanList); + elementsList.add(elementsBuilder.build()); + return elementsList; + } + + private static List readElement(ByteBuf input) { + List elementsList = new ArrayList<>(); + while (input.readableBytes() > 0) { + ElementsBuilder elementsBuilder = new ElementsBuilder(); + int type = input.readUnsignedShort(); + int elementLength = input.readUnsignedShort(); + if (type == HelloElementType.VERSIONBITMAP.getIntValue()) { + elementsBuilder.setType(HelloElementType.forValue(type)); + int[] versionBitmap = new int[(elementLength - HelloInputMessageFactory.HELLO_ELEMENT_HEADER_SIZE) / 4]; + for (int i = 0; i < versionBitmap.length; i++) { + versionBitmap[i] = (int) input.readUnsignedInt(); + } + elementsBuilder.setVersionBitmap(readVersionBitmap(versionBitmap)); + int paddingRemainder = elementLength % EncodeConstants.PADDING; + if (paddingRemainder != 0) { + input.readBytes(EncodeConstants.PADDING - paddingRemainder); + } + } + elementsList.add(elementsBuilder.build()); + } + return elementsList; + } + + private static List readVersionBitmap(int[] input){ + List versionBitmapList = new ArrayList<>(); + for (int i = 0; i < input.length; i++) { + int mask = input[i]; + for (int j = 0; j < Integer.SIZE; j++) { + versionBitmapList.add((mask & (1< 0; - final Boolean _oFPMFPKTPS = (input & (1 << 1)) > 0; - final Boolean _oFPMFBURST = (input & (1 << 2)) > 0; - final Boolean _oFPMFSTATS = (input & (1 << 3)) > 0; - return new MeterFlags(_oFPMFBURST, _oFPMFKBPS, _oFPMFPKTPS, _oFPMFSTATS); - } - - private static List createBandsList(){ - List bandsList = new ArrayList<>(); - BandsBuilder bandsBuilder = new BandsBuilder(); - MeterBandDropBuilder dropBand = new MeterBandDropBuilder(); - dropBand.setType(MeterBandType.OFPMBTDROP); - dropBand.setRate(1L); - dropBand.setBurstSize(2L); - bandsList.add(bandsBuilder.setMeterBand(dropBand.build()).build()); - MeterBandDscpRemarkBuilder dscpRemarkBand = new MeterBandDscpRemarkBuilder(); - dscpRemarkBand.setType(MeterBandType.OFPMBTDSCPREMARK); - dscpRemarkBand.setRate(1L); - dscpRemarkBand.setBurstSize(2L); - dscpRemarkBand.setPrecLevel((short) 3); - bandsList.add(bandsBuilder.setMeterBand(dscpRemarkBand.build()).build()); - MeterBandExperimenterBuilder experimenterBand = new MeterBandExperimenterBuilder(); - experimenterBand.setType(MeterBandType.OFPMBTEXPERIMENTER); - experimenterBand.setRate(1L); - experimenterBand.setBurstSize(2L); - experimenterBand.setExperimenter(4L); - bandsList.add(bandsBuilder.setMeterBand(experimenterBand.build()).build()); - return bandsList; - } - - private static List decodeBandsList(ByteBuf input){ - List bandsList = new ArrayList<>(); - BandsBuilder bandsBuilder = new BandsBuilder(); - MeterBandDropBuilder dropBand = new MeterBandDropBuilder(); - dropBand.setType(MeterBandType.forValue(input.readUnsignedShort())); - input.skipBytes(Short.SIZE/Byte.SIZE); - dropBand.setRate(input.readUnsignedInt()); - dropBand.setBurstSize(input.readUnsignedInt()); - input.skipBytes(4); - bandsList.add(bandsBuilder.setMeterBand(dropBand.build()).build()); - MeterBandDscpRemarkBuilder dscpRemarkBand = new MeterBandDscpRemarkBuilder(); - dscpRemarkBand.setType(MeterBandType.forValue(input.readUnsignedShort())); - input.skipBytes(Short.SIZE/Byte.SIZE); - dscpRemarkBand.setRate(input.readUnsignedInt()); - dscpRemarkBand.setBurstSize(input.readUnsignedInt()); - dscpRemarkBand.setPrecLevel(input.readUnsignedByte()); - input.skipBytes(3); - bandsList.add(bandsBuilder.setMeterBand(dscpRemarkBand.build()).build()); - MeterBandExperimenterBuilder experimenterBand = new MeterBandExperimenterBuilder(); - experimenterBand.setType(MeterBandType.forValue(input.readUnsignedShort())); - input.skipBytes(Short.SIZE/Byte.SIZE); - experimenterBand.setRate(input.readUnsignedInt()); - experimenterBand.setBurstSize(input.readUnsignedInt()); - experimenterBand.setExperimenter(input.readUnsignedInt()); - bandsList.add(bandsBuilder.setMeterBand(experimenterBand.build()).build()); - return bandsList; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterModCommand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.BandsBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class MeterModInputMessageFactoryTest { + + /** + * @throws Exception + * Testing of {@link MeterModInputMessageFactory} for correct translation from POJO + */ + @Test + public void testMeterModInputMessage() throws Exception { + MeterModInputBuilder builder = new MeterModInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setCommand(MeterModCommand.forValue(1)); + builder.setFlags(new MeterFlags(false, true, true, false)); + builder.setMeterId(new MeterId(2248L)); + builder.setBands(createBandsList()); + MeterModInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MeterModInputMessageFactory factory = MeterModInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), 64); + Assert.assertEquals("Wrong meterModCommand", message.getCommand().getIntValue(), out.readUnsignedShort()); + Assert.assertEquals("Wrong meterFlags", message.getFlags(), decodeMeterModFlags(out.readShort())); + Assert.assertEquals("Wrong meterId", message.getMeterId().getValue().intValue(), out.readUnsignedInt()); + Assert.assertEquals("Wrong bands", message.getBands(), decodeBandsList(out)); + } + + private static MeterFlags decodeMeterModFlags(short input){ + final Boolean _oFPMFKBPS = (input & (1 << 0)) > 0; + final Boolean _oFPMFPKTPS = (input & (1 << 1)) > 0; + final Boolean _oFPMFBURST = (input & (1 << 2)) > 0; + final Boolean _oFPMFSTATS = (input & (1 << 3)) > 0; + return new MeterFlags(_oFPMFBURST, _oFPMFKBPS, _oFPMFPKTPS, _oFPMFSTATS); + } + + private static List createBandsList(){ + List bandsList = new ArrayList<>(); + BandsBuilder bandsBuilder = new BandsBuilder(); + MeterBandDropBuilder dropBand = new MeterBandDropBuilder(); + dropBand.setType(MeterBandType.OFPMBTDROP); + dropBand.setRate(1L); + dropBand.setBurstSize(2L); + bandsList.add(bandsBuilder.setMeterBand(dropBand.build()).build()); + MeterBandDscpRemarkBuilder dscpRemarkBand = new MeterBandDscpRemarkBuilder(); + dscpRemarkBand.setType(MeterBandType.OFPMBTDSCPREMARK); + dscpRemarkBand.setRate(1L); + dscpRemarkBand.setBurstSize(2L); + dscpRemarkBand.setPrecLevel((short) 3); + bandsList.add(bandsBuilder.setMeterBand(dscpRemarkBand.build()).build()); + MeterBandExperimenterBuilder experimenterBand = new MeterBandExperimenterBuilder(); + experimenterBand.setType(MeterBandType.OFPMBTEXPERIMENTER); + experimenterBand.setRate(1L); + experimenterBand.setBurstSize(2L); + experimenterBand.setExperimenter(4L); + bandsList.add(bandsBuilder.setMeterBand(experimenterBand.build()).build()); + return bandsList; + } + + private static List decodeBandsList(ByteBuf input){ + List bandsList = new ArrayList<>(); + BandsBuilder bandsBuilder = new BandsBuilder(); + MeterBandDropBuilder dropBand = new MeterBandDropBuilder(); + dropBand.setType(MeterBandType.forValue(input.readUnsignedShort())); + input.skipBytes(Short.SIZE/Byte.SIZE); + dropBand.setRate(input.readUnsignedInt()); + dropBand.setBurstSize(input.readUnsignedInt()); + input.skipBytes(4); + bandsList.add(bandsBuilder.setMeterBand(dropBand.build()).build()); + MeterBandDscpRemarkBuilder dscpRemarkBand = new MeterBandDscpRemarkBuilder(); + dscpRemarkBand.setType(MeterBandType.forValue(input.readUnsignedShort())); + input.skipBytes(Short.SIZE/Byte.SIZE); + dscpRemarkBand.setRate(input.readUnsignedInt()); + dscpRemarkBand.setBurstSize(input.readUnsignedInt()); + dscpRemarkBand.setPrecLevel(input.readUnsignedByte()); + input.skipBytes(3); + bandsList.add(bandsBuilder.setMeterBand(dscpRemarkBand.build()).build()); + MeterBandExperimenterBuilder experimenterBand = new MeterBandExperimenterBuilder(); + experimenterBand.setType(MeterBandType.forValue(input.readUnsignedShort())); + input.skipBytes(Short.SIZE/Byte.SIZE); + experimenterBand.setRate(input.readUnsignedInt()); + experimenterBand.setBurstSize(input.readUnsignedInt()); + experimenterBand.setExperimenter(input.readUnsignedInt()); + bandsList.add(bandsBuilder.setMeterBand(experimenterBand.build()).build()); + return bandsList; + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java index e725e64b..3b949bc3 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestInputFactoryTest.java @@ -1,539 +1,546 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Assert; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregate; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroup; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStats; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features.TableFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features.TableFeaturesBuilder; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class MultipartRequestInputFactoryTest { - private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4; - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestInputFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(1)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestFlow()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - Assert.assertEquals("Wrong flow", message.getMultipartRequestBody(), decodeRequestFlow(out)); - } - - private static MultipartRequestFlow createRequestFlow() { - MultipartRequestFlowBuilder builder = new MultipartRequestFlowBuilder(); - builder.setTableId((short) 8); - builder.setOutPort(85L); - builder.setOutGroup(95L); - byte[] cookie = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; - builder.setCookie(new BigInteger(cookie)); - byte[] cookieMask = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; - builder.setCookieMask(new BigInteger(cookieMask)); - MultipartRequestFlow flow = builder.build(); - //TODO match field - return flow; - } - - private static MultipartRequestFlow decodeRequestFlow(ByteBuf output) { - final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3; - final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4; - MultipartRequestFlowBuilder builder = new MultipartRequestFlowBuilder(); - builder.setTableId(output.readUnsignedByte()); - output.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01); - builder.setOutPort(output.readUnsignedInt()); - builder.setOutGroup(output.readUnsignedInt()); - output.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02); - byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; - output.readBytes(cookie); - builder.setCookie(new BigInteger(cookie)); - byte[] cookieMask = new byte[Long.SIZE/Byte.SIZE]; - output.readBytes(cookieMask); - builder.setCookieMask(new BigInteger(cookieMask)); - MultipartRequestFlow flow = builder.build(); - return flow; - } - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestInputAggregateBodyFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(2)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestAggregate()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - Assert.assertEquals("Wrong aggregate", message.getMultipartRequestBody(), decodeRequestAggregate(out)); - } - - private static MultipartRequestFlags decodeMultipartRequestFlags(short input){ - final Boolean _oFPMPFREQMORE = (input & (1 << 0)) > 0; - return new MultipartRequestFlags(_oFPMPFREQMORE); - } - - - private static MultipartRequestAggregate createRequestAggregate() { - MultipartRequestAggregateBuilder builder = new MultipartRequestAggregateBuilder(); - builder.setTableId((short) 8); - builder.setOutPort(85L); - builder.setOutGroup(95L); - byte[] cookie = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; - builder.setCookie(new BigInteger(cookie)); - byte[] cookieMask = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; - builder.setCookieMask(new BigInteger(cookieMask)); - MultipartRequestAggregate aggregate = builder.build(); - //TODO match field - return aggregate; - } - - private static MultipartRequestAggregate decodeRequestAggregate(ByteBuf output) { - final byte PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_01 = 3; - final byte PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_02 = 4; - MultipartRequestAggregateBuilder builder = new MultipartRequestAggregateBuilder(); - builder.setTableId(output.readUnsignedByte()); - output.skipBytes(PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_01); - builder.setOutPort(output.readUnsignedInt()); - builder.setOutGroup(output.readUnsignedInt()); - output.skipBytes(PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_02); - byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; - output.readBytes(cookie); - builder.setCookie(new BigInteger(cookie)); - byte[] cookieMask = new byte[Long.SIZE/Byte.SIZE]; - output.readBytes(cookieMask); - builder.setCookieMask(new BigInteger(cookieMask)); - MultipartRequestAggregate flow = builder.build(); - return flow; - } - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestInputTableFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(3)); - builder.setFlags(new MultipartRequestFlags(true)); - //multipart request for table does not have body - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - } - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestPortStatsMessageFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(4)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestPortStats()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - Assert.assertEquals("Wrong portStatsBody", message.getMultipartRequestBody(), decodeRequestPortStats(out)); - } - - private static MultipartRequestPortStats createRequestPortStats() { - MultipartRequestPortStatsBuilder builder = new MultipartRequestPortStatsBuilder(); - builder.setPortNo(2251L); - MultipartRequestPortStats portStats = builder.build(); - return portStats; - } - - private static MultipartRequestPortStats decodeRequestPortStats(ByteBuf output) { - final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4; - MultipartRequestPortStatsBuilder builder = new MultipartRequestPortStatsBuilder(); - builder.setPortNo(output.readUnsignedInt()); - output.skipBytes(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY); - MultipartRequestPortStats portRequest = builder.build(); - return portRequest; - } - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestQueueMessageFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(5)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestQueue()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - Assert.assertEquals("Wrong queueBody", message.getMultipartRequestBody(), decodeRequestQueue(out)); - } - - private static MultipartRequestQueue createRequestQueue() { - MultipartRequestQueueBuilder builder = new MultipartRequestQueueBuilder(); - builder.setPortNo(2256L); - builder.setQueueId(2211L); - MultipartRequestQueue queue = builder.build(); - return queue; - } - - private static MultipartRequestQueue decodeRequestQueue(ByteBuf output) { - MultipartRequestQueueBuilder builder = new MultipartRequestQueueBuilder(); - builder.setPortNo(output.readUnsignedInt()); - builder.setQueueId(output.readUnsignedInt()); - MultipartRequestQueue queue = builder.build(); - return queue; - } - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestGroupMessageFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(6)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestGroup()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - Assert.assertEquals("Wrong groupBody", message.getMultipartRequestBody(), decodeRequestGroup(out)); - } - - private static MultipartRequestGroup createRequestGroup() { - MultipartRequestGroupBuilder builder = new MultipartRequestGroupBuilder(); - builder.setGroupId(new GroupId(2258L)); - MultipartRequestGroup group = builder.build(); - return group; - } - - private static MultipartRequestGroup decodeRequestGroup(ByteBuf output) { - final byte PADDING_IN_MULTIPART_REQUEST_GROUP_BODY = 4; - MultipartRequestGroupBuilder builder = new MultipartRequestGroupBuilder(); - builder.setGroupId(new GroupId(output.readUnsignedInt())); - output.skipBytes(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY); - MultipartRequestGroup group = builder.build(); - return group; - } - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestMeterMessageFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(9)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestMeter()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - Assert.assertEquals("Wrong meterBody", message.getMultipartRequestBody(), decodeRequestMeter(out)); - } - - private static MultipartRequestMeter createRequestMeter() { - MultipartRequestMeterBuilder builder = new MultipartRequestMeterBuilder(); - builder.setMeterId(new MeterId(1121L)); - MultipartRequestMeter meter = builder.build(); - return meter; - } - - private static MultipartRequestMeter decodeRequestMeter(ByteBuf output) { - final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4; - MultipartRequestMeterBuilder builder = new MultipartRequestMeterBuilder(); - builder.setMeterId(new MeterId(output.readUnsignedInt())); - output.skipBytes(PADDING_IN_MULTIPART_REQUEST_METER_BODY); - MultipartRequestMeter meter = builder.build(); - return meter; - } - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestMeterConfigMessageFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(10)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestMeterConfig()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - Assert.assertEquals("Wrong meterConfigBody", message.getMultipartRequestBody(), decodeRequestMeterConfig(out)); - } - - private static MultipartRequestMeterConfig createRequestMeterConfig() { - MultipartRequestMeterConfigBuilder builder = new MultipartRequestMeterConfigBuilder(); - builder.setMeterId(new MeterId(1133L)); - MultipartRequestMeterConfig meterConfig = builder.build(); - return meterConfig; - } - - private static MultipartRequestMeterConfig decodeRequestMeterConfig(ByteBuf output) { - final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4; - MultipartRequestMeterConfigBuilder builder = new MultipartRequestMeterConfigBuilder(); - builder.setMeterId(new MeterId(output.readUnsignedInt())); - output.skipBytes(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY); - MultipartRequestMeterConfig meterConfig = builder.build(); - return meterConfig; - } - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestExperimenterMessageFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(0xffff)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestExperimenter()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - Assert.assertEquals("Wrong experimenterBody", message.getMultipartRequestBody(), decodeRequestExperimenter(out)); - } - - private static MultipartRequestExperimenter createRequestExperimenter() { - MultipartRequestExperimenterBuilder builder = new MultipartRequestExperimenterBuilder(); - builder.setExperimenter(1133L); - builder.setExpType(1135L); - MultipartRequestExperimenter experimenter = builder.build(); - return experimenter; - } - - private static MultipartRequestExperimenter decodeRequestExperimenter(ByteBuf output) { - MultipartRequestExperimenterBuilder builder = new MultipartRequestExperimenterBuilder(); - builder.setExperimenter(output.readUnsignedInt()); - builder.setExpType(output.readUnsignedInt()); - MultipartRequestExperimenter experimenter = builder.build(); - return experimenter; - } - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestDescMessageFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(0)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestDesc()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - } - - private static MultipartRequestBody createRequestDesc() { - MultipartRequestDescBuilder builder = new MultipartRequestDescBuilder(); - return builder.build(); - } - - /** - * @throws Exception - * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO - */ - @Test - public void testMultipartRequestTableFeaturesMessageFactory() throws Exception { - MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setType(MultipartType.forValue(12)); - builder.setFlags(new MultipartRequestFlags(true)); - builder.setMultipartRequestBody(createRequestTableFeatures()); - MultipartRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); - out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); - - MultipartRequestTableFeatures messageTableFeatures = (MultipartRequestTableFeatures) message.getMultipartRequestBody(); - Assert.assertEquals("Wrong tableFeaturesBody", messageTableFeatures.getTableFeatures(), decodeRequestTableFeatures(out).getTableFeatures()); - } - - private static MultipartRequestTableFeatures createRequestTableFeatures() { - MultipartRequestTableFeaturesBuilder builder = new MultipartRequestTableFeaturesBuilder(); - List tableFeaturesList = new ArrayList<>(); - TableFeaturesBuilder tableFeaturesBuilder = new TableFeaturesBuilder(); - tableFeaturesBuilder.setTableId((short) 8); - tableFeaturesBuilder.setName("AAAABBBBCCCCDDDDEEEEFFFFGGGG"); - tableFeaturesBuilder.setMetadataMatch(new BigInteger(new byte[] {0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01})); - tableFeaturesBuilder.setMetadataWrite(new BigInteger(new byte[] {0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01})); - tableFeaturesBuilder.setConfig(new TableConfig(true)); - tableFeaturesBuilder.setMaxEntries(65L); - TableFeatures tableFeature = tableFeaturesBuilder.build(); - tableFeaturesList.add(tableFeature); - builder.setTableFeatures(tableFeaturesList); - MultipartRequestTableFeatures tableFeaturesRequest = builder.build(); - return tableFeaturesRequest; - } - - private static MultipartRequestTableFeatures decodeRequestTableFeatures(ByteBuf output) { - final byte PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY = 5; - final byte OFP_MAX_TABLE_NAME_LEN = 32; - MultipartRequestTableFeaturesBuilder builder = new MultipartRequestTableFeaturesBuilder(); - List tableFeaturesList = new ArrayList<>(); - TableFeaturesBuilder tableFeaturesBuilder = new TableFeaturesBuilder(); - tableFeaturesBuilder.setTableId(output.readUnsignedByte()); - output.skipBytes(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY); - byte[] tableNameBytes = new byte[OFP_MAX_TABLE_NAME_LEN]; - output.readBytes(tableNameBytes); - String tableName = new String(tableNameBytes); - tableFeaturesBuilder.setName(tableName.trim()); - byte[] metadataMatch = new byte[Long.SIZE/Byte.SIZE]; - output.readBytes(metadataMatch); - tableFeaturesBuilder.setMetadataMatch(new BigInteger(metadataMatch)); - byte[] metadataWrite = new byte[Long.SIZE/Byte.SIZE]; - output.readBytes(metadataWrite); - tableFeaturesBuilder.setMetadataWrite(new BigInteger(metadataWrite)); - tableFeaturesBuilder.setConfig(decodeTableConfig(output.readInt())); - tableFeaturesBuilder.setMaxEntries(output.readUnsignedInt()); - TableFeatures tableFeature = tableFeaturesBuilder.build(); - tableFeaturesList.add(tableFeature); - builder.setTableFeatures(tableFeaturesList); - MultipartRequestTableFeatures tableFeaturesRequest = builder.build(); - return tableFeaturesRequest; - } - - private static TableConfig decodeTableConfig(int input) { - final Boolean _oFPTCDEPRECATEDMASK = (input & (1 << 3)) > 0; - return new TableConfig(_oFPTCDEPRECATEDMASK); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features.TableFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features.TableFeaturesBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class MultipartRequestInputFactoryTest { + private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4; + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestInputFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(1)); + builder.setFlags(new MultipartRequestFlags(true)); + builder.setMultipartRequestBody(createRequestFlow()); + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + Assert.assertEquals("Wrong flow", message.getMultipartRequestBody(), decodeRequestFlow(out)); + } + + private static MultipartRequestFlow createRequestFlow() { + MultipartRequestFlowBuilder builder = new MultipartRequestFlowBuilder(); + builder.setTableId((short) 8); + builder.setOutPort(85L); + builder.setOutGroup(95L); + byte[] cookie = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; + builder.setCookie(new BigInteger(cookie)); + byte[] cookieMask = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; + builder.setCookieMask(new BigInteger(cookieMask)); + MultipartRequestFlow flow = builder.build(); + //TODO match field + return flow; + } + + private static MultipartRequestFlow decodeRequestFlow(ByteBuf output) { + final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3; + final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4; + MultipartRequestFlowBuilder builder = new MultipartRequestFlowBuilder(); + builder.setTableId(output.readUnsignedByte()); + output.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01); + builder.setOutPort(output.readUnsignedInt()); + builder.setOutGroup(output.readUnsignedInt()); + output.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02); + byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; + output.readBytes(cookie); + builder.setCookie(new BigInteger(cookie)); + byte[] cookieMask = new byte[Long.SIZE/Byte.SIZE]; + output.readBytes(cookieMask); + builder.setCookieMask(new BigInteger(cookieMask)); + MultipartRequestFlow flow = builder.build(); + return flow; + } + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestInputAggregateBodyFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(2)); + builder.setFlags(new MultipartRequestFlags(true)); + builder.setMultipartRequestBody(createRequestAggregate()); + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + Assert.assertEquals("Wrong aggregate", message.getMultipartRequestBody(), decodeRequestAggregate(out)); + } + + private static MultipartRequestFlags decodeMultipartRequestFlags(short input){ + final Boolean _oFPMPFREQMORE = (input & (1 << 0)) > 0; + return new MultipartRequestFlags(_oFPMPFREQMORE); + } + + + private static MultipartRequestAggregate createRequestAggregate() { + MultipartRequestAggregateBuilder builder = new MultipartRequestAggregateBuilder(); + builder.setTableId((short) 8); + builder.setOutPort(85L); + builder.setOutGroup(95L); + byte[] cookie = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; + builder.setCookie(new BigInteger(cookie)); + byte[] cookieMask = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; + builder.setCookieMask(new BigInteger(cookieMask)); + MultipartRequestAggregate aggregate = builder.build(); + //TODO match field + return aggregate; + } + + private static MultipartRequestAggregate decodeRequestAggregate(ByteBuf output) { + final byte PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_01 = 3; + final byte PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_02 = 4; + MultipartRequestAggregateBuilder builder = new MultipartRequestAggregateBuilder(); + builder.setTableId(output.readUnsignedByte()); + output.skipBytes(PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_01); + builder.setOutPort(output.readUnsignedInt()); + builder.setOutGroup(output.readUnsignedInt()); + output.skipBytes(PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_02); + byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; + output.readBytes(cookie); + builder.setCookie(new BigInteger(cookie)); + byte[] cookieMask = new byte[Long.SIZE/Byte.SIZE]; + output.readBytes(cookieMask); + builder.setCookieMask(new BigInteger(cookieMask)); + MultipartRequestAggregate flow = builder.build(); + return flow; + } + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestInputTableFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(3)); + builder.setFlags(new MultipartRequestFlags(true)); + //multipart request for table does not have body + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + } + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestPortStatsMessageFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(4)); + builder.setFlags(new MultipartRequestFlags(true)); + builder.setMultipartRequestBody(createRequestPortStats()); + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + Assert.assertEquals("Wrong portStatsBody", message.getMultipartRequestBody(), decodeRequestPortStats(out)); + } + + private static MultipartRequestPortStats createRequestPortStats() { + MultipartRequestPortStatsBuilder builder = new MultipartRequestPortStatsBuilder(); + builder.setPortNo(2251L); + MultipartRequestPortStats portStats = builder.build(); + return portStats; + } + + private static MultipartRequestPortStats decodeRequestPortStats(ByteBuf output) { + final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4; + MultipartRequestPortStatsBuilder builder = new MultipartRequestPortStatsBuilder(); + builder.setPortNo(output.readUnsignedInt()); + output.skipBytes(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY); + MultipartRequestPortStats portRequest = builder.build(); + return portRequest; + } + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestQueueMessageFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(5)); + builder.setFlags(new MultipartRequestFlags(true)); + builder.setMultipartRequestBody(createRequestQueue()); + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + Assert.assertEquals("Wrong queueBody", message.getMultipartRequestBody(), decodeRequestQueue(out)); + } + + private static MultipartRequestQueue createRequestQueue() { + MultipartRequestQueueBuilder builder = new MultipartRequestQueueBuilder(); + builder.setPortNo(2256L); + builder.setQueueId(2211L); + MultipartRequestQueue queue = builder.build(); + return queue; + } + + private static MultipartRequestQueue decodeRequestQueue(ByteBuf output) { + MultipartRequestQueueBuilder builder = new MultipartRequestQueueBuilder(); + builder.setPortNo(output.readUnsignedInt()); + builder.setQueueId(output.readUnsignedInt()); + MultipartRequestQueue queue = builder.build(); + return queue; + } + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestGroupMessageFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(6)); + builder.setFlags(new MultipartRequestFlags(true)); + builder.setMultipartRequestBody(createRequestGroup()); + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + Assert.assertEquals("Wrong groupBody", message.getMultipartRequestBody(), decodeRequestGroup(out)); + } + + private static MultipartRequestGroup createRequestGroup() { + MultipartRequestGroupBuilder builder = new MultipartRequestGroupBuilder(); + builder.setGroupId(new GroupId(2258L)); + MultipartRequestGroup group = builder.build(); + return group; + } + + private static MultipartRequestGroup decodeRequestGroup(ByteBuf output) { + final byte PADDING_IN_MULTIPART_REQUEST_GROUP_BODY = 4; + MultipartRequestGroupBuilder builder = new MultipartRequestGroupBuilder(); + builder.setGroupId(new GroupId(output.readUnsignedInt())); + output.skipBytes(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY); + MultipartRequestGroup group = builder.build(); + return group; + } + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestMeterMessageFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(9)); + builder.setFlags(new MultipartRequestFlags(true)); + builder.setMultipartRequestBody(createRequestMeter()); + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + Assert.assertEquals("Wrong meterBody", message.getMultipartRequestBody(), decodeRequestMeter(out)); + } + + private static MultipartRequestMeter createRequestMeter() { + MultipartRequestMeterBuilder builder = new MultipartRequestMeterBuilder(); + builder.setMeterId(new MeterId(1121L)); + MultipartRequestMeter meter = builder.build(); + return meter; + } + + private static MultipartRequestMeter decodeRequestMeter(ByteBuf output) { + final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4; + MultipartRequestMeterBuilder builder = new MultipartRequestMeterBuilder(); + builder.setMeterId(new MeterId(output.readUnsignedInt())); + output.skipBytes(PADDING_IN_MULTIPART_REQUEST_METER_BODY); + MultipartRequestMeter meter = builder.build(); + return meter; + } + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestMeterConfigMessageFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(10)); + builder.setFlags(new MultipartRequestFlags(true)); + builder.setMultipartRequestBody(createRequestMeterConfig()); + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + Assert.assertEquals("Wrong meterConfigBody", message.getMultipartRequestBody(), decodeRequestMeterConfig(out)); + } + + private static MultipartRequestMeterConfig createRequestMeterConfig() { + MultipartRequestMeterConfigBuilder builder = new MultipartRequestMeterConfigBuilder(); + builder.setMeterId(new MeterId(1133L)); + MultipartRequestMeterConfig meterConfig = builder.build(); + return meterConfig; + } + + private static MultipartRequestMeterConfig decodeRequestMeterConfig(ByteBuf output) { + final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4; + MultipartRequestMeterConfigBuilder builder = new MultipartRequestMeterConfigBuilder(); + builder.setMeterId(new MeterId(output.readUnsignedInt())); + output.skipBytes(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY); + MultipartRequestMeterConfig meterConfig = builder.build(); + return meterConfig; + } + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestExperimenterMessageFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(0xffff)); + builder.setFlags(new MultipartRequestFlags(true)); + builder.setMultipartRequestBody(createRequestExperimenter()); + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + Assert.assertEquals("Wrong experimenterBody", message.getMultipartRequestBody(), decodeRequestExperimenter(out)); + } + + private static MultipartRequestExperimenter createRequestExperimenter() { + MultipartRequestExperimenterBuilder builder = new MultipartRequestExperimenterBuilder(); + builder.setExperimenter(1133L); + builder.setExpType(1135L); + MultipartRequestExperimenter experimenter = builder.build(); + return experimenter; + } + + private static MultipartRequestExperimenter decodeRequestExperimenter(ByteBuf output) { + MultipartRequestExperimenterBuilder builder = new MultipartRequestExperimenterBuilder(); + builder.setExperimenter(output.readUnsignedInt()); + builder.setExpType(output.readUnsignedInt()); + MultipartRequestExperimenter experimenter = builder.build(); + return experimenter; + } + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestDescMessageFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(0)); + builder.setFlags(new MultipartRequestFlags(true)); + builder.setMultipartRequestBody(createRequestDesc()); + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + } + + private static MultipartRequestBody createRequestDesc() { + MultipartRequestDescBuilder builder = new MultipartRequestDescBuilder(); + return builder.build(); + } + + /** + * @throws Exception + * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO + */ + @Test + public void testMultipartRequestTableFeaturesMessageFactory() throws Exception { + MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setType(MultipartType.forValue(12)); + builder.setFlags(new MultipartRequestFlags(true)); + builder.setMultipartRequestBody(createRequestTableFeatures()); + MultipartRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); + Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); + out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); + + MultipartRequestTableFeatures messageTableFeatures = (MultipartRequestTableFeatures) message.getMultipartRequestBody(); + Assert.assertEquals("Wrong tableFeaturesBody", messageTableFeatures.getTableFeatures(), decodeRequestTableFeatures(out).getTableFeatures()); + } + + private static MultipartRequestTableFeatures createRequestTableFeatures() { + MultipartRequestTableFeaturesBuilder builder = new MultipartRequestTableFeaturesBuilder(); + List tableFeaturesList = new ArrayList<>(); + TableFeaturesBuilder tableFeaturesBuilder = new TableFeaturesBuilder(); + tableFeaturesBuilder.setTableId((short) 8); + tableFeaturesBuilder.setName("AAAABBBBCCCCDDDDEEEEFFFFGGGG"); + tableFeaturesBuilder.setMetadataMatch(new BigInteger(new byte[] {0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01})); + tableFeaturesBuilder.setMetadataWrite(new BigInteger(new byte[] {0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01})); + tableFeaturesBuilder.setConfig(new TableConfig(true)); + tableFeaturesBuilder.setMaxEntries(65L); + TableFeatures tableFeature = tableFeaturesBuilder.build(); + tableFeaturesList.add(tableFeature); + builder.setTableFeatures(tableFeaturesList); + MultipartRequestTableFeatures tableFeaturesRequest = builder.build(); + return tableFeaturesRequest; + } + + private static MultipartRequestTableFeatures decodeRequestTableFeatures(ByteBuf output) { + final byte PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY = 5; + final byte OFP_MAX_TABLE_NAME_LEN = 32; + MultipartRequestTableFeaturesBuilder builder = new MultipartRequestTableFeaturesBuilder(); + List tableFeaturesList = new ArrayList<>(); + TableFeaturesBuilder tableFeaturesBuilder = new TableFeaturesBuilder(); + tableFeaturesBuilder.setTableId(output.readUnsignedByte()); + output.skipBytes(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY); + byte[] tableNameBytes = new byte[OFP_MAX_TABLE_NAME_LEN]; + output.readBytes(tableNameBytes); + String tableName = new String(tableNameBytes); + tableFeaturesBuilder.setName(tableName.trim()); + byte[] metadataMatch = new byte[Long.SIZE/Byte.SIZE]; + output.readBytes(metadataMatch); + tableFeaturesBuilder.setMetadataMatch(new BigInteger(metadataMatch)); + byte[] metadataWrite = new byte[Long.SIZE/Byte.SIZE]; + output.readBytes(metadataWrite); + tableFeaturesBuilder.setMetadataWrite(new BigInteger(metadataWrite)); + tableFeaturesBuilder.setConfig(decodeTableConfig(output.readInt())); + tableFeaturesBuilder.setMaxEntries(output.readUnsignedInt()); + TableFeatures tableFeature = tableFeaturesBuilder.build(); + tableFeaturesList.add(tableFeature); + builder.setTableFeatures(tableFeaturesList); + MultipartRequestTableFeatures tableFeaturesRequest = builder.build(); + return tableFeaturesRequest; + } + + private static TableConfig decodeTableConfig(int input) { + final Boolean _oFPTCDEPRECATEDMASK = (input & (1 << 3)) > 0; + return new TableConfig(_oFPTCDEPRECATEDMASK); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactoryTest.java index 93ba0b06..7e50fa8b 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10BarrierInputMessageFactoryTest.java @@ -1,36 +1,43 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class OF10BarrierInputMessageFactoryTest { - - /** - * Testing of {@link OF10BarrierInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void test() throws Exception { - BarrierInputBuilder bib = new BarrierInputBuilder(); - BufferHelper.setupHeader(bib, EncodeConstants.OF10_VERSION_ID); - BarrierInput bi = bib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10BarrierInputMessageFactory bimf = OF10BarrierInputMessageFactory.getInstance(); - bimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, bi); - - BufferHelper.checkHeaderV10(out, (byte) 18, 8); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10BarrierInputMessageFactoryTest { + + /** + * Testing of {@link OF10BarrierInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() throws Exception { + BarrierInputBuilder bib = new BarrierInputBuilder(); + BufferHelper.setupHeader(bib, EncodeConstants.OF10_VERSION_ID); + BarrierInput bi = bib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10BarrierInputMessageFactory bimf = OF10BarrierInputMessageFactory.getInstance(); + bimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, bi); + + BufferHelper.checkHeaderV10(out, (byte) 18, 8); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactoryTest.java index 1c2d53f8..fbb00757 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactoryTest.java @@ -1,137 +1,144 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class OF10FlowModInputMessageFactoryTest { - - /** - * @throws Exception - * Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO - */ - @Test - public void testFlowModInputMessageFactory() throws Exception { - FlowModInputBuilder builder = new FlowModInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - MatchV10Builder matchBuilder = new MatchV10Builder(); - matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true, true)); - matchBuilder.setNwSrcMask((short) 0); - matchBuilder.setNwDstMask((short) 0); - matchBuilder.setInPort(58); - matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01")); - matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff")); - matchBuilder.setDlVlan(18); - matchBuilder.setDlVlanPcp((short) 5); - matchBuilder.setDlType(42); - matchBuilder.setNwTos((short) 4); - matchBuilder.setNwProto((short) 7); - matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8")); - matchBuilder.setNwDst(new Ipv4Address("16.16.16.16")); - matchBuilder.setTpSrc(6653); - matchBuilder.setTpDst(6633); - builder.setMatchV10(matchBuilder.build()); - byte[] cookie = new byte[]{0x00, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01}; - builder.setCookie(new BigInteger(cookie)); - builder.setCommand(FlowModCommand.forValue(0)); - builder.setIdleTimeout(12); - builder.setHardTimeout(16); - builder.setPriority(1); - builder.setBufferId(2L); - builder.setOutPort(new PortNumber(4422L)); - builder.setFlagsV10(new FlowModFlagsV10(true, false, true)); - List actions = new ArrayList<>(); - ActionsListBuilder actionsListBuilder = new ActionsListBuilder(); - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetNwDst.class); - IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder(); - ipBuilder.setIpAddress(new Ipv4Address("2.2.2.2")); - actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build()); - actionsListBuilder.setAction(actionBuilder.build()); - actions.add(actionsListBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(SetTpSrc.class); - PortActionBuilder portBuilder = new PortActionBuilder(); - portBuilder.setPort(new PortNumber(42L)); - actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); - actionsListBuilder.setAction(actionBuilder.build()); - actions.add(actionsListBuilder.build()); - builder.setActionsList(actions); - FlowModInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10FlowModInputMessageFactory factory = OF10FlowModInputMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); - - BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt()); - Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort()); - byte[] dlSrc = new byte[6]; - out.readBytes(dlSrc); - Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc)); - byte[] dlDst = new byte[6]; - out.readBytes(dlDst); - Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst)); - Assert.assertEquals("Wrong dlVlan", 18, out.readUnsignedShort()); - Assert.assertEquals("Wrong dlVlanPcp", 5, out.readUnsignedByte()); - out.skipBytes(1); - Assert.assertEquals("Wrong dlType", 42, out.readUnsignedShort()); - Assert.assertEquals("Wrong nwTos", 4, out.readUnsignedByte()); - Assert.assertEquals("Wrong nwProto", 7, out.readUnsignedByte()); - out.skipBytes(2); - Assert.assertEquals("Wrong nwSrc", 134744072, out.readUnsignedInt()); - Assert.assertEquals("Wrong nwDst", 269488144, out.readUnsignedInt()); - Assert.assertEquals("Wrong tpSrc", 6653, out.readUnsignedShort()); - Assert.assertEquals("Wrong tpDst", 6633, out.readUnsignedShort()); - byte[] cookieRead = new byte[8]; - out.readBytes(cookieRead); - Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead); - Assert.assertEquals("Wrong command", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong idleTimeOut", 12, out.readUnsignedShort()); - Assert.assertEquals("Wrong hardTimeOut", 16, out.readUnsignedShort()); - Assert.assertEquals("Wrong priority", 1, out.readUnsignedShort()); - Assert.assertEquals("Wrong bufferId", 2, out.readUnsignedInt()); - Assert.assertEquals("Wrong outPort", 4422, out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort()); - Assert.assertEquals("Wrong action - type", 7, out.readUnsignedShort()); - Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", 33686018, out.readUnsignedInt()); - Assert.assertEquals("Wrong action - type", 9, out.readUnsignedShort()); - Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong flags", 42, out.readUnsignedShort()); - out.skipBytes(2); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10FlowModInputMessageFactoryTest { + + /** + * @throws Exception + * Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO + */ + @Test + public void testFlowModInputMessageFactory() throws Exception { + FlowModInputBuilder builder = new FlowModInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); + MatchV10Builder matchBuilder = new MatchV10Builder(); + matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true, true)); + matchBuilder.setNwSrcMask((short) 0); + matchBuilder.setNwDstMask((short) 0); + matchBuilder.setInPort(58); + matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01")); + matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff")); + matchBuilder.setDlVlan(18); + matchBuilder.setDlVlanPcp((short) 5); + matchBuilder.setDlType(42); + matchBuilder.setNwTos((short) 4); + matchBuilder.setNwProto((short) 7); + matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8")); + matchBuilder.setNwDst(new Ipv4Address("16.16.16.16")); + matchBuilder.setTpSrc(6653); + matchBuilder.setTpDst(6633); + builder.setMatchV10(matchBuilder.build()); + byte[] cookie = new byte[]{0x00, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01}; + builder.setCookie(new BigInteger(cookie)); + builder.setCommand(FlowModCommand.forValue(0)); + builder.setIdleTimeout(12); + builder.setHardTimeout(16); + builder.setPriority(1); + builder.setBufferId(2L); + builder.setOutPort(new PortNumber(4422L)); + builder.setFlagsV10(new FlowModFlagsV10(true, false, true)); + List actions = new ArrayList<>(); + ActionsListBuilder actionsListBuilder = new ActionsListBuilder(); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetNwDst.class); + IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder(); + ipBuilder.setIpAddress(new Ipv4Address("2.2.2.2")); + actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build()); + actionsListBuilder.setAction(actionBuilder.build()); + actions.add(actionsListBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetTpSrc.class); + PortActionBuilder portBuilder = new PortActionBuilder(); + portBuilder.setPort(new PortNumber(42L)); + actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); + actionsListBuilder.setAction(actionBuilder.build()); + actions.add(actionsListBuilder.build()); + builder.setActionsList(actions); + FlowModInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10FlowModInputMessageFactory factory = OF10FlowModInputMessageFactory.getInstance(); + factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + + BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt()); + Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort()); + byte[] dlSrc = new byte[6]; + out.readBytes(dlSrc); + Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc)); + byte[] dlDst = new byte[6]; + out.readBytes(dlDst); + Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst)); + Assert.assertEquals("Wrong dlVlan", 18, out.readUnsignedShort()); + Assert.assertEquals("Wrong dlVlanPcp", 5, out.readUnsignedByte()); + out.skipBytes(1); + Assert.assertEquals("Wrong dlType", 42, out.readUnsignedShort()); + Assert.assertEquals("Wrong nwTos", 4, out.readUnsignedByte()); + Assert.assertEquals("Wrong nwProto", 7, out.readUnsignedByte()); + out.skipBytes(2); + Assert.assertEquals("Wrong nwSrc", 134744072, out.readUnsignedInt()); + Assert.assertEquals("Wrong nwDst", 269488144, out.readUnsignedInt()); + Assert.assertEquals("Wrong tpSrc", 6653, out.readUnsignedShort()); + Assert.assertEquals("Wrong tpDst", 6633, out.readUnsignedShort()); + byte[] cookieRead = new byte[8]; + out.readBytes(cookieRead); + Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead); + Assert.assertEquals("Wrong command", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong idleTimeOut", 12, out.readUnsignedShort()); + Assert.assertEquals("Wrong hardTimeOut", 16, out.readUnsignedShort()); + Assert.assertEquals("Wrong priority", 1, out.readUnsignedShort()); + Assert.assertEquals("Wrong bufferId", 2, out.readUnsignedInt()); + Assert.assertEquals("Wrong outPort", 4422, out.readUnsignedShort()); + Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort()); + Assert.assertEquals("Wrong action - type", 7, out.readUnsignedShort()); + Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort()); + Assert.assertEquals("Wrong flags", 33686018, out.readUnsignedInt()); + Assert.assertEquals("Wrong action - type", 9, out.readUnsignedShort()); + Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort()); + Assert.assertEquals("Wrong flags", 42, out.readUnsignedShort()); + out.skipBytes(2); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactoryTest.java index 8a715aa7..7575be11 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10HelloInputMessageFactoryTest.java @@ -1,36 +1,43 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class OF10HelloInputMessageFactoryTest { - - /** - * Testing of {@link OF10HelloInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testWithoutElementsSet() throws Exception { - HelloInputBuilder hib = new HelloInputBuilder(); - BufferHelper.setupHeader(hib, EncodeConstants.OF10_VERSION_ID); - HelloInput hi = hib.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10HelloInputMessageFactory himf = OF10HelloInputMessageFactory.getInstance(); - himf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, hi); - - BufferHelper.checkHeaderV10(out, (byte) 0, 8); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10HelloInputMessageFactoryTest { + + /** + * Testing of {@link OF10HelloInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testWithoutElementsSet() throws Exception { + HelloInputBuilder hib = new HelloInputBuilder(); + BufferHelper.setupHeader(hib, EncodeConstants.OF10_VERSION_ID); + HelloInput hi = hib.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10HelloInputMessageFactory himf = OF10HelloInputMessageFactory.getInstance(); + himf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, hi); + + BufferHelper.checkHeaderV10(out, (byte) 0, 8); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactoryTest.java index bc3fa472..899b34d1 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PacketOutInputMessageFactoryTest.java @@ -1,86 +1,93 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class OF10PacketOutInputMessageFactoryTest { - - /** - * Testing of {@link OF10PacketOutInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testPacketOutInputMessage() throws Exception { - PacketOutInputBuilder builder = new PacketOutInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - builder.setBufferId(256L); - builder.setInPort(new PortNumber(257L)); - List actions = new ArrayList<>(); - ActionsListBuilder actionsListBuilder = new ActionsListBuilder(); - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(Output.class); - PortActionBuilder portBuilder = new PortActionBuilder(); - portBuilder.setPort(new PortNumber((long) 42)); - actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); - MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); - maxLen.setMaxLength(50); - actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); - actionsListBuilder.setAction(actionBuilder.build()); - actions.add(actionsListBuilder.build()); - actionsListBuilder = new ActionsListBuilder(); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(StripVlan.class); - actionsListBuilder.setAction(actionBuilder.build()); - builder.setActionsList(actions); - actions.add(actionsListBuilder.build()); - builder.setActionsList(actions); - builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14")); - PacketOutInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10PacketOutInputMessageFactory factory = OF10PacketOutInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV10(out, (byte) 13, 48); - Assert.assertEquals("Wrong BufferId", 256, out.readUnsignedInt()); - Assert.assertEquals("Wrong PortNumber", 257, out.readUnsignedShort()); - Assert.assertEquals("Wrong actions length", 16, out.readUnsignedShort()); - Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong port", 42, out.readUnsignedShort()); - Assert.assertEquals("Wrong maxlength", 50, out.readUnsignedShort()); - Assert.assertEquals("Wrong action type", 3, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); - out.skipBytes(4); - Assert.assertArrayEquals("Wrong data", message.getData(), out.readBytes(out.readableBytes()).array()); - Assert.assertTrue("Unread data", out.readableBytes() == 0); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10PacketOutInputMessageFactoryTest { + + /** + * Testing of {@link OF10PacketOutInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testPacketOutInputMessage() throws Exception { + PacketOutInputBuilder builder = new PacketOutInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); + builder.setBufferId(256L); + builder.setInPort(new PortNumber(257L)); + List actions = new ArrayList<>(); + ActionsListBuilder actionsListBuilder = new ActionsListBuilder(); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Output.class); + PortActionBuilder portBuilder = new PortActionBuilder(); + portBuilder.setPort(new PortNumber((long) 42)); + actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); + MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); + maxLen.setMaxLength(50); + actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); + actionsListBuilder.setAction(actionBuilder.build()); + actions.add(actionsListBuilder.build()); + actionsListBuilder = new ActionsListBuilder(); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(StripVlan.class); + actionsListBuilder.setAction(actionBuilder.build()); + builder.setActionsList(actions); + actions.add(actionsListBuilder.build()); + builder.setActionsList(actions); + builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14")); + PacketOutInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10PacketOutInputMessageFactory factory = OF10PacketOutInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV10(out, (byte) 13, 48); + Assert.assertEquals("Wrong BufferId", 256, out.readUnsignedInt()); + Assert.assertEquals("Wrong PortNumber", 257, out.readUnsignedShort()); + Assert.assertEquals("Wrong actions length", 16, out.readUnsignedShort()); + Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); + Assert.assertEquals("Wrong port", 42, out.readUnsignedShort()); + Assert.assertEquals("Wrong maxlength", 50, out.readUnsignedShort()); + Assert.assertEquals("Wrong action type", 3, out.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); + out.skipBytes(4); + Assert.assertArrayEquals("Wrong data", message.getData(), out.readBytes(out.readableBytes()).array()); + Assert.assertTrue("Unread data", out.readableBytes() == 0); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactoryTest.java index 407c2fef..c49b7b26 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactoryTest.java @@ -1,57 +1,64 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import junit.framework.Assert; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class OF10PortModInputMessageFactoryTest { - - /** - * Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testPortModInput() throws Exception { - PortModInputBuilder builder = new PortModInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - builder.setPortNo(new PortNumber(6633L)); - builder.setHwAddress(new MacAddress("08:00:27:00:B0:EB")); - builder.setConfigV10(new PortConfigV10(true, false, false, true, false, false, true)); - builder.setMaskV10(new PortConfigV10(false, true, true, false, false, true, false)); - builder.setAdvertiseV10(new PortFeaturesV10(true, true, false, false, false, false, - false, true, true, false, false, false)); - PortModInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10PortModInputMessageFactory factory = OF10PortModInputMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); - - BufferHelper.checkHeaderV10(out, (byte) 15, 32); - Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedShort()); - byte[] address = new byte[6]; - out.readBytes(address); - Assert.assertEquals("Wrong MacAddress", message.getHwAddress(), - new MacAddress(ByteBufUtils.macAddressToString(address))); - Assert.assertEquals("Wrong config", 21, out.readUnsignedInt()); - Assert.assertEquals("Wrong mask", 98, out.readUnsignedInt()); - Assert.assertEquals("Wrong advertise", 652, out.readUnsignedInt()); - out.skipBytes(4); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import junit.framework.Assert; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10PortModInputMessageFactoryTest { + + /** + * Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testPortModInput() throws Exception { + PortModInputBuilder builder = new PortModInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); + builder.setPortNo(new PortNumber(6633L)); + builder.setHwAddress(new MacAddress("08:00:27:00:B0:EB")); + builder.setConfigV10(new PortConfigV10(true, false, false, true, false, false, true)); + builder.setMaskV10(new PortConfigV10(false, true, true, false, false, true, false)); + builder.setAdvertiseV10(new PortFeaturesV10(true, true, false, false, false, false, + false, true, true, false, false, false)); + PortModInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10PortModInputMessageFactory factory = OF10PortModInputMessageFactory.getInstance(); + factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + + BufferHelper.checkHeaderV10(out, (byte) 15, 32); + Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedShort()); + byte[] address = new byte[6]; + out.readBytes(address); + Assert.assertEquals("Wrong MacAddress", message.getHwAddress(), + new MacAddress(ByteBufUtils.macAddressToString(address))); + Assert.assertEquals("Wrong config", 21, out.readUnsignedInt()); + Assert.assertEquals("Wrong mask", 98, out.readUnsignedInt()); + Assert.assertEquals("Wrong advertise", 652, out.readUnsignedInt()); + out.skipBytes(4); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactoryTest.java index af6d2a90..5b78232e 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10QueueGetConfigInputMessageFactoryTest.java @@ -1,41 +1,48 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import junit.framework.Assert; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class OF10QueueGetConfigInputMessageFactoryTest { - - /** - * Testing of {@link OF10QueueGetConfigInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void test() throws Exception { - GetQueueConfigInputBuilder builder = new GetQueueConfigInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - builder.setPort(new PortNumber(6653L)); - GetQueueConfigInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10QueueGetConfigInputMessageFactory factory = OF10QueueGetConfigInputMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); - - BufferHelper.checkHeaderV10(out, (byte) 20, 12); - Assert.assertEquals("Wrong port", 6653L, out.readUnsignedShort()); - out.skipBytes(2); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import junit.framework.Assert; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10QueueGetConfigInputMessageFactoryTest { + + /** + * Testing of {@link OF10QueueGetConfigInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() throws Exception { + GetQueueConfigInputBuilder builder = new GetQueueConfigInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); + builder.setPort(new PortNumber(6653L)); + GetQueueConfigInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10QueueGetConfigInputMessageFactory factory = OF10QueueGetConfigInputMessageFactory.getInstance(); + factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + + BufferHelper.checkHeaderV10(out, (byte) 20, 12); + Assert.assertEquals("Wrong port", 6653L, out.readUnsignedShort()); + out.skipBytes(2); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java index 360b33e2..540801a9 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10VendorInputMessageFactoryTest.java @@ -1,43 +1,50 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; - -/** - * @author michal.polkorab - * - */ -public class OF10VendorInputMessageFactoryTest { - - /** - * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void test() throws Exception { - ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - builder.setExperimenter(0x0001020304L); - builder.setData(new byte[] {0x01, 0x02, 0x03, 0x04}); - ExperimenterInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - OF10VendorInputMessageFactory factory = OF10VendorInputMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); - - BufferHelper.checkHeaderV10(out, (byte) 4, factory.computeLength(message)); - Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); - byte[] data = new byte[4]; - out.readBytes(data); - Assert.assertArrayEquals("Wrong data", message.getData(), data); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; + +/** + * @author michal.polkorab + * + */ +public class OF10VendorInputMessageFactoryTest { + + /** + * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void test() throws Exception { + ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); + builder.setExperimenter(0x0001020304L); + builder.setData(new byte[] {0x01, 0x02, 0x03, 0x04}); + ExperimenterInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + OF10VendorInputMessageFactory factory = OF10VendorInputMessageFactory.getInstance(); + factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + + BufferHelper.checkHeaderV10(out, (byte) 4, factory.computeLength(message)); + Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); + byte[] data = new byte[4]; + out.readBytes(data); + Assert.assertArrayEquals("Wrong data", message.getData(), data); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java index a975c4a9..d845336d 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactoryTest.java @@ -1,82 +1,89 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder; - -/** - * @author timotej.kubas - * - */ -public class PacketOutInputMessageFactoryTest { - private static final byte MESSAGE_TYPE = 13; - private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6; - private static final int PADDING_IN_ACTION_HEADER = 4; - - /** - * Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testPacketOutInputMessage() throws Exception { - PacketOutInputBuilder builder = new PacketOutInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setBufferId(256L); - builder.setInPort(new PortNumber(256L)); - List actions = new ArrayList<>(); - ActionsListBuilder actionsListBuilder = new ActionsListBuilder(); - ActionBuilder actionBuilder = new ActionBuilder(); - actionBuilder.setType(PushVlan.class); - EthertypeActionBuilder ethertypeBuilder = new EthertypeActionBuilder(); - ethertypeBuilder.setEthertype(new EtherType(25)); - actionBuilder.addAugmentation(EthertypeAction.class, ethertypeBuilder.build()); - actionsListBuilder.setAction(actionBuilder.build()); - actions.add(actionsListBuilder.build()); - actionBuilder = new ActionBuilder(); - actionBuilder.setType(PopVlan.class); - actionsListBuilder.setAction(actionBuilder.build()); - actions.add(actionsListBuilder.build()); - builder.setActionsList(actions); - builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14")); - PacketOutInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - PacketOutInputMessageFactory factory = PacketOutInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 56); - Assert.assertEquals("Wrong BufferId", message.getBufferId().longValue(), out.readUnsignedInt()); - Assert.assertEquals("Wrong PortNumber", message.getInPort().getValue().longValue(), out.readUnsignedInt()); - Assert.assertEquals("Wrong ActionsLength", 16, out.readUnsignedShort()); - out.skipBytes(PADDING_IN_PACKET_OUT_MESSAGE); - Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong ethertype", 25, out.readUnsignedShort()); - out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - Assert.assertEquals("Wrong action type", 18, out.readUnsignedShort()); - Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); - out.skipBytes(PADDING_IN_ACTION_HEADER); - Assert.assertArrayEquals("Wrong data", message.getData(), out.readBytes(out.readableBytes()).array()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder; + +/** + * @author timotej.kubas + * + */ +public class PacketOutInputMessageFactoryTest { + private static final byte MESSAGE_TYPE = 13; + private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6; + private static final int PADDING_IN_ACTION_HEADER = 4; + + /** + * Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testPacketOutInputMessage() throws Exception { + PacketOutInputBuilder builder = new PacketOutInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setBufferId(256L); + builder.setInPort(new PortNumber(256L)); + List actions = new ArrayList<>(); + ActionsListBuilder actionsListBuilder = new ActionsListBuilder(); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(PushVlan.class); + EthertypeActionBuilder ethertypeBuilder = new EthertypeActionBuilder(); + ethertypeBuilder.setEthertype(new EtherType(25)); + actionBuilder.addAugmentation(EthertypeAction.class, ethertypeBuilder.build()); + actionsListBuilder.setAction(actionBuilder.build()); + actions.add(actionsListBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(PopVlan.class); + actionsListBuilder.setAction(actionBuilder.build()); + actions.add(actionsListBuilder.build()); + builder.setActionsList(actions); + builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14")); + PacketOutInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + PacketOutInputMessageFactory factory = PacketOutInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 56); + Assert.assertEquals("Wrong BufferId", message.getBufferId().longValue(), out.readUnsignedInt()); + Assert.assertEquals("Wrong PortNumber", message.getInPort().getValue().longValue(), out.readUnsignedInt()); + Assert.assertEquals("Wrong ActionsLength", 16, out.readUnsignedShort()); + out.skipBytes(PADDING_IN_PACKET_OUT_MESSAGE); + Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); + Assert.assertEquals("Wrong ethertype", 25, out.readUnsignedShort()); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + Assert.assertEquals("Wrong action type", 18, out.readUnsignedShort()); + Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); + out.skipBytes(PADDING_IN_ACTION_HEADER); + Assert.assertArrayEquals("Wrong data", message.getData(), out.readBytes(out.readableBytes()).array()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java index b5469e22..f55be957 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java @@ -1,96 +1,103 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import junit.framework.Assert; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class PortModInputMessageFactoryTest { - private static final byte MESSAGE_TYPE = 16; - private static final byte PADDING_IN_PORT_MOD_MESSAGE_01 = 4; - private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2; - private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4; - private static final int MESSAGE_LENGTH = 40; - - /** - * Testing of {@link PortModInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testPortModInput() throws Exception { - PortModInputBuilder builder = new PortModInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setPortNo(new PortNumber(9L)); - builder.setHwAddress(new MacAddress("08:00:27:00:B0:EB")); - builder.setConfig(new PortConfig(true, false, true, false)); - builder.setMask(new PortConfig(false, true, false, true)); - builder.setAdvertise(new PortFeatures(true, false, false, false, - false, false, false, true, - false, false, false, false, - false, false, false, false)); - PortModInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - PortModInputMessageFactory factory = PortModInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); - Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedInt()); - out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_01); - byte[] address = new byte[6]; - out.readBytes(address); - Assert.assertEquals("Wrong MacAddress", message.getHwAddress().getValue(), - new MacAddress(ByteBufUtils.macAddressToString(address)).getValue()); - out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_02); - Assert.assertEquals("Wrong config", message.getConfig(), createPortConfig(out.readInt())); - Assert.assertEquals("Wrong mask", message.getMask(), createPortConfig(out.readInt())); - Assert.assertEquals("Wrong advertise", message.getAdvertise(), createPortFeatures(out.readInt())); - out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_03); - } - - private static PortConfig createPortConfig(long input){ - final Boolean _portDown = ((input) & (1<<0)) > 0; - final Boolean _noRecv = ((input) & (1<<2)) > 0; - final Boolean _noFwd = ((input) & (1<<5)) > 0; - final Boolean _noPacketIn = ((input) & (1<<6)) > 0; - return new PortConfig(_noFwd, _noPacketIn, _noRecv, _portDown); - } - - private static PortFeatures createPortFeatures(long input){ - final Boolean _10mbHd = ((input) & (1<<0)) > 0; - final Boolean _10mbFd = ((input) & (1<<1)) > 0; - final Boolean _100mbHd = ((input) & (1<<2)) > 0; - final Boolean _100mbFd = ((input) & (1<<3)) > 0; - final Boolean _1gbHd = ((input) & (1<<4)) > 0; - final Boolean _1gbFd = ((input) & (1<<5)) > 0; - final Boolean _10gbFd = ((input) & (1<<6)) > 0; - final Boolean _40gbFd = ((input) & (1<<7)) > 0; - final Boolean _100gbFd = ((input) & (1<<8)) > 0; - final Boolean _1tbFd = ((input) & (1<<9)) > 0; - final Boolean _other = ((input) & (1<<10)) > 0; - final Boolean _copper = ((input) & (1<<11)) > 0; - final Boolean _fiber = ((input) & (1<<12)) > 0; - final Boolean _autoneg = ((input) & (1<<13)) > 0; - final Boolean _pause = ((input) & (1<<14)) > 0; - final Boolean _pauseAsym = ((input) & (1<<15)) > 0; - return new PortFeatures(_100gbFd, _100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, - _1gbFd, _1gbHd, _1tbFd, _40gbFd, _autoneg, _copper, _fiber, _other, _pause, _pauseAsym); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import junit.framework.Assert; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class PortModInputMessageFactoryTest { + private static final byte MESSAGE_TYPE = 16; + private static final byte PADDING_IN_PORT_MOD_MESSAGE_01 = 4; + private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2; + private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4; + private static final int MESSAGE_LENGTH = 40; + + /** + * Testing of {@link PortModInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testPortModInput() throws Exception { + PortModInputBuilder builder = new PortModInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setPortNo(new PortNumber(9L)); + builder.setHwAddress(new MacAddress("08:00:27:00:B0:EB")); + builder.setConfig(new PortConfig(true, false, true, false)); + builder.setMask(new PortConfig(false, true, false, true)); + builder.setAdvertise(new PortFeatures(true, false, false, false, + false, false, false, true, + false, false, false, false, + false, false, false, false)); + PortModInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + PortModInputMessageFactory factory = PortModInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); + Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedInt()); + out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_01); + byte[] address = new byte[6]; + out.readBytes(address); + Assert.assertEquals("Wrong MacAddress", message.getHwAddress().getValue(), + new MacAddress(ByteBufUtils.macAddressToString(address)).getValue()); + out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_02); + Assert.assertEquals("Wrong config", message.getConfig(), createPortConfig(out.readInt())); + Assert.assertEquals("Wrong mask", message.getMask(), createPortConfig(out.readInt())); + Assert.assertEquals("Wrong advertise", message.getAdvertise(), createPortFeatures(out.readInt())); + out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_03); + } + + private static PortConfig createPortConfig(long input){ + final Boolean _portDown = ((input) & (1<<0)) > 0; + final Boolean _noRecv = ((input) & (1<<2)) > 0; + final Boolean _noFwd = ((input) & (1<<5)) > 0; + final Boolean _noPacketIn = ((input) & (1<<6)) > 0; + return new PortConfig(_noFwd, _noPacketIn, _noRecv, _portDown); + } + + private static PortFeatures createPortFeatures(long input){ + final Boolean _10mbHd = ((input) & (1<<0)) > 0; + final Boolean _10mbFd = ((input) & (1<<1)) > 0; + final Boolean _100mbHd = ((input) & (1<<2)) > 0; + final Boolean _100mbFd = ((input) & (1<<3)) > 0; + final Boolean _1gbHd = ((input) & (1<<4)) > 0; + final Boolean _1gbFd = ((input) & (1<<5)) > 0; + final Boolean _10gbFd = ((input) & (1<<6)) > 0; + final Boolean _40gbFd = ((input) & (1<<7)) > 0; + final Boolean _100gbFd = ((input) & (1<<8)) > 0; + final Boolean _1tbFd = ((input) & (1<<9)) > 0; + final Boolean _other = ((input) & (1<<10)) > 0; + final Boolean _copper = ((input) & (1<<11)) > 0; + final Boolean _fiber = ((input) & (1<<12)) > 0; + final Boolean _autoneg = ((input) & (1<<13)) > 0; + final Boolean _pause = ((input) & (1<<14)) > 0; + final Boolean _pauseAsym = ((input) & (1<<15)) > 0; + return new PortFeatures(_100gbFd, _100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, + _1gbFd, _1gbHd, _1tbFd, _40gbFd, _autoneg, _copper, _fiber, _other, _pause, _pauseAsym); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactoryTest.java index 27274aad..9baa8553 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactoryTest.java @@ -1,50 +1,57 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.math.BigInteger; - -import junit.framework.Assert; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class RoleRequestInputMessageFactoryTest { - private static final byte MESSAGE_TYPE = 24; - private static final int MESSAGE_LENGTH = 24; - private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4; - - /** - * Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testRoleRequestInputMessage() throws Exception { - RoleRequestInputBuilder builder = new RoleRequestInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setRole(ControllerRole.forValue(2)); - byte[] generationId = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; - builder.setGenerationId(new BigInteger(generationId)); - RoleRequestInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - RoleRequestInputMessageFactory factory = RoleRequestInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); - Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue()); - out.skipBytes(PADDING_IN_ROLE_REQUEST_MESSAGE); - Assert.assertEquals("Wrong generation ID", message.getGenerationId().longValue(), out.readLong()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.math.BigInteger; + +import junit.framework.Assert; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class RoleRequestInputMessageFactoryTest { + private static final byte MESSAGE_TYPE = 24; + private static final int MESSAGE_LENGTH = 24; + private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4; + + /** + * Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testRoleRequestInputMessage() throws Exception { + RoleRequestInputBuilder builder = new RoleRequestInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setRole(ControllerRole.forValue(2)); + byte[] generationId = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; + builder.setGenerationId(new BigInteger(generationId)); + RoleRequestInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + RoleRequestInputMessageFactory factory = RoleRequestInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); + Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue()); + out.skipBytes(PADDING_IN_ROLE_REQUEST_MESSAGE); + Assert.assertEquals("Wrong generation ID", message.getGenerationId().longValue(), out.readLong()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java index 217177cc..1de6dc12 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactoryTest.java @@ -1,123 +1,130 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class SetAsyncInputMessageFactoryTest { - private static final Logger LOGGER = LoggerFactory - .getLogger(SetAsyncInputMessageFactoryTest.class); - /** - * @throws Exception - * Testing of {@link SetAsyncInputMessageFactory} for correct translation from POJO - */ - @Test - public void testSetAsyncInputMessage() throws Exception { - SetAsyncInputBuilder builder = new SetAsyncInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setPacketInMask(createPacketInMask()); - builder.setPortStatusMask(createPortStatusMask()); - builder.setFlowRemovedMask(createFlowRemowedMask()); - SetAsyncInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - SetAsyncInputMessageFactory factory = SetAsyncInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(out)); - BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); - Assert.assertEquals("Wrong packetInMask", 5, out.readUnsignedInt()); - Assert.assertEquals("Wrong packetInMask", 7, out.readUnsignedInt()); - Assert.assertEquals("Wrong portStatusMask", 6, out.readUnsignedInt()); - Assert.assertEquals("Wrong portStatusMask", 0, out.readUnsignedInt()); - Assert.assertEquals("Wrong flowRemovedMask", 10, out.readUnsignedInt()); - Assert.assertEquals("Wrong flowRemovedMask", 5, out.readUnsignedInt()); - - } - - private static List createPacketInMask() { - List masks = new ArrayList<>(); - PacketInMaskBuilder builder; - // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER - builder = new PacketInMaskBuilder(); - List packetInReasonList = new ArrayList<>(); - packetInReasonList.add(PacketInReason.OFPRNOMATCH); - packetInReasonList.add(PacketInReason.OFPRINVALIDTTL); - builder.setMask(packetInReasonList); - masks.add(builder.build()); - // OFPCR_ROLE_SLAVE - builder = new PacketInMaskBuilder(); - packetInReasonList = new ArrayList<>(); - packetInReasonList.add(PacketInReason.OFPRNOMATCH); - packetInReasonList.add(PacketInReason.OFPRACTION); - packetInReasonList.add(PacketInReason.OFPRINVALIDTTL); - builder.setMask(packetInReasonList); - masks.add(builder.build()); - System.out.println(masks.size()); - return masks; - } - - private static List createPortStatusMask() { - List masks = new ArrayList<>(); - PortStatusMaskBuilder builder; - builder = new PortStatusMaskBuilder(); - // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER - List portReasonList = new ArrayList<>(); - portReasonList.add(PortReason.OFPPRDELETE); - portReasonList.add(PortReason.OFPPRMODIFY); - builder.setMask(portReasonList); - masks.add(builder.build()); - // OFPCR_ROLE_SLAVE - builder = new PortStatusMaskBuilder(); - portReasonList = new ArrayList<>(); - builder.setMask(portReasonList); - masks.add(builder.build()); - return masks; - } - - private static List createFlowRemowedMask() { - List masks = new ArrayList<>(); - FlowRemovedMaskBuilder builder; - // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER - builder = new FlowRemovedMaskBuilder(); - List flowRemovedReasonList = new ArrayList<>(); - flowRemovedReasonList.add(FlowRemovedReason.OFPRRHARDTIMEOUT); - flowRemovedReasonList.add(FlowRemovedReason.OFPRRGROUPDELETE); - builder.setMask(flowRemovedReasonList); - masks.add(builder.build()); - // OFPCR_ROLE_SLAVE - builder = new FlowRemovedMaskBuilder(); - flowRemovedReasonList = new ArrayList<>(); - flowRemovedReasonList.add(FlowRemovedReason.OFPRRIDLETIMEOUT); - flowRemovedReasonList.add(FlowRemovedReason.OFPRRDELETE); - builder.setMask(flowRemovedReasonList); - masks.add(builder.build()); - return masks; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMaskBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class SetAsyncInputMessageFactoryTest { + private static final Logger LOGGER = LoggerFactory + .getLogger(SetAsyncInputMessageFactoryTest.class); + /** + * @throws Exception + * Testing of {@link SetAsyncInputMessageFactory} for correct translation from POJO + */ + @Test + public void testSetAsyncInputMessage() throws Exception { + SetAsyncInputBuilder builder = new SetAsyncInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setPacketInMask(createPacketInMask()); + builder.setPortStatusMask(createPortStatusMask()); + builder.setFlowRemovedMask(createFlowRemowedMask()); + SetAsyncInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + SetAsyncInputMessageFactory factory = SetAsyncInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(out)); + BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); + Assert.assertEquals("Wrong packetInMask", 5, out.readUnsignedInt()); + Assert.assertEquals("Wrong packetInMask", 7, out.readUnsignedInt()); + Assert.assertEquals("Wrong portStatusMask", 6, out.readUnsignedInt()); + Assert.assertEquals("Wrong portStatusMask", 0, out.readUnsignedInt()); + Assert.assertEquals("Wrong flowRemovedMask", 10, out.readUnsignedInt()); + Assert.assertEquals("Wrong flowRemovedMask", 5, out.readUnsignedInt()); + + } + + private static List createPacketInMask() { + List masks = new ArrayList<>(); + PacketInMaskBuilder builder; + // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER + builder = new PacketInMaskBuilder(); + List packetInReasonList = new ArrayList<>(); + packetInReasonList.add(PacketInReason.OFPRNOMATCH); + packetInReasonList.add(PacketInReason.OFPRINVALIDTTL); + builder.setMask(packetInReasonList); + masks.add(builder.build()); + // OFPCR_ROLE_SLAVE + builder = new PacketInMaskBuilder(); + packetInReasonList = new ArrayList<>(); + packetInReasonList.add(PacketInReason.OFPRNOMATCH); + packetInReasonList.add(PacketInReason.OFPRACTION); + packetInReasonList.add(PacketInReason.OFPRINVALIDTTL); + builder.setMask(packetInReasonList); + masks.add(builder.build()); + System.out.println(masks.size()); + return masks; + } + + private static List createPortStatusMask() { + List masks = new ArrayList<>(); + PortStatusMaskBuilder builder; + builder = new PortStatusMaskBuilder(); + // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER + List portReasonList = new ArrayList<>(); + portReasonList.add(PortReason.OFPPRDELETE); + portReasonList.add(PortReason.OFPPRMODIFY); + builder.setMask(portReasonList); + masks.add(builder.build()); + // OFPCR_ROLE_SLAVE + builder = new PortStatusMaskBuilder(); + portReasonList = new ArrayList<>(); + builder.setMask(portReasonList); + masks.add(builder.build()); + return masks; + } + + private static List createFlowRemowedMask() { + List masks = new ArrayList<>(); + FlowRemovedMaskBuilder builder; + // OFPCR_ROLE_EQUAL or OFPCR_ROLE_MASTER + builder = new FlowRemovedMaskBuilder(); + List flowRemovedReasonList = new ArrayList<>(); + flowRemovedReasonList.add(FlowRemovedReason.OFPRRHARDTIMEOUT); + flowRemovedReasonList.add(FlowRemovedReason.OFPRRGROUPDELETE); + builder.setMask(flowRemovedReasonList); + masks.add(builder.build()); + // OFPCR_ROLE_SLAVE + builder = new FlowRemovedMaskBuilder(); + flowRemovedReasonList = new ArrayList<>(); + flowRemovedReasonList.add(FlowRemovedReason.OFPRRIDLETIMEOUT); + flowRemovedReasonList.add(FlowRemovedReason.OFPRRDELETE); + builder.setMask(flowRemovedReasonList); + masks.add(builder.build()); + return masks; + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactoryTest.java index 5f54df8a..2d5de55b 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactoryTest.java @@ -1,66 +1,73 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class SetConfigMessageFactoryTest { - private static final byte MESSAGE_TYPE = 9; - private static final int MESSAGE_LENGTH = 12; - - /** - * Testing of {@link SetConfigMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testSetConfigMessageV13() throws Exception { - SetConfigInputBuilder builder = new SetConfigInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - SwitchConfigFlag flag = SwitchConfigFlag.FRAGNORMAL; - builder.setFlags(flag); - builder.setMissSendLen(10); - SetConfigInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); - - BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); - Assert.assertEquals("Wrong flags", SwitchConfigFlag.FRAGNORMAL.getIntValue(), out.readUnsignedShort()); - Assert.assertEquals("Wrong missSendLen", 10, out.readUnsignedShort()); - } - - /** - * Testing of {@link SetConfigMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testSetConfigMessageV10() throws Exception { - SetConfigInputBuilder builder = new SetConfigInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); - SwitchConfigFlag flag = SwitchConfigFlag.OFPCFRAGDROP; - builder.setFlags(flag); - builder.setMissSendLen(85); - SetConfigInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance(); - factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); - - BufferHelper.checkHeaderV10(out, MESSAGE_TYPE, MESSAGE_LENGTH); - Assert.assertEquals("Wrong flags", SwitchConfigFlag.OFPCFRAGDROP.getIntValue(), out.readUnsignedShort()); - Assert.assertEquals("Wrong missSendLen", 85, out.readUnsignedShort()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class SetConfigMessageFactoryTest { + private static final byte MESSAGE_TYPE = 9; + private static final int MESSAGE_LENGTH = 12; + + /** + * Testing of {@link SetConfigMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testSetConfigMessageV13() throws Exception { + SetConfigInputBuilder builder = new SetConfigInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + SwitchConfigFlag flag = SwitchConfigFlag.FRAGNORMAL; + builder.setFlags(flag); + builder.setMissSendLen(10); + SetConfigInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance(); + factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + + BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); + Assert.assertEquals("Wrong flags", SwitchConfigFlag.FRAGNORMAL.getIntValue(), out.readUnsignedShort()); + Assert.assertEquals("Wrong missSendLen", 10, out.readUnsignedShort()); + } + + /** + * Testing of {@link SetConfigMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testSetConfigMessageV10() throws Exception { + SetConfigInputBuilder builder = new SetConfigInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); + SwitchConfigFlag flag = SwitchConfigFlag.OFPCFRAGDROP; + builder.setFlags(flag); + builder.setMissSendLen(85); + SetConfigInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance(); + factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); + + BufferHelper.checkHeaderV10(out, MESSAGE_TYPE, MESSAGE_LENGTH); + Assert.assertEquals("Wrong flags", SwitchConfigFlag.OFPCFRAGDROP.getIntValue(), out.readUnsignedShort()); + Assert.assertEquals("Wrong missSendLen", 85, out.readUnsignedShort()); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java index e0e3d78c..1daa581a 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java @@ -1,47 +1,54 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import junit.framework.Assert; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInputBuilder; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class TableModInputMessageFactoryTest { - private static final byte MESSAGE_TYPE = 17; - private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3; - - /** - * Testing of {@link TableModInputMessageFactory} for correct translation from POJO - * @throws Exception - */ - @Test - public void testTableModInput() throws Exception { - TableModInputBuilder builder = new TableModInputBuilder(); - BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); - builder.setTableId(new TableId(9L)); - builder.setConfig(new TableConfig(true)); - TableModInput message = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - TableModInputMessageFactory factory = TableModInputMessageFactory.getInstance(); - factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); - - BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16); - Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readUnsignedByte()); - out.skipBytes(PADDING_IN_TABLE_MOD_MESSAGE); - Assert.assertEquals("Wrong TableConfig", 8, out.readUnsignedInt()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.factories; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import junit.framework.Assert; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInputBuilder; + +/** + * @author timotej.kubas + * @author michal.polkorab + */ +public class TableModInputMessageFactoryTest { + private static final byte MESSAGE_TYPE = 17; + private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3; + + /** + * Testing of {@link TableModInputMessageFactory} for correct translation from POJO + * @throws Exception + */ + @Test + public void testTableModInput() throws Exception { + TableModInputBuilder builder = new TableModInputBuilder(); + BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); + builder.setTableId(new TableId(9L)); + builder.setConfig(new TableConfig(true)); + TableModInput message = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + TableModInputMessageFactory factory = TableModInputMessageFactory.getInstance(); + factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); + + BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16); + Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readUnsignedByte()); + out.skipBytes(PADDING_IN_TABLE_MOD_MESSAGE); + Assert.assertEquals("Wrong TableConfig", 8, out.readUnsignedInt()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java index aac10dab..787c1d7e 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java @@ -1,162 +1,169 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.junit.Assert; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; -import org.opendaylight.yangtools.yang.binding.DataObject; - -/** - * @author michal.polkorab - * - */ -public abstract class BufferHelper { - - /** - * - */ - public static final Long DEFAULT_XID = 0x01020304L; - private static final byte[] XID = new byte[] { 0x01, 0x02, 0x03, 0x04 }; - - /** - * @param payload - * @return ByteBuf filled with OpenFlow protocol message without first 4 - * bytes - */ - public static ByteBuf buildBuffer(byte[] payload) { - ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer(); - bb.writeBytes(XID); - bb.writeBytes(payload); - return bb; - } - - /** - * @param payload String in hex format - * @return ByteBuf filled with OpenFlow protocol message without first 4 - * bytes - */ - public static ByteBuf buildBuffer(String payload) { - return buildBuffer(ByteBufUtils.hexStringToBytes(payload)); - } - - /** - * @return ByteBuf filled with OpenFlow protocol header message without first 4 - * bytes - */ - public static ByteBuf buildBuffer() { - ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer(); - bb.writeBytes(XID); - bb.writeBytes(new byte[0]); - return bb; - } - - /** - * Use version 1.3 for encoded message - * @param input ByteBuf to be checked for correct OpenFlow Protocol header - * @param msgType type of received message - * @param length expected length of message in header - */ - public static void checkHeaderV13(ByteBuf input, byte msgType, int length) { - checkHeader(input, msgType, length, (short) EncodeConstants.OF13_VERSION_ID); - } - - /** - * Use version 1.0 for encoded message - * @param input ByteBuf to be checked for correct OpenFlow Protocol header - * @param msgType type of received message - * @param length expected length of message in header - */ - public static void checkHeaderV10(ByteBuf input, byte msgType, int length) { - checkHeader(input, msgType, length, (short) EncodeConstants.OF10_VERSION_ID); - } - - private static void checkHeader(ByteBuf input, byte msgType, int length, Short version) { - Assert.assertEquals("Wrong version", version, Short.valueOf(input.readByte())); - Assert.assertEquals("Wrong type", msgType, input.readByte()); - Assert.assertEquals("Wrong length", length, input.readUnsignedShort()); - Assert.assertEquals("Wrong Xid", DEFAULT_XID, Long.valueOf(input.readUnsignedInt())); - } - - - /** - * @param ofHeader OpenFlow protocol header - */ - public static void checkHeaderV13(OfHeader ofHeader) { - checkHeader(ofHeader, (short) EncodeConstants.OF13_VERSION_ID); - } - - /** - * @param ofHeader OpenFlow protocol header - */ - public static void checkHeaderV10(OfHeader ofHeader) { - checkHeader(ofHeader, (short) EncodeConstants.OF10_VERSION_ID); - } - - private static void checkHeader(OfHeader ofHeader, Short version) { - Assert.assertEquals("Wrong version", version, ofHeader.getVersion()); - Assert.assertEquals("Wrong Xid", DEFAULT_XID, ofHeader.getXid()); - } - - /** - * @param builder - * @param version wire protocol number used - * @throws NoSuchMethodException - * @throws SecurityException - * @throws IllegalAccessException - * @throws IllegalArgumentException - * @throws InvocationTargetException - */ - public static void setupHeader(Object builder, int version) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Method m = builder.getClass().getMethod("setVersion", Short.class); - m.invoke(builder, (short) version); - Method m2 = builder.getClass().getMethod("setXid", Long.class); - m2.invoke(builder, BufferHelper.DEFAULT_XID); - } - - /** - * Use version 1.3 for decoding message - * @param decoder decoder instance - * @param bb data input buffer - * @return message decoded pojo - */ - public static E decodeV13(OFDeserializer decoder, ByteBuf bb) { - return bufferToMessage(decoder, EncodeConstants.OF13_VERSION_ID, bb); - } - - /** - * Use version 1.0 for decoding message - * @param decoder decoder instance - * @param bb data input buffer - * @return message decoded pojo - */ - public static E decodeV10(OFDeserializer decoder, ByteBuf bb) { - return bufferToMessage(decoder, EncodeConstants.OF10_VERSION_ID, bb); - } - - private static E bufferToMessage(OFDeserializer decoder, short version, ByteBuf bb) { - return decoder.bufferToMessage(bb, version); - } - - /** - * Use OF-protocol version 1.3 - * @param encoder serialize factory - * @param out buffer the result will be written into - * @param pojo input message - */ - public static void encodeV13(OFSerializer encoder, ByteBuf out, E pojo) { - messageToBuffer(encoder, out, pojo, HelloMessageFactoryTest.VERSION_YET_SUPPORTED); - } - - private static void messageToBuffer( - OFSerializer encoder, ByteBuf out, E pojo, Short version) { - encoder.messageToBuffer(version, out, pojo); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.junit.Assert; +import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest; +import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * @author michal.polkorab + * + */ +public abstract class BufferHelper { + + /** + * + */ + public static final Long DEFAULT_XID = 0x01020304L; + private static final byte[] XID = new byte[] { 0x01, 0x02, 0x03, 0x04 }; + + /** + * @param payload + * @return ByteBuf filled with OpenFlow protocol message without first 4 + * bytes + */ + public static ByteBuf buildBuffer(byte[] payload) { + ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer(); + bb.writeBytes(XID); + bb.writeBytes(payload); + return bb; + } + + /** + * @param payload String in hex format + * @return ByteBuf filled with OpenFlow protocol message without first 4 + * bytes + */ + public static ByteBuf buildBuffer(String payload) { + return buildBuffer(ByteBufUtils.hexStringToBytes(payload)); + } + + /** + * @return ByteBuf filled with OpenFlow protocol header message without first 4 + * bytes + */ + public static ByteBuf buildBuffer() { + ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer(); + bb.writeBytes(XID); + bb.writeBytes(new byte[0]); + return bb; + } + + /** + * Use version 1.3 for encoded message + * @param input ByteBuf to be checked for correct OpenFlow Protocol header + * @param msgType type of received message + * @param length expected length of message in header + */ + public static void checkHeaderV13(ByteBuf input, byte msgType, int length) { + checkHeader(input, msgType, length, (short) EncodeConstants.OF13_VERSION_ID); + } + + /** + * Use version 1.0 for encoded message + * @param input ByteBuf to be checked for correct OpenFlow Protocol header + * @param msgType type of received message + * @param length expected length of message in header + */ + public static void checkHeaderV10(ByteBuf input, byte msgType, int length) { + checkHeader(input, msgType, length, (short) EncodeConstants.OF10_VERSION_ID); + } + + private static void checkHeader(ByteBuf input, byte msgType, int length, Short version) { + Assert.assertEquals("Wrong version", version, Short.valueOf(input.readByte())); + Assert.assertEquals("Wrong type", msgType, input.readByte()); + Assert.assertEquals("Wrong length", length, input.readUnsignedShort()); + Assert.assertEquals("Wrong Xid", DEFAULT_XID, Long.valueOf(input.readUnsignedInt())); + } + + + /** + * @param ofHeader OpenFlow protocol header + */ + public static void checkHeaderV13(OfHeader ofHeader) { + checkHeader(ofHeader, (short) EncodeConstants.OF13_VERSION_ID); + } + + /** + * @param ofHeader OpenFlow protocol header + */ + public static void checkHeaderV10(OfHeader ofHeader) { + checkHeader(ofHeader, (short) EncodeConstants.OF10_VERSION_ID); + } + + private static void checkHeader(OfHeader ofHeader, Short version) { + Assert.assertEquals("Wrong version", version, ofHeader.getVersion()); + Assert.assertEquals("Wrong Xid", DEFAULT_XID, ofHeader.getXid()); + } + + /** + * @param builder + * @param version wire protocol number used + * @throws NoSuchMethodException + * @throws SecurityException + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws InvocationTargetException + */ + public static void setupHeader(Object builder, int version) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method m = builder.getClass().getMethod("setVersion", Short.class); + m.invoke(builder, (short) version); + Method m2 = builder.getClass().getMethod("setXid", Long.class); + m2.invoke(builder, BufferHelper.DEFAULT_XID); + } + + /** + * Use version 1.3 for decoding message + * @param decoder decoder instance + * @param bb data input buffer + * @return message decoded pojo + */ + public static E decodeV13(OFDeserializer decoder, ByteBuf bb) { + return bufferToMessage(decoder, EncodeConstants.OF13_VERSION_ID, bb); + } + + /** + * Use version 1.0 for decoding message + * @param decoder decoder instance + * @param bb data input buffer + * @return message decoded pojo + */ + public static E decodeV10(OFDeserializer decoder, ByteBuf bb) { + return bufferToMessage(decoder, EncodeConstants.OF10_VERSION_ID, bb); + } + + private static E bufferToMessage(OFDeserializer decoder, short version, ByteBuf bb) { + return decoder.bufferToMessage(bb, version); + } + + /** + * Use OF-protocol version 1.3 + * @param encoder serialize factory + * @param out buffer the result will be written into + * @param pojo input message + */ + public static void encodeV13(OFSerializer encoder, ByteBuf out, E pojo) { + messageToBuffer(encoder, out, pojo, HelloMessageFactoryTest.VERSION_YET_SUPPORTED); + } + + private static void messageToBuffer( + OFSerializer encoder, ByteBuf out, E pojo, Short version) { + encoder.messageToBuffer(version, out, pojo); + } +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java index 5596917a..ce4b5301 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java @@ -1,207 +1,214 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author michal.polkorab - * - */ -public class ByteBufUtilsTest { - - private byte[] expected = new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, (byte) 0xff}; - - /** - * Test of {@link ByteBufUtils#hexStringToBytes(String)} - */ - @Test - public void testHexStringToBytes() { - byte[] data = ByteBufUtils.hexStringToBytes("01 02 03 04 05 ff"); - - Assert.assertArrayEquals(expected, data); - } - - /** - * Test of {@link ByteBufUtils#hexStringToBytes(String, boolean)} - */ - @Test - public void testHexStringToBytes2() { - byte[] data = ByteBufUtils.hexStringToBytes("0102030405ff", false); - - Assert.assertArrayEquals(expected, data); - } - - /** - * Test of {@link ByteBufUtils#hexStringToByteBuf(String)} - */ - @Test - public void testHexStringToByteBuf() { - ByteBuf bb = ByteBufUtils.hexStringToByteBuf("01 02 03 04 05 ff"); - - Assert.assertArrayEquals(expected, byteBufToByteArray(bb)); - } - - /** - * Test of {@link ByteBufUtils#hexStringToByteBuf(String, ByteBuf)} - */ - @Test - public void testHexStringToGivenByteBuf() { - ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); - ByteBufUtils.hexStringToByteBuf("01 02 03 04 05 ff", buffer); - - Assert.assertArrayEquals(expected, byteBufToByteArray(buffer)); - } - - private static byte[] byteBufToByteArray(ByteBuf bb) { - byte[] result = new byte[bb.readableBytes()]; - bb.readBytes(result); - return result; - } - - /** - * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)} - */ - @Test - public void testFillBitmaskByEmptyMap() { - Map emptyMap = new HashMap<>(); - String expectedBinaryString = "00000000000000000000000000000000"; - String bitmaskInBinaryString = toBinaryString(emptyMap, 32); - - Assert.assertEquals("Not null string", expectedBinaryString, bitmaskInBinaryString); - } - - private static String toBinaryString(Map emptyMap, int length) { - String binaryString = Integer.toBinaryString(ByteBufUtils.fillBitMaskFromMap(emptyMap)); - return String.format("%"+length+"s", binaryString).replaceAll(" ", "0"); - } - - /** - * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)} - */ - @Test - public void testFillBitmaskByFullMap() { - Map fullMap = new HashMap<>(); - String expectedBinaryString = "11111111111111111111111111111111"; - String bitmaskValueInBinarySytring; - for(Integer i=0;i<=31;i++) { - fullMap.put(i, true); - } - bitmaskValueInBinarySytring = toBinaryString(fullMap, 32); - Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); - } - - /** - * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)} - */ - @Test - public void testFillBitmaskByZeroMap() { - Map zeroMap = new HashMap<>(); - String expectedBinaryString = "00000000000000000000000000000000"; - String bitmaskValueInBinarySytring; - for(Integer i=0;i<=31;i++) { - zeroMap.put(i, false); - } - bitmaskValueInBinarySytring = toBinaryString(zeroMap, 32); - Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); - } - - /** - * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)} - */ - @Test - public void testFillBitmaskByRandomSet() { - Map randomMap = new HashMap<>(); - String expectedBinaryString = "00000000000000000111100000000000"; - String bitmaskValueInBinarySytring; - Boolean mapValue; - for(Integer i=0;i<=31;i++) { - mapValue = false; - if(i>=11 && i<=14) { - mapValue = true; - } - randomMap.put(i, mapValue); - } - bitmaskValueInBinarySytring = toBinaryString(randomMap, 32); - Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); - } - - /** - * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} - */ - @Test - public void testFillBitmaskByEmptyList() { - List emptyList = new ArrayList<>(); - emptyList.add(null); - String expectedBinaryString = "00000000000000000000000000000000"; - String bitmaskInBinaryString = listToBinaryString(emptyList, 32); - - Assert.assertEquals("Not null string", expectedBinaryString, bitmaskInBinaryString); - } - - private static String listToBinaryString(List emptyList, int length) { - int[] bitMaskArray; - bitMaskArray = ByteBufUtils.fillBitMaskFromList(emptyList); - String binaryString = Integer.toBinaryString(bitMaskArray[0]); - return String.format("%"+length+"s", binaryString).replaceAll(" ", "0"); - } - - /** - * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} - */ - @Test - public void testFillBitmaskByFullList() { - List fullList = new ArrayList<>(); - String expectedBinaryString = "11111111111111111111111111111111"; - String bitmaskValueInBinarySytring; - for(Integer i=0;i<=31;i++) { - fullList.add(true); - } - bitmaskValueInBinarySytring = listToBinaryString(fullList, 32); - Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); - } - - /** - * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} - */ - @Test - public void testFillBitmaskByZeroList() { - List zeroList = new ArrayList<>(); - String expectedBinaryString = "00000000000000000000000000000000"; - String bitmaskValueInBinarySytring; - for(Integer i=0;i<=31;i++) { - zeroList.add(false); - } - bitmaskValueInBinarySytring = listToBinaryString(zeroList, 32); - Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); - } - - /** - * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} - */ - @Test - public void testFillBitmaskFromRandomList() { - List randomList = new ArrayList<>(); - String expectedBinaryString = "00000000000000000111100000000000"; - String bitmaskValueInBinarySytring; - Boolean listValue; - for(Integer i=0;i<=31;i++) { - listValue = false; - if(i>=11 && i<=14) { - listValue = true; - } - randomList.add(listValue); - } - bitmaskValueInBinarySytring = listToBinaryString(randomList, 32); - Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author michal.polkorab + * + */ +public class ByteBufUtilsTest { + + private byte[] expected = new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, (byte) 0xff}; + + /** + * Test of {@link ByteBufUtils#hexStringToBytes(String)} + */ + @Test + public void testHexStringToBytes() { + byte[] data = ByteBufUtils.hexStringToBytes("01 02 03 04 05 ff"); + + Assert.assertArrayEquals(expected, data); + } + + /** + * Test of {@link ByteBufUtils#hexStringToBytes(String, boolean)} + */ + @Test + public void testHexStringToBytes2() { + byte[] data = ByteBufUtils.hexStringToBytes("0102030405ff", false); + + Assert.assertArrayEquals(expected, data); + } + + /** + * Test of {@link ByteBufUtils#hexStringToByteBuf(String)} + */ + @Test + public void testHexStringToByteBuf() { + ByteBuf bb = ByteBufUtils.hexStringToByteBuf("01 02 03 04 05 ff"); + + Assert.assertArrayEquals(expected, byteBufToByteArray(bb)); + } + + /** + * Test of {@link ByteBufUtils#hexStringToByteBuf(String, ByteBuf)} + */ + @Test + public void testHexStringToGivenByteBuf() { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); + ByteBufUtils.hexStringToByteBuf("01 02 03 04 05 ff", buffer); + + Assert.assertArrayEquals(expected, byteBufToByteArray(buffer)); + } + + private static byte[] byteBufToByteArray(ByteBuf bb) { + byte[] result = new byte[bb.readableBytes()]; + bb.readBytes(result); + return result; + } + + /** + * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)} + */ + @Test + public void testFillBitmaskByEmptyMap() { + Map emptyMap = new HashMap<>(); + String expectedBinaryString = "00000000000000000000000000000000"; + String bitmaskInBinaryString = toBinaryString(emptyMap, 32); + + Assert.assertEquals("Not null string", expectedBinaryString, bitmaskInBinaryString); + } + + private static String toBinaryString(Map emptyMap, int length) { + String binaryString = Integer.toBinaryString(ByteBufUtils.fillBitMaskFromMap(emptyMap)); + return String.format("%"+length+"s", binaryString).replaceAll(" ", "0"); + } + + /** + * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)} + */ + @Test + public void testFillBitmaskByFullMap() { + Map fullMap = new HashMap<>(); + String expectedBinaryString = "11111111111111111111111111111111"; + String bitmaskValueInBinarySytring; + for(Integer i=0;i<=31;i++) { + fullMap.put(i, true); + } + bitmaskValueInBinarySytring = toBinaryString(fullMap, 32); + Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); + } + + /** + * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)} + */ + @Test + public void testFillBitmaskByZeroMap() { + Map zeroMap = new HashMap<>(); + String expectedBinaryString = "00000000000000000000000000000000"; + String bitmaskValueInBinarySytring; + for(Integer i=0;i<=31;i++) { + zeroMap.put(i, false); + } + bitmaskValueInBinarySytring = toBinaryString(zeroMap, 32); + Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); + } + + /** + * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)} + */ + @Test + public void testFillBitmaskByRandomSet() { + Map randomMap = new HashMap<>(); + String expectedBinaryString = "00000000000000000111100000000000"; + String bitmaskValueInBinarySytring; + Boolean mapValue; + for(Integer i=0;i<=31;i++) { + mapValue = false; + if(i>=11 && i<=14) { + mapValue = true; + } + randomMap.put(i, mapValue); + } + bitmaskValueInBinarySytring = toBinaryString(randomMap, 32); + Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); + } + + /** + * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} + */ + @Test + public void testFillBitmaskByEmptyList() { + List emptyList = new ArrayList<>(); + emptyList.add(null); + String expectedBinaryString = "00000000000000000000000000000000"; + String bitmaskInBinaryString = listToBinaryString(emptyList, 32); + + Assert.assertEquals("Not null string", expectedBinaryString, bitmaskInBinaryString); + } + + private static String listToBinaryString(List emptyList, int length) { + int[] bitMaskArray; + bitMaskArray = ByteBufUtils.fillBitMaskFromList(emptyList); + String binaryString = Integer.toBinaryString(bitMaskArray[0]); + return String.format("%"+length+"s", binaryString).replaceAll(" ", "0"); + } + + /** + * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} + */ + @Test + public void testFillBitmaskByFullList() { + List fullList = new ArrayList<>(); + String expectedBinaryString = "11111111111111111111111111111111"; + String bitmaskValueInBinarySytring; + for(Integer i=0;i<=31;i++) { + fullList.add(true); + } + bitmaskValueInBinarySytring = listToBinaryString(fullList, 32); + Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); + } + + /** + * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} + */ + @Test + public void testFillBitmaskByZeroList() { + List zeroList = new ArrayList<>(); + String expectedBinaryString = "00000000000000000000000000000000"; + String bitmaskValueInBinarySytring; + for(Integer i=0;i<=31;i++) { + zeroList.add(false); + } + bitmaskValueInBinarySytring = listToBinaryString(zeroList, 32); + Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); + } + + /** + * Test of {@link ByteBufUtils#fillBitMaskFromList(java.util.Map)} + */ + @Test + public void testFillBitmaskFromRandomList() { + List randomList = new ArrayList<>(); + String expectedBinaryString = "00000000000000000111100000000000"; + String bitmaskValueInBinarySytring; + Boolean listValue; + for(Integer i=0;i<=31;i++) { + listValue = false; + if(i>=11 && i<=14) { + listValue = true; + } + randomList.add(listValue); + } + bitmaskValueInBinarySytring = listToBinaryString(randomList, 32); + Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest.java index 67d148fb..220e7bce 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializerTest.java @@ -1,207 +1,214 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder; - -/** - * @author michal.polkorab - * - */ -public class MatchSerializerTest { - - /** - * Test for correct serialization of Ipv4Address match entry - */ - @Test - public void test() { - MatchBuilder builder = new MatchBuilder(); - builder.setType(OxmMatchType.class); - List entries = new ArrayList<>(); - MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(OpenflowBasicClass.class); - entriesBuilder.setOxmMatchField(Ipv4Src.class); - entriesBuilder.setHasMask(false); - Ipv4AddressMatchEntryBuilder addressBuilder = new Ipv4AddressMatchEntryBuilder(); - addressBuilder.setIpv4Address(new Ipv4Address("1.2.3.4")); - entriesBuilder.addAugmentation(Ipv4AddressMatchEntry.class, addressBuilder.build()); - entries.add(entriesBuilder.build()); - builder.setMatchEntries(entries); - Match match = builder.build(); - - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MatchSerializer.encodeMatch(match, out); - - Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); - out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); - Assert.assertEquals("Wrong field and mask", 22, out.readUnsignedByte()); - out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); - Assert.assertEquals("Wrong ip address (first number)", 1, out.readUnsignedByte()); - Assert.assertEquals("Wrong ip address (second number)", 2, out.readUnsignedByte()); - Assert.assertEquals("Wrong ip address (third number)", 3, out.readUnsignedByte()); - Assert.assertEquals("Wrong ip address (fourth number)", 4, out.readUnsignedByte()); - } - - /** - * Test for correct serialization of Ipv6Address match entry - */ - @Test - public void test2() { - MatchBuilder builder = new MatchBuilder(); - builder.setType(OxmMatchType.class); - List entries = new ArrayList<>(); - // ipv6 match entry with correct Ipv6 address - MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(OpenflowBasicClass.class); - entriesBuilder.setOxmMatchField(Ipv6Src.class); - entriesBuilder.setHasMask(false); - Ipv6AddressMatchEntryBuilder addressBuilder = new Ipv6AddressMatchEntryBuilder(); - addressBuilder.setIpv6Address(new Ipv6Address("1:2:3:4:5:6:7:8")); - entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); - entries.add(entriesBuilder.build()); - // ipv6 match entry with abbreviated Ipv6 address - entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(OpenflowBasicClass.class); - entriesBuilder.setOxmMatchField(Ipv6NdTarget.class); - entriesBuilder.setHasMask(false); - addressBuilder = new Ipv6AddressMatchEntryBuilder(); - addressBuilder.setIpv6Address(new Ipv6Address("1:2::6:7:8")); - entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); - entries.add(entriesBuilder.build()); - // ipv6 match entry with abbreviated Ipv6 address - entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(Nxm1Class.class); - entriesBuilder.setOxmMatchField(Ipv6Dst.class); - entriesBuilder.setHasMask(false); - addressBuilder = new Ipv6AddressMatchEntryBuilder(); - addressBuilder.setIpv6Address(new Ipv6Address("1::8")); - entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); - entries.add(entriesBuilder.build()); - // ipv6 match entry with abbreviated Ipv6 address - entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(Nxm1Class.class); - entriesBuilder.setOxmMatchField(Ipv6Dst.class); - entriesBuilder.setHasMask(false); - addressBuilder = new Ipv6AddressMatchEntryBuilder(); - addressBuilder.setIpv6Address(new Ipv6Address("::1")); - entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); - entries.add(entriesBuilder.build()); - // ipv6 match entry with abbreviated Ipv6 address - entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(Nxm0Class.class); - entriesBuilder.setOxmMatchField(Ipv6Dst.class); - entriesBuilder.setHasMask(false); - addressBuilder = new Ipv6AddressMatchEntryBuilder(); - addressBuilder.setIpv6Address(new Ipv6Address("::")); - entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); - entries.add(entriesBuilder.build()); - // ipv6 match entry with incorrect Ipv6 address (longer) - entriesBuilder = new MatchEntriesBuilder(); - entriesBuilder.setOxmClass(OpenflowBasicClass.class); - entriesBuilder.setOxmMatchField(Ipv6Dst.class); - entriesBuilder.setHasMask(false); - addressBuilder = new Ipv6AddressMatchEntryBuilder(); - addressBuilder.setIpv6Address(new Ipv6Address("1:2:3:4:5:6:7:8:9")); - entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); - entries.add(entriesBuilder.build()); - builder.setMatchEntries(entries); - Match match = builder.build(); - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MatchSerializer.encodeMatch(match, out); - - Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); - out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); - Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); - Assert.assertEquals("Wrong field and mask", 52, out.readUnsignedByte()); - Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); - Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 3, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 4, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 5, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); - Assert.assertEquals("Wrong field and mask", 62, out.readUnsignedByte()); - Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); - Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong class", 0x0001, out.readUnsignedShort()); - Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); - Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); - Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); - Assert.assertEquals("Wrong class", 0x0001, out.readUnsignedShort()); - Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); - Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); - Assert.assertEquals("Wrong class", 0x0000, out.readUnsignedShort()); - Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); - Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); - Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); - Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); - Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); - Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 3, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 4, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 5, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort()); - Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder; + +/** + * @author michal.polkorab + * + */ +public class MatchSerializerTest { + + /** + * Test for correct serialization of Ipv4Address match entry + */ + @Test + public void test() { + MatchBuilder builder = new MatchBuilder(); + builder.setType(OxmMatchType.class); + List entries = new ArrayList<>(); + MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(Ipv4Src.class); + entriesBuilder.setHasMask(false); + Ipv4AddressMatchEntryBuilder addressBuilder = new Ipv4AddressMatchEntryBuilder(); + addressBuilder.setIpv4Address(new Ipv4Address("1.2.3.4")); + entriesBuilder.addAugmentation(Ipv4AddressMatchEntry.class, addressBuilder.build()); + entries.add(entriesBuilder.build()); + builder.setMatchEntries(entries); + Match match = builder.build(); + + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MatchSerializer.encodeMatch(match, out); + + Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); + Assert.assertEquals("Wrong field and mask", 22, out.readUnsignedByte()); + out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); + Assert.assertEquals("Wrong ip address (first number)", 1, out.readUnsignedByte()); + Assert.assertEquals("Wrong ip address (second number)", 2, out.readUnsignedByte()); + Assert.assertEquals("Wrong ip address (third number)", 3, out.readUnsignedByte()); + Assert.assertEquals("Wrong ip address (fourth number)", 4, out.readUnsignedByte()); + } + + /** + * Test for correct serialization of Ipv6Address match entry + */ + @Test + public void test2() { + MatchBuilder builder = new MatchBuilder(); + builder.setType(OxmMatchType.class); + List entries = new ArrayList<>(); + // ipv6 match entry with correct Ipv6 address + MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(Ipv6Src.class); + entriesBuilder.setHasMask(false); + Ipv6AddressMatchEntryBuilder addressBuilder = new Ipv6AddressMatchEntryBuilder(); + addressBuilder.setIpv6Address(new Ipv6Address("1:2:3:4:5:6:7:8")); + entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); + entries.add(entriesBuilder.build()); + // ipv6 match entry with abbreviated Ipv6 address + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(Ipv6NdTarget.class); + entriesBuilder.setHasMask(false); + addressBuilder = new Ipv6AddressMatchEntryBuilder(); + addressBuilder.setIpv6Address(new Ipv6Address("1:2::6:7:8")); + entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); + entries.add(entriesBuilder.build()); + // ipv6 match entry with abbreviated Ipv6 address + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(Nxm1Class.class); + entriesBuilder.setOxmMatchField(Ipv6Dst.class); + entriesBuilder.setHasMask(false); + addressBuilder = new Ipv6AddressMatchEntryBuilder(); + addressBuilder.setIpv6Address(new Ipv6Address("1::8")); + entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); + entries.add(entriesBuilder.build()); + // ipv6 match entry with abbreviated Ipv6 address + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(Nxm1Class.class); + entriesBuilder.setOxmMatchField(Ipv6Dst.class); + entriesBuilder.setHasMask(false); + addressBuilder = new Ipv6AddressMatchEntryBuilder(); + addressBuilder.setIpv6Address(new Ipv6Address("::1")); + entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); + entries.add(entriesBuilder.build()); + // ipv6 match entry with abbreviated Ipv6 address + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(Nxm0Class.class); + entriesBuilder.setOxmMatchField(Ipv6Dst.class); + entriesBuilder.setHasMask(false); + addressBuilder = new Ipv6AddressMatchEntryBuilder(); + addressBuilder.setIpv6Address(new Ipv6Address("::")); + entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); + entries.add(entriesBuilder.build()); + // ipv6 match entry with incorrect Ipv6 address (longer) + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(Ipv6Dst.class); + entriesBuilder.setHasMask(false); + addressBuilder = new Ipv6AddressMatchEntryBuilder(); + addressBuilder.setIpv6Address(new Ipv6Address("1:2:3:4:5:6:7:8:9")); + entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); + entries.add(entriesBuilder.build()); + builder.setMatchEntries(entries); + Match match = builder.build(); + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MatchSerializer.encodeMatch(match, out); + + Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); + out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); + Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); + Assert.assertEquals("Wrong field and mask", 52, out.readUnsignedByte()); + Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); + Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 3, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 4, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 5, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); + Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); + Assert.assertEquals("Wrong field and mask", 62, out.readUnsignedByte()); + Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); + Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); + Assert.assertEquals("Wrong class", 0x0001, out.readUnsignedShort()); + Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); + Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); + Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); + Assert.assertEquals("Wrong class", 0x0001, out.readUnsignedShort()); + Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); + Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); + Assert.assertEquals("Wrong class", 0x0000, out.readUnsignedShort()); + Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); + Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); + Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); + Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); + Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); + Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 3, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 4, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 5, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort()); + Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializerTest.java index 06b78e34..30c2c3f9 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchDeserializerTest.java @@ -1,75 +1,82 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; - -/** - * @author michal.polkorab - * - */ -public class OF10MatchDeserializerTest { - - /** - * Testing correct deserialization of ofp_match - */ - @Test - public void test() { - ByteBuf message = BufferHelper.buildBuffer("00 24 08 91 00 20 AA BB CC DD EE FF " - + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 " - + "50 50 20 20"); - message.skipBytes(4); // skip XID - MatchV10 match = OF10MatchDeserializer.createMatchV10(message); - Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, false, true, false, - false, true, false, true, true, false), match.getWildcards()); - Assert.assertEquals("Wrong srcMask", 24, match.getNwSrcMask().shortValue()); - Assert.assertEquals("Wrong dstMask", 16, match.getNwDstMask().shortValue()); - Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue()); - Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc()); - Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst()); - Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue()); - Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue()); - Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue()); - Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue()); - Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue()); - Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc()); - Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst()); - Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue()); - Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue()); - } - - /** - * Testing correct deserialization of ofp_match - */ - @Test - public void test2() { - ByteBuf message = BufferHelper.buildBuffer("00 3F FF FF 00 20 AA BB CC DD EE FF " - + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 " - + "50 50 20 20"); - message.skipBytes(4); // skip XID - MatchV10 match = OF10MatchDeserializer.createMatchV10(message); - Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true, true, - true, true, true, true, true, true), match.getWildcards()); - Assert.assertEquals("Wrong srcMask", 0, match.getNwSrcMask().shortValue()); - Assert.assertEquals("Wrong dstMask", 0, match.getNwDstMask().shortValue()); - Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue()); - Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc()); - Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst()); - Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue()); - Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue()); - Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue()); - Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue()); - Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue()); - Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc()); - Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst()); - Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue()); - Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue()); - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; + +/** + * @author michal.polkorab + * + */ +public class OF10MatchDeserializerTest { + + /** + * Testing correct deserialization of ofp_match + */ + @Test + public void test() { + ByteBuf message = BufferHelper.buildBuffer("00 24 08 91 00 20 AA BB CC DD EE FF " + + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 " + + "50 50 20 20"); + message.skipBytes(4); // skip XID + MatchV10 match = OF10MatchDeserializer.createMatchV10(message); + Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, false, true, false, + false, true, false, true, true, false), match.getWildcards()); + Assert.assertEquals("Wrong srcMask", 24, match.getNwSrcMask().shortValue()); + Assert.assertEquals("Wrong dstMask", 16, match.getNwDstMask().shortValue()); + Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue()); + Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc()); + Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst()); + Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue()); + Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue()); + Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue()); + Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue()); + Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue()); + Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc()); + Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst()); + Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue()); + Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue()); + } + + /** + * Testing correct deserialization of ofp_match + */ + @Test + public void test2() { + ByteBuf message = BufferHelper.buildBuffer("00 3F FF FF 00 20 AA BB CC DD EE FF " + + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 " + + "50 50 20 20"); + message.skipBytes(4); // skip XID + MatchV10 match = OF10MatchDeserializer.createMatchV10(message); + Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true, true, + true, true, true, true, true, true), match.getWildcards()); + Assert.assertEquals("Wrong srcMask", 0, match.getNwSrcMask().shortValue()); + Assert.assertEquals("Wrong dstMask", 0, match.getNwDstMask().shortValue()); + Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue()); + Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc()); + Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst()); + Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue()); + Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue()); + Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue()); + Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue()); + Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue()); + Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc()); + Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst()); + Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue()); + Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue()); + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializerTest.java index c077cf83..240d64ca 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/OF10MatchSerializerTest.java @@ -1,114 +1,121 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.util; - -import junit.framework.Assert; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder; - -/** - * @author michal.polkorab - * - */ -public class OF10MatchSerializerTest { - - /** - * Testing correct serialization of ofp_match - */ - @Test - public void test() { - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MatchV10Builder builder = new MatchV10Builder(); - builder.setWildcards(new FlowWildcardsV10(false, false, false, true, false, - false, true, false, true, true, true)); - builder.setNwSrcMask((short) 24); - builder.setNwDstMask((short) 16); - builder.setInPort(6653); - builder.setDlSrc(new MacAddress("01:01:01:01:01:01")); - builder.setDlDst(new MacAddress("02:02:02:02:02:02")); - builder.setDlVlan(128); - builder.setDlVlanPcp((short) 2); - builder.setDlType(15); - builder.setNwTos((short) 14); - builder.setNwProto((short) 85); - builder.setNwSrc(new Ipv4Address("1.1.1.2")); - builder.setNwDst(new Ipv4Address("32.16.8.1")); - builder.setTpSrc(2048); - builder.setTpDst(4096); - MatchV10 match = builder.build(); - OF10MatchSerializer.encodeMatchV10(out, match); - - Assert.assertEquals("Wrong wildcards", 2361553, out.readUnsignedInt()); - Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort()); - byte[] dlSrc = new byte[6]; - out.readBytes(dlSrc); - Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc)); - byte[] dlDst = new byte[6]; - out.readBytes(dlDst); - Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst)); - Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort()); - Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte()); - out.skipBytes(1); - Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort()); - Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte()); - Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte()); - out.skipBytes(2); - Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt()); - Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt()); - Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort()); - Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort()); - } - - /** - * Testing correct serialization of ofp_match - */ - @Test - public void test2() { - ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); - MatchV10Builder builder = new MatchV10Builder(); - builder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, - true, true, true, true, true, true)); - builder.setNwSrcMask((short) 0); - builder.setNwDstMask((short) 0); - builder.setInPort(6653); - builder.setDlSrc(new MacAddress("01:01:01:01:01:01")); - builder.setDlDst(new MacAddress("02:02:02:02:02:02")); - builder.setDlVlan(128); - builder.setDlVlanPcp((short) 2); - builder.setDlType(15); - builder.setNwTos((short) 14); - builder.setNwProto((short) 85); - builder.setNwSrc(new Ipv4Address("1.1.1.2")); - builder.setNwDst(new Ipv4Address("32.16.8.1")); - builder.setTpSrc(2048); - builder.setTpDst(4096); - MatchV10 match = builder.build(); - OF10MatchSerializer.encodeMatchV10(out, match); - - Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt()); - Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort()); - byte[] dlSrc = new byte[6]; - out.readBytes(dlSrc); - Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc)); - byte[] dlDst = new byte[6]; - out.readBytes(dlDst); - Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst)); - Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort()); - Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte()); - out.skipBytes(1); - Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort()); - Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte()); - Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte()); - out.skipBytes(2); - Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt()); - Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt()); - Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort()); - Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort()); - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.util; + +import junit.framework.Assert; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder; + +/** + * @author michal.polkorab + * + */ +public class OF10MatchSerializerTest { + + /** + * Testing correct serialization of ofp_match + */ + @Test + public void test() { + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MatchV10Builder builder = new MatchV10Builder(); + builder.setWildcards(new FlowWildcardsV10(false, false, false, true, false, + false, true, false, true, true, true)); + builder.setNwSrcMask((short) 24); + builder.setNwDstMask((short) 16); + builder.setInPort(6653); + builder.setDlSrc(new MacAddress("01:01:01:01:01:01")); + builder.setDlDst(new MacAddress("02:02:02:02:02:02")); + builder.setDlVlan(128); + builder.setDlVlanPcp((short) 2); + builder.setDlType(15); + builder.setNwTos((short) 14); + builder.setNwProto((short) 85); + builder.setNwSrc(new Ipv4Address("1.1.1.2")); + builder.setNwDst(new Ipv4Address("32.16.8.1")); + builder.setTpSrc(2048); + builder.setTpDst(4096); + MatchV10 match = builder.build(); + OF10MatchSerializer.encodeMatchV10(out, match); + + Assert.assertEquals("Wrong wildcards", 2361553, out.readUnsignedInt()); + Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort()); + byte[] dlSrc = new byte[6]; + out.readBytes(dlSrc); + Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc)); + byte[] dlDst = new byte[6]; + out.readBytes(dlDst); + Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst)); + Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort()); + Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte()); + out.skipBytes(1); + Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort()); + Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte()); + Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte()); + out.skipBytes(2); + Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt()); + Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt()); + Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort()); + Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort()); + } + + /** + * Testing correct serialization of ofp_match + */ + @Test + public void test2() { + ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); + MatchV10Builder builder = new MatchV10Builder(); + builder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, + true, true, true, true, true, true)); + builder.setNwSrcMask((short) 0); + builder.setNwDstMask((short) 0); + builder.setInPort(6653); + builder.setDlSrc(new MacAddress("01:01:01:01:01:01")); + builder.setDlDst(new MacAddress("02:02:02:02:02:02")); + builder.setDlVlan(128); + builder.setDlVlanPcp((short) 2); + builder.setDlType(15); + builder.setNwTos((short) 14); + builder.setNwProto((short) 85); + builder.setNwSrc(new Ipv4Address("1.1.1.2")); + builder.setNwDst(new Ipv4Address("32.16.8.1")); + builder.setTpSrc(2048); + builder.setTpDst(4096); + MatchV10 match = builder.build(); + OF10MatchSerializer.encodeMatchV10(out, match); + + Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt()); + Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort()); + byte[] dlSrc = new byte[6]; + out.readBytes(dlSrc); + Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc)); + byte[] dlDst = new byte[6]; + out.readBytes(dlDst); + Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst)); + Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort()); + Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte()); + out.skipBytes(1); + Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort()); + Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte()); + Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte()); + out.skipBytes(2); + Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt()); + Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt()); + Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort()); + Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort()); + } +} diff --git a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java index d7d3ccf1..2627d61f 100644 --- a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java +++ b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java @@ -1,144 +1,151 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.integration; - -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT; -import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent; -import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioFactory; -import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler; -import org.opendaylight.openflowjava.protocol.impl.clients.SendEvent; -import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient; -import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent; -import org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent; -import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl; -import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class IntegrationTest { - - private static final Logger LOGGER = LoggerFactory - .getLogger(IntegrationTest.class); - private static int port; - private static final FEATURE_SUPPORT DEFAULT_TLS_SUPPORT = FEATURE_SUPPORT.NOT_SUPPORTED; - private static final int SWITCH_IDLE_TIMEOUT = 2000; - private static final long CONNECTION_TIMEOUT = 2000; - private InetAddress startupAddress; - private MockPlugin mockPlugin; - private SwitchConnectionProviderImpl scpimpl; - private List configs; - - /** - * @throws Exception - */ - @Before - public void setUp() throws Exception { - LOGGER.debug("\n\nstarting test -------------------------------"); - startupAddress = InetAddress.getLocalHost(); - mockPlugin = new MockPlugin(); - scpimpl = new SwitchConnectionProviderImpl(); - scpimpl.setSwitchConnectionHandler(mockPlugin); - configs = new ArrayList<>(); - configs.add(new TestingConnConfigImpl(startupAddress, 0, DEFAULT_TLS_SUPPORT, SWITCH_IDLE_TIMEOUT)); - scpimpl.configure(configs); - scpimpl.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); - TcpHandler server = (TcpHandler) scpimpl.getServerLot().iterator().next(); - port = server.getPort(); - } - - /** - * @throws Exception - */ - @After - public void tearDown() throws Exception { - Thread.sleep(500); - } - - /** - * Library integration and communication test with handshake - * @throws Exception - */ - @Test - public void testHandshake() throws Exception { - int amountOfCLients = 1; - Stack scenario = ScenarioFactory.createHandshakeScenario(); - ScenarioHandler handler = new ScenarioHandler(scenario); - List clients = createAndStartClient(amountOfCLients, handler); - SimpleClient firstClient = clients.get(0); - firstClient.getScenarioDone().get(); - mockPlugin.shutdown(); - mockPlugin.getFinishedFuture().get(); - } - - /** - * Library integration and communication test with handshake + echo exchange - * @throws Exception - */ - @Test - public void testHandshakeAndEcho() throws Exception { - int amountOfCLients = 1; - Stack scenario = ScenarioFactory.createHandshakeScenario(); - scenario.add(0, new SleepEvent(100)); - scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04"))); - scenario.add(0, new SleepEvent(100)); - scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04"))); - ScenarioHandler handler = new ScenarioHandler(scenario); - List clients = createAndStartClient(amountOfCLients, handler); - SimpleClient firstClient = clients.get(0); - firstClient.getScenarioDone().get(); - mockPlugin.shutdown(); - mockPlugin.getFinishedFuture().get(); - } - - /** - * Library integration and communication test (with virtual machine) - * @throws Exception - */ - //@Test - public void testCommunicationWithVM() throws Exception { - mockPlugin.getFinishedFuture().get(); - } - - /** - * @param amountOfCLients - * @return new clients up and running - * @throws ExecutionException if some client could not start - */ - private List createAndStartClient(int amountOfCLients, ScenarioHandler scenarioHandler) - throws ExecutionException { - List clientsHorde = new ArrayList<>(); - for (int i = 0; i < amountOfCLients; i++) { - LOGGER.debug("startup address in createclient: " + startupAddress.getHostAddress()); - SimpleClient sc = new SimpleClient(startupAddress.getHostAddress(), port); - sc.setSecuredClient(false); - sc.setScenarioHandler(scenarioHandler); - clientsHorde.add(sc); - sc.start(); - } - for (SimpleClient sc : clientsHorde) { - try { - sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); - } catch (Exception e) { - LOGGER.error(e.getMessage(), e); - throw new ExecutionException(e); - } - } - return clientsHorde; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.integration; + +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT; +import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent; +import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioFactory; +import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler; +import org.opendaylight.openflowjava.protocol.impl.clients.SendEvent; +import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient; +import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent; +import org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent; +import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl; +import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class IntegrationTest { + + private static final Logger LOGGER = LoggerFactory + .getLogger(IntegrationTest.class); + private static int port; + private static final FEATURE_SUPPORT DEFAULT_TLS_SUPPORT = FEATURE_SUPPORT.NOT_SUPPORTED; + private static final int SWITCH_IDLE_TIMEOUT = 2000; + private static final long CONNECTION_TIMEOUT = 2000; + private InetAddress startupAddress; + private MockPlugin mockPlugin; + private SwitchConnectionProviderImpl scpimpl; + private List configs; + + /** + * @throws Exception + */ + @Before + public void setUp() throws Exception { + LOGGER.debug("\n\nstarting test -------------------------------"); + startupAddress = InetAddress.getLocalHost(); + mockPlugin = new MockPlugin(); + scpimpl = new SwitchConnectionProviderImpl(); + scpimpl.setSwitchConnectionHandler(mockPlugin); + configs = new ArrayList<>(); + configs.add(new TestingConnConfigImpl(startupAddress, 0, DEFAULT_TLS_SUPPORT, SWITCH_IDLE_TIMEOUT)); + scpimpl.configure(configs); + scpimpl.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); + TcpHandler server = (TcpHandler) scpimpl.getServerLot().iterator().next(); + port = server.getPort(); + } + + /** + * @throws Exception + */ + @After + public void tearDown() throws Exception { + Thread.sleep(500); + } + + /** + * Library integration and communication test with handshake + * @throws Exception + */ + @Test + public void testHandshake() throws Exception { + int amountOfCLients = 1; + Stack scenario = ScenarioFactory.createHandshakeScenario(); + ScenarioHandler handler = new ScenarioHandler(scenario); + List clients = createAndStartClient(amountOfCLients, handler); + SimpleClient firstClient = clients.get(0); + firstClient.getScenarioDone().get(); + mockPlugin.shutdown(); + mockPlugin.getFinishedFuture().get(); + } + + /** + * Library integration and communication test with handshake + echo exchange + * @throws Exception + */ + @Test + public void testHandshakeAndEcho() throws Exception { + int amountOfCLients = 1; + Stack scenario = ScenarioFactory.createHandshakeScenario(); + scenario.add(0, new SleepEvent(100)); + scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04"))); + scenario.add(0, new SleepEvent(100)); + scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04"))); + ScenarioHandler handler = new ScenarioHandler(scenario); + List clients = createAndStartClient(amountOfCLients, handler); + SimpleClient firstClient = clients.get(0); + firstClient.getScenarioDone().get(); + mockPlugin.shutdown(); + mockPlugin.getFinishedFuture().get(); + } + + /** + * Library integration and communication test (with virtual machine) + * @throws Exception + */ + //@Test + public void testCommunicationWithVM() throws Exception { + mockPlugin.getFinishedFuture().get(); + } + + /** + * @param amountOfCLients + * @return new clients up and running + * @throws ExecutionException if some client could not start + */ + private List createAndStartClient(int amountOfCLients, ScenarioHandler scenarioHandler) + throws ExecutionException { + List clientsHorde = new ArrayList<>(); + for (int i = 0; i < amountOfCLients; i++) { + LOGGER.debug("startup address in createclient: " + startupAddress.getHostAddress()); + SimpleClient sc = new SimpleClient(startupAddress.getHostAddress(), port); + sc.setSecuredClient(false); + sc.setScenarioHandler(scenarioHandler); + clientsHorde.add(sc); + sc.start(); + } + for (SimpleClient sc : clientsHorde) { + try { + sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + throw new ExecutionException(e); + } + } + return clientsHorde; + } + +} diff --git a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java index 7ca6ddd8..f31ed029 100644 --- a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java +++ b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java @@ -1,228 +1,235 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.integration; - -import java.net.InetAddress; -import java.util.Arrays; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener; -import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener; -import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.util.concurrent.SettableFuture; - -/** - * @author michal.polkorab - * - */ -public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHandler, - SystemNotificationsListener, ConnectionReadyListener { - - protected static final Logger LOGGER = LoggerFactory.getLogger(MockPlugin.class); - protected ConnectionAdapter adapter; - private SettableFuture finishedFuture; - private int idleCounter = 0; - - /** Creates MockPlugin */ - public MockPlugin() { - LOGGER.info("Creating MockPlugin"); - finishedFuture = SettableFuture.create(); - LOGGER.info("mockPlugin: "+System.identityHashCode(this)); - } - - @Override - public void onSwitchConnected(ConnectionAdapter connection) { - LOGGER.info("onSwitchConnected: " + connection); - this.adapter = connection; - connection.setMessageListener(this); - connection.setSystemListener(this); - connection.setConnectionReadyListener(this); - } - - @Override - public boolean accept(InetAddress switchAddress) { - return true; - } - - @Override - public void onEchoRequestMessage(final EchoRequestMessage notification) { - new Thread(new Runnable() { - @Override - public void run() { - LOGGER.debug("EchoRequest message received"); - EchoReplyInputBuilder replyBuilder = new EchoReplyInputBuilder(); - replyBuilder.setVersion((short) 4); - replyBuilder.setXid(notification.getXid()); - EchoReplyInput echoReplyInput = replyBuilder.build(); - adapter.echoReply(echoReplyInput); - LOGGER.debug("EchoReplyInput sent"); - LOGGER.debug("adapter: "+adapter); - } - }).start(); - } - - @Override - public void onErrorMessage(ErrorMessage notification) { - LOGGER.debug("Error message received"); - - } - - @Override - public void onExperimenterMessage(ExperimenterMessage notification) { - LOGGER.debug("Experimenter message received"); - - } - - @Override - public void onFlowRemovedMessage(FlowRemovedMessage notification) { - LOGGER.debug("FlowRemoved message received"); - - } - - @Override - public void onHelloMessage(HelloMessage notification) { - new Thread(new Runnable() { - @Override - public void run() { - LOGGER.debug("Hello message received"); - HelloInputBuilder hib = new HelloInputBuilder(); - hib.setVersion((short) 4); - hib.setXid(2L); - HelloInput hi = hib.build(); - adapter.hello(hi); - LOGGER.debug("hello msg sent"); - new Thread(new Runnable() { - @Override - public void run() { - sendFeaturesReply(); - } - }).start(); - LOGGER.debug("adapter: "+adapter); - } - }).start(); - } - - protected void sendFeaturesReply() { - GetFeaturesInputBuilder featuresBuilder = new GetFeaturesInputBuilder(); - featuresBuilder.setVersion((short) 4); - featuresBuilder.setXid(3L); - GetFeaturesInput featuresInput = featuresBuilder.build(); - try { - LOGGER.debug("Going to send featuresRequest"); - RpcResult rpcResult = adapter.getFeatures( - featuresInput).get(2500, TimeUnit.MILLISECONDS); - if (rpcResult.isSuccessful()) { - byte[] byteArray = rpcResult.getResult().getDatapathId() - .toByteArray(); - LOGGER.info("DatapathId: " + Arrays.toString(byteArray)); - } else { - RpcError rpcError = rpcResult.getErrors().iterator().next(); - LOGGER.warn("rpcResult failed: " - + rpcError.getCause().getMessage(), rpcError.getCause()); - } - } catch (InterruptedException | ExecutionException | TimeoutException e) { - LOGGER.error(e.getMessage(), e); - } - LOGGER.info("After FeaturesReply message"); - } - - protected void shutdown() { - LOGGER.debug("adapter: "+adapter); - try { - LOGGER.info("mockPlugin: "+System.identityHashCode(this)); - Thread.sleep(500); - if (adapter != null) { - Future disconnect = adapter.disconnect(); - disconnect.get(); - LOGGER.info("Disconnected"); - } - } catch (Exception e) { - LOGGER.error(e.getMessage(), e); - } - finishedFuture.set(null); - } - - @Override - public void onMultipartReplyMessage(MultipartReplyMessage notification) { - LOGGER.debug("MultipartReply message received"); - - } - - @Override - public void onPacketInMessage(PacketInMessage notification) { - LOGGER.debug("PacketIn message received"); - LOGGER.debug("BufferId: " + notification.getBufferId()); - LOGGER.debug("TotalLength: " + notification.getTotalLen()); - LOGGER.debug("Reason: " + notification.getReason()); - LOGGER.debug("TableId: " + notification.getTableId()); - LOGGER.debug("Cookie: " + notification.getCookie()); - LOGGER.debug("Class: " + notification.getMatch().getMatchEntries().get(0).getOxmClass()); - LOGGER.debug("Field: " + notification.getMatch().getMatchEntries().get(0).getOxmMatchField()); - LOGGER.debug("Datasize: " + notification.getData().length); - } - - @Override - public void onPortStatusMessage(PortStatusMessage notification) { - LOGGER.debug("PortStatus message received"); - - } - - @Override - public void onDisconnectEvent(DisconnectEvent notification) { - LOGGER.debug("disconnection ocured: "+notification.getInfo()); - LOGGER.debug("adapter: "+adapter); - } - - /** - * @return finishedFuture object - */ - public SettableFuture getFinishedFuture() { - return finishedFuture; - } - - @Override - public void onSwitchIdleEvent(SwitchIdleEvent notification) { - LOGGER.debug("switch status: "+notification.getInfo()); - idleCounter ++; - } - - /** - * @return number of occured idleEvents - */ - public int getIdleCounter() { - return idleCounter; - } - - @Override - public void onConnectionReady() { - LOGGER.debug("connection ready notification arrived"); - } - - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.integration; + +import java.net.InetAddress; +import java.util.Arrays; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener; +import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener; +import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.SettableFuture; + +/** + * @author michal.polkorab + * + */ +public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHandler, + SystemNotificationsListener, ConnectionReadyListener { + + protected static final Logger LOGGER = LoggerFactory.getLogger(MockPlugin.class); + protected ConnectionAdapter adapter; + private SettableFuture finishedFuture; + private int idleCounter = 0; + + /** Creates MockPlugin */ + public MockPlugin() { + LOGGER.info("Creating MockPlugin"); + finishedFuture = SettableFuture.create(); + LOGGER.info("mockPlugin: "+System.identityHashCode(this)); + } + + @Override + public void onSwitchConnected(ConnectionAdapter connection) { + LOGGER.info("onSwitchConnected: " + connection); + this.adapter = connection; + connection.setMessageListener(this); + connection.setSystemListener(this); + connection.setConnectionReadyListener(this); + } + + @Override + public boolean accept(InetAddress switchAddress) { + return true; + } + + @Override + public void onEchoRequestMessage(final EchoRequestMessage notification) { + new Thread(new Runnable() { + @Override + public void run() { + LOGGER.debug("EchoRequest message received"); + EchoReplyInputBuilder replyBuilder = new EchoReplyInputBuilder(); + replyBuilder.setVersion((short) 4); + replyBuilder.setXid(notification.getXid()); + EchoReplyInput echoReplyInput = replyBuilder.build(); + adapter.echoReply(echoReplyInput); + LOGGER.debug("EchoReplyInput sent"); + LOGGER.debug("adapter: "+adapter); + } + }).start(); + } + + @Override + public void onErrorMessage(ErrorMessage notification) { + LOGGER.debug("Error message received"); + + } + + @Override + public void onExperimenterMessage(ExperimenterMessage notification) { + LOGGER.debug("Experimenter message received"); + + } + + @Override + public void onFlowRemovedMessage(FlowRemovedMessage notification) { + LOGGER.debug("FlowRemoved message received"); + + } + + @Override + public void onHelloMessage(HelloMessage notification) { + new Thread(new Runnable() { + @Override + public void run() { + LOGGER.debug("Hello message received"); + HelloInputBuilder hib = new HelloInputBuilder(); + hib.setVersion((short) 4); + hib.setXid(2L); + HelloInput hi = hib.build(); + adapter.hello(hi); + LOGGER.debug("hello msg sent"); + new Thread(new Runnable() { + @Override + public void run() { + sendFeaturesReply(); + } + }).start(); + LOGGER.debug("adapter: "+adapter); + } + }).start(); + } + + protected void sendFeaturesReply() { + GetFeaturesInputBuilder featuresBuilder = new GetFeaturesInputBuilder(); + featuresBuilder.setVersion((short) 4); + featuresBuilder.setXid(3L); + GetFeaturesInput featuresInput = featuresBuilder.build(); + try { + LOGGER.debug("Going to send featuresRequest"); + RpcResult rpcResult = adapter.getFeatures( + featuresInput).get(2500, TimeUnit.MILLISECONDS); + if (rpcResult.isSuccessful()) { + byte[] byteArray = rpcResult.getResult().getDatapathId() + .toByteArray(); + LOGGER.info("DatapathId: " + Arrays.toString(byteArray)); + } else { + RpcError rpcError = rpcResult.getErrors().iterator().next(); + LOGGER.warn("rpcResult failed: " + + rpcError.getCause().getMessage(), rpcError.getCause()); + } + } catch (InterruptedException | ExecutionException | TimeoutException e) { + LOGGER.error(e.getMessage(), e); + } + LOGGER.info("After FeaturesReply message"); + } + + protected void shutdown() { + LOGGER.debug("adapter: "+adapter); + try { + LOGGER.info("mockPlugin: "+System.identityHashCode(this)); + Thread.sleep(500); + if (adapter != null) { + Future disconnect = adapter.disconnect(); + disconnect.get(); + LOGGER.info("Disconnected"); + } + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + } + finishedFuture.set(null); + } + + @Override + public void onMultipartReplyMessage(MultipartReplyMessage notification) { + LOGGER.debug("MultipartReply message received"); + + } + + @Override + public void onPacketInMessage(PacketInMessage notification) { + LOGGER.debug("PacketIn message received"); + LOGGER.debug("BufferId: " + notification.getBufferId()); + LOGGER.debug("TotalLength: " + notification.getTotalLen()); + LOGGER.debug("Reason: " + notification.getReason()); + LOGGER.debug("TableId: " + notification.getTableId()); + LOGGER.debug("Cookie: " + notification.getCookie()); + LOGGER.debug("Class: " + notification.getMatch().getMatchEntries().get(0).getOxmClass()); + LOGGER.debug("Field: " + notification.getMatch().getMatchEntries().get(0).getOxmMatchField()); + LOGGER.debug("Datasize: " + notification.getData().length); + } + + @Override + public void onPortStatusMessage(PortStatusMessage notification) { + LOGGER.debug("PortStatus message received"); + + } + + @Override + public void onDisconnectEvent(DisconnectEvent notification) { + LOGGER.debug("disconnection ocured: "+notification.getInfo()); + LOGGER.debug("adapter: "+adapter); + } + + /** + * @return finishedFuture object + */ + public SettableFuture getFinishedFuture() { + return finishedFuture; + } + + @Override + public void onSwitchIdleEvent(SwitchIdleEvent notification) { + LOGGER.debug("switch status: "+notification.getInfo()); + idleCounter ++; + } + + /** + * @return number of occured idleEvents + */ + public int getIdleCounter() { + return idleCounter; + } + + @Override + public void onConnectionReady() { + LOGGER.debug("connection ready notification arrived"); + } + + +} diff --git a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java index 3a9bd55b..578001d4 100644 --- a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java +++ b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java @@ -1,65 +1,72 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.integration; - -import java.net.InetAddress; - -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; - -/** - * @author michal.polkorab - * - */ -public class TestingConnConfigImpl implements ConnectionConfiguration { - - private InetAddress address; - private int port; - private Object transferProtocol; - private FEATURE_SUPPORT tlsSupport; - private long switchIdleTimeout; - - /** - * Creates {@link TestingConnConfigImpl} - * @param address - * @param port - * @param tlsSupport - * @param switchIdleTimeout - */ - public TestingConnConfigImpl(InetAddress address, int port, FEATURE_SUPPORT tlsSupport, long switchIdleTimeout) { - this.address = address; - this.port = port; - this.tlsSupport = tlsSupport; - this.switchIdleTimeout = switchIdleTimeout; - } - - @Override - public InetAddress getAddress() { - return address; - } - - @Override - public int getPort() { - return port; - } - - @Override - public Object getTransferProtocol() { - return transferProtocol; - } - - @Override - public FEATURE_SUPPORT getTlsSupport() { - return tlsSupport; - } - - @Override - public long getSwitchIdleTimeout() { - return switchIdleTimeout; - } - - @Override - public Object getSslContext() { - // TODO Auto-generated method stub - return null; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.integration; + +import java.net.InetAddress; + +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; + +/** + * @author michal.polkorab + * + */ +public class TestingConnConfigImpl implements ConnectionConfiguration { + + private InetAddress address; + private int port; + private Object transferProtocol; + private FEATURE_SUPPORT tlsSupport; + private long switchIdleTimeout; + + /** + * Creates {@link TestingConnConfigImpl} + * @param address + * @param port + * @param tlsSupport + * @param switchIdleTimeout + */ + public TestingConnConfigImpl(InetAddress address, int port, FEATURE_SUPPORT tlsSupport, long switchIdleTimeout) { + this.address = address; + this.port = port; + this.tlsSupport = tlsSupport; + this.switchIdleTimeout = switchIdleTimeout; + } + + @Override + public InetAddress getAddress() { + return address; + } + + @Override + public int getPort() { + return port; + } + + @Override + public Object getTransferProtocol() { + return transferProtocol; + } + + @Override + public FEATURE_SUPPORT getTlsSupport() { + return tlsSupport; + } + + @Override + public long getSwitchIdleTimeout() { + return switchIdleTimeout; + } + + @Override + public Object getSslContext() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java b/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java index 9cf1b736..0465ab4e 100644 --- a/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java +++ b/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.spi.connection; diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ClientEvent.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ClientEvent.java index 2f2d80ba..39b86460 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ClientEvent.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ClientEvent.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.clients; /** diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioFactory.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioFactory.java index 2d2ddcf8..71d03968 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioFactory.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioFactory.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.clients; import java.util.Stack; diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java index 29244dba..24f90c9d 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.clients; import io.netty.channel.ChannelHandlerContext; diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java index e59bce07..bd664b80 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.clients; import io.netty.buffer.ByteBuf; diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java index b85b6b0e..159471ce 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java @@ -1,4 +1,11 @@ - /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.clients; import io.netty.bootstrap.Bootstrap; diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientFramer.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientFramer.java index 95eb08c0..48d7e475 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientFramer.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientFramer.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.clients; diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java index e9453b58..9c7ae5db 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java @@ -1,68 +1,75 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ - -package org.opendaylight.openflowjava.protocol.impl.clients; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; - -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.util.concurrent.SettableFuture; - -/** - * - * @author michal.polkorab - */ -public class SimpleClientHandler extends ChannelInboundHandlerAdapter { - - protected static final Logger LOGGER = LoggerFactory.getLogger(SimpleClientHandler.class); - private static final int LENGTH_INDEX_IN_HEADER = 2; - private SettableFuture isOnlineFuture; - protected ScenarioHandler scenarioHandler; - - /** - * @param isOnlineFuture future notifier of connected channel - * @param scenarioHandler handler of scenario events - */ - public SimpleClientHandler(SettableFuture isOnlineFuture, ScenarioHandler scenarioHandler) { - this.isOnlineFuture = isOnlineFuture; - this.scenarioHandler = scenarioHandler; - } - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - ByteBuf bb = (ByteBuf) msg; - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(bb)); - } - int length = bb.getUnsignedShort(LENGTH_INDEX_IN_HEADER); - LOGGER.info("SimpleClientHandler - start of read"); - byte[] message = new byte[length]; - bb.readBytes(message); - scenarioHandler.addOfMsg(message); - LOGGER.info("end of read"); - } - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - LOGGER.info("Client is active"); - if (isOnlineFuture != null) { - isOnlineFuture.set(true); - isOnlineFuture = null; - } - scenarioHandler.setCtx(ctx); - scenarioHandler.start(); - - } - - /** - * @param scenarioHandler handler of scenario events - */ - public void setScenario(ScenarioHandler scenarioHandler) { - this.scenarioHandler = scenarioHandler; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + + +package org.opendaylight.openflowjava.protocol.impl.clients; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; + +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.SettableFuture; + +/** + * + * @author michal.polkorab + */ +public class SimpleClientHandler extends ChannelInboundHandlerAdapter { + + protected static final Logger LOGGER = LoggerFactory.getLogger(SimpleClientHandler.class); + private static final int LENGTH_INDEX_IN_HEADER = 2; + private SettableFuture isOnlineFuture; + protected ScenarioHandler scenarioHandler; + + /** + * @param isOnlineFuture future notifier of connected channel + * @param scenarioHandler handler of scenario events + */ + public SimpleClientHandler(SettableFuture isOnlineFuture, ScenarioHandler scenarioHandler) { + this.isOnlineFuture = isOnlineFuture; + this.scenarioHandler = scenarioHandler; + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + ByteBuf bb = (ByteBuf) msg; + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(bb)); + } + int length = bb.getUnsignedShort(LENGTH_INDEX_IN_HEADER); + LOGGER.info("SimpleClientHandler - start of read"); + byte[] message = new byte[length]; + bb.readBytes(message); + scenarioHandler.addOfMsg(message); + LOGGER.info("end of read"); + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + LOGGER.info("Client is active"); + if (isOnlineFuture != null) { + isOnlineFuture.set(true); + isOnlineFuture = null; + } + scenarioHandler.setCtx(ctx); + scenarioHandler.start(); + + } + + /** + * @param scenarioHandler handler of scenario events + */ + public void setScenario(ScenarioHandler scenarioHandler) { + this.scenarioHandler = scenarioHandler; + } + +} diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientInitializer.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientInitializer.java index eed60970..bd9a911b 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientInitializer.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientInitializer.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.clients; diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SleepEvent.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SleepEvent.java index 490a094b..25ed0d46 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SleepEvent.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SleepEvent.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.clients; import org.slf4j.Logger; diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/WaitForMessageEvent.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/WaitForMessageEvent.java index 1ad9b944..688a128e 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/WaitForMessageEvent.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/WaitForMessageEvent.java @@ -1,4 +1,11 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.clients; import java.util.Arrays; -- 2.36.6