blob: 2a5739754083871b2cc2f663ce4f6e4bd09e2934 [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;
Ray Milkey0068fd02018-10-11 15:45:39 -070020import org.apache.karaf.shell.api.action.Completion;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
22import org.apache.karaf.shell.api.action.Option;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.ConnectPoint;
Ray Milkeya2cf3a12018-02-15 16:13:56 -080024import org.onosproject.net.FilteredConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
27import org.onosproject.net.intent.Constraint;
28import org.onosproject.net.intent.Intent;
29import org.onosproject.net.intent.IntentService;
30import org.onosproject.net.intent.PointToPointIntent;
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080031import org.onosproject.net.intent.constraint.ProtectedConstraint;
32
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070033import static org.onosproject.net.intent.constraint.ProtectionConstraint.protection;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070034
Jonathan Hartc3af35a2015-04-30 22:20:29 -070035import java.util.List;
Ray Milkey5b3717e2015-02-05 11:44:08 -080036
Ray Milkeya058c732014-10-08 13:52:34 -070037/**
38 * Installs point-to-point connectivity intents.
39 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070040@Service
Ray Milkeya058c732014-10-08 13:52:34 -070041@Command(scope = "onos", name = "add-point-intent",
42 description = "Installs point-to-point connectivity intent")
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070043public class AddPointToPointIntentCommand extends ConnectivityIntentCommand {
Ray Milkeya058c732014-10-08 13:52:34 -070044
45 @Argument(index = 0, name = "ingressDevice",
46 description = "Ingress Device/Port Description",
47 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070048 @Completion(ConnectPointCompleter.class)
Ray Milkeya058c732014-10-08 13:52:34 -070049 String ingressDeviceString = null;
50
51 @Argument(index = 1, name = "egressDevice",
52 description = "Egress Device/Port Description",
53 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070054 @Completion(ConnectPointCompleter.class)
Ray Milkeya058c732014-10-08 13:52:34 -070055 String egressDeviceString = null;
56
helenyrwu2a674902016-07-20 09:48:04 -070057 private boolean backup = false;
58
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080059 /**
60 * Option to consume protected path.
61 */
62 @Option(name = "--useProtected",
63 description = "use protected links only")
64 private boolean useProtected = false;
65
Ray Milkeya058c732014-10-08 13:52:34 -070066 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070067 protected void doExecute() {
Ray Milkeya058c732014-10-08 13:52:34 -070068 IntentService service = get(IntentService.class);
69
Jonathan Hartc3af35a2015-04-30 22:20:29 -070070 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070071
Jonathan Hartc3af35a2015-04-30 22:20:29 -070072 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070073
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070074 TrafficSelector selector = buildTrafficSelector();
Ray Milkeyac1441d2014-11-13 09:31:47 -080075 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkeya058c732014-10-08 13:52:34 -070076
Ray Milkey460f4022014-11-05 15:41:43 -080077 List<Constraint> constraints = buildConstraints();
helenyrwu2a674902016-07-20 09:48:04 -070078 if (backup) {
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070079 constraints.add(protection());
helenyrwu2a674902016-07-20 09:48:04 -070080 }
Ray Milkey460f4022014-11-05 15:41:43 -080081
Yuta HIGUCHI3e8e0352017-01-09 19:57:57 -080082 if (useProtected) {
83 constraints.add(ProtectedConstraint.useProtectedLink());
84 }
85
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070086 Intent intent = PointToPointIntent.builder()
87 .appId(appId())
88 .key(key())
89 .selector(selector)
90 .treatment(treatment)
Ray Milkeya2cf3a12018-02-15 16:13:56 -080091 .filteredIngressPoint(new FilteredConnectPoint(ingress))
92 .filteredEgressPoint(new FilteredConnectPoint(egress))
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070093 .constraints(constraints)
94 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -080095 .resourceGroup(resourceGroup())
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070096 .build();
Ray Milkeya058c732014-10-08 13:52:34 -070097 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080098 print("Point to point intent submitted:\n%s", intent.toString());
Ray Milkeya058c732014-10-08 13:52:34 -070099 }
Ray Milkeya058c732014-10-08 13:52:34 -0700100}