alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | */ |
| 16 | |
| 17 | package org.onosproject.olt.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.olt.AccessDeviceData; |
| 24 | import org.onosproject.olt.AccessDeviceService; |
| 25 | |
| 26 | import java.util.Map; |
| 27 | |
| 28 | /** |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame^] | 29 | * Shows configured OLTs. |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 30 | */ |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame^] | 31 | @Command(scope = "onos", name = "olts", |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 32 | description = "Shows configured OLTs") |
| 33 | public 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 | } |