Upgrade ietf-{inet,yang}-types to 2013-07-15
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / EthDstCodec.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
9 package org.opendaylight.openflowjava.nx.codec.match;
10
11 import io.netty.buffer.ByteBuf;
12
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.Nxm0Class;
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.NxmOfEthDst;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.eth.dst.grouping.EthDstValuesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthDstCaseValue;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthDstCaseValueBuilder;
28
29 public class EthDstCodec extends AbstractMatchCodec {
30
31     private static final int VALUE_LENGTH = 6;
32     private static final int NXM_FIELD_CODE = 1;
33     public static final MatchEntrySerializerKey<Nxm0Class, NxmOfEthDst> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
34             EncodeConstants.OF13_VERSION_ID, Nxm0Class.class, NxmOfEthDst.class);
35     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
36             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
37
38     @Override
39     public void serialize(MatchEntry input, ByteBuf outBuffer) {
40         serializeHeader(input, outBuffer);
41         EthDstCaseValue ethDstCase = ((EthDstCaseValue) input.getMatchEntryValue());
42         outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(ethDstCase.getEthDstValues().getMacAddress().getValue()));
43     }
44
45     @Override
46     public MatchEntry deserialize(ByteBuf message) {
47         MatchEntryBuilder matchEntryBuilder = deserializeHeader(message);
48         byte[] address = new byte[VALUE_LENGTH];
49         message.readBytes(address);
50         EthDstCaseValueBuilder caseBuilder = new EthDstCaseValueBuilder();
51         caseBuilder.setEthDstValues(new EthDstValuesBuilder().setMacAddress(
52                 new MacAddress(ByteBufUtils.macAddressToString(address))).build());
53         matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
54         return matchEntryBuilder.build();
55     }
56
57     @Override
58     public int getNxmFieldCode() {
59         return NXM_FIELD_CODE;
60     }
61
62     @Override
63     public int getOxmClassCode() {
64         return OxmMatchConstants.NXM_0_CLASS;
65     }
66
67     @Override
68     public int getValueLength() {
69         return VALUE_LENGTH;
70     }
71
72     @Override
73     public Class<? extends MatchField> getNxmField() {
74         return NxmOfEthDst.class;
75     }
76
77     @Override
78     public Class<? extends OxmClassBase> getOxmClass() {
79         return Nxm0Class.class;
80     }
81
82 }