Bump upstreams for 2022.09 Chlorine
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / TunIdCodec.java
1 /*
2  * Copyright (c) 2014, 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.readUint64;
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.NxmNxTunId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.TunIdCaseValue;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.TunIdCaseValueBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.id.grouping.TunIdValuesBuilder;
25
26 public class TunIdCodec extends AbstractMatchCodec {
27     private static final int VALUE_LENGTH = 8;
28     private static final int NXM_FIELD_CODE = 16;
29     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxTunId> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
30             EncodeConstants.OF_VERSION_1_3, Nxm1Class.VALUE, NxmNxTunId.VALUE);
31     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
32             EncodeConstants.OF_VERSION_1_3, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
33
34     @Override
35     public void serialize(final MatchEntry input, final ByteBuf outBuffer) {
36         serializeHeader(input, outBuffer);
37         outBuffer.writeLong(((TunIdCaseValue) input.getMatchEntryValue()).getTunIdValues().getValue().longValue());
38     }
39
40     @Override
41     public MatchEntry deserialize(final ByteBuf message) {
42         return deserializeHeaderToBuilder(message)
43             .setMatchEntryValue(new TunIdCaseValueBuilder()
44                 .setTunIdValues(new TunIdValuesBuilder().setValue(readUint64(message)).build())
45                 .build())
46             .build();
47     }
48
49     @Override
50     public int getNxmFieldCode() {
51         return NXM_FIELD_CODE;
52     }
53
54     @Override
55     public int getOxmClassCode() {
56         return OxmMatchConstants.NXM_1_CLASS;
57     }
58
59     @Override
60     public int getValueLength() {
61         return VALUE_LENGTH;
62     }
63
64     @Override
65     public MatchField getNxmField() {
66         return NxmNxTunId.VALUE;
67     }
68
69     @Override
70     public OxmClassBase getOxmClass() {
71         return Nxm1Class.VALUE;
72     }
73 }