Rework MatchEntrySerializer
[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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
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.ipv6.match.fields.Ipv6Label;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
19
20 public class Ipv6LabelEntrySerializer extends AbstractMatchEntrySerializer<Ipv6Label, Ipv6FlowLabel> {
21     public Ipv6LabelEntrySerializer() {
22         super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.IPV6_FLABEL,
23             EncodeConstants.SIZE_OF_INT_IN_BYTES);
24     }
25
26     @Override
27     protected Ipv6Label extractEntry(final Match match) {
28         final Layer3Match l3Match = match.getLayer3Match();
29         return l3Match instanceof Ipv6Match ? ((Ipv6Match) l3Match).getIpv6Label() : null;
30     }
31
32     @Override
33     protected Ipv6FlowLabel extractEntryMask(final Ipv6Label entry) {
34         return entry.getFlabelMask();
35     }
36
37     @Override
38     protected void serializeEntry(final Ipv6Label entry, final Ipv6FlowLabel mask, final ByteBuf outBuffer) {
39         outBuffer.writeInt(entry.getIpv6Flabel().getValue().intValue());
40         if (mask != null) {
41             writeMask(ByteUtil.unsignedIntToBytes(mask.getValue()), outBuffer, EncodeConstants.SIZE_OF_INT_IN_BYTES);
42         }
43     }
44 }