From 1fb4c42a5a1180c3e6498d913ebecbad0d68822f Mon Sep 17 00:00:00 2001 From: Pierantonio Merlino Date: Mon, 6 Nov 2023 13:34:56 +0100 Subject: [PATCH] feat(web2): IPv6 Network on Status tab (#4944) * Added ipv6 values on status tab Signed-off-by: pierantoniomerlino * Extracted constansts in Status tab class Signed-off-by: pierantoniomerlino * Changed Status page layout for network status Signed-off-by: pierantoniomerlino --------- Signed-off-by: pierantoniomerlino --- .../kura/web/server/GwtStatusServiceImpl.java | 352 ++++++++++++++---- 1 file changed, 272 insertions(+), 80 deletions(-) diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtStatusServiceImpl.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtStatusServiceImpl.java index c28cea9eb96..c6674605979 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtStatusServiceImpl.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtStatusServiceImpl.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import org.eclipse.kura.cloud.CloudService; import org.eclipse.kura.cloudconnection.CloudConnectionManager; @@ -61,21 +62,16 @@ public class GwtStatusServiceImpl extends OsgiRemoteServiceServlet implements GwtStatusService { private static final String IP_ACQUISITION = "IP Acquisition: "; - private static final String MODE = "Mode: "; - private static final String SUBNET_MASK = "Subnet Mask: "; - private static final String POSITION_STATUS = "positionStatus"; - private static final Logger logger = LoggerFactory.getLogger(GwtStatusServiceImpl.class); - private static final long serialVersionUID = 8256280782910423734L; - private static final String KURA_SERVICE_PID = ConfigurationService.KURA_SERVICE_PID; private static final String DATA_SERVICE_REFERENCE_NAME = "DataService"; private static final String DATA_TRANSPORT_SERVICE_REFERENCE_NAME = "DataTransportService"; - + private static final String NL = "
"; + private static final String TAB = "    "; private static final long NETWORK_INFO_REFRESH_TIMEOUT = 30000l; private static List networkStatus; @@ -267,10 +263,9 @@ private static List getNetworkStatus(boolean recompute) throws } List pairs = new ArrayList<>(); - String nl = "
"; - String tab = "    "; GwtNetworkServiceImplFacade gwtNetworkService = new GwtNetworkServiceImplFacade(); + boolean isNet2 = gwtNetworkService.isNet2(); List gwtNetInterfaceConfigs; @@ -285,87 +280,284 @@ private static List getNetworkStatus(boolean recompute) throws for (GwtNetInterfaceConfig gwtNetInterfaceConfig : gwtNetInterfaceConfigs) { - String currentAddress = gwtNetInterfaceConfig.getIpAddress(); - String currentSubnetMask = gwtNetInterfaceConfig.getSubnetMask(); + Optional statusGroup = getStatusGroup(gwtNetInterfaceConfig); + Optional statusName = getStatusName(gwtNetInterfaceConfig); + Optional statusValue = getStatusValue(gwtNetInterfaceConfig, isNet2); + + if (statusGroup.isPresent() && statusName.isPresent() && statusValue.isPresent()) { + pairs.add(new GwtGroupedNVPair(statusGroup.get(), statusName.get(), statusValue.get())); + } + + } + + networkStatus = pairs; + lastUpdate = System.currentTimeMillis(); + return networkStatus; + } + + private static Optional getStatusGroup(GwtNetInterfaceConfig gwtNetInterfaceConfig) { + if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.ETHERNET) { + return Optional.of("networkStatusEthernet"); + } else if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.WIFI) { + return Optional.of("networkStatusWifi"); + } else if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.MODEM) { + return Optional.of("networkStatusModem"); + } else { + return Optional.empty(); + } + } + + private static Optional getStatusName(GwtNetInterfaceConfig gwtNetInterfaceConfig) { + if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.ETHERNET + || gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.WIFI) { + return Optional.of(gwtNetInterfaceConfig.getName()); + } else if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.MODEM) { + String name = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getName(); + String interfaceName = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getInterfaceName(); + if (Objects.nonNull(interfaceName) && !interfaceName.isEmpty()) { + name = name + " (" + interfaceName + ")"; + } + return Optional.of(name); + } else { + return Optional.empty(); + } + } + + private static Optional getStatusValue(GwtNetInterfaceConfig gwtNetInterfaceConfig, boolean isNet2) { + StringBuilder sb = new StringBuilder(); + Optional statusIPv4 = getIPv4Status(gwtNetInterfaceConfig); + statusIPv4.ifPresent(sb::append); + + if (isNet2) { + Optional statusIPv6 = getIPv6Status(gwtNetInterfaceConfig, isNet2); + statusIPv6.ifPresent(status -> { + if (sb.length() != 0) { + sb.append(NL); + } + sb.append(status); + }); + } + + if (sb.length() == 0) { + return Optional.empty(); + } else { + return Optional.of(sb.toString()); + } + + } + + private static Optional getIPv4Status(GwtNetInterfaceConfig gwtNetInterfaceConfig) { + String currentAddress = gwtNetInterfaceConfig.getIpAddress(); + String currentSubnetMask = gwtNetInterfaceConfig.getSubnetMask(); + + String currentConfigMode; + if (gwtNetInterfaceConfig.getConfigModeEnum() == GwtNetIfConfigMode.netIPv4ConfigModeDHCP) { + currentConfigMode = "DHCP"; + } else { + currentConfigMode = "Manual"; + } + + String currentRouterMode; + if (gwtNetInterfaceConfig.getRouterModeEnum() == GwtNetRouterMode.netRouterDchp) { + currentRouterMode = "DHCPD"; + } else if (gwtNetInterfaceConfig.getRouterModeEnum() == GwtNetRouterMode.netRouterNat) { + currentRouterMode = "NAT"; + } else if (gwtNetInterfaceConfig.getRouterModeEnum() == GwtNetRouterMode.netRouterDchpNat) { + currentRouterMode = "DHCPD & NAT"; + } else { + currentRouterMode = ""; + } - String currentConfigMode; - if (gwtNetInterfaceConfig.getConfigModeEnum() == GwtNetIfConfigMode.netIPv4ConfigModeDHCP) { - currentConfigMode = "DHCP"; + StringBuilder sb = new StringBuilder(); + if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.ETHERNET) { + if (gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusDisabled + || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusUnmanaged + || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusL2Only) { + sb.append("IPv4").append(NL).append(TAB) + .append(gwtNetInterfaceConfig.getStatusEnum().getValue()); } else { - currentConfigMode = "Manual"; + sb.append("IPv4").append(NL) + .append(TAB).append(currentAddress).append(NL) + .append(TAB).append(TAB).append(SUBNET_MASK).append(currentSubnetMask).append(NL) + .append(TAB).append(TAB).append(MODE).append(gwtNetInterfaceConfig.getStatusEnum().getValue()) + .append(NL) + .append(TAB).append(TAB).append(IP_ACQUISITION).append(currentConfigMode).append(NL) + .append(TAB).append(TAB).append("Router Mode: ").append(currentRouterMode); + } + return Optional.of(sb.toString()); + } else if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.WIFI + && !gwtNetInterfaceConfig.getName().startsWith("mon")) { + String currentWifiMode = ((GwtWifiNetInterfaceConfig) gwtNetInterfaceConfig) + .getWirelessModeEnum() == GwtWifiWirelessMode.netWifiWirelessModeStation ? "Station Mode" + : "Access Point"; + GwtWifiConfig gwtActiveWifiConfig = ((GwtWifiNetInterfaceConfig) gwtNetInterfaceConfig) + .getActiveWifiConfig(); + String currentWifiSsid = null; + if (gwtActiveWifiConfig != null) { + currentWifiSsid = gwtActiveWifiConfig.getWirelessSsid(); + } + if (gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusDisabled + || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusUnmanaged + || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusL2Only) { + sb.append("IPv4").append(NL).append(TAB) + .append(gwtNetInterfaceConfig.getStatusEnum().getValue()); + } else { + sb.append("IPv4").append(NL) + .append(TAB).append(currentAddress).append(NL) + .append(TAB).append(TAB).append(SUBNET_MASK).append(currentSubnetMask).append(NL) + .append(TAB).append(TAB).append(MODE).append(gwtNetInterfaceConfig.getStatusEnum().getValue()) + .append(NL) + .append(TAB).append(TAB).append(IP_ACQUISITION).append(currentConfigMode).append(NL) + .append(TAB).append(TAB).append("Router Mode: ").append(currentRouterMode).append(NL) + .append(TAB).append(TAB).append("Wireless Mode:").append(currentWifiMode).append(NL) + .append(TAB).append(TAB).append("SSID: ").append(currentWifiSsid).append(NL); + } + return Optional.of(sb.toString()); + } else if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.MODEM) { + String currentModemApn = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getApn(); + String name = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getName(); + String interfaceName = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getInterfaceName(); + if (Objects.nonNull(interfaceName) && !interfaceName.isEmpty()) { + name = name + " (" + interfaceName + ")"; } + if (gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusDisabled + || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusUnmanaged + || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusL2Only) { + sb.append("IPv4").append(NL).append(TAB) + .append(gwtNetInterfaceConfig.getStatusEnum().getValue()); + } else { + sb.append("IPv4").append(NL) + .append(TAB).append(currentAddress).append(NL) + .append(TAB).append(TAB).append(SUBNET_MASK).append(currentSubnetMask) + .append(NL).append(TAB).append(TAB).append(MODE) + .append(gwtNetInterfaceConfig.getStatusEnum().getValue()).append(NL) + .append(TAB).append(TAB).append(IP_ACQUISITION) + .append(currentConfigMode).append(NL) + .append(TAB).append(TAB).append("APN: ").append(currentModemApn).append(NL) + .append(TAB).append(TAB).append("Interface: ").append(interfaceName); + } + return Optional.of(sb.toString()); + } else { + return Optional.empty(); + } + } - String currentRouterMode; - if (gwtNetInterfaceConfig.getRouterModeEnum() == GwtNetRouterMode.netRouterDchp) { - currentRouterMode = "DHCPD"; - } else if (gwtNetInterfaceConfig.getRouterModeEnum() == GwtNetRouterMode.netRouterNat) { - currentRouterMode = "NAT"; - } else if (gwtNetInterfaceConfig.getRouterModeEnum() == GwtNetRouterMode.netRouterDchpNat) { - currentRouterMode = "DHCPD & NAT"; + private static Optional getIPv6Status(GwtNetInterfaceConfig gwtNetInterfaceConfig, boolean isNet2) { + if (!isNet2) { + return Optional.empty(); + } + + String currentIPv6Address = gwtNetInterfaceConfig.getIpv6Address(); + String currentIPv6SubnetMask = String.valueOf(gwtNetInterfaceConfig.getIpv6SubnetMask()); + + String currentIPv6ConfigMode; + String currentIPv6ConfigModeString = gwtNetInterfaceConfig.getIpv6ConfigMode(); + if (Objects.nonNull(currentIPv6ConfigModeString)) { + if (gwtNetInterfaceConfig.getIpv6ConfigMode().equals("netIPv6MethodAuto")) { + currentIPv6ConfigMode = "Auto"; + } else if (currentIPv6ConfigModeString.equals("netIPv6MethodDhcp")) { + currentIPv6ConfigMode = "DHCP"; } else { - currentRouterMode = ""; + currentIPv6ConfigMode = "Manual"; } + } else { + currentIPv6ConfigMode = "Manual"; + } - if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.ETHERNET) { - if (gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusDisabled - || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusUnmanaged - || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusL2Only) { - pairs.add(new GwtGroupedNVPair("networkStatusEthernet", gwtNetInterfaceConfig.getName(), - gwtNetInterfaceConfig.getStatusEnum().getValue())); - } else { - pairs.add(new GwtGroupedNVPair("networkStatusEthernet", gwtNetInterfaceConfig.getName(), - currentAddress + nl + tab + SUBNET_MASK + currentSubnetMask + nl + tab + MODE - + gwtNetInterfaceConfig.getStatusEnum().getValue() + nl + tab + IP_ACQUISITION - + currentConfigMode + nl + tab + "Router Mode: " + currentRouterMode)); - } - } else if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.WIFI - && !gwtNetInterfaceConfig.getName().startsWith("mon")) { - String currentWifiMode = ((GwtWifiNetInterfaceConfig) gwtNetInterfaceConfig) - .getWirelessModeEnum() == GwtWifiWirelessMode.netWifiWirelessModeStation ? "Station Mode" - : "Access Point"; - GwtWifiConfig gwtActiveWifiConfig = ((GwtWifiNetInterfaceConfig) gwtNetInterfaceConfig) - .getActiveWifiConfig(); - String currentWifiSsid = null; - if (gwtActiveWifiConfig != null) { - currentWifiSsid = gwtActiveWifiConfig.getWirelessSsid(); - } - if (gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusDisabled - || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusUnmanaged - || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusL2Only) { - pairs.add(new GwtGroupedNVPair("networkStatusWifi", gwtNetInterfaceConfig.getName(), - gwtNetInterfaceConfig.getStatusEnum().getValue())); - } else { - pairs.add(new GwtGroupedNVPair("networkStatusWifi", gwtNetInterfaceConfig.getName(), - currentAddress + nl + tab + SUBNET_MASK + currentSubnetMask + nl + tab + MODE - + gwtNetInterfaceConfig.getStatusEnum().getValue() + nl + tab + IP_ACQUISITION - + currentConfigMode + nl + tab + "Router Mode: " + currentRouterMode + nl + tab - + "Wireless Mode:" + currentWifiMode + nl + tab + "SSID: " + currentWifiSsid + nl)); - } - } else if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.MODEM) { - String currentModemApn = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getApn(); - String name = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getName(); - String interfaceName = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getInterfaceName(); - if (Objects.nonNull(interfaceName) && !interfaceName.isEmpty()) { - name = name + " (" + interfaceName + ")"; - } - if (gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusDisabled - || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusUnmanaged - || gwtNetInterfaceConfig.getStatusEnum() == GwtNetIfStatus.netIPv4StatusL2Only) { - pairs.add(new GwtGroupedNVPair("networkStatusModem", name, - gwtNetInterfaceConfig.getStatusEnum().getValue())); - } else { - pairs.add(new GwtGroupedNVPair("networkStatusModem", name, - currentAddress + nl + SUBNET_MASK + currentSubnetMask + nl + tab + MODE - + gwtNetInterfaceConfig.getStatusEnum().getValue() + nl + tab + IP_ACQUISITION - + currentConfigMode + nl + tab + "APN: " + currentModemApn + nl + tab - + "Interface: " + interfaceName)); - } + String statusIPv6 = gwtNetInterfaceConfig.getIpv6Status(); + if (Objects.isNull(statusIPv6)) { + statusIPv6 = "netIPv6StatusDisabled"; + + } + + StringBuilder sb = new StringBuilder(); + if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.ETHERNET) { + if (statusIPv6.equals("netIPv6StatusDisabled") + || statusIPv6.equals("netIPv6StatusUnmanaged") + || statusIPv6.equals("netIPv6StatusL2Only")) { + sb.append("IPv6").append(NL).append(TAB) + .append(convertIPv6Status(statusIPv6)); + } else { + sb.append("IPv6").append(NL) + .append(TAB).append(currentIPv6Address).append(NL) + .append(TAB).append(TAB).append(SUBNET_MASK).append(currentIPv6SubnetMask).append(NL) + .append(TAB).append(TAB).append(MODE).append(convertIPv6Status(statusIPv6)).append(NL) + .append(TAB).append(TAB).append(IP_ACQUISITION).append(currentIPv6ConfigMode); + } + return Optional.of(sb.toString()); + } else if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.WIFI + && !gwtNetInterfaceConfig.getName().startsWith("mon")) { + String currentWifiMode = ((GwtWifiNetInterfaceConfig) gwtNetInterfaceConfig) + .getWirelessModeEnum() == GwtWifiWirelessMode.netWifiWirelessModeStation ? "Station Mode" + : "Access Point"; + GwtWifiConfig gwtActiveWifiConfig = ((GwtWifiNetInterfaceConfig) gwtNetInterfaceConfig) + .getActiveWifiConfig(); + String currentWifiSsid = null; + if (gwtActiveWifiConfig != null) { + currentWifiSsid = gwtActiveWifiConfig.getWirelessSsid(); + } + if (statusIPv6.equals("netIPv6StatusDisabled") + || statusIPv6.equals("netIPv6StatusUnmanaged") + || statusIPv6.equals("netIPv6StatusL2Only")) { + sb.append("IPv6").append(NL).append(TAB).append(convertIPv6Status(statusIPv6)); + } else { + sb.append("IPv6").append(NL) + .append(TAB).append(currentIPv6Address).append(NL) + .append(TAB).append(TAB).append(SUBNET_MASK).append(currentIPv6SubnetMask).append(NL) + .append(TAB).append(TAB).append(MODE).append(convertIPv6Status(statusIPv6)).append(NL) + .append(TAB).append(TAB).append(IP_ACQUISITION).append(currentIPv6ConfigMode).append(NL) + .append(TAB).append(TAB).append("Wireless Mode:").append(currentWifiMode).append(NL) + .append(TAB).append(TAB).append("SSID: ").append(currentWifiSsid).append(NL); + } + return Optional.of(sb.toString()); + } else if (gwtNetInterfaceConfig.getHwTypeEnum() == GwtNetIfType.MODEM) { + String currentModemApn = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getApn(); + String name = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getName(); + String interfaceName = ((GwtModemInterfaceConfig) gwtNetInterfaceConfig).getInterfaceName(); + if (Objects.nonNull(interfaceName) && !interfaceName.isEmpty()) { + name = name + " (" + interfaceName + ")"; + } + if (statusIPv6.equals("netIPv6StatusDisabled") + || statusIPv6.equals("netIPv6StatusUnmanaged") + || statusIPv6.equals("netIPv6StatusL2Only")) { + sb.append("IPv6").append(NL).append(TAB).append(convertIPv6Status(statusIPv6)); + } else { + sb.append("IPv6").append(NL) + .append(TAB).append(currentIPv6Address).append(NL) + .append(TAB).append(TAB).append(SUBNET_MASK).append(currentIPv6SubnetMask).append(NL) + .append(TAB).append(TAB).append(MODE).append(convertIPv6Status(statusIPv6)).append(NL) + .append(TAB).append(TAB).append(IP_ACQUISITION).append(currentIPv6ConfigMode).append(NL) + .append(TAB).append(TAB).append("APN: ").append(currentModemApn).append(NL) + .append(TAB).append(TAB).append("Interface: ").append(interfaceName); } + return Optional.of(sb.toString()); + } else { + return Optional.empty(); + } + + } + + private static String convertIPv6Status(String status) { + if (Objects.isNull(status)) { + return "netIPv6StatusDisabled"; + } + switch (status) { + case "netIPv6StatusDisabled": + return "Disabled"; + case "netIPv6StatusUnmanaged": + return "Unmanaged"; + case "netIPv6StatusL2Only": + return "L2Only"; + case "netIPv6StatusEnabledLAN": + return "LAN"; + case "netIPv6StatusEnabledWAN": + return "WAN"; + case "netIPv6StatusUnknown": + return "Unknown"; + default: + return "Unknown"; } - networkStatus = pairs; - lastUpdate = System.currentTimeMillis(); - return networkStatus; } private List getPositionStatus() throws GwtKuraException {