Fix checkstyle violations
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / ArpOpCodec.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 io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
12 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfArpOp;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.arp.op.grouping.ArpOpValuesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpOpCaseValue;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpOpCaseValueBuilder;
24
25 public class ArpOpCodec extends AbstractMatchCodec {
26     private static final int VALUE_LENGTH = 2;
27     private static final int NXM_FIELD_CODE = 15;
28     public static final MatchEntrySerializerKey<Nxm0Class, NxmOfArpOp> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
29             EncodeConstants.OF13_VERSION_ID, Nxm0Class.class, NxmOfArpOp.class);
30     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
31             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
32
33     @Override
34     public void serialize(MatchEntry input, ByteBuf outBuffer) {
35         serializeHeader(input, outBuffer);
36         ArpOpCaseValue arpOpCase = ((ArpOpCaseValue) input.getMatchEntryValue());
37         outBuffer.writeShort(arpOpCase.getArpOpValues().getValue().toJava());
38     }
39
40     @Override
41     public MatchEntry deserialize(ByteBuf message) {
42         MatchEntryBuilder matchEntryBuilder = deserializeHeaderToBuilder(message);
43         ArpOpCaseValueBuilder caseBuilder = new ArpOpCaseValueBuilder();
44         caseBuilder.setArpOpValues(new ArpOpValuesBuilder().setValue(message.readUnsignedShort()).build());
45         matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
46         return matchEntryBuilder.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_0_CLASS;
57     }
58
59     @Override
60     public int getValueLength() {
61         return VALUE_LENGTH;
62     }
63
64     @Override
65     public Class<? extends MatchField> getNxmField() {
66         return NxmOfArpOp.class;
67     }
68
69     @Override
70     public Class<? extends OxmClassBase> getOxmClass() {
71         return Nxm0Class.class;
72     }
73 }