Search in sources :

Example 1 with TableProfileStream

use of com.exalttech.trex.ui.views.models.TableProfileStream in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketTableView method openStreamDialog.

/**
 * open stream properties
 */
private void openStreamDialog(StreamBuilderType type) {
    try {
        TableProfileStream data = streamPacketTableView.getSelectionModel().getSelectedItem();
        if ("0".equals(data.getLength()) && !Util.isConfirmed("Problem reading file, Do you want to continue anyway ?")) {
            return;
        }
        setStreamEditingWindowOpen(true);
        String windowTitle = "Edit Stream (" + data.getName() + ")";
        if (streamWindow == null) {
            Stage currentStage = (Stage) streamPacketTableView.getScene().getWindow();
            streamWindow = new DialogWindow("PacketBuilderHome.fxml", windowTitle, 40, 30, false, currentStage);
        }
        streamWindow.setTitle(windowTitle);
        PacketBuilderHomeController controller = (PacketBuilderHomeController) streamWindow.getController();
        boolean streaminited = controller.initStreamBuilder(tabledata.getProfiles(), streamPacketTableView.getSelectionModel().getSelectedIndex(), tabledata.getYamlFileName(), type);
        if (streaminited) {
            streamWindow.show(true);
        } else {
            LOG.error("Error while initing editor dialog");
        }
    } catch (Exception ex) {
        LOG.error("Error opening file", ex);
    }
}
Also used : PacketBuilderHomeController(com.exalttech.trex.ui.controllers.PacketBuilderHomeController) TableProfileStream(com.exalttech.trex.ui.views.models.TableProfileStream) Stage(javafx.stage.Stage) DialogWindow(com.exalttech.trex.ui.dialog.DialogWindow) IllegalRawDataException(org.pcap4j.packet.IllegalRawDataException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 2 with TableProfileStream

use of com.exalttech.trex.ui.views.models.TableProfileStream in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketTableView method buildUI.

/**
 * Build component UI
 */
private void buildUI(boolean addExportToYamlBtn) {
    setTopAnchor(this, 0d);
    setLeftAnchor(this, 0d);
    setBottomAnchor(this, 0d);
    setRightAnchor(this, 0d);
    // build btn bar
    HBox buttonContainer = new HBox();
    buttonContainer.setSpacing(5);
    // add build stream btn
    buildPacketBtn = new StreamTableButton(StreamTableAction.BUILD);
    buildPacketBtn.setId("buildStreamBtn");
    initializeStreamButtons(buildPacketBtn, false);
    buttonContainer.getChildren().add(buildPacketBtn);
    editPacketBtn = new StreamTableButton(StreamTableAction.EDIT);
    editPacketBtn.setId("editStreanBtn");
    initializeStreamButtons(editPacketBtn, true);
    buttonContainer.getChildren().add(editPacketBtn);
    duplicatePacketBtn = new StreamTableButton(StreamTableAction.DUPLICATE);
    initializeStreamButtons(duplicatePacketBtn, true);
    buttonContainer.getChildren().add(duplicatePacketBtn);
    deleteButtonBtn = new StreamTableButton(StreamTableAction.DELETE);
    initializeStreamButtons(deleteButtonBtn, true);
    buttonContainer.getChildren().add(deleteButtonBtn);
    importPcapButton = new StreamTableButton(StreamTableAction.IMPORT_PCAP);
    initializeStreamButtons(importPcapButton, false);
    buttonContainer.getChildren().add(importPcapButton);
    exportPcapButton = new StreamTableButton(StreamTableAction.EXPORT_TO_PCAP);
    initializeStreamButtons(exportPcapButton, true);
    buttonContainer.getChildren().add(exportPcapButton);
    if (addExportToYamlBtn) {
        exportToYaml = new StreamTableButton(StreamTableAction.EXPORT_TO_YAML);
        initializeStreamButtons(exportToYaml, false);
        buttonContainer.getChildren().add(exportToYaml);
    }
    getChildren().add(buttonContainer);
    setTopAnchor(buttonContainer, 5d);
    rightClickMenu = new ContextMenu();
    addMenuItem(StreamTableAction.EDIT);
    addMenuItem(StreamTableAction.DUPLICATE);
    addMenuItem(StreamTableAction.DELETE);
    addMenuItem(StreamTableAction.EXPORT_TO_PCAP);
    addMenuItem(StreamTableAction.EXPORT_TO_YAML);
    // add table view
    streamPacketTableView = new TableView<>();
    streamPacketTableView.setId("streamTableView");
    streamPacketTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    streamPacketTableView.setFixedCellSize(32);
    streamPacketTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    streamPacketTableView.setOnMouseClicked(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            handleTableRowClick(event);
        }
    });
    streamPacketTableView.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends TableProfileStream> observable, TableProfileStream oldValue, TableProfileStream newValue) -> {
        boolean notSelected = !(newValue != null);
        exportPcapButton.setDisable(notSelected);
        editPacketBtn.setDisable(notSelected);
        duplicatePacketBtn.setDisable(notSelected);
        deleteButtonBtn.setDisable(notSelected);
    });
    streamPacketTableView.addEventFilter(KeyEvent.KEY_RELEASED, (KeyEvent event) -> {
        if (isEditingCell()) {
            return;
        }
        if (copyCombination.match(event)) {
            copiedProfiles = getSelectedProfiles();
        } else if (pasteCombination.match(event) && !copiedProfiles.isEmpty()) {
            handlePasteStreams(copiedProfiles);
        } else if (event.getCode() == KeyCode.DELETE) {
            handleDeletePacket();
        }
    });
    streamPacketTableView.setEditable(true);
    initializeTableColumn();
    // disable table reordering
    streamPacketTableView.widthProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> source, Number oldWidth, Number newWidth) {
            TableHeaderRow header = (TableHeaderRow) streamPacketTableView.lookup("TableHeaderRow");
            header.reorderingProperty().addListener(new ChangeListener<Boolean>() {

                @Override
                public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                    header.setReordering(false);
                }
            });
        }
    });
    getChildren().add(streamPacketTableView);
    setTopAnchor(streamPacketTableView, 35d);
    setBottomAnchor(streamPacketTableView, 5d);
    setLeftAnchor(streamPacketTableView, 0d);
    setRightAnchor(streamPacketTableView, 0d);
}
Also used : HBox(javafx.scene.layout.HBox) TableHeaderRow(com.sun.javafx.scene.control.skin.TableHeaderRow) TableProfileStream(com.exalttech.trex.ui.views.models.TableProfileStream) ObservableValue(javafx.beans.value.ObservableValue) StreamTableButton(com.exalttech.trex.ui.views.streamtable.StreamTableButton) ChangeListener(javafx.beans.value.ChangeListener)

Example 3 with TableProfileStream

use of com.exalttech.trex.ui.views.models.TableProfileStream in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketTableView method loadStreamTable.

/**
 * Load stream table data
 *
 * @param fileToLoad
 * @return
 * @throws Exception
 */
public Profile[] loadStreamTable(File fileToLoad) throws Exception {
    this.loadedProfile = fileToLoad;
    Profile[] profileList;
    this.profileName = fileToLoad.getName();
    try {
        profileList = trafficProfile.getTrafficProfile(fileToLoad);
    } catch (IOException ex) {
        LOG.warn("Profile does not have any streams");
        profileList = new Profile[0];
    }
    List<TableProfileStream> packetDataList = trafficProfile.convertProfilesToTableData(profileList);
    TableProfile tableData = new TableProfile(new ArrayList<>(Arrays.asList(profileList)), packetDataList, fileToLoad.getPath());
    setPacketData(tableData);
    return profileList;
}
Also used : TableProfile(com.exalttech.trex.ui.views.models.TableProfile) TableProfileStream(com.exalttech.trex.ui.views.models.TableProfileStream) IOException(java.io.IOException) Profile(com.exalttech.trex.remote.models.profiles.Profile) TableProfile(com.exalttech.trex.ui.views.models.TableProfile) TrafficProfile(com.exalttech.trex.util.TrafficProfile)

Example 4 with TableProfileStream

use of com.exalttech.trex.ui.views.models.TableProfileStream in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketTableView method handleAddPacket.

/**
 * Handle Add packet button clicked
 *
 * @param streamName
 * @param type
 */
public void handleAddPacket(String streamName, StreamBuilderType type) {
    TableProfileStream newRow = new TableProfileStream();
    newRow.setName(streamName);
    tabledata.getStreamsList().add(newRow);
    Profile newProfile = new Profile();
    newProfile.setName(streamName);
    newProfile.setStreamId(getNewId());
    tabledata.getProfiles().add(newProfile);
    streamPacketTableView.setItems(FXCollections.observableArrayList(tabledata.getStreamsList()));
    streamPacketTableView.getSelectionModel().select(newRow);
    openStreamDialog(type);
}
Also used : TableProfileStream(com.exalttech.trex.ui.views.models.TableProfileStream) Profile(com.exalttech.trex.remote.models.profiles.Profile) TableProfile(com.exalttech.trex.ui.views.models.TableProfile) TrafficProfile(com.exalttech.trex.util.TrafficProfile)

Example 5 with TableProfileStream

use of com.exalttech.trex.ui.views.models.TableProfileStream in project trex-stateless-gui by cisco-system-traffic-generator.

the class TrafficProfile method convertProfilesToTableData.

/**
 * Convert profiles to equivalent tableProfile data
 *
 * @param profilesList
 * @return
 */
public List<TableProfileStream> convertProfilesToTableData(Profile[] profilesList) {
    List<TableProfileStream> tableData = new ArrayList<>();
    for (int index = 0; index < profilesList.length; index++) {
        Profile p = profilesList[index];
        TableProfileStream stream = new TableProfileStream();
        Mode modeYaml = p.getStream().getMode();
        stream.setIndex(String.valueOf(index + 1));
        stream.setEnabled(p.getStream().isEnabled());
        stream.setName(p.getName());
        stream.setMode(modeYaml.getType());
        String rateUnits = "";
        switch(modeYaml.getRate().getType()) {
            case Rate.RateTypes.PPS:
                rateUnits = "pps";
                break;
            case Rate.RateTypes.BPS_L1:
                rateUnits = "bps L1";
                break;
            case Rate.RateTypes.BPS_L2:
                rateUnits = "bps L2";
                break;
            case Rate.RateTypes.PERCENTAGE:
                rateUnits = "%";
                break;
        }
        stream.setRate(Util.formattedData((long) modeYaml.getRate().getValue(), true) + rateUnits);
        stream.setNextStream(getNextStreamValue(p.getNext()));
        String packetBinary = p.getStream().getPacket().getBinary();
        String packetModel = p.getStream().getPacket().getModel();
        stream.setPcapBinary(packetBinary);
        stream.setPktModel(packetModel);
        PacketInfo packetInfo = getPacketInfo(packetBinary);
        stream.setLength(String.valueOf(packetInfo.getLength() + Constants.EXTRA_BYTE));
        stream.setPacketType(packetInfo.getType());
        tableData.add(stream);
    }
    return tableData;
}
Also used : TableProfileStream(com.exalttech.trex.ui.views.models.TableProfileStream)

Aggregations

TableProfileStream (com.exalttech.trex.ui.views.models.TableProfileStream)5 Profile (com.exalttech.trex.remote.models.profiles.Profile)2 TableProfile (com.exalttech.trex.ui.views.models.TableProfile)2 TrafficProfile (com.exalttech.trex.util.TrafficProfile)2 IOException (java.io.IOException)2 PacketBuilderHomeController (com.exalttech.trex.ui.controllers.PacketBuilderHomeController)1 DialogWindow (com.exalttech.trex.ui.dialog.DialogWindow)1 StreamTableButton (com.exalttech.trex.ui.views.streamtable.StreamTableButton)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TableHeaderRow (com.sun.javafx.scene.control.skin.TableHeaderRow)1 ChangeListener (javafx.beans.value.ChangeListener)1 ObservableValue (javafx.beans.value.ObservableValue)1 HBox (javafx.scene.layout.HBox)1 Stage (javafx.stage.Stage)1 IllegalRawDataException (org.pcap4j.packet.IllegalRawDataException)1