Simon Hunt

Topology Overlay Archetype (uitopo) - first pass.

Change-Id: I483aca5d12f7e5bd4daf5577be5329c78e780efc
Showing 18 changed files with 1075 additions and 1 deletions
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
39 <module>cli</module> 39 <module>cli</module>
40 <module>ui</module> 40 <module>ui</module>
41 <module>uitab</module> 41 <module>uitab</module>
42 + <module>uitopo</module>
42 </modules> 43 </modules>
43 44
44 <build> 45 <build>
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
26 A message from our sponsors: 26 A message from our sponsors:
27 </p> 27 </p>
28 <p> 28 <p>
29 - <span class="quote">{{data.message}} </span> 29 + <span class="quote"> {{data.message}} </span>
30 </p> 30 </p>
31 </div> 31 </div>
32 </div> 32 </div>
......
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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18 + <modelVersion>4.0.0</modelVersion>
19 +
20 + <parent>
21 + <groupId>org.onosproject</groupId>
22 + <artifactId>onos-archetypes</artifactId>
23 + <version>1.4.0-SNAPSHOT</version>
24 + </parent>
25 +
26 + <artifactId>onos-uitopo-archetype</artifactId>
27 + <packaging>maven-archetype</packaging>
28 +
29 + <description>ONOS UI Topology-Overlay overlay archetype</description>
30 +
31 +</project>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +
3 +<!--
4 + ~ Copyright 2015 Open Networking Laboratory
5 + ~
6 + ~ Licensed under the Apache License, Version 2.0 (the "License");
7 + ~ you may not use this file except in compliance with the License.
8 + ~ You may obtain a copy of the License at
9 + ~
10 + ~ http://www.apache.org/licenses/LICENSE-2.0
11 + ~
12 + ~ Unless required by applicable law or agreed to in writing, software
13 + ~ distributed under the License is distributed on an "AS IS" BASIS,
14 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 + ~ See the License for the specific language governing permissions and
16 + ~ limitations under the License.
17 + -->
18 +<archetype-descriptor
19 + xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
20 + name="onos-uitopo" partial="true"
21 + xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
22 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
23 + <fileSets>
24 + <fileSet filtered="true" packaged="true" encoding="UTF-8">
25 + <directory>src/main/java</directory>
26 + <includes>
27 + <include>**/*.java</include>
28 + </includes>
29 + </fileSet>
30 + <fileSet filtered="true" packaged="false" encoding="UTF-8">
31 + <directory>src/main/resources</directory>
32 + <includes>
33 + <include>**/*.html</include>
34 + <include>**/*.js</include>
35 + <include>**/*.css</include>
36 + </includes>
37 + </fileSet>
38 + </fileSets>
39 +</archetype-descriptor>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +
3 +<!--
4 + ~ Copyright 2015 Open Networking Laboratory
5 + ~
6 + ~ Licensed under the Apache License, Version 2.0 (the "License");
7 + ~ you may not use this file except in compliance with the License.
8 + ~ You may obtain a copy of the License at
9 + ~
10 + ~ http://www.apache.org/licenses/LICENSE-2.0
11 + ~
12 + ~ Unless required by applicable law or agreed to in writing, software
13 + ~ distributed under the License is distributed on an "AS IS" BASIS,
14 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 + ~ See the License for the specific language governing permissions and
16 + ~ limitations under the License.
17 + -->
18 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
19 + <modelVersion>4.0.0</modelVersion>
20 +
21 + <groupId>${groupId}</groupId>
22 + <artifactId>${artifactId}</artifactId>
23 + <version>${version}</version>
24 + <packaging>bundle</packaging>
25 +
26 + <description>ONOS OSGi UI Topology-Overlay bundle archetype</description>
27 + <url>http://onosproject.org</url>
28 +
29 + <properties>
30 + <onos.version>1.4.0-SNAPSHOT</onos.version>
31 + <!-- Uncomment to generate ONOS app from this module.
32 + <onos.app.name>org.foo.app</onos.app.name>
33 + <onos.app.origin>Foo, Inc.</onos.app.origin>
34 + -->
35 + </properties>
36 +
37 + <dependencies>
38 + <dependency>
39 + <groupId>org.onosproject</groupId>
40 + <artifactId>onos-api</artifactId>
41 + <version>${onos.version}</version>
42 + </dependency>
43 +
44 + <dependency>
45 + <groupId>org.onosproject</groupId>
46 + <artifactId>onlab-osgi</artifactId>
47 + <version>${onos.version}</version>
48 + </dependency>
49 +
50 + <dependency>
51 + <groupId>junit</groupId>
52 + <artifactId>junit</artifactId>
53 + <version>4.11</version>
54 + <scope>test</scope>
55 + </dependency>
56 +
57 + <dependency>
58 + <groupId>org.onosproject</groupId>
59 + <artifactId>onos-api</artifactId>
60 + <version>${onos.version}</version>
61 + <scope>test</scope>
62 + <classifier>tests</classifier>
63 + </dependency>
64 +
65 + <dependency>
66 + <groupId>org.apache.felix</groupId>
67 + <artifactId>org.apache.felix.scr.annotations</artifactId>
68 + <version>1.9.8</version>
69 + <scope>provided</scope>
70 + </dependency>
71 + </dependencies>
72 +
73 + <build>
74 + <plugins>
75 + <plugin>
76 + <groupId>org.apache.felix</groupId>
77 + <artifactId>maven-bundle-plugin</artifactId>
78 + <version>2.5.3</version>
79 + <extensions>true</extensions>
80 + </plugin>
81 + <plugin>
82 + <groupId>org.apache.maven.plugins</groupId>
83 + <artifactId>maven-compiler-plugin</artifactId>
84 + <version>2.5.1</version>
85 + <configuration>
86 + <source>1.8</source>
87 + <target>1.8</target>
88 + </configuration>
89 + </plugin>
90 + <plugin>
91 + <groupId>org.apache.felix</groupId>
92 + <artifactId>maven-scr-plugin</artifactId>
93 + <version>1.20.0</version>
94 + <executions>
95 + <execution>
96 + <id>generate-scr-srcdescriptor</id>
97 + <goals>
98 + <goal>scr</goal>
99 + </goals>
100 + </execution>
101 + </executions>
102 + <configuration>
103 + <supportedProjectTypes>
104 + <supportedProjectType>bundle</supportedProjectType>
105 + <supportedProjectType>war</supportedProjectType>
106 + </supportedProjectTypes>
107 + </configuration>
108 + </plugin>
109 + <plugin>
110 + <groupId>org.onosproject</groupId>
111 + <artifactId>onos-maven-plugin</artifactId>
112 + <version>1.5</version>
113 + <executions>
114 + <execution>
115 + <id>cfg</id>
116 + <phase>generate-resources</phase>
117 + <goals>
118 + <goal>cfg</goal>
119 + </goals>
120 + </execution>
121 + <execution>
122 + <id>swagger</id>
123 + <phase>generate-sources</phase>
124 + <goals>
125 + <goal>swagger</goal>
126 + </goals>
127 + </execution>
128 + <execution>
129 + <id>app</id>
130 + <phase>package</phase>
131 + <goals>
132 + <goal>app</goal>
133 + </goals>
134 + </execution>
135 + </executions>
136 + </plugin>
137 + </plugins>
138 + </build>
139 +
140 +</project>
1 +#set( $symbol_pound = '#' )
2 +#set( $symbol_dollar = '$' )
3 +#set( $symbol_escape = '\' )
4 +/*
5 + * Copyright 2014,2015 Open Networking Laboratory
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License");
8 + * you may not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS,
15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +package ${package};
20 +
21 +import com.google.common.collect.ImmutableList;
22 +import org.apache.felix.scr.annotations.Activate;
23 +import org.apache.felix.scr.annotations.Component;
24 +import org.apache.felix.scr.annotations.Deactivate;
25 +import org.apache.felix.scr.annotations.Reference;
26 +import org.apache.felix.scr.annotations.ReferenceCardinality;
27 +import org.onosproject.ui.UiExtension;
28 +import org.onosproject.ui.UiExtensionService;
29 +import org.onosproject.ui.UiMessageHandlerFactory;
30 +import org.onosproject.ui.UiTopoOverlayFactory;
31 +import org.onosproject.ui.UiView;
32 +import org.onosproject.ui.UiViewHidden;
33 +import org.slf4j.Logger;
34 +import org.slf4j.LoggerFactory;
35 +
36 +import java.util.List;
37 +
38 +/**
39 + * Skeletal ONOS UI Topology-Overlay application component.
40 + */
41 +@Component(immediate = true)
42 +public class AppUiTopovComponent {
43 +
44 + private static final ClassLoader CL = AppUiTopovComponent.class.getClassLoader();
45 +
46 + private final Logger log = LoggerFactory.getLogger(getClass());
47 +
48 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
49 + protected UiExtensionService uiExtensionService;
50 +
51 + // List of application views
52 + private final List<UiView> uiViews = ImmutableList.of(
53 + new UiViewHidden("sampleTopov")
54 + );
55 +
56 + // Factory for UI message handlers
57 + private final UiMessageHandlerFactory messageHandlerFactory =
58 + () -> ImmutableList.of(
59 + new AppUiTopovMessageHandler()
60 + );
61 +
62 + // Factory for UI topology overlays
63 + private final UiTopoOverlayFactory topoOverlayFactory =
64 + () -> ImmutableList.of(
65 + new AppUiTopovOverlay()
66 + );
67 +
68 + // Application UI extension
69 + protected UiExtension extension =
70 + new UiExtension.Builder(CL, uiViews)
71 + .resourcePath("sampleTopov")
72 + .messageHandlerFactory(messageHandlerFactory)
73 + .topoOverlayFactory(topoOverlayFactory)
74 + .build();
75 +
76 + @Activate
77 + protected void activate() {
78 + uiExtensionService.register(extension);
79 + log.info("Started");
80 + }
81 +
82 + @Deactivate
83 + protected void deactivate() {
84 + uiExtensionService.unregister(extension);
85 + log.info("Stopped");
86 + }
87 +
88 +}
1 +#set( $symbol_pound = '#' )
2 +#set( $symbol_dollar = '$' )
3 +#set( $symbol_escape = '\' )
4 +/*
5 + * Copyright 2014,2015 Open Networking Laboratory
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License");
8 + * you may not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS,
15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +package ${package};
20 +
21 +import com.fasterxml.jackson.databind.node.ObjectNode;
22 +import com.google.common.base.Strings;
23 +import com.google.common.collect.ImmutableSet;
24 +import org.onlab.osgi.ServiceDirectory;
25 +import org.onosproject.net.Device;
26 +import org.onosproject.net.DeviceId;
27 +import org.onosproject.net.Element;
28 +import org.onosproject.net.HostId;
29 +import org.onosproject.net.Link;
30 +import org.onosproject.net.device.DeviceService;
31 +import org.onosproject.net.host.HostService;
32 +import org.onosproject.net.link.LinkService;
33 +import org.onosproject.ui.RequestHandler;
34 +import org.onosproject.ui.UiConnection;
35 +import org.onosproject.ui.UiMessageHandler;
36 +import org.onosproject.ui.topo.Highlights;
37 +import org.onosproject.ui.topo.TopoJson;
38 +import org.slf4j.Logger;
39 +import org.slf4j.LoggerFactory;
40 +
41 +import java.util.Collection;
42 +import java.util.HashSet;
43 +import java.util.Set;
44 +import java.util.Timer;
45 +import java.util.TimerTask;
46 +
47 +/**
48 + * Skeletal ONOS UI Topology-Overlay message handler.
49 + */
50 +public class AppUiTopovMessageHandler extends UiMessageHandler {
51 +
52 + private static final String SAMPLE_DISPLAY_START = "sampleDisplayStart";
53 + private static final String SAMPLE_DISPLAY_UPDATE = "sampleDisplayUpdate";
54 + private static final String SAMPLE_DISPLAY_STOP = "sampleDisplayStop";
55 +
56 + private static final String ID = "id";
57 + private static final String MODE = "mode";
58 +
59 + private static final long UPDATE_PERIOD_MS = 1000;
60 +
61 + private static final Link[] EMPTY_LINK_SET = new Link[0];
62 +
63 + private enum Mode { IDLE, MOUSE, LINK }
64 +
65 + private final Logger log = LoggerFactory.getLogger(getClass());
66 +
67 + private DeviceService deviceService;
68 + private HostService hostService;
69 + private LinkService linkService;
70 +
71 + private final Timer timer = new Timer("sample-overlay");
72 + private TimerTask demoTask = null;
73 + private Mode currentMode = Mode.IDLE;
74 + private Element elementOfNote;
75 + private Link[] linkSet = EMPTY_LINK_SET;
76 + private int linkIndex;
77 +
78 +
79 + // ===============-=-=-=-=-=-======================-=-=-=-=-=-=-================================
80 +
81 +
82 + @Override
83 + public void init(UiConnection connection, ServiceDirectory directory) {
84 + super.init(connection, directory);
85 + deviceService = directory.get(DeviceService.class);
86 + hostService = directory.get(HostService.class);
87 + linkService = directory.get(LinkService.class);
88 + }
89 +
90 + @Override
91 + protected Collection<RequestHandler> createRequestHandlers() {
92 + return ImmutableSet.of(
93 + new DisplayStartHandler(),
94 + new DisplayUpdateHandler(),
95 + new DisplayStopHandler()
96 + );
97 + }
98 +
99 + // === -------------------------
100 + // === Handler classes
101 +
102 + private final class DisplayStartHandler extends RequestHandler {
103 + public DisplayStartHandler() {
104 + super(SAMPLE_DISPLAY_START);
105 + }
106 +
107 + @Override
108 + public void process(long sid, ObjectNode payload) {
109 + String mode = string(payload, MODE);
110 +
111 + log.debug("Start Display: mode [{}]", mode);
112 + clearState();
113 + clearForMode();
114 +
115 + switch (mode) {
116 + case "mouse":
117 + currentMode = Mode.MOUSE;
118 + cancelTask();
119 + sendMouseData();
120 + break;
121 +
122 + case "link":
123 + currentMode = Mode.LINK;
124 + scheduleTask();
125 + initLinkSet();
126 + sendLinkData();
127 + break;
128 +
129 + default:
130 + currentMode = Mode.IDLE;
131 + cancelTask();
132 + break;
133 + }
134 + }
135 + }
136 +
137 + private final class DisplayUpdateHandler extends RequestHandler {
138 + public DisplayUpdateHandler() {
139 + super(SAMPLE_DISPLAY_UPDATE);
140 + }
141 +
142 + @Override
143 + public void process(long sid, ObjectNode payload) {
144 + String id = string(payload, ID);
145 + log.debug("Update Display: id [{}]", id);
146 + if (!Strings.isNullOrEmpty(id)) {
147 + updateForMode(id);
148 + } else {
149 + clearForMode();
150 + }
151 + }
152 + }
153 +
154 + private final class DisplayStopHandler extends RequestHandler {
155 + public DisplayStopHandler() {
156 + super(SAMPLE_DISPLAY_STOP);
157 + }
158 +
159 + @Override
160 + public void process(long sid, ObjectNode payload) {
161 + log.debug("Stop Display");
162 + cancelTask();
163 + clearState();
164 + clearForMode();
165 + }
166 + }
167 +
168 + // === ------------
169 +
170 + private void clearState() {
171 + currentMode = Mode.IDLE;
172 + elementOfNote = null;
173 + linkSet = EMPTY_LINK_SET;
174 + }
175 +
176 + private void updateForMode(String id) {
177 + log.debug("host service: {}", hostService);
178 + log.debug("device service: {}", deviceService);
179 +
180 + try {
181 + HostId hid = HostId.hostId(id);
182 + log.debug("host id {}", hid);
183 + elementOfNote = hostService.getHost(hid);
184 + log.debug("host element {}", elementOfNote);
185 +
186 + } catch (Exception e) {
187 + try {
188 + DeviceId did = DeviceId.deviceId(id);
189 + log.debug("device id {}", did);
190 + elementOfNote = deviceService.getDevice(did);
191 + log.debug("device element {}", elementOfNote);
192 +
193 + } catch (Exception e2) {
194 + log.debug("Unable to process ID [{}]", id);
195 + elementOfNote = null;
196 + }
197 + }
198 +
199 + switch (currentMode) {
200 + case MOUSE:
201 + sendMouseData();
202 + break;
203 +
204 + case LINK:
205 + sendLinkData();
206 + break;
207 +
208 + default:
209 + break;
210 + }
211 +
212 + }
213 +
214 + private void clearForMode() {
215 + sendHighlights(new Highlights());
216 + }
217 +
218 + private void sendHighlights(Highlights highlights) {
219 + sendMessage(TopoJson.highlightsMessage(highlights));
220 + }
221 +
222 +
223 + private void sendMouseData() {
224 + if (elementOfNote != null && elementOfNote instanceof Device) {
225 + DeviceId devId = (DeviceId) elementOfNote.id();
226 + Set<Link> links = linkService.getDeviceEgressLinks(devId);
227 + sendHighlights(fromLinks(links, devId));
228 + }
229 + // Note: could also process Host, if available
230 + }
231 +
232 + private Highlights fromLinks(Set<Link> links, DeviceId devId) {
233 + DemoLinkMap linkMap = new DemoLinkMap();
234 + if (links != null) {
235 + log.debug("Processing {} links", links.size());
236 + links.forEach(linkMap::add);
237 + } else {
238 + log.debug("No egress links found for device {}", devId);
239 + }
240 +
241 + Highlights highlights = new Highlights();
242 +
243 + for (DemoLink dlink : linkMap.biLinks()) {
244 + dlink.makeImportant().setLabel("Yo!");
245 + highlights.add(dlink.highlight(null));
246 + }
247 + return highlights;
248 + }
249 +
250 + private void initLinkSet() {
251 + Set<Link> links = new HashSet<>();
252 + for (Link link : linkService.getActiveLinks()) {
253 + links.add(link);
254 + }
255 + linkSet = links.toArray(new Link[links.size()]);
256 + linkIndex = 0;
257 + log.debug("initialized link set to {}", linkSet.length);
258 + }
259 +
260 + private void sendLinkData() {
261 + DemoLinkMap linkMap = new DemoLinkMap();
262 + for (Link link : linkSet) {
263 + linkMap.add(link);
264 + }
265 + DemoLink dl = linkMap.add(linkSet[linkIndex]);
266 + dl.makeImportant().setLabel(Integer.toString(linkIndex));
267 + log.debug("sending link data (index {})", linkIndex);
268 +
269 + linkIndex += 1;
270 + if (linkIndex >= linkSet.length) {
271 + linkIndex = 0;
272 + }
273 +
274 + Highlights highlights = new Highlights();
275 + for (DemoLink dlink : linkMap.biLinks()) {
276 + highlights.add(dlink.highlight(null));
277 + }
278 +
279 + sendHighlights(highlights);
280 + }
281 +
282 + private synchronized void scheduleTask() {
283 + if (demoTask == null) {
284 + log.debug("Starting up demo task...");
285 + demoTask = new DisplayUpdateTask();
286 + timer.schedule(demoTask, UPDATE_PERIOD_MS, UPDATE_PERIOD_MS);
287 + } else {
288 + log.debug("(demo task already running");
289 + }
290 + }
291 +
292 + private synchronized void cancelTask() {
293 + if (demoTask != null) {
294 + demoTask.cancel();
295 + demoTask = null;
296 + }
297 + }
298 +
299 +
300 + private class DisplayUpdateTask extends TimerTask {
301 + @Override
302 + public void run() {
303 + try {
304 + switch (currentMode) {
305 + case LINK:
306 + sendLinkData();
307 + break;
308 +
309 + default:
310 + break;
311 + }
312 + } catch (Exception e) {
313 + log.warn("Unable to process demo task: {}", e.getMessage());
314 + log.debug("Oops", e);
315 + }
316 + }
317 + }
318 +
319 +}
...\ No newline at end of file ...\ No newline at end of file
1 +#set( $symbol_pound = '#' )
2 +#set( $symbol_dollar = '$' )
3 +#set( $symbol_escape = '\' )
4 +/*
5 + * Copyright 2014,2015 Open Networking Laboratory
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License");
8 + * you may not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS,
15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +package ${package};
20 +
21 +import org.onosproject.ui.UiTopoOverlay;
22 +import org.onosproject.ui.topo.ButtonId;
23 +import org.onosproject.ui.topo.PropertyPanel;
24 +import org.onosproject.ui.topo.TopoConstants.CoreButtons;
25 +import org.onosproject.ui.topo.TopoConstants.Glyphs;
26 +
27 +import static org.onosproject.ui.topo.TopoConstants.Properties.*;
28 +
29 +/**
30 + * Our topology overlay.
31 + */
32 +public class AppUiTopovOverlay extends UiTopoOverlay {
33 +
34 + // NOTE: this must match the ID defined in sampleTopov.js
35 + private static final String OVERLAY_ID = "meowster-overlay";
36 +
37 + private static final String MY_TITLE = "My App Rocks!";
38 + private static final String MY_VERSION = "Beta-1.0.0042";
39 + private static final String MY_DEVICE_TITLE = "I changed the title";
40 +
41 + private static final ButtonId FOO_BUTTON = new ButtonId("foo");
42 + private static final ButtonId BAR_BUTTON = new ButtonId("bar");
43 +
44 + public AppUiTopovOverlay() {
45 + super(OVERLAY_ID);
46 + }
47 +
48 +
49 + @Override
50 + public void modifySummary(PropertyPanel pp) {
51 + pp.title(MY_TITLE)
52 + .typeId(Glyphs.CROWN)
53 + .removeProps(
54 + TOPOLOGY_SSCS,
55 + INTENTS,
56 + TUNNELS,
57 + FLOWS,
58 + VERSION
59 + )
60 + .addProp(VERSION, MY_VERSION);
61 + }
62 +
63 + @Override
64 + public void modifyDeviceDetails(PropertyPanel pp) {
65 + pp.title(MY_DEVICE_TITLE);
66 + pp.removeProps(LATITUDE, LONGITUDE);
67 +
68 + pp.addButton(FOO_BUTTON)
69 + .addButton(BAR_BUTTON);
70 +
71 + pp.removeButtons(CoreButtons.SHOW_PORT_VIEW)
72 + .removeButtons(CoreButtons.SHOW_GROUP_VIEW);
73 + }
74 +
75 +}
1 +#set( $symbol_pound = '#' )
2 +#set( $symbol_dollar = '$' )
3 +#set( $symbol_escape = '\' )
4 +/*
5 + * Copyright 2014,2015 Open Networking Laboratory
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License");
8 + * you may not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS,
15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +package ${package};
20 +
21 +import org.onosproject.net.Link;
22 +import org.onosproject.net.LinkKey;
23 +import org.onosproject.ui.topo.BiLink;
24 +import org.onosproject.ui.topo.LinkHighlight;
25 +import org.onosproject.ui.topo.LinkHighlight.Flavor;
26 +
27 +/**
28 + * Our demo concrete class of a bi-link. We give it state so we can decide
29 + * how to create link highlights.
30 + */
31 +public class DemoLink extends BiLink {
32 +
33 + private boolean important = false;
34 + private String label = null;
35 +
36 + public DemoLink(LinkKey key, Link link) {
37 + super(key, link);
38 + }
39 +
40 + public DemoLink makeImportant() {
41 + important = true;
42 + return this;
43 + }
44 +
45 + public DemoLink setLabel(String label) {
46 + this.label = label;
47 + return this;
48 + }
49 +
50 + @Override
51 + public LinkHighlight highlight(Enum<?> anEnum) {
52 + Flavor flavor = important ? Flavor.PRIMARY_HIGHLIGHT
53 + : Flavor.SECONDARY_HIGHLIGHT;
54 + return new LinkHighlight(this.linkId(), flavor)
55 + .setLabel(label);
56 + }
57 +}
1 +#set( $symbol_pound = '#' )
2 +#set( $symbol_dollar = '$' )
3 +#set( $symbol_escape = '\' )
4 +/*
5 + * Copyright 2014,2015 Open Networking Laboratory
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License");
8 + * you may not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS,
15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +package ${package};
20 +
21 +import org.onosproject.net.Link;
22 +import org.onosproject.net.LinkKey;
23 +import org.onosproject.ui.topo.BiLinkMap;
24 +
25 +/**
26 + * Our concrete link map.
27 + */
28 +public class DemoLinkMap extends BiLinkMap<DemoLink> {
29 + @Override
30 + protected DemoLink create(LinkKey linkKey, Link link) {
31 + return new DemoLink(linkKey, link);
32 + }
33 +}
1 +<!-- partial HTML -->
2 +<div id="ov-sample-topov">
3 + <p>This is a hidden view .. just a placeholder to house the javascript</p>
4 +</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 + Sample Demo module. This contains the "business logic" for the topology
19 + overlay that we are implementing.
20 + */
21 +
22 +(function () {
23 + 'use strict';
24 +
25 + // injected refs
26 + var $log, fs, flash, wss;
27 +
28 + // constants
29 + var displayStart = 'sampleDisplayStart',
30 + displayUpdate = 'sampleDisplayUpdate',
31 + displayStop = 'sampleDisplayStop';
32 +
33 + // internal state
34 + var currentMode = null;
35 +
36 +
37 + // === ---------------------------
38 + // === Helper functions
39 +
40 + function sendDisplayStart(mode) {
41 + wss.sendEvent(displayStart, {
42 + mode: mode
43 + });
44 + }
45 +
46 + function sendDisplayUpdate(what) {
47 + wss.sendEvent(displayUpdate, {
48 + id: what ? what.id : ''
49 + });
50 + }
51 +
52 + function sendDisplayStop() {
53 + wss.sendEvent(displayStop);
54 + }
55 +
56 + // === ---------------------------
57 + // === Main API functions
58 +
59 + function startDisplay(mode) {
60 + if (currentMode === mode) {
61 + $log.debug('(in mode', mode, 'already)');
62 + } else {
63 + currentMode = mode;
64 + sendDisplayStart(mode);
65 + flash.flash('Starting display mode: ' + mode);
66 + }
67 + }
68 +
69 + function updateDisplay(m) {
70 + if (currentMode) {
71 + sendDisplayUpdate(m);
72 + }
73 + }
74 +
75 + function stopDisplay() {
76 + if (currentMode) {
77 + currentMode = null;
78 + sendDisplayStop();
79 + flash.flash('Canceling display mode');
80 + return true;
81 + }
82 + return false;
83 + }
84 +
85 + // === ---------------------------
86 + // === Module Factory Definition
87 +
88 + angular.module('ovSampleTopov', [])
89 + .factory('SampleTopovDemoService',
90 + ['$log', 'FnService', 'FlashService', 'WebSocketService',
91 +
92 + function (_$log_, _fs_, _flash_, _wss_) {
93 + $log = _$log_;
94 + fs = _fs_;
95 + flash = _flash_;
96 + wss = _wss_;
97 +
98 + return {
99 + startDisplay: startDisplay,
100 + updateDisplay: updateDisplay,
101 + stopDisplay: stopDisplay
102 + };
103 + }]);
104 +}());
1 +// sample topology overlay - client side
2 +//
3 +// This is the glue that binds our business logic (in sampleTopovDemo.js)
4 +// to the overlay framework.
5 +
6 +(function () {
7 + 'use strict';
8 +
9 + // injected refs
10 + var $log, tov, stds;
11 +
12 + // internal state should be kept in the service module (not here)
13 +
14 + // our overlay definition
15 + var overlay = {
16 + // NOTE: this must match the ID defined in AppUiTopoOverlay
17 + overlayId: 'meowster-overlay',
18 + glyphId: '*star4',
19 + tooltip: 'Sample Meowster Topo Overlay',
20 +
21 + // These glyphs get installed using the overlayId as a prefix.
22 + // e.g. 'star4' is installed as 'meowster-overlay-star4'
23 + // They can be referenced (from this overlay) as '*star4'
24 + // That is, the '*' prefix stands in for 'meowster-overlay-'
25 + glyphs: {
26 + star4: {
27 + vb: '0 0 8 8',
28 + d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z'
29 + },
30 + banner: {
31 + vb: '0 0 6 6',
32 + d: 'M1,1v4l2,-2l2,2v-4z'
33 + }
34 + },
35 +
36 + activate: function () {
37 + $log.debug("Sample topology overlay ACTIVATED");
38 + },
39 + deactivate: function () {
40 + stds.stopDisplay();
41 + $log.debug("Sample topology overlay DEACTIVATED");
42 + },
43 +
44 + // detail panel button definitions
45 + buttons: {
46 + foo: {
47 + gid: 'chain',
48 + tt: 'A FOO action',
49 + cb: function (data) {
50 + $log.debug('FOO action invoked with data:', data);
51 + }
52 + },
53 + bar: {
54 + gid: '*banner',
55 + tt: 'A BAR action',
56 + cb: function (data) {
57 + $log.debug('BAR action invoked with data:', data);
58 + }
59 + }
60 + },
61 +
62 + // Key bindings for traffic overlay buttons
63 + // NOTE: fully qual. button ID is derived from overlay-id and key-name
64 + keyBindings: {
65 + 0: {
66 + cb: function () { stds.stopDisplay(); },
67 + tt: 'Cancel Display Mode',
68 + gid: 'xMark'
69 + },
70 + V: {
71 + cb: function () { stds.startDisplay('mouse'); },
72 + tt: 'Start Mouse Mode',
73 + gid: '*banner'
74 + },
75 + F: {
76 + cb: function () { stds.startDisplay('link'); },
77 + tt: 'Start Link Mode',
78 + gid: 'chain'
79 + },
80 + G: {
81 + cb: buttonCallback,
82 + tt: 'Uses the G key',
83 + gid: 'crown'
84 + },
85 + T: {
86 + cb: buttonCallback,
87 + tt: 'Uses the T key',
88 + gid: 'switch'
89 + },
90 + R: {
91 + cb: buttonCallback,
92 + tt: 'Uses the R key',
93 + gid: 'endstation'
94 + },
95 +
96 + _keyOrder: [
97 + '0', 'V', 'F', 'G', 'T', 'R'
98 + ]
99 +
100 + // NOTE: T and R should be rejected (not installed)
101 + // T is reserved for 'toggle Theme'
102 + // R is reserved for 'Reset pan and zoom'
103 + },
104 +
105 + hooks: {
106 + // hook for handling escape key
107 + // Must return true to consume ESC, false otherwise.
108 + escape: function () {
109 + // Must return true to consume ESC, false otherwise.
110 + return stds.stopDisplay();
111 + },
112 +
113 + // hooks for when the selection changes...
114 + empty: function () {
115 + selectionCallback('empty');
116 + },
117 + single: function (data) {
118 + selectionCallback('single', data);
119 + },
120 + multi: function (selectOrder) {
121 + selectionCallback('multi', selectOrder);
122 + tov.addDetailButton('foo');
123 + tov.addDetailButton('bar');
124 + },
125 + mouseover: function (m) {
126 + // m has id, class, and type properties
127 + $log.debug('mouseover:', m);
128 + stds.updateDisplay(m);
129 + },
130 + mouseout: function () {
131 + $log.debug('mouseout');
132 + stds.updateDisplay();
133 + }
134 + }
135 + };
136 +
137 +
138 + function buttonCallback(x) {
139 + $log.debug('Toolbar-button callback', x);
140 + }
141 +
142 + function selectionCallback(x, d) {
143 + $log.debug('Selection callback', x, d);
144 + }
145 +
146 + // invoke code to register with the overlay service
147 + angular.module('ovSampleTopov')
148 + .run(['$log', 'TopoOverlayService', 'SampleTopovDemoService',
149 +
150 + function (_$log_, _tov_, _stds_) {
151 + $log = _$log_;
152 + tov = _tov_;
153 + stds = _stds_;
154 + tov.register(overlay);
155 + }]);
156 +
157 +}());
1 +<link rel="stylesheet" href="app/view/sampleTopov/sampleTopov.css">
...\ No newline at end of file ...\ No newline at end of file
1 +<script src="app/view/sampleTopov/sampleTopovDemo.js"></script>
2 +<script src="app/view/sampleTopov/sampleTopovOverlay.js"></script>
...\ 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 +#Thu Dec 04 09:24:50 PST 2014
18 +package=it.pkg
19 +version=0.1-SNAPSHOT
20 +groupId=archetype.it
21 +artifactId=basic