Mass replace CRLF->LF
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / match / OxmVlanVidDeserializer.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.match;
9
10 import io.netty.buffer.ByteBuf;
11
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmClassBase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
22
23 /**
24  * @author michal.polkorab
25  *
26  */
27 public class OxmVlanVidDeserializer extends AbstractOxmMatchEntryDeserializer
28         implements OFDeserializer<MatchEntries> {
29
30     @Override
31     public MatchEntries deserialize(ByteBuf input) {
32         MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input);
33         addVlanVidAugmentation(input, builder);
34         if (builder.isHasMask()) {
35             OxmMaskDeserializer.addMaskAugmentation(builder, input, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
36         }
37         return builder.build();
38     }
39
40     private static void addVlanVidAugmentation(ByteBuf input, MatchEntriesBuilder builder) {
41         VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
42         int vidEntryValue = input.readUnsignedShort();
43         vlanVidBuilder.setCfiBit((vidEntryValue & (1 << 12)) != 0); // cfi is 13-th bit
44         vlanVidBuilder.setVlanVid(vidEntryValue & ((1 << 12) - 1)); // value without 13-th bit
45         builder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
46     }
47
48     @Override
49     protected Class<? extends MatchField> getOxmField() {
50         return VlanVid.class;
51     }
52
53     @Override
54     protected Class<? extends OxmClassBase> getOxmClass() {
55         return OpenflowBasicClass.class;
56     }
57 }