Add multipart request message serializers
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / ArpTargetHardwareAddressEntrySerializer.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 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
19
20 public class ArpTargetHardwareAddressEntrySerializer extends AbstractMatchEntrySerializer {
21
22     @Override
23     public void serialize(Match match, ByteBuf outBuffer) {
24         super.serialize(match, outBuffer);
25         final ArpTargetHardwareAddress arpTargetHardwareAddress =
26                 ArpMatch.class.cast(match.getLayer3Match()).getArpTargetHardwareAddress();
27         writeMacAddress(arpTargetHardwareAddress.getAddress(), outBuffer);
28
29         if (getHasMask(match)) {
30             writeMask(ByteBufUtils.macAddressToBytes(
31                     arpTargetHardwareAddress.getMask().getValue()),
32                     outBuffer,
33                     getValueLength());
34         }
35     }
36
37     @Override
38     public boolean matchTypeCheck(Match match) {
39         return Objects.nonNull(match.getLayer3Match()) &&
40                 ArpMatch.class.isInstance(match.getLayer3Match()) &&
41                 Objects.nonNull(ArpMatch.class.cast(match.getLayer3Match()).getArpTargetHardwareAddress());
42     }
43
44     @Override
45     protected boolean getHasMask(Match match) {
46         return Objects.nonNull(ArpMatch.class.cast(match.getLayer3Match()).getArpTargetHardwareAddress().getMask());
47     }
48
49     @Override
50     protected int getOxmFieldCode() {
51         return OxmMatchConstants.ARP_THA;
52     }
53
54     @Override
55     protected int getOxmClassCode() {
56         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
57     }
58
59     @Override
60     protected int getValueLength() {
61         return EncodeConstants.MAC_ADDRESS_LENGTH;
62     }
63
64 }