Commit e57d07c6 authored by predusi's avatar predusi
Browse files

make an workaround in order to support the case when the release msg is missing.

parent 0bc89236
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import java.util.Vector;

@@ -37,6 +38,7 @@ 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.runtime.OctetString;
import de.tu_berlin.cs.uebb.ttcn.tri.TriMessageParameter;

public class TracePortPlugin extends AbstractPlugin implements  ISAPlugin {
@@ -57,6 +59,7 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin {
	private String obuName;
	private String dutyCycle;
	private String repNo;
	private byte[] RELEASEMSG;
	
	public TracePortPlugin(PluginIdentifier pluginId){
		this.pluginId = pluginId;
@@ -474,24 +477,32 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin {
		List<TransactionStructure> transactions = traceParse.getTrace(trace);
		TriPortId tsiPortId = null;
		TriComponentId componentId = null;
		boolean firstUL=true;
		OctetString releaseEvent=null;
		BigInteger lastUL_TS=null;
		
		for (TransactionStructure transaction : transactions) {
			if (transaction.getDirection() == TransactionStructure.OBU) { //UL
				tsiPortId = obuTsiPortId;
				componentId = obuComponent;
				// if the first UL was registered then take the LinkId and build the Release Msg
				if (firstUL && transaction.getPayload() != null && transaction.getPayload().length>=4) {
					OctetString linkId = new OctetString(RB, transaction.getPayload().length, transaction.getPayload()).substr(0, 4);
					RELEASEMSG = new byte[]{(byte)0x80, (byte)0x03 , (byte)0x91 , (byte)0x20 , (byte)0x00, (byte)0x00};
					releaseEvent = linkId.concat(new OctetString(RB, RELEASEMSG.length, RELEASEMSG));
				}
				//take the time stamp of the last UL in order to calculate later the transaction duration
				lastUL_TS = transaction.getTimeStamp();
			}
			if (transaction.getDirection() == TransactionStructure.RSU) { //DL
				tsiPortId = rsuTsiPortId;
				componentId = rsuComponent;
			}
			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));
			RB.getTriCommunicationTE().triEnqueueMsg(tsiPortId, getAddress(transaction.getTimeStamp()), componentId, new TriMessageImpl(payload));
			// This sleep is added as a workaround so that the exchanged of the messages between the components is shoed synchronized
			try {
				Thread.sleep(100);
@@ -499,9 +510,21 @@ public class TracePortPlugin extends AbstractPlugin implements ISAPlugin {
				//ignore
			}
		}
		// at the end of transaction enqueue the Release Msg
		if (releaseEvent!=null && lastUL_TS!=null) {
			RB.getTriCommunicationTE().triEnqueueMsg(tsiPortId, getAddress(lastUL_TS), componentId, new TriMessageImpl(releaseEvent.toByteArray()));
		}
		return result;
	}


	private TriAddress getAddress(BigInteger timestamp) {
		IntegerValue iv = (IntegerValue) RB.getTciCDRequired().getInteger().newInstance();
		iv.setBigInt(timestamp);
		TriMessage address = RB.TestAdapter.getCodec(MSG_ENCODING).encode(iv);
		return new TriAddressImpl(address.getEncodedMessage());
	}
	
	public String getCharstringParameterData(final TriParameter param) throws UnsupportedOperationException {
		if (param instanceof TriMessageParameter) {
			TriMessageParameter triMsgParam = (TriMessageParameter) param;