f591bf54ca0e57a60c888b031b0f59315232b369
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / match / OxmEthDstDeserializer.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. 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.protocol.impl.deserialization.match;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthDst;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthDstCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.dst._case.EthDstBuilder;
20
21 /**
22  * Translates OxmEthDst messages.
23  *
24  * @author michal.polkorab
25  */
26 public class OxmEthDstDeserializer extends AbstractOxmMatchEntryDeserializer {
27     @Override
28     public MatchEntry deserialize(final ByteBuf input) {
29         MatchEntryBuilder builder = processHeader(getOxmClass(), getOxmField(), input);
30         addEthDstValue(input, builder);
31         return builder.build();
32     }
33
34     private static void addEthDstValue(final ByteBuf input, final MatchEntryBuilder builder) {
35         EthDstCaseBuilder caseBuilder = new EthDstCaseBuilder();
36         EthDstBuilder ethBuilder = new EthDstBuilder();
37         ethBuilder.setMacAddress(OxmDeserializerHelper.convertMacAddress(input));
38         if (builder.isHasMask()) {
39             ethBuilder.setMask(OxmDeserializerHelper.convertMask(input, EncodeConstants.MAC_ADDRESS_LENGTH));
40         }
41         caseBuilder.setEthDst(ethBuilder.build());
42         builder.setMatchEntryValue(caseBuilder.build());
43     }
44
45     @Override
46     protected Class<? extends MatchField> getOxmField() {
47         return EthDst.class;
48     }
49
50     @Override
51     protected Class<? extends OxmClassBase> getOxmClass() {
52         return OpenflowBasicClass.class;
53     }
54
55 }