blob: 0d07683d6bdcb639f32550e74b136c2d9f20e80e [file] [log] [blame]
alshabibe0559672016-02-21 14:49:51 -08001/*
Brian O'Connord6a135a2017-08-03 22:46:05 -07002 * Copyright 2016-present Open Networking Foundation
alshabibe0559672016-02-21 14:49:51 -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 */
16
alshabib36a4d732016-06-01 16:03:59 -070017package org.opencord.olt.cli;
alshabibe0559672016-02-21 14:49:51 -080018
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.DeviceId;
alshabibf3a573e2016-06-01 17:39:10 -070023import org.opencord.cordconfig.access.AccessDeviceData;
alshabib36a4d732016-06-01 16:03:59 -070024import org.opencord.olt.AccessDeviceService;
alshabibe0559672016-02-21 14:49:51 -080025
26import java.util.Map;
27
28/**
Jonathan Hartfd6c1b32016-03-08 14:09:09 -080029 * Shows configured OLTs.
alshabibe0559672016-02-21 14:49:51 -080030 */
Jonathan Hartfd6c1b32016-03-08 14:09:09 -080031@Command(scope = "onos", name = "olts",
alshabibe0559672016-02-21 14:49:51 -080032 description = "Shows configured OLTs")
33public class ShowOltCommand extends AbstractShellCommand {
34
35 @Argument(index = 0, name = "deviceId", description = "Access device ID",
36 required = false, multiValued = false)
37 private String strDeviceId = null;
38
39 @Override
40 protected void execute() {
41 AccessDeviceService service = AbstractShellCommand.get(AccessDeviceService.class);
42 Map<DeviceId, AccessDeviceData> data = service.fetchOlts();
43 if (strDeviceId != null) {
44 DeviceId deviceId = DeviceId.deviceId(strDeviceId);
45 print("OLT %s:", deviceId);
46 display(data.get(deviceId));
47 } else {
48 data.keySet().forEach(did -> {
49 print("OLT %s:", did);
50 display(data.get(did));
51 });
52 }
53 }
54
55 private void display(AccessDeviceData accessDeviceData) {
56 print("\tvlan : %s", accessDeviceData.vlan());
57 print("\tuplink : %s", accessDeviceData.uplink());
58 }
59}