Default experimenter bundle migrated to ConfigSubsystem
[openflowjava.git] / openflow-protocol-ext / src / main / java / org / opendaylight / openflowjava / protocol / ext / serialization / OF13TableFeatExpSerializer.java
1 /*\r
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.ext.serialization;\r
10 \r
11 import io.netty.buffer.ByteBuf;\r
12 \r
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
14 import org.opendaylight.openflowjava.protocol.ext.util.ExtBufferUtils;\r
15 import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterRelatedTableFeatureProperty;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;\r
19 \r
20 /**\r
21  * @author michal.polkorab\r
22  *\r
23  */\r
24 public class OF13TableFeatExpSerializer implements OFSerializer<TableFeatureProperties> {\r
25 \r
26     private static final int EXPERIMENTER_CODE = 65534; // 0xFFFE\r
27     private static final int EXPERIMENTER_MISS_CODE = 65535; // 0xFFFF\r
28     \r
29     @Override\r
30     public void serialize(TableFeatureProperties property, ByteBuf outBuffer) {\r
31         int startIndex = outBuffer.writerIndex();\r
32         if (property.getType().equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)) {\r
33             outBuffer.writeShort(EXPERIMENTER_CODE);\r
34         } else {\r
35             outBuffer.writeShort(EXPERIMENTER_MISS_CODE);\r
36         }\r
37         int lengthIndex = outBuffer.writerIndex();\r
38         outBuffer.writeShort(ExtConstants.EMPTY_LENGTH);\r
39         ExperimenterRelatedTableFeatureProperty exp = property.\r
40                 getAugmentation(ExperimenterRelatedTableFeatureProperty.class);\r
41         outBuffer.writeInt(exp.getExperimenter().intValue());\r
42         outBuffer.writeInt(exp.getExpType().intValue());\r
43         byte[] data = exp.getData();\r
44         if (data != null) {\r
45             outBuffer.writeBytes(data);\r
46         }\r
47         int paddingRemainder = (outBuffer.writerIndex() - startIndex) % ExtConstants.PADDING;\r
48         if (paddingRemainder != 0) {\r
49             int padding = ExtConstants.PADDING - paddingRemainder;\r
50             ExtBufferUtils.padBuffer(padding, outBuffer);\r
51         }\r
52         outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);\r
53     }\r
54 \r
55 }\r