alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
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 | |
| 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 Hart | 9ad777f | 2016-02-19 12:44:36 -0800 | [diff] [blame] | 39 | 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] | 40 | required = true, multiValued = false) |
| 41 | String gAddr = null; |
| 42 | |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 43 | @Argument(index = 2, name = "egressList", |
| 44 | description = "Egress id/port", |
| 45 | required = false, multiValued = true) |
| 46 | String[] egressList = null; |
| 47 | |
| 48 | |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 49 | @Override |
| 50 | protected void execute() { |
Jonathan Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 51 | MulticastRouteService mcastRouteManager = get(MulticastRouteService.class); |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 52 | |
Jonathan Hart | 9ad777f | 2016-02-19 12:44:36 -0800 | [diff] [blame] | 53 | if (sAddr.equals("*") && gAddr.equals("*")) { |
| 54 | // Clear all routes |
| 55 | mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove); |
| 56 | return; |
| 57 | } |
| 58 | |
Jonathan Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 59 | McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr), |
| 60 | IpAddress.valueOf(gAddr), McastRoute.Type.STATIC); |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 61 | |
| 62 | if (egressList == null) { |
Julian Lawrence | fa790f6 | 2016-01-07 17:18:30 -0800 | [diff] [blame] | 63 | mcastRouteManager.remove(mRoute); |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 64 | } else { |
| 65 | // check list for validity before we begin to delete. |
| 66 | for (String egress : egressList) { |
Julian Lawrence | fa790f6 | 2016-01-07 17:18:30 -0800 | [diff] [blame] | 67 | ConnectPoint eCp = ConnectPoint.deviceConnectPoint(egress); |
| 68 | mcastRouteManager.removeSink(mRoute, eCp); |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 69 | } |
| 70 | } |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 71 | } |
Julian Lawrence | 14c7318 | 2015-10-08 18:31:52 -0700 | [diff] [blame] | 72 | } |