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