d3f51e9cc421e3451eb3f6ef9c08c675fde7bb76
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / action / ActionSetNwDstReactorTest.java
1 /**
2  * Copyright (c) 2013 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.sal.convertor.action;
9
10 import org.junit.Assert;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.opendaylight.openflowplugin.api.OFConstants;
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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
24
25 /**
26  * match conversion and injection test
27  */
28 public class ActionSetNwDstReactorTest {
29
30     private Address[] addresses;
31
32     /**
33      * prepare input match
34      */
35     @Before
36     public void setUp() {
37         addresses = new Address[]{
38                 new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1/32")).build(),
39                 new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1/16")).build(),
40                 new Ipv6Builder().setIpv6Address(new Ipv6Prefix("1234:5678:9abc:def1:2345:6789:abcd:ef12/128")).build(),
41                 new Ipv6Builder().setIpv6Address(new Ipv6Prefix("1234:5678:9abc:def1:2345:6789:abcd:ef12/42")).build(),
42         };
43     }
44
45     /**
46      * convert for OF-1.3, inject into {@link ActionBuilder}
47      */
48     @Test
49     public void testMatchConvertorV13_flow() {
50         final ActionBuilder target = new ActionBuilder();
51         for (final Address address : addresses) {
52             final SetNwDstActionCase action = prepareSetNwDstActionCase(address);
53             ActionSetNwDstReactor.getInstance().convert(action,
54                     OFConstants.OFP_VERSION_1_3, target);
55             final Object mEntry = target.getActionChoice();
56 /*
57             Assert.assertNotNull(mEntry);
58             if (address instanceof Ipv4) {
59                 Ipv4DstCase ipv4DstCase = ((Ipv4DstCase) mEntry.getMatchEntryValue());
60                 Assert.assertNotNull(ipv4DstCase.getIpv4Dst());
61             } else if (address instanceof Ipv6) {
62                 Ipv6DstCase ipv6DstCase = ((Ipv6DstCase) mEntry.getMatchEntryValue());
63                 Assert.assertNotNull(ipv6DstCase.getIpv6Dst());
64             } else {
65                 Assert.fail("not tested yet: " + address.getClass().getName());
66             }
67 */
68         }
69     }
70
71     /**
72      * @param address
73      * @return
74      */
75     private static SetNwDstActionCase prepareSetNwDstActionCase(final Address address) {
76         return new SetNwDstActionCaseBuilder().setSetNwDstAction(
77                 new SetNwDstActionBuilder().setAddress(address).build()).build();
78     }
79
80     /**
81      * convert for OF-1.0, inject into {@link ActionBuilder}
82      */
83     @Test
84     public void testMatchConvertorV10_flow() {
85         final ActionBuilder target = new ActionBuilder();
86         for (final Address address : addresses) {
87             final SetNwDstActionCase action = prepareSetNwDstActionCase(address);
88
89             if (address instanceof Ipv4) {
90                 ActionSetNwDstReactor.getInstance().convert(action,
91                         OFConstants.OFP_VERSION_1_0, target);
92 //                Assert.assertNotNull(target.getAugmentation(IpAddressAction.class).getIpAddress());
93             } else {
94                 try {
95                     ActionSetNwDstReactor.getInstance().convert(action,
96                             OFConstants.OFP_VERSION_1_0, target);
97                     Assert.fail("address of this type must not pass the reactor: " + address.getClass().getName());
98                 } catch (final Exception e) {
99                     //expected
100                     Assert.assertEquals(IllegalArgumentException.class, e.getClass());
101                 }
102             }
103         }
104     }
105 }