alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 3 | * |
| 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 Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
Jonathan Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 20 | import org.onlab.packet.IpAddress; |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
Julian Lawrence | fa790f6 | 2016-01-07 17:18:30 -0800 | [diff] [blame] | 22 | import org.onosproject.net.ConnectPoint; |
| 23 | import org.onosproject.net.mcast.McastRoute; |
| 24 | import org.onosproject.net.mcast.MulticastRouteService; |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
Rusty Eddy | c0e3fea | 2015-09-28 21:20:41 +0000 | [diff] [blame] | 27 | * Deletes a multicast route. |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 28 | */ |
| 29 | @Command(scope = "onos", name = "mcast-delete", |
| 30 | description = "Delete a multicast route flow") |
| 31 | public class McastDeleteCommand extends AbstractShellCommand { |
| 32 | |
Pier Luigi | b29144d | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 33 | // 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 | |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 41 | @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 Hart | 9ad777f | 2016-02-19 12:44:36 -0800 | [diff] [blame] | 47 | description = "IP Address of the multicast group. '*' can be used to denote all groups", |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 48 | required = true, multiValued = false) |
| 49 | String gAddr = null; |
| 50 | |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 51 | @Argument(index = 2, name = "egressList", |
| 52 | description = "Egress id/port", |
| 53 | required = false, multiValued = true) |
| 54 | String[] egressList = null; |
| 55 | |
| 56 | |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 57 | @Override |
| 58 | protected void execute() { |
Jonathan Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 59 | MulticastRouteService mcastRouteManager = get(MulticastRouteService.class); |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 60 | |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 61 | if ("*".equals(sAddr) && "*".equals(gAddr)) { |
Jonathan Hart | 9ad777f | 2016-02-19 12:44:36 -0800 | [diff] [blame] | 62 | // Clear all routes |
| 63 | mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove); |
| 64 | return; |
| 65 | } |
| 66 | |
Jonathan Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 67 | McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr), |
| 68 | IpAddress.valueOf(gAddr), McastRoute.Type.STATIC); |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 69 | |
| 70 | if (egressList == null) { |
Julian Lawrence | fa790f6 | 2016-01-07 17:18:30 -0800 | [diff] [blame] | 71 | mcastRouteManager.remove(mRoute); |
Pier Luigi | b29144d | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 72 | print(D_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source()); |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 73 | } else { |
| 74 | // check list for validity before we begin to delete. |
| 75 | for (String egress : egressList) { |
Julian Lawrence | fa790f6 | 2016-01-07 17:18:30 -0800 | [diff] [blame] | 76 | ConnectPoint eCp = ConnectPoint.deviceConnectPoint(egress); |
| 77 | mcastRouteManager.removeSink(mRoute, eCp); |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 78 | } |
Pier Luigi | b29144d | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 79 | print(U_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source()); |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 80 | } |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 81 | } |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 82 | } |