Bug 1492 - java.lang.IllegalArgumentException: 'Ipv4Address
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / translator / FlowRemovedTranslatorTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.openflow.md.core.translator;
9
10 import org.junit.Test;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
25
26 import static org.junit.Assert.assertEquals;
27
28 public class FlowRemovedTranslatorTest extends FlowRemovedTranslator {
29
30     @Test
31     public void MatchEntryToIpv4PrefixTest() {
32         Ipv4AddressMatchEntry ipv4AddressMatchEntry = new Ipv4AddressMatchEntryBuilder()
33                 .setIpv4Address(new Ipv4Address("10.0.0.0")).build();
34         byte[] maskBytes = new byte[1];
35         maskBytes[0] = (byte) 255;
36         MaskMatchEntry maskMatchEntry = new MaskMatchEntryBuilder().setMask(maskBytes).build();
37         MatchEntries entry = new MatchEntriesBuilder().setOxmMatchField(Ipv4Src.class)
38                 .addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressMatchEntry)
39                 .addAugmentation(MaskMatchEntry.class, maskMatchEntry).setHasMask(true).build();
40         Ipv4Prefix ipv4Prefix = toIpv4Prefix(entry);
41         assertEquals("10.0.0.0/8", ipv4Prefix.getValue());
42     }
43
44     @Test
45     public void MatchEntryToIpv6PrefixTest() {
46         Ipv6AddressMatchEntry ipv6AddressMatchEntry = new Ipv6AddressMatchEntryBuilder()
47                 .setIpv6Address(new Ipv6Address("1234:5678:9ABC:DEF0:FDCD:A987:6543:0")).build();
48         byte[] maskBytes = new byte[1];
49         maskBytes[0] = (byte) 255;
50         MaskMatchEntry maskMatchEntry = new MaskMatchEntryBuilder().setMask(maskBytes).build();
51         MatchEntries entry = new MatchEntriesBuilder().setOxmMatchField(Ipv6Src.class)
52                 .addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressMatchEntry)
53                 .addAugmentation(MaskMatchEntry.class, maskMatchEntry).setHasMask(true).build();
54         Ipv6Prefix ipv6Prefix = toIpv6Prefix(entry);
55         assertEquals("1234:5678:9ABC:DEF0:FDCD:A987:6543:0/8", ipv6Prefix.getValue());
56     }
57 }