/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
package org.opendaylight.openflowjava.protocol.impl.integration;\r
\r
-import java.lang.reflect.InvocationTargetException;\r
import java.net.InetAddress;\r
import java.util.Arrays;\r
import java.util.concurrent.ExecutionException;\r
+import java.util.concurrent.Future;\r
import java.util.concurrent.TimeUnit;\r
import java.util.concurrent.TimeoutException;\r
\r
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;\r
import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;\r
-import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;\r
private int idleCounter = 0;\r
\r
public MockPlugin() {\r
+ LOGGER.info("Creating MockPlugin");\r
finishedFuture = SettableFuture.create();\r
+ LOGGER.info("mockPlugin: "+System.identityHashCode(this));\r
}\r
\r
@Override\r
public void onSwitchConnected(ConnectionAdapter connection) {\r
- LOGGER.debug("onSwitchConnected");\r
+ LOGGER.info("onSwitchConnected: " + connection);\r
this.adapter = connection;\r
connection.setMessageListener(this);\r
connection.setSystemListener(this);\r
LOGGER.debug("EchoRequest message received");\r
LOGGER.debug("Building EchoReplyInput");\r
EchoReplyInputBuilder replyBuilder = new EchoReplyInputBuilder();\r
- try {\r
- BufferHelper.setupHeader(replyBuilder);\r
- } catch (NoSuchMethodException | SecurityException\r
- | IllegalAccessException | IllegalArgumentException\r
- | InvocationTargetException e) {\r
- LOGGER.error(e.getMessage(), e);\r
- }\r
+ replyBuilder.setVersion((short) 4);\r
replyBuilder.setXid(notification.getXid());\r
EchoReplyInput echoReplyInput = replyBuilder.build();\r
LOGGER.debug("EchoReplyInput built");\r
LOGGER.debug("Going to send EchoReplyInput");\r
adapter.echoReply(echoReplyInput);\r
LOGGER.debug("EchoReplyInput sent");\r
+ LOGGER.debug("adapter: "+adapter);\r
}\r
\r
@Override\r
\r
@Override\r
public void onHelloMessage(HelloMessage notification) {\r
+ LOGGER.debug("adapter: "+adapter);\r
LOGGER.debug("Hello message received");\r
HelloInputBuilder hib = new HelloInputBuilder();\r
GetFeaturesInputBuilder featuresBuilder = new GetFeaturesInputBuilder();\r
- try {\r
- BufferHelper.setupHeader(hib);\r
- BufferHelper.setupHeader(featuresBuilder);\r
- } catch (Exception e) {\r
- LOGGER.error(e.getMessage(), e);\r
- }\r
+ hib.setVersion((short) 4);\r
+ hib.setXid(2L);\r
+ featuresBuilder.setVersion((short) 4);\r
+ featuresBuilder.setXid(3L);\r
HelloInput hi = hib.build();\r
adapter.hello(hi);\r
LOGGER.debug("hello msg sent");\r
if (rpcResult.isSuccessful()) {\r
byte[] byteArray = rpcResult.getResult().getDatapathId()\r
.toByteArray();\r
- LOGGER.debug("DatapathId: " + Arrays.toString(byteArray));\r
+ LOGGER.info("DatapathId: " + Arrays.toString(byteArray));\r
} else {\r
RpcError rpcError = rpcResult.getErrors().iterator().next();\r
LOGGER.warn("rpcResult failed: "\r
}\r
} catch (InterruptedException | ExecutionException | TimeoutException e) {\r
LOGGER.error(e.getMessage(), e);\r
+ // TODO - Collect exceptions and check for existence in tests\r
+ }\r
+ LOGGER.info("After FeaturesReply message");\r
+ LOGGER.debug("adapter: "+adapter);\r
+ }\r
+\r
+ protected void shutdown() {\r
+ LOGGER.debug("adapter: "+adapter);\r
+ try {\r
+ LOGGER.info("mockPlugin: "+System.identityHashCode(this));\r
+ Thread.sleep(500);\r
+// if (adapter != null) {\r
+ Future<Boolean> disconnect = adapter.disconnect();\r
+ disconnect.get();\r
+ LOGGER.info("Disconnected");\r
+// }\r
+ } catch (Exception e) {\r
+ LOGGER.error(e.getMessage(), e);\r
}\r
- LOGGER.info("After FeaturesReply message - disconnecting");\r
- adapter.disconnect();\r
finishedFuture.set(null);\r
}\r
\r
@Override\r
public void onDisconnectEvent(DisconnectEvent notification) {\r
LOGGER.debug("disconnection ocured: "+notification.getInfo());\r
+ LOGGER.debug("adapter: "+adapter);\r
}\r
\r
public SettableFuture<Void> getFinishedFuture() {\r