6d0828cf0cdcd4476685e11b2b3158013d00653f
[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.WaitForMessageEvent;
15 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
16
17 /**
18  * provisioning of most common scenarios used by testing of integration between OFLibrary, OFPlugin and MD-SAL 
19  */
20 public abstract class ScenarioFactory {
21     
22     /** version bitmap hex-string containing version 1.3 */
23     public static final String VERSION_BITMAP_13 = "00 01 00 08 00 00 00 10";
24     /** version bitmap hex-string containing versions: 1.0 + 1.3 */
25     public static final String VERSION_BITMAP_10_13 = "00 01 00 08 00 00 00 12";
26
27     /**
28      * Creates stack with handshake needed messages.
29      * <ol> XID of messages:
30      *   <li> hello sent - 00000001
31      *   <li> hello waiting - 00000015
32      *   <li> featuresrequest waiting - 00000002
33      *   <li> featuresreply sent - 00000002
34      * </ol>
35      * @param switchVersionBitmap
36      * @param auxId
37      * @param pluginVersionBitmap
38      * @return stack filled with Handshake messages
39      */
40     public static Stack<ClientEvent> createHandshakeScenarioVBM(
41             String switchVersionBitmap, short auxId, String pluginVersionBitmap) {
42         Stack<ClientEvent> stack = new Stack<>();
43         
44         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 10 00 00 00 01 " 
45                 + switchVersionBitmap)));
46         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 10 00 00 00 15 "
47                 + pluginVersionBitmap)));
48         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 02")));
49         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes(
50                 "04 06 00 20 00 00 00 02 "
51                 + "00 01 02 03 04 05 06 07 "
52                 + "00 01 02 03 01 "
53                 + Integer.toHexString(auxId)
54                 + " 00 00 00 01 02 03 00 01 02 03")));
55         return stack;
56     }
57
58     /**
59      * @param auxId
60      * @param pluginVersionBitmap 
61      * @return handshake scenario without switch version bitmap
62      */
63     public static Stack<ClientEvent> createHandshakeScenario(short auxId, String pluginVersionBitmap) {
64         Stack<ClientEvent> stack = new Stack<>();
65         
66         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
67         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 10 00 00 00 15 "
68                 + pluginVersionBitmap)));
69         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 02")));
70         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes(
71                 "04 06 00 20 00 00 00 02 "
72                 + "00 01 02 03 04 05 06 07 "
73                 + "00 01 02 03 01 "
74                 + Integer.toHexString(auxId)
75                 + " 00 00 00 01 02 03 00 01 02 03")));
76         return stack;
77     }
78 }