2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.clients;
11 import java.util.ArrayDeque;
12 import java.util.Deque;
14 import org.opendaylight.openflowjava.util.ByteBufUtils;
17 * Class for providing prepared handshake scenario
19 * @author michal.polkorab
21 public final class ScenarioFactory {
23 private ScenarioFactory() {
24 throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
28 * Creates stack with handshake needed messages. XID of messages:
30 * <li> hello sent - 00000001
31 * <li> hello waiting - 00000002
32 * <li> featuresrequest waiting - 00000003
33 * <li> featuresreply sent - 00000003
35 * @return stack filled with Handshake messages
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")));
48 * Creates stack with handshake needed messages. XID of messages:
50 * <li> hello sent - 00000001
51 * <li> hello waiting - 00000021
52 * <li> featuresrequest waiting - 00000002
53 * <li> featuresreply sent - 00000002
55 * @return stack filled with Handshake messages
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
70 * Creates stack with handshake needed messages. XID of messages:
72 * <li> hello sent - 00000001
73 * <li> hello waiting - 00000002
74 * <li> featuresrequest waiting - 00000003
75 * <li> featuresreply sent - 00000003
77 * @param auxiliaryId auxiliaryId wanted in featuresReply message
78 * @return stack filled with Handshake messages (featuresReply with auxiliaryId set)
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")));