Search in sources :

Example 1 with ScapyClientNeedConnectEvent

use of com.xored.javafx.packeteditor.events.ScapyClientNeedConnectEvent in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketBuilderHomeController method initStreamBuilder.

public boolean initStreamBuilder(String pcapFileBinary, List<Profile> profileList, int selectedProfileIndex, String yamlFileName, StreamBuilderType type) {
    selectedProfile = profileList.get(selectedProfileIndex);
    this.profileList = profileList;
    this.yamlFileName = yamlFileName;
    currentSelectedProfileIndex = selectedProfileIndex;
    if (selectedProfile.getStream().getAdvancedMode() && !ConnectionManager.getInstance().isScapyConnected()) {
        boolean loop = true;
        while (loop) {
            eventBus.post(new ScapyClientNeedConnectEvent());
            if (ConnectionManager.getInstance().isScapyConnected()) {
                loop = false;
            } else {
                loop = alertWarning("Can't open packet editor in Advanced mode", "There is no connection to Scapy server." + "\nPlease refer to documentation about" + "\nScapy server and advanced mode.");
            }
        }
        if (!ConnectionManager.getInstance().isScapyConnected()) {
            return false;
        }
    }
    packetBuilderController.reset();
    streamPropertiesController.init(profileList, selectedProfileIndex);
    updateNextPrevButtonState();
    switch(type) {
        case BUILD_STREAM:
            initStreamBuilder(new BuilderDataBinding());
            showSimpleModeTabs();
            break;
        case EDIT_STREAM:
            initEditStream(pcapFileBinary);
            if (selectedProfile.getStream().getAdvancedMode()) {
                showAdvancedModeTabs();
            } else {
                showSimpleModeTabs();
            }
            break;
        default:
            break;
    }
    return true;
}
Also used : BuilderDataBinding(com.exalttech.trex.ui.views.streams.binders.BuilderDataBinding) ScapyClientNeedConnectEvent(com.xored.javafx.packeteditor.events.ScapyClientNeedConnectEvent)

Example 2 with ScapyClientNeedConnectEvent

use of com.xored.javafx.packeteditor.events.ScapyClientNeedConnectEvent in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketBuilderHomeController method switchEditorMode.

@FXML
public void switchEditorMode(ActionEvent event) throws Exception {
    Stream currentStream = streamPropertiesController.getUpdatedSelectedProfile().getStream();
    boolean advancedMode = currentStream.getAdvancedMode();
    try {
        if (!ConnectionManager.getInstance().isScapyConnected()) {
            eventBus.post(new ScapyClientNeedConnectEvent());
        }
        if (advancedMode) {
            streamEditorModeBtn.setText("Advanced mode");
            currentStream.setAdvancedMode(false);
            showSimpleModeTabs();
        } else {
            if (ConnectionManager.getInstance().isScapyConnected()) {
                if (isImportedStreamProperty.getValue()) {
                    byte[] base64Packet = currentStream.getPacket().getBinary().getBytes();
                    byte[] packet = Base64.getDecoder().decode(base64Packet);
                    packetBuilderController.loadPcapBinary(packet);
                } else {
                    packetBuilderController.loadSimpleUserModel(builderDataBinder.serializeAsPacketModel());
                }
                streamEditorModeBtn.setText("Simple mode");
                currentStream.setAdvancedMode(true);
                showAdvancedModeTabs();
            } else {
                alertWarning("Can't open Advanced mode", "There is no connection to Scapy server." + "\nPlease refer to documentation about" + "\nScapy server and advanced configuration mode.");
            }
        }
    } catch (Exception e) {
        LOG.error("Unable to open advanced mode due to: " + e.getMessage());
        alertWarning("Can't open Advanced mode", "Some errors occurred. See logs for more details.");
    }
}
Also used : ScapyClientNeedConnectEvent(com.xored.javafx.packeteditor.events.ScapyClientNeedConnectEvent) Stream(com.exalttech.trex.remote.models.profiles.Stream) IOException(java.io.IOException) FXML(javafx.fxml.FXML)

Aggregations

ScapyClientNeedConnectEvent (com.xored.javafx.packeteditor.events.ScapyClientNeedConnectEvent)2 Stream (com.exalttech.trex.remote.models.profiles.Stream)1 BuilderDataBinding (com.exalttech.trex.ui.views.streams.binders.BuilderDataBinding)1 IOException (java.io.IOException)1 FXML (javafx.fxml.FXML)1