tom

Enhanced DeviceDescription and added default implementation for it.

1 package org.onlab.onos.net; 1 package org.onlab.onos.net;
2 2
3 -import org.onlab.onos.net.provider.Provided;
4 -
5 /** 3 /**
6 * Base abstraction of a network element, i.e. an infrastructure device or an end-station host. 4 * Base abstraction of a network element, i.e. an infrastructure device or an end-station host.
7 */ 5 */
......
1 package org.onlab.onos.net; 1 package org.onlab.onos.net;
2 2
3 -import org.onlab.onos.net.provider.Provided;
4 -
5 /** 3 /**
6 * Abstraction of a network infrastructure link. 4 * Abstraction of a network infrastructure link.
7 */ 5 */
......
1 -package org.onlab.onos.net.provider; 1 +package org.onlab.onos.net;
2 +
3 +import org.onlab.onos.net.provider.ProviderId;
2 4
3 /** 5 /**
4 * Abstraction of an entity supplied by a provider. 6 * Abstraction of an entity supplied by a provider.
......
...@@ -3,7 +3,7 @@ package org.onlab.onos.net; ...@@ -3,7 +3,7 @@ package org.onlab.onos.net;
3 /** 3 /**
4 * Represents a network topology computation snapshot. 4 * Represents a network topology computation snapshot.
5 */ 5 */
6 -public interface Topology { 6 +public interface Topology extends Provided {
7 7
8 /** 8 /**
9 * Returns the time, specified in milliseconds since start of epoch, 9 * Returns the time, specified in milliseconds since start of epoch,
......
1 +package org.onlab.onos.net.device;
2 +
3 +import java.net.URI;
4 +
5 +import static com.google.common.base.Objects.toStringHelper;
6 +import static com.google.common.base.Preconditions.checkNotNull;
7 +import static org.onlab.onos.net.Device.Type;
8 +
9 +/**
10 + * Default implementation of immutable device description entity.
11 + */
12 +public class DefaultDeviceDescription implements DeviceDescription {
13 + private final URI uri;
14 + private final Type type;
15 + private final String manufacturer;
16 + private final String hwVersion;
17 + private final String swVersion;
18 + private final String serialNumber;
19 +
20 + /**
21 + * Creates a device description using the supplied information.
22 + *
23 + * @param uri device URI
24 + * @param type device type
25 + * @param manufacturer device manufacturer
26 + * @param hwVersion device HW version
27 + * @param swVersion device SW version
28 + * @param serialNumber device serial number
29 + */
30 + public DefaultDeviceDescription(URI uri, Type type, String manufacturer,
31 + String hwVersion, String swVersion,
32 + String serialNumber) {
33 + this.uri = checkNotNull(uri, "Device URI cannot be null");
34 + this.type = checkNotNull(type, "Device type cannot be null");
35 + this.manufacturer = manufacturer;
36 + this.hwVersion = hwVersion;
37 + this.swVersion = swVersion;
38 + this.serialNumber = serialNumber;
39 + }
40 +
41 + @Override
42 + public URI deviceURI() {
43 + return uri;
44 + }
45 +
46 + @Override
47 + public Type type() {
48 + return type;
49 + }
50 +
51 + @Override
52 + public String manufacturer() {
53 + return manufacturer;
54 + }
55 +
56 + @Override
57 + public String hwVersion() {
58 + return hwVersion;
59 + }
60 +
61 + @Override
62 + public String swVersion() {
63 + return swVersion;
64 + }
65 +
66 + @Override
67 + public String serialNumber() {
68 + return serialNumber;
69 + }
70 +
71 + @Override
72 + public String toString() {
73 + return toStringHelper(this)
74 + .add("uri", uri).add("type", type).add("mfr", manufacturer)
75 + .add("hw", hwVersion).add("sw", swVersion)
76 + .add("serial", serialNumber)
77 + .toString();
78 + }
79 +
80 +}
1 +package org.onlab.onos.net.device;
2 +
3 +/**
4 + * Default implementation of immutable port description.
5 + */
6 +public class DefaultPortDescription implements PortDescription {
7 +}
1 package org.onlab.onos.net.device; 1 package org.onlab.onos.net.device;
2 2
3 import org.onlab.onos.net.Description; 3 import org.onlab.onos.net.Description;
4 +import org.onlab.onos.net.Device;
4 5
5 import java.net.URI; 6 import java.net.URI;
6 7
...@@ -18,4 +19,39 @@ public interface DeviceDescription extends Description { ...@@ -18,4 +19,39 @@ public interface DeviceDescription extends Description {
18 */ 19 */
19 URI deviceURI(); 20 URI deviceURI();
20 21
22 + /**
23 + * Returns the type of the infrastructure device.
24 + *
25 + * @return type of the device
26 + */
27 + Device.Type type();
28 +
29 + /**
30 + * Returns the device manufacturer name.
31 + *
32 + * @return manufacturer name
33 + */
34 + String manufacturer();
35 +
36 + /**
37 + * Returns the device hardware version.
38 + *
39 + * @return hardware version
40 + */
41 + String hwVersion();
42 +
43 + /**
44 + * Returns the device software version.
45 + *
46 + * @return software version
47 + */
48 + String swVersion();
49 +
50 + /**
51 + * Returns the device serial number.
52 + *
53 + * @return serial number
54 + */
55 + String serialNumber();
56 +
21 } 57 }
......
1 package org.onlab.onos.provider.of.device.impl; 1 package org.onlab.onos.provider.of.device.impl;
2 2
3 -import static org.slf4j.LoggerFactory.getLogger;
4 -
5 -import java.net.URI;
6 -import java.net.URISyntaxException;
7 -
8 import org.apache.felix.scr.annotations.Activate; 3 import org.apache.felix.scr.annotations.Activate;
9 import org.apache.felix.scr.annotations.Component; 4 import org.apache.felix.scr.annotations.Component;
10 import org.apache.felix.scr.annotations.Deactivate; 5 import org.apache.felix.scr.annotations.Deactivate;
...@@ -13,6 +8,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -13,6 +8,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
13 import org.onlab.onos.net.Device; 8 import org.onlab.onos.net.Device;
14 import org.onlab.onos.net.DeviceId; 9 import org.onlab.onos.net.DeviceId;
15 import org.onlab.onos.net.MastershipRole; 10 import org.onlab.onos.net.MastershipRole;
11 +import org.onlab.onos.net.device.DefaultDeviceDescription;
16 import org.onlab.onos.net.device.DeviceDescription; 12 import org.onlab.onos.net.device.DeviceDescription;
17 import org.onlab.onos.net.device.DeviceProvider; 13 import org.onlab.onos.net.device.DeviceProvider;
18 import org.onlab.onos.net.device.DeviceProviderRegistry; 14 import org.onlab.onos.net.device.DeviceProviderRegistry;
...@@ -25,6 +21,11 @@ import org.onlab.onos.of.controller.OpenFlowSwitchListener; ...@@ -25,6 +21,11 @@ import org.onlab.onos.of.controller.OpenFlowSwitchListener;
25 import org.onlab.onos.of.controller.RoleState; 21 import org.onlab.onos.of.controller.RoleState;
26 import org.slf4j.Logger; 22 import org.slf4j.Logger;
27 23
24 +import java.net.URI;
25 +import java.net.URISyntaxException;
26 +
27 +import static org.slf4j.LoggerFactory.getLogger;
28 +
28 /** 29 /**
29 * Provider which uses an OpenFlow controller to detect network 30 * Provider which uses an OpenFlow controller to detect network
30 * infrastructure devices. 31 * infrastructure devices.
...@@ -90,17 +91,14 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -90,17 +91,14 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
90 } 91 }
91 92
92 private class InternalDeviceProvider implements OpenFlowSwitchListener { 93 private class InternalDeviceProvider implements OpenFlowSwitchListener {
93 -
94 @Override 94 @Override
95 - public void switchAdded(final Dpid dpid) { 95 + public void switchAdded(Dpid dpid) {
96 URI uri = buildURI(dpid); 96 URI uri = buildURI(dpid);
97 - providerService.deviceConnected(new DeviceId(uri), new DeviceDescription() { 97 + // TODO: fetch and provide switch desc information
98 - 98 + DeviceDescription description =
99 - @Override 99 + new DefaultDeviceDescription(buildURI(dpid), Device.Type.SWITCH,
100 - public URI deviceURI() { 100 + null, null, null, null);
101 - return buildURI(dpid); 101 + providerService.deviceConnected(new DeviceId(uri), description);
102 - }
103 - });
104 } 102 }
105 103
106 @Override 104 @Override
......