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.Stack;
12 import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
13 import org.opendaylight.openflowjava.protocol.impl.clients.SendEvent;
14 import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
15 import org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent;
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
19 * provisioning of most common scenarios used by testing of integration between OFLibrary, OFPlugin and MD-SAL
21 public abstract class ScenarioFactory {
23 /** version bitmap hex-string containing version 1.3 */
24 public static final String VERSION_BITMAP_13 = "00 01 00 08 00 00 00 10";
25 /** version bitmap hex-string containing versions: 1.0 + 1.3 */
26 public static final String VERSION_BITMAP_10_13 = "00 01 00 08 00 00 00 12";
29 * Creates stack with handshake needed messages.
30 * <ol> XID of messages:
31 * <li> hello sent - 00000001
32 * <li> hello waiting - 00000015
33 * <li> featuresrequest waiting - 00000002
34 * <li> featuresreply sent - 00000002
36 * @param switchVersionBitmap
38 * @param pluginVersionBitmap
39 * @return stack filled with Handshake messages
41 public static Stack<ClientEvent> createHandshakeScenarioVBM(
42 String switchVersionBitmap, short auxId, String pluginVersionBitmap) {
43 Stack<ClientEvent> stack = new Stack<>();
45 stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 10 00 00 00 01 "
46 + switchVersionBitmap)));
47 stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 10 00 00 00 15 "
48 + pluginVersionBitmap)));
49 stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 02")));
50 stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes(
51 "04 06 00 20 00 00 00 02 "
52 + "00 01 02 03 04 05 06 07 "
54 + Integer.toHexString(auxId)
55 + " 00 00 00 01 02 03 00 01 02 03")));
63 private static void addSleep(Stack<ClientEvent> stack) {
64 stack.add(0, new SleepEvent(2000));
69 * @param pluginVersionBitmap
70 * @return handshake scenario without switch version bitmap
72 public static Stack<ClientEvent> createHandshakeScenario(short auxId, String pluginVersionBitmap) {
73 Stack<ClientEvent> stack = new Stack<>();
75 stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
76 stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 10 00 00 00 15 "
77 + pluginVersionBitmap)));
78 stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 02")));
79 stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes(
80 "04 06 00 20 00 00 00 02 "
81 + "00 01 02 03 04 05 06 07 "
83 + Integer.toHexString(auxId)
84 + " 00 00 00 01 02 03 00 01 02 03")));