Committed by
Jonathan Hart
Patch Panel Application with Ui
Change-Id: I0906983cf494ce82de233e8bfbd66b60d0792c89
Showing
15 changed files
with
916 additions
and
0 deletions
apps/patchpanel/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016 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 | + <parent> | ||
19 | + <artifactId>onos-apps</artifactId> | ||
20 | + <groupId>org.onosproject</groupId> | ||
21 | + <version>1.7.0-SNAPSHOT</version> | ||
22 | + </parent> | ||
23 | + <modelVersion>4.0.0</modelVersion> | ||
24 | + | ||
25 | + <groupId>org.onosproject</groupId> | ||
26 | + <artifactId>patchPanel</artifactId> | ||
27 | + <version>1.0</version> | ||
28 | + <packaging>bundle</packaging> | ||
29 | + | ||
30 | + <description>ONOS OSGi bundle archetype</description> | ||
31 | + <url>http://onosproject.org</url> | ||
32 | + | ||
33 | + <properties> | ||
34 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
35 | + <onos.version>1.7.0-SNAPSHOT</onos.version> | ||
36 | + <onos.app.name>org.onosproject.patchPanel</onos.app.name> | ||
37 | + <onos.app.title>Patch Panel</onos.app.title> | ||
38 | + <onos.app.origin>Foo, Inc.</onos.app.origin> | ||
39 | + <onos.app.category>default</onos.app.category> | ||
40 | + <onos.app.url>http://onosproject.org</onos.app.url> | ||
41 | + <onos.app.readme>ONOS OSGi bundle archetype.</onos.app.readme> | ||
42 | + | ||
43 | + </properties> | ||
44 | + | ||
45 | + <dependencies> | ||
46 | + <dependency> | ||
47 | + <groupId>org.onosproject</groupId> | ||
48 | + <artifactId>onos-api</artifactId> | ||
49 | + <version>1.7.0-SNAPSHOT</version> | ||
50 | + </dependency> | ||
51 | + | ||
52 | + <dependency> | ||
53 | + <groupId>org.onosproject</groupId> | ||
54 | + <artifactId>onlab-misc</artifactId> | ||
55 | + <version>1.7.0-SNAPSHOT</version> | ||
56 | + </dependency> | ||
57 | + | ||
58 | + <dependency> | ||
59 | + <groupId>org.onosproject</groupId> | ||
60 | + <artifactId>onlab-osgi</artifactId> | ||
61 | + <version>${onos.version}</version> | ||
62 | + </dependency> | ||
63 | + | ||
64 | + <dependency> | ||
65 | + <groupId>junit</groupId> | ||
66 | + <artifactId>junit</artifactId> | ||
67 | + <version>4.12</version> | ||
68 | + <scope>test</scope> | ||
69 | + </dependency> | ||
70 | + | ||
71 | + <dependency> | ||
72 | + <groupId>org.onosproject</groupId> | ||
73 | + <artifactId>onos-api</artifactId> | ||
74 | + <version>${onos.version}</version> | ||
75 | + <scope>test</scope> | ||
76 | + <classifier>tests</classifier> | ||
77 | + </dependency> | ||
78 | + | ||
79 | + <dependency> | ||
80 | + <groupId>org.apache.felix</groupId> | ||
81 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
82 | + <version>1.9.12</version> | ||
83 | + <scope>provided</scope> | ||
84 | + </dependency> | ||
85 | + | ||
86 | + <dependency> | ||
87 | + <groupId>org.onosproject</groupId> | ||
88 | + <artifactId>onos-incubator-api</artifactId> | ||
89 | + <version>1.7.0-SNAPSHOT</version> | ||
90 | + </dependency> | ||
91 | + | ||
92 | + <dependency> | ||
93 | + <groupId>org.onosproject</groupId> | ||
94 | + <artifactId>onos-core-common</artifactId> | ||
95 | + <version>1.7.0-SNAPSHOT</version> | ||
96 | + </dependency> | ||
97 | + | ||
98 | + <dependency> | ||
99 | + <groupId>org.onosproject</groupId> | ||
100 | + <artifactId>onos-cli</artifactId> | ||
101 | + <version>1.7.0-SNAPSHOT</version> | ||
102 | + <scope>provided</scope> | ||
103 | + </dependency> | ||
104 | + | ||
105 | + <dependency> | ||
106 | + <groupId>org.osgi</groupId> | ||
107 | + <artifactId>org.osgi.core</artifactId> | ||
108 | + <version>5.0.0</version> | ||
109 | + <scope>provided</scope> | ||
110 | + </dependency> | ||
111 | + | ||
112 | + <dependency> | ||
113 | + <groupId>org.apache.karaf.shell</groupId> | ||
114 | + <artifactId>org.apache.karaf.shell.console</artifactId> | ||
115 | + <version>3.0.5</version> | ||
116 | + <scope>provided</scope> | ||
117 | + </dependency> | ||
118 | + | ||
119 | + </dependencies> | ||
120 | + | ||
121 | + <build> | ||
122 | + <plugins> | ||
123 | + <plugin> | ||
124 | + <groupId>org.apache.felix</groupId> | ||
125 | + <artifactId>maven-bundle-plugin</artifactId> | ||
126 | + <version>3.0.1</version> | ||
127 | + <extensions>true</extensions> | ||
128 | + </plugin> | ||
129 | + <plugin> | ||
130 | + <groupId>org.apache.maven.plugins</groupId> | ||
131 | + <artifactId>maven-compiler-plugin</artifactId> | ||
132 | + <version>2.5.1</version> | ||
133 | + <configuration> | ||
134 | + <source>1.8</source> | ||
135 | + <target>1.8</target> | ||
136 | + </configuration> | ||
137 | + </plugin> | ||
138 | + <plugin> | ||
139 | + <groupId>org.apache.felix</groupId> | ||
140 | + <artifactId>maven-scr-plugin</artifactId> | ||
141 | + <version>1.21.0</version> | ||
142 | + <executions> | ||
143 | + <execution> | ||
144 | + <id>generate-scr-srcdescriptor</id> | ||
145 | + <goals> | ||
146 | + <goal>scr</goal> | ||
147 | + </goals> | ||
148 | + </execution> | ||
149 | + </executions> | ||
150 | + <configuration> | ||
151 | + <supportedProjectTypes> | ||
152 | + <supportedProjectType>bundle</supportedProjectType> | ||
153 | + <supportedProjectType>war</supportedProjectType> | ||
154 | + </supportedProjectTypes> | ||
155 | + </configuration> | ||
156 | + </plugin> | ||
157 | + <plugin> | ||
158 | + <groupId>org.onosproject</groupId> | ||
159 | + <artifactId>onos-maven-plugin</artifactId> | ||
160 | + <version>1.9</version> | ||
161 | + <executions> | ||
162 | + <execution> | ||
163 | + <id>cfg</id> | ||
164 | + <phase>generate-resources</phase> | ||
165 | + <goals> | ||
166 | + <goal>cfg</goal> | ||
167 | + </goals> | ||
168 | + </execution> | ||
169 | + <execution> | ||
170 | + <id>swagger</id> | ||
171 | + <phase>generate-sources</phase> | ||
172 | + <goals> | ||
173 | + <goal>swagger</goal> | ||
174 | + </goals> | ||
175 | + </execution> | ||
176 | + <execution> | ||
177 | + <id>app</id> | ||
178 | + <phase>package</phase> | ||
179 | + <goals> | ||
180 | + <goal>app</goal> | ||
181 | + </goals> | ||
182 | + </execution> | ||
183 | + </executions> | ||
184 | + </plugin> | ||
185 | + </plugins> | ||
186 | + </build> | ||
187 | + | ||
188 | +</project> |
1 | +/* | ||
2 | + * Copyright 2016-present 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 | + * This class defines the cli command for the PatchPanel class. It creates | ||
19 | + * an instance of the PatchPanelService class to call it's method addPatch(). | ||
20 | + * The command takes 2 parameters, 2 connectPoints. | ||
21 | + */ | ||
22 | +package org.onosproject.patchpanel.cli; | ||
23 | + | ||
24 | +import org.apache.karaf.shell.commands.Argument; | ||
25 | +import org.apache.karaf.shell.commands.Command; | ||
26 | +import org.onosproject.cli.AbstractShellCommand; | ||
27 | +import org.onosproject.net.ConnectPoint; | ||
28 | +import org.onosproject.net.DeviceId; | ||
29 | +import org.onosproject.patchpanel.impl.PatchPanelService; | ||
30 | + | ||
31 | +//name of command and description | ||
32 | +@Command(scope = "onos", name = "patch", | ||
33 | + description = "Gets the 2 ports of one ConnectPoint that will be patched") | ||
34 | + | ||
35 | +public class PatchPanelCommand extends AbstractShellCommand { | ||
36 | + //the 2 arguments, both connect points | ||
37 | + @Argument(index = 0, name = "switch/portNumber", description = "ConnectPoint and first port number", | ||
38 | + required = true, multiValued = false) | ||
39 | + String port1 = null; | ||
40 | + @Argument (index = 1, name = "switch/portNumber2", description = "ConnectPoint and second port number", | ||
41 | + required = true, multiValued = false) | ||
42 | + String port2 = null; | ||
43 | + | ||
44 | + private ConnectPoint cp1, cp2; | ||
45 | + private PatchPanelService patchPanelService; | ||
46 | + private DeviceId deviceId, deviceId2; | ||
47 | + | ||
48 | + /** | ||
49 | + * This method creates an instance of the Service class and then uses the user | ||
50 | + * input to call the addPatch method in PatchPanel. It also | ||
51 | + * @throws IllegalArgumentException if the 2 connectpoints are of different devices | ||
52 | + */ | ||
53 | + @Override | ||
54 | + protected void execute() { | ||
55 | + patchPanelService = get(PatchPanelService.class); | ||
56 | + boolean done = false; | ||
57 | + cp1 = ConnectPoint.deviceConnectPoint(port1); | ||
58 | + cp2 = ConnectPoint.deviceConnectPoint(port2); | ||
59 | + deviceId = cp1.deviceId(); | ||
60 | + deviceId2 = cp2.deviceId(); | ||
61 | + if (!(deviceId.equals(deviceId2))) { | ||
62 | + throw new IllegalArgumentException("ERROR: Two Different Device Id's"); | ||
63 | + } else { | ||
64 | + done = patchPanelService.addPatch(cp1, cp2); | ||
65 | + } | ||
66 | + if (done) { | ||
67 | + log.info("This patch has been created"); | ||
68 | + } else { | ||
69 | + log.info("This patch was NOT created"); | ||
70 | + } | ||
71 | + | ||
72 | + } | ||
73 | + | ||
74 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present 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 | + * patch panel-related CLI commands(in cli folder). | ||
19 | + */ | ||
20 | +package org.onosproject.patchpanel.cli; | ||
21 | + |
1 | +/* | ||
2 | + * Copyright 2016-present 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.patchpanel.impl; | ||
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.onosproject.ui.UiExtension; | ||
25 | +import org.onosproject.ui.UiExtensionService; | ||
26 | +import org.onosproject.ui.UiMessageHandlerFactory; | ||
27 | +import org.onosproject.ui.UiView; | ||
28 | +import org.slf4j.Logger; | ||
29 | +import org.slf4j.LoggerFactory; | ||
30 | + | ||
31 | +import java.util.List; | ||
32 | + | ||
33 | +/** | ||
34 | + * ONOS UI Custom-View application component for the Patch Panel Application. | ||
35 | + */ | ||
36 | +@Component(immediate = true) | ||
37 | +public class AppUiComponent { | ||
38 | + | ||
39 | + private static final String VIEW_ID = "sampleCustom"; | ||
40 | + private static final String VIEW_TEXT = "Patch Panel Application"; | ||
41 | + | ||
42 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
43 | + | ||
44 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
45 | + protected UiExtensionService uiExtensionService; | ||
46 | + | ||
47 | + // List of application views | ||
48 | + private final List<UiView> uiViews = ImmutableList.of( | ||
49 | + new UiView(UiView.Category.OTHER, VIEW_ID, VIEW_TEXT) | ||
50 | + ); | ||
51 | + | ||
52 | + // Factory for UI message handlers | ||
53 | + private final UiMessageHandlerFactory messageHandlerFactory = | ||
54 | + () -> ImmutableList.of(new AppUiMessageHandler()); | ||
55 | + | ||
56 | + // Application UI extension | ||
57 | + protected UiExtension extension = | ||
58 | + new UiExtension.Builder(getClass().getClassLoader(), uiViews) | ||
59 | + .resourcePath(VIEW_ID) | ||
60 | + .messageHandlerFactory(messageHandlerFactory) | ||
61 | + .build(); | ||
62 | + | ||
63 | + @Activate | ||
64 | + protected void activate() { | ||
65 | + uiExtensionService.register(extension); | ||
66 | + log.info("Started"); | ||
67 | + } | ||
68 | + | ||
69 | + @Deactivate | ||
70 | + protected void deactivate() { | ||
71 | + uiExtensionService.unregister(extension); | ||
72 | + log.info("Stopped"); | ||
73 | + } | ||
74 | + | ||
75 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present 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 | +package org.onosproject.patchpanel.impl; | ||
18 | + | ||
19 | + | ||
20 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
21 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
22 | +import com.google.common.collect.ImmutableSet; | ||
23 | +import org.onosproject.net.ConnectPoint; | ||
24 | +import org.onosproject.ui.RequestHandler; | ||
25 | +import org.onosproject.ui.UiMessageHandler; | ||
26 | +import org.slf4j.Logger; | ||
27 | +import org.slf4j.LoggerFactory; | ||
28 | +import org.onosproject.net.Device; | ||
29 | +import org.onosproject.net.Port; | ||
30 | +import org.onosproject.net.device.DeviceService; | ||
31 | + | ||
32 | +import java.util.ArrayList; | ||
33 | +import java.util.Collection; | ||
34 | +import java.util.List; | ||
35 | + | ||
36 | +/** | ||
37 | + * ONOS UI Custom-View message handler. | ||
38 | + * | ||
39 | + * This class contains the request handlers that handle the response | ||
40 | + * to each event. In this particular implementation the second message | ||
41 | + * handler creates the patch and the first message handler loads the data | ||
42 | + */ | ||
43 | +public class AppUiMessageHandler extends UiMessageHandler { | ||
44 | + | ||
45 | + private static final String SAMPLE_CUSTOM_DATA_REQ = "sampleCustomDataRequest"; | ||
46 | + private static final String SAMPLE_CUSTOM_DATA_RESP = "sampleCustomDataResponse"; | ||
47 | + private static final String SAMPLE_CUSTOM_DATA_REQ2 = "sampleCustomDataRequest2"; | ||
48 | + private static final String SAMPLE_CUSTOM_DATA_RESP2 = "sampleCustomDataResponse2"; | ||
49 | + private static final String SAMPLE_CUSTOM_DATA_REQ3 = "sampleCustomDataRequest3"; | ||
50 | + private static final String SAMPLE_CUSTOM_DATA_RESP3 = "sampleCustomDataResponse3"; | ||
51 | + private String message = ""; | ||
52 | + private String cpoints = ""; | ||
53 | + private List<ConnectPoint> previous = new ArrayList<>(); | ||
54 | + private static ConnectPoint cp1; | ||
55 | + private static ConnectPoint cp2; | ||
56 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
57 | + | ||
58 | + @Override | ||
59 | + protected Collection<RequestHandler> createRequestHandlers() { | ||
60 | + return ImmutableSet.of(new DataRequestHandler(), new SecondDataRequestHandler(), new ThirdDataRequestHandler()); | ||
61 | + } | ||
62 | + | ||
63 | + // handler for data requests/events | ||
64 | + private final class DataRequestHandler extends RequestHandler { | ||
65 | + | ||
66 | + private DataRequestHandler() { | ||
67 | + super(SAMPLE_CUSTOM_DATA_REQ); | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public void process(long sid, ObjectNode payload) { | ||
72 | + DeviceService service = get(DeviceService.class); | ||
73 | + ObjectNode result = objectNode(); | ||
74 | + ArrayNode cps = arrayNode(); | ||
75 | + result.set("cps", cps); | ||
76 | + | ||
77 | + for (Device device : service.getDevices()) { | ||
78 | + cps.add(device.id().toString()); | ||
79 | + for (Port port : service.getPorts(device.id())) { | ||
80 | + if (!port.number().isLogical()) { | ||
81 | + cps.add(port.number().toString()); | ||
82 | + log.info(device.id().toString() + "/" + port.number()); | ||
83 | + } | ||
84 | + } | ||
85 | + } | ||
86 | + sendMessage(SAMPLE_CUSTOM_DATA_RESP, 0, result); | ||
87 | + } | ||
88 | + } | ||
89 | + | ||
90 | + private final class SecondDataRequestHandler extends RequestHandler { | ||
91 | + | ||
92 | + private SecondDataRequestHandler() { | ||
93 | + super(SAMPLE_CUSTOM_DATA_REQ2); | ||
94 | + } | ||
95 | + | ||
96 | + @Override | ||
97 | + public void process(long sid, ObjectNode payload) { | ||
98 | + boolean done; | ||
99 | + String deviceId = payload.get("result").get(0).asText(); | ||
100 | + cp1 = ConnectPoint.deviceConnectPoint(deviceId + "/" + payload.get("result").get(1).asText()); | ||
101 | + cp2 = ConnectPoint.deviceConnectPoint(deviceId + "/" + payload.get("result").get(2).asText()); | ||
102 | + PatchPanelService patchPanelService; | ||
103 | + patchPanelService = get(PatchPanelService.class); | ||
104 | + done = patchPanelService.addPatch(cp1, cp2); | ||
105 | + if (done) { | ||
106 | + message = "Patch has been created"; | ||
107 | + previous.add(cp1); | ||
108 | + previous.add(cp2); | ||
109 | + } else { | ||
110 | + message = "One or both of these ports are already in use"; | ||
111 | + if (cp1.port().equals(cp2.port())) { | ||
112 | + message = "Both ports can not be the same"; | ||
113 | + } | ||
114 | + } | ||
115 | + payload.put("message", message); | ||
116 | + sendMessage(SAMPLE_CUSTOM_DATA_RESP2, sid, payload); | ||
117 | + | ||
118 | + } | ||
119 | + } | ||
120 | + private final class ThirdDataRequestHandler extends RequestHandler { | ||
121 | + private ThirdDataRequestHandler() { | ||
122 | + super(SAMPLE_CUSTOM_DATA_REQ3); | ||
123 | + } | ||
124 | + | ||
125 | + @Override | ||
126 | + public void process(long sid, ObjectNode payload) { | ||
127 | + cpoints = ""; | ||
128 | + for (int i = 0; i < previous.size(); i++) { | ||
129 | + if (i % 2 == 1) { | ||
130 | + cpoints += previous.get(i) + "\n"; | ||
131 | + } else { | ||
132 | + cpoints += previous.get(i) + " with "; | ||
133 | + } | ||
134 | + } | ||
135 | + payload.put("cpoints", cpoints); | ||
136 | + sendMessage(SAMPLE_CUSTOM_DATA_RESP3, sid, payload); | ||
137 | + } | ||
138 | + } | ||
139 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2016-present 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 | + * This class acts as a software patch panel application. | ||
19 | + * The user specifies 2 connectpoint on the same device that he/she would like to patch. | ||
20 | + * Using a flow rule, the 2 connectpoints are patched. | ||
21 | + * | ||
22 | + * @author Parvahti Meyyappan | ||
23 | + * @version %I%, %G% | ||
24 | + */ | ||
25 | + | ||
26 | +package org.onosproject.patchpanel.impl; | ||
27 | + | ||
28 | +import org.apache.felix.scr.annotations.Component; | ||
29 | +import org.apache.felix.scr.annotations.Reference; | ||
30 | +import org.apache.felix.scr.annotations.Service; | ||
31 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
32 | +import org.apache.felix.scr.annotations.Activate; | ||
33 | +import org.apache.felix.scr.annotations.Deactivate; | ||
34 | +import org.onosproject.core.ApplicationId; | ||
35 | +import org.onosproject.core.CoreService; | ||
36 | +import org.onosproject.net.PortNumber; | ||
37 | +import org.onosproject.net.flow.DefaultFlowRule; | ||
38 | +import org.onosproject.net.flow.FlowRuleService; | ||
39 | +import org.onosproject.net.flow.FlowRule; | ||
40 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
41 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
42 | +import org.onosproject.net.packet.PacketPriority; | ||
43 | +import org.onosproject.net.ConnectPoint; | ||
44 | +import org.slf4j.Logger; | ||
45 | +import org.slf4j.LoggerFactory; | ||
46 | +import java.util.ArrayList; | ||
47 | +import java.util.List; | ||
48 | + | ||
49 | + | ||
50 | +@Component(immediate = true) | ||
51 | +@Service | ||
52 | +public class PatchPanel implements PatchPanelService { | ||
53 | + | ||
54 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
55 | + protected FlowRuleService flowRuleService; | ||
56 | + | ||
57 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
58 | + protected CoreService coreService; | ||
59 | + | ||
60 | + private List<ConnectPoint> previous = new ArrayList<>(); | ||
61 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
62 | + private ApplicationId appId; | ||
63 | + private ConnectPoint cp1, cp2; | ||
64 | + | ||
65 | + | ||
66 | + @Activate | ||
67 | + protected void activate() throws NullPointerException { | ||
68 | + log.info("Started"); | ||
69 | + try { | ||
70 | + appId = coreService.getAppId("org.onosproject.patchPanel"); | ||
71 | + } catch (NullPointerException e) { | ||
72 | + throw new NullPointerException("ERROR:App Id is null"); | ||
73 | + } | ||
74 | + } | ||
75 | + | ||
76 | + @Deactivate | ||
77 | + protected void deactivate() { | ||
78 | + log.info("Stopped"); | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public boolean addPatch(ConnectPoint num, ConnectPoint num2) { | ||
83 | + cp1 = num; | ||
84 | + cp2 = num2; | ||
85 | + if ((cp1.port().equals(cp2.port())) || (previous.contains(cp1) || previous.contains(cp2))) { | ||
86 | + log.info("One or both of these ports are already in use, NO FLOW"); | ||
87 | + return false; | ||
88 | + } else { | ||
89 | + previous.add(cp1); | ||
90 | + previous.add(cp2); | ||
91 | + setFlowRuleService(); | ||
92 | + return true; | ||
93 | + } | ||
94 | + } | ||
95 | + | ||
96 | + public void setFlowRuleService() { | ||
97 | + PortNumber outPort = cp2.port(); | ||
98 | + PortNumber inPort = cp1.port(); | ||
99 | + FlowRule fr = DefaultFlowRule.builder() | ||
100 | + .forDevice(cp1.deviceId()) | ||
101 | + .withSelector(DefaultTrafficSelector.builder().matchInPort(inPort).build()) | ||
102 | + .withTreatment(DefaultTrafficTreatment.builder().setOutput(outPort).build()) | ||
103 | + .withPriority(PacketPriority.REACTIVE.priorityValue()) | ||
104 | + .makeTemporary(5) | ||
105 | + .fromApp(appId).build(); | ||
106 | + | ||
107 | + flowRuleService.applyFlowRules(fr); | ||
108 | + | ||
109 | + } | ||
110 | + | ||
111 | +} |
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 | +package org.onosproject.patchpanel.impl; | ||
18 | +import org.onosproject.net.ConnectPoint; | ||
19 | + | ||
20 | +/** | ||
21 | + * A service for the patch panel application to | ||
22 | + * export and use with the cli . | ||
23 | + */ | ||
24 | +public interface PatchPanelService { | ||
25 | + | ||
26 | + /** | ||
27 | + * Get the connectPoints that need to be patched. | ||
28 | + * @param cp the first connect point | ||
29 | + * @param cp2 the second connect point | ||
30 | + * @return void | ||
31 | + */ | ||
32 | + public boolean addPatch(ConnectPoint cp, ConnectPoint cp2); | ||
33 | + | ||
34 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | + | ||
2 | +/* | ||
3 | + * Copyright 2016-present 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 | +/** | ||
19 | + * patch panel-related CLI commands(in implementation folder). | ||
20 | + */ | ||
21 | +package org.onosproject.patchpanel.impl; |
1 | +<!-- | ||
2 | + ~ Copyright 2016-present 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.patchpanel.cli.PatchPanelCommand"/> | ||
20 | + <completers> | ||
21 | + <ref component-id="ConnectPointCompleter"/> | ||
22 | + </completers> | ||
23 | + </command> | ||
24 | + </command-bundle> | ||
25 | + <bean id="ConnectPointCompleter" class="org.onosproject.cli.net.ConnectPointCompleter"/> | ||
26 | +</blueprint> |
1 | +/* css for sample app custom view */ | ||
2 | + | ||
3 | +#ov-sample-custom { | ||
4 | + padding: 20px; | ||
5 | +} | ||
6 | +.light #ov-sample-custom { | ||
7 | + color: navy; | ||
8 | +} | ||
9 | +.dark #ov-sample-custom { | ||
10 | + color: #88f; | ||
11 | +} | ||
12 | + | ||
13 | +#ov-sample-custom .button-panel { | ||
14 | + margin: 10px; | ||
15 | + width: 200px; | ||
16 | +} | ||
17 | + | ||
18 | +.light #ov-sample-custom .button-panel { | ||
19 | + background-color: #ccf; | ||
20 | +} | ||
21 | +.dark #ov-sample-custom .button-panel { | ||
22 | + background-color: #444; | ||
23 | +} | ||
24 | + | ||
25 | +#ov-sample-custom .my-button { | ||
26 | + cursor: pointer; | ||
27 | + padding: 4px; | ||
28 | + text-align: center; | ||
29 | +} | ||
30 | + | ||
31 | +.light #ov-sample-custom .my-button { | ||
32 | + color: white; | ||
33 | + background-color: #99d; | ||
34 | +} | ||
35 | +.dark #ov-sample-custom .my-button { | ||
36 | + color: black; | ||
37 | + background-color: #aaa; | ||
38 | +} | ||
39 | + | ||
40 | +#ov-sample-custom .number { | ||
41 | + font-size: 140%; | ||
42 | + text-align: right; | ||
43 | +} | ||
44 | + | ||
45 | +#ov-sample-custom .quote { | ||
46 | + margin: 10px 20px; | ||
47 | + font-style: italic; | ||
48 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +<!-- partial HTML of patch panel app --> | ||
2 | +<div id="ov-sample-custom" ng-controller="OvSampleCustomCtrl"> | ||
3 | + <div class="button-panel"> | ||
4 | + <div class="my-button" ng-click="getData()"> | ||
5 | + Load Devices | ||
6 | + </div> | ||
7 | + | ||
8 | + </div> | ||
9 | + <div class="data-panel"> | ||
10 | + <div> | ||
11 | + <label>Devices: | ||
12 | + <select ng-model="myDev" ng-options="dev.name for dev in devices"></select> | ||
13 | + </label> | ||
14 | + | ||
15 | + </div> | ||
16 | + </div> | ||
17 | + <div class="button-panel"> | ||
18 | + <div class="my-button" ng-click="loadPorts()"> | ||
19 | + Load Ports | ||
20 | + </div> | ||
21 | + </div> | ||
22 | + <div class="data-panel2"> | ||
23 | + <label>First Port: | ||
24 | + <select ng-model="myPort1" ng-options="port.name for port in ports"></select> | ||
25 | + </label> | ||
26 | + <label>Second Port: | ||
27 | + <select ng-model="myPort2" ng-options="port.name for port in ports"></select> | ||
28 | + </label> | ||
29 | + </div> | ||
30 | + <div class="button-panel"> | ||
31 | + <div class="my-button" ng-click="done()"> | ||
32 | + Patch! | ||
33 | + </div> | ||
34 | + </div> | ||
35 | + <div class="data-panel3"> | ||
36 | + <p> | ||
37 | + <span class="quote">{{data.message}} </span> | ||
38 | + </p> | ||
39 | + <pre> | ||
40 | + | ||
41 | + | ||
42 | + </pre> | ||
43 | + </div> | ||
44 | + <div class="button-panel"> | ||
45 | + <div class="my-button" ng-click="used()"> | ||
46 | + ConnectPoints in use | ||
47 | + </div> | ||
48 | + </div> | ||
49 | + <div class="data-panel4"> | ||
50 | + <p> | ||
51 | + <span class="quote">{{data.cpoints}} </span> | ||
52 | + </p> | ||
53 | + </div> | ||
54 | +</div> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +// js for patch panel app custom view | ||
2 | +(function () { | ||
3 | + 'use strict'; | ||
4 | + | ||
5 | + // injected refs | ||
6 | + var $log, $scope, wss, ks; | ||
7 | + | ||
8 | + // constants | ||
9 | + var dataReq = 'sampleCustomDataRequest', | ||
10 | + dataResp = 'sampleCustomDataResponse'; | ||
11 | + var dataReq2 = 'sampleCustomDataRequest2', | ||
12 | + dataResp2 = 'sampleCustomDataResponse2'; | ||
13 | + var dataReq3 = 'sampleCustomDataRequest3', | ||
14 | + dataResp3 = 'sampleCustomDataResponse3'; | ||
15 | + | ||
16 | + | ||
17 | + function addKeyBindings() { | ||
18 | + var map = {space: [getData, 'Fetch data from server'], _helpFormat: [['space']]}; | ||
19 | + ks.keyBindings(map); | ||
20 | + | ||
21 | + } | ||
22 | + | ||
23 | + function getData() { | ||
24 | + wss.sendEvent(dataReq); | ||
25 | + } | ||
26 | + function used() { | ||
27 | + wss.sendEvent(dataReq3); | ||
28 | + } | ||
29 | + function loadPorts(){ | ||
30 | + $scope.ports = []; | ||
31 | + var i; | ||
32 | + var index; | ||
33 | + for(i = 0; i < $scope.cps.length ; i++){ | ||
34 | + if($scope.cps[i] == $scope.myDev){ | ||
35 | + index = i; | ||
36 | + } | ||
37 | + } | ||
38 | + var j = index+1; | ||
39 | + while( $scope.data.cps[j].indexOf("o") != 0){ | ||
40 | + var tempi = {name : $scope.data.cps[j]}; | ||
41 | + $scope.ports.push(tempi); | ||
42 | + j++; | ||
43 | + } | ||
44 | + } | ||
45 | + function done(){ | ||
46 | + var temp = [$scope.myDev.name, $scope.myPort1.name, $scope.myPort2.name]; | ||
47 | + var temp1 = {result : temp}; | ||
48 | + wss.sendEvent(dataReq2, temp1); | ||
49 | + | ||
50 | + } | ||
51 | + function respDataCb(data) { | ||
52 | + $scope.data = data; | ||
53 | + $scope.cps = []; | ||
54 | + $scope.devices = []; | ||
55 | + var i; | ||
56 | + for(i = 0; i < $scope.data.cps.length; i++){ | ||
57 | + $scope.cps.push(temp); | ||
58 | + if($scope.data.cps[i].indexOf("o") == 0){ | ||
59 | + var temp = {name : $scope.data.cps[i]}; | ||
60 | + $scope.devices.push(temp); | ||
61 | + } | ||
62 | + } | ||
63 | + $scope.$apply(); | ||
64 | + } | ||
65 | + function respDataCb2(data) { | ||
66 | + $scope.data = data; | ||
67 | + $scope.$apply(); | ||
68 | + } | ||
69 | + function respDataCb3(data) { | ||
70 | + $scope.data = data; | ||
71 | + $scope.$apply(); | ||
72 | + } | ||
73 | + | ||
74 | + var app = angular.module('ovSampleCustom', []) | ||
75 | + .controller('OvSampleCustomCtrl', | ||
76 | + ['$log', '$scope', 'WebSocketService', 'KeyService', | ||
77 | + | ||
78 | + function (_$log_, _$scope_, _wss_, _ks_) { | ||
79 | + $log = _$log_; | ||
80 | + $scope = _$scope_; | ||
81 | + wss = _wss_; | ||
82 | + ks = _ks_; | ||
83 | + | ||
84 | + $scope.cps = []; | ||
85 | + $scope.devices = []; | ||
86 | + $scope.ports = []; | ||
87 | + $scope.myDev = $scope.devices[0]; | ||
88 | + $scope.myPort1 = $scope.ports[0]; | ||
89 | + $scope.myPort2 = $scope.ports[0]; | ||
90 | + | ||
91 | + | ||
92 | + var handlers = {}; | ||
93 | + $scope.data = {}; | ||
94 | + | ||
95 | + // data response handler | ||
96 | + handlers[dataResp] = respDataCb; | ||
97 | + handlers[dataResp2] = respDataCb2; | ||
98 | + handlers[dataResp3] = respDataCb3; | ||
99 | + wss.bindHandlers(handlers); | ||
100 | + | ||
101 | + addKeyBindings(); | ||
102 | + | ||
103 | + // custom click handler | ||
104 | + $scope.getData = getData; | ||
105 | + $scope.loadPorts = loadPorts; | ||
106 | + $scope.used = used; | ||
107 | + $scope.done = done; | ||
108 | + | ||
109 | + // cleanup | ||
110 | + $scope.$on('$destroy', function () { | ||
111 | + wss.unbindHandlers(handlers); | ||
112 | + ks.unbindKeys(); | ||
113 | + $log.log('OvSampleCustomCtrl has been destroyed'); | ||
114 | + }); | ||
115 | + | ||
116 | + $log.log('OvSampleCustomCtrl has been created'); | ||
117 | + }]); | ||
118 | + | ||
119 | + | ||
120 | + | ||
121 | +}()); | ||
122 | + |
1 | +<link rel="stylesheet" href="app/view/sampleCustom/sampleCustom.css"> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +<script src="app/view/sampleCustom/sampleCustom.js"></script> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -60,6 +60,7 @@ | ... | @@ -60,6 +60,7 @@ |
60 | <module>pim</module> | 60 | <module>pim</module> |
61 | <module>mlb</module> | 61 | <module>mlb</module> |
62 | <module>pathpainter</module> | 62 | <module>pathpainter</module> |
63 | + <module>patchpanel</module> | ||
63 | <module>drivermatrix</module> | 64 | <module>drivermatrix</module> |
64 | <module>cpman</module> | 65 | <module>cpman</module> |
65 | <module>events</module> | 66 | <module>events</module> | ... | ... |
-
Please register or login to post a comment