dacbe1f87630b1892a9ef1b10a2ab5bcc5267bcf
[openflowjava.git] / openflow-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / EthDstCodec.java
1 package org.opendaylight.openflowjava.nx.codec.match;
2
3 import io.netty.buffer.ByteBuf;
4
5 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
6 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
7 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
8 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
9 import org.opendaylight.openflowjava.util.ByteBufUtils;
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.extension.nicira.match.rev140421.NxmOfEthDst;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.extension.nicira.match.rev140421.OfjAugNxMatch;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.extension.nicira.match.rev140421.OfjAugNxMatchBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.extension.nicira.match.rev140421.ofj.nxm.of.match.eth.dst.grouping.EthDstValuesBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmClassBase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
20
21 public class EthDstCodec extends AbstractMatchCodec {
22
23     private static final int VALUE_LENGTH = 6;
24     private static final int NXM_FIELD_CODE = 2;
25     public static final MatchEntrySerializerKey<Nxm0Class, NxmOfEthDst> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
26             EncodeConstants.OF13_VERSION_ID, Nxm0Class.class, NxmOfEthDst.class);
27     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
28             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
29
30     @Override
31     public void serialize(MatchEntries input, ByteBuf outBuffer) {
32         serializeHeader(input, outBuffer);
33         String value = input.getAugmentation(OfjAugNxMatch.class).getEthDstValues().getMacAddress().getValue();
34         outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(value));
35     }
36
37     @Override
38     public MatchEntries deserialize(ByteBuf message) {
39         MatchEntriesBuilder matchEntriesBuilder = deserializeHeader(message);
40         OfjAugNxMatchBuilder augNxMatchBuilder = new OfjAugNxMatchBuilder();
41         byte[] address = new byte[VALUE_LENGTH];
42         message.readBytes(address);
43         augNxMatchBuilder.setEthDstValues(new EthDstValuesBuilder().setMacAddress(
44                 new MacAddress(ByteBufUtils.macAddressToString(address))).build());
45         matchEntriesBuilder.addAugmentation(OfjAugNxMatch.class, augNxMatchBuilder.build());
46         return matchEntriesBuilder.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 NxmOfEthDst.class;
67     }
68
69     @Override
70     public Class<? extends OxmClassBase> getOxmClass() {
71         return Nxm0Class.class;
72     }
73
74 }