<groupId>org.opendaylight.controller.model</groupId>
<artifactId>model-flow-service</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-buffer</artifactId>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.api.extensibility;\r
+\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+/**\r
+ * Does only-header serialization (such as oxm_ids, action_ids, instruction_ids)\r
+ * @author michal.polkorab\r
+ * @param <SERIALIZER_TYPE>\r
+ */\r
+public interface HeaderSerializer<SERIALIZER_TYPE extends DataObject> extends OFGeneralSerializer {\r
+\r
+ /**\r
+ * Serializes object headers (e.g. for Multipart message - Table Features)\r
+ * @param input object whose headers should be serialized\r
+ * @param outBuffer output buffer\r
+ */\r
+ public void serializeHeader(SERIALIZER_TYPE input, ByteBuf outBuffer);\r
+}\r
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.openflowjava.protocol.impl.serialization;
+package org.opendaylight.openflowjava.protocol.api.extensibility;
-import org.opendaylight.yangtools.yang.binding.DataObject;
/**
- * Class used as a key in {@link EncoderTable}
+ * Class used as a key in {@link SerializerRegistry}
* @author michal.polkorab
* @author timotej.kubas
* @param <E> message type (class)
*/
-public class MessageTypeKey<E extends DataObject> {
+public class MessageTypeKey<E> {
private final Class<E> msgType;
private final short msgVersion;
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.api.extensibility;\r
+\r
+/**\r
+ * Unifying superinterface\r
+ * @author michal.polkorab\r
+ * */\r
+public interface OFGeneralSerializer {\r
+\r
+ // empty unifying superinterface\r
+}\r
--- /dev/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.api.extensibility;
+
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+import io.netty.buffer.ByteBuf;
+
+/**
+ * Uniform interface for serializers
+ * @author michal.polkorab
+ * @author timotej.kubas
+ * @param <SERIALIZER_TYPE> message type
+ */
+public interface OFSerializer <SERIALIZER_TYPE extends DataObject> extends OFGeneralSerializer {
+
+ /**
+ * Transforms POJO/DTO into byte message (ByteBuf).
+ * @param input object to be serialized
+ * @param outBuffer output buffer
+ */
+ public void serialize(SERIALIZER_TYPE input, ByteBuf outBuffer);
+
+}
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.api.extensibility;\r
+\r
+/**\r
+ * Serializer registry injector\r
+ * @author michal.polkorab\r
+ */\r
+public interface RegistryInjector {\r
+\r
+ /**\r
+ * Injects serializer registry\r
+ * @param serializerRegistry registry instance\r
+ */\r
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry);\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.api.extensibility;\r
+\r
+\r
+/**\r
+ * Stores and handles serializers \r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public interface SerializerRegistry {\r
+\r
+ /**\r
+ * Serializer registry provisioning\r
+ */\r
+ public void init();\r
+\r
+ /**\r
+ * @param msgTypeKey lookup key\r
+ * @return serializer or NullPointerException if no serializer was found\r
+ */\r
+ public <KEY_TYPE, SERIALIZER_TYPE extends OFGeneralSerializer> SERIALIZER_TYPE \r
+ getSerializer(MessageTypeKey<KEY_TYPE> msgTypeKey);\r
+\r
+ /**\r
+ * Registers serializer under key\r
+ * @param msgTypeKey lookup key\r
+ * @param serializer serializer implementation\r
+ */\r
+ public <KEY_TYPE> void\r
+ registerSerializer(MessageTypeKey<KEY_TYPE> msgTypeKey, OFGeneralSerializer serializer);\r
+}\r
package org.opendaylight.openflowjava.protocol.impl.connection;
-import java.util.concurrent.Future;
-
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT;
import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @author michal.polkorab
*/
public class SwitchConnectionProviderImpl implements SwitchConnectionProvider {
-
+
private static final Logger LOGGER = LoggerFactory
.getLogger(SwitchConnectionProviderImpl.class);
private SwitchConnectionHandler switchConnectionHandler;
private ServerFacade serverFacade;
private ConnectionConfiguration connConfig;
+ private SerializationFactory serializationFactory;
+ private SerializerRegistry serializerRegistry;
+
+ /** Constructor */
+ public SwitchConnectionProviderImpl() {
+ serializerRegistry = new SerializerRegistryImpl();
+ serializerRegistry.init();
+ serializationFactory = new SerializationFactory();
+ serializationFactory.setSerializerTable(serializerRegistry);
+ }
@Override
public void setConfiguration(ConnectionConfiguration connConfig) {
server.setSwitchIdleTimeout(connConfig.getSwitchIdleTimeout());
boolean tlsSupported = FEATURE_SUPPORT.REQUIRED.equals(connConfig.getTlsSupport());
server.setEncryption(tlsSupported);
-
+ server.setSerializationFactory(serializationFactory);
return server;
}
return serverFacade;
}
+ @Override
+ public <E extends DataObject> void registerCustomSerializer(MessageTypeKey<E> key,
+ OFSerializer<E> serializer) {
+ serializerRegistry.registerSerializer(key, serializer);
+ }
+
@Override
public void close() throws Exception {
shutdown();
public class OFEncoder extends MessageToByteEncoder<OfHeader> {
private static final Logger LOGGER = LoggerFactory.getLogger(OFEncoder.class);
-
+ private SerializationFactory serializationFactory;
+
/** Constructor of class */
public OFEncoder() {
LOGGER.trace("Creating OF13Encoder");
}
-
+
@Override
protected void encode(ChannelHandlerContext ctx, OfHeader msg, ByteBuf out)
throws Exception {
LOGGER.trace("Encoding");
try {
- SerializationFactory.messageToBuffer(msg.getVersion(), out, msg);
+ serializationFactory.messageToBuffer(msg.getVersion(), out, msg);
} catch(Exception e) {
LOGGER.error("Message serialization failed");
LOGGER.error(e.getMessage(), e);
}
}
+ /**
+ * @param serializationFactory
+ */
+ public void setSerializationFactory(SerializationFactory serializationFactory) {
+ this.serializationFactory = serializationFactory;
+ }
+
}
import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionAdapterFactory;
import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionFacade;
import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private SwitchConnectionHandler switchConnectionHandler;
private long switchIdleTimeout;
private boolean encryption;
-
+ private SerializationFactory serializationFactory;
+
/**
* default ctor
*/
ch.pipeline().addLast(COMPONENT_NAMES.OF_FRAME_DECODER.name(), new OFFrameDecoder());
ch.pipeline().addLast(COMPONENT_NAMES.OF_VERSION_DETECTOR.name(), new OFVersionDetector());
ch.pipeline().addLast(COMPONENT_NAMES.OF_DECODER.name(), new OFDecoder());
- ch.pipeline().addLast(COMPONENT_NAMES.OF_ENCODER.name(), new OFEncoder());
+ OFEncoder ofEncoder = new OFEncoder();
+ ofEncoder.setSerializationFactory(serializationFactory);
+ ch.pipeline().addLast(COMPONENT_NAMES.OF_ENCODER.name(), ofEncoder);
ch.pipeline().addLast(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER.name(), new DelegatingInboundHandler(connectionFacade));
if (!encryption) {
connectionFacade.fireConnectionReadyNotification();
public void setEncryption(boolean tlsSupported) {
encryption = tlsSupported;
}
-
+
+ /**
+ * @param serializationFactory
+ */
+ public void setSerializationFactory(SerializationFactory serializationFactory) {
+ this.serializationFactory = serializationFactory;
+ }
}
import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
import org.opendaylight.openflowjava.protocol.impl.connection.ServerFacade;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
channelInitializer.setEncryption(tlsSupported);
}
+ /**
+ * @param sf serialization factory
+ */
+ public void setSerializationFactory(SerializationFactory sf) {
+ channelInitializer.setSerializationFactory(sf);
+ }
}
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+\r
+/**\r
+ * More specific key for {@link SerializerRegistry}\r
+ * @author michal.polkorab\r
+ * @param <E> main type\r
+ * @param <F> specific type\r
+ */\r
+public class EnhancedMessageTypeKey<E, F> extends MessageTypeKey<E> {\r
+\r
+ private final Class<F> msgType2;\r
+\r
+ /**\r
+ * @param msgVersion\r
+ * @param msgType\r
+ * @param msgType2\r
+ */\r
+ public EnhancedMessageTypeKey(short msgVersion, Class<E> msgType, Class<F> msgType2) {\r
+ super(msgVersion, msgType);\r
+ this.msgType2 = msgType2;\r
+ }\r
+\r
+ /**\r
+ * @return more specific type\r
+ */\r
+ public Class<F> getMsgType2() {\r
+ return msgType2;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (this == obj)\r
+ return true;\r
+ if (!super.equals(obj))\r
+ return false;\r
+ if (getClass() != obj.getClass())\r
+ return false;\r
+ @SuppressWarnings("rawtypes")\r
+ EnhancedMessageTypeKey other = (EnhancedMessageTypeKey) obj;\r
+ if (msgType2 == null) {\r
+ if (other.msgType2 != null)\r
+ return false;\r
+ } else if (!msgType2.equals(other.msgType2))\r
+ return false;\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ return super.toString() + " msgType2: " + msgType2.getName();\r
+ }\r
+}\r
package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
+import io.netty.buffer.ByteBuf;
+
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;
public class HelloMessageFactory implements OFDeserializer<HelloMessage> {
private static HelloMessageFactory instance;
-
+ private static final byte HELLO_ELEMENT_HEADER_SIZE = 4;
+
private HelloMessageFactory() {
// do nothing, just singleton
}
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];
+ int[] versionBitmap = new int[(elementLength - HELLO_ELEMENT_HEADER_SIZE) / 4];
for (int i = 0; i < versionBitmap.length; i++) {
versionBitmap[i] = (int) input.readUnsignedInt();
}
+++ /dev/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.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<MessageTypeKey<?>, 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 <E extends DataObject> OFSerializer<E> getEncoder(MessageTypeKey<E> msgTypeKey) {
- return (OFSerializer<E>) table.get(msgTypeKey);
- }
-
-}
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpOpSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpShaSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpSpaSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpThaSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpTpaSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmEthDstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmEthSrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmEthTypeSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv4CodeSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv4TypeSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv6CodeSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIcmpv6TypeSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmInPhyPortSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmInPortSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpDscpSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpEcnSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpProtoSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv4DstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv4SrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6DstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6ExtHdrSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6FlabelSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6NdSllSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6NdTargetSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6NdTllSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmIpv6SrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMetadataSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsBosSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsLabelSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsTcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmPbbIsidSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmSctpDstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmSctpSrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTcpDstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTcpSrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTunnelIdSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmUdpDstSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmUdpSrcSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmVlanPcpSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmVlanVidSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OF13MatchEntriesRegistryHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;\r
+\r
+/**\r
+ * Initializes serializer registry with match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public class MatchEntriesInitializer {\r
+\r
+ /**\r
+ * Registers match entry serializers into provided registry\r
+ * @param serializerRegistry registry to be initialized with match entry serializers\r
+ */\r
+ public static void registerMatchEntrySerializers(SerializerRegistry serializerRegistry) {\r
+ // register OF v1.3 OpenflowBasicClass match entry serializers\r
+ Class<OpenflowBasicClass> oxmClass = OpenflowBasicClass.class;\r
+ OF13MatchEntriesRegistryHelper<OpenflowBasicClass> registryHelper =\r
+ new OF13MatchEntriesRegistryHelper<>(EncodeConstants.OF13_VERSION_ID, oxmClass, serializerRegistry);\r
+ registryHelper.registerSerializer(InPort.class, new OxmInPortSerializer());\r
+ registryHelper.registerSerializer(InPhyPort.class, new OxmInPhyPortSerializer());\r
+ registryHelper.registerSerializer(Metadata.class, new OxmMetadataSerializer());\r
+ registryHelper.registerSerializer(EthDst.class, new OxmEthDstSerializer());\r
+ registryHelper.registerSerializer(EthSrc.class, new OxmEthSrcSerializer());\r
+ registryHelper.registerSerializer(EthType.class, new OxmEthTypeSerializer());\r
+ registryHelper.registerSerializer(VlanVid.class, new OxmVlanVidSerializer());\r
+ registryHelper.registerSerializer(VlanPcp.class, new OxmVlanPcpSerializer());\r
+ registryHelper.registerSerializer(IpDscp.class, new OxmIpDscpSerializer());\r
+ registryHelper.registerSerializer(IpEcn.class, new OxmIpEcnSerializer());\r
+ registryHelper.registerSerializer(IpProto.class, new OxmIpProtoSerializer());\r
+ registryHelper.registerSerializer(Ipv4Src.class, new OxmIpv4SrcSerializer());\r
+ registryHelper.registerSerializer(Ipv4Dst.class, new OxmIpv4DstSerializer());\r
+ registryHelper.registerSerializer(TcpSrc.class, new OxmTcpSrcSerializer());\r
+ registryHelper.registerSerializer(TcpDst.class, new OxmTcpDstSerializer());\r
+ registryHelper.registerSerializer(UdpSrc.class, new OxmUdpSrcSerializer());\r
+ registryHelper.registerSerializer(UdpDst.class, new OxmUdpDstSerializer());\r
+ registryHelper.registerSerializer(SctpSrc.class, new OxmSctpSrcSerializer());\r
+ registryHelper.registerSerializer(SctpDst.class, new OxmSctpDstSerializer());\r
+ registryHelper.registerSerializer(Icmpv4Type.class, new OxmIcmpv4TypeSerializer());\r
+ registryHelper.registerSerializer(Icmpv4Code.class, new OxmIcmpv4CodeSerializer());\r
+ registryHelper.registerSerializer(ArpOp.class, new OxmArpOpSerializer());\r
+ registryHelper.registerSerializer(ArpSpa.class, new OxmArpSpaSerializer());\r
+ registryHelper.registerSerializer(ArpTpa.class, new OxmArpTpaSerializer());\r
+ registryHelper.registerSerializer(ArpSha.class, new OxmArpShaSerializer());\r
+ registryHelper.registerSerializer(ArpTha.class, new OxmArpThaSerializer());\r
+ registryHelper.registerSerializer(Ipv6Src.class, new OxmIpv6SrcSerializer());\r
+ registryHelper.registerSerializer(Ipv6Dst.class, new OxmIpv6DstSerializer());\r
+ registryHelper.registerSerializer(Ipv6Flabel.class, new OxmIpv6FlabelSerializer());\r
+ registryHelper.registerSerializer(Icmpv6Type.class, new OxmIcmpv6TypeSerializer());\r
+ registryHelper.registerSerializer(Icmpv6Code.class, new OxmIcmpv6CodeSerializer());\r
+ registryHelper.registerSerializer(Ipv6NdTarget.class, new OxmIpv6NdTargetSerializer());\r
+ registryHelper.registerSerializer(Ipv6NdSll.class, new OxmIpv6NdSllSerializer());\r
+ registryHelper.registerSerializer(Ipv6NdTll.class, new OxmIpv6NdTllSerializer());\r
+ registryHelper.registerSerializer(MplsLabel.class, new OxmMplsLabelSerializer());\r
+ registryHelper.registerSerializer(MplsTc.class, new OxmMplsTcSerializer());\r
+ registryHelper.registerSerializer(MplsBos.class, new OxmMplsBosSerializer());\r
+ registryHelper.registerSerializer(PbbIsid.class, new OxmPbbIsidSerializer());\r
+ registryHelper.registerSerializer(TunnelId.class, new OxmTunnelIdSerializer());\r
+ registryHelper.registerSerializer(Ipv6Exthdr.class, new OxmIpv6ExtHdrSerializer());\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.BarrierInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoReplyInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.FlowModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetAsyncRequestMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetConfigInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetFeaturesInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GetQueueConfigInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.GroupModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MeterModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10BarrierInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FlowModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10HelloInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PacketOutInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PortModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10QueueGetConfigInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PacketOutInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.PortModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.RoleRequestInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetAsyncInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetConfigMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.factories.TableModInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.util.CommonMessageRegistryHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class MessageFactoryInitializer {\r
+\r
+ /**\r
+ * Registers message serializers into provided registry\r
+ * @param serializerRegistry registry to be initialized with message serializers\r
+ */\r
+ public static void registerMessageSerializers(SerializerRegistry serializerRegistry) {\r
+ // register OF v1.0 message serializers\r
+ short version = EncodeConstants.OF10_VERSION_ID;\r
+ CommonMessageRegistryHelper registryHelper = new CommonMessageRegistryHelper(version, serializerRegistry);\r
+ registryHelper.registerSerializer(BarrierInput.class, new OF10BarrierInputMessageFactory());\r
+ registryHelper.registerSerializer(EchoInput.class, new EchoInputMessageFactory());\r
+ registryHelper.registerSerializer(EchoReplyInput.class, new EchoReplyInputMessageFactory());\r
+ registryHelper.registerSerializer(FlowModInput.class, new OF10FlowModInputMessageFactory());\r
+ registryHelper.registerSerializer(GetConfigInput.class, new GetConfigInputMessageFactory());\r
+ registryHelper.registerSerializer(GetFeaturesInput.class, new GetFeaturesInputMessageFactory());\r
+ registryHelper.registerSerializer(GetQueueConfigInput.class, new OF10QueueGetConfigInputMessageFactory());\r
+ registryHelper.registerSerializer(HelloInput.class, new OF10HelloInputMessageFactory());\r
+ registryHelper.registerSerializer(MultipartRequestInput.class, new OF10StatsRequestInputFactory());\r
+ registryHelper.registerSerializer(PacketOutInput.class, new OF10PacketOutInputMessageFactory());\r
+ registryHelper.registerSerializer(PortModInput.class, new OF10PortModInputMessageFactory());\r
+ registryHelper.registerSerializer(SetConfigInput.class, new SetConfigMessageFactory());\r
+ // register OF v1.0 message serializers\r
+ version = EncodeConstants.OF13_VERSION_ID;\r
+ registryHelper = new CommonMessageRegistryHelper(version, serializerRegistry);\r
+ registryHelper.registerSerializer(BarrierInput.class, new BarrierInputMessageFactory());\r
+ registryHelper.registerSerializer(EchoInput.class, new EchoInputMessageFactory());\r
+ registryHelper.registerSerializer(EchoReplyInput.class, new EchoReplyInputMessageFactory());\r
+ registryHelper.registerSerializer(FlowModInput.class, new FlowModInputMessageFactory());\r
+ registryHelper.registerSerializer(GetAsyncInput.class, new GetAsyncRequestMessageFactory());\r
+ registryHelper.registerSerializer(GetConfigInput.class, new GetConfigInputMessageFactory());\r
+ registryHelper.registerSerializer(GetFeaturesInput.class, new GetFeaturesInputMessageFactory());\r
+ registryHelper.registerSerializer(GetQueueConfigInput.class, new GetQueueConfigInputMessageFactory());\r
+ registryHelper.registerSerializer(GroupModInput.class, new GroupModInputMessageFactory());\r
+ registryHelper.registerSerializer(HelloInput.class, new HelloInputMessageFactory());\r
+ registryHelper.registerSerializer(MeterModInput.class, new MeterModInputMessageFactory());\r
+ registryHelper.registerSerializer(MultipartRequestInput.class, new MultipartRequestInputFactory());\r
+ registryHelper.registerSerializer(PacketOutInput.class, new PacketOutInputMessageFactory());\r
+ registryHelper.registerSerializer(PortModInput.class, new PortModInputMessageFactory());\r
+ registryHelper.registerSerializer(RoleRequestInput.class, new RoleRequestInputMessageFactory());\r
+ registryHelper.registerSerializer(SetAsyncInput.class, new SetAsyncInputMessageFactory());\r
+ registryHelper.registerSerializer( SetConfigInput.class, new SetConfigMessageFactory());\r
+ registryHelper.registerSerializer(TableModInput.class, new TableModInputMessageFactory());\r
+ }\r
+}\r
+++ /dev/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.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 <E> message type
- */
-public interface OFSerializer <E extends DataObject> {
-
- /**
- * 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();
-}
import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* @author michal.polkorab
*/
public class SerializationFactory {
- private static final Logger LOGGER = LoggerFactory
- .getLogger(SerializationFactory.class);
+ private SerializerRegistry registry;
+
/**
* 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 <E extends DataObject> void messageToBuffer(short version, ByteBuf out, E message) {
- @SuppressWarnings("unchecked")
- MessageTypeKey<E> msgTypeKey = new MessageTypeKey<>(version, (Class<E>) message.getClass());
- OFSerializer<E> 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());
+ public void messageToBuffer(short version, ByteBuf out, DataObject message) {
+ OFSerializer<DataObject> serializer = registry.getSerializer(
+ new MessageTypeKey<>(version, message.getClass()));
+ if (serializer != null) {
+ serializer.serialize(message, out);
}
}
+
+ /**
+ * @param serializerRegistry registry with serializers
+ */
+ public void setSerializerTable(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
+ }
+
}
--- /dev/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.serialization;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.OF13ActionsSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.OF13InstructionsSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.OF13MatchSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
+
+/**
+ * Stores and handles serializers
+ * @author michal.polkorab
+ * @author timotej.kubas
+ */
+public class SerializerRegistryImpl implements SerializerRegistry {
+
+ private static final short OF10 = EncodeConstants.OF10_VERSION_ID;
+ private static final short OF13 = EncodeConstants.OF13_VERSION_ID;
+ private Map<MessageTypeKey<?>, OFGeneralSerializer> registry;
+
+
+ @Override
+ public void init() {
+ registry = new HashMap<>();
+ // Openflow message type serializers
+ MessageFactoryInitializer.registerMessageSerializers(this);
+
+ // common structure serializers
+ registerSerializer(new MessageTypeKey<>(OF10, MatchV10.class), new OF10MatchSerializer());
+ registerSerializer(new MessageTypeKey<>(OF13, Match.class), new OF13MatchSerializer());
+ registerSerializer(new MessageTypeKey<>(OF10, Action.class), new OF10ActionsSerializer());
+ registerSerializer(new MessageTypeKey<>(OF13, Action.class), new OF13ActionsSerializer());
+ registerSerializer(new MessageTypeKey<>(OF13, Instruction.class), new OF13InstructionsSerializer());
+
+ // match entry serializers
+ MatchEntriesInitializer.registerMatchEntrySerializers(this);
+ }
+
+ /**
+ * @param msgTypeKey
+ * @return encoder for current type of message (msgTypeKey)
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public <KEY_TYPE, SERIALIZER_TYPE extends OFGeneralSerializer> SERIALIZER_TYPE getSerializer(
+ MessageTypeKey<KEY_TYPE> msgTypeKey) {
+ OFGeneralSerializer serializer = registry.get(msgTypeKey);
+ if (serializer == null) {
+ if (msgTypeKey instanceof EnhancedMessageTypeKey) {
+ EnhancedMessageTypeKey<KEY_TYPE, ?> key = (EnhancedMessageTypeKey<KEY_TYPE, ?>) msgTypeKey;
+ throw new NullPointerException("Serializer for key: " + key.toString()
+ + " was not found");
+ }
+ throw new NullPointerException("Serializer for key: " + msgTypeKey.toString()
+ + " was not found");
+ }
+ return (SERIALIZER_TYPE) serializer;
+ }
+
+ @Override
+ public <KEY_TYPE> void registerSerializer(
+ MessageTypeKey<KEY_TYPE> msgTypeKey, OFGeneralSerializer serializer) {
+ if ((msgTypeKey == null) || (serializer == null)) {
+ throw new NullPointerException("MessageTypeKey or Serializer is null");
+ }
+ if (serializer instanceof RegistryInjector) {
+ ((RegistryInjector) serializer).injectSerializerRegistry(this);
+ }
+ registry.put(msgTypeKey, serializer);
+ }
+}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.BarrierInput;
/**
public class BarrierInputMessageFactory implements OFSerializer<BarrierInput> {
/** 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);
- }
+ private static final byte MESSAGE_TYPE = 20;
@Override
- public int computeLength(BarrierInput message) {
- return MESSAGE_LENGTH;
+ public void serialize(BarrierInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE);
}
- @Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
- }
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.EchoInput;
/**
public class EchoInputMessageFactory implements OFSerializer<EchoInput> {
/** 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;
- }
+ private static final byte MESSAGE_TYPE = 2;
@Override
- public void messageToBuffer(short version, ByteBuf out, EchoInput message) {
- ByteBufUtils.writeOFHeader(instance, message, out);
+ public void serialize(EchoInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
byte[] data = message.getData();
if (data != null) {
- out.writeBytes(data);
+ outBuffer.writeBytes(data);
}
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
- @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;
- }
-
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.EchoReplyInput;
/**
public class EchoReplyInputMessageFactory implements OFSerializer<EchoReplyInput>{
/** 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;
- }
+ private static final byte MESSAGE_TYPE = 3;
@Override
- public void messageToBuffer(short version, ByteBuf out,
- EchoReplyInput message) {
- ByteBufUtils.writeOFHeader(instance, message, out);
+ public void serialize(EchoReplyInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE);
byte[] data = message.getData();
if (data != null) {
- out.writeBytes(data);
+ outBuffer.writeBytes(data);
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
}
- @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;
- }
}
+++ /dev/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.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<ExperimenterInput>{
-
- /** 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;
- }
-
-}
import java.util.HashMap;
import java.util.Map;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
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.openflowjava.protocol.impl.util.CodingUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
/**
* @author timotej.kubas
* @author michal.polkorab
*/
-public class FlowModInputMessageFactory implements OFSerializer<FlowModInput> {
+public class FlowModInputMessageFactory implements OFSerializer<FlowModInput>, RegistryInjector {
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.getInstruction(), out);
- }
+ private SerializerRegistry registry;
@Override
- public int computeLength(FlowModInput message) {
- return MESSAGE_LENGTH + MatchSerializer.computeMatchLength(message.getMatch())
- + InstructionsSerializer.computeInstructionsLength(message.getInstruction());
+ public void serialize(FlowModInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeLong(message.getCookie().longValue());
+ outBuffer.writeLong(message.getCookieMask().longValue());
+ outBuffer.writeByte(message.getTableId().getValue().byteValue());
+ outBuffer.writeByte(message.getCommand().getIntValue());
+ outBuffer.writeShort(message.getIdleTimeout().intValue());
+ outBuffer.writeShort(message.getHardTimeout().intValue());
+ outBuffer.writeShort(message.getPriority());
+ outBuffer.writeInt(message.getBufferId().intValue());
+ outBuffer.writeInt(message.getOutPort().getValue().intValue());
+ outBuffer.writeInt(message.getOutGroup().intValue());
+ outBuffer.writeShort(createFlowModFlagsBitmask(message.getFlags()));
+ ByteBufUtils.padBuffer(PADDING_IN_FLOW_MOD_MESSAGE, outBuffer);
+ registry.<Match, OFSerializer<Match>>getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class))
+ .serialize(message.getMatch(), outBuffer);
+ OFSerializer<Instruction> instructionSerializer =
+ registry.getSerializer(new MessageTypeKey<>(message.getVersion(), Instruction.class));
+ CodingUtils.serializeList(message.getInstruction(), instructionSerializer, outBuffer);
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
@Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
}
private static int createFlowModFlagsBitmask(FlowModFlags flags) {
flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap);
return flowModFlagBitmask;
}
-
-
+
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.GetAsyncInput;
/**
*/
public class GetAsyncRequestMessageFactory implements OFSerializer<GetAsyncInput> {
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;
+ public void serialize(GetAsyncInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE);
}
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.GetConfigInput;
/**
public class GetConfigInputMessageFactory implements OFSerializer<GetConfigInput> {
/** 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;
- }
+ private static final byte MESSAGE_TYPE = 7;
@Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
+ public void serialize(GetConfigInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE);
}
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.GetFeaturesInput;
/**
public class GetFeaturesInputMessageFactory implements OFSerializer<GetFeaturesInput>{
/** 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;
- }
+ private static final byte MESSAGE_TYPE = 5;
@Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
+ public void serialize(GetFeaturesInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE);
}
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.GetQueueConfigInput;
/**
private static final byte MESSAGE_TYPE = 22;
private static final byte PADDING_IN_GET_QUEUE_CONFIG_MESSAGE = 4;
- private static final int MESSAGE_LENGTH = 16;
-
- private static GetQueueConfigInputMessageFactory instance;
-
-
- private GetQueueConfigInputMessageFactory() {
- // singleton
- }
-
-
- /**
- * @return singleton factory
- */
- public static synchronized GetQueueConfigInputMessageFactory getInstance(){
- if(instance == null){
- instance = new GetQueueConfigInputMessageFactory();
- }
- return instance;
- }
-
- @Override
- public void messageToBuffer(short version, ByteBuf out, GetQueueConfigInput message){
- ByteBufUtils.writeOFHeader(instance, message, out);
- out.writeInt(message.getPort().getValue().intValue());
- ByteBufUtils.padBuffer(PADDING_IN_GET_QUEUE_CONFIG_MESSAGE, out);
- }
@Override
- public int computeLength(GetQueueConfigInput message){
- return MESSAGE_LENGTH;
+ public void serialize(GetQueueConfigInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeInt(message.getPort().getValue().intValue());
+ ByteBufUtils.padBuffer(PADDING_IN_GET_QUEUE_CONFIG_MESSAGE, outBuffer);
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
- @Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
- }
}
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.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
* @author timotej.kubas
* @author michal.polkorab
*/
-public class GroupModInputMessageFactory implements OFSerializer<GroupModInput> {
+public class GroupModInputMessageFactory implements OFSerializer<GroupModInput>, RegistryInjector {
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);
- }
+ private SerializerRegistry registry;
@Override
- public int computeLength(GroupModInput message) {
- return MESSAGE_LENGTH + computeLengthOfBuckets(message.getBucketsList());
+ public void serialize(GroupModInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeShort(message.getCommand().getIntValue());
+ outBuffer.writeByte(message.getType().getIntValue());
+ ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, outBuffer);
+ outBuffer.writeInt(message.getGroupId().getValue().intValue());
+ serializerBuckets(message.getBucketsList(), outBuffer);
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
- @Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
- }
-
- private static void encodeBuckets(List<BucketsList> buckets, ByteBuf outBuffer) {
+ private void serializerBuckets(List<BucketsList> buckets, ByteBuf outBuffer) {
if (buckets != null) {
for (BucketsList currentBucket : buckets) {
- outBuffer.writeShort(computeLengthOfBucket(currentBucket));
+ int bucketLengthIndex = outBuffer.writerIndex();
+ outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
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.getAction(), outBuffer);
+ OFSerializer<Action> actionSerializer = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class));
+ CodingUtils.serializeList(currentBucket.getAction(), actionSerializer, outBuffer);
+ outBuffer.setShort(bucketLengthIndex, outBuffer.writerIndex() - bucketLengthIndex);
}
}
}
-
- private static int computeLengthOfBucket(BucketsList bucket) {
- int lengthOfBuckets = 0;
- if (bucket != null) {
- lengthOfBuckets = LENGTH_OF_BUCKET_STRUCTURE
- + ActionsSerializer.computeLengthOfActions(bucket.getAction());
- }
- return lengthOfBuckets;
- }
-
- private static int computeLengthOfBuckets(List<BucketsList> buckets) {
- int lengthOfBuckets = 0;
- if (buckets != null) {
- for (BucketsList currentBucket : buckets) {
- lengthOfBuckets += LENGTH_OF_BUCKET_STRUCTURE
- + ActionsSerializer.computeLengthOfActions(currentBucket.getAction());
- }
- }
- return lengthOfBuckets;
+
+ @Override
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
}
-
}
import io.netty.buffer.ByteBuf;
-import java.util.List;
-
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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;
/** 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 HelloInputMessageFactory() {
- // do nothing, just singleton
- }
-
- /**
- * @return singleton factory
- */
- public static synchronized HelloInputMessageFactory getInstance() {
- if (instance == null) {
- instance = new HelloInputMessageFactory();
- }
- return instance;
- }
+ private static final byte HELLO_ELEMENT_HEADER_SIZE = 4;
- @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);
- ByteBufUtils.padBuffer(writtenBytesDiff, out);
- }
-
- @Override
- public int computeLength(HelloInput message) {
- int length = MESSAGE_LENGTH;
- List<Elements> 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) {
+ private static void serializeElementsList(HelloInput message, ByteBuf output) {
int[] versionBitmap;
if (message.getElements() != null) {
for (Elements currElement : message.getElements()) {
+ int elementStartIndex = output.writerIndex();
output.writeShort(currElement.getType().getIntValue());
if (currElement.getType().equals(HelloElementType.VERSIONBITMAP)) {
- short bitmapLength = computeVersionBitmapLength(currElement);
- output.writeShort(bitmapLength);
+ int elementLengthIndex = output.writerIndex();
+ output.writeShort(EncodeConstants.EMPTY_LENGTH);
versionBitmap = ByteBufUtils.fillBitMaskFromList(currElement.getVersionBitmap());
for (int i = 0; i < versionBitmap.length; i++) {
output.writeInt(versionBitmap[i]);
}
- int padding = bitmapLength - versionBitmap.length * 4 - HELLO_ELEMENT_HEADER_SIZE;
+ int length = output.writerIndex() - elementStartIndex;
+ int padding = length - versionBitmap.length * 4 - HELLO_ELEMENT_HEADER_SIZE;
ByteBufUtils.padBuffer(padding , output);
+ output.setShort(elementLengthIndex, output.writerIndex() - elementStartIndex);
}
}
}
}
-
- 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);
+
+ @Override
+ public void serialize(HelloInput message, ByteBuf outBuffer) {
+ int startWriterIndex = outBuffer.writerIndex();
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ serializeElementsList(message, outBuffer);
+ int endWriterIndex = outBuffer.writerIndex();
+ int paddingRemainder = (endWriterIndex - startWriterIndex) % EncodeConstants.PADDING;
+ if (paddingRemainder != 0) {
+ ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, outBuffer);
}
- return elementlength;
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
+
}
import java.util.List;
import java.util.Map;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.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;
*/
public class MeterModInputMessageFactory implements OFSerializer<MeterModInput> {
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;
+ public void serialize(MeterModInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeShort(message.getCommand().getIntValue());
+ outBuffer.writeShort(createMeterFlagsBitmask(message.getFlags()));
+ outBuffer.writeInt(message.getMeterId().getValue().intValue());
+ serializeBands(message.getBands(), outBuffer);
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
private static int createMeterFlagsBitmask(MeterFlags flags) {
return meterFlagBitmask;
}
- private static void encodeBands(List<Bands> bands, ByteBuf outBuffer) {
+ private static void serializeBands(List<Bands> bands, ByteBuf outBuffer) {
if (bands != null) {
for (Bands currentBand : bands) {
MeterBand meterBand = currentBand.getMeterBand();
outBuffer.writeInt(meterBand.getRate().intValue());
outBuffer.writeInt(meterBand.getBurstSize().intValue());
}
-
+
}
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.api.extensibility.HeaderSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils;
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.common.instruction.rev130731.Experimenter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
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.match.grouping.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.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.MultipartRequestAggregateCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableFeaturesCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregate;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroup;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeter;
* @author timotej.kubas
* @author michal.polkorab
*/
-public class MultipartRequestInputFactory implements OFSerializer<MultipartRequestInput> {
+public class MultipartRequestInputFactory implements OFSerializer<MultipartRequestInput>, RegistryInjector {
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 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_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;
- }
+ private SerializerRegistry registry;
@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);
+ public void serialize(MultipartRequestInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeShort(message.getType().getIntValue());
+ outBuffer.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));
+ ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_MESSAGE, outBuffer);
if (message.getMultipartRequestBody() instanceof MultipartRequestDescCase){
- encodeDescBody(message.getMultipartRequestBody(), out);
+ serializeDescBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestFlowCase) {
- encodeFlowBody(message.getMultipartRequestBody(), out);
+ serializeFlowBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregateCase) {
- encodeAggregateBody(message.getMultipartRequestBody(), out);
+ serializeAggregateBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestTableCase) {
- encodeTableBody(message.getMultipartRequestBody(), out);
+ serializeTableBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStatsCase) {
- encodePortStatsBody(message.getMultipartRequestBody(), out);
+ serializePortStatsBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestQueueCase) {
- encodeQueueBody(message.getMultipartRequestBody(), out);
+ serializeQueueBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupCase) {
- encodeGroupStatsBody(message.getMultipartRequestBody(), out);
+ serializeeGroupStatsBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupDescCase) {
- encodeGroupDescBody(message.getMultipartRequestBody(), out);
+ serializeGroupDescBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestGroupFeaturesCase) {
- encodeGroupFeaturesBody(message.getMultipartRequestBody(), out);
+ serializeGroupFeaturesBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterCase) {
- encodeMeterBody(message.getMultipartRequestBody(), out);
+ serializeMeterBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterConfigCase) {
- encodeMeterConfigBody(message.getMultipartRequestBody(), out);
+ serializeMeterConfigBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestMeterFeaturesCase) {
- encodeMeterFeaturesBody(message.getMultipartRequestBody(), out);
+ serializeMeterFeaturesBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestTableFeaturesCase) {
- encodeTableFeaturesBody(message.getMultipartRequestBody(), out);
+ serializeTableFeaturesBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestPortDescCase) {
- encodePortDescBody(message.getMultipartRequestBody(), out);
- } else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenterCase) {
- 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)) {
- MultipartRequestFlowCase bodyCase = (MultipartRequestFlowCase) message.getMultipartRequestBody();
- MultipartRequestFlow body = bodyCase.getMultipartRequestFlow();
- length += FLOW_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());
- } else if (type.equals(MultipartType.OFPMPAGGREGATE)) {
- MultipartRequestAggregateCase bodyCase = (MultipartRequestAggregateCase) message.getMultipartRequestBody();
- MultipartRequestAggregate body = bodyCase.getMultipartRequestAggregate();
- 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)) {
- MultipartRequestTableFeaturesCase bodyCase = (MultipartRequestTableFeaturesCase) message.getMultipartRequestBody();
- MultipartRequestTableFeatures body = bodyCase.getMultipartRequestTableFeatures();
- length += computeTableFeaturesLength(body);
- } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) {
- MultipartRequestExperimenterCase bodyCase = (MultipartRequestExperimenterCase) message.getMultipartRequestBody();
- MultipartRequestExperimenter body = bodyCase.getMultipartRequestExperimenter();
- length += EXPERIMENTER_BODY_LENGTH;
- if (body.getData() != null) {
- length += body.getData().length;
- }
+ serializePortDescBody(message.getMultipartRequestBody(), outBuffer);
}
- return length;
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
- private static int computeTableFeaturesLength(MultipartRequestTableFeatures body) {
- int length = 0;
- if (body != null && body.getTableFeatures() != null) {
- List<TableFeatures> tableFeatures = body.getTableFeatures();
- for (TableFeatures feature : tableFeatures) {
- length += computeSingleTableFeatureLength(feature);
- }
- }
- return length;
- }
-
- private static int computeSingleTableFeatureLength(TableFeatures feature) {
- return TABLE_FEATURES_LENGTH + computeTableFeatPropsLength(feature);
- }
-
- private static int computeTableFeatPropsLength(TableFeatures feature) {
- int length = 0;
- List<TableFeatureProperties> 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.getInstruction().size() * STRUCTURE_HEADER_LENGTH;
- length += paddingNeeded(length);
- } else if (featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class) != null) {
- NextTableRelatedTableFeatureProperty property =
- featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class);
- length += property.getNextTableIds().size();
- length += paddingNeeded(length);
- } else if (featProp.getAugmentation(ActionRelatedTableFeatureProperty.class) != null) {
- ActionRelatedTableFeatureProperty property =
- featProp.getAugmentation(ActionRelatedTableFeatureProperty.class);
- length += property.getAction().size() * STRUCTURE_HEADER_LENGTH;
- length += paddingNeeded(length);
- } else if (featProp.getAugmentation(OxmRelatedTableFeatureProperty.class) != null) {
- OxmRelatedTableFeatureProperty property =
- featProp.getAugmentation(OxmRelatedTableFeatureProperty.class);
- length += property.getMatchEntries().size() * STRUCTURE_HEADER_LENGTH;
- length += paddingNeeded(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;
- }
- length += paddingNeeded(length);
- }
- }
- }
- return length;
- }
-
-
-
private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) {
int multipartRequestFlagsBitmask = 0;
Map<Integer, Boolean> multipartRequestFlagsMap = new HashMap<>();
* @param multipartRequestBody
* @param output
*/
- private void encodeDescBody(MultipartRequestBody multipartRequestBody,
+ private void serializeDescBody(MultipartRequestBody multipartRequestBody,
ByteBuf output) {
// The body of MultiPartRequestDesc is empty
}
* @param multipartRequestBody
* @param out
*/
- private void encodeTableBody(MultipartRequestBody multipartRequestBody,
+ private void serializeTableBody(MultipartRequestBody multipartRequestBody,
ByteBuf out) {
// The body of MultiPartTable is empty
}
* @param multipartRequestBody
* @param out
*/
- private void encodeGroupDescBody(MultipartRequestBody multipartRequestBody,
+ private void serializeGroupDescBody(MultipartRequestBody multipartRequestBody,
ByteBuf out) {
// The body of MultiPartRequestGroupDesc is empty
}
* @param multipartRequestBody
* @param out
*/
- private void encodeGroupFeaturesBody(
+ private void serializeGroupFeaturesBody(
MultipartRequestBody multipartRequestBody, ByteBuf out) {
// The body of MultiPartRequestGroupFeatures is empty
}
* @param multipartRequestBody
* @param out
*/
- private void encodeMeterFeaturesBody(
+ private void serializeMeterFeaturesBody(
MultipartRequestBody multipartRequestBody, ByteBuf out) {
// The body of MultiPartMeterFeatures is empty
}
* @param multipartRequestBody
* @param out
*/
- private void encodePortDescBody(MultipartRequestBody multipartRequestBody,
+ private void serializePortDescBody(MultipartRequestBody multipartRequestBody,
ByteBuf out) {
// The body of MultiPartPortDesc is empty
}
- private static void encodeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private void serializeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestFlowCase flowCase = (MultipartRequestFlowCase) multipartRequestBody;
MultipartRequestFlow flow = flowCase.getMultipartRequestFlow();
output.writeByte(flow.getTableId().byteValue());
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);
+ OFSerializer<Match> serializer = registry.getSerializer(new MessageTypeKey<>(
+ EncodeConstants.OF13_VERSION_ID, Match.class));
+ serializer.serialize(flow.getMatch(), output);
}
- private static void encodeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private void serializeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestAggregateCase aggregateCase = (MultipartRequestAggregateCase) multipartRequestBody;
MultipartRequestAggregate aggregate = aggregateCase.getMultipartRequestAggregate();
output.writeByte(aggregate.getTableId().byteValue());
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);
+ OFSerializer<Match> serializer = registry.getSerializer(new MessageTypeKey<>(
+ EncodeConstants.OF13_VERSION_ID, Match.class));
+ serializer.serialize(aggregate.getMatch(), output);
}
- private static void encodePortStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private static void serializePortStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestPortStatsCase portstatsCase = (MultipartRequestPortStatsCase) multipartRequestBody;
MultipartRequestPortStats portstats = portstatsCase.getMultipartRequestPortStats();
output.writeInt(portstats.getPortNo().intValue());
ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY, output);
}
- private static void encodeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private static void serializeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestQueueCase queueCase = (MultipartRequestQueueCase) multipartRequestBody;
MultipartRequestQueue queue = queueCase.getMultipartRequestQueue();
output.writeInt(queue.getPortNo().intValue());
output.writeInt(queue.getQueueId().intValue());
}
- private static void encodeGroupStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private static void serializeeGroupStatsBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestGroupCase groupStatsCase = (MultipartRequestGroupCase) multipartRequestBody;
MultipartRequestGroup groupStats = groupStatsCase.getMultipartRequestGroup();
output.writeInt(groupStats.getGroupId().getValue().intValue());
ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY, output);
}
- private static void encodeMeterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private static void serializeMeterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestMeterCase meterCase = (MultipartRequestMeterCase) multipartRequestBody;
MultipartRequestMeter meter = meterCase.getMultipartRequestMeter();
output.writeInt(meter.getMeterId().getValue().intValue());
ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_BODY, output);
}
- private static void encodeMeterConfigBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private static void serializeMeterConfigBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestMeterConfigCase meterConfigCase = (MultipartRequestMeterConfigCase) multipartRequestBody;
MultipartRequestMeterConfig meterConfig = meterConfigCase.getMultipartRequestMeterConfig();
output.writeInt(meterConfig.getMeterId().getValue().intValue());
ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY, output);
}
- private static void encodeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
- MultipartRequestExperimenterCase experimenterCase = (MultipartRequestExperimenterCase) multipartRequestBody;
- MultipartRequestExperimenter experimenter = experimenterCase.getMultipartRequestExperimenter();
- 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) {
+ private void serializeTableFeaturesBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
if (multipartRequestBody != null) {
MultipartRequestTableFeaturesCase tableFeaturesCase = (MultipartRequestTableFeaturesCase) multipartRequestBody;
MultipartRequestTableFeatures tableFeatures = tableFeaturesCase.getMultipartRequestTableFeatures();
if(tableFeatures.getTableFeatures() != null) {
for (TableFeatures currTableFeature : tableFeatures.getTableFeatures()) {
- int length = computeSingleTableFeatureLength(currTableFeature);
- length += paddingNeeded(length);
- output.writeShort(length);
+ int tableFeatureLengthIndex = output.writerIndex();
+ output.writeShort(EncodeConstants.EMPTY_LENGTH);
output.writeByte(currTableFeature.getTableId());
ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES_BODY, output);
output.writeBytes(currTableFeature.getName().getBytes());
output.writeInt(createTableConfigBitmask(currTableFeature.getConfig()));
output.writeInt(currTableFeature.getMaxEntries().intValue());
writeTableFeatureProperties(output, currTableFeature.getTableFeatureProperties());
+ output.setShort(tableFeatureLengthIndex, output.writerIndex() - tableFeatureLengthIndex);
}
}
}
}
- private static void writeTableFeatureProperties(ByteBuf output, List<TableFeatureProperties> props) {
+ private void writeTableFeatureProperties(ByteBuf output, List<TableFeatureProperties> props) {
if (props != null) {
for (TableFeatureProperties property : props) {
TableFeaturesPropType type = property.getType();
}
}
- private static void writeInstructionRelatedTableProperty(ByteBuf output,
+ private void writeInstructionRelatedTableProperty(ByteBuf output,
TableFeatureProperties property, byte code) {
output.writeShort(code);
List<Instruction> instructions = property.
}
padding = paddingNeeded(length);
output.writeShort(length);
- InstructionsSerializer.encodeInstructionIds(instructions, output);
+ HeaderSerializer<Instruction> instructionSerializer = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Instruction.class));
+ CodingUtils.serializeHeaders(instructions, instructionSerializer, output);
} else {
padding = paddingNeeded(length);
output.writeShort(length);
return result;
}
- private static void writeActionsRelatedTableProperty(ByteBuf output,
+ private void writeActionsRelatedTableProperty(ByteBuf output,
TableFeatureProperties property, byte code) {
output.writeShort(code);
List<Action> actions = property.
length += actions.size() * STRUCTURE_HEADER_LENGTH;
padding += paddingNeeded(length);
output.writeShort(length);
- ActionsSerializer.encodeActionIds(actions, output);
+ HeaderSerializer<Action> actionSerializer = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class));
+ CodingUtils.serializeHeaders(actions, actionSerializer, output);
} else {
padding = paddingNeeded(length);
output.writeShort(length);
ByteBufUtils.padBuffer(padding, output);
}
- private static void writeOxmRelatedTableProperty(ByteBuf output,
+ private void writeOxmRelatedTableProperty(ByteBuf output,
TableFeatureProperties property, byte code) {
output.writeShort(code);
List<MatchEntries> entries = property.
length += entries.size() * STRUCTURE_HEADER_LENGTH;
padding = paddingNeeded(length);
output.writeShort(length);
- MatchSerializer.encodeMatchIds(entries, output);
+
+ for (MatchEntries entry : entries) {
+ HeaderSerializer<MatchEntries> entrySerializer = registry.getSerializer(
+ new EnhancedMessageTypeKey<>(EncodeConstants.OF13_VERSION_ID,
+ entry.getOxmClass(), entry.getOxmMatchField()));
+ entrySerializer.serializeHeader(entry, output);
+ }
} else {
padding = paddingNeeded(length);
output.writeShort(length);
tableConfigBitmask = ByteBufUtils.fillBitMaskFromMap(tableConfigMap);
return tableConfigBitmask;
}
+
+ @Override
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
+ }
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.BarrierInput;
/**
public class OF10BarrierInputMessageFactory implements OFSerializer<BarrierInput> {
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);
+ public void serialize(BarrierInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE);
}
- @Override
- public int computeLength(BarrierInput message) {
- return MESSAGE_LENGTH;
- }
-
- @Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
- }
}
import java.util.HashMap;
import java.util.Map;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
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.openflowjava.protocol.impl.util.CodingUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
/**
* Translates FlowMod messages
* @author michal.polkorab
*/
-public class OF10FlowModInputMessageFactory implements OFSerializer<FlowModInput> {
+public class OF10FlowModInputMessageFactory implements OFSerializer<FlowModInput>, RegistryInjector {
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.getAction());
- }
-
- @Override
- public int computeLength(FlowModInput message) {
- return MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getAction());
- }
+ private SerializerRegistry registry;
@Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
+ public void serialize(FlowModInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ OFSerializer<MatchV10> matchSerializer = registry.getSerializer(new MessageTypeKey<>(
+ message.getVersion(), MatchV10.class));
+ matchSerializer.serialize(message.getMatchV10(), outBuffer);
+ outBuffer.writeLong(message.getCookie().longValue());
+ outBuffer.writeShort(message.getCommand().getIntValue());
+ outBuffer.writeShort(message.getIdleTimeout().intValue());
+ outBuffer.writeShort(message.getHardTimeout().intValue());
+ outBuffer.writeShort(message.getPriority());
+ outBuffer.writeInt(message.getBufferId().intValue());
+ outBuffer.writeShort(message.getOutPort().getValue().intValue());
+ outBuffer.writeShort(createFlowModFlagsBitmask(message.getFlagsV10()));
+ OFSerializer<Action> actionSerializer = registry.getSerializer(
+ new MessageTypeKey<>(message.getVersion(), Action.class));
+ CodingUtils.serializeList(message.getAction(), actionSerializer, outBuffer);
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
private static int createFlowModFlagsBitmask(FlowModFlagsV10 flags) {
flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap);
return flowModFlagBitmask;
}
+
+ @Override
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
+ }
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.HelloInput;
/**
public class OF10HelloInputMessageFactory implements OFSerializer<HelloInput> {
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);
+ public void serialize(HelloInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE);
}
- @Override
- public int computeLength(HelloInput message) {
- return MESSAGE_LENGTH;
- }
-
- @Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
- }
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
-import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
/**
* Translates PacketOut messages
* @author michal.polkorab
*/
-public class OF10PacketOutInputMessageFactory implements OFSerializer<PacketOutInput> {
+public class OF10PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>, RegistryInjector {
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.getAction()));
- OF10ActionsSerializer.encodeActionsV10(out, message.getAction());
- byte[] data = message.getData();
- if (data != null) {
- out.writeBytes(data);
- }
- }
+ private SerializerRegistry registry;
@Override
- public int computeLength(PacketOutInput message) {
- int length = MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getAction());
+ public void serialize(PacketOutInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeInt(message.getBufferId().intValue());
+ outBuffer.writeShort(message.getInPort().getValue().intValue());
+ int actionsLengthIndex = outBuffer.writerIndex();
+ outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
+ int actionsStartIndex = outBuffer.writerIndex();
+ OFSerializer<Action> serializer =
+ registry.getSerializer(new MessageTypeKey<>(message.getVersion(), Action.class));
+ CodingUtils.serializeList(message.getAction(), serializer, outBuffer);
+ outBuffer.setShort(actionsLengthIndex, outBuffer.writerIndex() - actionsStartIndex);
byte[] data = message.getData();
if (data != null) {
- length += data.length;
+ outBuffer.writeBytes(data);
}
- return length;
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
@Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
}
}
import java.util.HashMap;
import java.util.Map;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.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;
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;
+ public void serialize(PortModInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeShort(message.getPortNo().getValue().intValue());
+ outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue()));
+ outBuffer.writeInt(createPortConfigBitmask(message.getConfigV10()));
+ outBuffer.writeInt(createPortConfigBitmask(message.getMaskV10()));
+ outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10()));
+ ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE, outBuffer);
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
- @Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
- }
-
-
/**
* @param config
* @return port config bitmask
configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap);
return configBitmask;
}
+
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.GetQueueConfigInput;
/**
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;
+ public void serialize(GetQueueConfigInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeShort(message.getPort().getValue().intValue());
+ ByteBufUtils.padBuffer(PADDING_IN_GET_QUEUE_CONFIG_MESSAGE, outBuffer);
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
}
import java.util.HashMap;
import java.util.Map;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
-import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
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.oxm.rev130731.match.v10.grouping.MatchV10;
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.MultipartRequestAggregateCase;
* Translates StatsRequest messages
* @author michal.polkorab
*/
-public class OF10StatsRequestInputFactory implements OFSerializer<MultipartRequestInput> {
+public class OF10StatsRequestInputFactory implements OFSerializer<MultipartRequestInput>, RegistryInjector {
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 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;
- }
-
+ private SerializerRegistry registry;
+
@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()));
+ public void serialize(MultipartRequestInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE);
+ outBuffer.writeShort(message.getType().getIntValue());
+ outBuffer.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));
if (message.getMultipartRequestBody() instanceof MultipartRequestDescCase) {
- encodeDescBody(message.getMultipartRequestBody(), out);
+ serializeDescBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestFlowCase) {
- encodeFlowBody(message.getMultipartRequestBody(), out);
+ serializeFlowBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregateCase) {
- encodeAggregateBody(message.getMultipartRequestBody(), out);
+ serializeAggregateBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestTableCase) {
- encodeTableBody(message.getMultipartRequestBody(), out);
+ serializeTableBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestPortStatsCase) {
- encodePortBody(message.getMultipartRequestBody(), out);
+ serializePortBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestQueueCase) {
- encodeQueueBody(message.getMultipartRequestBody(), out);
+ serializeQueueBody(message.getMultipartRequestBody(), outBuffer);
} else if (message.getMultipartRequestBody() instanceof MultipartRequestExperimenterCase) {
- encodeExperimenterBody(message.getMultipartRequestBody(), out);
+ serializeExperimenterBody(message.getMultipartRequestBody(), outBuffer);
}
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
-
- @Override
- public int computeLength(MultipartRequestInput message) {
- return MESSAGE_LENGTH + computeBodyLength(message);
- }
- @Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
- }
-
+
/**
*
* @param message
* @param multipartRequestBody
* @param output
*/
- private void encodeDescBody(MultipartRequestBody multipartRequestBody,
+ private void serializeDescBody(MultipartRequestBody multipartRequestBody,
ByteBuf output) {
// The body of MultiPartRequestDesc is empty
}
* @param multipartRequestBody
* @param out
*/
- private void encodeTableBody(MultipartRequestBody multipartRequestBody,
+ private void serializeTableBody(MultipartRequestBody multipartRequestBody,
ByteBuf out) {
// The body of MultiPartTable is empty
}
- private static void encodeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private void serializeFlowBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestFlowCase flowCase = (MultipartRequestFlowCase) multipartRequestBody;
MultipartRequestFlow flow = flowCase.getMultipartRequestFlow();
- OF10MatchSerializer.encodeMatchV10(output, flow.getMatchV10());
+ OFSerializer<MatchV10> matchSerializer = registry.getSerializer(new MessageTypeKey<>(
+ EncodeConstants.OF10_VERSION_ID, MatchV10.class));
+ matchSerializer.serialize(flow.getMatchV10(), output);
output.writeByte(flow.getTableId().shortValue());
ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY, output);
output.writeShort(flow.getOutPort().intValue());
}
- private static void encodeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private void serializeAggregateBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestAggregateCase aggregateCase = (MultipartRequestAggregateCase) multipartRequestBody;
MultipartRequestAggregate aggregate = aggregateCase.getMultipartRequestAggregate();
- OF10MatchSerializer.encodeMatchV10(output, aggregate.getMatchV10());
+ OFSerializer<MatchV10> matchSerializer = registry.getSerializer(new MessageTypeKey<>(
+ EncodeConstants.OF10_VERSION_ID, MatchV10.class));
+ matchSerializer.serialize(aggregate.getMatchV10(), output);
output.writeByte(aggregate.getTableId().shortValue());
ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY, output);
output.writeShort(aggregate.getOutPort().intValue());
}
- private static void encodePortBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private static void serializePortBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestPortStatsCase portstatsCase = (MultipartRequestPortStatsCase) multipartRequestBody;
MultipartRequestPortStats portstats = portstatsCase.getMultipartRequestPortStats();
output.writeShort(portstats.getPortNo().intValue());
ByteBufUtils.padBuffer(PADDING_IN_MULTIPART_REQUEST_PORT_BODY, output);
}
- private static void encodeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private static void serializeQueueBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestQueueCase queueCase = (MultipartRequestQueueCase) multipartRequestBody;
MultipartRequestQueue queue = queueCase.getMultipartRequestQueue();
output.writeShort(queue.getPortNo().intValue());
output.writeInt(queue.getQueueId().intValue());
}
- private static void encodeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
+ private static void serializeExperimenterBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {
MultipartRequestExperimenterCase experimenterCase = (MultipartRequestExperimenterCase) multipartRequestBody;
MultipartRequestExperimenter experimenter = experimenterCase.getMultipartRequestExperimenter();
output.writeInt(experimenter.getExperimenter().intValue());
output.writeBytes(experimenter.getData());
}
+
+ @Override
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
+ }
}
+++ /dev/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.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<ExperimenterInput> {
-
- 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;
- }
-
-}
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.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
/**
* @author michal.polkorab
* @author timotej.kubas
*/
-public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>{
+public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>, RegistryInjector {
/** Code type of PacketOut message */
- public static final byte MESSAGE_TYPE = 13;
- private static final int MESSAGE_LENGTH = 24;
+ private static final byte MESSAGE_TYPE = 13;
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.getAction()));
- ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out);
- ActionsSerializer.encodeActions(message.getAction(), out);
- byte[] data = message.getData();
- if (data != null) {
- out.writeBytes(data);
- }
- }
+ private SerializerRegistry registry;
@Override
- public int computeLength(PacketOutInput message) {
- int length = MESSAGE_LENGTH;
- length += ActionsSerializer.computeLengthOfActions(message.getAction());
+ public void serialize(PacketOutInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeInt(message.getBufferId().intValue());
+ outBuffer.writeInt(message.getInPort().getValue().intValue());
+ int actionsLengthIndex = outBuffer.writerIndex();
+ outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
+ ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, outBuffer);
+ int actionsStartIndex = outBuffer.writerIndex();
+ OFSerializer<Action> actionSerializer = registry.getSerializer(
+ new MessageTypeKey<>(message.getVersion(), Action.class));
+ CodingUtils.serializeList(message.getAction(), actionSerializer, outBuffer);
+ outBuffer.setShort(actionsLengthIndex, outBuffer.writerIndex() - actionsStartIndex);
byte[] data = message.getData();
if (data != null) {
- length += data.length;
+ outBuffer.writeBytes(data);
}
- return length;
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
@Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
}
}
import java.util.HashMap;
import java.util.Map;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.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;
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;
+ public void serialize(PortModInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeInt(message.getPortNo().getValue().intValue());
+ ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_01, outBuffer);
+ outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue()));
+ ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_02, outBuffer);
+ outBuffer.writeInt(createPortConfigBitmask(message.getConfig()));
+ outBuffer.writeInt(createPortConfigBitmask(message.getMask()));
+ outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertise()));
+ ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_03, outBuffer);
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
- @Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
- }
-
-
/**
* @param config
* @return port config bitmask
configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap);
return configBitmask;
}
+
}
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.RoleRequestInput;
/**
public class RoleRequestInputMessageFactory implements OFSerializer<RoleRequestInput> {
/** Code type of RoleRequest message */
- public static final byte MESSAGE_TYPE = 24;
- private static final int MESSAGE_LENGTH = 24;
+ private static final byte MESSAGE_TYPE = 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;
+ public void serialize(RoleRequestInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeInt(message.getRole().getIntValue());
+ ByteBufUtils.padBuffer(PADDING_IN_ROLE_REQUEST_MESSAGE, outBuffer);
+ outBuffer.writeLong(message.getGenerationId().longValue());
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
-}
+}
\ No newline at end of file
import java.util.List;
import java.util.Map;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.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;
*/
public class SetAsyncInputMessageFactory implements OFSerializer<SetAsyncInput> {
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;
+ public void serialize(SetAsyncInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ serializePacketInMask(message.getPacketInMask(), outBuffer);
+ serializePortStatusMask(message.getPortStatusMask(), outBuffer);
+ serializerFlowRemovedMask(message.getFlowRemovedMask(), outBuffer);
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
- @Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
- }
-
- private static void encodePacketInMask(List<PacketInMask> packetInMask, ByteBuf outBuffer) {
+ private static void serializePacketInMask(List<PacketInMask> packetInMask, ByteBuf outBuffer) {
if (packetInMask != null) {
for (PacketInMask currentPacketMask : packetInMask) {
List<PacketInReason> mask = currentPacketMask.getMask();
}
}
- private static void encodePortStatusMask(List<PortStatusMask> portStatusMask, ByteBuf outBuffer) {
+ private static void serializePortStatusMask(List<PortStatusMask> portStatusMask, ByteBuf outBuffer) {
if (portStatusMask != null) {
for (PortStatusMask currentPortStatusMask : portStatusMask) {
List<PortReason> mask = currentPortStatusMask.getMask();
}
}
- private static void encodeFlowRemovedMask(List<FlowRemovedMask> flowRemovedMask, ByteBuf outBuffer) {
+ private static void serializerFlowRemovedMask(List<FlowRemovedMask> flowRemovedMask, ByteBuf outBuffer) {
if (flowRemovedMask != null) {
for (FlowRemovedMask currentFlowRemovedMask : flowRemovedMask) {
List<FlowRemovedReason> mask = currentFlowRemovedMask.getMask();
}
}
}
-
+
}
\ No newline at end of file
import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.SetConfigInput;
/**
public class SetConfigMessageFactory implements OFSerializer<SetConfigInput> {
/** 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;
- }
+ private static final byte MESSAGE_TYPE = 9;
@Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
+ public void serialize(SetConfigInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeShort(message.getFlags().getIntValue());
+ outBuffer.writeShort(message.getMissSendLen());
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
}
import java.util.HashMap;
import java.util.Map;
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.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.TableConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
public class TableModInputMessageFactory implements OFSerializer<TableModInput> {
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;
+ public void serialize(TableModInput message, ByteBuf outBuffer) {
+ ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+ outBuffer.writeByte(message.getTableId().getValue().byteValue());
+ ByteBufUtils.padBuffer(PADDING_IN_TABLE_MOD_MESSAGE, outBuffer);
+ outBuffer.writeInt(createConfigBitmask(message.getConfig()));
+ ByteBufUtils.updateOFHeaderLength(outBuffer);
}
- @Override
- public byte getMessageType() {
- return MESSAGE_TYPE;
- }
-
/**
* @param tableConfig
* @return port config bitmask
int configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap);
return configBitmask;
}
+
}
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for Ipv4 address based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmIpv4AddressSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ writeIpv4Address(entry, outBuffer);\r
+ writeMask(entry, outBuffer, getValueLength());\r
+ }\r
+\r
+ private static void writeIpv4Address(MatchEntries entry, ByteBuf out) {\r
+ String[] addressGroups = entry.getAugmentation(Ipv4AddressMatchEntry.class)\r
+ .getIpv4Address().getValue().split("\\.");\r
+ for (int i = 0; i < addressGroups.length; i++) {\r
+ out.writeByte(Integer.parseInt(addressGroups[i]));\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.Arrays;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for Ipv6 address based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmIpv6AddressSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue();\r
+ String[] address;\r
+ if (textAddress.equals("::")) {\r
+ address = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];\r
+ Arrays.fill(address, "0");\r
+ } else {\r
+ address = parseIpv6Address(textAddress.split(":"));\r
+ }\r
+ for (int i = 0; i < address.length; i++) {\r
+ outBuffer.writeShort(Integer.parseInt(address[i], 16));\r
+ }\r
+ writeMask(entry, outBuffer, getValueLength());\r
+ }\r
+\r
+ private static String[] parseIpv6Address(String[] addressGroups) {\r
+ int countEmpty = 0;\r
+ for (int i = 0; i < addressGroups.length; i++) {\r
+ if (addressGroups[i].equals("")){\r
+ countEmpty++;\r
+ }\r
+ }\r
+ String[] ready = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];\r
+ switch (countEmpty) {\r
+ case 0:\r
+ ready = addressGroups;\r
+ break;\r
+ case 1:\r
+ int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.length + 1;\r
+ int index = 0;\r
+ for (int i = 0; i < addressGroups.length; i++) {\r
+ if (addressGroups[i].equals("")) {\r
+ for (int j = 0; j < zerosToBePushed; j++) {\r
+ ready[index] = "0";\r
+ index++;\r
+ }\r
+ } else {\r
+ ready[index] = addressGroups[i];\r
+ index++;\r
+ }\r
+ }\r
+ break;\r
+ case 2:\r
+ Arrays.fill(ready, "0");\r
+ ready[ready.length - 1] = addressGroups[addressGroups.length - 1];\r
+ break;\r
+ default:\r
+ throw new IllegalStateException("Incorrect ipv6 address");\r
+ }\r
+ return ready;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for MAC address based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmMacAddressSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ String macAddress = entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue();\r
+ outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(macAddress)); // 48 b + mask [OF 1.3.2 spec]\r
+ writeMask(entry, outBuffer, getValueLength());\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for all match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmMatchEntrySerializer\r
+ implements OFSerializer<MatchEntries>, HeaderSerializer<MatchEntries>{\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ serializeHeader(entry, outBuffer);\r
+ }\r
+\r
+ @Override\r
+ public void serializeHeader(MatchEntries entry, ByteBuf outBuffer) {\r
+ outBuffer.writeShort(getOxmClassCode());\r
+ writeOxmFieldAndLength(outBuffer, getOxmFieldCode(), entry.isHasMask(),\r
+ getValueLength());\r
+ }\r
+\r
+ protected static void writeMask(MatchEntries entry, ByteBuf out, int length) {\r
+ if (entry.isHasMask()) {\r
+ byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
+ if (mask != null && mask.length != length) {\r
+ throw new IllegalArgumentException("incorrect length of mask: "+\r
+ mask.length + ", expected: " + length);\r
+ }\r
+ out.writeBytes(mask);\r
+ }\r
+ }\r
+\r
+ protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) {\r
+ int fieldAndMask = fieldValue << 1;\r
+ int length = lengthArg;\r
+ if (hasMask) {\r
+ fieldAndMask |= 1;\r
+ length *= 2;\r
+ }\r
+ out.writeByte(fieldAndMask);\r
+ out.writeByte(length);\r
+ }\r
+\r
+ /**\r
+ * @return numeric representation of oxm_field\r
+ */\r
+ protected abstract int getOxmFieldCode();\r
+\r
+ /**\r
+ * @return numeric representation of oxm_class\r
+ */\r
+ protected abstract int getOxmClassCode();\r
+\r
+ /**\r
+ * @return match entry value length (without mask length)\r
+ */\r
+ protected abstract int getValueLength();\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for metadata based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmMetadataSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata());\r
+ writeMask(entry, outBuffer, getValueLength());\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for port(32-bit) based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmPortNumberSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * Parent for port(16-bit) based match entry serializers\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class AbstractOxmPortSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmArpOpSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeShort(entry.getAugmentation(OpCodeMatchEntry.class).getOpCode());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ARP_OP;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmArpShaSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ARP_SHA;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmArpSpaSerializer extends AbstractOxmIpv4AddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ARP_SPA;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmArpThaSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ARP_THA;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmArpTpaSerializer extends AbstractOxmIpv4AddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ARP_TPA;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmEthDstSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ETH_DST;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmEthSrcSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ETH_SRC;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmEthTypeSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeShort(entry.getAugmentation(EthTypeMatchEntry.class).getEthType().getValue().shortValue());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ETH_TYPE;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIcmpv4CodeSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeByte(entry.getAugmentation(Icmpv4CodeMatchEntry.class).getIcmpv4Code());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ICMPV4_CODE;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIcmpv4TypeSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeByte(entry.getAugmentation(Icmpv4TypeMatchEntry.class).getIcmpv4Type());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ICMPV4_TYPE;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIcmpv6CodeSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeByte(entry.getAugmentation(Icmpv6CodeMatchEntry.class).getIcmpv6Code());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ICMPV6_CODE;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIcmpv6TypeSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeByte(entry.getAugmentation(Icmpv6TypeMatchEntry.class).getIcmpv6Type());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.ICMPV6_TYPE;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmInPhyPortSerializer extends AbstractOxmPortNumberSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IN_PHY_PORT;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmInPortSerializer extends AbstractOxmPortNumberSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IN_PORT;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpDscpSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeByte(entry.getAugmentation(DscpMatchEntry.class).getDscp().getValue());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IP_DSCP;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpEcnSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeByte(entry.getAugmentation(EcnMatchEntry.class).getEcn());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IP_ECN;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpProtoSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeByte(entry.getAugmentation(ProtocolNumberMatchEntry.class).getProtocolNumber());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IP_PROTO;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv4DstSerializer extends AbstractOxmIpv4AddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IPV4_DST;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv4SrcSerializer extends AbstractOxmIpv4AddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IPV4_SRC;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6DstSerializer extends AbstractOxmIpv6AddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IPV6_DST;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6ExtHdrSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ Ipv6ExthdrFlags pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField();\r
+ Map<Integer, Boolean> map = new HashMap<>();\r
+ map.put(0, pseudoField.isNonext());\r
+ map.put(1, pseudoField.isEsp());\r
+ map.put(2, pseudoField.isAuth());\r
+ map.put(3, pseudoField.isDest());\r
+ map.put(4, pseudoField.isFrag());\r
+ map.put(5, pseudoField.isRouter());\r
+ map.put(6, pseudoField.isHop());\r
+ map.put(7, pseudoField.isUnrep());\r
+ map.put(8, pseudoField.isUnseq());\r
+ int bitmap = ByteBufUtils.fillBitMaskFromMap(map);\r
+ outBuffer.writeShort(bitmap);\r
+ writeMask(entry, outBuffer, getValueLength());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IPV6_EXTHDR;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6FlabelSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue());\r
+ writeMask(entry, outBuffer, getValueLength());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IPV6_FLABEL;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6NdSllSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IPV6_ND_SLL;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6NdTargetSerializer extends AbstractOxmIpv6AddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IPV6_ND_TARGET;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6NdTllSerializer extends AbstractOxmMacAddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IPV6_ND_TLL;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.MAC_ADDRESS_LENGTH;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmIpv6SrcSerializer extends AbstractOxmIpv6AddressSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.IPV6_SRC;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmMetadataSerializer extends AbstractOxmMetadataSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.METADATA;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_LONG_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmMplsBosSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeBoolean(entry.getAugmentation(BosMatchEntry.class).isBos().booleanValue());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.MPLS_BOS;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmMplsLabelSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.MPLS_LABEL;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_INT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmMplsTcSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeByte(entry.getAugmentation(TcMatchEntry.class).getTc());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.MPLS_TC;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmPbbIsidSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeMedium(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue());\r
+ writeMask(entry, outBuffer, getValueLength());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.PBB_ISID;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_3_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmSctpDstSerializer extends AbstractOxmPortSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.SCTP_DST;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmSctpSrcSerializer extends AbstractOxmPortSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.SCTP_SRC;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmTcpDstSerializer extends AbstractOxmPortSerializer{\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.TCP_DST;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmTcpSrcSerializer extends AbstractOxmPortSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.TCP_SRC;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmTunnelIdSerializer extends AbstractOxmMetadataSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.TUNNEL_ID;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_LONG_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmUdpDstSerializer extends AbstractOxmPortSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.UDP_DST;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmUdpSrcSerializer extends AbstractOxmPortSerializer {\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.UDP_SRC;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmVlanPcpSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ outBuffer.writeByte(entry.getAugmentation(VlanPcpMatchEntry.class).getVlanPcp().byteValue());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.VLAN_PCP;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_BYTE_IN_BYTES;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.impl.util.OxmMatchConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OxmVlanVidSerializer extends AbstractOxmMatchEntrySerializer {\r
+\r
+ @Override\r
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
+ super.serialize(entry, outBuffer);\r
+ VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class);\r
+ int vlanVidValue = vlanVid.getVlanVid();\r
+ if (vlanVid.isCfiBit()) {\r
+ short cfi = 1 << 12; // 13-th bit\r
+ vlanVidValue = vlanVidValue | cfi;\r
+ }\r
+\r
+ outBuffer.writeShort(vlanVidValue);\r
+ writeMask(entry, outBuffer, getValueLength());\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmClassCode() {\r
+ return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
+ }\r
+\r
+ @Override\r
+ protected int getOxmFieldCode() {\r
+ return OxmMatchConstants.VLAN_VID;\r
+ }\r
+\r
+ @Override\r
+ protected int getValueLength() {\r
+ return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
+ }\r
+\r
+}\r
* @author timotej.kubas
* @author michal.polkorab
*/
-public abstract class ActionsDeserializer {
+public class ActionsDeserializer {
private static final byte ACTION_HEADER_LENGTH = 4;
private static final byte PADDING_IN_ACTIONS_HEADER = 4;
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;
}
}
+
/**
* Create standard OF header
- * @param factory serialization factory
+ * @param msgType message code
* @param message POJO
* @param out writing buffer
+ * @param length ofheader length
*/
- public static <E extends OfHeader> void writeOFHeader(OFSerializer<E> factory, E message, ByteBuf out) {
+ public static <E extends OfHeader> void writeOFHeader(byte msgType, E message, ByteBuf out, int length) {
out.writeByte(message.getVersion());
- out.writeByte(factory.getMessageType());
- out.writeShort(factory.computeLength(message));
+ out.writeByte(msgType);
+ out.writeShort(length);
out.writeInt(message.getXid().intValue());
-
+ }
+
+ /**
+ * Write length standard OF header
+ * @param out writing buffer
+ */
+ public static void updateOFHeaderLength(ByteBuf out) {
+ out.setShort(EncodeConstants.OFHEADER_LENGTH_INDEX, out.readableBytes());
}
/**
* @return byte representation of mac address
* @see {@link MacAddress}
*/
+ @SuppressWarnings("javadoc")
public static byte[] macAddressToBytes(String macAddress) {
String[] sequences = macAddress.split(":");
byte[] result = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
* @return String representation of mac address
* @see {@link MacAddress}
*/
+ @SuppressWarnings("javadoc")
public static String macAddressToString(byte[] address) {
List<String> groups = new ArrayList<>();
for(int i=0; i < EncodeConstants.MAC_ADDRESS_LENGTH; i++){
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.util.List;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
+/**\r
+ * Class for common serialization & deserialization operations\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class CodingUtils {\r
+\r
+ /**\r
+ * Serializes list\r
+ * @param list list of items to be serialized\r
+ * @param serializer serializer that can serialize list items\r
+ * @param outBuffer output buffer\r
+ */\r
+ public static <T extends DataObject> void serializeList(List<T> list, OFSerializer<T> serializer, ByteBuf outBuffer){\r
+ if (list != null) {\r
+ for (T item : list) {\r
+ serializer.serialize(item, outBuffer);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Serializes header fields for all objects in a list\r
+ * @param list list of items to be serialized\r
+ * @param serializer serializer that can serialize list items\r
+ * @param outBuffer output buffer\r
+ */\r
+ public static <T extends DataObject> void serializeHeaders(List<T> list, HeaderSerializer<T> serializer, ByteBuf outBuffer){\r
+ if (list != null) {\r
+ for (T item : list) {\r
+ serializer.serializeHeader(item, outBuffer);\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class CommonMessageRegistryHelper {\r
+\r
+ private short version;\r
+ private SerializerRegistry serializerRegistry;\r
+\r
+ /**\r
+ * @param version\r
+ * @param serializerRegistry\r
+ */\r
+ public CommonMessageRegistryHelper(short version, SerializerRegistry serializerRegistry) {\r
+ this.version = version;\r
+ this.serializerRegistry = serializerRegistry;\r
+ }\r
+\r
+ /**\r
+ * @param msgType\r
+ * @param serializer\r
+ */\r
+ public void registerSerializer(Class<?> msgType, OFGeneralSerializer serializer) {\r
+ serializerRegistry.registerSerializer(new MessageTypeKey<>(version, msgType), serializer);\r
+ }\r
+}\r
public abstract class EncodeConstants {
/** Default OF padding (in bytes) */
- public static final byte PADDING = EncodeConstants.SIZE_OF_LONG_IN_BYTES;
+ public static final byte PADDING = 8;
/** 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;
-
+ /** Index of length in Openflow header */
+ public static final int OFHEADER_LENGTH_INDEX = 2;
+ /** Size of Openflow header */
+ public static final int OFHEADER_SIZE = 8;
+ /** Zero length - used when the length is updated later */
+ public static final int EMPTY_LENGTH = 0;
+
/** Length of mac address */
public static final byte MAC_ADDRESS_LENGTH = 6;
/** Number of groups in ipv4 address */
public static final byte MAX_PORT_NAME_LENGTH = 16;
/** OF v1.3 lenght of experimenter_ids - see Multipart TableFeatures (properties) message */
public static final byte EXPERIMENTER_IDS_LENGTH = 8;
+
}
+++ /dev/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.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.grouping.Action;
-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.grouping.Instruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.InstructionBase;
-
-/**
- * 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 METER_LENGTH = 8;
- private static final byte EXPERIMENTER_LENGTH = 8;
- private static final byte ACTIONS_INSTRUCTION_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;
- private static final byte INSTRUCTION_IDS_LENGTH = 4;
- private static final byte PADDING_IN_ACTIONS_INSTRUCTION = 4;
-
- /**
- * Encodes instructions
- * @param instructions List of instructions
- * @param out output buffer
- */
- public static void encodeInstructions(List<Instruction> instructions, ByteBuf out) {
- if (instructions != null) {
- for (Instruction instruction : instructions) {
- Class<? extends InstructionBase> 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, ACTIONS_INSTRUCTION_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);
- }
- }
- }
-
- }
-
- /**
- * Encodes instruction ids (for Multipart - TableFeatures messages)
- * @param instructions List of instruction identifiers (without values)
- * @param out output buffer
- */
- public static void encodeInstructionIds(List<Instruction> instructions, ByteBuf out) {
- if (instructions != null) {
- for (Instruction instruction : instructions) {
- Class<? extends InstructionBase> type = instruction.getType();
- if (type.isAssignableFrom(GotoTable.class)) {
- writeTypeAndLength(out, GOTO_TABLE_TYPE, INSTRUCTION_IDS_LENGTH);
- } else if (type.isAssignableFrom(WriteMetadata.class)) {
- writeTypeAndLength(out, WRITE_METADATA_TYPE, INSTRUCTION_IDS_LENGTH);
- } else if (type.isAssignableFrom(WriteActions.class)) {
- writeTypeAndLength(out, WRITE_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH);
- } else if (type.isAssignableFrom(ApplyActions.class)) {
- writeTypeAndLength(out, APPLY_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH);
- } else if (type.isAssignableFrom(ClearActions.class)) {
- writeTypeAndLength(out, CLEAR_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH);
- } else if (type.isAssignableFrom(Meter.class)) {
- writeTypeAndLength(out, METER_TYPE, INSTRUCTION_IDS_LENGTH);
- } else if (type.isAssignableFrom(Experimenter.class)) {
- ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class);
- writeTypeAndLength(out, EXPERIMENTER_TYPE, EncodeConstants.EXPERIMENTER_IDS_LENGTH);
- out.writeInt(experimenter.getExperimenter().intValue());
- }
- }
- }
- }
-
- private static void writeTypeAndLength(ByteBuf out, int type, int length) {
- out.writeShort(type);
- out.writeShort(length);
- }
-
- private static void writeActionsInstruction(ByteBuf out,
- Instruction instruction, int type) {
- out.writeShort(type);
- if (instruction.getAugmentation(ActionsInstruction.class) != null) {
- List<Action> actions = instruction.getAugmentation(ActionsInstruction.class).getAction();
- out.writeShort(ACTIONS_INSTRUCTION_LENGTH + ActionsSerializer.computeLengthOfActions(actions));
- ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out);
- ActionsSerializer.encodeActions(actions, out);
- } else {
- out.writeShort(ACTIONS_INSTRUCTION_LENGTH);
- ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out);
- }
- }
-
- /**
- * Computes length of instructions
- * @param instructions List of instructions
- * @return length of instructions (in bytes)
- */
- public static int computeInstructionsLength(List<Instruction> instructions) {
- int length = 0;
- if (instructions != null) {
- for (Instruction instruction : instructions) {
- Class<? extends InstructionBase> 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 += ACTIONS_INSTRUCTION_LENGTH;
- if (instruction.getAugmentation(ActionsInstruction.class) != null) {
- length += ActionsSerializer.computeLengthOfActions(
- instruction.getAugmentation(ActionsInstruction.class).getAction());
- }
- } else if (type.isAssignableFrom(ApplyActions.class)) {
- length += ACTIONS_INSTRUCTION_LENGTH;
- if (instruction.getAugmentation(ActionsInstruction.class) != null) {
- length += ActionsSerializer.computeLengthOfActions(
- instruction.getAugmentation(ActionsInstruction.class).getAction());
- }
- } else if (type.isAssignableFrom(ClearActions.class)) {
- length += ACTIONS_INSTRUCTION_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;
- }
-}
+++ /dev/null
-/*\r
- * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.openflowjava.protocol.impl.util;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
-\r
-/**\r
- * Encodes match ids (oxm_ids) needed in Multipart-TableFeatures messages\r
- * @author michal.polkorab\r
- */\r
-public abstract class MatchIdsSerializer {\r
-\r
- /**\r
- * Encodes oxm headers (without values) \r
- * @param entry match entry\r
- * @param out output ByteBuf\r
- */\r
- public static void encodeIdsRest(MatchEntries entry, ByteBuf out) {\r
- int fieldValue = 0;\r
- Class<? extends MatchField> field = entry.getOxmMatchField();\r
- if (field.isAssignableFrom(InPort.class)) {\r
- fieldValue = 0;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES);\r
- } else if (field.isAssignableFrom(InPhyPort.class)) {\r
- fieldValue = 1;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES);\r
- } else if (field.isAssignableFrom(Metadata.class)) {\r
- fieldValue = 2;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_LONG_IN_BYTES);\r
- } else if (field.isAssignableFrom(EthDst.class)) {\r
- fieldValue = 3;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.MAC_ADDRESS_LENGTH);\r
- } else if (field.isAssignableFrom(EthSrc.class)) {\r
- fieldValue = 4;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.MAC_ADDRESS_LENGTH);\r
- } else if (field.isAssignableFrom(EthType.class)) {\r
- fieldValue = 5;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(VlanVid.class)) {\r
- fieldValue = 6;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(VlanPcp.class)) {\r
- fieldValue = 7;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
- } else if (field.isAssignableFrom(IpDscp.class)) {\r
- fieldValue = 8;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
- } else if (field.isAssignableFrom(IpEcn.class)) {\r
- fieldValue = 9;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
- } else if (field.isAssignableFrom(IpProto.class)) {\r
- fieldValue = 10;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
- } else if (field.isAssignableFrom(Ipv4Src.class)) {\r
- fieldValue = 11;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_INT_IN_BYTES);\r
- } else if (field.isAssignableFrom(Ipv4Dst.class)) {\r
- fieldValue = 12;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(TcpSrc.class)) {\r
- fieldValue = 13;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(TcpDst.class)) {\r
- fieldValue = 14;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(UdpSrc.class)) {\r
- fieldValue = 15;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(UdpDst.class)) {\r
- fieldValue = 16;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(SctpSrc.class)) {\r
- fieldValue = 17;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(SctpDst.class)) {\r
- fieldValue = 18;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(Icmpv4Type.class)) {\r
- fieldValue = 19;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
- } else if (field.isAssignableFrom(Icmpv4Code.class)) {\r
- fieldValue = 20;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
- } else if (field.isAssignableFrom(ArpOp.class)) {\r
- fieldValue = 21;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(ArpSpa.class)) {\r
- fieldValue = 22;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(ArpTpa.class)) {\r
- fieldValue = 23;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- } else if (field.isAssignableFrom(ArpSha.class)) {\r
- fieldValue = 24;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.MAC_ADDRESS_LENGTH);\r
- } else if (field.isAssignableFrom(ArpTha.class)) {\r
- fieldValue = 25;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.MAC_ADDRESS_LENGTH);\r
- } else if (field.isAssignableFrom(Ipv6Src.class)) {\r
- fieldValue = 26;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);\r
- } else if (field.isAssignableFrom(Ipv6Dst.class)) {\r
- fieldValue = 27;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);\r
- } else if (field.isAssignableFrom(Ipv6Flabel.class)) {\r
- fieldValue = 28;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_INT_IN_BYTES);\r
- } else if (field.isAssignableFrom(Icmpv6Type.class)) {\r
- fieldValue = 29;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
- } else if (field.isAssignableFrom(Icmpv6Code.class)) {\r
- fieldValue = 30;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
- } else if (field.isAssignableFrom(Ipv6NdTarget.class)) {\r
- fieldValue = 31;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);\r
- } else if (field.isAssignableFrom(Ipv6NdSll.class)) {\r
- fieldValue = 32;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.MAC_ADDRESS_LENGTH);\r
- } else if (field.isAssignableFrom(Ipv6NdTll.class)) {\r
- fieldValue = 33;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.MAC_ADDRESS_LENGTH);\r
- } else if (field.isAssignableFrom(MplsLabel.class)) {\r
- fieldValue = 34;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES);\r
- } else if (field.isAssignableFrom(MplsTc.class)) {\r
- fieldValue = 35;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
- } else if (field.isAssignableFrom(MplsBos.class)) {\r
- fieldValue = 36;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
- } else if (field.isAssignableFrom(PbbIsid.class)) {\r
- fieldValue = 37;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_3_BYTES);\r
- } else if (field.isAssignableFrom(TunnelId.class)) {\r
- fieldValue = 38;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_LONG_IN_BYTES);\r
- } else if (field.isAssignableFrom(Ipv6Exthdr.class)) {\r
- fieldValue = 39;\r
- MatchSerializer.writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),\r
- EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
- }\r
- }\r
-\r
-}\r
+++ /dev/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.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.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.Ipv6ExthdrFlags;
-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.match.grouping.Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
-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 abstract 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> matchEntries, ByteBuf out) {
- if (matchEntries == null) {
- LOGGER.debug("Match entries are null");
- return;
- }
- for (MatchEntries entry : matchEntries) {
- encodeClass(entry.getOxmClass(), out);
- encodeRest(entry, out);
- }
- }
-
- /**
- * Encodes OXM ids (for Multipart - TableFeatures messages)
- * @param matchEntries list of match entries (oxm_fields)
- * @param out output ByteBuf
- */
- public static void encodeMatchIds(List<MatchEntries> matchEntries, ByteBuf out) {
- if (matchEntries == null) {
- LOGGER.debug("Match entries are null");
- return;
- }
- for (MatchEntries entry : matchEntries) {
- encodeClass(entry.getOxmClass(), out);
- MatchIdsSerializer.encodeIdsRest(entry, out);
- }
- }
-
- private static void encodeClass(Class<? extends Clazz> 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<? extends MatchField> field = entry.getOxmMatchField();
- if (field.isAssignableFrom(InPort.class)) {
- fieldValue = 0;
- writeOxmFieldAndLength(out, fieldValue, false, 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, false, 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, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
- out.writeShort(entry.getAugmentation(EthTypeMatchEntry.class).getEthType().getValue().shortValue());
- } else if (field.isAssignableFrom(VlanVid.class)) {
- fieldValue = 6;
- VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class);
- int vlanVidValue = vlanVid.getVlanVid();
- if (vlanVid.isCfiBit()) {
- short cfi = 1 << 12; // 13-th bit
- vlanVidValue = vlanVidValue | cfi;
- }
-
- writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),
- EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
- out.writeShort(vlanVidValue);
- writeMask(entry, out, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
- } else if (field.isAssignableFrom(VlanPcp.class)) {
- fieldValue = 7;
- writeOxmFieldAndLength(out, fieldValue, false, 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, false, 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, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
- out.writeByte(entry.getAugmentation(EcnMatchEntry.class).getEcn());
- } else if (field.isAssignableFrom(IpProto.class)) {
- fieldValue = 10;
- writeOxmFieldAndLength(out, fieldValue, false, 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, false, 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, false, 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, false, 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, false, 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, false, 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, false, 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, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
- out.writeByte(entry.getAugmentation(Icmpv4TypeMatchEntry.class).getIcmpv4Type());
- } else if (field.isAssignableFrom(Icmpv4Code.class)) {
- fieldValue = 20;
- writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
- out.writeByte(entry.getAugmentation(Icmpv4CodeMatchEntry.class).getIcmpv4Code());
- } else if (field.isAssignableFrom(ArpOp.class)) {
- fieldValue = 21;
- writeOxmFieldAndLength(out, fieldValue, false, 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;
- writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),
- EncodeConstants.SIZE_OF_INT_IN_BYTES);
- out.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue());
- writeMask(entry, out, EncodeConstants.SIZE_OF_INT_IN_BYTES);
- } else if (field.isAssignableFrom(Icmpv6Type.class)) {
- fieldValue = 29;
- writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
- out.writeByte(entry.getAugmentation(Icmpv6TypeMatchEntry.class).getIcmpv6Type());
- } else if (field.isAssignableFrom(Icmpv6Code.class)) {
- fieldValue = 30;
- writeOxmFieldAndLength(out, fieldValue, false, 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, false, EncodeConstants.SIZE_OF_INT_IN_BYTES);
- out.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue());
- } else if (field.isAssignableFrom(MplsTc.class)) {
- fieldValue = 35;
- writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
- out.writeByte(entry.getAugmentation(TcMatchEntry.class).getTc());
- } else if (field.isAssignableFrom(MplsBos.class)) {
- fieldValue = 36;
- writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
- out.writeBoolean(entry.getAugmentation(BosMatchEntry.class).isBos().booleanValue());
- } else if (field.isAssignableFrom(PbbIsid.class)) {
- fieldValue = 37;
- writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_3_BYTES);
- out.writeMedium(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue());
- writeMask(entry, out, EncodeConstants.SIZE_OF_3_BYTES);
- } else if (field.isAssignableFrom(TunnelId.class)) {
- fieldValue = 38;
- writeMetadataRelatedEntry(entry, out, fieldValue);
- } else if (field.isAssignableFrom(Ipv6Exthdr.class)) {
- fieldValue = 39;
- Ipv6ExthdrFlags pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField();
- Map<Integer, Boolean> 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);
-
- writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),
- EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
- out.writeShort(bitmap);
- writeMask(entry, out, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
- }
- }
-
- private static void writeMask(MatchEntries entry, ByteBuf out, int length) {
- if (entry.isHasMask()) {
- byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();
- if (mask != null && mask.length != length) {
- throw new IllegalArgumentException("incorrect length of mask: "+
- mask.length + ", expected: " + length);
- }
- out.writeBytes(mask);
- }
- }
-
- protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) {
- int fieldAndMask = fieldValue << 1;
- int length = lengthArg;
- if (hasMask) {
- fieldAndMask |= 1;
- length *= 2;
- }
-
- out.writeByte(fieldAndMask);
- out.writeByte(length);
-
- }
-
- private static void writeMetadataRelatedEntry(MatchEntries entry, ByteBuf out, int value) {
- int fieldValue = value;
- writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),
- EncodeConstants.SIZE_OF_LONG_IN_BYTES);
- out.writeBytes(entry.getAugmentation(MetadataMatchEntry.class).getMetadata());
- writeMask(entry, out, EncodeConstants.SIZE_OF_LONG_IN_BYTES);
- }
-
- private static void writeMacAddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) {
- int fieldValue = value;
-
- writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),
- EncodeConstants.MAC_ADDRESS_LENGTH);
- String macAddress = entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress().getValue();
- out.writeBytes(ByteBufUtils.macAddressToBytes(macAddress)); // 48 b + mask [OF 1.3.2 spec]
- writeMask(entry, out, EncodeConstants.MAC_ADDRESS_LENGTH);
- }
-
- private static void writeIpv4AddressRelatedEntry(MatchEntries entry, ByteBuf out, int value) {
- int fieldValue = value;
-
- writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),
- EncodeConstants.SIZE_OF_INT_IN_BYTES);
- writeIpv4Address(entry, out);
- writeMask(entry, out, EncodeConstants.SIZE_OF_INT_IN_BYTES);
- }
-
- 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;
- 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(":"));
- }
-
- writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(),
- EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);
- for (int i = 0; i < address.length; i++) {
- out.writeShort(Integer.parseInt(address[i], 16));
- }
- writeMask(entry, out, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);
- }
-
- 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> matchEntries) {
- int length = 0;
- if (matchEntries != null) {
- for (MatchEntries entry : matchEntries) {
- length += MATCH_ENTRY_HEADER_LENGTH;
- Class<? extends MatchField> 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_3_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;
- }
-
-}
import io.netty.buffer.ByteBuf;
-import java.util.List;
-
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
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;
* Serializes ofp_action (OpenFlow v1.0) structures
* @author michal.polkorab
*/
-public abstract class OF10ActionsSerializer {
+public class OF10ActionsSerializer implements OFSerializer<Action>, RegistryInjector {
private static final byte OUTPUT_CODE = 0;
private static final byte SET_VLAN_VID_CODE = 1;
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 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;
+ private SerializerRegistry registry;
-
- /**
- * Encodes ofp_action (OpenFlow v1.0) structures
- * @param out output ByteBuf that actions will be written into
- * @param actions actions to be encoded
- */
- public static void encodeActionsV10(ByteBuf out, List<Action> actions) {
- if (actions == null) {
- return;
- }
- for (Action action : actions) {
- 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);
- }
+ @Override
+ public void serialize(Action action, ByteBuf outBuffer) {
+ if (action.getType().equals(Output.class)) {
+ encodeOutputAction(action, outBuffer);
+ } else if (action.getType().equals(SetVlanVid.class)) {
+ encodeSetVlanVidAction(action, outBuffer);
+ } else if (action.getType().equals(SetVlanPcp.class)) {
+ encodeSetVlanPcpAction(action, outBuffer);
+ } else if (action.getType().equals(StripVlan.class)) {
+ encodeGenericAction(STRIP_VLAN_CODE, outBuffer);
+ } else if (action.getType().equals(SetDlSrc.class)) {
+ encodeDlAddressAction(action, outBuffer, SET_DL_SRC_CODE);
+ } else if (action.getType().equals(SetDlDst.class)) {
+ encodeDlAddressAction(action, outBuffer, SET_DL_DST_CODE);
+ } else if (action.getType().equals(SetNwSrc.class)) {
+ encodeIpAddressAction(action, outBuffer, SET_NW_SRC_CODE);
+ } else if (action.getType().equals(SetNwDst.class)) {
+ encodeIpAddressAction(action, outBuffer, SET_NW_DST_CODE);
+ } else if (action.getType().equals(SetNwTos.class)) {
+ encodeNwTosAction(action, outBuffer);
+ } else if (action.getType().equals(SetTpSrc.class)) {
+ encodeTpPortAction(action, outBuffer, SET_TP_SRC_CODE);
+ } else if (action.getType().equals(SetTpDst.class)) {
+ encodeTpPortAction(action, outBuffer, SET_TP_DST_CODE);
+ } else if (action.getType().equals(Enqueue.class)) {
+ encodeEnqueueAction(action, outBuffer);
+ } else if (action.getType().equals(Experimenter.class)) {
+ encodeExperimenterAction(action, outBuffer);
}
}
-
+
+ @Override
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
+ }
+
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);
QueueIdAction queueId = action.getAugmentation(QueueIdAction.class);
out.writeInt(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 actions
- * @return length of actions (OpenFlow v1.0)
- */
- public static int computeActionsLength(List<Action> actions) {
- int length = 0;
- if (actions != null) {
- for (Action action : actions) {
- 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;
+
+ private void encodeExperimenterAction(Action action, ByteBuf outBuffer) {
+ OFSerializer<ExperimenterAction> serializer = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Experimenter.class));
+ serializer.serialize((ExperimenterAction) action, outBuffer);
}
}
package org.opendaylight.openflowjava.protocol.impl.util;
+import io.netty.buffer.ByteBuf;
+
import java.util.HashMap;
import java.util.Map;
-import io.netty.buffer.ByteBuf;
-
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
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 {
+public class OF10MatchSerializer implements OFSerializer<MatchV10> {
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;
-
+
/**
- * Encodes ofp_match (OpenFlow v1.0)
- * @param out output ByteBuf that match will be written into
- * @param match match to be encoded
+ * Serializes ofp_match (OpenFlow v1.0)
+ * @param outBuffer output ByteBuf
+ * @param match match to be serialized
*/
- 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);
+ @Override
+ public void serialize(MatchV10 match, ByteBuf outBuffer) {
+ outBuffer.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask()));
+ outBuffer.writeShort(match.getInPort());
+ outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlSrc().getValue()));
+ outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlDst().getValue()));
+ outBuffer.writeShort(match.getDlVlan());
+ outBuffer.writeByte(match.getDlVlanPcp());
+ ByteBufUtils.padBuffer(PADDING_IN_MATCH, outBuffer);
+ outBuffer.writeShort(match.getDlType());
+ outBuffer.writeByte(match.getNwTos());
+ outBuffer.writeByte(match.getNwProto());
+ ByteBufUtils.padBuffer(PADDING_IN_MATCH_2, outBuffer);
String[] srcGroups = match.getNwSrc().getValue().split("\\.");
for (int i = 0; i < srcGroups.length; i++) {
- out.writeByte(Integer.parseInt(srcGroups[i]));
+ outBuffer.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]));
+ outBuffer.writeByte(Integer.parseInt(dstGroups[i]));
}
- out.writeShort(match.getTpSrc());
- out.writeShort(match.getTpDst());
+ outBuffer.writeShort(match.getTpSrc());
+ outBuffer.writeShort(match.getTpDst());
}
-
+
private static int encodeWildcards(FlowWildcardsV10 wildcards, short srcMask, short dstMask) {
int bitmask = 0;
Map<Integer, Boolean> wildcardsMap = new HashMap<>();
bitmask |= ((32 - dstMask) << NW_DST_SHIFT);
return bitmask;
}
-
+
}
import io.netty.buffer.ByteBuf;
-import java.util.List;
-
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey;
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;
* @author michal.polkorab
* @author timotej.kubas
*/
-public abstract class ActionsSerializer {
+public class OF13ActionsSerializer implements OFSerializer<Action>,
+ HeaderSerializer<Action>, RegistryInjector {
private static final byte OUTPUT_CODE = 0;
private static final byte COPY_TTL_OUT_CODE = 11;
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_ACTION_HEADER_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;
private static final byte ACTION_IDS_LENGTH = 4;
+ private SerializerRegistry registry;
-
- /**
- * Encodes actions to ByteBuf
- * @param actionsList list of actions to be encoded
- * @param outBuffer output ByteBuf
- */
- public static void encodeActions(List<Action> actionsList, ByteBuf outBuffer) {
- if (actionsList == null) {
- return;
- }
- for (Action action : actionsList) {
- 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);
- }
- }
- }
-
- /**
- * Encodes action ids to ByteBuf (for Multipart - TableFeatures messages)
- * @param actionsList list of actions to be encoded
- * @param outBuffer output ByteBuf
- */
- public static void encodeActionIds(List<Action> actionsList, ByteBuf outBuffer) {
- if (actionsList == null) {
- return;
- }
- for (Action action : actionsList) {
- if (action.getType().isAssignableFrom(Output.class)) {
- writeTypeAndLength(outBuffer, OUTPUT_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(CopyTtlOut.class)) {
- writeTypeAndLength(outBuffer, COPY_TTL_OUT_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(CopyTtlIn.class)) {
- writeTypeAndLength(outBuffer, COPY_TTL_IN_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(SetMplsTtl.class)) {
- writeTypeAndLength(outBuffer, SET_MPLS_TTL_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(DecMplsTtl.class)) {
- writeTypeAndLength(outBuffer, DEC_MPLS_TTL_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(PushVlan.class)) {
- writeTypeAndLength(outBuffer, PUSH_VLAN_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(PopVlan.class)) {
- writeTypeAndLength(outBuffer, POP_VLAN_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(PushMpls.class)) {
- writeTypeAndLength(outBuffer, PUSH_MPLS_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(PopMpls.class)) {
- writeTypeAndLength(outBuffer, POP_MPLS_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(SetQueue.class)) {
- writeTypeAndLength(outBuffer, SET_QUEUE_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(Group.class)) {
- writeTypeAndLength(outBuffer, GROUP_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(SetNwTtl.class)) {
- writeTypeAndLength(outBuffer, SET_NW_TTL_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(DecNwTtl.class)) {
- writeTypeAndLength(outBuffer, DEC_NW_TTL_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(SetField.class)) {
- writeTypeAndLength(outBuffer, SET_FIELD_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(PushPbb.class)) {
- writeTypeAndLength(outBuffer, PUSH_PBB_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(PopPbb.class)) {
- writeTypeAndLength(outBuffer, POP_PBB_CODE, ACTION_IDS_LENGTH);
- } else if (action.getType().isAssignableFrom(Experimenter.class)) {
- writeTypeAndLength(outBuffer, EXPERIMENTER_CODE, EncodeConstants.EXPERIMENTER_IDS_LENGTH);
- ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);
- outBuffer.writeInt(experimenter.getExperimenter().intValue());
- }
+ @Override
+ public void serialize(Action action, ByteBuf outBuffer) {
+ 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 writeTypeAndLength(ByteBuf out, int type, int length) {
out.writeShort(type);
out.writeShort(length);
outBuffer.writeShort(DEC_NW_TTL_CODE);
encodeRestOfActionHeader(outBuffer);
}
-
- private static void encodeSetFieldAction(Action action, ByteBuf outBuffer) {
+
+ private void encodeSetFieldAction(Action action, ByteBuf outBuffer) {
OxmFieldsAction oxmField = action.getAugmentation(OxmFieldsAction.class);
- int length = MatchSerializer.computeMatchEntriesLength(oxmField.getMatchEntries()) + SET_FIELD_HEADER_LENGTH;
+ int setFieldStartIndex = outBuffer.writerIndex();
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);
+ int setFieldLengthIndex = outBuffer.writerIndex();
+ outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
+ MatchEntries entry = oxmField.getMatchEntries().get(0);
+ OFSerializer<MatchEntries> serializer = registry.getSerializer(new EnhancedMessageTypeKey<>(
+ EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(), entry.getOxmMatchField()));
+ serializer.serialize(entry, outBuffer);
+ int paddingRemainder = (outBuffer.writerIndex() - setFieldStartIndex) % EncodeConstants.PADDING;
if (paddingRemainder != 0) {
ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, outBuffer);
}
+ outBuffer.setShort(setFieldLengthIndex, outBuffer.writerIndex() - setFieldStartIndex);
}
private static void encodePushPbbAction(Action action, ByteBuf outBuffer) {
encodeRestOfActionHeader(outBuffer);
}
- private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) {
- outBuffer.writeShort(EXPERIMENTER_CODE);
- ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);
- if (experimenter.getData() != null) {
- outBuffer.writeShort(EXPERIMENTER_ACTION_HEADER_LENGTH + experimenter.getData().length);
- outBuffer.writeInt(experimenter.getExperimenter().intValue());
- outBuffer.writeBytes(experimenter.getData());
- } else {
- outBuffer.writeShort(EXPERIMENTER_ACTION_HEADER_LENGTH);
- outBuffer.writeInt(experimenter.getExperimenter().intValue());
- }
+ private void encodeExperimenterAction(Action action, ByteBuf outBuffer) {
+ OFSerializer<ExperimenterAction> serializer = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Experimenter.class));
+ serializer.serialize((ExperimenterAction) action, outBuffer);
}
private static void encodeRestOfActionHeader(ByteBuf outBuffer) {
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<Action> actionsList) {
- int lengthOfActions = 0;
- if (actionsList != null) {
- for (Action action : actionsList) {
- if (action.getType().isAssignableFrom(Output.class)) {
- lengthOfActions += OUTPUT_LENGTH;
- } else if (action.getType().isAssignableFrom(SetField.class)){
- List<MatchEntries> 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 if (action.getType().isAssignableFrom(Experimenter.class)) {
- ExperimenterAction experimenterAction = action.getAugmentation(ExperimenterAction.class);
- lengthOfActions += experimenterAction.getData().length;
- lengthOfActions += EncodeConstants.SIZE_OF_LONG_IN_BYTES;
- } else {
- lengthOfActions += LENGTH_OF_OTHER_ACTIONS;
- }
- }
+
+ @Override
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
+ }
+
+ @Override
+ public void serializeHeader(Action action, ByteBuf outBuffer) {
+ if (action.getType().isAssignableFrom(Output.class)) {
+ writeTypeAndLength(outBuffer, OUTPUT_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(CopyTtlOut.class)) {
+ writeTypeAndLength(outBuffer, COPY_TTL_OUT_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(CopyTtlIn.class)) {
+ writeTypeAndLength(outBuffer, COPY_TTL_IN_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(SetMplsTtl.class)) {
+ writeTypeAndLength(outBuffer, SET_MPLS_TTL_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(DecMplsTtl.class)) {
+ writeTypeAndLength(outBuffer, DEC_MPLS_TTL_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(PushVlan.class)) {
+ writeTypeAndLength(outBuffer, PUSH_VLAN_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(PopVlan.class)) {
+ writeTypeAndLength(outBuffer, POP_VLAN_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(PushMpls.class)) {
+ writeTypeAndLength(outBuffer, PUSH_MPLS_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(PopMpls.class)) {
+ writeTypeAndLength(outBuffer, POP_MPLS_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(SetQueue.class)) {
+ writeTypeAndLength(outBuffer, SET_QUEUE_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(Group.class)) {
+ writeTypeAndLength(outBuffer, GROUP_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(SetNwTtl.class)) {
+ writeTypeAndLength(outBuffer, SET_NW_TTL_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(DecNwTtl.class)) {
+ writeTypeAndLength(outBuffer, DEC_NW_TTL_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(SetField.class)) {
+ writeTypeAndLength(outBuffer, SET_FIELD_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(PushPbb.class)) {
+ writeTypeAndLength(outBuffer, PUSH_PBB_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(PopPbb.class)) {
+ writeTypeAndLength(outBuffer, POP_PBB_CODE, ACTION_IDS_LENGTH);
+ } else if (action.getType().isAssignableFrom(Experimenter.class)) {
+ HeaderSerializer<ExperimenterAction> serializer = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Experimenter.class));
+ serializer.serializeHeader((ExperimenterAction) action, outBuffer);
}
- return lengthOfActions;
}
+
}
--- /dev/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.util;
+
+import io.netty.buffer.ByteBuf;
+
+import java.util.List;
+
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+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.grouping.Action;
+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.grouping.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.InstructionBase;
+
+/**
+ * Serializes ofp_instruction (OpenFlow v 1.3) structure
+ * @author michal.polkorab
+ * @author timotej.kubas
+ */
+public class OF13InstructionsSerializer implements OFSerializer<Instruction>,
+ HeaderSerializer<Instruction>, RegistryInjector {
+
+ 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 GOTO_TABLE_LENGTH = 8;
+ private static final byte WRITE_METADATA_LENGTH = 24;
+ private static final byte METER_LENGTH = 8;
+ private static final byte ACTIONS_INSTRUCTION_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;
+ private static final byte INSTRUCTION_IDS_LENGTH = 4;
+ private static final byte PADDING_IN_ACTIONS_INSTRUCTION = 4;
+ private SerializerRegistry registry;
+
+ private static void writeTypeAndLength(ByteBuf out, int type, int length) {
+ out.writeShort(type);
+ out.writeShort(length);
+ }
+
+ private void writeActionsInstruction(ByteBuf out,
+ Instruction instruction, int type) {
+ int instructionStartIndex = out.writerIndex();
+ out.writeShort(type);
+ if (instruction.getAugmentation(ActionsInstruction.class) != null) {
+ List<Action> actions = instruction.getAugmentation(ActionsInstruction.class).getAction();
+ int instructionLengthIndex = out.writerIndex();
+ out.writeShort(EncodeConstants.EMPTY_LENGTH);
+ ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out);
+ OFSerializer<Action> serializer = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class));
+ CodingUtils.serializeList(actions, serializer, out);
+ int instructionLength = out.writerIndex() - instructionStartIndex;
+ out.setShort(instructionLengthIndex, instructionLength);
+ } else {
+ out.writeShort(ACTIONS_INSTRUCTION_LENGTH);
+ ByteBufUtils.padBuffer(PADDING_IN_ACTIONS_INSTRUCTION, out);
+ }
+ }
+
+ @Override
+ public void serialize(Instruction instruction, ByteBuf outBuffer) {
+ Class<? extends InstructionBase> type = instruction.getType();
+ if (type.isAssignableFrom(GotoTable.class)) {
+ writeTypeAndLength(outBuffer, GOTO_TABLE_TYPE, GOTO_TABLE_LENGTH);
+ outBuffer.writeByte(instruction.getAugmentation(TableIdInstruction.class).getTableId());
+ ByteBufUtils.padBuffer(PADDING_IN_GOTO_TABLE, outBuffer);
+ } else if (type.isAssignableFrom(WriteMetadata.class)) {
+ writeTypeAndLength(outBuffer, WRITE_METADATA_TYPE, WRITE_METADATA_LENGTH);
+ ByteBufUtils.padBuffer(PADDING_IN_WRITE_METADATA, outBuffer);
+ MetadataInstruction metadata = instruction.getAugmentation(MetadataInstruction.class);
+ outBuffer.writeBytes(metadata.getMetadata());
+ outBuffer.writeBytes(metadata.getMetadataMask());
+ } else if (type.isAssignableFrom(WriteActions.class)) {
+ writeActionsInstruction(outBuffer, instruction, WRITE_ACTIONS_TYPE);
+ } else if (type.isAssignableFrom(ApplyActions.class)) {
+ writeActionsInstruction(outBuffer, instruction, APPLY_ACTIONS_TYPE);
+ } else if (type.isAssignableFrom(ClearActions.class)) {
+ writeTypeAndLength(outBuffer, CLEAR_ACTIONS_TYPE, ACTIONS_INSTRUCTION_LENGTH);
+ ByteBufUtils.padBuffer(PADDING_IN_CLEAR_ACTIONS, outBuffer);
+ } else if (type.isAssignableFrom(Meter.class)) {
+ writeTypeAndLength(outBuffer, METER_TYPE, METER_LENGTH);
+ outBuffer.writeInt(instruction.getAugmentation(MeterIdInstruction.class).getMeterId().intValue());
+ } else if (type.isAssignableFrom(Experimenter.class)) {
+ OFSerializer<ExperimenterInstruction> serializer = registry.getSerializer(new MessageTypeKey<>(
+ EncodeConstants.OF13_VERSION_ID, Experimenter.class));
+ serializer.serialize((ExperimenterInstruction) instruction, outBuffer);
+ }
+ }
+
+ @Override
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
+ }
+
+ @Override
+ public void serializeHeader(Instruction instruction, ByteBuf outBuffer) {
+ Class<? extends InstructionBase> type = instruction.getType();
+ if (type.isAssignableFrom(GotoTable.class)) {
+ writeTypeAndLength(outBuffer, GOTO_TABLE_TYPE, INSTRUCTION_IDS_LENGTH);
+ } else if (type.isAssignableFrom(WriteMetadata.class)) {
+ writeTypeAndLength(outBuffer, WRITE_METADATA_TYPE, INSTRUCTION_IDS_LENGTH);
+ } else if (type.isAssignableFrom(WriteActions.class)) {
+ writeTypeAndLength(outBuffer, WRITE_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH);
+ } else if (type.isAssignableFrom(ApplyActions.class)) {
+ writeTypeAndLength(outBuffer, APPLY_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH);
+ } else if (type.isAssignableFrom(ClearActions.class)) {
+ writeTypeAndLength(outBuffer, CLEAR_ACTIONS_TYPE, INSTRUCTION_IDS_LENGTH);
+ } else if (type.isAssignableFrom(Meter.class)) {
+ writeTypeAndLength(outBuffer, METER_TYPE, INSTRUCTION_IDS_LENGTH);
+ } else if (type.isAssignableFrom(Experimenter.class)) {
+ HeaderSerializer<ExperimenterInstruction> serializer = registry.getSerializer(new MessageTypeKey<>(
+ EncodeConstants.OF13_VERSION_ID, Experimenter.class));
+ serializer.serializeHeader((ExperimenterInstruction) instruction, outBuffer);
+ }
+ }
+
+}
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @param <T> OXM class\r
+ */\r
+public class OF13MatchEntriesRegistryHelper<T> {\r
+\r
+ private short version;\r
+ private Class<T> oxmClass;\r
+ private SerializerRegistry serializerRegistry;\r
+\r
+ /**\r
+ * @param version Openflow wire version\r
+ * @param oxmClass\r
+ * @param serializerRegistry\r
+ */\r
+ public OF13MatchEntriesRegistryHelper(short version, Class<T> oxmClass, SerializerRegistry serializerRegistry) {\r
+ this.version = version;\r
+ this.oxmClass = oxmClass;\r
+ this.serializerRegistry = serializerRegistry;\r
+ }\r
+\r
+ /**\r
+ * Registers given serializer\r
+ * @param oxmField\r
+ * @param serializer\r
+ */\r
+ public void registerSerializer(Class<?> oxmField, OFGeneralSerializer serializer) {\r
+ serializerRegistry.registerSerializer(new EnhancedMessageTypeKey<>(version, oxmClass, oxmField),\r
+ serializer);\r
+ }\r
+}\r
--- /dev/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.util;
+
+import io.netty.buffer.ByteBuf;
+
+import java.util.List;
+
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.RegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.EnhancedMessageTypeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Serializes ofp_match (OpenFlow v1.3)
+ * @author michal.polkorab
+ * @author timotej.kubas
+ */
+public class OF13MatchSerializer implements OFSerializer<Match>, RegistryInjector {
+ private static final Logger LOGGER = LoggerFactory.getLogger(OF13MatchSerializer.class);
+ private static final byte STANDARD_MATCH_TYPE_CODE = 0;
+ private static final byte OXM_MATCH_TYPE_CODE = 1;
+ private SerializerRegistry registry;
+
+ @Override
+ public void serialize(Match match, ByteBuf outBuffer) {
+ if (match == null) {
+ LOGGER.debug("Match is null");
+ return;
+ }
+ int matchStartIndex = outBuffer.writerIndex();
+ serializeType(match, outBuffer);
+ int matchLengthIndex = outBuffer.writerIndex();
+ outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
+ serializeMatchEntries(match.getMatchEntries(), outBuffer);
+ // Length of ofp_match (excluding padding)
+ int matchLength = outBuffer.writerIndex() - matchStartIndex;
+ outBuffer.setShort(matchLengthIndex, matchLength);
+ int paddingRemainder = matchLength % EncodeConstants.PADDING;
+ if (paddingRemainder != 0) {
+ ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, outBuffer);
+ }
+ }
+
+ private static void serializeType(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);
+ }
+ }
+
+ /**
+ * Serializes MatchEntries
+ * @param matchEntries list of match entries (oxm_fields)
+ * @param out output ByteBuf
+ */
+ public void serializeMatchEntries(List<MatchEntries> matchEntries, ByteBuf out) {
+ if (matchEntries == null) {
+ LOGGER.debug("Match entries are null");
+ return;
+ }
+ for (MatchEntries entry : matchEntries) {
+ OFSerializer<MatchEntries> entrySerializer = registry.getSerializer(
+ new EnhancedMessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(),
+ entry.getOxmMatchField()));
+ entrySerializer.serialize(entry, out);
+ }
+ }
+
+ @Override
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
+ }
+
+}
--- /dev/null
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+/**\r
+ * Stores oxm_match constants\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public abstract class OxmMatchConstants {\r
+\r
+ /** Backward compatibility with NXM */\r
+ public static final int NXM_0_CLASS = 0x0000;\r
+ /** Backward compatibility with NXM */\r
+ public static final int NXM_1_CLASS = 0x0001;\r
+ /** Basic class for OpenFlow */\r
+ public static final int OPENFLOW_BASIC_CLASS = 0x8000;\r
+ /** Experimenter class */\r
+ public static final int EXPERIMENTER_CLASS = 0xFFFF;\r
+ \r
+ /** Switch input port */\r
+ public static final int IN_PORT = 0;\r
+ /** Switch physical input port */\r
+ public static final int IN_PHY_PORT = 1;\r
+ /** Metadata passed between tables */\r
+ public static final int METADATA = 2;\r
+ /** Ethernet destination address */\r
+ public static final int ETH_DST = 3;\r
+ /** Ethernet source address */\r
+ public static final int ETH_SRC = 4;\r
+ /** Ethernet frame type */\r
+ public static final int ETH_TYPE = 5;\r
+ /** VLAN id. */\r
+ public static final int VLAN_VID = 6;\r
+ /** VLAN priority. */\r
+ public static final int VLAN_PCP = 7;\r
+ /** IP DSCP (6 bits in ToS field). */\r
+ public static final int IP_DSCP = 8;\r
+ /** IP ECN (2 bits in ToS field). */\r
+ public static final int IP_ECN = 9;\r
+ /** IP protocol. */\r
+ public static final int IP_PROTO = 10;\r
+ /** IPv4 source address. */\r
+ public static final int IPV4_SRC = 11;\r
+ /** IPv4 destination address. */\r
+ public static final int IPV4_DST = 12;\r
+ /** TCP source port. */\r
+ public static final int TCP_SRC = 13;\r
+ /** TCP destination port. */\r
+ public static final int TCP_DST = 14;\r
+ /** UDP source port. */\r
+ public static final int UDP_SRC = 15;\r
+ /** UDP destination port. */\r
+ public static final int UDP_DST = 16;\r
+ /** SCTP source port. */\r
+ public static final int SCTP_SRC = 17;\r
+ /** SCTP destination port. */\r
+ public static final int SCTP_DST = 18;\r
+ /** ICMP type. */\r
+ public static final int ICMPV4_TYPE = 19;\r
+ /** ICMP code. */\r
+ public static final int ICMPV4_CODE = 20;\r
+ /** ARP opcode. */\r
+ public static final int ARP_OP = 21;\r
+ /** ARP source IPv4 address. */\r
+ public static final int ARP_SPA = 22;\r
+ /** ARP target IPv4 address. */\r
+ public static final int ARP_TPA = 23;\r
+ /** ARP source hardware address. */\r
+ public static final int ARP_SHA = 24;\r
+ /** ARP target hardware address. */\r
+ public static final int ARP_THA = 25;\r
+ /** IPv6 source address. */\r
+ public static final int IPV6_SRC = 26;\r
+ /** IPv6 destination address. */\r
+ public static final int IPV6_DST = 27;\r
+ /** IPv6 Flow Label */\r
+ public static final int IPV6_FLABEL = 28;\r
+ /** ICMPv6 type. */\r
+ public static final int ICMPV6_TYPE = 29;\r
+ /** ICMPv6 code. */\r
+ public static final int ICMPV6_CODE = 30;\r
+ /** Target address for ND. */\r
+ public static final int IPV6_ND_TARGET = 31;\r
+ /** Source link-layer for ND. */\r
+ public static final int IPV6_ND_SLL = 32;\r
+ /** Target link-layer for ND. */\r
+ public static final int IPV6_ND_TLL = 33;\r
+ /** MPLS label. */\r
+ public static final int MPLS_LABEL = 34;\r
+ /** MPLS TC. */\r
+ public static final int MPLS_TC = 35;\r
+ /** MPLS BoS bit. */\r
+ public static final int MPLS_BOS = 36;\r
+ /** PBB I-SID. */\r
+ public static final int PBB_ISID = 37;\r
+ /** Logical Port Metadata. */\r
+ public static final int TUNNEL_ID = 38;\r
+ /** IPv6 Extension Header pseudo-field */\r
+ public static final int IPV6_EXTHDR = 39;\r
+}\r
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*/
public class BarrierInputMessageFactoryTest {
- private static final byte BARRIER_REQUEST_MESSAGE_CODE_TYPE = BarrierInputMessageFactory.MESSAGE_TYPE;
-
+ private static final byte BARRIER_REQUEST_MESSAGE_CODE_TYPE = 20;
+ private SerializerRegistry registry;
+ private OFSerializer<BarrierInput> barrierFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ barrierFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, BarrierInput.class));
+ }
+
/**
* Testing of {@link BarrierInputMessageFactory} for correct translation from POJO
* @throws Exception
BarrierInput bi = bib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- BarrierInputMessageFactory bimf = BarrierInputMessageFactory.getInstance();
- bimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, bi);
+ barrierFactory.serialize(bi, out);
BufferHelper.checkHeaderV13(out, BARRIER_REQUEST_MESSAGE_CODE_TYPE, 8);
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*/
public class EchoInputMessageFactoryTest {
- private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = EchoInputMessageFactory.MESSAGE_TYPE;
-
+ private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = 2;
+ private SerializerRegistry registry;
+ private OFSerializer<EchoInput> echoFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ echoFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, EchoInput.class));
+ }
+
/**
* Testing of {@link EchoInputMessageFactory} for correct translation from POJO
* @throws Exception
EchoInput ei = eib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance();
- eimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, ei);
+ echoFactory.serialize(ei, out);
BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8);
}
EchoInput ei = eib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance();
- eimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, ei);
+ echoFactory.serialize(ei, out);
BufferHelper.checkHeaderV10(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8);
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*/
public class EchoReplyInputMessageFactoryTest {
- private static final byte ECHO_REPLY_MESSAGE_CODE_TYPE = EchoReplyInputMessageFactory.MESSAGE_TYPE;
-
+ private static final byte ECHO_REPLY_MESSAGE_CODE_TYPE = 3;
+ private SerializerRegistry registry;
+ private OFSerializer<EchoReplyInput> echoFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ echoFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, EchoReplyInput.class));
+ }
+
/**
* Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO
* @throws Exception
EchoReplyInput eri = erib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance();
- eimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, eri);
+ echoFactory.serialize(eri, out);
BufferHelper.checkHeaderV13(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8);
}
EchoReplyInput eri = erib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance();
- eimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, eri);
+ echoFactory.serialize(eri, out);
BufferHelper.checkHeaderV10(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8);
}
+++ /dev/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.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;
- }
-}
import java.util.List;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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.ActionsInstruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder;
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.MaxLengthAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder;
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.PortAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;
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.action.rev130731.Output;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
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.GotoTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata;
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.match.grouping.MatchBuilder;
*/
public class FlowModInputMessageFactoryTest {
private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2;
-
+ private SerializerRegistry registry;
+ private OFSerializer<FlowModInput> flowModFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ flowModFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, FlowModInput.class));
+ }
+
/**
* @throws Exception
* Testing of {@link FlowModInputMessageFactory} for correct translation from POJO
portNumberBuilder.setPortNumber(new PortNumber(42L));
entriesBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build());
entries.add(entriesBuilder.build());
- entriesBuilder.setOxmClass(Nxm0Class.class);
+ entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(IpEcn.class);
entriesBuilder.setHasMask(false);
EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
instructions.add(insBuilder.build());
insBuilder = new InstructionBuilder();
insBuilder.setType(ApplyActions.class);
- insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
+ List<Action> actions = new ArrayList<>();
+ ActionBuilder actionBuilder = new ActionBuilder();
+ actionBuilder.setType(Output.class);
+ PortActionBuilder port = new PortActionBuilder();
+ port.setPort(new PortNumber(42L));
+ actionBuilder.addAugmentation(PortAction.class, port.build());
+ MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder();
+ maxLen.setMaxLength(52);
+ actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build());
+ actions.add(actionBuilder.build());
+ ActionsInstructionBuilder actionInstructionBuilder = new ActionsInstructionBuilder();
+ actionInstructionBuilder.setAction(actions);
+ insBuilder.addAugmentation(ActionsInstruction.class, actionInstructionBuilder.build());
instructions.add(insBuilder.build());
builder.setInstruction(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));
+ flowModFactory.serialize(message, out);
+
+ BufferHelper.checkHeaderV13(out,(byte) 14, 128);
cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
out.readBytes(cookie);
Assert.assertEquals("Wrong cookie", message.getCookie(), new BigInteger(1, cookie));
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());
+ Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort());
fieldAndMask = out.readUnsignedByte();
Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead);
Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead);
Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());
- Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
+ Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort());
out.skipBytes(4);
+ Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
+ Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
+ Assert.assertEquals("Wrong port", 42, out.readUnsignedInt());
+ Assert.assertEquals("Wrong max-length", 52, out.readUnsignedShort());
+ out.skipBytes(6);
Assert.assertTrue("Unread data", out.readableBytes() == 0);
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*/
public class GetConfigInputMessageFactoryTest {
- private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = GetConfigInputMessageFactory.MESSAGE_TYPE;
-
+ private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = 7;
+ private SerializerRegistry registry;
+ private OFSerializer<GetConfigInput> getConfigFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ getConfigFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GetConfigInput.class));
+ }
+
/**
* Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO
* @throws Exception
GetConfigInput gci = gcib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance();
- gcimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, gci);
-
+ getConfigFactory.serialize(gci, out);
+
BufferHelper.checkHeaderV13(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8);
}
GetConfigInput gci = gcib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance();
- gcimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, gci);
+ getConfigFactory.serialize(gci, out);
BufferHelper.checkHeaderV10(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8);
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*/
public class GetFeaturesInputMessageFactoryTest {
- private static final byte FEATURES_REQUEST_MESSAGE_CODE_TYPE = GetFeaturesInputMessageFactory.MESSAGE_TYPE;
-
+ private static final byte FEATURES_REQUEST_MESSAGE_CODE_TYPE = 5;
+ private SerializerRegistry registry;
+ private OFSerializer<GetFeaturesInput> featuresFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ featuresFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GetFeaturesInput.class));
+ }
+
/**
* Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO
* @throws Exception
GetFeaturesInput gfi = gfib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance();
- gfimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, gfi);
-
+ featuresFactory.serialize(gfi, out);
+
BufferHelper.checkHeaderV13(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8);
}
GetFeaturesInput gfi = gfib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance();
- gfimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, gfi);
-
+ featuresFactory.serialize(gfi, out);
+
BufferHelper.checkHeaderV10(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8);
}
}
import io.netty.buffer.UnpooledByteBufAllocator;
import junit.framework.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
public class GetQueueConfigInputMessageFactoryTest {
private static final byte GET_QUEUE_CONFIG_INPUT_MESSAGE_CODE_TYPE = 22;
private static final byte PADDING_IN_QUEUE_CONFIG_INPUT_MESSAGE = 4;
-
+ private SerializerRegistry registry;
+ private OFSerializer<GetQueueConfigInput> getQueueFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ getQueueFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GetQueueConfigInput.class));
+ }
+
/**
* Testing of {@link GetQueueConfigInputMessageFactory} for correct translation from POJO
* @throws Exception
GetQueueConfigInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- GetQueueConfigInputMessageFactory factory = GetQueueConfigInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
-
+ getQueueFactory.serialize(message, out);
+
BufferHelper.checkHeaderV13(out, GET_QUEUE_CONFIG_INPUT_MESSAGE_CODE_TYPE, 16);
Assert.assertEquals("Wrong port", 0x00010203, out.readUnsignedInt());
out.skipBytes(PADDING_IN_QUEUE_CONFIG_INPUT_MESSAGE);
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
public class GetaAsyncRequestMessageFactoryTest {
private static final byte MESSAGE_TYPE = 26;
private static final int MESSAGE_LENGTH = 8;
-
+ private SerializerRegistry registry;
+ private OFSerializer<GetAsyncInput> getAsyncFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ getAsyncFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GetAsyncInput.class));
+ }
+
/**
* Testing of {@link GetAsyncRequestMessageFactory} for correct translation from POJO
* @throws Exception
GetAsyncInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- GetAsyncRequestMessageFactory factory = GetAsyncRequestMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ getAsyncFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
}
import java.util.List;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*
*/
public class GroupModInputMessageFactoryTest {
+ private static final byte MESSAGE_TYPE = 15;
private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1;
-
+ private SerializerRegistry registry;
+ private OFSerializer<GroupModInput> groupModFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ groupModFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GroupModInput.class));
+ }
+
/**
* @throws Exception
* Testing of {@link GroupModInputMessageFactory} for correct translation from POJO
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));
+ groupModFactory.serialize(message, out);
+
+ BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 32);
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);
import java.util.List;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
public class HelloInputMessageFactoryTest {
private static final Logger LOGGER = LoggerFactory.getLogger(HelloInputMessageFactoryTest.class);
-
+ private SerializerRegistry registry;
+ private OFSerializer<HelloInput> helloFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ helloFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, HelloInput.class));
+ }
+
/**
* Testing of {@link HelloInputMessageFactory} for correct translation from POJO
* @throws Exception
HelloInput hi = hib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance();
- himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi);
+ helloFactory.serialize(hi, out);
- BufferHelper.checkHeaderV13(out, himf.getMessageType(), himf.computeLength(hi));
+ BufferHelper.checkHeaderV13(out,(byte) 0, EncodeConstants.OFHEADER_SIZE);
}
/**
HelloInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ helloFactory.serialize(message, out);
LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out));
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 0, 16);
Elements element = readElement(out).get(0);
Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType());
Elements comparation = createComparationElement(lengthOfBitmap).get(0);
HelloInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- HelloInputMessageFactory factory = HelloInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ helloFactory.serialize(message, out);
LOGGER.debug("bytebuf: " + ByteBufUtils.byteBufToHexString(out));
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 0, 24);
Elements element = readElement(out).get(0);
Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType());
Elements comparation = createComparationElement(lengthOfBitmap).get(0);
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];
+ int[] versionBitmap = new int[(elementLength - 4) / 4];
for (int i = 0; i < versionBitmap.length; i++) {
versionBitmap[i] = (int) input.readUnsignedInt();
}
import junit.framework.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*/
public class MeterModInputMessageFactoryTest {
+ private SerializerRegistry registry;
+ private OFSerializer<MeterModInput> meterModFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ meterModFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, MeterModInput.class));
+ }
+
/**
* @throws Exception
* Testing of {@link MeterModInputMessageFactory} for correct translation from POJO
MeterModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MeterModInputMessageFactory factory = MeterModInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ meterModFactory.serialize(message, out);
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), 64);
+ BufferHelper.checkHeaderV13(out, (byte) 29, 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());
import java.math.BigInteger;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.desc._case.MultipartRequestDescBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
public class MultipartRequestInputFactoryTest {
/** padding in MultipartRequest message */
public static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE = 4;
+ private SerializerRegistry registry;
+ private OFSerializer<MultipartRequestInput> multipartFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ multipartFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, MultipartRequestInput.class));
+ }
/**
* @throws Exception
* Testing of {@link MultipartRequestInputFactory} for correct translation from POJO
*/
@Test
- public void testMultipartRequestInputFactory() throws Exception {
+ public void testMultipartRequestFlowInputFactory() throws Exception {
MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setType(MultipartType.forValue(1));
MultipartRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ multipartFactory.serialize(message, out);
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 18, 48);
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);
MultipartRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ multipartFactory.serialize(message, out);
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 18, 48);
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);
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
+ //multipart request for registry 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);
+ multipartFactory.serialize(message, out);
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 18, 16);
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);
MultipartRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ multipartFactory.serialize(message, out);
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 18, 24);
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);
MultipartRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ multipartFactory.serialize(message, out);
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 18, 24);
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);
MultipartRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ multipartFactory.serialize(message, out);
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 18, 24);
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);
MultipartRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ multipartFactory.serialize(message, out);
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 18, 24);
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);
MultipartRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ multipartFactory.serialize(message, out);
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 18, 24);
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);
return caseBuilder.build();
}
- /**
- * @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 MultipartRequestExperimenterCase createRequestExperimenter() {
- MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder();
- MultipartRequestExperimenterBuilder builder = new MultipartRequestExperimenterBuilder();
- builder.setExperimenter(1133L);
- builder.setExpType(1135L);
- caseBuilder.setMultipartRequestExperimenter(builder.build());
- return caseBuilder.build();
- }
-
- private static MultipartRequestExperimenterCase decodeRequestExperimenter(ByteBuf output) {
- MultipartRequestExperimenterCaseBuilder caseBuilder = new MultipartRequestExperimenterCaseBuilder();
- MultipartRequestExperimenterBuilder builder = new MultipartRequestExperimenterBuilder();
- builder.setExperimenter(output.readUnsignedInt());
- builder.setExpType(output.readUnsignedInt());
- caseBuilder.setMultipartRequestExperimenter(builder.build());
- return caseBuilder.build();
- }
-
/**
* @throws Exception
* Testing of {@link MultipartRequestInputFactory} for correct translation from POJO
MultipartRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ multipartFactory.serialize(message, out);
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out, (byte) 18, 16);
Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort());
Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort()));
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*/
public class OF10BarrierInputMessageFactoryTest {
+ private SerializerRegistry registry;
+ private OFSerializer<BarrierInput> barrierFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ barrierFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class));
+ }
+
/**
* Testing of {@link OF10BarrierInputMessageFactory} for correct translation from POJO
* @throws Exception
BarrierInput bi = bib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- OF10BarrierInputMessageFactory bimf = OF10BarrierInputMessageFactory.getInstance();
- bimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, bi);
+ barrierFactory.serialize(bi, out);
BufferHelper.checkHeaderV10(out, (byte) 18, 8);
}
import java.util.List;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
*/
public class OF10FlowModInputMessageFactoryTest {
+ private SerializerRegistry registry;
+ private OFSerializer<FlowModInput> flowModFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ flowModFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, FlowModInput.class));
+ }
+
/**
* @throws Exception
* Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO
FlowModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- OF10FlowModInputMessageFactory factory = OF10FlowModInputMessageFactory.getInstance();
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
+ flowModFactory.serialize(message, out);
- BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV10(out, (byte) 14, 88);
Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt());
Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort());
byte[] dlSrc = new byte[6];
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*/
public class OF10HelloInputMessageFactoryTest {
+ private SerializerRegistry registry;
+ private OFSerializer<HelloInput> helloFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ helloFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, HelloInput.class));
+ }
+
/**
* Testing of {@link OF10HelloInputMessageFactory} for correct translation from POJO
* @throws Exception
HelloInput hi = hib.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- OF10HelloInputMessageFactory himf = OF10HelloInputMessageFactory.getInstance();
- himf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, hi);
+ helloFactory.serialize(hi, out);
BufferHelper.checkHeaderV10(out, (byte) 0, 8);
}
import java.util.List;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
*/
public class OF10PacketOutInputMessageFactoryTest {
+ private SerializerRegistry registry;
+ private OFSerializer<PacketOutInput> packetOutFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ packetOutFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, PacketOutInput.class));
+ }
+
/**
* Testing of {@link OF10PacketOutInputMessageFactory} for correct translation from POJO
* @throws Exception
PacketOutInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- OF10PacketOutInputMessageFactory factory = OF10PacketOutInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ packetOutFactory.serialize(message, out);
BufferHelper.checkHeaderV10(out, (byte) 13, 48);
Assert.assertEquals("Wrong BufferId", 256, out.readUnsignedInt());
import io.netty.buffer.UnpooledByteBufAllocator;
import junit.framework.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
*/
public class OF10PortModInputMessageFactoryTest {
+ private SerializerRegistry registry;
+ private OFSerializer<PortModInput> portModFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ portModFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, PortModInput.class));
+ }
+
/**
* Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO
* @throws Exception
PortModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- OF10PortModInputMessageFactory factory = OF10PortModInputMessageFactory.getInstance();
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
+ portModFactory.serialize(message, out);
BufferHelper.checkHeaderV10(out, (byte) 15, 32);
Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedShort());
import io.netty.buffer.UnpooledByteBufAllocator;
import junit.framework.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*/
public class OF10QueueGetConfigInputMessageFactoryTest {
+ private SerializerRegistry registry;
+ private OFSerializer<GetQueueConfigInput> queueFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ queueFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, GetQueueConfigInput.class));
+ }
+
/**
* Testing of {@link OF10QueueGetConfigInputMessageFactory} for correct translation from POJO
* @throws Exception
GetQueueConfigInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- OF10QueueGetConfigInputMessageFactory factory = OF10QueueGetConfigInputMessageFactory.getInstance();
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
+ queueFactory.serialize(message, out);
BufferHelper.checkHeaderV10(out, (byte) 20, 12);
Assert.assertEquals("Wrong port", 6653L, out.readUnsignedShort());
import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
import org.junit.Assert;\r
+import org.junit.Before;\r
import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
*/\r
public class OF10StatsRequestInputFactoryTest {\r
\r
+ private SerializerRegistry registry;\r
+ private OFSerializer<MultipartRequestInput> multipartFactory;\r
+\r
+ /**\r
+ * Initializes serializer registry and stores correct factory in field\r
+ */\r
+ @Before\r
+ public void startUp() {\r
+ registry = new SerializerRegistryImpl();\r
+ registry.init();\r
+ multipartFactory = registry.getSerializer(\r
+ new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MultipartRequestInput.class));\r
+ }\r
+\r
/**\r
* Testing OF10StatsRequestInputFactory (Desc) for correct serialization\r
* @throws Exception\r
MultipartRequestInput message = builder.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+ multipartFactory.serialize(message, out);\r
\r
- BufferHelper.checkHeaderV10(out, factory.getMessageType(), 12);\r
+ BufferHelper.checkHeaderV10(out, (byte) 16, 12);\r
Assert.assertEquals("Wrong type", 0, out.readUnsignedShort());\r
Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
MultipartRequestInput message = builder.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+ multipartFactory.serialize(message, out);\r
\r
- BufferHelper.checkHeaderV10(out, factory.getMessageType(), 56);\r
+ BufferHelper.checkHeaderV10(out, (byte) 16, 56);\r
Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());\r
Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
Assert.assertEquals("Wrong wildcards", 3414271, out.readUnsignedInt());\r
Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt());\r
Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort());\r
Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong table-id", 1, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong registry-id", 1, out.readUnsignedByte());\r
out.skipBytes(1);\r
Assert.assertEquals("Wrong out-port", 42, out.readUnsignedShort());\r
Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
MultipartRequestInput message = builder.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+ multipartFactory.serialize(message, out);\r
\r
- BufferHelper.checkHeaderV10(out, factory.getMessageType(), 56);\r
+ BufferHelper.checkHeaderV10(out, (byte) 16, 56);\r
Assert.assertEquals("Wrong type", 2, out.readUnsignedShort());\r
Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
Assert.assertEquals("Wrong wildcards", 0, out.readUnsignedInt());\r
Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt());\r
Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort());\r
Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong table-id", 42, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong registry-id", 42, out.readUnsignedByte());\r
out.skipBytes(1);\r
Assert.assertEquals("Wrong out-port", 6653, out.readUnsignedShort());\r
Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
MultipartRequestInput message = builder.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+ multipartFactory.serialize(message, out);\r
\r
- BufferHelper.checkHeaderV10(out, factory.getMessageType(), 12);\r
+ BufferHelper.checkHeaderV10(out, (byte) 16, 12);\r
Assert.assertEquals("Wrong type", 3, out.readUnsignedShort());\r
Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
MultipartRequestInput message = builder.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+ multipartFactory.serialize(message, out);\r
\r
- BufferHelper.checkHeaderV10(out, factory.getMessageType(), 20);\r
+ BufferHelper.checkHeaderV10(out, (byte) 16, 20);\r
Assert.assertEquals("Wrong type", 4, out.readUnsignedShort());\r
Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort());\r
MultipartRequestInput message = builder.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();\r
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+ multipartFactory.serialize(message, out);\r
\r
- BufferHelper.checkHeaderV10(out, factory.getMessageType(), 20);\r
+ BufferHelper.checkHeaderV10(out, (byte) 16, 20);\r
Assert.assertEquals("Wrong type", 5, out.readUnsignedShort());\r
Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());\r
Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort());\r
+++ /dev/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.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);
- }
-
-}
import java.util.List;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
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;
-
+ private SerializerRegistry registry;
+ private OFSerializer<PacketOutInput> packetOutFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ packetOutFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, PacketOutInput.class));
+ }
+
/**
* Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO
* @throws Exception
PacketOutInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- PacketOutInputMessageFactory factory = PacketOutInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ packetOutFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 56);
Assert.assertEquals("Wrong BufferId", message.getBufferId().longValue(), out.readUnsignedInt());
import io.netty.buffer.UnpooledByteBufAllocator;
import junit.framework.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
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 SerializerRegistry registry;
+ private OFSerializer<PortModInput> portModFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ portModFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, PortModInput.class));
+ }
+
/**
* Testing of {@link PortModInputMessageFactory} for correct translation from POJO
* @throws Exception
PortModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- PortModInputMessageFactory factory = PortModInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ portModFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedInt());
import junit.framework.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
private static final byte MESSAGE_TYPE = 24;
private static final int MESSAGE_LENGTH = 24;
private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4;
-
+ private SerializerRegistry registry;
+ private OFSerializer<RoleRequestInput> roleFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ roleFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, RoleRequestInput.class));
+ }
+
/**
* Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO
* @throws Exception
RoleRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- RoleRequestInputMessageFactory factory = RoleRequestInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ roleFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue());
import java.util.List;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
public class SetAsyncInputMessageFactoryTest {
private static final Logger LOGGER = LoggerFactory
.getLogger(SetAsyncInputMessageFactoryTest.class);
+ private SerializerRegistry registry;
+ private OFSerializer<SetAsyncInput> setAsyncFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ setAsyncFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, SetAsyncInput.class));
+ }
+
/**
* @throws Exception
* Testing of {@link SetAsyncInputMessageFactory} for correct translation from POJO
SetAsyncInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- SetAsyncInputMessageFactory factory = SetAsyncInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ setAsyncFactory.serialize(message, out);
LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(out));
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
+ BufferHelper.checkHeaderV13(out,(byte) 28, 32);
Assert.assertEquals("Wrong packetInMask", 5, out.readUnsignedInt());
Assert.assertEquals("Wrong packetInMask", 7, out.readUnsignedInt());
Assert.assertEquals("Wrong portStatusMask", 6, out.readUnsignedInt());
import io.netty.buffer.UnpooledByteBufAllocator;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
public class SetConfigMessageFactoryTest {
private static final byte MESSAGE_TYPE = 9;
private static final int MESSAGE_LENGTH = 12;
-
+ private SerializerRegistry registry;
+ private OFSerializer<SetConfigInput> setConfigFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ setConfigFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, SetConfigInput.class));
+ }
+
/**
* Testing of {@link SetConfigMessageFactory} for correct translation from POJO
* @throws Exception
SetConfigInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance();
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
+ setConfigFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
Assert.assertEquals("Wrong flags", SwitchConfigFlag.FRAGNORMAL.getIntValue(), out.readUnsignedShort());
SetConfigInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance();
- factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
+ setConfigFactory.serialize(message, out);
BufferHelper.checkHeaderV10(out, MESSAGE_TYPE, MESSAGE_LENGTH);
Assert.assertEquals("Wrong flags", SwitchConfigFlag.OFPCFRAGDROP.getIntValue(), out.readUnsignedShort());
import io.netty.buffer.UnpooledByteBufAllocator;
import junit.framework.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
public class TableModInputMessageFactoryTest {
private static final byte MESSAGE_TYPE = 17;
private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3;
-
+ private SerializerRegistry registry;
+ private OFSerializer<TableModInput> tableModFactory;
+
+ /**
+ * Initializes serializer registry and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ tableModFactory = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, TableModInput.class));
+ }
+
/**
* Testing of {@link TableModInputMessageFactory} for correct translation from POJO
* @throws Exception
TableModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- TableModInputMessageFactory factory = TableModInputMessageFactory.getInstance();
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
+ tableModFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16);
Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readUnsignedByte());
import java.util.List;\r
\r
import org.junit.Assert;\r
+import org.junit.Before;\r
import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory;\r
import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactoryTest;\r
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;\r
public class TableFeaturesTest {\r
private static final byte PADDING_IN_MULTIPART_REQUEST_MESSAGE =\r
MultipartRequestInputFactoryTest.PADDING_IN_MULTIPART_REQUEST_MESSAGE;\r
+ private SerializerRegistry registry;\r
+ private OFSerializer<MultipartRequestInput> multipartFactory;\r
+\r
+ /**\r
+ * Initializes serializer registry and stores correct factory in field\r
+ */\r
+ @Before\r
+ public void startUp() {\r
+ registry = new SerializerRegistryImpl();\r
+ registry.init();\r
+ multipartFactory = registry.getSerializer(\r
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, MultipartRequestInput.class));\r
+ }\r
\r
/**\r
* @throws Exception\r
entriesBuilder.setHasMask(false);\r
entries.add(entriesBuilder.build());\r
entriesBuilder = new MatchEntriesBuilder();\r
- entriesBuilder.setOxmClass(Nxm0Class.class);\r
+ entriesBuilder.setOxmClass(OpenflowBasicClass.class);\r
entriesBuilder.setOxmMatchField(InPort.class);\r
entriesBuilder.setHasMask(false);\r
entries.add(entriesBuilder.build());\r
entriesBuilder.setHasMask(false);\r
entries.add(entriesBuilder.build());\r
entriesBuilder = new MatchEntriesBuilder();\r
- entriesBuilder.setOxmClass(Nxm1Class.class);\r
+ entriesBuilder.setOxmClass(OpenflowBasicClass.class);\r
entriesBuilder.setOxmMatchField(IpEcn.class);\r
entriesBuilder.setHasMask(false);\r
entries.add(entriesBuilder.build());\r
MultipartRequestInput message = builder.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance();\r
- factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);\r
+ multipartFactory.serialize(message, out);\r
\r
- BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));\r
+ BufferHelper.checkHeaderV13(out, (byte) 18, 232);\r
Assert.assertEquals("Wrong type", 12, out.readUnsignedShort());\r
Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort());\r
out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE);\r
Assert.assertEquals("Wrong length", 120, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong table-id", 8, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong registry-id", 8, out.readUnsignedByte());\r
out.skipBytes(5);\r
Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG",\r
ByteBufUtils.decodeNullTerminatedString(out, 32));\r
Assert.assertEquals("Wrong max-entries", 65, out.readUnsignedInt());\r
Assert.assertEquals("Wrong property type", 2, out.readUnsignedShort());\r
Assert.assertEquals("Wrong property length", 6, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong next-table-id", 1, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong next-table-id", 2, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong next-registry-id", 1, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong next-registry-id", 2, out.readUnsignedByte());\r
out.skipBytes(2);\r
Assert.assertEquals("Wrong property type", 3, out.readUnsignedShort());\r
Assert.assertEquals("Wrong property length", 5, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong next-table-id", 3, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong next-registry-id", 3, out.readUnsignedByte());\r
out.skipBytes(3);\r
Assert.assertEquals("Wrong property type", 0, out.readUnsignedShort());\r
Assert.assertEquals("Wrong property length", 12, out.readUnsignedShort());\r
Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());\r
Assert.assertEquals("Wrong instruction length", 4, out.readUnsignedShort());\r
Assert.assertEquals("Wrong length", 96, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong table-id", 8, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong registry-id", 8, out.readUnsignedByte());\r
out.skipBytes(5);\r
Assert.assertEquals("Wrong name", "AAAABBBBCCCCDDDDEEEEFFFFGGGG",\r
ByteBufUtils.decodeNullTerminatedString(out, 32));\r
Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort());\r
Assert.assertEquals("Wrong match field&mask", 2, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match length", 4, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong match class", 0, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort());\r
Assert.assertEquals("Wrong match field&mask", 0, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match length", 4, out.readUnsignedByte());\r
out.skipBytes(4);\r
Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort());\r
Assert.assertEquals("Wrong match field&mask", 20, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte());\r
- Assert.assertEquals("Wrong match class", 1, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match class", 0x8000, out.readUnsignedShort());\r
Assert.assertEquals("Wrong match field&mask", 18, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match length", 1, out.readUnsignedByte());\r
out.skipBytes(4);\r
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;
private static <E extends DataObject> E bufferToMessage(OFDeserializer<E> 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 <E extends DataObject> void encodeV13(OFSerializer<E> encoder, ByteBuf out, E pojo) {
- messageToBuffer(encoder, out, pojo, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);
- }
-
- private static <E extends DataObject> void messageToBuffer(
- OFSerializer<E> encoder, ByteBuf out, E pojo, Short version) {
- encoder.messageToBuffer(version, out, pojo);
- }
+
}
import java.util.List;\r
\r
import org.junit.Assert;\r
+import org.junit.Before;\r
import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc;\r
*/\r
public class OF10ActionsSerializerTest {\r
\r
+ private SerializerRegistry registry;\r
+ private OFSerializer<Action> actionSerializer;\r
+\r
+ /**\r
+ * Initializes serializer table and stores correct factory in field\r
+ */\r
+ @Before\r
+ public void startUp() {\r
+ registry = new SerializerRegistryImpl();\r
+ registry.init();\r
+ actionSerializer = registry.getSerializer(\r
+ new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class));\r
+ }\r
+\r
/**\r
* Testing correct serialization of actions (OF v1.0) \r
*/\r
queueBuilder.setQueueId(400L);\r
actionBuilder.addAugmentation(QueueIdAction.class, queueBuilder.build());\r
actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(Experimenter.class);\r
- ExperimenterActionBuilder expBuilder = new ExperimenterActionBuilder();\r
- expBuilder.setExperimenter(500L);\r
- actionBuilder.addAugmentation(ExperimenterAction.class, expBuilder.build());\r
- actions.add(actionBuilder.build());\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- OF10ActionsSerializer.encodeActionsV10(out, actions);\r
+ CodingUtils.serializeList(actions, actionSerializer, out);\r
\r
Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());\r
Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
Assert.assertEquals("Wrong port", 6613, out.readUnsignedShort());\r
out.skipBytes(6);\r
Assert.assertEquals("Wrong queue-id", 400, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong vendor-id", 500, out.readUnsignedInt());\r
Assert.assertTrue("Written more bytes than needed", out.readableBytes() == 0);\r
}\r
\r
package org.opendaylight.openflowjava.protocol.impl.util;
-import junit.framework.Assert;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
+import junit.framework.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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;
*/
public class OF10MatchSerializerTest {
+ private SerializerRegistry registry;
+ private OFSerializer<MatchV10> matchSerializer;
+
+ /**
+ * Initializes serializer table and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ matchSerializer = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MatchV10.class));
+ }
+
/**
* Testing correct serialization of ofp_match
*/
builder.setTpSrc(2048);
builder.setTpDst(4096);
MatchV10 match = builder.build();
- OF10MatchSerializer.encodeMatchV10(out, match);
+ matchSerializer.serialize(match, out);
Assert.assertEquals("Wrong wildcards", 2361553, out.readUnsignedInt());
Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());
builder.setTpSrc(2048);
builder.setTpDst(4096);
MatchV10 match = builder.build();
- OF10MatchSerializer.encodeMatchV10(out, match);
+ matchSerializer.serialize(match, out);
Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt());
Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());
import java.util.List;\r
\r
import org.junit.Assert;\r
+import org.junit.Before;\r
import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls;\r
* @author michal.polkorab\r
* \r
*/\r
-public class ActionsSerializerTest {\r
+public class OF13ActionsSerializerTest {\r
+\r
+ private SerializerRegistry registry;\r
+ private OFSerializer<Action> actionSerializer;\r
+\r
+ /**\r
+ * Initializes serializer table and stores correct factory in field\r
+ */\r
+ @Before\r
+ public void startUp() {\r
+ registry = new SerializerRegistryImpl();\r
+ registry.init();\r
+ actionSerializer = registry.getSerializer(\r
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class));\r
+ }\r
\r
/**\r
* Testing correct serialization of actions\r
actionBuilder = new ActionBuilder();\r
actionBuilder.setType(PopPbb.class);\r
actions.add(actionBuilder.build());\r
- actionBuilder = new ActionBuilder();\r
- actionBuilder.setType(Experimenter.class);\r
- ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder();\r
- experimenter.setExperimenter(4L);\r
- experimenter.setData(new byte[]{0, 1, 2, 3, 4, 5, 6, 7});\r
- actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build());\r
- actions.add(actionBuilder.build());\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- ActionsSerializer.encodeActions(actions, out);\r
+ CodingUtils.serializeList(actions, actionSerializer, out);\r
\r
Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());\r
Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort());\r
Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
out.skipBytes(4);\r
- Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong experimenter", 4, out.readUnsignedInt());\r
- byte[] data = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];\r
- out.readBytes(data);\r
- Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, data);\r
Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
}\r
\r
import java.util.List;\r
\r
import org.junit.Assert;\r
+import org.junit.Before;\r
import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
* @author michal.polkorab\r
*\r
*/\r
-public class InstructionsSerializerTest {\r
+public class OF13InstructionsSerializerTest {\r
+\r
+ private SerializerRegistry registry;\r
+ private OFSerializer<Instruction> instructionSerializer;\r
+\r
+ /**\r
+ * Initializes serializer table and stores correct factory in field\r
+ */\r
+ @Before\r
+ public void startUp() {\r
+ registry = new SerializerRegistryImpl();\r
+ registry.init();\r
+ instructionSerializer = registry.getSerializer(\r
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Instruction.class));\r
+ }\r
\r
/**\r
* Testing instructions translation\r
instructions.add(builder.build());\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- InstructionsSerializer.encodeInstructions(instructions, out);\r
+ CodingUtils.serializeList(instructions, instructionSerializer, out);\r
\r
Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());\r
Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());\r
import java.util.List;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
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.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
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.match.grouping.Match;
* @author michal.polkorab
*
*/
-public class MatchSerializerTest {
-
+public class OF13MatchSerializerTest {
+
private static final Logger LOG = LoggerFactory
- .getLogger(MatchSerializerTest.class);
+ .getLogger(OF13MatchSerializerTest.class);
+ private SerializerRegistry registry;
+ private OFSerializer<Match> matchSerializer;
+
+ /**
+ * Initializes serializer table and stores correct factory in field
+ */
+ @Before
+ public void startUp() {
+ registry = new SerializerRegistryImpl();
+ registry.init();
+ matchSerializer = registry.getSerializer(
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Match.class));
+ }
/**
* Test for correct serialization of Ipv4Address match entry
Match match = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MatchSerializer.encodeMatch(match, out);
+ matchSerializer.serialize(match, out);
Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
entries.add(entriesBuilder.build());
// ipv6 match entry with abbreviated Ipv6 address
entriesBuilder = new MatchEntriesBuilder();
- entriesBuilder.setOxmClass(Nxm1Class.class);
+ entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv6Dst.class);
entriesBuilder.setHasMask(false);
addressBuilder = new Ipv6AddressMatchEntryBuilder();
entries.add(entriesBuilder.build());
// ipv6 match entry with abbreviated Ipv6 address
entriesBuilder = new MatchEntriesBuilder();
- entriesBuilder.setOxmClass(Nxm1Class.class);
+ entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv6Dst.class);
entriesBuilder.setHasMask(false);
addressBuilder = new Ipv6AddressMatchEntryBuilder();
entries.add(entriesBuilder.build());
// ipv6 match entry with abbreviated Ipv6 address
entriesBuilder = new MatchEntriesBuilder();
- entriesBuilder.setOxmClass(Nxm0Class.class);
+ entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv6Dst.class);
entriesBuilder.setHasMask(false);
addressBuilder = new Ipv6AddressMatchEntryBuilder();
builder.setMatchEntries(entries);
Match match = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MatchSerializer.encodeMatch(match, out);
+ matchSerializer.serialize(match, out);
Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
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 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", 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 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", 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 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", 0, out.readUnsignedShort());
Match match = buildIpv6FLabelMatch(0x0f9e8dL, false, null);
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MatchSerializer.encodeMatch(match, out);
+ matchSerializer.serialize(match, out);
Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
Match match = buildIpv6FLabelMatch(0x0f9e8dL, true, new byte[]{0, 0x0c, 0x7b, 0x6a});
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
- MatchSerializer.encodeMatch(match, out);
+ matchSerializer.serialize(match, out);
Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
try {
- MatchSerializer.encodeMatch(match, out);
+ matchSerializer.serialize(match, out);
Assert.fail("incorrect length of mask ignored");
} catch (IllegalArgumentException e) {
//expected
import java.util.List;\r
\r
import org.junit.Assert;\r
+import org.junit.Before;\r
import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;\r
* @author michal.polkorab\r
*\r
*/\r
-public class MatchSerializerTest2 {\r
+public class OF13MatchSerializerTest2 {\r
+\r
+ private SerializerRegistry registry;\r
+ private OFSerializer<Match> matchSerializer;\r
+\r
+ /**\r
+ * Initializes serializer table and stores correct factory in field\r
+ */\r
+ @Before\r
+ public void startUp() {\r
+ registry = new SerializerRegistryImpl();\r
+ registry.init();\r
+ matchSerializer = registry.getSerializer(\r
+ new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Match.class));\r
+ }\r
\r
/**\r
* Testing serialization of match\r
Match match = builder.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- MatchSerializer.encodeMatch(match, out);\r
+ matchSerializer.serialize(match, out);\r
\r
Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort());\r
Assert.assertEquals("Wrong match length", 4, out.readUnsignedShort());\r
builder.setType(OxmMatchType.class);\r
List<MatchEntries> entries = new ArrayList<>();\r
MatchEntriesBuilder entryBuilder = new MatchEntriesBuilder();\r
- entryBuilder.setOxmClass(Nxm0Class.class);\r
+ entryBuilder.setOxmClass(OpenflowBasicClass.class);\r
entryBuilder.setOxmMatchField(InPort.class);\r
entryBuilder.setHasMask(false);\r
PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder();\r
entryBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build());\r
entries.add(entryBuilder.build());\r
entryBuilder = new MatchEntriesBuilder();\r
- entryBuilder.setOxmClass(Nxm1Class.class);\r
+ entryBuilder.setOxmClass(OpenflowBasicClass.class);\r
entryBuilder.setOxmMatchField(InPhyPort.class);\r
entryBuilder.setHasMask(false);\r
portNumberBuilder = new PortNumberMatchEntryBuilder();\r
entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
entries.add(entryBuilder.build());\r
entryBuilder = new MatchEntriesBuilder();\r
- entryBuilder.setOxmClass(ExperimenterClass.class);\r
+ entryBuilder.setOxmClass(OpenflowBasicClass.class);\r
entryBuilder.setOxmMatchField(EthDst.class);\r
entryBuilder.setHasMask(true);\r
MacAddressMatchEntryBuilder macBuilder = new MacAddressMatchEntryBuilder();\r
entryBuilder = new MatchEntriesBuilder();\r
entryBuilder.setOxmClass(OpenflowBasicClass.class);\r
entryBuilder.setOxmMatchField(VlanPcp.class);\r
- entryBuilder.setHasMask(true);\r
+ entryBuilder.setHasMask(false);\r
VlanPcpMatchEntryBuilder pcpBuilder = new VlanPcpMatchEntryBuilder();\r
pcpBuilder.setVlanPcp((short) 14);\r
entryBuilder.addAugmentation(VlanPcpMatchEntry.class, pcpBuilder.build());\r
entryBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6Builder.build());\r
entries.add(entryBuilder.build());\r
entryBuilder = new MatchEntriesBuilder();\r
- entryBuilder.setOxmClass(ExperimenterClass.class);\r
+ entryBuilder.setOxmClass(OpenflowBasicClass.class);\r
entryBuilder.setOxmMatchField(Ipv6NdSll.class);\r
entryBuilder.setHasMask(false);\r
macBuilder = new MacAddressMatchEntryBuilder();\r
Match match = builder.build();\r
\r
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
- MatchSerializer.encodeMatch(match, out);\r
+ matchSerializer.serialize(match, out);\r
\r
Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort());\r
Assert.assertEquals("Wrong match length", 428, out.readUnsignedShort());\r
- Assert.assertEquals("Wrong match entry class", 0, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());\r
Assert.assertEquals("Wrong match entry field & hasMask", 0, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match entry value", 42, out.readUnsignedInt());\r
- Assert.assertEquals("Wrong match entry class", 1, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());\r
Assert.assertEquals("Wrong match entry field & hasMask", 2, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match entry value", 43, out.readUnsignedInt());\r
Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match entry value", 1L, out.readLong());\r
Assert.assertEquals("Wrong match entry mask", 2L, out.readLong());\r
- Assert.assertEquals("Wrong match entry class", 0xFFFF, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());\r
Assert.assertEquals("Wrong match entry field & hasMask", 7, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte());\r
byte[] array = new byte[6];\r
array = new byte[16];\r
out.readBytes(array);\r
Assert.assertArrayEquals("Wrong match entry value", new byte[]{0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, array);\r
- Assert.assertEquals("Wrong match entry class", 0xFFFF, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());\r
Assert.assertEquals("Wrong match entry field & hasMask", 64, out.readUnsignedByte());\r
Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte());\r
array = new byte[6];\r
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
+import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import com.google.common.util.concurrent.ListenableFuture;
* @param switchConHandler instance being informed when new switch connects
*/
void setSwitchConnectionHandler(SwitchConnectionHandler switchConHandler);
-
+
+ /**
+ * Registers custom serializer
+ * @param key used for serializer lookup
+ * @param serializer serializer implementation
+ */
+ public <E extends DataObject> void registerCustomSerializer(MessageTypeKey<E> key,
+ OFSerializer<E> serializer);
}
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-buffer</artifactId>
+ <version>${netty.version}</version>
+ </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>