Merge "Rework bit-copying functions and re-enable tests"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / ArpTargetTransportAddressEntrySerializer.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.Iterator;
13 import java.util.Objects;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
19
20 public class ArpTargetTransportAddressEntrySerializer extends AbstractMatchEntrySerializer {
21
22     @Override
23     public void serialize(Match match, ByteBuf outBuffer) {
24         super.serialize(match, outBuffer);
25         writeIpv4Prefix(((ArpMatch) match.getLayer3Match()).getArpTargetTransportAddress(), outBuffer);
26     }
27
28     @Override
29     public boolean matchTypeCheck(Match match) {
30         return Objects.nonNull(match.getLayer3Match())
31                 && match.getLayer3Match() instanceof ArpMatch
32                 && Objects.nonNull(((ArpMatch) match.getLayer3Match()).getArpTargetTransportAddress());
33     }
34
35     @Override
36     protected boolean getHasMask(Match match) {
37         // Split address to IP and mask
38         final Iterator<String> addressParts = IpConversionUtil.splitToParts(
39                 ((ArpMatch) match.getLayer3Match()).getArpTargetTransportAddress());
40         addressParts.next();
41
42         // Check if we have mask
43         return addressParts.hasNext() && Integer.parseInt(addressParts.next()) < 32;
44     }
45
46     @Override
47     protected int getOxmFieldCode() {
48         return OxmMatchConstants.ARP_TPA;
49     }
50
51     @Override
52     protected int getOxmClassCode() {
53         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
54     }
55
56     @Override
57     protected int getValueLength() {
58         return EncodeConstants.SIZE_OF_INT_IN_BYTES;
59     }
60
61 }