package org.opendaylight.openflowplugin.openflow.md.it;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
import org.opendaylight.controller.sal.binding.api.NotificationService;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
-import org.opendaylight.controller.test.sal.binding.it.TestHelper;
import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioFactory;
import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.junit.Assert.*;
-import static org.opendaylight.controller.test.sal.binding.it.TestHelper.*;
-
/**
* @author mirehak
*/
mavenBundle(ODL, "sal").versionAsInProject(), mavenBundle(ODL, "sal.connection").versionAsInProject(),
mdSalCoreBundles(), bindingAwareSalBundles(), baseModelBundles(), flowCapableModelBundles(),
+ configMinumumBundles(),
mavenBundle("org.opendaylight.controller.thirdparty", "org.openflow.openflowj").versionAsInProject(),
List<NodeRemoved> nodeRemoved = new ArrayList<>();
List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
+
+ /**
+ * default ctor
+ */
+ protected TestInventoryListener() {
+ // do nothing
+ }
@Override
public void onNodeUpdated(NodeUpdated notification) {
public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
nodeConnectorRemoved.add(notification);
}
- };
+ }
}
import java.util.concurrent.TimeUnit;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
import org.opendaylight.openflowplugin.openflow.md.core.session.SessionManager;
* @author mirehak
*/
public class ConnectionConductorImpl implements OpenflowProtocolListener,
- SystemNotificationsListener, ConnectionConductor {
+ SystemNotificationsListener, ConnectionConductor, ConnectionReadyListener {
private static final Logger LOG = LoggerFactory
.getLogger(ConnectionConductorImpl.class);
public void init() {
connectionAdapter.setMessageListener(this);
connectionAdapter.setSystemListener(this);
- //TODO : Wait for library to provide interface from which we can send first hello message
-// sendFirstHelloMessage();
+ connectionAdapter.setConnectionReadyListener(this);
}
* TODO: Better to handle handshake into a maintainable innerclass which uses State-Pattern.
*/
@Override
- public void onHelloMessage(HelloMessage hello) {
+ public void onHelloMessage(final HelloMessage hello) {
// do handshake
LOG.info("handshake STARTED");
checkState(CONDUCTOR_STATE.HANDSHAKING);
- Short remoteVersion = hello.getVersion();
- List<Elements> elements = hello.getElements();
- long xid = hello.getXid();
- short proposedVersion;
- LOG.debug("Hello message version={} and bitmap={}", remoteVersion, elements);
- try {
- // find the version from header version field
- proposedVersion = proposeVersion(remoteVersion);
-
- } catch (IllegalArgumentException e) {
- handleException(e);
- connectionAdapter.disconnect();
- throw e;
- }
-
- // sent version is equal to remote --> version is negotiated
- if (proposedVersion == remoteVersion) {
- LOG.debug("sending helloReply as version in header is supported: {}", proposedVersion);
- sendHelloReply(proposedVersion, ++xid);
- postHandshake(proposedVersion, ++xid);
-
- } else if (isBitmapNegotiationEnable && null != elements && 0 != elements.size()) {
- try {
- // hello contains version bitmap, checking highest common
- // version in bitmap
- proposedVersion = proposeBitmapVersion(elements);
- } catch (IllegalArgumentException ex) {
- handleException(ex);
- connectionAdapter.disconnect();
- throw ex;
- }
- LOG.debug("sending helloReply for common bitmap version : {}", proposedVersion);
- sendHelloReply(proposedVersion, ++xid);
- postHandshake(proposedVersion, ++xid);
- } else {
- if (isFirstHelloNegotiation) {
- isFirstHelloNegotiation = false;
- LOG.debug("sending helloReply for lowest supported version : {}", proposedVersion);
- // send hello reply with lower version number supported
- sendHelloReply(proposedVersion, ++xid);
- } else {
- // terminate the connection.
- LOG.debug("Version negotiation failed. unsupported version : {}", remoteVersion);
- connectionAdapter.disconnect();
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ Short remoteVersion = hello.getVersion();
+ List<Elements> elements = hello.getElements();
+ long xid = hello.getXid();
+ short proposedVersion;
+ LOG.debug("Hello message version={} and bitmap={}", remoteVersion, elements);
+ try {
+ // find the version from header version field
+ proposedVersion = proposeVersion(remoteVersion);
+
+ } catch (IllegalArgumentException e) {
+ handleException(e);
+ connectionAdapter.disconnect();
+ throw e;
+ }
+
+ // sent version is equal to remote --> version is negotiated
+ if (proposedVersion == remoteVersion) {
+ LOG.debug("sending helloReply as version in header is supported: {}", proposedVersion);
+ sendHelloReply(proposedVersion, ++xid);
+ postHandshake(proposedVersion, ++xid);
+
+ } else if (isBitmapNegotiationEnable && null != elements && 0 != elements.size()) {
+ try {
+ // hello contains version bitmap, checking highest common
+ // version in bitmap
+ proposedVersion = proposeBitmapVersion(elements);
+ } catch (IllegalArgumentException ex) {
+ handleException(ex);
+ connectionAdapter.disconnect();
+ throw ex;
+ }
+ LOG.debug("sending helloReply for common bitmap version : {}", proposedVersion);
+ sendHelloReply(proposedVersion, ++xid);
+ postHandshake(proposedVersion, ++xid);
+ } else {
+ if (isFirstHelloNegotiation) {
+ isFirstHelloNegotiation = false;
+ LOG.debug("sending helloReply for lowest supported version : {}", proposedVersion);
+ // send hello reply with lower version number supported
+ sendHelloReply(proposedVersion, ++xid);
+ } else {
+ // terminate the connection.
+ LOG.debug("Version negotiation failed. unsupported version : {}", remoteVersion);
+ connectionAdapter.disconnect();
+ }
+ }
}
- }
+
+ }).start();
}
/**
public ConnectionAdapter getConnectionAdapter() {
return connectionAdapter;
}
+
+ @Override
+ public void onConnectionReady() {
+ // TODO Auto-generated method stub
+ }
}
import org.opendaylight.controller.sal.common.util.RpcErrors;
import org.opendaylight.controller.sal.common.util.Rpcs;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
protected List<Exception> occuredExceptions = new ArrayList<>();
+ private ConnectionReadyListener connectionReadyListener;
+
/**
* default ctor
*/
@Override
public void checkListeners() {
- if (ofListener == null || systemListener == null) {
+ if (ofListener == null || systemListener == null || connectionReadyListener == null) {
occuredExceptions
.add(new IllegalStateException("missing listeners"));
}
public List<Exception> getOccuredExceptions() {
return occuredExceptions;
}
+
+ @Override
+ public void fireConnectionReadyNotification() {
+ if (connectionReadyListener != null) {
+ connectionReadyListener.onConnectionReady();
+ }
+ }
+
+ @Override
+ public void setConnectionReadyListener(
+ ConnectionReadyListener connectionReadyListener) {
+ this.connectionReadyListener = connectionReadyListener;
+ }
}