CORD-247 Add host management network interface to integration bridge
- Node can have management network connectivity by adding "hostManagementIface"
field to the network config "nodes" block, it's optional field
- Added Builder of CordVtnNode
- Improved cordvtn-node-check result
- Some renamings, intBrId -> integrationBridgeId, dpIp -> dataIp,
dpIntf -> dataIface, and dpPort -> dataPort
Change-Id: I7a54edfb273181f0cb35b69fcfc7a448015734bf
diff --git a/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeCheckCommand.java b/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeCheckCommand.java
index 6d591b0..d0189e4 100644
--- a/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeCheckCommand.java
+++ b/src/main/java/org/opencord/cordvtn/cli/CordVtnNodeCheckCommand.java
@@ -16,14 +16,23 @@
package org.opencord.cordvtn.cli;
+import com.jcraft.jsch.Session;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
+import org.onlab.packet.IpAddress;
import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
import org.opencord.cordvtn.api.CordVtnNode;
import org.opencord.cordvtn.impl.CordVtnNodeManager;
import org.onosproject.net.Device;
import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.driver.DriverService;
+
+import java.util.Set;
+
+import static org.onosproject.net.AnnotationKeys.PORT_NAME;
+import static org.opencord.cordvtn.api.Constants.*;
+import static org.opencord.cordvtn.impl.RemoteIpCommandUtil.*;
/**
* Checks detailed node init state.
@@ -52,23 +61,74 @@
return;
}
- print(nodeManager.checkNodeInitState(node));
+ print("%n[Integration Bridge Status]");
+ Device device = deviceService.getDevice(node.integrationBridgeId());
+ if (device != null) {
+ print("%s %s=%s available=%s %s",
+ deviceService.isAvailable(device.id()) ? MSG_OK : MSG_NO,
+ INTEGRATION_BRIDGE,
+ device.id(),
+ deviceService.isAvailable(device.id()),
+ device.annotations());
- print("%n[DEBUG]");
- Device device = deviceService.getDevice(node.intBrId());
- String driver = get(DriverService.class).getDriver(device.id()).name();
- print("%s available=%s driver=%s %s",
- device.id(),
- deviceService.isAvailable(device.id()),
- driver,
- device.annotations());
+ node.systemIfaces().stream().forEach(iface -> print(
+ getPortState(deviceService, node.integrationBridgeId(), iface)));
+ } else {
+ print("%s %s=%s is not available",
+ MSG_NO,
+ INTEGRATION_BRIDGE,
+ node.integrationBridgeId());
+ }
- deviceService.getPorts(node.intBrId()).forEach(port -> {
- Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled";
- print("port=%s state=%s %s",
- port.number(),
- portIsEnabled,
- port.annotations());
- });
+ print("%n[Interfaces and IP setup]");
+ Session session = connect(node.sshInfo());
+ if (session != null) {
+ Set<IpAddress> ips = getCurrentIps(session, INTEGRATION_BRIDGE);
+ boolean isUp = isInterfaceUp(session, INTEGRATION_BRIDGE);
+ boolean isIp = ips.contains(node.dataIp().ip()) && ips.contains(node.localMgmtIp().ip());
+
+ print("%s %s up=%s Ips=%s",
+ isUp && isIp ? MSG_OK : MSG_NO,
+ INTEGRATION_BRIDGE,
+ isUp ? Boolean.TRUE : Boolean.FALSE,
+ getCurrentIps(session, INTEGRATION_BRIDGE));
+
+ print(getSystemIfaceState(session, node.dataIface()));
+ if (node.hostMgmtIface().isPresent()) {
+ print(getSystemIfaceState(session, node.hostMgmtIface().get()));
+ }
+
+ disconnect(session);
+ } else {
+ print("%s Unable to SSH to %s", MSG_NO, node.hostname());
+ }
+ }
+
+ private String getPortState(DeviceService deviceService, DeviceId deviceId, String portName) {
+ Port port = deviceService.getPorts(deviceId).stream()
+ .filter(p -> p.annotations().value(PORT_NAME).equals(portName) &&
+ p.isEnabled())
+ .findAny().orElse(null);
+
+ if (port != null) {
+ return String.format("%s %s portNum=%s enabled=%s %s",
+ port.isEnabled() ? MSG_OK : MSG_NO,
+ portName,
+ port.number(),
+ port.isEnabled() ? Boolean.TRUE : Boolean.FALSE,
+ port.annotations());
+ } else {
+ return String.format("%s %s does not exist", MSG_NO, portName);
+ }
+ }
+
+ private String getSystemIfaceState(Session session, String iface) {
+ boolean isUp = isInterfaceUp(session, iface);
+ boolean isIp = getCurrentIps(session, iface).isEmpty();
+ return String.format("%s %s up=%s IpFlushed=%s",
+ isUp && isIp ? MSG_OK : MSG_NO,
+ iface,
+ isUp ? Boolean.TRUE : Boolean.FALSE,
+ isIp ? Boolean.TRUE : Boolean.FALSE);
}
}