Committed by
Gerrit Code Review
Added deviceId to the DriverData as part of available context.
Change-Id: I5be94f35a2889e0c93cf3c20c4c9d6f907411121
Showing
9 changed files
with
40 additions
and
12 deletions
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.net.driver; | 16 | package org.onosproject.net.driver; |
| 17 | 17 | ||
| 18 | import com.google.common.collect.ImmutableSet; | 18 | import com.google.common.collect.ImmutableSet; |
| 19 | +import org.onosproject.net.DeviceId; | ||
| 19 | import org.onosproject.net.MutableAnnotations; | 20 | import org.onosproject.net.MutableAnnotations; |
| 20 | 21 | ||
| 21 | import java.util.HashMap; | 22 | import java.util.HashMap; |
| ... | @@ -30,6 +31,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -30,6 +31,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
| 30 | public class DefaultDriverData implements DriverData { | 31 | public class DefaultDriverData implements DriverData { |
| 31 | 32 | ||
| 32 | private final Driver driver; | 33 | private final Driver driver; |
| 34 | + private final DeviceId deviceId; | ||
| 33 | private final Map<String, String> properties; | 35 | private final Map<String, String> properties; |
| 34 | 36 | ||
| 35 | /** | 37 | /** |
| ... | @@ -37,8 +39,9 @@ public class DefaultDriverData implements DriverData { | ... | @@ -37,8 +39,9 @@ public class DefaultDriverData implements DriverData { |
| 37 | * | 39 | * |
| 38 | * @param driver parent driver type | 40 | * @param driver parent driver type |
| 39 | */ | 41 | */ |
| 40 | - public DefaultDriverData(Driver driver) { | 42 | + public DefaultDriverData(Driver driver, DeviceId deviceId) { |
| 41 | this.driver = driver; | 43 | this.driver = driver; |
| 44 | + this.deviceId = deviceId; | ||
| 42 | this.properties = new HashMap<>(); | 45 | this.properties = new HashMap<>(); |
| 43 | } | 46 | } |
| 44 | 47 | ||
| ... | @@ -48,6 +51,11 @@ public class DefaultDriverData implements DriverData { | ... | @@ -48,6 +51,11 @@ public class DefaultDriverData implements DriverData { |
| 48 | } | 51 | } |
| 49 | 52 | ||
| 50 | @Override | 53 | @Override |
| 54 | + public DeviceId deviceId() { | ||
| 55 | + return deviceId; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + @Override | ||
| 51 | public <T extends Behaviour> T behaviour(Class<T> behaviourClass) { | 59 | public <T extends Behaviour> T behaviour(Class<T> behaviourClass) { |
| 52 | return driver.createBehaviour(this, behaviourClass); | 60 | return driver.createBehaviour(this, behaviourClass); |
| 53 | } | 61 | } | ... | ... |
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.driver; | 16 | package org.onosproject.net.driver; |
| 17 | 17 | ||
| 18 | +import org.onosproject.net.DeviceId; | ||
| 18 | import org.onosproject.net.MutableAnnotations; | 19 | import org.onosproject.net.MutableAnnotations; |
| 19 | 20 | ||
| 20 | /** | 21 | /** |
| ... | @@ -31,6 +32,13 @@ public interface DriverData extends MutableAnnotations { | ... | @@ -31,6 +32,13 @@ public interface DriverData extends MutableAnnotations { |
| 31 | Driver driver(); | 32 | Driver driver(); |
| 32 | 33 | ||
| 33 | /** | 34 | /** |
| 35 | + * Returns the device identifier. | ||
| 36 | + * | ||
| 37 | + * @return device identifier | ||
| 38 | + */ | ||
| 39 | + DeviceId deviceId(); | ||
| 40 | + | ||
| 41 | + /** | ||
| 34 | * Returns the specified facet of behaviour to access the device data. | 42 | * Returns the specified facet of behaviour to access the device data. |
| 35 | * | 43 | * |
| 36 | * @param behaviourClass behaviour class | 44 | * @param behaviourClass behaviour class | ... | ... |
| ... | @@ -18,11 +18,15 @@ package org.onosproject.net.driver; | ... | @@ -18,11 +18,15 @@ package org.onosproject.net.driver; |
| 18 | import com.google.common.collect.ImmutableMap; | 18 | import com.google.common.collect.ImmutableMap; |
| 19 | import org.junit.Before; | 19 | import org.junit.Before; |
| 20 | import org.junit.Test; | 20 | import org.junit.Test; |
| 21 | +import org.onosproject.net.DeviceId; | ||
| 21 | 22 | ||
| 22 | import static org.junit.Assert.*; | 23 | import static org.junit.Assert.*; |
| 24 | +import static org.onosproject.net.DeviceId.deviceId; | ||
| 23 | 25 | ||
| 24 | public class DefaultDriverDataTest { | 26 | public class DefaultDriverDataTest { |
| 25 | 27 | ||
| 28 | + public static final DeviceId DEVICE_ID = deviceId("of:0011223344556677"); | ||
| 29 | + | ||
| 26 | DefaultDriver ddc; | 30 | DefaultDriver ddc; |
| 27 | DefaultDriverData data; | 31 | DefaultDriverData data; |
| 28 | 32 | ||
| ... | @@ -32,12 +36,13 @@ public class DefaultDriverDataTest { | ... | @@ -32,12 +36,13 @@ public class DefaultDriverDataTest { |
| 32 | ImmutableMap.of(TestBehaviour.class, | 36 | ImmutableMap.of(TestBehaviour.class, |
| 33 | TestBehaviourImpl.class), | 37 | TestBehaviourImpl.class), |
| 34 | ImmutableMap.of("foo", "bar")); | 38 | ImmutableMap.of("foo", "bar")); |
| 35 | - data = new DefaultDriverData(ddc); | 39 | + data = new DefaultDriverData(ddc, DEVICE_ID); |
| 36 | } | 40 | } |
| 37 | 41 | ||
| 38 | @Test | 42 | @Test |
| 39 | public void basics() { | 43 | public void basics() { |
| 40 | - assertSame("incorrect type", ddc, data.driver()); | 44 | + assertSame("incorrect driver", ddc, data.driver()); |
| 45 | + assertEquals("incorrect device id", DEVICE_ID, data.deviceId()); | ||
| 41 | assertTrue("incorrect toString", data.toString().contains("foo.bar")); | 46 | assertTrue("incorrect toString", data.toString().contains("foo.bar")); |
| 42 | } | 47 | } |
| 43 | 48 | ... | ... |
| ... | @@ -36,7 +36,7 @@ public class DefaultDriverHandlerTest { | ... | @@ -36,7 +36,7 @@ public class DefaultDriverHandlerTest { |
| 36 | TestBehaviourTwo.class, | 36 | TestBehaviourTwo.class, |
| 37 | TestBehaviourTwoImpl.class), | 37 | TestBehaviourTwoImpl.class), |
| 38 | ImmutableMap.of("foo", "bar")); | 38 | ImmutableMap.of("foo", "bar")); |
| 39 | - data = new DefaultDriverData(ddc); | 39 | + data = new DefaultDriverData(ddc, DefaultDriverDataTest.DEVICE_ID); |
| 40 | handler = new DefaultDriverHandler(data); | 40 | handler = new DefaultDriverHandler(data); |
| 41 | } | 41 | } |
| 42 | 42 | ... | ... |
| ... | @@ -20,6 +20,7 @@ import org.junit.Test; | ... | @@ -20,6 +20,7 @@ import org.junit.Test; |
| 20 | 20 | ||
| 21 | import static org.junit.Assert.assertEquals; | 21 | import static org.junit.Assert.assertEquals; |
| 22 | import static org.junit.Assert.assertTrue; | 22 | import static org.junit.Assert.assertTrue; |
| 23 | +import static org.onosproject.net.driver.DefaultDriverDataTest.DEVICE_ID; | ||
| 23 | 24 | ||
| 24 | public class DefaultDriverTest { | 25 | public class DefaultDriverTest { |
| 25 | 26 | ||
| ... | @@ -45,10 +46,10 @@ public class DefaultDriverTest { | ... | @@ -45,10 +46,10 @@ public class DefaultDriverTest { |
| 45 | assertEquals("incorrect behaviour count", 0, ddc.behaviours().size()); | 46 | assertEquals("incorrect behaviour count", 0, ddc.behaviours().size()); |
| 46 | assertTrue("incorrect behaviour", ddc.hasBehaviour(TestBehaviour.class)); | 47 | assertTrue("incorrect behaviour", ddc.hasBehaviour(TestBehaviour.class)); |
| 47 | 48 | ||
| 48 | - Behaviour b1 = ddc.createBehaviour(new DefaultDriverData(ddc), TestBehaviour.class); | 49 | + Behaviour b1 = ddc.createBehaviour(new DefaultDriverData(ddc, DEVICE_ID), TestBehaviour.class); |
| 49 | assertTrue("incorrect behaviour class", b1 instanceof TestBehaviourImpl); | 50 | assertTrue("incorrect behaviour class", b1 instanceof TestBehaviourImpl); |
| 50 | 51 | ||
| 51 | - Behaviour b2 = ddc.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(ddc)), | 52 | + Behaviour b2 = ddc.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(ddc, DEVICE_ID)), |
| 52 | TestBehaviourTwo.class); | 53 | TestBehaviourTwo.class); |
| 53 | assertTrue("incorrect behaviour class", b2 instanceof TestBehaviourTwoImpl); | 54 | assertTrue("incorrect behaviour class", b2 instanceof TestBehaviourTwoImpl); |
| 54 | 55 | ... | ... |
| ... | @@ -23,6 +23,7 @@ import java.util.Iterator; | ... | @@ -23,6 +23,7 @@ import java.util.Iterator; |
| 23 | 23 | ||
| 24 | import static org.junit.Assert.assertEquals; | 24 | import static org.junit.Assert.assertEquals; |
| 25 | import static org.junit.Assert.assertTrue; | 25 | import static org.junit.Assert.assertTrue; |
| 26 | +import static org.onosproject.net.driver.DefaultDriverDataTest.DEVICE_ID; | ||
| 26 | 27 | ||
| 27 | /** | 28 | /** |
| 28 | * Tests of the XML driver loader implementation. | 29 | * Tests of the XML driver loader implementation. |
| ... | @@ -73,7 +74,7 @@ public class XmlDriverLoaderTest { | ... | @@ -73,7 +74,7 @@ public class XmlDriverLoaderTest { |
| 73 | InputStream stream = getClass().getResourceAsStream("drivers.noconstructor.xml"); | 74 | InputStream stream = getClass().getResourceAsStream("drivers.noconstructor.xml"); |
| 74 | DriverProvider provider = loader.loadDrivers(stream, null); | 75 | DriverProvider provider = loader.loadDrivers(stream, null); |
| 75 | Driver driver = provider.getDrivers().iterator().next(); | 76 | Driver driver = provider.getDrivers().iterator().next(); |
| 76 | - driver.createBehaviour(new DefaultDriverData(driver), TestBehaviour.class); | 77 | + driver.createBehaviour(new DefaultDriverData(driver, DEVICE_ID), TestBehaviour.class); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | } | 80 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -177,7 +177,7 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS | ... | @@ -177,7 +177,7 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS |
| 177 | checkPermission(Permission.DRIVER_WRITE); | 177 | checkPermission(Permission.DRIVER_WRITE); |
| 178 | 178 | ||
| 179 | Driver driver = getDriver(deviceId); | 179 | Driver driver = getDriver(deviceId); |
| 180 | - return new DefaultDriverHandler(new DefaultDriverData(driver)); | 180 | + return new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | // Produces a composite driver key using the specified components. | 183 | // Produces a composite driver key using the specified components. | ... | ... |
| ... | @@ -43,7 +43,7 @@ | ... | @@ -43,7 +43,7 @@ |
| 43 | <groupId>org.apache.felix</groupId> | 43 | <groupId>org.apache.felix</groupId> |
| 44 | <artifactId>org.apache.felix.scr.annotations</artifactId> | 44 | <artifactId>org.apache.felix.scr.annotations</artifactId> |
| 45 | </dependency> | 45 | </dependency> |
| 46 | - <dependency> | 46 | + <dependency> |
| 47 | <groupId>org.osgi</groupId> | 47 | <groupId>org.osgi</groupId> |
| 48 | <artifactId>org.osgi.compendium</artifactId> | 48 | <artifactId>org.osgi.compendium</artifactId> |
| 49 | </dependency> | 49 | </dependency> | ... | ... |
| ... | @@ -43,6 +43,8 @@ import java.util.Map; | ... | @@ -43,6 +43,8 @@ import java.util.Map; |
| 43 | import java.util.concurrent.Executors; | 43 | import java.util.concurrent.Executors; |
| 44 | 44 | ||
| 45 | import static org.onlab.util.Tools.groupedThreads; | 45 | import static org.onlab.util.Tools.groupedThreads; |
| 46 | +import static org.onosproject.net.DeviceId.deviceId; | ||
| 47 | +import static org.onosproject.openflow.controller.Dpid.uri; | ||
| 46 | 48 | ||
| 47 | 49 | ||
| 48 | /** | 50 | /** |
| ... | @@ -208,9 +210,12 @@ public class Controller { | ... | @@ -208,9 +210,12 @@ public class Controller { |
| 208 | .getDriver(desc.getMfrDesc(), desc.getHwDesc(), desc.getSwDesc()); | 210 | .getDriver(desc.getMfrDesc(), desc.getHwDesc(), desc.getSwDesc()); |
| 209 | 211 | ||
| 210 | if (driver != null && driver.hasBehaviour(OpenFlowSwitchDriver.class)) { | 212 | if (driver != null && driver.hasBehaviour(OpenFlowSwitchDriver.class)) { |
| 211 | - OpenFlowSwitchDriver ofSwitchDriver = driver.createBehaviour(new DefaultDriverHandler( | 213 | + Dpid did = new Dpid(dpid); |
| 212 | - new DefaultDriverData(driver)), OpenFlowSwitchDriver.class); | 214 | + DefaultDriverHandler handler = |
| 213 | - ofSwitchDriver.init(new Dpid(dpid), desc, ofv); | 215 | + new DefaultDriverHandler(new DefaultDriverData(driver, deviceId(uri(did)))); |
| 216 | + OpenFlowSwitchDriver ofSwitchDriver = | ||
| 217 | + driver.createBehaviour(handler, OpenFlowSwitchDriver.class); | ||
| 218 | + ofSwitchDriver.init(did, desc, ofv); | ||
| 214 | ofSwitchDriver.setAgent(agent); | 219 | ofSwitchDriver.setAgent(agent); |
| 215 | ofSwitchDriver.setRoleHandler(new RoleManager(ofSwitchDriver)); | 220 | ofSwitchDriver.setRoleHandler(new RoleManager(ofSwitchDriver)); |
| 216 | log.info("OpenFlow handshaker found for device {}: {}", dpid, ofSwitchDriver); | 221 | log.info("OpenFlow handshaker found for device {}: {}", dpid, ofSwitchDriver); | ... | ... |
-
Please register or login to post a comment