Skip to content

Commit

Permalink
feat(application): servers don't have access on AdHocModule anymore (#…
Browse files Browse the repository at this point in the history
…404)

* Major refactoring of operating system interface hierarchy with a clear definition of which modules are available via additional interfaces.
* An OperatingSystem itself is not "owner" of a module anymore (but the implementing simulation unit is). Instead an specific OperatingSystem defines which modules it provides, by defining additional interfaces `CommunicativeCell`, `Perceptive`, `Navigable` and so on.
* `AbstractSimulationUnit` still implements and provides functionality a specific unit not necessarily needs, e.g., the `AbstractSimulationUnit` provides an `AdhocModule`, even if the implementing `ServerSimulationUnit` does not need such. Still, a server application can not access the `AdhocModule` anymore due to the clear definition of the `OperatingSystem` interfaces.
* Moved `navigation` package inside `simulation` package alongside `perception` and `communication`.
  • Loading branch information
kschrab authored Sep 3, 2024
1 parent a991ae4 commit eb5db43
Show file tree
Hide file tree
Showing 46 changed files with 348 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package org.eclipse.mosaic.app.examples.commuter;

import org.eclipse.mosaic.fed.application.ambassador.navigation.INavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.navigation.RoadPositionFactory;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.INavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.RoadPositionFactory;
import org.eclipse.mosaic.fed.application.ambassador.util.UnitLogger;
import org.eclipse.mosaic.fed.application.app.AbstractApplication;
import org.eclipse.mosaic.fed.application.app.api.Application;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

package org.eclipse.mosaic.app.tutorial;

import org.eclipse.mosaic.fed.application.ambassador.navigation.INavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.AdHocModuleConfiguration;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedAcknowledgement;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedV2xMessage;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.INavigationModule;
import org.eclipse.mosaic.fed.application.app.AbstractApplication;
import org.eclipse.mosaic.fed.application.app.api.CommunicationApplication;
import org.eclipse.mosaic.fed.application.app.api.VehicleApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import static org.mockito.Mockito.when;

import org.eclipse.mosaic.app.tutorial.WeatherWarningApp;
import org.eclipse.mosaic.fed.application.ambassador.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.VehicleParameters;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.AdHocModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedV2xMessage;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.util.UnitLogger;
import org.eclipse.mosaic.fed.application.app.api.os.VehicleOperatingSystem;
import org.eclipse.mosaic.lib.enums.SensorType;
Expand All @@ -34,7 +34,6 @@
import org.eclipse.mosaic.lib.objects.road.IConnection;
import org.eclipse.mosaic.lib.objects.road.IRoadPosition;
import org.eclipse.mosaic.lib.objects.v2x.MessageRouting;
import org.eclipse.mosaic.lib.objects.v2x.V2xMessage;
import org.eclipse.mosaic.lib.objects.v2x.V2xReceiverInformation;
import org.eclipse.mosaic.lib.objects.v2x.etsi.Denm;
import org.eclipse.mosaic.lib.objects.vehicle.VehicleData;
Expand Down
2 changes: 1 addition & 1 deletion bundle/src/assembly/resources/etc/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<appender-ref ref="CellLog"/>
</logger>

<logger name="org.eclipse.mosaic.fed.application.ambassador.navigation" additivity="false" level="INFO">
<logger name="org.eclipse.mosaic.fed.application.ambassador.simulation.navigation" additivity="false" level="INFO">
<appender-ref ref="NavigationLog"/>
</logger>
<logger name="org.eclipse.mosaic.lib.routing" additivity="false" level="INFO">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package org.eclipse.mosaic.fed.application.ambassador;

import org.eclipse.mosaic.fed.application.ambassador.eventresources.RemoveVehicles;
import org.eclipse.mosaic.fed.application.ambassador.navigation.CentralNavigationComponent;
import org.eclipse.mosaic.fed.application.ambassador.simulation.AbstractSimulationUnit;
import org.eclipse.mosaic.fed.application.ambassador.simulation.TrafficLightGroupUnit;
import org.eclipse.mosaic.fed.application.ambassador.simulation.TrafficManagementCenterUnit;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedV2xMessage;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.CentralNavigationComponent;
import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.CentralPerceptionComponent;
import org.eclipse.mosaic.fed.application.ambassador.util.EventNicenessPriorityRegister;
import org.eclipse.mosaic.fed.application.app.api.MosaicApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package org.eclipse.mosaic.fed.application.ambassador;

import org.eclipse.mosaic.fed.application.ambassador.navigation.CentralNavigationComponent;
import org.eclipse.mosaic.fed.application.ambassador.simulation.AbstractSimulationUnit;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.CentralNavigationComponent;
import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.CentralPerceptionComponent;
import org.eclipse.mosaic.fed.application.config.CApplicationAmbassador;
import org.eclipse.mosaic.interactions.communication.V2xMessageRemoval;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.AbstractCommunicationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.AdHocModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CellModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CommunicationModuleOwner;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedAcknowledgement;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedV2xMessage;
import org.eclipse.mosaic.fed.application.ambassador.util.ClassNameParser;
Expand Down Expand Up @@ -60,6 +61,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
Expand All @@ -72,7 +74,7 @@
* It supplies all functionality for loading applications, communication with the RTI
* and the processing of events, etc.
*/
public abstract class AbstractSimulationUnit implements EventProcessor, OperatingSystem {
public abstract class AbstractSimulationUnit implements EventProcessor, OperatingSystem, CommunicationModuleOwner {

/**
* Id (name) which indicates the unit.
Expand All @@ -99,7 +101,7 @@ public abstract class AbstractSimulationUnit implements EventProcessor, Operatin
/**
* Environment sensor data.
*/
private final HashMap<SensorType, EnvironmentEvent> environmentEvents = new HashMap<>();
private final Map<SensorType, EnvironmentEvent> environmentEvents = new HashMap<>();

private final AdHocModule adhocModule;

Expand Down Expand Up @@ -213,8 +215,6 @@ public final long getSimulationTime() {
return SimulationKernel.SimulationKernel.getCurrentSimulationTime();
}


@Override
public GeoPoint getInitialPosition() {
return initialPosition;
}
Expand Down Expand Up @@ -466,12 +466,10 @@ final byte[] getAndResetUserTaggedValue() {
return tmp;
}

@Override
public AdHocModule getAdHocModule() {
return this.adhocModule;
}

@Override
public final CellModule getCellModule() {
return this.cellModule;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package org.eclipse.mosaic.fed.application.ambassador.simulation;

import org.eclipse.mosaic.fed.application.ambassador.ErrorRegister;
import org.eclipse.mosaic.fed.application.ambassador.navigation.IRoutingModule;
import org.eclipse.mosaic.fed.application.ambassador.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.IRoutingModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.app.api.CommunicationApplication;
import org.eclipse.mosaic.fed.application.app.api.os.RoadSideUnitOperatingSystem;
import org.eclipse.mosaic.lib.enums.RsuType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
package org.eclipse.mosaic.fed.application.ambassador.simulation;

import org.eclipse.mosaic.fed.application.ambassador.ErrorRegister;
import org.eclipse.mosaic.fed.application.ambassador.navigation.IRoutingModule;
import org.eclipse.mosaic.fed.application.ambassador.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.AdHocModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.IRoutingModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.app.api.os.ServerOperatingSystem;
import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.mapping.ServerMapping;
import org.eclipse.mosaic.lib.util.scheduling.Event;

Expand Down Expand Up @@ -54,21 +52,11 @@ public ServerUnit(String unitName) {
routingModule = new NavigationModule(this);
}

@Override
public GeoPoint getPosition() {
throw new UnsupportedOperationException("Servers aren't mapped to a location.");
}

@Override
public CamBuilder assembleCamMessage(CamBuilder camBuilder) {
throw new UnsupportedOperationException("Servers can't send CAMs.");
}

@Override
public AdHocModule getAdHocModule() {
throw new UnsupportedOperationException("Servers can't access AdHoc functionality.");
}

@Override
public IRoutingModule getRoutingModule() {
return routingModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

import org.eclipse.mosaic.fed.application.ambassador.ErrorRegister;
import org.eclipse.mosaic.fed.application.ambassador.SimulationKernel;
import org.eclipse.mosaic.fed.application.ambassador.navigation.INavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.navigation.RoadPositionFactory;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.INavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.RoadPositionFactory;
import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.NopPerceptionModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.PerceptionModuleOwner;
import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.SimplePerceptionConfiguration;
import org.eclipse.mosaic.fed.application.app.api.CommunicationApplication;
import org.eclipse.mosaic.fed.application.app.api.VehicleApplication;
Expand Down Expand Up @@ -54,7 +55,7 @@
/**
* This class represents a vehicle in the application simulator.
*/
public class VehicleUnit extends AbstractSimulationUnit implements VehicleOperatingSystem {
public class VehicleUnit extends AbstractSimulationUnit implements VehicleOperatingSystem, PerceptionModuleOwner {

@Nonnull
private final NavigationModule navigationModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

import static java.lang.Integer.min;

import org.eclipse.mosaic.fed.application.app.api.os.modules.Locatable;
import org.eclipse.mosaic.interactions.communication.AdHocCommunicationConfiguration;
import org.eclipse.mosaic.lib.enums.AdHocChannel;
import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.addressing.AdHocMessageRoutingBuilder;
import org.eclipse.mosaic.lib.objects.communication.AdHocConfiguration;
import org.eclipse.mosaic.lib.objects.communication.InterfaceConfiguration;
import org.eclipse.mosaic.lib.objects.v2x.MessageRouting;
import org.eclipse.mosaic.lib.objects.v2x.V2xMessage;

import org.slf4j.Logger;
Expand Down Expand Up @@ -115,9 +116,7 @@ public Integer sendCam() {
log.warn("sendCAM: Ad hoc communication disabled (!adhocModule.isEnabled()).");
return null;
}

final MessageRouting routing = createMessageRouting().topoBroadCast();
return super.sendCam(routing);
return super.sendCam(createMessageRouting().topoBroadCast());
}

@Override
Expand All @@ -141,6 +140,10 @@ public void sendV2xMessage(V2xMessage msg) {
* @return the created builder for further configuration
*/
public AdHocMessageRoutingBuilder createMessageRouting() {
return new AdHocMessageRoutingBuilder(this.getOwner().getId(), this.getOwner().getPosition());
if (!(getOwner() instanceof Locatable)) {
throw new UnsupportedOperationException("Cannot send message from senders without a location.");
}
GeoPoint position = ((Locatable) getOwner()).getPosition();
return new AdHocMessageRoutingBuilder(getOwner().getId(), position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@

package org.eclipse.mosaic.fed.application.ambassador.simulation.communication;

import org.eclipse.mosaic.fed.application.app.api.os.OperatingSystem;
import org.eclipse.mosaic.fed.application.app.api.os.ServerOperatingSystem;
import org.eclipse.mosaic.fed.application.app.api.os.modules.Locatable;
import org.eclipse.mosaic.interactions.communication.CellularCommunicationConfiguration;
import org.eclipse.mosaic.lib.enums.DestinationType;
import org.eclipse.mosaic.lib.geo.GeoCircle;
import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.addressing.CellMessageRoutingBuilder;
import org.eclipse.mosaic.lib.objects.communication.CellConfiguration;
import org.eclipse.mosaic.lib.objects.v2x.MessageRouting;
import org.eclipse.mosaic.lib.objects.v2x.V2xMessage;

import org.slf4j.Logger;
Expand All @@ -40,7 +37,7 @@ public class CellModule extends AbstractCommunicationModule<CellModuleConfigurat
*/
private final static long DEFAULT_CAM_GEO_RADIUS = 300;

public CellModule(OperatingSystem owner, Logger log) {
public CellModule(CommunicationModuleOwner owner, Logger log) {
super(owner, log);
}

Expand Down Expand Up @@ -110,23 +107,44 @@ public Integer sendCam() {
log.warn("sendCAM: Cell communication disabled (!cellModule.isEnabled()).");
return null;
}

if (configuration == null || configuration.getCamConfiguration() == null) {
log.warn("sendCAM: No camConfiguration with addressingMode and geoRadius given.");
return null;
}

CellModuleConfiguration.CellCamConfiguration camConfiguration = configuration.getCamConfiguration();
final MessageRouting routing;
if (camConfiguration.getAddressingMode().equals(DestinationType.CELL_TOPOCAST)) {
routing = createMessageRouting().topoCast(camConfiguration.getTopocastReceiver());
} else {
final GeoCircle destination = new GeoCircle(owner.getPosition(), camConfiguration.getGeoRadius());
if (camConfiguration.getAddressingMode().equals(DestinationType.CELL_GEOCAST)) {
routing = createMessageRouting().geoBroadcastBasedOnUnicast(destination);
} else {
routing = createMessageRouting().geoBroadcastMbms(destination);
}
switch (camConfiguration.getAddressingMode()) {
case CELL_TOPOCAST:
return sendCamViaTopocast(camConfiguration);
case CELL_GEOCAST:
return sendCamViaGeoBroadcast(camConfiguration);
case CELL_GEOCAST_MBMS:
return sendCamViaGeoBroadcastMbms(camConfiguration);
default:
log.warn("sendCam: Unsupported addressing mode {}.", camConfiguration.getAddressingMode());
return null;
}
}

private Integer sendCamViaTopocast(CellModuleConfiguration.CellCamConfiguration camConfiguration) {
return super.sendCam(createMessageRouting().topoCast(camConfiguration.getTopocastReceiver()));
}

private Integer sendCamViaGeoBroadcast(CellModuleConfiguration.CellCamConfiguration camConfiguration) {
if (!(getOwner() instanceof Locatable)) {
throw new UnsupportedOperationException("Cannot send CAM for entities without a location.");
}
final GeoCircle destination = new GeoCircle(((Locatable) getOwner()).getPosition(), camConfiguration.getGeoRadius());
return super.sendCam(createMessageRouting().geoBroadcastBasedOnUnicast(destination));
}

private Integer sendCamViaGeoBroadcastMbms(CellModuleConfiguration.CellCamConfiguration camConfiguration) {
if (!(getOwner() instanceof Locatable)) {
throw new UnsupportedOperationException("Cannot send CAM for entities without a location.");
}
return super.sendCam(routing);
final GeoCircle destination = new GeoCircle(((Locatable) getOwner()).getPosition(), camConfiguration.getGeoRadius());
return super.sendCam(createMessageRouting().geoBroadcastMbms(destination));
}

/**
Expand Down Expand Up @@ -155,7 +173,9 @@ public void sendV2xMessage(V2xMessage msg) {
* @return the created builder for further configuration
*/
public CellMessageRoutingBuilder createMessageRouting() {
GeoPoint position = getOwner() instanceof ServerOperatingSystem ? null : getOwner().getPosition();
GeoPoint position = getOwner() instanceof Locatable
? ((Locatable) getOwner()).getPosition()
: null;
return new CellMessageRoutingBuilder(getOwner().getId(), position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.eclipse.mosaic.fed.application.ambassador.simulation.communication;

import org.eclipse.mosaic.interactions.communication.V2xMessageTransmission;
import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.v2x.MessageRouting;
import org.eclipse.mosaic.lib.objects.v2x.etsi.Cam;
import org.eclipse.mosaic.rti.api.Interaction;
Expand All @@ -29,13 +28,6 @@ public interface CommunicationModuleOwner {

String getId();

/**
* Returns the current position as a {@link GeoPoint}.
*
* @return the current position.
*/
GeoPoint getPosition();

long getSimulationTime();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Contact: [email protected]
*/

package org.eclipse.mosaic.fed.application.ambassador.navigation;
package org.eclipse.mosaic.fed.application.ambassador.simulation.navigation;

import org.eclipse.mosaic.fed.application.ambassador.ApplicationAmbassador;
import org.eclipse.mosaic.fed.application.ambassador.SimulationKernel;
Expand Down
Loading

0 comments on commit eb5db43

Please sign in to comment.