Update MRI upstreams for Phosphorus
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / CtTpSrcCodec.java
1 /*
2  * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. 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.readUint16;
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.NxmNxCtTpSrc;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.CtTpSrcCaseValue;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.CtTpSrcCaseValueBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.tp.src.grouping.CtTpSrcValuesBuilder;
25
26 public class CtTpSrcCodec extends AbstractMatchCodec {
27
28     private static final int VALUE_LENGTH = 2;
29     private static final int NXM_FIELD_CODE = 124;
30     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxCtTpSrc> SERIALIZER_KEY =
31             new MatchEntrySerializerKey<>(EncodeConstants.OF_VERSION_1_3, Nxm1Class.class, NxmNxCtTpSrc.class);
32     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
33             EncodeConstants.OF_VERSION_1_3, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
34
35     @Override
36     public void serialize(final MatchEntry input, final ByteBuf outBuffer) {
37         serializeHeader(input, outBuffer);
38         CtTpSrcCaseValue ctTpSrcCase = (CtTpSrcCaseValue)input.getMatchEntryValue();
39         outBuffer.writeShort(ctTpSrcCase.getCtTpSrcValues().getCtTpSrc().toJava());
40     }
41
42     @Override
43     public MatchEntry deserialize(final ByteBuf message) {
44         return deserializeHeaderToBuilder(message)
45                 .setMatchEntryValue(new CtTpSrcCaseValueBuilder()
46                     .setCtTpSrcValues(new CtTpSrcValuesBuilder().setCtTpSrc(readUint16(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 NxmNxCtTpSrc.class;
69     }
70
71     @Override
72     public Class<? extends OxmClassBase> getOxmClass() {
73         return Nxm1Class.class;
74     }
75 }