blob: 87ede2b93650f44d3cd4af4a3e89811f51010d77 [file] [log] [blame]
alshabibab984662014-12-04 18:56:18 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
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
Michele Santuari4a338072014-11-05 18:38:55 +010018import 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.IntentService;
25import org.onosproject.net.intent.SinglePointToMultiPointIntent;
Michele Santuari4a338072014-11-05 18:38:55 +010026
Jonathan Hartc3af35a2015-04-30 22:20:29 -070027import java.util.HashSet;
28import java.util.List;
29import java.util.Set;
Jonathan Hart9a4157b2015-02-05 10:19:29 -080030
Charles M.C. Chan6f5bdc62015-04-22 01:21:09 +080031/**
32 * Installs connectivity intent between a single ingress device and multiple egress devices.
33 */
Michele Santuari4a338072014-11-05 18:38:55 +010034@Command(scope = "onos", name = "add-single-to-multi-intent",
Pavlin Radoslavov70761df2015-03-09 11:05:49 -070035 description = "Installs connectivity intent between a single ingress device and multiple egress devices")
Michele Santuari4a338072014-11-05 18:38:55 +010036public class AddSinglePointToMultiPointIntentCommand extends ConnectivityIntentCommand {
Pavlin Radoslavov70761df2015-03-09 11:05:49 -070037 @Argument(index = 0, name = "ingressDevice egressDevices",
38 description = "ingressDevice/Port egressDevice/Port...egressDevice/Port",
Michele Santuari4a338072014-11-05 18:38:55 +010039 required = true, multiValued = true)
40 String[] deviceStrings = null;
41
42 @Override
43 protected void execute() {
44 IntentService service = get(IntentService.class);
45
46 if (deviceStrings.length < 2) {
47 return;
48 }
49
Pavlin Radoslavov70761df2015-03-09 11:05:49 -070050 String ingressDeviceString = deviceStrings[0];
Jonathan Hartc3af35a2015-04-30 22:20:29 -070051 ConnectPoint ingressPoint = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Michele Santuari4a338072014-11-05 18:38:55 +010052
53 Set<ConnectPoint> egressPoints = new HashSet<>();
Pavlin Radoslavov70761df2015-03-09 11:05:49 -070054 for (int index = 1; index < deviceStrings.length; index++) {
Michele Santuari4a338072014-11-05 18:38:55 +010055 String egressDeviceString = deviceStrings[index];
Jonathan Hartc3af35a2015-04-30 22:20:29 -070056 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Michele Santuari4a338072014-11-05 18:38:55 +010057 egressPoints.add(egress);
58 }
59
60 TrafficSelector selector = buildTrafficSelector();
Brian O'Connor406e2642016-04-18 11:45:35 -070061 TrafficTreatment treatment = buildTrafficTreatment();
Michele Santuari4a338072014-11-05 18:38:55 +010062 List<Constraint> constraints = buildConstraints();
63
Ray Milkey5b3717e2015-02-05 11:44:08 -080064 SinglePointToMultiPointIntent intent =
Ray Milkeyebc5d222015-03-18 15:45:36 -070065 SinglePointToMultiPointIntent.builder()
66 .appId(appId())
67 .key(key())
68 .selector(selector)
69 .treatment(treatment)
70 .ingressPoint(ingressPoint)
71 .egressPoints(egressPoints)
72 .constraints(constraints)
73 .priority(priority())
74 .build();
Michele Santuari4a338072014-11-05 18:38:55 +010075 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080076 print("Single point to multipoint intent submitted:\n%s", intent.toString());
Michele Santuari4a338072014-11-05 18:38:55 +010077 }
78
Michele Santuari4a338072014-11-05 18:38:55 +010079}