blob: e0d804740860ef179fd16cda5936fdfabf43018b [file] [log] [blame]
Madan Jampanic27b6b22016-02-05 11:36:31 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Madan Jampanic27b6b22016-02-05 11:36:31 -08003 *
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 Hart1d006392016-02-11 09:12:56 -080016package org.onosproject.cli.net;
Madan Jampanic27b6b22016-02-05 11:36:31 -080017
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkey0068fd02018-10-11 15:45:39 -070020import org.apache.karaf.shell.api.action.Completion;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Jonathan Hart1d006392016-02-11 09:12:56 -080022import org.onlab.packet.IpAddress;
Madan Jampanic27b6b22016-02-05 11:36:31 -080023import org.onosproject.cli.AbstractShellCommand;
Ray Milkey0068fd02018-10-11 15:45:39 -070024import org.onosproject.cli.PlaceholderCompleter;
Madan Jampanic27b6b22016-02-05 11:36:31 -080025import org.onosproject.net.ConnectPoint;
26import org.onosproject.net.mcast.McastRoute;
27import org.onosproject.net.mcast.MulticastRouteService;
28
29/**
30 * Installs a source, multicast group flow.
31 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070032@Service
Madan Jampanic27b6b22016-02-05 11:36:31 -080033@Command(scope = "onos", name = "mcast-join",
34 description = "Installs a source, multicast group flow")
35public class McastJoinCommand extends AbstractShellCommand {
36
Pier Luigib29144d2018-01-15 18:06:43 +010037 // Format for group line
38 private static final String FORMAT_MAPPING = "Added the mcast route: " +
39 "origin=%s, group=%s, source=%s";
40
Madan Jampanic27b6b22016-02-05 11:36:31 -080041 @Argument(index = 0, name = "sAddr",
42 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
43 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070044 @Completion(PlaceholderCompleter.class)
Madan Jampanic27b6b22016-02-05 11:36:31 -080045 String sAddr = null;
46
47 @Argument(index = 1, name = "gAddr",
48 description = "IP Address of the multicast group",
49 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070050 @Completion(McastGroupCompleter.class)
Madan Jampanic27b6b22016-02-05 11:36:31 -080051 String gAddr = null;
52
53 @Argument(index = 2, name = "ingressPort",
54 description = "Ingress port of:XXXXXXXXXX/XX",
55 required = false, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070056 @Completion(ConnectPointCompleter.class)
Madan Jampanic27b6b22016-02-05 11:36:31 -080057 String ingressPort = null;
58
59 @Argument(index = 3, name = "ports",
60 description = "Egress ports of:XXXXXXXXXX/XX...",
61 required = false, multiValued = true)
62 String[] ports = null;
63
64 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070065 protected void doExecute() {
Jonathan Hart1d006392016-02-11 09:12:56 -080066 MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
Madan Jampanic27b6b22016-02-05 11:36:31 -080067
Jonathan Hart1d006392016-02-11 09:12:56 -080068 McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr),
69 IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
Madan Jampanic27b6b22016-02-05 11:36:31 -080070 mcastRouteManager.add(mRoute);
71
Jonathan Hart1d006392016-02-11 09:12:56 -080072 if (ingressPort != null) {
73 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressPort);
74 mcastRouteManager.addSource(mRoute, ingress);
Madan Jampanic27b6b22016-02-05 11:36:31 -080075 }
Jonathan Hart1d006392016-02-11 09:12:56 -080076
77 if (ports != null) {
78 for (String egCP : ports) {
Jonathan Hart1d006392016-02-11 09:12:56 -080079 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egCP);
80 mcastRouteManager.addSink(mRoute, egress);
81
82 }
83 }
Pier Luigib29144d2018-01-15 18:06:43 +010084 printMcastRoute(mRoute);
85 }
86
87 private void printMcastRoute(McastRoute mcastRoute) {
88 print(FORMAT_MAPPING, mcastRoute.type(), mcastRoute.group(), mcastRoute.source());
Madan Jampanic27b6b22016-02-05 11:36:31 -080089 }
90}