3270e1f14dbb61a0eaab727db8bc3bd499a6db4f
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / Ipv4ArbitraryBitMaskDestinationEntrySerializerTest.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 static org.junit.Assert.assertArrayEquals;
12
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMaskBuilder;
21
22 public class Ipv4ArbitraryBitMaskDestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
23
24     @Test
25     public void testSerialize() {
26         final Ipv4Address ipv4Address = new Ipv4Address("192.168.10.0");
27         final DottedQuad ipv4mask = new DottedQuad("255.255.255.0");
28
29         final Match ipv4abmMatch = new MatchBuilder()
30                 .setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder()
31                         .setIpv4DestinationAddressNoMask(ipv4Address)
32                         .setIpv4DestinationArbitraryBitmask(ipv4mask)
33                         .build())
34                 .build();
35
36         assertMatch(ipv4abmMatch, true, (out) -> {
37             byte[] address = new byte[4];
38             out.readBytes(address);
39             assertArrayEquals(address, new byte[]{ (byte) 192, (byte) 168, 10, 0 });
40
41             byte[] mask = new byte[4];
42             out.readBytes(mask);
43             assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
44         });
45
46         final Match ipv4abmMatchNoMask = new MatchBuilder()
47                 .setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder()
48                         .setIpv4DestinationAddressNoMask(ipv4Address)
49                         .build())
50                 .build();
51
52         assertMatch(ipv4abmMatchNoMask, false, (out) -> {
53             byte[] address = new byte[4];
54             out.readBytes(address);
55             assertArrayEquals(address, new byte[]{ (byte) 192, (byte) 168, 10, 0 });
56         });
57     }
58
59     @Override
60     protected short getLength() {
61         return EncodeConstants.SIZE_OF_INT_IN_BYTES;
62     }
63
64     @Override
65     protected int getOxmFieldCode() {
66         return OxmMatchConstants.IPV4_DST;
67     }
68
69     @Override
70     protected int getOxmClassCode() {
71         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
72     }
73
74 }