Brian O'Connor

Moving some apps to new repository

Repo URL: https://gerrit.onosproject.org/onos-app-samples

Apps moved
- calendar
- database-perf
- demo
- election
- ifwd
- intent-perf
- tvue

Apps removed
- foo

Change-Id: I90e8313554246aaeb92e46f9e9efcb93d951585b
Showing 74 changed files with 0 additions and 4179 deletions
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-apps</artifactId>
25 - <version>1.2.0-SNAPSHOT</version>
26 - <relativePath>../pom.xml</relativePath>
27 - </parent>
28 -
29 - <artifactId>onos-app-calendar</artifactId>
30 - <packaging>bundle</packaging>
31 -
32 - <description>ONOS simple calendaring REST interface for intents</description>
33 -
34 - <properties>
35 - <web.context>/onos/calendar</web.context>
36 - </properties>
37 -
38 - <dependencies>
39 - <dependency>
40 - <groupId>org.onosproject</groupId>
41 - <artifactId>onlab-rest</artifactId>
42 - <version>${project.version}</version>
43 - </dependency>
44 -
45 - <dependency>
46 - <groupId>com.sun.jersey</groupId>
47 - <artifactId>jersey-servlet</artifactId>
48 - </dependency>
49 - <dependency>
50 - <groupId>com.sun.jersey.jersey-test-framework</groupId>
51 - <artifactId>jersey-test-framework-core</artifactId>
52 - <version>1.18.1</version>
53 - <scope>test</scope>
54 - </dependency>
55 - <dependency>
56 - <groupId>com.sun.jersey.jersey-test-framework</groupId>
57 - <artifactId>jersey-test-framework-grizzly2</artifactId>
58 - <version>1.18.1</version>
59 - <scope>test</scope>
60 - </dependency>
61 - <dependency>
62 - <groupId>org.osgi</groupId>
63 - <artifactId>org.osgi.core</artifactId>
64 - </dependency>
65 -
66 - <dependency>
67 - <groupId>org.onosproject</groupId>
68 - <artifactId>onlab-thirdparty</artifactId>
69 - </dependency>
70 -
71 - <dependency>
72 - <groupId>org.onosproject</groupId>
73 - <artifactId>onlab-misc</artifactId>
74 - </dependency>
75 -
76 - <dependency>
77 - <groupId>org.onosproject</groupId>
78 - <artifactId>onlab-junit</artifactId>
79 - <scope>test</scope>
80 - </dependency>
81 -
82 - <dependency>
83 - <groupId>org.onosproject</groupId>
84 - <artifactId>onos-cli</artifactId>
85 - <version>${project.version}</version>
86 - </dependency>
87 - <dependency>
88 - <groupId>org.apache.karaf.shell</groupId>
89 - <artifactId>org.apache.karaf.shell.console</artifactId>
90 - </dependency>
91 - </dependencies>
92 -
93 - <build>
94 - <plugins>
95 - <plugin>
96 - <groupId>org.apache.felix</groupId>
97 - <artifactId>maven-bundle-plugin</artifactId>
98 - <extensions>true</extensions>
99 - <configuration>
100 - <instructions>
101 - <_wab>src/main/webapp/</_wab>
102 - <Bundle-SymbolicName>
103 - ${project.groupId}.${project.artifactId}
104 - </Bundle-SymbolicName>
105 - <Import-Package>
106 - org.slf4j,
107 - org.osgi.framework,
108 - javax.ws.rs,javax.ws.rs.core,
109 - com.sun.jersey.api.core,
110 - com.sun.jersey.spi.container.servlet,
111 - com.sun.jersey.server.impl.container.servlet,
112 - org.onlab.packet.*,
113 - org.onlab.rest.*,
114 - org.onosproject.*
115 - </Import-Package>
116 - <Web-ContextPath>${web.context}</Web-ContextPath>
117 - </instructions>
118 - </configuration>
119 - </plugin>
120 - </plugins>
121 - </build>
122 -
123 -</project>
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Application providing integration between OSCARS and ONOS intent
19 - * framework via REST API.
20 - */
21 -package org.onosproject.calendar;
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 -<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
18 - xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
19 - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
20 - id="ONOS" version="2.5">
21 - <display-name>ONOS GUI</display-name>
22 -
23 - <servlet>
24 - <servlet-name>JAX-RS Service</servlet-name>
25 - <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
26 - <init-param>
27 - <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
28 - <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
29 - </init-param>
30 - <init-param>
31 - <param-name>com.sun.jersey.config.property.classnames</param-name>
32 - <param-value>org.onosproject.calendar.BandwidthCalendarResource</param-value>
33 - </init-param>
34 - <load-on-startup>10</load-on-startup>
35 - </servlet>
36 -
37 - <servlet-mapping>
38 - <servlet-name>JAX-RS Service</servlet-name>
39 - <url-pattern>/*</url-pattern>
40 - </servlet-mapping>
41 -
42 -</web-app>
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015 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-apps</artifactId>
25 - <version>1.2.0-SNAPSHOT</version>
26 - <relativePath>../pom.xml</relativePath>
27 - </parent>
28 -
29 - <artifactId>onos-app-database-perf</artifactId>
30 - <packaging>bundle</packaging>
31 -
32 - <description>ONOS partitioned database perf test app bundle</description>
33 -
34 - <build>
35 - <plugins>
36 - <plugin>
37 - <groupId>org.apache.maven.plugins</groupId>
38 - <artifactId>maven-assembly-plugin</artifactId>
39 - <version>2.5.3</version>
40 - <configuration>
41 - <descriptor>src/assembly/bin.xml</descriptor>
42 - </configuration>
43 - <executions>
44 - <execution>
45 - <phase>package</phase>
46 - <goals>
47 - <goal>single</goal>
48 - </goals>
49 - </execution>
50 - </executions>
51 - </plugin>
52 - </plugins>
53 - </build>
54 -</project>
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015 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 -<app name="org.onosproject.databaseperf" origin="ON.Lab" version="1.1.0"
18 - features="onos-app-database-perf">
19 - <description>Partitioned database performance measurement application</description>
20 -</app>
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015 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 -<assembly
18 - xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
19 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
21 - <formats>
22 - <format>zip</format>
23 - </formats>
24 - <id>onos</id>
25 - <includeBaseDirectory>false</includeBaseDirectory>
26 - <files>
27 - <file>
28 - <source>src/assembly/app.xml</source>
29 - <destName>app.xml</destName>
30 - </file>
31 - <file>
32 - <source>target/${project.artifactId}-${project.version}.jar</source>
33 - <destName>m2/org/onosproject/${project.artifactId}/${project.version}/${project.artifactId}-${project.version}.jar</destName>
34 - </file>
35 - </files>
36 -</assembly>
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.databaseperf;
17 -
18 -import static org.apache.felix.scr.annotations.ReferenceCardinality.MANDATORY_UNARY;
19 -import static org.onlab.util.Tools.delay;
20 -import static org.onlab.util.Tools.groupedThreads;
21 -import static org.slf4j.LoggerFactory.getLogger;
22 -
23 -import java.util.Timer;
24 -import java.util.TimerTask;
25 -import java.util.UUID;
26 -import java.util.concurrent.ExecutorService;
27 -import java.util.concurrent.Executors;
28 -import java.util.concurrent.TimeUnit;
29 -import java.util.concurrent.atomic.AtomicInteger;
30 -import java.util.stream.IntStream;
31 -
32 -import org.apache.commons.lang.math.RandomUtils;
33 -import org.apache.felix.scr.annotations.Activate;
34 -import org.apache.felix.scr.annotations.Component;
35 -import org.apache.felix.scr.annotations.Deactivate;
36 -import org.apache.felix.scr.annotations.Reference;
37 -import org.onlab.util.KryoNamespace;
38 -import org.onosproject.cluster.ClusterService;
39 -import org.onosproject.cluster.ControllerNode;
40 -import org.onosproject.core.ApplicationId;
41 -import org.onosproject.core.CoreService;
42 -import org.onosproject.store.service.ConsistentMap;
43 -import org.onosproject.store.service.Serializer;
44 -import org.onosproject.store.service.StorageService;
45 -import org.slf4j.Logger;
46 -
47 -/**
48 - * Application to measure partitioned database performance.
49 - */
50 -@Component(immediate = true)
51 -public class DatabasePerfInstaller {
52 -
53 - private final Logger log = getLogger(getClass());
54 -
55 - @Reference(cardinality = MANDATORY_UNARY)
56 - protected CoreService coreService;
57 -
58 - @Reference(cardinality = MANDATORY_UNARY)
59 - protected ClusterService clusterService;
60 -
61 - @Reference(cardinality = MANDATORY_UNARY)
62 - protected StorageService storageService;
63 -
64 - private boolean stopped;
65 -
66 - private ApplicationId appId;
67 -
68 - private static final long REPORT_PERIOD = 5000L; //ms
69 - private Timer reportTimer;
70 -
71 - private AtomicInteger successCount = new AtomicInteger(0);
72 - private AtomicInteger failureCount = new AtomicInteger(0);
73 -
74 - private ConsistentMap<String, String> cmap;
75 -
76 - private ControllerNode localNode;
77 -
78 - private long reportStartTime = System.currentTimeMillis();
79 -
80 - private static final int NUM_TASK_THREADS = 2;
81 - private ExecutorService taskExecutor;
82 -
83 - private static final Serializer SERIALIZER = new Serializer() {
84 -
85 - KryoNamespace kryo = new KryoNamespace.Builder().build();
86 -
87 - @Override
88 - public <T> byte[] encode(T object) {
89 - return kryo.serialize(object);
90 - }
91 -
92 - @Override
93 - public <T> T decode(byte[] bytes) {
94 - return kryo.deserialize(bytes);
95 - }
96 -
97 - };
98 -
99 - @Activate
100 - public void activate() {
101 - localNode = clusterService.getLocalNode();
102 - String nodeId = localNode.ip().toString();
103 - appId = coreService.registerApplication("org.onosproject.nettyperf."
104 - + nodeId);
105 -
106 - cmap = storageService.createConsistentMap("onos-app-database-perf-test-map", SERIALIZER);
107 - taskExecutor = Executors.newFixedThreadPool(NUM_TASK_THREADS, groupedThreads("onos/database-perf", "worker"));
108 - log.info("Started with Application ID {}", appId.id());
109 - start();
110 - }
111 -
112 - @Deactivate
113 - public void deactivate() {
114 - stop();
115 - log.info("Stopped");
116 - }
117 -
118 - public void start() {
119 - long delay = System.currentTimeMillis() % REPORT_PERIOD;
120 - reportTimer = new Timer("onos-netty-perf-reporter");
121 - reportTimer.scheduleAtFixedRate(new TimerTask() {
122 - @Override
123 - public void run() {
124 - report();
125 - }
126 - }, delay, REPORT_PERIOD);
127 -
128 - stopped = false;
129 - IntStream.range(0, NUM_TASK_THREADS).forEach(i -> {
130 - taskExecutor.submit(() -> {
131 - delay(2000); // take a breath to start
132 - while (!stopped) {
133 - performDBOperation();
134 - delay(2); // take a breather
135 - }
136 - });
137 - });
138 - }
139 -
140 - private void performDBOperation() {
141 - String key = String.format("test%d", RandomUtils.nextInt(1000));
142 - try {
143 - if (RandomUtils.nextBoolean()) {
144 - cmap.put(key, UUID.randomUUID().toString());
145 - } else {
146 - cmap.get(key);
147 - }
148 - successCount.incrementAndGet();
149 - } catch (Exception e) {
150 - failureCount.incrementAndGet();
151 - }
152 - }
153 -
154 - private void report() {
155 - long delta = System.currentTimeMillis() - reportStartTime;
156 - if (delta > 0) {
157 - int rate = (int) Math.round(((successCount.get() * 1000.0) / delta));
158 - log.info("Passed: {}, Failed: {}, Rate: {}",
159 - successCount.getAndSet(0), failureCount.getAndSet(0), rate);
160 - reportStartTime = System.currentTimeMillis();
161 - }
162 - }
163 -
164 - public void stop() {
165 - reportTimer.cancel();
166 - reportTimer = null;
167 - stopped = true;
168 - try {
169 - taskExecutor.awaitTermination(5, TimeUnit.SECONDS);
170 - } catch (InterruptedException e) {
171 - log.warn("Failed to stop worker.");
172 - }
173 - }
174 -}
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 - * Performance test application that induces steady load on the partitioned database.
19 - */
20 -package org.onosproject.databaseperf;
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-apps</artifactId>
25 - <version>1.2.0-SNAPSHOT</version>
26 - <relativePath>../pom.xml</relativePath>
27 - </parent>
28 -
29 - <artifactId>onos-app-demo</artifactId>
30 - <packaging>bundle</packaging>
31 -
32 - <description>ONOS demo app bundle</description>
33 -
34 - <properties>
35 - <web.context>/onos/demo</web.context>
36 - </properties>
37 -
38 - <dependencies>
39 - <dependency>
40 - <groupId>org.osgi</groupId>
41 - <artifactId>org.osgi.compendium</artifactId>
42 - </dependency>
43 - <dependency>
44 - <groupId>org.onosproject</groupId>
45 - <artifactId>onlab-rest</artifactId>
46 - <version>${project.version}</version>
47 - </dependency>
48 -
49 - <dependency>
50 - <groupId>org.onosproject</groupId>
51 - <artifactId>onos-rest</artifactId>
52 - <version>${project.version}</version>
53 - </dependency>
54 -
55 - <dependency>
56 - <groupId>com.sun.jersey</groupId>
57 - <artifactId>jersey-servlet</artifactId>
58 - </dependency>
59 - <dependency>
60 - <groupId>com.sun.jersey.jersey-test-framework</groupId>
61 - <artifactId>jersey-test-framework-core</artifactId>
62 - <version>1.18.1</version>
63 - <scope>test</scope>
64 - </dependency>
65 - <dependency>
66 - <groupId>com.sun.jersey.jersey-test-framework</groupId>
67 - <artifactId>jersey-test-framework-grizzly2</artifactId>
68 - <version>1.18.1</version>
69 - <scope>test</scope>
70 - </dependency>
71 -
72 - <dependency>
73 - <groupId>com.fasterxml.jackson.core</groupId>
74 - <artifactId>jackson-databind</artifactId>
75 - </dependency>
76 -
77 - <dependency>
78 - <groupId>com.fasterxml.jackson.core</groupId>
79 - <artifactId>jackson-annotations</artifactId>
80 - </dependency>
81 -
82 - <dependency>
83 - <groupId>org.osgi</groupId>
84 - <artifactId>org.osgi.core</artifactId>
85 - </dependency>
86 - </dependencies>
87 -
88 - <build>
89 - <plugins>
90 - <plugin>
91 - <groupId>org.apache.felix</groupId>
92 - <artifactId>maven-bundle-plugin</artifactId>
93 - <extensions>true</extensions>
94 - <configuration>
95 - <instructions>
96 - <_wab>src/main/webapp/</_wab>
97 - <Bundle-SymbolicName>
98 - ${project.groupId}.${project.artifactId}
99 - </Bundle-SymbolicName>
100 - <Import-Package>
101 - org.slf4j,
102 - org.osgi.framework,
103 - javax.ws.rs,javax.ws.rs.core,
104 - com.sun.jersey.api.core,
105 - com.sun.jersey.spi.container.servlet,
106 - com.sun.jersey.server.impl.container.servlet,
107 - com.fasterxml.jackson.databind,
108 - com.fasterxml.jackson.databind.node,
109 - org.apache.commons.lang.math.*,
110 - com.google.common.*,
111 - org.onlab.packet.*,
112 - org.onlab.rest.*,
113 - org.onosproject.*,
114 - org.onlab.util.*,
115 - org.jboss.netty.util.*
116 - </Import-Package>
117 - <Web-ContextPath>${web.context}</Web-ContextPath>
118 - </instructions>
119 - </configuration>
120 - </plugin>
121 - </plugins>
122 - </build>
123 -
124 -</project>
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.demo;
17 -
18 -import com.fasterxml.jackson.databind.JsonNode;
19 -
20 -import java.util.Optional;
21 -
22 -/**
23 - * Simple demo api interface.
24 - */
25 -public interface DemoAPI {
26 -
27 - enum InstallType { MESH, RANDOM };
28 -
29 - /**
30 - * Tests flow subsystem based on the parameters supplied.
31 - *
32 - * @param params the test parameters
33 - * @return JSON representation
34 - */
35 - JsonNode flowTest(Optional<JsonNode> params);
36 -
37 - /**
38 - * Installs intents based on the installation type.
39 - * @param type the installation type.
40 - * @param runParams run params
41 - */
42 - void setup(InstallType type, Optional<JsonNode> runParams);
43 -
44 - /**
45 - * Uninstalls all existing intents.
46 - */
47 - void tearDown();
48 -
49 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.demo;
17 -
18 -import com.fasterxml.jackson.databind.JsonNode;
19 -import com.fasterxml.jackson.databind.ObjectMapper;
20 -import org.onlab.rest.BaseResource;
21 -
22 -import javax.ws.rs.Consumes;
23 -import javax.ws.rs.GET;
24 -import javax.ws.rs.POST;
25 -import javax.ws.rs.Path;
26 -import javax.ws.rs.Produces;
27 -import javax.ws.rs.core.MediaType;
28 -import javax.ws.rs.core.Response;
29 -import java.io.IOException;
30 -import java.io.InputStream;
31 -import java.util.Optional;
32 -
33 -/**
34 - * Rest API for demos.
35 - */
36 -@Path("intents")
37 -public class DemoResource extends BaseResource {
38 -
39 -
40 -
41 - @POST
42 - @Path("flowTest")
43 - @Consumes(MediaType.APPLICATION_JSON)
44 - @Produces(MediaType.APPLICATION_JSON)
45 - public Response flowTest(InputStream input) throws IOException {
46 - ObjectMapper mapper = new ObjectMapper();
47 - JsonNode cfg = mapper.readTree(input);
48 - DemoAPI demo = get(DemoAPI.class);
49 - return Response.ok(demo.flowTest(Optional.ofNullable(cfg)).toString()).build();
50 - }
51 -
52 - @POST
53 - @Path("setup")
54 - @Consumes(MediaType.APPLICATION_JSON)
55 - @Produces(MediaType.APPLICATION_JSON)
56 - public Response setup(InputStream input) throws IOException {
57 - ObjectMapper mapper = new ObjectMapper();
58 - JsonNode cfg = mapper.readTree(input);
59 - if (!cfg.has("type")) {
60 - return Response.status(Response.Status.BAD_REQUEST)
61 - .entity("Expected type field containing either mesh or random.").build();
62 - }
63 -
64 -
65 - DemoAPI.InstallType type = DemoAPI.InstallType.valueOf(
66 - cfg.get("type").asText().toUpperCase());
67 - DemoAPI demo = get(DemoAPI.class);
68 - demo.setup(type, Optional.ofNullable(cfg.get("runParams")));
69 -
70 - return Response.ok(mapper.createObjectNode().toString()).build();
71 - }
72 -
73 - @GET
74 - @Path("teardown")
75 - @Produces(MediaType.APPLICATION_JSON)
76 - public Response tearDown() throws IOException {
77 - ObjectMapper mapper = new ObjectMapper();
78 - DemoAPI demo = get(DemoAPI.class);
79 - demo.tearDown();
80 - return Response.ok(mapper.createObjectNode().toString()).build();
81 - }
82 -
83 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Demo applications live here.
19 - */
20 -package org.onosproject.demo;
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 -<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
18 - xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
19 - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
20 - id="ONOS" version="2.5">
21 - <display-name>ONOS DEMO APP API v1.0</display-name>
22 -
23 - <servlet>
24 - <servlet-name>JAX-RS Service</servlet-name>
25 - <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
26 - <init-param>
27 - <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
28 - <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
29 - </init-param>
30 - <init-param>
31 - <param-name>com.sun.jersey.config.property.classnames</param-name>
32 - <param-value>
33 - org.onosproject.demo.DemoResource
34 - </param-value>
35 - </init-param>
36 - <load-on-startup>1</load-on-startup>
37 - </servlet>
38 -
39 - <servlet-mapping>
40 - <servlet-name>JAX-RS Service</servlet-name>
41 - <url-pattern>/*</url-pattern>
42 - </servlet-mapping>
43 -
44 -</web-app>
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 -
18 -<project xmlns="http://maven.apache.org/POM/4.0.0"
19 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
21 - <modelVersion>4.0.0</modelVersion>
22 -
23 - <parent>
24 - <groupId>org.onosproject</groupId>
25 - <artifactId>onos-apps</artifactId>
26 - <version>1.2.0-SNAPSHOT</version>
27 - <relativePath>../pom.xml</relativePath>
28 - </parent>
29 -
30 - <artifactId>onos-app-election</artifactId>
31 - <packaging>bundle</packaging>
32 -
33 - <description>ONOS app leadership election test</description>
34 -
35 - <dependencies>
36 -
37 - <dependency>
38 - <groupId>org.onosproject</groupId>
39 - <artifactId>onos-api</artifactId>
40 - <version>${project.version}</version>
41 - <scope>test</scope>
42 - <classifier>tests</classifier>
43 - </dependency>
44 -
45 - <dependency>
46 - <groupId>org.onosproject</groupId>
47 - <artifactId>onos-cli</artifactId>
48 - <version>${project.version}</version>
49 - </dependency>
50 -
51 - <dependency>
52 - <groupId>org.osgi</groupId>
53 - <artifactId>org.osgi.core</artifactId>
54 - </dependency>
55 - <dependency>
56 - <groupId>org.apache.karaf.shell</groupId>
57 - <artifactId>org.apache.karaf.shell.console</artifactId>
58 - </dependency>
59 -
60 - </dependencies>
61 -
62 -</project>
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.election;
17 -
18 -import static org.slf4j.LoggerFactory.getLogger;
19 -
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.Reference;
24 -import org.apache.felix.scr.annotations.ReferenceCardinality;
25 -import org.onosproject.cluster.ClusterService;
26 -import org.onosproject.core.CoreService;
27 -import org.onosproject.cluster.ControllerNode;
28 -import org.onosproject.cluster.LeadershipEvent;
29 -import org.onosproject.cluster.LeadershipEventListener;
30 -import org.onosproject.cluster.LeadershipService;
31 -import org.onosproject.core.ApplicationId;
32 -
33 -import org.slf4j.Logger;
34 -
35 -
36 -/**
37 - * Simple application to test leadership election.
38 - */
39 -@Component(immediate = true)
40 -public class ElectionTest {
41 -
42 - private final Logger log = getLogger(getClass());
43 -
44 - private static final String ELECTION_APP = "org.onosproject.election";
45 - private ApplicationId appId;
46 -
47 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
48 - protected ClusterService clusterService;
49 -
50 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
51 - protected CoreService coreService;
52 -
53 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
54 - protected LeadershipService leadershipService;
55 -
56 - private LeadershipEventListener leadershipEventListener =
57 - new InnerLeadershipEventListener();
58 -
59 - private ControllerNode localControllerNode;
60 -
61 -
62 - @Activate
63 - protected void activate() {
64 - log.info("Election-test app started");
65 -
66 - appId = coreService.registerApplication(ELECTION_APP);
67 -
68 - localControllerNode = clusterService.getLocalNode();
69 -
70 - leadershipService.addListener(leadershipEventListener);
71 - leadershipService.runForLeadership(appId.name());
72 - }
73 -
74 - @Deactivate
75 - protected void deactivate() {
76 -
77 - leadershipService.withdraw(appId.name());
78 - leadershipService.removeListener(leadershipEventListener);
79 -
80 - log.info("Election-test app Stopped");
81 - }
82 -
83 - /**
84 - * A listener for Leadership Events.
85 - */
86 - private class InnerLeadershipEventListener
87 - implements LeadershipEventListener {
88 -
89 - @Override
90 - public void event(LeadershipEvent event) {
91 -
92 -
93 - if (!event.subject().topic().equals(appId.name())) {
94 - return; // Not our topic: ignore
95 - }
96 -
97 - //only log what pertains to us
98 - log.debug("Leadership Event: time = {} type = {} event = {}",
99 - event.time(), event.type(), event);
100 -
101 - if (!event.subject().leader().equals(
102 - localControllerNode.id())) {
103 - return; // The event is not about this instance: ignore
104 - }
105 -
106 - switch (event.type()) {
107 - case LEADER_ELECTED:
108 - log.info("Election-test app leader elected");
109 - break;
110 - case LEADER_BOOTED:
111 - log.info("Election-test app lost election");
112 - break;
113 - case LEADER_REELECTED:
114 - log.debug("Election-test app was re-elected");
115 - break;
116 - default:
117 - break;
118 - }
119 - }
120 - }
121 -
122 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.election.cli;
17 -
18 -import org.onosproject.cluster.NodeId;
19 -import org.apache.karaf.shell.commands.Command;
20 -import org.onosproject.cli.AbstractShellCommand;
21 -import org.onosproject.cluster.LeadershipService;
22 -
23 -/**
24 - * CLI command to get the current leader for the Election test application.
25 - */
26 -@Command(scope = "onos", name = "election-test-leader",
27 - description = "Get the current leader for the Election test application")
28 -public class ElectionTestLeaderCommand extends AbstractShellCommand {
29 -
30 - private NodeId leader;
31 - private static final String ELECTION_APP = "org.onosproject.election";
32 -
33 - @Override
34 - protected void execute() {
35 - LeadershipService service = get(LeadershipService.class);
36 -
37 - //print the current leader
38 - leader = service.getLeader(ELECTION_APP);
39 - printLeader(leader);
40 - }
41 -
42 - /**
43 - * Prints the leader.
44 - *
45 - * @param leader the leader to print
46 - */
47 - private void printLeader(NodeId leader) {
48 - if (leader != null) {
49 - print("The current leader for the Election app is %s.", leader);
50 - } else {
51 - print("There is currently no leader elected for the Election app");
52 - }
53 - }
54 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.election.cli;
17 -
18 -import org.apache.karaf.shell.commands.Command;
19 -import org.onosproject.cli.AbstractShellCommand;
20 -import org.onosproject.cluster.LeadershipService;
21 -
22 -/**
23 - * CLI command to run for leadership of the Election test application.
24 - */
25 -@Command(scope = "onos", name = "election-test-run",
26 - description = "Run for leader of the Election test application")
27 -public class ElectionTestRunCommand extends AbstractShellCommand {
28 -
29 - private static final String ELECTION_APP = "org.onosproject.election";
30 -
31 - @Override
32 - protected void execute() {
33 - LeadershipService service = get(LeadershipService.class);
34 -
35 - service.runForLeadership(ELECTION_APP);
36 - //print the current leader
37 - print("Entering leadership elections for the Election app.");
38 - }
39 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.election.cli;
17 -
18 -import org.apache.karaf.shell.commands.Command;
19 -import org.onosproject.cli.AbstractShellCommand;
20 -import org.onosproject.cluster.LeadershipService;
21 -
22 -/**
23 - * CLI command to withdraw the local node from leadership election for
24 - * the Election test application.
25 - */
26 -@Command(scope = "onos", name = "election-test-withdraw",
27 - description = "Withdraw node from leadership election for the Election test application")
28 -public class ElectionTestWithdrawCommand extends AbstractShellCommand {
29 -
30 - private static final String ELECTION_APP = "org.onosproject.election";
31 -
32 - @Override
33 - protected void execute() {
34 - LeadershipService service = get(LeadershipService.class);
35 -
36 - service.withdraw(ELECTION_APP);
37 - //print the current leader
38 - print("Withdrawing from leadership elections for the Election app.");
39 - }
40 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Election test command-line handlers.
19 - */
20 -package org.onosproject.election.cli;
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Sample application for use in various experiments.
19 - */
20 -package org.onosproject.election;
1 -<!--
2 - ~ Copyright 2014 Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -<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.election.cli.ElectionTestLeaderCommand"/>
21 - </command>
22 - <command>
23 - <action class="org.onosproject.election.cli.ElectionTestRunCommand"/>
24 - </command>
25 - <command>
26 - <action class="org.onosproject.election.cli.ElectionTestWithdrawCommand"/>
27 - </command>
28 - </command-bundle>
29 -
30 -</blueprint>
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-apps</artifactId>
25 - <version>1.1.0-SNAPSHOT</version>
26 - <relativePath>../pom.xml</relativePath>
27 - </parent>
28 -
29 - <artifactId>onos-app-foo</artifactId>
30 - <packaging>bundle</packaging>
31 -
32 - <description>ONOS application for miscellaneous experiments</description>
33 -
34 - <dependencies>
35 - <dependency>
36 - <groupId>org.onosproject</groupId>
37 - <artifactId>onos-cli</artifactId>
38 - <version>${project.version}</version>
39 - </dependency>
40 - <dependency>
41 - <groupId>org.onosproject</groupId>
42 - <artifactId>onlab-osgi</artifactId>
43 - <version>${project.version}</version>
44 - </dependency>
45 - <dependency>
46 - <groupId>org.onosproject</groupId>
47 - <artifactId>onlab-nio</artifactId>
48 - <version>${project.version}</version>
49 - </dependency>
50 - <dependency>
51 - <groupId>org.onosproject</groupId>
52 - <artifactId>onlab-netty</artifactId>
53 - <version>${project.version}</version>
54 - </dependency>
55 - <dependency>
56 - <groupId>org.apache.karaf.shell</groupId>
57 - <artifactId>org.apache.karaf.shell.console</artifactId>
58 - </dependency>
59 - <dependency>
60 - <groupId>org.onosproject</groupId>
61 - <artifactId>onlab-misc</artifactId>
62 - </dependency>
63 - <dependency>
64 - <groupId>com.google.guava</groupId>
65 - <artifactId>guava</artifactId>
66 - </dependency>
67 - <dependency>
68 - <groupId>org.osgi</groupId>
69 - <artifactId>org.osgi.core</artifactId>
70 - </dependency>
71 - </dependencies>
72 -</project>
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import static java.util.concurrent.Executors.newScheduledThreadPool;
19 -import static org.onlab.util.Tools.namedThreads;
20 -import static org.slf4j.LoggerFactory.getLogger;
21 -
22 -import java.nio.ByteBuffer;
23 -import java.util.concurrent.ScheduledExecutorService;
24 -//import java.util.concurrent.TimeUnit;
25 -
26 -
27 -
28 -import org.apache.felix.scr.annotations.Activate;
29 -import org.apache.felix.scr.annotations.Component;
30 -import org.apache.felix.scr.annotations.Deactivate;
31 -import org.apache.felix.scr.annotations.Reference;
32 -import org.apache.felix.scr.annotations.ReferenceCardinality;
33 -import org.onosproject.cluster.ClusterEvent;
34 -import org.onosproject.cluster.ClusterEventListener;
35 -import org.onosproject.cluster.ClusterService;
36 -import org.onosproject.cluster.NodeId;
37 -import org.onosproject.mastership.MastershipEvent;
38 -import org.onosproject.mastership.MastershipListener;
39 -import org.onosproject.mastership.MastershipService;
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.intent.IntentEvent;
44 -import org.onosproject.net.intent.IntentListener;
45 -import org.onosproject.net.intent.IntentService;
46 -import org.onosproject.store.service.DatabaseAdminService;
47 -import org.onosproject.store.service.DatabaseException;
48 -import org.onosproject.store.service.DatabaseService;
49 -import org.onosproject.store.service.Lock;
50 -import org.onosproject.store.service.LockService;
51 -import org.onosproject.store.service.VersionedValue;
52 -import org.slf4j.Logger;
53 -
54 -/**
55 - * Playground app component.
56 - */
57 -@Component(immediate = true)
58 -public class FooComponent {
59 -
60 - private final Logger log = getLogger(getClass());
61 -
62 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 - protected ClusterService clusterService;
64 -
65 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 - protected DeviceService deviceService;
67 -
68 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
69 - protected IntentService intentService;
70 -
71 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
72 - protected MastershipService mastershipService;
73 -
74 - @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
75 - protected DatabaseAdminService dbAdminService;
76 -
77 - @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
78 - protected DatabaseService dbService;
79 -
80 - @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
81 - protected LockService lockService;
82 -
83 - private final ClusterEventListener clusterListener = new InnerClusterListener();
84 - private final DeviceListener deviceListener = new InnerDeviceListener();
85 - private final IntentListener intentListener = new InnerIntentListener();
86 - private final MastershipListener mastershipListener = new InnerMastershipListener();
87 -
88 - private ScheduledExecutorService executor;
89 -
90 - @Activate
91 - public void activate() {
92 - executor = newScheduledThreadPool(4, namedThreads("foo-executor-%d"));
93 -
94 - clusterService.addListener(clusterListener);
95 - deviceService.addListener(deviceListener);
96 - intentService.addListener(intentListener);
97 - mastershipService.addListener(mastershipListener);
98 -
99 - if (dbService == null || dbAdminService == null) {
100 - log.info("Couldn't find DB service");
101 - } else {
102 - log.info("Found DB service");
103 - //longIncrementor();
104 - //lockUnlock();
105 - //executor.scheduleAtFixedRate(new LongIncrementor(), 1, 10, TimeUnit.SECONDS);
106 - //executor.scheduleAtFixedRate(new LongIncrementor(), 1, 10, TimeUnit.SECONDS);
107 - }
108 - log.info("Started");
109 - }
110 -
111 - @Deactivate
112 - public void deactivate() {
113 - executor.shutdown();
114 - clusterService.removeListener(clusterListener);
115 - deviceService.removeListener(deviceListener);
116 - intentService.removeListener(intentListener);
117 - mastershipService.removeListener(mastershipListener);
118 - log.info("Stopped");
119 - }
120 -
121 - private class InnerClusterListener implements ClusterEventListener {
122 - @Override
123 - public void event(ClusterEvent event) {
124 - log.info("WOOOOT! {}", event);
125 - }
126 - }
127 -
128 - private class InnerDeviceListener implements DeviceListener {
129 - @Override
130 - public void event(DeviceEvent event) {
131 - log.info("YEEEEHAAAAW! {}", event);
132 - }
133 - }
134 -
135 - private class InnerIntentListener implements IntentListener {
136 - @Override
137 - public void event(IntentEvent event) {
138 - String message;
139 - if (event.type() == IntentEvent.Type.INSTALL_REQ) {
140 - message = "WOW! It looks like someone has some intentions: {}";
141 - } else if (event.type() == IntentEvent.Type.INSTALLED) {
142 - message = "AWESOME! So far things are going great: {}";
143 - } else if (event.type() == IntentEvent.Type.WITHDRAWN) {
144 - message = "HMMM! Ambitions are fading apparently: {}";
145 - } else {
146 - message = "CRAP!!! Things are not turning out as intended: {}";
147 - }
148 - log.info(message, event.subject());
149 - }
150 - }
151 -
152 - private class InnerMastershipListener implements MastershipListener {
153 - @Override
154 - public void event(MastershipEvent event) {
155 - final NodeId myId = clusterService.getLocalNode().id();
156 - if (myId.equals(event.roleInfo().master())) {
157 - log.info("I have control/I wish you luck {}", event);
158 - } else {
159 - log.info("you have control {}", event);
160 - }
161 - }
162 - }
163 -
164 - private void lockUnlock() throws InterruptedException {
165 - try {
166 - final String locksTable = "onos-locks";
167 -
168 - if (!dbAdminService.listTables().contains(locksTable)) {
169 - dbAdminService.createTable(locksTable, 10000);
170 - }
171 - Lock lock = lockService.create("foo-bar");
172 - log.info("Requesting lock");
173 - lock.lock(10000);
174 - //try {
175 - //Thread.sleep(5000);
176 - //} catch (InterruptedException e) {
177 - //e.printStackTrace();
178 - //}
179 - log.info("Acquired Lock");
180 - log.info("Do I have the lock: {} ", lock.isLocked());
181 - //lock.unlock();
182 - log.info("Do I have the lock: {} ", lock.isLocked());
183 - } finally {
184 - log.info("Done");
185 - }
186 - }
187 -
188 - private void longIncrementor() {
189 - try {
190 - final String someTable = "admin";
191 - final String someKey = "long";
192 -
193 - if (!dbAdminService.listTables().contains(someTable)) {
194 - dbAdminService.createTable(someTable);
195 - }
196 -
197 - VersionedValue vv = dbService.get(someTable, someKey);
198 - if (vv == null) {
199 - ByteBuffer zero = ByteBuffer.allocate(Long.BYTES).putLong(0);
200 - if (dbService.putIfAbsent(someTable, someKey, zero.array())) {
201 - log.info("Wrote initial value");
202 - vv = dbService.get(someTable, someKey);
203 - } else {
204 - log.info("Concurrent write detected.");
205 - // concurrent write detected, read and fall through
206 - vv = dbService.get(someTable, someKey);
207 - if (vv == null) {
208 - log.error("Shouldn't reach here");
209 - }
210 - }
211 - }
212 - int retry = 1;
213 -
214 - do {
215 - if (vv == null) {
216 - log.error("Shouldn't reach here - value is null");
217 - break;
218 - }
219 - ByteBuffer prev = ByteBuffer.wrap(vv.value());
220 - long next = prev.getLong() + 1;
221 - byte[] newValue = ByteBuffer.allocate(Long.BYTES).putLong(next).array();
222 - if (dbService.putIfVersionMatches(someTable, someKey, newValue, vv.version())) {
223 - log.info("Write success. New value: {}", next);
224 - break;
225 - } else {
226 - log.info("Write failed retrying.....{}", retry);
227 - vv = dbService.get(someTable, someKey);
228 - if (vv == null) {
229 - log.error("Shouldn't reach here");
230 - }
231 - }
232 - } while (retry++ < 5);
233 - } catch (DatabaseException e) {
234 - log.debug("DB Exception thrown {}", e.getMessage());
235 - } catch (Exception e) {
236 - log.error("Exception thrown", e);
237 - }
238 - }
239 -
240 - private final class LongIncrementor implements Runnable {
241 -
242 - @Override
243 - public void run() {
244 - longIncrementor();
245 - }
246 -
247 - }
248 -}
249 -
250 -
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import com.google.common.collect.Lists;
19 -import org.onlab.nio.AcceptorLoop;
20 -import org.onlab.nio.IOLoop;
21 -import org.onlab.nio.MessageStream;
22 -import org.onlab.util.Counter;
23 -import org.slf4j.Logger;
24 -import org.slf4j.LoggerFactory;
25 -
26 -import java.io.IOException;
27 -import java.net.InetAddress;
28 -import java.net.InetSocketAddress;
29 -import java.net.Socket;
30 -import java.net.SocketAddress;
31 -import java.nio.channels.ByteChannel;
32 -import java.nio.channels.ServerSocketChannel;
33 -import java.nio.channels.SocketChannel;
34 -import java.text.DecimalFormat;
35 -import java.util.ArrayList;
36 -import java.util.List;
37 -import java.util.concurrent.ExecutorService;
38 -import java.util.concurrent.Executors;
39 -
40 -import static java.lang.String.format;
41 -import static java.lang.System.nanoTime;
42 -import static java.lang.System.out;
43 -import static org.onlab.util.Tools.delay;
44 -import static org.onlab.util.Tools.namedThreads;
45 -
46 -/**
47 - * Auxiliary test fixture to measure speed of NIO-based channels.
48 - */
49 -public class IOLoopTestServer {
50 -
51 - private static Logger log = LoggerFactory.getLogger(IOLoopTestServer.class);
52 -
53 - private static final int PRUNE_FREQUENCY = 1000;
54 -
55 - static final int PORT = 9876;
56 - static final long TIMEOUT = 1000;
57 -
58 - static final boolean SO_NO_DELAY = false;
59 - static final int SO_SEND_BUFFER_SIZE = 128 * 1024;
60 - static final int SO_RCV_BUFFER_SIZE = 128 * 1024;
61 -
62 - static final DecimalFormat FORMAT = new DecimalFormat("#,##0");
63 -
64 - private final AcceptorLoop aloop;
65 - private final ExecutorService apool = Executors.newSingleThreadExecutor(namedThreads("accept"));
66 -
67 - private final List<CustomIOLoop> iloops = new ArrayList<>();
68 - private final ExecutorService ipool;
69 -
70 - private final int workerCount;
71 - private final int msgLength;
72 - private int lastWorker = -1;
73 -
74 - Counter messages;
75 - Counter bytes;
76 -
77 - /**
78 - * Main entry point to launch the server.
79 - *
80 - * @param args command-line arguments
81 - * @throws java.io.IOException if unable to crate IO loops
82 - */
83 - public static void main(String[] args) throws IOException {
84 - startStandalone(args);
85 - System.exit(0);
86 - }
87 -
88 - /*
89 - * Starts a standalone IO loop test server.
90 - *
91 - * @param args command-line arguments
92 - */
93 - public static void startStandalone(String[] args) throws IOException {
94 - InetAddress ip = InetAddress.getByName(args.length > 0 ? args[0] : "127.0.0.1");
95 - int wc = args.length > 1 ? Integer.parseInt(args[1]) : 6;
96 - int ml = args.length > 2 ? Integer.parseInt(args[2]) : 128;
97 -
98 - log.info("Setting up the server with {} workers, {} byte messages on {}... ",
99 - wc, ml, ip);
100 - IOLoopTestServer server = new IOLoopTestServer(ip, wc, ml, PORT);
101 - server.start();
102 -
103 - // Start pruning clients and keep going until their number goes to 0.
104 - int remaining = -1;
105 - while (remaining == -1 || remaining > 0) {
106 - delay(PRUNE_FREQUENCY);
107 - int r = server.prune();
108 - remaining = remaining == -1 && r == 0 ? remaining : r;
109 - }
110 - server.stop();
111 - }
112 -
113 - /**
114 - * Creates a speed server.
115 - *
116 - * @param ip optional ip of the adapter where to bind
117 - * @param wc worker count
118 - * @param ml message length in bytes
119 - * @param port listen port
120 - * @throws java.io.IOException if unable to create IO loops
121 - */
122 - public IOLoopTestServer(InetAddress ip, int wc, int ml, int port) throws IOException {
123 - this.workerCount = wc;
124 - this.msgLength = ml;
125 - this.ipool = Executors.newFixedThreadPool(workerCount, namedThreads("io-loop"));
126 -
127 - this.aloop = new CustomAcceptLoop(new InetSocketAddress(ip, port));
128 - for (int i = 0; i < workerCount; i++) {
129 - iloops.add(new CustomIOLoop());
130 - }
131 - }
132 -
133 - /**
134 - * Start the server IO loops and kicks off throughput tracking.
135 - */
136 - public void start() {
137 - messages = new Counter();
138 - bytes = new Counter();
139 -
140 - for (CustomIOLoop l : iloops) {
141 - ipool.execute(l);
142 - }
143 - apool.execute(aloop);
144 -
145 - for (CustomIOLoop l : iloops) {
146 - l.awaitStart(TIMEOUT);
147 - }
148 - aloop.awaitStart(TIMEOUT);
149 - }
150 -
151 - /**
152 - * Stop the server IO loops and freezes throughput tracking.
153 - */
154 - public void stop() {
155 - aloop.shutdown();
156 - for (CustomIOLoop l : iloops) {
157 - l.shutdown();
158 - }
159 -
160 - for (CustomIOLoop l : iloops) {
161 - l.awaitStop(TIMEOUT);
162 - }
163 - aloop.awaitStop(TIMEOUT);
164 -
165 - messages.freeze();
166 - bytes.freeze();
167 - }
168 -
169 - /**
170 - * Reports on the accumulated throughput and latency.
171 - */
172 - public void report() {
173 - DecimalFormat f = new DecimalFormat("#,##0");
174 - out.println(format("Server: %s messages; %s bytes; %s mps; %s MBs",
175 - f.format(messages.total()), f.format(bytes.total()),
176 - f.format(messages.throughput()),
177 - f.format(bytes.throughput() / (1024 * msgLength))));
178 - }
179 -
180 - /**
181 - * Prunes the IO loops of stale message buffers.
182 - *
183 - * @return number of remaining IO loops among all workers.
184 - */
185 - public int prune() {
186 - int count = 0;
187 - for (CustomIOLoop l : iloops) {
188 - count += l.pruneStaleStreams();
189 - }
190 - return count;
191 - }
192 -
193 - // Get the next worker to which a client should be assigned
194 - private synchronized CustomIOLoop nextWorker() {
195 - lastWorker = (lastWorker + 1) % workerCount;
196 - return iloops.get(lastWorker);
197 - }
198 -
199 - // Loop for transfer of fixed-length messages
200 - private class CustomIOLoop extends IOLoop<TestMessage, TestMessageStream> {
201 -
202 - public CustomIOLoop() throws IOException {
203 - super(500);
204 - }
205 -
206 - @Override
207 - protected TestMessageStream createStream(ByteChannel channel) {
208 - return new TestMessageStream(msgLength, channel, this);
209 - }
210 -
211 - @Override
212 - protected void removeStream(MessageStream<TestMessage> stream) {
213 - super.removeStream(stream);
214 - messages.add(stream.messagesIn().total());
215 - bytes.add(stream.bytesIn().total());
216 - }
217 -
218 - @Override
219 - protected void processMessages(List<TestMessage> messages,
220 - MessageStream<TestMessage> stream) {
221 - try {
222 - stream.write(createResponses(messages));
223 - } catch (IOException e) {
224 - log.error("Unable to echo messages", e);
225 - }
226 - }
227 -
228 - private List<TestMessage> createResponses(List<TestMessage> messages) {
229 - List<TestMessage> responses = Lists.newArrayListWithCapacity(messages.size());
230 - for (TestMessage message : messages) {
231 - responses.add(new TestMessage(message.length(), message.requestorTime(),
232 - nanoTime(), message.padding()));
233 - }
234 - return responses;
235 - }
236 - }
237 -
238 - // Loop for accepting client connections
239 - private class CustomAcceptLoop extends AcceptorLoop {
240 -
241 - public CustomAcceptLoop(SocketAddress address) throws IOException {
242 - super(500, address);
243 - }
244 -
245 - @Override
246 - protected void acceptConnection(ServerSocketChannel channel) throws IOException {
247 - SocketChannel sc = channel.accept();
248 - sc.configureBlocking(false);
249 -
250 - Socket so = sc.socket();
251 - so.setTcpNoDelay(SO_NO_DELAY);
252 - so.setReceiveBufferSize(SO_RCV_BUFFER_SIZE);
253 - so.setSendBufferSize(SO_SEND_BUFFER_SIZE);
254 -
255 - nextWorker().acceptStream(sc);
256 - log.info("Connected client");
257 - }
258 - }
259 -
260 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import java.io.IOException;
19 -
20 -import org.onlab.netty.Message;
21 -import org.onlab.netty.MessageHandler;
22 -
23 -
24 -/**
25 - * Message handler that echos the message back to the sender.
26 - */
27 -public class NettyEchoHandler implements MessageHandler {
28 -
29 - @Override
30 - public void handle(Message message) throws IOException {
31 - message.respond(message.payload());
32 - }
33 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import org.onlab.netty.Message;
19 -import org.onlab.netty.MessageHandler;
20 -import org.slf4j.Logger;
21 -import org.slf4j.LoggerFactory;
22 -
23 -/**
24 - * A MessageHandler that simply logs the information.
25 - */
26 -public class NettyNothingHandler implements MessageHandler {
27 -
28 - private final Logger log = LoggerFactory.getLogger(getClass());
29 -
30 - @Override
31 - public void handle(Message message) {
32 - // Do nothing
33 - }
34 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import static java.lang.Thread.sleep;
19 -
20 -import java.io.IOException;
21 -import java.util.concurrent.ExecutionException;
22 -import java.util.concurrent.Future;
23 -import java.util.concurrent.TimeUnit;
24 -import java.util.concurrent.TimeoutException;
25 -
26 -import org.onlab.metrics.MetricsComponent;
27 -import org.onlab.metrics.MetricsFeature;
28 -import org.onlab.metrics.MetricsManager;
29 -import org.onlab.netty.Endpoint;
30 -import org.onlab.netty.NettyMessagingService;
31 -import org.slf4j.Logger;
32 -import org.slf4j.LoggerFactory;
33 -
34 -import com.codahale.metrics.Timer;
35 -
36 -/**
37 - * The Simple netty client test.
38 - */
39 -// FIXME: Should be move out to test or app
40 -public final class SimpleNettyClient {
41 -
42 -private static Logger log = LoggerFactory.getLogger(SimpleNettyClient.class);
43 -
44 - static NettyMessagingService messaging;
45 - static MetricsManager metrics;
46 -
47 - private SimpleNettyClient() {
48 - }
49 -
50 - /**
51 - * The entry point of application.
52 - *
53 - * @param args the input arguments
54 - * @throws IOException the iO exception
55 - * @throws InterruptedException the interrupted exception
56 - * @throws ExecutionException the execution exception
57 - * @throws TimeoutException the timeout exception
58 - */
59 - public static void main(String[] args)
60 - throws IOException, InterruptedException, ExecutionException,
61 - TimeoutException {
62 - try {
63 - startStandalone(args);
64 - } catch (Exception e) {
65 - e.printStackTrace();
66 - }
67 -
68 - System.exit(0);
69 - }
70 -
71 - /**
72 - * Start standalone.
73 - *
74 - * @param args the args
75 - * @throws Exception the exception
76 - */
77 - public static void startStandalone(String[] args) throws Exception {
78 - String host = args.length > 0 ? args[0] : "localhost";
79 - int port = args.length > 1 ? Integer.parseInt(args[1]) : 8081;
80 - int warmup = args.length > 2 ? Integer.parseInt(args[2]) : 1000;
81 - int iterations = args.length > 3 ? Integer.parseInt(args[3]) : 50 * 100000;
82 - messaging = new TestNettyMessagingService(9081);
83 - metrics = new MetricsManager();
84 - Endpoint endpoint = new Endpoint(host, port);
85 - messaging.activate();
86 - MetricsFeature feature = new MetricsFeature("latency");
87 - MetricsComponent component = metrics.registerComponent("NettyMessaging");
88 - log.info("connecting " + host + ":" + port + " warmup:" + warmup + " iterations:" + iterations);
89 -
90 - for (int i = 0; i < warmup; i++) {
91 - messaging.sendAsync(endpoint, "simple", "Hello World".getBytes());
92 - Future<byte[]> responseFuture = messaging
93 - .sendAndReceive(endpoint, "echo",
94 - "Hello World".getBytes());
95 - responseFuture.get(100000, TimeUnit.MILLISECONDS);
96 - }
97 -
98 - log.info("measuring round-trip send & receive");
99 - Timer sendAndReceiveTimer = metrics.createTimer(component, feature, "SendAndReceive");
100 - int timeouts = 0;
101 -
102 - for (int i = 0; i < iterations; i++) {
103 - Future<byte[]> responseFuture;
104 - Timer.Context context = sendAndReceiveTimer.time();
105 - try {
106 - responseFuture = messaging
107 - .sendAndReceive(endpoint, "echo",
108 - "Hello World".getBytes());
109 - responseFuture.get(10000, TimeUnit.MILLISECONDS);
110 - } catch (TimeoutException e) {
111 - timeouts++;
112 - log.info("timeout:" + timeouts + " at iteration:" + i);
113 - } finally {
114 - context.stop();
115 - }
116 - // System.out.println("Got back:" + new String(response.get(2, TimeUnit.SECONDS)));
117 - }
118 -
119 - //sleep(1000);
120 - log.info("measuring async sender");
121 - Timer sendAsyncTimer = metrics.createTimer(component, feature, "AsyncSender");
122 -
123 - for (int i = 0; i < iterations; i++) {
124 - Timer.Context context = sendAsyncTimer.time();
125 - messaging.sendAsync(endpoint, "simple", "Hello World".getBytes());
126 - context.stop();
127 - }
128 - sleep(10000);
129 - }
130 -
131 - public static void stop() {
132 - try {
133 - messaging.deactivate();
134 - } catch (Exception e) {
135 - log.info("Unable to stop client %s", e);
136 - }
137 - }
138 -
139 - /**
140 - * The type Test netty messaging service.
141 - */
142 - public static class TestNettyMessagingService extends NettyMessagingService {
143 - /**
144 - * Instantiates a new Test netty messaging service.
145 - *
146 - * @param port the port
147 - * @throws Exception the exception
148 - */
149 - public TestNettyMessagingService(int port) throws Exception {
150 - super(port);
151 - }
152 - }
153 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import static org.onosproject.foo.SimpleNettyClient.startStandalone;
19 -import static org.onosproject.foo.SimpleNettyClient.stop;
20 -
21 -import org.apache.karaf.shell.commands.Argument;
22 -import org.apache.karaf.shell.commands.Command;
23 -import org.onosproject.cli.AbstractShellCommand;
24 -
25 -/**
26 - * Test Netty client performance.
27 - */
28 -@Command(scope = "onos", name = "simple-netty-client",
29 - description = "Starts simple Netty client")
30 -public class SimpleNettyClientCommand extends AbstractShellCommand {
31 -
32 - //FIXME: replace these arguments with proper ones needed for the test.
33 - @Argument(index = 0, name = "hostname", description = "Server Hostname",
34 - required = false, multiValued = false)
35 - String hostname = "localhost";
36 -
37 - @Argument(index = 1, name = "port", description = "Port",
38 - required = false, multiValued = false)
39 - String port = "8081";
40 -
41 - @Argument(index = 2, name = "warmupCount", description = "Warm-up count",
42 - required = false, multiValued = false)
43 - String warmupCount = "1000";
44 -
45 - @Argument(index = 3, name = "messageCount", description = "Message count",
46 - required = false, multiValued = false)
47 - String messageCount = "1000000";
48 -
49 - @Override
50 - protected void execute() {
51 - try {
52 - startStandalone(new String[]{hostname, port, warmupCount, messageCount});
53 - } catch (Exception e) {
54 - error("Unable to start client %s", e);
55 - }
56 - stop();
57 - }
58 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import org.onlab.netty.NettyMessagingService;
19 -import org.slf4j.Logger;
20 -import org.slf4j.LoggerFactory;
21 -
22 -/**
23 - * Test to measure Messaging performance.
24 - */
25 - public final class SimpleNettyServer {
26 - private static Logger log = LoggerFactory.getLogger(SimpleNettyServer.class);
27 -
28 - private SimpleNettyServer() {}
29 -
30 - /**
31 - * The entry point of application.
32 - *
33 - * @param args the input arguments
34 - * @throws Exception the exception
35 - */
36 - public static void main(String... args) throws Exception {
37 - startStandalone(args);
38 - System.exit(0);
39 - }
40 -
41 - /**
42 - * Start standalone server.
43 - *
44 - * @param args the args
45 - * @throws Exception the exception
46 - */
47 - public static void startStandalone(String[] args) throws Exception {
48 - int port = args.length > 0 ? Integer.parseInt(args[0]) : 8081;
49 - NettyMessagingService server = new NettyMessagingService(port);
50 - server.activate();
51 - server.registerHandler("simple", new NettyNothingHandler());
52 - server.registerHandler("echo", new NettyEchoHandler());
53 - log.info("Netty Server server on port " + port);
54 - }
55 - }
56 -
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import static org.onosproject.foo.SimpleNettyServer.startStandalone;
19 -
20 -import org.apache.karaf.shell.commands.Argument;
21 -import org.apache.karaf.shell.commands.Command;
22 -import org.onosproject.cli.AbstractShellCommand;
23 -
24 -/**
25 - * Starts the Simple Netty server.
26 - */
27 -@Command(scope = "onos", name = "simple-netty-server",
28 - description = "Starts simple Netty server")
29 -public class SimpleNettyServerCommand extends AbstractShellCommand {
30 -
31 - //FIXME: Replace these with parameters for
32 - @Argument(index = 0, name = "port", description = "listen port",
33 - required = false, multiValued = false)
34 - String port = "8081";
35 -
36 - @Override
37 - protected void execute() {
38 - try {
39 - startStandalone(new String[]{port});
40 - } catch (Exception e) {
41 - error("Unable to start server %s", e);
42 - }
43 - }
44 -
45 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import org.apache.karaf.shell.commands.Argument;
19 -import org.apache.karaf.shell.commands.Command;
20 -import org.onosproject.cli.AbstractShellCommand;
21 -
22 -import static org.onosproject.foo.IOLoopTestClient.startStandalone;
23 -
24 -/**
25 - * Starts the test IO loop client.
26 - */
27 -@Command(scope = "onos", name = "test-io-client",
28 - description = "Starts the test IO loop client")
29 -public class TestIOClientCommand extends AbstractShellCommand {
30 -
31 - @Argument(index = 0, name = "serverIp", description = "Server IP address",
32 - required = false, multiValued = false)
33 - String serverIp = "127.0.0.1";
34 -
35 - @Argument(index = 1, name = "workers", description = "IO workers",
36 - required = false, multiValued = false)
37 - String workers = "6";
38 -
39 - @Argument(index = 2, name = "messageCount", description = "Message count",
40 - required = false, multiValued = false)
41 - String messageCount = "1000000";
42 -
43 - @Argument(index = 3, name = "messageLength", description = "Message length (bytes)",
44 - required = false, multiValued = false)
45 - String messageLength = "128";
46 -
47 - @Argument(index = 4, name = "timeoutSecs", description = "Test timeout (seconds)",
48 - required = false, multiValued = false)
49 - String timeoutSecs = "60";
50 -
51 - @Override
52 - protected void execute() {
53 - try {
54 - startStandalone(new String[]{serverIp, workers, messageCount, messageLength, timeoutSecs});
55 - } catch (Exception e) {
56 - error("Unable to start client %s", e);
57 - }
58 - }
59 -
60 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import org.apache.karaf.shell.commands.Argument;
19 -import org.apache.karaf.shell.commands.Command;
20 -import org.onosproject.cli.AbstractShellCommand;
21 -
22 -import static org.onosproject.foo.IOLoopTestServer.startStandalone;
23 -
24 -/**
25 - * Starts the test IO loop server.
26 - */
27 -@Command(scope = "onos", name = "test-io-server",
28 - description = "Starts the test IO loop server")
29 -public class TestIOServerCommand extends AbstractShellCommand {
30 -
31 - @Argument(index = 0, name = "serverIp", description = "Server IP address",
32 - required = false, multiValued = false)
33 - String serverIp = "127.0.0.1";
34 -
35 - @Argument(index = 1, name = "workers", description = "IO workers",
36 - required = false, multiValued = false)
37 - String workers = "6";
38 -
39 - @Argument(index = 2, name = "messageLength", description = "Message length (bytes)",
40 - required = false, multiValued = false)
41 - String messageLength = "128";
42 -
43 - @Override
44 - protected void execute() {
45 - try {
46 - startStandalone(new String[]{serverIp, workers, messageLength});
47 - } catch (Exception e) {
48 - error("Unable to start server %s", e);
49 - }
50 - }
51 -
52 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import org.onlab.nio.AbstractMessage;
19 -
20 -import static com.google.common.base.Preconditions.checkNotNull;
21 -
22 -/**
23 - * Test message for measuring rate and round-trip latency.
24 - */
25 -public class TestMessage extends AbstractMessage {
26 -
27 - private final byte[] padding;
28 -
29 - private final long requestorTime;
30 - private final long responderTime;
31 -
32 - /**
33 - * Creates a new message with the specified data.
34 - *
35 - * @param length message length
36 - * @param requestorTime requester time
37 - * @param responderTime responder time
38 - * @param padding message padding
39 - */
40 - TestMessage(int length, long requestorTime, long responderTime, byte[] padding) {
41 - this.length = length;
42 - this.requestorTime = requestorTime;
43 - this.responderTime = responderTime;
44 - this.padding = checkNotNull(padding, "Padding cannot be null");
45 - }
46 -
47 - public long requestorTime() {
48 - return requestorTime;
49 - }
50 -
51 - public long responderTime() {
52 - return responderTime;
53 - }
54 -
55 - public byte[] padding() {
56 - return padding;
57 - }
58 -
59 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.foo;
17 -
18 -import org.onlab.nio.IOLoop;
19 -import org.onlab.nio.MessageStream;
20 -
21 -import java.nio.ByteBuffer;
22 -import java.nio.channels.ByteChannel;
23 -
24 -import static com.google.common.base.Preconditions.checkArgument;
25 -import static com.google.common.base.Preconditions.checkState;
26 -
27 -/**
28 - * Fixed-length message transfer buffer.
29 - */
30 -public class TestMessageStream extends MessageStream<TestMessage> {
31 -
32 - private static final String E_WRONG_LEN = "Illegal message length: ";
33 - private static final long START_TAG = 0xfeedcafedeaddeedL;
34 - private static final long END_TAG = 0xbeadcafedeaddeedL;
35 - private static final int META_LENGTH = 40;
36 -
37 - private final int length;
38 - private boolean isStrict = true;
39 -
40 - public TestMessageStream(int length, ByteChannel ch, IOLoop<TestMessage, ?> loop) {
41 - super(loop, ch, 64 * 1024, 500);
42 - checkArgument(length >= META_LENGTH, "Length must be greater than header length of 40");
43 - this.length = length;
44 - }
45 -
46 - void setNonStrict() {
47 - isStrict = false;
48 - }
49 -
50 - @Override
51 - protected TestMessage read(ByteBuffer rb) {
52 - if (rb.remaining() < length) {
53 - return null;
54 - }
55 -
56 - long startTag = rb.getLong();
57 - if (isStrict) {
58 - checkState(startTag == START_TAG, "Incorrect message start");
59 - }
60 -
61 - long size = rb.getLong();
62 - long requestorTime = rb.getLong();
63 - long responderTime = rb.getLong();
64 - byte[] padding = padding();
65 - rb.get(padding);
66 -
67 - long endTag = rb.getLong();
68 - if (isStrict) {
69 - checkState(endTag == END_TAG, "Incorrect message end");
70 - }
71 -
72 - return new TestMessage((int) size, requestorTime, responderTime, padding);
73 - }
74 -
75 - @Override
76 - protected void write(TestMessage message, ByteBuffer wb) {
77 - if (message.length() != length) {
78 - throw new IllegalArgumentException(E_WRONG_LEN + message.length());
79 - }
80 -
81 - wb.putLong(START_TAG);
82 - wb.putLong(message.length());
83 - wb.putLong(message.requestorTime());
84 - wb.putLong(message.responderTime());
85 - wb.put(message.padding(), 0, length - META_LENGTH);
86 - wb.putLong(END_TAG);
87 - }
88 -
89 - public byte[] padding() {
90 - return new byte[length - META_LENGTH];
91 - }
92 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Sample application for use in various experiments.
19 - */
20 -package org.onosproject.foo;
1 -<!--
2 - ~ Copyright 2014 Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -<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.foo.TestIOClientCommand"/>
21 - </command>
22 - <command>
23 - <action class="org.onosproject.foo.TestIOServerCommand"/>
24 - </command>
25 - <command>
26 - <action class="org.onosproject.foo.SimpleNettyServerCommand"/>
27 - </command>
28 - <command>
29 - <action class="org.onosproject.foo.SimpleNettyClientCommand"/>
30 - </command>
31 - </command-bundle>
32 -
33 -</blueprint>
1 -#
2 -# Copyright 2014 Open Networking Laboratory
3 -#
4 -# Licensed under the Apache License, Version 2.0 (the "License");
5 -# you may not use this file except in compliance with the License.
6 -# You may obtain a copy of the License at
7 -#
8 -# http://www.apache.org/licenses/LICENSE-2.0
9 -#
10 -# Unless required by applicable law or agreed to in writing, software
11 -# distributed under the License is distributed on an "AS IS" BASIS,
12 -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 -# See the License for the specific language governing permissions and
14 -# limitations under the License.
15 -#
16 -livetribe.slp.da.expired.services.purge.period=60
17 -livetribe.slp.sa.client.connect.address=127.0.0.1
18 -livetribe.slp.sa.client.factory=org.livetribe.slp.sa.StandardServiceAgentClient$Factory
19 -livetribe.slp.sa.factory=org.livetribe.slp.sa.StandardServiceAgent$Factory
20 -livetribe.slp.sa.service.renewal.enabled=true
21 -livetribe.slp.sa.unicast.prefer.tcp=false
22 -livetribe.slp.tcp.connector.factory=org.livetribe.slp.spi.net.SocketTCPConnector$Factory
23 -livetribe.slp.tcp.connector.server.factory=org.livetribe.slp.spi.net.SocketTCPConnectorServer$Factory
24 -livetribe.slp.tcp.message.max.length=4096
25 -livetribe.slp.tcp.read.timeout=300000
26 -livetribe.slp.ua.client.factory=org.livetribe.slp.ua.StandardUserAgentClient$Factory
27 -livetribe.slp.ua.factory=org.livetribe.slp.ua.StandardUserAgent$Factory
28 -livetribe.slp.ua.unicast.prefer.tcp=false
29 -livetribe.slp.udp.connector.factory=org.livetribe.slp.spi.net.SocketUDPConnector$Factory
30 -livetribe.slp.udp.connector.server.factory=org.livetribe.slp.spi.net.SocketUDPConnectorServer$Factory
31 -net.slp.DAAddresses=
32 -net.slp.DAAttributes=
33 -net.slp.DAHeartBeat=10800
34 -net.slp.MTU=1400
35 -net.slp.SAAttributes=
36 -net.slp.broadcastAddress=255.255.255.255
37 -net.slp.datagramTimeouts=150,250,400
38 -net.slp.interfaces=0.0.0.0
39 -net.slp.isBroadcastOnly=false
40 -net.slp.locale=en
41 -net.slp.multicastAddress=239.255.255.253
42 -net.slp.multicastMaximumWait=15000
43 -net.slp.multicastTTL=255
44 -net.slp.multicastTimeouts=150,250,400,600,1000
45 -net.slp.notificationPort=1847
46 -net.slp.port=427
47 -net.slp.useScopes=default
48 -
49 -org.onlab.cluster.name = TV-ONOS
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015 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 -<app name="org.onosproject.app.ifwd" origin="ON.Lab" version="1.1.0"
18 - features="onos-app-ifwd">
19 - <description>ONOS Reactive forwarding application using intent subsystem (experimental)</description>
20 -</app>
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-apps</artifactId>
25 - <version>1.2.0-SNAPSHOT</version>
26 - <relativePath>../pom.xml</relativePath>
27 - </parent>
28 -
29 - <artifactId>onos-app-ifwd</artifactId>
30 - <packaging>bundle</packaging>
31 -
32 - <description>ONOS simple reactive forwarding app that uses intent service</description>
33 -
34 -</project>
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.ifwd;
17 -
18 -import static org.slf4j.LoggerFactory.getLogger;
19 -
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.Reference;
24 -import org.apache.felix.scr.annotations.ReferenceCardinality;
25 -import org.onlab.packet.Ethernet;
26 -import org.onosproject.core.ApplicationId;
27 -import org.onosproject.core.CoreService;
28 -import org.onosproject.net.Host;
29 -import org.onosproject.net.HostId;
30 -import org.onosproject.net.PortNumber;
31 -import org.onosproject.net.flow.DefaultTrafficSelector;
32 -import org.onosproject.net.flow.DefaultTrafficTreatment;
33 -import org.onosproject.net.flow.FlowRuleService;
34 -import org.onosproject.net.flow.TrafficSelector;
35 -import org.onosproject.net.flow.TrafficTreatment;
36 -import org.onosproject.net.host.HostService;
37 -import org.onosproject.net.intent.HostToHostIntent;
38 -import org.onosproject.net.intent.IntentService;
39 -import org.onosproject.net.packet.DefaultOutboundPacket;
40 -import org.onosproject.net.packet.InboundPacket;
41 -import org.onosproject.net.packet.OutboundPacket;
42 -import org.onosproject.net.packet.PacketContext;
43 -import org.onosproject.net.packet.PacketPriority;
44 -import org.onosproject.net.packet.PacketProcessor;
45 -import org.onosproject.net.packet.PacketService;
46 -import org.onosproject.net.topology.TopologyService;
47 -import org.slf4j.Logger;
48 -
49 -/**
50 - * WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework.
51 - */
52 -@Component(immediate = true)
53 -public class IntentReactiveForwarding {
54 -
55 - private final Logger log = getLogger(getClass());
56 -
57 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 - protected CoreService coreService;
59 -
60 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
61 - protected TopologyService topologyService;
62 -
63 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
64 - protected PacketService packetService;
65 -
66 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
67 - protected IntentService intentService;
68 -
69 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
70 - protected HostService hostService;
71 -
72 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
73 - protected FlowRuleService flowRuleService;
74 -
75 - private ReactivePacketProcessor processor = new ReactivePacketProcessor();
76 - private ApplicationId appId;
77 -
78 - @Activate
79 - public void activate() {
80 - appId = coreService.registerApplication("org.onosproject.ifwd");
81 -
82 - packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2);
83 -
84 - TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
85 - selector.matchEthType(Ethernet.TYPE_IPV4);
86 - packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId);
87 -
88 - log.info("Started");
89 - }
90 -
91 - @Deactivate
92 - public void deactivate() {
93 - packetService.removeProcessor(processor);
94 - processor = null;
95 - log.info("Stopped");
96 - }
97 -
98 - /**
99 - * Packet processor responsible for forwarding packets along their paths.
100 - */
101 - private class ReactivePacketProcessor implements PacketProcessor {
102 -
103 - @Override
104 - public void process(PacketContext context) {
105 - // Stop processing if the packet has been handled, since we
106 - // can't do any more to it.
107 - if (context.isHandled()) {
108 - return;
109 - }
110 -
111 - InboundPacket pkt = context.inPacket();
112 - Ethernet ethPkt = pkt.parsed();
113 -
114 - if (ethPkt == null) {
115 - return;
116 - }
117 -
118 - HostId srcId = HostId.hostId(ethPkt.getSourceMAC());
119 - HostId dstId = HostId.hostId(ethPkt.getDestinationMAC());
120 -
121 - // Do we know who this is for? If not, flood and bail.
122 - Host dst = hostService.getHost(dstId);
123 - if (dst == null) {
124 - flood(context);
125 - return;
126 - }
127 -
128 - // Otherwise forward and be done with it.
129 - setUpConnectivity(context, srcId, dstId);
130 - forwardPacketToDst(context, dst);
131 - }
132 - }
133 -
134 - // Floods the specified packet if permissible.
135 - private void flood(PacketContext context) {
136 - if (topologyService.isBroadcastPoint(topologyService.currentTopology(),
137 - context.inPacket().receivedFrom())) {
138 - packetOut(context, PortNumber.FLOOD);
139 - } else {
140 - context.block();
141 - }
142 - }
143 -
144 - // Sends a packet out the specified port.
145 - private void packetOut(PacketContext context, PortNumber portNumber) {
146 - context.treatmentBuilder().setOutput(portNumber);
147 - context.send();
148 - }
149 -
150 - private void forwardPacketToDst(PacketContext context, Host dst) {
151 - TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(dst.location().port()).build();
152 - OutboundPacket packet = new DefaultOutboundPacket(dst.location().deviceId(),
153 - treatment, context.inPacket().unparsed());
154 - packetService.emit(packet);
155 - log.info("sending packet: {}", packet);
156 - }
157 -
158 - // Install a rule forwarding the packet to the specified port.
159 - private void setUpConnectivity(PacketContext context, HostId srcId, HostId dstId) {
160 - TrafficSelector selector = DefaultTrafficSelector.emptySelector();
161 - TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
162 -
163 - HostToHostIntent intent = new HostToHostIntent(appId, srcId, dstId,
164 - selector, treatment);
165 -
166 - intentService.submit(intent);
167 - }
168 -
169 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Sample application that provides simple form of reactive forwarding
19 - * using the intent service.
20 - */
21 -package org.onosproject.ifwd;
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015 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-apps</artifactId>
25 - <version>1.2.0-SNAPSHOT</version>
26 - <relativePath>../pom.xml</relativePath>
27 - </parent>
28 -
29 - <artifactId>onos-app-intent-perf</artifactId>
30 - <packaging>bundle</packaging>
31 -
32 - <description>ONOS intent perf app bundle</description>
33 -
34 - <dependencies>
35 - <dependency>
36 - <groupId>org.apache.karaf.shell</groupId>
37 - <artifactId>org.apache.karaf.shell.console</artifactId>
38 - </dependency>
39 -
40 - <dependency>
41 - <groupId>org.onosproject</groupId>
42 - <artifactId>onos-cli</artifactId>
43 - <version>${project.version}</version>
44 - </dependency>
45 - <dependency>
46 - <groupId>org.osgi</groupId>
47 - <artifactId>org.osgi.compendium</artifactId>
48 - </dependency>
49 - <!-- Required for javadoc generation -->
50 - <dependency>
51 - <groupId>org.osgi</groupId>
52 - <artifactId>org.osgi.core</artifactId>
53 - </dependency>
54 - </dependencies>
55 -
56 - <build>
57 - <plugins>
58 - <plugin>
59 - <groupId>org.apache.maven.plugins</groupId>
60 - <artifactId>maven-assembly-plugin</artifactId>
61 - <version>2.5.3</version>
62 - <configuration>
63 - <descriptor>src/assembly/bin.xml</descriptor>
64 - </configuration>
65 - <executions>
66 - <execution>
67 - <phase>package</phase>
68 - <goals>
69 - <goal>single</goal>
70 - </goals>
71 - </execution>
72 - </executions>
73 - </plugin>
74 - </plugins>
75 - </build>
76 -</project>
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015 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 -<app name="org.onosproject.intentperf" origin="ON.Lab" version="1.1.0"
18 - features="onos-app-intent-perf">
19 - <description>Intent performance application</description>
20 -</app>
...\ No newline at end of file ...\ No newline at end of file
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015 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 -<assembly
18 - xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
19 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
21 - <formats>
22 - <format>zip</format>
23 - </formats>
24 - <id>onos</id>
25 - <includeBaseDirectory>false</includeBaseDirectory>
26 - <files>
27 - <file>
28 - <source>src/assembly/app.xml</source>
29 - <destName>app.xml</destName>
30 - </file>
31 - <file>
32 - <source>target/${project.artifactId}-${project.version}.jar</source>
33 - <destName>m2/org/onosproject/${project.artifactId}/${project.version}/${project.artifactId}-${project.version}.jar</destName>
34 - </file>
35 - </files>
36 -</assembly>
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.intentperf;
17 -
18 -import com.google.common.collect.ImmutableList;
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.apache.felix.scr.annotations.Service;
25 -import org.onosproject.cluster.ClusterService;
26 -import org.onosproject.cluster.ControllerNode;
27 -import org.onosproject.cluster.NodeId;
28 -import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
29 -import org.onosproject.store.cluster.messaging.ClusterMessage;
30 -import org.onosproject.store.cluster.messaging.ClusterMessageHandler;
31 -import org.onosproject.store.cluster.messaging.MessageSubject;
32 -import org.slf4j.Logger;
33 -
34 -import java.util.ArrayList;
35 -import java.util.Arrays;
36 -import java.util.HashMap;
37 -import java.util.LinkedList;
38 -import java.util.List;
39 -import java.util.Map;
40 -import java.util.concurrent.ExecutorService;
41 -import java.util.concurrent.Executors;
42 -
43 -import static org.onlab.util.Tools.groupedThreads;
44 -import static org.slf4j.LoggerFactory.getLogger;
45 -
46 -/**
47 - * Collects and distributes performance samples.
48 - */
49 -@Component(immediate = true)
50 -@Service(value = IntentPerfCollector.class)
51 -public class IntentPerfCollector {
52 -
53 - private static final long SAMPLE_TIME_WINDOW_MS = 5_000;
54 - private final Logger log = getLogger(getClass());
55 -
56 - private static final int MAX_SAMPLES = 1_000;
57 -
58 - private final List<Sample> samples = new LinkedList<>();
59 -
60 - private static final MessageSubject SAMPLE = new MessageSubject("intent-perf-sample");
61 -
62 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 - protected ClusterCommunicationService communicationService;
64 -
65 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 - protected ClusterService clusterService;
67 -
68 - @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
69 - protected IntentPerfUi ui;
70 -
71 - // Auxiliary structures used to accrue data for normalized time interval
72 - // across all nodes.
73 - private long newestTime;
74 - private Sample overall;
75 - private Sample current;
76 -
77 - private ControllerNode[] nodes;
78 - private Map<NodeId, Integer> nodeToIndex;
79 -
80 - private NodeId nodeId;
81 - private ExecutorService messageHandlingExecutor;
82 -
83 - @Activate
84 - public void activate() {
85 - nodeId = clusterService.getLocalNode().id();
86 -
87 - // TODO: replace with shared executor
88 - messageHandlingExecutor = Executors.newSingleThreadExecutor(
89 - groupedThreads("onos/perf", "message-handler"));
90 -
91 - communicationService.addSubscriber(SAMPLE, new InternalSampleCollector(),
92 - messageHandlingExecutor);
93 -
94 - nodes = clusterService.getNodes().toArray(new ControllerNode[]{});
95 - Arrays.sort(nodes, (a, b) -> a.id().toString().compareTo(b.id().toString()));
96 -
97 - nodeToIndex = new HashMap<>();
98 - for (int i = 0; i < nodes.length; i++) {
99 - nodeToIndex.put(nodes[i].id(), i);
100 - }
101 -
102 - clearSamples();
103 - log.info("Started");
104 - }
105 -
106 - @Deactivate
107 - public void deactivate() {
108 - messageHandlingExecutor.shutdown();
109 - communicationService.removeSubscriber(SAMPLE);
110 - log.info("Stopped");
111 - }
112 -
113 - /**
114 - * Clears all previously accumulated data.
115 - */
116 - public void clearSamples() {
117 - newestTime = 0;
118 - overall = new Sample(0, nodes.length);
119 - current = new Sample(0, nodes.length);
120 - samples.clear();
121 - }
122 -
123 -
124 - /**
125 - * Records a sample point of data about intent operation rate.
126 - *
127 - * @param overallRate overall rate
128 - * @param currentRate current rate
129 - */
130 - public void recordSample(double overallRate, double currentRate) {
131 - long now = System.currentTimeMillis();
132 - addSample(now, nodeId, overallRate, currentRate);
133 - broadcastSample(now, nodeId, overallRate, currentRate);
134 - }
135 -
136 - /**
137 - * Returns set of node ids as headers.
138 - *
139 - * @return node id headers
140 - */
141 - public List<String> getSampleHeaders() {
142 - List<String> headers = new ArrayList<>();
143 - for (ControllerNode node : nodes) {
144 - headers.add(node.id().toString());
145 - }
146 - return headers;
147 - }
148 -
149 - /**
150 - * Returns set of all accumulated samples normalized to the local set of
151 - * samples.
152 - *
153 - * @return accumulated samples
154 - */
155 - public synchronized List<Sample> getSamples() {
156 - return ImmutableList.copyOf(samples);
157 - }
158 -
159 - /**
160 - * Returns overall throughput performance for each of the cluster nodes.
161 - *
162 - * @return overall intent throughput
163 - */
164 - public synchronized Sample getOverall() {
165 - return overall;
166 - }
167 -
168 - // Records a new sample to our collection of samples
169 - private synchronized void addSample(long time, NodeId nodeId,
170 - double overallRate, double currentRate) {
171 - Sample fullSample = createCurrentSampleIfNeeded(time);
172 - setSampleData(current, nodeId, currentRate);
173 - setSampleData(overall, nodeId, overallRate);
174 - pruneSamplesIfNeeded();
175 -
176 - if (fullSample != null && ui != null) {
177 - ui.reportSample(fullSample);
178 - }
179 - }
180 -
181 - private Sample createCurrentSampleIfNeeded(long time) {
182 - Sample oldSample = time - newestTime > SAMPLE_TIME_WINDOW_MS || current.isComplete() ? current : null;
183 - if (oldSample != null) {
184 - newestTime = time;
185 - current = new Sample(time, nodes.length);
186 - if (oldSample.time > 0) {
187 - samples.add(oldSample);
188 - }
189 - }
190 - return oldSample;
191 - }
192 -
193 - private void setSampleData(Sample sample, NodeId nodeId, double data) {
194 - Integer index = nodeToIndex.get(nodeId);
195 - if (index != null) {
196 - sample.data[index] = data;
197 - }
198 - }
199 -
200 - private void pruneSamplesIfNeeded() {
201 - if (samples.size() > MAX_SAMPLES) {
202 - samples.remove(0);
203 - }
204 - }
205 -
206 - // Performance data sample.
207 - static class Sample {
208 - final long time;
209 - final double[] data;
210 -
211 - public Sample(long time, int nodeCount) {
212 - this.time = time;
213 - this.data = new double[nodeCount];
214 - Arrays.fill(data, -1);
215 - }
216 -
217 - public boolean isComplete() {
218 - for (int i = 0; i < data.length; i++) {
219 - if (data[i] < 0) {
220 - return false;
221 - }
222 - }
223 - return true;
224 - }
225 - }
226 -
227 - private void broadcastSample(long time, NodeId nodeId, double overallRate, double currentRate) {
228 - String data = String.format("%d|%f|%f", time, overallRate, currentRate);
229 - communicationService.broadcast(new ClusterMessage(nodeId, SAMPLE, data.getBytes()));
230 - }
231 -
232 - private class InternalSampleCollector implements ClusterMessageHandler {
233 - @Override
234 - public void handle(ClusterMessage message) {
235 - String[] fields = new String(message.payload()).split("\\|");
236 - log.debug("Received sample from {}: {}", message.sender(), fields);
237 - addSample(Long.parseLong(fields[0]), message.sender(),
238 - Double.parseDouble(fields[1]), Double.parseDouble(fields[2]));
239 - }
240 - }
241 -}
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.intentperf;
17 -
18 -import org.apache.karaf.shell.commands.Command;
19 -import org.apache.karaf.shell.commands.Option;
20 -import org.onosproject.cli.AbstractShellCommand;
21 -import org.onosproject.intentperf.IntentPerfCollector.Sample;
22 -
23 -import java.text.SimpleDateFormat;
24 -import java.util.Date;
25 -import java.util.List;
26 -
27 -/**
28 - * Displays accumulated performance metrics.
29 - */
30 -@Command(scope = "onos", name = "intent-perf",
31 - description = "Displays accumulated performance metrics")
32 -public class IntentPerfListCommand extends AbstractShellCommand {
33 -
34 - @Option(name = "-s", aliases = "--summary", description = "Output just summary",
35 - required = false, multiValued = false)
36 - private boolean summary = false;
37 -
38 - @Override
39 - protected void execute() {
40 - if (summary) {
41 - printSummary();
42 - } else {
43 - printSamples();
44 - }
45 - }
46 -
47 - private void printSummary() {
48 - IntentPerfCollector collector = get(IntentPerfCollector.class);
49 - List<String> headers = collector.getSampleHeaders();
50 - Sample overall = collector.getOverall();
51 - double total = 0;
52 - print("%12s: %14s", "Node ID", "Overall Rate");
53 - for (int i = 0; i < overall.data.length; i++) {
54 - if (overall.data[i] >= 0) {
55 - print("%12s: %14.2f", headers.get(i), overall.data[i]);
56 - total += overall.data[i];
57 - } else {
58 - print("%12s: %14s", headers.get(i), " ");
59 - }
60 - }
61 - print("%12s: %14.2f", "total", total);
62 - }
63 -
64 - private void printSamples() {
65 - IntentPerfCollector collector = get(IntentPerfCollector.class);
66 - List<String> headers = collector.getSampleHeaders();
67 - List<Sample> samples = collector.getSamples();
68 -
69 - System.out.print(String.format("%10s ", "Time"));
70 - for (String header : headers) {
71 - System.out.print(String.format("%12s ", header));
72 - }
73 - System.out.println(String.format("%12s", "Total"));
74 -
75 - SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
76 - for (Sample sample : samples) {
77 - double total = 0;
78 - System.out.print(String.format("%10s ", sdf.format(new Date(sample.time))));
79 - for (int i = 0; i < sample.data.length; i++) {
80 - if (sample.data[i] >= 0) {
81 - System.out.print(String.format("%12.2f ", sample.data[i]));
82 - total += sample.data[i];
83 - } else {
84 - System.out.print(String.format("%12s ", " "));
85 - }
86 - }
87 - System.out.println(String.format("%12.2f", total));
88 - }
89 - }
90 -
91 -}
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.intentperf;
17 -
18 -import org.apache.karaf.shell.commands.Command;
19 -import org.onosproject.cli.AbstractShellCommand;
20 -
21 -/**
22 - * Starts intent performance test run.
23 - */
24 -@Command(scope = "onos", name = "intent-perf-start",
25 - description = "Starts intent performance test run")
26 -public class IntentPerfStartCommand extends AbstractShellCommand {
27 -
28 - @Override
29 - protected void execute() {
30 - get(IntentPerfInstaller.class).start();
31 - }
32 -
33 -}
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.intentperf;
17 -
18 -import org.apache.karaf.shell.commands.Command;
19 -import org.onosproject.cli.AbstractShellCommand;
20 -
21 -/**
22 - * Stops intent performance test run.
23 - */
24 -@Command(scope = "onos", name = "intent-perf-stop",
25 - description = "Stops intent performance test run")
26 -public class IntentPerfStopCommand extends AbstractShellCommand {
27 -
28 - @Override
29 - protected void execute() {
30 - get(IntentPerfInstaller.class).stop();
31 - }
32 -
33 -}
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.intentperf;
17 -
18 -import com.fasterxml.jackson.databind.node.ObjectNode;
19 -import com.google.common.collect.ImmutableList;
20 -import com.google.common.collect.ImmutableSet;
21 -import org.apache.felix.scr.annotations.Activate;
22 -import org.apache.felix.scr.annotations.Component;
23 -import org.apache.felix.scr.annotations.Deactivate;
24 -import org.apache.felix.scr.annotations.Reference;
25 -import org.apache.felix.scr.annotations.ReferenceCardinality;
26 -import org.onlab.osgi.ServiceDirectory;
27 -import org.onosproject.intentperf.IntentPerfCollector.Sample;
28 -import org.onosproject.ui.UiConnection;
29 -import org.onosproject.ui.UiExtension;
30 -import org.onosproject.ui.UiExtensionService;
31 -import org.onosproject.ui.UiMessageHandler;
32 -import org.onosproject.ui.UiView;
33 -
34 -import java.util.Collection;
35 -import java.util.HashSet;
36 -import java.util.List;
37 -import java.util.Set;
38 -
39 -import static java.util.Collections.synchronizedSet;
40 -
41 -/**
42 - * Mechanism to stream data to the GUI.
43 - */
44 -@Component(immediate = true, enabled = false)
45 -public class IntentPerfUi {
46 -
47 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
48 - protected UiExtensionService uiExtensionService;
49 -
50 - private final Set<StreamingControl> handlers = synchronizedSet(new HashSet<>());
51 -
52 - private List<UiView> views = ImmutableList.of(new UiView("intentPerf", "Intent Performance"));
53 - private UiExtension uiExtension = new UiExtension(views, this::newHandlers,
54 - getClass().getClassLoader());
55 -
56 - @Activate
57 - protected void activate() {
58 - uiExtensionService.register(uiExtension);
59 - }
60 -
61 - @Deactivate
62 - protected void deactivate() {
63 - uiExtensionService.unregister(uiExtension);
64 - }
65 -
66 - /**
67 - * Reports a single sample of performance data.
68 - *
69 - * @param sample performance sample
70 - */
71 - public void reportSample(Sample sample) {
72 - synchronized (handlers) {
73 - handlers.forEach(h -> h.send(sample));
74 - }
75 - }
76 -
77 - // Creates and returns session specific message handler.
78 - private Collection<UiMessageHandler> newHandlers() {
79 - return ImmutableList.of(new StreamingControl());
80 - }
81 -
82 - // UI Message handlers for turning on/off reporting to a session.
83 - private class StreamingControl extends UiMessageHandler {
84 -
85 - private boolean streamingEnabled = false;
86 -
87 - protected StreamingControl() {
88 - super(ImmutableSet.of("intentPerfStart", "intentPerfStop"));
89 - }
90 -
91 - @Override
92 - public void process(ObjectNode message) {
93 - streamingEnabled = message.path("event").asText("unknown").equals("initPerfStart");
94 - }
95 -
96 - @Override
97 - public void init(UiConnection connection, ServiceDirectory directory) {
98 - super.init(connection, directory);
99 - handlers.add(this);
100 - }
101 -
102 - @Override
103 - public void destroy() {
104 - super.destroy();
105 - handlers.remove(this);
106 - }
107 -
108 - private void send(Sample sample) {
109 - // FIXME: finish this
110 - ObjectNode sn = mapper.createObjectNode()
111 - .put("time", sample.time);
112 - connection().sendMessage("intentPerf", 0, sn);
113 - }
114 - }
115 -
116 -}
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 - * Performance test application that induces steady load on the intent subsystem.
19 - */
20 -package org.onosproject.intentperf;
...\ No newline at end of file ...\ No newline at end of file
1 -<!--
2 - ~ Copyright 2015 Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
17 - <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
18 - <command>
19 - <action class="org.onosproject.intentperf.IntentPerfListCommand"/>
20 - </command>
21 - <command>
22 - <action class="org.onosproject.intentperf.IntentPerfStartCommand"/>
23 - </command>
24 - <command>
25 - <action class="org.onosproject.intentperf.IntentPerfStopCommand"/>
26 - </command>
27 - </command-bundle>
28 -</blueprint>
1 -date,value,node
2 -00:55:15,68.38,node1
3 -00:55:15,55.61,node2
4 -00:55:15,74.00,node3
5 -00:55:30,74.20,node1
6 -00:55:30,77.60,node2
7 -00:55:30,74.80,node3
8 -00:55:45,74.60,node1
9 -00:55:45,72.80,node2
10 -00:55:45,77.00,node3
11 -00:56:00,73.60,node1
12 -00:56:00,75.00,node2
13 -00:56:00,76.98,node3
14 -00:56:15,75.82,node1
15 -00:56:15,75.40,node2
16 -00:56:15,76.00,node3
17 -00:56:30,75.60,node1
18 -00:56:30,74.59,node2
19 -00:56:30,74.01,node3
...\ No newline at end of file ...\ No newline at end of file
1 -key,value,date
2 -Group1,37,00:23:00
3 -Group2,12,00:23:00
4 -Group3,46,00:23:00
5 -Group1,32,00:23:05
6 -Group2,19,00:23:05
7 -Group3,42,00:23:05
8 -Group1,45,00:23:10
9 -Group2,16,00:23:10
10 -Group3,44,00:23:10
11 -Group1,24,00:23:15
12 -Group2,52,00:23:15
13 -Group3,64,00:23:15
14 -Group1,34,00:23:20
15 -Group2,62,00:23:20
16 -Group3,74,00:23:20
17 -Group1,34,00:23:25
18 -Group2,62,00:23:25
19 -Group3,74,00:23:25
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/*
18 - ONOS GUI -- Intent Perf View -- CSS file
19 - */
20 -
21 -.light #ov-intentPerf {
22 - color: navy;
23 -}
24 -
25 -.dark #ov-intentPerf {
26 - color: #1e5e6f;
27 -}
28 -
29 -.dark a {
30 - color: #88c;
31 -}
32 -
33 -#ov-intentPerf .msg {
34 - color: darkorange;
35 -}
36 -
37 -.light #ov-intentPerf .msg {
38 - color: darkorange;
39 -}
40 -
41 -.dark #ov-intentPerf .msg {
42 - color: #904e00;
43 -}
44 -
45 -
46 -
47 -.axis path,
48 -.axis line {
49 - fill: none;
50 - stroke: #000;
51 - shape-rendering: crispEdges;
52 -}
53 -
54 -.browser text {
55 - text-anchor: end;
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 -
17 -<!-- Intent Performance partial HTML -->
18 -<div id="ov-sample">
19 - <h2> Intent Performance View </h2>
20 -
21 - <span class="msg">{{ ctrl.message }}</span>
22 -
23 - <div id="intent-perf-chart"></div>
24 -</div>
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 - ONOS GUI -- Intent Performance View Module
19 - */
20 -(function () {
21 - 'use strict';
22 -
23 - // injected refs
24 - var $log, tbs, flash;
25 -
26 - function start() {
27 - //var format = d3.time.format("%m/%d/%y");
28 - var format = d3.time.format("%H:%M:%S");
29 - var samples = [];
30 -
31 - var margin = {top: 20, right: 30, bottom: 30, left: 40},
32 - width = 960 - margin.left - margin.right,
33 - height = 500 - margin.top - margin.bottom;
34 -
35 - var x = d3.time.scale()
36 - .range([0, width]);
37 -
38 - var y = d3.scale.linear()
39 - .range([height, 0]);
40 -
41 - var z = d3.scale.category20c();
42 -
43 - var xAxis = d3.svg.axis()
44 - .scale(x)
45 - .orient("bottom")
46 - .ticks(d3.time.seconds);
47 -
48 - var yAxis = d3.svg.axis()
49 - .scale(y)
50 - .orient("left");
51 -
52 - var stack = d3.layout.stack()
53 - .offset("zero")
54 - .values(function(d) { return d.values; })
55 - .x(function(d) { return d.date; })
56 - .y(function(d) { return d.value; });
57 -
58 - var nest = d3.nest()
59 - .key(function(d) { return d.key; });
60 -
61 - var area = d3.svg.area()
62 - .interpolate("cardinal")
63 - .x(function(d) { return x(d.date); })
64 - .y0(function(d) { return y(d.y0); })
65 - .y1(function(d) { return y(d.y0 + d.y); });
66 -
67 - var svg = d3.select("body").append("svg")
68 - .attr("width", width + margin.left + margin.right)
69 - .attr("height", height + margin.top + margin.bottom)
70 - .append("g")
71 - .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
72 -
73 - svg.append("g")
74 - .attr("class", "x axis")
75 - .attr("transform", "translate(0," + height + ")")
76 - .call(xAxis);
77 -
78 - svg.append("g")
79 - .attr("class", "y axis")
80 - .call(yAxis);
81 -
82 - function fetchData() {
83 - d3.csv("app/view/intentPerf/data.csv", function (data) {
84 - samples = data;
85 - updateGraph();
86 - });
87 - }
88 -
89 - function updateGraph() {
90 - samples.forEach(function(d) {
91 - d.date = format.parse(d.date);
92 - d.value = +d.value;
93 - });
94 -
95 - var layers = stack(nest.entries(samples));
96 -
97 - x.domain(d3.extent(samples, function(d) { return d.date; }));
98 - y.domain([0, d3.max(samples, function(d) { return d.y0 + d.y; })]);
99 -
100 - svg.selectAll(".layer")
101 - .data(layers)
102 - .enter().append("path")
103 - .attr("class", "layer")
104 - .attr("d", function(d) { return area(d.values); })
105 - .style("fill", function(d, i) { return z(i); });
106 -
107 - svg.select(".x")
108 - .attr("transform", "translate(0," + height + ")")
109 - .call(xAxis);
110 -
111 - svg.select(".y")
112 - .call(yAxis);
113 -
114 - console.log('tick');
115 - }
116 - }
117 -
118 - start();
119 -
120 - // define the controller
121 -
122 - angular.module('ovIntentPerf', ['onosUtil'])
123 - .controller('OvIntentPerfCtrl',
124 - ['$scope', '$log', 'ToolbarService', 'FlashService',
125 -
126 - function ($scope, _$log_, _tbs_, _flash_) {
127 - var self = this
128 -
129 - $log = _$log_;
130 - tbs = _tbs_;
131 - flash = _flash_;
132 -
133 - self.message = 'Hey there dudes!';
134 - start();
135 -
136 - // Clean up on destroyed scope
137 - $scope.$on('$destroy', function () {
138 - });
139 -
140 - $log.log('OvIntentPerfCtrl has been created');
141 - }]);
142 -}());
1 -<link rel="stylesheet" href="app/view/intentPerf/intentPerf.css">
1 -<!DOCTYPE html>
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 -<html>
18 -<head>
19 - <title>Dev View</title>
20 - <script src="tp/d3.min.js"></script>
21 - <script src="tp/jquery-2.1.1.min.js"></script>
22 -
23 - <link rel="stylesheet" href="app/view/intentPerf/intentPerf.css">
24 -</head>
25 -<body>
26 -<div id="intent-perf-chart" style="width: 1024px; height: 800px"></div>
27 -<script src="app/view/intentPerf/intentPerf.js"></script>
28 -</body>
29 -</html>
...\ No newline at end of file ...\ No newline at end of file
1 -<script src="app/view/intentPerf/intentPerf.js"></script>
...@@ -32,24 +32,17 @@ ...@@ -32,24 +32,17 @@
32 <description>ONOS sample applications</description> 32 <description>ONOS sample applications</description>
33 33
34 <modules> 34 <modules>
35 - <module>tvue</module>
36 <module>fwd</module> 35 <module>fwd</module>
37 - <module>ifwd</module>
38 <module>mobility</module> 36 <module>mobility</module>
39 <module>proxyarp</module> 37 <module>proxyarp</module>
40 <module>config</module> 38 <module>config</module>
41 <module>sdnip</module> 39 <module>sdnip</module>
42 - <module>calendar</module>
43 <module>optical</module> 40 <module>optical</module>
44 <module>metrics</module> 41 <module>metrics</module>
45 <module>oecfg</module> 42 <module>oecfg</module>
46 - <module>demo</module>
47 - <module>election</module>
48 <module>routing</module> 43 <module>routing</module>
49 <module>routing-api</module> 44 <module>routing-api</module>
50 <module>bgprouter</module> 45 <module>bgprouter</module>
51 - <module>intent-perf</module>
52 - <module>database-perf</module>
53 </modules> 46 </modules>
54 47
55 <properties> 48 <properties>
......
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015 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 -<app name="org.onosproject.app.tvue" origin="ON.Lab" version="1.1.0"
18 - features="onos-app-tvue">
19 - <description>Early prototype GUI (deprecated)</description>
20 -</app>
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-apps</artifactId>
25 - <version>1.2.0-SNAPSHOT</version>
26 - <relativePath>../pom.xml</relativePath>
27 - </parent>
28 -
29 - <artifactId>onos-app-tvue</artifactId>
30 - <packaging>bundle</packaging>
31 -
32 - <description>ONOS simple topology viewer</description>
33 -
34 - <properties>
35 - <web.context>/onos/tvue</web.context>
36 - </properties>
37 -
38 - <dependencies>
39 - <dependency>
40 - <groupId>org.onosproject</groupId>
41 - <artifactId>onlab-rest</artifactId>
42 - <version>${project.version}</version>
43 - </dependency>
44 -
45 - <dependency>
46 - <groupId>com.sun.jersey</groupId>
47 - <artifactId>jersey-servlet</artifactId>
48 - </dependency>
49 - <dependency>
50 - <groupId>com.sun.jersey.jersey-test-framework</groupId>
51 - <artifactId>jersey-test-framework-core</artifactId>
52 - <version>1.18.1</version>
53 - <scope>test</scope>
54 - </dependency>
55 - <dependency>
56 - <groupId>com.sun.jersey.jersey-test-framework</groupId>
57 - <artifactId>jersey-test-framework-grizzly2</artifactId>
58 - <version>1.18.1</version>
59 - <scope>test</scope>
60 - </dependency>
61 -
62 - <dependency>
63 - <groupId>com.fasterxml.jackson.core</groupId>
64 - <artifactId>jackson-databind</artifactId>
65 - </dependency>
66 -
67 - <dependency>
68 - <groupId>com.fasterxml.jackson.core</groupId>
69 - <artifactId>jackson-annotations</artifactId>
70 - </dependency>
71 -
72 - <dependency>
73 - <groupId>org.osgi</groupId>
74 - <artifactId>org.osgi.core</artifactId>
75 - </dependency>
76 - </dependencies>
77 -
78 - <build>
79 - <plugins>
80 - <plugin>
81 - <groupId>org.apache.felix</groupId>
82 - <artifactId>maven-bundle-plugin</artifactId>
83 - <extensions>true</extensions>
84 - <configuration>
85 - <instructions>
86 - <_wab>src/main/webapp/</_wab>
87 - <Bundle-SymbolicName>
88 - ${project.groupId}.${project.artifactId}
89 - </Bundle-SymbolicName>
90 - <Import-Package>
91 - org.osgi.framework,
92 - javax.ws.rs,javax.ws.rs.core,
93 - com.sun.jersey.api.core,
94 - com.sun.jersey.spi.container.servlet,
95 - com.sun.jersey.server.impl.container.servlet,
96 - com.fasterxml.jackson.databind,
97 - com.fasterxml.jackson.databind.node,
98 - org.onlab.packet.*,
99 - org.onlab.rest.*,
100 - org.onosproject.*
101 - </Import-Package>
102 - <Web-ContextPath>${web.context}</Web-ContextPath>
103 - </instructions>
104 - </configuration>
105 - </plugin>
106 - </plugins>
107 - </build>
108 -
109 -</project>
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.tvue;
17 -
18 -import com.fasterxml.jackson.databind.ObjectMapper;
19 -import com.fasterxml.jackson.databind.node.ArrayNode;
20 -import com.fasterxml.jackson.databind.node.ObjectNode;
21 -import org.onosproject.net.ConnectPoint;
22 -import org.onosproject.net.ElementId;
23 -import org.onosproject.net.Host;
24 -import org.onosproject.net.Link;
25 -import org.onosproject.net.Path;
26 -import org.onosproject.net.device.DeviceService;
27 -import org.onosproject.net.host.HostService;
28 -import org.onosproject.net.link.LinkService;
29 -import org.onosproject.net.topology.PathService;
30 -import org.onosproject.net.topology.Topology;
31 -import org.onosproject.net.topology.TopologyGraph;
32 -import org.onosproject.net.topology.TopologyService;
33 -import org.onosproject.net.topology.TopologyVertex;
34 -import org.onlab.packet.IpAddress;
35 -import org.onlab.rest.BaseResource;
36 -
37 -import javax.ws.rs.GET;
38 -import javax.ws.rs.PathParam;
39 -import javax.ws.rs.Produces;
40 -import javax.ws.rs.core.Response;
41 -import java.util.HashMap;
42 -import java.util.HashSet;
43 -import java.util.Map;
44 -import java.util.Set;
45 -
46 -import static org.onosproject.net.DeviceId.deviceId;
47 -import static org.onosproject.net.HostId.hostId;
48 -import static org.onosproject.net.PortNumber.portNumber;
49 -
50 -/**
51 - * Topology viewer resource.
52 - */
53 -@javax.ws.rs.Path("topology")
54 -public class TopologyResource extends BaseResource {
55 -
56 - @javax.ws.rs.Path("/graph")
57 - @GET
58 - @Produces("application/json")
59 - public Response graph() {
60 - ObjectMapper mapper = new ObjectMapper();
61 -
62 - // Fetch the services we'll be using.
63 - DeviceService deviceService = get(DeviceService.class);
64 - HostService hostService = get(HostService.class);
65 - TopologyService topologyService = get(TopologyService.class);
66 -
67 - // Fetch the current topology and its graph that we'll use to render.
68 - Topology topo = topologyService.currentTopology();
69 - TopologyGraph graph = topologyService.getGraph(topo);
70 -
71 - // Build all interior vertexes, i.e. no end-station hosts yet
72 - ArrayNode vertexesNode = mapper.createArrayNode();
73 - for (TopologyVertex vertex : graph.getVertexes()) {
74 - vertexesNode.add(json(mapper, vertex.deviceId(), 2,
75 - vertex.deviceId().uri().getSchemeSpecificPart(),
76 - deviceService.isAvailable(vertex.deviceId())));
77 - }
78 -
79 - // Now scan all links and count number of them between the same devices
80 - // using a normalized link key.
81 - Map<String, AggLink> linkRecords = aggregateLinks();
82 -
83 - // Now build all interior edges using the aggregated links.
84 - ArrayNode edgesNode = mapper.createArrayNode();
85 - for (AggLink lr : linkRecords.values()) {
86 - edgesNode.add(json(mapper, lr.links.size(), lr.link.src(), lr.link.dst()));
87 - }
88 -
89 - // Merge the exterior and interior vertexes and inject host links as
90 - // the exterior edges.
91 - for (Host host : hostService.getHosts()) {
92 - Set<IpAddress> ipAddresses = host.ipAddresses();
93 - IpAddress ipAddress = ipAddresses.isEmpty() ? null : ipAddresses.iterator().next();
94 - String label = ipAddress != null ? ipAddress.toString() : host.mac().toString();
95 - vertexesNode.add(json(mapper, host.id(), 3, label, true));
96 - edgesNode.add(json(mapper, 1, host.location(), new ConnectPoint(host.id(), portNumber(-1))));
97 - }
98 -
99 - // Now put the vertexes and edges into a root node and ship them off
100 - ObjectNode rootNode = mapper.createObjectNode();
101 - rootNode.set("vertexes", vertexesNode);
102 - rootNode.set("edges", edgesNode);
103 - return Response.ok(rootNode.toString()).build();
104 - }
105 -
106 -
107 - /**
108 - * Returns a JSON array of all paths between the specified hosts.
109 - *
110 - * @param src source host id
111 - * @param dst target host id
112 - * @return JSON array of paths
113 - */
114 - @javax.ws.rs.Path("/paths/{src}/{dst}")
115 - @GET
116 - @Produces("application/json")
117 - public Response paths(@PathParam("src") String src, @PathParam("dst") String dst) {
118 - ObjectMapper mapper = new ObjectMapper();
119 - PathService pathService = get(PathService.class);
120 - Set<Path> paths = pathService.getPaths(elementId(src), elementId(dst));
121 -
122 - ArrayNode pathsNode = mapper.createArrayNode();
123 - for (Path path : paths) {
124 - pathsNode.add(json(mapper, path));
125 - }
126 -
127 - // Now put the vertexes and edges into a root node and ship them off
128 - ObjectNode rootNode = mapper.createObjectNode();
129 - rootNode.set("paths", pathsNode);
130 - return Response.ok(rootNode.toString()).build();
131 - }
132 -
133 - // Creates either device ID or host ID as appropriate.
134 - private ElementId elementId(String id) {
135 - return id.startsWith("nic:") ? hostId(id) : deviceId(id);
136 - }
137 -
138 - // Scan all links and counts number of them between the same devices
139 - // using a normalized link key.
140 - private Map<String, AggLink> aggregateLinks() {
141 - Map<String, AggLink> aggLinks = new HashMap<>();
142 - LinkService linkService = get(LinkService.class);
143 - for (Link link : linkService.getLinks()) {
144 - String key = key(link);
145 - AggLink lr = aggLinks.get(key);
146 - if (lr == null) {
147 - lr = new AggLink(key);
148 - aggLinks.put(key, lr);
149 - }
150 - lr.addLink(link);
151 - }
152 - return aggLinks;
153 - }
154 -
155 - // Produces JSON for a graph vertex.
156 - private ObjectNode json(ObjectMapper mapper, ElementId id, int group,
157 - String label, boolean isOnline) {
158 - return mapper.createObjectNode()
159 - .put("name", id.toString())
160 - .put("label", label)
161 - .put("group", group)
162 - .put("online", isOnline);
163 - }
164 -
165 - // Produces JSON for a graph edge.
166 - private ObjectNode json(ObjectMapper mapper, int count,
167 - ConnectPoint src, ConnectPoint dst) {
168 - return json(mapper, count, id(src), id(dst));
169 - }
170 -
171 - // Produces JSON for a graph edge.
172 - private ObjectNode json(ObjectMapper mapper, int count, String src, String dst) {
173 - return mapper.createObjectNode()
174 - .put("source", src).put("target", dst).put("value", count);
175 - }
176 -
177 - // Produces JSON representation of a network path.
178 - private ArrayNode json(ObjectMapper mapper, Path path) {
179 - ArrayNode pathNode = mapper.createArrayNode();
180 - for (Link link : path.links()) {
181 - ObjectNode linkNode = mapper.createObjectNode()
182 - .put("src", id(link.src()))
183 - .put("dst", id(link.dst()));
184 - pathNode.add(linkNode);
185 - }
186 - return pathNode;
187 - }
188 -
189 -
190 - // Aggregate link of all links between the same devices regardless of
191 - // their direction.
192 - private class AggLink {
193 - Link link; // representative links
194 -
195 - final String key;
196 - final Set<Link> links = new HashSet<>();
197 -
198 - AggLink(String key) {
199 - this.key = key;
200 - }
201 -
202 - void addLink(Link link) {
203 - links.add(link);
204 - if (this.link == null) {
205 - this.link = link;
206 - }
207 - }
208 - }
209 -
210 - // Returns a canonical key for the specified link.
211 - static String key(Link link) {
212 - String s = id(link.src());
213 - String d = id(link.dst());
214 - return s.compareTo(d) > 0 ? d + s : s + d;
215 - }
216 -
217 - // Returns a formatted string for the element associated with the given
218 - // connection point.
219 - private static String id(ConnectPoint cp) {
220 - return cp.elementId().toString();
221 - }
222 -
223 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Sample topology viewer application.
19 - */
20 -package org.onosproject.tvue;
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 -<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
18 - xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
19 - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
20 - id="ONOS" version="2.5">
21 - <display-name>ONOS GUI</display-name>
22 -
23 - <welcome-file-list>
24 - <welcome-file>index.html</welcome-file>
25 - </welcome-file-list>
26 -
27 - <servlet>
28 - <servlet-name>JAX-RS Service</servlet-name>
29 - <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
30 - <init-param>
31 - <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
32 - <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
33 - </init-param>
34 - <init-param>
35 - <!--param-name>com.sun.jersey.config.property.packages</param-name>
36 - <param-value>org.onosproject.tvue</param-value-->
37 - <param-name>com.sun.jersey.config.property.classnames</param-name>
38 - <param-value>org.onosproject.tvue.TopologyResource</param-value>
39 - </init-param>
40 - <load-on-startup>10</load-on-startup>
41 - </servlet>
42 -
43 - <servlet-mapping>
44 - <servlet-name>JAX-RS Service</servlet-name>
45 - <url-pattern>/rs/*</url-pattern>
46 - </servlet-mapping>
47 -
48 -</web-app>
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.