blob: a5ad5feb5f9da4fd0e1cb3df05aad3d5a6ef4e62 [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
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;
Jonathan Hart1d006392016-02-11 09:12:56 -080022import org.onlab.packet.IpAddress;
alshabibeff00542015-09-23 13:22:33 -070023import org.onosproject.cli.AbstractShellCommand;
Ray Milkey0068fd02018-10-11 15:45:39 -070024import org.onosproject.cli.PlaceholderCompleter;
Julian Lawrencefa790f62016-01-07 17:18:30 -080025import org.onosproject.net.ConnectPoint;
26import org.onosproject.net.mcast.McastRoute;
27import org.onosproject.net.mcast.MulticastRouteService;
alshabibeff00542015-09-23 13:22:33 -070028
29/**
Rusty Eddyc0e3fea2015-09-28 21:20:41 +000030 * Deletes a multicast route.
alshabibeff00542015-09-23 13:22:33 -070031 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070032@Service
alshabibeff00542015-09-23 13:22:33 -070033@Command(scope = "onos", name = "mcast-delete",
34 description = "Delete a multicast route flow")
35public class McastDeleteCommand extends AbstractShellCommand {
36
Pier Luigib29144d2018-01-15 18:06:43 +010037 // Delete format for group line
38 private static final String D_FORMAT_MAPPING = "Deleted the mcast route: " +
39 "origin=%s, group=%s, source=%s";
40
41 // Update format for group line
42 private static final String U_FORMAT_MAPPING = "Updated the mcast route: " +
43 "origin=%s, group=%s, source=%s";
44
alshabibeff00542015-09-23 13:22:33 -070045 @Argument(index = 0, name = "sAddr",
46 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
47 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070048 @Completion(PlaceholderCompleter.class)
alshabibeff00542015-09-23 13:22:33 -070049 String sAddr = null;
50
51 @Argument(index = 1, name = "gAddr",
Jonathan Hart9ad777f2016-02-19 12:44:36 -080052 description = "IP Address of the multicast group. '*' can be used to denote all groups",
alshabibeff00542015-09-23 13:22:33 -070053 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070054 @Completion(McastGroupCompleter.class)
alshabibeff00542015-09-23 13:22:33 -070055 String gAddr = null;
56
Julian Lawrence14c73182015-10-08 18:31:52 -070057 @Argument(index = 2, name = "egressList",
58 description = "Egress id/port",
59 required = false, multiValued = true)
Ray Milkey0068fd02018-10-11 15:45:39 -070060 @Completion(ConnectPointCompleter.class)
Julian Lawrence14c73182015-10-08 18:31:52 -070061 String[] egressList = null;
62
63
alshabibeff00542015-09-23 13:22:33 -070064 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070065 protected void doExecute() {
Jonathan Hart1d006392016-02-11 09:12:56 -080066 MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
Julian Lawrence14c73182015-10-08 18:31:52 -070067
Jon Halla3fcf672017-03-28 16:53:22 -070068 if ("*".equals(sAddr) && "*".equals(gAddr)) {
Jonathan Hart9ad777f2016-02-19 12:44:36 -080069 // Clear all routes
70 mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove);
71 return;
72 }
73
Jonathan Hart1d006392016-02-11 09:12:56 -080074 McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr),
75 IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
Julian Lawrence14c73182015-10-08 18:31:52 -070076
77 if (egressList == null) {
Julian Lawrencefa790f62016-01-07 17:18:30 -080078 mcastRouteManager.remove(mRoute);
Pier Luigib29144d2018-01-15 18:06:43 +010079 print(D_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source());
Julian Lawrence14c73182015-10-08 18:31:52 -070080 } else {
81 // check list for validity before we begin to delete.
82 for (String egress : egressList) {
Julian Lawrencefa790f62016-01-07 17:18:30 -080083 ConnectPoint eCp = ConnectPoint.deviceConnectPoint(egress);
84 mcastRouteManager.removeSink(mRoute, eCp);
Julian Lawrence14c73182015-10-08 18:31:52 -070085 }
Pier Luigib29144d2018-01-15 18:06:43 +010086 print(U_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source());
Julian Lawrence14c73182015-10-08 18:31:52 -070087 }
alshabibeff00542015-09-23 13:22:33 -070088 }
Julian Lawrence14c73182015-10-08 18:31:52 -070089}