BUG-837: IT unstable
[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.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
46                 .hexStringToBytes("04 00 00 10 00 00 00 01 "
47                         + switchVersionBitmap)));
48         stack.add(0, new WaitForMessageEvent(ByteBufUtils
49                 .hexStringToBytes("04 00 00 10 00 00 00 15 "
50                         + pluginVersionBitmap)));
51         stack.add(0, new WaitForMessageEvent(ByteBufUtils
52                 .hexStringToBytes("04 05 00 08 00 00 00 02")));
53         stack.add(0, new SendEvent(ByteBufUtils
54                 .hexStringToBytes("04 06 00 20 00 00 00 02 "
55                         + "00 01 02 03 04 05 06 07 " + "00 01 02 03 01 "
56                         + Integer.toHexString(auxId)
57                         + " 00 00 00 01 02 03 00 01 02 03")));
58         addSleep(stack);
59         return stack;
60     }
61
62     /**
63      * @param stack
64      */
65     private static void addSleep(Stack<ClientEvent> stack) {
66         stack.add(0, new SleepEvent(2000));
67     }
68
69     /**
70      * @param auxId
71      * @param pluginVersionBitmap
72      * @return handshake scenario without switch version bitmap
73      */
74     public static Stack<ClientEvent> createHandshakeScenario(short auxId,
75             String pluginVersionBitmap) {
76         Stack<ClientEvent> stack = new Stack<>();
77
78         stack.add(0, new SendEvent(ByteBufUtils
79                 .hexStringToBytes("04 00 00 08 00 00 00 01")));
80         stack.add(0, new WaitForMessageEvent(ByteBufUtils
81                 .hexStringToBytes("04 00 00 10 00 00 00 15 "
82                         + pluginVersionBitmap)));
83         stack.add(0, new WaitForMessageEvent(ByteBufUtils
84                 .hexStringToBytes("04 05 00 08 00 00 00 02")));
85         stack.add(0, new SendEvent(ByteBufUtils
86                 .hexStringToBytes("04 06 00 20 00 00 00 02 "
87                         + "00 01 02 03 04 05 06 07 " + "00 01 02 03 01 "
88                         + Integer.toHexString(auxId)
89                         + " 00 00 00 01 02 03 00 01 02 03")));
90         addSleep(stack);
91         return stack;
92     }
93
94     /**
95      * Attempt to simulate the MLX running 1.0 talking to ODL
96      *
97      * @param auxId
98      * @param pluginVersionBitmap
99      * @return handshake scenario without switch version bitmap
100      */
101     public static Stack<ClientEvent> createHandshakeScenarioNoVBM_OF10_TwoHello() {
102         Stack<ClientEvent> stack = new Stack<>();
103
104         stack.add(0, new SendEvent(ByteBufUtils
105                 .hexStringToBytes("01 00 00 08 00 00 01 67")));
106         stack.add(0, new WaitForMessageEvent(ByteBufUtils
107                         .hexStringToBytes("04 00 00 10 00 00 00 15 00 01 00 08 00 00 00 12")));
108         stack.add(0, new SendEvent(ByteBufUtils
109                 .hexStringToBytes("01 01 00 0c 00 00 00 15 00 00 00 00")));
110         stack.add(0, new WaitForMessageEvent(ByteBufUtils
111                 .hexStringToBytes("01 00 00 08 00 00 01 68")));
112         stack.add(0, new SendEvent(ByteBufUtils
113                 .hexStringToBytes("01 00 00 08 00 00 01 68")));
114         stack.add(0, new WaitForMessageEvent(ByteBufUtils
115                 .hexStringToBytes("01 05 00 08 00 00 01 69")));
116
117         stack.add(0, new SendEvent(
118                 ByteBufUtils
119                         .hexStringToBytes("01 06 00 80 00 00 01 69 cc 4e 24 1c 4a 00 00 00"
120                                 + " 00 00 01 00 01 00 00 00 00 00 00 07 00 00 01 0f"
121                                 + " 00 61 cc 4e 24 1c 4a 60 65 74 68 33 2f 31 00 00"
122                                 + " 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 01"
123                                 + " 00 00 01 40 00 00 01 40 00 00 01 40 00 00 01 40"
124                                 + " 00 62 cc 4e 24 1c 4a 61 65 74 68 33 2f 32 00 00"
125                                 + " 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 01"
126                                 + " 00 00 01 40 00 00 01 40 00 00 01 40 00 00 01 40")));
127
128         stack.add(0, new WaitForMessageEvent(ByteBufUtils
129                 .hexStringToBytes("01 10 00 0c 00 00 00 01 00 00 00 00")));
130
131         stack.add(0, new SendEvent(
132                 ByteBufUtils
133                         .hexStringToBytes("01 11 04 2c 00 00 00 01 00 00 00 00 42 72 6f 63"
134                                 + " 61 64 65 20 43 6f 6d 6d 75 6e 69 63 61 74 69"
135                                 + " 6f 6e 73 2c 20 49 6e 63 00 00 00 00 00 00 00"
136                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
137                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
138                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
139                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
140                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
141                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
142                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
143                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
144                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
145                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
146                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
147                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
148                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
149                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
150                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 4d 75 6c"
151                                 + " 74 69 2d 53 65 72 76 69 63 65 20 49 72 6f 6e"
152                                 + " 77 61 72 65 00 00 00 00 00 00 00 00 00 00 00"
153                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
154                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
155                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
156                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
157                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
158                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
159                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
160                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
161                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
162                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
163                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
164                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
165                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
166                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
167                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 4e 49"
168                                 + " 20 35 2e 37 00 00 00 00 00 00 00 00 00 00 00"
169                                 + " 00 00 00 00 00 00 00 00 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 00 00 4e"
185                                 + " 6f 6e 65 00 00 00 00 00 00 00 00 00 00 00 00"
186                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
187                                 + " 00 4e 6f 6e 65 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 00 00"
202                                 + " 00 00 00 00 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")));
205
206         stack.add(0, new SleepEvent(5000));
207
208         addSleep(stack);
209         return stack;
210     }
211
212     /**
213      * Attempt to simulate the MLX running 1.0 talking to ODL
214      *
215      * @param auxId
216      * @param pluginVersionBitmap
217      * @return handshake scenario without switch version bitmap
218      */
219     public static Stack<ClientEvent> createHandshakeScenarioNOVBM_OF10_OneHello() {
220         System.out.println("createHandshakeScenarioMininet");
221         Stack<ClientEvent> stack = new Stack<>();
222
223         stack.add(0, new SendEvent(ByteBufUtils
224                 .hexStringToBytes("01 00 00 08 00 00 00 0d")));
225         stack.add(0, new WaitForMessageEvent(ByteBufUtils
226                 .hexStringToBytes("04 00 00 10 00 00 00 15")));
227         stack.add(0, new WaitForMessageEvent(ByteBufUtils
228                 .hexStringToBytes("01 00 00 08 00 00 00 0e")));
229         stack.add(0, new WaitForMessageEvent(ByteBufUtils
230                 .hexStringToBytes("01 05 00 08 00 00 00 0f")));
231
232         stack.add(0, new SendEvent(
233                 ByteBufUtils
234                         .hexStringToBytes("01 01 00 14 00 00 00 0e 00 01 00 01 01 00 00 08 00 00 00 0e")));
235
236         stack.add(0, new SendEvent(
237                 ByteBufUtils
238                         .hexStringToBytes(" 01 06 00 b0 00 00 00 0f 00 00 00 00 00 00 00 01 00 00 01 00 fe 00"
239                                 + " 00 00 00 00 00 c7 00 00 0f ff 00 01 fa 01 ff 57 86 aa 73 31 2d"
240                                 + " 65 74 68 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01"
241                                 + " 00 00 00 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 02 c2 51 d8"
242                                 + " 24 38 97 73 31 2d 65 74 68 32 00 00 00 00 00 00 00 00 00 00 00"
243                                 + " 00 00 00 00 00 00 00 00 00 c0 00 00 00 00 00 00 00 00 00 00 00"
244                                 + " 00 ff fe ea bd f8 db 41 40 73 31 00 00 00 00 00 00 00 00 00 00"
245                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
246                                 + " 00 00 00 00 00 00 00")));
247         addSleep(stack);
248         return stack;
249     }
250 }