diff --git a/.github/workflows/daemon-checks.yml b/.github/workflows/daemon-checks.yml
index 023f5165..21dd95dc 100644
--- a/.github/workflows/daemon-checks.yml
+++ b/.github/workflows/daemon-checks.yml
@@ -17,6 +17,8 @@ jobs:
pip install pipenv
cd daemon
cp setup.py.in setup.py
+ cp core/constants.py.in core/constants.py
+ sed -i 's/True/False/g' core/constants.py
pipenv install --dev
- name: isort
run: |
@@ -30,3 +32,11 @@ jobs:
run: |
cd daemon
pipenv run flake8
+ - name: grpc
+ run: |
+ cd daemon/proto
+ pipenv run python -m grpc_tools.protoc -I . --python_out=.. --grpc_python_out=.. core/api/grpc/core.proto
+ - name: test
+ run: |
+ cd daemon
+ pipenv run test --mock
diff --git a/.gitignore b/.gitignore
index 038146aa..700cbf17 100644
--- a/.gitignore
+++ b/.gitignore
@@ -58,3 +58,6 @@ ns3/setup.py
# ignore corefx build
corefx/target
+
+# python
+__pycache__
diff --git a/Makefile.am b/Makefile.am
index ff31a5a4..fec08074 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -44,15 +44,6 @@ DISTCLEANFILES = aclocal.m4 \
MAINTAINERCLEANFILES = .version \
.version.date
-
-if PYTHON3
-PYTHON_DEB_DEP = python3 >= 3.6
-PYTHON_RPM_DEP = python3 >= 3.6
-else
-PYTHON_DEB_DEP = python (>= 2.7), python (<< 3.0)
-PYTHON_RPM_DEP = python >= 2.7, python < 3.0
-endif
-
define fpm-rpm =
fpm -s dir -t rpm -n core \
-m "$(PACKAGE_MAINTAINERS)" \
@@ -60,7 +51,7 @@ fpm -s dir -t rpm -n core \
--description "Common Open Research Emulator" \
--url https://github.com/coreemu/core \
--vendor "$(PACKAGE_VENDOR)" \
- -p core_$(PYTHON)_VERSION_ARCH.rpm \
+ -p core_VERSION_ARCH.rpm \
-v $(PACKAGE_VERSION) \
--rpm-init scripts/core-daemon \
--config-files "/etc/core" \
@@ -69,12 +60,12 @@ fpm -s dir -t rpm -n core \
-d "tk" \
-d "procps-ng" \
-d "bash >= 3.0" \
- -d "bridge-utils" \
-d "ebtables" \
-d "iproute" \
-d "libev" \
-d "net-tools" \
- -d "$(PYTHON_RPM_DEP)" \
+ -d "python3 >= 3.6" \
+ -d "python3-tkinter" \
-C $(DESTDIR)
endef
@@ -85,7 +76,7 @@ fpm -s dir -t deb -n core \
--description "Common Open Research Emulator" \
--url https://github.com/coreemu/core \
--vendor "$(PACKAGE_VENDOR)" \
- -p core_$(PYTHON)_VERSION_ARCH.deb \
+ -p core_VERSION_ARCH.deb \
-v $(PACKAGE_VERSION) \
--deb-systemd scripts/core-daemon.service \
--deb-no-default-config-files \
@@ -97,11 +88,11 @@ fpm -s dir -t deb -n core \
-d "procps" \
-d "libc6 >= 2.14" \
-d "bash >= 3.0" \
- -d "bridge-utils" \
-d "ebtables" \
-d "iproute2" \
-d "libev4" \
- -d "$(PYTHON_DEB_DEP)" \
+ -d "python3 >= 3.6" \
+ -d "python3-tk" \
-C $(DESTDIR)
endef
@@ -128,8 +119,6 @@ define change-files =
$(info creating file $1 from $1.in)
@$(SED) -e 's,[@]sbindir[@],$(sbindir),g' \
-e 's,[@]bindir[@],$(bindir),g' \
- -e 's,[@]pythondir[@],$(pythondir),g' \
- -e 's,[@]PYTHON[@],$(PYTHON),g' \
-e 's,[@]PACKAGE_VERSION[@],$(PACKAGE_VERSION),g' \
-e 's,[@]PACKAGE_DATE[@],$(PACKAGE_DATE),g' \
-e 's,[@]CORE_LIB_DIR[@],$(CORE_LIB_DIR),g' \
@@ -137,15 +126,6 @@ $(info creating file $1 from $1.in)
-e 's,[@]CORE_DATA_DIR[@],$(CORE_DATA_DIR),g' \
-e 's,[@]CORE_CONF_DIR[@],$(CORE_CONF_DIR),g' \
-e 's,[@]CORE_GUI_CONF_DIR[@],$(CORE_GUI_CONF_DIR),g' \
- -e 's,[@]brctl_path[@],$(brctl_path),g' \
- -e 's,[@]sysctl_path[@],$(sysctl_path),g' \
- -e 's,[@]ip_path[@],$(ip_path),g' \
- -e 's,[@]tc_path[@],$(tc_path),g' \
- -e 's,[@]ebtables_path[@],$(ebtables_path),g' \
- -e 's,[@]mount_path[@],$(mount_path),g' \
- -e 's,[@]umount_path[@],$(umount_path),g' \
- -e 's,[@]ovs_vs_path[@],$(ovs_vs_path),g' \
- -e 's,[@]ovs_of_path[@],$(ovs_of_path),g' \
< $1.in > $1
endef
diff --git a/configure.ac b/configure.ac
index fec902a3..9c7f799a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
# this defines the CORE version number, must be static for AC_INIT
-AC_INIT(core, 5.5.2)
+AC_INIT(core, 6.0.0)
# autoconf and automake initialization
AC_CONFIG_SRCDIR([netns/version.h.in])
@@ -55,12 +55,6 @@ else
want_python=no
fi
-AC_ARG_ENABLE([python3],
- [AS_HELP_STRING([--enable-python3],
- [sets python3 flag for building packages])],
- [enable_python3=yes], [enable_python3=no])
-AM_CONDITIONAL([PYTHON3], [test "x$enable_python3" == "xyes"])
-
AC_ARG_ENABLE([daemon],
[AS_HELP_STRING([--enable-daemon[=ARG]],
[build and install the daemon with Python modules
@@ -116,14 +110,9 @@ if test "x$enable_daemon" = "xyes"; then
AC_FUNC_REALLOC
AC_CHECK_FUNCS([atexit dup2 gettimeofday memset socket strerror uname])
- AM_PATH_PYTHON(2.7)
+ AM_PATH_PYTHON(3.6)
AS_IF([$PYTHON -m grpc_tools.protoc -h &> /dev/null], [], [AC_MSG_ERROR([please install python grpcio-tools])])
- AC_CHECK_PROG(brctl_path, brctl, $as_dir, no, $SEARCHPATH)
- if test "x$brctl_path" = "xno" ; then
- AC_MSG_ERROR([Could not locate brctl (from bridge-utils package).])
- fi
-
AC_CHECK_PROG(sysctl_path, sysctl, $as_dir, no, $SEARCHPATH)
if test "x$sysctl_path" = "xno" ; then
AC_MSG_ERROR([Could not locate sysctl (from procps package).])
diff --git a/corefx/pom.xml b/corefx/pom.xml
deleted file mode 100644
index ed5454e0..00000000
--- a/corefx/pom.xml
+++ /dev/null
@@ -1,147 +0,0 @@
-
-
- 4.0.0
-
- com.core
- corefx
- 1.0-SNAPSHOT
-
-
- UTF-8
- 1.8
- 1.8
- 2.1.1
- 2.10.0.pr2
- 1.20.0
- 2.9.0
-
-
-
-
- net.sf.jung
- jung-api
- ${jung.version}
-
-
- net.sf.jung
- jung-graph-impl
- ${jung.version}
-
-
- net.sf.jung
- jung-algorithms
- ${jung.version}
-
-
- net.sf.jung
- jung-io
- ${jung.version}
-
-
- net.sf.jung
- jung-visualization
- ${jung.version}
-
-
- com.fasterxml.jackson.core
- jackson-core
- ${jackson.version}
-
-
- com.fasterxml.jackson.core
- jackson-databind
- ${jackson.version}
-
-
- com.fasterxml.jackson.core
- jackson-annotations
- ${jackson.version}
-
-
- org.apache.logging.log4j
- log4j-api
- ${log4j.version}
-
-
- org.apache.logging.log4j
- log4j-core
- ${log4j.version}
-
-
- org.projectlombok
- lombok
- 1.18.0
- provided
-
-
- com.jfoenix
- jfoenix
- 8.0.7
-
-
- io.grpc
- grpc-netty-shaded
- ${grpc.version}
-
-
- io.grpc
- grpc-protobuf
- ${grpc.version}
-
-
- io.grpc
- grpc-stub
- ${grpc.version}
-
-
- com.google.guava
- guava
- 20.0
-
-
- com.github.seancfoley
- ipaddress
- 5.0.2
-
-
-
-
-
-
- kr.motd.maven
- os-maven-plugin
- 1.5.0.Final
-
-
-
-
- com.zenjava
- javafx-maven-plugin
- 8.8.3
-
- com.core.Main
-
-
-
- org.xolstice.maven.plugins
- protobuf-maven-plugin
- 0.5.1
-
- com.google.protobuf:protoc:3.7.1:exe:${os.detected.classifier}
- grpc-java
- io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}
-
-
-
-
- compile
- compile-custom
-
-
-
-
-
-
-
diff --git a/corefx/src/main/java/com/core/Controller.java b/corefx/src/main/java/com/core/Controller.java
deleted file mode 100644
index a9aa5021..00000000
--- a/corefx/src/main/java/com/core/Controller.java
+++ /dev/null
@@ -1,517 +0,0 @@
-package com.core;
-
-import com.core.client.ICoreClient;
-import com.core.client.grpc.CoreGrpcClient;
-import com.core.data.*;
-import com.core.graph.NetworkGraph;
-import com.core.ui.*;
-import com.core.ui.dialogs.*;
-import com.core.utils.ConfigUtils;
-import com.core.utils.Configuration;
-import com.core.utils.NodeTypeConfig;
-import com.jfoenix.controls.JFXDecorator;
-import com.jfoenix.controls.JFXProgressBar;
-import javafx.application.Application;
-import javafx.application.Platform;
-import javafx.concurrent.Task;
-import javafx.embed.swing.SwingNode;
-import javafx.event.ActionEvent;
-import javafx.fxml.FXML;
-import javafx.fxml.Initializable;
-import javafx.scene.control.CheckMenuItem;
-import javafx.scene.control.MenuItem;
-import javafx.scene.layout.BorderPane;
-import javafx.scene.layout.StackPane;
-import javafx.scene.layout.VBox;
-import javafx.stage.FileChooser;
-import javafx.stage.Stage;
-import lombok.Data;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.awt.event.ItemEvent;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.stream.Collectors;
-
-@Data
-public class Controller implements Initializable {
- private static final Logger logger = LogManager.getLogger();
- @FXML private StackPane stackPane;
- @FXML private BorderPane borderPane;
- @FXML private VBox top;
- @FXML private VBox bottom;
- @FXML private SwingNode swingNode;
- @FXML private MenuItem saveXmlMenuItem;
- @FXML private JFXProgressBar progressBar;
- @FXML private CheckMenuItem throughputMenuItem;
-
- private final ExecutorService executorService = Executors.newSingleThreadExecutor();
- private final Map mobilityScripts = new HashMap<>();
- private final Map mobilityPlayerDialogs = new HashMap<>();
- private Application application;
- private JFXDecorator decorator;
- private Stage window;
- private Configuration configuration;
- private Map> defaultServices = new HashMap<>();
-
- // core client utilities
- private ICoreClient coreClient = new CoreGrpcClient();
-
- // ui elements
- private NetworkGraph networkGraph = new NetworkGraph(this);
- private AnnotationToolbar annotationToolbar = new AnnotationToolbar(networkGraph);
- private NodeDetails nodeDetails = new NodeDetails(this);
- private LinkDetails linkDetails = new LinkDetails(this);
- private GraphToolbar graphToolbar = new GraphToolbar(this);
-
- // dialogs
- private Rj45Dialog rj45Dialog = new Rj45Dialog(this);
- private SessionsDialog sessionsDialog = new SessionsDialog(this);
- private ServiceDialog serviceDialog = new ServiceDialog(this);
- private NodeServicesDialog nodeServicesDialog = new NodeServicesDialog(this);
- private NodeEmaneDialog nodeEmaneDialog = new NodeEmaneDialog(this);
- private NodeWlanDialog nodeWlanDialog = new NodeWlanDialog(this);
- private ConfigDialog configDialog = new ConfigDialog(this);
- private HooksDialog hooksDialog = new HooksDialog(this);
- private MobilityDialog mobilityDialog = new MobilityDialog(this);
- private ChartDialog chartDialog = new ChartDialog(this);
- private NodeTypesDialog nodeTypesDialog = new NodeTypesDialog(this);
- private BackgroundDialog backgroundDialog = new BackgroundDialog(this);
- private LocationDialog locationDialog = new LocationDialog(this);
- private GeoDialog geoDialog = new GeoDialog(this);
- private ConnectDialog connectDialog = new ConnectDialog(this);
- private GuiPreferencesDialog guiPreferencesDialog = new GuiPreferencesDialog(this);
- private NodeTypeCreateDialog nodeTypeCreateDialog = new NodeTypeCreateDialog(this);
-
- public void connectToCore(String address, int port) {
- executorService.submit(() -> {
- try {
- coreClient.setConnection(address, port);
- initialJoin();
- } catch (IOException ex) {
- Toast.error(String.format("Connection failure: %s", ex.getMessage()), ex);
- Platform.runLater(() -> connectDialog.showDialog());
- }
- });
- }
-
- private void initialJoin() throws IOException {
- Map> serviceGroups = coreClient.getServices();
- logger.info("core services: {}", serviceGroups);
- nodeServicesDialog.setServices(serviceGroups);
- nodeTypeCreateDialog.setServices(serviceGroups);
-
- logger.info("initial core session join");
- List sessions = coreClient.getSessions();
-
- logger.info("existing sessions: {}", sessions);
- Integer sessionId;
- if (sessions.isEmpty()) {
- logger.info("creating initial session");
- SessionOverview sessionOverview = coreClient.createSession();
- sessionId = sessionOverview.getId();
- Toast.info(String.format("Created Session %s", sessionId));
- } else {
- SessionOverview sessionOverview = sessions.get(0);
- sessionId = sessionOverview.getId();
- Toast.info(String.format("Joined Session %s", sessionId));
- }
-
- joinSession(sessionId);
-
- // set emane models
- List emaneModels = coreClient.getEmaneModels();
- logger.info("emane models: {}", emaneModels);
- nodeEmaneDialog.setModels(emaneModels);
- }
-
- public void joinSession(Integer sessionId) throws IOException {
- // clear graph
- networkGraph.reset();
-
- // clear out any previously set information
- mobilityPlayerDialogs.clear();
- mobilityScripts.clear();
- mobilityDialog.setNode(null);
- Platform.runLater(() -> borderPane.setRight(null));
-
- // get session to join
- Session session = coreClient.joinSession(sessionId);
-
- // display all nodes
- for (CoreNode node : session.getNodes()) {
- networkGraph.addNode(node);
- }
-
- // display all links
- for (CoreLink link : session.getLinks()) {
- networkGraph.addLink(link);
- }
-
- // refresh graph
- networkGraph.getGraphViewer().repaint();
-
- // update other components for new session
- graphToolbar.setRunButton(coreClient.isRunning());
- hooksDialog.updateHooks();
-
- // update session default services
- setCoreDefaultServices();
-
- // retrieve current mobility script configurations and show dialogs
- Map mobilityConfigMap = coreClient.getMobilityConfigs();
- mobilityScripts.putAll(mobilityConfigMap);
- showMobilityScriptDialogs();
-
- Platform.runLater(() -> decorator.setTitle(String.format("CORE (Session %s)", sessionId)));
- }
-
- public boolean startSession() {
- // force nodes to get latest positions
- networkGraph.updatePositions();
-
- // retrieve items for creation/start
- Collection nodes = networkGraph.getGraph().getVertices();
- Collection links = networkGraph.getGraph().getEdges();
- List hooks = hooksDialog.getHooks();
-
- // start/create session
- boolean result = false;
- progressBar.setVisible(true);
- 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;
- }
-
- public boolean stopSession() throws IOException {
- // clear out any drawn wireless links
- List wirelessLinks = networkGraph.getGraph().getEdges().stream()
- .filter(CoreLink::isWireless)
- .collect(Collectors.toList());
- wirelessLinks.forEach(networkGraph::removeWirelessLink);
- networkGraph.getGraphViewer().repaint();
-
- // stop session
- progressBar.setVisible(true);
- boolean result = coreClient.stop();
- progressBar.setVisible(false);
- if (result) {
- saveXmlMenuItem.setDisable(true);
- }
- return result;
- }
-
- public void handleThroughputs(Throughputs throughputs) {
- for (InterfaceThroughput interfaceThroughput : throughputs.getInterfaces()) {
- int nodeId = interfaceThroughput.getNode();
- CoreNode node = networkGraph.getVertex(nodeId);
- Collection links = networkGraph.getGraph().getIncidentEdges(node);
- int interfaceId = interfaceThroughput.getNodeInterface();
- for (CoreLink link : links) {
- if (nodeId == link.getNodeOne()) {
- if (interfaceId == link.getInterfaceOne().getId()) {
- link.setThroughput(interfaceThroughput.getThroughput());
- }
- } else {
- if (interfaceId == link.getInterfaceTwo().getId()) {
- link.setThroughput(interfaceThroughput.getThroughput());
- }
- }
- }
- }
- networkGraph.getGraphViewer().repaint();
- }
-
- private void setCoreDefaultServices() {
- try {
- coreClient.setDefaultServices(defaultServices);
- } catch (IOException ex) {
- Toast.error("Error updating core default services", ex);
- }
- }
-
- public void updateNodeTypes() {
- graphToolbar.setupNodeTypes();
- setCoreDefaultServices();
- try {
- ConfigUtils.save(configuration);
- } catch (IOException ex) {
- Toast.error("Error saving configuration", ex);
- }
- }
-
- public void deleteNode(CoreNode node) {
- networkGraph.removeNode(node);
- CoreNode mobilityNode = mobilityDialog.getNode();
- if (mobilityNode != null && mobilityNode.getId().equals(node.getId())) {
- mobilityDialog.setNode(null);
- }
- }
-
- void setWindow(Stage window) {
- this.window = window;
- sessionsDialog.setOwner(window);
- hooksDialog.setOwner(window);
- nodeServicesDialog.setOwner(window);
- serviceDialog.setOwner(window);
- nodeWlanDialog.setOwner(window);
- nodeEmaneDialog.setOwner(window);
- configDialog.setOwner(window);
- mobilityDialog.setOwner(window);
- nodeTypesDialog.setOwner(window);
- backgroundDialog.setOwner(window);
- locationDialog.setOwner(window);
- connectDialog.setOwner(window);
- guiPreferencesDialog.setOwner(window);
- nodeTypeCreateDialog.setOwner(window);
- rj45Dialog.setOwner(window);
- }
-
- private void showMobilityScriptDialogs() {
- for (Map.Entry entry : mobilityScripts.entrySet()) {
- Integer nodeId = entry.getKey();
- CoreNode node = networkGraph.getVertex(nodeId);
- MobilityConfig mobilityConfig = entry.getValue();
- Platform.runLater(() -> {
- MobilityPlayerDialog mobilityPlayerDialog = new MobilityPlayerDialog(this, node);
- mobilityPlayerDialog.setOwner(window);
- mobilityPlayerDialogs.put(nodeId, mobilityPlayerDialog);
- mobilityPlayerDialog.showDialog(mobilityConfig);
- });
- }
- }
-
- @FXML
- private void onCoreMenuConnect(ActionEvent event) {
- logger.info("showing connect!");
- connectDialog.showDialog();
- }
-
- @FXML
- private void onOptionsMenuNodeTypes(ActionEvent event) {
- nodeTypesDialog.showDialog();
- }
-
- @FXML
- private void onOptionsMenuBackground(ActionEvent event) {
- backgroundDialog.showDialog();
- }
-
- @FXML
- private void onOptionsMenuLocation(ActionEvent event) {
- locationDialog.showDialog();
- }
-
- @FXML
- private void onOptionsMenuPreferences(ActionEvent event) {
- guiPreferencesDialog.showDialog();
- }
-
- @FXML
- private void onHelpMenuWebsite(ActionEvent event) {
- application.getHostServices().showDocument("https://github.com/coreemu/core");
- }
-
- @FXML
- private void onHelpMenuDocumentation(ActionEvent event) {
- application.getHostServices().showDocument("http://coreemu.github.io/core/");
- }
-
- @FXML
- private void onOpenXmlAction() {
- FileChooser fileChooser = new FileChooser();
- fileChooser.setTitle("Open Session");
- fileChooser.setInitialDirectory(new File(configuration.getXmlPath()));
- fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml"));
- try {
- File file = fileChooser.showOpenDialog(window);
- if (file != null) {
- openXml(file);
- }
- } catch (IllegalArgumentException ex) {
- Toast.error(String.format("Invalid XML directory: %s", configuration.getXmlPath()));
- }
- }
-
- private void openXml(File file) {
- logger.info("opening session xml: {}", file.getPath());
- try {
- SessionOverview sessionOverview = coreClient.openSession(file);
- Integer sessionId = sessionOverview.getId();
- joinSession(sessionId);
- Toast.info(String.format("Joined Session %s", sessionId));
- } catch (IOException ex) {
- Toast.error("Error opening session xml", ex);
- }
- }
-
- @FXML
- private void onSaveXmlAction() {
- FileChooser fileChooser = new FileChooser();
- fileChooser.setTitle("Save Session");
- fileChooser.setInitialFileName("session.xml");
- fileChooser.setInitialDirectory(new File(configuration.getXmlPath()));
- fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml"));
- File file = fileChooser.showSaveDialog(window);
- if (file != null) {
- logger.info("saving session xml: {}", file.getPath());
- try {
- coreClient.saveSession(file);
- } catch (IOException ex) {
- Toast.error("Error saving session xml", ex);
- }
- }
- }
-
- @FXML
- private void onSessionMenu(ActionEvent event) {
- logger.info("sessions menu clicked");
- try {
- sessionsDialog.showDialog();
- } catch (IOException ex) {
- Toast.error("Error retrieving sessions", ex);
- }
- }
-
- @FXML
- private void onSessionHooksMenu(ActionEvent event) {
- hooksDialog.showDialog();
- }
-
- @FXML
- private void onSessionOptionsMenu(ActionEvent event) {
- try {
- List configGroups = coreClient.getSessionConfig();
- configDialog.showDialog("Session Options", configGroups, () -> {
- List options = configDialog.getOptions();
- try {
- boolean result = coreClient.setSessionConfig(options);
- if (result) {
- Toast.info("Session options saved");
- } else {
- Toast.error("Failure to set session config");
- }
- } catch (IOException ex) {
- logger.error("error getting session config");
- }
- });
- } catch (IOException ex) {
- logger.error("error getting session config");
- }
- }
-
- @FXML
- private void onTestMenuCharts(ActionEvent event) {
- chartDialog.show();
- }
-
- @FXML
- private void onTestMenuGeo(ActionEvent event) {
- geoDialog.showDialog();
- }
-
- @Override
- public void initialize(URL location, ResourceBundle resources) {
- configuration = ConfigUtils.load();
- String address = configuration.getCoreAddress();
- int port = configuration.getCorePort();
- logger.info("core connection: {}:{}", address, port);
- connectDialog.setAddress(address);
- connectDialog.setPort(port);
- connectToCore(address, port);
-
- logger.info("controller initialize");
- coreClient.initialize(this);
- swingNode.setContent(networkGraph.getGraphViewer());
-
- // update graph preferences
- networkGraph.updatePreferences(configuration);
-
- // set node types / default services
- graphToolbar.setupNodeTypes();
- defaultServices = configuration.getNodeTypeConfigs().stream()
- .collect(Collectors.toMap(NodeTypeConfig::getModel, NodeTypeConfig::getServices));
-
- // set graph toolbar
- borderPane.setLeft(graphToolbar);
-
- // setup snackbar
- Toast.setSnackbarRoot(stackPane);
-
- // setup throughput menu item
- throughputMenuItem.setOnAction(event -> executorService.submit(new ChangeThroughputTask()));
-
- // node details
- networkGraph.getGraphViewer().getPickedVertexState().addItemListener(event -> {
- CoreNode node = (CoreNode) event.getItem();
- logger.info("picked: {}", node.getName());
- if (event.getStateChange() == ItemEvent.SELECTED) {
- Platform.runLater(() -> {
- nodeDetails.setNode(node);
- borderPane.setRight(nodeDetails);
- });
- } else {
- Platform.runLater(() -> borderPane.setRight(null));
- }
- });
-
- // edge details
- networkGraph.getGraphViewer().getPickedEdgeState().addItemListener(event -> {
- CoreLink link = (CoreLink) event.getItem();
- logger.info("picked: {} - {}", link.getNodeOne(), link.getNodeTwo());
- if (event.getStateChange() == ItemEvent.SELECTED) {
- Platform.runLater(() -> {
- linkDetails.setLink(link);
- borderPane.setRight(linkDetails);
- });
- } else {
- Platform.runLater(() -> borderPane.setRight(null));
- }
- });
- }
-
- private class ChangeThroughputTask extends Task {
- @Override
- protected Boolean call() throws Exception {
- if (throughputMenuItem.isSelected()) {
- return coreClient.startThroughput(Controller.this);
- } else {
- return coreClient.stopThroughput();
- }
- }
-
- @Override
- protected void succeeded() {
- if (getValue()) {
- if (throughputMenuItem.isSelected()) {
- networkGraph.setShowThroughput(true);
- } else {
- networkGraph.setShowThroughput(false);
- networkGraph.getGraph().getEdges().forEach(edge -> edge.setThroughput(0));
- networkGraph.getGraphViewer().repaint();
- }
- } else {
- Toast.error("Failure changing throughput");
- }
- }
-
- @Override
- protected void failed() {
- Toast.error("Error changing throughput", new RuntimeException(getException()));
- }
- }
-}
diff --git a/corefx/src/main/java/com/core/Main.java b/corefx/src/main/java/com/core/Main.java
deleted file mode 100644
index 4834278f..00000000
--- a/corefx/src/main/java/com/core/Main.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.core;
-
-import com.core.utils.ConfigUtils;
-import com.jfoenix.controls.JFXDecorator;
-import com.jfoenix.svg.SVGGlyphLoader;
-import javafx.application.Application;
-import javafx.application.Platform;
-import javafx.fxml.FXMLLoader;
-import javafx.scene.Parent;
-import javafx.scene.Scene;
-import javafx.scene.image.Image;
-import javafx.scene.image.ImageView;
-import javafx.scene.text.Font;
-import javafx.stage.Stage;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-public class Main extends Application {
- private static final Path LOG_FILE = Paths.get(System.getProperty("user.home"), ".core", "core.log");
-
- @Override
- public void start(Stage window) throws Exception {
- // set core dir property for logging
- System.setProperty("core_log", LOG_FILE.toString());
-
- // check for and create gui home directory
- ConfigUtils.checkHomeDirectory();
-
- // load svg icons
- SVGGlyphLoader.loadGlyphsFont(getClass().getResourceAsStream("/icons/icomoon_material.svg"),
- "icomoon.svg");
-
- // load font
- Font.loadFont(getClass().getResourceAsStream("/font/roboto/Roboto-Regular.ttf"), 10);
-
- // load main fxml
- FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
- Parent root = loader.load();
-
- // window decorator
- JFXDecorator decorator = new JFXDecorator(window, root);
- decorator.setCustomMaximize(true);
- decorator.setMaximized(true);
- decorator.setTitle("CORE");
- Image coreIcon = new Image(getClass().getResourceAsStream("/core-icon.png"));
- decorator.setGraphic(new ImageView(coreIcon));
- window.getIcons().add(coreIcon);
-
- // create scene and set as current scene within window
- Scene scene = new Scene(decorator);
- scene.getStylesheets().add(getClass().getResource("/css/main.css").toExternalForm());
- window.setScene(scene);
-
- // update controller
- Controller controller = loader.getController();
- controller.setApplication(this);
- controller.setWindow(window);
- controller.setDecorator(decorator);
-
- // configure window
- window.setOnCloseRequest(event -> {
- Platform.exit();
- System.exit(0);
- });
- window.show();
- }
-
- public static void main(String[] args) {
- launch(args);
- }
-}
diff --git a/corefx/src/main/java/com/core/client/ICoreClient.java b/corefx/src/main/java/com/core/client/ICoreClient.java
deleted file mode 100644
index 4060956f..00000000
--- a/corefx/src/main/java/com/core/client/ICoreClient.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package com.core.client;
-
-import com.core.Controller;
-import com.core.data.*;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public interface ICoreClient {
- void setConnection(String address, int port);
-
- boolean isLocalConnection();
-
- Integer currentSession();
-
- boolean startThroughput(Controller controller) throws IOException;
-
- boolean stopThroughput() throws IOException;
-
- SessionOverview createSession() throws IOException;
-
- boolean deleteSession(Integer sessionId) throws IOException;
-
- List getSessions() throws IOException;
-
- Session joinSession(Integer sessionId) throws IOException;
-
- Session getSession(Integer sessionId) throws IOException;
-
- boolean start(Collection nodes, Collection links, List hooks) throws IOException;
-
- boolean stop() throws IOException;
-
- boolean setState(SessionState state) throws IOException;
-
- Map> getServices() throws IOException;
-
- Map> getDefaultServices() throws IOException;
-
- boolean setDefaultServices(Map> defaults) throws IOException;
-
- CoreService getService(CoreNode node, String serviceName) throws IOException;
-
- boolean setService(CoreNode node, String serviceName, CoreService service) throws IOException;
-
- String getServiceFile(CoreNode node, String serviceName, String fileName) throws IOException;
-
- boolean startService(CoreNode node, String serviceName) throws IOException;
-
- boolean stopService(CoreNode node, String serviceName) throws IOException;
-
- boolean restartService(CoreNode node, String serviceName) throws IOException;
-
- boolean validateService(CoreNode node, String serviceName) throws IOException;
-
- boolean setServiceFile(CoreNode node, String serviceName, ServiceFile serviceFile) throws IOException;
-
- List getEmaneConfig(CoreNode node) throws IOException;
-
- List getEmaneModels() throws IOException;
-
- boolean setEmaneConfig(CoreNode node, List options) throws IOException;
-
- List getEmaneModelConfig(Integer id, String model) throws IOException;
-
- boolean setEmaneModelConfig(Integer id, String model, List options) throws IOException;
-
- boolean isRunning();
-
- void saveSession(File file) throws IOException;
-
- SessionOverview openSession(File file) throws IOException;
-
- List getSessionConfig() throws IOException;
-
- boolean setSessionConfig(List configOptions) throws IOException;
-
- boolean createNode(CoreNode node) throws IOException;
-
- String nodeCommand(CoreNode node, String command) throws IOException;
-
- boolean editNode(CoreNode node) throws IOException;
-
- boolean deleteNode(CoreNode node) throws IOException;
-
- boolean createLink(CoreLink link) throws IOException;
-
- boolean editLink(CoreLink link) throws IOException;
-
- boolean createHook(Hook hook) throws IOException;
-
- List getHooks() throws IOException;
-
- WlanConfig getWlanConfig(CoreNode node) throws IOException;
-
- boolean setWlanConfig(CoreNode node, WlanConfig config) throws IOException;
-
- String getTerminalCommand(CoreNode node) throws IOException;
-
- Map getMobilityConfigs() throws IOException;
-
- boolean setMobilityConfig(CoreNode node, MobilityConfig config) throws IOException;
-
- MobilityConfig getMobilityConfig(CoreNode node) throws IOException;
-
- boolean mobilityAction(CoreNode node, String action) throws IOException;
-
- LocationConfig getLocationConfig() throws IOException;
-
- boolean setLocationConfig(LocationConfig config) throws IOException;
-
- void initialize(Controller controller);
-
- List getInterfaces() throws IOException;
-}
diff --git a/corefx/src/main/java/com/core/client/grpc/CoreGrpcClient.java b/corefx/src/main/java/com/core/client/grpc/CoreGrpcClient.java
deleted file mode 100644
index 665dd1a4..00000000
--- a/corefx/src/main/java/com/core/client/grpc/CoreGrpcClient.java
+++ /dev/null
@@ -1,1294 +0,0 @@
-package com.core.client.grpc;
-
-import com.core.Controller;
-import com.core.client.ICoreClient;
-import com.core.data.*;
-import com.core.ui.dialogs.MobilityPlayerDialog;
-import inet.ipaddr.IPAddress;
-import inet.ipaddr.IPAddressString;
-import io.grpc.Context;
-import io.grpc.ManagedChannel;
-import io.grpc.ManagedChannelBuilder;
-import io.grpc.StatusRuntimeException;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-public class CoreGrpcClient implements ICoreClient {
- private static final Logger logger = LogManager.getLogger();
- private String address;
- private int port;
- private Integer sessionId;
- private SessionState sessionState;
- private CoreApiGrpc.CoreApiBlockingStub blockingStub;
- private ManagedChannel channel;
- private final ExecutorService executorService = Executors.newFixedThreadPool(6);
- private boolean handlingEvents = false;
- private boolean handlingThroughputs = false;
- private Controller controller;
-
- private CoreProto.Node nodeToProto(CoreNode node) {
- CoreProto.Position position = CoreProto.Position.newBuilder()
- .setX(node.getPosition().getX().intValue())
- .setY(node.getPosition().getY().intValue())
- .build();
- CoreProto.Node.Builder builder = CoreProto.Node.newBuilder()
- .addAllServices(node.getServices())
- .setType(CoreProto.NodeType.Enum.forNumber(node.getType()))
- .setPosition(position);
- if (node.getId() != null) {
- builder.setId(node.getId());
- }
- if (node.getName() != null) {
- builder.setName(node.getName());
- }
- if (node.getEmane() != null) {
- builder.setEmane(node.getEmane());
- }
- if (node.getModel() != null) {
- builder.setModel(node.getModel());
- }
- if (node.getIcon() != null) {
- builder.setIcon(node.getIcon());
- }
- if (node.getImage() != null) {
- builder.setImage(node.getImage());
- }
-
- return builder.build();
- }
-
- private List protoToConfigGroups(List protoConfigs) {
- List configs = new ArrayList<>();
- for (CoreProto.ConfigGroup protoConfig : protoConfigs) {
- ConfigGroup config = new ConfigGroup();
- config.setName(protoConfig.getName());
- for (CoreProto.ConfigOption protoOption : protoConfig.getOptionsList()) {
- ConfigOption option = new ConfigOption();
- option.setType(protoOption.getType());
- option.setLabel(protoOption.getLabel());
- option.setName(protoOption.getName());
- option.setValue(protoOption.getValue());
- option.setSelect(protoOption.getSelectList());
- config.getOptions().add(option);
- }
- configs.add(config);
- }
- return configs;
- }
-
- private CoreProto.LinkOptions linkOptionsToProto(CoreLinkOptions options) {
- CoreProto.LinkOptions.Builder builder = CoreProto.LinkOptions.newBuilder();
- if (options.getUnidirectional() != null) {
- builder.setUnidirectional(options.getUnidirectional());
- }
- if (options.getBandwidth() != null) {
- builder.setBandwidth(options.getBandwidth());
- }
- if (options.getBurst() != null) {
- builder.setBurst(options.getBurst());
- }
- if (options.getDelay() != null) {
- builder.setDelay(options.getDelay());
- }
- if (options.getDup() != null) {
- builder.setDup(options.getDup());
- }
- if (options.getJitter() != null) {
- builder.setJitter(options.getJitter());
- }
- if (options.getMburst() != null) {
- builder.setMburst(options.getMburst());
- }
- if (options.getMer() != null) {
- builder.setMer(options.getMer());
- }
- if (options.getPer() != null) {
- builder.setPer(options.getPer().floatValue());
- }
- if (options.getKey() != null) {
- builder.setKey(options.getKey());
- }
- if (options.getOpaque() != null) {
- builder.setOpaque(options.getOpaque());
- }
- return builder.build();
- }
-
- private CoreProto.Interface interfaceToProto(CoreInterface coreInterface) {
- CoreProto.Interface.Builder builder = CoreProto.Interface.newBuilder();
- if (coreInterface.getId() != null) {
- builder.setId(coreInterface.getId());
- }
- if (coreInterface.getName() != null) {
- builder.setName(coreInterface.getName());
- }
- if (coreInterface.getMac() != null) {
- builder.setMac(coreInterface.getMac());
- }
- if (coreInterface.getIp4() != null) {
- builder.setIp4(coreInterface.getIp4().toAddressString().getHostAddress().toString());
- }
- if (coreInterface.getIp4() != null) {
- builder.setIp4Mask(coreInterface.getIp4().getPrefixLength());
- }
- if (coreInterface.getIp6() != null) {
- builder.setIp6(coreInterface.getIp6().toAddressString().getHostAddress().toString());
- }
- if (coreInterface.getIp6() != null) {
- builder.setIp6Mask(coreInterface.getIp6().getPrefixLength());
- }
- return builder.build();
- }
-
- private Map configOptionListToMap(List options) {
- Map config = new HashMap<>();
- for (ConfigOption option : options) {
- config.put(option.getName(), option.getValue());
- }
- return config;
- }
-
- private CoreNode protoToNode(CoreProto.Node protoNode) {
- CoreNode node = new CoreNode(protoNode.getId());
- node.setType(protoNode.getTypeValue());
- node.setName(protoNode.getName());
- node.setIcon(protoNode.getIcon());
- node.setModel(protoNode.getModel());
- if (!protoNode.getEmane().isEmpty()) {
- node.setEmane(protoNode.getEmane());
- }
- if (!protoNode.getImage().isEmpty()) {
- node.setImage(protoNode.getImage());
- }
- node.setServices(new HashSet<>(protoNode.getServicesList()));
- node.getPosition().setX((double) protoNode.getPosition().getX());
- node.getPosition().setY((double) protoNode.getPosition().getY());
- NodeType nodeType = NodeType.find(node.getType(), node.getModel());
- if (nodeType == null) {
- logger.error("failed to find node type({}) model({}): {}",
- node.getType(), node.getModel(), node.getName());
- }
- node.setNodeType(nodeType);
- node.setLoaded(true);
- return node;
- }
-
- private CoreInterface protoToInterface(CoreProto.Interface protoInterface) {
- CoreInterface coreInterface = new CoreInterface();
- coreInterface.setId(protoInterface.getId());
- coreInterface.setName(protoInterface.getName());
- if (!protoInterface.getMac().isEmpty()) {
- coreInterface.setMac(protoInterface.getMac());
- }
- String ip4String = String.format("%s/%s", protoInterface.getIp4(), protoInterface.getIp4Mask());
- IPAddress ip4 = new IPAddressString(ip4String).getAddress();
- coreInterface.setIp4(ip4);
- String ip6String = String.format("%s/%s", protoInterface.getIp6(), protoInterface.getIp6Mask());
- IPAddress ip6 = new IPAddressString(ip6String).getAddress();
- coreInterface.setIp6(ip6);
- return coreInterface;
- }
-
- private CoreLink protoToLink(CoreProto.Link linkProto) {
- CoreLink link = new CoreLink();
- link.setType(linkProto.getTypeValue());
- link.setNodeOne(linkProto.getNodeOneId());
- link.setNodeTwo(linkProto.getNodeTwoId());
- CoreInterface interfaceOne = protoToInterface(linkProto.getInterfaceOne());
- link.setInterfaceOne(interfaceOne);
- CoreInterface interfaceTwo = protoToInterface(linkProto.getInterfaceTwo());
- link.setInterfaceTwo(interfaceTwo);
-
- CoreLinkOptions options = new CoreLinkOptions();
- CoreProto.LinkOptions protoOptions = linkProto.getOptions();
- options.setBandwidth((int) protoOptions.getBandwidth());
- options.setDelay((int) protoOptions.getDelay());
- options.setDup((int) protoOptions.getDup());
- options.setJitter((int) protoOptions.getJitter());
- options.setPer((double) protoOptions.getPer());
- options.setBurst((int) protoOptions.getBurst());
- if (protoOptions.hasField(CoreProto.LinkOptions.getDescriptor().findFieldByName("key"))) {
- options.setKey(protoOptions.getKey());
- }
- options.setMburst((int) protoOptions.getMburst());
- options.setMer((int) protoOptions.getMer());
- options.setOpaque(protoOptions.getOpaque());
- options.setUnidirectional(protoOptions.getUnidirectional());
- link.setOptions(options);
-
- return link;
- }
-
- @Override
- public void initialize(Controller controller) {
- this.controller = controller;
- }
-
- @Override
- public void setConnection(String address, int port) {
- this.address = address;
- this.port = port;
- logger.info("set connection: {}:{}", this.address, this.port);
- channel = ManagedChannelBuilder.forAddress(this.address, this.port).usePlaintext().build();
- logger.info("channel: {}", channel);
- blockingStub = CoreApiGrpc.newBlockingStub(channel);
- logger.info("stub: {}", blockingStub);
- }
-
- @Override
- public boolean isLocalConnection() {
- return address.equals("127.0.0.1") || address.equals("localhost");
- }
-
- @Override
- public Integer currentSession() {
- return sessionId;
- }
-
- @Override
- public boolean startThroughput(Controller controller) throws IOException {
- CoreProto.ThroughputsRequest request = CoreProto.ThroughputsRequest.newBuilder().build();
- try {
- handlingThroughputs = true;
- executorService.submit(() -> {
- Context.CancellableContext context = Context.current().withCancellation();
- context.run(() -> {
- try {
- Iterator iterator = blockingStub.throughputs(request);
- while (handlingThroughputs) {
- CoreProto.ThroughputsEvent event = iterator.next();
- logger.info("handling throughputs: {}", event);
- Throughputs throughputs = new Throughputs();
- for (CoreProto.BridgeThroughput protoBridge : event.getBridgeThroughputsList()) {
- BridgeThroughput bridge = new BridgeThroughput();
- bridge.setNode(protoBridge.getNodeId());
- bridge.setThroughput(protoBridge.getThroughput());
- throughputs.getBridges().add(bridge);
- }
- for (CoreProto.InterfaceThroughput protoInterface : event.getInterfaceThroughputsList()) {
- InterfaceThroughput interfaceThroughput = new InterfaceThroughput();
- interfaceThroughput.setNode(protoInterface.getNodeId());
- interfaceThroughput.setNodeInterface(protoInterface.getInterfaceId());
- interfaceThroughput.setThroughput(protoInterface.getThroughput());
- throughputs.getInterfaces().add(interfaceThroughput);
- }
- controller.handleThroughputs(throughputs);
- }
- logger.info("exiting handling throughputs");
- } catch (StatusRuntimeException ex) {
- logger.error("error handling session events", ex);
- } finally {
- context.cancel(null);
- context.close();
- }
- });
- });
- return true;
- } catch (StatusRuntimeException ex) {
- throw new IOException("setup event handlers error", ex);
- }
- }
-
- @Override
- public boolean stopThroughput() throws IOException {
- logger.info("cancelling throughputs");
- handlingThroughputs = false;
- return true;
- }
-
- @Override
- public SessionOverview createSession() throws IOException {
- CoreProto.CreateSessionRequest request = CoreProto.CreateSessionRequest.newBuilder().build();
- try {
- CoreProto.CreateSessionResponse response = blockingStub.createSession(request);
- SessionOverview overview = new SessionOverview();
- overview.setId(response.getSessionId());
- overview.setState(response.getStateValue());
- overview.setNodes(0);
- return overview;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean deleteSession(Integer sessionId) throws IOException {
- CoreProto.DeleteSessionRequest request = CoreProto.DeleteSessionRequest.newBuilder()
- .setSessionId(sessionId).build();
- try {
- return blockingStub.deleteSession(request).getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public List getSessions() throws IOException {
- CoreProto.GetSessionsRequest request = CoreProto.GetSessionsRequest.newBuilder().build();
- try {
- CoreProto.GetSessionsResponse response = blockingStub.getSessions(request);
- List sessions = new ArrayList<>();
- for (CoreProto.SessionSummary summary : response.getSessionsList()) {
- SessionOverview overview = new SessionOverview();
- overview.setId(summary.getId());
- overview.setNodes(summary.getNodes());
- overview.setState(summary.getStateValue());
- sessions.add(overview);
- }
- return sessions;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public Session getSession(Integer sessionId) throws IOException {
- logger.info("getting session: {}", sessionId);
- CoreProto.GetSessionRequest request = CoreProto.GetSessionRequest.newBuilder().setSessionId(sessionId).build();
- try {
- CoreProto.GetSessionResponse response = blockingStub.getSession(request);
- Session session = new Session();
- session.setId(sessionId);
- for (CoreProto.Node protoNode : response.getSession().getNodesList()) {
- if (CoreProto.NodeType.Enum.PEER_TO_PEER == protoNode.getType()) {
- continue;
- }
-
- logger.info("adding node: {}", protoNode);
- CoreNode node = protoToNode(protoNode);
- session.getNodes().add(node);
- }
- for (CoreProto.Link linkProto : response.getSession().getLinksList()) {
- logger.info("adding link: {}", linkProto);
- CoreLink link = protoToLink(linkProto);
- session.getLinks().add(link);
- }
- SessionState state = SessionState.get(response.getSession().getStateValue());
- session.setState(state);
- return session;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public Session joinSession(Integer sessionId) throws IOException {
- // stop handling previous session events if currently running
- if (isRunning()) {
- handlingEvents = false;
- }
-
- // join desired session
- Session session = getSession(sessionId);
- this.sessionId = session.getId();
- sessionState = session.getState();
- logger.info("joining session({}) state({})", this.sessionId, sessionState);
-
- // setup event handlers if joined session is running
- if (isRunning()) {
- setupEventHandlers();
- }
-
- return session;
- }
-
- @Override
- public boolean start(Collection nodes, Collection links, List hooks) throws IOException {
- setupEventHandlers();
-
- boolean result = setState(SessionState.DEFINITION);
- if (!result) {
- return false;
- }
-
- result = setState(SessionState.CONFIGURATION);
- if (!result) {
- return false;
- }
-
- for (Hook hook : hooks) {
- if (!createHook(hook)) {
- return false;
- }
- }
-
- for (CoreNode node : nodes) {
- // must pre-configure wlan nodes, if not already
- if (node.getNodeType().getValue() == NodeType.WLAN) {
- WlanConfig config = getWlanConfig(node);
- setWlanConfig(node, config);
- }
-
- if (!createNode(node)) {
- return false;
- }
- }
-
- for (CoreLink link : links) {
- if (!createLink(link)) {
- return false;
- }
- }
-
- return setState(SessionState.INSTANTIATION);
- }
-
- @Override
- public boolean stop() throws IOException {
- handlingEvents = false;
- return setState(SessionState.SHUTDOWN);
- }
-
- @Override
- public boolean setState(SessionState state) throws IOException {
- CoreProto.SetSessionStateRequest request = CoreProto.SetSessionStateRequest.newBuilder()
- .setSessionId(sessionId)
- .setStateValue(state.getValue())
- .build();
- try {
- CoreProto.SetSessionStateResponse response = blockingStub.setSessionState(request);
- if (response.getResult()) {
- sessionState = state;
- }
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public Map> getServices() throws IOException {
- CoreProto.GetServicesRequest request = CoreProto.GetServicesRequest.newBuilder().build();
- try {
- CoreProto.GetServicesResponse response = blockingStub.getServices(request);
- Map> servicesMap = new HashMap<>();
- for (CoreProto.Service protoService : response.getServicesList()) {
- List services = servicesMap.computeIfAbsent(protoService.getGroup(), x -> new ArrayList<>());
- services.add(protoService.getName());
- }
- return servicesMap;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public Map> getDefaultServices() throws IOException {
- CoreProto.GetServiceDefaultsRequest request = CoreProto.GetServiceDefaultsRequest.newBuilder().build();
- try {
- CoreProto.GetServiceDefaultsResponse response = blockingStub.getServiceDefaults(request);
- Map> servicesMap = new HashMap<>();
- for (CoreProto.ServiceDefaults serviceDefaults : response.getDefaultsList()) {
- servicesMap.put(serviceDefaults.getNodeType(), serviceDefaults.getServicesList());
- }
- return servicesMap;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean setDefaultServices(Map> defaults) throws IOException {
- List allDefaults = new ArrayList<>();
- for (Map.Entry> entry : defaults.entrySet()) {
- String nodeType = entry.getKey();
- Set services = entry.getValue();
- CoreProto.ServiceDefaults serviceDefaults = CoreProto.ServiceDefaults.newBuilder()
- .setNodeType(nodeType)
- .addAllServices(services)
- .build();
- allDefaults.add(serviceDefaults);
- }
- CoreProto.SetServiceDefaultsRequest request = CoreProto.SetServiceDefaultsRequest.newBuilder()
- .setSessionId(sessionId)
- .addAllDefaults(allDefaults)
- .build();
- try {
- CoreProto.SetServiceDefaultsResponse response = blockingStub.setServiceDefaults(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public CoreService getService(CoreNode node, String serviceName) throws IOException {
- CoreProto.GetNodeServiceRequest request = CoreProto.GetNodeServiceRequest.newBuilder().build();
- try {
- CoreProto.GetNodeServiceResponse response = blockingStub.getNodeService(request);
- CoreProto.NodeServiceData nodeServiceData = response.getService();
- CoreService service = new CoreService();
- service.setShutdown(nodeServiceData.getShutdownList());
- service.setStartup(nodeServiceData.getStartupList());
- service.setValidate(nodeServiceData.getValidateList());
- service.setConfigs(nodeServiceData.getConfigsList());
- service.setDependencies(nodeServiceData.getDependenciesList());
- service.setDirs(nodeServiceData.getDirsList());
- service.setExecutables(nodeServiceData.getExecutablesList());
- service.setMeta(nodeServiceData.getMeta());
- service.setValidationMode(nodeServiceData.getValidationMode().name());
- service.setValidationTimer(Integer.toString(nodeServiceData.getValidationTimer()));
- return service;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean setService(CoreNode node, String serviceName, CoreService service) throws IOException {
- CoreProto.SetNodeServiceRequest request = CoreProto.SetNodeServiceRequest.newBuilder()
- .setNodeId(node.getId())
- .setSessionId(sessionId)
- .setService(serviceName)
- .build();
- request.getShutdownList().addAll(service.getShutdown());
- request.getValidateList().addAll(service.getValidate());
- request.getStartupList().addAll(service.getStartup());
- try {
- return blockingStub.setNodeService(request).getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public String getServiceFile(CoreNode node, String serviceName, String fileName) throws IOException {
- CoreProto.GetNodeServiceFileRequest request = CoreProto.GetNodeServiceFileRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .setService(serviceName)
- .build();
- try {
- CoreProto.GetNodeServiceFileResponse response = blockingStub.getNodeServiceFile(request);
- return response.getData();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean startService(CoreNode node, String serviceName) throws IOException {
- CoreProto.ServiceActionRequest request = CoreProto.ServiceActionRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .setService(serviceName)
- .setAction(CoreProto.ServiceAction.Enum.START)
- .build();
- try {
- return blockingStub.serviceAction(request).getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean stopService(CoreNode node, String serviceName) throws IOException {
- CoreProto.ServiceActionRequest request = CoreProto.ServiceActionRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .setService(serviceName)
- .setAction(CoreProto.ServiceAction.Enum.STOP)
- .build();
- try {
- return blockingStub.serviceAction(request).getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean restartService(CoreNode node, String serviceName) throws IOException {
- CoreProto.ServiceActionRequest request = CoreProto.ServiceActionRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .setService(serviceName)
- .setAction(CoreProto.ServiceAction.Enum.RESTART)
- .build();
- try {
- return blockingStub.serviceAction(request).getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean validateService(CoreNode node, String serviceName) throws IOException {
- CoreProto.ServiceActionRequest request = CoreProto.ServiceActionRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .setService(serviceName)
- .setAction(CoreProto.ServiceAction.Enum.VALIDATE)
- .build();
- try {
- return blockingStub.serviceAction(request).getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean setServiceFile(CoreNode node, String serviceName, ServiceFile serviceFile) throws IOException {
- CoreProto.SetNodeServiceFileRequest request = CoreProto.SetNodeServiceFileRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .setService(serviceName)
- .setFile(serviceFile.getName())
- .setData(serviceFile.getData())
- .build();
- try {
- CoreProto.SetNodeServiceFileResponse response = blockingStub.setNodeServiceFile(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public List getEmaneConfig(CoreNode node) throws IOException {
- CoreProto.GetEmaneConfigRequest request = CoreProto.GetEmaneConfigRequest.newBuilder()
- .setSessionId(sessionId)
- .build();
- try {
- CoreProto.GetEmaneConfigResponse response = blockingStub.getEmaneConfig(request);
- return protoToConfigGroups(response.getGroupsList());
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public List getEmaneModels() throws IOException {
- CoreProto.GetEmaneModelsRequest request = CoreProto.GetEmaneModelsRequest.newBuilder()
- .setSessionId(sessionId)
- .build();
- try {
- CoreProto.GetEmaneModelsResponse response = blockingStub.getEmaneModels(request);
- return new ArrayList<>(response.getModelsList());
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean setEmaneConfig(CoreNode node, List options) throws IOException {
- Map config = configOptionListToMap(options);
- CoreProto.SetEmaneConfigRequest request = CoreProto.SetEmaneConfigRequest.newBuilder()
- .setSessionId(sessionId)
- .putAllConfig(config)
- .build();
- try {
- CoreProto.SetEmaneConfigResponse response = blockingStub.setEmaneConfig(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public List getEmaneModelConfig(Integer id, String model) throws IOException {
- CoreProto.GetEmaneModelConfigRequest request = CoreProto.GetEmaneModelConfigRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(id)
- .setModel(model)
- .build();
- try {
- CoreProto.GetEmaneModelConfigResponse response = blockingStub.getEmaneModelConfig(request);
- return protoToConfigGroups(response.getGroupsList());
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean setEmaneModelConfig(Integer id, String model, List options) throws IOException {
- Map config = configOptionListToMap(options);
- CoreProto.SetEmaneModelConfigRequest request = CoreProto.SetEmaneModelConfigRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(id)
- .setModel(model)
- .putAllConfig(config)
- .build();
- try {
- CoreProto.SetEmaneModelConfigResponse response = blockingStub.setEmaneModelConfig(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean isRunning() {
- return sessionState == SessionState.RUNTIME;
- }
-
- @Override
- public void saveSession(File file) throws IOException {
- CoreProto.SaveXmlRequest request = CoreProto.SaveXmlRequest.newBuilder()
- .setSessionId(sessionId)
- .build();
- try {
- CoreProto.SaveXmlResponse response = blockingStub.saveXml(request);
- try (PrintWriter writer = new PrintWriter(file)) {
- writer.print(response.getData());
- }
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public SessionOverview openSession(File file) throws IOException {
- try {
- byte[] encoded = Files.readAllBytes(file.toPath());
- String data = new String(encoded, StandardCharsets.UTF_8);
- CoreProto.OpenXmlRequest request = CoreProto.OpenXmlRequest.newBuilder()
- .setData(data)
- .build();
-
- CoreProto.OpenXmlResponse response = blockingStub.openXml(request);
- SessionOverview sessionOverview = new SessionOverview();
- sessionOverview.setId(response.getSessionId());
- return sessionOverview;
- } catch (IOException | StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public List getSessionConfig() throws IOException {
- CoreProto.GetSessionOptionsRequest request = CoreProto.GetSessionOptionsRequest.newBuilder()
- .setSessionId(sessionId)
- .build();
- try {
- CoreProto.GetSessionOptionsResponse response = blockingStub.getSessionOptions(request);
- return protoToConfigGroups(response.getGroupsList());
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean setSessionConfig(List configOptions) throws IOException {
- Map config = configOptionListToMap(configOptions);
- CoreProto.SetSessionOptionsRequest request = CoreProto.SetSessionOptionsRequest.newBuilder()
- .setSessionId(sessionId)
- .putAllConfig(config)
- .build();
- try {
- CoreProto.SetSessionOptionsResponse response = blockingStub.setSessionOptions(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean createNode(CoreNode node) throws IOException {
- CoreProto.Node protoNode = nodeToProto(node);
- CoreProto.AddNodeRequest request = CoreProto.AddNodeRequest.newBuilder()
- .setSessionId(sessionId)
- .setNode(protoNode)
- .build();
- try {
- blockingStub.addNode(request);
- return true;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public String nodeCommand(CoreNode node, String command) throws IOException {
- CoreProto.NodeCommandRequest request = CoreProto.NodeCommandRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .setCommand(command)
- .build();
- try {
- CoreProto.NodeCommandResponse response = blockingStub.nodeCommand(request);
- return response.getOutput();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean editNode(CoreNode node) throws IOException {
- CoreProto.Position position = CoreProto.Position.newBuilder()
- .setX(node.getPosition().getX().intValue())
- .setY(node.getPosition().getY().intValue())
- .build();
- CoreProto.EditNodeRequest request = CoreProto.EditNodeRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .setPosition(position)
- .build();
- try {
- CoreProto.EditNodeResponse response = blockingStub.editNode(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean deleteNode(CoreNode node) throws IOException {
- CoreProto.DeleteNodeRequest request = CoreProto.DeleteNodeRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .build();
- try {
- CoreProto.DeleteNodeResponse response = blockingStub.deleteNode(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean createLink(CoreLink link) throws IOException {
- CoreProto.Link.Builder builder = CoreProto.Link.newBuilder()
- .setTypeValue(link.getType());
- if (link.getNodeOne() != null) {
- builder.setNodeOneId(link.getNodeOne());
- }
- if (link.getNodeTwo() != null) {
- builder.setNodeTwoId(link.getNodeTwo());
- }
- if (link.getInterfaceOne() != null) {
- builder.setInterfaceOne(interfaceToProto(link.getInterfaceOne()));
- }
- if (link.getInterfaceTwo() != null) {
- builder.setInterfaceTwo(interfaceToProto(link.getInterfaceTwo()));
- }
- if (link.getOptions() != null) {
- builder.setOptions(linkOptionsToProto(link.getOptions()));
- }
- CoreProto.Link protoLink = builder.build();
- CoreProto.AddLinkRequest request = CoreProto.AddLinkRequest.newBuilder()
- .setSessionId(sessionId)
- .setLink(protoLink)
- .build();
- try {
- CoreProto.AddLinkResponse response = blockingStub.addLink(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean editLink(CoreLink link) throws IOException {
- CoreProto.EditLinkRequest.Builder builder = CoreProto.EditLinkRequest.newBuilder()
- .setSessionId(sessionId);
- if (link.getNodeOne() != null) {
- builder.setNodeOneId(link.getNodeOne());
- }
- if (link.getNodeTwo() != null) {
- builder.setNodeTwoId(link.getNodeTwo());
- }
- if (link.getInterfaceOne() != null) {
- builder.setInterfaceOneId(link.getInterfaceOne().getId());
- }
- if (link.getInterfaceTwo() != null) {
- builder.setInterfaceTwoId(link.getInterfaceTwo().getId());
- }
- if (link.getOptions() != null) {
- CoreProto.LinkOptions protoOptions = linkOptionsToProto(link.getOptions());
- builder.setOptions(protoOptions);
- }
- CoreProto.EditLinkRequest request = builder.build();
- try {
- CoreProto.EditLinkResponse response = blockingStub.editLink(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean createHook(Hook hook) throws IOException {
- CoreProto.Hook hookProto = CoreProto.Hook.newBuilder()
- .setStateValue(hook.getState())
- .setData(hook.getData())
- .setFile(hook.getFile())
- .build();
- CoreProto.AddHookRequest request = CoreProto.AddHookRequest.newBuilder()
- .setHook(hookProto)
- .build();
- try {
- CoreProto.AddHookResponse response = blockingStub.addHook(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public List getHooks() throws IOException {
- CoreProto.GetHooksRequest request = CoreProto.GetHooksRequest.newBuilder().setSessionId(sessionId).build();
- try {
- CoreProto.GetHooksResponse response = blockingStub.getHooks(request);
- List hooks = new ArrayList<>();
- for (CoreProto.Hook protoHook : response.getHooksList()) {
- Hook hook = new Hook();
- hook.setFile(protoHook.getFile());
- hook.setData(protoHook.getData());
- hook.setState(protoHook.getStateValue());
- hooks.add(hook);
- }
- return hooks;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public WlanConfig getWlanConfig(CoreNode node) throws IOException {
- CoreProto.GetWlanConfigRequest request = CoreProto.GetWlanConfigRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .build();
- try {
- CoreProto.GetWlanConfigResponse response = blockingStub.getWlanConfig(request);
- Map protoConfig = new HashMap<>();
- for (CoreProto.ConfigGroup group : response.getGroupsList()) {
- for (CoreProto.ConfigOption option : group.getOptionsList()) {
- protoConfig.put(option.getName(), option.getValue());
- }
- }
- WlanConfig config = new WlanConfig();
- config.setBandwidth(protoConfig.get("bandwidth"));
- config.setDelay(protoConfig.get("delay"));
- config.setError(protoConfig.get("error"));
- config.setJitter(protoConfig.get("jitter"));
- config.setRange(protoConfig.get("range"));
- return config;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean setWlanConfig(CoreNode node, WlanConfig config) throws IOException {
- Map protoConfig = new HashMap<>();
- protoConfig.put("bandwidth", config.getBandwidth());
- protoConfig.put("delay", config.getDelay());
- protoConfig.put("error", config.getError());
- protoConfig.put("jitter", config.getJitter());
- protoConfig.put("range", config.getRange());
- CoreProto.SetWlanConfigRequest request = CoreProto.SetWlanConfigRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .putAllConfig(protoConfig)
- .build();
- try {
- CoreProto.SetWlanConfigResponse response = blockingStub.setWlanConfig(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public String getTerminalCommand(CoreNode node) throws IOException {
- CoreProto.GetNodeTerminalRequest request = CoreProto.GetNodeTerminalRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .build();
- try {
- return blockingStub.getNodeTerminal(request).getTerminal();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public Map getMobilityConfigs() throws IOException {
- CoreProto.GetMobilityConfigsRequest request = CoreProto.GetMobilityConfigsRequest.newBuilder()
- .setSessionId(sessionId).build();
- try {
- CoreProto.GetMobilityConfigsResponse response = blockingStub.getMobilityConfigs(request);
-
- Map mobilityConfigs = new HashMap<>();
- for (Integer nodeId : response.getConfigsMap().keySet()) {
- CoreProto.GetMobilityConfigsResponse.MobilityConfig protoMobilityConfig = response.getConfigsMap()
- .get(nodeId);
- MobilityConfig mobilityConfig = new MobilityConfig();
- Map protoConfig = new HashMap<>();
- for (CoreProto.ConfigGroup group : protoMobilityConfig.getGroupsList()) {
- for (CoreProto.ConfigOption option : group.getOptionsList()) {
- protoConfig.put(option.getName(), option.getValue());
- }
- }
- mobilityConfig.setFile(protoConfig.get("file"));
- mobilityConfig.setRefresh(Integer.parseInt(protoConfig.get("refresh_ms")));
- mobilityConfig.setAutostart(protoConfig.get("autostart"));
- mobilityConfig.setLoop(protoConfig.get("loop"));
- mobilityConfig.setPauseScript(protoConfig.get("script_pause"));
- mobilityConfig.setStartScript(protoConfig.get("script_start"));
- mobilityConfig.setStopScript(protoConfig.get("script_stop"));
- mobilityConfig.setMap(protoConfig.get("map"));
- mobilityConfigs.put(nodeId, mobilityConfig);
- }
- return mobilityConfigs;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean setMobilityConfig(CoreNode node, MobilityConfig config) throws IOException {
- Map protoConfig = new HashMap<>();
- protoConfig.put("file", config.getFile());
- if (config.getRefresh() != null) {
- protoConfig.put("refresh_ms", config.getRefresh().toString());
- }
- protoConfig.put("autostart", config.getAutostart());
- protoConfig.put("loop", config.getLoop());
- protoConfig.put("map", config.getMap());
- protoConfig.put("script_pause", config.getPauseScript());
- protoConfig.put("script_start", config.getStartScript());
- protoConfig.put("script_stop", config.getStopScript());
- CoreProto.SetMobilityConfigRequest request = CoreProto.SetMobilityConfigRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .putAllConfig(protoConfig)
- .build();
- try {
- CoreProto.SetMobilityConfigResponse response = blockingStub.setMobilityConfig(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public MobilityConfig getMobilityConfig(CoreNode node) throws IOException {
- CoreProto.GetMobilityConfigRequest request = CoreProto.GetMobilityConfigRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .build();
- try {
- CoreProto.GetMobilityConfigResponse response = blockingStub.getMobilityConfig(request);
- Map protoConfig = new HashMap<>();
- for (CoreProto.ConfigGroup group : response.getGroupsList()) {
- for (CoreProto.ConfigOption option : group.getOptionsList()) {
- protoConfig.put(option.getName(), option.getValue());
- }
- }
- MobilityConfig config = new MobilityConfig();
- config.setFile(protoConfig.get("file"));
- config.setRefresh(Integer.parseInt(protoConfig.get("refresh_ms")));
- config.setAutostart(protoConfig.get("autostart"));
- config.setLoop(protoConfig.get("loop"));
- config.setPauseScript(protoConfig.get("script_pause"));
- config.setStartScript(protoConfig.get("script_start"));
- config.setStopScript(protoConfig.get("script_stop"));
- config.setMap(protoConfig.get("map"));
- return config;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean mobilityAction(CoreNode node, String action) throws IOException {
- CoreProto.MobilityActionRequest request = CoreProto.MobilityActionRequest.newBuilder()
- .setSessionId(sessionId)
- .setNodeId(node.getId())
- .setAction(CoreProto.MobilityAction.Enum.valueOf(action))
- .build();
- try {
- CoreProto.MobilityActionResponse response = blockingStub.mobilityAction(request);
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public LocationConfig getLocationConfig() throws IOException {
- CoreProto.GetSessionLocationRequest request = CoreProto.GetSessionLocationRequest.newBuilder()
- .setSessionId(sessionId)
- .build();
- try {
- CoreProto.GetSessionLocationResponse response = blockingStub.getSessionLocation(request);
- LocationConfig config = new LocationConfig();
- config.setScale((double) response.getScale());
- config.getPosition().setX((double) response.getPosition().getX());
- config.getPosition().setY((double) response.getPosition().getY());
- config.getPosition().setZ((double) response.getPosition().getZ());
- config.getLocation().setLatitude((double) response.getPosition().getLat());
- config.getLocation().setLongitude((double) response.getPosition().getLon());
- config.getLocation().setAltitude((double) response.getPosition().getAlt());
- return config;
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- @Override
- public boolean setLocationConfig(LocationConfig config) throws IOException {
- CoreProto.SetSessionLocationRequest.Builder builder = CoreProto.SetSessionLocationRequest.newBuilder()
- .setSessionId(sessionId);
- if (config.getScale() != null) {
- builder.setScale(config.getScale().floatValue());
- }
- CoreProto.Position.Builder positionBuilder = CoreProto.Position.newBuilder();
- if (config.getPosition().getX() != null) {
- positionBuilder.setX(config.getPosition().getX().intValue());
- }
- if (config.getPosition().getY() != null) {
- positionBuilder.setY(config.getPosition().getY().intValue());
- }
- if (config.getPosition().getZ() != null) {
- positionBuilder.setZ(config.getPosition().getZ().intValue());
- }
- if (config.getLocation().getLongitude() != null) {
- positionBuilder.setLon(config.getLocation().getLongitude().floatValue());
- }
- if (config.getLocation().getLatitude() != null) {
- positionBuilder.setLat(config.getLocation().getLatitude().floatValue());
- }
- if (config.getLocation().getAltitude() != null) {
- positionBuilder.setAlt(config.getLocation().getAltitude().floatValue());
- }
- try {
- CoreProto.SetSessionLocationResponse response = blockingStub.setSessionLocation(builder.build());
- return response.getResult();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-
- private void setupEventHandlers() throws IOException {
- logger.info("setting up event handlers");
- handlingEvents = true;
- try {
- CoreProto.EventsRequest request = CoreProto.EventsRequest.newBuilder()
- .setSessionId(sessionId)
- .build();
-
- Iterator events = blockingStub.events(request);
- executorService.submit(() -> {
- Context.CancellableContext context = Context.current().withCancellation();
- context.run(() -> {
- try {
- while (handlingEvents) {
- CoreProto.Event event = events.next();
- logger.info("handling event: {}", event);
- switch (event.getEventTypeCase()) {
- case SESSION_EVENT:
- handleSessionEvents(event.getSessionEvent());
- break;
- case NODE_EVENT:
- handleNodeEvents(event.getNodeEvent());
- break;
- case LINK_EVENT:
- handleLinkEvents(event.getLinkEvent());
- break;
- case CONFIG_EVENT:
- handleConfigEvents(event.getConfigEvent());
- break;
- case EXCEPTION_EVENT:
- handleExceptionEvents(event.getExceptionEvent());
- break;
- case FILE_EVENT:
- handleFileEvents(event.getFileEvent());
- break;
- default:
- logger.error("unknown event type: {}", event.getEventTypeCase());
- }
- }
- } catch (StatusRuntimeException ex) {
- logger.error("error handling session events", ex);
- } finally {
- context.cancel(null);
- context.close();
- }
- });
- });
- } catch (StatusRuntimeException ex) {
- throw new IOException("setup event handlers error", ex);
- }
- }
-
- private void handleSessionEvents(CoreProto.SessionEvent event) {
- logger.info("session event: {}", event);
- SessionState state = SessionState.get(event.getEvent());
- if (state == null) {
- logger.warn("unknown session event: {}", event.getEvent());
- return;
- }
-
- // session state event
- if (state.getValue() <= 6) {
- logger.info("event updating session state: {}", state);
- sessionState = state;
- // mobility script event
- } else if (state.getValue() <= 9) {
- Integer nodeId = event.getNodeId();
- String[] values = event.getData().split("\\s+");
- Integer start = Integer.parseInt(values[0].split("=")[1]);
- Integer end = Integer.parseInt(values[1].split("=")[1]);
- logger.info(String.format("node(%s) mobility event (%s) - start(%s) stop(%s)",
- nodeId, state, start, end));
- logger.info("all dialogs: {}", controller.getMobilityPlayerDialogs().keySet());
- MobilityPlayerDialog mobilityPlayerDialog = controller.getMobilityPlayerDialogs().get(nodeId);
- mobilityPlayerDialog.event(state, start, end);
- }
- }
-
- private void handleNodeEvents(CoreProto.NodeEvent event) {
- logger.info("node event: {}", event);
- CoreNode node = protoToNode(event.getNode());
- controller.getNetworkGraph().setNodeLocation(node);
- }
-
- private void handleExceptionEvents(CoreProto.ExceptionEvent event) {
- logger.info("exception event: {}", event);
- }
-
- private void handleConfigEvents(CoreProto.ConfigEvent event) {
- logger.info("config event: {}", event);
- }
-
- private void handleLinkEvents(CoreProto.LinkEvent event) {
- logger.info("link event: {}", event);
- CoreLink link = protoToLink(event.getLink());
- MessageFlags flag = MessageFlags.get(event.getMessageTypeValue());
- if (MessageFlags.DELETE == flag) {
- logger.info("delete");
- controller.getNetworkGraph().removeWirelessLink(link);
- } else if (MessageFlags.ADD == flag) {
- link.setLoaded(true);
- controller.getNetworkGraph().addLink(link);
- }
- controller.getNetworkGraph().getGraphViewer().repaint();
- }
-
- private void handleFileEvents(CoreProto.FileEvent event) {
- logger.info("file event: {}", event);
- }
-
- @Override
- public List getInterfaces() throws IOException {
- CoreProto.GetInterfacesRequest request = CoreProto.GetInterfacesRequest.newBuilder().build();
- try {
- CoreProto.GetInterfacesResponse response = blockingStub.getInterfaces(request);
- return response.getInterfacesList();
- } catch (StatusRuntimeException ex) {
- throw new IOException(ex);
- }
- }
-}
diff --git a/corefx/src/main/java/com/core/data/BridgeThroughput.java b/corefx/src/main/java/com/core/data/BridgeThroughput.java
deleted file mode 100644
index 167fb402..00000000
--- a/corefx/src/main/java/com/core/data/BridgeThroughput.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-@Data
-public class BridgeThroughput {
- private int node;
- private Double throughput;
-}
diff --git a/corefx/src/main/java/com/core/data/ConfigDataType.java b/corefx/src/main/java/com/core/data/ConfigDataType.java
deleted file mode 100644
index 3dd44864..00000000
--- a/corefx/src/main/java/com/core/data/ConfigDataType.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.core.data;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-public enum ConfigDataType {
- UINT8(1),
- UINT16(2),
- UINT32(3),
- UINT64(4),
- INT8(5),
- INT16(6),
- INT32(7),
- INT64(8),
- FLOAT(9),
- STRING(10),
- BOOL(11);
-
- private static final Map LOOKUP = new HashMap<>();
-
- static {
- Arrays.stream(ConfigDataType.values()).forEach(x -> LOOKUP.put(x.getValue(), x));
- }
-
- private final int value;
-
- ConfigDataType(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
-
- public static ConfigDataType get(int value) {
- return LOOKUP.get(value);
- }
-}
diff --git a/corefx/src/main/java/com/core/data/ConfigGroup.java b/corefx/src/main/java/com/core/data/ConfigGroup.java
deleted file mode 100644
index 9b45bdb7..00000000
--- a/corefx/src/main/java/com/core/data/ConfigGroup.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Data
-public class ConfigGroup {
- private String name;
- private List options = new ArrayList<>();
-}
diff --git a/corefx/src/main/java/com/core/data/ConfigOption.java b/corefx/src/main/java/com/core/data/ConfigOption.java
deleted file mode 100644
index 77af265e..00000000
--- a/corefx/src/main/java/com/core/data/ConfigOption.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Data
-public class ConfigOption {
- private String label;
- private String name;
- private String value;
- private Integer type;
- private List select = new ArrayList<>();
-}
diff --git a/corefx/src/main/java/com/core/data/CoreEvent.java b/corefx/src/main/java/com/core/data/CoreEvent.java
deleted file mode 100644
index 718097d8..00000000
--- a/corefx/src/main/java/com/core/data/CoreEvent.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-@Data
-public class CoreEvent {
- private Integer session;
- private Integer node;
- private String name;
- private Double time;
- private EventType eventType;
- private String data;
-}
diff --git a/corefx/src/main/java/com/core/data/CoreInterface.java b/corefx/src/main/java/com/core/data/CoreInterface.java
deleted file mode 100644
index 200aeabd..00000000
--- a/corefx/src/main/java/com/core/data/CoreInterface.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.core.data;
-
-import inet.ipaddr.IPAddress;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@NoArgsConstructor
-public class CoreInterface {
- private Integer id;
- private String name;
- private String mac;
- private IPAddress ip4;
- private IPAddress ip6;
-}
diff --git a/corefx/src/main/java/com/core/data/CoreLink.java b/corefx/src/main/java/com/core/data/CoreLink.java
deleted file mode 100644
index 8500c437..00000000
--- a/corefx/src/main/java/com/core/data/CoreLink.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.NoArgsConstructor;
-
-@Data
-@NoArgsConstructor
-@EqualsAndHashCode(onlyExplicitlyIncluded = true)
-public class CoreLink {
- @EqualsAndHashCode.Include
- private Integer id;
- private Float weight = 1.0f;
- private boolean loaded = true;
- private double throughput;
- private boolean visible = true;
- private Integer messageType;
- private Integer type = LinkTypes.WIRED.getValue();
- private Integer nodeOne;
- private Integer nodeTwo;
- private CoreInterface interfaceOne;
- private CoreInterface interfaceTwo;
- private CoreLinkOptions options = new CoreLinkOptions();
-
- public CoreLink(Integer id) {
- this.id = id;
- this.weight = (float) id;
- this.loaded = false;
- }
-
- public boolean isWireless() {
- return interfaceOne == null && interfaceTwo == null;
- }
-}
diff --git a/corefx/src/main/java/com/core/data/CoreLinkOptions.java b/corefx/src/main/java/com/core/data/CoreLinkOptions.java
deleted file mode 100644
index 036b5e20..00000000
--- a/corefx/src/main/java/com/core/data/CoreLinkOptions.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@NoArgsConstructor
-public class CoreLinkOptions {
- private String opaque;
- private Integer session;
- private Integer jitter;
- private Integer key;
- private Integer mburst;
- private Integer mer;
- private Double per;
- private Integer bandwidth;
- private Integer burst;
- private Integer delay;
- private Integer dup;
- private Boolean unidirectional;
-}
diff --git a/corefx/src/main/java/com/core/data/CoreNode.java b/corefx/src/main/java/com/core/data/CoreNode.java
deleted file mode 100644
index 042355d3..00000000
--- a/corefx/src/main/java/com/core/data/CoreNode.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.core.data;
-
-import com.core.graph.RadioIcon;
-import com.core.utils.IconUtils;
-import edu.uci.ics.jung.visualization.LayeredIcon;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.NoArgsConstructor;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.HashSet;
-import java.util.Set;
-
-@Data
-@NoArgsConstructor
-@EqualsAndHashCode(onlyExplicitlyIncluded = true)
-public class CoreNode {
- private static final Logger logger = LogManager.getLogger();
- @EqualsAndHashCode.Include
- private Integer id;
- private String name;
- private Integer type;
- private String model;
- private Position position = new Position();
- private Set services = new HashSet<>();
- private String emane;
- private String url;
- private NodeType nodeType;
- private String icon;
- private String image;
- private boolean loaded = true;
- private LayeredIcon graphIcon;
- private RadioIcon radioIcon = new RadioIcon();
-
- public CoreNode(Integer id) {
- this.id = id;
- this.name = String.format("Node%s", this.id);
- this.loaded = false;
- }
-
- public void setNodeType(NodeType nodeType) {
- type = nodeType.getValue();
- model = nodeType.getModel();
- icon = nodeType.getIcon();
- if (icon.startsWith("file:")) {
- graphIcon = IconUtils.getExternalLayeredIcon(icon);
- } else {
- graphIcon = IconUtils.getLayeredIcon(icon);
- }
- graphIcon.add(radioIcon);
- this.nodeType = nodeType;
- }
-}
diff --git a/corefx/src/main/java/com/core/data/CoreService.java b/corefx/src/main/java/com/core/data/CoreService.java
deleted file mode 100644
index c33aebed..00000000
--- a/corefx/src/main/java/com/core/data/CoreService.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Data
-public class CoreService {
- private List executables = new ArrayList<>();
- private List dependencies = new ArrayList<>();
- private List dirs = new ArrayList<>();
- private List configs = new ArrayList<>();
- private List startup = new ArrayList<>();
- private List validate = new ArrayList<>();
- private String validationMode;
- private String validationTimer;
- private List shutdown = new ArrayList<>();
- private String meta;
-}
diff --git a/corefx/src/main/java/com/core/data/EventType.java b/corefx/src/main/java/com/core/data/EventType.java
deleted file mode 100644
index 487de4c1..00000000
--- a/corefx/src/main/java/com/core/data/EventType.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.core.data;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-public enum EventType {
- NONE(0),
- DEFINITION_STATE(1),
- CONFIGURATION_STATE(2),
- INSTANTIATION_STATE(3),
- RUNTIME_STATE(4),
- DATACOLLECT_STATE(5),
- SHUTDOWN_STATE(6),
- START(7),
- STOP(8),
- PAUSE(9),
- RESTART(10),
- FILE_OPEN(11),
- FILE_SAVE(12),
- SCHEDULED(13),
- RECONFIGURE(14),
- INSTANTIATION_COMPLETE(15);
-
- private static final Map LOOKUP = new HashMap<>();
-
- static {
- Arrays.stream(EventType.values()).forEach(x -> LOOKUP.put(x.getValue(), x));
- }
-
- private final int value;
-
- EventType(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
-
- public static EventType get(int value) {
- return LOOKUP.get(value);
- }
-}
diff --git a/corefx/src/main/java/com/core/data/Hook.java b/corefx/src/main/java/com/core/data/Hook.java
deleted file mode 100644
index 652976b0..00000000
--- a/corefx/src/main/java/com/core/data/Hook.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-@Data
-public class Hook {
- private String file;
- private Integer state;
- private String stateDisplay;
- private String data;
-}
diff --git a/corefx/src/main/java/com/core/data/InterfaceThroughput.java b/corefx/src/main/java/com/core/data/InterfaceThroughput.java
deleted file mode 100644
index 8df86501..00000000
--- a/corefx/src/main/java/com/core/data/InterfaceThroughput.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-@Data
-public class InterfaceThroughput {
- private int node;
- private int nodeInterface;
- private double throughput;
-}
diff --git a/corefx/src/main/java/com/core/data/LinkTypes.java b/corefx/src/main/java/com/core/data/LinkTypes.java
deleted file mode 100644
index 4bfaf1dc..00000000
--- a/corefx/src/main/java/com/core/data/LinkTypes.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.core.data;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public enum LinkTypes {
- WIRELESS(0),
- WIRED(1);
-
- private static final Map LOOKUP = new HashMap<>();
-
- static {
- for (LinkTypes state : LinkTypes.values()) {
- LOOKUP.put(state.getValue(), state);
- }
- }
-
- private final int value;
-
- LinkTypes(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return this.value;
- }
-
- public static LinkTypes get(int value) {
- return LOOKUP.get(value);
- }
-}
diff --git a/corefx/src/main/java/com/core/data/Location.java b/corefx/src/main/java/com/core/data/Location.java
deleted file mode 100644
index f5c399c4..00000000
--- a/corefx/src/main/java/com/core/data/Location.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-@Data
-public class Location {
- private Double latitude = 0.0;
- private Double longitude = 0.0;
- private Double altitude = 0.0;
-}
diff --git a/corefx/src/main/java/com/core/data/LocationConfig.java b/corefx/src/main/java/com/core/data/LocationConfig.java
deleted file mode 100644
index 10ba11ac..00000000
--- a/corefx/src/main/java/com/core/data/LocationConfig.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-@Data
-public class LocationConfig {
- private Position position = new Position();
- private Location location = new Location();
- private Double scale;
-}
diff --git a/corefx/src/main/java/com/core/data/MessageFlags.java b/corefx/src/main/java/com/core/data/MessageFlags.java
deleted file mode 100644
index 6272099b..00000000
--- a/corefx/src/main/java/com/core/data/MessageFlags.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.core.data;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public enum MessageFlags {
- ADD(1),
- DELETE(2),
- CRI(4),
- LOCAL(8),
- STRING(16),
- TEXT(32),
- TTY(64);
-
- private static final Map LOOKUP = new HashMap<>();
-
- static {
- for (MessageFlags state : MessageFlags.values()) {
- LOOKUP.put(state.getValue(), state);
- }
- }
-
- private final int value;
-
- MessageFlags(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return this.value;
- }
-
- public static MessageFlags get(int value) {
- return LOOKUP.get(value);
- }
-}
diff --git a/corefx/src/main/java/com/core/data/MobilityConfig.java b/corefx/src/main/java/com/core/data/MobilityConfig.java
deleted file mode 100644
index f16de6ff..00000000
--- a/corefx/src/main/java/com/core/data/MobilityConfig.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-import java.io.File;
-
-@Data
-public class MobilityConfig {
- private String file;
- private File scriptFile;
- private Integer refresh;
- private String loop;
- private String autostart;
- private String map;
- private String startScript;
- private String pauseScript;
- private String stopScript;
-}
diff --git a/corefx/src/main/java/com/core/data/NodeType.java b/corefx/src/main/java/com/core/data/NodeType.java
deleted file mode 100644
index e9743ea8..00000000
--- a/corefx/src/main/java/com/core/data/NodeType.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package com.core.data;
-
-import javafx.scene.control.Label;
-import javafx.scene.image.ImageView;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
-
-@Data
-@EqualsAndHashCode(onlyExplicitlyIncluded = true)
-public class NodeType {
- private static final Logger logger = LogManager.getLogger();
- private static final AtomicInteger idGenerator = new AtomicInteger(0);
- private static final Map ID_LOOKUP = new HashMap<>();
- public static final int DEFAULT = 0;
- 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;
- @EqualsAndHashCode.Include
- private final int id;
- private final int value;
- private final Set services = new TreeSet<>();
- private String display;
- private String model;
- private String icon;
-
- static {
- 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(DOCKER, null, "DockerNode", "/icons/dockernode-100.png"));
- add(new NodeType(LXC, null, "LxcNode", "/icons/lxcnode-100.png"));
- }
-
-
- public NodeType(int value, String model, String display, String icon) {
- this.id = idGenerator.incrementAndGet();
- this.value = value;
- this.model = model;
- this.display = display;
- this.icon = icon;
- }
-
- public Label createLabel(int size) {
- ImageView labelIcon = new ImageView(icon);
- labelIcon.setFitWidth(size);
- labelIcon.setFitHeight(size);
- Label label = new Label(display, labelIcon);
- label.setUserData(id);
- return label;
- }
-
- public static boolean isDefault(NodeType nodeType) {
- return nodeType.value == DEFAULT || nodeType.value == DOCKER || nodeType.value == LXC;
- }
-
- public static void add(NodeType nodeType) {
- ID_LOOKUP.put(nodeType.getId(), nodeType);
- }
-
- public static void remove(NodeType nodeType) {
- ID_LOOKUP.remove(nodeType.getId());
- }
-
- public static NodeType get(Integer id) {
- return ID_LOOKUP.get(id);
- }
-
- public static Collection getAll() {
- return ID_LOOKUP.values();
- }
-
- public static NodeType find(Integer type, String model) {
- return ID_LOOKUP.values().stream()
- .filter(nodeType -> {
- boolean sameType = nodeType.getValue() == type;
- boolean sameModel = true;
- if (model != null && !model.isEmpty()) {
- sameModel = model.equals(nodeType.getModel());
- }
- return sameType && sameModel;
- })
- .findFirst().orElse(null);
- }
-}
diff --git a/corefx/src/main/java/com/core/data/Position.java b/corefx/src/main/java/com/core/data/Position.java
deleted file mode 100644
index c5bfa728..00000000
--- a/corefx/src/main/java/com/core/data/Position.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@NoArgsConstructor
-public class Position {
- private Double x;
- private Double y;
- private Double z;
-}
diff --git a/corefx/src/main/java/com/core/data/ServiceFile.java b/corefx/src/main/java/com/core/data/ServiceFile.java
deleted file mode 100644
index f30efcd0..00000000
--- a/corefx/src/main/java/com/core/data/ServiceFile.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.core.data;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@AllArgsConstructor
-@NoArgsConstructor
-public class ServiceFile {
- private String name;
- private String data;
-}
diff --git a/corefx/src/main/java/com/core/data/Session.java b/corefx/src/main/java/com/core/data/Session.java
deleted file mode 100644
index e12ddeb9..00000000
--- a/corefx/src/main/java/com/core/data/Session.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Data
-@NoArgsConstructor
-public class Session {
- private Integer id;
- private SessionState state;
- private List nodes = new ArrayList<>();
- private List links = new ArrayList<>();
-}
diff --git a/corefx/src/main/java/com/core/data/SessionOverview.java b/corefx/src/main/java/com/core/data/SessionOverview.java
deleted file mode 100644
index 47773338..00000000
--- a/corefx/src/main/java/com/core/data/SessionOverview.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@NoArgsConstructor
-public class SessionOverview {
- private Integer id;
- private Integer state;
- private Integer nodes = 0;
- private String url;
-}
diff --git a/corefx/src/main/java/com/core/data/SessionState.java b/corefx/src/main/java/com/core/data/SessionState.java
deleted file mode 100644
index c9e92904..00000000
--- a/corefx/src/main/java/com/core/data/SessionState.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.core.data;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public enum SessionState {
- DEFINITION(1),
- CONFIGURATION(2),
- INSTANTIATION(3),
- RUNTIME(4),
- DATA_COLLECT(5),
- SHUTDOWN(6),
- START(7),
- STOP(8),
- PAUSE(9);
-
- private static final Map LOOKUP = new HashMap<>();
-
- static {
- for (SessionState state : SessionState.values()) {
- LOOKUP.put(state.getValue(), state);
- }
- }
-
- private final int value;
-
- SessionState(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return this.value;
- }
-
- public static SessionState get(int value) {
- return LOOKUP.get(value);
- }
-}
diff --git a/corefx/src/main/java/com/core/data/Throughputs.java b/corefx/src/main/java/com/core/data/Throughputs.java
deleted file mode 100644
index c02a7f6f..00000000
--- a/corefx/src/main/java/com/core/data/Throughputs.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Data
-public class Throughputs {
- private List interfaces = new ArrayList<>();
- private List bridges = new ArrayList<>();
-}
diff --git a/corefx/src/main/java/com/core/data/WlanConfig.java b/corefx/src/main/java/com/core/data/WlanConfig.java
deleted file mode 100644
index 26048d73..00000000
--- a/corefx/src/main/java/com/core/data/WlanConfig.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.core.data;
-
-import lombok.Data;
-
-@Data
-public class WlanConfig {
- private String range;
- private String bandwidth;
- private String jitter;
- private String delay;
- private String error;
-}
diff --git a/corefx/src/main/java/com/core/datavis/CoreGraph.java b/corefx/src/main/java/com/core/datavis/CoreGraph.java
deleted file mode 100644
index f5a0c0fd..00000000
--- a/corefx/src/main/java/com/core/datavis/CoreGraph.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.core.datavis;
-
-import lombok.Data;
-
-@Data
-public class CoreGraph {
- private String title;
- private CoreGraphAxis xAxis;
- private CoreGraphAxis yAxis;
- private GraphType graphType;
-}
diff --git a/corefx/src/main/java/com/core/datavis/CoreGraphAxis.java b/corefx/src/main/java/com/core/datavis/CoreGraphAxis.java
deleted file mode 100644
index 8631f3a1..00000000
--- a/corefx/src/main/java/com/core/datavis/CoreGraphAxis.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.core.datavis;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@AllArgsConstructor
-@NoArgsConstructor
-public class CoreGraphAxis {
- private String label;
- private Double lower;
- private Double upper;
- private Double tick;
-}
diff --git a/corefx/src/main/java/com/core/datavis/CoreGraphData.java b/corefx/src/main/java/com/core/datavis/CoreGraphData.java
deleted file mode 100644
index ff0d4c77..00000000
--- a/corefx/src/main/java/com/core/datavis/CoreGraphData.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.core.datavis;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@AllArgsConstructor
-@NoArgsConstructor
-public class CoreGraphData {
- private String name;
- private Double x;
- private Double y;
- private Double weight;
-}
diff --git a/corefx/src/main/java/com/core/datavis/CoreGraphWrapper.java b/corefx/src/main/java/com/core/datavis/CoreGraphWrapper.java
deleted file mode 100644
index eae92e8f..00000000
--- a/corefx/src/main/java/com/core/datavis/CoreGraphWrapper.java
+++ /dev/null
@@ -1,157 +0,0 @@
-package com.core.datavis;
-
-import javafx.scene.chart.*;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-public class CoreGraphWrapper {
- private static final Logger logger = LogManager.getLogger();
- private final GraphType graphType;
- private PieChart pieChart;
- private final Map pieData = new HashMap<>();
- private BarChart barChart;
- private final Map> barMap = new HashMap<>();
- private XYChart xyChart;
- private final XYChart.Series series = new XYChart.Series<>();
- private final XYChart.Series barSeries = new XYChart.Series<>();
- private AtomicInteger timeValue = new AtomicInteger(0);
-
- public CoreGraphWrapper(CoreGraph coreGraph) {
- graphType = coreGraph.getGraphType();
- createChart(coreGraph);
- }
-
- public Chart getChart() {
- switch (graphType) {
- case PIE:
- return pieChart;
- case BAR:
- return barChart;
- default:
- return xyChart;
- }
- }
-
- public void add(CoreGraphData coreGraphData) {
- switch (graphType) {
- case PIE:
- case BAR:
- add(coreGraphData.getName(), coreGraphData.getY());
- break;
- case TIME:
- add(coreGraphData.getY());
- break;
- case BUBBLE:
- add(coreGraphData.getX(), coreGraphData.getY(), coreGraphData.getWeight());
- break;
- default:
- add(coreGraphData.getX(), coreGraphData.getY());
- }
- }
-
- public void add(String name, double value) {
- if (GraphType.PIE == graphType) {
- PieChart.Data data = pieData.computeIfAbsent(name, x -> {
- PieChart.Data newData = new PieChart.Data(x, value);
- pieChart.getData().add(newData);
- return newData;
- });
- data.setPieValue(value);
- } else {
- XYChart.Data data = barMap.computeIfAbsent(name, x -> {
- XYChart.Data newData = new XYChart.Data<>(name, value);
- barSeries.getData().add(newData);
- return newData;
- });
- data.setYValue(value);
- }
- }
-
- public void add(Number y) {
- series.getData().add(new XYChart.Data<>(timeValue.getAndIncrement(), y));
- }
-
- public void add(Number x, Number y) {
- series.getData().add(new XYChart.Data<>(x, y));
- }
-
- public void add(Number x, Number y, Number weight) {
- series.getData().add(new XYChart.Data<>(x, y, weight));
- }
-
- private NumberAxis getAxis(CoreGraphAxis graphAxis) {
- return new NumberAxis(graphAxis.getLabel(), graphAxis.getLower(),
- graphAxis.getUpper(), graphAxis.getTick());
- }
-
- private void createChart(CoreGraph coreGraph) {
- NumberAxis xAxis;
- NumberAxis yAxis;
-
- switch (coreGraph.getGraphType()) {
- case AREA:
- xAxis = getAxis(coreGraph.getXAxis());
- yAxis = getAxis(coreGraph.getYAxis());
- xyChart = new AreaChart<>(xAxis, yAxis);
- xyChart.setTitle(coreGraph.getTitle());
- xyChart.setLegendVisible(false);
- xyChart.getData().add(series);
- break;
- case TIME:
- xAxis = new NumberAxis();
- xAxis.setLabel(coreGraph.getXAxis().getLabel());
- xAxis.setTickUnit(1);
- xAxis.setLowerBound(0);
- yAxis = getAxis(coreGraph.getYAxis());
- xyChart = new LineChart<>(xAxis, yAxis);
- xyChart.setTitle(coreGraph.getTitle());
- xyChart.setLegendVisible(false);
- xyChart.getData().add(series);
- break;
- case LINE:
- xAxis = getAxis(coreGraph.getXAxis());
- yAxis = getAxis(coreGraph.getYAxis());
- xyChart = new LineChart<>(xAxis, yAxis);
- xyChart.setTitle(coreGraph.getTitle());
- xyChart.setLegendVisible(false);
- xyChart.getData().add(series);
- break;
- case BUBBLE:
- xAxis = getAxis(coreGraph.getXAxis());
- yAxis = getAxis(coreGraph.getYAxis());
- xyChart = new BubbleChart<>(xAxis, yAxis);
- xyChart.setTitle(coreGraph.getTitle());
- xyChart.setLegendVisible(false);
- xyChart.getData().add(series);
- break;
- case SCATTER:
- xAxis = getAxis(coreGraph.getXAxis());
- yAxis = getAxis(coreGraph.getYAxis());
- xyChart = new ScatterChart<>(xAxis, yAxis);
- xyChart.setTitle(coreGraph.getTitle());
- xyChart.setLegendVisible(false);
- xyChart.getData().add(series);
- break;
- case PIE:
- pieChart = new PieChart();
- pieChart.setTitle(coreGraph.getTitle());
- break;
- case BAR:
- CategoryAxis categoryAxis = new CategoryAxis();
- categoryAxis.setLabel(coreGraph.getXAxis().getLabel());
- yAxis = getAxis(coreGraph.getYAxis());
- barChart = new BarChart<>(categoryAxis, yAxis);
- barChart.setLegendVisible(false);
- barChart.setTitle(coreGraph.getTitle());
- barChart.getData().add(barSeries);
- break;
- default:
- throw new IllegalArgumentException(String.format("unknown graph type: %s",
- coreGraph.getGraphType()));
- }
- }
-}
diff --git a/corefx/src/main/java/com/core/datavis/GraphType.java b/corefx/src/main/java/com/core/datavis/GraphType.java
deleted file mode 100644
index 7609eee3..00000000
--- a/corefx/src/main/java/com/core/datavis/GraphType.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.core.datavis;
-
-public enum GraphType {
- PIE,
- LINE,
- TIME,
- AREA,
- BAR,
- SCATTER,
- BUBBLE
-}
diff --git a/corefx/src/main/java/com/core/graph/AbstractNodeContextMenu.java b/corefx/src/main/java/com/core/graph/AbstractNodeContextMenu.java
deleted file mode 100644
index d04097c2..00000000
--- a/corefx/src/main/java/com/core/graph/AbstractNodeContextMenu.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.core.graph;
-
-import com.core.Controller;
-import com.core.data.CoreNode;
-import javafx.event.ActionEvent;
-import javafx.event.EventHandler;
-import javafx.scene.control.MenuItem;
-
-abstract class AbstractNodeContextMenu extends GraphContextMenu {
- final CoreNode coreNode;
-
- AbstractNodeContextMenu(Controller controller, CoreNode coreNode) {
- super(controller);
- this.coreNode = coreNode;
- }
-
- void addMenuItem(String text, EventHandler handler) {
- MenuItem menuItem = new MenuItem(text);
- menuItem.setOnAction(handler);
- getItems().add(menuItem);
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/BackgroundPaintable.java b/corefx/src/main/java/com/core/graph/BackgroundPaintable.java
deleted file mode 100644
index b0cfe6a3..00000000
--- a/corefx/src/main/java/com/core/graph/BackgroundPaintable.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.core.graph;
-
-import edu.uci.ics.jung.visualization.Layer;
-import edu.uci.ics.jung.visualization.VisualizationViewer;
-
-import javax.imageio.ImageIO;
-import javax.swing.*;
-import java.awt.*;
-import java.awt.geom.AffineTransform;
-import java.io.IOException;
-import java.nio.file.Paths;
-
-public class BackgroundPaintable implements VisualizationViewer.Paintable {
- private final ImageIcon imageIcon;
- private final VisualizationViewer vv;
- private final String imagePath;
-
- public BackgroundPaintable(String imagePath, VisualizationViewer vv) throws IOException {
- this.imagePath = imagePath;
- Image image = ImageIO.read(Paths.get(imagePath).toFile());
- imageIcon = new ImageIcon(image);
- this.vv = vv;
- }
-
- public String getImage() {
- return imagePath;
- }
-
- @Override
- public void paint(Graphics g) {
- Graphics2D g2d = (Graphics2D) g;
- AffineTransform oldXform = g2d.getTransform();
- AffineTransform lat =
- vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).getTransform();
- AffineTransform vat =
- vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).getTransform();
- AffineTransform at = new AffineTransform();
- at.concatenate(g2d.getTransform());
- at.concatenate(vat);
- at.concatenate(lat);
- g2d.setTransform(at);
- g.drawImage(imageIcon.getImage(), 0, 0,
- imageIcon.getIconWidth(), imageIcon.getIconHeight(), vv);
- g2d.setTransform(oldXform);
- }
-
- @Override
- public boolean useTransform() {
- return false;
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/CoreAddresses.java b/corefx/src/main/java/com/core/graph/CoreAddresses.java
deleted file mode 100644
index ee1daa1a..00000000
--- a/corefx/src/main/java/com/core/graph/CoreAddresses.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.core.graph;
-
-import com.core.data.CoreInterface;
-import inet.ipaddr.IPAddress;
-import inet.ipaddr.IPAddressString;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.Queue;
-import java.util.Set;
-import java.util.concurrent.LinkedBlockingQueue;
-
-public class CoreAddresses {
- private static final String ADDRESS = "10.0.0.0/24";
- private static final Logger logger = LogManager.getLogger();
- private IPAddress currentSubnet = new IPAddressString(ADDRESS).getAddress().toPrefixBlock();
- private Queue deleted = new LinkedBlockingQueue<>();
- private Set usedSubnets = new HashSet<>();
-
- public void usedAddress(IPAddress address) {
- logger.info("adding used address: {} - {}", address, address.toPrefixBlock());
- usedSubnets.add(address.toPrefixBlock());
- logger.info("used subnets: {}", usedSubnets);
- }
-
- public void reuseSubnet(IPAddress subnet) {
- deleted.add(subnet);
- }
-
- public IPAddress nextSubnet() {
- logger.info("getting next subnet: {}", currentSubnet);
- // skip existing subnets, when loaded from file
- while (usedSubnets.contains(currentSubnet)) {
- currentSubnet = currentSubnet.incrementBoundary(1).toPrefixBlock();
- }
-
- // re-use any deleted subnets
- IPAddress next = deleted.poll();
- if (next == null) {
- next = currentSubnet;
- currentSubnet = currentSubnet.incrementBoundary(1).toPrefixBlock();
- }
- return next;
- }
-
- public IPAddress findSubnet(Set interfaces) {
- IPAddress subnet;
- logger.info("finding subnet from interfaces: {}", interfaces);
- if (interfaces.isEmpty()) {
- subnet = nextSubnet();
- } else {
- IPAddress maxAddress = getMaxAddress(interfaces);
- subnet = maxAddress.toPrefixBlock();
- }
- return subnet;
- }
-
- private IPAddress getMaxAddress(Set interfaces) {
- return interfaces.stream()
- .map(CoreInterface::getIp4)
- .max(Comparator.comparingInt(x -> x.toIPv4().intValue()))
- .orElseGet(() -> currentSubnet);
- }
-
- public void reset() {
- deleted.clear();
- usedSubnets.clear();
- currentSubnet = new IPAddressString(ADDRESS).getAddress().toPrefixBlock();
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/CoreAnnotatingGraphMousePlugin.java b/corefx/src/main/java/com/core/graph/CoreAnnotatingGraphMousePlugin.java
deleted file mode 100644
index 6cbd1bf8..00000000
--- a/corefx/src/main/java/com/core/graph/CoreAnnotatingGraphMousePlugin.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.core.graph;
-
-import com.core.Controller;
-import edu.uci.ics.jung.visualization.RenderContext;
-import edu.uci.ics.jung.visualization.VisualizationViewer;
-import edu.uci.ics.jung.visualization.annotations.AnnotatingGraphMousePlugin;
-import edu.uci.ics.jung.visualization.annotations.Annotation;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.MouseEvent;
-import java.awt.geom.Point2D;
-import java.awt.geom.RectangularShape;
-
-public class CoreAnnotatingGraphMousePlugin extends AnnotatingGraphMousePlugin {
- private static final Logger logger = LogManager.getLogger();
- private final Controller controller;
- private JFrame frame = new JFrame();
-
- public CoreAnnotatingGraphMousePlugin(Controller controller, RenderContext renderContext) {
- super(renderContext);
- this.controller = controller;
- frame.setVisible(false);
- frame.setAlwaysOnTop(true);
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- VisualizationViewer vv = (VisualizationViewer) e.getSource();
- if (e.isPopupTrigger()) {
- frame.setLocationRelativeTo(vv);
- String annotationString = JOptionPane.showInputDialog(frame, "Annotation:",
- "Annotation Label", JOptionPane.PLAIN_MESSAGE);
- if (annotationString != null && annotationString.length() > 0) {
- Point2D p = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(this.down);
- Annotation annotation = new Annotation(annotationString, this.layer,
- this.annotationColor, this.fill, p);
- this.annotationManager.add(this.layer, annotation);
- }
- } else if (e.getModifiers() == this.modifiers && this.down != null) {
- Point2D out = e.getPoint();
- RectangularShape arect = (RectangularShape) this.rectangularShape.clone();
- arect.setFrameFromDiagonal(this.down, out);
- Shape s = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(arect);
- Annotation annotation = new Annotation(s, this.layer, this.annotationColor, this.fill, out);
- this.annotationManager.add(this.layer, annotation);
- }
-
- this.down = null;
- vv.removePostRenderPaintable(this.lensPaintable);
- vv.repaint();
- }
-
-
-}
diff --git a/corefx/src/main/java/com/core/graph/CoreEditingModalGraphMouse.java b/corefx/src/main/java/com/core/graph/CoreEditingModalGraphMouse.java
deleted file mode 100644
index 9d80183e..00000000
--- a/corefx/src/main/java/com/core/graph/CoreEditingModalGraphMouse.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.core.graph;
-
-import com.core.Controller;
-import com.google.common.base.Supplier;
-import edu.uci.ics.jung.visualization.RenderContext;
-import edu.uci.ics.jung.visualization.control.EditingModalGraphMouse;
-
-public class CoreEditingModalGraphMouse extends EditingModalGraphMouse {
- public CoreEditingModalGraphMouse(Controller controller, NetworkGraph networkGraph,
- RenderContext rc, Supplier vertexFactory, Supplier edgeFactory) {
- super(rc, vertexFactory, edgeFactory);
- remove(annotatingPlugin);
- remove(popupEditingPlugin);
- annotatingPlugin = new CoreAnnotatingGraphMousePlugin<>(controller, rc);
- popupEditingPlugin = new CorePopupGraphMousePlugin<>(controller, networkGraph, vertexFactory, edgeFactory);
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/CoreObservableGraph.java b/corefx/src/main/java/com/core/graph/CoreObservableGraph.java
deleted file mode 100644
index cbf678f0..00000000
--- a/corefx/src/main/java/com/core/graph/CoreObservableGraph.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.core.graph;
-
-import edu.uci.ics.jung.graph.Graph;
-import edu.uci.ics.jung.graph.ObservableGraph;
-import edu.uci.ics.jung.graph.util.EdgeType;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-public class CoreObservableGraph extends ObservableGraph {
- private static final Logger logger = LogManager.getLogger();
-
- public CoreObservableGraph(Graph graph) {
- super(graph);
- }
-
- @Override
- public boolean addEdge(E e, V v1, V v2, EdgeType edgeType) {
- if (v1 == null || v2 == null) {
- return false;
- }
- return super.addEdge(e, v1, v2, edgeType);
- }
-
- @Override
- public boolean addEdge(E e, V v1, V v2) {
- if (v1 == null || v2 == null) {
- return false;
- }
- return super.addEdge(e, v1, v2);
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/CorePopupGraphMousePlugin.java b/corefx/src/main/java/com/core/graph/CorePopupGraphMousePlugin.java
deleted file mode 100644
index bd46f4c3..00000000
--- a/corefx/src/main/java/com/core/graph/CorePopupGraphMousePlugin.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.core.graph;
-
-import com.core.Controller;
-import com.core.data.CoreLink;
-import com.core.data.CoreNode;
-import com.core.data.NodeType;
-import com.google.common.base.Supplier;
-import edu.uci.ics.jung.algorithms.layout.GraphElementAccessor;
-import edu.uci.ics.jung.algorithms.layout.Layout;
-import edu.uci.ics.jung.visualization.control.EditingPopupGraphMousePlugin;
-import javafx.application.Platform;
-import javafx.scene.control.ContextMenu;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.awt.event.MouseEvent;
-import java.awt.geom.Point2D;
-
-public class CorePopupGraphMousePlugin extends EditingPopupGraphMousePlugin {
- private static final Logger logger = LogManager.getLogger();
- private final Controller controller;
- private final NetworkGraph networkGraph;
- private final Layout graphLayout;
- private final GraphElementAccessor pickSupport;
-
- public CorePopupGraphMousePlugin(Controller controller, NetworkGraph networkGraph,
- Supplier vertexFactory, Supplier edgeFactory) {
- super(vertexFactory, edgeFactory);
- this.controller = controller;
- this.networkGraph = networkGraph;
- graphLayout = this.networkGraph.getGraphLayout();
- pickSupport = this.networkGraph.getGraphViewer().getPickSupport();
- }
-
- @Override
- protected void handlePopup(MouseEvent e) {
- logger.info("showing popup!");
- final Point2D p = e.getPoint();
-
- final CoreNode node = pickSupport.getVertex(graphLayout, p.getX(), p.getY());
- final CoreLink link = pickSupport.getEdge(graphLayout, p.getX(), p.getY());
-
- final ContextMenu contextMenu;
- if (node != null) {
- contextMenu = handleNodeContext(node);
- } else if (link != null) {
- contextMenu = new LinkContextMenu(controller, link);
- } else {
- contextMenu = new ContextMenu();
- }
-
- if (!contextMenu.getItems().isEmpty()) {
- logger.info("showing context menu");
- Platform.runLater(() -> contextMenu.show(controller.getWindow(),
- e.getXOnScreen(), e.getYOnScreen()));
- }
- }
-
- private ContextMenu handleNodeContext(final CoreNode node) {
- ContextMenu contextMenu = new ContextMenu();
- switch (node.getType()) {
- case NodeType.DEFAULT:
- case NodeType.DOCKER:
- case NodeType.LXC:
- contextMenu = new NodeContextMenu(controller, node);
- break;
- case NodeType.WLAN:
- contextMenu = new WlanContextMenu(controller, node);
- break;
- 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;
- }
-
- return contextMenu;
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/CoreVertexLabelRenderer.java b/corefx/src/main/java/com/core/graph/CoreVertexLabelRenderer.java
deleted file mode 100644
index 25c49fa3..00000000
--- a/corefx/src/main/java/com/core/graph/CoreVertexLabelRenderer.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.core.graph;
-
-import edu.uci.ics.jung.visualization.renderers.DefaultVertexLabelRenderer;
-
-import javax.swing.*;
-import javax.swing.border.EmptyBorder;
-import java.awt.*;
-
-public class CoreVertexLabelRenderer extends DefaultVertexLabelRenderer {
- private Color foregroundColor = Color.WHITE;
- private Color backgroundColor = Color.BLACK;
-
- CoreVertexLabelRenderer() {
- super(Color.YELLOW);
- }
-
- public void setColors(Color foregroundColor, Color backgroundColor) {
- this.foregroundColor = foregroundColor;
- this.backgroundColor = backgroundColor;
- }
-
- @Override
- public Component getVertexLabelRendererComponent(JComponent vv, Object value, Font font, boolean isSelected, V vertex) {
- super.setForeground(foregroundColor);
- if (isSelected) {
- this.setForeground(this.pickedVertexLabelColor);
- }
-
- super.setBackground(backgroundColor);
- if (font != null) {
- this.setFont(font);
- } else {
- this.setFont(vv.getFont());
- }
-
- this.setIcon(null);
- EmptyBorder padding = new EmptyBorder(5, 5, 5, 5);
- this.setBorder(padding);
- this.setValue(value);
- setFont(getFont().deriveFont(Font.BOLD));
- return this;
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/EmaneContextMenu.java b/corefx/src/main/java/com/core/graph/EmaneContextMenu.java
deleted file mode 100644
index 848bbfb3..00000000
--- a/corefx/src/main/java/com/core/graph/EmaneContextMenu.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.core.graph;
-
-import com.core.Controller;
-import com.core.data.CoreNode;
-import com.core.ui.dialogs.MobilityPlayerDialog;
-
-class EmaneContextMenu extends AbstractNodeContextMenu {
- EmaneContextMenu(Controller controller, CoreNode coreNode) {
- super(controller, coreNode);
- setup();
- }
-
- private void setup() {
- addMenuItem("EMANE Settings", event -> controller.getNodeEmaneDialog().showDialog(coreNode));
- if (controller.getCoreClient().isRunning()) {
- MobilityPlayerDialog mobilityPlayerDialog = controller.getMobilityPlayerDialogs().get(coreNode.getId());
- if (mobilityPlayerDialog != null && !mobilityPlayerDialog.getStage().isShowing()) {
- addMenuItem("Mobility Script", event -> mobilityPlayerDialog.show());
- }
- } else {
- addMenuItem("Mobility", event -> controller.getMobilityDialog().showDialog(coreNode));
- addMenuItem("Link MDRs", event -> controller.getNetworkGraph().linkMdrs(coreNode));
- addMenuItem("Delete Node", event -> controller.deleteNode(coreNode));
- }
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/GraphContextMenu.java b/corefx/src/main/java/com/core/graph/GraphContextMenu.java
deleted file mode 100644
index c93ecba9..00000000
--- a/corefx/src/main/java/com/core/graph/GraphContextMenu.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.core.graph;
-
-import com.core.Controller;
-import javafx.event.ActionEvent;
-import javafx.event.EventHandler;
-import javafx.scene.control.ContextMenu;
-import javafx.scene.control.MenuItem;
-
-abstract class GraphContextMenu extends ContextMenu {
- final Controller controller;
-
- GraphContextMenu(Controller controller) {
- super();
- this.controller = controller;
- }
-
- void addMenuItem(String text, EventHandler handler) {
- MenuItem menuItem = new MenuItem(text);
- menuItem.setOnAction(handler);
- getItems().add(menuItem);
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/LinkContextMenu.java b/corefx/src/main/java/com/core/graph/LinkContextMenu.java
deleted file mode 100644
index d9b11115..00000000
--- a/corefx/src/main/java/com/core/graph/LinkContextMenu.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.core.graph;
-
-import com.core.Controller;
-import com.core.data.CoreLink;
-
-class LinkContextMenu extends GraphContextMenu {
- final CoreLink coreLink;
-
- LinkContextMenu(Controller controller, CoreLink coreLink) {
- super(controller);
- this.coreLink = coreLink;
- setup();
- }
-
- private void setup() {
- if (!controller.getCoreClient().isRunning()) {
- addMenuItem("Delete Link",
- event -> controller.getNetworkGraph().removeLink(coreLink));
- }
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/NetworkGraph.java b/corefx/src/main/java/com/core/graph/NetworkGraph.java
deleted file mode 100644
index 145bdc4c..00000000
--- a/corefx/src/main/java/com/core/graph/NetworkGraph.java
+++ /dev/null
@@ -1,578 +0,0 @@
-package com.core.graph;
-
-import com.core.Controller;
-import com.core.data.*;
-import com.core.ui.Toast;
-import com.core.ui.dialogs.TerminalDialog;
-import com.core.utils.Configuration;
-import com.core.utils.IconUtils;
-import com.google.common.base.Supplier;
-import edu.uci.ics.jung.algorithms.layout.StaticLayout;
-import edu.uci.ics.jung.graph.ObservableGraph;
-import edu.uci.ics.jung.graph.event.GraphEvent;
-import edu.uci.ics.jung.graph.event.GraphEventListener;
-import edu.uci.ics.jung.graph.util.Pair;
-import edu.uci.ics.jung.visualization.RenderContext;
-import edu.uci.ics.jung.visualization.VisualizationViewer;
-import edu.uci.ics.jung.visualization.annotations.AnnotationControls;
-import edu.uci.ics.jung.visualization.control.EditingModalGraphMouse;
-import edu.uci.ics.jung.visualization.control.GraphMouseListener;
-import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
-import edu.uci.ics.jung.visualization.decorators.EdgeShape;
-import edu.uci.ics.jung.visualization.renderers.Renderer;
-import inet.ipaddr.IPAddress;
-import javafx.application.Platform;
-import lombok.Data;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.MouseEvent;
-import java.awt.geom.Ellipse2D;
-import java.io.IOException;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-
-
-@Data
-public class NetworkGraph {
- private static final Logger logger = LogManager.getLogger();
- private static final int EDGE_LABEL_OFFSET = -5;
- private static final int EDGE_WIDTH = 5;
- private Controller controller;
- private ObservableGraph graph;
- private StaticLayout graphLayout;
- private VisualizationViewer graphViewer;
- private EditingModalGraphMouse graphMouse;
- private AnnotationControls annotationControls;
-
- private CoreAddresses coreAddresses = new CoreAddresses();
- private NodeType nodeType;
- private Map nodeMap = new ConcurrentHashMap<>();
- private int vertexId = 1;
- private int linkId = 1;
- private Supplier vertexFactory = () -> new CoreNode(vertexId++);
- private Supplier linkFactory = () -> new CoreLink(linkId++);
- private CorePopupGraphMousePlugin customPopupPlugin;
- private CoreAnnotatingGraphMousePlugin customAnnotatingPlugin;
- private BackgroundPaintable backgroundPaintable;
- private CoreVertexLabelRenderer nodeLabelRenderer = new CoreVertexLabelRenderer();
-
- // display options
- private boolean showThroughput = false;
- private Double throughputLimit = null;
- private int throughputWidth = 10;
-
- public NetworkGraph(Controller controller) {
- this.controller = controller;
- graph = new CoreObservableGraph<>(new UndirectedSimpleGraph<>());
- graph.addGraphEventListener(graphEventListener);
- graphLayout = new StaticLayout<>(graph);
- graphViewer = new VisualizationViewer<>(graphLayout);
- graphViewer.setBackground(Color.WHITE);
- graphViewer.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S);
-
- // node render properties
- RenderContext renderContext = graphViewer.getRenderContext();
- renderContext.setVertexLabelTransformer(CoreNode::getName);
- renderContext.setVertexLabelRenderer(nodeLabelRenderer);
- renderContext.setVertexShapeTransformer(node -> {
- double offset = -(IconUtils.ICON_SIZE / 2.0);
- return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
- });
- renderContext.setVertexIconTransformer(vertex -> {
- long wirelessLinks = wirelessLinkCount(vertex);
- vertex.getRadioIcon().setWiressLinks(wirelessLinks);
- return vertex.getGraphIcon();
- });
-
- // link render properties
- renderContext.setEdgeLabelTransformer(edge -> {
- if (!showThroughput || edge == null) {
- return null;
- }
- double kbps = edge.getThroughput() / 1000.0;
- return String.format("%.2f kbps", kbps);
- });
- renderContext.setLabelOffset(EDGE_LABEL_OFFSET);
- renderContext.setEdgeStrokeTransformer(edge -> {
- // determine edge width
- int width = EDGE_WIDTH;
- if (throughputLimit != null && edge.getThroughput() > throughputLimit) {
- width = throughputWidth;
- }
-
- LinkTypes linkType = LinkTypes.get(edge.getType());
- if (LinkTypes.WIRELESS == linkType) {
- float[] dash = {15.0f};
- return new BasicStroke(width, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND,
- 0, dash, 0);
- } else {
- return new BasicStroke(width);
- }
- });
- renderContext.setEdgeShapeTransformer(EdgeShape.line(graph));
- renderContext.setEdgeDrawPaintTransformer(edge -> {
- LinkTypes linkType = LinkTypes.get(edge.getType());
- if (LinkTypes.WIRELESS == linkType) {
- return Color.BLUE;
- } else {
- return Color.BLACK;
- }
- });
- renderContext.setEdgeIncludePredicate(predicate -> predicate.element.isVisible());
-
- graphViewer.setVertexToolTipTransformer(renderContext.getVertexLabelTransformer());
- graphMouse = new CoreEditingModalGraphMouse<>(controller, this, renderContext,
- vertexFactory, linkFactory);
- graphViewer.setGraphMouse(graphMouse);
-
- // mouse events
- graphViewer.addGraphMouseListener(new GraphMouseListener() {
- @Override
- public void graphClicked(CoreNode node, MouseEvent mouseEvent) {
- // double click
- logger.info("click count: {}, running?: {}", mouseEvent.getClickCount(),
- controller.getCoreClient().isRunning());
-
- if (mouseEvent.getClickCount() == 2 && controller.getCoreClient().isRunning()) {
- if (controller.getCoreClient().isLocalConnection()) {
- try {
- String shellCommand = controller.getConfiguration().getShellCommand();
- String terminalCommand = controller.getCoreClient().getTerminalCommand(node);
- terminalCommand = String.format("%s %s", shellCommand, terminalCommand);
- logger.info("launching node terminal: {}", terminalCommand);
- String[] commands = terminalCommand.split("\\s+");
- logger.info("launching node terminal: {}", Arrays.toString(commands));
- Process p = new ProcessBuilder(commands).start();
- try {
- if (!p.waitFor(5, TimeUnit.SECONDS)) {
- Toast.error("Node terminal command failed");
- }
- } catch (InterruptedException ex) {
- logger.error("error waiting for terminal to start", ex);
- }
- } catch (IOException ex) {
- logger.error("error launching terminal", ex);
- Toast.error("Node terminal failed to start");
- }
- } else {
- Platform.runLater(() -> {
- TerminalDialog terminalDialog = new TerminalDialog(controller);
- terminalDialog.setOwner(controller.getWindow());
- terminalDialog.showDialog(node);
- });
- }
- }
- }
-
- @Override
- public void graphPressed(CoreNode node, MouseEvent mouseEvent) {
- logger.debug("graph pressed: {} - {}", node, mouseEvent);
- }
-
- @Override
- public void graphReleased(CoreNode node, MouseEvent mouseEvent) {
- if (SwingUtilities.isLeftMouseButton(mouseEvent)) {
- Double newX = graphLayout.getX(node);
- Double newY = graphLayout.getY(node);
- Double oldX = node.getPosition().getX();
- Double oldY = node.getPosition().getY();
- if (newX.equals(oldX) && newY.equals(oldY)) {
- return;
- }
- logger.debug("graph moved node({}): {},{}", node.getName(), newX, newY);
- node.getPosition().setX(newX);
- node.getPosition().setY(newY);
-
- // upate node when session is active
- if (controller.getCoreClient().isRunning()) {
- try {
- controller.getCoreClient().editNode(node);
- } catch (IOException ex) {
- Toast.error("failed to update node location");
- }
- }
- }
- }
- });
- }
-
- private Color convertJfxColor(String hexValue) {
- javafx.scene.paint.Color color = javafx.scene.paint.Color.web(hexValue);
- return new Color((float) color.getRed(), (float) color.getGreen(), (float) color.getBlue());
- }
-
- public void updatePreferences(Configuration configuration) {
- Color nodeLabelColor = convertJfxColor(configuration.getNodeLabelColor());
- Color nodeLabelBackgroundColor = convertJfxColor(configuration.getNodeLabelBackgroundColor());
- nodeLabelRenderer.setColors(nodeLabelColor, nodeLabelBackgroundColor);
- throughputLimit = configuration.getThroughputLimit();
- if (configuration.getThroughputWidth() != null) {
- throughputWidth = configuration.getThroughputWidth();
- }
- graphViewer.repaint();
- }
-
- public void setBackground(String imagePath) {
- try {
- backgroundPaintable = new BackgroundPaintable<>(imagePath, graphViewer);
- graphViewer.addPreRenderPaintable(backgroundPaintable);
- graphViewer.repaint();
- } catch (IOException ex) {
- logger.error("error setting background", ex);
- }
- }
-
- public void removeBackground() {
- if (backgroundPaintable != null) {
- graphViewer.removePreRenderPaintable(backgroundPaintable);
- graphViewer.repaint();
- backgroundPaintable = null;
- }
- }
-
- public void setMode(ModalGraphMouse.Mode mode) {
- graphMouse.setMode(mode);
- }
-
- public void reset() {
- logger.info("network graph reset");
- vertexId = 1;
- linkId = 1;
- for (CoreNode node : nodeMap.values()) {
- graph.removeVertex(node);
- }
- nodeMap.clear();
- graphViewer.repaint();
- coreAddresses.reset();
- }
-
- public void updatePositions() {
- for (CoreNode node : graph.getVertices()) {
- Double x = graphLayout.getX(node);
- Double y = graphLayout.getY(node);
- node.getPosition().setX(x);
- node.getPosition().setY(y);
- logger.debug("updating node position node({}): {},{}", node, x, y);
- }
- }
-
- public CoreNode getVertex(int id) {
- return nodeMap.get(id);
- }
-
- private GraphEventListener graphEventListener = graphEvent -> {
- logger.info("graph event: {}", graphEvent.getType());
- switch (graphEvent.getType()) {
- case EDGE_ADDED:
- handleEdgeAdded((GraphEvent.Edge) graphEvent);
- break;
- case EDGE_REMOVED:
- handleEdgeRemoved((GraphEvent.Edge) graphEvent);
- break;
- case VERTEX_ADDED:
- handleVertexAdded((GraphEvent.Vertex) graphEvent);
- break;
- case VERTEX_REMOVED:
- handleVertexRemoved((GraphEvent.Vertex) graphEvent);
- break;
- }
- };
-
- private void handleEdgeAdded(GraphEvent.Edge edgeEvent) {
- CoreLink link = edgeEvent.getEdge();
- if (link.isLoaded()) {
- // load addresses to avoid duplication
- if (link.getInterfaceOne().getIp4() != null) {
- coreAddresses.usedAddress(link.getInterfaceOne().getIp4());
- }
- if (link.getInterfaceTwo().getIp4() != null) {
- coreAddresses.usedAddress(link.getInterfaceTwo().getIp4());
- }
- return;
- }
- Pair endpoints = graph.getEndpoints(link);
- CoreNode nodeOne = endpoints.getFirst();
- CoreNode nodeTwo = endpoints.getSecond();
- boolean nodeOneIsDefault = NodeType.isDefault(nodeOne.getNodeType());
- boolean nodeTwoIsDefault = NodeType.isDefault(nodeTwo.getNodeType());
-
- // check what we are linking together
- IPAddress subnet = null;
- Set interfaces;
- if (nodeOneIsDefault && nodeTwoIsDefault) {
- subnet = coreAddresses.nextSubnet();
- logger.info("linking node to node using subnet: {}", subnet);
- } else if (nodeOneIsDefault) {
- interfaces = getNetworkInterfaces(nodeTwo, new HashSet<>());
- subnet = coreAddresses.findSubnet(interfaces);
- logger.info("linking node one to network using subnet: {}", subnet);
- } else if (nodeTwoIsDefault) {
- interfaces = getNetworkInterfaces(nodeOne, new HashSet<>());
- subnet = coreAddresses.findSubnet(interfaces);
- logger.info("linking node two to network using subnet: {}", subnet);
- } else {
- logger.info("subnet not needed for linking networks together");
- }
-
- link.setNodeOne(nodeOne.getId());
- if (nodeOneIsDefault) {
- int interfaceOneId = nextInterfaceId(nodeOne);
- CoreInterface interfaceOne = createInterface(nodeOne, interfaceOneId, subnet);
- link.setInterfaceOne(interfaceOne);
- }
-
- link.setNodeTwo(nodeTwo.getId());
- if (nodeTwoIsDefault) {
- int interfaceTwoId = nextInterfaceId(nodeTwo);
- CoreInterface interfaceTwo = createInterface(nodeTwo, interfaceTwoId, subnet);
- link.setInterfaceTwo(interfaceTwo);
- }
-
- boolean isVisible = !checkForWirelessNode(nodeOne, nodeTwo);
- link.setVisible(isVisible);
- logger.info("adding user created edge: {}", link);
- }
-
- public Set getNetworkInterfaces(CoreNode node, Set visited) {
- Set interfaces = new HashSet<>();
- if (visited.contains(node)) {
- return interfaces;
- }
- visited.add(node);
-
- logger.info("checking network node links: {}", node);
- for (CoreLink link : graph.getIncidentEdges(node)) {
- logger.info("checking link: {}", link);
- if (link.getNodeOne() == null && link.getNodeTwo() == null) {
- continue;
- }
-
- // ignore oneself
- CoreNode currentNode = getVertex(link.getNodeOne());
- CoreInterface currentInterface = link.getInterfaceOne();
- if (node.getId().equals(link.getNodeOne())) {
- currentNode = getVertex(link.getNodeTwo());
- currentInterface = link.getInterfaceTwo();
- }
-
- if (NodeType.isDefault(currentNode.getNodeType())) {
- interfaces.add(currentInterface);
- } else {
- Set nextInterfaces = getNetworkInterfaces(currentNode, visited);
- interfaces.addAll(nextInterfaces);
- }
- }
-
- return interfaces;
- }
-
- public Set getNodeInterfaces(CoreNode node) {
- return graph.getIncidentEdges(node).stream()
- .map(link -> {
- if (node.getId().equals(link.getNodeOne())) {
- return link.getInterfaceOne();
- } else {
- return link.getInterfaceTwo();
- }
- })
- .filter(Objects::nonNull)
- .collect(Collectors.toSet());
- }
-
- private int nextInterfaceId(CoreNode node) {
- Set interfaceIds = graph.getIncidentEdges(node).stream()
- .map(link -> {
- if (node.getId().equals(link.getNodeOne())) {
- return link.getInterfaceOne();
- } else {
- return link.getInterfaceTwo();
- }
- })
- .filter(Objects::nonNull)
- .map(CoreInterface::getId)
- .collect(Collectors.toSet());
-
- int i = 0;
- while (true) {
- if (!interfaceIds.contains(i)) {
- return i;
- }
-
- i += 1;
- }
- }
-
- private CoreInterface createInterface(CoreNode node, int interfaceId, IPAddress subnet) {
- CoreInterface coreInterface = new CoreInterface();
- coreInterface.setId(interfaceId);
- coreInterface.setName(String.format("eth%s", interfaceId));
- IPAddress address = subnet.increment(node.getId());
- logger.info("creating interface for node({}): {}", node.getId(), address);
- coreInterface.setIp4(address);
- coreInterface.setIp6(address.toIPv6());
- return coreInterface;
- }
-
- private void handleEdgeRemoved(GraphEvent.Edge edgeEvent) {
- CoreLink link = edgeEvent.getEdge();
- logger.info("removed edge: {}", link);
- CoreNode nodeOne = getVertex(link.getNodeOne());
- CoreInterface interfaceOne = link.getInterfaceOne();
- CoreNode nodeTwo = getVertex(link.getNodeTwo());
- CoreInterface interfaceTwo = link.getInterfaceTwo();
- boolean nodeOneIsDefault = NodeType.isDefault(nodeOne.getNodeType());
- boolean nodeTwoIsDefault = NodeType.isDefault(nodeTwo.getNodeType());
-
- // check what we are unlinking
- Set interfaces;
- IPAddress subnet = null;
- if (nodeOneIsDefault && nodeTwoIsDefault) {
- subnet = interfaceOne.getIp4().toPrefixBlock();
- logger.info("unlinking node to node reuse subnet: {}", subnet);
- } else if (nodeOneIsDefault) {
- interfaces = getNetworkInterfaces(nodeTwo, new HashSet<>());
- if (interfaces.isEmpty()) {
- subnet = interfaceOne.getIp4().toPrefixBlock();
- logger.info("unlinking node one from network reuse subnet: {}", subnet);
- }
- } else if (nodeTwoIsDefault) {
- interfaces = getNetworkInterfaces(nodeOne, new HashSet<>());
- if (interfaces.isEmpty()) {
- subnet = interfaceTwo.getIp4().toPrefixBlock();
- logger.info("unlinking node two from network reuse subnet: {}", subnet);
- }
- } else {
- logger.info("nothing to do when unlinking networks");
- }
-
- if (subnet != null) {
- coreAddresses.reuseSubnet(subnet);
- }
- }
-
- private void handleVertexAdded(GraphEvent.Vertex vertexEvent) {
- CoreNode node = vertexEvent.getVertex();
- if (node.isLoaded()) {
- return;
- }
-
- node.setNodeType(nodeType);
- if (node.getType() == NodeType.EMANE) {
- String emaneModel = controller.getNodeEmaneDialog().getModels().get(0);
- node.setEmane(emaneModel);
- } else if (node.getType() == NodeType.DOCKER || node.getType() == NodeType.LXC) {
- node.setImage("ubuntu");
- } else if (node.getType() == NodeType.RJ45) {
- Platform.runLater(() -> controller.getRj45Dialog().showDialog(node));
- }
-
- logger.info("adding user created node: {}", node);
- nodeMap.put(node.getId(), node);
- }
-
- private void handleVertexRemoved(GraphEvent.Vertex vertexEvent) {
- CoreNode node = vertexEvent.getVertex();
- logger.info("removed vertex: {}", node);
- nodeMap.remove(node.getId());
- }
-
- public void addNode(CoreNode node) {
- vertexId = Math.max(node.getId() + 1, node.getId());
- double x = Math.abs(node.getPosition().getX());
- double y = Math.abs(node.getPosition().getY());
- logger.info("adding session node: {}", node);
- graph.addVertex(node);
- graphLayout.setLocation(node, x, y);
- nodeMap.put(node.getId(), node);
- }
-
- public void setNodeLocation(CoreNode nodeData) {
- // update actual graph node
- CoreNode node = nodeMap.get(nodeData.getId());
- node.getPosition().setX(nodeData.getPosition().getX());
- node.getPosition().setY(nodeData.getPosition().getY());
-
- // set graph node location
- double x = Math.abs(node.getPosition().getX());
- double y = Math.abs(node.getPosition().getY());
- graphLayout.setLocation(node, x, y);
- graphViewer.repaint();
- }
-
- public void removeNode(CoreNode node) {
- try {
- controller.getCoreClient().deleteNode(node);
- } catch (IOException ex) {
- logger.error("error deleting node", ex);
- Toast.error(String.format("Error deleting node: %s", node.getName()));
- }
- graphViewer.getPickedVertexState().pick(node, false);
- graph.removeVertex(node);
- graphViewer.repaint();
- }
-
- private boolean isWirelessNode(CoreNode node) {
- return node != null && (node.getType() == NodeType.EMANE || node.getType() == NodeType.WLAN);
- }
-
- private boolean checkForWirelessNode(CoreNode nodeOne, CoreNode nodeTwo) {
- boolean result = isWirelessNode(nodeOne);
- return result || isWirelessNode(nodeTwo);
- }
-
- private long wirelessLinkCount(CoreNode node) {
- return graph.getNeighbors(node).stream()
- .filter(this::isWirelessNode)
- .count();
- }
-
- public void addLink(CoreLink link) {
- logger.info("adding session link: {}", link);
- link.setId(linkId++);
- CoreNode nodeOne = nodeMap.get(link.getNodeOne());
- CoreNode nodeTwo = nodeMap.get(link.getNodeTwo());
-
- boolean isVisible = !checkForWirelessNode(nodeOne, nodeTwo);
- link.setVisible(isVisible);
-
- graph.addEdge(link, nodeOne, nodeTwo);
- }
-
- public void removeWirelessLink(CoreLink link) {
- logger.info("deleting link: {}", link);
- CoreNode nodeOne = nodeMap.get(link.getNodeOne());
- CoreNode nodeTwo = nodeMap.get(link.getNodeTwo());
-
- CoreLink existingLink = graph.findEdge(nodeOne, nodeTwo);
- if (existingLink != null) {
- graph.removeEdge(existingLink);
- }
- }
-
- public void removeLink(CoreLink link) {
- graphViewer.getPickedEdgeState().pick(link, false);
- graph.removeEdge(link);
- graphViewer.repaint();
- }
-
- public void linkMdrs(CoreNode node) {
- for (CoreNode currentNode : graph.getVertices()) {
- if (!"mdr".equals(currentNode.getModel())) {
- continue;
- }
-
- // only links mdrs we have not already linked
- Collection links = graph.findEdgeSet(node, currentNode);
- if (links.isEmpty()) {
- CoreLink link = linkFactory.get();
- graph.addEdge(link, currentNode, node);
- graphViewer.repaint();
- }
- }
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/NodeContextMenu.java b/corefx/src/main/java/com/core/graph/NodeContextMenu.java
deleted file mode 100644
index d50cd58a..00000000
--- a/corefx/src/main/java/com/core/graph/NodeContextMenu.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package com.core.graph;
-
-import com.core.Controller;
-import com.core.data.CoreNode;
-import com.core.ui.Toast;
-import javafx.scene.control.Menu;
-import javafx.scene.control.MenuItem;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Set;
-
-class NodeContextMenu extends AbstractNodeContextMenu {
- private static final Logger logger = LogManager.getLogger();
-
- NodeContextMenu(Controller controller, CoreNode coreNode) {
- super(controller, coreNode);
- setup();
- }
-
- private MenuItem createStartItem(String service) {
- MenuItem menuItem = new MenuItem("Start");
- menuItem.setOnAction(event -> {
- try {
- boolean result = controller.getCoreClient().startService(coreNode, service);
- if (result) {
- Toast.success("Started " + service);
- } else {
- Toast.error("Failure to start " + service);
- }
- } catch (IOException ex) {
- Toast.error("Error starting " + service, ex);
- }
- });
- return menuItem;
- }
-
- private MenuItem createStopItem(String service) {
- MenuItem menuItem = new MenuItem("Stop");
- menuItem.setOnAction(event -> {
- try {
- boolean result = controller.getCoreClient().stopService(coreNode, service);
- if (result) {
- Toast.success("Stopped " + service);
- } else {
- Toast.error("Failure to stop " + service);
- }
- } catch (IOException ex) {
- Toast.error("Error stopping " + service, ex);
- }
- });
- return menuItem;
- }
-
- private MenuItem createRestartItem(String service) {
- MenuItem menuItem = new MenuItem("Restart");
- menuItem.setOnAction(event -> {
- try {
- boolean result = controller.getCoreClient().restartService(coreNode, service);
- if (result) {
- Toast.success("Restarted " + service);
- } else {
- Toast.error("Failure to restart " + service);
- }
- } catch (IOException ex) {
- Toast.error("Error restarting " + service, ex);
- }
- });
- return menuItem;
- }
-
- private MenuItem createValidateItem(String service) {
- MenuItem menuItem = new MenuItem("Validate");
- menuItem.setOnAction(event -> {
- try {
- boolean result = controller.getCoreClient().validateService(coreNode, service);
- if (result) {
- Toast.success("Validated " + service);
- } else {
- Toast.error("Validation failed for " + service);
- }
- } catch (IOException ex) {
- Toast.error("Error validating " + service, ex);
- }
- });
- return menuItem;
- }
-
- private void setup() {
- if (controller.getCoreClient().isRunning()) {
- Set services = coreNode.getServices();
- if (services.isEmpty()) {
- services = controller.getDefaultServices().getOrDefault(coreNode.getModel(), Collections.emptySet());
- }
-
- if (!services.isEmpty()) {
- Menu menu = new Menu("Manage Services");
- for (String service : services) {
- Menu serviceMenu = new Menu(service);
- MenuItem startItem = createStartItem(service);
- MenuItem stopItem = createStopItem(service);
- MenuItem restartItem = createRestartItem(service);
- MenuItem validateItem = createValidateItem(service);
- serviceMenu.getItems().addAll(startItem, stopItem, restartItem, validateItem);
- menu.getItems().add(serviceMenu);
- }
- getItems().add(menu);
- }
- } else {
- addMenuItem("Services", event -> controller.getNodeServicesDialog().showDialog(coreNode));
- addMenuItem("Delete Node", event -> controller.deleteNode(coreNode));
- }
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/RadioIcon.java b/corefx/src/main/java/com/core/graph/RadioIcon.java
deleted file mode 100644
index e3139eaf..00000000
--- a/corefx/src/main/java/com/core/graph/RadioIcon.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.core.graph;
-
-import com.core.utils.IconUtils;
-import lombok.Data;
-
-import javax.swing.*;
-import java.awt.*;
-
-@Data
-public class RadioIcon implements Icon {
- private long wiressLinks = 0;
-
- @Override
- public int getIconHeight() {
- return IconUtils.ICON_SIZE;
- }
-
- @Override
- public int getIconWidth() {
- return IconUtils.ICON_SIZE;
- }
-
- @Override
- public void paintIcon(Component c, Graphics g, int x, int y) {
- g.setColor(Color.black);
- for (int i = 0; i < wiressLinks; i++) {
- g.fillOval(x, y, 10, 10);
- x += 15;
- }
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/Rj45ContextMenu.java b/corefx/src/main/java/com/core/graph/Rj45ContextMenu.java
deleted file mode 100644
index 3d0da724..00000000
--- a/corefx/src/main/java/com/core/graph/Rj45ContextMenu.java
+++ /dev/null
@@ -1,21 +0,0 @@
-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/graph/UndirectedSimpleGraph.java b/corefx/src/main/java/com/core/graph/UndirectedSimpleGraph.java
deleted file mode 100644
index 355b44a0..00000000
--- a/corefx/src/main/java/com/core/graph/UndirectedSimpleGraph.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.core.graph;
-
-import edu.uci.ics.jung.graph.UndirectedSparseGraph;
-import edu.uci.ics.jung.graph.util.EdgeType;
-import edu.uci.ics.jung.graph.util.Pair;
-
-public class UndirectedSimpleGraph extends UndirectedSparseGraph {
- @Override
- public boolean addEdge(E edge, Pair extends V> endpoints, EdgeType edgeType) {
- Pair newEndpoints = getValidatedEndpoints(edge, endpoints);
- if (newEndpoints == null) {
- return false;
- }
-
- V first = newEndpoints.getFirst();
- V second = newEndpoints.getSecond();
-
- if (first.equals(second)) {
- return false;
- } else {
- return super.addEdge(edge, endpoints, edgeType);
- }
- }
-}
diff --git a/corefx/src/main/java/com/core/graph/WlanContextMenu.java b/corefx/src/main/java/com/core/graph/WlanContextMenu.java
deleted file mode 100644
index 937eef15..00000000
--- a/corefx/src/main/java/com/core/graph/WlanContextMenu.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.core.graph;
-
-import com.core.Controller;
-import com.core.data.CoreNode;
-import com.core.ui.dialogs.MobilityPlayerDialog;
-
-class WlanContextMenu extends AbstractNodeContextMenu {
- WlanContextMenu(Controller controller, CoreNode coreNode) {
- super(controller, coreNode);
- setup();
- }
-
- private void setup() {
- addMenuItem("WLAN Settings", event -> controller.getNodeWlanDialog().showDialog(coreNode));
- if (controller.getCoreClient().isRunning()) {
- MobilityPlayerDialog mobilityPlayerDialog = controller.getMobilityPlayerDialogs().get(coreNode.getId());
- if (mobilityPlayerDialog != null && !mobilityPlayerDialog.getStage().isShowing()) {
- addMenuItem("Mobility Script", event -> mobilityPlayerDialog.show());
- }
- } else {
- addMenuItem("Mobility", event -> controller.getMobilityDialog().showDialog(coreNode));
- addMenuItem("Link MDRs", event -> controller.getNetworkGraph().linkMdrs(coreNode));
- addMenuItem("Delete Node", event -> controller.deleteNode(coreNode));
- }
- }
-}
diff --git a/corefx/src/main/java/com/core/ui/AnnotationToolbar.java b/corefx/src/main/java/com/core/ui/AnnotationToolbar.java
deleted file mode 100644
index b32d3c8b..00000000
--- a/corefx/src/main/java/com/core/ui/AnnotationToolbar.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package com.core.ui;
-
-import com.core.graph.NetworkGraph;
-import com.core.utils.FxmlUtils;
-import com.jfoenix.controls.JFXColorPicker;
-import com.jfoenix.controls.JFXComboBox;
-import com.jfoenix.controls.JFXToggleButton;
-import edu.uci.ics.jung.visualization.annotations.Annotation;
-import javafx.event.ActionEvent;
-import javafx.fxml.FXML;
-import javafx.scene.layout.GridPane;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.awt.*;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.RectangularShape;
-import java.awt.geom.RoundRectangle2D;
-
-public class AnnotationToolbar extends GridPane {
- private static final Logger logger = LogManager.getLogger();
- private static final String RECTANGLE = "Rectangle";
- private static final String ROUND_RECTANGLE = "RoundRectangle";
- private static final String ELLIPSE = "Ellipse";
- private static final String UPPER_LAYER = "Upper";
- private static final String LOWER_LAYER = "Lower";
- private NetworkGraph graph;
- @FXML private JFXComboBox shapeCombo;
- @FXML private JFXColorPicker colorPicker;
- @FXML private JFXComboBox layerCombo;
- @FXML private JFXToggleButton fillToggle;
-
- public AnnotationToolbar(NetworkGraph graph) {
- this.graph = graph;
- FxmlUtils.loadRootController(this, "/fxml/annotation_toolbar.fxml");
-
- // setup annotation shape combo
- shapeCombo.getItems().addAll(RECTANGLE, ROUND_RECTANGLE, ELLIPSE);
- shapeCombo.setOnAction(this::shapeChange);
- shapeCombo.getSelectionModel().selectFirst();
-
- // setup annotation layer combo
- layerCombo.getItems().addAll(LOWER_LAYER, UPPER_LAYER);
- layerCombo.setOnAction(this::layerChange);
- layerCombo.getSelectionModel().selectFirst();
-
- // setup annotation color picker
- colorPicker.setOnAction(this::colorChange);
- colorPicker.setValue(javafx.scene.paint.Color.AQUA);
- colorPicker.fireEvent(new ActionEvent());
-
- // setup annotation toggle fill
- fillToggle.setOnAction(this::fillChange);
- }
-
- private void fillChange(ActionEvent event) {
- boolean selected = fillToggle.isSelected();
- graph.getGraphMouse().getAnnotatingPlugin().setFill(selected);
- }
-
- private void colorChange(ActionEvent event) {
- javafx.scene.paint.Color fxColor = colorPicker.getValue();
- java.awt.Color color = new java.awt.Color(
- (float) fxColor.getRed(),
- (float) fxColor.getGreen(),
- (float) fxColor.getBlue(),
- (float) fxColor.getOpacity()
- );
- logger.info("color selected: {}", fxColor);
- graph.getGraphMouse().getAnnotatingPlugin().setAnnotationColor(color);
- }
-
- private void layerChange(ActionEvent event) {
- String selected = layerCombo.getSelectionModel().getSelectedItem();
- logger.info("annotation layer selected: {}", selected);
- Annotation.Layer layer;
- if (LOWER_LAYER.equals(selected)) {
- layer = Annotation.Layer.LOWER;
- } else {
- layer = Annotation.Layer.UPPER;
- }
- graph.getGraphMouse().getAnnotatingPlugin().setLayer(layer);
- }
-
- private void shapeChange(ActionEvent event) {
- String selected = shapeCombo.getSelectionModel().getSelectedItem();
- logger.info("annotation shape selected: {}", selected);
- RectangularShape shape = new Rectangle();
- switch (selected) {
- case RECTANGLE:
- shape = new Rectangle();
- break;
- case ROUND_RECTANGLE:
- shape = new RoundRectangle2D.Double(0, 0, 0, 0, 50.0, 50.0);
- break;
- case ELLIPSE:
- shape = new Ellipse2D.Double();
- break;
- default:
- Toast.error("Unknown annotation shape " + selected);
- }
- graph.getGraphMouse().getAnnotatingPlugin().setRectangularShape(shape);
- }
-}
diff --git a/corefx/src/main/java/com/core/ui/DetailsPanel.java b/corefx/src/main/java/com/core/ui/DetailsPanel.java
deleted file mode 100644
index 2df434fc..00000000
--- a/corefx/src/main/java/com/core/ui/DetailsPanel.java
+++ /dev/null
@@ -1,171 +0,0 @@
-package com.core.ui;
-
-import com.core.Controller;
-import com.core.data.CoreInterface;
-import com.core.data.CoreNode;
-import com.core.ui.textfields.DoubleFilter;
-import com.core.utils.FxmlUtils;
-import com.jfoenix.controls.JFXButton;
-import com.jfoenix.controls.JFXTextField;
-import inet.ipaddr.IPAddress;
-import javafx.event.ActionEvent;
-import javafx.event.EventHandler;
-import javafx.fxml.FXML;
-import javafx.geometry.Insets;
-import javafx.geometry.Orientation;
-import javafx.scene.control.Label;
-import javafx.scene.control.ScrollPane;
-import javafx.scene.control.Separator;
-import javafx.scene.control.TextFormatter;
-import javafx.scene.layout.GridPane;
-import javafx.util.converter.DoubleStringConverter;
-import javafx.util.converter.IntegerStringConverter;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.function.UnaryOperator;
-
-abstract class DetailsPanel extends ScrollPane {
- private static final Logger logger = LogManager.getLogger();
- private static final int START_INDEX = 1;
- final Controller controller;
- @FXML Label title;
- @FXML ScrollPane scrollPane;
- @FXML GridPane gridPane;
- int index = START_INDEX;
-
- DetailsPanel(Controller controller) {
- this.controller = controller;
- FxmlUtils.loadRootController(this, "/fxml/details_panel.fxml");
- setPrefWidth(400);
- }
-
- void setTitle(String text) {
- title.setText(text);
- }
-
- void addButton(String text, EventHandler handler) {
- JFXButton emaneButton = new JFXButton(text);
- emaneButton.getStyleClass().add("core-button");
- emaneButton.setMaxWidth(Double.MAX_VALUE);
- emaneButton.setOnAction(handler);
- gridPane.add(emaneButton, 0, index++, 2, 1);
- }
-
- void addLabel(String text) {
- Label label = new Label(text);
- label.getStyleClass().add("details-label");
- gridPane.add(label, 0, index++, 2, 1);
- }
-
- void addSeparator() {
- Separator separator = new Separator(Orientation.HORIZONTAL);
- gridPane.add(separator, 0, index++, 2, 1);
- GridPane.setMargin(separator, new Insets(10, 0, 0, 0));
- }
-
- void addInterface(CoreInterface coreInterface, CoreNode linkedNode) {
- if (linkedNode != null) {
- addRow("Linked To", linkedNode.getName(), true);
- }
- addRow("Interface", coreInterface.getName(), true);
- if (coreInterface.getMac() != null) {
- addRow("MAC", coreInterface.getMac(), true);
- }
- addAddress("IP4", coreInterface.getIp4());
- addAddress("IP6", coreInterface.getIp6());
- }
-
- void addInterface(CoreInterface coreInterface) {
- addInterface(coreInterface, null);
- }
-
- 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;
- }
-
- JFXTextField addDoubleRow(String labelText, Double value) {
- Label label = new Label(labelText);
- String valueString = null;
- if (value != null) {
- valueString = value.toString();
- }
- JFXTextField textField = new JFXTextField();
- TextFormatter formatter = new TextFormatter<>(
- new DoubleStringConverter(), null, new DoubleFilter());
- textField.setTextFormatter(formatter);
- textField.setText(valueString);
- gridPane.addRow(index++, label, textField);
- return textField;
- }
-
- Double getDouble(JFXTextField textField) {
- if (textField.getText() == null) {
- return null;
- }
-
- Double value = null;
- try {
- logger.info("double field text: {}", textField.getText());
- value = Double.parseDouble(textField.getText());
- } catch (NumberFormatException ex) {
- logger.error("error getting double value", ex);
- }
- return value;
- }
-
- JFXTextField addIntegerRow(String labelText, Integer value) {
- Label label = new Label(labelText);
- String valueString = null;
- if (value != null) {
- valueString = value.toString();
- }
- JFXTextField textField = new JFXTextField();
- UnaryOperator filter = change -> {
- String text = change.getText();
- if (text.matches("[0-9]*")) {
- return change;
- }
- return null;
- };
- TextFormatter formatter = new TextFormatter<>(
- new IntegerStringConverter(), null, filter);
- textField.setTextFormatter(formatter);
- textField.setText(valueString);
- gridPane.addRow(index++, label, textField);
- return textField;
- }
-
- Integer getInteger(JFXTextField textField) {
- if (textField.getText() == null) {
- return null;
- }
-
- Integer value = null;
- try {
- logger.info("integer field text: {}", textField.getText());
- value = Integer.parseInt(textField.getText());
- } catch (NumberFormatException ex) {
- logger.error("error getting integer value", ex);
- }
- return value;
- }
-
- private void addAddress(String label, IPAddress ip) {
- if (ip == null) {
- return;
- }
- addRow(label, ip.toString(), true);
- }
-
- void clear() {
- if (gridPane.getChildren().size() > START_INDEX) {
- gridPane.getChildren().remove(START_INDEX, gridPane.getChildren().size());
- }
- index = START_INDEX;
- }
-}
diff --git a/corefx/src/main/java/com/core/ui/GraphToolbar.java b/corefx/src/main/java/com/core/ui/GraphToolbar.java
deleted file mode 100644
index 07fa2246..00000000
--- a/corefx/src/main/java/com/core/ui/GraphToolbar.java
+++ /dev/null
@@ -1,292 +0,0 @@
-package com.core.ui;
-
-import com.core.Controller;
-import com.core.data.NodeType;
-import com.core.utils.FxmlUtils;
-import com.core.utils.IconUtils;
-import com.jfoenix.controls.JFXButton;
-import com.jfoenix.controls.JFXListView;
-import com.jfoenix.controls.JFXPopup;
-import com.jfoenix.svg.SVGGlyph;
-import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
-import javafx.application.Platform;
-import javafx.css.PseudoClass;
-import javafx.event.ActionEvent;
-import javafx.fxml.FXML;
-import javafx.scene.control.ComboBox;
-import javafx.scene.control.Label;
-import javafx.scene.control.Tooltip;
-import javafx.scene.image.ImageView;
-import javafx.scene.layout.VBox;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Map;
-
-public class GraphToolbar extends VBox {
- private static final Logger logger = LogManager.getLogger();
- private static final int ICON_SIZE = 40;
- private static final int NODES_ICON_SIZE = 20;
- private static final PseudoClass START_CLASS = PseudoClass.getPseudoClass("start");
- private static final PseudoClass STOP_CLASS = PseudoClass.getPseudoClass("stop");
- private static final PseudoClass SELECTED_CLASS = PseudoClass.getPseudoClass("selected");
- private final Controller controller;
- private final Map labelMap = new HashMap<>();
- private SVGGlyph startIcon;
- private SVGGlyph stopIcon;
- private JFXListView