use of com.exalttech.trex.remote.models.profiles.Profile in project trex-stateless-gui by cisco-system-traffic-generator.
the class PacketBuilderHomeController method saveStream.
private boolean saveStream() {
try {
String fieldEngineError = packetBuilderController.getFieldEngineError();
if (!Strings.isNullOrEmpty(fieldEngineError)) {
streamTabPane.getSelectionModel().select(fieldEngineTab);
LOG.error("Unable to save stream due to errors in Field Engine:" + fieldEngineError);
return false;
}
updateCurrentProfile();
if (streamPropertiesController.isValidStreamPropertiesFields()) {
String yamlData = trafficProfile.convertTrafficProfileToYaml(profileList.toArray(new Profile[profileList.size()]));
FileUtils.writeStringToFile(new File(yamlFileName), yamlData);
Util.optimizeMemory();
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 Util method tuneJSONParams.
/**
* This method tunes the JSON Params. This method was added as the original
* requirement was to use the VM and RX_Stat as is but it is not the case.
*
* @param jsonString
* @param params
* @param apiH
* @return
*/
public static String tuneJSONParams(String jsonString, Params params, String apiH) {
String tunedString = jsonString;
if (tunedString.contains("\"params\":{")) {
tunedString = tunedString.replace("\"params\":{", "\"params\":{ \"api_h\": \"" + apiH + "\",");
}
if (params instanceof Profile) {
String vm = "\"vm\": " + "{\n" + " \"instructions\": [],\n" + " \"split_by_var\": \"\"\n" + " }";
String rxStats = "\"rx_stats\": " + "{\n" + " \"enabled\": false\n" + " }";
if (!tunedString.contains("\"vm\"")) {
tunedString = tunedString.replace("\"self_start\"", vm + ",\r" + "\"self_start\"");
}
if (!tunedString.contains("\"rx_stats\"")) {
tunedString = tunedString.replace("\"self_start\"", rxStats + ",\r" + "\"self_start\"");
}
if (tunedString.contains("\"vm\":[]")) {
tunedString = tunedString.replace("\"vm\":[]", vm);
}
if (tunedString.contains("\"rx_stats\":[]")) {
tunedString = tunedString.replace("\"rx_stats\":[]", rxStats);
}
// Add Split by vars in the VM if missing.
if (!tunedString.contains("split_by_var")) {
tunedString = tunedString.replace("\"vm\":{", "\"vm\":{\n" + " \"split_by_var\": \"\",\n");
}
// Remove quotes from uInt32
String pattern = "\"0x[^\"]*\"";
String originalString = tunedString;
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(originalString);
while (m.find()) {
String hexString = m.group(0).replace("\"", "").replace("0x", "");
int hexValue = (int) Integer.valueOf(hexString, SHORT_LENGTH);
tunedString = tunedString.replace(m.group(0), "" + hexValue);
}
return tunedString;
}
return tunedString;
}
use of com.exalttech.trex.remote.models.profiles.Profile in project trex-stateless-gui by cisco-system-traffic-generator.
the class TrafficProfile method getTrafficProfile.
/**
* @param yamlFile File containing the Traffic Profile Yaml.
* @return parsed Yaml file
* @throws java.io.IOException
*/
public Profile[] getTrafficProfile(File yamlFile) throws IOException {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
Profile[] trafficProfileArray = mapper.readValue(yamlFile, Profile[].class);
int i = 0;
for (Profile profile : trafficProfileArray) {
Map<String, Object> streamAdditionalProperties = profile.getStream().getAdditionalProperties();
if (streamAdditionalProperties.containsKey("vm")) {
profile.getStream().setVmRaw(streamAdditionalProperties.get("vm").toString());
}
if (streamAdditionalProperties.containsKey("rx_stats")) {
profile.getStream().setRxStatsRaw(streamAdditionalProperties.get("rx_stats").toString());
}
// Check the Binary is in the Yaml File
if (profile.getStream().getPacket().getBinary() == null) {
String absolutePath = yamlFile.getAbsolutePath();
String filePath = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));
String pacpFile = profile.getStream().getPacket().getPcap();
String encodedPcap = encodePcapFile(filePath + File.separator + pacpFile);
profile.getStream().getPacket().setBinary(encodedPcap);
}
profile.getStream().getPacket().setPcap(null);
if (profile.getName() == null) {
profile.setName("Stream" + i++);
}
}
return trafficProfileArray;
}
use of com.exalttech.trex.remote.models.profiles.Profile in project trex-stateless-gui by cisco-system-traffic-generator.
the class TrafficProfile method convertStreamNameToInteger.
/**
* Convert stream name to integer
*
* @param trafficProfileArray
* @return
*/
public Map<String, Integer> convertStreamNameToInteger(Profile[] trafficProfileArray) {
HashMap<String, Integer> streamNameMap = new HashMap<>();
int streamID = 0;
for (Profile profile : trafficProfileArray) {
if (!streamNameMap.containsKey(profile.getName())) {
streamNameMap.put(profile.getName(), streamID++);
}
}
return streamNameMap;
}
use of com.exalttech.trex.remote.models.profiles.Profile in project trex-stateless-gui by cisco-system-traffic-generator.
the class TrafficProfile method convertTrafficProfileToJson.
/**
* @param trafficProfileArray
* @param portID
* @param handler
* @return returns a formatted JSON Array of Streams for a given port
* @throws Exception
*
*/
public String convertTrafficProfileToJson(Profile[] trafficProfileArray, int portID, String handler) throws Exception {
Profile[] preparedTrafficProfile = prepareTrafficProfile(trafficProfileArray, portID, handler);
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(preparedTrafficProfile);
return Util.toPrettyFormat(jsonString);
}
Aggregations