blob: 3f22e7afb58f58f7e6205d91ba984294d0b914fb [file] [log] [blame]
alshabibeff00542015-09-23 13:22:33 -07001/*
2 * Copyright 2014-2015 Open Networking Laboratory
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 */
16package org.onosproject.mfwd.cli;
17
Julian Lawrencefa790f62016-01-07 17:18:30 -080018import org.apache.felix.scr.annotations.Reference;
19import org.apache.felix.scr.annotations.ReferenceCardinality;
alshabibeff00542015-09-23 13:22:33 -070020import org.apache.karaf.shell.commands.Argument;
21import org.apache.karaf.shell.commands.Command;
alshabibeff00542015-09-23 13:22:33 -070022import org.onosproject.cli.AbstractShellCommand;
Julian Lawrencefa790f62016-01-07 17:18:30 -080023import org.onosproject.mfwd.impl.McastForwarding;
24import org.onosproject.net.ConnectPoint;
25import org.onosproject.net.mcast.McastRoute;
26import org.onosproject.net.mcast.MulticastRouteService;
alshabibeff00542015-09-23 13:22:33 -070027
28/**
29 * Installs a source, multicast group flow.
30 */
31@Command(scope = "onos", name = "mcast-join",
32 description = "Installs a source, multicast group flow")
33public class McastJoinCommand extends AbstractShellCommand {
34
Julian Lawrencefa790f62016-01-07 17:18:30 -080035 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
36 MulticastRouteService mcastRouteManager = AbstractShellCommand.get(MulticastRouteService.class);
37
alshabibeff00542015-09-23 13:22:33 -070038 @Argument(index = 0, name = "sAddr",
39 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
40 required = true, multiValued = false)
41 String sAddr = null;
42
43 @Argument(index = 1, name = "gAddr",
44 description = "IP Address of the multicast group",
45 required = true, multiValued = false)
46 String gAddr = null;
47
48 @Argument(index = 2, name = "ingressPort",
Julian Lawrencefa790f62016-01-07 17:18:30 -080049 description = "Ingress port of:XXXXXXXXXX/XX",
alshabibeff00542015-09-23 13:22:33 -070050 required = false, multiValued = false)
51 String ingressPort = null;
52
53 @Argument(index = 3, name = "ports",
Julian Lawrencefa790f62016-01-07 17:18:30 -080054 description = "Egress ports of:XXXXXXXXXX/XX...",
alshabibeff00542015-09-23 13:22:33 -070055 required = false, multiValued = true)
56 String[] ports = null;
57
58 @Override
59 protected void execute() {
alshabibeff00542015-09-23 13:22:33 -070060
Julian Lawrencefa790f62016-01-07 17:18:30 -080061 McastRoute mRoute = McastForwarding.createStaticRoute(sAddr, gAddr);
62 mcastRouteManager.add(mRoute);
alshabibeff00542015-09-23 13:22:33 -070063
Julian Lawrencefa790f62016-01-07 17:18:30 -080064 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressPort);
65 mcastRouteManager.addSource(mRoute, ingress);
66
67 for (String egCP : ports) {
alshabibeff00542015-09-23 13:22:33 -070068 log.debug("Egress port provided: " + egCP);
Julian Lawrencefa790f62016-01-07 17:18:30 -080069 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egCP);
70 mcastRouteManager.addSink(mRoute, egress);
71
alshabibeff00542015-09-23 13:22:33 -070072 }
73 print("Added the mcast route");
74 }
75}