2 * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
11 import static org.junit.Assert.assertArrayEquals;
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;
22 public class Ipv4ArbitraryBitMaskSourceEntrySerializerTest extends AbstractMatchEntrySerializerTest {
25 public void testSerialize() throws Exception {
26 final Ipv4Address ipv4Address = new Ipv4Address("192.168.10.0");
27 final DottedQuad ipv4mask = new DottedQuad("255.255.255.0");
29 final Match ipv4abmMatch = new MatchBuilder()
30 .setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder()
31 .setIpv4SourceAddressNoMask(ipv4Address)
32 .setIpv4SourceArbitraryBitmask(ipv4mask)
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 });
41 byte[] mask = new byte[4];
43 assertArrayEquals(mask, new byte[]{ (byte) 255, (byte) 255, (byte) 255, 0 });
46 final Match ipv4abmMatchNoMask = new MatchBuilder()
47 .setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder()
48 .setIpv4SourceAddressNoMask(ipv4Address)
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 });
60 protected short getLength() {
61 return EncodeConstants.SIZE_OF_INT_IN_BYTES;
65 protected int getOxmFieldCode() {
66 return OxmMatchConstants.IPV4_SRC;
70 protected int getOxmClassCode() {
71 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;