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