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 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 18 | import static org.onosproject.net.Link.State.ACTIVE; |
| 19 | import static org.onosproject.net.Link.Type.DIRECT; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 20 | import static org.slf4j.LoggerFactory.getLogger; |
| 21 | |
Priyanka B | 06420d9 | 2016-06-21 08:27:03 +0530 | [diff] [blame] | 22 | import java.util.Collection; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 23 | import java.util.List; |
| 24 | import java.util.LinkedList; |
| 25 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 26 | import com.google.common.collect.Lists; |
| 27 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 28 | import org.apache.karaf.shell.api.action.Argument; |
| 29 | import org.apache.karaf.shell.api.action.Command; |
| 30 | import org.apache.karaf.shell.api.action.Option; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 31 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 32 | import org.onlab.util.DataRateUnit; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 33 | import org.onosproject.cli.AbstractShellCommand; |
Priyanka B | 06420d9 | 2016-06-21 08:27:03 +0530 | [diff] [blame] | 34 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 35 | import org.onosproject.incubator.net.tunnel.TunnelService; |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 36 | import org.onosproject.net.ConnectPoint; |
| 37 | import org.onosproject.net.DefaultLink; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 38 | import org.onosproject.net.DeviceId; |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 39 | import org.onosproject.net.NetworkResource; |
| 40 | import org.onosproject.net.PortNumber; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 41 | import org.onosproject.net.intent.Constraint; |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 42 | import org.onosproject.net.provider.ProviderId; |
| 43 | import org.onosproject.pce.pceservice.ExplicitPathInfo; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 44 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 45 | import org.onosproject.pce.pceservice.LspType; |
| 46 | import org.onosproject.pce.pceservice.api.PceService; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 47 | import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 48 | import org.slf4j.Logger; |
| 49 | |
| 50 | /** |
| 51 | * Supports creating the pce path. |
| 52 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 53 | @Service |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 54 | @Command(scope = "onos", name = "pce-setup-path", description = "Supports creating pce path.") |
| 55 | public class PceSetupPathCommand extends AbstractShellCommand { |
| 56 | private final Logger log = getLogger(getClass()); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 57 | public static final byte SUBTYPE_DEVICEID = 0; |
| 58 | public static final byte SUBTYPE_LINK = 1; |
| 59 | public static final byte SUBTYPE_INDEX = 1; |
| 60 | public static final byte TYPE_INDEX = 0; |
| 61 | |
| 62 | public static final byte DEVICEID_INDEX = 2; |
| 63 | public static final byte SOURCE_DEVICEID_INDEX = 2; |
| 64 | public static final byte SOURCE_PORTNO_INDEX = 3; |
| 65 | public static final byte DESTINATION_DEVICEID_INDEX = 4; |
| 66 | public static final byte DESTINATION_PORTNO_INDEX = 5; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 67 | |
| 68 | @Argument(index = 0, name = "src", description = "source device.", required = true, multiValued = false) |
| 69 | String src = null; |
| 70 | |
| 71 | @Argument(index = 1, name = "dst", description = "destination device.", required = true, multiValued = false) |
| 72 | String dst = null; |
| 73 | |
| 74 | @Argument(index = 2, name = "type", description = "LSP type:" + " It includes " |
| 75 | + "PCE tunnel with signalling in network (0), " |
| 76 | + "PCE tunnel without signalling in network with segment routing (1), " |
| 77 | + "PCE tunnel without signalling in network (2).", |
| 78 | required = true, multiValued = false) |
| 79 | int type = 0; |
| 80 | |
| 81 | @Argument(index = 3, name = "name", description = "symbolic-path-name.", required = true, multiValued = false) |
| 82 | String name = null; |
| 83 | |
| 84 | @Option(name = "-c", aliases = "--cost", description = "The cost attribute IGP cost(1) or TE cost(2)", |
| 85 | required = false, multiValued = false) |
| 86 | int cost = 2; |
| 87 | |
| 88 | @Option(name = "-b", aliases = "--bandwidth", description = "The bandwidth attribute of path. " |
| 89 | + "Data rate unit is in BPS.", required = false, multiValued = false) |
| 90 | double bandwidth = 0.0; |
| 91 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 92 | @Option(name = "-e", aliases = "--explicitPathObjects", description = "List of strict and loose hopes" |
| 93 | + " explicitPathInfo format : Type/SubType/Value(DeviceId or Link info)\n" + |
| 94 | " If Value is Device : Type/SubType/deviceId\n" + |
| 95 | " If Value is Link : Type/SubType/SourceDeviceId/SourcePortNo/DestinationDeviceId/DestinationPortNo" + |
| 96 | "Type 0 - strict, 1 - loose \n" + "SubType 0 - deviceId, 1 - link \n", |
| 97 | required = false, multiValued = true) |
| 98 | String[] explicitPathInfoStrings; |
| 99 | |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 100 | @Option(name = "-l", aliases = "--loadBalancing", description = "The load balancing option for user. ", |
| 101 | required = false, multiValued = false) |
| 102 | boolean loadBalancing = false; |
| 103 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 104 | //explicitPathInfo format : Type/SubType/Value(DeviceId or Link info) |
| 105 | //If Value is Device : Type/SubType/deviceId |
| 106 | //If Value is Link : Type/SubType/SourceDeviceId/SourcePortNo/DestinationDeviceId/DestinationPortNo |
| 107 | List<ExplicitPathInfo> explicitPathInfo = Lists.newLinkedList(); |
| 108 | |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 109 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 110 | protected void doExecute() { |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 111 | log.info("executing pce-setup-path"); |
| 112 | |
| 113 | PceService service = get(PceService.class); |
Priyanka B | 06420d9 | 2016-06-21 08:27:03 +0530 | [diff] [blame] | 114 | TunnelService tunnelService = get(TunnelService.class); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 115 | |
| 116 | DeviceId srcDevice = DeviceId.deviceId(src); |
| 117 | DeviceId dstDevice = DeviceId.deviceId(dst); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 118 | List<Constraint> listConstrnt = new LinkedList<>(); |
| 119 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 120 | // LSP type validation |
| 121 | if ((type < 0) || (type > 2)) { |
| 122 | error("The LSP type value can be PCE tunnel with signalling in network (0), " + |
| 123 | "PCE tunnel without signalling in network with segment routing (1), " + |
| 124 | "PCE tunnel without signalling in network (2)."); |
| 125 | return; |
| 126 | } |
| 127 | LspType lspType = LspType.values()[type]; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 128 | |
Priyanka B | 06420d9 | 2016-06-21 08:27:03 +0530 | [diff] [blame] | 129 | //Validating tunnel name, duplicated tunnel names not allowed |
| 130 | Collection<Tunnel> existingTunnels = tunnelService.queryTunnel(Tunnel.Type.MPLS); |
| 131 | for (Tunnel t : existingTunnels) { |
| 132 | if (t.tunnelName().toString().equals(name)) { |
| 133 | error("Path creation failed, Tunnel name already exists"); |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 138 | // Add bandwidth |
Priyanka B | 4c3cef0 | 2016-06-14 20:27:53 +0530 | [diff] [blame] | 139 | // bandwidth default data rate unit is in BPS |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 140 | if (bandwidth != 0.0) { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 141 | listConstrnt.add(PceBandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS"))); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 142 | } |
| 143 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 144 | // Add cost |
| 145 | // Cost validation |
| 146 | if ((cost < 1) || (cost > 2)) { |
| 147 | error("The cost attribute value either IGP cost(1) or TE cost(2)."); |
| 148 | return; |
| 149 | } |
| 150 | // Here 'cost - 1' indicates the index of enum |
| 151 | CostConstraint.Type costType = CostConstraint.Type.values()[cost - 1]; |
| 152 | listConstrnt.add(CostConstraint.of(costType)); |
| 153 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 154 | if (explicitPathInfoStrings != null) { |
| 155 | for (String str : explicitPathInfoStrings) { |
| 156 | String[] splitted = str.split("/"); |
| 157 | DeviceId deviceId; |
| 158 | NetworkResource res = null; |
| 159 | PortNumber portNo; |
| 160 | int explicitPathType = Integer.parseInt(splitted[TYPE_INDEX]); |
| 161 | if ((explicitPathType < 0) || (explicitPathType > 1)) { |
| 162 | error("Explicit path validation failed"); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | //subtype 0 = deviceId, 1 = link |
| 167 | //subtype is required to store either as deviceId or Link |
| 168 | if (splitted[DEVICEID_INDEX] != null && Integer.parseInt(splitted[SUBTYPE_INDEX]) == SUBTYPE_DEVICEID) { |
| 169 | res = DeviceId.deviceId(splitted[DEVICEID_INDEX]); |
| 170 | } else if (Integer.parseInt(splitted[SUBTYPE_INDEX]) == SUBTYPE_LINK |
| 171 | && splitted[SOURCE_DEVICEID_INDEX] != null |
| 172 | && splitted[SOURCE_PORTNO_INDEX] != null |
| 173 | && splitted[DESTINATION_DEVICEID_INDEX] != null |
| 174 | && splitted[DESTINATION_PORTNO_INDEX] != null) { |
| 175 | |
| 176 | deviceId = DeviceId.deviceId(splitted[SOURCE_DEVICEID_INDEX]); |
| 177 | portNo = PortNumber.portNumber(splitted[SOURCE_PORTNO_INDEX]); |
| 178 | ConnectPoint cpSrc = new ConnectPoint(deviceId, portNo); |
| 179 | deviceId = DeviceId.deviceId(splitted[DESTINATION_DEVICEID_INDEX]); |
| 180 | portNo = PortNumber.portNumber(splitted[DESTINATION_PORTNO_INDEX]); |
| 181 | ConnectPoint cpDst = new ConnectPoint(deviceId, portNo); |
| 182 | res = DefaultLink.builder() |
| 183 | .providerId(ProviderId.NONE) |
| 184 | .src(cpSrc) |
| 185 | .dst(cpDst) |
| 186 | .type(DIRECT) |
| 187 | .state(ACTIVE) |
| 188 | .build(); |
| 189 | } else { |
| 190 | error("Explicit path validation failed"); |
| 191 | return; |
| 192 | } |
| 193 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.values()[explicitPathType], res); |
| 194 | explicitPathInfo.add(obj); |
| 195 | } |
| 196 | } |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 197 | |
| 198 | //with load balancing option |
| 199 | if (loadBalancing) { |
| 200 | if (!service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType, loadBalancing)) { |
| 201 | error("Path creation failed."); |
| 202 | } |
| 203 | return; |
| 204 | } |
| 205 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 206 | if (!service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType, explicitPathInfo)) { |
Mahesh Poojary S | 8e1670e | 2016-05-19 22:15:34 +0530 | [diff] [blame] | 207 | error("Path creation failed."); |
| 208 | } |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 209 | } |
| 210 | } |