Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 17 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 22 | import org.apache.karaf.shell.api.action.Option; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.net.ConnectPoint; |
Ray Milkey | a2cf3a1 | 2018-02-15 16:13:56 -0800 | [diff] [blame] | 24 | import org.onosproject.net.FilteredConnectPoint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.flow.TrafficSelector; |
| 26 | import org.onosproject.net.flow.TrafficTreatment; |
| 27 | import org.onosproject.net.intent.Constraint; |
| 28 | import org.onosproject.net.intent.Intent; |
| 29 | import org.onosproject.net.intent.IntentService; |
| 30 | import org.onosproject.net.intent.PointToPointIntent; |
Yuta HIGUCHI | 3e8e035 | 2017-01-09 19:57:57 -0800 | [diff] [blame] | 31 | import org.onosproject.net.intent.constraint.ProtectedConstraint; |
| 32 | |
Yuta HIGUCHI | 23547b3 | 2016-09-01 16:02:40 -0700 | [diff] [blame] | 33 | import static org.onosproject.net.intent.constraint.ProtectionConstraint.protection; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 34 | |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 35 | import java.util.List; |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 36 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Installs point-to-point connectivity intents. |
| 39 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 40 | @Service |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 41 | @Command(scope = "onos", name = "add-point-intent", |
| 42 | description = "Installs point-to-point connectivity intent") |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 43 | public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 44 | |
| 45 | @Argument(index = 0, name = "ingressDevice", |
| 46 | description = "Ingress Device/Port Description", |
| 47 | required = true, multiValued = false) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 48 | @Completion(ConnectPointCompleter.class) |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 49 | String ingressDeviceString = null; |
| 50 | |
| 51 | @Argument(index = 1, name = "egressDevice", |
| 52 | description = "Egress Device/Port Description", |
| 53 | required = true, multiValued = false) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 54 | @Completion(ConnectPointCompleter.class) |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 55 | String egressDeviceString = null; |
| 56 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 57 | private boolean backup = false; |
| 58 | |
Yuta HIGUCHI | 3e8e035 | 2017-01-09 19:57:57 -0800 | [diff] [blame] | 59 | /** |
| 60 | * Option to consume protected path. |
| 61 | */ |
| 62 | @Option(name = "--useProtected", |
| 63 | description = "use protected links only") |
| 64 | private boolean useProtected = false; |
| 65 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 66 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 67 | protected void doExecute() { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 68 | IntentService service = get(IntentService.class); |
| 69 | |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 70 | ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 71 | |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 72 | ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 73 | |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 74 | TrafficSelector selector = buildTrafficSelector(); |
Ray Milkey | ac1441d | 2014-11-13 09:31:47 -0800 | [diff] [blame] | 75 | TrafficTreatment treatment = buildTrafficTreatment(); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 76 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 77 | List<Constraint> constraints = buildConstraints(); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 78 | if (backup) { |
Yuta HIGUCHI | 23547b3 | 2016-09-01 16:02:40 -0700 | [diff] [blame] | 79 | constraints.add(protection()); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 80 | } |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 81 | |
Yuta HIGUCHI | 3e8e035 | 2017-01-09 19:57:57 -0800 | [diff] [blame] | 82 | if (useProtected) { |
| 83 | constraints.add(ProtectedConstraint.useProtectedLink()); |
| 84 | } |
| 85 | |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 86 | Intent intent = PointToPointIntent.builder() |
| 87 | .appId(appId()) |
| 88 | .key(key()) |
| 89 | .selector(selector) |
| 90 | .treatment(treatment) |
Ray Milkey | a2cf3a1 | 2018-02-15 16:13:56 -0800 | [diff] [blame] | 91 | .filteredIngressPoint(new FilteredConnectPoint(ingress)) |
| 92 | .filteredEgressPoint(new FilteredConnectPoint(egress)) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 93 | .constraints(constraints) |
| 94 | .priority(priority()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 95 | .resourceGroup(resourceGroup()) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 96 | .build(); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 97 | service.submit(intent); |
Ray Milkey | cb33a13 | 2015-02-02 10:05:12 -0800 | [diff] [blame] | 98 | print("Point to point intent submitted:\n%s", intent.toString()); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 99 | } |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 100 | } |