diff --git a/corefx/src/main/java/com/core/Controller.java b/corefx/src/main/java/com/core/Controller.java index a203ec61..5eb9d2ff 100644 --- a/corefx/src/main/java/com/core/Controller.java +++ b/corefx/src/main/java/com/core/Controller.java @@ -170,7 +170,7 @@ public class Controller implements Initializable { Platform.runLater(() -> decorator.setTitle(String.format("CORE (Session %s)", sessionId))); } - public boolean startSession() throws IOException { + public boolean startSession() { // force nodes to get latest positions networkGraph.updatePositions(); @@ -180,12 +180,18 @@ public class Controller implements Initializable { List hooks = hooksDialog.getHooks(); // start/create session + boolean result = false; progressBar.setVisible(true); - boolean result = coreClient.start(nodes, links, hooks); - progressBar.setVisible(false); - if (result) { - showMobilityScriptDialogs(); - saveXmlMenuItem.setDisable(false); + try { + result = coreClient.start(nodes, links, hooks); + if (result) { + showMobilityScriptDialogs(); + saveXmlMenuItem.setDisable(false); + } + } catch (IOException ex) { + Toast.error("Failure Starting Session", ex); + } finally { + progressBar.setVisible(false); } return result; } diff --git a/corefx/src/main/java/com/core/data/NodeType.java b/corefx/src/main/java/com/core/data/NodeType.java index f8276a6d..e9743ea8 100644 --- a/corefx/src/main/java/com/core/data/NodeType.java +++ b/corefx/src/main/java/com/core/data/NodeType.java @@ -20,6 +20,7 @@ public class NodeType { public static final int SWITCH = 4; public static final int HUB = 5; public static final int WLAN = 6; + public static final int RJ45 = 7; public static final int EMANE = 10; public static final int DOCKER = 15; public static final int LXC = 16; @@ -35,9 +36,10 @@ public class NodeType { add(new NodeType(SWITCH, "lanswitch", "Switch", "/icons/switch-100.png")); add(new NodeType(HUB, "hub", "Hub", "/icons/hub-100.png")); add(new NodeType(WLAN, "wlan", "WLAN", "/icons/wlan-100.png")); + add(new NodeType(RJ45, "rj45", "RJ45", "/icons/rj45-80.png")); add(new NodeType(EMANE, "wlan", "EMANE", "/icons/emane-100.png")); - add(new NodeType(NodeType.DOCKER, null, "DockerNode", "/icons/dockernode-100.png")); - add(new NodeType(NodeType.LXC, null, "LxcNode", "/icons/lxcnode-100.png")); + add(new NodeType(DOCKER, null, "DockerNode", "/icons/dockernode-100.png")); + add(new NodeType(LXC, null, "LxcNode", "/icons/lxcnode-100.png")); } diff --git a/corefx/src/main/java/com/core/graph/CorePopupGraphMousePlugin.java b/corefx/src/main/java/com/core/graph/CorePopupGraphMousePlugin.java index b41af0d2..bd46f4c3 100644 --- a/corefx/src/main/java/com/core/graph/CorePopupGraphMousePlugin.java +++ b/corefx/src/main/java/com/core/graph/CorePopupGraphMousePlugin.java @@ -70,6 +70,9 @@ public class CorePopupGraphMousePlugin extends EditingPopupGraphMousePlugi case NodeType.EMANE: contextMenu = new EmaneContextMenu(controller, node); break; + case NodeType.RJ45: + contextMenu = new Rj45ContextMenu(controller, node); + break; default: logger.warn("no context menu for node: {}", node.getType()); break; diff --git a/corefx/src/main/java/com/core/graph/Rj45ContextMenu.java b/corefx/src/main/java/com/core/graph/Rj45ContextMenu.java new file mode 100644 index 00000000..3d0da724 --- /dev/null +++ b/corefx/src/main/java/com/core/graph/Rj45ContextMenu.java @@ -0,0 +1,21 @@ +package com.core.graph; + +import com.core.Controller; +import com.core.data.CoreNode; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +class Rj45ContextMenu extends AbstractNodeContextMenu { + private static final Logger logger = LogManager.getLogger(); + + Rj45ContextMenu(Controller controller, CoreNode coreNode) { + super(controller, coreNode); + setup(); + } + + private void setup() { + if (!controller.getCoreClient().isRunning()) { + addMenuItem("Delete Node", event -> controller.deleteNode(coreNode)); + } + } +} diff --git a/corefx/src/main/java/com/core/ui/GraphToolbar.java b/corefx/src/main/java/com/core/ui/GraphToolbar.java index 8a404213..651e0b0f 100644 --- a/corefx/src/main/java/com/core/ui/GraphToolbar.java +++ b/corefx/src/main/java/com/core/ui/GraphToolbar.java @@ -167,6 +167,7 @@ public class GraphToolbar extends VBox { addNodeType(NodeType.SWITCH, "lanswitch", devicesList); addNodeType(NodeType.WLAN, "wlan", devicesList); addNodeType(NodeType.EMANE, "wlan", devicesList); + addNodeType(NodeType.RJ45, "rj45", devicesList); devicesList.getSelectionModel().selectFirst(); updateButtonValues(devicesButton, devicesList.getSelectionModel().getSelectedItem()); setupButtonSelection("Network Nodes", devicesButton, devicesList); @@ -237,15 +238,11 @@ public class GraphToolbar extends VBox { private void startSession() { runButton.setDisable(true); new Thread(() -> { - try { - boolean result = controller.startSession(); - if (result) { - Toast.success("Session Started"); - setRunButton(true); - } - } catch (IOException ex) { - Toast.error("Failure Starting Session", ex); + boolean result = controller.startSession(); + if (result) { + Toast.success("Session Started"); } + setRunButton(result); }).start(); } diff --git a/corefx/src/main/java/com/core/ui/NodeDetails.java b/corefx/src/main/java/com/core/ui/NodeDetails.java index 55816568..e2ad3bbd 100644 --- a/corefx/src/main/java/com/core/ui/NodeDetails.java +++ b/corefx/src/main/java/com/core/ui/NodeDetails.java @@ -43,6 +43,8 @@ public class NodeDetails extends ScrollPane { public void setNode(CoreNode node) { clear(); + boolean sessionRunning = controller.getCoreClient().isRunning(); + title.setText(node.getName()); addSeparator(); @@ -54,15 +56,18 @@ public class NodeDetails extends ScrollPane { addRow("Type", node.getNodeType().getDisplay(), true); } addRow("EMANE", node.getEmane(), true); - addRow("Image", node.getImage(), true); addRow("X", node.getPosition().getX().toString(), true); addRow("Y", node.getPosition().getY().toString(), true); - addLabel("Interfaces"); + if (node.getType() == NodeType.DOCKER || node.getType() == NodeType.LXC) { + setContainerDetails(node, sessionRunning); + } + boolean firstInterface = true; for (CoreLink link : controller.getNetworkGraph().getGraph().getIncidentEdges(node)) { if (firstInterface) { firstInterface = false; + addLabel("Interfaces"); } else { addSeparator(); } @@ -119,6 +124,15 @@ public class NodeDetails extends ScrollPane { JFXScrollPane.smoothScrolling(scrollPane); } + private void setContainerDetails(CoreNode node, boolean sessionRunning) { + JFXTextField imageField = addRow("Image", node.getImage(), sessionRunning); + addButton("Update", event -> { + if (node.getType() == NodeType.DOCKER || node.getType() == NodeType.LXC) { + node.setImage(imageField.getText()); + } + }); + } + private void addButton(String text, EventHandler handler) { JFXButton emaneButton = new JFXButton(text); emaneButton.getStyleClass().add("core-button"); @@ -147,14 +161,12 @@ public class NodeDetails extends ScrollPane { addAddress("IP6", coreInterface.getIp6()); } - private void addRow(String labelText, String value, boolean disabled) { - if (value == null) { - return; - } + private JFXTextField addRow(String labelText, String value, boolean disabled) { Label label = new Label(labelText); JFXTextField textField = new JFXTextField(value); textField.setDisable(disabled); gridPane.addRow(index++, label, textField); + return textField; } private void addAddress(String label, IPAddress ip) { diff --git a/corefx/src/main/java/com/core/ui/dialogs/NodeServicesDialog.java b/corefx/src/main/java/com/core/ui/dialogs/NodeServicesDialog.java index c8e4b1a0..274c8547 100644 --- a/corefx/src/main/java/com/core/ui/dialogs/NodeServicesDialog.java +++ b/corefx/src/main/java/com/core/ui/dialogs/NodeServicesDialog.java @@ -129,7 +129,7 @@ public class NodeServicesDialog extends StageDialog { Set nodeServices = node.getServices(); if (nodeServices.isEmpty()) { - nodeServices = getController().getDefaultServices().get(node.getModel()); + nodeServices = getController().getDefaultServices().getOrDefault(node.getModel(), new HashSet<>()); } for (List items : serviceItemGroups.values()) { diff --git a/corefx/src/main/resources/icons/rj45-80.png b/corefx/src/main/resources/icons/rj45-80.png new file mode 100644 index 00000000..8c8cfcbc Binary files /dev/null and b/corefx/src/main/resources/icons/rj45-80.png differ