IT unstability fix - BUG 837
[openflowplugin.git] / openflowplugin-it / src / test / java / org / opendaylight / openflowplugin / openflow / md / it / ScenarioFactory.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.it;
9
10 import java.util.Stack;
11
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.protocol.impl.util.ByteBufUtils;
17
18 /**
19  * provisioning of most common scenarios used by testing of integration between OFLibrary, OFPlugin and MD-SAL 
20  */
21 public abstract class ScenarioFactory {
22     
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";
27
28     /**
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
35      * </ol>
36      * @param switchVersionBitmap
37      * @param auxId
38      * @param pluginVersionBitmap
39      * @return stack filled with Handshake messages
40      */
41     public static Stack<ClientEvent> createHandshakeScenarioVBM(
42             String switchVersionBitmap, short auxId, String pluginVersionBitmap) {
43         Stack<ClientEvent> stack = new Stack<>();
44         
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 "
53                 + "00 01 02 03 01 "
54                 + Integer.toHexString(auxId)
55                 + " 00 00 00 01 02 03 00 01 02 03")));
56         addSleep(stack);
57         return stack;
58     }
59
60     /**
61      * @param stack
62      */
63     private static void addSleep(Stack<ClientEvent> stack) {
64         stack.add(0, new SleepEvent(2000));
65     }
66
67     /**
68      * @param auxId
69      * @param pluginVersionBitmap 
70      * @return handshake scenario without switch version bitmap
71      */
72     public static Stack<ClientEvent> createHandshakeScenario(short auxId, String pluginVersionBitmap) {
73         Stack<ClientEvent> stack = new Stack<>();
74         
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 "
82                 + "00 01 02 03 01 "
83                 + Integer.toHexString(auxId)
84                 + " 00 00 00 01 02 03 00 01 02 03")));
85         addSleep(stack);
86         return stack;
87     }
88 }