Thomas Vachuska
Committed by Gerrit Code Review

Adding ability to project device, link and host model as alternate entities.

Change-Id: If23c018b024a3bbe693f0e66888c5f1707e3f66d
1 package org.onosproject.flowanalyzer; 1 package org.onosproject.flowanalyzer;
2 2
3 -import org.onosproject.net.PortNumber;
4 -import org.onosproject.net.link.LinkServiceAdapter;
5 -import org.onosproject.net.topology.TopologyEdge;
6 import org.onosproject.net.ConnectPoint; 3 import org.onosproject.net.ConnectPoint;
4 +import org.onosproject.net.DefaultLink;
7 import org.onosproject.net.DeviceId; 5 import org.onosproject.net.DeviceId;
8 import org.onosproject.net.ElementId; 6 import org.onosproject.net.ElementId;
9 import org.onosproject.net.HostId; 7 import org.onosproject.net.HostId;
10 import org.onosproject.net.Link; 8 import org.onosproject.net.Link;
11 -import org.onosproject.net.Annotations; 9 +import org.onosproject.net.PortNumber;
12 -import org.onosproject.net.provider.ProviderId; 10 +import org.onosproject.net.link.LinkServiceAdapter;
11 +import org.onosproject.net.topology.TopologyEdge;
13 import org.onosproject.net.topology.TopologyVertex; 12 import org.onosproject.net.topology.TopologyVertex;
14 13
15 -import java.util.Set;
16 import java.util.ArrayList; 14 import java.util.ArrayList;
17 -import java.util.List;
18 import java.util.HashSet; 15 import java.util.HashSet;
16 +import java.util.List;
17 +import java.util.Set;
19 18
20 import static org.onosproject.net.Link.State.ACTIVE; 19 import static org.onosproject.net.Link.State.ACTIVE;
21 20
22 -
23 /** 21 /**
24 - * Created by nikcheerla on 7/21/15. 22 + * Test fixture for the flow analyzer.
25 */ 23 */
26 public class MockLinkService extends LinkServiceAdapter { 24 public class MockLinkService extends LinkServiceAdapter {
27 DefaultMutableTopologyGraph createdGraph = new DefaultMutableTopologyGraph(new HashSet<>(), new HashSet<>()); 25 DefaultMutableTopologyGraph createdGraph = new DefaultMutableTopologyGraph(new HashSet<>(), new HashSet<>());
...@@ -47,7 +45,7 @@ public class MockLinkService extends LinkServiceAdapter { ...@@ -47,7 +45,7 @@ public class MockLinkService extends LinkServiceAdapter {
47 @Override 45 @Override
48 public Set<Link> getDeviceEgressLinks(DeviceId deviceId) { 46 public Set<Link> getDeviceEgressLinks(DeviceId deviceId) {
49 Set<Link> setL = new HashSet<>(); 47 Set<Link> setL = new HashSet<>();
50 - for (Link l: links) { 48 + for (Link l : links) {
51 if (l.src().elementId() instanceof DeviceId && l.src().deviceId().equals(deviceId)) { 49 if (l.src().elementId() instanceof DeviceId && l.src().deviceId().equals(deviceId)) {
52 setL.add(l); 50 setL.add(l);
53 } 51 }
...@@ -58,7 +56,7 @@ public class MockLinkService extends LinkServiceAdapter { ...@@ -58,7 +56,7 @@ public class MockLinkService extends LinkServiceAdapter {
58 @Override 56 @Override
59 public Set<Link> getDeviceIngressLinks(DeviceId deviceId) { 57 public Set<Link> getDeviceIngressLinks(DeviceId deviceId) {
60 Set<Link> setL = new HashSet<>(); 58 Set<Link> setL = new HashSet<>();
61 - for (Link l: links) { 59 + for (Link l : links) {
62 if (l.dst().elementId() instanceof DeviceId && l.dst().deviceId().equals(deviceId)) { 60 if (l.dst().elementId() instanceof DeviceId && l.dst().deviceId().equals(deviceId)) {
63 setL.add(l); 61 setL.add(l);
64 } 62 }
...@@ -70,7 +68,7 @@ public class MockLinkService extends LinkServiceAdapter { ...@@ -70,7 +68,7 @@ public class MockLinkService extends LinkServiceAdapter {
70 @Override 68 @Override
71 public Set<Link> getEgressLinks(ConnectPoint pt) { 69 public Set<Link> getEgressLinks(ConnectPoint pt) {
72 Set<Link> setL = new HashSet<>(); 70 Set<Link> setL = new HashSet<>();
73 - for (Link l: links) { 71 + for (Link l : links) {
74 if (l.src().equals(pt)) { 72 if (l.src().equals(pt)) {
75 setL.add(l); 73 setL.add(l);
76 } 74 }
...@@ -81,7 +79,7 @@ public class MockLinkService extends LinkServiceAdapter { ...@@ -81,7 +79,7 @@ public class MockLinkService extends LinkServiceAdapter {
81 @Override 79 @Override
82 public Set<Link> getIngressLinks(ConnectPoint pt) { 80 public Set<Link> getIngressLinks(ConnectPoint pt) {
83 Set<Link> setL = new HashSet<>(); 81 Set<Link> setL = new HashSet<>();
84 - for (Link l: links) { 82 + for (Link l : links) {
85 if (l.dst().equals(pt)) { 83 if (l.dst().equals(pt)) {
86 setL.add(l); 84 setL.add(l);
87 } 85 }
...@@ -92,7 +90,7 @@ public class MockLinkService extends LinkServiceAdapter { ...@@ -92,7 +90,7 @@ public class MockLinkService extends LinkServiceAdapter {
92 @Override 90 @Override
93 public Set<Link> getLinks(ConnectPoint pt) { 91 public Set<Link> getLinks(ConnectPoint pt) {
94 Set<Link> setL = new HashSet<>(); 92 Set<Link> setL = new HashSet<>();
95 - for (Link l: links) { 93 + for (Link l : links) {
96 if (l.src().equals(pt) || l.dst().equals(pt)) { 94 if (l.src().equals(pt) || l.dst().equals(pt)) {
97 setL.add(l); 95 setL.add(l);
98 } 96 }
...@@ -119,47 +117,7 @@ public class MockLinkService extends LinkServiceAdapter { ...@@ -119,47 +117,7 @@ public class MockLinkService extends LinkServiceAdapter {
119 ConnectPoint src = new ConnectPoint(d1, PortNumber.portNumber(port)); 117 ConnectPoint src = new ConnectPoint(d1, PortNumber.portNumber(port));
120 ConnectPoint dst = new ConnectPoint(d2, PortNumber.portNumber(port2)); 118 ConnectPoint dst = new ConnectPoint(d2, PortNumber.portNumber(port2));
121 Link curLink; 119 Link curLink;
122 - curLink = new Link() { 120 + curLink = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).build();
123 - @Override
124 - public ConnectPoint src() {
125 - return src;
126 - }
127 -
128 - @Override
129 - public ConnectPoint dst() {
130 - return dst;
131 - }
132 -
133 - @Override
134 - public boolean isDurable() {
135 - return true;
136 - }
137 -
138 - @Override
139 - public boolean isExpected() {
140 - return false;
141 - }
142 -
143 - @Override
144 - public Annotations annotations() {
145 - return null;
146 - }
147 -
148 - @Override
149 - public Type type() {
150 - return null;
151 - }
152 -
153 - @Override
154 - public ProviderId providerId() {
155 - return null;
156 - }
157 -
158 - @Override
159 - public State state() {
160 - return ACTIVE;
161 - }
162 - };
163 links.add(curLink); 121 links.add(curLink);
164 if (d1 instanceof DeviceId && d2 instanceof DeviceId) { 122 if (d1 instanceof DeviceId && d2 instanceof DeviceId) {
165 TopologyVertex v1 = () -> (DeviceId) d1, v2 = () -> (DeviceId) d2; 123 TopologyVertex v1 = () -> (DeviceId) d1, v2 = () -> (DeviceId) d2;
......
...@@ -20,7 +20,7 @@ import org.onosproject.net.provider.ProviderId; ...@@ -20,7 +20,7 @@ import org.onosproject.net.provider.ProviderId;
20 /** 20 /**
21 * Base implementation of network elements, i.e. devices or hosts. 21 * Base implementation of network elements, i.e. devices or hosts.
22 */ 22 */
23 -public abstract class AbstractElement extends AbstractModel implements Element { 23 +public abstract class AbstractElement extends AbstractProjectableModel implements Element {
24 24
25 protected final ElementId id; 25 protected final ElementId id;
26 26
......
1 +/*
2 + * Copyright 2014-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;
17 +
18 +import com.google.common.annotations.Beta;
19 +import org.onlab.util.ItemNotFoundException;
20 +import org.onosproject.net.driver.Behaviour;
21 +import org.onosproject.net.driver.Driver;
22 +import org.onosproject.net.driver.DriverData;
23 +import org.onosproject.net.driver.DriverService;
24 +import org.onosproject.net.driver.Projectable;
25 +import org.onosproject.net.provider.ProviderId;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
28 +
29 +import java.util.Set;
30 +
31 +import static com.google.common.base.Preconditions.checkState;
32 +
33 +/**
34 + * Base model entity, capable of being extended via projection mechanism.
35 + */
36 +@Beta
37 +public abstract class AbstractProjectableModel extends AbstractModel implements Projectable {
38 +
39 + private static Logger log = LoggerFactory.getLogger(AbstractProjectableModel.class);
40 +
41 + protected static final String NO_DRIVER_SERVICE = "Driver service not bound yet";
42 + protected static final String NO_DRIVER = "Driver has not been bound to %s";
43 +
44 + // Static reference to the driver service; injected via setDriverService
45 + private static DriverService driverService;
46 +
47 + private Driver driver;
48 +
49 + // For serialization
50 + public AbstractProjectableModel() {
51 + }
52 +
53 + /**
54 + * Creates a model entity attributed to the specified provider and
55 + * optionally annotated.
56 + *
57 + * @param providerId identity of the provider
58 + * @param annotations optional key/value annotations
59 + */
60 + public AbstractProjectableModel(ProviderId providerId, Annotations[] annotations) {
61 + super(providerId, annotations);
62 + }
63 +
64 + /**
65 + * Injects the driver service reference for use during projections into
66 + * various behaviours.
67 + * <p>
68 + * This is a privileged call; unauthorized invocations will result in
69 + * illegal state exception
70 + *
71 + * @param key opaque admin key object
72 + * @param driverService injected driver service
73 + * @throws IllegalStateException when invoked sans authorization
74 + */
75 + public static void setDriverService(Object key, DriverService driverService) {
76 + // TODO: Rework this once we have means to enforce access to admin services in general
77 + checkState(AbstractProjectableModel.driverService == key, "Unauthorized invocation");
78 + AbstractProjectableModel.driverService = driverService;
79 + }
80 +
81 + /**
82 + * Returns the currently bound driver service reference.
83 + *
84 + * @return driver service
85 + */
86 + protected static DriverService driverService() {
87 + return driverService;
88 + }
89 +
90 + /**
91 + * Returns the currently bound driver or null of no driver is bound.
92 + *
93 + * @return bound driver; null if none
94 + */
95 + protected Driver driver() {
96 + return driver;
97 + }
98 +
99 + @Override
100 + public <B extends Behaviour> B as(Class<B> projectionClass) {
101 + checkState(driverService != null, NO_DRIVER_SERVICE);
102 + if (driver == null) {
103 + driver = locateDriver();
104 + }
105 + checkState(driver != null, NO_DRIVER, this);
106 + return driver.createBehaviour(asData(), projectionClass);
107 + }
108 +
109 + @Override
110 + public <B extends Behaviour> boolean is(Class<B> projectionClass) {
111 + checkState(driverService != null, NO_DRIVER_SERVICE);
112 + if (driver == null) {
113 + driver = locateDriver();
114 + }
115 + checkState(driver != null, "Driver has not been bound to %s", this);
116 + return driver.hasBehaviour(projectionClass);
117 + }
118 +
119 + /**
120 + * Locates the driver to be used by this entity.
121 + * <p>
122 + * The default implementation derives the driver based on the {@code driver}
123 + * annotation value.
124 + *
125 + * @return driver for alternate projections of this model entity or null
126 + * if no driver is expected or driver is not found
127 + */
128 + protected Driver locateDriver() {
129 + String driverName = annotations().value(AnnotationKeys.DRIVER);
130 + if (driverName != null) {
131 + try {
132 + return driverService.getDriver(driverName);
133 + } catch (ItemNotFoundException e) {
134 + log.warn("Driver {} not found.", driverName);
135 + }
136 + }
137 + return null;
138 + }
139 +
140 + /**
141 + * Returns self as an immutable driver data instance.
142 + *
143 + * @return self as driver data
144 + */
145 + protected DriverData asData() {
146 + return new AnnotationDriverData();
147 + }
148 +
149 +
150 + /**
151 + * Projection of the parent entity as a driver data entity.
152 + */
153 + protected class AnnotationDriverData implements DriverData {
154 + @Override
155 + public Driver driver() {
156 + return driver;
157 + }
158 +
159 + @Override
160 + public DeviceId deviceId() {
161 + throw new UnsupportedOperationException("Entity not a device");
162 + }
163 +
164 + @Override
165 + public MutableAnnotations set(String key, String value) {
166 + throw new UnsupportedOperationException("Entity is immutable");
167 + }
168 +
169 + @Override
170 + public MutableAnnotations clear(String... keys) {
171 + throw new UnsupportedOperationException("Entity is immutable");
172 + }
173 +
174 + @Override
175 + public Set<String> keys() {
176 + return annotations().keys();
177 + }
178 +
179 + @Override
180 + public String value(String key) {
181 + return annotations().value(key);
182 + }
183 + }
184 +
185 +}
...@@ -15,12 +15,15 @@ ...@@ -15,12 +15,15 @@
15 */ 15 */
16 package org.onosproject.net; 16 package org.onosproject.net;
17 17
18 -import org.onosproject.net.provider.ProviderId;
19 import org.onlab.packet.ChassisId; 18 import org.onlab.packet.ChassisId;
19 +import org.onosproject.net.driver.Driver;
20 +import org.onosproject.net.driver.DriverData;
21 +import org.onosproject.net.provider.ProviderId;
20 22
21 import java.util.Objects; 23 import java.util.Objects;
22 24
23 import static com.google.common.base.MoreObjects.toStringHelper; 25 import static com.google.common.base.MoreObjects.toStringHelper;
26 +import static org.onlab.util.Tools.nullIsNotFound;
24 27
25 /** 28 /**
26 * Default infrastructure device model implementation. 29 * Default infrastructure device model implementation.
...@@ -105,6 +108,33 @@ public class DefaultDevice extends AbstractElement implements Device { ...@@ -105,6 +108,33 @@ public class DefaultDevice extends AbstractElement implements Device {
105 return chassisId; 108 return chassisId;
106 } 109 }
107 110
111 + /**
112 + * Returns self as an immutable driver data instance.
113 + *
114 + * @return self as driver data
115 + */
116 + protected DriverData asData() {
117 + return new DeviceDriverData();
118 + }
119 +
120 + @Override
121 + protected Driver locateDriver() {
122 + Driver driver = super.locateDriver();
123 + return driver != null ? driver :
124 + nullIsNotFound(driverService().getDriver(manufacturer, hwVersion, swVersion),
125 + "Driver not found");
126 + }
127 +
128 + /**
129 + * Projection of the parent entity as a driver data entity.
130 + */
131 + protected class DeviceDriverData extends AnnotationDriverData {
132 + @Override
133 + public DeviceId deviceId() {
134 + return id();
135 + }
136 + }
137 +
108 @Override 138 @Override
109 public int hashCode() { 139 public int hashCode() {
110 return Objects.hash(id, type, manufacturer, hwVersion, swVersion, serialNumber); 140 return Objects.hash(id, type, manufacturer, hwVersion, swVersion, serialNumber);
...@@ -136,6 +166,7 @@ public class DefaultDevice extends AbstractElement implements Device { ...@@ -136,6 +166,7 @@ public class DefaultDevice extends AbstractElement implements Device {
136 .add("hwVersion", hwVersion) 166 .add("hwVersion", hwVersion)
137 .add("swVersion", swVersion) 167 .add("swVersion", swVersion)
138 .add("serialNumber", serialNumber) 168 .add("serialNumber", serialNumber)
169 + .add("driver", driver() != null ? driver().name() : "")
139 .toString(); 170 .toString();
140 } 171 }
141 172
......
...@@ -24,11 +24,10 @@ import static org.onosproject.net.Link.State.ACTIVE; ...@@ -24,11 +24,10 @@ import static org.onosproject.net.Link.State.ACTIVE;
24 import static org.onosproject.net.DefaultAnnotations.EMPTY; 24 import static org.onosproject.net.DefaultAnnotations.EMPTY;
25 import static com.google.common.base.Preconditions.checkNotNull; 25 import static com.google.common.base.Preconditions.checkNotNull;
26 26
27 -
28 /** 27 /**
29 * Default infrastructure link model implementation. 28 * Default infrastructure link model implementation.
30 */ 29 */
31 -public class DefaultLink extends AbstractModel implements Link { 30 +public class DefaultLink extends AbstractProjectableModel implements Link {
32 31
33 private final ConnectPoint src; 32 private final ConnectPoint src;
34 private final ConnectPoint dst; 33 private final ConnectPoint dst;
...@@ -60,7 +59,7 @@ public class DefaultLink extends AbstractModel implements Link { ...@@ -60,7 +59,7 @@ public class DefaultLink extends AbstractModel implements Link {
60 * @param dst link destination 59 * @param dst link destination
61 * @param type link type 60 * @param type link type
62 * @param state link state 61 * @param state link state
63 - * @param isExpected indicates if the link is preconfigured 62 + * @param isExpected indicates if the link is preconfigured
64 * @param annotations optional key/value annotations 63 * @param annotations optional key/value annotations
65 */ 64 */
66 private DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, 65 private DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst,
......
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
15 */ 15 */
16 package org.onosproject.net; 16 package org.onosproject.net;
17 17
18 +import org.onosproject.net.driver.Projectable;
19 +
18 /** 20 /**
19 * Base abstraction of a network element, i.e. an infrastructure device or an end-station host. 21 * Base abstraction of a network element, i.e. an infrastructure device or an end-station host.
20 */ 22 */
21 -public interface Element extends Annotated, Provided { 23 +public interface Element extends Annotated, Provided, Projectable {
22 24
23 /** 25 /**
24 * Returns the network element identifier. 26 * Returns the network element identifier.
......
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
15 */ 15 */
16 package org.onosproject.net; 16 package org.onosproject.net;
17 17
18 +import org.onosproject.net.driver.Projectable;
19 +
18 /** 20 /**
19 * Abstraction of a network infrastructure link. 21 * Abstraction of a network infrastructure link.
20 */ 22 */
21 -public interface Link extends Annotated, Provided, NetworkResource { 23 +public interface Link extends Annotated, Provided, Projectable, NetworkResource {
22 24
23 /** 25 /**
24 * Coarse representation of the link type. 26 * Coarse representation of the link type.
......
...@@ -18,7 +18,7 @@ package org.onosproject.net.driver; ...@@ -18,7 +18,7 @@ package org.onosproject.net.driver;
18 import static com.google.common.base.Preconditions.checkState; 18 import static com.google.common.base.Preconditions.checkState;
19 19
20 /** 20 /**
21 - * Base implementation of device driver behaviour. 21 + * Base implementation of a driver behaviour.
22 */ 22 */
23 public class AbstractBehaviour implements Behaviour { 23 public class AbstractBehaviour implements Behaviour {
24 24
......
...@@ -18,7 +18,7 @@ package org.onosproject.net.driver; ...@@ -18,7 +18,7 @@ package org.onosproject.net.driver;
18 import static com.google.common.base.Preconditions.checkState; 18 import static com.google.common.base.Preconditions.checkState;
19 19
20 /** 20 /**
21 - * Base implementation of device driver handler behaviour. 21 + * Base implementation of a driver handler behaviour.
22 */ 22 */
23 public class AbstractHandlerBehaviour 23 public class AbstractHandlerBehaviour
24 extends AbstractBehaviour implements HandlerBehaviour { 24 extends AbstractBehaviour implements HandlerBehaviour {
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 package org.onosproject.net.driver; 16 package org.onosproject.net.driver;
17 17
18 /** 18 /**
19 - * Representation of a facet of device behaviour that can be used to talk about 19 + * Representation of a facet of behaviour that can be used to talk about
20 - * a device (in context of {@link DriverData}) or to a device (in context of 20 + * an entity (in context of {@link DriverData}) or to an entity (in context of
21 * {@link DriverHandler}). 21 * {@link DriverHandler}).
22 */ 22 */
23 public interface Behaviour { 23 public interface Behaviour {
......
...@@ -57,11 +57,6 @@ public class DefaultDriverData implements DriverData { ...@@ -57,11 +57,6 @@ public class DefaultDriverData implements DriverData {
57 } 57 }
58 58
59 @Override 59 @Override
60 - public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
61 - return driver.createBehaviour(this, behaviourClass);
62 - }
63 -
64 - @Override
65 public MutableAnnotations set(String key, String value) { 60 public MutableAnnotations set(String key, String value) {
66 properties.put(key, value); 61 properties.put(key, value);
67 return this; 62 return this;
......
...@@ -19,7 +19,7 @@ import org.onosproject.net.DeviceId; ...@@ -19,7 +19,7 @@ import org.onosproject.net.DeviceId;
19 import org.onosproject.net.MutableAnnotations; 19 import org.onosproject.net.MutableAnnotations;
20 20
21 /** 21 /**
22 - * Container for data about a device. Data is stored using 22 + * Container for data about an entity, e.g. device, link. Data is stored using
23 * {@link org.onosproject.net.MutableAnnotations}. 23 * {@link org.onosproject.net.MutableAnnotations}.
24 * 24 *
25 * Note that only derivatives of {@link HandlerBehaviour} can expect mutability 25 * Note that only derivatives of {@link HandlerBehaviour} can expect mutability
...@@ -45,10 +45,15 @@ public interface DriverData extends MutableAnnotations { ...@@ -45,10 +45,15 @@ public interface DriverData extends MutableAnnotations {
45 /** 45 /**
46 * Returns the specified facet of behaviour to access the device data. 46 * Returns the specified facet of behaviour to access the device data.
47 * 47 *
48 + * Implementations are expected to defer to the backing driver for creation
49 + * of the requested behaviour.
50 + *
48 * @param behaviourClass behaviour class 51 * @param behaviourClass behaviour class
49 * @param <T> type of behaviour 52 * @param <T> type of behaviour
50 * @return requested behaviour or null if not supported 53 * @return requested behaviour or null if not supported
51 */ 54 */
52 - <T extends Behaviour> T behaviour(Class<T> behaviourClass); 55 + default <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
56 + return driver().createBehaviour(this, behaviourClass);
57 + }
53 58
54 } 59 }
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 package org.onosproject.net.driver; 16 package org.onosproject.net.driver;
17 17
18 /** 18 /**
19 - * Representation of a facet of device behaviour that can be used to interact 19 + * Representation of a facet of behaviour that can be used to interact
20 - * with a device (in context of {@link org.onosproject.net.driver.DriverHandler}). 20 + * with an entity (in context of {@link org.onosproject.net.driver.DriverHandler}).
21 */ 21 */
22 public interface HandlerBehaviour extends Behaviour { 22 public interface HandlerBehaviour extends Behaviour {
23 23
......
...@@ -38,7 +38,7 @@ public interface Projectable { ...@@ -38,7 +38,7 @@ public interface Projectable {
38 * Returns true if this entity is capable of being projected as the 38 * Returns true if this entity is capable of being projected as the
39 * specified class. 39 * specified class.
40 * 40 *
41 - * @param projectionClass projection class 41 + * @param projectionClass requested projection class
42 * @param <B> type of behaviour 42 * @param <B> type of behaviour
43 * @return true if the requested projection is supported 43 * @return true if the requested projection is supported
44 */ 44 */
......
...@@ -16,21 +16,23 @@ ...@@ -16,21 +16,23 @@
16 16
17 /** 17 /**
18 * Set of facilities to allow the platform to be extended with 18 * Set of facilities to allow the platform to be extended with
19 - * device specific behaviours and to allow modeling device behaviours while 19 + * device specific behaviours and to allow modeling device (and other entity)
20 - * hiding details of specific device driver implementations. 20 + * behaviours while hiding details of specific driver implementations.
21 + * While primarily intended for devices, this subsystem can be used to abstract
22 + * behaviours of other entities as well.
21 * <p> 23 * <p>
22 * {@link org.onosproject.net.driver.Driver} is a representation of a 24 * {@link org.onosproject.net.driver.Driver} is a representation of a
23 - * specific family of devices supports set of 25 + * specific family of entities (devices, links, etc.) which supports set of
24 * {@link org.onosproject.net.driver.Behaviour behaviour classes}. Default 26 * {@link org.onosproject.net.driver.Behaviour behaviour classes}. Default
25 * implementation is provided by the platform and allows DriverProviders to 27 * implementation is provided by the platform and allows DriverProviders to
26 * add different behaviour implementations via DriverService. 28 * add different behaviour implementations via DriverService.
27 * </p> 29 * </p>
28 * <p> 30 * <p>
29 * {@link org.onosproject.net.driver.DriverData} is a container for data 31 * {@link org.onosproject.net.driver.DriverData} is a container for data
30 - * learned about a device. It is associated with a specific 32 + * learned about an entity. It is associated with a specific
31 * {@link org.onosproject.net.driver.Driver} 33 * {@link org.onosproject.net.driver.Driver}
32 * and provides set of {@link org.onosproject.net.driver.Behaviour behaviours} 34 * and provides set of {@link org.onosproject.net.driver.Behaviour behaviours}
33 - * for talking about a device. A default 35 + * for talking about an entity. A default
34 * implementation provided by platform and has mutable key/value store for use by 36 * implementation provided by platform and has mutable key/value store for use by
35 * implementations of {@link org.onosproject.net.driver.Behaviour behaviours}. 37 * implementations of {@link org.onosproject.net.driver.Behaviour behaviours}.
36 * </p> 38 * </p>
......
...@@ -22,6 +22,7 @@ import org.onosproject.net.DeviceId; ...@@ -22,6 +22,7 @@ import org.onosproject.net.DeviceId;
22 import org.onosproject.net.Link; 22 import org.onosproject.net.Link;
23 import org.onosproject.net.LinkKey; 23 import org.onosproject.net.LinkKey;
24 import org.onosproject.net.PortNumber; 24 import org.onosproject.net.PortNumber;
25 +import org.onosproject.net.driver.Behaviour;
25 import org.onosproject.net.provider.ProviderId; 26 import org.onosproject.net.provider.ProviderId;
26 27
27 /** 28 /**
...@@ -63,6 +64,16 @@ public abstract class BiLinkTestBase { ...@@ -63,6 +64,16 @@ public abstract class BiLinkTestBase {
63 @Override public ProviderId providerId() { 64 @Override public ProviderId providerId() {
64 return null; 65 return null;
65 } 66 }
67 +
68 + @Override
69 + public <B extends Behaviour> B as(Class<B> projectionClass) {
70 + return null;
71 + }
72 +
73 + @Override
74 + public <B extends Behaviour> boolean is(Class<B> projectionClass) {
75 + return false;
76 + }
66 } 77 }
67 78
68 protected static final DeviceId DEV_A_ID = DeviceId.deviceId("device-A"); 79 protected static final DeviceId DEV_A_ID = DeviceId.deviceId("device-A");
......
...@@ -19,24 +19,18 @@ package org.onosproject.ui.topo; ...@@ -19,24 +19,18 @@ package org.onosproject.ui.topo;
19 import com.fasterxml.jackson.databind.ObjectMapper; 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import com.fasterxml.jackson.databind.node.ArrayNode; 20 import com.fasterxml.jackson.databind.node.ArrayNode;
21 import com.fasterxml.jackson.databind.node.ObjectNode; 21 import com.fasterxml.jackson.databind.node.ObjectNode;
22 +import com.google.common.collect.ImmutableSet;
22 import org.junit.Test; 23 import org.junit.Test;
23 -import org.onlab.packet.ChassisId; 24 +import org.onosproject.net.DefaultDevice;
24 -import org.onlab.packet.IpAddress; 25 +import org.onosproject.net.DefaultHost;
25 -import org.onlab.packet.MacAddress;
26 -import org.onlab.packet.VlanId;
27 -import org.onosproject.net.Annotations;
28 import org.onosproject.net.Device; 26 import org.onosproject.net.Device;
29 import org.onosproject.net.DeviceId; 27 import org.onosproject.net.DeviceId;
30 import org.onosproject.net.Host; 28 import org.onosproject.net.Host;
31 import org.onosproject.net.HostId; 29 import org.onosproject.net.HostId;
32 -import org.onosproject.net.HostLocation;
33 import org.onosproject.net.device.DeviceService; 30 import org.onosproject.net.device.DeviceService;
34 import org.onosproject.net.device.DeviceServiceAdapter; 31 import org.onosproject.net.device.DeviceServiceAdapter;
35 import org.onosproject.net.host.HostService; 32 import org.onosproject.net.host.HostService;
36 import org.onosproject.net.host.HostServiceAdapter; 33 import org.onosproject.net.host.HostServiceAdapter;
37 -import org.onosproject.net.provider.ProviderId;
38 -
39 -import java.util.Set;
40 34
41 import static org.junit.Assert.*; 35 import static org.junit.Assert.*;
42 36
...@@ -45,106 +39,18 @@ import static org.junit.Assert.*; ...@@ -45,106 +39,18 @@ import static org.junit.Assert.*;
45 */ 39 */
46 public class NodeSelectionTest { 40 public class NodeSelectionTest {
47 41
48 - private static class FakeDevice implements Device { 42 + private static class FakeDevice extends DefaultDevice {
49 -
50 - private final DeviceId id;
51 -
52 FakeDevice(DeviceId id) { 43 FakeDevice(DeviceId id) {
53 - this.id = id; 44 + super(null, id, null, null, null, null, null, null);
54 - }
55 -
56 - @Override
57 - public DeviceId id() {
58 - return id;
59 - }
60 -
61 - @Override
62 - public Type type() {
63 - return null;
64 - }
65 -
66 - @Override
67 - public String manufacturer() {
68 - return null;
69 - }
70 -
71 - @Override
72 - public String hwVersion() {
73 - return null;
74 - }
75 -
76 - @Override
77 - public String swVersion() {
78 - return null;
79 - }
80 -
81 - @Override
82 - public String serialNumber() {
83 - return null;
84 - }
85 -
86 - @Override
87 - public ChassisId chassisId() {
88 - return null;
89 - }
90 -
91 - @Override
92 - public Annotations annotations() {
93 - return null;
94 - }
95 -
96 - @Override
97 - public ProviderId providerId() {
98 - return null;
99 } 45 }
100 } 46 }
101 47
102 - private static class FakeHost implements Host { 48 + private static class FakeHost extends DefaultHost {
103 -
104 - private final HostId id;
105 -
106 FakeHost(HostId id) { 49 FakeHost(HostId id) {
107 - this.id = id; 50 + super(null, id, null, null, null, ImmutableSet.of());
108 - }
109 -
110 - @Override
111 - public HostId id() {
112 - return id;
113 - }
114 -
115 - @Override
116 - public MacAddress mac() {
117 - return null;
118 - }
119 -
120 - @Override
121 - public VlanId vlan() {
122 - return null;
123 - }
124 -
125 - @Override
126 - public Set<IpAddress> ipAddresses() {
127 - return null;
128 - }
129 -
130 - @Override
131 - public HostLocation location() {
132 - return null;
133 - }
134 -
135 - @Override
136 - public Annotations annotations() {
137 - return null;
138 - }
139 -
140 - @Override
141 - public ProviderId providerId() {
142 - return null;
143 } 51 }
144 } 52 }
145 53
146 -
147 -
148 private final ObjectMapper mapper = new ObjectMapper(); 54 private final ObjectMapper mapper = new ObjectMapper();
149 55
150 private static final String IDS = "ids"; 56 private static final String IDS = "ids";
......
...@@ -21,6 +21,7 @@ import org.onlab.packet.ChassisId; ...@@ -21,6 +21,7 @@ import org.onlab.packet.ChassisId;
21 import org.onosproject.codec.CodecContext; 21 import org.onosproject.codec.CodecContext;
22 import org.onosproject.net.Annotations; 22 import org.onosproject.net.Annotations;
23 import org.onosproject.net.DefaultAnnotations; 23 import org.onosproject.net.DefaultAnnotations;
24 +import org.onosproject.net.DefaultDevice;
24 import org.onosproject.net.DefaultPort; 25 import org.onosproject.net.DefaultPort;
25 import org.onosproject.net.Device; 26 import org.onosproject.net.Device;
26 import org.onosproject.net.DeviceId; 27 import org.onosproject.net.DeviceId;
...@@ -99,62 +100,16 @@ public final class PortCodec extends AnnotatedCodec<Port> { ...@@ -99,62 +100,16 @@ public final class PortCodec extends AnnotatedCodec<Port> {
99 /** 100 /**
100 * Dummy Device which only holds DeviceId. 101 * Dummy Device which only holds DeviceId.
101 */ 102 */
102 - private static final class DummyDevice implements Device { 103 + private static final class DummyDevice extends DefaultDevice {
103 -
104 - private final DeviceId did;
105 -
106 /** 104 /**
107 * Constructs Dummy Device which only holds DeviceId. 105 * Constructs Dummy Device which only holds DeviceId.
108 * 106 *
109 * @param did device Id 107 * @param did device Id
110 */ 108 */
111 public DummyDevice(DeviceId did) { 109 public DummyDevice(DeviceId did) {
112 - this.did = did; 110 + super(new ProviderId(did.uri().getScheme(), "PortCodec"), did,
113 - } 111 + Type.SWITCH, "dummy", "0", "0", "0", new ChassisId(),
114 - 112 + DefaultAnnotations.EMPTY);
115 - @Override
116 - public Annotations annotations() {
117 - return DefaultAnnotations.EMPTY;
118 - }
119 -
120 - @Override
121 - public ProviderId providerId() {
122 - return new ProviderId(did.uri().getScheme(), "PortCodec");
123 - }
124 -
125 - @Override
126 - public DeviceId id() {
127 - return did;
128 - }
129 -
130 - @Override
131 - public Type type() {
132 - return Type.SWITCH;
133 - }
134 -
135 - @Override
136 - public String manufacturer() {
137 - return "dummy";
138 - }
139 -
140 - @Override
141 - public String hwVersion() {
142 - return "0";
143 - }
144 -
145 - @Override
146 - public String swVersion() {
147 - return "0";
148 - }
149 -
150 - @Override
151 - public String serialNumber() {
152 - return "0";
153 - }
154 -
155 - @Override
156 - public ChassisId chassisId() {
157 - return new ChassisId();
158 } 113 }
159 } 114 }
160 } 115 }
......
...@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 25 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 import org.apache.felix.scr.annotations.Service; 26 import org.apache.felix.scr.annotations.Service;
27 import org.onlab.util.ItemNotFoundException; 27 import org.onlab.util.ItemNotFoundException;
28 +import org.onosproject.net.AbstractProjectableModel;
28 import org.onosproject.net.Device; 29 import org.onosproject.net.Device;
29 import org.onosproject.net.DeviceId; 30 import org.onosproject.net.DeviceId;
30 import org.onosproject.net.device.DeviceService; 31 import org.onosproject.net.device.DeviceService;
...@@ -72,15 +73,16 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS ...@@ -72,15 +73,16 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS
72 73
73 @Activate 74 @Activate
74 protected void activate() { 75 protected void activate() {
76 + AbstractProjectableModel.setDriverService(null, this);
75 log.info("Started"); 77 log.info("Started");
76 } 78 }
77 79
78 @Deactivate 80 @Deactivate
79 protected void deactivate() { 81 protected void deactivate() {
82 + AbstractProjectableModel.setDriverService(this, null);
80 log.info("Stopped"); 83 log.info("Stopped");
81 } 84 }
82 85
83 -
84 @Override 86 @Override
85 public Set<DriverProvider> getProviders() { 87 public Set<DriverProvider> getProviders() {
86 return ImmutableSet.copyOf(providers); 88 return ImmutableSet.copyOf(providers);
......