blob: 7bd79708601977d68749a6e4ff561e8e12858f9c [file] [log] [blame]
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05301/*
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +05302 * Copyright 2016-present Open Networking Laboratory
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05303 *
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 */
16package org.onosproject.pce.cli;
17
18import static org.slf4j.LoggerFactory.getLogger;
19
Priyanka B06420d92016-06-21 08:27:03 +053020import java.util.Collection;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053021import java.util.List;
22import java.util.LinkedList;
23
24import org.apache.karaf.shell.commands.Argument;
25import org.apache.karaf.shell.commands.Command;
26import org.apache.karaf.shell.commands.Option;
27
Mahesh Poojary S33536202016-05-30 07:22:36 +053028import org.onlab.util.DataRateUnit;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053029import org.onosproject.cli.AbstractShellCommand;
Priyanka B06420d92016-06-21 08:27:03 +053030import org.onosproject.incubator.net.tunnel.Tunnel;
31import org.onosproject.incubator.net.tunnel.TunnelService;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053032import org.onosproject.net.DeviceId;
Mahesh Poojary S33536202016-05-30 07:22:36 +053033import org.onosproject.net.intent.constraint.BandwidthConstraint;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053034import org.onosproject.net.intent.Constraint;
Mahesh Poojary S33536202016-05-30 07:22:36 +053035import org.onosproject.pce.pceservice.constraint.CostConstraint;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053036import org.onosproject.pce.pceservice.LspType;
37import org.onosproject.pce.pceservice.api.PceService;
38
39import org.slf4j.Logger;
40
41/**
42 * Supports creating the pce path.
43 */
44@Command(scope = "onos", name = "pce-setup-path", description = "Supports creating pce path.")
45public class PceSetupPathCommand extends AbstractShellCommand {
46 private final Logger log = getLogger(getClass());
47
48 @Argument(index = 0, name = "src", description = "source device.", required = true, multiValued = false)
49 String src = null;
50
51 @Argument(index = 1, name = "dst", description = "destination device.", required = true, multiValued = false)
52 String dst = null;
53
54 @Argument(index = 2, name = "type", description = "LSP type:" + " It includes "
55 + "PCE tunnel with signalling in network (0), "
56 + "PCE tunnel without signalling in network with segment routing (1), "
57 + "PCE tunnel without signalling in network (2).",
58 required = true, multiValued = false)
59 int type = 0;
60
61 @Argument(index = 3, name = "name", description = "symbolic-path-name.", required = true, multiValued = false)
62 String name = null;
63
64 @Option(name = "-c", aliases = "--cost", description = "The cost attribute IGP cost(1) or TE cost(2)",
65 required = false, multiValued = false)
66 int cost = 2;
67
68 @Option(name = "-b", aliases = "--bandwidth", description = "The bandwidth attribute of path. "
69 + "Data rate unit is in BPS.", required = false, multiValued = false)
70 double bandwidth = 0.0;
71
72 @Override
73 protected void execute() {
74 log.info("executing pce-setup-path");
75
76 PceService service = get(PceService.class);
Priyanka B06420d92016-06-21 08:27:03 +053077 TunnelService tunnelService = get(TunnelService.class);
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053078
79 DeviceId srcDevice = DeviceId.deviceId(src);
80 DeviceId dstDevice = DeviceId.deviceId(dst);
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053081 List<Constraint> listConstrnt = new LinkedList<>();
82
Mahesh Poojary S33536202016-05-30 07:22:36 +053083 // LSP type validation
84 if ((type < 0) || (type > 2)) {
85 error("The LSP type value can be PCE tunnel with signalling in network (0), " +
86 "PCE tunnel without signalling in network with segment routing (1), " +
87 "PCE tunnel without signalling in network (2).");
88 return;
89 }
90 LspType lspType = LspType.values()[type];
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053091
Priyanka B06420d92016-06-21 08:27:03 +053092 //Validating tunnel name, duplicated tunnel names not allowed
93 Collection<Tunnel> existingTunnels = tunnelService.queryTunnel(Tunnel.Type.MPLS);
94 for (Tunnel t : existingTunnels) {
95 if (t.tunnelName().toString().equals(name)) {
96 error("Path creation failed, Tunnel name already exists");
97 return;
98 }
99 }
100
Mahesh Poojary S33536202016-05-30 07:22:36 +0530101 // Add bandwidth
Priyanka B4c3cef02016-06-14 20:27:53 +0530102 // bandwidth default data rate unit is in BPS
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530103 if (bandwidth != 0.0) {
Priyanka B4c3cef02016-06-14 20:27:53 +0530104 listConstrnt.add(BandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS")));
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530105 }
106
Mahesh Poojary S33536202016-05-30 07:22:36 +0530107 // Add cost
108 // Cost validation
109 if ((cost < 1) || (cost > 2)) {
110 error("The cost attribute value either IGP cost(1) or TE cost(2).");
111 return;
112 }
113 // Here 'cost - 1' indicates the index of enum
114 CostConstraint.Type costType = CostConstraint.Type.values()[cost - 1];
115 listConstrnt.add(CostConstraint.of(costType));
116
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +0530117 if (!service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) {
118 error("Path creation failed.");
119 }
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530120 }
121}