Finish OFJ nicira migration
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / NshNpCodec.java
1 /*
2  * Copyright (c) 2015 Intel, 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.readUint8;
11
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.nx.api.NiciraConstants;
14 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
15 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ExperimenterClass;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxNshNp;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsh.np.grouping.NshNpValues;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsh.np.grouping.NshNpValuesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.NxExpMatchEntryValue;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.nx.exp.match.entry.value.NshNpCaseValue;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.nx.exp.match.entry.value.NshNpCaseValueBuilder;
25 import org.opendaylight.yangtools.yang.common.Uint32;
26
27 public class NshNpCodec extends AbstractExperimenterMatchCodec {
28
29     private static final int VALUE_LENGTH = Byte.BYTES;
30     private static final int NXM_FIELD_CODE = 3;
31     public static final MatchEntrySerializerKey<ExperimenterClass, NxmNxNshNp> SERIALIZER_KEY =
32             createSerializerKey(
33                     EncodeConstants.OF13_VERSION_ID,
34                     NiciraConstants.NX_NSH_VENDOR_ID,
35                     NxmNxNshNp.class);
36     public static final MatchEntryDeserializerKey DESERIALIZER_KEY =
37             createDeserializerKey(
38                     EncodeConstants.OF13_VERSION_ID,
39                     NiciraConstants.NX_NSH_VENDOR_ID,
40                     NXM_FIELD_CODE);
41
42     @Override
43     protected void serializeValue(NxExpMatchEntryValue value, boolean hasMask, ByteBuf outBuffer) {
44         NshNpCaseValue nshNpCaseValue = (NshNpCaseValue) value;
45         NshNpValues nshNpValues = nshNpCaseValue.getNshNpValues();
46         outBuffer.writeByte(nshNpValues.getValue().toJava());
47     }
48
49     @Override
50     protected NxExpMatchEntryValue deserializeValue(ByteBuf message, boolean hasMask) {
51         return new NshNpCaseValueBuilder()
52                 .setNshNpValues(new NshNpValuesBuilder().setValue(readUint8(message)).build())
53                 .build();
54     }
55
56     @Override
57     public int getNxmFieldCode() {
58         return NXM_FIELD_CODE;
59     }
60
61     @Override
62     protected Uint32 getExperimenterId() {
63         return NiciraConstants.NX_NSH_VENDOR_ID;
64     }
65
66     @Override
67     public int getValueLength() {
68         return VALUE_LENGTH;
69     }
70
71     @Override
72     public Class<? extends MatchField> getNxmField() {
73         return NxmNxNshNp.class;
74     }
75 }