Thomas Vachuska
Committed by Gerrit Code Review

Added deviceId to the DriverData as part of available context.

Change-Id: I5be94f35a2889e0c93cf3c20c4c9d6f907411121
......@@ -16,6 +16,7 @@
package org.onosproject.net.driver;
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MutableAnnotations;
import java.util.HashMap;
......@@ -30,6 +31,7 @@ import static com.google.common.base.MoreObjects.toStringHelper;
public class DefaultDriverData implements DriverData {
private final Driver driver;
private final DeviceId deviceId;
private final Map<String, String> properties;
/**
......@@ -37,8 +39,9 @@ public class DefaultDriverData implements DriverData {
*
* @param driver parent driver type
*/
public DefaultDriverData(Driver driver) {
public DefaultDriverData(Driver driver, DeviceId deviceId) {
this.driver = driver;
this.deviceId = deviceId;
this.properties = new HashMap<>();
}
......@@ -48,6 +51,11 @@ public class DefaultDriverData implements DriverData {
}
@Override
public DeviceId deviceId() {
return deviceId;
}
@Override
public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
return driver.createBehaviour(this, behaviourClass);
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.net.driver;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MutableAnnotations;
/**
......@@ -31,6 +32,13 @@ public interface DriverData extends MutableAnnotations {
Driver driver();
/**
* Returns the device identifier.
*
* @return device identifier
*/
DeviceId deviceId();
/**
* Returns the specified facet of behaviour to access the device data.
*
* @param behaviourClass behaviour class
......
......@@ -18,11 +18,15 @@ package org.onosproject.net.driver;
import com.google.common.collect.ImmutableMap;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.net.DeviceId;
import static org.junit.Assert.*;
import static org.onosproject.net.DeviceId.deviceId;
public class DefaultDriverDataTest {
public static final DeviceId DEVICE_ID = deviceId("of:0011223344556677");
DefaultDriver ddc;
DefaultDriverData data;
......@@ -32,12 +36,13 @@ public class DefaultDriverDataTest {
ImmutableMap.of(TestBehaviour.class,
TestBehaviourImpl.class),
ImmutableMap.of("foo", "bar"));
data = new DefaultDriverData(ddc);
data = new DefaultDriverData(ddc, DEVICE_ID);
}
@Test
public void basics() {
assertSame("incorrect type", ddc, data.driver());
assertSame("incorrect driver", ddc, data.driver());
assertEquals("incorrect device id", DEVICE_ID, data.deviceId());
assertTrue("incorrect toString", data.toString().contains("foo.bar"));
}
......
......@@ -36,7 +36,7 @@ public class DefaultDriverHandlerTest {
TestBehaviourTwo.class,
TestBehaviourTwoImpl.class),
ImmutableMap.of("foo", "bar"));
data = new DefaultDriverData(ddc);
data = new DefaultDriverData(ddc, DefaultDriverDataTest.DEVICE_ID);
handler = new DefaultDriverHandler(data);
}
......
......@@ -20,6 +20,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.onosproject.net.driver.DefaultDriverDataTest.DEVICE_ID;
public class DefaultDriverTest {
......@@ -45,10 +46,10 @@ public class DefaultDriverTest {
assertEquals("incorrect behaviour count", 0, ddc.behaviours().size());
assertTrue("incorrect behaviour", ddc.hasBehaviour(TestBehaviour.class));
Behaviour b1 = ddc.createBehaviour(new DefaultDriverData(ddc), TestBehaviour.class);
Behaviour b1 = ddc.createBehaviour(new DefaultDriverData(ddc, DEVICE_ID), TestBehaviour.class);
assertTrue("incorrect behaviour class", b1 instanceof TestBehaviourImpl);
Behaviour b2 = ddc.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(ddc)),
Behaviour b2 = ddc.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(ddc, DEVICE_ID)),
TestBehaviourTwo.class);
assertTrue("incorrect behaviour class", b2 instanceof TestBehaviourTwoImpl);
......
......@@ -23,6 +23,7 @@ import java.util.Iterator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.onosproject.net.driver.DefaultDriverDataTest.DEVICE_ID;
/**
* Tests of the XML driver loader implementation.
......@@ -73,7 +74,7 @@ public class XmlDriverLoaderTest {
InputStream stream = getClass().getResourceAsStream("drivers.noconstructor.xml");
DriverProvider provider = loader.loadDrivers(stream, null);
Driver driver = provider.getDrivers().iterator().next();
driver.createBehaviour(new DefaultDriverData(driver), TestBehaviour.class);
driver.createBehaviour(new DefaultDriverData(driver, DEVICE_ID), TestBehaviour.class);
}
}
\ No newline at end of file
......
......@@ -177,7 +177,7 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS
checkPermission(Permission.DRIVER_WRITE);
Driver driver = getDriver(deviceId);
return new DefaultDriverHandler(new DefaultDriverData(driver));
return new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
}
// Produces a composite driver key using the specified components.
......
......@@ -43,7 +43,7 @@
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
......
......@@ -43,6 +43,8 @@ import java.util.Map;
import java.util.concurrent.Executors;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.openflow.controller.Dpid.uri;
/**
......@@ -208,9 +210,12 @@ public class Controller {
.getDriver(desc.getMfrDesc(), desc.getHwDesc(), desc.getSwDesc());
if (driver != null && driver.hasBehaviour(OpenFlowSwitchDriver.class)) {
OpenFlowSwitchDriver ofSwitchDriver = driver.createBehaviour(new DefaultDriverHandler(
new DefaultDriverData(driver)), OpenFlowSwitchDriver.class);
ofSwitchDriver.init(new Dpid(dpid), desc, ofv);
Dpid did = new Dpid(dpid);
DefaultDriverHandler handler =
new DefaultDriverHandler(new DefaultDriverData(driver, deviceId(uri(did))));
OpenFlowSwitchDriver ofSwitchDriver =
driver.createBehaviour(handler, OpenFlowSwitchDriver.class);
ofSwitchDriver.init(did, desc, ofv);
ofSwitchDriver.setAgent(agent);
ofSwitchDriver.setRoleHandler(new RoleManager(ofSwitchDriver));
log.info("OpenFlow handshaker found for device {}: {}", dpid, ofSwitchDriver);
......