-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e39433b
commit f0f449c
Showing
3 changed files
with
93 additions
and
67 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
jdeeco-network-plugin/src/cz/cuni/mff/d3s/jdeeco/network/device/BroadcastLoopback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package cz.cuni.mff.d3s.jdeeco.network.device; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import cz.cuni.mff.d3s.deeco.runtime.DEECoContainer; | ||
import cz.cuni.mff.d3s.deeco.runtime.DEECoPlugin; | ||
import cz.cuni.mff.d3s.jdeeco.network.Network; | ||
import cz.cuni.mff.d3s.jdeeco.network.address.Address; | ||
import cz.cuni.mff.d3s.jdeeco.network.address.MANETBroadcastAddress; | ||
import cz.cuni.mff.d3s.jdeeco.network.l1.Layer1; | ||
import cz.cuni.mff.d3s.jdeeco.network.l1.ReceivedInfo; | ||
|
||
/** | ||
* Loop-back broadcast plugin | ||
* | ||
* Can be initialized by more DEECo run-times at the same time. Packets send are then instantly delivered to all of | ||
* them. | ||
* | ||
* @author Vladimir Matena <matena@d3s.mff.cuni.cz> | ||
* | ||
*/ | ||
public class BroadcastLoopback implements DEECoPlugin { | ||
/** | ||
* Loop device used to provide broadcast device to layer 1 | ||
*/ | ||
class LoopDevice extends Device { | ||
public Layer1 layer1; | ||
public MANETBroadcastAddress address; | ||
|
||
private String id; | ||
|
||
public LoopDevice(String id, Layer1 layer1) { | ||
this.id = id; | ||
this.address = new MANETBroadcastAddress(getId()); | ||
this.layer1 = layer1; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public int getMTU() { | ||
return 128; | ||
} | ||
|
||
@Override | ||
public boolean canSend(Address address) { | ||
return address instanceof MANETBroadcastAddress; | ||
} | ||
|
||
@Override | ||
public void send(byte[] data, Address addressNotUsed) { | ||
BroadcastLoopback.this.sendToAll(data, this); | ||
} | ||
} | ||
|
||
// Layers this device is registered with | ||
private Set<LoopDevice> loops = new HashSet<>(); | ||
|
||
/** | ||
* Sends packet to all registered loop devices | ||
* | ||
* @param data | ||
* Packet data | ||
* @param source | ||
* Source loop device | ||
*/ | ||
public void sendToAll(byte[] data, LoopDevice source) { | ||
for (LoopDevice loop : loops) { | ||
loop.layer1.processL0Packet(data, source, new ReceivedInfo(source.address)); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Class<? extends DEECoPlugin>> getDependencies() { | ||
return Arrays.asList(Network.class); | ||
} | ||
|
||
@Override | ||
public void init(DEECoContainer container) { | ||
Layer1 l1 = container.getPluginInstance(Network.class).getL1(); | ||
LoopDevice loop = new LoopDevice(String.valueOf(container.getId()), l1); | ||
l1.registerDevice(loop); | ||
loops.add(loop); | ||
} | ||
} |
65 changes: 0 additions & 65 deletions
65
jdeeco-network-plugin/src/cz/cuni/mff/d3s/jdeeco/network/device/LoopbackBroadcastDevice.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters