blob: 8a0639ae78f5e460a4286e7716db632e31ff38ff [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 Milkey0742ec92014-10-13 08:39:55 -070018import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.ConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.flow.TrafficSelector;
22import org.onosproject.net.flow.TrafficTreatment;
23import org.onosproject.net.intent.Constraint;
24import org.onosproject.net.intent.Intent;
25import org.onosproject.net.intent.IntentService;
26import org.onosproject.net.intent.MultiPointToSinglePointIntent;
Ray Milkey0742ec92014-10-13 08:39:55 -070027
Jonathan Hart9a4157b2015-02-05 10:19:29 -080028import java.util.HashSet;
29import java.util.List;
30import java.util.Set;
31
Ray Milkey0742ec92014-10-13 08:39:55 -070032/**
Charles M.C. Chan6f5bdc62015-04-22 01:21:09 +080033 * Installs connectivity intent between multiple ingress devices and a single egress device.
Ray Milkey0742ec92014-10-13 08:39:55 -070034 */
35@Command(scope = "onos", name = "add-multi-to-single-intent",
Charles M.C. Chan6f5bdc62015-04-22 01:21:09 +080036 description = "Installs connectivity intent between multiple ingress devices and a single egress device")
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070037public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentCommand {
Ray Milkey0742ec92014-10-13 08:39:55 -070038
Jonathan Hart9a4157b2015-02-05 10:19:29 -080039 @Argument(index = 0, name = "ingressDevices egressDevice",
40 description = "ingressDevice/Port..ingressDevice/Port egressDevice/Port",
Ray Milkey0742ec92014-10-13 08:39:55 -070041 required = true, multiValued = true)
42 String[] deviceStrings = null;
43
Ray Milkey0742ec92014-10-13 08:39:55 -070044 @Override
45 protected void execute() {
46 IntentService service = get(IntentService.class);
47
48 if (deviceStrings.length < 2) {
49 return;
50 }
51
52 String egressDeviceString = deviceStrings[deviceStrings.length - 1];
Jonathan Hartc3af35a2015-04-30 22:20:29 -070053 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Ray Milkey0742ec92014-10-13 08:39:55 -070054
Jonathan Hartc3af35a2015-04-30 22:20:29 -070055 Set<ConnectPoint> ingressPoints = new HashSet<>();
Ray Milkey0742ec92014-10-13 08:39:55 -070056 for (int index = 0; index < deviceStrings.length - 1; index++) {
57 String ingressDeviceString = deviceStrings[index];
Jonathan Hartc3af35a2015-04-30 22:20:29 -070058 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Ray Milkey0742ec92014-10-13 08:39:55 -070059 ingressPoints.add(ingress);
60 }
61
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070062 TrafficSelector selector = buildTrafficSelector();
Jonathan Hart2c25e362014-11-17 18:14:19 -080063 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkey460f4022014-11-05 15:41:43 -080064 List<Constraint> constraints = buildConstraints();
Ray Milkey0742ec92014-10-13 08:39:55 -070065
Ray Milkeyebc5d222015-03-18 15:45:36 -070066 Intent intent = MultiPointToSinglePointIntent.builder()
67 .appId(appId())
68 .key(key())
69 .selector(selector)
70 .treatment(treatment)
71 .ingressPoints(ingressPoints)
72 .egressPoint(egress)
73 .constraints(constraints)
74 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -080075 .resourceGroup(resourceGroup())
Ray Milkeyebc5d222015-03-18 15:45:36 -070076 .build();
Ray Milkey0742ec92014-10-13 08:39:55 -070077 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080078 print("Multipoint to single point intent submitted:\n%s", intent.toString());
Ray Milkey0742ec92014-10-13 08:39:55 -070079 }
Ray Milkey0742ec92014-10-13 08:39:55 -070080}