Skip to content

Commit

Permalink
feat: refactor AdHocMessageRoutingBuilder (#433)
Browse files Browse the repository at this point in the history
* fix(workshop): Enabled color changing of externally added vehicles in SUMO
* feat: Refactored AdHoc message routing
* feat: Added hops argument for builder
  • Loading branch information
FunKuchen authored Nov 19, 2024
1 parent fddfe99 commit 4a4a335
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ private void detectEmergencyBrake() {

// Prepare the DENMessage
MessageRouting routing =
getOs().getAdHocModule().createMessageRouting().viaChannel(AdHocChannel.CCH).topoBroadCast();
getOs().getAdHocModule().createMessageRouting()
.channel(AdHocChannel.CCH)
.singlehop()
.broadcast()
.topological()
.build();
Denm denm = new Denm(routing, new DenmContent(getOs().getSimulationTime(), vehicleLongLat, roadId,
SensorType.SPEED, 1, curSpeed, curDeceleration * 9.81f, null,
null, null), 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public class RoadSideUnitApp extends AbstractApplication<RoadSideUnitOperatingSy

private void sendAdHocBroadcast() {
final MessageRouting routing =
getOs().getAdHocModule().createMessageRouting().viaChannel(AdHocChannel.CCH).topoBroadCast();
getOs().getAdHocModule().createMessageRouting()
.channel(AdHocChannel.CCH)
.singlehop()
.broadcast()
.topological()
.build();
final InterVehicleMsg message = new InterVehicleMsg(routing, getOs().getPosition());
getOs().getAdHocModule().sendV2xMessage(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
public final class VehicleToTrafficLightApp extends AbstractApplication<VehicleOperatingSystem> {
private final static long TIME_INTERVAL = TIME.SECOND;

//Use TopoBroadcast instead of GeoBroadcast because latter is not compatible with OMNeT++ or ns-3
//Use topologically-scoped broadcast instead of geologically-scoped broadcast because latter is not compatible with OMNeT++ or ns-3
private void sendTopoBroadcastMessage() {
final MessageRouting routing = getOperatingSystem()
.getAdHocModule()
.createMessageRouting()
.topoBroadCast();
final MessageRouting routing = getOperatingSystem().getAdHocModule().createMessageRouting()
.singlehop()
.broadcast()
.topological()
.build();
getOs().getAdHocModule().sendV2xMessage(new GreenWaveMsg(routing, TrafficLightApp.SECRET));
getLog().infoSimTime(this, "Sent secret passphrase");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void reactOnEnvironmentData(SensorType type, int strength) {
if (useCellNetwork()) {
mr = getOs().getCellModule().createMessageRouting().topoCast("server_0");
} else {
mr = getOs().getAdHocModule().createMessageRouting().geoBroadCast(dest);
mr = getOs().getAdHocModule().createMessageRouting().broadcast().geographical(dest).build();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.mosaic.fed.application.app.api.os.VehicleOperatingSystem;
import org.eclipse.mosaic.fed.application.app.api.perception.BasicSensorModule;
import org.eclipse.mosaic.lib.enums.SensorType;
import org.eclipse.mosaic.lib.geo.GeoArea;
import org.eclipse.mosaic.lib.objects.addressing.AdHocMessageRoutingBuilder;
import org.eclipse.mosaic.lib.objects.addressing.SourceAddressContainer;
import org.eclipse.mosaic.lib.objects.road.IConnection;
Expand Down Expand Up @@ -129,7 +130,9 @@ private void setupMessageRouting() {
AdHocMessageRoutingBuilder adHocMessageRoutingBuilderMock = mock(AdHocMessageRoutingBuilder.class);
when(adHocModuleMock.createMessageRouting()).thenReturn(adHocMessageRoutingBuilderMock);
MessageRouting messageRoutingMock = mock(MessageRouting.class);
when(adHocMessageRoutingBuilderMock.geoBroadCast(any())).thenReturn(messageRoutingMock);
when(adHocMessageRoutingBuilderMock.broadcast()).thenReturn(adHocMessageRoutingBuilderMock);
when(adHocMessageRoutingBuilderMock.geographical(any(GeoArea.class))).thenReturn(adHocMessageRoutingBuilderMock);
when(adHocMessageRoutingBuilderMock.build()).thenReturn(messageRoutingMock);
}

private void setupVehiclePosition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public Integer sendCam() {
log.warn("sendCAM: Ad hoc communication disabled (!adhocModule.isEnabled()).");
return null;
}
return super.sendCam(createMessageRouting().topoBroadCast());
return super.sendCam(createMessageRouting().singlehop().broadcast().topological().build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void testStartEvent_cellRouting() {
@Test
public void testStartEvent_adhocRouting() {
//SETUP
routing.set(new AdHocMessageRoutingBuilder("veh_0", null).topoBroadCast());
routing.set(new AdHocMessageRoutingBuilder("veh_0", null).singlehop().broadcast().topological().build());

V2xMessageTransmission sendV2xMsg = new V2xMessageTransmission(12 * TIME.SECOND, v2XMessage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void setUp() {
// ======================================================

AdHocMessageRoutingBuilder adHocMessageRoutingBuilder = new AdHocMessageRoutingBuilder("veh_0", null);
MessageRouting messageRouting = adHocMessageRoutingBuilder.viaChannel(AdHocChannel.CCH).topoBroadCast();
MessageRouting messageRouting = adHocMessageRoutingBuilder.channel(AdHocChannel.CCH).singlehop().broadcast().topological().build();

V2xMessage em = new V2xMessage.Empty(messageRouting);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ public void topoBroadcast_differentSendingRadiusPerVehicle() throws InternalFede

//RUN + ASSERT
AdHocMessageRoutingBuilder adHocMessageRoutingBuilder = new AdHocMessageRoutingBuilder("veh_0", vehToPosition.get("veh_0"));
MessageRouting routing1 = adHocMessageRoutingBuilder.viaChannel(AdHocChannel.CCH).topoBroadCast();
MessageRouting routing1 = adHocMessageRoutingBuilder.channel(AdHocChannel.CCH).singlehop().broadcast().topological().build();
sendMessage(routing1);
assertReceivedMessages("veh_1");

adHocMessageRoutingBuilder = new AdHocMessageRoutingBuilder("veh_1", vehToPosition.get("veh_1"));
MessageRouting routing2 = adHocMessageRoutingBuilder.viaChannel(AdHocChannel.CCH).topoBroadCast();
MessageRouting routing2 = adHocMessageRoutingBuilder.channel(AdHocChannel.CCH).singlehop().broadcast().topological().build();
sendMessage(routing2);
assertReceivedMessages("veh_0", "veh_2");

adHocMessageRoutingBuilder = new AdHocMessageRoutingBuilder("veh_2", vehToPosition.get("veh_2"));
MessageRouting routing3 = adHocMessageRoutingBuilder.viaChannel(AdHocChannel.CCH).topoBroadCast();
MessageRouting routing3 = adHocMessageRoutingBuilder.channel(AdHocChannel.CCH).singlehop().broadcast().topological().build();

sendMessage(routing3);
assertReceivedMessages();
Expand All @@ -168,8 +168,10 @@ public void geoBroadcast_vehiclesInRowWithCustomRadius() throws InternalFederate
// RUN + ASSERT
AdHocMessageRoutingBuilder adHocMessageRoutingBuilder = new AdHocMessageRoutingBuilder("veh_0", vehToPosition.get("veh_0"));
MessageRouting routing1 = adHocMessageRoutingBuilder
.viaChannel(AdHocChannel.CCH)
.geoBroadCast(new GeoCircle(vehToPosition.get("veh_2"), 300));
.channel(AdHocChannel.CCH)
.broadcast()
.geographical(new GeoCircle(vehToPosition.get("veh_2"), 300))
.build();
sendMessage(routing1);
assertReceivedMessages("veh_1", "veh_2");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ private void receiveInteraction(VehicleSensorActivation vehicleSensorActivation)
*/
private void receiveInteraction(VehicleParametersChange vehicleParametersChange) throws InternalFederateException {
if (externalVehicles.containsKey(vehicleParametersChange.getVehicleId())) {
changeExternalParameters(vehicleParametersChange);
return;
}

Expand Down Expand Up @@ -1283,6 +1284,17 @@ private void removeExternalVehiclesFromUpdates(VehicleUpdates updates) {
updates.getRemovedNames().removeIf(vehicle -> externalVehicles.remove(vehicle) != null);
}

public void changeExternalParameters(VehicleParametersChange vehicleParametersChange) throws InternalFederateException {
final String veh_id = vehicleParametersChange.getVehicleId();
for (final VehicleParameter param : vehicleParametersChange.getVehicleParameters()) {
// Only color is supported as a parameter for external vehicles so far.
if (param.getParameterType() == VehicleParameter.VehicleParameterType.COLOR) {
final Color color = param.getValue();
bridge.getVehicleControl().setColor(veh_id, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}
}
}

/**
* This handles the case that sumo handles routing and creates new routes while doing so.
*
Expand Down
Loading

0 comments on commit 4a4a335

Please sign in to comment.