2 * Copyright (c) 2016 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.openflowplugin.impl.protocol.serialization.match;
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
12 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
16 public class VlanVidEntrySerializer extends AbstractMatchEntrySerializer {
17 private static final byte[] VLAN_VID_MASK = new byte[]{16, 0};
20 public void serialize(final Match match, final ByteBuf outBuffer) {
21 super.serialize(match, outBuffer);
22 final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId vlanId =
23 match.getVlanMatch().getVlanId().getVlanId();
25 int vlanVidValue = vlanId != null ? vlanId.getValue().toJava() : 0;
27 if (Boolean.TRUE.equals(match.getVlanMatch().getVlanId().isVlanIdPresent())) {
29 vlanVidValue = vlanVidValue | cfi;
32 outBuffer.writeShort(vlanVidValue);
34 if (getHasMask(match)) {
35 writeMask(VLAN_VID_MASK, outBuffer, getValueLength());
40 public boolean matchTypeCheck(final Match match) {
41 return match.getVlanMatch() != null && match.getVlanMatch().getVlanId() != null;
45 protected boolean getHasMask(final Match match) {
46 final VlanId vlanId = match.getVlanMatch().getVlanId();
47 return Boolean.TRUE.equals(vlanId.isVlanIdPresent())
48 && (vlanId.getVlanId() == null || vlanId.getVlanId().getValue().toJava() == 0);
52 protected int getOxmFieldCode() {
53 return OxmMatchConstants.VLAN_VID;
57 protected int getOxmClassCode() {
58 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
62 protected int getValueLength() {
63 return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;