Skip to content

Commit

Permalink
feat: refactored CellMessageRoutingBuilder (#437)
Browse files Browse the repository at this point in the history
* fix: Added comments for CellMessageRoutingBuilder and fixed AdHocMessageRoutingBuilder
  • Loading branch information
FunKuchen authored Nov 20, 2024
1 parent bec61b5 commit 1c94711
Show file tree
Hide file tree
Showing 16 changed files with 299 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import org.eclipse.mosaic.fed.application.app.api.CommunicationApplication;
import org.eclipse.mosaic.fed.application.app.api.os.ServerOperatingSystem;
import org.eclipse.mosaic.interactions.communication.V2xMessageTransmission;
import org.eclipse.mosaic.lib.enums.SensorType;
import org.eclipse.mosaic.lib.geo.GeoCircle;
import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.v2x.MessageRouting;
import org.eclipse.mosaic.lib.objects.v2x.V2xMessage;
import org.eclipse.mosaic.lib.objects.v2x.etsi.Denm;
Expand Down Expand Up @@ -110,7 +108,7 @@ private void sample() {
*/
private Denm constructDenm() {
final GeoCircle geoCircle = new GeoCircle(lastReceivedMessage.getEventLocation(), 3000.0D);
final MessageRouting routing = getOs().getCellModule().createMessageRouting().geoBroadcastBasedOnUnicast(geoCircle);
final MessageRouting routing = getOs().getCellModule().createMessageRouting().broadcast().geographical(geoCircle).build();
return new Denm(routing,
new DenmContent(
lastReceivedMessage.getTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void reactOnEnvironmentData(SensorType type, int strength) {
* with a builder and build a geoBroadCast for the circle area defined in dest.
*/
if (useCellNetwork()) {
mr = getOs().getCellModule().createMessageRouting().topoCast("server_0");
mr = getOs().getCellModule().createMessageRouting().destination("server_0").topological().build();
} else {
mr = getOs().getAdHocModule().createMessageRouting().broadcast().geographical(dest).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,23 @@ public Integer sendCam() {
}

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

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

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ public void addEvent(@Nonnull Event event) {
@Test
public void testStartEvent_cellRouting() {
//SETUP
routing.set(new CellMessageRoutingBuilder("veh_0", null).topoCast(new byte[]{1, 2, 3, 4}));
routing.set(new CellMessageRoutingBuilder("veh_0", null)
.destination(new byte[]{1, 2, 3, 4})
.topological()
.build());

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

Expand All @@ -127,7 +130,7 @@ public void testStartEvent_cellRouting() {
@Test
public void testStartEvent_adhocRouting() {
//SETUP
routing.set(new AdHocMessageRoutingBuilder("veh_0", null).singlehop().broadcast().topological().build());
routing.set(new AdHocMessageRoutingBuilder("veh_0", null).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 @@ -172,8 +172,7 @@ public void testProcessMessage_regularMessageMulticast() throws Exception {
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
final Multimap<CNetworkProperties, String> receiverMap = ArrayListMultimap.create();
Expand Down Expand Up @@ -211,8 +210,7 @@ public void testProcessMessage_regularMessageMulticast_NodeLimited() throws Exce
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
final Multimap<CNetworkProperties, String> receiverMap = ArrayListMultimap.create();
Expand Down Expand Up @@ -252,7 +250,7 @@ public void testProcessMessage_regularMessageMulticast_NodeLimitedRegionLimited(
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4})
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
final Multimap<CNetworkProperties, String> receiverMap = ArrayListMultimap.create();
Expand Down Expand Up @@ -289,8 +287,7 @@ public void testProcessMessage_regularMessageMulticast_MultipleRegions() throws
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
final Multimap<CNetworkProperties, String> receiverMap = ArrayListMultimap.create();
Expand Down Expand Up @@ -353,9 +350,8 @@ public void testProcessMessage_regularMessageNodeLimited() throws Exception {
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
))
;
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
String receiverName = "veh_0";
Event event = createEvent(receiverName, sampleV2XMessage);
Expand All @@ -381,8 +377,7 @@ public void testProcessMessage_regularMessageNodeLimitedRegionLessLimited() thro
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
String receiverName = "veh_0";
Expand Down Expand Up @@ -411,8 +406,7 @@ public void testProcessMessage_regularMessageNodeLimitedRegionMoreLimited() thro
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
String receiverName = "veh_0";
Expand Down Expand Up @@ -441,8 +435,7 @@ public void testProcessMessage_regularMessageNodeUnlimited_plusFreeBandwidth() t
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
String receiverName = "veh_0";
Expand Down Expand Up @@ -485,8 +478,7 @@ public void testProcessMessage_regularMessageNodeUnlimitedRegionLimited() throws
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
String receiverName = "veh_0";
Expand All @@ -513,7 +505,7 @@ public void testProcessMessage_TransmissionAfterPacketLossTcp() throws Exception
new CellMessageRoutingBuilder("veh_0", null)
.protocol(ProtocolType.TCP)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4})
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);

SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
Expand Down Expand Up @@ -551,8 +543,7 @@ public void testProcessMessage_packetLossUdp() throws Exception {
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);

SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
Expand Down Expand Up @@ -589,8 +580,7 @@ public void testProcessMessage_nodeCapacityExceededRegionUnlimited() throws Exce
new CellMessageRoutingBuilder("veh_0", null)
.protocol(ProtocolType.TCP)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
String receiverName = "veh_0";
Expand Down Expand Up @@ -622,8 +612,7 @@ public void testProcessMessage_nodeCapacityExceededRegionLimited() throws Except
new CellMessageRoutingBuilder("veh_0", null)
.protocol(ProtocolType.TCP)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
String receiverName = "veh_0";
Expand Down Expand Up @@ -657,8 +646,7 @@ public void testProcessMessage_channelCapacityExceededTcp() throws Exception {
new CellMessageRoutingBuilder("veh_0", null)
.protocol(ProtocolType.TCP)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
String receiverName = "veh_0";
Expand Down Expand Up @@ -689,8 +677,7 @@ public void testProcessMessage_channelNodeCapacityExceeded() throws Exception {
new CellMessageRoutingBuilder("veh_0", null)
.protocol(ProtocolType.TCP)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
String receiverName = "veh_0";
Expand Down Expand Up @@ -724,8 +711,7 @@ public void testProcessMessage_nodeDeactivatedTcp() throws Exception {
new CellMessageRoutingBuilder("veh_0", null)
.protocol(ProtocolType.TCP)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
String receiverName = "veh_0";
Expand Down Expand Up @@ -756,8 +742,7 @@ public void testProcessMessage_nodeDeactivatedUdp() throws Exception {
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), 5);
String receiverName = "veh_0";
Expand All @@ -782,8 +767,7 @@ public void testProcessMessage_nodeNotRegisteredTcp() throws Exception {
new CellMessageRoutingBuilder("veh_0", null)
.protocol(ProtocolType.TCP)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), 5);
Event event = createEvent("rsu_4", sampleV2XMessage);
Expand All @@ -809,8 +793,7 @@ public void testProcessMessage_nodeNotRegisteredUdp() throws Exception {
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
Event event = createEvent("rsu_4", sampleV2XMessage);
Expand All @@ -835,8 +818,7 @@ public void testFreeBandwidth_regularMessage() throws Exception {
routing.set(
new CellMessageRoutingBuilder("veh_0", null)
.streaming(EVENT_DURATION, EVENT_BANDWIDTH)
.topoCast(new byte[]{1, 2, 3, 4}
)
.destination(new byte[]{1, 2, 3, 4}).topological().build()
);
SampleV2xMessage sampleV2XMessage = new SampleV2xMessage(routing.get(), MESSAGE_SIZE);
StreamResult streamResult =
Expand Down
Loading

0 comments on commit 1c94711

Please sign in to comment.