| /* |
| * Copyright 2016-present Open Networking Foundation |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package org.onosproject.mcast.cli; |
| |
| import org.apache.karaf.shell.commands.Command; |
| import org.apache.karaf.shell.commands.Option; |
| import org.onlab.packet.IpAddress; |
| import org.onosproject.cli.AbstractShellCommand; |
| import org.onosproject.mcast.api.McastRoute; |
| import org.onosproject.mcast.api.MulticastRouteService; |
| import org.onosproject.net.ConnectPoint; |
| import org.onosproject.net.HostId; |
| |
| import java.util.Arrays; |
| import java.util.Set; |
| import java.util.stream.Collectors; |
| |
| /** |
| * Deletes a multicast route. |
| */ |
| @Command(scope = "onos", name = "mcast-host-delete", |
| description = "Delete a multicast route flow") |
| public class McastHostDeleteCommand extends AbstractShellCommand { |
| |
| // Delete format for group line |
| private static final String D_FORMAT_MAPPING = "Deleted the mcast route: " + |
| "origin=%s, group=%s, source=%s"; |
| |
| // Update format for group line |
| private static final String U_FORMAT_MAPPING = "Updated the mcast route: " + |
| "origin=%s, group=%s, source=%s"; |
| |
| @Option(name = "-sAddr", aliases = "--sourceAddress", |
| description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry", |
| valueToShowInHelp = "1.1.1.1", |
| required = true, multiValued = false) |
| String sAddr = null; |
| |
| @Option(name = "-gAddr", aliases = "--groupAddress", |
| description = "IP Address of the multicast group", |
| valueToShowInHelp = "224.0.0.0", |
| required = true, multiValued = false) |
| String gAddr = null; |
| |
| @Option(name = "-h", aliases = "--host", |
| description = "Host sink format: MAC/VLAN", |
| valueToShowInHelp = "00:00:00:00:00:00/None") |
| String host = null; |
| |
| @Option(name = "-cps", aliases = "--connectPoint", |
| description = "Egress port of:XXXXXXXXXX/XX", |
| valueToShowInHelp = "of:0000000000000001/1", |
| multiValued = true) |
| String[] egressList = null; |
| |
| |
| @Override |
| protected void execute() { |
| MulticastRouteService mcastRouteManager = get(MulticastRouteService.class); |
| |
| if ("*".equals(sAddr) && "*".equals(gAddr)) { |
| // Clear all routes |
| mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove); |
| return; |
| } |
| if (host != null && host.isEmpty()) { |
| print("Please provide a non-empty host Id"); |
| return; |
| } |
| print("%s", host); |
| HostId hostId = HostId.hostId(host); |
| McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr), |
| IpAddress.valueOf(gAddr), McastRoute.Type.STATIC); |
| if (!mcastRouteManager.getRoutes().contains(mRoute)) { |
| print("Route is not present, store it first"); |
| print(U_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source()); |
| return; |
| } |
| if (host != null && egressList != null) { |
| Set<ConnectPoint> sinksSet = Arrays.stream(egressList) |
| .map(ConnectPoint::deviceConnectPoint) |
| .collect(Collectors.toSet()); |
| mcastRouteManager.removeSinks(mRoute, hostId, sinksSet); |
| } else if (host != null) { |
| mcastRouteManager.removeSink(mRoute, hostId); |
| } |
| print(U_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source()); |
| print("%s", mcastRouteManager.routeData(mRoute)); |
| } |
| } |