blob: 3b483749850b1685ec7a8a8d046fbe55885553e5 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
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;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.flow.TrafficSelector;
23import org.onosproject.net.flow.TrafficTreatment;
24import org.onosproject.net.intent.Constraint;
25import org.onosproject.net.intent.Intent;
26import org.onosproject.net.intent.IntentService;
27import org.onosproject.net.intent.PointToPointIntent;
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080028import org.onosproject.net.intent.constraint.ProtectedConstraint;
29
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070030import static org.onosproject.net.intent.constraint.ProtectionConstraint.protection;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070031
Jonathan Hartc3af35a2015-04-30 22:20:29 -070032import java.util.List;
Ray Milkey5b3717e2015-02-05 11:44:08 -080033
Ray Milkeya058c732014-10-08 13:52:34 -070034/**
35 * Installs point-to-point connectivity intents.
36 */
37@Command(scope = "onos", name = "add-point-intent",
38 description = "Installs point-to-point connectivity intent")
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070039public class AddPointToPointIntentCommand extends ConnectivityIntentCommand {
Ray Milkeya058c732014-10-08 13:52:34 -070040
41 @Argument(index = 0, name = "ingressDevice",
42 description = "Ingress Device/Port Description",
43 required = true, multiValued = false)
44 String ingressDeviceString = null;
45
46 @Argument(index = 1, name = "egressDevice",
47 description = "Egress Device/Port Description",
48 required = true, multiValued = false)
49 String egressDeviceString = null;
50
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080051
52 /**
53 * Option to produce protected path.
54 * @deprecated in 1.9.0
55 */
Yuta HIGUCHIcd318502016-09-01 14:25:58 -070056 // -p already defined in ConnectivityIntentCommand
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080057 @Deprecated
Yuta HIGUCHIcd318502016-09-01 14:25:58 -070058 @Option(name = "-r", aliases = "--protect",
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080059 description = "(deprecated) Utilize path protection",
helenyrwu2a674902016-07-20 09:48:04 -070060 required = false, multiValued = false)
61 private boolean backup = false;
62
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080063 /**
64 * Option to consume protected path.
65 */
66 @Option(name = "--useProtected",
67 description = "use protected links only")
68 private boolean useProtected = false;
69
Ray Milkeya058c732014-10-08 13:52:34 -070070 @Override
71 protected void execute() {
72 IntentService service = get(IntentService.class);
73
Jonathan Hartc3af35a2015-04-30 22:20:29 -070074 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070075
Jonathan Hartc3af35a2015-04-30 22:20:29 -070076 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070077
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070078 TrafficSelector selector = buildTrafficSelector();
Ray Milkeyac1441d2014-11-13 09:31:47 -080079 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkeya058c732014-10-08 13:52:34 -070080
Ray Milkey460f4022014-11-05 15:41:43 -080081 List<Constraint> constraints = buildConstraints();
helenyrwu2a674902016-07-20 09:48:04 -070082 if (backup) {
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070083 constraints.add(protection());
helenyrwu2a674902016-07-20 09:48:04 -070084 }
Ray Milkey460f4022014-11-05 15:41:43 -080085
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080086 if (useProtected) {
87 constraints.add(ProtectedConstraint.useProtectedLink());
88 }
89
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070090 Intent intent = PointToPointIntent.builder()
91 .appId(appId())
92 .key(key())
93 .selector(selector)
94 .treatment(treatment)
95 .ingressPoint(ingress)
96 .egressPoint(egress)
97 .constraints(constraints)
98 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -080099 .resourceGroup(resourceGroup())
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700100 .build();
Ray Milkeya058c732014-10-08 13:52:34 -0700101 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -0800102 print("Point to point intent submitted:\n%s", intent.toString());
Ray Milkeya058c732014-10-08 13:52:34 -0700103 }
Ray Milkeya058c732014-10-08 13:52:34 -0700104}