blob: 6d591b0f982042cf5291431c57bb1b6a513be33d [file] [log] [blame]
Hyunsun Moonde372572016-01-14 03:42:47 -08001/*
Brian O'Connor8e57fd52016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Hyunsun Moonde372572016-01-14 03:42:47 -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
alshabibb4d31712016-06-01 18:51:03 -070017package org.opencord.cordvtn.cli;
Hyunsun Moonde372572016-01-14 03:42:47 -080018
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
alshabibb4d31712016-06-01 18:51:03 -070022import org.opencord.cordvtn.api.CordVtnNode;
23import org.opencord.cordvtn.impl.CordVtnNodeManager;
Hyunsun Moon479b7752016-05-06 20:13:28 -070024import org.onosproject.net.Device;
25import org.onosproject.net.device.DeviceService;
Hyunsun Moon0592c3d2016-06-23 14:47:52 -070026import org.onosproject.net.driver.DriverService;
Hyunsun Moonde372572016-01-14 03:42:47 -080027
28/**
29 * Checks detailed node init state.
30 */
31@Command(scope = "onos", name = "cordvtn-node-check",
32 description = "Shows detailed node init state")
33public 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 Mooncb799442016-01-15 20:03:18 -080041 CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class);
Hyunsun Moon479b7752016-05-06 20:13:28 -070042 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
43
Hyunsun Mooncb799442016-01-15 20:03:18 -080044 CordVtnNode node = nodeManager.getNodes()
Hyunsun Moonde372572016-01-14 03:42:47 -080045 .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 Moon0592c3d2016-06-23 14:47:52 -070055 print(nodeManager.checkNodeInitState(node));
Hyunsun Moon479b7752016-05-06 20:13:28 -070056
Hyunsun Moon0592c3d2016-06-23 14:47:52 -070057 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());
Hyunsun Moon479b7752016-05-06 20:13:28 -070065
Hyunsun Moon0592c3d2016-06-23 14:47:52 -070066 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 Moonde372572016-01-14 03:42:47 -080073 }
74}