List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:com.devoteam.srit.xmlloader.core.operations.basic.operators.PluggableParameterOperatorFile.java
License:Open Source License
@Override public Parameter operate(Runner runner, Map<String, Parameter> operands, String name, String resultant) throws Exception { normalizeParameters(operands);/*from w w w.j av a 2 s. c om*/ Parameter path = assertAndGetParameter(operands, "value", "path"); Parameter result = new Parameter(); if (path.length() > 0) { URI filePathURI = URIRegistry.MTS_TEST_HOME.resolve(path.get(0).toString()); if (name.equals(NAME_B_WRITE) || name.equals(NAME_S_WRITE)) { Parameter data = assertAndGetParameter(operands, "value2", "data"); if (data.length() != 0) { String fileData = data.get(0).toString(); File file = new File(filePathURI); if (!file.exists()) file.createNewFile(); OutputStream out = new FileOutputStream(file, true); Array array; if (name.equals(NAME_B_WRITE)) { array = Array.fromHexString(fileData); } else { array = new DefaultArray(fileData.getBytes()); } out.write(array.getBytes()); out.close(); } result = null; } else if (name.equals(NAME_B_READ) || name.equals(NAME_S_READ)) { File file = new File(filePathURI); byte[] bytes = new byte[(int) file.length()]; InputStream in = new FileInputStream(file); in.read(bytes); in.close(); if (name.equals(NAME_B_READ)) { result.add(Array.toHexString(new DefaultArray(bytes))); } else { result.add(new String(bytes)); } } else if (name.equals(NAME_CREATE)) { File file = new File(filePathURI); if (file.exists()) file.delete(); file.createNewFile(); result = null; } else if (name.equals(NAME_REMOVE)) { new File(filePathURI).delete(); result = null; } else if (name.equals(NAME_EXISTS)) { result.add(new File(filePathURI).exists()); } else if (name.equals(NAME_READPROPERTY)) { normalizeParameters(operands); Parameter config = path; Parameter property = PluggableParameterOperatorList.assertAndGetParameter(operands, "value2"); String configName = ""; String propertyName = ""; configName = config.get(0).toString(); propertyName = property.get(0).toString(); result.add(Config.getConfigByName(configName).getString(propertyName)); } else if (name.equals(NAME_LISTPROPERTYKEYS)) { normalizeParameters(operands); Parameter config = path; String configName = ""; configName = config.get(0).toString(); Vector<String> names = Config.getConfigByName(configName).getPropertiesEnhanced() .getNameOfAllParameters(); for (String key : names) { result.add(key); } } else if (name.equals(NAME_READCSV)) { Parameter csvCol = PluggableParameterOperatorList.assertAndGetParameter(operands, "value2"); String comment = Config.getConfigByName("tester.properties") .getString("operations.CSV_COMMENT_CHAR", "#"); String separator = Config.getConfigByName("tester.properties") .getString("operations.CSV_SEPARATOR_CHAR", ";"); String escape = Config.getConfigByName("tester.properties").getString("operations.CSV_ESCAPE_CHAR", "\""); CSVReader csvReader = new CSVReader(comment, separator, escape + escape); String var2 = csvCol.get(0).toString(); int column = -1; List<String> listData = null; if (Utils.isInteger(var2)) { column = Integer.parseInt(var2); listData = csvReader.loadData(filePathURI, column, false); } else { // get the header line to retrieve the column number String[] listHeader = csvReader.loadHeader(filePathURI); for (int j = 0; j < listHeader.length; j++) { if (listHeader[j].equals(var2.trim())) { column = j; break; } } if (column >= 0) { listData = csvReader.loadData(filePathURI, column, true); } } if (listData != null) { result.addAll(listData); } } else if (name.equals(NAME_READMEDIA)) { String resultantUnbracketed = ParameterPool.unbracket(resultant); Parameter payloadList = new Parameter(resultantUnbracketed + ".payload"); Parameter timestampList = new Parameter(resultantUnbracketed + ".timestampList"); Parameter seqList = new Parameter(resultantUnbracketed + ".seqList"); Parameter payloadType = new Parameter(resultantUnbracketed + ".payloadType"); Parameter deltaTime = new Parameter(resultantUnbracketed + ".deltaTime"); Parameter markList = new Parameter(resultantUnbracketed + ".markList"); boolean isPayloadTypeSet = false; long timestamp = 0; long oldTimestamp = 0; long diffTimestamp = 0; String value = null; Element node = null; InputStream in = null; Document document = null; try { SAXReader reader = new SAXReader(); in = SingletonFSInterface.instance().getInputStream(filePathURI); document = reader.read(in); in.close(); } catch (Exception e) { if (in != null) in.close(); throw e; } //parsing du fichier List listNode = document.selectNodes( "//proto[@name='geninfo' or @name='rtp']/field[@name='timestamp' or @name='rtp.payload' or @name='rtp.seq' or @name='rtp.timestamp' or @name='rtp.p_type' or @name='rtp.marker']");//5s for 50000 for (int j = 0; j < listNode.size(); j++)//parse all rtp message { node = (Element) listNode.get(j); value = node.attributeValue("name"); if (value.equalsIgnoreCase("rtp.payload")) { value = node.attributeValue("value");//get payload in hexa string payloadList.add(value); } else if (value.equalsIgnoreCase("rtp.timestamp")) { value = node.attributeValue("show");//get timestamp timestampList.add(Long.parseLong(value)); } else if (value.equalsIgnoreCase("rtp.seq")) { value = node.attributeValue("show");//get seqnum seqList.add(Long.parseLong(value)); } else if (value.equalsIgnoreCase("rtp.marker")) { value = node.attributeValue("show");//get mark header markList.add((Integer) Integer.parseInt(value)); } else if (!isPayloadTypeSet && value.equalsIgnoreCase("rtp.p_type")) { value = node.attributeValue("show");//get payloadType payloadType.add((Integer) Integer.parseInt(value)); isPayloadTypeSet = true; } else if (value.equalsIgnoreCase("timestamp"))//get arrival time, useful to calculate deltaTime between each packet { value = node.attributeValue("value");//get capture timestamp timestamp = (long) (Double.parseDouble(value) * 1000);//convert in ms if (oldTimestamp != 0)//for all messages except the first received { diffTimestamp = timestamp - oldTimestamp; } oldTimestamp = timestamp; deltaTime.add(diffTimestamp); } } runner.getParameterPool().set("[" + resultantUnbracketed + ".payload" + "]", payloadList); runner.getParameterPool().set("[" + resultantUnbracketed + ".timestamp" + "]", timestampList); runner.getParameterPool().set("[" + resultantUnbracketed + ".seq" + "]", seqList); runner.getParameterPool().set("[" + resultantUnbracketed + ".payloadType" + "]", payloadType); runner.getParameterPool().set("[" + resultantUnbracketed + ".deltaTime" + "]", deltaTime); runner.getParameterPool().set("[" + resultantUnbracketed + ".markList" + "]", markList); result.add(resultantUnbracketed + ".payload"); result.add(resultantUnbracketed + ".timestamp"); result.add(resultantUnbracketed + ".seq"); result.add(resultantUnbracketed + ".payloadType"); result.add(resultantUnbracketed + ".deltaTime"); result.add(resultantUnbracketed + ".markList"); } else if (name.equals(NAME_READWAVE)) { String resultantUnbracketed = ParameterPool.unbracket(resultant); Parameter payloadList = new Parameter(resultantUnbracketed + ".payload"); Parameter payloadType = new Parameter(resultantUnbracketed + ".payloadType"); Parameter bitRate = new Parameter(resultantUnbracketed + ".bitRate"); InputStream in = null; WAVReader waveFileReader = null; AudioFileFormat format = null; try { in = SingletonFSInterface.instance().getInputStream(filePathURI); if (in == null) { Exception e = new FileNotFoundException(filePathURI.toString() + " file is not found."); throw e; } waveFileReader = new WAVReader(); format = waveFileReader.getAudioFileFormat(in); in.close(); } catch (Exception e) { if (in != null) in.close(); throw e; } if (format != null) { byte[] payload = waveFileReader.getPayload(); //recuperation du nombre de paquets par ech a partir du fichier xml Parameter paraDeltaTimeMilliSec = PluggableParameterOperatorList.assertAndGetParameter(operands, "value2"); String strDeltaTimeMilliSec = paraDeltaTimeMilliSec.get(0).toString(); int deltaTimeMilliSec = Integer.parseInt(strDeltaTimeMilliSec); int nbEchPerPacket = deltaTimeMilliSec * waveFileReader.getBitRate() / 8; //recuperation du nombre totale de paquets int nbPacket = payload.length / nbEchPerPacket; int nbFullPacket = nbPacket; int nbEchInLastPacket = 0; if (payload.length % nbEchPerPacket != 0) { //si la division a un reste, un rajoute un paquet qui ne sera pas plein nbEchInLastPacket = payload.length - nbEchPerPacket * nbPacket; nbPacket++; } //recuperation et decoupage du payload byte[] val; for (int j = 0; j < payload.length; j += nbEchPerPacket) { DefaultArray temp; if (j < nbFullPacket * nbEchPerPacket) { val = new byte[nbEchPerPacket]; for (int k = j; k < j + nbEchPerPacket; k++) { val[k - j] = payload[k]; } temp = new DefaultArray(val); payloadList.add(Array.toHexString(temp)); } else { val = new byte[nbEchInLastPacket]; //on ajoute le dernier paquet qui ne sera pas plein for (int k = j; k < j + nbEchInLastPacket; k++) { val[k - j] = payload[k]; } temp = new DefaultArray(val); payloadList.add(Array.toHexString(temp)); } } int payloadTypeInt = waveFileReader.getPayloadType(); if (!(payloadTypeInt != 0) && !(payloadTypeInt != 8)) { throw new ParameterException("The codec is not supported : " + payloadTypeInt); } payloadType.add(payloadTypeInt); bitRate.add(waveFileReader.getBitRate()); runner.getParameterPool().set("[" + resultantUnbracketed + ".payload" + "]", payloadList); runner.getParameterPool().set("[" + resultantUnbracketed + ".payloadType" + "]", payloadType); runner.getParameterPool().set("[" + resultantUnbracketed + ".bitRate" + "]", bitRate); result.add(resultantUnbracketed + ".payload"); result.add(resultantUnbracketed + ".payloadType"); result.add(resultantUnbracketed + ".bitRate"); } } else if (name.equals(NAME_WRITEWAVE)) { byte[] chunkID = "RIFF".getBytes(); byte[] chunkSize; byte[] format = "WAVE".getBytes(); byte[] subChunk1ID = "fmt ".getBytes(); byte[] subChunk1Size; byte[] audioFormat; byte[] numberChannels; byte[] sampleRate; byte[] byteRate; byte[] blockAlign; byte[] bitsPerSample; byte[] subChunkFactID = "fact".getBytes(); byte[] subChunkFactSize; byte[] fact; byte[] subChunk2ID = "data".getBytes(); byte[] subChunk2Size; byte[] payload; CodecDictionary dico = new CodecDictionary(); Parameter paraPayloadType = PluggableParameterOperatorList.assertAndGetParameter(operands, "value2"); String strPayloadType = paraPayloadType.get(0).toString(); int payloadType = Integer.parseInt(strPayloadType); if (payloadType != 0 && payloadType != 8) { throw new Exception("Payload Type not supported yet"); } Protocol protocol = dico.getProtocol(payloadType); int formatAudio; if (protocol == null) { formatAudio = 6;//default value for PCMA } else { formatAudio = protocol.getCompressionCode(); } if (formatAudio < 0) { formatAudio = 6; } audioFormat = Utils.convertFromIntegerToByte(formatAudio, 2); audioFormat = Utils.convertToLittleEndian(audioFormat); Parameter paraNbChannel = PluggableParameterOperatorList.getParameter(operands, "value6"); int nbChannels; if (paraNbChannel != null && paraNbChannel.length() > 0) { String strNbChannel = paraNbChannel.get(0).toString(); nbChannels = Integer.parseInt(strNbChannel); } else { if (protocol == null) { nbChannels = 1; } else { nbChannels = protocol.getNbChannel(); } if (nbChannels <= 0) { nbChannels = 1; } } numberChannels = Utils.convertFromIntegerToByte(nbChannels, 2); numberChannels = Utils.convertToLittleEndian(numberChannels); Parameter paraSampleRate = PluggableParameterOperatorList.getParameter(operands, "value5"); int rateSample; if (paraSampleRate != null && paraSampleRate.length() > 0) { String strSampleRate = paraSampleRate.get(0).toString(); rateSample = Integer.parseInt(strSampleRate); } else { if (protocol == null) { rateSample = 8000;//8000 default value for PCMA/PCMU } else { rateSample = protocol.getClockRate(); } if (rateSample <= 0) { rateSample = 8000; } } sampleRate = Utils.convertFromIntegerToByte(rateSample, 4); sampleRate = Utils.convertToLittleEndian(sampleRate); Parameter paraBitsPerSample = PluggableParameterOperatorList.getParameter(operands, "value4"); int bitsSample; if (paraBitsPerSample != null && paraBitsPerSample.length() > 0) { String strBitsPerSample = paraBitsPerSample.get(0).toString(); bitsSample = Integer.parseInt(strBitsPerSample); } else { bitsSample = 8;//8 par defaut } bitsPerSample = Utils.convertFromIntegerToByte(bitsSample, 2); bitsPerSample = Utils.convertToLittleEndian(bitsPerSample); int alignBlock = bitsSample * nbChannels / 8; blockAlign = Utils.convertFromIntegerToByte(alignBlock, 2); blockAlign = Utils.convertToLittleEndian(blockAlign); int rateByte = bitsSample * nbChannels * rateSample / 8; byteRate = Utils.convertFromIntegerToByte(rateByte, 4); byteRate = Utils.convertToLittleEndian(byteRate); Parameter paraPayloadBinary = PluggableParameterOperatorList.assertAndGetParameter(operands, "value3"); SupArray concat = new SupArray(); String temp; for (int k = 0; k < paraPayloadBinary.length(); k++) { temp = (String) paraPayloadBinary.get(k); concat.addLast(Array.fromHexString(temp)); } payload = concat.getBytes(); subChunk2Size = Utils.convertFromIntegerToByte(payload.length, 4); subChunk2Size = Utils.convertToLittleEndian(subChunk2Size); int sub1 = 28;//16 (same for all) + 12 (for PCMA: "fact" field) subChunk1Size = Utils.convertFromIntegerToByte(sub1, 4); subChunk1Size = Utils.convertToLittleEndian(subChunk1Size); int sub0 = 4 + (8 + sub1) + (8 + payload.length); chunkSize = Utils.convertFromIntegerToByte(sub0, 4); chunkSize = Utils.convertToLittleEndian(chunkSize); int subFact = 4; subChunkFactSize = Utils.convertFromIntegerToByte(subFact, 4); subChunkFactSize = Utils.convertToLittleEndian(subChunkFactSize); fact = subChunk2Size; int totalLength = chunkID.length + chunkSize.length + format.length + subChunk1ID.length + subChunk1Size.length + audioFormat.length + numberChannels.length + sampleRate.length + byteRate.length + blockAlign.length + bitsPerSample.length + subChunkFactID.length + subChunkFactSize.length + fact.length + subChunk2ID.length + subChunk2Size.length + payload.length; byte[] buf = new byte[totalLength]; System.arraycopy(chunkID, 0, buf, 0, 4); System.arraycopy(chunkSize, 0, buf, 4, 4); System.arraycopy(format, 0, buf, 8, 4); System.arraycopy(subChunk1ID, 0, buf, 12, 4); System.arraycopy(subChunk1Size, 0, buf, 16, 4); System.arraycopy(audioFormat, 0, buf, 20, 2); System.arraycopy(numberChannels, 0, buf, 22, 2); System.arraycopy(sampleRate, 0, buf, 24, 4); System.arraycopy(byteRate, 0, buf, 28, 4); System.arraycopy(blockAlign, 0, buf, 32, 2); System.arraycopy(bitsPerSample, 0, buf, 34, 2); System.arraycopy(subChunkFactID, 0, buf, 36, 4); System.arraycopy(subChunkFactSize, 0, buf, 40, 4); System.arraycopy(fact, 0, buf, 44, 4); System.arraycopy(subChunk2ID, 0, buf, 48, 4); System.arraycopy(subChunk2Size, 0, buf, 52, 4); System.arraycopy(payload, 0, buf, 56, payload.length); File myFile = new File(filePathURI); if (myFile.exists()) { myFile.delete(); } if (buf.length > 0) { OutputStream out = null; try { out = SingletonFSInterface.instance().getOutputStream(filePathURI); out.write(buf); out.close(); } catch (Exception e) { if (out != null) out.close(); throw e; } } result = null; } else { throw new RuntimeException("unsupported operation " + name); } } return result; }
From source file:com.devoteam.srit.xmlloader.core.operations.functions.Function.java
License:Open Source License
public Function(Element root, Scenario scenario, long version) throws Exception { _name = root.attributeValue("name"); _version = version;/* ww w. j av a 2s. co m*/ _root = root; // TODO : handle stopCount better (at executions and not parsing ?) _do = new OperationSequence(root.element("do"), scenario); }
From source file:com.devoteam.srit.xmlloader.core.operations.functions.Function.java
License:Open Source License
public HashMap<String, Parameter> execute(Runner runner, HashMap<String, Parameter> inputs) throws Exception { HashMap<String, Parameter> outputs = new HashMap(); try {/*ww w .j a va 2s.c o m*/ // check args (type, mandatory, create with default value if necessary ...) // also extract the parameters from the input hashmap and put them into the pool ((ScenarioRunner) runner).stackFunctionParameterPool(); for (Object object : _root.selectNodes("./input/parameter")) { Element element = (Element) object; String inputName = element.attributeValue("name"); String inputDefault = element.attributeValue("default"); String inputType = element.attributeValue("type"); if (!Parameter.matchesParameter(inputName)) { throw new ExecutionException( "invalid input argument name format in function call\r\n" + element.asXML(), null); } if (inputName.contains("function:")) { inputName = Utils.replaceNoRegex(inputName, "function:", ""); } Parameter inputParameter = inputs.get(inputName); if (null == inputParameter && inputDefault != null) { inputParameter = new Parameter(); if (!"EMPTY_LIST".equals(inputDefault)) { inputParameter.add(inputDefault); } } else if (null == inputParameter && inputDefault == null) { throw new ExecutionException( "mandatory input argument (no default value) not passed from the function call\r\n" + element.asXML(), null); } // check the type checkType(inputParameter, inputType); runner.getParameterPool().set(inputName, inputParameter); } // put the input args them into the pool for (Entry<String, Parameter> entry : inputs.entrySet()) { runner.getParameterPool().set(entry.getKey(), entry.getValue()); } // execute the function _do.execute(runner); // extract the parameters from the pool and put them into the output hashmap for (Object object : _root.selectNodes("./output/parameter")) { Element element = (Element) object; String outputName = element.attributeValue("name"); if (outputName.contains("function:")) { outputName = Utils.replaceNoRegex(outputName, "function:", ""); } if (!runner.getParameterPool().existsLocal(outputName)) { throw new ExecutionException( "invalid ouput arg value (does not exists) in function def\r\n" + element.asXML(), null); } outputs.put(outputName, runner.getParameterPool().get(outputName)); } } finally { ((ScenarioRunner) runner).unstackFunctionParameterPool(); } return outputs; }
From source file:com.devoteam.srit.xmlloader.core.operations.protocol.OperationReceiveMessage.java
License:Open Source License
/** * Creates a new instance of ReceiveMsgOperation *//*w ww. jav a 2 s . co m*/ public OperationReceiveMessage(String protocol, Element rootNode, Scenario aScenario) throws Exception { super(rootNode, XMLElementDefaultParser.instance(), false); this.protocol = protocol; operations = new LinkedList<Operation>(); scenario = aScenario; //part for deprecated grammar String connexion = rootNode.attributeValue("connexionName"); if (null != connexion) { addParameterTestTag(rootNode, "string.equals", "channel.name", connexion); } //part for deprecated grammar String request = rootNode.attributeValue("request"); String listenpoint = rootNode.attributeValue("listenpoint"); String channel = rootNode.attributeValue("channel"); String type = rootNode.attributeValue("type"); String result = rootNode.attributeValue("result"); String probe = rootNode.attributeValue("probe"); //for DIAMETER Protocol /* * if ((protocol == StackFactory.PROTOCOL_DIAMETER) && (type != null) && (!Utils.isInteger(type))) { // use ApplicationID "base" but will search in all Applications anyway * com.devoteam.srit.xmlloader.diameter.dictionary.CommandDef commandDef = com.devoteam.srit.xmlloader.diameter.dictionary.Dictionary.getInstance().getCommandDefByName(type, "base"); if (null * != commandDef) { type = Integer.toString(commandDef.get_code()); } } */ if (null != protocol) { addParameterTestTag(rootNode, "string.startsWith", "message.protocol", protocol); } if (null != request) { addParameterTestTag(rootNode, "string.equals", "message.request", new Boolean(request).toString()); } if (null != channel) { addParameterTestTag(rootNode, "string.equals", "channel.name", channel); } if (null != listenpoint) { addParameterTestTag(rootNode, "string.equals", "listenpoint.name", listenpoint); } if (null != type) { addParameterTestTag(rootNode, "string.contains", "message.typeComparison", ":" + type + ":"); } if (null != result) { addParameterTestTag(rootNode, "string.contains", "message.resultComparison", result); } if (null != probe) { addParameterTestTag(rootNode, "string.equals", "probe.name", probe); } parse(rootNode); }
From source file:com.devoteam.srit.xmlloader.core.protocol.Channel.java
License:Open Source License
/** * Parse the channel from XML element /*w w w .ja v a2 s.co m*/ */ public void parseFromXml(Element root, Runner runner, String protocol) throws Exception { this.protocol = protocol; this.name = root.attributeValue("name"); String localHost = root.attributeValue("localHost"); if (localHost != null) { localHost = InetAddress.getByName(localHost).getHostAddress(); this.localHost = Utils.formatIPAddress(localHost); } String localPort = root.attributeValue("localPort"); if (localPort != null) { this.localPort = Integer.parseInt(localPort); } String localURL = root.attributeValue("localURL"); if (localURL != null) { URI uri = new URI(localURL).normalize(); this.localHost = uri.getHost(); this.localPort = uri.getPort(); } String remoteHost = root.attributeValue("remoteHost"); if (remoteHost != null) { remoteHost = InetAddress.getByName(remoteHost).getHostAddress(); this.remoteHost = Utils.formatIPAddress(remoteHost); } String remotePort = root.attributeValue("remotePort"); if (remotePort != null) { this.remotePort = Integer.parseInt(remotePort); } String remoteURL = root.attributeValue("remoteURL"); if (remoteURL != null) { URI uri = new URI(remoteURL).normalize(); this.remoteHost = uri.getHost(); this.remotePort = uri.getPort(); } String transport = root.attributeValue("transport"); if (transport == null) { transport = stack.getConfig().getString("listenpoint.TRANSPORT"); } this.transport = transport.toUpperCase(); }
From source file:com.devoteam.srit.xmlloader.core.protocol.Listenpoint.java
License:Open Source License
/** Creates a Listenpoint specific from XML tree*/ public Listenpoint(Stack stack, Element root) throws Exception { this(stack);/*from w w w . j av a2 s . co m*/ // deprecated message this.name = root.attributeValue("providerName"); if (this.name == null) { this.name = root.attributeValue("name"); } this.host = Utils.formatIPAddress(root.attributeValue("localHost")); if (null == this.host || this.host.length() <= 0) { this.host = "0.0.0.0"; } String portAttr = root.attributeValue("localPort"); if (portAttr != null) { this.port = Integer.parseInt(portAttr); } else { this.port = 0; } String listenUDPAttr = root.attributeValue("listenUDP"); if (listenUDPAttr != null) { this.listenUDP = Boolean.parseBoolean(listenUDPAttr); } String listenTCPAttr = root.attributeValue("listenTCP"); if (listenTCPAttr != null) { this.listenTCP = Boolean.parseBoolean(listenTCPAttr); } String listenSCTPAttr = root.attributeValue("listenSCTP"); if (listenSCTPAttr != null) { this.listenSCTP = Boolean.parseBoolean(listenSCTPAttr); } String listenTLSAttr = root.attributeValue("listenTLS"); if (listenTLSAttr != null) { this.listenTLS = Boolean.parseBoolean(listenTLSAttr); } String localPortTLSAttr = root.attributeValue("localPortTLS"); if ((this.listenTLS) && (localPortTLSAttr == null) && (this.portTLS > 0)) { throw new ExecutionException( "The attribute \"localPortTLS\" is required because you have asked to listen on TLS; please set this attribute on the <createListenpointPPP> operation."); } if (localPortTLSAttr != null && Utils.isInteger(localPortTLSAttr)) { this.portTLS = Integer.parseInt(localPortTLSAttr); } else { this.portTLS = 0; } if (this.portTLS <= 0) { this.portTLS = this.port + 1; } String transportAttr = root.attributeValue("transport"); if (transportAttr != null) { this.transport = transportAttr; } }
From source file:com.devoteam.srit.xmlloader.core.protocol.Probe.java
License:Open Source License
/** Creates a Probe specific from XML tree*/ public Probe(Stack stack, Element root) throws Exception { this.stack = stack; this.name = root.attributeValue("name"); this.networkInterface = root.attributeValue("networkInterface"); String capFilter = root.attributeValue("captureFilter"); if (capFilter != null) { capFilter = Utils.replaceNoRegex(capFilter, "[", ""); capFilter = Utils.replaceNoRegex(capFilter, "]", ""); }//from w w w. jav a 2 s . c o m this.captureFilter = capFilter; this.filename = root.attributeValue("filename"); this.regexFilter = root.attributeValue("regexFilter"); this.sockets = new ExpireHashMap<String, PTCPSocket>("captured TCP streams", 600000); if (regexFilter != null && !regexFilter.equals("")) { this.pattern = Pattern.compile(regexFilter); } else { this.pattern = null; } this.promiscuousMode = root.attributeValue("promiscuousMode"); this.probeJpcapThread = new PJpcapThread(this); PIPReassembler.start(); // ETHERNET protocol only // To avoid using two jpcap capture at the same time // enable isEthernetProbeCreated in EthernetStack if (stack instanceof StackEthernet) ((StackEthernet) stack).setEthernetProbeCreated(true); }
From source file:com.devoteam.srit.xmlloader.core.report.CounterReportTemplate.java
License:Open Source License
public CounterReportTemplate(String type, StatKey arg1, StatKey arg2, Element root) { super();/* w w w . java 2s. c o m*/ this.type = type; this.arg1 = arg1; this.arg2 = arg2; this.summary = root.attributeValue("shortDesc"); if (this.summary == null) { this.summary = root.attributeValue("summary"); } else { GlobalLogger.instance().logDeprecatedMessage("stats> <... shortDesc=\"XXXX\" ...> ...</stats", "stats> <... summary=\"XXXX\" ...> ...</stats"); } this.name = root.attributeValue("description"); if (name == null) { this.name = root.attributeValue("name"); } else { GlobalLogger.instance().logDeprecatedMessage("stats> <... description=\"XXXX\" ...> ...</stats", "stats> <... name=\"XXXX\" ...> ...</stats"); } this.complete = root.attributeValue("longDesc"); if (complete == null) { this.complete = root.attributeValue("complete"); } else { GlobalLogger.instance().logDeprecatedMessage("stats> <... longDesc=\"XXXX\" ...> ...</stats", "stats> <... complete=\"XXXX\" ...> ...</stats"); } }
From source file:com.devoteam.srit.xmlloader.core.RunProfile.java
License:Open Source License
public synchronized void parse(Element root) throws Exception { long now = System.currentTimeMillis(); this.executions = 0; this.points = new ArrayList(); this.profilePeriod = PROFILE_INF; Element start = root.element("start"); if (null != start) { if (null != start.attributeValue("time")) { String date = start.attributeValue("time"); this.startTime = DateUtils.parseDate(date); } else if (null != start.attributeValue("delay")) { this.startTime = -(long) (Double.parseDouble(start.attributeValue("delay")) * 1000); } else {/*from w w w. j a v a 2 s. co m*/ } if (null != start.attributeValue("time") && null != start.attributeValue("delay")) { throw new ParsingException("only specify time or delay attributes in <start>, not both"); } } else { this.startTime = 0; } for (Object object : root.elements("step")) { Element element = (Element) object; long time = (long) Double.parseDouble(element.attributeValue("time")) * 1000; if (time == this.profilePeriod) time += 1; else if (time < this.profilePeriod) throw new ParsingException("time isn't greater than previous time"); double frequence; String periodStr = element.attributeValue("period"); String frequencyStr = element.attributeValue("frequency"); if (periodStr == null && frequencyStr == null) throw new ParsingException("missing period or frequence attribute"); if (periodStr != null && frequencyStr != null) throw new ParsingException("please define only period or frequence attribute"); if (null != periodStr && Double.parseDouble(periodStr) > 0) { frequence = (1 / Double.parseDouble(periodStr)); } else { frequence = PROFILE_INF; } if (null != frequencyStr) frequence = Double.parseDouble(frequencyStr); if (frequence == 0) frequence = 0.000000001; this.points.add(new Point(time, frequence)); this.profilePeriod = time; } // add steps if there is only one or no step at time 0 if (this.points.size() == 0) { double period = Config.getConfigByName("tester.properties").getDouble("runprofile.PERIOD"); if (0 == period) period = PROFILE_INF; this.points.add(new Point(0, period)); // add point @ 0 } // add steps if there is only one or no step at time 0 if (this.points.get(0).date != 0) { this.points.add(0, new Point(0, 0.000000001)); // add point @ 0 } // if there is only one step at zero if (this.points.size() == 1) { // add point to make a constant, ten second later this.points.add(this.points.get(0).clone()); if (this.points.get(0).frequency == -1) { this.points.get(1).date = 10000; } else { double delay = 1 / this.points.get(0).frequency; while (delay < 1) delay *= 10; delay = Math.round(delay); this.points.get(1).date = delay * 10000; } this.profilePeriod = (long) Math.round(this.points.get(1).date); } Element end = root.element("end"); if (null != end) { boolean hasTime = true; boolean hasExecutions = true; if (null != end.attributeValue("time")) { String date = end.attributeValue("time"); this.endTime = DateUtils.parseDate(date); } else if (null != end.attributeValue("delay")) { long delay = (long) (Double.parseDouble(end.attributeValue("delay")) * 1000); if (delay == 0) this.endTime = 0; else this.endTime = -delay; } else { hasTime = false; } if (null != end.attributeValue("iteration")) { this.executions = Long.parseLong(end.attributeValue("iteration")); } else { hasExecutions = false; } if (null != end.attributeValue("time") && null != end.attributeValue("delay")) { throw new ParsingException("only specify time or delay attributes in <end>, not both"); } if (!hasTime && !hasExecutions) { // some error, must define end by time or iterations } } else { long delay = (long) Config.getConfigByName("tester.properties").getDouble("runprofile.DURATION", 0) * 1000; if (delay == 0) this.endTime = 0; else this.endTime = -delay; this.executions = Config.getConfigByName("tester.properties").getInteger("runprofile.NUMBER", 0); } long tempStartTime = 0; if (startTime < 0) tempStartTime = now - startTime; if (startTime > 0) tempStartTime = startTime; long tempEndTime = 0; if (endTime < 0) tempEndTime = now - endTime; if (endTime > 0) tempEndTime = endTime; if (0 != tempEndTime && tempEndTime <= tempStartTime) throw new ParsingException( "start time cannot be greater than end time (check start and end dates or delays?)"); // if the profile is a zero-only, set executions to zero and endTime to startTime nothingToDo = true; for (int i = 0; i < points.size(); i++) { if (points.get(i).frequency != 0.000000001) { nothingToDo = false; break; } } this.profileSize = this.points.size(); }
From source file:com.devoteam.srit.xmlloader.core.Scenario.java
License:Open Source License
/** * Parse a ReceiveXXXXXAAA operation/*from www. ja va 2 s .c o m*/ */ @Deprecated private Operation parseReceiveAAA(String protocol, boolean request, Element node) throws Exception { String type = node.attributeValue("command"); // go read the value of the command in dictionnary if ((type != null) && (!Utils.isInteger(type))) { // use ApplicationID "base" but will search in all Applications anyway CommandDef commandDef = Dictionary.getInstance().getCommandDefByName(type, "0"); if (null != commandDef) { type = Integer.toString(commandDef.get_code()); } } String result = node.attributeValue("result"); return new OperationReceiveMsg(StackFactory.PROTOCOL_DIAMETER, request, null, null, type, result, node, this); }