Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 1 | /* |
Mahesh Poojary S | 8e1670e | 2016-05-19 22:15:34 +0530 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
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; |
| 29 | import org.onosproject.net.DeviceId; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 30 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
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.LspType; |
| 34 | import org.onosproject.pce.pceservice.api.PceService; |
| 35 | |
| 36 | import org.slf4j.Logger; |
| 37 | |
| 38 | /** |
| 39 | * Supports creating the pce path. |
| 40 | */ |
| 41 | @Command(scope = "onos", name = "pce-setup-path", description = "Supports creating pce path.") |
| 42 | public class PceSetupPathCommand extends AbstractShellCommand { |
| 43 | private final Logger log = getLogger(getClass()); |
| 44 | |
| 45 | @Argument(index = 0, name = "src", description = "source device.", required = true, multiValued = false) |
| 46 | String src = null; |
| 47 | |
| 48 | @Argument(index = 1, name = "dst", description = "destination device.", required = true, multiValued = false) |
| 49 | String dst = null; |
| 50 | |
| 51 | @Argument(index = 2, name = "type", description = "LSP type:" + " It includes " |
| 52 | + "PCE tunnel with signalling in network (0), " |
| 53 | + "PCE tunnel without signalling in network with segment routing (1), " |
| 54 | + "PCE tunnel without signalling in network (2).", |
| 55 | required = true, multiValued = false) |
| 56 | int type = 0; |
| 57 | |
| 58 | @Argument(index = 3, name = "name", description = "symbolic-path-name.", required = true, multiValued = false) |
| 59 | String name = null; |
| 60 | |
| 61 | @Option(name = "-c", aliases = "--cost", description = "The cost attribute IGP cost(1) or TE cost(2)", |
| 62 | required = false, multiValued = false) |
| 63 | int cost = 2; |
| 64 | |
| 65 | @Option(name = "-b", aliases = "--bandwidth", description = "The bandwidth attribute of path. " |
| 66 | + "Data rate unit is in BPS.", required = false, multiValued = false) |
| 67 | double bandwidth = 0.0; |
| 68 | |
| 69 | @Override |
| 70 | protected void execute() { |
| 71 | log.info("executing pce-setup-path"); |
| 72 | |
| 73 | PceService service = get(PceService.class); |
| 74 | |
| 75 | DeviceId srcDevice = DeviceId.deviceId(src); |
| 76 | DeviceId dstDevice = DeviceId.deviceId(dst); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 77 | List<Constraint> listConstrnt = new LinkedList<>(); |
| 78 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 79 | // LSP type validation |
| 80 | if ((type < 0) || (type > 2)) { |
| 81 | error("The LSP type value can be PCE tunnel with signalling in network (0), " + |
| 82 | "PCE tunnel without signalling in network with segment routing (1), " + |
| 83 | "PCE tunnel without signalling in network (2)."); |
| 84 | return; |
| 85 | } |
| 86 | LspType lspType = LspType.values()[type]; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 87 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 88 | // Add bandwidth |
Priyanka B | 4c3cef0 | 2016-06-14 20:27:53 +0530 | [diff] [blame^] | 89 | // bandwidth default data rate unit is in BPS |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 90 | if (bandwidth != 0.0) { |
Priyanka B | 4c3cef0 | 2016-06-14 20:27:53 +0530 | [diff] [blame^] | 91 | listConstrnt.add(BandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS"))); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 92 | } |
| 93 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 94 | // Add cost |
| 95 | // Cost validation |
| 96 | if ((cost < 1) || (cost > 2)) { |
| 97 | error("The cost attribute value either IGP cost(1) or TE cost(2)."); |
| 98 | return; |
| 99 | } |
| 100 | // Here 'cost - 1' indicates the index of enum |
| 101 | CostConstraint.Type costType = CostConstraint.Type.values()[cost - 1]; |
| 102 | listConstrnt.add(CostConstraint.of(costType)); |
| 103 | |
Mahesh Poojary S | 8e1670e | 2016-05-19 22:15:34 +0530 | [diff] [blame] | 104 | if (!service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) { |
| 105 | error("Path creation failed."); |
| 106 | } |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 107 | } |
| 108 | } |