Use IpAddressBuilder instead of char[] constructor
[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
9 package org.opendaylight.openflowjava.nx.codec.match;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
13 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxNshNp;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsh.np.grouping.NshNpValuesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NshNpCaseValue;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NshNpCaseValueBuilder;
25
26 public class NshNpCodec extends AbstractMatchCodec {
27
28     private static final int VALUE_LENGTH = 1;
29     private static final int NXM_FIELD_CODE = 120;
30     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxNshNp> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
31             EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmNxNshNp.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         NshNpCaseValue nshNpCaseValue = ((NshNpCaseValue) input.getMatchEntryValue());
39         outBuffer.writeByte(nshNpCaseValue.getNshNpValues().getValue());
40     }
41
42     @Override
43     public MatchEntry deserialize(ByteBuf message) {
44         MatchEntryBuilder matchEntriesBuilder = deserializeHeaderToBuilder(message);
45         NshNpCaseValueBuilder nshNpCaseValueBuilder = new NshNpCaseValueBuilder();
46         nshNpCaseValueBuilder.setNshNpValues(new NshNpValuesBuilder().setValue(message.readUnsignedByte()).build());
47         matchEntriesBuilder.setMatchEntryValue(nshNpCaseValueBuilder.build());
48         matchEntriesBuilder.setHasMask(false);
49         return matchEntriesBuilder.build();
50     }
51
52     @Override
53     public int getNxmFieldCode() {
54         return NXM_FIELD_CODE;
55     }
56
57     @Override
58     public int getOxmClassCode() {
59         return OxmMatchConstants.NXM_1_CLASS;
60     }
61
62     @Override
63     public int getValueLength() {
64         return VALUE_LENGTH;
65     }
66
67     @Override
68     public Class<? extends MatchField> getNxmField() {
69         return NxmNxNshNp.class;
70     }
71
72     @Override
73     public Class<? extends OxmClassBase> getOxmClass() {
74         return Nxm1Class.class;
75     }
76 }