Migrate uint/ByteBuf interactions
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / TunIpv4DstCodec.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, 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.NxmNxTunIpv4Dst;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.ipv4.dst.grouping.TunIpv4DstValuesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4DstCaseValue;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIpv4DstCaseValueBuilder;
25
26 public class TunIpv4DstCodec extends AbstractMatchCodec {
27
28     private static final int VALUE_LENGTH = 4;
29     private static final int NXM_FIELD_CODE = 32;
30     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxTunIpv4Dst> SERIALIZER_KEY =
31             new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmNxTunIpv4Dst.class);
32     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
33             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
34
35     @Override
36     public void serialize(MatchEntry input, ByteBuf outBuffer) {
37         serializeHeader(input, outBuffer);
38         TunIpv4DstCaseValue caseValue = (TunIpv4DstCaseValue) input.getMatchEntryValue();
39         outBuffer.writeInt(caseValue.getTunIpv4DstValues().getValue().intValue());
40     }
41
42     @Override
43     public MatchEntry deserialize(ByteBuf message) {
44         return deserializeHeaderToBuilder(message)
45                 .setMatchEntryValue(new TunIpv4DstCaseValueBuilder()
46                     .setTunIpv4DstValues(new TunIpv4DstValuesBuilder().setValue(readUint32(message)).build())
47                     .build())
48                 .build();
49     }
50
51     @Override
52     public int getNxmFieldCode() {
53         return NXM_FIELD_CODE;
54     }
55
56     @Override
57     public int getOxmClassCode() {
58         return OxmMatchConstants.NXM_1_CLASS;
59     }
60
61     @Override
62     public int getValueLength() {
63         return VALUE_LENGTH;
64     }
65
66     @Override
67     public Class<? extends MatchField> getNxmField() {
68         return NxmNxTunIpv4Dst.class;
69     }
70
71     @Override
72     public Class<? extends OxmClassBase> getOxmClass() {
73         return Nxm1Class.class;
74     }
75
76 }