blob: d06b491bd45ca0c4f94a84a3337cdbcc68a21843 [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 Milkey0742ec92014-10-13 08:39:55 -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;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.ConnectPoint;
Ray Milkey27cff8c2018-03-05 14:58:26 -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.MultiPointToSinglePointIntent;
Ray Milkey0742ec92014-10-13 08:39:55 -070030
Jonathan Hart9a4157b2015-02-05 10:19:29 -080031import java.util.HashSet;
32import java.util.List;
33import java.util.Set;
34
Ray Milkey0742ec92014-10-13 08:39:55 -070035/**
Charles M.C. Chan6f5bdc62015-04-22 01:21:09 +080036 * Installs connectivity intent between multiple ingress devices and a single egress device.
Ray Milkey0742ec92014-10-13 08:39:55 -070037 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070038@Service
Ray Milkey0742ec92014-10-13 08:39:55 -070039@Command(scope = "onos", name = "add-multi-to-single-intent",
Charles M.C. Chan6f5bdc62015-04-22 01:21:09 +080040 description = "Installs connectivity intent between multiple ingress devices and a single egress device")
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070041public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentCommand {
Ray Milkey0742ec92014-10-13 08:39:55 -070042
Jonathan Hart9a4157b2015-02-05 10:19:29 -080043 @Argument(index = 0, name = "ingressDevices egressDevice",
44 description = "ingressDevice/Port..ingressDevice/Port egressDevice/Port",
Ray Milkey0742ec92014-10-13 08:39:55 -070045 required = true, multiValued = true)
Ray Milkey0068fd02018-10-11 15:45:39 -070046 @Completion(ConnectPointCompleter.class)
Ray Milkey0742ec92014-10-13 08:39:55 -070047 String[] deviceStrings = null;
48
Ray Milkey0742ec92014-10-13 08:39:55 -070049 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070050 protected void doExecute() {
Ray Milkey0742ec92014-10-13 08:39:55 -070051 IntentService service = get(IntentService.class);
52
53 if (deviceStrings.length < 2) {
54 return;
55 }
56
57 String egressDeviceString = deviceStrings[deviceStrings.length - 1];
Ray Milkey27cff8c2018-03-05 14:58:26 -080058 FilteredConnectPoint egress = new FilteredConnectPoint(ConnectPoint.deviceConnectPoint(egressDeviceString));
Ray Milkey0742ec92014-10-13 08:39:55 -070059
Ray Milkey27cff8c2018-03-05 14:58:26 -080060 Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
Ray Milkey0742ec92014-10-13 08:39:55 -070061 for (int index = 0; index < deviceStrings.length - 1; index++) {
62 String ingressDeviceString = deviceStrings[index];
Jonathan Hartc3af35a2015-04-30 22:20:29 -070063 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Ray Milkey27cff8c2018-03-05 14:58:26 -080064 ingressPoints.add(new FilteredConnectPoint(ingress));
Ray Milkey0742ec92014-10-13 08:39:55 -070065 }
66
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070067 TrafficSelector selector = buildTrafficSelector();
Jonathan Hart2c25e362014-11-17 18:14:19 -080068 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkey460f4022014-11-05 15:41:43 -080069 List<Constraint> constraints = buildConstraints();
Ray Milkey0742ec92014-10-13 08:39:55 -070070
Ray Milkeyebc5d222015-03-18 15:45:36 -070071 Intent intent = MultiPointToSinglePointIntent.builder()
72 .appId(appId())
73 .key(key())
74 .selector(selector)
75 .treatment(treatment)
Ray Milkey27cff8c2018-03-05 14:58:26 -080076 .filteredIngressPoints(ingressPoints)
77 .filteredEgressPoint(egress)
Ray Milkeyebc5d222015-03-18 15:45:36 -070078 .constraints(constraints)
79 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -080080 .resourceGroup(resourceGroup())
Ray Milkeyebc5d222015-03-18 15:45:36 -070081 .build();
Ray Milkey0742ec92014-10-13 08:39:55 -070082 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080083 print("Multipoint to single point intent submitted:\n%s", intent.toString());
Ray Milkey0742ec92014-10-13 08:39:55 -070084 }
Ray Milkey0742ec92014-10-13 08:39:55 -070085}