Bump upstreams
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / match / ArpTargetTransportAddressEntryDeserializerTest.java
1 /*
2  * Copyright (c) 2017 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.openflowplugin.impl.protocol.deserialization.match;
9
10 import static org.junit.Assert.assertEquals;
11
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.UnpooledByteBufAllocator;
14 import java.util.Iterator;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
23
24 public class ArpTargetTransportAddressEntryDeserializerTest extends AbstractMatchEntryDeserializerTest {
25     @Test
26     public void deserializeEntry() {
27         final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
28         final Ipv4Prefix arpTargetTransportAddress = new Ipv4Prefix("192.168.0.0/24");
29         final Ipv4Prefix arpTargetTransportAddressNoMask = new Ipv4Prefix("192.168.0.0/32");
30
31         writeHeader(in, false);
32         Iterator<String> addressParts = IpConversionUtil.splitToParts(arpTargetTransportAddressNoMask);
33         in.writeBytes(IetfInetUtil.ipv4AddressBytes(new Ipv4Address(addressParts.next())));
34
35         assertEquals(arpTargetTransportAddressNoMask.getValue(),
36                 ((ArpMatch) deserialize(in).getLayer3Match()).getArpTargetTransportAddress().getValue());
37         assertEquals(0, in.readableBytes());
38
39         writeHeader(in, true);
40         addressParts = IpConversionUtil.splitToParts(arpTargetTransportAddress);
41         in.writeBytes(IetfInetUtil.ipv4AddressBytes(new Ipv4Address(addressParts.next())));
42         in.writeBytes(MatchConvertorUtil.extractIpv4Mask(addressParts));
43
44         final Ipv4Prefix desAddress =
45                 ((ArpMatch) deserialize(in).getLayer3Match()).getArpTargetTransportAddress();
46         assertEquals(arpTargetTransportAddress.getValue(), desAddress.getValue());
47         assertEquals(0, in.readableBytes());
48     }
49
50     @Override
51     protected int getOxmClassCode() {
52         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
53     }
54
55     @Override
56     protected int getOxmFieldCode() {
57         return OxmMatchConstants.ARP_TPA;
58     }
59
60     @Override
61     protected int getValueLength() {
62         return Integer.BYTES;
63     }
64 }