775b91a8a355f37ba7234ea9182fb6f594277fc8
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / match / OxmVlanVidSerializer.java
1 /*\r
2  * Copyright (c) 2013 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 package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
9 \r
10 import io.netty.buffer.ByteBuf;\r
11 \r
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
13 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
16 \r
17 /**\r
18  * @author michal.polkorab\r
19  *\r
20  */\r
21 public class OxmVlanVidSerializer extends AbstractOxmMatchEntrySerializer {\r
22 \r
23     @Override\r
24     public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
25         super.serialize(entry, outBuffer);\r
26         VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class);\r
27         int vlanVidValue = vlanVid.getVlanVid();\r
28         if (vlanVid.isCfiBit()) {\r
29             short cfi = 1 << 12; // 13-th bit\r
30             vlanVidValue = vlanVidValue | cfi;\r
31         }\r
32 \r
33         outBuffer.writeShort(vlanVidValue);\r
34         writeMask(entry, outBuffer, getValueLength());\r
35     }\r
36 \r
37     @Override\r
38     protected int getOxmClassCode() {\r
39         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;\r
40     }\r
41 \r
42     @Override\r
43     protected int getOxmFieldCode() {\r
44         return OxmMatchConstants.VLAN_VID;\r
45     }\r
46 \r
47     @Override\r
48     protected int getValueLength() {\r
49         return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;\r
50     }\r
51 \r
52 }\r