Committed by
Gerrit Code Review
[ONOS-4160] pce rest and cli
Change-Id: Icc1ec3070fe595bfc1439048234d6a6f23127c13
Showing
23 changed files
with
1986 additions
and
2 deletions
... | @@ -37,9 +37,90 @@ | ... | @@ -37,9 +37,90 @@ |
37 | </properties> | 37 | </properties> |
38 | <dependencies> | 38 | <dependencies> |
39 | <dependency> | 39 | <dependency> |
40 | + <groupId>org.osgi</groupId> | ||
41 | + <artifactId>org.osgi.compendium</artifactId> | ||
42 | + </dependency> | ||
43 | + | ||
44 | + <dependency> | ||
45 | + <groupId>org.onosproject</groupId> | ||
46 | + <artifactId>onos-cli</artifactId> | ||
47 | + <version>${project.version}</version> | ||
48 | + </dependency> | ||
49 | + | ||
50 | + <dependency> | ||
51 | + <groupId>org.apache.karaf.shell</groupId> | ||
52 | + <artifactId>org.apache.karaf.shell.console</artifactId> | ||
53 | + <scope>compile</scope> | ||
54 | + </dependency> | ||
55 | + | ||
56 | + <dependency> | ||
40 | <groupId>org.onosproject</groupId> | 57 | <groupId>org.onosproject</groupId> |
41 | <artifactId>onlab-junit</artifactId> | 58 | <artifactId>onlab-junit</artifactId> |
42 | <scope>test</scope> | 59 | <scope>test</scope> |
43 | </dependency> | 60 | </dependency> |
44 | - </dependencies> | 61 | + <dependency> |
62 | + <groupId>org.onosproject</groupId> | ||
63 | + <artifactId>onos-core-serializers</artifactId> | ||
64 | + <version>${project.version}</version> | ||
65 | + </dependency> | ||
66 | + <dependency> | ||
67 | + <groupId>com.google.guava</groupId> | ||
68 | + <artifactId>guava-testlib</artifactId> | ||
69 | + <scope>test</scope> | ||
70 | + </dependency> | ||
71 | + <dependency> | ||
72 | + <groupId>org.easymock</groupId> | ||
73 | + <artifactId>easymock</artifactId> | ||
74 | + <scope>test</scope> | ||
75 | + </dependency> | ||
76 | + <dependency> | ||
77 | + <groupId>org.onosproject</groupId> | ||
78 | + <artifactId>onlab-osgi</artifactId> | ||
79 | + <classifier>tests</classifier> | ||
80 | + <scope>test</scope> | ||
81 | + </dependency> | ||
82 | + <dependency> | ||
83 | + <groupId>org.onosproject</groupId> | ||
84 | + <artifactId>onos-api</artifactId> | ||
85 | + <scope>test</scope> | ||
86 | + <classifier>tests</classifier> | ||
87 | + </dependency> | ||
88 | + <dependency> | ||
89 | + <groupId>org.onosproject</groupId> | ||
90 | + <artifactId>onos-rest</artifactId> | ||
91 | + <version>${project.version}</version> | ||
92 | + </dependency> | ||
93 | + <dependency> | ||
94 | + <groupId>org.onosproject</groupId> | ||
95 | + <artifactId>onlab-rest</artifactId> | ||
96 | + <version>${project.version}</version> | ||
97 | + </dependency> | ||
98 | + <dependency> | ||
99 | + <groupId>javax.ws.rs</groupId> | ||
100 | + <artifactId>jsr311-api</artifactId> | ||
101 | + <version>1.1.1</version> | ||
102 | + </dependency> | ||
103 | + <dependency> | ||
104 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
105 | + <artifactId>jackson-databind</artifactId> | ||
106 | + </dependency> | ||
107 | + <dependency> | ||
108 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
109 | + <artifactId>jackson-annotations</artifactId> | ||
110 | + </dependency> | ||
111 | + <dependency> | ||
112 | + <groupId>org.glassfish.jersey.containers</groupId> | ||
113 | + <artifactId>jersey-container-servlet</artifactId> | ||
114 | + </dependency> | ||
115 | + <dependency> | ||
116 | + <groupId>org.glassfish.jersey.test-framework</groupId> | ||
117 | + <artifactId>jersey-test-framework-core</artifactId> | ||
118 | + <scope>test</scope> | ||
119 | + </dependency> | ||
120 | + <dependency> | ||
121 | + <groupId>org.glassfish.jersey.test-framework.providers</groupId> | ||
122 | + <artifactId>jersey-test-framework-provider-grizzly2</artifactId> | ||
123 | + <scope>test</scope> | ||
124 | + </dependency> | ||
125 | + </dependencies> | ||
45 | </project> | 126 | </project> | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.cli; | ||
17 | + | ||
18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
19 | + | ||
20 | +import org.apache.karaf.shell.commands.Argument; | ||
21 | +import org.apache.karaf.shell.commands.Command; | ||
22 | + | ||
23 | +import org.onosproject.cli.AbstractShellCommand; | ||
24 | +import org.onosproject.pce.pceservice.api.PceService; | ||
25 | + | ||
26 | +import org.slf4j.Logger; | ||
27 | + | ||
28 | +/** | ||
29 | + * Supports deleting pce path. | ||
30 | + */ | ||
31 | +@Command(scope = "onos", name = "pce-delete-path", description = "Supports deleting pce path.") | ||
32 | +public class PceDeletePathCommand extends AbstractShellCommand { | ||
33 | + private final Logger log = getLogger(getClass()); | ||
34 | + | ||
35 | + @Argument(index = 0, name = "id", description = "Path Id.", required = true, multiValued = false) | ||
36 | + String id = null; | ||
37 | + | ||
38 | + @Override | ||
39 | + protected void execute() { | ||
40 | + log.info("executing pce-delete-path"); | ||
41 | + | ||
42 | + PceService service = get(PceService.class); | ||
43 | + | ||
44 | + //TODO: need to uncomment below lines once releasePath method is added to PceService | ||
45 | + //if (!service.releasePath(PcePathId.of(id))) { | ||
46 | + // error("Path deletion failed."); | ||
47 | + // return; | ||
48 | + //} | ||
49 | + } | ||
50 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.cli; | ||
17 | + | ||
18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
19 | + | ||
20 | +import org.apache.karaf.shell.commands.Command; | ||
21 | +import org.apache.karaf.shell.commands.Option; | ||
22 | + | ||
23 | +import org.onosproject.cli.AbstractShellCommand; | ||
24 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
25 | +import org.onosproject.net.AnnotationKeys; | ||
26 | +import org.onosproject.pce.pceservice.api.PceService; | ||
27 | + | ||
28 | +import org.slf4j.Logger; | ||
29 | + | ||
30 | +/** | ||
31 | + * Supports quering PCE path. | ||
32 | + */ | ||
33 | +@Command(scope = "onos", name = "pce-query-path", | ||
34 | + description = "Supports querying PCE path.") | ||
35 | +public class PceQueryPathCommand extends AbstractShellCommand { | ||
36 | + private final Logger log = getLogger(getClass()); | ||
37 | + | ||
38 | + @Option(name = "-i", aliases = "--id", description = "path-id", required = false, | ||
39 | + multiValued = false) | ||
40 | + String id = null; | ||
41 | + | ||
42 | + @Override | ||
43 | + protected void execute() { | ||
44 | + log.info("executing pce-query-path"); | ||
45 | + | ||
46 | + PceService service = get(PceService.class); | ||
47 | + if (null == id) { | ||
48 | + //TODO: need to uncomment below line once queryAllPath method is added to PceService | ||
49 | + Iterable<Tunnel> tunnels = null; // = service.queryAllPath(); | ||
50 | + if (tunnels != null) { | ||
51 | + for (final Tunnel tunnel : tunnels) { | ||
52 | + display(tunnel); | ||
53 | + } | ||
54 | + } else { | ||
55 | + print("No path is found."); | ||
56 | + return; | ||
57 | + } | ||
58 | + } else { | ||
59 | + //TODO: need to uncomment below line once queryPath method is added to PceService | ||
60 | + Tunnel tunnel = null; // = service.queryPath(PcePathId.of(id)); | ||
61 | + if (tunnel == null) { | ||
62 | + print("Path doesnot exists."); | ||
63 | + return; | ||
64 | + } | ||
65 | + display(tunnel); | ||
66 | + } | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * Display tunnel information on the terminal. | ||
71 | + * | ||
72 | + * @param tunnel pce tunnel | ||
73 | + */ | ||
74 | + void display(Tunnel tunnel) { | ||
75 | + print("\npath-id : %d \n" + | ||
76 | + "source : %s \n" + | ||
77 | + "destination : %s \n" + | ||
78 | + "path-type : %d \n" + | ||
79 | + "symbolic-path-name : %s \n" + | ||
80 | + "constraints: \n" + | ||
81 | + " cost : %d \n" + | ||
82 | + " bandwidth : %.2f", | ||
83 | + tunnel.tunnelId().id(), tunnel.src().toString(), tunnel.dst().toString(), | ||
84 | + tunnel.type(), tunnel.tunnelName(), tunnel.path().cost(), | ||
85 | + tunnel.annotations().value(AnnotationKeys.BANDWIDTH)); | ||
86 | + } | ||
87 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.cli; | ||
17 | + | ||
18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
19 | + | ||
20 | +import java.util.List; | ||
21 | +import java.util.LinkedList; | ||
22 | + | ||
23 | +import org.apache.karaf.shell.commands.Argument; | ||
24 | +import org.apache.karaf.shell.commands.Command; | ||
25 | +import org.apache.karaf.shell.commands.Option; | ||
26 | + | ||
27 | +import org.onosproject.cli.AbstractShellCommand; | ||
28 | +import org.onosproject.net.DeviceId; | ||
29 | +import org.onosproject.net.intent.Constraint; | ||
30 | +import org.onosproject.pce.pceservice.LspType; | ||
31 | +import org.onosproject.pce.pceservice.api.PceService; | ||
32 | + | ||
33 | +import org.slf4j.Logger; | ||
34 | + | ||
35 | +/** | ||
36 | + * Supports creating the pce path. | ||
37 | + */ | ||
38 | +@Command(scope = "onos", name = "pce-setup-path", description = "Supports creating pce path.") | ||
39 | +public class PceSetupPathCommand extends AbstractShellCommand { | ||
40 | + private final Logger log = getLogger(getClass()); | ||
41 | + | ||
42 | + @Argument(index = 0, name = "src", description = "source device.", required = true, multiValued = false) | ||
43 | + String src = null; | ||
44 | + | ||
45 | + @Argument(index = 1, name = "dst", description = "destination device.", required = true, multiValued = false) | ||
46 | + String dst = null; | ||
47 | + | ||
48 | + @Argument(index = 2, name = "type", description = "LSP type:" + " It includes " | ||
49 | + + "PCE tunnel with signalling in network (0), " | ||
50 | + + "PCE tunnel without signalling in network with segment routing (1), " | ||
51 | + + "PCE tunnel without signalling in network (2).", | ||
52 | + required = true, multiValued = false) | ||
53 | + int type = 0; | ||
54 | + | ||
55 | + @Argument(index = 3, name = "name", description = "symbolic-path-name.", required = true, multiValued = false) | ||
56 | + String name = null; | ||
57 | + | ||
58 | + @Option(name = "-c", aliases = "--cost", description = "The cost attribute IGP cost(1) or TE cost(2)", | ||
59 | + required = false, multiValued = false) | ||
60 | + int cost = 2; | ||
61 | + | ||
62 | + @Option(name = "-b", aliases = "--bandwidth", description = "The bandwidth attribute of path. " | ||
63 | + + "Data rate unit is in BPS.", required = false, multiValued = false) | ||
64 | + double bandwidth = 0.0; | ||
65 | + | ||
66 | + @Override | ||
67 | + protected void execute() { | ||
68 | + log.info("executing pce-setup-path"); | ||
69 | + | ||
70 | + PceService service = get(PceService.class); | ||
71 | + | ||
72 | + DeviceId srcDevice = DeviceId.deviceId(src); | ||
73 | + DeviceId dstDevice = DeviceId.deviceId(dst); | ||
74 | + LspType lspType = LspType.values()[type]; | ||
75 | + List<Constraint> listConstrnt = new LinkedList<>(); | ||
76 | + | ||
77 | + // add cost | ||
78 | + //TODO: need to uncomment below lines once CostConstraint is ready | ||
79 | + //CostConstraint.Type costType = CostConstraint.Type.values()[cost]; | ||
80 | + //listConstrnt.add(CostConstraint.of(costType)); | ||
81 | + | ||
82 | + // add bandwidth | ||
83 | + // bandwidth default data rate unit is in BPS | ||
84 | + if (bandwidth != 0.0) { | ||
85 | + //TODO: need to uncomment below line once BandwidthConstraint is ready | ||
86 | + //listConstrnt.add(LocalBandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS"))); | ||
87 | + } | ||
88 | + | ||
89 | + //TODO: need to uncomment below lines once setupPath method is modified in PceService | ||
90 | + //if (null == service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) { | ||
91 | + // error("Path creation failed."); | ||
92 | + //} | ||
93 | + } | ||
94 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.cli; | ||
17 | + | ||
18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
19 | + | ||
20 | +import java.util.List; | ||
21 | +import java.util.LinkedList; | ||
22 | + | ||
23 | +import org.apache.karaf.shell.commands.Argument; | ||
24 | +import org.apache.karaf.shell.commands.Command; | ||
25 | +import org.apache.karaf.shell.commands.Option; | ||
26 | + | ||
27 | +import org.onosproject.cli.AbstractShellCommand; | ||
28 | +import org.onosproject.net.intent.Constraint; | ||
29 | +import org.onosproject.pce.pceservice.api.PceService; | ||
30 | + | ||
31 | +import org.slf4j.Logger; | ||
32 | + | ||
33 | +/** | ||
34 | + * Supports updating the PCE path. | ||
35 | + */ | ||
36 | +@Command(scope = "onos", name = "pce-update-path", | ||
37 | + description = "Supports updating PCE path.") | ||
38 | +public class PceUpdatePathCommand extends AbstractShellCommand { | ||
39 | + private final Logger log = getLogger(getClass()); | ||
40 | + | ||
41 | + @Argument(index = 0, name = "id", description = "Path Id.", required = true, multiValued = false) | ||
42 | + String id = null; | ||
43 | + | ||
44 | + @Option(name = "-c", aliases = "--cost", description = "The cost attribute IGP cost (1) or TE cost (2).", | ||
45 | + required = false, multiValued = false) | ||
46 | + int cost = 0; | ||
47 | + | ||
48 | + @Option(name = "-b", aliases = "--bandwidth", description = "The bandwidth attribute of path. " | ||
49 | + + "Data rate unit is in Bps.", required = false, multiValued = false) | ||
50 | + double bandwidth = 0.0; | ||
51 | + | ||
52 | + @Override | ||
53 | + protected void execute() { | ||
54 | + log.info("executing pce-update-path"); | ||
55 | + | ||
56 | + PceService service = get(PceService.class); | ||
57 | + | ||
58 | + List<Constraint> constrntList = new LinkedList<>(); | ||
59 | + // Assign cost | ||
60 | + if (cost != 0) { | ||
61 | + //TODO: need to uncomment below lines once CostConstraint is ready | ||
62 | + //CostConstraint.Type costType = CostConstraint.Type.values()[Integer.valueOf(cost)]; | ||
63 | + //constrntList.add(CostConstraint.of(costType)); | ||
64 | + } | ||
65 | + | ||
66 | + // Assign bandwidth. Data rate unit is in Bps. | ||
67 | + if (bandwidth != 0.0) { | ||
68 | + //TODO: need to uncomment below line once BandwidthConstraint is ready | ||
69 | + //constrntList.add(LocalBandwidthConstraint.of(Double.valueOf(bandwidth), DataRateUnit.valueOf("BPS"))); | ||
70 | + } | ||
71 | + | ||
72 | + //TODO: need to uncomment below lines once updatePath method is added to PceService | ||
73 | + //if (null == service.updatePath(PcePathId.of(id), constrntList)) { | ||
74 | + // error("Path updation failed."); | ||
75 | + // return; | ||
76 | + //} | ||
77 | + } | ||
78 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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 | + * PCE path console command-line extensions. | ||
19 | + */ | ||
20 | +package org.onosproject.pce.cli; |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.pceservice; | ||
18 | + | ||
19 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
20 | + | ||
21 | +import java.util.Objects; | ||
22 | + | ||
23 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
24 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
25 | +import org.onosproject.net.intent.Constraint; | ||
26 | + | ||
27 | +/** | ||
28 | + * Implementation of an entity which provides functionalities of pce path. | ||
29 | + */ | ||
30 | +public final class DefaultPcePath implements PcePath { | ||
31 | + | ||
32 | + private TunnelId id; // path id | ||
33 | + private String source; // Ingress | ||
34 | + private String destination; // Egress | ||
35 | + private LspType lspType; // LSP type | ||
36 | + private String name; // symbolic-path-name | ||
37 | + private Constraint costConstraint; // cost constraint | ||
38 | + private Constraint bandwidthConstraint; // bandwidth constraint | ||
39 | + | ||
40 | + /** | ||
41 | + * Initializes PCE path attributes. | ||
42 | + * | ||
43 | + * @param id path id | ||
44 | + * @param src ingress | ||
45 | + * @param dst egress | ||
46 | + * @param lspType lsp type | ||
47 | + * @param name symbolic-path-name | ||
48 | + * @param constrnt pce constraint | ||
49 | + */ | ||
50 | + private DefaultPcePath(TunnelId id, String src, String dst, LspType lspType, | ||
51 | + String name, Constraint costConstrnt, Constraint bandwidthConstrnt) { | ||
52 | + | ||
53 | + this.id = id; | ||
54 | + this.source = src; | ||
55 | + this.destination = dst; | ||
56 | + this.lspType = lspType; | ||
57 | + this.name = name; | ||
58 | + this.costConstraint = costConstrnt; | ||
59 | + this.bandwidthConstraint = bandwidthConstrnt; | ||
60 | + } | ||
61 | + | ||
62 | + @Override | ||
63 | + public TunnelId id() { | ||
64 | + return id; | ||
65 | + } | ||
66 | + | ||
67 | + @Override | ||
68 | + public void id(TunnelId id) { | ||
69 | + this.id = id; | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public String source() { | ||
74 | + return source; | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + public void source(String src) { | ||
79 | + this.source = src; | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public String destination() { | ||
84 | + return destination; | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public void destination(String dst) { | ||
89 | + this.destination = dst; | ||
90 | + } | ||
91 | + | ||
92 | + @Override | ||
93 | + public LspType lspType() { | ||
94 | + return lspType; | ||
95 | + } | ||
96 | + | ||
97 | + @Override | ||
98 | + public String name() { | ||
99 | + return name; | ||
100 | + } | ||
101 | + | ||
102 | + @Override | ||
103 | + public Constraint costConstraint() { | ||
104 | + return costConstraint; | ||
105 | + } | ||
106 | + | ||
107 | + @Override | ||
108 | + public Constraint bandwidthConstraint() { | ||
109 | + return bandwidthConstraint; | ||
110 | + } | ||
111 | + | ||
112 | + @Override | ||
113 | + public PcePath copy(PcePath path) { | ||
114 | + if (null != path.source()) { | ||
115 | + this.source = path.source(); | ||
116 | + } | ||
117 | + if (null != path.destination()) { | ||
118 | + this.destination = path.destination(); | ||
119 | + } | ||
120 | + | ||
121 | + this.lspType = path.lspType(); | ||
122 | + | ||
123 | + if (null != path.name()) { | ||
124 | + this.name = path.name(); | ||
125 | + } | ||
126 | + if (null != path.costConstraint()) { | ||
127 | + this.costConstraint = path.costConstraint(); | ||
128 | + } | ||
129 | + if (null != path.bandwidthConstraint()) { | ||
130 | + this.bandwidthConstraint = path.bandwidthConstraint(); | ||
131 | + } | ||
132 | + return this; | ||
133 | + } | ||
134 | + | ||
135 | + @Override | ||
136 | + public int hashCode() { | ||
137 | + return Objects.hash(id, source, destination, lspType, name, costConstraint, bandwidthConstraint); | ||
138 | + } | ||
139 | + | ||
140 | + @Override | ||
141 | + public boolean equals(Object obj) { | ||
142 | + if (this == obj) { | ||
143 | + return true; | ||
144 | + } | ||
145 | + if (obj instanceof DefaultPcePath) { | ||
146 | + DefaultPcePath that = (DefaultPcePath) obj; | ||
147 | + return Objects.equals(id, that.id) | ||
148 | + && Objects.equals(source, that.source) | ||
149 | + && Objects.equals(destination, that.destination) | ||
150 | + && Objects.equals(lspType, that.lspType) | ||
151 | + && Objects.equals(name, that.name) | ||
152 | + && Objects.equals(costConstraint, that.costConstraint) | ||
153 | + && Objects.equals(bandwidthConstraint, that.bandwidthConstraint); | ||
154 | + } | ||
155 | + return false; | ||
156 | + } | ||
157 | + | ||
158 | + @Override | ||
159 | + public String toString() { | ||
160 | + return toStringHelper(this) | ||
161 | + .add("id", id()) | ||
162 | + .add("source", source) | ||
163 | + .add("destination", destination) | ||
164 | + .add("lsptype", lspType) | ||
165 | + .add("name", name) | ||
166 | + .add("costConstraint", costConstraint.toString()) | ||
167 | + .add("bandwidthConstraint", bandwidthConstraint.toString()) | ||
168 | + .toString(); | ||
169 | + } | ||
170 | + | ||
171 | + /** | ||
172 | + * Creates an instance of the pce path builder. | ||
173 | + * | ||
174 | + * @return instance of builder | ||
175 | + */ | ||
176 | + public static Builder builder() { | ||
177 | + return new Builder(); | ||
178 | + } | ||
179 | + | ||
180 | + /** | ||
181 | + * Builder class for pce path. | ||
182 | + */ | ||
183 | + public static final class Builder implements PcePath.Builder { | ||
184 | + private TunnelId id; | ||
185 | + private String source; | ||
186 | + private String destination; | ||
187 | + private LspType lspType; | ||
188 | + private String name; | ||
189 | + private Constraint costConstraint; | ||
190 | + private Constraint bandwidthConstraint; | ||
191 | + | ||
192 | + @Override | ||
193 | + public Builder id(String id) { | ||
194 | + this.id = TunnelId.valueOf(id); | ||
195 | + return this; | ||
196 | + } | ||
197 | + | ||
198 | + @Override | ||
199 | + public Builder source(String source) { | ||
200 | + this.source = source; | ||
201 | + return this; | ||
202 | + } | ||
203 | + | ||
204 | + @Override | ||
205 | + public Builder destination(String destination) { | ||
206 | + this.destination = destination; | ||
207 | + return this; | ||
208 | + } | ||
209 | + | ||
210 | + @Override | ||
211 | + public Builder lspType(String type) { | ||
212 | + if (null != type) { | ||
213 | + this.lspType = LspType.values()[Integer.valueOf(type) - 1]; | ||
214 | + } | ||
215 | + return this; | ||
216 | + } | ||
217 | + | ||
218 | + @Override | ||
219 | + public Builder name(String name) { | ||
220 | + this.name = name; | ||
221 | + return this; | ||
222 | + } | ||
223 | + | ||
224 | + @Override | ||
225 | + public Builder costConstraint(String cost) { | ||
226 | + this.costConstraint = null; | ||
227 | + //TODO: below lines will be uncommented once CostConstraint class is ready | ||
228 | + // this.costConstraint = CostConstraint.of(cost); | ||
229 | + //} | ||
230 | + return this; | ||
231 | + } | ||
232 | + | ||
233 | + @Override | ||
234 | + public Builder bandwidthConstraint(String bandwidth) { | ||
235 | + this.bandwidthConstraint = null; | ||
236 | + //TODO: below lines will be uncommented once LocalBandwidthConstraint class is ready | ||
237 | + // this.bandwidthConstraint = LocalBandwidthConstraint.of(bandwidth); | ||
238 | + //} | ||
239 | + return this; | ||
240 | + } | ||
241 | + | ||
242 | + @Override | ||
243 | + public Builder of(Tunnel tunnel) { | ||
244 | + this.id = TunnelId.valueOf(tunnel.tunnelId().id()); | ||
245 | + this.source = tunnel.src().toString(); | ||
246 | + this.destination = tunnel.dst().toString(); | ||
247 | + //TODO: need to uncomment below line once LSP_SIG_TYPE is added to AnnotationKeys | ||
248 | + this.lspType = null; // = LspType.valueOf(tunnel.annotations().value(AnnotationKeys.LSP_SIG_TYPE)); | ||
249 | + this.name = tunnel.tunnelName().toString(); | ||
250 | + this.costConstraint = null; //CostConstraint.of(tunnel.path().cost()); | ||
251 | + this.bandwidthConstraint = null; | ||
252 | + //LocalBandwidthConstraint.of(tunnel.annotations().value(AnnotationKeys.BANDWIDTH)); | ||
253 | + return this; | ||
254 | + } | ||
255 | + | ||
256 | + @Override | ||
257 | + public PcePath build() { | ||
258 | + return new DefaultPcePath(id, source, destination, lspType, name, | ||
259 | + costConstraint, bandwidthConstraint); | ||
260 | + } | ||
261 | + } | ||
262 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.pceservice; | ||
18 | + | ||
19 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
20 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
21 | +import org.onosproject.net.intent.Constraint; | ||
22 | +import org.onosproject.pce.pceservice.DefaultPcePath.Builder; | ||
23 | + | ||
24 | +/** | ||
25 | + * Abstraction of an entity which provides functionalities of pce path. | ||
26 | + */ | ||
27 | +public interface PcePath { | ||
28 | + | ||
29 | + /** | ||
30 | + * Returns the attribute path id. | ||
31 | + * | ||
32 | + * @return path id | ||
33 | + */ | ||
34 | + TunnelId id(); | ||
35 | + | ||
36 | + /** | ||
37 | + * Sets the attribute path id. | ||
38 | + * | ||
39 | + * @param id path id | ||
40 | + */ | ||
41 | + void id(TunnelId id); | ||
42 | + | ||
43 | + /** | ||
44 | + * Returns the attribute ingress. | ||
45 | + * | ||
46 | + * @return source | ||
47 | + */ | ||
48 | + String source(); | ||
49 | + | ||
50 | + /** | ||
51 | + * Sets the attribute ingress. | ||
52 | + * | ||
53 | + * @param src pce source | ||
54 | + */ | ||
55 | + void source(String src); | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns the attribute egress. | ||
59 | + * | ||
60 | + * @return destination | ||
61 | + */ | ||
62 | + String destination(); | ||
63 | + | ||
64 | + /** | ||
65 | + * Sets the attribute egress. | ||
66 | + * | ||
67 | + * @param dst pce destination. | ||
68 | + */ | ||
69 | + void destination(String dst); | ||
70 | + | ||
71 | + /** | ||
72 | + * Returns the attribute lspType. | ||
73 | + * | ||
74 | + * @return lspType | ||
75 | + */ | ||
76 | + LspType lspType(); | ||
77 | + | ||
78 | + /** | ||
79 | + * Returns the attribute symbolic-path-name. | ||
80 | + * | ||
81 | + * @return symbolic-path-name | ||
82 | + */ | ||
83 | + String name(); | ||
84 | + | ||
85 | + /** | ||
86 | + * Returns the attribute cost constraint. | ||
87 | + * | ||
88 | + * @return cost constraint | ||
89 | + */ | ||
90 | + Constraint costConstraint(); | ||
91 | + | ||
92 | + /** | ||
93 | + * Returns the attribute bandwidth constraint. | ||
94 | + * | ||
95 | + * @return bandwidth constraint | ||
96 | + */ | ||
97 | + Constraint bandwidthConstraint(); | ||
98 | + | ||
99 | + /** | ||
100 | + * Copies only non-null or non-zero member variables. | ||
101 | + * | ||
102 | + * @param id path-id | ||
103 | + * @return pce-path | ||
104 | + */ | ||
105 | + PcePath copy(PcePath id); | ||
106 | + | ||
107 | + /** | ||
108 | + * Builder for pce path. | ||
109 | + */ | ||
110 | + interface Builder { | ||
111 | + | ||
112 | + /** | ||
113 | + * Returns the builder object of path id. | ||
114 | + * | ||
115 | + * @param id path id | ||
116 | + * @return builder object of path id | ||
117 | + */ | ||
118 | + Builder id(String id); | ||
119 | + | ||
120 | + /** | ||
121 | + * Returns the builder object of ingress. | ||
122 | + * | ||
123 | + * @param source ingress | ||
124 | + * @return builder object of ingress | ||
125 | + */ | ||
126 | + Builder source(String source); | ||
127 | + | ||
128 | + /** | ||
129 | + * Returns the builder object of egress. | ||
130 | + * | ||
131 | + * @param destination egress | ||
132 | + * @return builder object of egress | ||
133 | + */ | ||
134 | + Builder destination(String destination); | ||
135 | + | ||
136 | + /** | ||
137 | + * Returns the builder object of lspType. | ||
138 | + * | ||
139 | + * @param lspType lsp type | ||
140 | + * @return builder object of lsp type | ||
141 | + */ | ||
142 | + Builder lspType(String lspType); | ||
143 | + | ||
144 | + /** | ||
145 | + * Returns the builder object of symbolic-path-name. | ||
146 | + * | ||
147 | + * @param n symbolic-path-name | ||
148 | + * @return builder object of symbolic-path-name | ||
149 | + */ | ||
150 | + Builder name(String n); | ||
151 | + | ||
152 | + /** | ||
153 | + * Returns the builder object of cost constraint. | ||
154 | + * | ||
155 | + * @param cost constraint | ||
156 | + * @return builder object of cost constraint | ||
157 | + */ | ||
158 | + Builder costConstraint(String cost); | ||
159 | + | ||
160 | + /** | ||
161 | + * Returns the builder object of bandwidth constraint. | ||
162 | + * | ||
163 | + * @param bandwidth constraint | ||
164 | + * @return builder object of bandwidth constraint | ||
165 | + */ | ||
166 | + Builder bandwidthConstraint(String bandwidth); | ||
167 | + | ||
168 | + /** | ||
169 | + * Copies tunnel information to local. | ||
170 | + * | ||
171 | + * @param tunnel pcc tunnel | ||
172 | + * @return object of pce-path | ||
173 | + */ | ||
174 | + Builder of(Tunnel tunnel); | ||
175 | + | ||
176 | + /** | ||
177 | + * Builds object of pce path. | ||
178 | + * | ||
179 | + * @return object of pce path. | ||
180 | + */ | ||
181 | + PcePath build(); | ||
182 | + } | ||
183 | +} |
1 | /* | 1 | /* |
2 | - * Copyright 2016-present Open Networking Laboratory | 2 | + * Copyright 2016 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.web; | ||
17 | + | ||
18 | +import org.apache.felix.scr.annotations.Activate; | ||
19 | +import org.apache.felix.scr.annotations.Component; | ||
20 | +import org.apache.felix.scr.annotations.Deactivate; | ||
21 | +import org.apache.felix.scr.annotations.Reference; | ||
22 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
23 | +import org.onosproject.codec.CodecService; | ||
24 | +import org.onosproject.pce.pceservice.PcePath; | ||
25 | +import org.slf4j.Logger; | ||
26 | +import org.slf4j.LoggerFactory; | ||
27 | + | ||
28 | +/** | ||
29 | + * Implementation of the json codec brokering service for pce app. | ||
30 | + */ | ||
31 | +@Component(immediate = true) | ||
32 | +public class PceCodecRegistrator { | ||
33 | + | ||
34 | + private static Logger log = LoggerFactory.getLogger(PceCodecRegistrator.class); | ||
35 | + | ||
36 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
37 | + protected CodecService codecService; | ||
38 | + | ||
39 | + @Activate | ||
40 | + public void activate() { | ||
41 | + codecService.registerCodec(PcePath.class, new PcePathCodec()); | ||
42 | + log.info("Started"); | ||
43 | + } | ||
44 | + | ||
45 | + @Deactivate | ||
46 | + public void deactivate() { | ||
47 | + log.info("Stopped"); | ||
48 | + } | ||
49 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.web; | ||
17 | + | ||
18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | + | ||
20 | +import org.onosproject.codec.CodecContext; | ||
21 | +import org.onosproject.codec.JsonCodec; | ||
22 | +import org.onosproject.pce.pceservice.PcePath; | ||
23 | +import org.onosproject.pce.pceservice.DefaultPcePath; | ||
24 | +import org.slf4j.Logger; | ||
25 | +import org.slf4j.LoggerFactory; | ||
26 | + | ||
27 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
28 | +import com.fasterxml.jackson.databind.JsonNode; | ||
29 | + | ||
30 | +/** | ||
31 | + * PCE path json codec. | ||
32 | + */ | ||
33 | +public final class PcePathCodec extends JsonCodec<PcePath> { | ||
34 | + private final Logger log = LoggerFactory.getLogger(PcePathCodec.class); | ||
35 | + private static final String SOURCE = "source"; | ||
36 | + private static final String DESTINATION = "destination"; | ||
37 | + private static final String LSP_TYPE = "pathType"; | ||
38 | + private static final String SYMBOLIC_PATH_NAME = "name"; | ||
39 | + private static final String CONSTRAINT = "constraint"; | ||
40 | + private static final String COST = "cost"; | ||
41 | + private static final String BANDWIDTH = "bandwidth"; | ||
42 | + private static final String PATH_ID = "pathId"; | ||
43 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in pce-path"; | ||
44 | + | ||
45 | + @Override | ||
46 | + public PcePath decode(ObjectNode json, CodecContext context) { | ||
47 | + if (json == null || !json.isObject()) { | ||
48 | + log.error("Empty json input"); | ||
49 | + return null; | ||
50 | + } | ||
51 | + | ||
52 | + // build pce-path | ||
53 | + PcePath.Builder resultBuilder = new DefaultPcePath.Builder(); | ||
54 | + | ||
55 | + // retrieve source | ||
56 | + JsonNode jNode = json.get(SOURCE); | ||
57 | + if (jNode != null) { | ||
58 | + String src = jNode.asText(); | ||
59 | + resultBuilder.source(src); | ||
60 | + } | ||
61 | + | ||
62 | + // retrieve destination | ||
63 | + jNode = json.get(DESTINATION); | ||
64 | + if (jNode != null) { | ||
65 | + String dst = jNode.asText(); | ||
66 | + resultBuilder.destination(dst); | ||
67 | + } | ||
68 | + | ||
69 | + // retrieve lsp-type | ||
70 | + jNode = json.get(LSP_TYPE); | ||
71 | + if (jNode != null) { | ||
72 | + String lspType = jNode.asText(); | ||
73 | + resultBuilder.lspType(lspType); | ||
74 | + } | ||
75 | + | ||
76 | + // retrieve symbolic-path-name | ||
77 | + jNode = json.get(SYMBOLIC_PATH_NAME); | ||
78 | + if (jNode != null) { | ||
79 | + String name = jNode.asText(); | ||
80 | + resultBuilder.name(name); | ||
81 | + } | ||
82 | + | ||
83 | + // retrieve constraint | ||
84 | + JsonNode constraintJNode = (JsonNode) json.path(CONSTRAINT); | ||
85 | + if ((constraintJNode != null) && (!constraintJNode.isMissingNode())) { | ||
86 | + // retrieve cost | ||
87 | + jNode = constraintJNode.get(COST); | ||
88 | + if (jNode != null) { | ||
89 | + String cost = jNode.asText(); | ||
90 | + resultBuilder.bandwidthConstraint(cost); | ||
91 | + } | ||
92 | + | ||
93 | + // retrieve bandwidth | ||
94 | + jNode = constraintJNode.get(BANDWIDTH); | ||
95 | + if (jNode != null) { | ||
96 | + String bandwidth = jNode.asText(); | ||
97 | + resultBuilder.bandwidthConstraint(bandwidth); | ||
98 | + } | ||
99 | + } | ||
100 | + | ||
101 | + return resultBuilder.build(); | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public ObjectNode encode(PcePath path, CodecContext context) { | ||
106 | + checkNotNull(path, "path output cannot be null"); | ||
107 | + ObjectNode result = context.mapper() | ||
108 | + .createObjectNode() | ||
109 | + .put(PATH_ID, path.id().id()) | ||
110 | + .put(SOURCE, path.source()) | ||
111 | + .put(DESTINATION, path.destination()) | ||
112 | + .put(LSP_TYPE, path.lspType().type()) | ||
113 | + .put(SYMBOLIC_PATH_NAME, path.name()); | ||
114 | + | ||
115 | + ObjectNode constraintNode = context.mapper() | ||
116 | + .createObjectNode() | ||
117 | + .put(COST, path.costConstraint().toString()) | ||
118 | + .put(BANDWIDTH, path.bandwidthConstraint().toString()); | ||
119 | + | ||
120 | + result.set(CONSTRAINT, constraintNode); | ||
121 | + return result; | ||
122 | + } | ||
123 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.web; | ||
17 | + | ||
18 | +import static javax.ws.rs.core.Response.Status.OK; | ||
19 | + | ||
20 | +import java.io.IOException; | ||
21 | +import java.io.InputStream; | ||
22 | +import java.util.List; | ||
23 | +import java.util.LinkedList; | ||
24 | + | ||
25 | +import javax.ws.rs.Consumes; | ||
26 | +import javax.ws.rs.DELETE; | ||
27 | +import javax.ws.rs.GET; | ||
28 | +import javax.ws.rs.POST; | ||
29 | +import javax.ws.rs.PUT; | ||
30 | +import javax.ws.rs.Path; | ||
31 | +import javax.ws.rs.PathParam; | ||
32 | +import javax.ws.rs.Produces; | ||
33 | +import javax.ws.rs.core.MediaType; | ||
34 | +import javax.ws.rs.core.Response; | ||
35 | + | ||
36 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
37 | +import org.onosproject.net.DeviceId; | ||
38 | +import org.onosproject.net.intent.Constraint; | ||
39 | +import org.onosproject.pce.pceservice.PcePath; | ||
40 | +import org.onosproject.pce.pceservice.DefaultPcePath; | ||
41 | +import org.onosproject.pce.pceservice.LspType; | ||
42 | +import org.onosproject.rest.AbstractWebResource; | ||
43 | +import org.slf4j.Logger; | ||
44 | +import org.slf4j.LoggerFactory; | ||
45 | + | ||
46 | +import com.fasterxml.jackson.databind.JsonNode; | ||
47 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
48 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
49 | + | ||
50 | +/** | ||
51 | + * Query and program pce path. | ||
52 | + */ | ||
53 | + | ||
54 | +@Path("path") | ||
55 | +public class PcePathWebResource extends AbstractWebResource { | ||
56 | + | ||
57 | + private final Logger log = LoggerFactory.getLogger(PcePathWebResource.class); | ||
58 | + public static final String PCE_PATH_NOT_FOUND = "Path not found"; | ||
59 | + public static final String PCE_PATH_ID_EXIST = "Path exists"; | ||
60 | + public static final String PCE_PATH_ID_NOT_EXIST = "Path does not exist for the identifier"; | ||
61 | + | ||
62 | + /** | ||
63 | + * Retrieve details of all paths created. | ||
64 | + * | ||
65 | + * @return 200 OK | ||
66 | + */ | ||
67 | + @GET | ||
68 | + @Produces(MediaType.APPLICATION_JSON) | ||
69 | + public Response queryAllPath() { | ||
70 | + log.debug("Query all paths."); | ||
71 | + //TODO: need to uncomment below line once queryAllPath method is added to PceService | ||
72 | + Iterable<Tunnel> tunnels = null; // = get(PceService.class).queryAllPath(); | ||
73 | + ObjectNode result = mapper().createObjectNode(); | ||
74 | + ArrayNode pathEntry = result.putArray("paths"); | ||
75 | + if (tunnels != null) { | ||
76 | + for (final Tunnel tunnel : tunnels) { | ||
77 | + PcePath path = DefaultPcePath.builder().of(tunnel).build(); | ||
78 | + pathEntry.add(codec(PcePath.class).encode(path, this)); | ||
79 | + } | ||
80 | + } | ||
81 | + return ok(result.toString()).build(); | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Retrieve details of a specified path id. | ||
86 | + * | ||
87 | + * @param id path id | ||
88 | + * @return 200 OK, 404 if given identifier does not exist | ||
89 | + */ | ||
90 | + @GET | ||
91 | + @Path("{path_id}") | ||
92 | + @Produces(MediaType.APPLICATION_JSON) | ||
93 | + public Response queryPath(@PathParam("path_id") String id) { | ||
94 | + log.debug("Query path by identifier {}.", id); | ||
95 | + //TODO: need to uncomment below lines once queryPath method is added to PceService | ||
96 | + Tunnel tunnel = null; // = nullIsNotFound(get(PceService.class).queryPath(PcePathId.of(id)), | ||
97 | + //PCE_PATH_NOT_FOUND); | ||
98 | + PcePath path = DefaultPcePath.builder().of(tunnel).build(); | ||
99 | + ObjectNode result = mapper().createObjectNode(); | ||
100 | + result.set("path", codec(PcePath.class).encode(path, this)); | ||
101 | + return ok(result.toString()).build(); | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * Creates a new path. | ||
106 | + * | ||
107 | + * @param stream pce path from json | ||
108 | + * @return status of the request | ||
109 | + */ | ||
110 | + @POST | ||
111 | + @Consumes(MediaType.APPLICATION_JSON) | ||
112 | + @Produces(MediaType.APPLICATION_JSON) | ||
113 | + public Response setupPath(InputStream stream) { | ||
114 | + log.debug("Setup path."); | ||
115 | + try { | ||
116 | + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); | ||
117 | + JsonNode port = jsonTree.get("path"); | ||
118 | + PcePath path = codec(PcePath.class).decode((ObjectNode) port, this); | ||
119 | + | ||
120 | + DeviceId srcDevice = DeviceId.deviceId(path.source()); | ||
121 | + DeviceId dstDevice = DeviceId.deviceId(path.destination()); | ||
122 | + LspType lspType = path.lspType(); | ||
123 | + List<Constraint> listConstrnt = new LinkedList<Constraint>(); | ||
124 | + | ||
125 | + // add cost | ||
126 | + //TODO: need to uncomment below lines once Bandwidth and Cost constraint classes are ready | ||
127 | + //CostConstraint.Type costType = CostConstraint.Type.values()[Integer.valueOf(path.constraint().cost())]; | ||
128 | + //listConstrnt.add(CostConstraint.of(costType)); | ||
129 | + | ||
130 | + // add bandwidth. Data rate unit is in BPS. | ||
131 | + //listConstrnt.add(LocalBandwidthConstraint.of(Double.valueOf(path.constraint().bandwidth()), DataRateUnit | ||
132 | + // .valueOf("BPS"))); | ||
133 | + | ||
134 | + //TODO: need to uncomment below lines once setupPath method is modified in PceService | ||
135 | + Boolean issuccess = true; // = (null != get(PceService.class) | ||
136 | + //.setupPath(srcDevice, dstDevice, path.name(), listConstrnt, lspType)) ? true : false; | ||
137 | + return Response.status(OK).entity(issuccess.toString()).build(); | ||
138 | + } catch (IOException e) { | ||
139 | + log.error("Exception while creating path {}.", e.toString()); | ||
140 | + throw new IllegalArgumentException(e); | ||
141 | + } | ||
142 | + } | ||
143 | + | ||
144 | + /** | ||
145 | + * Update details of a specified path id. | ||
146 | + * | ||
147 | + * @param id path id | ||
148 | + * @param stream pce path from json | ||
149 | + * @return 200 OK, 404 if given identifier does not exist | ||
150 | + */ | ||
151 | + @PUT | ||
152 | + @Path("{path_id}") | ||
153 | + @Produces(MediaType.APPLICATION_JSON) | ||
154 | + @Consumes(MediaType.APPLICATION_JSON) | ||
155 | + public Response updatePath(@PathParam("path_id") String id, | ||
156 | + final InputStream stream) { | ||
157 | + log.debug("Update path by identifier {}.", id); | ||
158 | + try { | ||
159 | + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); | ||
160 | + JsonNode pathNode = jsonTree.get("path"); | ||
161 | + PcePath path = codec(PcePath.class).decode((ObjectNode) pathNode, this); | ||
162 | + // Assign cost | ||
163 | + List<Constraint> constrntList = new LinkedList<Constraint>(); | ||
164 | + //TODO: need to uncomment below lines once CostConstraint class is ready | ||
165 | + if (path.costConstraint() != null) { | ||
166 | + //CostConstraint.Type costType = CostConstraint.Type.values()[path.constraint().cost()]; | ||
167 | + //constrntList.add(CostConstraint.of(costType)); | ||
168 | + } | ||
169 | + | ||
170 | + // Assign bandwidth. Data rate unit is in BPS. | ||
171 | + if (path.bandwidthConstraint() != null) { | ||
172 | + //TODO: need to uncomment below lines once BandwidthConstraint class is ready | ||
173 | + //constrntList.add(LocalBandwidthConstraint | ||
174 | + // .of(path.constraint().bandwidth(), DataRateUnit.valueOf("BPS"))); | ||
175 | + } | ||
176 | + | ||
177 | + //TODO: need to uncomment below line once updatePath is added to PceService | ||
178 | + Boolean result = true; // = (null != (get(PceService.class).updatePath(PcePathId.of(id), constrntList))) | ||
179 | + //? true : false; | ||
180 | + return Response.status(OK).entity(result.toString()).build(); | ||
181 | + } catch (IOException e) { | ||
182 | + log.error("Update path failed because of exception {}.", e.toString()); | ||
183 | + throw new IllegalArgumentException(e); | ||
184 | + } | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * Release a specified path. | ||
189 | + * | ||
190 | + * @param id path id | ||
191 | + * @return 200 OK, 404 if given identifier does not exist | ||
192 | + */ | ||
193 | + @Path("{path_id}") | ||
194 | + @DELETE | ||
195 | + public Response releasePath(@PathParam("path_id") String id) { | ||
196 | + log.debug("Deletes path by identifier {}.", id); | ||
197 | + | ||
198 | + //TODO: need to uncomment below lines once releasePath method is added to PceService | ||
199 | + Boolean isSuccess = true; // = nullIsNotFound(get(PceService.class).releasePath(PcePathId.of(id)), | ||
200 | + //PCE_PATH_NOT_FOUND); | ||
201 | + if (!isSuccess) { | ||
202 | + log.debug("Path identifier {} does not exist", id); | ||
203 | + } | ||
204 | + | ||
205 | + return Response.status(OK).entity(isSuccess.toString()).build(); | ||
206 | + } | ||
207 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.web; | ||
18 | + | ||
19 | +import org.onlab.rest.AbstractWebApplication; | ||
20 | + | ||
21 | +import java.util.Set; | ||
22 | + | ||
23 | +/** | ||
24 | + * PCE rest api web application. | ||
25 | + */ | ||
26 | +public class PceWebApplication extends AbstractWebApplication { | ||
27 | + @Override | ||
28 | + public Set<Class<?>> getClasses() { | ||
29 | + return getClasses(PcePathWebResource.class); | ||
30 | + } | ||
31 | +} | ||
32 | + |
1 | +/* | ||
2 | + * Copyright 2016 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 | + * PCE rest application. | ||
19 | + */ | ||
20 | +package org.onosproject.pce.web; |
1 | +<!-- | ||
2 | + ~ Copyright 2016 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.pce.cli.PceQueryPathCommand"/> | ||
20 | + </command> | ||
21 | + <command> | ||
22 | + <action class="org.onosproject.pce.cli.PceSetupPathCommand"/> | ||
23 | + </command> | ||
24 | + <command> | ||
25 | + <action class="org.onosproject.pce.cli.PceUpdatePathCommand"/> | ||
26 | + </command> | ||
27 | + <command> | ||
28 | + <action class="org.onosproject.pce.cli.PceDeletePathCommand"/> | ||
29 | + </command> | ||
30 | + </command-bundle> | ||
31 | +</blueprint> |
apps/pce/src/main/webapp/WEB-INF/web.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 | +<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>PCE REST 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>javax.ws.rs.Application</param-name> | ||
28 | + <param-value>org.onosproject.pce.web.PceWebApplication</param-value> | ||
29 | + </init-param> | ||
30 | + <load-on-startup>1</load-on-startup> | ||
31 | + </servlet> | ||
32 | + | ||
33 | + <servlet-mapping> | ||
34 | + <servlet-name>JAX-RS Service</servlet-name> | ||
35 | + <url-pattern>/*</url-pattern> | ||
36 | + </servlet-mapping> | ||
37 | +</web-app> |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.pceservice; | ||
18 | + | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
22 | +import static org.hamcrest.Matchers.is; | ||
23 | + | ||
24 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit tests for DefaultPcePath class. | ||
28 | + */ | ||
29 | +public class DefaultPcePathTest { | ||
30 | + /** | ||
31 | + * Checks the operation of equals() methods. | ||
32 | + */ | ||
33 | + @Test | ||
34 | + public void testEquals() { | ||
35 | + // create same two pce-path objects. | ||
36 | + final String cost1 = "1"; | ||
37 | + final String bandwidth1 = "200"; | ||
38 | + final String src1 = "foo"; | ||
39 | + final String dst1 = "bee"; | ||
40 | + final String type1 = "1"; | ||
41 | + final String name1 = "pcc"; | ||
42 | + | ||
43 | + PcePath path1 = DefaultPcePath.builder() | ||
44 | + .source(src1) | ||
45 | + .destination(dst1) | ||
46 | + .lspType(type1) | ||
47 | + .name(name1) | ||
48 | + .costConstraint(cost1) | ||
49 | + .bandwidthConstraint(bandwidth1) | ||
50 | + .build(); | ||
51 | + path1.id(TunnelId.valueOf("1")); | ||
52 | + | ||
53 | + // create same as above object | ||
54 | + PcePath samePath1 = DefaultPcePath.builder() | ||
55 | + .source(src1) | ||
56 | + .destination(dst1) | ||
57 | + .lspType(type1) | ||
58 | + .name(name1) | ||
59 | + .costConstraint(cost1) | ||
60 | + .bandwidthConstraint(bandwidth1) | ||
61 | + .build(); | ||
62 | + samePath1.id(TunnelId.valueOf("1")); | ||
63 | + | ||
64 | + // Create different pce-path object. | ||
65 | + final String cost2 = "1"; | ||
66 | + final String bandwidth2 = "200"; | ||
67 | + final String src2 = "google"; | ||
68 | + final String dst2 = "yahoo"; | ||
69 | + final String type2 = "2"; | ||
70 | + final String name2 = "pcc2"; | ||
71 | + | ||
72 | + PcePath path2 = DefaultPcePath.builder() | ||
73 | + .source(src2) | ||
74 | + .destination(dst2) | ||
75 | + .lspType(type2) | ||
76 | + .name(name2) | ||
77 | + .costConstraint(cost2) | ||
78 | + .bandwidthConstraint(bandwidth2) | ||
79 | + .build(); | ||
80 | + path2.id(TunnelId.valueOf("2")); | ||
81 | + //TODO: will be uncommented below line once CostConstraint and LocalBandwidthConstraint classes are ready | ||
82 | + //new EqualsTester().addEqualityGroup(path1, samePath1).addEqualityGroup(path2).testEquals(); | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * Checks the construction of a DefaultPcePath object. | ||
87 | + */ | ||
88 | + @Test | ||
89 | + public void testConstruction() { | ||
90 | + final String cost = "1"; | ||
91 | + final String bandwidth = "600"; | ||
92 | + final String src = "indiatimes"; | ||
93 | + final String dst = "deccan"; | ||
94 | + final String type = "3"; | ||
95 | + final String name = "pcc4"; | ||
96 | + | ||
97 | + PcePath path = DefaultPcePath.builder() | ||
98 | + .source(src) | ||
99 | + .destination(dst) | ||
100 | + .lspType(type) | ||
101 | + .name(name) | ||
102 | + .costConstraint(cost) | ||
103 | + .bandwidthConstraint(bandwidth) | ||
104 | + .build(); | ||
105 | + | ||
106 | + assertThat(src, is(path.source())); | ||
107 | + assertThat(dst, is(path.destination())); | ||
108 | + assertThat(LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR, is(path.lspType())); | ||
109 | + assertThat(name, is(path.name())); | ||
110 | + //TODO: will be uncommented below lines once CostConstraint and LocalBandwidthConstraint classes are ready | ||
111 | + //assertThat(cost, is(path.costConstraint().toString())); | ||
112 | + //assertThat(bandwidth, is(path.bandwidthConstraint().toString())); | ||
113 | + } | ||
114 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.web; | ||
17 | + | ||
18 | +import org.onosproject.codec.CodecContext; | ||
19 | +import org.onosproject.codec.CodecService; | ||
20 | +import org.onosproject.codec.JsonCodec; | ||
21 | +import org.onosproject.codec.impl.CodecManager; | ||
22 | + | ||
23 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
24 | + | ||
25 | +/** | ||
26 | + * Mock codec context for use in codec unit tests. | ||
27 | + */ | ||
28 | +public class MockPceCodecContext implements CodecContext { | ||
29 | + | ||
30 | + private final ObjectMapper mapper = new ObjectMapper(); | ||
31 | + private final CodecManager codecManager = new CodecManager(); | ||
32 | + private final PceCodecRegistrator manager = new PceCodecRegistrator(); | ||
33 | + | ||
34 | + /** | ||
35 | + * Constructs a new mock codec context. | ||
36 | + */ | ||
37 | + public MockPceCodecContext() { | ||
38 | + codecManager.activate(); | ||
39 | + manager.codecService = codecManager; | ||
40 | + manager.activate(); | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ObjectMapper mapper() { | ||
45 | + return mapper; | ||
46 | + } | ||
47 | + | ||
48 | + @SuppressWarnings("unchecked") | ||
49 | + @Override | ||
50 | + public <T> T getService(Class<T> serviceClass) { | ||
51 | + // TODO | ||
52 | + return null; | ||
53 | + } | ||
54 | + | ||
55 | + @Override | ||
56 | + public <T> JsonCodec<T> codec(Class<T> entityClass) { | ||
57 | + return codecManager.getCodec(entityClass); | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Get the codec manager. | ||
62 | + * | ||
63 | + * @return instance of codec manager | ||
64 | + */ | ||
65 | + public CodecService codecManager() { | ||
66 | + return codecManager; | ||
67 | + } | ||
68 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.web; | ||
17 | + | ||
18 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
19 | +import static org.hamcrest.Matchers.is; | ||
20 | +import static org.hamcrest.Matchers.notNullValue; | ||
21 | + | ||
22 | +import java.io.IOException; | ||
23 | +import java.io.InputStream; | ||
24 | + | ||
25 | +import org.junit.Before; | ||
26 | +import org.junit.Test; | ||
27 | +import org.onosproject.codec.JsonCodec; | ||
28 | +import org.onosproject.pce.pceservice.PcePath; | ||
29 | + | ||
30 | +import com.fasterxml.jackson.databind.JsonNode; | ||
31 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
32 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
33 | + | ||
34 | +/** | ||
35 | + * PCE path codec unit tests. | ||
36 | + */ | ||
37 | +public class PcePathCodecTest { | ||
38 | + | ||
39 | + MockPceCodecContext context; | ||
40 | + JsonCodec<PcePath> pcePathCodec; | ||
41 | + /** | ||
42 | + * Sets up for each test. Creates a context and fetches the PCE path codec. | ||
43 | + */ | ||
44 | + @Before | ||
45 | + public void setUp() { | ||
46 | + context = new MockPceCodecContext(); | ||
47 | + pcePathCodec = context.codec(PcePath.class); | ||
48 | + assertThat(pcePathCodec, notNullValue()); | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * Reads in a pce-path from the given resource and decodes it. | ||
53 | + * | ||
54 | + * @param resourceName resource to use to read the json for the pce-path | ||
55 | + * @return decoded pce-path | ||
56 | + * @throws IOException if processing the resource fails | ||
57 | + */ | ||
58 | + private PcePath getPcePath(String resourceName) throws IOException { | ||
59 | + InputStream jsonStream = PcePathCodecTest.class | ||
60 | + .getResourceAsStream(resourceName); | ||
61 | + ObjectMapper mapper = new ObjectMapper(); | ||
62 | + JsonNode json = mapper.readTree(jsonStream); | ||
63 | + assertThat(json, notNullValue()); | ||
64 | + PcePath pcePath = pcePathCodec.decode((ObjectNode) json, context); | ||
65 | + assertThat(pcePath, notNullValue()); | ||
66 | + return pcePath; | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * Checks that a simple pce-path is decoded properly. | ||
71 | + * | ||
72 | + * @throws IOException if the resource cannot be processed | ||
73 | + */ | ||
74 | + @Test | ||
75 | + public void codecPcePathTest() throws IOException { | ||
76 | + | ||
77 | + PcePath pcePath = getPcePath("pcePath.json"); | ||
78 | + | ||
79 | + assertThat(pcePath, notNullValue()); | ||
80 | + | ||
81 | + assertThat(pcePath.source().toString(), is("11.0.0.1")); | ||
82 | + assertThat(pcePath.destination(), is("11.0.0.2")); | ||
83 | + assertThat(pcePath.lspType().toString(), is("SR_WITHOUT_SIGNALLING")); | ||
84 | + //TODO: uncomment below lines once CostConstraint and LocalBandwidthConstraint are ready | ||
85 | + //assertThat(pcePath.costConstraint().toString(), is(2)); | ||
86 | + //assertThat(pcePath.bandwidthConstraint().toString(), is(200.0)); | ||
87 | + } | ||
88 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.web; | ||
17 | + | ||
18 | +//import static org.easymock.EasyMock.anyObject; | ||
19 | +import static org.easymock.EasyMock.createMock; | ||
20 | +//import static org.easymock.EasyMock.expect; | ||
21 | +//import static org.easymock.EasyMock.replay; | ||
22 | +//import static org.hamcrest.Matchers.containsString; | ||
23 | +//import static org.hamcrest.Matchers.is; | ||
24 | +//import static org.hamcrest.Matchers.notNullValue; | ||
25 | +//import static org.junit.Assert.assertThat; | ||
26 | +//import static org.junit.Assert.fail; | ||
27 | + | ||
28 | +//import javax.ws.rs.NotFoundException; | ||
29 | +//import javax.ws.rs.client.Entity; | ||
30 | +//import javax.ws.rs.client.WebTarget; | ||
31 | +//import javax.ws.rs.core.MediaType; | ||
32 | +//import javax.ws.rs.core.Response; | ||
33 | +//import java.io.InputStream; | ||
34 | +//import java.net.HttpURLConnection; | ||
35 | +//import java.util.HashSet; | ||
36 | +//import java.util.List; | ||
37 | +//import java.util.Objects; | ||
38 | +//import java.util.Optional; | ||
39 | +//import java.util.Set; | ||
40 | + | ||
41 | +//import com.eclipsesource.json.Json; | ||
42 | +//import com.eclipsesource.json.JsonObject; | ||
43 | +//import com.google.common.collect.ImmutableList; | ||
44 | +//import com.google.common.collect.Lists; | ||
45 | + | ||
46 | +import org.junit.After; | ||
47 | +import org.junit.Before; | ||
48 | +import org.junit.Test; | ||
49 | +import org.onlab.osgi.ServiceDirectory; | ||
50 | +import org.onlab.osgi.TestServiceDirectory; | ||
51 | +import org.onlab.rest.BaseResource; | ||
52 | +import org.onosproject.codec.CodecService; | ||
53 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
54 | +import org.onosproject.net.intent.Constraint; | ||
55 | +import org.onosproject.pce.pceservice.PcePath; | ||
56 | +import org.onosproject.pce.pceservice.LspType; | ||
57 | +import org.onosproject.pce.pceservice.api.PceService; | ||
58 | + | ||
59 | +/** | ||
60 | + * Unit tests for pce path REST APIs. | ||
61 | + */ | ||
62 | +public class PcePathResourceTest extends PceResourceTest { | ||
63 | + final PceService pceService = createMock(PceService.class); | ||
64 | + final TunnelId pcePathId1 = TunnelId.valueOf("1"); | ||
65 | + //TODO: will be uncommented below lines once CostConstraint and LocalBandwidthConstraint classes are ready | ||
66 | + final Constraint costConstraint = null; //CostConstraint.of("2"); | ||
67 | + final Constraint bandwidthConstraint = null; //LocalBandwidthConstraint.of("200.0"); | ||
68 | + final LspType lspType = LspType.WITH_SIGNALLING; | ||
69 | + final MockPcePath pcePath1 = new MockPcePath(pcePathId1, "11.0.0.1", "11.0.0.2", lspType, "pcc2", | ||
70 | + costConstraint, bandwidthConstraint); | ||
71 | + | ||
72 | + /** | ||
73 | + * Mock class for a pce path. | ||
74 | + */ | ||
75 | + private static class MockPcePath implements PcePath { | ||
76 | + private TunnelId id; | ||
77 | + private String source; | ||
78 | + private String destination; | ||
79 | + private LspType lspType; | ||
80 | + private String name; | ||
81 | + private Constraint costConstraint; | ||
82 | + private Constraint bandwidthConstraint; | ||
83 | + | ||
84 | + /** | ||
85 | + * Constructor to initialize member variables. | ||
86 | + * | ||
87 | + * @param id pce path id | ||
88 | + * @param src source device | ||
89 | + * @param dst destination device | ||
90 | + * @param type lsp type | ||
91 | + * @param name symbolic path name | ||
92 | + * @param constrnt pce constraint | ||
93 | + */ | ||
94 | + public MockPcePath(TunnelId id, String src, String dst, LspType type, String name, | ||
95 | + Constraint costConstrnt, Constraint bandwidthConstrnt) { | ||
96 | + this.id = id; | ||
97 | + this.source = src; | ||
98 | + this.destination = dst; | ||
99 | + this.name = name; | ||
100 | + this.lspType = type; | ||
101 | + this.costConstraint = costConstrnt; | ||
102 | + this.bandwidthConstraint = bandwidthConstrnt; | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public TunnelId id() { | ||
107 | + return id; | ||
108 | + } | ||
109 | + | ||
110 | + @Override | ||
111 | + public void id(TunnelId id) { | ||
112 | + this.id = id; | ||
113 | + } | ||
114 | + | ||
115 | + @Override | ||
116 | + public String source() { | ||
117 | + return source; | ||
118 | + } | ||
119 | + | ||
120 | + @Override | ||
121 | + public void source(String src) { | ||
122 | + this.source = src; | ||
123 | + } | ||
124 | + | ||
125 | + @Override | ||
126 | + public String destination() { | ||
127 | + return destination; | ||
128 | + } | ||
129 | + | ||
130 | + @Override | ||
131 | + public void destination(String dst) { | ||
132 | + this.destination = dst; | ||
133 | + } | ||
134 | + | ||
135 | + @Override | ||
136 | + public LspType lspType() { | ||
137 | + return lspType; | ||
138 | + } | ||
139 | + | ||
140 | + @Override | ||
141 | + public String name() { | ||
142 | + return name; | ||
143 | + } | ||
144 | + | ||
145 | + @Override | ||
146 | + public Constraint costConstraint() { | ||
147 | + return costConstraint; | ||
148 | + } | ||
149 | + | ||
150 | + @Override | ||
151 | + public Constraint bandwidthConstraint() { | ||
152 | + return bandwidthConstraint; | ||
153 | + } | ||
154 | + | ||
155 | + @Override | ||
156 | + public PcePath copy(PcePath path) { | ||
157 | + if (null != path.source()) { | ||
158 | + this.source = path.source(); | ||
159 | + } | ||
160 | + if (null != path.destination()) { | ||
161 | + this.destination = path.destination(); | ||
162 | + } | ||
163 | + if (this.lspType != path.lspType()) { | ||
164 | + this.lspType = path.lspType(); | ||
165 | + } | ||
166 | + if (null != path.name()) { | ||
167 | + this.name = path.name(); | ||
168 | + } | ||
169 | + if (null != path.costConstraint()) { | ||
170 | + this.costConstraint = path.costConstraint(); | ||
171 | + } | ||
172 | + if (null != path.bandwidthConstraint()) { | ||
173 | + this.bandwidthConstraint = path.bandwidthConstraint(); | ||
174 | + } | ||
175 | + return this; | ||
176 | + } | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * Sets up the global values for all the tests. | ||
181 | + */ | ||
182 | + @Before | ||
183 | + public void setUpTest() { | ||
184 | + MockPceCodecContext context = new MockPceCodecContext(); | ||
185 | + ServiceDirectory testDirectory = new TestServiceDirectory().add(PceService.class, pceService) | ||
186 | + .add(CodecService.class, context.codecManager()); | ||
187 | + BaseResource.setServiceDirectory(testDirectory); | ||
188 | + } | ||
189 | + | ||
190 | + /** | ||
191 | + * Cleans up. | ||
192 | + */ | ||
193 | + @After | ||
194 | + public void tearDownTest() { | ||
195 | + } | ||
196 | + | ||
197 | + /** | ||
198 | + * Tests the result of the rest api GET when there are no pce paths. | ||
199 | + */ | ||
200 | + @Test | ||
201 | + public void testPcePathsEmpty() { | ||
202 | + //TODO: will be uncommented below code once PceService is ready | ||
203 | + //expect(pceService.queryAllPath()).andReturn(null).anyTimes(); | ||
204 | + //replay(pceService); | ||
205 | + //final WebTarget wt = target(); | ||
206 | + //final String response = wt.path("path").request().get(String.class); | ||
207 | + //assertThat(response, is("{\"paths\":[]}")); | ||
208 | + } | ||
209 | + | ||
210 | + /** | ||
211 | + * Tests the result of a rest api GET for pce path id. | ||
212 | + */ | ||
213 | + @Test | ||
214 | + public void testGetTunnelId() { | ||
215 | + //TODO: will be uncommented below code once PceService is ready | ||
216 | + //final Set<PcePath> pcePaths = new HashSet<>(); | ||
217 | + //pcePaths.add(pcePath1); | ||
218 | + | ||
219 | + //expect(pceService.queryPath(anyObject())).andReturn(pcePath1).anyTimes(); | ||
220 | + //replay(pceService); | ||
221 | + | ||
222 | + //final WebTarget wt = target(); | ||
223 | + //final String response = wt.path("path/1").request().get(String.class); | ||
224 | + //final JsonObject result = Json.parse(response).asObject(); | ||
225 | + //assertThat(result, notNullValue()); | ||
226 | + } | ||
227 | + | ||
228 | + /** | ||
229 | + * Tests that a fetch of a non-existent pce path object throws an exception. | ||
230 | + */ | ||
231 | + @Test | ||
232 | + public void testBadGet() { | ||
233 | + //TODO: will be uncommented below code once PceService is ready | ||
234 | + //expect(pceService.queryPath(anyObject())) | ||
235 | + // .andReturn(null).anyTimes(); | ||
236 | + //replay(pceService); | ||
237 | + | ||
238 | + //WebTarget wt = target(); | ||
239 | + //try { | ||
240 | + // wt.path("path/1").request().get(String.class); | ||
241 | + // fail("Fetch of non-existent pce path did not throw an exception"); | ||
242 | + //} catch (NotFoundException ex) { | ||
243 | + // assertThat(ex.getMessage(), | ||
244 | + // containsString("HTTP 404 Not Found")); | ||
245 | + //} | ||
246 | + } | ||
247 | + | ||
248 | + /** | ||
249 | + * Tests creating a pce path with POST. | ||
250 | + */ | ||
251 | + @Test | ||
252 | + public void testPost() { | ||
253 | + //TODO: will be uncommented below code once PceService is ready | ||
254 | + //expect(pceService.setupPath(anyObject())) | ||
255 | + // .andReturn(true).anyTimes(); | ||
256 | + //replay(pceService); | ||
257 | + | ||
258 | + //WebTarget wt = target(); | ||
259 | + //InputStream jsonStream = PcePathResourceTest.class.getResourceAsStream("post-PcePath.json"); | ||
260 | + | ||
261 | + //Response response = wt.path("path") | ||
262 | + // .request(MediaType.APPLICATION_JSON_TYPE) | ||
263 | + // .post(Entity.json(jsonStream)); | ||
264 | + //assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); | ||
265 | + } | ||
266 | + | ||
267 | + /** | ||
268 | + * Tests creating a pce path with PUT. | ||
269 | + */ | ||
270 | + @Test | ||
271 | + public void testPut() { | ||
272 | + //TODO: will be uncommented below code once PceService is ready | ||
273 | + //expect(pceService.updatePath(anyObject())) | ||
274 | + // .andReturn(true).anyTimes(); | ||
275 | + //replay(pceService); | ||
276 | + | ||
277 | + //WebTarget wt = target(); | ||
278 | + //InputStream jsonStream = PcePathResourceTest.class.getResourceAsStream("post-PcePath.json"); | ||
279 | + | ||
280 | + //Response response = wt.path("path/1") | ||
281 | + // .request(MediaType.APPLICATION_JSON_TYPE) | ||
282 | + // .put(Entity.json(jsonStream)); | ||
283 | + //assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); | ||
284 | + } | ||
285 | + | ||
286 | + /** | ||
287 | + * Tests deleting a pce path. | ||
288 | + */ | ||
289 | + @Test | ||
290 | + public void testDelete() { | ||
291 | + //TODO: will be uncommented below code once PceService is ready | ||
292 | + //expect(pceService.releasePath(anyObject())) | ||
293 | + // .andReturn(true).anyTimes(); | ||
294 | + //replay(pceService); | ||
295 | + | ||
296 | + //WebTarget wt = target(); | ||
297 | + | ||
298 | + //String location = "path/1"; | ||
299 | + | ||
300 | + //Response deleteResponse = wt.path(location) | ||
301 | + // .request(MediaType.APPLICATION_JSON_TYPE) | ||
302 | + // .delete(); | ||
303 | + //assertThat(deleteResponse.getStatus(), | ||
304 | + // is(HttpURLConnection.HTTP_OK)); | ||
305 | + } | ||
306 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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.pce.web; | ||
17 | + | ||
18 | +import org.glassfish.jersey.server.ResourceConfig; | ||
19 | +import org.glassfish.jersey.test.JerseyTest; | ||
20 | + | ||
21 | +/** | ||
22 | + * Base class for pce rest api tests. Performs common configuration operations. | ||
23 | + */ | ||
24 | +public class PceResourceTest extends JerseyTest { | ||
25 | + | ||
26 | + /** | ||
27 | + * Creates a new web-resource test. | ||
28 | + */ | ||
29 | + public PceResourceTest() { | ||
30 | + super(ResourceConfig.forApplicationClass(PceWebApplication.class)); | ||
31 | + } | ||
32 | +} |
-
Please register or login to post a comment