Thomas Vachuska

Removed deprecated null provider sub-modules.

Change-Id: I154bdbc5eb27ce79ae5428ec6dc01b1dc09be8b0
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.2.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 - <dependencies>
35 - <dependency>
36 - <groupId>org.osgi</groupId>
37 - <artifactId>org.osgi.compendium</artifactId>
38 - </dependency>
39 - </dependencies>
40 -
41 -</project>
1 -/*
2 - * Copyright 2014-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.provider.nil.device.impl;
17 -
18 -import com.google.common.collect.Lists;
19 -import com.google.common.collect.Maps;
20 -import org.apache.felix.scr.annotations.Activate;
21 -import org.apache.felix.scr.annotations.Component;
22 -import org.apache.felix.scr.annotations.Deactivate;
23 -import org.apache.felix.scr.annotations.Modified;
24 -import org.apache.felix.scr.annotations.Property;
25 -import org.apache.felix.scr.annotations.Reference;
26 -import org.apache.felix.scr.annotations.ReferenceCardinality;
27 -import org.onlab.packet.ChassisId;
28 -import org.onosproject.cfg.ComponentConfigService;
29 -import org.onosproject.cluster.ClusterService;
30 -import org.onosproject.cluster.NodeId;
31 -import org.onosproject.net.Device;
32 -import org.onosproject.net.DeviceId;
33 -import org.onosproject.net.MastershipRole;
34 -import org.onosproject.net.Port;
35 -import org.onosproject.net.PortNumber;
36 -import org.onosproject.net.device.DefaultDeviceDescription;
37 -import org.onosproject.net.device.DefaultPortDescription;
38 -import org.onosproject.net.device.DeviceDescription;
39 -import org.onosproject.net.device.DeviceProvider;
40 -import org.onosproject.net.device.DeviceProviderRegistry;
41 -import org.onosproject.net.device.DeviceProviderService;
42 -import org.onosproject.net.device.PortDescription;
43 -import org.onosproject.net.provider.AbstractProvider;
44 -import org.onosproject.net.provider.ProviderId;
45 -import org.osgi.service.component.ComponentContext;
46 -import org.slf4j.Logger;
47 -
48 -import java.net.URI;
49 -import java.net.URISyntaxException;
50 -import java.util.Dictionary;
51 -import java.util.List;
52 -import java.util.Map;
53 -import java.util.concurrent.ExecutorService;
54 -import java.util.concurrent.Executors;
55 -import java.util.concurrent.TimeUnit;
56 -
57 -import static com.google.common.base.Strings.isNullOrEmpty;
58 -import static org.onlab.util.Tools.*;
59 -import static org.slf4j.LoggerFactory.getLogger;
60 -
61 -/**
62 - * Provider which advertises fake/nonexistant devices to the core.
63 - * nodeID is passed as part of the fake device id so that multiple nodes can run simultaneously.
64 - * To be used for benchmarking only.
65 - */
66 -@Component(immediate = true)
67 -public class NullDeviceProvider extends AbstractProvider implements DeviceProvider {
68 -
69 - private static final Logger log = getLogger(NullDeviceProvider.class);
70 -
71 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
72 - protected ClusterService clusterService;
73 -
74 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
75 - protected DeviceProviderRegistry providerRegistry;
76 -
77 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
78 - protected ComponentConfigService cfgService;
79 -
80 - private DeviceProviderService providerService;
81 -
82 - private ExecutorService deviceBuilder =
83 - Executors.newFixedThreadPool(1, groupedThreads("onos/null", "device-creator"));
84 -
85 - private static final String SCHEME = "null";
86 - private static final int DEF_NUMDEVICES = 10;
87 - private static final int DEF_NUMPORTS = 10;
88 -
89 - //Delay between events in ms.
90 - private static final int EVENTINTERVAL = 5;
91 -
92 - private final Map<Integer, DeviceDescription> descriptions = Maps.newHashMap();
93 -
94 - @Property(name = "devConfigs", value = "", label = "Instance-specific configurations")
95 - private String devConfigs = null;
96 -
97 - private int numDevices = DEF_NUMDEVICES;
98 -
99 - @Property(name = "numPorts", intValue = 10, label = "Number of ports per devices")
100 - private int numPorts = DEF_NUMPORTS;
101 -
102 - private DeviceCreator creator;
103 -
104 - /**
105 - *
106 - * Creates a provider with the supplier identifier.
107 - *
108 - */
109 - public NullDeviceProvider() {
110 - super(new ProviderId("null", "org.onosproject.provider.nil"));
111 - }
112 -
113 - @Activate
114 - public void activate(ComponentContext context) {
115 - cfgService.registerProperties(getClass());
116 - providerService = providerRegistry.register(this);
117 - if (!modified(context)) {
118 - deviceBuilder.submit(new DeviceCreator(true));
119 - }
120 - log.info("Started");
121 -
122 - }
123 -
124 - @Deactivate
125 - public void deactivate(ComponentContext context) {
126 - cfgService.unregisterProperties(getClass(), false);
127 - deviceBuilder.submit(new DeviceCreator(false));
128 - try {
129 - deviceBuilder.awaitTermination(1000, TimeUnit.MILLISECONDS);
130 - } catch (InterruptedException e) {
131 - log.error("Device builder did not terminate");
132 - }
133 - deviceBuilder.shutdownNow();
134 - providerRegistry.unregister(this);
135 - providerService = null;
136 -
137 - log.info("Stopped");
138 - }
139 -
140 - @Modified
141 - public boolean modified(ComponentContext context) {
142 - if (context == null) {
143 - log.info("No configuration file, using defaults: numDevices={}, numPorts={}",
144 - numDevices, numPorts);
145 - return false;
146 - }
147 -
148 - Dictionary<?, ?> properties = context.getProperties();
149 -
150 - int newDevNum = DEF_NUMDEVICES;
151 - int newPortNum = DEF_NUMPORTS;
152 - try {
153 - String s = get(properties, "devConfigs");
154 - if (!isNullOrEmpty(s)) {
155 - newDevNum = getDevicesConfig(s);
156 - }
157 - s = get(properties, "numPorts");
158 - newPortNum = isNullOrEmpty(s) ? DEF_NUMPORTS : Integer.parseInt(s.trim());
159 - } catch (NumberFormatException e) {
160 - log.warn(e.getMessage());
161 - newDevNum = numDevices;
162 - newPortNum = numPorts;
163 - }
164 -
165 - boolean chgd = false;
166 - if (newDevNum != numDevices) {
167 - numDevices = newDevNum;
168 - chgd |= true;
169 - }
170 - if (newPortNum != numPorts) {
171 - numPorts = newPortNum;
172 - chgd |= true;
173 - }
174 - log.info("Using settings numDevices={}, numPorts={}", numDevices, numPorts);
175 - if (chgd) {
176 - deviceBuilder.submit(new DeviceCreator(true));
177 - }
178 - return chgd;
179 - }
180 -
181 - private int getDevicesConfig(String config) {
182 - for (String sub : config.split(",")) {
183 - String[] params = sub.split(":");
184 - if (params.length == 2) {
185 - NodeId that = new NodeId(params[0].trim());
186 - String nd = params[1];
187 - if (clusterService.getLocalNode().id().equals(that)) {
188 - return Integer.parseInt(nd.trim());
189 - }
190 - continue;
191 - }
192 - }
193 - return DEF_NUMDEVICES;
194 - }
195 -
196 - @Override
197 - public void triggerProbe(DeviceId deviceId) {}
198 -
199 - @Override
200 - public void roleChanged(DeviceId deviceId, MastershipRole newRole) {}
201 -
202 - @Override
203 - public boolean isReachable(DeviceId deviceId) {
204 - return descriptions.values().stream()
205 - .anyMatch(desc -> desc.deviceURI().equals(deviceId.uri()));
206 - }
207 -
208 -
209 - private class DeviceCreator implements Runnable {
210 -
211 - private boolean setup;
212 -
213 - public DeviceCreator(boolean setup) {
214 - this.setup = setup;
215 - }
216 -
217 - @Override
218 - public void run() {
219 - if (setup) {
220 - try {
221 - advertiseDevices();
222 - } catch (URISyntaxException e) {
223 - log.warn("URI creation failed during device adverts {}", e.getMessage());
224 - }
225 - } else {
226 - removeDevices();
227 - }
228 - }
229 -
230 - private void removeDevices() {
231 - for (DeviceDescription desc : descriptions.values()) {
232 - providerService.deviceDisconnected(
233 - DeviceId.deviceId(desc.deviceURI()));
234 - delay(EVENTINTERVAL);
235 - }
236 - descriptions.clear();
237 - }
238 -
239 - private void advertiseDevices() throws URISyntaxException {
240 - DeviceId did;
241 - ChassisId cid;
242 -
243 - // nodeIdHash takes into account for nodeID to avoid collisions when running multi-node providers.
244 - long nodeIdHash = clusterService.getLocalNode().id().hashCode() << 16;
245 -
246 - for (int i = 0; i < numDevices; i++) {
247 - long id = nodeIdHash | i;
248 -
249 - did = DeviceId.deviceId(new URI(SCHEME, toHex(id), null));
250 - cid = new ChassisId(i);
251 - DeviceDescription desc =
252 - new DefaultDeviceDescription(did.uri(), Device.Type.SWITCH,
253 - "ON.Lab", "0.0.1", "0.0.1", "1234",
254 - cid);
255 - descriptions.put(i, desc);
256 - providerService.deviceConnected(did, desc);
257 - providerService.updatePorts(did, buildPorts());
258 - delay(EVENTINTERVAL);
259 - }
260 - }
261 -
262 - private List<PortDescription> buildPorts() {
263 - List<PortDescription> ports = Lists.newArrayList();
264 - for (int i = 0; i < numPorts; i++) {
265 - ports.add(new DefaultPortDescription(PortNumber.portNumber(i), true,
266 - Port.Type.COPPER,
267 - 0));
268 - }
269 - return ports;
270 - }
271 - }
272 -}
1 -/*
2 - * Copyright 2014-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 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.2.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 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.provider.nil.flow.impl;
17 -
18 -import com.google.common.collect.Sets;
19 -import org.apache.felix.scr.annotations.Activate;
20 -import org.apache.felix.scr.annotations.Component;
21 -import org.apache.felix.scr.annotations.Deactivate;
22 -import org.apache.felix.scr.annotations.Reference;
23 -import org.apache.felix.scr.annotations.ReferenceCardinality;
24 -import org.jboss.netty.util.HashedWheelTimer;
25 -import org.jboss.netty.util.Timeout;
26 -import org.jboss.netty.util.TimerTask;
27 -import org.onlab.util.Timer;
28 -import org.onosproject.core.ApplicationId;
29 -import org.onosproject.net.DeviceId;
30 -import org.onosproject.net.flow.CompletedBatchOperation;
31 -import org.onosproject.net.flow.DefaultFlowEntry;
32 -import org.onosproject.net.flow.FlowEntry;
33 -import org.onosproject.net.flow.FlowRule;
34 -import org.onosproject.net.flow.FlowRuleBatchEntry;
35 -import org.onosproject.net.flow.FlowRuleBatchOperation;
36 -import org.onosproject.net.flow.FlowRuleProvider;
37 -import org.onosproject.net.flow.FlowRuleProviderRegistry;
38 -import org.onosproject.net.flow.FlowRuleProviderService;
39 -import org.onosproject.net.provider.AbstractProvider;
40 -import org.onosproject.net.provider.ProviderId;
41 -import org.slf4j.Logger;
42 -
43 -import java.util.Collections;
44 -import java.util.Set;
45 -import java.util.concurrent.ConcurrentHashMap;
46 -import java.util.concurrent.ConcurrentMap;
47 -import java.util.concurrent.TimeUnit;
48 -
49 -import static org.slf4j.LoggerFactory.getLogger;
50 -
51 -/**
52 - * Null provider to accept any flow and report them.
53 - */
54 -@Component(immediate = true)
55 -public class NullFlowRuleProvider extends AbstractProvider implements FlowRuleProvider {
56 -
57 - private final Logger log = getLogger(getClass());
58 -
59 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 - protected FlowRuleProviderRegistry providerRegistry;
61 -
62 - private ConcurrentMap<DeviceId, Set<FlowEntry>> flowTable = new ConcurrentHashMap<>();
63 -
64 - private FlowRuleProviderService providerService;
65 -
66 - private HashedWheelTimer timer = Timer.getTimer();
67 - private Timeout timeout;
68 -
69 - public NullFlowRuleProvider() {
70 - super(new ProviderId("null", "org.onosproject.provider.nil"));
71 - }
72 -
73 - @Activate
74 - public void activate() {
75 - providerService = providerRegistry.register(this);
76 - timeout = timer.newTimeout(new StatisticTask(), 5, TimeUnit.SECONDS);
77 -
78 - log.info("Started");
79 - }
80 -
81 - @Deactivate
82 - public void deactivate() {
83 - providerRegistry.unregister(this);
84 - providerService = null;
85 - timeout.cancel();
86 -
87 - log.info("Stopped");
88 - }
89 -
90 - @Override
91 - public void applyFlowRule(FlowRule... flowRules) {}
92 -
93 - @Override
94 - public void removeFlowRule(FlowRule... flowRules) {}
95 -
96 - @Override
97 - public void removeRulesById(ApplicationId id, FlowRule... flowRules) {
98 - log.info("removal by app id not supported in null provider");
99 - }
100 -
101 - @Override
102 - public void executeBatch(
103 - FlowRuleBatchOperation batch) {
104 - Set<FlowEntry> flowRules = flowTable.getOrDefault(batch.deviceId(), Sets.newConcurrentHashSet());
105 - for (FlowRuleBatchEntry fbe : batch.getOperations()) {
106 - switch (fbe.operator()) {
107 - case ADD:
108 - flowRules.add(new DefaultFlowEntry(fbe.target()));
109 - break;
110 - case REMOVE:
111 - flowRules.remove(new DefaultFlowEntry(fbe.target()));
112 - break;
113 - case MODIFY:
114 - FlowEntry entry = new DefaultFlowEntry(fbe.target());
115 - flowRules.remove(entry);
116 - flowRules.add(entry);
117 - break;
118 - default:
119 - log.error("Unknown flow operation: {}", fbe);
120 - }
121 - }
122 - flowTable.put(batch.deviceId(), flowRules);
123 - providerService.batchOperationCompleted(batch.id(),
124 - new CompletedBatchOperation(
125 - true,
126 - Collections.emptySet(),
127 - batch.deviceId()));
128 - }
129 -
130 - private class StatisticTask implements TimerTask {
131 -
132 - @Override
133 - public void run(Timeout to) throws Exception {
134 - for (DeviceId devId : flowTable.keySet()) {
135 - providerService.pushFlowMetrics(devId,
136 - flowTable.getOrDefault(devId, Collections.emptySet()));
137 - }
138 - timeout = timer.newTimeout(to.getTask(), 5, TimeUnit.SECONDS);
139 -
140 - }
141 - }
142 -}
1 -/*
2 - * Copyright 2014-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 will accept any flow rules.
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.2.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 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.provider.nil.host.impl;
17 -
18 -import org.apache.felix.scr.annotations.Activate;
19 -import org.apache.felix.scr.annotations.Component;
20 -import org.apache.felix.scr.annotations.Deactivate;
21 -import org.apache.felix.scr.annotations.Reference;
22 -import org.apache.felix.scr.annotations.ReferenceCardinality;
23 -import org.onlab.packet.MacAddress;
24 -import org.onlab.packet.VlanId;
25 -import org.onosproject.cluster.ClusterService;
26 -import org.onosproject.mastership.MastershipService;
27 -import org.onosproject.net.Device;
28 -import org.onosproject.net.Host;
29 -import org.onosproject.net.HostId;
30 -import org.onosproject.net.HostLocation;
31 -import org.onosproject.net.MastershipRole;
32 -import org.onosproject.net.PortNumber;
33 -import org.onosproject.net.device.DeviceEvent;
34 -import org.onosproject.net.device.DeviceListener;
35 -import org.onosproject.net.device.DeviceService;
36 -import org.onosproject.net.host.DefaultHostDescription;
37 -import org.onosproject.net.host.HostDescription;
38 -import org.onosproject.net.host.HostProvider;
39 -import org.onosproject.net.host.HostProviderRegistry;
40 -import org.onosproject.net.host.HostProviderService;
41 -import org.onosproject.net.provider.AbstractProvider;
42 -import org.onosproject.net.provider.ProviderId;
43 -import org.slf4j.Logger;
44 -
45 -import static org.onlab.util.Tools.toHex;
46 -import static org.slf4j.LoggerFactory.getLogger;
47 -
48 -/**
49 - * Null provider to advertise fake hosts.
50 - */
51 -@Component(immediate = true)
52 -public class NullHostProvider extends AbstractProvider implements HostProvider {
53 -
54 - private final Logger log = getLogger(getClass());
55 -
56 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
57 - protected DeviceService deviceService;
58 -
59 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 - protected MastershipService roleService;
61 -
62 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 - protected ClusterService nodeService;
64 -
65 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 - protected HostProviderRegistry providerRegistry;
67 -
68 - private HostProviderService providerService;
69 -
70 - //make sure the device has enough ports to accomodate all of them.
71 - private static final int HOSTSPERDEVICE = 5;
72 -
73 - private final InternalHostProvider hostProvider = new InternalHostProvider();
74 -
75 - /**
76 - * Creates an OpenFlow host provider.
77 - */
78 - public NullHostProvider() {
79 - super(new ProviderId("null", "org.onosproject.provider.nil"));
80 - }
81 -
82 - /**
83 - * Creates a provider with the supplier identifier.
84 - *
85 - * @param id provider id
86 - */
87 - protected NullHostProvider(ProviderId id) {
88 - super(id);
89 - }
90 -
91 - @Activate
92 - public void activate() {
93 - providerService = providerRegistry.register(this);
94 - for (Device dev : deviceService.getDevices()) {
95 - addHosts(dev);
96 - }
97 - deviceService.addListener(hostProvider);
98 -
99 - log.info("Started");
100 - }
101 -
102 - @Deactivate
103 - public void deactivate() {
104 - providerRegistry.unregister(this);
105 - deviceService.removeListener(hostProvider);
106 - providerService = null;
107 - log.info("Stopped");
108 - }
109 -
110 - @Override
111 - public void triggerProbe(Host host) {}
112 -
113 - private void addHosts(Device device) {
114 - String nhash = toHex(nodeService.getLocalNode().id().hashCode());
115 - String dhash = device.id().toString();
116 - // make sure this instance owns the device.
117 - if (!nhash.substring(nhash.length() - 3)
118 - .equals(dhash.substring(14, 17))) {
119 - log.warn("Device {} is not mine. Can't add hosts.", device.id());
120 - return;
121 - }
122 - for (int i = 0; i < HOSTSPERDEVICE; i++) {
123 - providerService.hostDetected(
124 - HostId.hostId(MacAddress.valueOf(i + device.hashCode()),
125 - VlanId.vlanId((short) -1)),
126 - buildHostDescription(device, i));
127 - }
128 - }
129 -
130 - private void removeHosts(Device device) {
131 - for (int i = 0; i < HOSTSPERDEVICE; i++) {
132 - providerService.hostVanished(
133 - HostId.hostId(MacAddress.valueOf(i + device.hashCode()),
134 - VlanId.vlanId((short) -1)));
135 - }
136 - }
137 -
138 - private HostDescription buildHostDescription(Device device, int port) {
139 - MacAddress mac = MacAddress.valueOf(device.hashCode() + port);
140 - HostLocation location = new HostLocation(device.id(),
141 - PortNumber.portNumber(port), 0L);
142 - return new DefaultHostDescription(mac, VlanId.vlanId((short) -1), location);
143 - }
144 -
145 - private class InternalHostProvider implements DeviceListener {
146 - @Override
147 - public void event(DeviceEvent event) {
148 - Device dev = event.subject();
149 - if (!deviceService.getRole(event.subject().id()).equals(
150 - MastershipRole.MASTER)) {
151 - log.info("Local node is not master for device {}", event
152 - .subject().id());
153 - return;
154 - }
155 - switch (event.type()) {
156 -
157 - case DEVICE_ADDED:
158 - addHosts(dev);
159 - break;
160 - case DEVICE_UPDATED:
161 - break;
162 - case DEVICE_REMOVED:
163 - removeHosts(dev);
164 - break;
165 - case DEVICE_SUSPENDED:
166 - break;
167 - case DEVICE_AVAILABILITY_CHANGED:
168 - break;
169 - case PORT_ADDED:
170 - break;
171 - case PORT_UPDATED:
172 - break;
173 - case PORT_REMOVED:
174 - break;
175 - default:
176 - break;
177 - }
178 - }
179 -
180 - }
181 -
182 -}
1 -/*
2 - * Copyright 2014-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 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.2.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 - <dependencies>
35 - <dependency>
36 - <groupId>org.osgi</groupId>
37 - <artifactId>org.osgi.compendium</artifactId>
38 - </dependency>
39 - </dependencies>
40 -
41 -</project>
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.provider.nil.link.impl;
17 -
18 -import com.google.common.base.Charsets;
19 -import com.google.common.collect.HashMultimap;
20 -import com.google.common.collect.Lists;
21 -import com.google.common.collect.Maps;
22 -import com.google.common.collect.Sets;
23 -import com.google.common.io.Files;
24 -
25 -import org.apache.felix.scr.annotations.Activate;
26 -import org.apache.felix.scr.annotations.Component;
27 -import org.apache.felix.scr.annotations.Deactivate;
28 -import org.apache.felix.scr.annotations.Modified;
29 -import org.apache.felix.scr.annotations.Property;
30 -import org.apache.felix.scr.annotations.Reference;
31 -import org.apache.felix.scr.annotations.ReferenceCardinality;
32 -import org.onosproject.cfg.ComponentConfigService;
33 -import org.onosproject.cluster.ClusterService;
34 -import org.onosproject.cluster.NodeId;
35 -import org.onosproject.mastership.MastershipService;
36 -import org.onosproject.net.ConnectPoint;
37 -import org.onosproject.net.Device;
38 -import org.onosproject.net.DeviceId;
39 -import org.onosproject.net.PortNumber;
40 -import org.onosproject.net.device.DeviceEvent;
41 -import org.onosproject.net.device.DeviceListener;
42 -import org.onosproject.net.device.DeviceService;
43 -import org.onosproject.net.link.DefaultLinkDescription;
44 -import org.onosproject.net.link.LinkDescription;
45 -import org.onosproject.net.link.LinkProvider;
46 -import org.onosproject.net.link.LinkProviderRegistry;
47 -import org.onosproject.net.link.LinkProviderService;
48 -import org.onosproject.net.provider.AbstractProvider;
49 -import org.onosproject.net.provider.ProviderId;
50 -import org.osgi.service.component.ComponentContext;
51 -import org.slf4j.Logger;
52 -
53 -import java.io.BufferedReader;
54 -import java.io.File;
55 -import java.io.IOException;
56 -import java.net.URI;
57 -import java.net.URISyntaxException;
58 -import java.util.Dictionary;
59 -import java.util.List;
60 -import java.util.Set;
61 -import java.util.concurrent.ConcurrentMap;
62 -import java.util.concurrent.Executors;
63 -import java.util.concurrent.ScheduledExecutorService;
64 -import java.util.concurrent.TimeUnit;
65 -
66 -import static org.onlab.util.Tools.groupedThreads;
67 -import static org.onlab.util.Tools.get;
68 -import static org.onlab.util.Tools.toHex;
69 -import static org.onosproject.net.Link.Type.DIRECT;
70 -import static org.slf4j.LoggerFactory.getLogger;
71 -import static com.google.common.base.Strings.isNullOrEmpty;
72 -
73 -/**
74 - * Provider which advertises fake/nonexistent links to the core. To be used for
75 - * benchmarking only.
76 - *
77 - * This provider takes a topology graph file with a DOT-like syntax.
78 - */
79 -@Component(immediate = true)
80 -public class NullLinkProvider extends AbstractProvider implements LinkProvider {
81 -
82 - private final Logger log = getLogger(getClass());
83 -
84 - // default topology file location and name.
85 - private static final String CFG_PATH = "etc/linkGraph.cfg";
86 -
87 - // default number of workers. Eventually make this tunable
88 - private static final int THREADS = (int) Math.max(1, Runtime.getRuntime().availableProcessors() * 0.8);
89 -
90 - private static final int CHECK_DURATION = 10; // sec
91 - private static final int DEFAULT_RATE = 0; // usec
92 - private static final int REFRESH_RATE = 3; // sec
93 - // Fake device used for non-flickering thread in deviceMap
94 - private static final DeviceId DEFAULT = DeviceId.deviceId("null:ffffffffffffffff");
95 -
96 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
97 - protected DeviceService deviceService;
98 -
99 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
100 - protected MastershipService roleService;
101 -
102 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
103 - protected ClusterService nodeService;
104 -
105 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
106 - protected LinkProviderRegistry providerRegistry;
107 -
108 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
109 - protected ComponentConfigService cfgService;
110 -
111 - private LinkProviderService providerService;
112 -
113 - private final InternalLinkProvider linkProvider = new InternalLinkProvider();
114 -
115 - // Mapping between device and drivers that advertise links from device
116 - private final ConcurrentMap<DeviceId, Set<LinkDriver>> driverMap = Maps
117 - .newConcurrentMap();
118 -
119 - // Link descriptions
120 - private final List<LinkDescription> linkDescrs = Lists.newArrayList();
121 -
122 - // Thread to description map for dividing links amongst threads in flicker mode
123 - private final List<List<LinkDescription>> linkTasks = Lists.newArrayList();
124 -
125 - private ScheduledExecutorService linkDriver =
126 - Executors.newScheduledThreadPool(THREADS, groupedThreads("onos/null", "link-driver-%d"));
127 -
128 - // For flicker = true, duration between events in msec.
129 - @Property(name = "eventRate", intValue = DEFAULT_RATE, label = "Duration between Link Event")
130 - private int eventRate = DEFAULT_RATE;
131 -
132 - // topology configuration file
133 - @Property(name = "cfgFile", value = CFG_PATH, label = "Topology file location")
134 - private String cfgFile = CFG_PATH;
135 -
136 - // flag checked to create a LinkDriver, if rate is non-zero.
137 - private volatile boolean flicker = false;
138 -
139 - public NullLinkProvider() {
140 - super(new ProviderId("null", "org.onosproject.provider.nil"));
141 - }
142 -
143 - @Activate
144 - public void activate(ComponentContext context) {
145 - cfgService.registerProperties(getClass());
146 - providerService = providerRegistry.register(this);
147 - modified(context);
148 - log.info("started");
149 - }
150 -
151 - @Deactivate
152 - public void deactivate(ComponentContext context) {
153 - cfgService.unregisterProperties(getClass(), false);
154 - linkDriver.shutdown();
155 - try {
156 - linkDriver.awaitTermination(1000, TimeUnit.MILLISECONDS);
157 - } catch (InterruptedException e) {
158 - log.error("LinkBuilder did not terminate");
159 - linkDriver.shutdownNow();
160 - }
161 - deviceService.removeListener(linkProvider);
162 - providerRegistry.unregister(this);
163 - deviceService = null;
164 -
165 - log.info("stopped");
166 - }
167 -
168 - @Modified
169 - public void modified(ComponentContext context) {
170 - if (context == null) {
171 - log.info("No configs, using defaults: eventRate={}", DEFAULT_RATE);
172 - return;
173 - }
174 - Dictionary<?, ?> properties = context.getProperties();
175 - int newRate;
176 - String newPath;
177 - try {
178 - String s = get(properties, "eventRate");
179 - newRate = isNullOrEmpty(s) ? DEFAULT_RATE : Integer.parseInt(s.trim());
180 - s = (String) properties.get("cfgFile");
181 - newPath = isNullOrEmpty(s) ? CFG_PATH : s.trim();
182 - } catch (NumberFormatException e) {
183 - log.warn(e.getMessage());
184 - newRate = eventRate;
185 - newPath = cfgFile;
186 - }
187 - // find/read topology file.
188 - if (!newPath.equals(cfgFile)) {
189 - cfgFile = newPath;
190 - }
191 - readGraph(cfgFile, nodeService.getLocalNode().id());
192 - // check for new eventRate settings.
193 - if (newRate != eventRate) {
194 - if (eventRate < 0) {
195 - log.warn("Invalid rate, ignoring and using default");
196 - eventRate = DEFAULT_RATE;
197 - } else {
198 - eventRate = newRate;
199 - }
200 - }
201 - configureWorkers();
202 - log.info("Using settings: eventRate={}, topofile={}", eventRate, cfgFile);
203 - }
204 -
205 - // Configures and schedules worker threads based on settings.
206 - private void configureWorkers() {
207 - if (eventRate > 0) {
208 - // now set to 'flicker', previously not flickering
209 - if (!flicker) {
210 - flicker = true;
211 - allocateLinks();
212 - // kill off refresh worker for symmetry
213 - if (driverMap.containsKey(DEFAULT)) {
214 - driverMap.get(DEFAULT).forEach(d -> d.setTasks(Lists.newArrayList()));
215 - driverMap.remove(DEFAULT);
216 - }
217 - for (int i = 0; i < linkTasks.size(); i++) {
218 - List<LinkDescription> links = linkTasks.get(i);
219 - LinkDriver driver = new LinkDriver(links);
220 - links.forEach(v -> {
221 - DeviceId sd = v.src().deviceId();
222 - DeviceId dd = v.src().deviceId();
223 - driverMap.computeIfAbsent(sd, k -> Sets.newConcurrentHashSet()).add(driver);
224 - driverMap.computeIfAbsent(dd, k -> Sets.newConcurrentHashSet()).add(driver);
225 - });
226 - linkDriver.schedule(driver, eventRate, TimeUnit.MICROSECONDS);
227 - }
228 - }
229 - // no need for was flicker since eventRate will be read by workers
230 - } else {
231 - // now set to 'refresh' was 'flicker' before
232 - if (flicker) {
233 - driverMap.forEach((dev, lds) -> lds.forEach(l -> l.deviceRemoved(dev)));
234 - driverMap.clear();
235 - linkTasks.clear();
236 - flicker = false;
237 - LinkDriver driver = new LinkDriver(linkDescrs);
238 - driverMap.computeIfAbsent(DEFAULT, k -> Sets.newConcurrentHashSet()).add(driver);
239 - linkDriver.schedule(driver, DEFAULT_RATE, TimeUnit.SECONDS);
240 - // was 'refresh' - something changed or we're just starting.
241 - } else {
242 - if (driverMap.containsKey(DEFAULT)) {
243 - driverMap.forEach((dev, ld) -> ld.forEach(d -> d.setTasks(linkDescrs)));
244 - return;
245 - }
246 - LinkDriver driver = new LinkDriver(linkDescrs);
247 - driverMap.computeIfAbsent(DEFAULT, k -> Sets.newConcurrentHashSet()).add(driver);
248 - linkDriver.schedule(driver, DEFAULT_RATE, TimeUnit.SECONDS);
249 - }
250 - }
251 - }
252 -
253 - // parse simplified dot-like topology graph
254 - private void readGraph(String path, NodeId me) {
255 - log.info("path: {}, local: {}", path, me);
256 - Set<LinkDescription> read = Sets.newHashSet();
257 - BufferedReader br = null;
258 - try {
259 - br = Files.newReader(new File(path), Charsets.US_ASCII);
260 - String cur = br.readLine();
261 - while (cur != null) {
262 - if (cur.startsWith("#")) {
263 - cur = br.readLine();
264 - continue;
265 - }
266 - String[] parts = cur.trim().split(" ");
267 - if (parts.length < 1) {
268 - continue;
269 - }
270 - if (parts[0].equals("graph")) {
271 - String node = parts[1].trim();
272 - if (node.equals(me.toString())) {
273 - cur = br.readLine(); // move to next line, start of links list
274 - while (cur != null) {
275 - if (cur.trim().contains("}")) {
276 - break;
277 - }
278 - readLink(cur.trim().split(" "), me, read);
279 - cur = br.readLine();
280 - }
281 - } else {
282 - while (cur != null) {
283 - if (cur.trim().equals("}")) {
284 - break;
285 - }
286 - cur = br.readLine();
287 - }
288 - }
289 - }
290 - cur = br.readLine();
291 - }
292 - } catch (IOException e) {
293 - log.warn("Could not find topology file: {}", e);
294 - } finally {
295 - try {
296 - if (br != null) {
297 - br.close();
298 - }
299 - } catch (IOException e) {
300 - log.warn("Could not close topology file: {}", e);
301 - }
302 - }
303 - synchronized (linkDescrs) {
304 - if (!read.isEmpty()) {
305 - linkDescrs.clear();
306 - linkDescrs.addAll(read);
307 - }
308 - }
309 - }
310 -
311 - // parses a link descriptor to make a LinkDescription
312 - private void readLink(String[] linkArr, NodeId me, Set<LinkDescription> links) {
313 - if (linkArr[0].startsWith("#")) {
314 - return;
315 - }
316 - if (linkArr.length != 3) {
317 - log.warn("Malformed link descriptor:"
318 - + " link should be of format src:port [--|->] dst:port,"
319 - + " skipping");
320 - return;
321 - }
322 -
323 - String op = linkArr[1];
324 - String[] cp1 = linkArr[0].split(":");
325 - String[] cp2 = linkArr[2].split(":");
326 -
327 - if (cp1.length != 2 && (cp2.length != 2 || cp2.length != 3)) {
328 - log.warn("Malformed endpoint descriptor(s):"
329 - + "endpoint format should be DeviceId:port or DeviceId:port:NodeId,"
330 - + "skipping");
331 - return;
332 - }
333 - // read in hints about topology.
334 - NodeId adj = null;
335 - if (cp2.length == 3) {
336 - adj = new NodeId(cp2[2]);
337 - log.debug("found an island: {}", adj);
338 - }
339 -
340 - // reconstruct deviceIDs. Convention is based on NullDeviceProvider.
341 - DeviceId sdev = recover(cp1[0], me);
342 - DeviceId ddev = (adj == null) ? recover(cp2[0], me) : recover(cp2[0], adj);
343 - ConnectPoint src = new ConnectPoint(sdev, PortNumber.portNumber(cp1[1]));
344 - ConnectPoint dst = new ConnectPoint(ddev, PortNumber.portNumber(cp2[1]));
345 - // both link types have incoming half-link
346 - LinkDescription in = new DefaultLinkDescription(dst, src, DIRECT);
347 - links.add(in);
348 - if (op.equals("--")) {
349 - // bidirectional - within our node's island, make outbound link
350 - LinkDescription out = new DefaultLinkDescription(src, dst, DIRECT);
351 - links.add(out);
352 - log.info("Created bidirectional link: {}, {}", out, in);
353 - } else if (op.equals("->")) {
354 - log.info("Created unidirectional link: {}", in);
355 - } else {
356 - log.warn("Unknown link descriptor operand:"
357 - + " operand must be '--' or '->', skipping");
358 - return;
359 - }
360 - }
361 -
362 - // recover DeviceId from configs and NodeID
363 - private DeviceId recover(String base, NodeId node) {
364 - long hash = node.hashCode() << 16;
365 - int dev = Integer.parseInt(base);
366 - try {
367 - return DeviceId.deviceId(new URI("null", toHex(hash | dev), null));
368 - } catch (URISyntaxException e) {
369 - log.warn("could not create a DeviceID for descriptor {}", dev);
370 - return DeviceId.NONE;
371 - }
372 - }
373 -
374 - // adds a LinkDescription to a worker's to-be queue, for flickering
375 - private void allocateLinks() {
376 - int index, lcount = 0;
377 - linkTasks.clear();
378 - for (LinkDescription ld : linkDescrs) {
379 - index = (lcount % THREADS);
380 - log.info("allocation: total={}, index={}", linkDescrs.size(), lcount, index);
381 - if (linkTasks.size() <= index) {
382 - linkTasks.add(index, Lists.newArrayList(ld));
383 - } else {
384 - linkTasks.get(index).add(ld);
385 - }
386 - lcount++;
387 - }
388 - }
389 -
390 - /**
391 - * Generate LinkEvents using configurations when devices are found.
392 - */
393 - private class InternalLinkProvider implements DeviceListener {
394 -
395 - @Override
396 - public void event(DeviceEvent event) {
397 - Device dev = event.subject();
398 - switch (event.type()) {
399 - case DEVICE_ADDED:
400 - // TODO: wait for all devices to stop core from balking
401 - break;
402 - case DEVICE_REMOVED:
403 - for (LinkDriver d : driverMap.get(dev.id())) {
404 - d.deviceRemoved(dev.id());
405 - }
406 - providerService.linksVanished(dev.id());
407 - break;
408 - default:
409 - break;
410 - }
411 - }
412 - }
413 -
414 - /**
415 - * Generates link events using fake links.
416 - * TODO: stats collection should be its own thing.
417 - */
418 - private class LinkDriver implements Runnable {
419 - // List to actually work off of
420 - List<LinkDescription> tasks = Lists.newCopyOnWriteArrayList();
421 - float effLoad = 0;
422 - Long counter = 0L;
423 - int next = 0;
424 - boolean up = true;
425 -
426 - long startTime;
427 -
428 - LinkDriver(List<LinkDescription> links) {
429 - setTasks(links);
430 - startTime = System.currentTimeMillis(); // yes, this will start off inaccurate
431 - }
432 -
433 - @Override
434 - public void run() {
435 - if (flicker) {
436 - flicker();
437 - } else {
438 - refresh();
439 - }
440 - }
441 -
442 - private void flicker() {
443 - if ((!linkDriver.isShutdown() || !tasks.isEmpty())) {
444 - log.trace("next: {}, count: {}", next, counter);
445 - if (counter <= CHECK_DURATION * 1_000_000 / eventRate) {
446 - if (up) {
447 - providerService.linkDetected(tasks.get(next++));
448 - } else {
449 - providerService.linkVanished(tasks.get(next++));
450 - }
451 - if (next >= tasks.size()) {
452 - next = 0;
453 - up = !up;
454 - }
455 - counter++;
456 - } else {
457 - // log in WARN the effective load generation rate in events/sec, every 10 seconds
458 - effLoad = (float) (counter * 1000.0 / (System
459 - .currentTimeMillis() - startTime));
460 - log.warn("Effective Loading for thread is {} events/second",
461 - String.valueOf(effLoad));
462 - counter = 0L;
463 - startTime = System.currentTimeMillis();
464 - }
465 - linkDriver.schedule(this, eventRate, TimeUnit.MICROSECONDS);
466 - }
467 - }
468 -
469 - private void refresh() {
470 - if (!linkDriver.isShutdown() || !tasks.isEmpty()) {
471 - log.trace("iter {} refresh_links", counter);
472 -
473 - for (LinkDescription desc : tasks) {
474 - providerService.linkDetected(desc);
475 - log.info("iteration {}, {}", counter, desc);
476 - }
477 - counter++;
478 - linkDriver.schedule(this, REFRESH_RATE, TimeUnit.SECONDS);
479 - }
480 - }
481 -
482 - public void deviceRemoved(DeviceId did) {
483 - List<LinkDescription> rm = Lists.newArrayList();
484 - for (LinkDescription ld : tasks) {
485 - if (did.equals(ld.dst().deviceId())
486 - || (did.equals(ld.src().deviceId()))) {
487 - rm.add(ld);
488 - }
489 - }
490 - tasks.removeAll(rm);
491 - }
492 -
493 - public void setTasks(List<LinkDescription> links) {
494 - HashMultimap<ConnectPoint, ConnectPoint> nm = HashMultimap.create();
495 - List<LinkDescription> rm = Lists.newArrayList();
496 - links.forEach(v -> nm.put(v.src(), v.dst()));
497 - // remove and send linkVanished for stale links.
498 - for (LinkDescription l : tasks) {
499 - if (!nm.containsEntry(l.src(), l.dst())) {
500 - rm.add(l);
501 - }
502 - }
503 - tasks.clear();
504 - tasks.addAll(links);
505 - rm.forEach(l -> providerService.linkVanished(l));
506 - }
507 - }
508 -
509 -}
1 -/*
2 - * Copyright 2014-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 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.2.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 - <dependencies>
35 - <dependency>
36 - <groupId>org.osgi</groupId>
37 - <artifactId>org.osgi.compendium</artifactId>
38 - </dependency>
39 - </dependencies>
40 -
41 -</project>
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.provider.nil.packet.impl;
17 -
18 -import org.apache.felix.scr.annotations.Activate;
19 -import org.apache.felix.scr.annotations.Component;
20 -import org.apache.felix.scr.annotations.Deactivate;
21 -import org.apache.felix.scr.annotations.Modified;
22 -import org.apache.felix.scr.annotations.Property;
23 -import org.apache.felix.scr.annotations.Reference;
24 -import org.apache.felix.scr.annotations.ReferenceCardinality;
25 -import org.onlab.packet.Ethernet;
26 -import org.onlab.packet.ICMP;
27 -import org.onosproject.cfg.ComponentConfigService;
28 -import org.onosproject.net.ConnectPoint;
29 -import org.onosproject.net.Device;
30 -import org.onosproject.net.PortNumber;
31 -import org.onosproject.net.device.DeviceService;
32 -import org.onosproject.net.packet.DefaultInboundPacket;
33 -import org.onosproject.net.packet.DefaultPacketContext;
34 -import org.onosproject.net.packet.InboundPacket;
35 -import org.onosproject.net.packet.OutboundPacket;
36 -import org.onosproject.net.packet.PacketContext;
37 -import org.onosproject.net.packet.PacketProvider;
38 -import org.onosproject.net.packet.PacketProviderRegistry;
39 -import org.onosproject.net.packet.PacketProviderService;
40 -import org.onosproject.net.provider.AbstractProvider;
41 -import org.onosproject.net.provider.ProviderId;
42 -import org.osgi.service.component.ComponentContext;
43 -import org.slf4j.Logger;
44 -
45 -import java.nio.ByteBuffer;
46 -import java.util.Dictionary;
47 -import java.util.concurrent.ExecutorService;
48 -import java.util.concurrent.Executors;
49 -import java.util.concurrent.TimeUnit;
50 -
51 -import static com.google.common.base.Strings.isNullOrEmpty;
52 -import static org.onlab.util.Tools.delay;
53 -import static org.onlab.util.Tools.groupedThreads;
54 -import static org.slf4j.LoggerFactory.getLogger;
55 -
56 -/**
57 - * Provider which 1) intercepts network-bound messages from the core, and 2)
58 - * generates PacketEvents at some tunable rate. To be used for benchmarking
59 - * only.
60 - */
61 -@Component(immediate = true)
62 -public class NullPacketProvider extends AbstractProvider implements
63 - PacketProvider {
64 -
65 - private final Logger log = getLogger(getClass());
66 -
67 - // Default packetEvent generation rate (in packets/sec)
68 - // If 0, we are just a sink for network-bound packets
69 - private static final int DEFAULT_RATE = 5;
70 - // arbitrary host "destination"
71 - private static final int DESTHOST = 5;
72 -
73 - private PacketProviderService providerService;
74 -
75 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
76 - protected PacketProviderRegistry providerRegistry;
77 -
78 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
79 - protected DeviceService deviceService;
80 -
81 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
82 - protected ComponentConfigService cfgService;
83 -
84 - // Rate to generate PacketEvents, per second
85 - @Property(name = "pktRate", intValue = DEFAULT_RATE,
86 - label = "Rate of PacketEvent generation")
87 - private int pktRate = DEFAULT_RATE;
88 -
89 - private ExecutorService packetDriver =
90 - Executors.newFixedThreadPool(1, groupedThreads("onos/null", "packet-driver"));
91 -
92 - public NullPacketProvider() {
93 - super(new ProviderId("null", "org.onosproject.provider.nil"));
94 - }
95 -
96 - @Activate
97 - public void activate(ComponentContext context) {
98 - cfgService.registerProperties(getClass());
99 - providerService = providerRegistry.register(this);
100 - if (!modified(context)) {
101 - packetDriver.submit(new PacketDriver());
102 - }
103 - log.info("started");
104 - }
105 -
106 - @Deactivate
107 - public void deactivate(ComponentContext context) {
108 - cfgService.unregisterProperties(getClass(), false);
109 - try {
110 - packetDriver.awaitTermination(1000, TimeUnit.MILLISECONDS);
111 - } catch (InterruptedException e) {
112 - log.error("PacketDriver did not terminate");
113 - }
114 - packetDriver.shutdownNow();
115 - providerRegistry.unregister(this);
116 - log.info("stopped");
117 - }
118 -
119 - @Modified
120 - public boolean modified(ComponentContext context) {
121 - if (context == null) {
122 - log.info("No configuration change, using defaults: pktRate={}",
123 - DEFAULT_RATE);
124 - return false;
125 - }
126 - Dictionary<?, ?> properties = context.getProperties();
127 -
128 - int newRate;
129 - try {
130 - String s = String.valueOf(properties.get("pktRate"));
131 - newRate = isNullOrEmpty(s) ? pktRate : Integer.parseInt(s.trim());
132 - } catch (NumberFormatException | ClassCastException e) {
133 - log.warn(e.getMessage());
134 - newRate = pktRate;
135 - }
136 -
137 - if (newRate != pktRate) {
138 - pktRate = newRate;
139 - packetDriver.submit(new PacketDriver());
140 - log.info("Using new settings: pktRate={}", pktRate);
141 - return true;
142 - }
143 - return false;
144 - }
145 -
146 - @Override
147 - public void emit(OutboundPacket packet) {
148 - // We don't have a network to emit to. Keep a counter here, maybe?
149 - }
150 -
151 - /**
152 - * Generates packet events at a given rate.
153 - */
154 - private class PacketDriver implements Runnable {
155 -
156 - // time between event firing, in milliseconds
157 - int pktInterval;
158 - // filler echo request
159 - ICMP icmp;
160 - Ethernet eth;
161 -
162 - public PacketDriver() {
163 - pktInterval = 1000 / pktRate;
164 - icmp = new ICMP();
165 - icmp.setIcmpType((byte) 8).setIcmpCode((byte) 0)
166 - .setChecksum((short) 0);
167 - eth = new Ethernet();
168 - eth.setEtherType(Ethernet.TYPE_IPV4);
169 - eth.setPayload(icmp);
170 - }
171 -
172 - @Override
173 - public void run() {
174 - log.info("PacketDriver started");
175 - while (!packetDriver.isShutdown()) {
176 - for (Device dev : deviceService.getDevices()) {
177 - sendEvents(dev);
178 - }
179 - }
180 - }
181 -
182 - private void sendEvents(Device dev) {
183 - // make it look like things came from ports attached to hosts
184 - for (int i = 0; i < 4; i++) {
185 - eth.setSourceMACAddress("00:00:10:00:00:0" + i)
186 - .setDestinationMACAddress("00:00:10:00:00:0" + DESTHOST);
187 - InboundPacket inPkt = new DefaultInboundPacket(
188 - new ConnectPoint(dev.id(), PortNumber.portNumber(i)),
189 - eth, ByteBuffer.wrap(eth.serialize()));
190 - PacketContext pctx = new NullPacketContext(
191 - System.currentTimeMillis(), inPkt, null, false);
192 - providerService.processPacket(pctx);
193 - delay(pktInterval);
194 - }
195 - }
196 -
197 - }
198 -
199 - /**
200 - * Minimal PacketContext to make core + applications happy.
201 - */
202 - private class NullPacketContext extends DefaultPacketContext {
203 -
204 - public NullPacketContext(long time, InboundPacket inPkt,
205 - OutboundPacket outPkt, boolean block) {
206 - super(time, inPkt, outPkt, block);
207 - }
208 -
209 - @Override
210 - public void send() {
211 - // We don't send anything out.
212 - }
213 -
214 - }
215 -
216 -}
1 -/*
2 - * Copyright 2014-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 sends and brings packets to &amp; from oblivion.
19 - */
20 -package org.onosproject.provider.nil.packet.impl;
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
29 <artifactId>onos-null-provider</artifactId> 29 <artifactId>onos-null-provider</artifactId>
30 <packaging>bundle</packaging> 30 <packaging>bundle</packaging>
31 31
32 - <description>ONOS null protocol adapters</description> 32 + <description>Null southbound providers application</description>
33 33
34 <dependencies> 34 <dependencies>
35 <dependency> 35 <dependency>
......