alshabib
Committed by Gerrit Code Review

null device provider implementation along with directory structure

for the other device providers

initial null provider directory structure

Change-Id: Ib7a766a854ba1863564ce2dc950f597a41a4e545

better with files

Change-Id: I041ea7bb718748e5f72ccaf06836c322b4e411d6

no binaries needed

Change-Id: I0bc978dd5bf6d20968bd1a28c6165b9f49ba585b

start nulldeviceprovider

Change-Id: If75bced900c185ca58a9302130c4d4a3cc18f12d

null device provider trivial implementation

supports hardcoded number of devices and ports, this will ultimately be extented to cli/rest configuration.

Change-Id: Iaeffc5526526b90fb1ecbcc0bd8b88103bdb921a
...@@ -118,6 +118,18 @@ ...@@ -118,6 +118,18 @@
118 <bundle>mvn:org.onosproject/onos-cli/@ONOS-VERSION</bundle> 118 <bundle>mvn:org.onosproject/onos-cli/@ONOS-VERSION</bundle>
119 </feature> 119 </feature>
120 120
121 + <feature name="onos-null" version="@FEATURE-VERSION"
122 + description="ONOS Null providers">
123 + <feature>onos-api</feature>
124 +
125 + <bundle>mvn:org.onosproject/onos-null-provider-device/@ONOS-VERSION</bundle>
126 + <bundle>mvn:org.onosproject/onos-null-provider-link/@ONOS-VERSION</bundle>
127 + <bundle>mvn:org.onosproject/onos-null-provider-host/@ONOS-VERSION</bundle>
128 + <bundle>mvn:org.onosproject/onos-null-provider-packet/@ONOS-VERSION</bundle>
129 + <bundle>mvn:org.onosproject/onos-null-provider-flow/@ONOS-VERSION</bundle>
130 +
131 + </feature>
132 +
121 <feature name="onos-openflow" version="@FEATURE-VERSION" 133 <feature name="onos-openflow" version="@FEATURE-VERSION"
122 description="ONOS OpenFlow API, Controller &amp; Providers"> 134 description="ONOS OpenFlow API, Controller &amp; Providers">
123 <feature>onos-api</feature> 135 <feature>onos-api</feature>
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 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 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-null-providers</artifactId>
25 + <version>1.1.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-null-provider-device</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>ONOS Null protocol device provider</description>
33 +
34 +</project>
1 +/*
2 + * Copyright 2014 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.provider.nil.device.impl;
17 +
18 +
19 +import com.google.common.collect.Lists;
20 +import com.google.common.collect.Maps;
21 +import org.apache.felix.scr.annotations.Activate;
22 +import org.apache.felix.scr.annotations.Component;
23 +import org.apache.felix.scr.annotations.Deactivate;
24 +import org.apache.felix.scr.annotations.Reference;
25 +import org.apache.felix.scr.annotations.ReferenceCardinality;
26 +import org.onlab.packet.ChassisId;
27 +import org.onosproject.net.Device;
28 +import org.onosproject.net.DeviceId;
29 +import org.onosproject.net.MastershipRole;
30 +import org.onosproject.net.Port;
31 +import org.onosproject.net.PortNumber;
32 +import org.onosproject.net.device.DefaultDeviceDescription;
33 +import org.onosproject.net.device.DefaultPortDescription;
34 +import org.onosproject.net.device.DeviceDescription;
35 +import org.onosproject.net.device.DeviceProvider;
36 +import org.onosproject.net.device.DeviceProviderRegistry;
37 +import org.onosproject.net.device.DeviceProviderService;
38 +import org.onosproject.net.device.PortDescription;
39 +import org.onosproject.net.provider.AbstractProvider;
40 +import org.onosproject.net.provider.ProviderId;
41 +import org.slf4j.Logger;
42 +
43 +import java.util.List;
44 +import java.util.Map;
45 +import java.util.concurrent.ExecutorService;
46 +import java.util.concurrent.Executors;
47 +import java.util.concurrent.TimeUnit;
48 +
49 +import static org.onlab.util.Tools.delay;
50 +import static org.onlab.util.Tools.namedThreads;
51 +import static org.slf4j.LoggerFactory.getLogger;
52 +
53 +/**
54 + * Provider which advertises fake/nonexistant devices to the core.
55 + * To be used for benchmarking only.
56 + */
57 +@Component(immediate = true)
58 +public class NullDeviceProvider extends AbstractProvider implements DeviceProvider {
59 +
60 + private static final Logger log = getLogger(NullDeviceProvider.class);
61 + private static final String SCHEME = "null";
62 +
63 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
64 + protected DeviceProviderRegistry providerRegistry;
65 +
66 + private DeviceProviderService providerService;
67 +
68 + private ExecutorService deviceBuilder = Executors.newFixedThreadPool(1,
69 + namedThreads("null-device-creator"));
70 +
71 +
72 +
73 + //currently hardcoded. will be made configurable via rest/cli.
74 + private static final int NUMDEVICES = 10;
75 + private static final int NUMPORTSPERDEVICE = 10;
76 +
77 + //Delay between events in ms.
78 + private static final int EVENTINTERVAL = 5;
79 +
80 + private final Map<Integer, DeviceDescription> descriptions = Maps.newHashMap();
81 +
82 + private DeviceCreator creator;
83 +
84 +
85 + /**
86 + *
87 + * Creates a provider with the supplier identifier.
88 + *
89 + */
90 + public NullDeviceProvider() {
91 + super(new ProviderId("null", "org.onosproject.provider.nil"));
92 + }
93 +
94 + @Activate
95 + public void activate() {
96 + providerService = providerRegistry.register(this);
97 + deviceBuilder.submit(new DeviceCreator(true));
98 + log.info("Started");
99 +
100 + }
101 +
102 + @Deactivate
103 + public void deactivate() {
104 + deviceBuilder.submit(new DeviceCreator(false));
105 + try {
106 + deviceBuilder.awaitTermination(1000, TimeUnit.MILLISECONDS);
107 + } catch (InterruptedException e) {
108 + log.error("Device builder did not terminate");
109 + }
110 + deviceBuilder.shutdownNow();
111 + providerRegistry.unregister(this);
112 + providerService = null;
113 +
114 + log.info("Stopped");
115 + }
116 +
117 + @Override
118 + public void triggerProbe(DeviceId deviceId) {}
119 +
120 + @Override
121 + public void roleChanged(DeviceId deviceId, MastershipRole newRole) {}
122 +
123 + @Override
124 + public boolean isReachable(DeviceId deviceId) {
125 + return descriptions.values().stream()
126 + .anyMatch(desc -> desc.deviceURI().equals(deviceId.uri()));
127 + }
128 +
129 +
130 + private class DeviceCreator implements Runnable {
131 +
132 + private boolean setup;
133 +
134 + public DeviceCreator(boolean setup) {
135 + this.setup = setup;
136 + }
137 +
138 + @Override
139 + public void run() {
140 + if (setup) {
141 + advertiseDevices();
142 + } else {
143 + removeDevices();
144 + }
145 + }
146 +
147 + private void removeDevices() {
148 + for (DeviceDescription desc : descriptions.values()) {
149 + providerService.deviceDisconnected(
150 + DeviceId.deviceId(desc.deviceURI()));
151 + delay(EVENTINTERVAL);
152 + }
153 + descriptions.clear();
154 + }
155 +
156 + private void advertiseDevices() {
157 + DeviceId did;
158 + ChassisId cid;
159 + for (int i = 0; i < NUMDEVICES; i++) {
160 + did = DeviceId.deviceId(String.format("%s:%d", SCHEME, i));
161 + cid = new ChassisId(i);
162 + DeviceDescription desc =
163 + new DefaultDeviceDescription(did.uri(), Device.Type.SWITCH,
164 + "ON.Lab", "0.0.1", "0.0.1", "1234",
165 + cid);
166 + descriptions.put(i, desc);
167 + providerService.deviceConnected(did, desc);
168 + providerService.updatePorts(did, buildPorts());
169 + delay(EVENTINTERVAL);
170 + }
171 + }
172 +
173 + private List<PortDescription> buildPorts() {
174 + List<PortDescription> ports = Lists.newArrayList();
175 + for (int i = 0; i < NUMPORTSPERDEVICE; i++) {
176 + ports.add(new DefaultPortDescription(PortNumber.portNumber(i), true,
177 + Port.Type.COPPER,
178 + (long) 0));
179 + }
180 + return ports;
181 + }
182 + }
183 +}
1 +/*
2 + * Copyright 2014 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 + * Null Provider that advertises fake devices.
19 + */
20 +package org.onosproject.provider.nil.device.impl;
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 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 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-null-providers</artifactId>
25 + <version>1.1.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-null-provider-flow</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>ONOS Null protocol flow provider</description>
33 +
34 +</project>
1 +/*
2 + * Copyright 2014 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 + * Null provider that will accept any flow.
19 + */
20 +package org.onosproject.provider.nil.flow.impl;
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 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 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-null-providers</artifactId>
25 + <version>1.1.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-null-provider-host</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>ONOS Null host provider</description>
33 +
34 +</project>
1 +/*
2 + * Copyright 2014 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 + * Null Provider that advertises fake hosts.
19 + */
20 +package org.onosproject.provider.nil.host.impl;
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 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 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-null-providers</artifactId>
25 + <version>1.1.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-null-provider-link</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>ONOS Null link provider</description>
33 +
34 +</project>
1 +/*
2 + * Copyright 2014 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 advertises fake links.
19 + */
20 +package org.onosproject.provider.nil.link.impl;
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 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 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-null-providers</artifactId>
25 + <version>1.1.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-null-provider-packet</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>ONOS Null packet provider</description>
33 +
34 +</project>
1 +/*
2 + * Copyright 2014 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 takes and brings to/from oblivion.
19 + */
20 +package org.onosproject.provider.nil.packet.impl;
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 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 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-providers</artifactId>
25 + <version>1.1.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-null-providers</artifactId>
30 + <packaging>pom</packaging>
31 +
32 + <description>ONOS null protocol adapters</description>
33 +
34 + <modules>
35 + <module>device</module>
36 + <module>link</module>
37 + <module>host</module>
38 + <module>packet</module>
39 + <module>flow</module>
40 + </modules>
41 +
42 + <dependencies>
43 +
44 + <dependency>
45 + <groupId>org.onosproject</groupId>
46 + <artifactId>onos-api</artifactId>
47 + <classifier>tests</classifier>
48 + <scope>test</scope>
49 + </dependency>
50 + </dependencies>
51 +
52 +</project>
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
35 <module>openflow</module> 35 <module>openflow</module>
36 <module>lldp</module> 36 <module>lldp</module>
37 <module>host</module> 37 <module>host</module>
38 + <module>null</module>
38 </modules> 39 </modules>
39 40
40 <dependencies> 41 <dependencies>
......