Commit e8ef5e9e authored by garciay's avatar garciay

Merge STF455 staff

parent dc910ff4
......@@ -9,6 +9,7 @@
package org.etsi.its.adapter;
import org.etsi.its.adapter.ports.FsapPort;
import org.etsi.its.adapter.ports.GnPort;
/**
......@@ -27,6 +28,12 @@ public interface IManagementLayers {
*/
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
* @return GeoNetworking beaconing interval in ms
......
......@@ -55,4 +55,15 @@ public interface IManagementTA {
*/
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;
import org.etsi.common.ByteHelper;
import org.etsi.common.ITuple;
import org.etsi.common.Tuple;
import org.etsi.its.adapter.ports.FsapPort;
import org.etsi.its.adapter.ports.GnPort;
import org.etsi.ttcn.tci.CharstringValue;
......@@ -68,6 +69,11 @@ public class Management implements IManagementTA, IManagementLayers {
*/
private GnPort gnPort = null;
/**
* Registered FSAP Port
*/
private FsapPort fsapPort = null; // FIXME Enhance this using Fsap.send() method
/**
* Private constructor (Multiton pattern)
*/
......@@ -281,4 +287,27 @@ public class Management implements IManagementTA, IManagementLayers {
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 {
// Obtain the list of network interfaces
List<PcapIf> alldevs = new ArrayList<PcapIf>(); // Will be filled with NICs
int r = Pcap.findAllDevs(alldevs, errbuf);
int r;
try {
r = Pcap.findAllDevs(alldevs, errbuf);
} catch (java.lang.UnsatisfiedLinkError e) {
e.printStackTrace();
return;
}
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
System.err.printf("Can't read list of devices, error is %s", errbuf.toString());
return;
......
......@@ -14,6 +14,7 @@ import java.util.Observer;
import org.etsi.adapter.ITERequired;
import org.etsi.adapter.TERFactory;
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.PortEvent;
import org.etsi.its.adapter.ports.ProtocolPortFactory;
......@@ -92,6 +93,8 @@ public class TestAdapter implements TriCommunicationSA, Observer {
port = new AdapterControlPort(portName, ComponentId);
} else if (tsiPortId.getPortName().equals("utPort")) {
port = new UpperTesterPort(portName, ComponentId);
} else if (tsiPortId.getPortName().equals("cfPort")) {
port = new ConfigTesterPort(portName, ComponentId);
} else {
String componentName = compPortId.getComponent().getComponentName();
......@@ -293,7 +296,8 @@ public class TestAdapter implements TriCommunicationSA, Observer {
*/
@Override
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 {
layers.put("GN", GnLayer.class);
layers.put("G5", G5Layer.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("Debug", DebugLayer.class);
layers.put("CamSource", CamSourceLayer.class);
......
......@@ -7,12 +7,19 @@ import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
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.its.adapter.IManagementLayers;
import org.etsi.ttcn.tci.CharstringValue;
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) {
super(management, lowerStack);
......@@ -23,7 +30,7 @@ public class UdpIpLayer extends Layer {
*/
@Override
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 {
iutSocket.send(packet);
} catch (IOException e) {
......@@ -40,10 +47,22 @@ public class UdpIpLayer extends Layer {
if(registeredUpperLayer == null) {
super.register(upperLayer);
try {
iutAddress = InetAddress.getByName("127.0.0.1");
//System.out.println("IUT Address: " + iutAddress.getHostAddress());
iutPort = 3750;
iutSocket = new DatagramSocket(3751);
// UDP connection parameters
String settings = ((CharstringValue)TERFactory.getInstance().getTaParameter("LowerTesterSettings")).getString();
Matcher matcher = settingsPattern.matcher(settings);
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.start();
} catch (Exception e) {
......@@ -69,7 +88,8 @@ public class UdpIpLayer extends Layer {
private DatagramSocket iutSocket;
private InetAddress iutAddress;
private int iutPort;
private int iutClientPort;
private int iutServerPort;
private Thread iutThread;
private class UdpThread extends Thread {
......
......@@ -20,6 +20,7 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl
/* AdapterControl Primitives */
private static final byte AcGnPrimitive = 0;
private static final byte AcGn6Primitive = 1;
private static final byte AcFsapPrimitive = 2;
/* AdapterControl Response */
private static final byte AcGnResponse = 0;
......@@ -112,6 +113,15 @@ public class AdapterControlPort extends AdapterPort implements IPort, IObservabl
}
*/
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
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
DatagramPacket packet = new DatagramPacket(buf, buf.length);
taSocket.receive(packet);
setChanged();
notifyObservers(new PortEvent(ByteHelper.extract(packet.getData(), packet.getOffset(), packet.getLength()), getPortName(), getComponentName()));
} catch (IOException e) {
running = false;
}
}
taSocket.close();
}
}
} // End of class ConfigTesterPort
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 FntpPort 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 FntpPort(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 FntpInd indication header
// Extract LINK_LAYER_DESTINATION
byte[] fntpInd = ByteHelper.concat(message, (byte[])lowerInfo.get(EthernetLayer.LINK_LAYER_DESTINATION));
super.receive(fntpInd, lowerInfo);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.ports.IPort#send(byte[])
*/
@Override
public boolean send(byte[] message) {
ByteHelper.dump("FntpPort.send", message);
HashMap<String, Object> params = new HashMap<String, Object>();
return send(message, params);
}
public boolean triggerInSapPrimitiveUp(byte[] inSapPrimitiveUp) {
ByteHelper.dump("FntpPort.triggerInSapPrimitiveUp", inSapPrimitiveUp);
HashMap<String, Object> params = new HashMap<String, Object>();
params.put(EthernetLayer.LINK_LAYER_DESTINATION, management.getLinkLayerAddress());
return send(inSapPrimitiveUp, params);