Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 17 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.net.ConnectPoint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.flow.TrafficSelector; |
| 22 | import org.onosproject.net.flow.TrafficTreatment; |
| 23 | import org.onosproject.net.intent.Constraint; |
| 24 | import org.onosproject.net.intent.Intent; |
| 25 | import org.onosproject.net.intent.IntentService; |
| 26 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 27 | |
Jonathan Hart | 9a4157b | 2015-02-05 10:19:29 -0800 | [diff] [blame] | 28 | import java.util.HashSet; |
| 29 | import java.util.List; |
| 30 | import java.util.Set; |
| 31 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 32 | /** |
Charles M.C. Chan | 6f5bdc6 | 2015-04-22 01:21:09 +0800 | [diff] [blame] | 33 | * Installs connectivity intent between multiple ingress devices and a single egress device. |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 34 | */ |
| 35 | @Command(scope = "onos", name = "add-multi-to-single-intent", |
Charles M.C. Chan | 6f5bdc6 | 2015-04-22 01:21:09 +0800 | [diff] [blame] | 36 | description = "Installs connectivity intent between multiple ingress devices and a single egress device") |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 37 | public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentCommand { |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 38 | |
Jonathan Hart | 9a4157b | 2015-02-05 10:19:29 -0800 | [diff] [blame] | 39 | @Argument(index = 0, name = "ingressDevices egressDevice", |
| 40 | description = "ingressDevice/Port..ingressDevice/Port egressDevice/Port", |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 41 | required = true, multiValued = true) |
| 42 | String[] deviceStrings = null; |
| 43 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 44 | @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 Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 53 | ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 54 | |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 55 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 56 | for (int index = 0; index < deviceStrings.length - 1; index++) { |
| 57 | String ingressDeviceString = deviceStrings[index]; |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 58 | ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 59 | ingressPoints.add(ingress); |
| 60 | } |
| 61 | |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 62 | TrafficSelector selector = buildTrafficSelector(); |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 63 | TrafficTreatment treatment = buildTrafficTreatment(); |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 64 | List<Constraint> constraints = buildConstraints(); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 65 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 66 | 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()) |
| 75 | .build(); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 76 | service.submit(intent); |
Ray Milkey | cb33a13 | 2015-02-02 10:05:12 -0800 | [diff] [blame] | 77 | print("Multipoint to single point intent submitted:\n%s", intent.toString()); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 78 | } |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 79 | } |