Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/routing/ActiveRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ public abstract class ActiveRouter extends MessageRouter {
* If set to true and final recipient of a message rejects it because it
* already has it, the message is deleted from buffer. Default=false. */
public static final String DELETE_DELIVERED_S = "deleteDelivered";
/** Concurrent transmissions -setting id ({@value}). Boolean valued.
* If set to true, multiple outgoing connections can be used concurrently.
* Default=false. */
public static final String CONCURRENT_TRANS_S = "concurrentTransmissions";
/** should messages that final recipient marks as delivered be deleted
* from message buffer */
protected boolean deleteDelivered;

protected boolean concurrentTransmissions;

/** prefix of all response message IDs */
public static final String RESPONSE_PREFIX = "R_";
/** how often TTL check (discarding old messages) is performed */
Expand All @@ -60,6 +66,7 @@ public ActiveRouter(Settings s) {
this.policy = new MessageTransferAcceptPolicy(s);

this.deleteDelivered = s.getBoolean(DELETE_DELIVERED_S, false);
this.concurrentTransmissions = s.getBoolean(CONCURRENT_TRANS_S, false);

if (s.contains(EnergyModel.INIT_ENERGY_S)) {
this.energy = new EnergyModel(s);
Expand All @@ -75,6 +82,7 @@ public ActiveRouter(Settings s) {
protected ActiveRouter(ActiveRouter r) {
super(r);
this.deleteDelivered = r.deleteDelivered;
this.concurrentTransmissions = r.concurrentTransmissions;
this.policy = r.policy;
this.energy = (r.energy != null ? r.energy.replicate() : null);
}
Expand Down Expand Up @@ -205,6 +213,9 @@ else if (deleteDelivered && retVal == DENIED_OLD &&
* @return True if router can start transfer, false if not
*/
protected boolean canStartTransfer() {
if (this.isTransferring() && !concurrentTransmissions) {
return false;
}
if (this.getNrofMessages() == 0) {
return false;
}
Expand Down Expand Up @@ -407,7 +418,7 @@ protected Message tryAllMessages(Connection con, List<Message> messages) {
if (retVal == RCV_OK) {
return m; // accepted a message, don't try others
}
else if (retVal > 0) {
else if (retVal > 0 && !concurrentTransmissions) {
return null; // should try later -> don't bother trying others
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/routing/DirectDeliveryRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected DirectDeliveryRouter(DirectDeliveryRouter r) {
@Override
public void update() {
super.update();
if (isTransferring() || !canStartTransfer()) {
if (!canStartTransfer()) {
return; // can't start a new transfer
}

Expand Down
2 changes: 1 addition & 1 deletion src/routing/EpidemicRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected EpidemicRouter(EpidemicRouter r) {
@Override
public void update() {
super.update();
if (isTransferring() || !canStartTransfer()) {
if (!canStartTransfer()) {
return; // transferring, don't try other connections yet
}

Expand Down
2 changes: 1 addition & 1 deletion src/routing/FirstContactRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected int checkReceiving(Message m, DTNHost from) {
@Override
public void update() {
super.update();
if (isTransferring() || !canStartTransfer()) {
if (!canStartTransfer()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/routing/LifeRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void update() {
Vector<String> messagesToDelete = new Vector<String>();
super.update();

if (isTransferring() || !canStartTransfer()) {
if (!canStartTransfer()) {
return; /* transferring, don't try other connections yet */
}

Expand Down
2 changes: 1 addition & 1 deletion src/routing/MaxPropRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ protected Message getNextMessageToRemove(boolean excludeMsgBeingSent) {
@Override
public void update() {
super.update();
if (!canStartTransfer() ||isTransferring()) {
if (!canStartTransfer()) {
return; // nothing to transfer or is currently transferring
}

Expand Down
2 changes: 1 addition & 1 deletion src/routing/MaxPropRouterWithEstimation.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ protected Message getNextMessageToRemove(boolean excludeMsgBeingSent) {
@Override
public void update() {
super.update();
if (!canStartTransfer() ||isTransferring()) {
if (!canStartTransfer()) {
return; // nothing to transfer or is currently transferring
}

Expand Down
2 changes: 1 addition & 1 deletion src/routing/ProphetRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private Map<DTNHost, Double> getDeliveryPreds() {
@Override
public void update() {
super.update();
if (!canStartTransfer() ||isTransferring()) {
if (!canStartTransfer()) {
return; // nothing to transfer or is currently transferring
}

Expand Down
2 changes: 1 addition & 1 deletion src/routing/ProphetRouterWithEstimation.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private Map<DTNHost, Double> getDeliveryPreds() {
@Override
public void update() {
super.update();
if (!canStartTransfer() ||isTransferring()) {
if (!canStartTransfer()) {
return; // nothing to transfer or is currently transferring
}

Expand Down
2 changes: 1 addition & 1 deletion src/routing/ProphetV2Router.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private Map<DTNHost, Double> getDeliveryPreds() {
@Override
public void update() {
super.update();
if (!canStartTransfer() ||isTransferring()) {
if (!canStartTransfer()) {
return; // nothing to transfer or is currently transferring
}

Expand Down
2 changes: 1 addition & 1 deletion src/routing/SprayAndWaitRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public boolean createNewMessage(Message msg) {
@Override
public void update() {
super.update();
if (!canStartTransfer() || isTransferring()) {
if (!canStartTransfer()) {
return; // nothing to transfer or is currently transferring
}

Expand Down
2 changes: 1 addition & 1 deletion src/routing/WaveRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ else if (oldest.getReceiveTime() > m.getReceiveTime()) {
public void update() {
super.update();

if (isTransferring() || !canStartTransfer()) {
if (!canStartTransfer()) {
return; /* transferring, don't try other connections yet */
}

Expand Down
37 changes: 37 additions & 0 deletions src/test/EpidemicRouterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package test;

import routing.ActiveRouter;
import routing.EpidemicRouter;
import routing.MessageRouter;
import core.DTNHost;
Expand Down Expand Up @@ -619,4 +620,40 @@ public void testRandomSendingQ() throws Exception {
assertNotSame(orderedIds, runMessageExchange(true));
assertNotSame(orderedIds, runMessageExchange(false));
}

/**
* Checks that concurrent transfers can be enabled
*/
public void testConcurrentTransfers() throws Exception {
ts.setNameSpace(null);
ts.putSetting(ActiveRouter.CONCURRENT_TRANS_S, "true");
this.setUp();

Message m1 = new Message(h1, h2, msgId1, 1);
h1.createNewMessage(m1);
Message m2 = new Message(h1, h3, msgId2, 1);
h1.createNewMessage(m2);
mc.reset();

// check that both routers start the transfer simultaneously
h1.connect(h2);
h1.connect(h3);
updateAllNodes();
assertTrue(mc.next());
assertEquals(mc.TYPE_START, mc.getLastType());
assertFalse(mc.next());
// next transfer should be started immediately, not advancing clock
updateAllNodes();
assertTrue(mc.next());
assertEquals(mc.TYPE_START, mc.getLastType());
assertFalse(mc.next());
// only two messages
updateAllNodes();
assertFalse(mc.next());

// restore setting as other tests depend on default behavior
ts.setNameSpace(null);
ts.putSetting(ActiveRouter.CONCURRENT_TRANS_S, "false");
this.setUp();
}
}