Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 8e57fd5 | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 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 | |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 17 | package org.opencord.cordvtn.cli; |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 22 | import org.opencord.cordvtn.api.CordVtnNode; |
| 23 | import org.opencord.cordvtn.impl.CordVtnNodeManager; |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 24 | import org.onosproject.net.Device; |
| 25 | import org.onosproject.net.device.DeviceService; |
| 26 | import org.onosproject.net.driver.DriverService; |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Checks detailed node init state. |
| 30 | */ |
| 31 | @Command(scope = "onos", name = "cordvtn-node-check", |
| 32 | description = "Shows detailed node init state") |
| 33 | public class CordVtnNodeCheckCommand extends AbstractShellCommand { |
| 34 | |
| 35 | @Argument(index = 0, name = "hostname", description = "Hostname", |
| 36 | required = true, multiValued = false) |
| 37 | private String hostname = null; |
| 38 | |
| 39 | @Override |
| 40 | protected void execute() { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 41 | CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class); |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 42 | DeviceService deviceService = AbstractShellCommand.get(DeviceService.class); |
| 43 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 44 | CordVtnNode node = nodeManager.getNodes() |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 45 | .stream() |
| 46 | .filter(n -> n.hostname().equals(hostname)) |
| 47 | .findFirst() |
| 48 | .orElse(null); |
| 49 | |
| 50 | if (node == null) { |
| 51 | print("Cannot find %s from registered nodes", hostname); |
| 52 | return; |
| 53 | } |
| 54 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 55 | print(nodeManager.checkNodeInitState(node)); |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 56 | |
| 57 | print("%n[DEBUG]"); |
| 58 | Device device = deviceService.getDevice(node.intBrId()); |
| 59 | String driver = get(DriverService.class).getDriver(device.id()).name(); |
| 60 | print("%s available=%s driver=%s %s", |
| 61 | device.id(), |
| 62 | deviceService.isAvailable(device.id()), |
| 63 | driver, |
| 64 | device.annotations()); |
| 65 | |
| 66 | deviceService.getPorts(node.intBrId()).forEach(port -> { |
| 67 | Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled"; |
| 68 | print("port=%s state=%s %s", |
| 69 | port.number(), |
| 70 | portIsEnabled, |
| 71 | port.annotations()); |
| 72 | }); |
Hyunsun Moon | de37257 | 2016-01-14 03:42:47 -0800 | [diff] [blame] | 73 | } |
| 74 | } |