Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 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 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 27 | import org.onlab.util.DataRateUnit; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 28 | import org.onosproject.cli.AbstractShellCommand; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 29 | import org.onosproject.incubator.net.tunnel.TunnelId; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 30 | import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 31 | import org.onosproject.net.intent.Constraint; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 32 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 33 | import org.onosproject.pce.pceservice.api.PceService; |
| 34 | |
| 35 | import org.slf4j.Logger; |
| 36 | |
| 37 | /** |
| 38 | * Supports updating the PCE path. |
| 39 | */ |
| 40 | @Command(scope = "onos", name = "pce-update-path", |
| 41 | description = "Supports updating PCE path.") |
| 42 | public class PceUpdatePathCommand extends AbstractShellCommand { |
| 43 | private final Logger log = getLogger(getClass()); |
| 44 | |
| 45 | @Argument(index = 0, name = "id", description = "Path Id.", required = true, multiValued = false) |
| 46 | String id = null; |
| 47 | |
| 48 | @Option(name = "-c", aliases = "--cost", description = "The cost attribute IGP cost (1) or TE cost (2).", |
| 49 | required = false, multiValued = false) |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 50 | Integer cost = null; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 51 | |
| 52 | @Option(name = "-b", aliases = "--bandwidth", description = "The bandwidth attribute of path. " |
| 53 | + "Data rate unit is in Bps.", required = false, multiValued = false) |
Priyanka B | 844ee05 | 2016-08-16 12:12:19 +0530 | [diff] [blame] | 54 | Double bandwidth = null; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 55 | |
| 56 | @Override |
| 57 | protected void execute() { |
| 58 | log.info("executing pce-update-path"); |
| 59 | |
| 60 | PceService service = get(PceService.class); |
| 61 | |
| 62 | List<Constraint> constrntList = new LinkedList<>(); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 63 | // Assign bandwidth. Data rate unit is in Bps. |
Priyanka B | 844ee05 | 2016-08-16 12:12:19 +0530 | [diff] [blame] | 64 | if (bandwidth != null) { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 65 | constrntList.add(PceBandwidthConstraint.of(Double.valueOf(bandwidth), DataRateUnit.valueOf("BPS"))); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 66 | } |
| 67 | |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 68 | // Cost validation |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 69 | if (cost != null) { |
Priyanka B | 9ea8ecb | 2016-07-26 09:53:22 +0530 | [diff] [blame] | 70 | if ((cost < 1) || (cost > 2)) { |
| 71 | error("The cost attribute value is either IGP cost(1) or TE cost(2)."); |
| 72 | return; |
| 73 | } |
| 74 | CostConstraint.Type costType = CostConstraint.Type.values()[cost - 1]; |
| 75 | constrntList.add(CostConstraint.of(costType)); |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | if (!service.updatePath(TunnelId.valueOf(id), constrntList)) { |
| 79 | error("Path updation failed."); |
| 80 | return; |
| 81 | } |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 82 | } |
| 83 | } |