Search in sources :

Example 1 with ImportPcapTableData

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

the class ImportedPacketTableView method getNextSelectedPacket.

/**
     * Get next selected stream
     *
     * @return
     */
private ImportPcapTableData getNextSelectedPacket() {
    if (index == tableDataList.size()) {
        index++;
        return null;
    }
    ImportPcapTableData tableData = tableDataList.get(index);
    index++;
    if (tableData.isSelected()) {
        return tableData;
    }
    return getNextSelectedPacket();
}
Also used : ImportPcapTableData(com.exalttech.trex.ui.views.models.ImportPcapTableData)

Example 2 with ImportPcapTableData

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

the class ImportedPacketTableView method setTableData.

/**
     * Set table data
     *
     * @param packetInfoList
     */
private void setTableData(List<PacketInfo> packetInfoList) {
    index = 1;
    tableDataList.clear();
    for (PacketInfo packetInfo : packetInfoList) {
        ImportPcapTableData tableData = new ImportPcapTableData();
        tableData.setName("packet_" + index);
        tableData.setIndex(index);
        tableData.setLength(packetInfo.getPacket().length());
        tableData.setMacSrc(packetInfo.getSrcMac());
        tableData.setMacDst(packetInfo.getDestMac());
        tableData.setIpSrc(packetInfo.getSrcIpv4());
        tableData.setIpDst(packetInfo.getDestIpv4());
        tableData.setPacketType(trafficProfile.getPacketTypeText(packetInfo.getPacket()).getType());
        tableData.setPacket(packetInfo.getPacket());
        tableData.setHasVlan(packetInfo.hasVlan());
        tableData.setTimeStamp(packetInfo.getTimeStamp());
        tableDataList.add(tableData);
        index++;
    }
    importedStreamTable.setItems(tableDataList);
}
Also used : PacketInfo(com.exalttech.trex.ui.models.PacketInfo) ImportPcapTableData(com.exalttech.trex.ui.views.models.ImportPcapTableData)

Example 3 with ImportPcapTableData

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

the class ImportedPacketTableView method validateStreamNames.

/**
     * Validate stream names
     *
     * @return
     */
private boolean validateStreamNames() {
    ObservableList<Integer> duplicateIndexesList = FXCollections.observableArrayList();
    duplicateRowNamesMap.clear();
    // validate saved stream names
    for (ImportPcapTableData tableData : tableDataList) {
        if (tableData.isSelected()) {
            // comparing with existing streams
            if ((existingNamesList.contains(tableData.getName()) || Util.isNullOrEmpty(tableData.getName().trim()))) {
                addDuplicateIndex(duplicateIndexesList, tableData);
            }
            // compairing with other streams in list
            if (duplicateRowNamesMap.get(tableData.getName()) != null) {
                // name is duplicate
                addDuplicateIndex(duplicateIndexesList, tableData);
                addDuplicateIndex(duplicateIndexesList, duplicateRowNamesMap.get(tableData.getName()));
            } else {
                // add existing names in imported table
                duplicateRowNamesMap.put(tableData.getName(), tableData);
            }
        }
    }
    highlightedRowFactory.getRowsToHighlight().setAll(duplicateIndexesList);
    boolean validNames = true;
    if (!duplicateIndexesList.isEmpty()) {
        validNames = false;
        Alert alert = Util.getAlert(Alert.AlertType.ERROR);
        alert.setContentText("Some packet names (highlighted in red) have the same names of exisiting packets !");
        alert.showAndWait();
    }
    return validNames;
}
Also used : Alert(javafx.scene.control.Alert) ImportPcapTableData(com.exalttech.trex.ui.views.models.ImportPcapTableData)

Example 4 with ImportPcapTableData

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

the class ImportedPacketTableView method doImport.

/**
     * Import pcap to current yaml file
     *
     * @return
     */
public boolean doImport() {
    try {
        if (validateStreamNames()) {
            index = 0;
            ImportPcapTableData current = getNextSelectedPacket();
            firstPacket = current;
            ImportPcapTableData next = null;
            boolean firstStream = true;
            long diffTimeStamp = 1;
            while (index <= tableDataList.size()) {
                if (current != null) {
                    Profile profile = new Profile();
                    profile.setName(current.getName());
                    profile.getStream().getMode().setType("single_burst");
                    String hexDataString = PacketBuilderHelper.getPacketHex(current.getPacket().getRawData());
                    profile.getStream().getPacket().setBinary(trafficProfile.encodeBinaryFromHexString(hexDataString));
                    // add vm
                    profile.getStream().setAdditionalProperties(getVm(current));
                    // update pps/ISG
                    defineISG_PPSValues(profile, getIpg(diffTimeStamp, firstStream));
                    if (firstStream) {
                        firstStream = false;
                    }
                    // get next stream 
                    next = getNextSelectedPacket();
                    if (next != null && next != current) {
                        profile.setNext(next.getName());
                        diffTimeStamp = next.getTimeStamp() - current.getTimeStamp();
                    } else if (propertiesBinder.getCount() > 0) {
                        profile.setNext(firstPacket.getName());
                        profile.getStream().setActionCount(propertiesBinder.getCount());
                    }
                    current = next;
                    profilesList.add(profile);
                }
            }
            // save yaml data
            String yamlData = trafficProfile.convertTrafficProfileToYaml(profilesList.toArray(new Profile[profilesList.size()]));
            FileUtils.writeStringToFile(new File(yamlFileName), yamlData);
            return true;
        }
    } catch (Exception ex) {
        LOG.error("Error saving Yaml file", ex);
    }
    return false;
}
Also used : ImportPcapTableData(com.exalttech.trex.ui.views.models.ImportPcapTableData) File(java.io.File) Profile(com.exalttech.trex.remote.models.profiles.Profile) TrafficProfile(com.exalttech.trex.util.TrafficProfile) TimeoutException(java.util.concurrent.TimeoutException) NotOpenException(org.pcap4j.core.NotOpenException) PcapNativeException(org.pcap4j.core.PcapNativeException) EOFException(java.io.EOFException)

Aggregations

ImportPcapTableData (com.exalttech.trex.ui.views.models.ImportPcapTableData)4 Profile (com.exalttech.trex.remote.models.profiles.Profile)1 PacketInfo (com.exalttech.trex.ui.models.PacketInfo)1 TrafficProfile (com.exalttech.trex.util.TrafficProfile)1 EOFException (java.io.EOFException)1 File (java.io.File)1 TimeoutException (java.util.concurrent.TimeoutException)1 Alert (javafx.scene.control.Alert)1 NotOpenException (org.pcap4j.core.NotOpenException)1 PcapNativeException (org.pcap4j.core.PcapNativeException)1