Remove trailing whitespace
[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 final class ScenarioFactory {
21
22     private ScenarioFactory() {
23         throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
24     }
25
26     /**
27      * Creates stack with handshake needed messages.
28      * <ol> XID of messages:
29      *   <li> hello sent - 00000001
30      *   <li> hello waiting - 00000002
31      *   <li> featuresrequest waiting - 00000003
32      *   <li> featuresreply sent - 00000003
33      * </ol>
34      * @return stack filled with Handshake messages
35      */
36     public static Stack<ClientEvent> createHandshakeScenario() {
37         Stack<ClientEvent> stack = new Stack<>();
38         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
39         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
40         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
41         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
42                 + "00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 00 01 02 03 00 01 02 03")));
43         return stack;
44     }
45
46     /**
47      * Creates stack with handshake needed messages.
48      * <ol> XID of messages:
49      *   <li> hello sent - 00000001
50      *   <li> hello waiting - 00000002
51      *   <li> featuresrequest waiting - 00000003
52      *   <li> featuresreply sent - 00000003
53      * </ol>
54      * @param auxiliaryId auxiliaryId wanted in featuresReply message
55      * @return stack filled with Handshake messages (featuresReply with auxiliaryId set)
56      */
57     public static Stack<ClientEvent> createHandshakeScenarioWithAuxiliaryId(byte auxiliaryId) {
58         Stack<ClientEvent> stack = new Stack<>();
59         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
60         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
61         stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
62         stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
63                 + "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")));
64         return stack;
65     }
66
67 }