Commit 6ec3bb99 authored by garciay's avatar garciay
Browse files

Add external function to compute TimeMark

parent dcd8c821
......@@ -28,6 +28,15 @@ public interface IItsExternalFunctionsProvider {
*/
public IntegerValue fx_getCurrentTime();
/**
* This external function gets the current time
* @return The current time in tenths of a second in the current or next hour in units of 1/10th second from UTC time
*
* TTCN-3 signature:
* external function fx_getCurrentTimeMark() return TimeMark;
*/
public IntegerValue fx_getCurrentTimeMark();
/**
* This external function gets the current time
* @param p_latitudeA Latitude of node A
......
......@@ -13,6 +13,8 @@ import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.logging.Logger;
......@@ -134,6 +136,18 @@ public class ItsExternalFunctionsProvider implements IItsExternalFunctionsProvid
return now;
} // End of method fx_getCurrentTime
@Override
public IntegerValue fx_getCurrentTimeMark() {
IntegerValue now = null;
//_logger.entering("ItsExternalFunctionsProvider", "fx_getCurrentTimeMark");
ZonedDateTime t = ZonedDateTime.now(ZoneOffset.UTC);
now = _tcicdWrapper.setInteger(new Integer((t.getMinute() * 60 + t.getSecond()) * 10));
//_logger.exiting("ItsExternalFunctionsProvider", "fx_getCurrentTimeMark", String.format("%4d", _tcicdWrapper.getBigInteger(now)));
return now;
}
/**
* This external function gets the current time
*
......@@ -214,8 +228,8 @@ public class ItsExternalFunctionsProvider implements IItsExternalFunctionsProvid
// String.format("%d, %d", p_distance.getInteger(),
// p_orientation.getInteger()));
FloatValue v_distance = _tcicdWrapper.getFloat();
v_distance.setFloat(p_distance.getFloat());
FloatValue v_distance = _tcicdWrapper.getFloat();
v_distance.setFloat(p_distance.getFloat());
double angularD = new Double(v_distance.getFloat()) / earthRadius;
double radHeading = new Double(_tcicdWrapper.getInteger(p_orientation)) * Math.PI / 180;
......@@ -793,25 +807,25 @@ public class ItsExternalFunctionsProvider implements IItsExternalFunctionsProvid
result.setBoolean(b);
if(b){
byte[] value = certificate.toByteArray();
p_certificate.setLength(value.length);
if (value.length != 0) {
for (int i = 0; i < value.length; i++) {
p_certificate.setOctet(i, value[i]);
} // End 'for' statement
}
byte[] value = certificate.toByteArray();
p_certificate.setLength(value.length);
if (value.length != 0) {
for (int i = 0; i < value.length; i++) {
p_certificate.setOctet(i, value[i]);
} // End 'for' statement
}
}else{
p_certificate.setLength(0);
p_certificate.setLength(0);
}
return result;
}
private static final byte[] ZERO32 = new byte[] {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
......@@ -829,19 +843,19 @@ public class ItsExternalFunctionsProvider implements IItsExternalFunctionsProvid
boolean b = _certCache.readCertificateDigest(p_certificateId.getString(), digest);
result.setBoolean(b);
p_digest.setLength(8);
byte[] value;
p_digest.setLength(8);
byte[] value;
if(b){
value = digest.toByteArray();
if (value.length != 8) {
value = ZERO32;
}
value = digest.toByteArray();
if (value.length != 8) {
value = ZERO32;
}
}else{
value = ZERO32;
}
for (int i = 0; i < 8; i++) {
p_digest.setOctet(i, value[i]);
} // End 'for' statement
value = ZERO32;
}
for (int i = 0; i < 8; i++) {
p_digest.setOctet(i, value[i]);
} // End 'for' statement
return result;
}
......@@ -860,20 +874,20 @@ public class ItsExternalFunctionsProvider implements IItsExternalFunctionsProvid
boolean b = _certCache.readSigningKey(p_keysId.getString(), key);
result.setBoolean(b);
p_key.setLength(32);
p_key.setLength(32);
byte[] value;
if(b){
byte[] value;
if(b){
value = key.toByteArray();
if(value.length != 32) {
value = ZERO32;
}
if(value.length != 32) {
value = ZERO32;
}
}else{
value = ZERO32;
value = ZERO32;
}
for (int i = 0; i < 32; i++) {
p_key.setOctet(i, value[i]);
}
p_key.setOctet(i, value[i]);
}
return result;
}
......@@ -892,20 +906,20 @@ public class ItsExternalFunctionsProvider implements IItsExternalFunctionsProvid
boolean b = _certCache.readEncryptingKey(p_keysId.getString(), key);
result.setBoolean(b);
p_key.setLength(32);
p_key.setLength(32);
byte[] value;
if(b){
byte[] value;
if(b){
value = key.toByteArray();
if(value.length != 32) {
value = ZERO32;
}
if(value.length != 32) {
value = ZERO32;
}
}else{
value = ZERO32;
value = ZERO32;
}
for (int i = 0; i < 32; i++) {
p_key.setOctet(i, value[i]);
}
p_key.setOctet(i, value[i]);
}
return result;
}
......
......@@ -21,7 +21,7 @@ public class LibItsContainer_asn1 extends LibIts_asn1 {
_encodingName = "ITS_Container";
}
@Override
@Override
public Value decode(final TriMessage message, final Type decodingHypothesis) {
_logger.entering("LibItsContainer_asn1", "decode", decodingHypothesis.getName());
......@@ -32,6 +32,10 @@ public class LibItsContainer_asn1 extends LibIts_asn1 {
TriMessage msg = TriProvider.getInstance().getTriFactory().createMessage();
msg.setEncodedMessage(ByteHelper.longToByteArray(lval, 6));
value = super.decode(msg, decodingHypothesis);
} else if (decodingHypothesis.getName().equals("TimeMark")) {
TriMessage msg1 = TriProvider.getInstance().getTriFactory().createMessage();
msg1.setEncodedMessage(message.getEncodedMessage());
value = super.decode(msg1, decodingHypothesis);
} else {
value = super.decode(message, decodingHypothesis);
}
......
......@@ -248,7 +248,7 @@ public class PluginAdapter implements TriCommunicationSA, TriCommunicationTE, xT
}
public TriStatus triExternalFunction(TriFunctionId functionId, TriParameterList parameterList, TriParameter returnValue) {
_logger.entering("PluginAdapter", "triExternalFunction", functionId.getFunctionName()); // + " - " + parameterList + " - " + returnValue.getParameterName() + " - " + returnValue.getParameterPassingMode());
//TERFactory.getInstance().logDebug(">>> PluginAdapter.triExternalFunction: " + functionId.getFunctionName()); // + " - " + parameterList + " - " + returnValue.getParameterName() + " - " + returnValue.getParameterPassingMode());
TriStatus result = m_triOK;
if (
......@@ -275,6 +275,9 @@ public class PluginAdapter implements TriCommunicationSA, TriCommunicationTE, xT
} else if (functionId.getFunctionName().endsWith("fx_getCurrentTime")) {
// Gets the current time
exec_getCurrentTime(returnValue);
} else if (functionId.getFunctionName().endsWith("fx_getCurrentTimeMark")) {
// Gets the current time
exec_getCurrentTimeMark(returnValue);
} else if (functionId.getFunctionName().endsWith("xf_parseIpv6Address")) {
exec_parseIpv6Address(parameterList, returnValue);
} else if (functionId.getFunctionName().endsWith("fx_hashWithSha256") && (parameterList.size() == 1)) {
......@@ -315,7 +318,7 @@ public class PluginAdapter implements TriCommunicationSA, TriCommunicationTE, xT
_logger.severe("Unprocessed external function");
result = m_triKO;
}
_logger.exiting("PluginAdapter", "triExternalFunction", ByteHelper.byteArrayToString(returnValue.getEncodedParameter()));
//TERFactory.getInstance().logDebug("<<< PluginAdapter.triExternalFunction: " + ByteHelper.byteArrayToString(returnValue.getEncodedParameter()));
return result;
}
......@@ -645,6 +648,23 @@ public class PluginAdapter implements TriCommunicationSA, TriCommunicationTE, xT
_logger.exiting("PluginAdapter", "exec_getCurrentTime", ByteHelper.byteArrayToString(returnValue.getEncodedParameter()));
} // End of method exec_getCurrentTime
private void exec_getCurrentTimeMark(TriParameter returnValue) {
//_logger.entering("PluginAdapter", "exec_getCurrentTimeMark");
// Execute the function
IntegerValue time = _extfuncsImpl.fx_getCurrentTimeMark();
//_logger.info(String.format("exec_getCurrentTimeMark returns %d", ((IntegerValueEx)time).getInt64()));
returnValue.setParameterPassingMode(TriParameterPassingMode.TRI_OUT);
returnValue.setNumberOfBits(Long.SIZE);
returnValue.setEncodedParameter(
ByteHelper.longToByteArray(
((IntegerValueEx)time).getInt64(),
4/*Integer.SIZE / Byte.SIZE*/ // Encoding on 32 bits
));
//_logger.exiting("PluginAdapter", "exec_getCurrentTimeMark: ", ByteHelper.byteArrayToString(returnValue.getEncodedParameter()));
} // End of method exec_getCurrentTimeMark
private void exec_generateKeyPair(TriParameterList parameterList, TriParameter returnValue) {
_logger.entering("PluginAdapter", "exec_generateKeyPair");
......
......@@ -5,16 +5,21 @@ camPort=BTP/GN/ETH
#camPort=BTP/GN/CSG
# Define the port/layer configuration for DENM
denmPort=BTP/GN/ETH
#denmPort=BTP/GN/CSG
# Define the port/layer configuration for MAPEM-SPATEM
mapemSpatemPort=BTP/GN/ETH
#mapemSpatemPort=BTP/GN/CSG
# Define the port/layer configuration for IVIM
ivimPort=BTP/GN/ETH
#ivimPort=BTP/GN/CSG
# Define the port/layer configuration for SREM-SSEM
sremSsemPort=BTP/GN/ETH
#sremSsemPort=BTP/GN/CSG
# Define the port/layer configuration for BTP
btpPort=GN/ETH
# Define the port/layer configuration for GeoNetworking
geoNetworkingPort=ETH
#geoNetworkingPort=ETH
geoNetworkingPort=CSG
# Define the port/layer configuration for GeoNetworking over IPv6
ipv6OverGeoNetworkingPort=Debug
# Define the port/layer configuration for CALM FNTP
......@@ -42,7 +47,9 @@ ConfigTesterSettings=172.17.15.39:12346
LocalEthernetMAC=00E08F008855
# Post-mortem ATS execution mode
OfflineMode=false
PcapFile=
PcapFile=pcap/vendor/uc1.pcappng
OffsetTime=30 # Start at +30 seconds
OffsetFrame=
# Define the Ethernet type value used by the IUT
IutEthernetTypeValue=0x8947
# Node Ethernet addresses
......
......@@ -114,6 +114,18 @@ public class ExternalFunctionsPluginProvider implements ExternalFunctionsProvide
return _externalFunctionsPluginProvider.fx_getCurrentTime();
}
/**
* This external function gets the current time
* @return The current time in tenths of a second in the current or next hour in units of 1/10th second from UTC time
*
* TTCN-3 signature:
* external function fx_getCurrentTimeMark() return TimeMark;
*/
@Override
public IntegerValue fx_getCurrentTimeMark() {
return _externalFunctionsPluginProvider.fx_getCurrentTimeMark();
}
/**
* External function to compute timestamp based on current time
* @return Unix-Epoch-Time mod 2^32
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment