f0e5b9cffbf958f7de182bcaf137beee038bbc39
[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.ArrayDeque;
12 import java.util.Deque;
13
14 import org.opendaylight.openflowjava.util.ByteBufUtils;
15
16 /**
17  * Class for providing prepared handshake scenario
18  *
19  * @author michal.polkorab
20  */
21 public final class ScenarioFactory {
22
23     private ScenarioFactory() {
24         throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
25     }
26
27     /**
28      * Creates stack with handshake needed messages.
29      * <ol> XID of messages:
30      *   <li> hello sent - 00000001
31      *   <li> hello waiting - 00000002
32      *   <li> featuresrequest waiting - 00000003
33      *   <li> featuresreply sent - 00000003
34      * </ol>
35      * @return stack filled with Handshake messages
36      */
37     public static Deque<ClientEvent> createHandshakeScenario() {
38         Deque<ClientEvent> stack = new ArrayDeque<>();
39         stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
40         stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
41         stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
42         stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
43                 + "00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 00 01 02 03 00 01 02 03")));
44         return stack;
45     }
46
47     /**
48      * Creates stack with handshake needed messages.
49      * <ol> XID of messages:
50      *   <li> hello sent - 00000001
51      *   <li> hello waiting - 00000002
52      *   <li> featuresrequest waiting - 00000003
53      *   <li> featuresreply sent - 00000003
54      * </ol>
55      * @param auxiliaryId auxiliaryId wanted in featuresReply message
56      * @return stack filled with Handshake messages (featuresReply with auxiliaryId set)
57      */
58     public static Deque<ClientEvent> createHandshakeScenarioWithAuxiliaryId(byte auxiliaryId) {
59         Deque<ClientEvent> queue = new ArrayDeque<>();
60         queue.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
61         queue.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
62         queue.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
63         queue.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
64                 + "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")));
65         return queue;
66     }
67
68 }