Search in sources :

Example 1 with IPv6Host

use of com.cisco.trex.stl.gui.models.IPv6Host in project trex-stateless-gui by cisco-system-traffic-generator.

the class PortLayerConfiguration method handleStartIPv6Scan.

private void handleStartIPv6Scan(ActionEvent actionEvent) {
    LogsController.getInstance().appendText(LogType.INFO, "Start scanning IPv6 neighbor hosts.");
    AsyncResponseManager.getInstance().muteLogger();
    AsyncResponseManager.getInstance().suppressIncomingEvents(true);
    boolean multicastEnabled = model.getMulticast();
    if (!multicastEnabled) {
        model.multicastProperty().setValue(true);
    }
    getIPv6NDService();
    startScanIpv6Btn.setDisable(true);
    ipv6Hosts.getItems().clear();
    ipv6Hosts.setPlaceholder(new Label("Scanning in progress..."));
    Task<Optional<Map<String, Ipv6Node>>> scanIpv6NeighborsTask = new Task<Optional<Map<String, Ipv6Node>>>() {

        @Override
        public Optional<Map<String, Ipv6Node>> call() {
            try {
                return Optional.of(iPv6NDService.scan(model.getIndex(), 10, null, null));
            } catch (ServiceModeRequiredException e) {
                AsyncResponseManager.getInstance().unmuteLogger();
                AsyncResponseManager.getInstance().suppressIncomingEvents(false);
                Platform.runLater(() -> {
                    ipv6Hosts.setPlaceholder(ipv6HostsDefaultPlaceholder);
                    LogsController.getInstance().appendText(LogType.ERROR, "Service mode is not enabled for port: " + model.getIndex() + ". Enable Service Mode in Control tab.");
                });
            }
            return Optional.empty();
        }
    };
    scanIpv6NeighborsTask.setOnSucceeded(e -> {
        AsyncResponseManager.getInstance().unmuteLogger();
        AsyncResponseManager.getInstance().suppressIncomingEvents(false);
        startScanIpv6Btn.setDisable(false);
        Optional<Map<String, Ipv6Node>> result = scanIpv6NeighborsTask.getValue();
        result.ifPresent((hosts) -> {
            ipv6Hosts.getItems().addAll(hosts.entrySet().stream().map(entry -> new IPv6Host(entry.getValue().getMac(), entry.getValue().getIp())).collect(Collectors.toList()));
            if (hosts.isEmpty()) {
                ipv6Hosts.setPlaceholder(ipv6HostsNotFoundPlaceholder);
            }
            LogsController.getInstance().appendText(LogType.INFO, "Found " + hosts.size() + " nodes.");
            LogsController.getInstance().appendText(LogType.INFO, "Scanning complete.");
        });
        if (!multicastEnabled) {
            model.multicastProperty().setValue(false);
        }
    });
    executorService.submit(scanIpv6NeighborsTask);
}
Also used : Ipv6Node(com.cisco.trex.stateless.model.Ipv6Node) IPv6Host(com.cisco.trex.stl.gui.models.IPv6Host) Task(javafx.concurrent.Task) ServiceModeRequiredException(com.cisco.trex.stateless.exception.ServiceModeRequiredException)

Aggregations

ServiceModeRequiredException (com.cisco.trex.stateless.exception.ServiceModeRequiredException)1 Ipv6Node (com.cisco.trex.stateless.model.Ipv6Node)1 IPv6Host (com.cisco.trex.stl.gui.models.IPv6Host)1 Task (javafx.concurrent.Task)1