Remove EncodeConstants.SIZE_OF_{BYTE,SHORT,INT,LONG}_IN_BYTES
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / Ipv4DestinationEntrySerializerTest.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 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
9
10 import static org.junit.Assert.assertArrayEquals;
11
12 import org.junit.Test;
13 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
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.match.layer._3.match.Ipv4MatchBuilder;
18
19 public class Ipv4DestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
20     @Test
21     public void testSerialize() {
22         final Match ipv4match = new MatchBuilder()
23                 .setLayer3Match(new Ipv4MatchBuilder()
24                         .setIpv4Destination(new Ipv4Prefix("10.0.2.0/24"))
25                         .build())
26                 .build();
27
28         assertMatch(ipv4match, true, (out) -> {
29             byte[] address = new byte[4];
30             out.readBytes(address);
31             assertArrayEquals(address, new byte[]{ 10, 0, 2, 0 });
32
33             byte[] mask = new byte[4];
34             out.readBytes(mask);
35             assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
36         });
37
38         final Match ipv4matchNoMask = new MatchBuilder()
39                 .setLayer3Match(new Ipv4MatchBuilder()
40                         .setIpv4Destination(new Ipv4Prefix("10.0.0.0/32"))
41                         .build())
42                 .build();
43
44         assertMatch(ipv4matchNoMask, false, (out) -> {
45             byte[] address = new byte[4];
46             out.readBytes(address);
47             assertArrayEquals(address, new byte[]{ 10, 0, 0, 0 });
48         });
49     }
50
51     @Override
52     protected short getLength() {
53         return Integer.BYTES;
54     }
55
56     @Override
57     protected int getOxmFieldCode() {
58         return OxmMatchConstants.IPV4_DST;
59     }
60
61     @Override
62     protected int getOxmClassCode() {
63         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
64     }
65 }