Scenarios can be in XML file
[openflowjava.git] / simple-client / src / main / java / org / opendaylight / openflowjava / protocol / impl / clients / ScenarioFactory.java
index 4e28c4cd74f58ced75b1b9ceb01ef2426e26e0ae..3e01cfa543a758bb21b602ff3aa4d5cfbc1a5c96 100644 (file)
@@ -8,10 +8,15 @@
 
 package org.opendaylight.openflowjava.protocol.impl.clients;
 
+import java.io.IOException;
 import java.util.ArrayDeque;
 import java.util.Deque;
+import java.util.Map;
 
 import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.xml.sax.SAXException;
+
+import javax.xml.bind.JAXBException;
 
 /**
  * Class for providing prepared handshake scenario
@@ -29,8 +34,8 @@ public final class ScenarioFactory {
      * <ol>
      *   <li> hello sent - 00000001
      *   <li> hello waiting - 00000002
-     *   <li> featuresrequest waiting - 00000003
-     *   <li> featuresreply sent - 00000003
+     *   <li> features request waiting - 00000003
+     *   <li> features reply sent - 00000003
      * </ol>
      * @return stack filled with Handshake messages
      */
@@ -49,8 +54,8 @@ public final class ScenarioFactory {
      * <ol>
      *   <li> hello sent - 00000001
      *   <li> hello waiting - 00000021
-     *   <li> featuresrequest waiting - 00000002
-     *   <li> featuresreply sent - 00000002
+     *   <li> features request waiting - 00000002
+     *   <li> features reply sent - 00000002
      * </ol>
      * @return stack filled with Handshake messages
      */
@@ -66,13 +71,26 @@ public final class ScenarioFactory {
         return stack;
     }
 
+    /**
+     * Creates stack from XML file
+     * @return stack filled with Handshake messages
+     */
+    public static Deque<ClientEvent> getScenarioFromXml(String scenarioName, String scenarioFile) throws JAXBException, SAXException, IOException {
+        ScenarioService scenarioService = new ScenarioServiceImpl(scenarioFile);
+        Deque<ClientEvent> stack = new ArrayDeque<>();
+        for (Map.Entry<Integer, ClientEvent> clientEvent : scenarioService.getEventsFromScenario(scenarioService.unMarshallData(scenarioName)).entrySet()) {
+            stack.addFirst(clientEvent.getValue());
+        }
+        return stack;
+    }
+
     /**
      * Creates stack with handshake needed messages. XID of messages:
      * <ol>
      *   <li> hello sent - 00000001
      *   <li> hello waiting - 00000002
-     *   <li> featuresrequest waiting - 00000003
-     *   <li> featuresreply sent - 00000003
+     *   <li> features request waiting - 00000003
+     *   <li> features reply sent - 00000003
      * </ol>
      * @param auxiliaryId auxiliaryId wanted in featuresReply message
      * @return stack filled with Handshake messages (featuresReply with auxiliaryId set)