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