Commit e8ef5e9e authored by garciay's avatar garciay

Merge STF455 staff

parent dc910ff4
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
package org.etsi.its.adapter; package org.etsi.its.adapter;
import org.etsi.its.adapter.ports.FsapPort;
import org.etsi.its.adapter.ports.GnPort; import org.etsi.its.adapter.ports.GnPort;
/** /**
...@@ -27,6 +28,12 @@ public interface IManagementLayers { ...@@ -27,6 +28,12 @@ public interface IManagementLayers {
*/ */
public void registerGnPort(GnPort gnPort); public void registerGnPort(GnPort gnPort);
/**
* Registers a FSAP port
* @param The FSAP port to register
*/
public void registerFsapPort(final FsapPort fntpPort);
/** /**
* Gets the GeoNetworking beaconing interval * Gets the GeoNetworking beaconing interval
* @return GeoNetworking beaconing interval in ms * @return GeoNetworking beaconing interval in ms
......
...@@ -55,4 +55,15 @@ public interface IManagementTA { ...@@ -55,4 +55,15 @@ public interface IManagementTA {
*/ */
public byte[] getLongPositionVector(byte[] targetGnAddress); public byte[] getLongPositionVector(byte[] targetGnAddress);
/**
* Requests Test Adapter to trigger a Service Provider InSapPrimitiveUp/SAM message sending
* @param sam The SAM message to transmit
*/
public void startSamTransmission(final byte[] sam);
/**
* Requests Test Adapter to stop a Service Provider InSapPrimitiveUp/SAM message sending
* @param sam The SAM message to transmit
*/
public void stopSamTransmission();
} }
...@@ -19,6 +19,7 @@ import org.etsi.adapter.TERFactory; ...@@ -19,6 +19,7 @@ import org.etsi.adapter.TERFactory;
import org.etsi.common.ByteHelper; import org.etsi.common.ByteHelper;
import org.etsi.common.ITuple; import org.etsi.common.ITuple;
import org.etsi.common.Tuple; import org.etsi.common.Tuple;
import org.etsi.its.adapter.ports.FsapPort;
import org.etsi.its.adapter.ports.GnPort; import org.etsi.its.adapter.ports.GnPort;
import org.etsi.ttcn.tci.CharstringValue; import org.etsi.ttcn.tci.CharstringValue;
...@@ -69,6 +70,11 @@ public class Management implements IManagementTA, IManagementLayers { ...@@ -69,6 +70,11 @@ public class Management implements IManagementTA, IManagementLayers {
private GnPort gnPort = null; private GnPort gnPort = null;
/** /**
* Registered FSAP Port
*/
private FsapPort fsapPort = null; // FIXME Enhance this using Fsap.send() method
/**
* Private constructor (Multiton pattern) * Private constructor (Multiton pattern)
*/ */
private Management() { private Management() {
...@@ -281,4 +287,27 @@ public class Management implements IManagementTA, IManagementLayers { ...@@ -281,4 +287,27 @@ public class Management implements IManagementTA, IManagementLayers {
enqueueBeacon = null; enqueueBeacon = null;
} }
/**
* Registers a FSAP port
* @param The FSAP port to register
*/
@Override
public void registerFsapPort(final FsapPort fsapPort) {
this.fsapPort = fsapPort;
}
@Override
public void startSamTransmission(final byte[] sam) {
if(fsapPort != null) {
fsapPort.startSamTransmission(sam);
}
}
@Override
public void stopSamTransmission() {
if(fsapPort != null) {
fsapPort.stopSamTransmission();
}
}
} }
...@@ -46,8 +46,13 @@ public class PcapMultiplexer implements Runnable { ...@@ -46,8 +46,13 @@ public class PcapMultiplexer implements Runnable {
// Obtain the list of network interfaces // Obtain the list of network interfaces
List<PcapIf> alldevs = new ArrayList<PcapIf>(); // Will be filled with NICs List<PcapIf> alldevs = new ArrayList<PcapIf>(); // Will be filled with NICs
int r;
int r = Pcap.findAllDevs(alldevs, errbuf); try {
r = Pcap.findAllDevs(alldevs, errbuf);
} catch (java.lang.UnsatisfiedLinkError e) {
e.printStackTrace();
return;
}
if (r == Pcap.NOT_OK || alldevs.isEmpty()) { if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
System.err.printf("Can't read list of devices, error is %s", errbuf.toString()); System.err.printf("Can't read list of devices, error is %s", errbuf.toString());
return; return;
......
...@@ -14,6 +14,7 @@ import java.util.Observer; ...@@ -14,6 +14,7 @@ import java.util.Observer;
import org.etsi.adapter.ITERequired; import org.etsi.adapter.ITERequired;
import org.etsi.adapter.TERFactory; import org.etsi.adapter.TERFactory;
import org.etsi.its.adapter.ports.AdapterControlPort; import org.etsi.its.adapter.ports.AdapterControlPort;
import org.etsi.its.adapter.ports.ConfigTesterPort;
import org.etsi.its.adapter.ports.IPort; import org.etsi.its.adapter.ports.IPort;
import org.etsi.its.adapter.ports.PortEvent; import org.etsi.its.adapter.ports.PortEvent;
import org.etsi.its.adapter.ports.ProtocolPortFactory; import org.etsi.its.adapter.ports.ProtocolPortFactory;
...@@ -92,6 +93,8 @@ public class TestAdapter implements TriCommunicationSA, Observer { ...@@ -92,6 +93,8 @@ public class TestAdapter implements TriCommunicationSA, Observer {
port = new AdapterControlPort(portName, ComponentId); port = new AdapterControlPort(portName, ComponentId);
} else if (tsiPortId.getPortName().equals("utPort")) { } else if (tsiPortId.getPortName().equals("utPort")) {
port = new UpperTesterPort(portName, ComponentId); port = new UpperTesterPort(portName, ComponentId);
} else if (tsiPortId.getPortName().equals("cfPort")) {
port = new ConfigTesterPort(portName, ComponentId);
} else { } else {
String componentName = compPortId.getComponent().getComponentName(); String componentName = compPortId.getComponent().getComponentName();
...@@ -293,7 +296,8 @@ public class TestAdapter implements TriCommunicationSA, Observer { ...@@ -293,7 +296,8 @@ public class TestAdapter implements TriCommunicationSA, Observer {
*/ */
@Override @Override
public TriStatus triSutActionInformal(String description) { public TriStatus triSutActionInformal(String description) {
return required.getTriStatus(TriStatus.TRI_ERROR, "triSutActionInformal not implemented"); javax.swing.JOptionPane.showMessageDialog(null, description);
return required.getTriStatus(TriStatus.TRI_OK, "");
} }
/** /**
......
package org.etsi.its.adapter.layers;
import java.util.Map;
import java.util.Stack;
import org.etsi.adapter.TERFactory;
import org.etsi.common.ByteHelper;
import org.etsi.its.adapter.IManagementLayers;
import org.etsi.ttcn.tci.CharstringValue;
/**
* Implementation of ITS IICP layer
*/
public class AtspLayer extends Layer implements IEthernetSpecific {
/**
* Constructor
* @param management Layer management instance
* @param lowerStack Lower protocol stack
*/
public AtspLayer(IManagementLayers management, Stack<String> lowerStack) {
super(management, lowerStack);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.ports.IEthernetSpecific#getEthernetType()
*/
@Override
public short getEthernetType() {
// Retrieve EthernetType value
Integer iutEthernetTypeValue = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("IutEthernetTypeValue")).getString());
return iutEthernetTypeValue.shortValue();
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#send(byte[], java.util.Map)
*/
@Override
public boolean send(byte[] message, Map<String, Object> params) {
return super.send(message, params);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#receive(byte[])
*/
@Override
public void receive(byte[] message, Map<String, Object> lowerInfo) {
super.receive(message, lowerInfo);
}
} // End of class AtspLayer
package org.etsi.its.adapter.layers;
import java.util.Map;
import java.util.Stack;
import org.etsi.adapter.TERFactory;
import org.etsi.its.adapter.IManagementLayers;
import org.etsi.ttcn.tci.CharstringValue;
/**
* Implementation of ITS FNTP layer
*/
public class FntpLayer extends Layer implements IEthernetSpecific {
/**
* Constructor
* @param management Layer management instance
* @param lowerStack Lower protocol stack
*/
public FntpLayer(IManagementLayers management, Stack<String> lowerStack) {
super(management, lowerStack);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.ports.IEthernetSpecific#getEthernetType()
*/
@Override
public short getEthernetType() {
// Retrieve EthernetType value
Integer iutEthernetTypeValue = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("IutEthernetTypeValue")).getString());
return iutEthernetTypeValue.shortValue();
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#send(byte[], java.util.Map)
*/
@Override
public boolean send(byte[] message, Map<String, Object> params) {
return super.send(message, params);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#receive(byte[])
*/
@Override
public void receive(byte[] message, Map<String, Object> lowerInfo) {
super.receive(message, lowerInfo);
}
} // End of class FntpLayer
package org.etsi.its.adapter.layers;
import java.util.Map;
import java.util.Stack;
import org.etsi.adapter.TERFactory;
import org.etsi.its.adapter.IManagementLayers;
import org.etsi.ttcn.tci.CharstringValue;
/**
* Implementation of ITS FSAP layer
*/
public class FsapLayer extends Layer implements IEthernetSpecific {
/**
* Constructor
* @param management Layer management instance
* @param lowerStack Lower protocol stack
*/
public FsapLayer(IManagementLayers management, Stack<String> lowerStack) {
super(management, lowerStack);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.ports.IEthernetSpecific#getEthernetType()
*/
@Override
public short getEthernetType() {
// Retrieve EthernetType value
Integer iutEthernetTypeValue = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("IutEthernetTypeValue")).getString());
return iutEthernetTypeValue.shortValue();
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#send(byte[], java.util.Map)
*/
@Override
public boolean send(byte[] message, Map<String, Object> params) {
return super.send(message, params);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#receive(byte[])
*/
@Override
public void receive(byte[] message, Map<String, Object> lowerInfo) {
super.receive(message, lowerInfo);
}
} // End of class FntpLayer
package org.etsi.its.adapter.layers;
import java.util.Map;
import java.util.Stack;
import org.etsi.adapter.TERFactory;
import org.etsi.its.adapter.IManagementLayers;
import org.etsi.ttcn.tci.CharstringValue;
/**
* Implementation of ITS IICP layer
*/
public class IicpLayer extends Layer implements IEthernetSpecific {
/**
* Constructor
* @param management Layer management instance
* @param lowerStack Lower protocol stack
*/
public IicpLayer(IManagementLayers management, Stack<String> lowerStack) {
super(management, lowerStack);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.ports.IEthernetSpecific#getEthernetType()
*/
@Override
public short getEthernetType() {
// Retrieve EthernetType value
Integer iutEthernetTypeValue = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("IutEthernetTypeValue")).getString());
return iutEthernetTypeValue.shortValue();
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#send(byte[], java.util.Map)
*/
@Override
public boolean send(byte[] message, Map<String, Object> params) {
return super.send(message, params);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.layers.Layer#receive(byte[])
*/
@Override
public void receive(byte[] message, Map<String, Object> lowerInfo) {
super.receive(message, lowerInfo);
}
} // End of class FntpLayer
...@@ -46,7 +46,11 @@ public class LayerFactory { ...@@ -46,7 +46,11 @@ public class LayerFactory {
layers.put("GN", GnLayer.class); layers.put("GN", GnLayer.class);
layers.put("G5", G5Layer.class); layers.put("G5", G5Layer.class);
layers.put("ETH", EthernetLayer.class); layers.put("ETH", EthernetLayer.class);
layers.put("UdpIp", UdpIpLayer.class); // Used for CALM ports
layers.put("FNTP", FntpLayer.class);
layers.put("FSAP", FsapLayer.class);
layers.put("IICP", IicpLayer.class);
layers.put("ATSP", AtspLayer.class);
layers.put("Loopback", LoopbackLayer.class); layers.put("Loopback", LoopbackLayer.class);
layers.put("Debug", DebugLayer.class); layers.put("Debug", DebugLayer.class);
layers.put("CamSource", CamSourceLayer.class); layers.put("CamSource", CamSourceLayer.class);
......
...@@ -7,12 +7,19 @@ import java.net.InetAddress; ...@@ -7,12 +7,19 @@ import java.net.InetAddress;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Stack; import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.etsi.adapter.TERFactory;
import org.etsi.common.ByteHelper; import org.etsi.common.ByteHelper;
import org.etsi.its.adapter.IManagementLayers; import org.etsi.its.adapter.IManagementLayers;
import org.etsi.ttcn.tci.CharstringValue;
public class UdpIpLayer extends Layer { public class UdpIpLayer extends Layer {
private static final String SETTINGS_PATTERN = "(\\S+)\\:(\\d+)\\:(\\d+)"; // FIXME The second port shall be optional if the same port shall be used for server and client
private Pattern settingsPattern = Pattern.compile(SETTINGS_PATTERN);
public UdpIpLayer(IManagementLayers management, Stack<String> lowerStack) { public UdpIpLayer(IManagementLayers management, Stack<String> lowerStack) {
super(management, lowerStack); super(management, lowerStack);
...@@ -23,7 +30,7 @@ public class UdpIpLayer extends Layer { ...@@ -23,7 +30,7 @@ public class UdpIpLayer extends Layer {
*/ */
@Override @Override
public boolean send(byte[] message, Map<String, Object> params) { public boolean send(byte[] message, Map<String, Object> params) {
DatagramPacket packet = new DatagramPacket(message, message.length, iutAddress, iutPort); DatagramPacket packet = new DatagramPacket(message, message.length, iutAddress, iutClientPort);
try { try {
iutSocket.send(packet); iutSocket.send(packet);
} catch (IOException e) { } catch (IOException e) {
...@@ -40,10 +47,22 @@ public class UdpIpLayer extends Layer { ...@@ -40,10 +47,22 @@ public class UdpIpLayer extends Layer {
if(registeredUpperLayer == null) { if(registeredUpperLayer == null) {
super.register(upperLayer); super.register(upperLayer);
try { try {
iutAddress = InetAddress.getByName("127.0.0.1"); // UDP connection parameters
//System.out.println("IUT Address: " + iutAddress.getHostAddress()); String settings = ((CharstringValue)TERFactory.getInstance().getTaParameter("LowerTesterSettings")).getString();
iutPort = 3750; Matcher matcher = settingsPattern.matcher(settings);
iutSocket = new DatagramSocket(3751); if (matcher.find()) {
iutAddress = InetAddress.getByName(matcher.group(1));
iutClientPort = Integer.parseInt(matcher.group(2));
if (matcher.group(3) != null) {
iutServerPort = Integer.parseInt(matcher.group(3));
} else {
iutServerPort = iutClientPort;
}
} else {
System.err.println("No pattern matching");
}
// UDP server socket for communication with UT
iutSocket = new DatagramSocket(iutServerPort);
iutThread = new UdpThread(iutSocket); iutThread = new UdpThread(iutSocket);
iutThread.start(); iutThread.start();
} catch (Exception e) { } catch (Exception e) {
...@@ -69,7 +88,8 @@ public class UdpIpLayer extends Layer { ...@@ -69,7 +88,8 @@ public class UdpIpLayer extends Layer {
private DatagramSocket iutSocket; private DatagramSocket iutSocket;
private InetAddress iutAddress; private InetAddress iutAddress;
private int iutPort; private int iutClientPort;
private int iutServerPort;
private Thread iutThread; private Thread iutThread;
private class UdpThread extends Thread { private class UdpThread extends Thread {
......
...@@ -20,6 +20,7 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl ...@@ -20,6 +20,7 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl
/* AdapterControl Primitives */ /* AdapterControl Primitives */
private static final byte AcGnPrimitive = 0; private static final byte AcGnPrimitive = 0;
private static final byte AcGn6Primitive = 1; private static final byte AcGn6Primitive = 1;
private static final byte AcFsapPrimitive = 2;
/* AdapterControl Response */ /* AdapterControl Response */
private static final byte AcGnResponse = 0; private static final byte AcGnResponse = 0;
...@@ -112,6 +113,15 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl ...@@ -112,6 +113,15 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl
} }
*/ */
break; break;
case AcFsapPrimitive:
ByteHelper.dump("AdapterControlPort.send", message);
byte[] data = ByteHelper.extract(message, 2, message.length - 2);
if ((data.length == 1) && (data[0] == 0x01)) {
Management.getInstance(getComponentName()).stopSamTransmission();
} else {
Management.getInstance(getComponentName()).startSamTransmission(data);
}
break;
} // End of 'switch' statement } // End of 'switch' statement
return result; return result;
......
package org.etsi.its.adapter.ports;
import java.util.HashMap;
import java.util.Map;
import org.etsi.adapter.TERFactory;
import org.etsi.common.ByteHelper;
import org.etsi.its.adapter.layers.EthernetLayer;
import org.etsi.its.adapter.layers.IEthernetSpecific;
import org.etsi.ttcn.tci.CharstringValue;
public class AtspPort extends ProtocolPort implements IEthernetSpecific {
/**
* Constructor
* @param portName Name of the port
* @param componentName Name of the component owning this port instance
* @param lowerStackDesc Description of the port's lower stack in the form "Layer/Layer/Layer/..."
* @param linkLayerAddress Link-layer address to be used by this port as source address (null if not applicable)
*/
public AtspPort(String portName, String componentName, String lowerStackDesc, String linkLayerAddress) {
super(portName, componentName, lowerStackDesc, linkLayerAddress);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.ports.IEthernetSpecific#getEthernetType()
*/
@Override
public short getEthernetType() {
// Retrieve EthernetType value
Integer iutEthernetTypeValue = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("IutEthernetTypeValue")).getString());
return iutEthernetTypeValue.shortValue();
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.ports.ProtocolPort#receive(byte[])
*/
@Override
public void receive(byte[] message, Map<String, Object> lowerInfo) {
// Encode with IicpInd indication header
// Extract LINK_LAYER_DESTINATION
byte[] iicpInd = ByteHelper.concat(message, (byte[])lowerInfo.get(EthernetLayer.LINK_LAYER_DESTINATION));
super.receive(iicpInd, lowerInfo);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.ports.IPort#send(byte[])
*/
@Override
public boolean send(byte[] message) {
ByteHelper.dump("AtspPort.send", message);
HashMap<String, Object> params = new HashMap<String, Object>();
return send(message, params);
}
public boolean triggerInSapPrimitiveUp(byte[] inSapPrimitiveUp) {
ByteHelper.dump("AtspPort.triggerInSapPrimitiveUp", inSapPrimitiveUp);
HashMap<String, Object> params = new HashMap<String, Object>();
params.put(EthernetLayer.LINK_LAYER_DESTINATION, management.getLinkLayerAddress());
return send(inSapPrimitiveUp, params);
}
} // End of class FntpPort
package org.etsi.its.adapter.ports;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.etsi.adapter.TERFactory;
import org.etsi.common.ByteHelper;
import org.etsi.ttcn.tci.CharstringValue;
/** This class implements behaviour for Configuration Tester port. This port is used to access to the IUT management port
* The Configuration tester entity in the SUT enables triggering Protocol functionalities by simulating primitives from
* from SAPs
* It is required to trigger the Protocol layer in the SUT to send Protocol specific messages, which are
* resulting from management layer primitives
*/
public class ConfigTesterPort extends AdapterPort implements IPort, IObservable {
private static final String SETTINGS_PATTERN = "(\\S+)\\:(\\d+)";
/**
* Constructor
* @param portName Name of the port
* @param componentName Name of the component owning this port instance
* @param localPortNumber Local port number for the UDP listener
* @param remotePortNumber UDP port listener of remote UT application
*/
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 {
cfPeerAddress = InetAddress.getByName(matcher.group(1));
} catch (UnknownHostException e1) {
e1.printStackTrace();
}
cfPeerPort = Integer.parseInt(matcher.group(2));
} else {
}
running = true;
// UDP socket for communication with UT
try {
cfSocket = new DatagramSocket();
cfThread = new UdpThread(cfSocket);
cfThread.start();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean send(final byte[] message) {
DatagramPacket packet = new DatagramPacket(message, message.length, cfPeerAddress, cfPeerPort);
try {
cfSocket.send(packet);
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
@Override
public void dispose() {
if(running) {
running = false;
if(cfThread != null) {
try {
cfSocket.close();
cfThread.join();
} 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
*/
private volatile boolean running;
private class UdpThread extends Thread {
private DatagramSocket taSocket;
public UdpThread(DatagramSocket taSocket) throws IOException {
this.taSocket = taSocket;
}
@Override
public void run() {
while(running) {
try {
byte[] buf = new byte[4096];
// receive packet