blob: f0dc33eb324f4865343162a85b1756f98e36c190 [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
Madan Jampanic27b6b22016-02-05 11:36:31 -080018import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Jonathan Hart1d006392016-02-11 09:12:56 -080020import org.onlab.packet.IpAddress;
Madan Jampanic27b6b22016-02-05 11:36:31 -080021import org.onosproject.cli.AbstractShellCommand;
Madan Jampanic27b6b22016-02-05 11:36:31 -080022import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.mcast.McastRoute;
24import 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")
31public class McastJoinCommand extends AbstractShellCommand {
32
Madan Jampanic27b6b22016-02-05 11:36:31 -080033 @Argument(index = 0, name = "sAddr",
34 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
35 required = true, multiValued = false)
36 String sAddr = null;
37
38 @Argument(index = 1, name = "gAddr",
39 description = "IP Address of the multicast group",
40 required = true, multiValued = false)
41 String gAddr = null;
42
43 @Argument(index = 2, name = "ingressPort",
44 description = "Ingress port of:XXXXXXXXXX/XX",
45 required = false, multiValued = false)
46 String ingressPort = null;
47
48 @Argument(index = 3, name = "ports",
49 description = "Egress ports of:XXXXXXXXXX/XX...",
50 required = false, multiValued = true)
51 String[] ports = null;
52
53 @Override
54 protected void execute() {
Jonathan Hart1d006392016-02-11 09:12:56 -080055 MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
Madan Jampanic27b6b22016-02-05 11:36:31 -080056
Jonathan Hart1d006392016-02-11 09:12:56 -080057 //McastRoute mRoute = McastForwarding.createStaticRoute(sAddr, gAddr);
58 McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr),
59 IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
Madan Jampanic27b6b22016-02-05 11:36:31 -080060 mcastRouteManager.add(mRoute);
61
Jonathan Hart1d006392016-02-11 09:12:56 -080062 if (ingressPort != null) {
63 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressPort);
64 mcastRouteManager.addSource(mRoute, ingress);
Madan Jampanic27b6b22016-02-05 11:36:31 -080065 }
Jonathan Hart1d006392016-02-11 09:12:56 -080066
67 if (ports != null) {
68 for (String egCP : ports) {
69 log.debug("Egress port provided: " + egCP);
70 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egCP);
71 mcastRouteManager.addSink(mRoute, egress);
72
73 }
74 }
75 print("Added the mcast route: %s", mRoute);
Madan Jampanic27b6b22016-02-05 11:36:31 -080076 }
77}