blob: 2a1a3c66437988712aecfde68514631306d656a2 [file] [log] [blame]
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07001/*
2 * Copyright 2021-present Open Networking Foundation
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 */
16
17package org.opencord.olt.cli;
18
19import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.Completion;
22import org.apache.karaf.shell.api.action.lifecycle.Service;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.cli.net.DeviceIdCompleter;
25import org.onosproject.net.ConnectPoint;
26import org.onosproject.net.DeviceId;
27import org.onosproject.net.PortNumber;
28import org.onosproject.net.device.DeviceService;
29import org.opencord.olt.AccessDeviceService;
30
31/**
32 * Adds a subscriber to an access device.
33 */
34@Service
35@Command(scope = "onos", name = "volt-add-all-subscriber-access",
36 description = "Adds a subscriber to an access device")
37public class SubscriberAddAllCommand extends AbstractShellCommand {
38
39 @Argument(index = 0, name = "deviceId", description = "Access device ID",
40 required = true, multiValued = false)
41 @Completion(DeviceIdCompleter.class)
42 private String strDeviceId = null;
43
44 @Override
45 protected void doExecute() {
46 AccessDeviceService service = AbstractShellCommand.get(AccessDeviceService.class);
47 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
48 DeviceId deviceId = DeviceId.deviceId(strDeviceId);
49
50 deviceService.getPorts(deviceId).forEach(p -> {
51 if (p.isEnabled()) {
52 PortNumber port = p.number();
53 ConnectPoint connectPoint = new ConnectPoint(deviceId, port);
54 service.provisionSubscriber(connectPoint);
55 }
56 });
57 }
58}