Skip to content

Commit

Permalink
fix: Added Inet4Address destination option, validated values, removed…
Browse files Browse the repository at this point in the history
… reset
  • Loading branch information
FunKuchen committed Nov 19, 2024
1 parent ba03a1b commit 5a39ff1
Showing 1 changed file with 13 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import org.eclipse.mosaic.lib.objects.v2x.MessageRouting;
import org.eclipse.mosaic.lib.objects.v2x.MessageStreamRouting;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.Validate;

import java.net.Inet4Address;

Expand All @@ -33,8 +32,6 @@
*/
public class CellMessageRoutingBuilder {

private static final Logger log = LoggerFactory.getLogger(CellMessageRoutingBuilder.class);

private final SourceAddressContainer sourceAddressContainer;

private long streamDuration = -1;
Expand Down Expand Up @@ -83,14 +80,9 @@ public MessageRouting build() {

private MessageRouting build(DestinationAddressContainer dac) {
if (streamDuration < 0) {
MessageRouting messageRouting = new MessageRouting(dac, sourceAddressContainer);
resetValues();
return messageRouting;
return new MessageRouting(dac, sourceAddressContainer);
} else {
MessageStreamRouting messageStreamRouting =
new MessageStreamRouting(dac, sourceAddressContainer, streamDuration, streamBandwidthInBitPs);
resetValues();
return messageStreamRouting;
return new MessageStreamRouting(dac, sourceAddressContainer, streamDuration, streamBandwidthInBitPs);
}
}

Expand All @@ -113,7 +105,7 @@ public CellMessageRoutingBuilder streaming(long streamDuration, long streamBandw
* @return the {@link CellMessageRoutingBuilder}
*/
public CellMessageRoutingBuilder protocol(ProtocolType type) {
assert !protocolChanged : "Protocol was already set! Using first setting.";
Validate.isTrue(!protocolChanged, "Protocol was already set!");
protocolType = type;
protocolChanged = true;
return this;
Expand All @@ -139,7 +131,7 @@ public CellMessageRoutingBuilder udp() {
}

public CellMessageRoutingBuilder destination(NetworkAddress networkAddress) {
assert !destinationChanged : "Destination was already set! Using first setting.";
Validate.isTrue(!destinationChanged, "Destination was already set!");
this.destination = networkAddress;
this.destinationChanged = true;
return this;
Expand All @@ -149,6 +141,10 @@ public CellMessageRoutingBuilder destination(String receiverName) {
return destination(IpResolver.getSingleton().nameToIp(receiverName).getAddress());
}

public CellMessageRoutingBuilder destination(Inet4Address ipAddress) {
return destination(new NetworkAddress(ipAddress));
}

public CellMessageRoutingBuilder destination(byte[] ipv4Address) {
return destination(new NetworkAddress(ipv4Address));
}
Expand All @@ -158,22 +154,22 @@ public CellMessageRoutingBuilder broadcast() {
}

public CellMessageRoutingBuilder mbs() {
assert !mbsChanged : "MBS was already chosen!";
Validate.isTrue(!mbsChanged, "MBS was already chosen!");
routing = DestinationType.CELL_GEOCAST_MBS;
mbsChanged = true;
return this;
}

public CellMessageRoutingBuilder topological() {
assert !routingChanged : "Routing was already set! Using first setting.";
assert !mbsChanged : "MBS can not be enabled for topological routing!";
Validate.isTrue(!routingChanged, "Routing was already set!");
Validate.isTrue(!mbsChanged, "MBS can not be enabled for topological routing!");
routing = DestinationType.CELL_TOPOCAST;
routingChanged = true;
return this;
}

public CellMessageRoutingBuilder geographical(GeoArea area) {
assert !routingChanged : "Routing was already set! Using first setting.";
Validate.isTrue(!routingChanged, "Routing was already set!");
if (!mbsChanged) {
routing = DestinationType.CELL_GEOCAST;
}
Expand All @@ -198,19 +194,4 @@ private void checkRouting() {
throw new IllegalArgumentException("No routing protocol was given! Aborting.");
}
}

private void resetValues() {
this.streamDuration = -1;
this.streamBandwidthInBitPs = -1;

this.destination = null;
this.routing = null;
this.targetArea = null;
this.protocolType = null;

this.destinationChanged = false;
this.routingChanged = false;
this.mbsChanged = false;
this.protocolChanged = false;
}
}

0 comments on commit 5a39ff1

Please sign in to comment.