import java.net.InetAddress;
import java.util.ArrayList;
+import java.util.Deque;
import java.util.List;
-import java.util.Stack;
+
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
public void testHandshake() throws Exception {
setUp(TransportProtocol.TCP);
int amountOfCLients = 1;
- Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
ScenarioHandler handler = new ScenarioHandler(scenario);
List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP);
OFClient firstClient = clients.get(0);
public void testTlsHandshake() throws Exception {
setUp(TransportProtocol.TLS);
int amountOfCLients = 1;
- Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
ScenarioHandler handler = new ScenarioHandler(scenario);
List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS);
OFClient firstClient = clients.get(0);
public void testHandshakeAndEcho() throws Exception {
setUp(TransportProtocol.TCP);
int amountOfCLients = 1;
- Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
- scenario.add(0, new SleepEvent(1000));
- scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
- scenario.add(0, new SleepEvent(1000));
- scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
+ Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ scenario.addFirst(new SleepEvent(1000));
+ scenario.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
+ scenario.addFirst(new SleepEvent(1000));
+ scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
ScenarioHandler handler = new ScenarioHandler(scenario);
List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP);
OFClient firstClient = clients.get(0);
public void testTlsHandshakeAndEcho() throws Exception {
setUp(TransportProtocol.TLS);
int amountOfCLients = 1;
- Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
- scenario.add(0, new SleepEvent(1000));
- scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
- scenario.add(0, new SleepEvent(1000));
- scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
+ Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ scenario.addFirst(new SleepEvent(1000));
+ scenario.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
+ scenario.addFirst(new SleepEvent(1000));
+ scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
ScenarioHandler handler = new ScenarioHandler(scenario);
List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS);
OFClient firstClient = clients.get(0);
public void testUdpHandshakeAndEcho() throws Exception {
setUp(TransportProtocol.UDP);
int amountOfCLients = 1;
- Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
- scenario.add(0, new SleepEvent(1000));
- scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
- scenario.add(0, new SleepEvent(1000));
- scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
+ Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ scenario.addFirst(new SleepEvent(1000));
+ scenario.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
+ scenario.addFirst(new SleepEvent(1000));
+ scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
ScenarioHandler handler = new ScenarioHandler(scenario);
List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.UDP);
OFClient firstClient = clients.get(0);
package org.opendaylight.openflowjava.protocol.impl.clients;
-import java.util.Stack;
+import java.util.ArrayDeque;
+import java.util.Deque;
import org.opendaylight.openflowjava.util.ByteBufUtils;
* </ol>
* @return stack filled with Handshake messages
*/
- public static Stack<ClientEvent> createHandshakeScenario() {
- Stack<ClientEvent> stack = new Stack<>();
- stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
- stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
- stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
- stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
+ public static Deque<ClientEvent> createHandshakeScenario() {
+ Deque<ClientEvent> stack = new ArrayDeque<>();
+ stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
+ stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
+ stack.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
+ stack.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
+ "00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 00 01 02 03 00 01 02 03")));
return stack;
}
* @param auxiliaryId auxiliaryId wanted in featuresReply message
* @return stack filled with Handshake messages (featuresReply with auxiliaryId set)
*/
- public static Stack<ClientEvent> createHandshakeScenarioWithAuxiliaryId(byte auxiliaryId) {
- Stack<ClientEvent> stack = new Stack<>();
- stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
- stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
- stack.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
- stack.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
+ public static Deque<ClientEvent> createHandshakeScenarioWithAuxiliaryId(byte auxiliaryId) {
+ Deque<ClientEvent> queue = new ArrayDeque<>();
+ queue.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 01")));
+ queue.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 00 00 08 00 00 00 02")));
+ queue.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 05 00 08 00 00 00 03")));
+ queue.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 06 00 20 00 00 00 03 "
+ "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")));
- return stack;
+ return queue;
}
}
import io.netty.channel.ChannelHandlerContext;
-import java.util.Stack;
+import java.util.Deque;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
public class ScenarioHandler extends Thread {
private static final Logger LOGGER = LoggerFactory.getLogger(ScenarioHandler.class);
- private Stack<ClientEvent> scenario;
+ private Deque<ClientEvent> scenario;
private BlockingQueue<byte[]> ofMsg;
private ChannelHandlerContext ctx;
private int eventNumber;
*
* @param scenario
*/
- public ScenarioHandler(Stack<ClientEvent> scenario) {
+ public ScenarioHandler(Deque<ClientEvent> scenario) {
this.scenario = scenario;
ofMsg = new LinkedBlockingQueue<>();
}
int freezeCounter = 0;
while (!scenario.isEmpty()) {
LOGGER.debug("Running event #" + eventNumber);
- ClientEvent peek = scenario.peek();
+ ClientEvent peek = scenario.peekLast();
if (peek instanceof WaitForMessageEvent) {
LOGGER.debug("WaitForMessageEvent");
try {
event.setCtx(ctx);
}
if (peek.eventExecuted()) {
- scenario.pop();
+ scenario.removeLast();
eventNumber++;
freezeCounter = 0;
} else {
/**
* @return scenario
*/
- public Stack<ClientEvent> getScenario() {
+ public Deque<ClientEvent> getScenario() {
return scenario;
}
/**
* @param scenario scenario filled with desired events
*/
- public void setScenario(Stack<ClientEvent> scenario) {
+ public void setScenario(Deque<ClientEvent> scenario) {
this.scenario = scenario;
}