From 26fb493b990f042776bceffabdc9900b3137ba31 Mon Sep 17 00:00:00 2001 From: Benjamin Becker Date: Tue, 30 Nov 2021 13:07:05 +0100 Subject: [PATCH] loop prevention --- .../linklayer/mac/MacEventInformation.java | 6 ++- .../mac/DefaultMacEventInformation.java | 13 +++++ .../linklayer/mac/wifi/Ieee80211AdHocMac.java | 11 ++-- .../impl/topology/views/RangedLink.java | 24 ++++++--- .../topology/views/RangedTopologyView.java | 6 +-- .../topology/views/wifi/WifiTopologyView.java | 21 +++++++- ...ropagationLossModelNormalDistribution.java | 53 +++++++++++++++---- 7 files changed, 105 insertions(+), 29 deletions(-) diff --git a/src/de/tud/kom/p2psim/api/linklayer/mac/MacEventInformation.java b/src/de/tud/kom/p2psim/api/linklayer/mac/MacEventInformation.java index a703ff14..0a001eb4 100644 --- a/src/de/tud/kom/p2psim/api/linklayer/mac/MacEventInformation.java +++ b/src/de/tud/kom/p2psim/api/linklayer/mac/MacEventInformation.java @@ -67,7 +67,9 @@ public interface MacEventInformation { * @return */ public long getTimeInQueue(); - + + public long getStartTime(); + /** * Beware, this might be called multiple times if this is a broadcast! It * will also be called if the LinkLayer-Message was dropped - in this case, @@ -82,4 +84,6 @@ public interface MacEventInformation { */ public void arrivedAt(MacLayer receiver, boolean wasDropped); + void setStartTime(long starttime); + } diff --git a/src/de/tud/kom/p2psim/impl/linklayer/mac/DefaultMacEventInformation.java b/src/de/tud/kom/p2psim/impl/linklayer/mac/DefaultMacEventInformation.java index adaa2554..f50afef2 100644 --- a/src/de/tud/kom/p2psim/impl/linklayer/mac/DefaultMacEventInformation.java +++ b/src/de/tud/kom/p2psim/impl/linklayer/mac/DefaultMacEventInformation.java @@ -45,6 +45,8 @@ public class DefaultMacEventInformation implements MacEventInformation { private MacAddress receiver; private long timeInQueue; + + private long starttime; public DefaultMacEventInformation(Message msg, MacAddress sender, MacAddress receiver, long timeInQueue) { @@ -85,4 +87,15 @@ public class DefaultMacEventInformation implements MacEventInformation { return timeInQueue; } + @Override + public long getStartTime() { + // TODO Auto-generated method stub + return starttime; + } + + @Override + public void setStartTime(long starttime) { + this.starttime=starttime; + } + } diff --git a/src/de/tud/kom/p2psim/impl/linklayer/mac/wifi/Ieee80211AdHocMac.java b/src/de/tud/kom/p2psim/impl/linklayer/mac/wifi/Ieee80211AdHocMac.java index ccae53d8..1784a3ed 100644 --- a/src/de/tud/kom/p2psim/impl/linklayer/mac/wifi/Ieee80211AdHocMac.java +++ b/src/de/tud/kom/p2psim/impl/linklayer/mac/wifi/Ieee80211AdHocMac.java @@ -315,6 +315,8 @@ public class Ieee80211AdHocMac extends AbstractMacLayer { WifiMacEventInformation eventInfo = new WifiMacEventInformation( msg, this.getMacAddress(), toSend.getReceiver(), Time.getCurrentTime() - toSend.getTimeEntered()); + + eventInfo.setStartTime(Time.getCurrentTime() - eventInfo.getTimeInQueue()); if (msg.getSize() >= MAX_FRAME_SIZE) { Monitor.log( @@ -354,6 +356,7 @@ public class Ieee80211AdHocMac extends AbstractMacLayer { * information to the message. */ private void tryToGetSendSlot(MacEventInformation eventInfo) { + dcfManager.resetBackoffTimer(); dcfManager.startBackoffTimer(); long tryTime = dcfManager.getBackoffTimeEnd(); @@ -665,7 +668,6 @@ public class Ieee80211AdHocMac extends AbstractMacLayer { messageDropped(DropReason.NO_LINK, eventInfo.getMessage()); sendNextMessage(); } - } /** @@ -747,7 +749,7 @@ public class Ieee80211AdHocMac extends AbstractMacLayer { getTxPowerDdm(), eventInfo.getMessage(), dataMode, preamble, this.getHost(), getMacAddress()); getEnergyComponent().send(duration, eventInfo.getMessage(), true); - this.successfulTransmitted(eventInfo); + this.successfulTransmitted(eventInfo,0); _linkMsgEvent(eventInfo.getMessage(), getHost(), Reason.SEND); @@ -802,7 +804,7 @@ public class Ieee80211AdHocMac extends AbstractMacLayer { (LinkLayerMessage) eventInfo.getMessage(), getPhyType(), eventInfo.getSender(), eventInfo.isBroadcast())); - senderMac.successfulTransmitted(eventInfo); + senderMac.successfulTransmitted(eventInfo, Time.getCurrentTime() - eventInfo.getStartTime()); // inform rateManager about the snr of the received packet double snr = rateManager.calculateActuallySNR( @@ -882,7 +884,7 @@ public class Ieee80211AdHocMac extends AbstractMacLayer { * The message which is successfully transmitted with all meta * information. */ - protected void successfulTransmitted(MacEventInformation eventInfo) { + protected void successfulTransmitted(MacEventInformation eventInfo, long time) { // for progress display if (eventInfo.isBroadcast() && ackCache.containsKey(eventInfo)) { _wifiBroadcastRcvd++; @@ -890,6 +892,7 @@ public class Ieee80211AdHocMac extends AbstractMacLayer { } if (!eventInfo.isBroadcast() && !ackCache.containsKey(eventInfo)) { _wifiUnicastRcvd++; + //System.out.println(time); } // reset the CW, because the message was successful transmitted diff --git a/src/de/tud/kom/p2psim/impl/topology/views/RangedLink.java b/src/de/tud/kom/p2psim/impl/topology/views/RangedLink.java index 59a8945a..b132e4c9 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/RangedLink.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/RangedLink.java @@ -21,9 +21,10 @@ package de.tud.kom.p2psim.impl.topology.views; import de.tud.kom.p2psim.api.linklayer.mac.MacAddress; +import de.tud.kom.p2psim.impl.topology.views.wifi.WifiTopologyView; +import de.tud.kom.p2psim.impl.topology.views.wifi.phy.InterferenceHelper; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; - /** * A Link that sets isConnected() and some other parameters based on the current * positions of source and destination. It supports obstacles in that a link is @@ -34,12 +35,14 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; */ public class RangedLink extends DefaultLink { - private double currentDistance = 0; - + private Location sourceLocation; + private Location destLocation; + WifiTopologyView wifiTopologyView; + /** * * @param source @@ -51,18 +54,20 @@ public class RangedLink extends DefaultLink { * @param mtu * @param maxDistance */ - public RangedLink(MacAddress source, MacAddress destination, Location sourceLocation, Location destLocation, - boolean isConnected, double dropProbability, long bandwidth, - long latency, int mtu) { + public RangedLink(MacAddress source, MacAddress destination, + Location sourceLocation, Location destLocation, boolean isConnected, + double dropProbability, long bandwidth, long latency, int mtu, + WifiTopologyView wifiTopologyView) { super(source, destination, isConnected, dropProbability, bandwidth, latency, mtu); this.setSourceLocation(sourceLocation); this.setDestLocation(destLocation); + this.wifiTopologyView = wifiTopologyView; } /** * Update the distance between source and destination after movement - * occurred. + * occurred. * * @param distance */ @@ -71,6 +76,11 @@ public class RangedLink extends DefaultLink { setConnected(connected); } + @Override + public boolean isConnected() { + return wifiTopologyView.inSendRange(sourceLocation, destLocation); + } + @Override public String toString() { return super.toString() + " distance: " + currentDistance; diff --git a/src/de/tud/kom/p2psim/impl/topology/views/RangedTopologyView.java b/src/de/tud/kom/p2psim/impl/topology/views/RangedTopologyView.java index bab0c2ba..fce43118 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/RangedTopologyView.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/RangedTopologyView.java @@ -71,7 +71,7 @@ public abstract class RangedTopologyView extends AbstractTopologyView linkList = new ArrayList(); + protected List linkList = new ArrayList(); /** * These are used for the GlobalKnowledge-Functions @@ -121,8 +121,6 @@ public abstract class RangedTopologyView extends AbstractTopologyView getCachedCSNeighbors(MacAddress source) { // updates the cachedCSNeighbors, if it is outdated + updateNeighborhood(source); getNeighbors(source); return cachedCSNeighbors.get(source); } @@ -202,12 +203,28 @@ public class WifiTopologyView extends RangedTopologyView { protected boolean inCsRange(Location sender, Location receiver) { return interferenceHelper.inRange(sender, receiver, maxTxPowerDbm, csDbm); } - + @Override + protected RangedLink createLink(MacAddress source, MacAddress destination) { + Location p1,p2; + + p1 = this.getPosition(source); + p2 = this.getPosition(destination); + + RangedLink link = new RangedLink(source, destination,p1,p2, true, + determineLinkDropProbability(source, destination), + determineLinkBandwidth(source, destination), + determineLinkLatency(source, destination), getPhyType() + .getDefaultMTU(), this); + synchronized (linkList) { + linkList.add(link); + } + return link; + } protected boolean inSatRange(Location sender, Location receiver) { return interferenceHelper.inRange(sender, receiver, maxTxPowerDbm, satDbm); } - protected boolean inSendRange(Location sender, Location receiver) { + public boolean inSendRange(Location sender, Location receiver) { return interferenceHelper.inRange(sender, receiver, maxTxPowerDbm, rxSensitivityDbm); } diff --git a/src/de/tud/kom/p2psim/impl/topology/views/wifi/phy/propagation/loss/LogDistancePropagationLossModelNormalDistribution.java b/src/de/tud/kom/p2psim/impl/topology/views/wifi/phy/propagation/loss/LogDistancePropagationLossModelNormalDistribution.java index 6858816a..2e80e534 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/wifi/phy/propagation/loss/LogDistancePropagationLossModelNormalDistribution.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/wifi/phy/propagation/loss/LogDistancePropagationLossModelNormalDistribution.java @@ -25,6 +25,7 @@ import java.util.Random; import de.tud.kom.p2psim.api.topology.views.wifi.phy.PropagationLossModel; import de.tudarmstadt.maki.simonstrator.api.Randoms; +import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; /** @@ -82,34 +83,64 @@ public class LogDistancePropagationLossModelNormalDistribution * Math.log10(4 * Math.PI * referenceDistance / lambda); private HashMap> pathLosses = new HashMap<>(); - + private HashMap pathLosses0 = new HashMap<>(); + + long lastSave = -1; @Override public double getRxPowerDbm(double txPowerDbm, Location a, Location b) { double distance = a.distanceTo(b); + + if (distance <= referenceDistance) { return txPowerDbm; } - double pathLoss; double rxc; + if (Time.getCurrentTime() / Time.SECOND > lastSave) { + pathLosses = new HashMap<>(); + lastSave = Time.getCurrentTime() / Time.SECOND; + } + HashMap pathlossesA; if (!pathLosses.containsKey(a)) { - HashMap pathlossesA = new HashMap<>(); + pathlossesA = new HashMap<>(); pathLosses.put(a, pathlossesA); + }else { + pathlossesA = pathLosses.get(a); } - - HashMap pathlossesA = pathLosses.get(a); if (pathlossesA.containsKey(b)) { rxc = pathlossesA.get(b); } else { - double x = Double.hashCode(Double.hashCode(a.getLatitudeOrY())/4. + Double.hashCode(b.getLatitudeOrY())/4. - + Double.hashCode(a.getLongitudeOrX())/4. + Double.hashCode(b.getLongitudeOrX())/4.); - Random r = new Random((long) x); + double pathLoss0; + if (pathLosses0.containsKey(distance)) { + pathLoss0 = pathLosses0.get(distance); + }else { + pathLoss0 = 10 * exponent * Math.log10(distance / referenceDistance); + pathLosses0.put(distance, pathLoss0); + } + + double x = Double.hashCode(Double.hashCode(a.getLatitudeOrY()) / 4. + + Double.hashCode(b.getLatitudeOrY()) / 4. + + Double.hashCode(a.getLongitudeOrX()) / 4. + + Double.hashCode(b.getLongitudeOrX()) / 4.); + long y = Time.getCurrentTime() / Time.SECOND; + Random r1 = new Random(y); + Random r = new Random((long) x + r1.nextLong()); + double gaussian = r.nextGaussian(); - double sigma = 8.0; - pathLoss = 10 * exponent * Math.log10(distance / referenceDistance) + gaussian*sigma; - rxc = - this.referenceLoss - pathLoss; + double sigma = 6.0; + + // 58:722.0,456.0 + // 1:803.0,599.0 +// if (a.getLatitudeOrY() == 456.0 && a.getLongitudeOrX() == 722.0) { +// if (b.getLatitudeOrY() == 599.0 && b.getLongitudeOrX() == 803.0) { +// System.out.println(Time.getFormattedTime() + ": " + gaussian); +// } +// } + + double pathLoss = pathLoss0 + gaussian * sigma; + rxc = -this.referenceLoss - pathLoss; pathlossesA.put(b, rxc); } return txPowerDbm + rxc; -- GitLab