blob: 270db57eaf563b1d5d195f3404a9fad449ffea77 [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;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
Jonathan Hart1d006392016-02-11 09:12:56 -080021import org.onlab.packet.IpAddress;
alshabibeff00542015-09-23 13:22:33 -070022import org.onosproject.cli.AbstractShellCommand;
Julian Lawrencefa790f62016-01-07 17:18:30 -080023import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.mcast.McastRoute;
25import org.onosproject.net.mcast.MulticastRouteService;
alshabibeff00542015-09-23 13:22:33 -070026
27/**
Rusty Eddyc0e3fea2015-09-28 21:20:41 +000028 * Deletes a multicast route.
alshabibeff00542015-09-23 13:22:33 -070029 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070030@Service
alshabibeff00542015-09-23 13:22:33 -070031@Command(scope = "onos", name = "mcast-delete",
32 description = "Delete a multicast route flow")
33public class McastDeleteCommand extends AbstractShellCommand {
34
Pier Luigib29144d2018-01-15 18:06:43 +010035 // Delete format for group line
36 private static final String D_FORMAT_MAPPING = "Deleted the mcast route: " +
37 "origin=%s, group=%s, source=%s";
38
39 // Update format for group line
40 private static final String U_FORMAT_MAPPING = "Updated the mcast route: " +
41 "origin=%s, group=%s, source=%s";
42
alshabibeff00542015-09-23 13:22:33 -070043 @Argument(index = 0, name = "sAddr",
44 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
45 required = true, multiValued = false)
46 String sAddr = null;
47
48 @Argument(index = 1, name = "gAddr",
Jonathan Hart9ad777f2016-02-19 12:44:36 -080049 description = "IP Address of the multicast group. '*' can be used to denote all groups",
alshabibeff00542015-09-23 13:22:33 -070050 required = true, multiValued = false)
51 String gAddr = null;
52
Julian Lawrence14c73182015-10-08 18:31:52 -070053 @Argument(index = 2, name = "egressList",
54 description = "Egress id/port",
55 required = false, multiValued = true)
56 String[] egressList = null;
57
58
alshabibeff00542015-09-23 13:22:33 -070059 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070060 protected void doExecute() {
Jonathan Hart1d006392016-02-11 09:12:56 -080061 MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
Julian Lawrence14c73182015-10-08 18:31:52 -070062
Jon Halla3fcf672017-03-28 16:53:22 -070063 if ("*".equals(sAddr) && "*".equals(gAddr)) {
Jonathan Hart9ad777f2016-02-19 12:44:36 -080064 // Clear all routes
65 mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove);
66 return;
67 }
68
Jonathan Hart1d006392016-02-11 09:12:56 -080069 McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr),
70 IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
Julian Lawrence14c73182015-10-08 18:31:52 -070071
72 if (egressList == null) {
Julian Lawrencefa790f62016-01-07 17:18:30 -080073 mcastRouteManager.remove(mRoute);
Pier Luigib29144d2018-01-15 18:06:43 +010074 print(D_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source());
Julian Lawrence14c73182015-10-08 18:31:52 -070075 } else {
76 // check list for validity before we begin to delete.
77 for (String egress : egressList) {
Julian Lawrencefa790f62016-01-07 17:18:30 -080078 ConnectPoint eCp = ConnectPoint.deviceConnectPoint(egress);
79 mcastRouteManager.removeSink(mRoute, eCp);
Julian Lawrence14c73182015-10-08 18:31:52 -070080 }
Pier Luigib29144d2018-01-15 18:06:43 +010081 print(U_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source());
Julian Lawrence14c73182015-10-08 18:31:52 -070082 }
alshabibeff00542015-09-23 13:22:33 -070083 }
Julian Lawrence14c73182015-10-08 18:31:52 -070084}