blob: 26dbfdeb4dbfdabaa616143e8b220bac4ad11d4b [file] [log] [blame]
alshabibeff00542015-09-23 13:22:33 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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
Pier Luigib29144d2018-01-15 18:06:43 +010033 // Delete format for group line
34 private static final String D_FORMAT_MAPPING = "Deleted the mcast route: " +
35 "origin=%s, group=%s, source=%s";
36
37 // Update format for group line
38 private static final String U_FORMAT_MAPPING = "Updated the mcast route: " +
39 "origin=%s, group=%s, source=%s";
40
alshabibeff00542015-09-23 13:22:33 -070041 @Argument(index = 0, name = "sAddr",
42 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
43 required = true, multiValued = false)
44 String sAddr = null;
45
46 @Argument(index = 1, name = "gAddr",
Jonathan Hart9ad777f2016-02-19 12:44:36 -080047 description = "IP Address of the multicast group. '*' can be used to denote all groups",
alshabibeff00542015-09-23 13:22:33 -070048 required = true, multiValued = false)
49 String gAddr = null;
50
Julian Lawrence14c73182015-10-08 18:31:52 -070051 @Argument(index = 2, name = "egressList",
52 description = "Egress id/port",
53 required = false, multiValued = true)
54 String[] egressList = null;
55
56
alshabibeff00542015-09-23 13:22:33 -070057 @Override
58 protected void execute() {
Jonathan Hart1d006392016-02-11 09:12:56 -080059 MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
Julian Lawrence14c73182015-10-08 18:31:52 -070060
Jon Halla3fcf672017-03-28 16:53:22 -070061 if ("*".equals(sAddr) && "*".equals(gAddr)) {
Jonathan Hart9ad777f2016-02-19 12:44:36 -080062 // Clear all routes
63 mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove);
64 return;
65 }
66
Jonathan Hart1d006392016-02-11 09:12:56 -080067 McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr),
68 IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
Julian Lawrence14c73182015-10-08 18:31:52 -070069
70 if (egressList == null) {
Julian Lawrencefa790f62016-01-07 17:18:30 -080071 mcastRouteManager.remove(mRoute);
Pier Luigib29144d2018-01-15 18:06:43 +010072 print(D_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source());
Julian Lawrence14c73182015-10-08 18:31:52 -070073 } else {
74 // check list for validity before we begin to delete.
75 for (String egress : egressList) {
Julian Lawrencefa790f62016-01-07 17:18:30 -080076 ConnectPoint eCp = ConnectPoint.deviceConnectPoint(egress);
77 mcastRouteManager.removeSink(mRoute, eCp);
Julian Lawrence14c73182015-10-08 18:31:52 -070078 }
Pier Luigib29144d2018-01-15 18:06:43 +010079 print(U_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source());
Julian Lawrence14c73182015-10-08 18:31:52 -070080 }
alshabibeff00542015-09-23 13:22:33 -070081 }
Julian Lawrence14c73182015-10-08 18:31:52 -070082}