Merge "Add Match entry serializers"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / EthernetDestinationEntrySerializer.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
10
11 import io.netty.buffer.ByteBuf;
12 import java.util.Objects;
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.opendaylight.model.match.types.rev131026.Match;
17
18 public class EthernetDestinationEntrySerializer extends AbstractMatchEntrySerializer {
19
20     @Override
21     public void serialize(Match match, ByteBuf outBuffer) {
22         super.serialize(match, outBuffer);
23         writeMacAddress(match.getEthernetMatch().getEthernetDestination().getAddress(), outBuffer);
24
25         if (getHasMask(match)) {
26             writeMask(ByteBufUtils.macAddressToBytes(
27                     match.getEthernetMatch().getEthernetDestination().getMask().getValue()),
28                     outBuffer,
29                     getValueLength());
30         }
31     }
32
33     @Override
34     public boolean matchTypeCheck(Match match) {
35         return Objects.nonNull(match.getEthernetMatch()) &&
36                 Objects.nonNull(match.getEthernetMatch().getEthernetDestination());
37     }
38
39     @Override
40     protected boolean getHasMask(Match match) {
41         return Objects.nonNull(match.getEthernetMatch().getEthernetDestination().getMask());
42     }
43
44     @Override
45     protected int getOxmFieldCode() {
46         return OxmMatchConstants.ETH_DST;
47     }
48
49     @Override
50     protected int getOxmClassCode() {
51         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
52     }
53
54     @Override
55     protected int getValueLength() {
56         return EncodeConstants.MAC_ADDRESS_LENGTH;
57     }
58
59 }