blob: 16250a38f185d41f3683bba3a5f00ef710f6bebf [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;
Ray Milkey27cff8c2018-03-05 14:58:26 -080021import org.onosproject.net.FilteredConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.flow.TrafficSelector;
23import org.onosproject.net.flow.TrafficTreatment;
24import org.onosproject.net.intent.Constraint;
25import org.onosproject.net.intent.Intent;
26import org.onosproject.net.intent.IntentService;
27import org.onosproject.net.intent.MultiPointToSinglePointIntent;
Ray Milkey0742ec92014-10-13 08:39:55 -070028
Jonathan Hart9a4157b2015-02-05 10:19:29 -080029import java.util.HashSet;
30import java.util.List;
31import java.util.Set;
32
Ray Milkey0742ec92014-10-13 08:39:55 -070033/**
Charles M.C. Chan6f5bdc62015-04-22 01:21:09 +080034 * Installs connectivity intent between multiple ingress devices and a single egress device.
Ray Milkey0742ec92014-10-13 08:39:55 -070035 */
36@Command(scope = "onos", name = "add-multi-to-single-intent",
Charles M.C. Chan6f5bdc62015-04-22 01:21:09 +080037 description = "Installs connectivity intent between multiple ingress devices and a single egress device")
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070038public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentCommand {
Ray Milkey0742ec92014-10-13 08:39:55 -070039
Jonathan Hart9a4157b2015-02-05 10:19:29 -080040 @Argument(index = 0, name = "ingressDevices egressDevice",
41 description = "ingressDevice/Port..ingressDevice/Port egressDevice/Port",
Ray Milkey0742ec92014-10-13 08:39:55 -070042 required = true, multiValued = true)
43 String[] deviceStrings = null;
44
Ray Milkey0742ec92014-10-13 08:39:55 -070045 @Override
46 protected void execute() {
47 IntentService service = get(IntentService.class);
48
49 if (deviceStrings.length < 2) {
50 return;
51 }
52
53 String egressDeviceString = deviceStrings[deviceStrings.length - 1];
Ray Milkey27cff8c2018-03-05 14:58:26 -080054 FilteredConnectPoint egress = new FilteredConnectPoint(ConnectPoint.deviceConnectPoint(egressDeviceString));
Ray Milkey0742ec92014-10-13 08:39:55 -070055
Ray Milkey27cff8c2018-03-05 14:58:26 -080056 Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
Ray Milkey0742ec92014-10-13 08:39:55 -070057 for (int index = 0; index < deviceStrings.length - 1; index++) {
58 String ingressDeviceString = deviceStrings[index];
Jonathan Hartc3af35a2015-04-30 22:20:29 -070059 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Ray Milkey27cff8c2018-03-05 14:58:26 -080060 ingressPoints.add(new FilteredConnectPoint(ingress));
Ray Milkey0742ec92014-10-13 08:39:55 -070061 }
62
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070063 TrafficSelector selector = buildTrafficSelector();
Jonathan Hart2c25e362014-11-17 18:14:19 -080064 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkey460f4022014-11-05 15:41:43 -080065 List<Constraint> constraints = buildConstraints();
Ray Milkey0742ec92014-10-13 08:39:55 -070066
Ray Milkeyebc5d222015-03-18 15:45:36 -070067 Intent intent = MultiPointToSinglePointIntent.builder()
68 .appId(appId())
69 .key(key())
70 .selector(selector)
71 .treatment(treatment)
Ray Milkey27cff8c2018-03-05 14:58:26 -080072 .filteredIngressPoints(ingressPoints)
73 .filteredEgressPoint(egress)
Ray Milkeyebc5d222015-03-18 15:45:36 -070074 .constraints(constraints)
75 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -080076 .resourceGroup(resourceGroup())
Ray Milkeyebc5d222015-03-18 15:45:36 -070077 .build();
Ray Milkey0742ec92014-10-13 08:39:55 -070078 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080079 print("Multipoint to single point intent submitted:\n%s", intent.toString());
Ray Milkey0742ec92014-10-13 08:39:55 -070080 }
Ray Milkey0742ec92014-10-13 08:39:55 -070081}