blob: 6b489148401a5ced928cded3a3a6836491410c9a [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
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
21import org.apache.karaf.shell.api.action.Option;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.ConnectPoint;
Ray Milkeya2cf3a12018-02-15 16:13:56 -080023import org.onosproject.net.FilteredConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
26import org.onosproject.net.intent.Constraint;
27import org.onosproject.net.intent.Intent;
28import org.onosproject.net.intent.IntentService;
29import org.onosproject.net.intent.PointToPointIntent;
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080030import org.onosproject.net.intent.constraint.ProtectedConstraint;
31
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070032import static org.onosproject.net.intent.constraint.ProtectionConstraint.protection;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070033
Jonathan Hartc3af35a2015-04-30 22:20:29 -070034import java.util.List;
Ray Milkey5b3717e2015-02-05 11:44:08 -080035
Ray Milkeya058c732014-10-08 13:52:34 -070036/**
37 * Installs point-to-point connectivity intents.
38 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070039@Service
Ray Milkeya058c732014-10-08 13:52:34 -070040@Command(scope = "onos", name = "add-point-intent",
41 description = "Installs point-to-point connectivity intent")
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070042public class AddPointToPointIntentCommand extends ConnectivityIntentCommand {
Ray Milkeya058c732014-10-08 13:52:34 -070043
44 @Argument(index = 0, name = "ingressDevice",
45 description = "Ingress Device/Port Description",
46 required = true, multiValued = false)
47 String ingressDeviceString = null;
48
49 @Argument(index = 1, name = "egressDevice",
50 description = "Egress Device/Port Description",
51 required = true, multiValued = false)
52 String egressDeviceString = null;
53
helenyrwu2a674902016-07-20 09:48:04 -070054 private boolean backup = false;
55
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080056 /**
57 * Option to consume protected path.
58 */
59 @Option(name = "--useProtected",
60 description = "use protected links only")
61 private boolean useProtected = false;
62
Ray Milkeya058c732014-10-08 13:52:34 -070063 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070064 protected void doExecute() {
Ray Milkeya058c732014-10-08 13:52:34 -070065 IntentService service = get(IntentService.class);
66
Jonathan Hartc3af35a2015-04-30 22:20:29 -070067 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070068
Jonathan Hartc3af35a2015-04-30 22:20:29 -070069 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070070
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070071 TrafficSelector selector = buildTrafficSelector();
Ray Milkeyac1441d2014-11-13 09:31:47 -080072 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkeya058c732014-10-08 13:52:34 -070073
Ray Milkey460f4022014-11-05 15:41:43 -080074 List<Constraint> constraints = buildConstraints();
helenyrwu2a674902016-07-20 09:48:04 -070075 if (backup) {
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070076 constraints.add(protection());
helenyrwu2a674902016-07-20 09:48:04 -070077 }
Ray Milkey460f4022014-11-05 15:41:43 -080078
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080079 if (useProtected) {
80 constraints.add(ProtectedConstraint.useProtectedLink());
81 }
82
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070083 Intent intent = PointToPointIntent.builder()
84 .appId(appId())
85 .key(key())
86 .selector(selector)
87 .treatment(treatment)
Ray Milkeya2cf3a12018-02-15 16:13:56 -080088 .filteredIngressPoint(new FilteredConnectPoint(ingress))
89 .filteredEgressPoint(new FilteredConnectPoint(egress))
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070090 .constraints(constraints)
91 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -080092 .resourceGroup(resourceGroup())
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070093 .build();
Ray Milkeya058c732014-10-08 13:52:34 -070094 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080095 print("Point to point intent submitted:\n%s", intent.toString());
Ray Milkeya058c732014-10-08 13:52:34 -070096 }
Ray Milkeya058c732014-10-08 13:52:34 -070097}