blob: 96796b5f0974d4bafbdb2ed3b07e3937eb28ef87 [file] [log] [blame]
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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
20import java.util.List;
21import java.util.LinkedList;
22
Ray Milkey86ad7bb2018-09-27 12:32:28 -070023import org.apache.karaf.shell.api.action.Argument;
24import org.apache.karaf.shell.api.action.Command;
25import org.apache.karaf.shell.api.action.Option;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053026
Ray Milkey7a2dee52018-09-28 10:58:28 -070027import org.apache.karaf.shell.api.action.lifecycle.Service;
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;
Mahesh Poojary S33536202016-05-30 07:22:36 +053030import org.onosproject.incubator.net.tunnel.TunnelId;
Satish K2eb5d842017-04-04 16:28:37 +053031import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053032import org.onosproject.net.intent.Constraint;
Mahesh Poojary S33536202016-05-30 07:22:36 +053033import org.onosproject.pce.pceservice.constraint.CostConstraint;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053034import org.onosproject.pce.pceservice.api.PceService;
35
36import org.slf4j.Logger;
37
38/**
39 * Supports updating the PCE path.
40 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070041@Service
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053042@Command(scope = "onos", name = "pce-update-path",
43 description = "Supports updating PCE path.")
44public class PceUpdatePathCommand extends AbstractShellCommand {
45 private final Logger log = getLogger(getClass());
46
47 @Argument(index = 0, name = "id", description = "Path Id.", required = true, multiValued = false)
48 String id = null;
49
50 @Option(name = "-c", aliases = "--cost", description = "The cost attribute IGP cost (1) or TE cost (2).",
51 required = false, multiValued = false)
Priyanka B3fdb9dd2016-08-08 10:47:24 +053052 Integer cost = null;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053053
54 @Option(name = "-b", aliases = "--bandwidth", description = "The bandwidth attribute of path. "
55 + "Data rate unit is in Bps.", required = false, multiValued = false)
Priyanka B844ee052016-08-16 12:12:19 +053056 Double bandwidth = null;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053057
58 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070059 protected void doExecute() {
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053060 log.info("executing pce-update-path");
61
62 PceService service = get(PceService.class);
63
64 List<Constraint> constrntList = new LinkedList<>();
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053065 // Assign bandwidth. Data rate unit is in Bps.
Priyanka B844ee052016-08-16 12:12:19 +053066 if (bandwidth != null) {
Satish K2eb5d842017-04-04 16:28:37 +053067 constrntList.add(PceBandwidthConstraint.of(Double.valueOf(bandwidth), DataRateUnit.valueOf("BPS")));
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053068 }
69
Priyanka B4c3b4512016-07-22 11:41:49 +053070 // Cost validation
Priyanka B3fdb9dd2016-08-08 10:47:24 +053071 if (cost != null) {
Priyanka B9ea8ecb2016-07-26 09:53:22 +053072 if ((cost < 1) || (cost > 2)) {
73 error("The cost attribute value is either IGP cost(1) or TE cost(2).");
74 return;
75 }
76 CostConstraint.Type costType = CostConstraint.Type.values()[cost - 1];
77 constrntList.add(CostConstraint.of(costType));
Mahesh Poojary S33536202016-05-30 07:22:36 +053078 }
79
80 if (!service.updatePath(TunnelId.valueOf(id), constrntList)) {
81 error("Path updation failed.");
82 return;
83 }
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053084 }
85}