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
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
11 import io.netty.buffer.ByteBuf;
12 import java.util.Objects;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
18 public class VlanVidEntrySerializer extends AbstractMatchEntrySerializer {
19 private static final byte[] VLAN_VID_MASK = new byte[]{16, 0};
22 public void serialize(Match match, ByteBuf outBuffer) {
23 super.serialize(match, outBuffer);
24 final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId vlanId =
25 match.getVlanMatch().getVlanId().getVlanId();
27 int vlanVidValue = Objects.nonNull(vlanId) ? vlanId.getValue() : 0;
29 if (Boolean.TRUE.equals(match.getVlanMatch().getVlanId().isVlanIdPresent())) {
31 vlanVidValue = vlanVidValue | cfi;
34 outBuffer.writeShort(vlanVidValue);
36 if (getHasMask(match)) {
37 writeMask(VLAN_VID_MASK, outBuffer, getValueLength());
42 public boolean matchTypeCheck(Match match) {
43 return Objects.nonNull(match.getVlanMatch())
44 && Objects.nonNull(match.getVlanMatch().getVlanId());
48 protected boolean getHasMask(Match match) {
49 final VlanId vlanId = match.getVlanMatch().getVlanId();
50 return Boolean.TRUE.equals(vlanId.isVlanIdPresent())
51 && (Objects.isNull(vlanId.getVlanId()) || vlanId.getVlanId().getValue() == 0);
55 protected int getOxmFieldCode() {
56 return OxmMatchConstants.VLAN_VID;
60 protected int getOxmClassCode() {
61 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
65 protected int getValueLength() {
66 return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;