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.io.IOException;
12 import java.util.ArrayDeque;
13 import java.util.Deque;
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
17 import org.xml.sax.SAXException;
19 import javax.xml.bind.JAXBException;
22 * Class for providing prepared handshake scenario
24 * @author michal.polkorab
26 public final class ScenarioFactory {
28 private ScenarioFactory() {
29 throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
33 * Creates stack with handshake needed messages. XID of messages:
35 * <li> hello sent - 00000001
36 * <li> hello waiting - 00000002
37 * <li> features request waiting - 00000003
38 * <li> features reply sent - 00000003
40 * @return stack filled with Handshake messages
42 public static Deque<ClientEvent> createHandshakeScenario() {
43 Deque<ClientEvent> stack = new ArrayDeque<>();
44 stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
45 stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
46 stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
47 stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
48 + "00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 00 01 02 03 00 01 02 03")));
53 * Creates stack with handshake needed messages. XID of messages:
55 * <li> hello sent - 00000001
56 * <li> hello waiting - 00000021
57 * <li> features request waiting - 00000002
58 * <li> features reply sent - 00000002
60 * @return stack filled with Handshake messages
62 public static Deque<ClientEvent> createHandshakeScenarioWithBarrier() {
63 Deque<ClientEvent> stack = new ArrayDeque<>();
64 stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
65 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
66 stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 02")));
67 stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 02 "
68 + "00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 00 01 02 03 00 01 02 03")));
69 stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 14 00 08 00 00 00 00"))); //Barrier request
70 stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 15 00 08 00 00 00 04"))); //Barrier reply
75 * Creates stack from XML file
76 * @return stack filled with Handshake messages
78 public static Deque<ClientEvent> getScenarioFromXml(String scenarioName, String scenarioFile) throws JAXBException, SAXException, IOException {
79 ScenarioService scenarioService = new ScenarioServiceImpl(scenarioFile);
80 Deque<ClientEvent> stack = new ArrayDeque<>();
81 for (Map.Entry<Integer, ClientEvent> clientEvent : scenarioService.getEventsFromScenario(scenarioService.unMarshallData(scenarioName)).entrySet()) {
82 stack.addFirst(clientEvent.getValue());
88 * Creates stack with handshake needed messages. XID of messages:
90 * <li> hello sent - 00000001
91 * <li> hello waiting - 00000002
92 * <li> features request waiting - 00000003
93 * <li> features reply sent - 00000003
95 * @param auxiliaryId auxiliaryId wanted in featuresReply message
96 * @return stack filled with Handshake messages (featuresReply with auxiliaryId set)
98 public static Deque<ClientEvent> createHandshakeScenarioWithAuxiliaryId(byte auxiliaryId) {
99 Deque<ClientEvent> queue = new ArrayDeque<>();
100 queue.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
101 queue.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
102 queue.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
103 queue.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
104 + "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")));