blob: aa026ed6197c809dbfbb0f23930d2fffb3a902ab [file] [log] [blame]
alshabibeff00542015-09-23 13:22:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
alshabibeff00542015-09-23 13:22:33 -07003 *
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 */
Jonathan Hart1d006392016-02-11 09:12:56 -080016package org.onosproject.cli.net;
alshabibeff00542015-09-23 13:22:33 -070017
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Jonathan Hart1d006392016-02-11 09:12:56 -080020import org.onlab.packet.IpAddress;
alshabibeff00542015-09-23 13:22:33 -070021import org.onosproject.cli.AbstractShellCommand;
Julian Lawrencefa790f62016-01-07 17:18:30 -080022import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.mcast.McastRoute;
24import org.onosproject.net.mcast.MulticastRouteService;
alshabibeff00542015-09-23 13:22:33 -070025
26/**
Rusty Eddyc0e3fea2015-09-28 21:20:41 +000027 * Deletes a multicast route.
alshabibeff00542015-09-23 13:22:33 -070028 */
29@Command(scope = "onos", name = "mcast-delete",
30 description = "Delete a multicast route flow")
31public class McastDeleteCommand extends AbstractShellCommand {
32
33 @Argument(index = 0, name = "sAddr",
34 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
35 required = true, multiValued = false)
36 String sAddr = null;
37
38 @Argument(index = 1, name = "gAddr",
Jonathan Hart9ad777f2016-02-19 12:44:36 -080039 description = "IP Address of the multicast group. '*' can be used to denote all groups",
alshabibeff00542015-09-23 13:22:33 -070040 required = true, multiValued = false)
41 String gAddr = null;
42
Julian Lawrence14c73182015-10-08 18:31:52 -070043 @Argument(index = 2, name = "egressList",
44 description = "Egress id/port",
45 required = false, multiValued = true)
46 String[] egressList = null;
47
48
alshabibeff00542015-09-23 13:22:33 -070049 @Override
50 protected void execute() {
Jonathan Hart1d006392016-02-11 09:12:56 -080051 MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
Julian Lawrence14c73182015-10-08 18:31:52 -070052
Jonathan Hart9ad777f2016-02-19 12:44:36 -080053 if (sAddr.equals("*") && gAddr.equals("*")) {
54 // Clear all routes
55 mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove);
56 return;
57 }
58
Jonathan Hart1d006392016-02-11 09:12:56 -080059 McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr),
60 IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
Julian Lawrence14c73182015-10-08 18:31:52 -070061
62 if (egressList == null) {
Julian Lawrencefa790f62016-01-07 17:18:30 -080063 mcastRouteManager.remove(mRoute);
Julian Lawrence14c73182015-10-08 18:31:52 -070064 } else {
65 // check list for validity before we begin to delete.
66 for (String egress : egressList) {
Julian Lawrencefa790f62016-01-07 17:18:30 -080067 ConnectPoint eCp = ConnectPoint.deviceConnectPoint(egress);
68 mcastRouteManager.removeSink(mRoute, eCp);
Julian Lawrence14c73182015-10-08 18:31:52 -070069 }
70 }
alshabibeff00542015-09-23 13:22:33 -070071 }
Julian Lawrence14c73182015-10-08 18:31:52 -070072}