Committed by
Gerrit Code Review
[ONOS-2261] - OVSDB -- Create the implementation of DeviceProvider using
OVSDB protocol. 1.Notify the Device System when the ovsdb node is connected. 2.Notify the Device System when the ovsdb node is disconected. Change-Id: Iff795bfaca624bf957eb1c17626dfb56e241550a
Showing
7 changed files
with
417 additions
and
0 deletions
... | @@ -51,6 +51,7 @@ | ... | @@ -51,6 +51,7 @@ |
51 | <module>features</module> | 51 | <module>features</module> |
52 | <module>tools/package/archetypes</module> | 52 | <module>tools/package/archetypes</module> |
53 | <module>tools/package/branding</module> | 53 | <module>tools/package/branding</module> |
54 | + <module>ovsdb</module> | ||
54 | </modules> | 55 | </modules> |
55 | 56 | ||
56 | <url>http://onosproject.org/</url> | 57 | <url>http://onosproject.org/</url> | ... | ... |
providers/ovsdb/device/pom.xml
0 → 100644
1 | +<?xml version="1.0"?> | ||
2 | +<project | ||
3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
4 | + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
5 | + <modelVersion>4.0.0</modelVersion> | ||
6 | + | ||
7 | + <parent> | ||
8 | + <groupId>org.onosproject</groupId> | ||
9 | + <artifactId>onos-ovsdb-providers</artifactId> | ||
10 | + <version>1.3.0-SNAPSHOT</version> | ||
11 | + </parent> | ||
12 | + | ||
13 | + <artifactId>onos-ovsdb-provider-device</artifactId> | ||
14 | + <packaging>bundle</packaging> | ||
15 | + | ||
16 | + <dependencies> | ||
17 | + <dependency> | ||
18 | + <groupId>junit</groupId> | ||
19 | + <artifactId>junit</artifactId> | ||
20 | + <scope>test</scope> | ||
21 | + </dependency> | ||
22 | + </dependencies> | ||
23 | + | ||
24 | +</project> |
providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProvider.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 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.ovsdb.providers.device; | ||
17 | + | ||
18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | +import static org.slf4j.LoggerFactory.getLogger; | ||
20 | + | ||
21 | +import java.net.URI; | ||
22 | + | ||
23 | +import org.apache.felix.scr.annotations.Activate; | ||
24 | +import org.apache.felix.scr.annotations.Component; | ||
25 | +import org.apache.felix.scr.annotations.Deactivate; | ||
26 | +import org.apache.felix.scr.annotations.Reference; | ||
27 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
28 | +import org.apache.felix.scr.annotations.Service; | ||
29 | +import org.onlab.packet.ChassisId; | ||
30 | +import org.onosproject.net.DefaultAnnotations; | ||
31 | +import org.onosproject.net.Device; | ||
32 | +import org.onosproject.net.DeviceId; | ||
33 | +import org.onosproject.net.MastershipRole; | ||
34 | +import org.onosproject.net.SparseAnnotations; | ||
35 | +import org.onosproject.net.device.DefaultDeviceDescription; | ||
36 | +import org.onosproject.net.device.DeviceDescription; | ||
37 | +import org.onosproject.net.device.DeviceProvider; | ||
38 | +import org.onosproject.net.device.DeviceProviderRegistry; | ||
39 | +import org.onosproject.net.device.DeviceProviderService; | ||
40 | +import org.onosproject.net.device.DeviceService; | ||
41 | +import org.onosproject.net.provider.AbstractProvider; | ||
42 | +import org.onosproject.net.provider.ProviderId; | ||
43 | +import org.onosproject.ovsdb.controller.OvsdbController; | ||
44 | +import org.onosproject.ovsdb.controller.OvsdbNodeId; | ||
45 | +import org.onosproject.ovsdb.controller.OvsdbNodeListener; | ||
46 | +import org.slf4j.Logger; | ||
47 | + | ||
48 | +/** | ||
49 | + * Provider which uses an ovsdb controller to detect device. | ||
50 | + */ | ||
51 | +@Component(immediate = true) | ||
52 | +@Service | ||
53 | +public class OvsdbDeviceProvider extends AbstractProvider | ||
54 | + implements DeviceProvider { | ||
55 | + private final Logger log = getLogger(getClass()); | ||
56 | + | ||
57 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
58 | + protected DeviceProviderRegistry providerRegistry; | ||
59 | + | ||
60 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
61 | + protected DeviceService deviceService; | ||
62 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
63 | + protected OvsdbController controller; | ||
64 | + | ||
65 | + private DeviceProviderService providerService; | ||
66 | + private OvsdbNodeListener innerNodeListener = new InnerOvsdbNodeListener(); | ||
67 | + protected static final String ISNOTNULL = "OvsdbNodeId is not null"; | ||
68 | + private static final String UNKNOWN = "unknown"; | ||
69 | + | ||
70 | + @Activate | ||
71 | + public void activate() { | ||
72 | + providerService = providerRegistry.register(this); | ||
73 | + controller.addNodeListener(innerNodeListener); | ||
74 | + log.info("Started"); | ||
75 | + } | ||
76 | + | ||
77 | + @Deactivate | ||
78 | + public void deactivate() { | ||
79 | + providerRegistry.unregister(this); | ||
80 | + providerService = null; | ||
81 | + log.info("Stopped"); | ||
82 | + } | ||
83 | + | ||
84 | + public OvsdbDeviceProvider() { | ||
85 | + super(new ProviderId("ovsdb", "org.onosproject.ovsdb.provider.device")); | ||
86 | + } | ||
87 | + | ||
88 | + @Override | ||
89 | + public void triggerProbe(DeviceId deviceId) { | ||
90 | + // TODO: This will be implemented later. | ||
91 | + log.info("Triggering probe on device {}", deviceId); | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public void roleChanged(DeviceId deviceId, MastershipRole newRole) { | ||
96 | + // TODO: This will be implemented later. | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public boolean isReachable(DeviceId deviceId) { | ||
101 | + return true; | ||
102 | + } | ||
103 | + | ||
104 | + private class InnerOvsdbNodeListener implements OvsdbNodeListener { | ||
105 | + | ||
106 | + @Override | ||
107 | + public void nodeAdded(OvsdbNodeId nodeId) { | ||
108 | + checkNotNull(nodeId, ISNOTNULL); | ||
109 | + DeviceId deviceId = DeviceId.deviceId(nodeId.toString()); | ||
110 | + URI uri = URI.create(nodeId.toString()); | ||
111 | + ChassisId cid = new ChassisId(); | ||
112 | + String ipAddress = nodeId.getIpAddress(); | ||
113 | + SparseAnnotations annotations = DefaultAnnotations.builder() | ||
114 | + .set("ipaddress", ipAddress).build(); | ||
115 | + DeviceDescription deviceDescription = new DefaultDeviceDescription( | ||
116 | + uri, | ||
117 | + Device.Type.CONTROLLER, | ||
118 | + UNKNOWN, UNKNOWN, | ||
119 | + UNKNOWN, UNKNOWN, | ||
120 | + cid, | ||
121 | + annotations); | ||
122 | + providerService.deviceConnected(deviceId, deviceDescription); | ||
123 | + | ||
124 | + } | ||
125 | + | ||
126 | + @Override | ||
127 | + public void nodeRemoved(OvsdbNodeId nodeId) { | ||
128 | + checkNotNull(nodeId, ISNOTNULL); | ||
129 | + DeviceId deviceId = DeviceId.deviceId(nodeId.toString()); | ||
130 | + providerService.deviceDisconnected(deviceId); | ||
131 | + | ||
132 | + } | ||
133 | + } | ||
134 | +} |
providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/package-info.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 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 | + | ||
17 | +/** | ||
18 | + *Provider that uses ovsdb controller as a means of infrastructure device discovery. | ||
19 | + * | ||
20 | + */ | ||
21 | +package org.onosproject.ovsdb.providers.device; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 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.ovsdb.providers.device; | ||
17 | + | ||
18 | +import static org.junit.Assert.assertEquals; | ||
19 | +import static org.junit.Assert.assertNotNull; | ||
20 | + | ||
21 | +import java.util.Collection; | ||
22 | +import java.util.HashSet; | ||
23 | +import java.util.List; | ||
24 | +import java.util.Set; | ||
25 | + | ||
26 | +import org.junit.After; | ||
27 | +import org.junit.Before; | ||
28 | +import org.junit.Test; | ||
29 | +import org.onlab.packet.IpAddress; | ||
30 | +import org.onosproject.net.DeviceId; | ||
31 | +import org.onosproject.net.MastershipRole; | ||
32 | +import org.onosproject.net.device.DeviceDescription; | ||
33 | +import org.onosproject.net.device.DeviceProvider; | ||
34 | +import org.onosproject.net.device.DeviceProviderRegistry; | ||
35 | +import org.onosproject.net.device.DeviceProviderService; | ||
36 | +import org.onosproject.net.device.PortDescription; | ||
37 | +import org.onosproject.net.device.PortStatistics; | ||
38 | +import org.onosproject.net.provider.ProviderId; | ||
39 | +import org.onosproject.ovsdb.controller.OvsdbClientService; | ||
40 | +import org.onosproject.ovsdb.controller.OvsdbController; | ||
41 | +import org.onosproject.ovsdb.controller.OvsdbEventListener; | ||
42 | +import org.onosproject.ovsdb.controller.OvsdbNodeId; | ||
43 | +import org.onosproject.ovsdb.controller.OvsdbNodeListener; | ||
44 | + | ||
45 | +import com.google.common.collect.HashMultimap; | ||
46 | +import com.google.common.collect.Multimap; | ||
47 | + | ||
48 | +/** | ||
49 | + * Test for ovsdb device provider. | ||
50 | + */ | ||
51 | +public class OvsdbDeviceProviderTest { | ||
52 | + private final OvsdbDeviceProvider provider = new OvsdbDeviceProvider(); | ||
53 | + private final TestDeviceRegistry registry = new TestDeviceRegistry(); | ||
54 | + private final TestController controller = new TestController(); | ||
55 | + | ||
56 | + @Before | ||
57 | + public void startUp() { | ||
58 | + provider.providerRegistry = registry; | ||
59 | + provider.controller = controller; | ||
60 | + provider.activate(); | ||
61 | + assertNotNull("provider should be registered", registry.provider); | ||
62 | + } | ||
63 | + | ||
64 | + @After | ||
65 | + public void tearDown() { | ||
66 | + provider.deactivate(); | ||
67 | + provider.controller = null; | ||
68 | + provider.providerRegistry = null; | ||
69 | + } | ||
70 | + | ||
71 | + @Test | ||
72 | + public void triggerProbe() { | ||
73 | + | ||
74 | + } | ||
75 | + | ||
76 | + @Test | ||
77 | + public void testNodeAdded() { | ||
78 | + controller.listener.nodeAdded(new OvsdbNodeId(IpAddress | ||
79 | + .valueOf("192.168.202.36"), 5000)); | ||
80 | + assertEquals("ovsdb node added", 1, registry.connected.size()); | ||
81 | + } | ||
82 | + | ||
83 | + @Test | ||
84 | + public void testNodeRemoved() { | ||
85 | + controller.listener.nodeAdded(new OvsdbNodeId(IpAddress | ||
86 | + .valueOf("192.168.202.36"), 5000)); | ||
87 | + controller.listener.nodeRemoved(new OvsdbNodeId(IpAddress | ||
88 | + .valueOf("192.168.202.36"), 5000)); | ||
89 | + assertEquals("ovsdb node removded", 0, registry.connected.size()); | ||
90 | + } | ||
91 | + | ||
92 | + private class TestDeviceRegistry implements DeviceProviderRegistry { | ||
93 | + DeviceProvider provider; | ||
94 | + | ||
95 | + Set<DeviceId> connected = new HashSet<>(); | ||
96 | + Multimap<DeviceId, PortDescription> ports = HashMultimap.create(); | ||
97 | + PortDescription descr = null; | ||
98 | + | ||
99 | + @Override | ||
100 | + public DeviceProviderService register(DeviceProvider provider) { | ||
101 | + this.provider = provider; | ||
102 | + return new TestProviderService(); | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public void unregister(DeviceProvider provider) { | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public Set<ProviderId> getProviders() { | ||
111 | + return null; | ||
112 | + } | ||
113 | + | ||
114 | + private class TestProviderService implements DeviceProviderService { | ||
115 | + | ||
116 | + @Override | ||
117 | + public DeviceProvider provider() { | ||
118 | + return null; | ||
119 | + } | ||
120 | + | ||
121 | + @Override | ||
122 | + public void deviceConnected(DeviceId deviceId, | ||
123 | + DeviceDescription deviceDescription) { | ||
124 | + connected.add(deviceId); | ||
125 | + } | ||
126 | + | ||
127 | + @Override | ||
128 | + public void deviceDisconnected(DeviceId deviceId) { | ||
129 | + connected.remove(deviceId); | ||
130 | + ports.removeAll(deviceId); | ||
131 | + } | ||
132 | + | ||
133 | + @Override | ||
134 | + public void updatePorts(DeviceId deviceId, | ||
135 | + List<PortDescription> portDescriptions) { | ||
136 | + for (PortDescription p : portDescriptions) { | ||
137 | + ports.put(deviceId, p); | ||
138 | + } | ||
139 | + } | ||
140 | + | ||
141 | + @Override | ||
142 | + public void portStatusChanged(DeviceId deviceId, | ||
143 | + PortDescription portDescription) { | ||
144 | + ports.put(deviceId, portDescription); | ||
145 | + descr = portDescription; | ||
146 | + } | ||
147 | + | ||
148 | + @Override | ||
149 | + public void receivedRoleReply(DeviceId deviceId, | ||
150 | + MastershipRole requested, | ||
151 | + MastershipRole response) { | ||
152 | + } | ||
153 | + | ||
154 | + @Override | ||
155 | + public void updatePortStatistics(DeviceId deviceId, | ||
156 | + Collection<PortStatistics> portStatistics) { | ||
157 | + | ||
158 | + } | ||
159 | + | ||
160 | + } | ||
161 | + } | ||
162 | + | ||
163 | + private class TestController implements OvsdbController { | ||
164 | + OvsdbNodeListener listener = null; | ||
165 | + | ||
166 | + @Override | ||
167 | + public void addNodeListener(OvsdbNodeListener listener) { | ||
168 | + this.listener = listener; | ||
169 | + } | ||
170 | + | ||
171 | + @Override | ||
172 | + public void removeNodeListener(OvsdbNodeListener listener) { | ||
173 | + this.listener = null; | ||
174 | + } | ||
175 | + | ||
176 | + @Override | ||
177 | + public void addOvsdbEventListener(OvsdbEventListener listener) { | ||
178 | + | ||
179 | + } | ||
180 | + | ||
181 | + @Override | ||
182 | + public void removeOvsdbEventListener(OvsdbEventListener listener) { | ||
183 | + | ||
184 | + } | ||
185 | + | ||
186 | + @Override | ||
187 | + public List<OvsdbNodeId> getNodeIds() { | ||
188 | + return null; | ||
189 | + } | ||
190 | + | ||
191 | + @Override | ||
192 | + public OvsdbClientService getOvsdbClient(OvsdbNodeId nodeId) { | ||
193 | + return null; | ||
194 | + } | ||
195 | + | ||
196 | + } | ||
197 | + | ||
198 | +} |
providers/ovsdb/pom.xml
0 → 100644
1 | +<?xml version="1.0"?> | ||
2 | +<project | ||
3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
4 | + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
5 | + <modelVersion>4.0.0</modelVersion> | ||
6 | + | ||
7 | + <parent> | ||
8 | + <groupId>org.onosproject</groupId> | ||
9 | + <artifactId>onos-providers</artifactId> | ||
10 | + <version>1.3.0-SNAPSHOT</version> | ||
11 | + </parent> | ||
12 | + | ||
13 | + <artifactId>onos-ovsdb-providers</artifactId> | ||
14 | + <packaging>pom</packaging> | ||
15 | + | ||
16 | + <modules> | ||
17 | + <module>device</module> | ||
18 | + </modules> | ||
19 | + | ||
20 | + <dependencies> | ||
21 | + <dependency> | ||
22 | + <groupId>junit</groupId> | ||
23 | + <artifactId>junit</artifactId> | ||
24 | + <scope>test</scope> | ||
25 | + </dependency> | ||
26 | + <dependency> | ||
27 | + <groupId>org.onosproject</groupId> | ||
28 | + <artifactId>onos-ovsdb-api</artifactId> | ||
29 | + <version>${project.version}</version> | ||
30 | + </dependency> | ||
31 | + <dependency> | ||
32 | + <groupId>org.easymock</groupId> | ||
33 | + <artifactId>easymock</artifactId> | ||
34 | + <scope>test</scope> | ||
35 | + </dependency> | ||
36 | + </dependencies> | ||
37 | + | ||
38 | +</project> |
... | @@ -38,6 +38,7 @@ | ... | @@ -38,6 +38,7 @@ |
38 | <module>netconf</module> | 38 | <module>netconf</module> |
39 | <module>null</module> | 39 | <module>null</module> |
40 | <module>pcep</module> | 40 | <module>pcep</module> |
41 | + <module>ovsdb</module> | ||
41 | </modules> | 42 | </modules> |
42 | 43 | ||
43 | <dependencies> | 44 | <dependencies> | ... | ... |
-
Please register or login to post a comment