Commit 12e61a34 authored by predusi's avatar predusi
Browse files

initial commit of the trace parser.

parent aaa2169b
Loading
Loading
Loading
Loading

.classpath

0 → 100644
+7 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con" path="com.testingtech.ttworkbench.core.TTWB_LIBRARY"/>
	<classpathentry kind="src" path="javasrc"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="output" path="build"/>
</classpath>

.project

0 → 100644
+28 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>DSRC_TraceValidation</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>com.testingtech.ttworkbench.ttthree.modelBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>com.testingtech.ttworkbench.xcleditor.todoBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>com.testingtech.ttworkbench.core.ttcn3nature</nature>
		<nature>org.eclipse.jdt.core.javanature</nature>
	</natures>
</projectDescription>
+26 −0
Original line number Original line Diff line number Diff line
: BID++
:  time
 Current value: 2011-05-09 11:19:49,912.468 (UTC)
   UTC Offset:  60 min
   DST on:      2011-03-27
   DST off:     2011-10-30
:  trace
0xAA481AC8 [+    0]   DL 18 bytes  FF A0 03 91 80 00 08 98 BD 9A 4D C7 CD F0 00 01 01 00 
0xAA481FB5 [+ 1261]   UL  5 bytes  7A C2 0E 2B 60  RSSI 1 UL_SIG 256
0xAA482A12 [+ 2653]   DL  5 bytes  7A C2 0E 2B 20 
0xAA483056 [+ 1604]   UL 36 bytes  7A C2 0E 2B C0 03 91 90 00 01 C1 01 02 10 6A 40 01 04 00 01 02 02 00 2F 02 04 A9 27 AF AE F2 02 00 01 02 00  RSSI 1 UL_SIG 1249
0xAA486646 [+13808]   DL 18 bytes  FF A0 03 91 80 00 08 98 BD 9A 4D C7 CD F0 00 01 01 00 
0xAA486B3A [+ 1268]   UL  5 bytes  7A C2 0E 2B 60  RSSI 1 UL_SIG 256
0xAA4876DB [+ 2977]   DL 40 bytes  7A C2 0E 2B A8 77 91 0D 01 00 04 77 81 89 23 11 01 20 04 2A A9 5A 88 76 91 6A 01 04 77 81 89 23 07 18 21 1A 11 13 14 16 
0xAA4888C2 [+ 4583]   UL 99 bytes  7A C2 0E 2B D0 F7 00 91 14 01 12 01 20 40 12 34 56 78 90 12 34 56 78 5F 2B 5D 00 00 04 DB 74 17 43 91 74 01 07 18 38 04 11 27 0B 82 21 41 2A A9 5A 25 6A 40 01 0B 5F 01 07 00 01 01 00 00 00 00 6A 40 01 03 00 01 00 00 00 00 1A 3A 00 05 11 31 14 13 33 00 00 14 34 00 00 00 00 00 00 16 36 10 00 00 00  RSSI 4 UL_SIG 3952
0xAA48A399 [+ 6871]   DL 18 bytes  FF A0 03 91 80 00 08 98 BD 9A 4D C7 CD F0 00 01 01 00 
0xAA48C3A4 [+ 8203]   DL 81 bytes  7A C2 0E 2B A0 F7 91 6A 01 04 77 81 89 23 01 10 91 49 01 04 77 81 89 23 03 21 41 2A A9 5A 88 6A 40 01 0B 5F 01 07 00 01 01 00 00 00 00 6A 40 01 04 00 01 00 00 00 00 63 7F 2A A9 5A 88 0B 5F 01 07 00 01 00 00 00 00 1A 3A 00 06 91 05 00 0A 00 00 
0xAA48CCBE [+ 2330]   UL 36 bytes  7A C2 0E 2B D0 77 00 91 74 01 01 10 2F 6A 40 0E 54 46 20 34 39 00 00 00 00 00 00 00 00 00 91 50 01 91 10 00  RSSI 11 UL_SIG 1700
0xAA48E0EC [+ 5166]   DL 18 bytes  FF A0 03 91 80 00 08 98 BD 9A 4D C7 CD F0 00 01 01 00 
0xAA490901 [+10261]   DL 10 bytes  7A C2 0E 2B 80 03 91 20 00 00 
0xAA490C45 [+  836]   DL 10 bytes  7A C2 0E 2B 80 03 91 20 00 00 
0xAA4911A7 [+ 1378]   DL 18 bytes  FF A0 03 91 80 00 08 98 BD 9A 4D C7 CD F0 00 01 01 00 


Those were the most recent 15 frames
: trace c
+136 −0
Original line number Original line Diff line number Diff line
package org.etsi.its.adapter;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import de.tu_berlin.cs.uebb.muttcn.runtime.RB;
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 stopCommandStr = "Those were the most recent";
	
	private String filePath;


	private final RB RB;
	
	public TraceParser(RB RB, String filePath){
		this.RB = RB;
		this.filePath = filePath;
	}
	
//	public static void main(String[] args) {
//		startTraceParsing("C:\\Demo_Dump2.txt");
//		
//	}
	
	public void parseTrace(){
		try {
			ArrayList<TransactionStructure> transactions = null;
			
			FileReader fr = new FileReader(filePath);
			BufferedReader br = new BufferedReader(fr);
			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)){
					transactionStarted = true;
					transactions = new ArrayList<TransactionStructure>();
					traceList.add(transactions);
					System.out.println("++++++++++++++++ Trace started ++++++++++++++++");
				}
//				else if (line.startsWith("<-----------")) {
				else if (line.startsWith(stopCommandStr)) {
					transactionStarted = false;
					System.out.println("++++++++++++++++ Trace finished ++++++++++++++++");
				}
				if (transactionStarted){
					if (line.startsWith("0x")) {
						line = line.substring(2); //cut 0x
						TransactionStructure transaction = new TransactionStructure();
						line = line.trim();
						String timestamp=line.substring(0, line.indexOf(" "));
						line=line.substring(line.indexOf(" "));
						
						System.out.println("Timestamp:   " + timestamp);
						transaction.setTimeStamp(new BigInteger(timestamp, 16));
						line = line.substring(line.lastIndexOf("]")+1).trim();
						StringTokenizer st = new StringTokenizer(line, " ");
						int tokens = st.countTokens();
						int bytes=0;
						int bytesCounter=0;
						for (int i=0; i<tokens;i++) {
							String token = st.nextToken();
							switch (i) {
							case 0:
								if (token.equals("UL")) { //UL
									transaction.setDirection(TransactionStructure.RSU); 
								}
								else if(token.equals("DL")) { //DL
									transaction.setDirection(TransactionStructure.OBU); 
								}
								else {
									//TODO error!
								}
								System.out.println("Direction:   " + token);
								break;
							case 1:
								System.out.println("no of bytes: " + token);
								bytes = Integer.parseInt(token);
								transaction.setNoOfBytes(bytes);
								break;
							case 2:
								//ignore
								break;
							case 3:
								if (bytesCounter<bytes) {
									System.out.print  ("payload    : " + token);
									transaction.setPayload(new OctetString(RB, token).toByteArray());
									
									bytesCounter++;
								}
								break;
							default:
								if (bytesCounter<bytes) {
									System.out.print(token);
									byte [] oldPayload = transaction.getPayload();
									transaction.setPayload(new OctetString(RB, oldPayload.length, oldPayload).concat(new OctetString(RB, token)).toByteArray());
									bytesCounter++;
								}
								if (i==tokens-1) {
									System.out.println();
								}
								break;
							}
						}
						transactions.add(transaction);
					}
				}
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	public int getTraceCount(){
		return traceList.size();
	}

	public List<TransactionStructure> getTrace(int index) {
		return traceList.get(index);
	}

}
+361 −0
Original line number Original line Diff line number Diff line
package org.etsi.its.adapter;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.etsi.ttcn.tci.BooleanValue;
import org.etsi.ttcn.tci.CharstringValue;
import org.etsi.ttcn.tci.IntegerValue;
import org.etsi.ttcn.tri.TriActionTemplate;
import org.etsi.ttcn.tri.TriAddress;
import org.etsi.ttcn.tri.TriAddressList;
import org.etsi.ttcn.tri.TriComponentId;
import org.etsi.ttcn.tri.TriException;
import org.etsi.ttcn.tri.TriMessage;
import org.etsi.ttcn.tri.TriParameter;
import org.etsi.ttcn.tri.TriParameterList;
import org.etsi.ttcn.tri.TriParameterPassingMode;
import org.etsi.ttcn.tri.TriPortId;
import org.etsi.ttcn.tri.TriPortIdList;
import org.etsi.ttcn.tri.TriSignatureId;
import org.etsi.ttcn.tri.TriStatus;
import org.etsi.ttcn.tri.TriTestCaseId;

import com.testingtech.ttcn.tri.AbstractPlugin;
import com.testingtech.ttcn.tri.ISAPlugin;
import com.testingtech.ttcn.tri.PluginIdentifier;
import com.testingtech.ttcn.tri.TriAddressImpl;
import com.testingtech.ttcn.tri.TriMessageImpl;
import com.testingtech.ttcn.tri.TriStatusImpl;

import de.tu_berlin.cs.uebb.muttcn.runtime.RB;
import de.tu_berlin.cs.uebb.ttcn.runtime.LocalMessage;
import de.tu_berlin.cs.uebb.ttcn.tri.TriMessageParameter;

public class TracePortPlugin extends AbstractPlugin implements  ISAPlugin {

	private static final String MSG_ENCODING = "BaseMessages";
	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;
	private TriComponentId ulComponent;

	private TriPortId ulTsiPortId;
	private TriComponentId dlComponent;
	private TriPortId dlTsiPortId;
	
	public TracePortPlugin(PluginIdentifier pluginId){
		this.pluginId = pluginId;
	}


	public void setRB(RB rb) {
		RB = rb;
	}

	public TriStatus setUp() {
		return new TriStatusImpl();
	}

	public TriStatus tearDown() {
		return new TriStatusImpl();
	}

	public TriStatus triCall(TriComponentId componentId, TriPortId portId,
			TriAddress address, TriSignatureId signatureId, TriParameterList parameterList) {
		
		String signatureName = signatureId.getSignatureName();
		if ("setTraceFile".equals(signatureName)) {
			TriParameter tracePathParam = parameterList.get(0);
			String  tracePath = getCharstringParameterData(tracePathParam);
			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("getTransactionCnt".equals(signatureName)){
			int traceCnt = getTraceCnt();
			IntegerReturn(componentId, portId, address, signatureId,
					parameterList, traceCnt);
		}else if("startAnalyzeTrace".equals(signatureName)){
			TriParameter transactionCntParam = parameterList.get(0);
			final int transactionCnt = getIntegerParameterData(transactionCntParam);
			new Thread(tracePath) {

				public void run() {
					startAnalyzeTrace(transactionCnt);
				}
				
			}.start();
			BooleanReturn(componentId, portId, address, signatureId,
					parameterList, true);
		}else if("finishAnalyzeTrace".equals(signatureName)){
			//TOD0
		}
		
		
		return new TriStatusImpl();
	}


	private void IntegerReturn(TriComponentId componentId, TriPortId portId,
			TriAddress address, TriSignatureId signatureId,
			TriParameterList parameterList, int traceCnt) {
		IntegerValue iv = (IntegerValue) RB.getTciCDRequired().getInteger().newInstance();
		iv.setInt(traceCnt);
		TriMessage returnValue = RB.TestAdapter.getCodec(SIGNATURE_ENCODING).encode(iv);
		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) {
		BooleanValue bv = (BooleanValue) RB.getTciCDRequired().getBoolean().newInstance();
		bv.setBoolean(result);
		TriMessage returnValue = RB.TestAdapter.getCodec(SIGNATURE_ENCODING).encode(bv);
		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);
		
		try {
			boolean fileCreated = traceFile.createNewFile();
			if (!fileCreated && traceFile.canRead()) {
				this.tracePath = tracePathPr;
				return true;
			}
			if (fileCreated) {
				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();
		
		return traceParse.getTraceCount();

	}
	
	private boolean startAnalyzeTrace(int trace){
        boolean result = false;
		List<TransactionStructure> transactions = traceParse.getTrace(trace);
		TriPortId tsiPortId = null;
		TriComponentId componentId = null;
		
		for (TransactionStructure transaction : transactions) {
			if (transaction.getDirection() == TransactionStructure.RSU) { //UL
				tsiPortId = ulTsiPortId;
				componentId = ulComponent;
			}
			if (transaction.getDirection() == TransactionStructure.OBU) { //DL
				tsiPortId = dlTsiPortId;
				componentId = dlComponent;
			}
			IntegerValue iv = (IntegerValue) RB.getTciCDRequired().getInteger().newInstance();
			iv.setBigInt(transaction.getTimeStamp());
			TriMessage address = RB.TestAdapter.getCodec(MSG_ENCODING).encode(iv);
			byte[] payload = transaction.getPayload();
			if (payload==null) {
				payload = new byte[]{};//TODO for empty messages it is null instead of empty array
			}
			RB.getTriCommunicationTE().triEnqueueMsg(tsiPortId, new TriAddressImpl(address.getEncodedMessage()), componentId, new TriMessageImpl(payload));
		}
		return result;
	}
	
	public String getCharstringParameterData(final TriParameter param) throws UnsupportedOperationException {
		if (param instanceof TriMessageParameter) {
			TriMessageParameter triMsgParam = (TriMessageParameter) param;
			if (triMsgParam.getMessage() instanceof LocalMessage) {
				LocalMessage localMsg = (LocalMessage) triMsgParam.getMessage();
				if (localMsg.getContent() instanceof CharstringValue) {
					CharstringValue v = (CharstringValue) localMsg.getContent();
					if (!v.notPresent()) {
						return v.getString();
					}
					else {
						return null;
					}
				}
			}
		}
		throw new UnsupportedOperationException("getCharstringParameterData: Parameter not of type charstring");
	}
	
	public int getIntegerParameterData(final TriParameter param) throws UnsupportedOperationException {
		if (param instanceof TriMessageParameter) {
			TriMessageParameter triMsgParam = (TriMessageParameter) param;
			if (triMsgParam.getMessage() instanceof LocalMessage) {
				LocalMessage localMsg = (LocalMessage) triMsgParam.getMessage();
				if (localMsg.getContent() instanceof IntegerValue) {
					IntegerValue v = (IntegerValue) localMsg.getContent();
					if (!v.notPresent()) {
						return v.getInt();
					}
				}
			}
		}
		throw new UnsupportedOperationException("getIntegerParameterData: Parameter not of type integer or omit");

	}

	public TriStatus triCallBC(TriComponentId componentId, TriPortId portId,
			TriSignatureId signatureId, TriParameterList parameterList) {
		return new TriStatusImpl("triCallBC not supported");
	}


	public TriStatus triCallMC(TriComponentId componentId, TriPortId portId,
			TriAddressList addressList, TriSignatureId signatureId, TriParameterList parameterList) {
		return new TriStatusImpl("triCallMC not supported");
	}


	public TriStatus triEndTestCase() {
		return new TriStatusImpl();
	}


	public TriStatus triExecuteTestcase(TriTestCaseId testCaseId, TriPortIdList portIdList) {
		return new TriStatusImpl();
	}


	public TriStatus triMap(TriPortId compPortId, TriPortId tsiPortId) {
		if (compPortId.getPortName().equals("rsuPort")) {
			ulComponent = compPortId.getComponent();
			ulTsiPortId = tsiPortId;
		}
		else if (compPortId.getPortName().equals("obuPort")) {
			dlComponent = compPortId.getComponent();
			dlTsiPortId = tsiPortId;
		}
		else if (compPortId.getPortName().equals("controlPort")) {
			
		}
		else {
			return new TriStatusImpl("Unsupported port: " + compPortId.getPortName());
		}
		return new TriStatusImpl();
	}


	public TriStatus triRaise(TriComponentId componentId, TriPortId portId,
			TriAddress address, TriSignatureId signatureId, TriException exception) {
		return new TriStatusImpl("triRaise not supported");
	}


	public TriStatus triRaiseBC(TriComponentId componentId, TriPortId portId,
			TriSignatureId signatureId, TriException exception) {
		return new TriStatusImpl("triRaiseBC not supported");
	}


	public TriStatus triRaiseMC(TriComponentId componentId, TriPortId portId,
			TriAddressList addressList, TriSignatureId signatureId, TriException exception) {
		return new TriStatusImpl("triRaiseMC not supported");
	}


	public TriStatus triReply(TriComponentId componentId, TriPortId portId,
			TriAddress address, TriSignatureId signatureId, TriParameterList parameterList,
			TriParameter parameter) {
		return new TriStatusImpl("triReply not supported");
	}


	public TriStatus triReplyBC(TriComponentId componentId, TriPortId portId,
			TriSignatureId signatureId, TriParameterList parameterList, TriParameter parameter) {
		return new TriStatusImpl("triReplyBC not supported");
	}


	public TriStatus triReplyMC(TriComponentId componentId, TriPortId portId,
			TriAddressList addressList, TriSignatureId signatureId, TriParameterList parameterList,
			TriParameter parameter) {
		return new TriStatusImpl("triReplyMC not supported");
	}


	public TriStatus triSAReset() {
		return new TriStatusImpl();
	}


	public TriStatus triSend(TriComponentId componentId, TriPortId portId,
			TriAddress address, TriMessage message) {
		return new TriStatusImpl("triSend not supported");
	}


	public TriStatus triSendBC(TriComponentId componentId, TriPortId portId,
			TriMessage message) {
		return new TriStatusImpl("triSendBC not supported");
	}


	public TriStatus triSendMC(TriComponentId componentId, TriPortId portId,
			TriAddressList addressList, TriMessage message) {
		return new TriStatusImpl("triSendMC not supported");
	}


	public TriStatus triSutActionInformal(String str) {
		return new TriStatusImpl("triSutActionInformal not supported");
	}


	public TriStatus triSutActionTemplate(TriActionTemplate actionTemplate) {
		return new TriStatusImpl("triSutActionTemplate not supported");
	}


	public TriStatus triUnmap(TriPortId portId, TriPortId portId1) {
		ulComponent = null;
		ulTsiPortId = null;
		dlComponent = null;
		dlTsiPortId = null;
		return new TriStatusImpl();
	}

}
Loading