Merge "Bug 4957 No empty transaction for every connection fix"
[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.ArrayDeque;
11 import java.util.Deque;
12
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;
18
19 /**
20  * provisioning of most common scenarios used by testing of integration between OFLibrary, OFPlugin and MD-SAL
21  */
22 public abstract class ScenarioFactory {
23
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";
30
31     /**
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
38      * </ol>
39      * @param switchVersionBitmap
40      * @param auxId
41      * @param pluginVersionBitmap
42      * @param addSleep if true - then add final sleep {@link #DEFAULT_SCENARIO_SLEEP}
43      * @return stack filled with Handshake messages
44      */
45     public static Deque<ClientEvent> createHandshakeScenarioVBM(
46             String switchVersionBitmap, short auxId, String pluginVersionBitmap, boolean addSleep) {
47         Deque<ClientEvent> stack = new ArrayDeque<>();
48
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")));
62
63         if (addSleep) {
64             addSleep(stack);
65         }
66
67         return stack;
68     }
69
70     /**
71      * @param stack
72      * @param addSleep if true - then add final sleep {@link #DEFAULT_SCENARIO_SLEEP}
73      * @return
74      */
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 00 00 00 00 00 00 00"  )));
82
83         if (addSleep) {
84             addSleep(stack);
85         }
86
87         return stack;
88     }
89
90     /**
91      * @param stack
92      */
93     private static void addSleep(Deque<ClientEvent> stack) {
94         stack.addFirst(new SleepEvent(DEFAULT_SCENARIO_SLEEP));
95     }
96
97     /**
98      * @param auxId
99      * @param pluginVersionBitmap
100      * @return handshake scenario without switch version bitmap
101      */
102     public static Deque<ClientEvent> createHandshakeScenario(short auxId,
103             String pluginVersionBitmap) {
104         Deque<ClientEvent> stack = new ArrayDeque<>();
105
106         stack.addFirst(new SendEvent(ByteBufUtils
107                 .hexStringToBytes("04 00 00 08 00 00 00 01")));
108         stack.addFirst(new WaitForMessageEvent(ByteBufUtils
109                 .hexStringToBytes("04 00 00 10 00 00 00 15 "
110                         + pluginVersionBitmap)));
111         stack.addFirst(new WaitForMessageEvent(ByteBufUtils
112                 .hexStringToBytes("04 05 00 08 00 00 00 02")));
113         stack.addFirst(new SendEvent(ByteBufUtils
114                 .hexStringToBytes("04 06 00 20 00 00 00 02 "
115                         + "00 01 02 03 04 05 06 07 " + "00 01 02 03 01 "
116                         + Integer.toHexString(auxId)
117                         + " 00 00 00 01 02 03 00 01 02 03")));
118         addSleep(stack);
119         return stack;
120     }
121
122     /**
123      * Attempt to simulate the MLX running 1.0 talking to ODL
124      *
125      * @param auxId
126      * @param pluginVersionBitmap
127      * @return handshake scenario without switch version bitmap
128      */
129     public static Deque<ClientEvent> createHandshakeScenarioNoVBM_OF10_TwoHello() {
130         Deque<ClientEvent> stack = new ArrayDeque<>();
131
132         stack.addFirst(new SendEvent(ByteBufUtils
133                 .hexStringToBytes("01 00 00 08 00 00 01 67")));
134         stack.addFirst(new WaitForMessageEvent(ByteBufUtils
135                         .hexStringToBytes("04 00 00 10 00 00 00 15 00 01 00 08 00 00 00 12")));
136         stack.addFirst(new SendEvent(ByteBufUtils
137                 .hexStringToBytes("01 01 00 0c 00 00 00 15 00 00 00 00")));
138         stack.addFirst(new WaitForMessageEvent(ByteBufUtils
139                 .hexStringToBytes("01 00 00 08 00 00 01 68")));
140         stack.addFirst(new SendEvent(ByteBufUtils
141                 .hexStringToBytes("01 00 00 08 00 00 01 68")));
142         stack.addFirst(new WaitForMessageEvent(ByteBufUtils
143                 .hexStringToBytes("01 05 00 08 00 00 01 69")));
144
145         stack.addFirst(new SendEvent(
146                 ByteBufUtils
147                         .hexStringToBytes("01 06 00 80 00 00 01 69 cc 4e 24 1c 4a 00 00 00"
148                                 + " 00 00 01 00 01 00 00 00 00 00 00 07 00 00 01 0f"
149                                 + " 00 61 cc 4e 24 1c 4a 60 65 74 68 33 2f 31 00 00"
150                                 + " 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 01"
151                                 + " 00 00 01 40 00 00 01 40 00 00 01 40 00 00 01 40"
152                                 + " 00 62 cc 4e 24 1c 4a 61 65 74 68 33 2f 32 00 00"
153                                 + " 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 01"
154                                 + " 00 00 01 40 00 00 01 40 00 00 01 40 00 00 01 40")));
155
156         stack.addFirst(new WaitForMessageEvent(ByteBufUtils
157                 .hexStringToBytes("01 10 00 0c 00 00 00 01 00 00 00 00")));
158
159         stack.addFirst(new SendEvent(
160                 ByteBufUtils
161                         .hexStringToBytes("01 11 04 2c 00 00 00 01 00 00 00 00 42 72 6f 63"
162                                 + " 61 64 65 20 43 6f 6d 6d 75 6e 69 63 61 74 69"
163                                 + " 6f 6e 73 2c 20 49 6e 63 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 00 00"
168                                 + " 00 00 00 00 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 4d 75 6c"
179                                 + " 74 69 2d 53 65 72 76 69 63 65 20 49 72 6f 6e"
180                                 + " 77 61 72 65 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 00"
185                                 + " 00 00 00 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 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 4e 49"
196                                 + " 20 35 2e 37 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 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 4e"
213                                 + " 6f 6e 65 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 4e 6f 6e 65 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 00"
219                                 + " 00 00 00 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 00 00 00 00 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")));
233
234         stack.addFirst(new SleepEvent(5000));
235
236         addSleep(stack);
237         return stack;
238     }
239
240     /**
241      * Attempt to simulate the MLX running 1.0 talking to ODL
242      *
243      * @param auxId
244      * @param pluginVersionBitmap
245      * @return handshake scenario without switch version bitmap
246      */
247     public static Deque<ClientEvent> createHandshakeScenarioNOVBM_OF10_OneHello() {
248         System.out.println("createHandshakeScenarioMininet");
249         Deque<ClientEvent> stack = new ArrayDeque<>();
250
251         stack.addFirst(new SendEvent(ByteBufUtils
252                 .hexStringToBytes("01 00 00 08 00 00 00 0d")));
253         stack.addFirst(new WaitForMessageEvent(ByteBufUtils
254                 .hexStringToBytes("04 00 00 10 00 00 00 15")));
255         stack.addFirst(new WaitForMessageEvent(ByteBufUtils
256                 .hexStringToBytes("01 00 00 08 00 00 00 0e")));
257         stack.addFirst(new WaitForMessageEvent(ByteBufUtils
258                 .hexStringToBytes("01 05 00 08 00 00 00 0f")));
259
260         stack.addFirst(new SendEvent(
261                 ByteBufUtils
262                         .hexStringToBytes("01 01 00 14 00 00 00 0e 00 01 00 01 01 00 00 08 00 00 00 0e")));
263
264         stack.addFirst(new SendEvent(
265                 ByteBufUtils
266                         .hexStringToBytes(" 01 06 00 b0 00 00 00 0f 00 00 00 00 00 00 00 01 00 00 01 00 fe 00"
267                                 + " 00 00 00 00 00 c7 00 00 0f ff 00 01 fa 01 ff 57 86 aa 73 31 2d"
268                                 + " 65 74 68 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01"
269                                 + " 00 00 00 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 02 c2 51 d8"
270                                 + " 24 38 97 73 31 2d 65 74 68 32 00 00 00 00 00 00 00 00 00 00 00"
271                                 + " 00 00 00 00 00 00 00 00 00 c0 00 00 00 00 00 00 00 00 00 00 00"
272                                 + " 00 ff fe ea bd f8 db 41 40 73 31 00 00 00 00 00 00 00 00 00 00"
273                                 + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
274                                 + " 00 00 00 00 00 00 00")));
275         addSleep(stack);
276         return stack;
277     }
278 }