Fix checkstyle violations in openflowjava extensions
[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
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.NxmNxCtMark;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.mark.grouping.CtMarkValuesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtMarkCaseValue;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtMarkCaseValueBuilder;
25
26 /**
27  * Codec for CtMark.
28  * s
29  * @author Bertrand Low.
30  */
31 public class CtMarkCodec extends AbstractMatchCodec {
32
33     private static final int VALUE_LENGTH = 8;
34     private static final int NXM_FIELD_CODE = 107;
35     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxCtMark> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
36             EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmNxCtMark.class);
37     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
38             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
39
40     @Override
41     public void serialize(MatchEntry input, ByteBuf outBuffer) {
42         serializeHeader(input, outBuffer);
43         CtMarkCaseValue ctMarkCase = (CtMarkCaseValue) input.getMatchEntryValue();
44         outBuffer.writeInt(ctMarkCase.getCtMarkValues().getCtMark().intValue());
45         outBuffer.writeInt(ctMarkCase.getCtMarkValues().getMask().intValue());
46     }
47
48     @Override
49     public MatchEntry deserialize(ByteBuf message) {
50         final MatchEntryBuilder matchEntryBuilder = deserializeHeaderToBuilder(message);
51         CtMarkCaseValueBuilder caseBuilder = new CtMarkCaseValueBuilder();
52         CtMarkValuesBuilder ctMarkValuesBuilder = new CtMarkValuesBuilder();
53         if (matchEntryBuilder.isHasMask()) {
54             ctMarkValuesBuilder.setMask(message.readUnsignedInt());
55         }
56         ctMarkValuesBuilder.setCtMark(message.readUnsignedInt());
57         caseBuilder.setCtMarkValues(ctMarkValuesBuilder.build());
58         matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
59         return matchEntryBuilder.build();
60     }
61
62     @Override
63     public int getNxmFieldCode() {
64         return NXM_FIELD_CODE;
65     }
66
67     @Override
68     public int getOxmClassCode() {
69         return OxmMatchConstants.NXM_1_CLASS;
70     }
71
72     @Override
73     public int getValueLength() {
74         return VALUE_LENGTH;
75     }
76
77     @Override
78     public Class<? extends MatchField> getNxmField() {
79         return NxmNxCtMark.class;
80     }
81
82     @Override
83     public Class<? extends OxmClassBase> getOxmClass() {
84         return Nxm1Class.class;
85     }
86
87 }