Skip to content

Commit 3d935f4

Browse files
committed
Move patchpanel app to onos-app-samples
Change-Id: I5d96655cf0447dcbaf307e6b901d7dea745d476b
1 parent ee664cf commit 3d935f4

File tree

19 files changed

+1107
-0
lines changed

19 files changed

+1107
-0
lines changed

patchpanel/pom.xml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
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+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18+
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+
<parent>
22+
<groupId>org.onosproject</groupId>
23+
<artifactId>onos-dependencies</artifactId>
24+
<version>1.8.2</version>
25+
<relativePath/><!-- parent is remote -->
26+
</parent>
27+
28+
<groupId>org.onosproject</groupId>
29+
<artifactId>onos-app-patchpanel</artifactId>
30+
<version>1.9.0-SNAPSHOT</version>
31+
<packaging>bundle</packaging>
32+
33+
<description>ONOS patch panel application</description>
34+
<url>http://onosproject.org</url>
35+
36+
<properties>
37+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38+
<onos.app.name>org.onosproject.patchpanel</onos.app.name>
39+
<onos.app.title>Patch Panel</onos.app.title>
40+
<onos.app.origin>ON.Lab</onos.app.origin>
41+
<onos.app.category>Traffic Steering</onos.app.category>
42+
<onos.app.url>http://onosproject.org</onos.app.url>
43+
<onos.app.readme>Creates patches between ports on a switch</onos.app.readme>
44+
</properties>
45+
46+
<dependencies>
47+
48+
<dependency>
49+
<groupId>org.onosproject</groupId>
50+
<artifactId>onos-cli</artifactId>
51+
<version>${project.version}</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>org.apache.karaf.shell</groupId>
56+
<artifactId>org.apache.karaf.shell.console</artifactId>
57+
</dependency>
58+
59+
</dependencies>
60+
61+
<build>
62+
<plugins>
63+
<plugin>
64+
<groupId>org.apache.felix</groupId>
65+
<artifactId>maven-bundle-plugin</artifactId>
66+
</plugin>
67+
<plugin>
68+
<groupId>org.apache.felix</groupId>
69+
<artifactId>maven-scr-plugin</artifactId>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.onosproject</groupId>
73+
<artifactId>onos-maven-plugin</artifactId>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
78+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.Command;
25+
import org.onosproject.cli.AbstractShellCommand;
26+
import org.onosproject.patchpanel.impl.Patch;
27+
import org.onosproject.patchpanel.impl.PatchPanelService;
28+
29+
/**
30+
* Lists the patches.
31+
*/
32+
@Command(scope = "onos", name = "patches",
33+
description = "Lists the patches")
34+
public class PatchListCommand extends AbstractShellCommand {
35+
36+
private static final String FORMAT = "%s: %s <-> %s";
37+
38+
@Override
39+
protected void execute() {
40+
PatchPanelService patchPanelService = get(PatchPanelService.class);
41+
42+
patchPanelService.getPatches().forEach(this::print);
43+
}
44+
45+
private void print(Patch patch) {
46+
print(FORMAT, patch.id(), patch.port1(), patch.port2());
47+
}
48+
49+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,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+
/**
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+
/**
32+
* Command for adding a new patch.
33+
*/
34+
@Command(scope = "onos", name = "patch",
35+
description = "Gets the 2 ports of one ConnectPoint that will be patched")
36+
public class PatchPanelCommand extends AbstractShellCommand {
37+
//the 2 arguments, both connect points
38+
@Argument(index = 0, name = "switch/portNumber", description = "ConnectPoint and first port number",
39+
required = true, multiValued = false)
40+
String port1 = null;
41+
@Argument (index = 1, name = "switch/portNumber2", description = "ConnectPoint and second port number",
42+
required = true, multiValued = false)
43+
String port2 = null;
44+
45+
private ConnectPoint cp1, cp2;
46+
private PatchPanelService patchPanelService;
47+
private DeviceId deviceId, deviceId2;
48+
49+
/**
50+
* This method creates an instance of the Service class and then uses the user
51+
* input to call the addPatch method in PatchPanel. It also
52+
* @throws IllegalArgumentException if the 2 connectpoints are of different devices
53+
*/
54+
@Override
55+
protected void execute() {
56+
patchPanelService = get(PatchPanelService.class);
57+
boolean done = false;
58+
cp1 = ConnectPoint.deviceConnectPoint(port1);
59+
cp2 = ConnectPoint.deviceConnectPoint(port2);
60+
deviceId = cp1.deviceId();
61+
deviceId2 = cp2.deviceId();
62+
if (!(deviceId.equals(deviceId2))) {
63+
throw new IllegalArgumentException("ERROR: Two Different Device Id's");
64+
} else {
65+
done = patchPanelService.addPatch(cp1, cp2);
66+
}
67+
if (done) {
68+
log.info("This patch has been created");
69+
} else {
70+
log.info("This patch was NOT created");
71+
}
72+
73+
}
74+
75+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.patchpanel.impl.PatchId;
28+
import org.onosproject.patchpanel.impl.PatchPanelService;
29+
30+
/**
31+
* Removes a patch.
32+
*/
33+
@Command(scope = "onos", name = "patch-remove",
34+
description = "Removes a patch")
35+
public class PatchRemoveCommand extends AbstractShellCommand {
36+
37+
@Argument(index = 0, name = "patchId", description = "ID of patch to remove",
38+
required = true, multiValued = false)
39+
String id = null;
40+
41+
private PatchPanelService patchPanelService;
42+
43+
@Override
44+
protected void execute() {
45+
patchPanelService = get(PatchPanelService.class);
46+
boolean done = false;
47+
48+
PatchId patchId = PatchId.patchId(Integer.parseInt(id));
49+
50+
done = patchPanelService.removePatch(patchId);
51+
52+
if (done) {
53+
log.info("This patch has been removed");
54+
} else {
55+
log.info("This patch was NOT removed");
56+
}
57+
58+
}
59+
60+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,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+
17+
/**
18+
* Patch panel-related CLI commands(in cli folder).
19+
*/
20+
package org.onosproject.patchpanel.cli;
21+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
import org.onosproject.net.ConnectPoint;
20+
21+
/**
22+
* Abstraction of a patch between two ports on a switch.
23+
*/
24+
public class Patch {
25+
26+
private final PatchId patchId;
27+
private final ConnectPoint port1;
28+
private final ConnectPoint port2;
29+
30+
/**
31+
* Creates a new patch.
32+
*
33+
* @param patchId patch ID
34+
* @param port1 first switch port
35+
* @param port2 second switch port
36+
*/
37+
public Patch(PatchId patchId, ConnectPoint port1, ConnectPoint port2) {
38+
this.patchId = patchId;
39+
this.port1 = port1;
40+
this.port2 = port2;
41+
}
42+
43+
/**
44+
* Gets the patch ID.
45+
*
46+
* @return patch ID
47+
*/
48+
public PatchId id() {
49+
return patchId;
50+
}
51+
52+
/**
53+
* Gets the first connect point.
54+
*
55+
* @return connect point
56+
*/
57+
public ConnectPoint port1() {
58+
return port1;
59+
}
60+
61+
/**
62+
* Gets the second connect point.
63+
*
64+
* @return connect point
65+
*/
66+
public ConnectPoint port2() {
67+
return port2;
68+
}
69+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
import org.onlab.util.Identifier;
20+
21+
/**
22+
* Identifier of a patch.
23+
*/
24+
public final class PatchId extends Identifier<Integer> {
25+
26+
private PatchId(int id) {
27+
super(id);
28+
}
29+
30+
/**
31+
* Creates a new patch based of an integer.
32+
*
33+
* @param id backing value
34+
* @return patch ID
35+
*/
36+
public static PatchId patchId(int id) {
37+
return new PatchId(id);
38+
}
39+
}

0 commit comments

Comments
 (0)