Bump MRI upstreams
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / Ipv6DstCodec.java
1 /*
2  * Copyright (c) 2017 Red Hat, Inc. 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.openflowjava.nx.codec.match;
9
10 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
11
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfIpDst;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.IpDstCaseValue;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.IpDstCaseValueBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.ip.dst.grouping.IpDstValuesBuilder;
25
26 /**
27  * Codec for the Ipv6Dst message.
28  *
29  * @author Sridhar Gaddam (sgaddam@redhat.com)
30  */
31 public class Ipv6DstCodec extends AbstractMatchCodec {
32
33     private static final int VALUE_LENGTH = 16;
34     private static final int NXM_FIELD_CODE = 20;
35     public static final MatchEntrySerializerKey<Nxm1Class, NxmOfIpDst> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
36             EncodeConstants.OF_VERSION_1_3, Nxm1Class.class, NxmOfIpDst.class);
37     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
38             EncodeConstants.OF_VERSION_1_3, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
39
40
41     @Override
42     public MatchEntry deserialize(final ByteBuf message) {
43         return deserializeHeaderToBuilder(message)
44                 .setMatchEntryValue(new IpDstCaseValueBuilder()
45                     .setIpDstValues(new IpDstValuesBuilder().setValue(readUint32(message)).build())
46                     .build())
47                 .build();
48     }
49
50     @Override
51     public void serialize(final MatchEntry input, final ByteBuf outBuffer) {
52         serializeHeader(input, outBuffer);
53         IpDstCaseValue ipDstCase = (IpDstCaseValue) input.getMatchEntryValue();
54         outBuffer.writeInt(ipDstCase.getIpDstValues().getValue().intValue());
55     }
56
57     @Override
58     public int getNxmFieldCode() {
59         return NXM_FIELD_CODE;
60     }
61
62     @Override
63     public int getOxmClassCode() {
64         return OxmMatchConstants.NXM_1_CLASS;
65     }
66
67     @Override
68     public int getValueLength() {
69         return VALUE_LENGTH;
70     }
71
72     @Override
73     public Class<? extends MatchField> getNxmField() {
74         return NxmOfIpDst.class;
75     }
76
77     @Override
78     public Class<? extends OxmClassBase> getOxmClass() {
79         return Nxm1Class.class;
80     }
81
82 }