package org.opendaylight.openflowjava.protocol.impl.clients;
-import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
-import javax.xml.bind.JAXBException;
import org.opendaylight.openflowjava.util.ByteBufUtils;
-import org.xml.sax.SAXException;
/**
* Class for providing prepared handshake scenario.
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 (ClientEvent clientEvent : scenarioService.getEventsFromScenario(
- scenarioService.unMarshallData(scenarioName))) {
- stack.addFirst(clientEvent);
- }
- return stack;
- }
-
/**
* Creates stack with handshake needed messages. XID of messages:
* <ol>
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowjava.protocol.impl.clients;
-
-import java.io.IOException;
-import java.util.List;
-import javax.xml.bind.JAXBException;
-import org.xml.sax.SAXException;
-
-/**
- * Interface for a scenario service.
- *
- * @author Jozef Bacigal
- */
-interface ScenarioService {
-
- String SIMPLE_CLIENT_SRC_MAIN_RESOURCES = "simple-client/src/main/resources/";
- String SIMPLE_CLIENT_SRC_MAIN_RESOURCES1 = "simple-client/src/main/resources/";
- String SCENARIO_XSD = "scenario.xsd";
- String SCENARIO_XML = "scenario.xml";
- String XSD_SCHEMA_PATH_WITH_FILE_NAME = SIMPLE_CLIENT_SRC_MAIN_RESOURCES1 + SCENARIO_XSD;
-
- /**
- * Method to load data from XML configuration file. Each configuration has a name.
- * @param scenarioName {@link String}
- * @return scenarios
- */
- Scenario unMarshallData(String scenarioName) throws SAXException, JAXBException;
-
- List<ClientEvent> getEventsFromScenario(Scenario scenario) throws IOException;
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowjava.protocol.impl.clients;
-
-import com.google.common.base.Preconditions;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import javax.xml.XMLConstants;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import org.opendaylight.openflowjava.util.ByteBufUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.SAXException;
-
-/**
- * Implementation of ScenarioService.
- *
- * @author Jozef Bacigal
- */
-public class ScenarioServiceImpl implements ScenarioService {
-
- private static final Logger LOG = LoggerFactory.getLogger(ScenarioServiceImpl.class);
-
- private String xmlFilePathWithFileName = SIMPLE_CLIENT_SRC_MAIN_RESOURCES + SCENARIO_XML;
-
- public ScenarioServiceImpl(String scenarioFile) {
- if (null != scenarioFile && !scenarioFile.isEmpty()) {
- this.xmlFilePathWithFileName = scenarioFile;
- }
- }
-
- @Override
- public Scenario unMarshallData(String scenarioName) throws SAXException, JAXBException {
- SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema schema = sf.newSchema(new File(XSD_SCHEMA_PATH_WITH_FILE_NAME));
- LOG.debug("Loading schema from: {}", XSD_SCHEMA_PATH_WITH_FILE_NAME);
-
- JAXBContext jc = JAXBContext.newInstance(Scenarios.class);
-
- Unmarshaller unmarshaller = jc.createUnmarshaller();
- unmarshaller.setSchema(schema);
-
- Scenarios scenarios = (Scenarios) unmarshaller.unmarshal(new File(xmlFilePathWithFileName));
- LOG.debug("Scenarios ({}) are un-marshaled from {}", scenarios.getScenario().size(),
- xmlFilePathWithFileName);
-
- boolean foundConfiguration = false;
- Scenario scenarioType = null;
- for (Scenario scenario : scenarios.getScenario()) {
- if (scenario.getName().equals(scenarioName)) {
- scenarioType = scenario;
- foundConfiguration = true;
- }
- }
- if (!foundConfiguration) {
- LOG.warn("Scenario {} not found.", scenarioName);
- } else {
- LOG.info("Scenario {} found with {} steps.", scenarioName, scenarioType.getStep().size());
- }
- return scenarioType;
- }
-
- @Override
- public List<ClientEvent> getEventsFromScenario(Scenario scenario) throws IOException {
- Preconditions.checkNotNull(scenario, "Scenario name not found. Check XML file, scenario name or directories.");
- List<Step> steps = scenario.getStep();
- List<ClientEvent> events = new ArrayList<>(steps.size());
- for (Step step : steps) {
- LOG.debug("Step {}: {}, type {}, bytes {}", step.getOrder(), step.getName(), step.getEvent().value(),
- step.getBytes().toArray());
- switch (step.getEvent()) {
- case SLEEP_EVENT:
- events.add(new SleepEvent(1000));
- break;
- case SEND_EVENT:
- events.add(new SendEvent(ByteBufUtils.serializeList(step.getBytes())));
- break;
- case WAIT_FOR_MESSAGE_EVENT:
- events.add(new WaitForMessageEvent(ByteBufUtils.serializeList(step.getBytes())));
- break;
- default:
- break;
- }
- }
- return events;
- }
-
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<scenarios xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="scenario.xsd">
- <scenario name="handshakeScenarioWithBarrier">
- <step>
- <order>1</order>
- <name>send Hello</name>
- <event>sendEvent</event>
- <bytes>04 00 00 08 00 00 00 01</bytes>
- </step>
- <step>
- <order>2</order>
- <name>wait for Hello_21</name>
- <event>waitForMessageEvent</event>
- <bytes>04 00 00 10 00 00 00 15 00 01 00 08 00 00 00 12</bytes>
- </step>
- <step>
- <order>3</order>
- <name>wait for features request</name>
- <event>waitForMessageEvent</event>
- <bytes>04 05 00 08 00 00 00 02</bytes>
- </step>
- <step>
- <order>4</order>
- <name>features reply</name>
- <event>sendEvent</event>
- <bytes>04 06 00 20 00 00 00 02 00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 00 01 02 03 00 01 02 03</bytes>
- </step>
- <step>
- <order>5</order>
- <name>wait for barrier</name>
- <event>waitForMessageEvent</event>
- <bytes>04 14 00 08 00 00 00 00</bytes>
- </step>
- <step>
- <order>6</order>
- <name>barrier reply</name>
- <event>sendEvent</event>
- <bytes>04 15 00 08 00 00 00 04</bytes>
- </step>
- </scenario>
-</scenarios>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
-
- <xs:simpleType name="eventType">
- <xs:restriction base="xs:string">
- <xs:enumeration value="sleepEvent"/>
- <xs:enumeration value="waitForMessageEvent"/>
- <xs:enumeration value="sendEvent"/>
- </xs:restriction>
- </xs:simpleType>
-
- <xs:simpleType name="bytes">
- <xs:list itemType="xs:short"/>
- </xs:simpleType>
-
- <xs:complexType name="step">
- <xs:sequence>
- <xs:element name="order" type="xs:short" minOccurs="1" maxOccurs="1"/>
- <xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1"/>
- <xs:element name="event" type="eventType" minOccurs="1" maxOccurs="1"/>
- <xs:element name="bytes" type="bytes" minOccurs="0" maxOccurs="1"/>
- </xs:sequence>
- </xs:complexType>
-
- <xs:complexType name="scenario">
- <xs:sequence>
- <xs:element name="step" type="step" minOccurs="1" maxOccurs="unbounded"/>
- </xs:sequence>
- <xs:attribute name="name" type="xs:string" use="required"/>
- </xs:complexType>
-
- <xs:element name="scenarios">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="scenario" type="scenario" maxOccurs="unbounded"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
-
-</xs:schema>
\ No newline at end of file