Search in sources :

Example 11 with Profile

use of com.exalttech.trex.remote.models.profiles.Profile in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketTableView method handleDuplicateStream.

/**
     * Handle duplicate stream
     */
public void handleDuplicateStream() {
    try {
        if (selectedProfile != null) {
            Profile clonedProfile = (Profile) selectedProfile.clone();
            clonedProfile.setName(selectedProfile.getName() + "_" + Util.getRandomNumericID(3));
            tabledata.getProfiles().add(clonedProfile);
            Profile[] newProfileDataList = tabledata.getProfiles().toArray(new Profile[tabledata.getProfiles().size()]);
            tabledata.setStreamsList(trafficProfile.convertProfilesToTableData(newProfileDataList));
            saveChangesToYamlFile(newProfileDataList);
        }
    } catch (CloneNotSupportedException | IOException ex) {
        LOG.error("Error duplicationg stream", ex);
    }
}
Also used : IOException(java.io.IOException) TableProfile(com.exalttech.trex.ui.views.models.TableProfile) Profile(com.exalttech.trex.remote.models.profiles.Profile) TrafficProfile(com.exalttech.trex.util.TrafficProfile)

Example 12 with Profile

use of com.exalttech.trex.remote.models.profiles.Profile 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)

Example 13 with Profile

use of com.exalttech.trex.remote.models.profiles.Profile in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketUtil method prepareAndSaveYamlFile.

/**
     * Prepare and save yaml file
     *
     * @param packetRawData
     * @param packetData
     * @throws JsonProcessingException
     * @throws IOException
     */
public void prepareAndSaveYamlFile(byte[] packetRawData, PacketData packetData) throws JsonProcessingException, IOException {
    String encodedBinaryPacket = getEncodedPacket(packetRawData);
    // save pqacket in the profile
    Profile profile = new Profile();
    profile.setName("stream0");
    profile.getStream().getMode().setType("continuous");
    profile.getStream().getPacket().setBinary(encodedBinaryPacket);
    profile.getStream().setAdditionalProperties(getVm(packetData));
    // save data to yaml file
    List<Profile> profileList = new ArrayList();
    profileList.add(profile);
    String yamlData = trafficProfile.getProfileYamlContent(profileList.toArray(new Profile[profileList.size()]));
    File newFile = FileManager.createNewFile(packetData.getTestFileName() + ".yaml");
    FileUtils.writeStringToFile(newFile, yamlData);
}
Also used : File(java.io.File) Profile(com.exalttech.trex.remote.models.profiles.Profile)

Example 14 with Profile

use of com.exalttech.trex.remote.models.profiles.Profile in project trex-stateless-gui by cisco-system-traffic-generator.

the class ProfileStreamNameDialogController method validInput.

/**
     * Validate input
     *
     * @return
     */
private boolean validInput() {
    Alert alert = Util.getAlert(Alert.AlertType.ERROR);
    if (Util.isNullOrEmpty(nameTF.getText())) {
        alert.setContentText("Please fill the empty fields");
        alert.showAndWait();
        return false;
    } else if (profileList != null && !profileWindow) {
        for (Profile p : profileList) {
            if (p.getName().equals(nameTF.getText())) {
                alert.setContentText("Stream name already exists, please select a different Stream name");
                alert.showAndWait();
                return false;
            }
        }
    }
    dataAvailabe = true;
    return true;
}
Also used : Alert(javafx.scene.control.Alert) Profile(com.exalttech.trex.remote.models.profiles.Profile)

Example 15 with Profile

use of com.exalttech.trex.remote.models.profiles.Profile in project trex-stateless-gui by cisco-system-traffic-generator.

the class TrafficProfileDialogController method handleLoadProfileBtnClick.

/**
     * Handle load profile button click
     *
     * @param event
     */
@FXML
public void handleLoadProfileBtnClick(MouseEvent event) {
    String loadFileName = "";
    try {
        FileChooser fileChooser = FileChooserFactory.get();
        FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("YAML Files (*.yaml)", "*.yaml");
        FileChooser.ExtensionFilter allFilesFilter = new FileChooser.ExtensionFilter("All files ", "*.*");
        fileChooser.getExtensionFilters().add(extFilter);
        fileChooser.getExtensionFilters().add(allFilesFilter);
        fileChooser.setTitle("Load Profile File");
        String loadFolderPath = PreferencesManager.getInstance().getLoadLocation();
        if (!Util.isNullOrEmpty(loadFolderPath) && new File(loadFolderPath).exists()) {
            fileChooser.setInitialDirectory(new File(loadFolderPath));
        }
        File loadedFile = fileChooser.showOpenDialog(((Button) (event.getSource())).getScene().getWindow());
        if (loadedFile != null) {
            loadFileName = loadedFile.getName();
            // check if exists in list or not
            if (!ProfileManager.getInstance().isFileExists(loadedFile.getName())) {
                // Read Selected File.
                Profile[] yamlTrafficProfile = trafficProfile.getTrafficProfile(loadedFile);
                // make a copy of selected file
                File localFile = trafficProfile.convertTrafficProfileToYamlFile(yamlTrafficProfile, loadedFile.getName());
                // add it to list
                profileListView.getItems().add(localFile.getName());
                // save the new selected profile
                ProfileManager.getInstance().updateProfilesList(localFile, true);
            }
            profileListView.getSelectionModel().select(loadedFile.getName());
            // enaprofileListView.getSelectionModel().select(localFile.getName());ble delete profile btn
            disableProfileFunctionBtn(false);
        }
    } catch (IOException ex) {
        Alert alert = Util.getAlert(AlertType.ERROR);
        alert.setContentText("Error loading file " + loadFileName);
        alert.showAndWait();
        LOG.error("Error loading the profile", ex);
    }
}
Also used : Button(javafx.scene.control.Button) FileChooser(javafx.stage.FileChooser) Alert(javafx.scene.control.Alert) IOException(java.io.IOException) File(java.io.File) Profile(com.exalttech.trex.remote.models.profiles.Profile) FXML(javafx.fxml.FXML)

Aggregations

Profile (com.exalttech.trex.remote.models.profiles.Profile)18 TrafficProfile (com.exalttech.trex.util.TrafficProfile)8 File (java.io.File)6 IOException (java.io.IOException)6 TableProfile (com.exalttech.trex.ui.views.models.TableProfile)5 TableProfileStream (com.exalttech.trex.ui.views.models.TableProfileStream)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DialogWindow (com.exalttech.trex.ui.dialog.DialogWindow)2 Alert (javafx.scene.control.Alert)2 Window (javafx.stage.Window)2 IncorrectRPCMethodException (com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException)1 InvalidRPCResponseException (com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)1 PortAcquireException (com.exalttech.trex.remote.exceptions.PortAcquireException)1 TrafficException (com.exalttech.trex.remote.exceptions.TrafficException)1 Mode (com.exalttech.trex.remote.models.profiles.Mode)1 PacketInfo (com.exalttech.trex.remote.models.profiles.PacketInfo)1 AssignedProfile (com.exalttech.trex.ui.views.models.AssignedProfile)1 ImportPcapTableData (com.exalttech.trex.ui.views.models.ImportPcapTableData)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 EOFException (java.io.EOFException)1