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.it;
10 import java.util.ArrayDeque;
11 import java.util.Deque;
13 import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
14 import org.opendaylight.openflowjava.protocol.impl.clients.SendEvent;
15 import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
16 import org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent;
17 import org.opendaylight.openflowjava.util.ByteBufUtils;
20 * provisioning of most common scenarios used by testing of integration between OFLibrary, OFPlugin and MD-SAL
22 public abstract class ScenarioFactory {
24 /** default sleep time [ms] - at scenario end */
25 public static final int DEFAULT_SCENARIO_SLEEP = 2000;
26 /** version bitmap hex-string containing version 1.3 */
27 public static final String VERSION_BITMAP_13 = "00 01 00 08 00 00 00 10";
28 /** version bitmap hex-string containing versions: 1.0 + 1.3 */
29 public static final String VERSION_BITMAP_10_13 = "00 01 00 08 00 00 00 12";
32 * Creates stack with handshake needed messages.
33 * <ol> XID of messages:
34 * <li> hello sent - 00000001
35 * <li> hello waiting - 00000015
36 * <li> featuresrequest waiting - 00000002
37 * <li> featuresreply sent - 00000002
39 * @param switchVersionBitmap
41 * @param pluginVersionBitmap
42 * @param addSleep if true - then add final sleep {@link #DEFAULT_SCENARIO_SLEEP}
43 * @return stack filled with Handshake messages
45 public static Deque<ClientEvent> createHandshakeScenarioVBM(
46 String switchVersionBitmap, short auxId, String pluginVersionBitmap, boolean addSleep) {
47 Deque<ClientEvent> stack = new ArrayDeque<>();
49 stack.addFirst(new SendEvent(ByteBufUtils
50 .hexStringToBytes("04 00 00 10 00 00 00 01 "
51 + switchVersionBitmap)));
52 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
53 .hexStringToBytes("04 00 00 10 00 00 00 15 "
54 + pluginVersionBitmap)));
55 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
56 .hexStringToBytes("04 05 00 08 00 00 00 02")));
57 stack.addFirst(new SendEvent(ByteBufUtils
58 .hexStringToBytes("04 06 00 20 00 00 00 02 "
59 + "00 01 02 03 04 05 06 07 " + "00 01 02 03 01 "
60 + Integer.toHexString(auxId)
61 + " 00 00 00 01 02 03 00 01 02 03")));
72 * @param addSleep if true - then add final sleep {@link #DEFAULT_SCENARIO_SLEEP}
75 public static Deque<ClientEvent> appendPostHandshakeScenario(Deque<ClientEvent> stack, boolean addSleep) {
76 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
77 .hexStringToBytes("04 12 00 10 00 00 00 01 "+
78 "00 0d 00 00 00 00 00 00" )));
79 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
80 .hexStringToBytes("04 12 00 10 00 00 00 02 "+
81 "00 08 00 00 00 00 00 00" )));
82 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
83 .hexStringToBytes("04 12 00 10 00 00 00 03 "+
84 "00 0b 00 00 00 00 00 00" )));
85 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
86 .hexStringToBytes("04 12 00 10 00 00 00 04 "+
87 "00 00 00 00 00 00 00 00" )));
99 private static void addSleep(Deque<ClientEvent> stack) {
100 stack.addFirst(new SleepEvent(DEFAULT_SCENARIO_SLEEP));
105 * @param pluginVersionBitmap
106 * @return handshake scenario without switch version bitmap
108 public static Deque<ClientEvent> createHandshakeScenario(short auxId,
109 String pluginVersionBitmap) {
110 Deque<ClientEvent> stack = new ArrayDeque<>();
112 stack.addFirst(new SendEvent(ByteBufUtils
113 .hexStringToBytes("04 00 00 08 00 00 00 01")));
114 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
115 .hexStringToBytes("04 00 00 10 00 00 00 15 "
116 + pluginVersionBitmap)));
117 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
118 .hexStringToBytes("04 05 00 08 00 00 00 02")));
119 stack.addFirst(new SendEvent(ByteBufUtils
120 .hexStringToBytes("04 06 00 20 00 00 00 02 "
121 + "00 01 02 03 04 05 06 07 " + "00 01 02 03 01 "
122 + Integer.toHexString(auxId)
123 + " 00 00 00 01 02 03 00 01 02 03")));
129 * Attempt to simulate the MLX running 1.0 talking to ODL
132 * @param pluginVersionBitmap
133 * @return handshake scenario without switch version bitmap
135 public static Deque<ClientEvent> createHandshakeScenarioNoVBM_OF10_TwoHello() {
136 Deque<ClientEvent> stack = new ArrayDeque<>();
138 stack.addFirst(new SendEvent(ByteBufUtils
139 .hexStringToBytes("01 00 00 08 00 00 01 67")));
140 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
141 .hexStringToBytes("04 00 00 10 00 00 00 15 00 01 00 08 00 00 00 12")));
142 stack.addFirst(new SendEvent(ByteBufUtils
143 .hexStringToBytes("01 01 00 0c 00 00 00 15 00 00 00 00")));
144 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
145 .hexStringToBytes("01 00 00 08 00 00 01 68")));
146 stack.addFirst(new SendEvent(ByteBufUtils
147 .hexStringToBytes("01 00 00 08 00 00 01 68")));
148 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
149 .hexStringToBytes("01 05 00 08 00 00 01 69")));
151 stack.addFirst(new SendEvent(
153 .hexStringToBytes("01 06 00 80 00 00 01 69 cc 4e 24 1c 4a 00 00 00"
154 + " 00 00 01 00 01 00 00 00 00 00 00 07 00 00 01 0f"
155 + " 00 61 cc 4e 24 1c 4a 60 65 74 68 33 2f 31 00 00"
156 + " 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 01"
157 + " 00 00 01 40 00 00 01 40 00 00 01 40 00 00 01 40"
158 + " 00 62 cc 4e 24 1c 4a 61 65 74 68 33 2f 32 00 00"
159 + " 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 01"
160 + " 00 00 01 40 00 00 01 40 00 00 01 40 00 00 01 40")));
162 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
163 .hexStringToBytes("01 10 00 0c 00 00 00 01 00 00 00 00")));
165 stack.addFirst(new SendEvent(
167 .hexStringToBytes("01 11 04 2c 00 00 00 01 00 00 00 00 42 72 6f 63"
168 + " 61 64 65 20 43 6f 6d 6d 75 6e 69 63 61 74 69"
169 + " 6f 6e 73 2c 20 49 6e 63 00 00 00 00 00 00 00"
170 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
171 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
172 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
173 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
174 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
175 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
176 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
177 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
178 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
179 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
180 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
181 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
182 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
183 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
184 + " 00 00 00 00 00 00 00 00 00 00 00 00 4d 75 6c"
185 + " 74 69 2d 53 65 72 76 69 63 65 20 49 72 6f 6e"
186 + " 77 61 72 65 00 00 00 00 00 00 00 00 00 00 00"
187 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
188 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
189 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
190 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
191 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
192 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
193 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
194 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
195 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
196 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
197 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
198 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
199 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
200 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
201 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 4e 49"
202 + " 20 35 2e 37 00 00 00 00 00 00 00 00 00 00 00"
203 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
204 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
205 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
206 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
207 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
208 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
209 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
210 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
211 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
212 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
213 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
214 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
215 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
216 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
217 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
218 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4e"
219 + " 6f 6e 65 00 00 00 00 00 00 00 00 00 00 00 00"
220 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
221 + " 00 4e 6f 6e 65 00 00 00 00 00 00 00 00 00 00"
222 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
223 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
224 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
225 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
226 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
227 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
228 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
229 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
230 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
231 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
232 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
233 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
234 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
235 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
236 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
237 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
240 stack.addFirst(new SleepEvent(5000));
247 * Attempt to simulate the MLX running 1.0 talking to ODL
250 * @param pluginVersionBitmap
251 * @return handshake scenario without switch version bitmap
253 public static Deque<ClientEvent> createHandshakeScenarioNOVBM_OF10_OneHello() {
254 System.out.println("createHandshakeScenarioMininet");
255 Deque<ClientEvent> stack = new ArrayDeque<>();
257 stack.addFirst(new SendEvent(ByteBufUtils
258 .hexStringToBytes("01 00 00 08 00 00 00 0d")));
259 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
260 .hexStringToBytes("04 00 00 10 00 00 00 15")));
261 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
262 .hexStringToBytes("01 00 00 08 00 00 00 0e")));
263 stack.addFirst(new WaitForMessageEvent(ByteBufUtils
264 .hexStringToBytes("01 05 00 08 00 00 00 0f")));
266 stack.addFirst(new SendEvent(
268 .hexStringToBytes("01 01 00 14 00 00 00 0e 00 01 00 01 01 00 00 08 00 00 00 0e")));
270 stack.addFirst(new SendEvent(
272 .hexStringToBytes(" 01 06 00 b0 00 00 00 0f 00 00 00 00 00 00 00 01 00 00 01 00 fe 00"
273 + " 00 00 00 00 00 c7 00 00 0f ff 00 01 fa 01 ff 57 86 aa 73 31 2d"
274 + " 65 74 68 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01"
275 + " 00 00 00 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 02 c2 51 d8"
276 + " 24 38 97 73 31 2d 65 74 68 32 00 00 00 00 00 00 00 00 00 00 00"
277 + " 00 00 00 00 00 00 00 00 00 c0 00 00 00 00 00 00 00 00 00 00 00"
278 + " 00 ff fe ea bd f8 db 41 40 73 31 00 00 00 00 00 00 00 00 00 00"
279 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
280 + " 00 00 00 00 00 00 00")));