1 package org.opendaylight.openflowjava.nx.codec.match;
3 import io.netty.buffer.ByteBuf;
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.oxm.rev130731.MatchField;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmClassBase;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfEthSrc;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.OfjAugNxMatch;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.OfjAugNxMatchBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.eth.src.grouping.EthSrcValuesBuilder;
21 public class EthSrcCodec extends AbstractMatchCodec {
23 private static final int VALUE_LENGTH = 6;
24 private static final int NXM_FIELD_CODE = 2;
25 public static final MatchEntrySerializerKey<Nxm0Class, NxmOfEthSrc> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
26 EncodeConstants.OF13_VERSION_ID, Nxm0Class.class, NxmOfEthSrc.class);
27 public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
28 EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
31 public void serialize(MatchEntries input, ByteBuf outBuffer) {
32 serializeHeader(input, outBuffer);
33 String value = input.getAugmentation(OfjAugNxMatch.class).getEthSrcValues().getMacAddress().getValue();
34 outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(value));
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.setEthSrcValues(new EthSrcValuesBuilder().setMacAddress(
44 new MacAddress(ByteBufUtils.macAddressToString(address))).build());
45 matchEntriesBuilder.addAugmentation(OfjAugNxMatch.class, augNxMatchBuilder.build());
46 return matchEntriesBuilder.build();
50 public int getNxmFieldCode() {
51 return NXM_FIELD_CODE;
55 public int getOxmClassCode() {
56 return OxmMatchConstants.NXM_0_CLASS;
60 public int getValueLength() {
65 public Class<? extends MatchField> getNxmField() {
66 return NxmOfEthSrc.class;
70 public Class<? extends OxmClassBase> getOxmClass() {
71 return Nxm0Class.class;