Bump upstreams for 2022.09 Chlorine
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / CtMarkCodec.java
1 /*
2  * Copyright (c) 2017 NEC Corporation 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.readUint32;
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.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxCtMark;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.CtMarkCaseValue;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.CtMarkCaseValueBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.mark.grouping.CtMarkValuesBuilder;
26
27 /**
28  * Codec for CtMark.
29  *
30  * @author Bertrand Low.
31  */
32 public class CtMarkCodec extends AbstractMatchCodec {
33     private static final int VALUE_LENGTH = 4;
34     private static final int NXM_FIELD_CODE = 107;
35
36     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxCtMark> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
37             EncodeConstants.OF_VERSION_1_3, Nxm1Class.VALUE, NxmNxCtMark.VALUE);
38     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
39             EncodeConstants.OF_VERSION_1_3, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
40
41     @Override
42     public void serialize(final MatchEntry input, final ByteBuf outBuffer) {
43         serializeHeader(input, outBuffer);
44         CtMarkCaseValue ctMarkCase = (CtMarkCaseValue) input.getMatchEntryValue();
45         outBuffer.writeInt(ctMarkCase.getCtMarkValues().getCtMark().intValue());
46         outBuffer.writeInt(ctMarkCase.getCtMarkValues().getMask().intValue());
47     }
48
49     @Override
50     public MatchEntry deserialize(final ByteBuf message) {
51         final MatchEntryBuilder matchEntryBuilder = deserializeHeaderToBuilder(message);
52         CtMarkCaseValueBuilder caseBuilder = new CtMarkCaseValueBuilder();
53         CtMarkValuesBuilder ctMarkValuesBuilder = new CtMarkValuesBuilder();
54         if (matchEntryBuilder.getHasMask()) {
55             ctMarkValuesBuilder.setMask(readUint32(message));
56         }
57         ctMarkValuesBuilder.setCtMark(readUint32(message));
58         caseBuilder.setCtMarkValues(ctMarkValuesBuilder.build());
59         matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
60         return matchEntryBuilder.build();
61     }
62
63     @Override
64     public int getNxmFieldCode() {
65         return NXM_FIELD_CODE;
66     }
67
68     @Override
69     public int getOxmClassCode() {
70         return OxmMatchConstants.NXM_1_CLASS;
71     }
72
73     @Override
74     public int getValueLength() {
75         return VALUE_LENGTH;
76     }
77
78     @Override
79     public MatchField getNxmField() {
80         return NxmNxCtMark.VALUE;
81     }
82
83     @Override
84     public OxmClassBase getOxmClass() {
85         return Nxm1Class.VALUE;
86     }
87 }