[ONOS-4160] pce rest and cli
Change-Id: Icc1ec3070fe595bfc1439048234d6a6f23127c13
diff --git a/apps/pce/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java b/apps/pce/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java
new file mode 100644
index 0000000..012fd28
--- /dev/null
+++ b/apps/pce/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.pce.cli;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.pce.pceservice.api.PceService;
+
+import org.slf4j.Logger;
+
+/**
+ * Supports deleting pce path.
+ */
+@Command(scope = "onos", name = "pce-delete-path", description = "Supports deleting pce path.")
+public class PceDeletePathCommand extends AbstractShellCommand {
+ private final Logger log = getLogger(getClass());
+
+ @Argument(index = 0, name = "id", description = "Path Id.", required = true, multiValued = false)
+ String id = null;
+
+ @Override
+ protected void execute() {
+ log.info("executing pce-delete-path");
+
+ PceService service = get(PceService.class);
+
+ //TODO: need to uncomment below lines once releasePath method is added to PceService
+ //if (!service.releasePath(PcePathId.of(id))) {
+ // error("Path deletion failed.");
+ // return;
+ //}
+ }
+}
diff --git a/apps/pce/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java b/apps/pce/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java
new file mode 100644
index 0000000..b7dc3a9
--- /dev/null
+++ b/apps/pce/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.pce.cli;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.pce.pceservice.api.PceService;
+
+import org.slf4j.Logger;
+
+/**
+ * Supports quering PCE path.
+ */
+@Command(scope = "onos", name = "pce-query-path",
+ description = "Supports querying PCE path.")
+public class PceQueryPathCommand extends AbstractShellCommand {
+ private final Logger log = getLogger(getClass());
+
+ @Option(name = "-i", aliases = "--id", description = "path-id", required = false,
+ multiValued = false)
+ String id = null;
+
+ @Override
+ protected void execute() {
+ log.info("executing pce-query-path");
+
+ PceService service = get(PceService.class);
+ if (null == id) {
+ //TODO: need to uncomment below line once queryAllPath method is added to PceService
+ Iterable<Tunnel> tunnels = null; // = service.queryAllPath();
+ if (tunnels != null) {
+ for (final Tunnel tunnel : tunnels) {
+ display(tunnel);
+ }
+ } else {
+ print("No path is found.");
+ return;
+ }
+ } else {
+ //TODO: need to uncomment below line once queryPath method is added to PceService
+ Tunnel tunnel = null; // = service.queryPath(PcePathId.of(id));
+ if (tunnel == null) {
+ print("Path doesnot exists.");
+ return;
+ }
+ display(tunnel);
+ }
+ }
+
+ /**
+ * Display tunnel information on the terminal.
+ *
+ * @param tunnel pce tunnel
+ */
+ void display(Tunnel tunnel) {
+ print("\npath-id : %d \n" +
+ "source : %s \n" +
+ "destination : %s \n" +
+ "path-type : %d \n" +
+ "symbolic-path-name : %s \n" +
+ "constraints: \n" +
+ " cost : %d \n" +
+ " bandwidth : %.2f",
+ tunnel.tunnelId().id(), tunnel.src().toString(), tunnel.dst().toString(),
+ tunnel.type(), tunnel.tunnelName(), tunnel.path().cost(),
+ tunnel.annotations().value(AnnotationKeys.BANDWIDTH));
+ }
+}
diff --git a/apps/pce/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java b/apps/pce/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java
new file mode 100644
index 0000000..5bf13ff
--- /dev/null
+++ b/apps/pce/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.pce.cli;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.List;
+import java.util.LinkedList;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.intent.Constraint;
+import org.onosproject.pce.pceservice.LspType;
+import org.onosproject.pce.pceservice.api.PceService;
+
+import org.slf4j.Logger;
+
+/**
+ * Supports creating the pce path.
+ */
+@Command(scope = "onos", name = "pce-setup-path", description = "Supports creating pce path.")
+public class PceSetupPathCommand extends AbstractShellCommand {
+ private final Logger log = getLogger(getClass());
+
+ @Argument(index = 0, name = "src", description = "source device.", required = true, multiValued = false)
+ String src = null;
+
+ @Argument(index = 1, name = "dst", description = "destination device.", required = true, multiValued = false)
+ String dst = null;
+
+ @Argument(index = 2, name = "type", description = "LSP type:" + " It includes "
+ + "PCE tunnel with signalling in network (0), "
+ + "PCE tunnel without signalling in network with segment routing (1), "
+ + "PCE tunnel without signalling in network (2).",
+ required = true, multiValued = false)
+ int type = 0;
+
+ @Argument(index = 3, name = "name", description = "symbolic-path-name.", required = true, multiValued = false)
+ String name = null;
+
+ @Option(name = "-c", aliases = "--cost", description = "The cost attribute IGP cost(1) or TE cost(2)",
+ required = false, multiValued = false)
+ int cost = 2;
+
+ @Option(name = "-b", aliases = "--bandwidth", description = "The bandwidth attribute of path. "
+ + "Data rate unit is in BPS.", required = false, multiValued = false)
+ double bandwidth = 0.0;
+
+ @Override
+ protected void execute() {
+ log.info("executing pce-setup-path");
+
+ PceService service = get(PceService.class);
+
+ DeviceId srcDevice = DeviceId.deviceId(src);
+ DeviceId dstDevice = DeviceId.deviceId(dst);
+ LspType lspType = LspType.values()[type];
+ List<Constraint> listConstrnt = new LinkedList<>();
+
+ // add cost
+ //TODO: need to uncomment below lines once CostConstraint is ready
+ //CostConstraint.Type costType = CostConstraint.Type.values()[cost];
+ //listConstrnt.add(CostConstraint.of(costType));
+
+ // add bandwidth
+ // bandwidth default data rate unit is in BPS
+ if (bandwidth != 0.0) {
+ //TODO: need to uncomment below line once BandwidthConstraint is ready
+ //listConstrnt.add(LocalBandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS")));
+ }
+
+ //TODO: need to uncomment below lines once setupPath method is modified in PceService
+ //if (null == service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) {
+ // error("Path creation failed.");
+ //}
+ }
+}
diff --git a/apps/pce/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java b/apps/pce/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java
new file mode 100644
index 0000000..e1dcd65
--- /dev/null
+++ b/apps/pce/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.pce.cli;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.List;
+import java.util.LinkedList;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.intent.Constraint;
+import org.onosproject.pce.pceservice.api.PceService;
+
+import org.slf4j.Logger;
+
+/**
+ * Supports updating the PCE path.
+ */
+@Command(scope = "onos", name = "pce-update-path",
+ description = "Supports updating PCE path.")
+public class PceUpdatePathCommand extends AbstractShellCommand {
+ private final Logger log = getLogger(getClass());
+
+ @Argument(index = 0, name = "id", description = "Path Id.", required = true, multiValued = false)
+ String id = null;
+
+ @Option(name = "-c", aliases = "--cost", description = "The cost attribute IGP cost (1) or TE cost (2).",
+ required = false, multiValued = false)
+ int cost = 0;
+
+ @Option(name = "-b", aliases = "--bandwidth", description = "The bandwidth attribute of path. "
+ + "Data rate unit is in Bps.", required = false, multiValued = false)
+ double bandwidth = 0.0;
+
+ @Override
+ protected void execute() {
+ log.info("executing pce-update-path");
+
+ PceService service = get(PceService.class);
+
+ List<Constraint> constrntList = new LinkedList<>();
+ // Assign cost
+ if (cost != 0) {
+ //TODO: need to uncomment below lines once CostConstraint is ready
+ //CostConstraint.Type costType = CostConstraint.Type.values()[Integer.valueOf(cost)];
+ //constrntList.add(CostConstraint.of(costType));
+ }
+
+ // Assign bandwidth. Data rate unit is in Bps.
+ if (bandwidth != 0.0) {
+ //TODO: need to uncomment below line once BandwidthConstraint is ready
+ //constrntList.add(LocalBandwidthConstraint.of(Double.valueOf(bandwidth), DataRateUnit.valueOf("BPS")));
+ }
+
+ //TODO: need to uncomment below lines once updatePath method is added to PceService
+ //if (null == service.updatePath(PcePathId.of(id), constrntList)) {
+ // error("Path updation failed.");
+ // return;
+ //}
+ }
+}
diff --git a/apps/pce/src/main/java/org/onosproject/pce/cli/package-info.java b/apps/pce/src/main/java/org/onosproject/pce/cli/package-info.java
new file mode 100644
index 0000000..d5c85c4
--- /dev/null
+++ b/apps/pce/src/main/java/org/onosproject/pce/cli/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * PCE path console command-line extensions.
+ */
+package org.onosproject.pce.cli;