Merge "Bug 1277 - Move ByteBuffUtils to separate bundle"
[openflowjava.git] / simple-client / src / main / java / org / opendaylight / openflowjava / protocol / impl / clients / ScenarioFactory.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowjava.protocol.impl.clients;
10
11 import java.util.Stack;
12
13 import org.opendaylight.openflowjava.util.ByteBufUtils;
14
15 /**
16  * Class for providing prepared handshake scenario
17  * 
18  * @author michal.polkorab
19  */
20 public class ScenarioFactory {
21
22     /**
23      * Creates stack with handshake needed messages.
24      * <ol> XID of messages:
25      *   <li> hello sent - 00000001
26      *   <li> hello waiting - 00000002
27      *   <li> featuresrequest waiting - 00000003
28      *   <li> featuresreply sent - 00000003
29      * </ol>
30      * @return stack filled with Handshake messages
31      */
32     public static Stack<ClientEvent> createHandshakeScenario() {
33         Stack<ClientEvent> stack = new Stack<>();
34         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
35         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
36         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
37         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
38                 + "00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 00 01 02 03 00 01 02 03")));
39         return stack;
40     }
41
42     /**
43      * Creates stack with handshake needed messages.
44      * <ol> XID of messages:
45      *   <li> hello sent - 00000001
46      *   <li> hello waiting - 00000002
47      *   <li> featuresrequest waiting - 00000003
48      *   <li> featuresreply sent - 00000003
49      * </ol>
50      * @param auxiliaryId auxiliaryId wanted in featuresReply message
51      * @return stack filled with Handshake messages (featuresReply with auxiliaryId set)
52      */
53     public static Stack<ClientEvent> createHandshakeScenarioWithAuxiliaryId(byte auxiliaryId) {
54         Stack<ClientEvent> stack = new Stack<>();
55         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
56         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
57         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
58         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
59                 + "00 01 02 03 04 05 06 07 00 01 02 03 01 " + String.format("%02x ", auxiliaryId) + " 00 00 00 01 02 03 00 01 02 03")));
60         return stack;
61     }
62
63 }