Committed by
Gerrit Code Review
ONOS-3650 Device driver multiple inheritance
Change-Id: Ib7b72d44533d4e63c4122662b50485243562aa21
Showing
17 changed files
with
294 additions
and
26 deletions
| ... | @@ -16,8 +16,11 @@ | ... | @@ -16,8 +16,11 @@ |
| 16 | package org.onosproject.net.driver; | 16 | package org.onosproject.net.driver; |
| 17 | 17 | ||
| 18 | import com.google.common.collect.ImmutableMap; | 18 | import com.google.common.collect.ImmutableMap; |
| 19 | +import com.google.common.collect.Lists; | ||
| 19 | import com.google.common.collect.Maps; | 20 | import com.google.common.collect.Maps; |
| 21 | +import org.slf4j.Logger; | ||
| 20 | 22 | ||
| 23 | +import java.util.List; | ||
| 21 | import java.util.Map; | 24 | import java.util.Map; |
| 22 | import java.util.Objects; | 25 | import java.util.Objects; |
| 23 | import java.util.Set; | 26 | import java.util.Set; |
| ... | @@ -26,14 +29,17 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -26,14 +29,17 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | import static com.google.common.base.Preconditions.checkArgument; | 29 | import static com.google.common.base.Preconditions.checkArgument; |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; | 30 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | import static com.google.common.collect.ImmutableMap.copyOf; | 31 | import static com.google.common.collect.ImmutableMap.copyOf; |
| 32 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 29 | 33 | ||
| 30 | /** | 34 | /** |
| 31 | * Default implementation of extensible driver. | 35 | * Default implementation of extensible driver. |
| 32 | */ | 36 | */ |
| 33 | public class DefaultDriver implements Driver { | 37 | public class DefaultDriver implements Driver { |
| 34 | 38 | ||
| 39 | + private final Logger log = getLogger(getClass()); | ||
| 40 | + | ||
| 35 | private final String name; | 41 | private final String name; |
| 36 | - private final Driver parent; | 42 | + private final List<Driver> parents; |
| 37 | 43 | ||
| 38 | private final String manufacturer; | 44 | private final String manufacturer; |
| 39 | private final String hwVersion; | 45 | private final String hwVersion; |
| ... | @@ -53,12 +59,37 @@ public class DefaultDriver implements Driver { | ... | @@ -53,12 +59,37 @@ public class DefaultDriver implements Driver { |
| 53 | * @param behaviours device behaviour classes | 59 | * @param behaviours device behaviour classes |
| 54 | * @param properties properties for configuration of device behaviour classes | 60 | * @param properties properties for configuration of device behaviour classes |
| 55 | */ | 61 | */ |
| 62 | + @Deprecated | ||
| 56 | public DefaultDriver(String name, Driver parent, String manufacturer, | 63 | public DefaultDriver(String name, Driver parent, String manufacturer, |
| 57 | String hwVersion, String swVersion, | 64 | String hwVersion, String swVersion, |
| 58 | Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours, | 65 | Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours, |
| 59 | Map<String, String> properties) { | 66 | Map<String, String> properties) { |
| 60 | this.name = checkNotNull(name, "Name cannot be null"); | 67 | this.name = checkNotNull(name, "Name cannot be null"); |
| 61 | - this.parent = parent; | 68 | + this.parents = parent == null ? null : Lists.newArrayList(parent); |
| 69 | + this.manufacturer = checkNotNull(manufacturer, "Manufacturer cannot be null"); | ||
| 70 | + this.hwVersion = checkNotNull(hwVersion, "HW version cannot be null"); | ||
| 71 | + this.swVersion = checkNotNull(swVersion, "SW version cannot be null"); | ||
| 72 | + this.behaviours = copyOf(checkNotNull(behaviours, "Behaviours cannot be null")); | ||
| 73 | + this.properties = copyOf(checkNotNull(properties, "Properties cannot be null")); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * Creates a driver with the specified name. | ||
| 78 | + * | ||
| 79 | + * @param name driver name | ||
| 80 | + * @param parents optional parent drivers | ||
| 81 | + * @param manufacturer device manufacturer | ||
| 82 | + * @param hwVersion device hardware version | ||
| 83 | + * @param swVersion device software version | ||
| 84 | + * @param behaviours device behaviour classes | ||
| 85 | + * @param properties properties for configuration of device behaviour classes | ||
| 86 | + */ | ||
| 87 | + public DefaultDriver(String name, List<Driver> parents, String manufacturer, | ||
| 88 | + String hwVersion, String swVersion, | ||
| 89 | + Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours, | ||
| 90 | + Map<String, String> properties) { | ||
| 91 | + this.name = checkNotNull(name, "Name cannot be null"); | ||
| 92 | + this.parents = parents == null || parents.isEmpty() ? null : parents; | ||
| 62 | this.manufacturer = checkNotNull(manufacturer, "Manufacturer cannot be null"); | 93 | this.manufacturer = checkNotNull(manufacturer, "Manufacturer cannot be null"); |
| 63 | this.hwVersion = checkNotNull(hwVersion, "HW version cannot be null"); | 94 | this.hwVersion = checkNotNull(hwVersion, "HW version cannot be null"); |
| 64 | this.swVersion = checkNotNull(swVersion, "SW version cannot be null"); | 95 | this.swVersion = checkNotNull(swVersion, "SW version cannot be null"); |
| ... | @@ -68,7 +99,7 @@ public class DefaultDriver implements Driver { | ... | @@ -68,7 +99,7 @@ public class DefaultDriver implements Driver { |
| 68 | 99 | ||
| 69 | @Override | 100 | @Override |
| 70 | public Driver merge(Driver other) { | 101 | public Driver merge(Driver other) { |
| 71 | - checkArgument(parent == null || Objects.equals(parent, other.parent()), | 102 | + checkArgument(parents == null || Objects.equals(parent(), other.parent()), |
| 72 | "Parent drivers are not the same"); | 103 | "Parent drivers are not the same"); |
| 73 | 104 | ||
| 74 | // Merge the behaviours. | 105 | // Merge the behaviours. |
| ... | @@ -81,7 +112,8 @@ public class DefaultDriver implements Driver { | ... | @@ -81,7 +112,8 @@ public class DefaultDriver implements Driver { |
| 81 | ImmutableMap.Builder<String, String> properties = ImmutableMap.builder(); | 112 | ImmutableMap.Builder<String, String> properties = ImmutableMap.builder(); |
| 82 | properties.putAll(this.properties).putAll(other.properties()); | 113 | properties.putAll(this.properties).putAll(other.properties()); |
| 83 | 114 | ||
| 84 | - return new DefaultDriver(name, other.parent(), manufacturer, hwVersion, swVersion, | 115 | + return new DefaultDriver(name, other.parents(), |
| 116 | + manufacturer, hwVersion, swVersion, | ||
| 85 | ImmutableMap.copyOf(behaviours), properties.build()); | 117 | ImmutableMap.copyOf(behaviours), properties.build()); |
| 86 | } | 118 | } |
| 87 | 119 | ||
| ... | @@ -107,7 +139,12 @@ public class DefaultDriver implements Driver { | ... | @@ -107,7 +139,12 @@ public class DefaultDriver implements Driver { |
| 107 | 139 | ||
| 108 | @Override | 140 | @Override |
| 109 | public Driver parent() { | 141 | public Driver parent() { |
| 110 | - return parent; | 142 | + return parents == null ? null : parents.get(0); |
| 143 | + } | ||
| 144 | + | ||
| 145 | + @Override | ||
| 146 | + public List<Driver> parents() { | ||
| 147 | + return parents; | ||
| 111 | } | 148 | } |
| 112 | 149 | ||
| 113 | @Override | 150 | @Override |
| ... | @@ -123,7 +160,8 @@ public class DefaultDriver implements Driver { | ... | @@ -123,7 +160,8 @@ public class DefaultDriver implements Driver { |
| 123 | @Override | 160 | @Override |
| 124 | public boolean hasBehaviour(Class<? extends Behaviour> behaviourClass) { | 161 | public boolean hasBehaviour(Class<? extends Behaviour> behaviourClass) { |
| 125 | return behaviours.containsKey(behaviourClass) || | 162 | return behaviours.containsKey(behaviourClass) || |
| 126 | - (parent != null && parent.hasBehaviour(behaviourClass)); | 163 | + (parents != null && parents.stream() |
| 164 | + .filter(parent -> parent.hasBehaviour(behaviourClass)).count() > 0); | ||
| 127 | } | 165 | } |
| 128 | 166 | ||
| 129 | @Override | 167 | @Override |
| ... | @@ -132,8 +170,14 @@ public class DefaultDriver implements Driver { | ... | @@ -132,8 +170,14 @@ public class DefaultDriver implements Driver { |
| 132 | T behaviour = createBehaviour(data, null, behaviourClass); | 170 | T behaviour = createBehaviour(data, null, behaviourClass); |
| 133 | if (behaviour != null) { | 171 | if (behaviour != null) { |
| 134 | return behaviour; | 172 | return behaviour; |
| 135 | - } else if (parent != null) { | 173 | + } else if (parents != null) { |
| 136 | - return parent.createBehaviour(data, behaviourClass); | 174 | + for (Driver parent : Lists.reverse(parents)) { |
| 175 | + try { | ||
| 176 | + return parent.createBehaviour(data, behaviourClass); | ||
| 177 | + } catch (IllegalArgumentException e) { | ||
| 178 | + log.debug("Parent {} does not support behaviour {}", parent, behaviourClass); | ||
| 179 | + } | ||
| 180 | + } | ||
| 137 | } | 181 | } |
| 138 | throw new IllegalArgumentException(behaviourClass.getName() + " not supported"); | 182 | throw new IllegalArgumentException(behaviourClass.getName() + " not supported"); |
| 139 | } | 183 | } |
| ... | @@ -144,8 +188,14 @@ public class DefaultDriver implements Driver { | ... | @@ -144,8 +188,14 @@ public class DefaultDriver implements Driver { |
| 144 | T behaviour = createBehaviour(handler.data(), handler, behaviourClass); | 188 | T behaviour = createBehaviour(handler.data(), handler, behaviourClass); |
| 145 | if (behaviour != null) { | 189 | if (behaviour != null) { |
| 146 | return behaviour; | 190 | return behaviour; |
| 147 | - } else if (parent != null) { | 191 | + } else if (parents != null && !parents.isEmpty()) { |
| 148 | - return parent.createBehaviour(handler, behaviourClass); | 192 | + for (Driver parent : Lists.reverse(parents)) { |
| 193 | + try { | ||
| 194 | + return parent.createBehaviour(handler, behaviourClass); | ||
| 195 | + } catch (IllegalArgumentException e) { | ||
| 196 | + log.debug("Parent {} does not support behaviour {}", parent, behaviourClass); | ||
| 197 | + } | ||
| 198 | + } | ||
| 149 | } | 199 | } |
| 150 | throw new IllegalArgumentException(behaviourClass.getName() + " not supported"); | 200 | throw new IllegalArgumentException(behaviourClass.getName() + " not supported"); |
| 151 | } | 201 | } |
| ... | @@ -202,7 +252,7 @@ public class DefaultDriver implements Driver { | ... | @@ -202,7 +252,7 @@ public class DefaultDriver implements Driver { |
| 202 | public String toString() { | 252 | public String toString() { |
| 203 | return toStringHelper(this) | 253 | return toStringHelper(this) |
| 204 | .add("name", name) | 254 | .add("name", name) |
| 205 | - .add("parent", parent) | 255 | + .add("parents", parents) |
| 206 | .add("manufacturer", manufacturer) | 256 | .add("manufacturer", manufacturer) |
| 207 | .add("hwVersion", hwVersion) | 257 | .add("hwVersion", hwVersion) |
| 208 | .add("swVersion", swVersion) | 258 | .add("swVersion", swVersion) | ... | ... |
| ... | @@ -17,6 +17,7 @@ package org.onosproject.net.driver; | ... | @@ -17,6 +17,7 @@ package org.onosproject.net.driver; |
| 17 | 17 | ||
| 18 | import org.onosproject.net.Annotations; | 18 | import org.onosproject.net.Annotations; |
| 19 | 19 | ||
| 20 | +import java.util.List; | ||
| 20 | import java.util.Map; | 21 | import java.util.Map; |
| 21 | import java.util.Set; | 22 | import java.util.Set; |
| 22 | 23 | ||
| ... | @@ -40,9 +41,18 @@ public interface Driver extends Annotations { | ... | @@ -40,9 +41,18 @@ public interface Driver extends Annotations { |
| 40 | * | 41 | * |
| 41 | * @return parent driver; null if driver has no parent | 42 | * @return parent driver; null if driver has no parent |
| 42 | */ | 43 | */ |
| 44 | + @Deprecated | ||
| 43 | Driver parent(); | 45 | Driver parent(); |
| 44 | 46 | ||
| 45 | /** | 47 | /** |
| 48 | + * Returns all the parent drivers from which this driver inherits behaviours | ||
| 49 | + * and properties. | ||
| 50 | + * | ||
| 51 | + * @return list of parent drivers; null if driver has no parent | ||
| 52 | + */ | ||
| 53 | + List<Driver> parents(); | ||
| 54 | + | ||
| 55 | + /** | ||
| 46 | * Returns the device manufacturer name. | 56 | * Returns the device manufacturer name. |
| 47 | * | 57 | * |
| 48 | * @return manufacturer name | 58 | * @return manufacturer name | ... | ... |
| ... | @@ -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.ImmutableMap; | 18 | import com.google.common.collect.ImmutableMap; |
| 19 | +import com.google.common.collect.Lists; | ||
| 19 | import com.google.common.collect.Maps; | 20 | import com.google.common.collect.Maps; |
| 20 | import org.apache.commons.configuration.ConfigurationException; | 21 | import org.apache.commons.configuration.ConfigurationException; |
| 21 | import org.apache.commons.configuration.HierarchicalConfiguration; | 22 | import org.apache.commons.configuration.HierarchicalConfiguration; |
| ... | @@ -23,7 +24,10 @@ import org.apache.commons.configuration.XMLConfiguration; | ... | @@ -23,7 +24,10 @@ import org.apache.commons.configuration.XMLConfiguration; |
| 23 | 24 | ||
| 24 | import java.io.IOException; | 25 | import java.io.IOException; |
| 25 | import java.io.InputStream; | 26 | import java.io.InputStream; |
| 27 | +import java.util.Arrays; | ||
| 28 | +import java.util.List; | ||
| 26 | import java.util.Map; | 29 | import java.util.Map; |
| 30 | +import java.util.stream.Collectors; | ||
| 27 | 31 | ||
| 28 | /** | 32 | /** |
| 29 | * Utility capable of reading driver configuration XML resources and producing | 33 | * Utility capable of reading driver configuration XML resources and producing |
| ... | @@ -126,13 +130,22 @@ public class XmlDriverLoader { | ... | @@ -126,13 +130,22 @@ public class XmlDriverLoader { |
| 126 | public DefaultDriver loadDriver(HierarchicalConfiguration driverCfg, | 130 | public DefaultDriver loadDriver(HierarchicalConfiguration driverCfg, |
| 127 | DriverResolver resolver) { | 131 | DriverResolver resolver) { |
| 128 | String name = driverCfg.getString(NAME); | 132 | String name = driverCfg.getString(NAME); |
| 129 | - String parentName = driverCfg.getString(EXTENDS); | 133 | + String parentsString = driverCfg.getString(EXTENDS, ""); |
| 134 | + List<Driver> parents = Lists.newArrayList(); | ||
| 135 | + if (!parentsString.equals("")) { | ||
| 136 | + List<String> parentsNames; | ||
| 137 | + if (parentsString.contains(",")) { | ||
| 138 | + parentsNames = Arrays.asList(parentsString.replace(" ", "").split(",")); | ||
| 139 | + } else { | ||
| 140 | + parentsNames = Lists.newArrayList(parentsString); | ||
| 141 | + } | ||
| 142 | + parents = parentsNames.stream().map(parent -> (parent != null) ? | ||
| 143 | + resolve(parent, resolver) : null).collect(Collectors.toList()); | ||
| 144 | + } | ||
| 130 | String manufacturer = driverCfg.getString(MFG, ""); | 145 | String manufacturer = driverCfg.getString(MFG, ""); |
| 131 | String hwVersion = driverCfg.getString(HW, ""); | 146 | String hwVersion = driverCfg.getString(HW, ""); |
| 132 | String swVersion = driverCfg.getString(SW, ""); | 147 | String swVersion = driverCfg.getString(SW, ""); |
| 133 | - | 148 | + return new DefaultDriver(name, parents, manufacturer, hwVersion, swVersion, |
| 134 | - Driver parent = parentName != null ? resolve(parentName, resolver) : null; | ||
| 135 | - return new DefaultDriver(name, parent, manufacturer, hwVersion, swVersion, | ||
| 136 | parseBehaviours(driverCfg), | 149 | parseBehaviours(driverCfg), |
| 137 | parseProperties(driverCfg)); | 150 | parseProperties(driverCfg)); |
| 138 | } | 151 | } | ... | ... |
| ... | @@ -20,6 +20,8 @@ import org.junit.Before; | ... | @@ -20,6 +20,8 @@ import org.junit.Before; |
| 20 | import org.junit.Test; | 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.DeviceId; | 21 | import org.onosproject.net.DeviceId; |
| 22 | 22 | ||
| 23 | +import java.util.ArrayList; | ||
| 24 | + | ||
| 23 | import static org.junit.Assert.*; | 25 | import static org.junit.Assert.*; |
| 24 | import static org.onosproject.net.DeviceId.deviceId; | 26 | import static org.onosproject.net.DeviceId.deviceId; |
| 25 | 27 | ||
| ... | @@ -32,7 +34,7 @@ public class DefaultDriverDataTest { | ... | @@ -32,7 +34,7 @@ public class DefaultDriverDataTest { |
| 32 | 34 | ||
| 33 | @Before | 35 | @Before |
| 34 | public void setUp() { | 36 | public void setUp() { |
| 35 | - ddc = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a", | 37 | + ddc = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a", |
| 36 | ImmutableMap.of(TestBehaviour.class, | 38 | ImmutableMap.of(TestBehaviour.class, |
| 37 | TestBehaviourImpl.class), | 39 | TestBehaviourImpl.class), |
| 38 | ImmutableMap.of("foo", "bar")); | 40 | ImmutableMap.of("foo", "bar")); | ... | ... |
| ... | @@ -19,6 +19,8 @@ import com.google.common.collect.ImmutableMap; | ... | @@ -19,6 +19,8 @@ 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 | 21 | ||
| 22 | +import java.util.ArrayList; | ||
| 23 | + | ||
| 22 | import static org.junit.Assert.assertSame; | 24 | import static org.junit.Assert.assertSame; |
| 23 | import static org.junit.Assert.assertTrue; | 25 | import static org.junit.Assert.assertTrue; |
| 24 | 26 | ||
| ... | @@ -30,7 +32,7 @@ public class DefaultDriverHandlerTest { | ... | @@ -30,7 +32,7 @@ public class DefaultDriverHandlerTest { |
| 30 | 32 | ||
| 31 | @Before | 33 | @Before |
| 32 | public void setUp() { | 34 | public void setUp() { |
| 33 | - ddc = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a", | 35 | + ddc = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a", |
| 34 | ImmutableMap.of(TestBehaviour.class, | 36 | ImmutableMap.of(TestBehaviour.class, |
| 35 | TestBehaviourImpl.class, | 37 | TestBehaviourImpl.class, |
| 36 | TestBehaviourTwo.class, | 38 | TestBehaviourTwo.class, | ... | ... |
| ... | @@ -18,6 +18,7 @@ package org.onosproject.net.driver; | ... | @@ -18,6 +18,7 @@ package org.onosproject.net.driver; |
| 18 | import com.google.common.collect.ImmutableMap; | 18 | import com.google.common.collect.ImmutableMap; |
| 19 | import org.junit.Test; | 19 | import org.junit.Test; |
| 20 | 20 | ||
| 21 | +import java.util.ArrayList; | ||
| 21 | import java.util.Set; | 22 | import java.util.Set; |
| 22 | 23 | ||
| 23 | import static com.google.common.collect.ImmutableSet.of; | 24 | import static com.google.common.collect.ImmutableSet.of; |
| ... | @@ -28,15 +29,15 @@ public class DefaultDriverProviderTest { | ... | @@ -28,15 +29,15 @@ public class DefaultDriverProviderTest { |
| 28 | @Test | 29 | @Test |
| 29 | public void basics() { | 30 | public void basics() { |
| 30 | DefaultDriverProvider ddp = new DefaultDriverProvider(); | 31 | DefaultDriverProvider ddp = new DefaultDriverProvider(); |
| 31 | - DefaultDriver one = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a", | 32 | + DefaultDriver one = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a", |
| 32 | ImmutableMap.of(TestBehaviour.class, | 33 | ImmutableMap.of(TestBehaviour.class, |
| 33 | TestBehaviourImpl.class), | 34 | TestBehaviourImpl.class), |
| 34 | ImmutableMap.of("foo", "bar")); | 35 | ImmutableMap.of("foo", "bar")); |
| 35 | - DefaultDriver two = new DefaultDriver("foo.bar", null, "", "", "", | 36 | + DefaultDriver two = new DefaultDriver("foo.bar", new ArrayList<>(), "", "", "", |
| 36 | ImmutableMap.of(TestBehaviourTwo.class, | 37 | ImmutableMap.of(TestBehaviourTwo.class, |
| 37 | TestBehaviourTwoImpl.class), | 38 | TestBehaviourTwoImpl.class), |
| 38 | ImmutableMap.of("goo", "wee")); | 39 | ImmutableMap.of("goo", "wee")); |
| 39 | - DefaultDriver three = new DefaultDriver("goo.foo", null, "BigTop", "better", "2.2", | 40 | + DefaultDriver three = new DefaultDriver("goo.foo", new ArrayList<>(), "BigTop", "better", "2.2", |
| 40 | ImmutableMap.of(TestBehaviourTwo.class, | 41 | ImmutableMap.of(TestBehaviourTwo.class, |
| 41 | TestBehaviourTwoImpl.class), | 42 | TestBehaviourTwoImpl.class), |
| 42 | ImmutableMap.of("goo", "gee")); | 43 | ImmutableMap.of("goo", "gee")); | ... | ... |
| ... | @@ -18,6 +18,8 @@ package org.onosproject.net.driver; | ... | @@ -18,6 +18,8 @@ package org.onosproject.net.driver; |
| 18 | import com.google.common.collect.ImmutableMap; | 18 | import com.google.common.collect.ImmutableMap; |
| 19 | import org.junit.Test; | 19 | import org.junit.Test; |
| 20 | 20 | ||
| 21 | +import java.util.ArrayList; | ||
| 22 | + | ||
| 21 | import static org.junit.Assert.assertEquals; | 23 | import static org.junit.Assert.assertEquals; |
| 22 | import static org.junit.Assert.assertTrue; | 24 | import static org.junit.Assert.assertTrue; |
| 23 | import static org.onosproject.net.driver.DefaultDriverDataTest.DEVICE_ID; | 25 | import static org.onosproject.net.driver.DefaultDriverDataTest.DEVICE_ID; |
| ... | @@ -26,7 +28,7 @@ public class DefaultDriverTest { | ... | @@ -26,7 +28,7 @@ public class DefaultDriverTest { |
| 26 | 28 | ||
| 27 | @Test | 29 | @Test |
| 28 | public void basics() { | 30 | public void basics() { |
| 29 | - DefaultDriver ddp = new DefaultDriver("foo.base", null, "Circus", "lux", "1.2a", | 31 | + DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a", |
| 30 | ImmutableMap.of(TestBehaviour.class, | 32 | ImmutableMap.of(TestBehaviour.class, |
| 31 | TestBehaviourImpl.class, | 33 | TestBehaviourImpl.class, |
| 32 | TestBehaviourTwo.class, | 34 | TestBehaviourTwo.class, |
| ... | @@ -62,12 +64,12 @@ public class DefaultDriverTest { | ... | @@ -62,12 +64,12 @@ public class DefaultDriverTest { |
| 62 | 64 | ||
| 63 | @Test | 65 | @Test |
| 64 | public void merge() { | 66 | public void merge() { |
| 65 | - DefaultDriver one = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a", | 67 | + DefaultDriver one = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a", |
| 66 | ImmutableMap.of(TestBehaviour.class, | 68 | ImmutableMap.of(TestBehaviour.class, |
| 67 | TestBehaviourImpl.class), | 69 | TestBehaviourImpl.class), |
| 68 | ImmutableMap.of("foo", "bar")); | 70 | ImmutableMap.of("foo", "bar")); |
| 69 | Driver ddc = | 71 | Driver ddc = |
| 70 | - one.merge(new DefaultDriver("foo.bar", null, "", "", "", | 72 | + one.merge(new DefaultDriver("foo.bar", new ArrayList<>(), "", "", "", |
| 71 | ImmutableMap.of(TestBehaviourTwo.class, | 73 | ImmutableMap.of(TestBehaviourTwo.class, |
| 72 | TestBehaviourTwoImpl.class), | 74 | TestBehaviourTwoImpl.class), |
| 73 | ImmutableMap.of("goo", "wee"))); | 75 | ImmutableMap.of("goo", "wee"))); | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.net.driver; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Test behaviour. | ||
| 20 | + */ | ||
| 21 | +public class TestBehaviourImpl2 extends AbstractHandlerBehaviour implements TestBehaviour { | ||
| 22 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.net.driver; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Test behaviour. | ||
| 20 | + */ | ||
| 21 | +public interface TestBehaviourThree extends HandlerBehaviour { | ||
| 22 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.net.driver; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Test behaviour. | ||
| 20 | + */ | ||
| 21 | +public class TestBehaviourThreeImpl extends AbstractHandlerBehaviour implements TestBehaviourThree { | ||
| 22 | +} |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.net.driver; | 16 | package org.onosproject.net.driver; |
| 17 | 17 | ||
| 18 | import org.junit.Test; | 18 | import org.junit.Test; |
| 19 | +import org.onosproject.net.DeviceId; | ||
| 19 | 20 | ||
| 20 | import java.io.IOException; | 21 | import java.io.IOException; |
| 21 | import java.io.InputStream; | 22 | import java.io.InputStream; |
| ... | @@ -77,4 +78,38 @@ public class XmlDriverLoaderTest { | ... | @@ -77,4 +78,38 @@ public class XmlDriverLoaderTest { |
| 77 | driver.createBehaviour(new DefaultDriverData(driver, DEVICE_ID), TestBehaviour.class); | 78 | driver.createBehaviour(new DefaultDriverData(driver, DEVICE_ID), TestBehaviour.class); |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 81 | + @Test | ||
| 82 | + public void multipleDrivers() throws IOException { | ||
| 83 | + XmlDriverLoader loader = new XmlDriverLoader(getClass().getClassLoader()); | ||
| 84 | + InputStream stream = getClass().getResourceAsStream("drivers.multipleInheritance.xml"); | ||
| 85 | + DriverProvider provider = loader.loadDrivers(stream, null); | ||
| 86 | + Iterator<Driver> iterator = provider.getDrivers().iterator(); | ||
| 87 | + Driver driver; | ||
| 88 | + do { | ||
| 89 | + driver = iterator.next(); | ||
| 90 | + } while (!driver.name().equals("foo.2")); | ||
| 91 | + assertTrue("incorrect multiple behaviour inheritance", driver.hasBehaviour(TestBehaviour.class)); | ||
| 92 | + assertTrue("incorrect multiple behaviour inheritance", driver.hasBehaviour(TestBehaviourTwo.class)); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Test | ||
| 96 | + public void multipleDriversSameBehaviors() throws IOException { | ||
| 97 | + XmlDriverLoader loader = new XmlDriverLoader(getClass().getClassLoader()); | ||
| 98 | + InputStream stream = getClass().getResourceAsStream("drivers.sameMultipleInheritance.xml"); | ||
| 99 | + DriverProvider provider = loader.loadDrivers(stream, null); | ||
| 100 | + Iterator<Driver> iterator = provider.getDrivers().iterator(); | ||
| 101 | + Driver driver; | ||
| 102 | + do { | ||
| 103 | + driver = iterator.next(); | ||
| 104 | + } while (!driver.name().equals("foo.2")); | ||
| 105 | + assertTrue("incorrect multiple behaviour inheritance", driver.hasBehaviour(TestBehaviour.class)); | ||
| 106 | + Behaviour b2 = driver.createBehaviour(new DefaultDriverHandler( | ||
| 107 | + new DefaultDriverData( | ||
| 108 | + driver, DeviceId.deviceId("test_device"))), | ||
| 109 | + TestBehaviour.class); | ||
| 110 | + assertTrue("incorrect multiple same behaviour inheritance", b2.getClass() | ||
| 111 | + .getSimpleName().equals("TestBehaviourImpl2")); | ||
| 112 | + assertTrue("incorrect multiple behaviour inheritance", driver.hasBehaviour(TestBehaviourTwo.class)); | ||
| 113 | + } | ||
| 114 | + | ||
| 80 | } | 115 | } | ... | ... |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!-- | ||
| 3 | + ~ Copyright 2016 Open Networking Laboratory | ||
| 4 | + ~ | ||
| 5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | + ~ you may not use this file except in compliance with the License. | ||
| 7 | + ~ You may obtain a copy of the License at | ||
| 8 | + ~ | ||
| 9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + ~ | ||
| 11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
| 12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | + ~ See the License for the specific language governing permissions and | ||
| 15 | + ~ limitations under the License. | ||
| 16 | + --> | ||
| 17 | +<drivers> | ||
| 18 | + <driver name="foo.0" manufacturer="Circus" hwVersion="1.2" swVersion="2.0"> | ||
| 19 | + <behaviour api="org.onosproject.net.driver.TestBehaviour" | ||
| 20 | + impl="org.onosproject.net.driver.TestBehaviourImpl"/> | ||
| 21 | + </driver> | ||
| 22 | + | ||
| 23 | + <driver name="foo.1" extends="foo.0" manufacturer="Circus" hwVersion="1.2a" swVersion="2.2"> | ||
| 24 | + <fingerprint>ding</fingerprint> | ||
| 25 | + <fingerprint>bat</fingerprint> | ||
| 26 | + | ||
| 27 | + <behaviour api="org.onosproject.net.driver.TestBehaviourTwo" | ||
| 28 | + impl="org.onosproject.net.driver.TestBehaviourTwoImpl"/> | ||
| 29 | + | ||
| 30 | + <property name="p1">v1</property> | ||
| 31 | + <property name="p2">v2</property> | ||
| 32 | + </driver> | ||
| 33 | + | ||
| 34 | + <driver name="foo.2" extends="foo.0,foo.1" manufacturer="Circus" hwVersion="1.2" swVersion="2.0"> | ||
| 35 | + <behaviour api="org.onosproject.net.driver.TestBehaviourThree" | ||
| 36 | + impl="org.onosproject.net.driver.TestBehaviourThreeImpl"/> | ||
| 37 | + </driver> | ||
| 38 | +</drivers> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
core/api/src/test/resources/org/onosproject/net/driver/drivers.sameMultipleInheritance.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!-- | ||
| 3 | + ~ Copyright 2016 Open Networking Laboratory | ||
| 4 | + ~ | ||
| 5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | + ~ you may not use this file except in compliance with the License. | ||
| 7 | + ~ You may obtain a copy of the License at | ||
| 8 | + ~ | ||
| 9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + ~ | ||
| 11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
| 12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | + ~ See the License for the specific language governing permissions and | ||
| 15 | + ~ limitations under the License. | ||
| 16 | + --> | ||
| 17 | +<drivers> | ||
| 18 | + <driver name="foo.0" manufacturer="Circus" hwVersion="1.2" swVersion="2.0"> | ||
| 19 | + <behaviour api="org.onosproject.net.driver.TestBehaviour" | ||
| 20 | + impl="org.onosproject.net.driver.TestBehaviourImpl"/> | ||
| 21 | + </driver> | ||
| 22 | + | ||
| 23 | + <driver name="foo.1" extends="foo.0" manufacturer="Circus" hwVersion="1.2a" swVersion="2.2"> | ||
| 24 | + <fingerprint>ding</fingerprint> | ||
| 25 | + <fingerprint>bat</fingerprint> | ||
| 26 | + | ||
| 27 | + <behaviour api="org.onosproject.net.driver.TestBehaviour" | ||
| 28 | + impl="org.onosproject.net.driver.TestBehaviourImpl2"/> | ||
| 29 | + <behaviour api="org.onosproject.net.driver.TestBehaviourTwo" | ||
| 30 | + impl="org.onosproject.net.driver.TestBehaviourTwoImpl"/> | ||
| 31 | + | ||
| 32 | + <property name="p1">v1</property> | ||
| 33 | + <property name="p2">v2</property> | ||
| 34 | + </driver> | ||
| 35 | + | ||
| 36 | + <driver name="foo.2" extends="foo.0,foo.1" manufacturer="Circus" hwVersion="1.2" swVersion="2.0"> | ||
| 37 | + <behaviour api="org.onosproject.net.driver.TestBehaviourThree" | ||
| 38 | + impl="org.onosproject.net.driver.TestBehaviourThreeImpl"/> | ||
| 39 | + </driver> | ||
| 40 | +</drivers> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.codec.impl; | 16 | package org.onosproject.codec.impl; |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | +import java.util.ArrayList; | ||
| 19 | import java.util.Map; | 20 | import java.util.Map; |
| 20 | 21 | ||
| 21 | import org.junit.Test; | 22 | import org.junit.Test; |
| ... | @@ -48,7 +49,7 @@ public class DriverCodecTest { | ... | @@ -48,7 +49,7 @@ public class DriverCodecTest { |
| 48 | Map<String, String> properties = | 49 | Map<String, String> properties = |
| 49 | ImmutableMap.of("key1", "value1", "key2", "value2"); | 50 | ImmutableMap.of("key1", "value1", "key2", "value2"); |
| 50 | 51 | ||
| 51 | - DefaultDriver parent = new DefaultDriver("parent", null, "Acme", | 52 | + DefaultDriver parent = new DefaultDriver("parent", new ArrayList<>(), "Acme", |
| 52 | "HW1.2.3", "SW1.2.3", | 53 | "HW1.2.3", "SW1.2.3", |
| 53 | behaviours, | 54 | behaviours, |
| 54 | properties); | 55 | properties); | ... | ... |
| ... | @@ -46,7 +46,7 @@ | ... | @@ -46,7 +46,7 @@ |
| 46 | impl="org.onosproject.driver.query.FullMplsAvailable" /> | 46 | impl="org.onosproject.driver.query.FullMplsAvailable" /> |
| 47 | </driver> | 47 | </driver> |
| 48 | <!--This driver is for simulated NETCONF devices through of-config tool on top og OVSDB--> | 48 | <!--This driver is for simulated NETCONF devices through of-config tool on top og OVSDB--> |
| 49 | - <driver name="ovs-netconf" extends="default" | 49 | + <driver name="ovs-netconf" extends="default,ovs" |
| 50 | manufacturer="" hwVersion="" swVersion=""> | 50 | manufacturer="" hwVersion="" swVersion=""> |
| 51 | <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" | 51 | <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" |
| 52 | impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/> | 52 | impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/> | ... | ... |
| ... | @@ -28,6 +28,8 @@ import org.onosproject.net.driver.DefaultDriverHandler; | ... | @@ -28,6 +28,8 @@ import org.onosproject.net.driver.DefaultDriverHandler; |
| 28 | import org.onosproject.ovsdb.controller.driver.OvsdbClientServiceAdapter; | 28 | import org.onosproject.ovsdb.controller.driver.OvsdbClientServiceAdapter; |
| 29 | import org.onosproject.ovsdb.controller.driver.OvsdbControllerAdapter; | 29 | import org.onosproject.ovsdb.controller.driver.OvsdbControllerAdapter; |
| 30 | 30 | ||
| 31 | +import java.util.ArrayList; | ||
| 32 | + | ||
| 31 | /** | 33 | /** |
| 32 | * Created by Andrea on 10/7/15. | 34 | * Created by Andrea on 10/7/15. |
| 33 | */ | 35 | */ |
| ... | @@ -51,7 +53,7 @@ public class OvsdbControllerConfigTest { | ... | @@ -51,7 +53,7 @@ public class OvsdbControllerConfigTest { |
| 51 | public void setUp() { | 53 | public void setUp() { |
| 52 | controllerConfig = new OvsdbControllerConfig(); | 54 | controllerConfig = new OvsdbControllerConfig(); |
| 53 | 55 | ||
| 54 | - ddc = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a", | 56 | + ddc = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a", |
| 55 | ImmutableMap.of(ControllerConfig.class, | 57 | ImmutableMap.of(ControllerConfig.class, |
| 56 | OvsdbControllerConfig.class), | 58 | OvsdbControllerConfig.class), |
| 57 | ImmutableMap.of("foo", "bar")); | 59 | ImmutableMap.of("foo", "bar")); | ... | ... |
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.openflow; | 16 | package org.onosproject.openflow; |
| 17 | 17 | ||
| 18 | +import java.util.List; | ||
| 18 | import java.util.Map; | 19 | import java.util.Map; |
| 19 | import java.util.Set; | 20 | import java.util.Set; |
| 20 | 21 | ||
| ... | @@ -39,6 +40,11 @@ public class DriverAdapter implements Driver { | ... | @@ -39,6 +40,11 @@ public class DriverAdapter implements Driver { |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | @Override | 42 | @Override |
| 43 | + public List<Driver> parents() { | ||
| 44 | + return null; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 42 | public String manufacturer() { | 48 | public String manufacturer() { |
| 43 | return null; | 49 | return null; |
| 44 | } | 50 | } | ... | ... |
-
Please register or login to post a comment