Remove Objects.{is,non}Null abuse
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / Ipv6LabelEntrySerializer.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.serialization.match;
9
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.openflowplugin.openflow.md.util.ByteUtil;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6Label;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
17
18 public class Ipv6LabelEntrySerializer extends AbstractMatchEntrySerializer {
19
20     @Override
21     public void serialize(Match match, ByteBuf outBuffer) {
22         super.serialize(match, outBuffer);
23         final Ipv6Label ipv6Label = ((Ipv6Match) match.getLayer3Match()).getIpv6Label();
24         outBuffer.writeInt(ipv6Label.getIpv6Flabel().getValue().intValue());
25
26         if (getHasMask(match)) {
27             writeMask(ByteUtil.unsignedIntToBytes(
28                     ipv6Label.getFlabelMask().getValue()),
29                     outBuffer,
30                     getValueLength());
31         }
32     }
33
34     @Override
35     public boolean matchTypeCheck(Match match) {
36         return match.getLayer3Match() != null
37                 && match.getLayer3Match() instanceof Ipv6Match
38                 && ((Ipv6Match) match.getLayer3Match()).getIpv6Label() != null;
39     }
40
41     @Override
42     protected boolean getHasMask(Match match) {
43         return ((Ipv6Match) match.getLayer3Match()).getIpv6Label().getFlabelMask() != null;
44     }
45
46     @Override
47     protected int getOxmFieldCode() {
48         return OxmMatchConstants.IPV6_FLABEL;
49     }
50
51     @Override
52     protected int getOxmClassCode() {
53         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
54     }
55
56     @Override
57     protected int getValueLength() {
58         return EncodeConstants.SIZE_OF_INT_IN_BYTES;
59     }
60 }