1 package org.opendaylight.openflowjava.nx.codec.match;
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.Nxm0Class;
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.EthSrcCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthSrcCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.src._case.EthSrcBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfEthSrc;
20 public class EthSrcCodec extends AbstractMatchCodec {
22 private static final int VALUE_LENGTH = 6;
23 private static final int NXM_FIELD_CODE = 2;
24 public static final MatchEntrySerializerKey<Nxm0Class, NxmOfEthSrc> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
25 EncodeConstants.OF13_VERSION_ID, Nxm0Class.class, NxmOfEthSrc.class);
26 public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
27 EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
30 public void serialize(MatchEntry input, ByteBuf outBuffer) {
31 serializeHeader(input, outBuffer);
32 EthSrcCase ethSrcCase = ((EthSrcCase) input.getMatchEntryValue());
33 outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(ethSrcCase.getEthSrc().getMacAddress().getValue()));
37 public MatchEntry deserialize(ByteBuf message) {
38 MatchEntryBuilder matchEntryBuilder = deserializeHeader(message);
39 byte[] address = new byte[VALUE_LENGTH];
40 message.readBytes(address);
41 EthSrcCaseBuilder ethSrcCaseBuilder = new EthSrcCaseBuilder();
42 EthSrcBuilder ethSrcBuilder = new EthSrcBuilder();
43 ethSrcBuilder.setMacAddress(new MacAddress(ByteBufUtils.macAddressToString(address)));
44 ethSrcCaseBuilder.setEthSrc(ethSrcBuilder.build());
45 matchEntryBuilder.setMatchEntryValue(ethSrcCaseBuilder.build());
46 matchEntryBuilder.setHasMask(false);
47 return matchEntryBuilder.build();
51 public int getNxmFieldCode() {
52 return NXM_FIELD_CODE;
56 public int getOxmClassCode() {
57 return OxmMatchConstants.NXM_0_CLASS;
61 public int getValueLength() {
66 public Class<? extends MatchField> getNxmField() {
67 return NxmOfEthSrc.class;
71 public Class<? extends OxmClassBase> getOxmClass() {
72 return Nxm0Class.class;