Bump upstreams for 2022.09 Chlorine
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / NshTtlCodec.java
1 /*
2  * Copyright (c) 2018 SUSE LINUX GmbH.  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.NxmNxNshTtl;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.exp.match.NxExpMatchEntryValue;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.exp.match.nx.exp.match.entry.value.NshTtlCaseValue;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.exp.match.nx.exp.match.entry.value.NshTtlCaseValueBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsh.ttl.grouping.NshTtlValuesBuilder;
24 import org.opendaylight.yangtools.yang.common.Uint32;
25
26 public class NshTtlCodec extends AbstractExperimenterMatchCodec {
27
28     private static final int VALUE_LENGTH = Byte.BYTES;
29     private static final int NXM_FIELD_CODE = 10;
30     public static final MatchEntrySerializerKey<ExperimenterClass, NxmNxNshTtl> SERIALIZER_KEY =
31             createSerializerKey(EncodeConstants.OF_VERSION_1_3, NiciraConstants.NX_NSH_VENDOR_ID, NxmNxNshTtl.VALUE);
32     public static final MatchEntryDeserializerKey DESERIALIZER_KEY =
33             createDeserializerKey(EncodeConstants.OF_VERSION_1_3, NiciraConstants.NX_NSH_VENDOR_ID, NXM_FIELD_CODE);
34
35     @Override
36     protected void serializeValue(final NxExpMatchEntryValue value, final boolean hasMask, final ByteBuf outBuffer) {
37         final var nshTtlValues = ((NshTtlCaseValue) value).getNshTtlValues();
38         outBuffer.writeByte(nshTtlValues.getNshTtl().toJava());
39         if (hasMask) {
40             outBuffer.writeByte(nshTtlValues.getMask().toJava());
41         }
42     }
43
44     @Override
45     protected NxExpMatchEntryValue deserializeValue(final ByteBuf message, final boolean hasMask) {
46         return new NshTtlCaseValueBuilder()
47             .setNshTtlValues(new NshTtlValuesBuilder()
48                 .setNshTtl(readUint8(message))
49                 .setMask(hasMask ? readUint8(message) : null)
50                 .build())
51             .build();
52     }
53
54     @Override
55     protected Uint32 getExperimenterId() {
56         return NiciraConstants.NX_NSH_VENDOR_ID;
57     }
58
59     @Override
60     public int getValueLength() {
61         return VALUE_LENGTH;
62     }
63
64     @Override
65     public int getNxmFieldCode() {
66         return NXM_FIELD_CODE;
67     }
68
69     @Override
70     public MatchField getNxmField() {
71         return NxmNxNshTtl.VALUE;
72     }
73 }