blob: b14d956aa4847b643abf89e57cb87c8694c6455f [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska7d693f52014-10-21 19:17:57 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli.net;
Ray Milkeya058c732014-10-08 13:52:34 -070017
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
helenyrwu2a674902016-07-20 09:48:04 -070020import org.apache.karaf.shell.commands.Option;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.ConnectPoint;
Ray Milkeya2cf3a12018-02-15 16:13:56 -080022import org.onosproject.net.FilteredConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
25import org.onosproject.net.intent.Constraint;
26import org.onosproject.net.intent.Intent;
27import org.onosproject.net.intent.IntentService;
28import org.onosproject.net.intent.PointToPointIntent;
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080029import org.onosproject.net.intent.constraint.ProtectedConstraint;
30
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070031import static org.onosproject.net.intent.constraint.ProtectionConstraint.protection;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070032
Jonathan Hartc3af35a2015-04-30 22:20:29 -070033import java.util.List;
Ray Milkey5b3717e2015-02-05 11:44:08 -080034
Ray Milkeya058c732014-10-08 13:52:34 -070035/**
36 * Installs point-to-point connectivity intents.
37 */
38@Command(scope = "onos", name = "add-point-intent",
39 description = "Installs point-to-point connectivity intent")
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070040public class AddPointToPointIntentCommand extends ConnectivityIntentCommand {
Ray Milkeya058c732014-10-08 13:52:34 -070041
42 @Argument(index = 0, name = "ingressDevice",
43 description = "Ingress Device/Port Description",
44 required = true, multiValued = false)
45 String ingressDeviceString = null;
46
47 @Argument(index = 1, name = "egressDevice",
48 description = "Egress Device/Port Description",
49 required = true, multiValued = false)
50 String egressDeviceString = null;
51
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080052
53 /**
54 * Option to produce protected path.
55 * @deprecated in 1.9.0
56 */
Yuta HIGUCHIcd318502016-09-01 14:25:58 -070057 // -p already defined in ConnectivityIntentCommand
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080058 @Deprecated
Yuta HIGUCHIcd318502016-09-01 14:25:58 -070059 @Option(name = "-r", aliases = "--protect",
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080060 description = "(deprecated) Utilize path protection",
helenyrwu2a674902016-07-20 09:48:04 -070061 required = false, multiValued = false)
62 private boolean backup = false;
63
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080064 /**
65 * Option to consume protected path.
66 */
67 @Option(name = "--useProtected",
68 description = "use protected links only")
69 private boolean useProtected = false;
70
Ray Milkeya058c732014-10-08 13:52:34 -070071 @Override
72 protected void execute() {
73 IntentService service = get(IntentService.class);
74
Jonathan Hartc3af35a2015-04-30 22:20:29 -070075 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070076
Jonathan Hartc3af35a2015-04-30 22:20:29 -070077 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070078
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070079 TrafficSelector selector = buildTrafficSelector();
Ray Milkeyac1441d2014-11-13 09:31:47 -080080 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkeya058c732014-10-08 13:52:34 -070081
Ray Milkey460f4022014-11-05 15:41:43 -080082 List<Constraint> constraints = buildConstraints();
helenyrwu2a674902016-07-20 09:48:04 -070083 if (backup) {
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070084 constraints.add(protection());
helenyrwu2a674902016-07-20 09:48:04 -070085 }
Ray Milkey460f4022014-11-05 15:41:43 -080086
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080087 if (useProtected) {
88 constraints.add(ProtectedConstraint.useProtectedLink());
89 }
90
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070091 Intent intent = PointToPointIntent.builder()
92 .appId(appId())
93 .key(key())
94 .selector(selector)
95 .treatment(treatment)
Ray Milkeya2cf3a12018-02-15 16:13:56 -080096 .filteredIngressPoint(new FilteredConnectPoint(ingress))
97 .filteredEgressPoint(new FilteredConnectPoint(egress))
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070098 .constraints(constraints)
99 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -0800100 .resourceGroup(resourceGroup())
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700101 .build();
Ray Milkeya058c732014-10-08 13:52:34 -0700102 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -0800103 print("Point to point intent submitted:\n%s", intent.toString());
Ray Milkeya058c732014-10-08 13:52:34 -0700104 }
Ray Milkeya058c732014-10-08 13:52:34 -0700105}