3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.sal.action;
12 import org.opendaylight.controller.sal.core.ConstructionException;
13 import java.net.InetAddress;
14 import java.net.UnknownHostException;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.junit.Test;
19 import org.junit.Assert;
20 import org.opendaylight.controller.sal.action.Action;
21 import org.opendaylight.controller.sal.action.Controller;
22 import org.opendaylight.controller.sal.action.Output;
23 import org.opendaylight.controller.sal.action.PopVlan;
24 import org.opendaylight.controller.sal.action.PushVlan;
25 import org.opendaylight.controller.sal.action.SetDlSrc;
26 import org.opendaylight.controller.sal.action.SetNwDst;
27 import org.opendaylight.controller.sal.action.SetNwSrc;
28 import org.opendaylight.controller.sal.action.SetNwTos;
29 import org.opendaylight.controller.sal.action.SetTpDst;
30 import org.opendaylight.controller.sal.action.SetTpSrc;
31 import org.opendaylight.controller.sal.action.SetVlanCfi;
32 import org.opendaylight.controller.sal.action.SetVlanId;
33 import org.opendaylight.controller.sal.action.SetVlanPcp;
34 import org.opendaylight.controller.sal.core.Node;
35 import org.opendaylight.controller.sal.core.NodeConnector;
36 import org.opendaylight.controller.sal.utils.EtherTypes;
37 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
39 public class ActionTest {
41 public void tesActionCreationValidation() {
42 Action action = new PopVlan();
43 Assert.assertTrue(action.isValid());
45 byte mac[] = { (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0x11,
46 (byte) 0x22, (byte) 0x33 };
48 action = new SetDlSrc(mac);
49 Assert.assertTrue(action.isValid());
51 action = new SetDlSrc(mac);
52 Assert.assertTrue(action.isValid());
56 public void testSetVlanActionCreation() {
59 action = new SetVlanId(2);
60 Assert.assertTrue(action.isValid());
62 action = new SetVlanId(4095);
63 Assert.assertTrue(action.isValid());
65 action = new SetVlanId(0);
66 Assert.assertFalse(action.isValid());
68 action = new SetVlanId(1);
69 Assert.assertTrue(action.isValid());
71 action = new SetVlanId(4096);
72 Assert.assertFalse(action.isValid());
76 public void testPushVlanActionCreation() {
79 action = new PushVlan(EtherTypes.QINQ, 0x4, 0x1, 2000);
80 Assert.assertTrue(action.isValid());
82 action = new PushVlan(EtherTypes.QINQ.intValue(), 0x4, 0x1, 2000);
83 Assert.assertTrue(action.isValid());
85 action = new PushVlan(EtherTypes.OLDQINQ, 0x4, 2, 2000);
86 Assert.assertFalse(action.isValid());
88 action = new PushVlan(EtherTypes.VLANTAGGED, 0x4, 0, 2000);
89 Assert.assertTrue(action.isValid());
91 action = new PushVlan(EtherTypes.QINQ.intValue(), 0x4, 0x1, 5000);
92 Assert.assertFalse(action.isValid());
94 action = new PushVlan(EtherTypes.LLDP, 0x4, 0x1, 2000);
95 Assert.assertFalse(action.isValid());
97 action = new PushVlan(EtherTypes.PVSTP, 0x4, 2, 2000);
98 Assert.assertFalse(action.isValid());
100 action = new PushVlan(EtherTypes.QINQ, 0x4, -1, 2000);
101 Assert.assertFalse(action.isValid());
105 public void testSetVlanPcpActionCreation() {
106 Action action = null;
108 action = new SetVlanPcp(0x4);
109 Assert.assertTrue(action.isValid());
111 action = new SetVlanPcp(0x8);
112 Assert.assertFalse(action.isValid());
114 action = new SetVlanPcp(-1);
115 Assert.assertFalse(action.isValid());
119 public void testSetVlanCfiActionCreation() {
120 Action action = null;
122 action = new SetVlanCfi(0x0);
123 Assert.assertTrue(action.isValid());
125 action = new SetVlanCfi(0x1);
126 Assert.assertTrue(action.isValid());
128 action = new SetVlanCfi(0x2);
129 Assert.assertFalse(action.isValid());
131 action = new SetVlanCfi(-1);
132 Assert.assertFalse(action.isValid());
136 public void testNetworkSetActionCreation() {
137 Action action = null;
139 InetAddress ip = null;
141 ip = InetAddress.getByName("171.71.9.52");
142 } catch (UnknownHostException e) {
146 action = new SetNwSrc(ip);
147 Assert.assertTrue(action.isValid());
149 action = new SetNwDst(ip);
150 Assert.assertTrue(action.isValid());
153 ip = InetAddress.getByName("2001:420:281:1003:f2de:f1ff:fe71:728d");
154 } catch (UnknownHostException e) {
157 action = new SetNwSrc(ip);
158 Assert.assertTrue(action.isValid());
160 action = new SetNwDst(ip);
161 Assert.assertTrue(action.isValid());
163 action = new SetNwTos(0xf);
164 Assert.assertTrue(action.isValid());
166 action = new SetNwTos(0xff);
167 Assert.assertTrue(action.isValid());
169 action = new SetNwTos(0xff1);
170 Assert.assertFalse(action.isValid());
172 action = new SetNwTos(-1);
173 Assert.assertFalse(action.isValid());
177 public void testTransportSetActionCreation() {
178 Action action = null;
180 action = new SetTpSrc(50000);
181 Assert.assertTrue(action.isValid());
183 action = new SetTpDst(65535);
184 Assert.assertTrue(action.isValid());
186 action = new SetTpDst(0);
187 Assert.assertFalse(action.isValid());
189 action = new SetTpSrc(-1);
190 Assert.assertFalse(action.isValid());
192 action = new SetTpDst(-1);
193 Assert.assertFalse(action.isValid());
195 action = new SetTpSrc(65536);
196 Assert.assertFalse(action.isValid());
198 action = new SetTpDst(65536);
199 Assert.assertFalse(action.isValid());
203 public void testActionList() {
204 List<Action> actions = new ArrayList<Action>();
205 short portId = (short) 9;
208 node = new Node(Node.NodeIDType.OPENFLOW, new Long(0x55667788L));
209 } catch (ConstructionException e) {
210 // If we reach this point the exception was raised
211 // which is not expected
212 Assert.assertTrue(false);
214 NodeConnector nc = NodeConnectorCreator.createNodeConnector(portId,
216 byte mac[] = { (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0x11,
217 (byte) 0x22, (byte) 0x33 };
218 InetAddress ip = null;
220 ip = InetAddress.getByName("1.1.1.1");
221 } catch (UnknownHostException e) {
225 actions.add(new SetDlSrc(mac));
226 actions.add(new SetNwSrc(ip));
227 actions.add(new Output(nc));
228 Assert.assertTrue(actions.size() == 3);
229 Assert.assertTrue(actions.get(0).isValid());
231 Action probe = new Output(nc);
232 Assert.assertTrue(actions.contains(probe));
233 Assert.assertFalse(actions.contains(new Output(NodeConnectorCreator
234 .createNodeConnector((short) 5, node))));
235 Assert.assertFalse(actions.contains(new Controller()));