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.deserialization.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.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
19 public class VlanVidEntryDeserializer extends AbstractMatchEntryDeserializer {
22 public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
23 final boolean hasMask = processHeader(message);
24 final VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
25 final int vlanVidValue = message.readUnsignedShort();
28 message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // Skip mask
30 .setVlanId(new VlanId(0))
31 .setVlanIdPresent(true);
33 final boolean vidPresent = (vlanVidValue & (1 << 12)) != 0;
36 .setVlanId(new VlanId((vidPresent ? vlanVidValue & ((1 << 12) - 1) : vlanVidValue)))
37 .setVlanIdPresent(vidPresent);
40 if (Objects.isNull(builder.getVlanMatch())) {
41 builder.setVlanMatch(new VlanMatchBuilder()
42 .setVlanId(vlanIdBuilder.build())
44 } else if (Objects.nonNull(builder.getVlanMatch().getVlanId())) {
45 builder.setVlanMatch(new VlanMatchBuilder(builder.getVlanMatch())
46 .setVlanId(vlanIdBuilder.build())
49 throwErrorOnMalformed(builder, "vlanMatch");