BUG-2794: incorporate openflowjava api changes to openflowplugin
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / ArpThaCodec.java
1 package org.opendaylight.openflowjava.nx.codec.match;
2
3 import io.netty.buffer.ByteBuf;
4 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
5 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
6 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
7 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
8 import org.opendaylight.openflowjava.util.ByteBufUtils;
9 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpThaCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpThaCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.tha._case.ArpThaBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxArpTha;
19
20 public class ArpThaCodec extends AbstractMatchCodec {
21
22     private static final int VALUE_LENGTH = 6;
23     private static final int NXM_FIELD_CODE = 18;
24     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxArpTha> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
25             EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmNxArpTha.class);
26     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
27             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
28
29     @Override
30     public void serialize(MatchEntry input, ByteBuf outBuffer) {
31         serializeHeader(input, outBuffer);
32         ArpThaCase arpThaCase = ((ArpThaCase) input.getMatchEntryValue());
33         outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(arpThaCase.getArpTha().getMacAddress().getValue()));
34     }
35
36     @Override
37     public MatchEntry deserialize(ByteBuf message) {
38         MatchEntryBuilder matchEntryBuilder = deserializeHeader(message);
39         byte[] address = new byte[VALUE_LENGTH];
40         message.readBytes(address);
41         ArpThaCaseBuilder arpThaCaseBuilder = new ArpThaCaseBuilder();
42         ArpThaBuilder arpThaBuilder = new ArpThaBuilder();
43         arpThaBuilder.setMacAddress(new MacAddress(ByteBufUtils.bytesToHexString(address)));
44         arpThaCaseBuilder.setArpTha(arpThaBuilder.build());
45         matchEntryBuilder.setMatchEntryValue(arpThaCaseBuilder.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_1_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 NxmNxArpTha.class;
67     }
68
69     @Override
70     public Class<? extends OxmClassBase> getOxmClass() {
71         return Nxm1Class.class;
72     }
73
74 }