Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [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; |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 17 | |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 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; |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 22 | import org.onosproject.net.ConnectPoint; |
| 23 | import org.onosproject.net.mcast.McastRoute; |
| 24 | import org.onosproject.net.mcast.MulticastRouteService; |
| 25 | |
| 26 | /** |
| 27 | * Installs a source, multicast group flow. |
| 28 | */ |
| 29 | @Command(scope = "onos", name = "mcast-join", |
| 30 | description = "Installs a source, multicast group flow") |
| 31 | public class McastJoinCommand extends AbstractShellCommand { |
| 32 | |
Pier Luigi | b29144d | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 33 | // Format for group line |
| 34 | private static final String FORMAT_MAPPING = "Added the mcast route: " + |
| 35 | "origin=%s, group=%s, source=%s"; |
| 36 | |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 37 | @Argument(index = 0, name = "sAddr", |
| 38 | description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry", |
| 39 | required = true, multiValued = false) |
| 40 | String sAddr = null; |
| 41 | |
| 42 | @Argument(index = 1, name = "gAddr", |
| 43 | description = "IP Address of the multicast group", |
| 44 | required = true, multiValued = false) |
| 45 | String gAddr = null; |
| 46 | |
| 47 | @Argument(index = 2, name = "ingressPort", |
| 48 | description = "Ingress port of:XXXXXXXXXX/XX", |
| 49 | required = false, multiValued = false) |
| 50 | String ingressPort = null; |
| 51 | |
| 52 | @Argument(index = 3, name = "ports", |
| 53 | description = "Egress ports of:XXXXXXXXXX/XX...", |
| 54 | required = false, multiValued = true) |
| 55 | String[] ports = null; |
| 56 | |
| 57 | @Override |
| 58 | protected void execute() { |
Jonathan Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 59 | MulticastRouteService mcastRouteManager = get(MulticastRouteService.class); |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 60 | |
Jonathan Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 61 | McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr), |
| 62 | IpAddress.valueOf(gAddr), McastRoute.Type.STATIC); |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 63 | mcastRouteManager.add(mRoute); |
| 64 | |
Jonathan Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 65 | if (ingressPort != null) { |
| 66 | ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressPort); |
| 67 | mcastRouteManager.addSource(mRoute, ingress); |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 68 | } |
Jonathan Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 69 | |
| 70 | if (ports != null) { |
| 71 | for (String egCP : ports) { |
Jonathan Hart | 1d00639 | 2016-02-11 09:12:56 -0800 | [diff] [blame] | 72 | ConnectPoint egress = ConnectPoint.deviceConnectPoint(egCP); |
| 73 | mcastRouteManager.addSink(mRoute, egress); |
| 74 | |
| 75 | } |
| 76 | } |
Pier Luigi | b29144d | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 77 | printMcastRoute(mRoute); |
| 78 | } |
| 79 | |
| 80 | private void printMcastRoute(McastRoute mcastRoute) { |
| 81 | print(FORMAT_MAPPING, mcastRoute.type(), mcastRoute.group(), mcastRoute.source()); |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 82 | } |
| 83 | } |