Added deviceId to the DriverData as part of available context.
Change-Id: I5be94f35a2889e0c93cf3c20c4c9d6f907411121
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverData.java b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverData.java
index efa632d..7063c03 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverData.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverData.java
@@ -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 @@
public class DefaultDriverData implements DriverData {
private final Driver driver;
+ private final DeviceId deviceId;
private final Map<String, String> properties;
/**
@@ -37,8 +39,9 @@
*
* @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 @@
}
@Override
+ public DeviceId deviceId() {
+ return deviceId;
+ }
+
+ @Override
public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
return driver.createBehaviour(this, behaviourClass);
}
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DriverData.java b/core/api/src/main/java/org/onosproject/net/driver/DriverData.java
index 4cf7093..1d66ea9 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DriverData.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DriverData.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.driver;
+import org.onosproject.net.DeviceId;
import org.onosproject.net.MutableAnnotations;
/**
@@ -31,6 +32,13 @@
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
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverDataTest.java b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverDataTest.java
index 006957d..e3d6910 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverDataTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverDataTest.java
@@ -18,11 +18,15 @@
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 @@
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"));
}
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverHandlerTest.java b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverHandlerTest.java
index 08a508c..717cda2 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverHandlerTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverHandlerTest.java
@@ -36,7 +36,7 @@
TestBehaviourTwo.class,
TestBehaviourTwoImpl.class),
ImmutableMap.of("foo", "bar"));
- data = new DefaultDriverData(ddc);
+ data = new DefaultDriverData(ddc, DefaultDriverDataTest.DEVICE_ID);
handler = new DefaultDriverHandler(data);
}
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
index 17af6c7..01cc7a1 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
@@ -20,6 +20,7 @@
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 @@
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);
diff --git a/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java b/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java
index ea77a50..f54e741 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java
@@ -23,6 +23,7 @@
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 @@
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
diff --git a/core/net/src/main/java/org/onosproject/net/driver/impl/DriverManager.java b/core/net/src/main/java/org/onosproject/net/driver/impl/DriverManager.java
index 43040da..b395307 100644
--- a/core/net/src/main/java/org/onosproject/net/driver/impl/DriverManager.java
+++ b/core/net/src/main/java/org/onosproject/net/driver/impl/DriverManager.java
@@ -177,7 +177,7 @@
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.
diff --git a/openflow/ctl/pom.xml b/openflow/ctl/pom.xml
index f90f952..9f52cf7 100644
--- a/openflow/ctl/pom.xml
+++ b/openflow/ctl/pom.xml
@@ -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>
diff --git a/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java b/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java
index 5b0c8ac..6cbd991 100644
--- a/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java
+++ b/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java
@@ -43,6 +43,8 @@
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 @@
.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);