2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.match;
10 import io.netty.buffer.ByteBuf;
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;
24 * @author michal.polkorab
27 public class OxmVlanVidDeserializer extends AbstractOxmMatchEntryDeserializer
28 implements OFDeserializer<MatchEntries> {
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);
37 return builder.build();
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());
49 protected Class<? extends MatchField> getOxmField() {
54 protected Class<? extends OxmClassBase> getOxmClass() {
55 return OpenflowBasicClass.class;