blob: 264eb39c4b6d43f3a1c24e7356f304f743e0d60d [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
helenyrwu2a674902016-07-20 09:48:04 -070052 private boolean backup = false;
53
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080054 /**
55 * Option to consume protected path.
56 */
57 @Option(name = "--useProtected",
58 description = "use protected links only")
59 private boolean useProtected = false;
60
Ray Milkeya058c732014-10-08 13:52:34 -070061 @Override
62 protected void execute() {
63 IntentService service = get(IntentService.class);
64
Jonathan Hartc3af35a2015-04-30 22:20:29 -070065 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070066
Jonathan Hartc3af35a2015-04-30 22:20:29 -070067 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070068
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070069 TrafficSelector selector = buildTrafficSelector();
Ray Milkeyac1441d2014-11-13 09:31:47 -080070 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkeya058c732014-10-08 13:52:34 -070071
Ray Milkey460f4022014-11-05 15:41:43 -080072 List<Constraint> constraints = buildConstraints();
helenyrwu2a674902016-07-20 09:48:04 -070073 if (backup) {
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070074 constraints.add(protection());
helenyrwu2a674902016-07-20 09:48:04 -070075 }
Ray Milkey460f4022014-11-05 15:41:43 -080076
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080077 if (useProtected) {
78 constraints.add(ProtectedConstraint.useProtectedLink());
79 }
80
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070081 Intent intent = PointToPointIntent.builder()
82 .appId(appId())
83 .key(key())
84 .selector(selector)
85 .treatment(treatment)
Ray Milkeya2cf3a12018-02-15 16:13:56 -080086 .filteredIngressPoint(new FilteredConnectPoint(ingress))
87 .filteredEgressPoint(new FilteredConnectPoint(egress))
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070088 .constraints(constraints)
89 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -080090 .resourceGroup(resourceGroup())
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070091 .build();
Ray Milkeya058c732014-10-08 13:52:34 -070092 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080093 print("Point to point intent submitted:\n%s", intent.toString());
Ray Milkeya058c732014-10-08 13:52:34 -070094 }
Ray Milkeya058c732014-10-08 13:52:34 -070095}