alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 17 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.net.ConnectPoint; |
Ray Milkey | 4f7e363 | 2019-02-19 15:35:20 -0800 | [diff] [blame] | 23 | import org.onosproject.net.FilteredConnectPoint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import org.onosproject.net.flow.TrafficSelector; |
| 25 | import org.onosproject.net.flow.TrafficTreatment; |
| 26 | import org.onosproject.net.intent.Constraint; |
| 27 | import org.onosproject.net.intent.IntentService; |
| 28 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 29 | |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 30 | import java.util.HashSet; |
| 31 | import java.util.List; |
| 32 | import java.util.Set; |
Jonathan Hart | 9a4157b | 2015-02-05 10:19:29 -0800 | [diff] [blame] | 33 | |
Charles M.C. Chan | 6f5bdc6 | 2015-04-22 01:21:09 +0800 | [diff] [blame] | 34 | /** |
| 35 | * Installs connectivity intent between a single ingress device and multiple egress devices. |
| 36 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 37 | @Service |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 38 | @Command(scope = "onos", name = "add-single-to-multi-intent", |
Pavlin Radoslavov | 70761df | 2015-03-09 11:05:49 -0700 | [diff] [blame] | 39 | description = "Installs connectivity intent between a single ingress device and multiple egress devices") |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 40 | public class AddSinglePointToMultiPointIntentCommand extends ConnectivityIntentCommand { |
Pavlin Radoslavov | 70761df | 2015-03-09 11:05:49 -0700 | [diff] [blame] | 41 | @Argument(index = 0, name = "ingressDevice egressDevices", |
| 42 | description = "ingressDevice/Port egressDevice/Port...egressDevice/Port", |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 43 | required = true, multiValued = true) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 44 | @Completion(ConnectPointCompleter.class) |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 45 | String[] deviceStrings = null; |
| 46 | |
| 47 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 48 | protected void doExecute() { |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 49 | IntentService service = get(IntentService.class); |
| 50 | |
| 51 | if (deviceStrings.length < 2) { |
| 52 | return; |
| 53 | } |
| 54 | |
Pavlin Radoslavov | 70761df | 2015-03-09 11:05:49 -0700 | [diff] [blame] | 55 | String ingressDeviceString = deviceStrings[0]; |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 56 | ConnectPoint ingressPoint = ConnectPoint.deviceConnectPoint(ingressDeviceString); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 57 | |
Ray Milkey | 4f7e363 | 2019-02-19 15:35:20 -0800 | [diff] [blame] | 58 | Set<FilteredConnectPoint> egressPoints = new HashSet<>(); |
Pavlin Radoslavov | 70761df | 2015-03-09 11:05:49 -0700 | [diff] [blame] | 59 | for (int index = 1; index < deviceStrings.length; index++) { |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 60 | String egressDeviceString = deviceStrings[index]; |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 61 | ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString); |
Ray Milkey | 4f7e363 | 2019-02-19 15:35:20 -0800 | [diff] [blame] | 62 | egressPoints.add(new FilteredConnectPoint(egress)); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | TrafficSelector selector = buildTrafficSelector(); |
Brian O'Connor | 406e264 | 2016-04-18 11:45:35 -0700 | [diff] [blame] | 66 | TrafficTreatment treatment = buildTrafficTreatment(); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 67 | List<Constraint> constraints = buildConstraints(); |
| 68 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 69 | SinglePointToMultiPointIntent intent = |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 70 | SinglePointToMultiPointIntent.builder() |
| 71 | .appId(appId()) |
| 72 | .key(key()) |
| 73 | .selector(selector) |
| 74 | .treatment(treatment) |
Ray Milkey | 4f7e363 | 2019-02-19 15:35:20 -0800 | [diff] [blame] | 75 | .filteredIngressPoint(new FilteredConnectPoint(ingressPoint)) |
| 76 | .filteredEgressPoints(egressPoints) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 77 | .constraints(constraints) |
| 78 | .priority(priority()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 79 | .resourceGroup(resourceGroup()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 80 | .build(); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 81 | service.submit(intent); |
Ray Milkey | cb33a13 | 2015-02-02 10:05:12 -0800 | [diff] [blame] | 82 | print("Single point to multipoint intent submitted:\n%s", intent.toString()); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 85 | } |