Commit 47feb5a0 authored by garciay's avatar garciay
Browse files

Add a configuration port to the RSUsimulator

parent 679bb02b
package org.etsi.its.adapter.ports;
/**
* Upper Tester port implementation. This port is used to trigger IUT's upper interface
*
* @author ETSI / STF424
* @version $URL$
* $Id$
*
*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
......@@ -31,25 +41,25 @@ public class ConfigTesterPort extends AdapterPort implements IPort, IObservable
*/
public ConfigTesterPort(final String portName, final String componentName) {
super(portName, componentName);
// UDP connection parameters
String settings = ((CharstringValue)TERFactory.getInstance().getTaParameter("ConfigTesterSettings")).getString();
Matcher matcher = settingsPattern.matcher(settings);
if (matcher.find()) {
try {
try {
cfPeerAddress = InetAddress.getByName(matcher.group(1));
} catch (UnknownHostException e1) {
e1.printStackTrace();
}
}
cfPeerPort = Integer.parseInt(matcher.group(2));
} else {
}
// FIXME
}
// UDP socket for communication with Configuration module
running = true;
// UDP socket for communication with UT
try {
cfSocket = new DatagramSocket();
cfSocket = new DatagramSocket(cfPeerPort + 1);
cfThread = new UdpThread(cfSocket);
cfThread.start();
} catch (Exception e) {
......@@ -59,20 +69,24 @@ public class ConfigTesterPort extends AdapterPort implements IPort, IObservable
@Override
public boolean send(final byte[] message) {
DatagramPacket packet = new DatagramPacket(message, message.length, cfPeerAddress, cfPeerPort);
try {
ByteArrayOutputStream dataToSent = new ByteArrayOutputStream();
dataToSent.write(message);
byte[] output = dataToSent.toByteArray();
DatagramPacket packet = new DatagramPacket(output, output.length, cfPeerAddress, cfPeerPort);
cfSocket.send(packet);
} catch (IOException e) {
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}
return false;
}
@Override
public void dispose() {
if(running) {
if(running) {
running = false;
if(cfThread != null) {
try {
......@@ -81,49 +95,50 @@ public class ConfigTesterPort extends AdapterPort implements IPort, IObservable
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
private DatagramSocket cfSocket;
private Thread cfThread;
private InetAddress cfPeerAddress = null;
private int cfPeerPort = 0;
private Pattern settingsPattern = Pattern.compile(SETTINGS_PATTERN);
/**
* Indicates whether the port is still active. Setting this field to false will cause
* the UDP communication with Config Tester to be stopped
* the UDP communication with Upper Tester to be stopped
*/
private volatile boolean running;
private class UdpThread extends Thread {
private DatagramSocket taSocket;
public UdpThread(DatagramSocket taSocket) throws IOException {
this.taSocket = taSocket;
}
@Override
}
@Override
public void run() {
while(running) {
try {
try {
byte[] buf = new byte[4096];
// receive packet
DatagramPacket packet = new DatagramPacket(buf, buf.length);
taSocket.receive(packet);
setChanged();
setChanged();
notifyObservers(new PortEvent(ByteHelper.extract(packet.getData(), packet.getOffset(), packet.getLength()), getPortName(), getComponentName()));
} catch (IOException e) {
running = false;
running = false;
}
}
taSocket.close();
}
}
} // End of class UdpThread
} // End of class ConfigTesterPort
......@@ -62,6 +62,7 @@ public class CodecFactory {
// initialize additional codec plugins
org.etsi.ttcn.codec.its.adapter.Plugin.init();
org.etsi.ttcn.codec.its.uppertester.Plugin.init();
org.etsi.ttcn.codec.its.configtester.Plugin.init();
org.etsi.ttcn.codec.its.geonetworking.Plugin.init();
org.etsi.ttcn.codec.its.btp.Plugin.init();
org.etsi.ttcn.codec.its.security.Plugin.init();
......@@ -80,8 +81,8 @@ public class CodecFactory {
//TERFactory.getInstance().logDebug("getExternalCodec: Search external codec for " + encoding);
codec = externalCodecs.get(encoding);
if(codec != null) {
TERFactory.getInstance().logDebug(String.format("%50s", encoding));
TERFactory.getInstance().logDebug(" ==> " + codec.getClass().getName());
//TERFactory.getInstance().logDebug(String.format("%50s", encoding));
//TERFactory.getInstance().logDebug(" ==> " + codec.getClass().getName());
return codec;
}
return null;
......@@ -89,11 +90,11 @@ public class CodecFactory {
public ICodec getCodec(MainCodec mainCodec, int classType, String encoding, String typeName) {
TERFactory.getInstance().logDebug(String.format("%50s", typeName + "(" + encoding + ")"));
//TERFactory.getInstance().logDebug(String.format("%50s", typeName + "(" + encoding + ")"));
Class<? extends ICodec> cls = null;
Class<?>[] ctorParams = {MainCodec.class};
TERFactory.getInstance().logDebug("getCodec: Search internal codec for " + classType + '/' + encoding + '/' + typeName);
//TERFactory.getInstance().logDebug("getCodec: Search internal codec for " + classType + '/' + encoding + '/' + typeName);
cls = codecs.get(classType + '/' + encoding + '/' + typeName);
if(cls == null) {
cls = codecs.get(classType + '/' + encoding + '/');
......@@ -103,7 +104,7 @@ public class CodecFactory {
}
if(cls != null) {
TERFactory.getInstance().logDebug(" ==> " + cls.getName());
//TERFactory.getInstance().logDebug(" ==> " + cls.getName());
try {
Constructor<? extends ICodec> ctor = cls.getConstructor(ctorParams);
return ctor.newInstance(mainCodec);
......@@ -113,7 +114,7 @@ public class CodecFactory {
}
}
TERFactory.getInstance().logDebug(" ==> No codec found !");
//TERFactory.getInstance().logDebug(" ==> No codec found !");
return new Dummy(mainCodec);
}
......
package org.etsi.ttcn.codec.its.configtester;
import org.etsi.ttcn.codec.CodecBuffer;
import org.etsi.ttcn.codec.MainCodec;
import org.etsi.ttcn.codec.generic.Charstring;
import org.etsi.ttcn.tci.Type;
public class CfEvent extends Charstring {
public CfEvent(MainCodec mainCodec) {
super(mainCodec);
}
@Override
protected void preDecode(CodecBuffer buf, Type decodingHypothesis) {
// Set Length for CfEvent
mainCodec.setHint("CfEventLen", new Integer(buf.getNbBytes()).toString());
return;
}
}
/**
* @author ETSI / STF517 / Yann garcia
* @version $URL$
* $Id$
*/
package org.etsi.ttcn.codec.its.configtester;
import org.etsi.ttcn.tci.TciTypeClass;
import org.etsi.ttcn.codec.CodecFactory;
import org.etsi.ttcn.codec.generic.Record;
import org.etsi.ttcn.codec.generic.Boolean;
public class Plugin {
public static void init() {
// Basics
CodecFactory cf = CodecFactory.getInstance();
cf.setCodec(TciTypeClass.RECORD, "ConfigTester", "", Record.class);
cf.setCodec(TciTypeClass.BOOLEAN, "ConfigTester", "", Boolean.class);
cf.setCodec(TciTypeClass.CHARSTRING, "ConfigTester", "", CfEvent.class);
}
}
\ No newline at end of file
# Debug level - Authorized values: OFF, ALL, INFO, SEVERE
DEBUG_ENABLED=ALL
# Define the port/layer configuration for CAM
#camPort=BTP/GN/ETH
camPort=BTP/GN/CSG
camPort=BTP/GN/ETH
#camPort=BTP/GN/CSG
# Define the port/layer configuration for DENM
denmPort=BTP/GN/ETH
# Define the port/layer configuration for MAPEM-SPATEM
......@@ -19,16 +19,17 @@ geoNetworkingPort=ETH
ipv6OverGeoNetworkingPort=Debug
# Define the port/layer configuration for CALM FNTP
#fntpPort=FNTP/ETH
fntpPort=FNTP/UdpIp
#fntpPort=FNTP/UdpIp
# Define the port/layer configuration for CALM FSAP
fsapPort=FSAP/UdpIp
fsapPort=FSAP/UdpIp
#fsapPort=FSAP/UdpIp
#fsapPort=FSAP/UdpIp
#UpperTesterSettings=192.168.42.1:12345
UpperTesterSettings=172.17.15.38:12345
ConfigTesterSettings=172.17.15.39:12346
# Peer ITS station
#LinkLayer_Peer=8BADF00D0099
#LinkLayer_Peer=8BADF00D0199
# Define the MAC address of the Ethernet interface connected to the IUT device
# Home laptop VMWare MAC address
......@@ -45,15 +46,15 @@ PcapFile=
# Define the Ethernet type value used by the IUT
IutEthernetTypeValue=0x8947
# Node Ethernet addresses
LinkLayer_MTC=8BADF00D0000
LinkLayer_MTC=8BADF00D0100
# Link-Layer address of component NodeA
LinkLayer_NodeA=8BADF00D0001
LinkLayer_NodeA=8BADF00D0101
# Link-Layer address of component NodeB
LinkLayer_NodeB=8BADF00D0002
LinkLayer_NodeB=8BADF00D0102
# Link-Layer address of component NodeC
LinkLayer_NodeC=8BADF00D0003
LinkLayer_NodeC=8BADF00D0103
# Link-Layer address of component NodeD
LinkLayer_NodeD=8BADF00D0004
LinkLayer_NodeD=8BADF00D0104
# Interval between each beacon sent by TS (ms)
TsBeaconInterval=1000
# Latitude of Test System
......
Supports Markdown
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