Remove EncodeConstants.SIZE_OF_{BYTE,SHORT,INT,LONG}_IN_BYTES
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / match / Ipv6FlabelEntryDeserializer.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.impl.protocol.deserialization.match;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmDeserializerHelper;
12 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
18
19 public class Ipv6FlabelEntryDeserializer extends AbstractMatchEntryDeserializer {
20     @Override
21     public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
22         final boolean hasMask = processHeader(message);
23         final Ipv6LabelBuilder ipv6labelBuilder = new Ipv6LabelBuilder()
24             .setIpv6Flabel(new Ipv6FlowLabel(message.readUnsignedInt()));
25
26         if (hasMask) {
27             final byte[] mask = OxmDeserializerHelper.convertMask(message, Integer.BYTES);
28             ipv6labelBuilder.setFlabelMask(new Ipv6FlowLabel(ByteUtil.bytesToUnsignedInt(mask)));
29         }
30
31         if (builder.getLayer3Match() == null) {
32             builder.setLayer3Match(new Ipv6MatchBuilder()
33                     .setIpv6Label(ipv6labelBuilder.build())
34                     .build());
35         } else if (builder.getLayer3Match() instanceof Ipv6Match
36                 && ((Ipv6Match) builder.getLayer3Match()).getIpv6Label() == null) {
37             final Ipv6Match match = (Ipv6Match) builder.getLayer3Match();
38             builder.setLayer3Match(new Ipv6MatchBuilder(match)
39                     .setIpv6Label(ipv6labelBuilder.build())
40                     .build());
41         } else {
42             throwErrorOnMalformed(builder, "layer3Match", "ipv6Label");
43         }
44     }
45 }