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);
}
}
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;
}
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);
}
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;
}
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);
}
}
Aggregations