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