2 * Copyright (c) 2013 Cisco Systems, Inc. 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
8 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action;
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.SetNwSrcActionCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
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;
26 * match conversion and injection test
28 public class ActionSetNwSrcReactorTest {
30 private Address[] addresses;
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(),
46 * convert for OF-1.3, inject into {@link ActionBuilder}
50 public void testMatchConvertorV13_flow() {
51 final ActionBuilder target = new ActionBuilder();
52 for (final Address address : addresses) {
53 final SetNwSrcActionCase action = prepareSetNwSrcActionCase(address);
54 ActionSetNwSrcReactor.getInstance().convert(action,
55 OFConstants.OFP_VERSION_1_3, target);
57 MatchEntry mEntry = target.getActionChoice() getAugmentation(OxmFieldsAction.class).getMatchEntry().get(0);
58 Assert.assertNotNull(mEntry);
59 if (address instanceof Ipv4) {
60 Ipv4SrcCase ipv4SrcCase = ((Ipv4SrcCase) mEntry.getMatchEntryValue());
61 Assert.assertNotNull(ipv4SrcCase.getIpv4Src());
62 } else if (address instanceof Ipv6) {
63 Ipv6SrcCase ipv6SrcCase = ((Ipv6SrcCase) mEntry.getMatchEntryValue());
64 Assert.assertNotNull(ipv6SrcCase.getIpv6Src().getIpv6Address());
66 Assert.fail("not tested yet: " + address.getClass().getName());
76 private static SetNwSrcActionCase prepareSetNwSrcActionCase(final Address address) {
77 return new SetNwSrcActionCaseBuilder().setSetNwSrcAction(
78 new SetNwSrcActionBuilder().setAddress(address).build()).build();
82 * convert for OF-1.0, inject into {@link ActionBuilder}
85 public void testMatchConvertorV10_flow() {
86 final ActionBuilder target = new ActionBuilder();
87 for (final Address address : addresses) {
88 final SetNwSrcActionCase action = prepareSetNwSrcActionCase(address);
90 if (address instanceof Ipv4) {
91 ActionSetNwSrcReactor.getInstance().convert(action,
92 OFConstants.OFP_VERSION_1_0, target);
95 ActionSetNwSrcReactor.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) {
100 Assert.assertEquals(IllegalArgumentException.class, e.getClass());