4e28c4cd74f58ced75b1b9ceb01ef2426e26e0ae
[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. XID of messages:
29      * <ol>
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. XID of messages:
49      * <ol>
50      *   <li> hello sent - 00000001
51      *   <li> hello waiting - 00000021
52      *   <li> featuresrequest waiting - 00000002
53      *   <li> featuresreply sent - 00000002
54      * </ol>
55      * @return stack filled with Handshake messages
56      */
57     public static Deque<ClientEvent> createHandshakeScenarioWithBarrier() {
58         Deque<ClientEvent> stack = new ArrayDeque<>();
59         stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
60         stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 10 00 00 00 15 00 01 00 08 00 00 00 12"))); //Hello message 21
61         stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 02")));
62         stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 02 "
63                 + "00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 00 01 02 03 00 01 02 03")));
64         stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 14 00 08 00 00 00 00"))); //Barrier request
65         stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 15 00 08 00 00 00 04"))); //Barrier reply
66         return stack;
67     }
68
69     /**
70      * Creates stack with handshake needed messages. XID of messages:
71      * <ol>
72      *   <li> hello sent - 00000001
73      *   <li> hello waiting - 00000002
74      *   <li> featuresrequest waiting - 00000003
75      *   <li> featuresreply sent - 00000003
76      * </ol>
77      * @param auxiliaryId auxiliaryId wanted in featuresReply message
78      * @return stack filled with Handshake messages (featuresReply with auxiliaryId set)
79      */
80     public static Deque<ClientEvent> createHandshakeScenarioWithAuxiliaryId(byte auxiliaryId) {
81         Deque<ClientEvent> queue = new ArrayDeque<>();
82         queue.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
83         queue.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
84         queue.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
85         queue.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
86                 + "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")));
87         return queue;
88     }
89
90 }