Loading javasrc/org/etsi/its/adapter/TraceParser.java +43 −30 Original line number Diff line number Diff line Loading @@ -14,8 +14,6 @@ import de.tu_berlin.cs.uebb.ttcn.runtime.OctetString; public class TraceParser { private List<List<TransactionStructure>> traceList = new ArrayList<List<TransactionStructure>>(); // private String startCommandStr = "trace"; // private String falseCommandStr = "trace c"; private String matchTrace = ".*:\\s.*trace$"; private String stopCommandStr = "Those were the most recent"; Loading @@ -29,11 +27,6 @@ public class TraceParser { this.filePath = filePath; } // public static void main(String[] args) { // startTraceParsing("C:\\Demo_Dump2.txt"); // // } public void parseTrace(){ try { ArrayList<TransactionStructure> transactions = null; Loading @@ -43,18 +36,15 @@ public class TraceParser { String line=null; boolean transactionStarted=false; while(null!=(line=br.readLine())) { // if (line.startsWith("here the dump starts ---------->")) { // if (line.startsWith(startCommandStr) && !line.startsWith(falseCommandStr)){ if (line.matches(matchTrace)){ transactionStarted = true; transactions = new ArrayList<TransactionStructure>(); traceList.add(transactions); System.out.println("++++++++++++++++ Trace started ++++++++++++++++"); //System.out.println("++++++++++++++++ Trace started ++++++++++++++++"); } // else if (line.startsWith("<-----------")) { else if (line.startsWith(stopCommandStr)) { transactionStarted = false; System.out.println("++++++++++++++++ Trace finished ++++++++++++++++"); //System.out.println("++++++++++++++++ Trace finished ++++++++++++++++"); } if (transactionStarted){ if (line.startsWith("0x")) { Loading @@ -64,8 +54,22 @@ public class TraceParser { String timestamp=line.substring(0, line.indexOf(" ")); line=line.substring(line.indexOf(" ")); System.out.println("Timestamp: " + timestamp); //System.out.println("Timestamp: " + timestamp); transaction.setTimeStamp(new BigInteger(timestamp, 16)); line = line.substring(line.lastIndexOf("]")+1).trim(); if (line.startsWith("UL")) { //UL transaction.setDirection(TransactionStructure.OBU); line = line.substring(2); //System.out.println("Direction: " + "UL"); } else if(line.startsWith("DL")) { //DL transaction.setDirection(TransactionStructure.RSU); line = line.substring(2); //System.out.println("Direction: " + "DL"); } else { //TODO error! } line = line.substring(line.lastIndexOf("]")+1).trim(); StringTokenizer st = new StringTokenizer(line, " "); int tokens = st.countTokens(); Loading @@ -75,28 +79,16 @@ public class TraceParser { String token = st.nextToken(); switch (i) { case 0: if (token.equals("UL")) { //UL transaction.setDirection(TransactionStructure.OBU); } else if(token.equals("DL")) { //DL transaction.setDirection(TransactionStructure.RSU); } else { //TODO error! } System.out.println("Direction: " + token); break; case 1: System.out.println("no of bytes: " + token); //System.out.println("no of bytes: " + token); bytes = Integer.parseInt(token); transaction.setNoOfBytes(bytes); break; case 2: case 1: //ignore break; case 3: case 2: if (bytesCounter<bytes) { System.out.print ("payload : " + token); //System.out.print ("payload : " + token); transaction.setPayload(new OctetString(RB, token).toByteArray()); bytesCounter++; Loading @@ -104,7 +96,7 @@ public class TraceParser { break; default: if (bytesCounter<bytes) { System.out.print(token); //System.out.print(token); byte [] oldPayload = transaction.getPayload(); transaction.setPayload(new OctetString(RB, oldPayload.length, oldPayload).concat(new OctetString(RB, token)).toByteArray()); bytesCounter++; Loading @@ -119,6 +111,8 @@ public class TraceParser { } } } br.close(); fr.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { Loading @@ -126,6 +120,25 @@ public class TraceParser { } } public boolean checkTraceFile(){ try { FileReader fr = new FileReader(filePath); BufferedReader br = new BufferedReader(fr); String line=null; while(null!=(line=br.readLine())) { if (line.matches(matchTrace)){ return true; } } br.close(); fr.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; } public int getTraceCount(){ return traceList.size(); Loading javasrc/org/etsi/its/adapter/TracePortPlugin.java +668 −373 Original line number Diff line number Diff line package org.etsi.its.adapter; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Vector; import org.etsi.ttcn.tci.BooleanValue; import org.etsi.ttcn.tci.CharstringValue; import org.etsi.ttcn.tci.IntegerValue; import org.etsi.ttcn.tci.RecordOfValue; import org.etsi.ttcn.tri.TriActionTemplate; import org.etsi.ttcn.tri.TriAddress; import org.etsi.ttcn.tri.TriAddressList; Loading Loading @@ -42,8 +45,6 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { private static final String SIGNATURE_ENCODING = "Signatures"; private static final long serialVersionUID = 7436181385675637901L; private String tracePath = ""; private boolean isFolder = false; private List<String> traceNameList = new ArrayList<String>(); private RB RB; private PluginIdentifier pluginId; private TraceParser traceParse; Loading @@ -51,6 +52,11 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { private TriPortId obuTsiPortId; private TriComponentId rsuComponent; private TriPortId rsuTsiPortId; private Thread startAnalyzeTraceThread; private String powerLevel; private String obuName; private String dutyCycle; private String repNo; public TracePortPlugin(PluginIdentifier pluginId){ this.pluginId = pluginId; Loading Loading @@ -85,8 +91,35 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { boolean result = setTraceFile(tracePath); BooleanReturn(componentId, portId, address, signatureId, parameterList, result); }else if("isFolder".equals(signatureName)){ BooleanReturn(componentId, portId, address, signatureId, parameterList, isFolder); }else if("getTraceFileList".equals(signatureName)){ TriParameter tracePathParam = parameterList.get(0); String tracePathStr = getCharstringParameterData(tracePathParam); File tracePath = new File(tracePathStr); if (tracePath.isDirectory()) { String[] fileList = tracePath.list(); Vector<String> traceFiles = new Vector<String>(); for (int i = 0; i < fileList.length; i++) { fileList[i] = tracePath.getAbsolutePath() + File.separator + fileList[i]; TraceParser parser = new TraceParser(RB, fileList[i]); if (parser.checkTraceFile()) { traceFiles.add(fileList[i]); } } TraceFileListReturn(componentId, portId, address, signatureId, parameterList, traceFiles.toArray(new String[]{})); } else if (tracePath.isFile()) { TraceParser parser = new TraceParser(RB, tracePathStr); if (parser.checkTraceFile()) { TraceFileListReturn(componentId, portId, address, signatureId, parameterList, new String []{tracePathStr}); } else { TraceFileListReturn(componentId, portId, address, signatureId, parameterList, new String []{}); } } else { return new TriStatusImpl("Unknown file object!"); } }else if("getTransactionCnt".equals(signatureName)){ int traceCnt = getTraceCnt(); IntegerReturn(componentId, portId, address, signatureId, Loading @@ -94,23 +127,288 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { }else if("startAnalyzeTrace".equals(signatureName)){ TriParameter transactionCntParam = parameterList.get(0); final int transactionCnt = getIntegerParameterData(transactionCntParam); new Thread(tracePath) { startAnalyzeTraceThread = new Thread(tracePath) { public void run() { startAnalyzeTrace(transactionCnt); } }.start(); }; startAnalyzeTraceThread.start(); BooleanReturn(componentId, portId, address, signatureId, parameterList, true); }else if("finishAnalyzeTrace".equals(signatureName)){ //TOD0 }else if("writeCSVITSParams".equals(signatureName)){ TriParameter csvFilePathParam = parameterList.get(0); String csvFilePath = getCharstringParameterData(csvFilePathParam); TriParameter powerLevelParam = parameterList.get(1); String powerLevel = getCharstringParameterData(powerLevelParam); TriParameter obuNameParam = parameterList.get(2); String obuName = getCharstringParameterData(obuNameParam); TriParameter dutyCycleParam = parameterList.get(3); String dutyCycle = getCharstringParameterData(dutyCycleParam); TriParameter repNoParam = parameterList.get(4); String repNo = getCharstringParameterData(repNoParam); boolean res = writeCSVITSParams(csvFilePath, powerLevel, obuName, dutyCycle, repNo); BooleanReturn(componentId, portId, address, signatureId, parameterList, res); }else if("writeCSVTransaction".equals(signatureName)){ TriParameter csvFilePathParam = parameterList.get(0); String csvFilePath = getCharstringParameterData(csvFilePathParam); TriParameter transDurationParam = parameterList.get(1); int transDuration = getIntegerParameterData(transDurationParam); TriParameter nrOfEmptyMsgParam = parameterList.get(2); int nrOfEmptyMsg = getIntegerParameterData(nrOfEmptyMsgParam); boolean res = writeCSVTransactionAll(csvFilePath, transDuration, nrOfEmptyMsg); BooleanReturn(componentId, portId, address, signatureId, parameterList, res); }else if("writeCSVMinMaxErrorRate".equals(signatureName)){ TriParameter csvFilePathParam = parameterList.get(0); String csvFilePath = getCharstringParameterData(csvFilePathParam); TriParameter minTranDurationParam = parameterList.get(1); int minTranDuration = getIntegerParameterData(minTranDurationParam); TriParameter minTranIndexParam = parameterList.get(2); int minTranIndex = getIntegerParameterData(minTranIndexParam); TriParameter maxTranDurationParam = parameterList.get(3); int maxTranDuration = getIntegerParameterData(maxTranDurationParam); TriParameter maxTranIndexParam = parameterList.get(4); int maxTranIndex = getIntegerParameterData(maxTranIndexParam); TriParameter averageTranDurationParam = parameterList.get(5); int averageTranDuration = getIntegerParameterData(averageTranDurationParam); TriParameter nrOfTransactionsParam = parameterList.get(6); int nrOfTransactions = getIntegerParameterData(nrOfTransactionsParam); TriParameter errorRateParam = parameterList.get(7); int errorRate = getIntegerParameterData(errorRateParam); boolean res = writeCSVMinMax(csvFilePath, minTranDuration, minTranIndex, maxTranDuration , maxTranIndex, averageTranDuration, nrOfTransactions, errorRate); BooleanReturn(componentId, portId, address, signatureId, parameterList, res); } return new TriStatusImpl(); } private boolean writeCSVMinMax(String csvFilePath, int minTranDuration, int minTranIndex, int maxTranDuration, int maxTranIndex, int averageTranDuration, int nrOfTransactions, int errorRate){ boolean result = false; String baseFileName = csvFilePath.substring(0, csvFilePath.lastIndexOf(".")); result = writeCSVMinMaxErrorrate(baseFileName, minTranDuration, minTranIndex, maxTranDuration, maxTranIndex, averageTranDuration, nrOfTransactions, errorRate); return result; } private boolean writeCSVMinMaxErrorrate(String baseFileName, int minTranDuration, int minTranIndex, int maxTranDuration, int maxTranIndex, int averageTranDuration, int nrOfTransactions, int errorRate){ String fileName = baseFileName + "Summary.csv"; BufferedWriter bufferedWriter = null; try { File file = new File(fileName); //Start writing to the output stream if (!file.exists()) { //Construct the BufferedWriter object bufferedWriter = new BufferedWriter(new FileWriter(file, true)); bufferedWriter.write("Power Lever"); bufferedWriter.write(";"); bufferedWriter.write("Obu Name"); bufferedWriter.write(";"); bufferedWriter.write("Duty Cycle"); bufferedWriter.write(";"); bufferedWriter.write("RepNo"); bufferedWriter.write(";"); bufferedWriter.write("Nr of Transactions"); bufferedWriter.write(";"); bufferedWriter.write("Error Rate"); bufferedWriter.write(";"); bufferedWriter.write("MinTranIndex"); bufferedWriter.write(";"); bufferedWriter.write("MinTranDuration"); bufferedWriter.write(";"); bufferedWriter.write("MaxTranIndex"); bufferedWriter.write(";"); bufferedWriter.write("MaxTranDuration"); bufferedWriter.write(";"); bufferedWriter.write("Average Transaction Time"); bufferedWriter.newLine(); } if(bufferedWriter == null){ bufferedWriter = new BufferedWriter(new FileWriter(file, true)); } bufferedWriter.write(powerLevel); bufferedWriter.write(";"); bufferedWriter.write(obuName); bufferedWriter.write(";"); bufferedWriter.write(dutyCycle); bufferedWriter.write(";"); bufferedWriter.write(repNo); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(nrOfTransactions)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(errorRate)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(minTranIndex)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(minTranDuration)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(maxTranIndex)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(maxTranDuration)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(averageTranDuration)); bufferedWriter.write(";"); bufferedWriter.newLine(); return true; } catch (FileNotFoundException ex) { ex.printStackTrace(); return false; } catch (IOException ex) { ex.printStackTrace(); return false; } finally { //Close the BufferedWriter try { if (bufferedWriter != null) { bufferedWriter.flush(); bufferedWriter.close(); } } catch (IOException ex) { ex.printStackTrace(); return false; } } } private boolean writeCSVITSParams(String csvFilePath, String powerLevel, String obuName, String dutyCycle, String repNo){ boolean result = false; String baseFileName = csvFilePath.substring(0, csvFilePath.lastIndexOf(".")); result = writeCSVITSParamsAll(baseFileName, powerLevel, obuName, dutyCycle, repNo); return result; } private boolean writeCSVITSParamsAll(String baseFileName, String powerLevel, String obuName, String dutyCycle, String repNo){ String fileName = baseFileName + "Transactions.csv"; BufferedWriter bufferedWriter = null; try { File file = new File(fileName); //Start writing to the output stream if (!file.exists()) { //Construct the BufferedWriter object bufferedWriter = new BufferedWriter(new FileWriter(file, true)); bufferedWriter.write("Power Lever"); bufferedWriter.write(";"); bufferedWriter.write("Obu Name"); bufferedWriter.write(";"); bufferedWriter.write("Duty Cycle"); bufferedWriter.write(";"); bufferedWriter.write("RepNo"); bufferedWriter.write(";"); bufferedWriter.write("Transaction Duration"); bufferedWriter.write(";"); bufferedWriter.write("Number of empty UL frames"); bufferedWriter.newLine(); } if(bufferedWriter == null){ bufferedWriter = new BufferedWriter(new FileWriter(file, true)); } this.powerLevel = powerLevel; this.obuName = obuName; this.dutyCycle = dutyCycle; this.repNo = repNo; return true; } catch (FileNotFoundException ex) { ex.printStackTrace(); return false; } catch (IOException ex) { ex.printStackTrace(); return false; } finally { //Close the BufferedWriter try { if (bufferedWriter != null) { bufferedWriter.flush(); bufferedWriter.close(); } } catch (IOException ex) { ex.printStackTrace(); return false; } } } private boolean writeCSVTransactionAll(String csvFilePath, int transDuration, int nrOfEmptyMsg){ String baseFileName = csvFilePath.substring(0, csvFilePath.lastIndexOf(".")); String fileName = baseFileName + "Transactions.csv"; BufferedWriter bufferedWriter = null; try { //Construct the BufferedWriter object bufferedWriter = new BufferedWriter(new FileWriter(fileName, true)); //Start writing to the output stream bufferedWriter.write(powerLevel); bufferedWriter.write(";"); bufferedWriter.write(obuName); bufferedWriter.write(";"); bufferedWriter.write(dutyCycle); bufferedWriter.write(";"); bufferedWriter.write(repNo); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(transDuration)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(nrOfEmptyMsg)); bufferedWriter.newLine(); return true; } catch (FileNotFoundException ex) { ex.printStackTrace(); return false; } catch (IOException ex) { ex.printStackTrace(); return false; } finally { //Close the BufferedWriter try { if (bufferedWriter != null) { bufferedWriter.flush(); bufferedWriter.close(); } } catch (IOException ex) { ex.printStackTrace(); return false; } } } private void IntegerReturn(TriComponentId componentId, TriPortId portId, TriAddress address, TriSignatureId signatureId, Loading @@ -121,7 +419,6 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { RB.getTriCommunicationTE().triEnqueueReply(portId, address, componentId, signatureId, parameterList, new TriMessageParameter(RB, TriParameterPassingMode.TRI_IN, "", returnValue)); } private void BooleanReturn(TriComponentId componentId, TriPortId portId, TriAddress address, TriSignatureId signatureId, TriParameterList parameterList, boolean result) { Loading @@ -131,6 +428,20 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { RB.getTriCommunicationTE().triEnqueueReply(portId, address, componentId, signatureId, parameterList, new TriMessageParameter(RB, TriParameterPassingMode.TRI_IN, "", returnValue)); } private void TraceFileListReturn(TriComponentId componentId, TriPortId portId, TriAddress address, TriSignatureId signatureId, TriParameterList parameterList, String [] result) { RecordOfValue rov = (RecordOfValue) RB.getTciCDRequired().getTypeForName("TraceParserSystem.TraceFileList").newInstance(); rov.setLength(0); for (String traceFileStr : result) { CharstringValue cv = (CharstringValue) RB.getTciCDRequired().getCharstring().newInstance(); cv.setString(traceFileStr); rov.appendField(cv); } TriMessage returnValue = RB.TestAdapter.getCodec(SIGNATURE_ENCODING).encode(rov); RB.getTriCommunicationTE().triEnqueueReply(portId, address, componentId, signatureId, parameterList, new TriMessageParameter(RB, TriParameterPassingMode.TRI_IN, "", returnValue)); } private boolean setTraceFile(String tracePathPr){ File traceFile = new File(tracePathPr); Loading @@ -144,35 +455,12 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { traceFile.delete(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; } // private boolean setTraceFile(String tracePathPr){ // File traceFile = new File(tracePathPr); // // if (traceFile.exists() && traceFile.canRead()) { // this.tracePath = tracePathPr; // isFolder(traceFile); // return true; // } // // return false; // } private void isFolder(File traceFile){ isFolder = traceFile.isDirectory(); } private void getFolderContent(File folder){ traceNameList = Arrays.asList(folder.list()); } private int getTraceCnt(){ traceParse = new TraceParser(RB, tracePath); traceParse.parseTrace(); Loading Loading @@ -263,6 +551,13 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { public TriStatus triEndTestCase() { if (startAnalyzeTraceThread!=null && startAnalyzeTraceThread.isAlive()) { try { startAnalyzeTraceThread.join(1000); } catch (InterruptedException e) { //ignore } } return new TriStatusImpl(); } Loading Loading
javasrc/org/etsi/its/adapter/TraceParser.java +43 −30 Original line number Diff line number Diff line Loading @@ -14,8 +14,6 @@ import de.tu_berlin.cs.uebb.ttcn.runtime.OctetString; public class TraceParser { private List<List<TransactionStructure>> traceList = new ArrayList<List<TransactionStructure>>(); // private String startCommandStr = "trace"; // private String falseCommandStr = "trace c"; private String matchTrace = ".*:\\s.*trace$"; private String stopCommandStr = "Those were the most recent"; Loading @@ -29,11 +27,6 @@ public class TraceParser { this.filePath = filePath; } // public static void main(String[] args) { // startTraceParsing("C:\\Demo_Dump2.txt"); // // } public void parseTrace(){ try { ArrayList<TransactionStructure> transactions = null; Loading @@ -43,18 +36,15 @@ public class TraceParser { String line=null; boolean transactionStarted=false; while(null!=(line=br.readLine())) { // if (line.startsWith("here the dump starts ---------->")) { // if (line.startsWith(startCommandStr) && !line.startsWith(falseCommandStr)){ if (line.matches(matchTrace)){ transactionStarted = true; transactions = new ArrayList<TransactionStructure>(); traceList.add(transactions); System.out.println("++++++++++++++++ Trace started ++++++++++++++++"); //System.out.println("++++++++++++++++ Trace started ++++++++++++++++"); } // else if (line.startsWith("<-----------")) { else if (line.startsWith(stopCommandStr)) { transactionStarted = false; System.out.println("++++++++++++++++ Trace finished ++++++++++++++++"); //System.out.println("++++++++++++++++ Trace finished ++++++++++++++++"); } if (transactionStarted){ if (line.startsWith("0x")) { Loading @@ -64,8 +54,22 @@ public class TraceParser { String timestamp=line.substring(0, line.indexOf(" ")); line=line.substring(line.indexOf(" ")); System.out.println("Timestamp: " + timestamp); //System.out.println("Timestamp: " + timestamp); transaction.setTimeStamp(new BigInteger(timestamp, 16)); line = line.substring(line.lastIndexOf("]")+1).trim(); if (line.startsWith("UL")) { //UL transaction.setDirection(TransactionStructure.OBU); line = line.substring(2); //System.out.println("Direction: " + "UL"); } else if(line.startsWith("DL")) { //DL transaction.setDirection(TransactionStructure.RSU); line = line.substring(2); //System.out.println("Direction: " + "DL"); } else { //TODO error! } line = line.substring(line.lastIndexOf("]")+1).trim(); StringTokenizer st = new StringTokenizer(line, " "); int tokens = st.countTokens(); Loading @@ -75,28 +79,16 @@ public class TraceParser { String token = st.nextToken(); switch (i) { case 0: if (token.equals("UL")) { //UL transaction.setDirection(TransactionStructure.OBU); } else if(token.equals("DL")) { //DL transaction.setDirection(TransactionStructure.RSU); } else { //TODO error! } System.out.println("Direction: " + token); break; case 1: System.out.println("no of bytes: " + token); //System.out.println("no of bytes: " + token); bytes = Integer.parseInt(token); transaction.setNoOfBytes(bytes); break; case 2: case 1: //ignore break; case 3: case 2: if (bytesCounter<bytes) { System.out.print ("payload : " + token); //System.out.print ("payload : " + token); transaction.setPayload(new OctetString(RB, token).toByteArray()); bytesCounter++; Loading @@ -104,7 +96,7 @@ public class TraceParser { break; default: if (bytesCounter<bytes) { System.out.print(token); //System.out.print(token); byte [] oldPayload = transaction.getPayload(); transaction.setPayload(new OctetString(RB, oldPayload.length, oldPayload).concat(new OctetString(RB, token)).toByteArray()); bytesCounter++; Loading @@ -119,6 +111,8 @@ public class TraceParser { } } } br.close(); fr.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { Loading @@ -126,6 +120,25 @@ public class TraceParser { } } public boolean checkTraceFile(){ try { FileReader fr = new FileReader(filePath); BufferedReader br = new BufferedReader(fr); String line=null; while(null!=(line=br.readLine())) { if (line.matches(matchTrace)){ return true; } } br.close(); fr.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; } public int getTraceCount(){ return traceList.size(); Loading
javasrc/org/etsi/its/adapter/TracePortPlugin.java +668 −373 Original line number Diff line number Diff line package org.etsi.its.adapter; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Vector; import org.etsi.ttcn.tci.BooleanValue; import org.etsi.ttcn.tci.CharstringValue; import org.etsi.ttcn.tci.IntegerValue; import org.etsi.ttcn.tci.RecordOfValue; import org.etsi.ttcn.tri.TriActionTemplate; import org.etsi.ttcn.tri.TriAddress; import org.etsi.ttcn.tri.TriAddressList; Loading Loading @@ -42,8 +45,6 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { private static final String SIGNATURE_ENCODING = "Signatures"; private static final long serialVersionUID = 7436181385675637901L; private String tracePath = ""; private boolean isFolder = false; private List<String> traceNameList = new ArrayList<String>(); private RB RB; private PluginIdentifier pluginId; private TraceParser traceParse; Loading @@ -51,6 +52,11 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { private TriPortId obuTsiPortId; private TriComponentId rsuComponent; private TriPortId rsuTsiPortId; private Thread startAnalyzeTraceThread; private String powerLevel; private String obuName; private String dutyCycle; private String repNo; public TracePortPlugin(PluginIdentifier pluginId){ this.pluginId = pluginId; Loading Loading @@ -85,8 +91,35 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { boolean result = setTraceFile(tracePath); BooleanReturn(componentId, portId, address, signatureId, parameterList, result); }else if("isFolder".equals(signatureName)){ BooleanReturn(componentId, portId, address, signatureId, parameterList, isFolder); }else if("getTraceFileList".equals(signatureName)){ TriParameter tracePathParam = parameterList.get(0); String tracePathStr = getCharstringParameterData(tracePathParam); File tracePath = new File(tracePathStr); if (tracePath.isDirectory()) { String[] fileList = tracePath.list(); Vector<String> traceFiles = new Vector<String>(); for (int i = 0; i < fileList.length; i++) { fileList[i] = tracePath.getAbsolutePath() + File.separator + fileList[i]; TraceParser parser = new TraceParser(RB, fileList[i]); if (parser.checkTraceFile()) { traceFiles.add(fileList[i]); } } TraceFileListReturn(componentId, portId, address, signatureId, parameterList, traceFiles.toArray(new String[]{})); } else if (tracePath.isFile()) { TraceParser parser = new TraceParser(RB, tracePathStr); if (parser.checkTraceFile()) { TraceFileListReturn(componentId, portId, address, signatureId, parameterList, new String []{tracePathStr}); } else { TraceFileListReturn(componentId, portId, address, signatureId, parameterList, new String []{}); } } else { return new TriStatusImpl("Unknown file object!"); } }else if("getTransactionCnt".equals(signatureName)){ int traceCnt = getTraceCnt(); IntegerReturn(componentId, portId, address, signatureId, Loading @@ -94,23 +127,288 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { }else if("startAnalyzeTrace".equals(signatureName)){ TriParameter transactionCntParam = parameterList.get(0); final int transactionCnt = getIntegerParameterData(transactionCntParam); new Thread(tracePath) { startAnalyzeTraceThread = new Thread(tracePath) { public void run() { startAnalyzeTrace(transactionCnt); } }.start(); }; startAnalyzeTraceThread.start(); BooleanReturn(componentId, portId, address, signatureId, parameterList, true); }else if("finishAnalyzeTrace".equals(signatureName)){ //TOD0 }else if("writeCSVITSParams".equals(signatureName)){ TriParameter csvFilePathParam = parameterList.get(0); String csvFilePath = getCharstringParameterData(csvFilePathParam); TriParameter powerLevelParam = parameterList.get(1); String powerLevel = getCharstringParameterData(powerLevelParam); TriParameter obuNameParam = parameterList.get(2); String obuName = getCharstringParameterData(obuNameParam); TriParameter dutyCycleParam = parameterList.get(3); String dutyCycle = getCharstringParameterData(dutyCycleParam); TriParameter repNoParam = parameterList.get(4); String repNo = getCharstringParameterData(repNoParam); boolean res = writeCSVITSParams(csvFilePath, powerLevel, obuName, dutyCycle, repNo); BooleanReturn(componentId, portId, address, signatureId, parameterList, res); }else if("writeCSVTransaction".equals(signatureName)){ TriParameter csvFilePathParam = parameterList.get(0); String csvFilePath = getCharstringParameterData(csvFilePathParam); TriParameter transDurationParam = parameterList.get(1); int transDuration = getIntegerParameterData(transDurationParam); TriParameter nrOfEmptyMsgParam = parameterList.get(2); int nrOfEmptyMsg = getIntegerParameterData(nrOfEmptyMsgParam); boolean res = writeCSVTransactionAll(csvFilePath, transDuration, nrOfEmptyMsg); BooleanReturn(componentId, portId, address, signatureId, parameterList, res); }else if("writeCSVMinMaxErrorRate".equals(signatureName)){ TriParameter csvFilePathParam = parameterList.get(0); String csvFilePath = getCharstringParameterData(csvFilePathParam); TriParameter minTranDurationParam = parameterList.get(1); int minTranDuration = getIntegerParameterData(minTranDurationParam); TriParameter minTranIndexParam = parameterList.get(2); int minTranIndex = getIntegerParameterData(minTranIndexParam); TriParameter maxTranDurationParam = parameterList.get(3); int maxTranDuration = getIntegerParameterData(maxTranDurationParam); TriParameter maxTranIndexParam = parameterList.get(4); int maxTranIndex = getIntegerParameterData(maxTranIndexParam); TriParameter averageTranDurationParam = parameterList.get(5); int averageTranDuration = getIntegerParameterData(averageTranDurationParam); TriParameter nrOfTransactionsParam = parameterList.get(6); int nrOfTransactions = getIntegerParameterData(nrOfTransactionsParam); TriParameter errorRateParam = parameterList.get(7); int errorRate = getIntegerParameterData(errorRateParam); boolean res = writeCSVMinMax(csvFilePath, minTranDuration, minTranIndex, maxTranDuration , maxTranIndex, averageTranDuration, nrOfTransactions, errorRate); BooleanReturn(componentId, portId, address, signatureId, parameterList, res); } return new TriStatusImpl(); } private boolean writeCSVMinMax(String csvFilePath, int minTranDuration, int minTranIndex, int maxTranDuration, int maxTranIndex, int averageTranDuration, int nrOfTransactions, int errorRate){ boolean result = false; String baseFileName = csvFilePath.substring(0, csvFilePath.lastIndexOf(".")); result = writeCSVMinMaxErrorrate(baseFileName, minTranDuration, minTranIndex, maxTranDuration, maxTranIndex, averageTranDuration, nrOfTransactions, errorRate); return result; } private boolean writeCSVMinMaxErrorrate(String baseFileName, int minTranDuration, int minTranIndex, int maxTranDuration, int maxTranIndex, int averageTranDuration, int nrOfTransactions, int errorRate){ String fileName = baseFileName + "Summary.csv"; BufferedWriter bufferedWriter = null; try { File file = new File(fileName); //Start writing to the output stream if (!file.exists()) { //Construct the BufferedWriter object bufferedWriter = new BufferedWriter(new FileWriter(file, true)); bufferedWriter.write("Power Lever"); bufferedWriter.write(";"); bufferedWriter.write("Obu Name"); bufferedWriter.write(";"); bufferedWriter.write("Duty Cycle"); bufferedWriter.write(";"); bufferedWriter.write("RepNo"); bufferedWriter.write(";"); bufferedWriter.write("Nr of Transactions"); bufferedWriter.write(";"); bufferedWriter.write("Error Rate"); bufferedWriter.write(";"); bufferedWriter.write("MinTranIndex"); bufferedWriter.write(";"); bufferedWriter.write("MinTranDuration"); bufferedWriter.write(";"); bufferedWriter.write("MaxTranIndex"); bufferedWriter.write(";"); bufferedWriter.write("MaxTranDuration"); bufferedWriter.write(";"); bufferedWriter.write("Average Transaction Time"); bufferedWriter.newLine(); } if(bufferedWriter == null){ bufferedWriter = new BufferedWriter(new FileWriter(file, true)); } bufferedWriter.write(powerLevel); bufferedWriter.write(";"); bufferedWriter.write(obuName); bufferedWriter.write(";"); bufferedWriter.write(dutyCycle); bufferedWriter.write(";"); bufferedWriter.write(repNo); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(nrOfTransactions)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(errorRate)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(minTranIndex)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(minTranDuration)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(maxTranIndex)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(maxTranDuration)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(averageTranDuration)); bufferedWriter.write(";"); bufferedWriter.newLine(); return true; } catch (FileNotFoundException ex) { ex.printStackTrace(); return false; } catch (IOException ex) { ex.printStackTrace(); return false; } finally { //Close the BufferedWriter try { if (bufferedWriter != null) { bufferedWriter.flush(); bufferedWriter.close(); } } catch (IOException ex) { ex.printStackTrace(); return false; } } } private boolean writeCSVITSParams(String csvFilePath, String powerLevel, String obuName, String dutyCycle, String repNo){ boolean result = false; String baseFileName = csvFilePath.substring(0, csvFilePath.lastIndexOf(".")); result = writeCSVITSParamsAll(baseFileName, powerLevel, obuName, dutyCycle, repNo); return result; } private boolean writeCSVITSParamsAll(String baseFileName, String powerLevel, String obuName, String dutyCycle, String repNo){ String fileName = baseFileName + "Transactions.csv"; BufferedWriter bufferedWriter = null; try { File file = new File(fileName); //Start writing to the output stream if (!file.exists()) { //Construct the BufferedWriter object bufferedWriter = new BufferedWriter(new FileWriter(file, true)); bufferedWriter.write("Power Lever"); bufferedWriter.write(";"); bufferedWriter.write("Obu Name"); bufferedWriter.write(";"); bufferedWriter.write("Duty Cycle"); bufferedWriter.write(";"); bufferedWriter.write("RepNo"); bufferedWriter.write(";"); bufferedWriter.write("Transaction Duration"); bufferedWriter.write(";"); bufferedWriter.write("Number of empty UL frames"); bufferedWriter.newLine(); } if(bufferedWriter == null){ bufferedWriter = new BufferedWriter(new FileWriter(file, true)); } this.powerLevel = powerLevel; this.obuName = obuName; this.dutyCycle = dutyCycle; this.repNo = repNo; return true; } catch (FileNotFoundException ex) { ex.printStackTrace(); return false; } catch (IOException ex) { ex.printStackTrace(); return false; } finally { //Close the BufferedWriter try { if (bufferedWriter != null) { bufferedWriter.flush(); bufferedWriter.close(); } } catch (IOException ex) { ex.printStackTrace(); return false; } } } private boolean writeCSVTransactionAll(String csvFilePath, int transDuration, int nrOfEmptyMsg){ String baseFileName = csvFilePath.substring(0, csvFilePath.lastIndexOf(".")); String fileName = baseFileName + "Transactions.csv"; BufferedWriter bufferedWriter = null; try { //Construct the BufferedWriter object bufferedWriter = new BufferedWriter(new FileWriter(fileName, true)); //Start writing to the output stream bufferedWriter.write(powerLevel); bufferedWriter.write(";"); bufferedWriter.write(obuName); bufferedWriter.write(";"); bufferedWriter.write(dutyCycle); bufferedWriter.write(";"); bufferedWriter.write(repNo); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(transDuration)); bufferedWriter.write(";"); bufferedWriter.write(Integer.toString(nrOfEmptyMsg)); bufferedWriter.newLine(); return true; } catch (FileNotFoundException ex) { ex.printStackTrace(); return false; } catch (IOException ex) { ex.printStackTrace(); return false; } finally { //Close the BufferedWriter try { if (bufferedWriter != null) { bufferedWriter.flush(); bufferedWriter.close(); } } catch (IOException ex) { ex.printStackTrace(); return false; } } } private void IntegerReturn(TriComponentId componentId, TriPortId portId, TriAddress address, TriSignatureId signatureId, Loading @@ -121,7 +419,6 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { RB.getTriCommunicationTE().triEnqueueReply(portId, address, componentId, signatureId, parameterList, new TriMessageParameter(RB, TriParameterPassingMode.TRI_IN, "", returnValue)); } private void BooleanReturn(TriComponentId componentId, TriPortId portId, TriAddress address, TriSignatureId signatureId, TriParameterList parameterList, boolean result) { Loading @@ -131,6 +428,20 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { RB.getTriCommunicationTE().triEnqueueReply(portId, address, componentId, signatureId, parameterList, new TriMessageParameter(RB, TriParameterPassingMode.TRI_IN, "", returnValue)); } private void TraceFileListReturn(TriComponentId componentId, TriPortId portId, TriAddress address, TriSignatureId signatureId, TriParameterList parameterList, String [] result) { RecordOfValue rov = (RecordOfValue) RB.getTciCDRequired().getTypeForName("TraceParserSystem.TraceFileList").newInstance(); rov.setLength(0); for (String traceFileStr : result) { CharstringValue cv = (CharstringValue) RB.getTciCDRequired().getCharstring().newInstance(); cv.setString(traceFileStr); rov.appendField(cv); } TriMessage returnValue = RB.TestAdapter.getCodec(SIGNATURE_ENCODING).encode(rov); RB.getTriCommunicationTE().triEnqueueReply(portId, address, componentId, signatureId, parameterList, new TriMessageParameter(RB, TriParameterPassingMode.TRI_IN, "", returnValue)); } private boolean setTraceFile(String tracePathPr){ File traceFile = new File(tracePathPr); Loading @@ -144,35 +455,12 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { traceFile.delete(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; } // private boolean setTraceFile(String tracePathPr){ // File traceFile = new File(tracePathPr); // // if (traceFile.exists() && traceFile.canRead()) { // this.tracePath = tracePathPr; // isFolder(traceFile); // return true; // } // // return false; // } private void isFolder(File traceFile){ isFolder = traceFile.isDirectory(); } private void getFolderContent(File folder){ traceNameList = Arrays.asList(folder.list()); } private int getTraceCnt(){ traceParse = new TraceParser(RB, tracePath); traceParse.parseTrace(); Loading Loading @@ -263,6 +551,13 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin { public TriStatus triEndTestCase() { if (startAnalyzeTraceThread!=null && startAnalyzeTraceThread.isAlive()) { try { startAnalyzeTraceThread.join(1000); } catch (InterruptedException e) { //ignore } } return new TriStatusImpl(); } Loading