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.oxm.rev150225.MatchField;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanVid;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVidBuilder;
24 * @author michal.polkorab
27 public class OxmVlanVidDeserializer extends AbstractOxmMatchEntryDeserializer
28 implements OFDeserializer<MatchEntry> {
31 public MatchEntry deserialize(ByteBuf input) {
32 MatchEntryBuilder builder = processHeader(getOxmClass(), getOxmField(), input);
33 addVlanVidValue(input, builder);
34 return builder.build();
37 private static void addVlanVidValue(ByteBuf input, MatchEntryBuilder builder) {
38 VlanVidCaseBuilder caseBuilder = new VlanVidCaseBuilder();
39 VlanVidBuilder vlanBuilder = new VlanVidBuilder();
40 int vidEntryValue = input.readUnsignedShort();
41 vlanBuilder.setCfiBit((vidEntryValue & (1 << 12)) != 0); // cfi is 13-th bit
42 vlanBuilder.setVlanVid(vidEntryValue & ((1 << 12) - 1)); // value without 13-th bit
43 if (builder.isHasMask()) {
44 vlanBuilder.setMask(OxmDeserializerHelper
45 .convertMask(input, EncodeConstants.SIZE_OF_SHORT_IN_BYTES));
47 caseBuilder.setVlanVid(vlanBuilder.build());
48 builder.setMatchEntryValue(caseBuilder.build());
52 protected Class<? extends MatchField> getOxmField() {
57 protected Class<? extends OxmClassBase> getOxmClass() {
58 return OpenflowBasicClass.class;