Consolidating null providers and making them fully configurable and integrated w…
…ith the ConfigProvider to allow arbitrary topologies. Change-Id: I899e27a9771af4013a3ce6da7f683a4927ffb438
Showing
40 changed files
with
1393 additions
and
47 deletions
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.cli; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.console.completer.StringsCompleter; | ||
19 | + | ||
20 | +import java.util.List; | ||
21 | +import java.util.SortedSet; | ||
22 | + | ||
23 | +/** | ||
24 | + * Abstraction of a completer with preset choices. | ||
25 | + */ | ||
26 | +public abstract class AbstractChoicesCompleter extends AbstractCompleter { | ||
27 | + | ||
28 | + protected abstract List<String> choices(); | ||
29 | + | ||
30 | + @Override | ||
31 | + public int complete(String buffer, int cursor, List<String> candidates) { | ||
32 | + StringsCompleter delegate = new StringsCompleter(); | ||
33 | + SortedSet<String> strings = delegate.getStrings(); | ||
34 | + choices().forEach(strings::add); | ||
35 | + return delegate.complete(buffer, cursor, candidates); | ||
36 | + } | ||
37 | + | ||
38 | +} |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.cli.net; | 16 | +package org.onosproject.cli; |
17 | 17 | ||
18 | import org.apache.felix.service.command.CommandSession; | 18 | import org.apache.felix.service.command.CommandSession; |
19 | import org.apache.karaf.shell.console.CommandSessionHolder; | 19 | import org.apache.karaf.shell.console.CommandSessionHolder; | ... | ... |
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.cli; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableList; | ||
19 | + | ||
20 | +import java.util.List; | ||
21 | + | ||
22 | +/** | ||
23 | + * Start/stop command completer. | ||
24 | + */ | ||
25 | +public class StartStopCompleter extends AbstractChoicesCompleter { | ||
26 | + | ||
27 | + public static final String START = "start"; | ||
28 | + public static final String STOP = "stop"; | ||
29 | + | ||
30 | + @Override | ||
31 | + public List<String> choices() { | ||
32 | + return ImmutableList.of(START, STOP); | ||
33 | + } | ||
34 | +} |
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.cli; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableList; | ||
19 | + | ||
20 | +import java.util.List; | ||
21 | + | ||
22 | +/** | ||
23 | + * Up/down command completer. | ||
24 | + */ | ||
25 | +public class UpDownCompleter extends AbstractChoicesCompleter { | ||
26 | + | ||
27 | + public static final String UP = "up"; | ||
28 | + public static final String DOWN = "down"; | ||
29 | + | ||
30 | + @Override | ||
31 | + public List<String> choices() { | ||
32 | + return ImmutableList.of(UP, DOWN); | ||
33 | + } | ||
34 | +} |
... | @@ -15,30 +15,20 @@ | ... | @@ -15,30 +15,20 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.cli.app; | 16 | package org.onosproject.cli.app; |
17 | 17 | ||
18 | -import org.apache.karaf.shell.console.Completer; | 18 | +import com.google.common.collect.ImmutableList; |
19 | -import org.apache.karaf.shell.console.completer.StringsCompleter; | 19 | +import org.onosproject.cli.AbstractChoicesCompleter; |
20 | 20 | ||
21 | import java.util.List; | 21 | import java.util.List; |
22 | -import java.util.SortedSet; | ||
23 | 22 | ||
24 | import static org.onosproject.cli.app.ApplicationCommand.*; | 23 | import static org.onosproject.cli.app.ApplicationCommand.*; |
25 | 24 | ||
26 | /** | 25 | /** |
27 | - * Application name completer. | 26 | + * Application command completer. |
28 | */ | 27 | */ |
29 | -public class ApplicationCommandCompleter implements Completer { | 28 | +public class ApplicationCommandCompleter extends AbstractChoicesCompleter { |
30 | @Override | 29 | @Override |
31 | - public int complete(String buffer, int cursor, List<String> candidates) { | 30 | + public List<String> choices() { |
32 | - // Delegate string completer | 31 | + return ImmutableList.of(INSTALL, UNINSTALL, ACTIVATE, DEACTIVATE); |
33 | - StringsCompleter delegate = new StringsCompleter(); | ||
34 | - SortedSet<String> strings = delegate.getStrings(); | ||
35 | - strings.add(INSTALL); | ||
36 | - strings.add(UNINSTALL); | ||
37 | - strings.add(ACTIVATE); | ||
38 | - strings.add(DEACTIVATE); | ||
39 | - | ||
40 | - // Now let the completer do the work for figuring out what to offer. | ||
41 | - return delegate.complete(buffer, cursor, candidates); | ||
42 | } | 32 | } |
43 | 33 | ||
44 | } | 34 | } | ... | ... |
... | @@ -19,7 +19,7 @@ import org.apache.karaf.shell.console.completer.ArgumentCompleter; | ... | @@ -19,7 +19,7 @@ import org.apache.karaf.shell.console.completer.ArgumentCompleter; |
19 | import org.apache.karaf.shell.console.completer.StringsCompleter; | 19 | import org.apache.karaf.shell.console.completer.StringsCompleter; |
20 | import org.onosproject.app.ApplicationService; | 20 | import org.onosproject.app.ApplicationService; |
21 | import org.onosproject.app.ApplicationState; | 21 | import org.onosproject.app.ApplicationState; |
22 | -import org.onosproject.cli.net.AbstractCompleter; | 22 | +import org.onosproject.cli.AbstractCompleter; |
23 | import org.onosproject.core.Application; | 23 | import org.onosproject.core.Application; |
24 | 24 | ||
25 | import java.util.Iterator; | 25 | import java.util.Iterator; | ... | ... |
... | @@ -19,7 +19,7 @@ import org.apache.karaf.shell.console.completer.ArgumentCompleter; | ... | @@ -19,7 +19,7 @@ import org.apache.karaf.shell.console.completer.ArgumentCompleter; |
19 | import org.apache.karaf.shell.console.completer.StringsCompleter; | 19 | import org.apache.karaf.shell.console.completer.StringsCompleter; |
20 | import org.onosproject.cfg.ComponentConfigService; | 20 | import org.onosproject.cfg.ComponentConfigService; |
21 | import org.onosproject.cfg.ConfigProperty; | 21 | import org.onosproject.cfg.ConfigProperty; |
22 | -import org.onosproject.cli.net.AbstractCompleter; | 22 | +import org.onosproject.cli.AbstractCompleter; |
23 | 23 | ||
24 | import java.util.List; | 24 | import java.util.List; |
25 | import java.util.Set; | 25 | import java.util.Set; | ... | ... |
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.cli.net; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.console.completer.ArgumentCompleter; | ||
19 | +import org.apache.karaf.shell.console.completer.StringsCompleter; | ||
20 | +import org.onosproject.cli.AbstractCompleter; | ||
21 | +import org.onosproject.cli.AbstractShellCommand; | ||
22 | +import org.onosproject.net.ConnectPoint; | ||
23 | +import org.onosproject.net.link.LinkService; | ||
24 | + | ||
25 | +import java.util.List; | ||
26 | +import java.util.SortedSet; | ||
27 | + | ||
28 | +import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId; | ||
29 | +import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber; | ||
30 | +import static org.onosproject.net.DeviceId.deviceId; | ||
31 | +import static org.onosproject.net.PortNumber.portNumber; | ||
32 | + | ||
33 | +/** | ||
34 | + * Link end-point completer. | ||
35 | + */ | ||
36 | +public class LinkDstCompleter extends AbstractCompleter { | ||
37 | + @Override | ||
38 | + public int complete(String buffer, int cursor, List<String> candidates) { | ||
39 | + // Delegate string completer | ||
40 | + StringsCompleter delegate = new StringsCompleter(); | ||
41 | + | ||
42 | + // Fetch our service and feed it's offerings to the string completer | ||
43 | + LinkService service = AbstractShellCommand.get(LinkService.class); | ||
44 | + | ||
45 | + // Link source the previous argument. | ||
46 | + ArgumentCompleter.ArgumentList list = getArgumentList(); | ||
47 | + String srcArg = list.getArguments()[list.getCursorArgumentIndex() - 1]; | ||
48 | + | ||
49 | + // Generate the device ID/port number identifiers | ||
50 | + SortedSet<String> strings = delegate.getStrings(); | ||
51 | + try { | ||
52 | + ConnectPoint src = new ConnectPoint(deviceId(getDeviceId(srcArg)), | ||
53 | + portNumber(getPortNumber(srcArg))); | ||
54 | + service.getEgressLinks(src) | ||
55 | + .forEach(link -> strings.add(link.dst().elementId().toString() + | ||
56 | + "/" + link.dst().port())); | ||
57 | + } catch (NumberFormatException e) { | ||
58 | + System.err.println("Invalid connect-point"); | ||
59 | + } | ||
60 | + | ||
61 | + // Now let the completer do the work for figuring out what to offer. | ||
62 | + return delegate.complete(buffer, cursor, candidates); | ||
63 | + } | ||
64 | + | ||
65 | +} |
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.cli.net; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.console.completer.StringsCompleter; | ||
19 | +import org.onosproject.cli.AbstractCompleter; | ||
20 | +import org.onosproject.cli.AbstractShellCommand; | ||
21 | +import org.onosproject.net.link.LinkService; | ||
22 | + | ||
23 | +import java.util.List; | ||
24 | +import java.util.SortedSet; | ||
25 | + | ||
26 | +/** | ||
27 | + * Link end-point completer. | ||
28 | + */ | ||
29 | +public class LinkSrcCompleter extends AbstractCompleter { | ||
30 | + @Override | ||
31 | + public int complete(String buffer, int cursor, List<String> candidates) { | ||
32 | + // Delegate string completer | ||
33 | + StringsCompleter delegate = new StringsCompleter(); | ||
34 | + | ||
35 | + // Fetch our service and feed it's offerings to the string completer | ||
36 | + LinkService service = AbstractShellCommand.get(LinkService.class); | ||
37 | + | ||
38 | + // Generate the device ID/port number identifiers | ||
39 | + SortedSet<String> strings = delegate.getStrings(); | ||
40 | + service.getLinks() | ||
41 | + .forEach(link -> strings.add(link.src().elementId().toString() + | ||
42 | + "/" + link.src().port())); | ||
43 | + | ||
44 | + // Now let the completer do the work for figuring out what to offer. | ||
45 | + return delegate.complete(buffer, cursor, candidates); | ||
46 | + } | ||
47 | + | ||
48 | +} |
... | @@ -332,4 +332,7 @@ | ... | @@ -332,4 +332,7 @@ |
332 | <bean id="ipProtocolCompleter" class="org.onosproject.cli.net.IpProtocolCompleter"/> | 332 | <bean id="ipProtocolCompleter" class="org.onosproject.cli.net.IpProtocolCompleter"/> |
333 | <bean id="driverNameCompleter" class="org.onosproject.cli.net.DriverNameCompleter"/> | 333 | <bean id="driverNameCompleter" class="org.onosproject.cli.net.DriverNameCompleter"/> |
334 | 334 | ||
335 | + <bean id="startStopCompleter" class="org.onosproject.cli.StartStopCompleter"/> | ||
336 | + <bean id="upDownCompleter" class="org.onosproject.cli.UpDownCompleter"/> | ||
337 | + | ||
335 | </blueprint> | 338 | </blueprint> | ... | ... |
... | @@ -20,7 +20,7 @@ import org.onosproject.net.DeviceId; | ... | @@ -20,7 +20,7 @@ import org.onosproject.net.DeviceId; |
20 | /** | 20 | /** |
21 | * Service for administering the inventory of infrastructure devices. | 21 | * Service for administering the inventory of infrastructure devices. |
22 | */ | 22 | */ |
23 | -public interface DeviceAdminService { | 23 | +public interface DeviceAdminService extends DeviceService { |
24 | 24 | ||
25 | /** | 25 | /** |
26 | * Removes the device with the specified identifier. | 26 | * Removes the device with the specified identifier. | ... | ... |
... | @@ -21,7 +21,7 @@ import org.onosproject.net.HostId; | ... | @@ -21,7 +21,7 @@ import org.onosproject.net.HostId; |
21 | /** | 21 | /** |
22 | * Service for administering the inventory of end-station hosts. | 22 | * Service for administering the inventory of end-station hosts. |
23 | */ | 23 | */ |
24 | -public interface HostAdminService { | 24 | +public interface HostAdminService extends HostService { |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * Removes the end-station host with the specified identifier. | 27 | * Removes the end-station host with the specified identifier. | ... | ... |
... | @@ -21,7 +21,7 @@ import org.onosproject.net.DeviceId; | ... | @@ -21,7 +21,7 @@ import org.onosproject.net.DeviceId; |
21 | /** | 21 | /** |
22 | * Service for administering the inventory of infrastructure links. | 22 | * Service for administering the inventory of infrastructure links. |
23 | */ | 23 | */ |
24 | -public interface LinkAdminService { | 24 | +public interface LinkAdminService extends LinkService { |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * Removes all infrastructure links leading to and from the | 27 | * Removes all infrastructure links leading to and from the | ... | ... |
... | @@ -705,7 +705,8 @@ public class DistributedGroupStore | ... | @@ -705,7 +705,8 @@ public class DistributedGroupStore |
705 | remove(new GroupStoreKeyMapKey(deviceId, group.appCookie())); | 705 | remove(new GroupStoreKeyMapKey(deviceId, group.appCookie())); |
706 | } | 706 | } |
707 | } else { | 707 | } else { |
708 | - if (deviceAuditStatus.get(deviceId)) { | 708 | + Boolean audited = deviceAuditStatus.get(deviceId); |
709 | + if (audited != null && audited) { | ||
709 | log.debug("deviceInitialAuditCompleted: Clearing AUDIT " | 710 | log.debug("deviceInitialAuditCompleted: Clearing AUDIT " |
710 | + "status for device {}", deviceId); | 711 | + "status for device {}", deviceId); |
711 | deviceAuditStatus.put(deviceId, false); | 712 | deviceAuditStatus.put(deviceId, false); |
... | @@ -717,8 +718,8 @@ public class DistributedGroupStore | ... | @@ -717,8 +718,8 @@ public class DistributedGroupStore |
717 | @Override | 718 | @Override |
718 | public boolean deviceInitialAuditStatus(DeviceId deviceId) { | 719 | public boolean deviceInitialAuditStatus(DeviceId deviceId) { |
719 | synchronized (deviceAuditStatus) { | 720 | synchronized (deviceAuditStatus) { |
720 | - return (deviceAuditStatus.get(deviceId) != null) | 721 | + Boolean audited = deviceAuditStatus.get(deviceId); |
721 | - ? deviceAuditStatus.get(deviceId) : false; | 722 | + return audited != null && audited; |
722 | } | 723 | } |
723 | } | 724 | } |
724 | 725 | ... | ... |
... | @@ -79,7 +79,7 @@ | ... | @@ -79,7 +79,7 @@ |
79 | <group> | 79 | <group> |
80 | <title>Null Providers</title> | 80 | <title>Null Providers</title> |
81 | <packages> | 81 | <packages> |
82 | - org.onosproject.provider.nil.* | 82 | + org.onosproject.provider.nil:org.onosproject.provider.nil.* |
83 | </packages> | 83 | </packages> |
84 | </group> | 84 | </group> |
85 | <group> | 85 | <group> | ... | ... |
... | @@ -131,13 +131,7 @@ | ... | @@ -131,13 +131,7 @@ |
131 | <feature name="onos-null" version="@FEATURE-VERSION" | 131 | <feature name="onos-null" version="@FEATURE-VERSION" |
132 | description="ONOS Null providers"> | 132 | description="ONOS Null providers"> |
133 | <feature>onos-api</feature> | 133 | <feature>onos-api</feature> |
134 | - | 134 | + <bundle>mvn:org.onosproject/onos-null-provider/@ONOS-VERSION</bundle> |
135 | - <bundle>mvn:org.onosproject/onos-null-provider-device/@ONOS-VERSION</bundle> | ||
136 | - <bundle>mvn:org.onosproject/onos-null-provider-link/@ONOS-VERSION</bundle> | ||
137 | - <bundle>mvn:org.onosproject/onos-null-provider-host/@ONOS-VERSION</bundle> | ||
138 | - <bundle>mvn:org.onosproject/onos-null-provider-packet/@ONOS-VERSION</bundle> | ||
139 | - <bundle>mvn:org.onosproject/onos-null-provider-flow/@ONOS-VERSION</bundle> | ||
140 | - | ||
141 | </feature> | 135 | </feature> |
142 | 136 | ||
143 | <feature name="onos-openflow" version="@FEATURE-VERSION" | 137 | <feature name="onos-openflow" version="@FEATURE-VERSION" | ... | ... |
... | @@ -26,20 +26,25 @@ | ... | @@ -26,20 +26,25 @@ |
26 | <relativePath>../pom.xml</relativePath> | 26 | <relativePath>../pom.xml</relativePath> |
27 | </parent> | 27 | </parent> |
28 | 28 | ||
29 | - <artifactId>onos-null-providers</artifactId> | 29 | + <artifactId>onos-null-provider</artifactId> |
30 | - <packaging>pom</packaging> | 30 | + <packaging>bundle</packaging> |
31 | 31 | ||
32 | <description>ONOS null protocol adapters</description> | 32 | <description>ONOS null protocol adapters</description> |
33 | 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> | 34 | <dependencies> |
35 | + <dependency> | ||
36 | + <groupId>org.osgi</groupId> | ||
37 | + <artifactId>org.osgi.compendium</artifactId> | ||
38 | + </dependency> | ||
39 | + <dependency> | ||
40 | + <groupId>org.apache.karaf.shell</groupId> | ||
41 | + <artifactId>org.apache.karaf.shell.console</artifactId> | ||
42 | + </dependency> | ||
43 | + <dependency> | ||
44 | + <groupId>org.onosproject</groupId> | ||
45 | + <artifactId>onos-cli</artifactId> | ||
46 | + <version>${project.version}</version> | ||
47 | + </dependency> | ||
43 | 48 | ||
44 | <dependency> | 49 | <dependency> |
45 | <groupId>org.onosproject</groupId> | 50 | <groupId>org.onosproject</groupId> | ... | ... |
providers/null/src/main/java/org/onosproject/provider/nil/CentipedeTopologySimulator.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.provider.nil; | ||
17 | + | ||
18 | +/** | ||
19 | + * Linear topology with hosts on every device. | ||
20 | + */ | ||
21 | +public class CentipedeTopologySimulator extends LinearTopologySimulator { | ||
22 | + | ||
23 | + /** | ||
24 | + * Creates simulated hosts. | ||
25 | + */ | ||
26 | + protected void createHosts() { | ||
27 | + deviceIds.forEach(id -> createHosts(id, infrastructurePorts)); | ||
28 | + } | ||
29 | + | ||
30 | +} |
providers/null/src/main/java/org/onosproject/provider/nil/ConfiguredTopologySimulator.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.provider.nil; | ||
17 | + | ||
18 | +/** | ||
19 | + * Topology simulator which operates on topology configured via the REST API | ||
20 | + * config service. | ||
21 | + */ | ||
22 | +public class ConfiguredTopologySimulator extends TopologySimulator { | ||
23 | + | ||
24 | + @Override | ||
25 | + protected void createDevices() { | ||
26 | + deviceService.getDevices() | ||
27 | + .forEach(device -> deviceProviderService | ||
28 | + .deviceConnected(device.id(), description(device))); | ||
29 | + } | ||
30 | + | ||
31 | + @Override | ||
32 | + protected void createLinks() { | ||
33 | + linkService.getLinks() | ||
34 | + .forEach(link -> linkProviderService | ||
35 | + .linkDetected(description(link))); | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + protected void createHosts() { | ||
40 | + hostService.getHosts() | ||
41 | + .forEach(host -> hostProviderService | ||
42 | + .hostDetected(host.id(), description(host))); | ||
43 | + } | ||
44 | +} |
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; | ||
17 | + | ||
18 | +import static com.google.common.base.Preconditions.checkArgument; | ||
19 | + | ||
20 | +/** | ||
21 | + * Linear topology simulator. | ||
22 | + */ | ||
23 | +public class LinearTopologySimulator extends TopologySimulator { | ||
24 | + | ||
25 | + @Override | ||
26 | + protected void processTopoShape(String shape) { | ||
27 | + super.processTopoShape(shape); | ||
28 | + deviceCount = (topoShape.length == 1) ? deviceCount : Integer.parseInt(topoShape[1]); | ||
29 | + } | ||
30 | + | ||
31 | + @Override | ||
32 | + public void setUpTopology() { | ||
33 | + checkArgument(deviceCount > 1, "There must be at least 2 devices"); | ||
34 | + | ||
35 | + prepareForDeviceEvents(deviceCount); | ||
36 | + createDevices(); | ||
37 | + waitForDeviceEvents(); | ||
38 | + | ||
39 | + createLinks(); | ||
40 | + createHosts(); | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + protected void createLinks() { | ||
45 | + for (int i = 0, n = deviceCount - 1; i < n; i++) { | ||
46 | + createLink(i, i + 1); | ||
47 | + } | ||
48 | + } | ||
49 | + | ||
50 | + @Override | ||
51 | + protected void createHosts() { | ||
52 | + createHosts(deviceIds.get(0), infrastructurePorts); | ||
53 | + createHosts(deviceIds.get(deviceCount - 1), infrastructurePorts); | ||
54 | + } | ||
55 | + | ||
56 | +} |
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; | ||
17 | + | ||
18 | +/** | ||
19 | + * Full mesh topology with hosts at each device. | ||
20 | + */ | ||
21 | +public class MeshTopologySimulator extends TopologySimulator { | ||
22 | + | ||
23 | + @Override | ||
24 | + protected void processTopoShape(String shape) { | ||
25 | + super.processTopoShape(shape); | ||
26 | + // FIXME: implement this | ||
27 | + } | ||
28 | + | ||
29 | + @Override | ||
30 | + public void setUpTopology() { | ||
31 | + // FIXME: implement this | ||
32 | + // checkArgument(FIXME, "There must be at least ..."); | ||
33 | + super.setUpTopology(); | ||
34 | + } | ||
35 | + | ||
36 | + @Override | ||
37 | + protected void createLinks() { | ||
38 | + } | ||
39 | + | ||
40 | + @Override | ||
41 | + protected void createHosts() { | ||
42 | + } | ||
43 | + | ||
44 | +} |
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; | ||
17 | + | ||
18 | +import com.google.common.collect.Sets; | ||
19 | +import org.jboss.netty.util.HashedWheelTimer; | ||
20 | +import org.jboss.netty.util.Timeout; | ||
21 | +import org.jboss.netty.util.TimerTask; | ||
22 | +import org.onlab.util.Timer; | ||
23 | +import org.onosproject.core.ApplicationId; | ||
24 | +import org.onosproject.net.DeviceId; | ||
25 | +import org.onosproject.net.flow.CompletedBatchOperation; | ||
26 | +import org.onosproject.net.flow.DefaultFlowEntry; | ||
27 | +import org.onosproject.net.flow.FlowEntry; | ||
28 | +import org.onosproject.net.flow.FlowRule; | ||
29 | +import org.onosproject.net.flow.FlowRuleBatchEntry; | ||
30 | +import org.onosproject.net.flow.FlowRuleBatchOperation; | ||
31 | +import org.onosproject.net.flow.FlowRuleProvider; | ||
32 | +import org.onosproject.net.flow.FlowRuleProviderService; | ||
33 | +import org.slf4j.Logger; | ||
34 | + | ||
35 | +import java.util.Collections; | ||
36 | +import java.util.Set; | ||
37 | +import java.util.concurrent.ConcurrentHashMap; | ||
38 | +import java.util.concurrent.ConcurrentMap; | ||
39 | +import java.util.concurrent.TimeUnit; | ||
40 | + | ||
41 | +import static org.slf4j.LoggerFactory.getLogger; | ||
42 | + | ||
43 | +/** | ||
44 | + * Null provider to accept any flow and report them. | ||
45 | + */ | ||
46 | +class NullFlowRuleProvider extends NullProviders.AbstractNullProvider | ||
47 | + implements FlowRuleProvider { | ||
48 | + | ||
49 | + private final Logger log = getLogger(getClass()); | ||
50 | + | ||
51 | + private ConcurrentMap<DeviceId, Set<FlowEntry>> flowTable = new ConcurrentHashMap<>(); | ||
52 | + | ||
53 | + private FlowRuleProviderService providerService; | ||
54 | + | ||
55 | + private HashedWheelTimer timer = Timer.getTimer(); | ||
56 | + private Timeout timeout; | ||
57 | + | ||
58 | + /** | ||
59 | + * Starts the flow rule provider simulation. | ||
60 | + * | ||
61 | + * @param providerService flow rule provider service | ||
62 | + */ | ||
63 | + void start(FlowRuleProviderService providerService) { | ||
64 | + this.providerService = providerService; | ||
65 | + timeout = timer.newTimeout(new StatisticTask(), 5, TimeUnit.SECONDS); | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * Stops the flow rule provider simulation. | ||
70 | + */ | ||
71 | + void stop() { | ||
72 | + timeout.cancel(); | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public void applyFlowRule(FlowRule... flowRules) { | ||
77 | + // FIXME: invoke executeBatch | ||
78 | + } | ||
79 | + | ||
80 | + @Override | ||
81 | + public void removeFlowRule(FlowRule... flowRules) { | ||
82 | + // FIXME: invoke executeBatch | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + public void removeRulesById(ApplicationId id, FlowRule... flowRules) { | ||
87 | + throw new UnsupportedOperationException("Cannot remove by appId from null provider"); | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public void executeBatch(FlowRuleBatchOperation batch) { | ||
92 | + // TODO: consider checking mastership | ||
93 | + Set<FlowEntry> entries = | ||
94 | + flowTable.getOrDefault(batch.deviceId(), | ||
95 | + Sets.newConcurrentHashSet()); | ||
96 | + for (FlowRuleBatchEntry fbe : batch.getOperations()) { | ||
97 | + switch (fbe.operator()) { | ||
98 | + case ADD: | ||
99 | + entries.add(new DefaultFlowEntry(fbe.target())); | ||
100 | + break; | ||
101 | + case REMOVE: | ||
102 | + entries.remove(new DefaultFlowEntry(fbe.target())); | ||
103 | + break; | ||
104 | + case MODIFY: | ||
105 | + FlowEntry entry = new DefaultFlowEntry(fbe.target()); | ||
106 | + entries.remove(entry); | ||
107 | + entries.add(entry); | ||
108 | + break; | ||
109 | + default: | ||
110 | + log.error("Unknown flow operation: {}", fbe); | ||
111 | + } | ||
112 | + } | ||
113 | + flowTable.put(batch.deviceId(), entries); | ||
114 | + CompletedBatchOperation op = | ||
115 | + new CompletedBatchOperation(true, Collections.emptySet(), | ||
116 | + batch.deviceId()); | ||
117 | + providerService.batchOperationCompleted(batch.id(), op); | ||
118 | + } | ||
119 | + | ||
120 | + // Periodically reports flow rule statistics. | ||
121 | + private class StatisticTask implements TimerTask { | ||
122 | + @Override | ||
123 | + public void run(Timeout to) throws Exception { | ||
124 | + for (DeviceId devId : flowTable.keySet()) { | ||
125 | + Set<FlowEntry> entries = | ||
126 | + flowTable.getOrDefault(devId, Collections.emptySet()); | ||
127 | + providerService.pushFlowMetrics(devId, entries); | ||
128 | + } | ||
129 | + timeout = timer.newTimeout(to.getTask(), 5, TimeUnit.SECONDS); | ||
130 | + } | ||
131 | + } | ||
132 | +} |
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; | ||
17 | + | ||
18 | +import org.jboss.netty.util.HashedWheelTimer; | ||
19 | +import org.jboss.netty.util.Timeout; | ||
20 | +import org.jboss.netty.util.TimerTask; | ||
21 | +import org.onlab.packet.Ethernet; | ||
22 | +import org.onlab.packet.ICMP; | ||
23 | +import org.onlab.util.Timer; | ||
24 | +import org.onosproject.net.ConnectPoint; | ||
25 | +import org.onosproject.net.Device; | ||
26 | +import org.onosproject.net.PortNumber; | ||
27 | +import org.onosproject.net.device.DeviceAdminService; | ||
28 | +import org.onosproject.net.host.HostService; | ||
29 | +import org.onosproject.net.packet.DefaultInboundPacket; | ||
30 | +import org.onosproject.net.packet.DefaultPacketContext; | ||
31 | +import org.onosproject.net.packet.InboundPacket; | ||
32 | +import org.onosproject.net.packet.OutboundPacket; | ||
33 | +import org.onosproject.net.packet.PacketProvider; | ||
34 | +import org.onosproject.net.packet.PacketProviderService; | ||
35 | +import org.slf4j.Logger; | ||
36 | + | ||
37 | +import java.nio.ByteBuffer; | ||
38 | +import java.util.List; | ||
39 | +import java.util.concurrent.TimeUnit; | ||
40 | +import java.util.stream.Collectors; | ||
41 | + | ||
42 | +import static com.google.common.collect.ImmutableList.copyOf; | ||
43 | +import static java.util.concurrent.TimeUnit.SECONDS; | ||
44 | +import static org.onosproject.net.MastershipRole.MASTER; | ||
45 | +import static org.slf4j.LoggerFactory.getLogger; | ||
46 | + | ||
47 | +/** | ||
48 | + * Provider which generates simulated packets and acts as a sink for outbound | ||
49 | + * packets. To be used for benchmarking only. | ||
50 | + */ | ||
51 | +class NullPacketProvider extends NullProviders.AbstractNullProvider | ||
52 | + implements PacketProvider { | ||
53 | + | ||
54 | + private static final int INITIAL_DELAY = 5; | ||
55 | + private final Logger log = getLogger(getClass()); | ||
56 | + | ||
57 | + // Arbitrary host src/dst | ||
58 | + private static final int SRC_HOST = 2; | ||
59 | + private static final int DST_HOST = 5; | ||
60 | + | ||
61 | + // Time between event firing, in milliseconds | ||
62 | + private int delay; | ||
63 | + | ||
64 | + // TODO: use host service to pick legitimate hosts connected to devices | ||
65 | + private HostService hostService; | ||
66 | + private PacketProviderService providerService; | ||
67 | + | ||
68 | + private List<Device> devices; | ||
69 | + private int currentDevice = 0; | ||
70 | + | ||
71 | + private HashedWheelTimer timer = Timer.getTimer(); | ||
72 | + private Timeout timeout; | ||
73 | + | ||
74 | + /** | ||
75 | + * Starts the packet generation process. | ||
76 | + * | ||
77 | + * @param packetRate packets per second | ||
78 | + * @param hostService host service | ||
79 | + * @param deviceService device service | ||
80 | + * @param providerService packet provider service | ||
81 | + */ | ||
82 | + void start(int packetRate, HostService hostService, | ||
83 | + DeviceAdminService deviceService, | ||
84 | + PacketProviderService providerService) { | ||
85 | + this.hostService = hostService; | ||
86 | + this.providerService = providerService; | ||
87 | + | ||
88 | + this.devices = copyOf(deviceService.getDevices()).stream() | ||
89 | + .filter(d -> deviceService.getRole(d.id()) == MASTER) | ||
90 | + .collect(Collectors.toList()); | ||
91 | + | ||
92 | + adjustRate(packetRate); | ||
93 | + timeout = timer.newTimeout(new PacketDriverTask(), INITIAL_DELAY, SECONDS); | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Adjusts packet rate. | ||
98 | + * | ||
99 | + * @param packetRate new packet rate | ||
100 | + */ | ||
101 | + void adjustRate(int packetRate) { | ||
102 | + delay = 1000 / packetRate; | ||
103 | + log.info("Settings: packetRate={}, delay={}", packetRate, delay); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Stops the packet generation process. | ||
108 | + */ | ||
109 | + void stop() { | ||
110 | + if (timeout != null) { | ||
111 | + timeout.cancel(); | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
115 | + @Override | ||
116 | + public void emit(OutboundPacket packet) { | ||
117 | + // We don't have a network to emit to. Keep a counter here, maybe? | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * Generates packet events at a given rate. | ||
122 | + */ | ||
123 | + private class PacketDriverTask implements TimerTask { | ||
124 | + | ||
125 | + // Filler echo request | ||
126 | + ICMP icmp; | ||
127 | + Ethernet eth; | ||
128 | + | ||
129 | + public PacketDriverTask() { | ||
130 | + icmp = new ICMP(); | ||
131 | + icmp.setIcmpType((byte) 8).setIcmpCode((byte) 0).setChecksum((short) 0); | ||
132 | + eth = new Ethernet(); | ||
133 | + eth.setEtherType(Ethernet.TYPE_IPV4); | ||
134 | + eth.setPayload(icmp); | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
138 | + public void run(Timeout to) { | ||
139 | + if (!devices.isEmpty()) { | ||
140 | + sendEvent(devices.get(currentDevice)); | ||
141 | + currentDevice = (currentDevice + 1) % devices.size(); | ||
142 | + timeout = timer.newTimeout(to.getTask(), delay, TimeUnit.MILLISECONDS); | ||
143 | + } | ||
144 | + } | ||
145 | + | ||
146 | + private void sendEvent(Device device) { | ||
147 | + // Make it look like things came from ports attached to hosts | ||
148 | + eth.setSourceMACAddress("00:00:10:00:00:0" + SRC_HOST) | ||
149 | + .setDestinationMACAddress("00:00:10:00:00:0" + DST_HOST); | ||
150 | + InboundPacket inPkt = new DefaultInboundPacket( | ||
151 | + new ConnectPoint(device.id(), PortNumber.portNumber(SRC_HOST)), | ||
152 | + eth, ByteBuffer.wrap(eth.serialize())); | ||
153 | + providerService.processPacket(new NullPacketContext(inPkt, null)); | ||
154 | + } | ||
155 | + } | ||
156 | + | ||
157 | + // Minimal PacketContext to make core and applications happy. | ||
158 | + private final class NullPacketContext extends DefaultPacketContext { | ||
159 | + private NullPacketContext(InboundPacket inPkt, OutboundPacket outPkt) { | ||
160 | + super(System.currentTimeMillis(), inPkt, outPkt, false); | ||
161 | + } | ||
162 | + | ||
163 | + @Override | ||
164 | + public void send() { | ||
165 | + // We don't send anything out. | ||
166 | + } | ||
167 | + } | ||
168 | + | ||
169 | +} |
This diff is collapsed. Click to expand it.
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; | ||
17 | + | ||
18 | +import static com.google.common.base.Preconditions.checkArgument; | ||
19 | + | ||
20 | +/** | ||
21 | + * Re-routable linear topology simulator with an alternate path in the middle. | ||
22 | + */ | ||
23 | +public class RerouteTopologySimulator extends LinearTopologySimulator { | ||
24 | + | ||
25 | + @Override | ||
26 | + protected void processTopoShape(String shape) { | ||
27 | + super.processTopoShape(shape); | ||
28 | + infrastructurePorts = 3; | ||
29 | + deviceCount = (topoShape.length == 1) ? deviceCount : Integer.parseInt(topoShape[1]); | ||
30 | + } | ||
31 | + | ||
32 | + @Override | ||
33 | + public void setUpTopology() { | ||
34 | + checkArgument(deviceCount > 2, "There must be at least 3 devices"); | ||
35 | + super.setUpTopology(); | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + protected void createLinks() { | ||
40 | + for (int i = 0, n = deviceCount - 2; i < n; i++) { | ||
41 | + createLink(i, i + 1); | ||
42 | + } | ||
43 | + int middle = (deviceCount - 1) / 2; | ||
44 | + int alternate = deviceCount - 1; | ||
45 | + createLink(middle - 1, alternate); | ||
46 | + createLink(middle, alternate); | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + protected void createHosts() { | ||
51 | + createHosts(deviceIds.get(0), infrastructurePorts); | ||
52 | + createHosts(deviceIds.get(deviceCount - 2), infrastructurePorts); | ||
53 | + } | ||
54 | + | ||
55 | +} |
providers/null/src/main/java/org/onosproject/provider/nil/SpineLeafTopologySimulator.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.provider.nil; | ||
17 | + | ||
18 | +/** | ||
19 | + * Spine-leaf topology with hosts at the leaf devices. | ||
20 | + */ | ||
21 | +public class SpineLeafTopologySimulator extends TopologySimulator { | ||
22 | + | ||
23 | + @Override | ||
24 | + protected void processTopoShape(String shape) { | ||
25 | + super.processTopoShape(shape); | ||
26 | + // FIXME: implement this | ||
27 | + } | ||
28 | + | ||
29 | + @Override | ||
30 | + public void setUpTopology() { | ||
31 | + // checkArgument(FIXME, "There must be at least one spine tier"); | ||
32 | + super.setUpTopology(); | ||
33 | + } | ||
34 | + | ||
35 | + @Override | ||
36 | + protected void createLinks() { | ||
37 | + } | ||
38 | + | ||
39 | + @Override | ||
40 | + protected void createHosts() { | ||
41 | + } | ||
42 | + | ||
43 | +} |
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; | ||
17 | + | ||
18 | +import com.google.common.collect.Lists; | ||
19 | +import org.onosproject.net.ConnectPoint; | ||
20 | +import org.onosproject.net.device.DeviceService; | ||
21 | +import org.onosproject.net.link.DefaultLinkDescription; | ||
22 | +import org.onosproject.net.link.LinkDescription; | ||
23 | +import org.onosproject.net.link.LinkProviderService; | ||
24 | +import org.onosproject.net.link.LinkService; | ||
25 | +import org.slf4j.Logger; | ||
26 | +import org.slf4j.LoggerFactory; | ||
27 | + | ||
28 | +import java.util.List; | ||
29 | +import java.util.Random; | ||
30 | +import java.util.concurrent.ExecutorService; | ||
31 | +import java.util.stream.Collectors; | ||
32 | + | ||
33 | +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
34 | +import static org.onlab.util.Tools.delay; | ||
35 | +import static org.onlab.util.Tools.groupedThreads; | ||
36 | +import static org.onosproject.net.Link.Type.DIRECT; | ||
37 | +import static org.onosproject.net.MastershipRole.MASTER; | ||
38 | +import static org.onosproject.provider.nil.TopologySimulator.description; | ||
39 | + | ||
40 | +/** | ||
41 | + * Drives topology mutations at a specified rate of events per second. | ||
42 | + */ | ||
43 | +class TopologyMutationDriver implements Runnable { | ||
44 | + | ||
45 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
46 | + | ||
47 | + private static final int WAIT_DELAY = 2_000; | ||
48 | + private static final int MAX_DOWN_LINKS = 5; | ||
49 | + | ||
50 | + private final Random random = new Random(); | ||
51 | + | ||
52 | + private volatile boolean stopped = true; | ||
53 | + | ||
54 | + private double mutationRate; | ||
55 | + private int millis, nanos; | ||
56 | + | ||
57 | + private LinkService linkService; | ||
58 | + private DeviceService deviceService; | ||
59 | + private LinkProviderService linkProviderService; | ||
60 | + | ||
61 | + private List<LinkDescription> activeLinks; | ||
62 | + private List<LinkDescription> inactiveLinks; | ||
63 | + | ||
64 | + private final ExecutorService executor = | ||
65 | + newSingleThreadScheduledExecutor(groupedThreads("onos/null", "topo-mutator")); | ||
66 | + | ||
67 | + /** | ||
68 | + * Starts the mutation process. | ||
69 | + * | ||
70 | + * @param mutationRate link events per second | ||
71 | + * @param linkService link service | ||
72 | + * @param deviceService device service | ||
73 | + * @param linkProviderService link provider service | ||
74 | + */ | ||
75 | + void start(double mutationRate, | ||
76 | + LinkService linkService, DeviceService deviceService, | ||
77 | + LinkProviderService linkProviderService) { | ||
78 | + stopped = false; | ||
79 | + this.linkService = linkService; | ||
80 | + this.deviceService = deviceService; | ||
81 | + this.linkProviderService = linkProviderService; | ||
82 | + activeLinks = reduceLinks(); | ||
83 | + inactiveLinks = Lists.newArrayList(); | ||
84 | + adjustRate(mutationRate); | ||
85 | + executor.submit(this); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Adjusts the topology mutation rate. | ||
90 | + * | ||
91 | + * @param mutationRate new topology mutation rate | ||
92 | + */ | ||
93 | + void adjustRate(double mutationRate) { | ||
94 | + this.mutationRate = mutationRate; | ||
95 | + if (mutationRate > 0) { | ||
96 | + this.millis = (int) (1_000 / mutationRate / 2); | ||
97 | + this.nanos = (int) (1_000_000 / mutationRate / 2) % 1_000_000; | ||
98 | + } else { | ||
99 | + this.millis = 0; | ||
100 | + this.nanos = 0; | ||
101 | + } | ||
102 | + log.info("Settings: millis={}, nanos={}", millis, nanos); | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * Stops the mutation process. | ||
107 | + */ | ||
108 | + void stop() { | ||
109 | + stopped = true; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * Severs the link between the specified end-points in both directions. | ||
114 | + * | ||
115 | + * @param one link endpoint | ||
116 | + * @param two link endpoint | ||
117 | + */ | ||
118 | + void severLink(ConnectPoint one, ConnectPoint two) { | ||
119 | + LinkDescription link = new DefaultLinkDescription(one, two, DIRECT); | ||
120 | + linkProviderService.linkVanished(link); | ||
121 | + linkProviderService.linkVanished(reverse(link)); | ||
122 | + | ||
123 | + } | ||
124 | + | ||
125 | + /** | ||
126 | + * Repairs the link between the specified end-points in both directions. | ||
127 | + * | ||
128 | + * @param one link endpoint | ||
129 | + * @param two link endpoint | ||
130 | + */ | ||
131 | + void repairLink(ConnectPoint one, ConnectPoint two) { | ||
132 | + LinkDescription link = new DefaultLinkDescription(one, two, DIRECT); | ||
133 | + linkProviderService.linkDetected(link); | ||
134 | + linkProviderService.linkDetected(reverse(link)); | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
138 | + public void run() { | ||
139 | + delay(WAIT_DELAY); | ||
140 | + | ||
141 | + while (!stopped) { | ||
142 | + if (mutationRate > 0 && inactiveLinks.isEmpty()) { | ||
143 | + primeInactiveLinks(); | ||
144 | + } else if (mutationRate <= 0 && !inactiveLinks.isEmpty()) { | ||
145 | + repairInactiveLinks(); | ||
146 | + } else if (inactiveLinks.isEmpty()) { | ||
147 | + delay(WAIT_DELAY); | ||
148 | + | ||
149 | + } else { | ||
150 | + activeLinks.add(repairLink()); | ||
151 | + pause(); | ||
152 | + inactiveLinks.add(severLink()); | ||
153 | + pause(); | ||
154 | + } | ||
155 | + } | ||
156 | + } | ||
157 | + | ||
158 | + // Primes the inactive links with a few random links. | ||
159 | + private void primeInactiveLinks() { | ||
160 | + for (int i = 0, n = Math.min(MAX_DOWN_LINKS, activeLinks.size()); i < n; i++) { | ||
161 | + inactiveLinks.add(severLink()); | ||
162 | + } | ||
163 | + } | ||
164 | + | ||
165 | + // Repairs all inactive links. | ||
166 | + private void repairInactiveLinks() { | ||
167 | + while (!inactiveLinks.isEmpty()) { | ||
168 | + repairLink(); | ||
169 | + } | ||
170 | + } | ||
171 | + | ||
172 | + // Picks a random active link and severs it. | ||
173 | + private LinkDescription severLink() { | ||
174 | + LinkDescription link = getRandomLink(activeLinks); | ||
175 | + linkProviderService.linkVanished(link); | ||
176 | + linkProviderService.linkVanished(reverse(link)); | ||
177 | + return link; | ||
178 | + } | ||
179 | + | ||
180 | + // Picks a random inactive link and repairs it. | ||
181 | + private LinkDescription repairLink() { | ||
182 | + LinkDescription link = getRandomLink(inactiveLinks); | ||
183 | + linkProviderService.linkDetected(link); | ||
184 | + linkProviderService.linkDetected(reverse(link)); | ||
185 | + return link; | ||
186 | + } | ||
187 | + | ||
188 | + // Produces a reverse of the specified link. | ||
189 | + private LinkDescription reverse(LinkDescription link) { | ||
190 | + return new DefaultLinkDescription(link.dst(), link.src(), link.type()); | ||
191 | + } | ||
192 | + | ||
193 | + // Returns a random link from the specified list of links. | ||
194 | + private LinkDescription getRandomLink(List<LinkDescription> links) { | ||
195 | + return links.remove(random.nextInt(links.size())); | ||
196 | + } | ||
197 | + | ||
198 | + // Reduces the given list of links to just a single link in each original pair. | ||
199 | + private List<LinkDescription> reduceLinks() { | ||
200 | + List<LinkDescription> links = Lists.newArrayList(); | ||
201 | + linkService.getLinks().forEach(link -> links.add(description(link))); | ||
202 | + return links.stream() | ||
203 | + .filter(this::isOurLink) | ||
204 | + .filter(this::isRightDirection) | ||
205 | + .collect(Collectors.toList()); | ||
206 | + } | ||
207 | + | ||
208 | + // Returns true if the specified link is ours. | ||
209 | + private boolean isOurLink(LinkDescription linkDescription) { | ||
210 | + return deviceService.getRole(linkDescription.src().deviceId()) == MASTER; | ||
211 | + } | ||
212 | + | ||
213 | + // Returns true if the link source is greater than the link destination. | ||
214 | + private boolean isRightDirection(LinkDescription link) { | ||
215 | + return link.src().deviceId().toString().compareTo(link.dst().deviceId().toString()) > 0; | ||
216 | + } | ||
217 | + | ||
218 | + // Pauses the current thread for the pre-computed time of millis & nanos. | ||
219 | + private void pause() { | ||
220 | + delay(millis, nanos); | ||
221 | + } | ||
222 | + | ||
223 | +} |
This diff is collapsed. Click to expand it.
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; | ||
17 | + | ||
18 | +import static com.google.common.base.Preconditions.checkArgument; | ||
19 | + | ||
20 | +/** | ||
21 | + * Tree topology with hosts at the leaf devices. | ||
22 | + */ | ||
23 | +public class TreeTopologySimulator extends TopologySimulator { | ||
24 | + | ||
25 | + private int[] tierMultiplier; | ||
26 | + private int[] tierDeviceCount; | ||
27 | + private int[] tierOffset; | ||
28 | + | ||
29 | + @Override | ||
30 | + protected void processTopoShape(String shape) { | ||
31 | + super.processTopoShape(shape); | ||
32 | + tierOffset = new int[topoShape.length]; | ||
33 | + tierMultiplier = new int[topoShape.length]; | ||
34 | + tierDeviceCount = new int[topoShape.length]; | ||
35 | + | ||
36 | + deviceCount = 1; | ||
37 | + | ||
38 | + tierOffset[0] = 0; | ||
39 | + tierMultiplier[0] = 1; | ||
40 | + tierDeviceCount[0] = deviceCount; | ||
41 | + | ||
42 | + for (int i = 1; i < topoShape.length; i++) { | ||
43 | + tierOffset[i] = deviceCount; | ||
44 | + tierMultiplier[i] = Integer.parseInt(topoShape[i]); | ||
45 | + tierDeviceCount[i] = tierDeviceCount[i - 1] * tierMultiplier[i]; | ||
46 | + deviceCount = deviceCount + tierDeviceCount[i]; | ||
47 | + } | ||
48 | + } | ||
49 | + | ||
50 | + @Override | ||
51 | + public void setUpTopology() { | ||
52 | + checkArgument(tierDeviceCount.length > 0, "There must be at least one tree tier"); | ||
53 | + super.setUpTopology(); | ||
54 | + } | ||
55 | + | ||
56 | + @Override | ||
57 | + protected void createLinks() { | ||
58 | + for (int t = 1; t < tierOffset.length; t++) { | ||
59 | + int child = tierOffset[t]; | ||
60 | + for (int parent = tierOffset[t - 1]; parent < tierOffset[t]; parent++) { | ||
61 | + for (int i = 0; i < tierMultiplier[t]; i++) { | ||
62 | + createLink(parent, child); | ||
63 | + child++; | ||
64 | + } | ||
65 | + } | ||
66 | + } | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + protected void createHosts() { | ||
71 | + for (int i = tierOffset[tierOffset.length - 1]; i < deviceCount; i++) { | ||
72 | + createHosts(deviceIds.get(i), hostCount); | ||
73 | + } | ||
74 | + } | ||
75 | +} |
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.cli; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Argument; | ||
19 | +import org.apache.karaf.shell.commands.Command; | ||
20 | +import org.onosproject.cfg.ComponentConfigService; | ||
21 | +import org.onosproject.cli.AbstractShellCommand; | ||
22 | +import org.onosproject.provider.nil.NullProviders; | ||
23 | + | ||
24 | +import static org.onosproject.cli.StartStopCompleter.START; | ||
25 | + | ||
26 | +/** | ||
27 | + * Starts or stops topology simulation. | ||
28 | + */ | ||
29 | +@Command(scope = "onos", name = "null-simulation", | ||
30 | + description = "Starts or stops topology simulation") | ||
31 | +public class NullControlCommand extends AbstractShellCommand { | ||
32 | + | ||
33 | + @Argument(index = 0, name = "cmd", description = "Control command: start/stop", | ||
34 | + required = true, multiValued = false) | ||
35 | + String cmd = null; | ||
36 | + | ||
37 | + @Argument(index = 1, name = "topoShape", | ||
38 | + description = "Topology shape: e.g. configured, linear, reroute, centipede, tree, spineleaf, mesh", | ||
39 | + required = false, multiValued = false) | ||
40 | + String topoShape = null; | ||
41 | + | ||
42 | + @Override | ||
43 | + protected void execute() { | ||
44 | + ComponentConfigService service = get(ComponentConfigService.class); | ||
45 | + if (topoShape != null) { | ||
46 | + service.setProperty(NullProviders.class.getName(), "topoShape", topoShape); | ||
47 | + } | ||
48 | + service.setProperty(NullProviders.class.getName(), "enabled", | ||
49 | + cmd.equals(START) ? "true" : "false"); | ||
50 | + } | ||
51 | + | ||
52 | +} |
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.cli; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Argument; | ||
19 | +import org.apache.karaf.shell.commands.Command; | ||
20 | +import org.onosproject.cli.AbstractShellCommand; | ||
21 | +import org.onosproject.net.ConnectPoint; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | +import org.onosproject.net.PortNumber; | ||
24 | +import org.onosproject.provider.nil.NullProviders; | ||
25 | + | ||
26 | +import static org.onosproject.cli.UpDownCompleter.DOWN; | ||
27 | +import static org.onosproject.cli.UpDownCompleter.UP; | ||
28 | +import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId; | ||
29 | +import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber; | ||
30 | +import static org.onosproject.net.DeviceId.deviceId; | ||
31 | +import static org.onosproject.net.PortNumber.portNumber; | ||
32 | + | ||
33 | +/** | ||
34 | + * Servers or repairs a simulated link. | ||
35 | + */ | ||
36 | +@Command(scope = "onos", name = "null-link", | ||
37 | + description = "Severs or repairs a simulated link") | ||
38 | +public class NullLinkCommand extends AbstractShellCommand { | ||
39 | + | ||
40 | + @Argument(index = 0, name = "one", description = "One link end-point as device/port", | ||
41 | + required = true, multiValued = false) | ||
42 | + String one = null; | ||
43 | + | ||
44 | + @Argument(index = 1, name = "two", description = "Another link end-point as device/port", | ||
45 | + required = true, multiValued = false) | ||
46 | + String two = null; | ||
47 | + | ||
48 | + @Argument(index = 2, name = "cmd", description = "up/down", | ||
49 | + required = true, multiValued = false) | ||
50 | + String cmd = null; | ||
51 | + | ||
52 | + | ||
53 | + @Override | ||
54 | + protected void execute() { | ||
55 | + NullProviders service = get(NullProviders.class); | ||
56 | + | ||
57 | + try { | ||
58 | + DeviceId oneId = deviceId(getDeviceId(one)); | ||
59 | + PortNumber onePort = portNumber(getPortNumber(one)); | ||
60 | + ConnectPoint onePoint = new ConnectPoint(oneId, onePort); | ||
61 | + | ||
62 | + DeviceId twoId = deviceId(getDeviceId(two)); | ||
63 | + PortNumber twoPort = portNumber(getPortNumber(two)); | ||
64 | + ConnectPoint twoPoint = new ConnectPoint(twoId, twoPort); | ||
65 | + | ||
66 | + if (cmd.equals(UP)) { | ||
67 | + service.repairLink(onePoint, twoPoint); | ||
68 | + } else if (cmd.equals(DOWN)) { | ||
69 | + service.severLink(onePoint, twoPoint); | ||
70 | + } else { | ||
71 | + error("Illegal command %s; must be up or down", cmd); | ||
72 | + } | ||
73 | + } catch (NumberFormatException e) { | ||
74 | + error("Invalid port number specified", e); | ||
75 | + } | ||
76 | + } | ||
77 | + | ||
78 | +} |
providers/null/src/main/java/org/onosproject/provider/nil/cli/TopologyShapeCompleter.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.provider.nil.cli; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableList; | ||
19 | +import org.onosproject.cli.AbstractChoicesCompleter; | ||
20 | + | ||
21 | +import java.util.List; | ||
22 | + | ||
23 | +/** | ||
24 | + * Topology shape completer. | ||
25 | + */ | ||
26 | +public class TopologyShapeCompleter extends AbstractChoicesCompleter { | ||
27 | + @Override | ||
28 | + public List<String> choices() { | ||
29 | + return ImmutableList.of("configured", "linear", "reroute", "centipede", | ||
30 | + "tree", "spineleaf", "mesh"); | ||
31 | + } | ||
32 | +} |
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 | + * Null provider CLI commands and completers. | ||
19 | + */ | ||
20 | +package org.onosproject.provider.nil.cli; |
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 | + * Set of null south-bound providers which permit simulating a network | ||
19 | + * topology using fake devices, links, hosts, etc. | ||
20 | + */ | ||
21 | +package org.onosproject.provider.nil; |
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 | +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> | ||
17 | + | ||
18 | + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> | ||
19 | + <command> | ||
20 | + <action class="org.onosproject.provider.nil.cli.NullControlCommand"/> | ||
21 | + <completers> | ||
22 | + <ref component-id="startStopCompleter"/> | ||
23 | + <ref component-id="topoShapeCompleter"/> | ||
24 | + <null/> | ||
25 | + </completers> | ||
26 | + </command> | ||
27 | + <command> | ||
28 | + <action class="org.onosproject.provider.nil.cli.NullLinkCommand"/> | ||
29 | + <completers> | ||
30 | + <ref component-id="linkSrcCompleter"/> | ||
31 | + <ref component-id="linkDstCompleter"/> | ||
32 | + <ref component-id="upDownCompleter"/> | ||
33 | + <null/> | ||
34 | + </completers> | ||
35 | + </command> | ||
36 | + </command-bundle> | ||
37 | + | ||
38 | + <bean id="startStopCompleter" class="org.onosproject.cli.StartStopCompleter"/> | ||
39 | + <bean id="upDownCompleter" class="org.onosproject.cli.UpDownCompleter"/> | ||
40 | + <bean id="topoShapeCompleter" class="org.onosproject.provider.nil.cli.TopologyShapeCompleter"/> | ||
41 | + <bean id="linkSrcCompleter" class="org.onosproject.cli.net.LinkSrcCompleter"/> | ||
42 | + <bean id="linkDstCompleter" class="org.onosproject.cli.net.LinkDstCompleter"/> | ||
43 | + | ||
44 | +</blueprint> |
tools/test/topos/attmpls-sim.json
0 → 100644
This diff is collapsed. Click to expand it.
... | @@ -192,6 +192,20 @@ public abstract class Tools { | ... | @@ -192,6 +192,20 @@ public abstract class Tools { |
192 | } | 192 | } |
193 | 193 | ||
194 | /** | 194 | /** |
195 | + * Suspends the current thread for a specified number of millis and nanos. | ||
196 | + * | ||
197 | + * @param ms number of millis | ||
198 | + * @param nanos number of nanos | ||
199 | + */ | ||
200 | + public static void delay(int ms, int nanos) { | ||
201 | + try { | ||
202 | + Thread.sleep(ms, nanos); | ||
203 | + } catch (InterruptedException e) { | ||
204 | + throw new RuntimeException("Interrupted", e); | ||
205 | + } | ||
206 | + } | ||
207 | + | ||
208 | + /** | ||
195 | * Slurps the contents of a file into a list of strings, one per line. | 209 | * Slurps the contents of a file into a list of strings, one per line. |
196 | * | 210 | * |
197 | * @param path file path | 211 | * @param path file path | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -18,6 +18,7 @@ package org.onosproject.rest; | ... | @@ -18,6 +18,7 @@ package org.onosproject.rest; |
18 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
19 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | import org.onosproject.net.device.DeviceProviderRegistry; | 20 | import org.onosproject.net.device.DeviceProviderRegistry; |
21 | +import org.onosproject.net.device.DeviceService; | ||
21 | import org.onosproject.net.host.HostProviderRegistry; | 22 | import org.onosproject.net.host.HostProviderRegistry; |
22 | import org.onosproject.net.link.LinkProviderRegistry; | 23 | import org.onosproject.net.link.LinkProviderRegistry; |
23 | import org.onlab.rest.BaseResource; | 24 | import org.onlab.rest.BaseResource; |
... | @@ -40,9 +41,9 @@ import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; | ... | @@ -40,9 +41,9 @@ import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; |
40 | * devices, ports and links. | 41 | * devices, ports and links. |
41 | */ | 42 | */ |
42 | @Path("config") | 43 | @Path("config") |
43 | -public class ConfigResource extends BaseResource { | 44 | +public class ConfigWebResource extends BaseResource { |
44 | 45 | ||
45 | - private static Logger log = LoggerFactory.getLogger(ConfigResource.class); | 46 | + private static Logger log = LoggerFactory.getLogger(ConfigWebResource.class); |
46 | 47 | ||
47 | @POST | 48 | @POST |
48 | @Path("topology") | 49 | @Path("topology") |
... | @@ -52,7 +53,8 @@ public class ConfigResource extends BaseResource { | ... | @@ -52,7 +53,8 @@ public class ConfigResource extends BaseResource { |
52 | try { | 53 | try { |
53 | ObjectMapper mapper = new ObjectMapper(); | 54 | ObjectMapper mapper = new ObjectMapper(); |
54 | JsonNode cfg = mapper.readTree(input); | 55 | JsonNode cfg = mapper.readTree(input); |
55 | - new ConfigProvider(cfg, get(DeviceProviderRegistry.class), | 56 | + new ConfigProvider(cfg, get(DeviceService.class), |
57 | + get(DeviceProviderRegistry.class), | ||
56 | get(LinkProviderRegistry.class), | 58 | get(LinkProviderRegistry.class), |
57 | get(HostProviderRegistry.class)).parse(); | 59 | get(HostProviderRegistry.class)).parse(); |
58 | return Response.ok().build(); | 60 | return Response.ok().build(); | ... | ... |
... | @@ -72,7 +72,7 @@ | ... | @@ -72,7 +72,7 @@ |
72 | org.onosproject.rest.IntentsWebResource, | 72 | org.onosproject.rest.IntentsWebResource, |
73 | org.onosproject.rest.FlowsWebResource, | 73 | org.onosproject.rest.FlowsWebResource, |
74 | org.onosproject.rest.TopologyWebResource, | 74 | org.onosproject.rest.TopologyWebResource, |
75 | - org.onosproject.rest.ConfigResource, | 75 | + org.onosproject.rest.ConfigWebResource, |
76 | org.onosproject.rest.PathsWebResource | 76 | org.onosproject.rest.PathsWebResource |
77 | </param-value> | 77 | </param-value> |
78 | </init-param> | 78 | </init-param> | ... | ... |
-
Please register or login to post a comment