tom

Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

Showing 16 changed files with 94 additions and 27 deletions
......@@ -219,6 +219,7 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
@Override
public void setRole(RoleState role) {
try {
log.info("Sending role {} to switch {}", role, getStringId());
if (this.roleMan.sendRoleRequest(role, RoleRecvStatus.MATCHED_SET_ROLE)) {
this.role = role;
}
......
......@@ -15,7 +15,7 @@
* under the License.
**/
package org.onlab.onos.of.controller.impl.internal;
package org.onlab.onos.of.controller.impl;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
......@@ -34,7 +34,7 @@ import org.onlab.onos.of.controller.driver.OpenFlowAgent;
import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver;
import org.onlab.onos.of.controller.impl.annotations.LogMessageDoc;
import org.onlab.onos.of.controller.impl.annotations.LogMessageDocs;
import org.onlab.onos.of.drivers.DriverManager;
import org.onlab.onos.of.drivers.impl.DriverManager;
import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
import org.projectfloodlight.openflow.protocol.OFFactories;
import org.projectfloodlight.openflow.protocol.OFFactory;
......
......@@ -15,7 +15,7 @@
* under the License.
**/
package org.onlab.onos.of.controller.impl.internal;
package org.onlab.onos.of.controller.impl;
/**
* Exception is thrown when the handshake fails to complete.
......
......@@ -15,7 +15,7 @@
* under the License.
**/
package org.onlab.onos.of.controller.impl.internal;
package org.onlab.onos.of.controller.impl;
import java.util.concurrent.TimeUnit;
......
package org.onlab.onos.of.controller.impl.internal;
package org.onlab.onos.of.controller.impl;
import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch;
import org.projectfloodlight.openflow.protocol.OFVersion;
......
//CHECKSTYLE:OFF
package org.onlab.onos.of.controller.impl.internal;
package org.onlab.onos.of.controller.impl;
import java.io.IOException;
import java.nio.channels.ClosedChannelException;
......@@ -415,17 +415,18 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
OFDescStatsReply drep = (OFDescStatsReply) m;
// Here is where we differentiate between different kinds of switches
h.sw = h.controller.getOFSwitchInstance(h.thisdpid, drep, h.ofVersion);
h.sw.setOFVersion(h.ofVersion);
h.sw.setFeaturesReply(h.featuresReply);
h.sw.setPortDescReply(h.portDescReply);
h.sw.setConnected(true);
h.sw.setChannel(h.channel);
boolean success = h.sw.connectSwitch();
if (!success) {
disconnectDuplicate(h);
return;
}
// set switch information
h.sw.setOFVersion(h.ofVersion);
h.sw.setFeaturesReply(h.featuresReply);
h.sw.setPortDescReply(h.portDescReply);
h.sw.setConnected(true);
h.sw.setChannel(h.channel);
log.info("Switch {} bound to class {}, description {}",
......
......@@ -15,7 +15,7 @@
* under the License.
**/
package org.onlab.onos.of.controller.impl.internal;
package org.onlab.onos.of.controller.impl;
import org.jboss.netty.buffer.ChannelBuffer;
......
......@@ -15,7 +15,7 @@
* under the License.
**/
package org.onlab.onos.of.controller.impl.internal;
package org.onlab.onos.of.controller.impl;
import java.util.List;
......
package org.onlab.onos.of.controller.impl.internal;
package org.onlab.onos.of.controller.impl;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
......@@ -15,7 +15,6 @@ import org.onlab.onos.of.controller.OpenFlowSwitch;
import org.onlab.onos.of.controller.OpenFlowSwitchListener;
import org.onlab.onos.of.controller.PacketListener;
import org.onlab.onos.of.controller.RoleState;
import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch;
import org.onlab.onos.of.controller.driver.OpenFlowAgent;
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.slf4j.Logger;
......@@ -68,17 +67,18 @@ public class OpenFlowControllerImpl implements OpenFlowController {
@Override
public OpenFlowSwitch getSwitch(Dpid dpid) {
return connectedSwitches.get(dpid.value());
return connectedSwitches.get(dpid);
}
@Override
public OpenFlowSwitch getMasterSwitch(Dpid dpid) {
return activeMasterSwitches.get(dpid.value());
return activeMasterSwitches.get(dpid);
}
@Override
public OpenFlowSwitch getEqualSwitch(Dpid dpid) {
return activeEqualSwitches.get(dpid.value()); }
return activeEqualSwitches.get(dpid);
}
@Override
public void addListener(OpenFlowSwitchListener listener) {
......@@ -116,9 +116,15 @@ public class OpenFlowControllerImpl implements OpenFlowController {
@Override
public void setRole(Dpid dpid, RoleState role) {
((AbstractOpenFlowSwitch) getSwitch(dpid)).setRole(role);
getSwitch(dpid).setRole(role);
}
/**
* Implementation of an OpenFlow Agent which is responsible for
* keeping track of connected switches and the state in which
* they are.
*
*/
public class OpenFlowSwitchAgent implements OpenFlowAgent {
private final Logger log = LoggerFactory.getLogger(OpenFlowSwitchAgent.class);
......@@ -204,6 +210,7 @@ public class OpenFlowControllerImpl implements OpenFlowController {
+ "was not found in controller-cache", dpid);
return;
}
log.info("Transitioned switch {} to MASTER", dpid);
activeMasterSwitches.put(dpid, sw);
} finally {
switchLock.unlock();
......@@ -224,6 +231,7 @@ public class OpenFlowControllerImpl implements OpenFlowController {
+ "was not found in controller-cache", dpid);
return;
}
log.info("Transitioned switch {} to EQUAL", dpid);
activeEqualSwitches.put(dpid, sw);
} finally {
switchLock.unlock();
......
......@@ -15,7 +15,7 @@
* under the License.
**/
package org.onlab.onos.of.controller.impl.internal;
package org.onlab.onos.of.controller.impl;
import java.util.concurrent.ThreadPoolExecutor;
......
package org.onlab.onos.of.controller.impl.internal;
package org.onlab.onos.of.controller.impl;
import java.io.IOException;
import java.util.Collections;
......
package org.onlab.onos.of.drivers;
package org.onlab.onos.of.drivers.impl;
import java.io.IOException;
import java.util.ArrayList;
......
package org.onlab.onos.of.drivers;
package org.onlab.onos.of.drivers.impl;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
......
package org.onlab.onos.provider.of.device.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.device.DeviceDescription;
import org.onlab.onos.net.device.DeviceProvider;
import org.onlab.onos.net.device.DeviceProviderRegistry;
import org.onlab.onos.net.device.DeviceProviderService;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.of.controller.Dpid;
import org.onlab.onos.of.controller.OpenFlowController;
import org.onlab.onos.of.controller.OpenFlowSwitchListener;
import org.onlab.onos.of.controller.RoleState;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provider which uses an OpenFlow controller to detect network
* infrastructure devices.
......@@ -44,6 +52,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
@Activate
public void activate() {
providerService = providerRegistry.register(this);
controller.addListener(new InternalDeviceProvider());
log.info("Started");
}
......@@ -61,7 +70,55 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
@Override
public void roleChanged(Device device, MastershipRole newRole) {
switch (newRole) {
case MASTER:
controller.setRole(new Dpid(device.id().uri().getSchemeSpecificPart()),
RoleState.MASTER);
break;
case STANDBY:
controller.setRole(new Dpid(device.id().uri().getSchemeSpecificPart()),
RoleState.EQUAL);
case NONE:
controller.setRole(new Dpid(device.id().uri().getSchemeSpecificPart()),
RoleState.SLAVE);
break;
default:
log.error("Unknown Mastership state : {}", newRole);
}
log.info("Accepting mastership role change for device {}", device.id());
}
private class InternalDeviceProvider implements OpenFlowSwitchListener {
@Override
public void switchAdded(final Dpid dpid) {
URI uri = buildURI(dpid);
providerService.deviceConnected(new DeviceId(uri), new DeviceDescription() {
@Override
public URI deviceURI() {
return buildURI(dpid);
}
});
}
@Override
public void switchRemoved(Dpid dpid) {
URI uri = buildURI(dpid);
providerService.deviceDisconnected(new DeviceId(uri));
}
private URI buildURI(Dpid dpid) {
URI uri = null;
try {
uri = new URI("of", Long.toHexString(dpid.value()), null);
} catch (URISyntaxException e) {
log.warn("URI construction for device {} failed.", dpid);
}
return uri;
}
}
}
......