Fix checkstyle violations
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / EthSrcCodec.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowjava.nx.codec.match;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
12 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
15 import org.opendaylight.openflowjava.util.ByteBufUtils;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfEthSrc;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.eth.src.grouping.EthSrcValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthSrcCaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthSrcCaseValueBuilder;
26
27 public class EthSrcCodec extends AbstractMatchCodec {
28     private static final int VALUE_LENGTH = 6;
29     private static final int NXM_FIELD_CODE = 2;
30     public static final MatchEntrySerializerKey<Nxm0Class, NxmOfEthSrc> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
31             EncodeConstants.OF13_VERSION_ID, Nxm0Class.class, NxmOfEthSrc.class);
32     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
33             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
34
35     @Override
36     public void serialize(MatchEntry input, ByteBuf outBuffer) {
37         serializeHeader(input, outBuffer);
38         EthSrcCaseValue ethSrcCase = ((EthSrcCaseValue) input.getMatchEntryValue());
39         outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(ethSrcCase.getEthSrcValues().getMacAddress().getValue()));
40     }
41
42     @Override
43     public MatchEntry deserialize(ByteBuf message) {
44         MatchEntryBuilder matchEntryBuilder = deserializeHeaderToBuilder(message);
45         byte[] address = new byte[VALUE_LENGTH];
46         message.readBytes(address);
47         EthSrcCaseValueBuilder caseBuilder = new EthSrcCaseValueBuilder();
48         caseBuilder.setEthSrcValues(new EthSrcValuesBuilder().setMacAddress(
49                 new MacAddress(ByteBufUtils.macAddressToString(address))).build());
50         matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
51         matchEntryBuilder.setHasMask(false);
52         return matchEntryBuilder.build();
53     }
54
55     @Override
56     public int getNxmFieldCode() {
57         return NXM_FIELD_CODE;
58     }
59
60     @Override
61     public int getOxmClassCode() {
62         return OxmMatchConstants.NXM_0_CLASS;
63     }
64
65     @Override
66     public int getValueLength() {
67         return VALUE_LENGTH;
68     }
69
70     @Override
71     public Class<? extends MatchField> getNxmField() {
72         return NxmOfEthSrc.class;
73     }
74
75     @Override
76     public Class<? extends OxmClassBase> getOxmClass() {
77         return Nxm0Class.class;
78     }
79 }