2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.nx.codec.match;
11 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.openflowjava.util.ByteBufUtils;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxArpSha;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.arp.sha.grouping.ArpShaValuesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpShaCaseValue;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpShaCaseValueBuilder;
29 public class ArpShaCodec extends AbstractMatchCodec {
31 private static final int VALUE_LENGTH = 6;
32 private static final int NXM_FIELD_CODE = 17;
33 public static final MatchEntrySerializerKey<Nxm1Class, NxmNxArpSha> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
34 EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmNxArpSha.class);
35 public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
36 EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
39 public void serialize(MatchEntry input, ByteBuf outBuffer) {
40 serializeHeader(input, outBuffer);
41 ArpShaCaseValue value = ((ArpShaCaseValue) input.getMatchEntryValue());
42 outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(value.getArpShaValues().getMacAddress().getValue()));
46 public MatchEntry deserialize(ByteBuf message) {
47 MatchEntryBuilder matchEntriesBuilder = deserializeHeader(message);
48 byte[] address = new byte[VALUE_LENGTH];
49 message.readBytes(address);
50 ArpShaCaseValueBuilder caseBuilder = new ArpShaCaseValueBuilder();
51 caseBuilder.setArpShaValues(new ArpShaValuesBuilder().setMacAddress(
52 new MacAddress(ByteBufUtils.macAddressToString(address))).build());
53 matchEntriesBuilder.setMatchEntryValue(caseBuilder.build());
54 return matchEntriesBuilder.build();
58 public int getNxmFieldCode() {
59 return NXM_FIELD_CODE;
63 public int getOxmClassCode() {
64 return OxmMatchConstants.NXM_1_CLASS;
68 public int getValueLength() {
73 public Class<? extends MatchField> getNxmField() {
74 return NxmNxArpSha.class;
78 public Class<? extends OxmClassBase> getOxmClass() {
79 return Nxm1Class.class;