blob: 8192dd45f094a18d0868fdffe956dc1bd9441307 [file] [log] [blame]
alshabibab984662014-12-04 18:56:18 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
alshabibab984662014-12-04 18:56:18 -08003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli.net;
Michele Santuari4a338072014-11-05 18:38:55 +010017
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 Milkey4f7e3632019-02-19 15:35:20 -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.IntentService;
28import org.onosproject.net.intent.SinglePointToMultiPointIntent;
Michele Santuari4a338072014-11-05 18:38:55 +010029
Jonathan Hartc3af35a2015-04-30 22:20:29 -070030import java.util.HashSet;
31import java.util.List;
32import java.util.Set;
Jonathan Hart9a4157b2015-02-05 10:19:29 -080033
Charles M.C. Chan6f5bdc62015-04-22 01:21:09 +080034/**
35 * Installs connectivity intent between a single ingress device and multiple egress devices.
36 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070037@Service
Michele Santuari4a338072014-11-05 18:38:55 +010038@Command(scope = "onos", name = "add-single-to-multi-intent",
Pavlin Radoslavov70761df2015-03-09 11:05:49 -070039 description = "Installs connectivity intent between a single ingress device and multiple egress devices")
Michele Santuari4a338072014-11-05 18:38:55 +010040public class AddSinglePointToMultiPointIntentCommand extends ConnectivityIntentCommand {
Pavlin Radoslavov70761df2015-03-09 11:05:49 -070041 @Argument(index = 0, name = "ingressDevice egressDevices",
42 description = "ingressDevice/Port egressDevice/Port...egressDevice/Port",
Michele Santuari4a338072014-11-05 18:38:55 +010043 required = true, multiValued = true)
Ray Milkey0068fd02018-10-11 15:45:39 -070044 @Completion(ConnectPointCompleter.class)
Michele Santuari4a338072014-11-05 18:38:55 +010045 String[] deviceStrings = null;
46
47 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070048 protected void doExecute() {
Michele Santuari4a338072014-11-05 18:38:55 +010049 IntentService service = get(IntentService.class);
50
51 if (deviceStrings.length < 2) {
52 return;
53 }
54
Pavlin Radoslavov70761df2015-03-09 11:05:49 -070055 String ingressDeviceString = deviceStrings[0];
Jonathan Hartc3af35a2015-04-30 22:20:29 -070056 ConnectPoint ingressPoint = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Michele Santuari4a338072014-11-05 18:38:55 +010057
Ray Milkey4f7e3632019-02-19 15:35:20 -080058 Set<FilteredConnectPoint> egressPoints = new HashSet<>();
Pavlin Radoslavov70761df2015-03-09 11:05:49 -070059 for (int index = 1; index < deviceStrings.length; index++) {
Michele Santuari4a338072014-11-05 18:38:55 +010060 String egressDeviceString = deviceStrings[index];
Jonathan Hartc3af35a2015-04-30 22:20:29 -070061 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Ray Milkey4f7e3632019-02-19 15:35:20 -080062 egressPoints.add(new FilteredConnectPoint(egress));
Michele Santuari4a338072014-11-05 18:38:55 +010063 }
64
65 TrafficSelector selector = buildTrafficSelector();
Brian O'Connor406e2642016-04-18 11:45:35 -070066 TrafficTreatment treatment = buildTrafficTreatment();
Michele Santuari4a338072014-11-05 18:38:55 +010067 List<Constraint> constraints = buildConstraints();
68
Ray Milkey5b3717e2015-02-05 11:44:08 -080069 SinglePointToMultiPointIntent intent =
Ray Milkeyebc5d222015-03-18 15:45:36 -070070 SinglePointToMultiPointIntent.builder()
71 .appId(appId())
72 .key(key())
73 .selector(selector)
74 .treatment(treatment)
Ray Milkey4f7e3632019-02-19 15:35:20 -080075 .filteredIngressPoint(new FilteredConnectPoint(ingressPoint))
76 .filteredEgressPoints(egressPoints)
Ray Milkeyebc5d222015-03-18 15:45:36 -070077 .constraints(constraints)
78 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -080079 .resourceGroup(resourceGroup())
Ray Milkeyebc5d222015-03-18 15:45:36 -070080 .build();
Michele Santuari4a338072014-11-05 18:38:55 +010081 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080082 print("Single point to multipoint intent submitted:\n%s", intent.toString());
Michele Santuari4a338072014-11-05 18:38:55 +010083 }
84
Michele Santuari4a338072014-11-05 18:38:55 +010085}