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