-
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
Michal Kit
committed
Feb 9, 2015
1 parent
725479b
commit df26089
Showing
11 changed files
with
375 additions
and
43 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
jdeeco-network-plugin/src/cz/cuni/mff/d3s/jdeeco/network/l1/DataIDSource.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,5 @@ | ||
package cz.cuni.mff.d3s.jdeeco.network.l1; | ||
|
||
public interface DataIDSource { | ||
public int createDataID(); | ||
} |
21 changes: 21 additions & 0 deletions
21
jdeeco-network-plugin/src/cz/cuni/mff/d3s/jdeeco/network/l1/DefaultDataIDSource.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,21 @@ | ||
package cz.cuni.mff.d3s.jdeeco.network.l1; | ||
|
||
public class DefaultDataIDSource implements DataIDSource { | ||
|
||
private static DefaultDataIDSource instance; | ||
private static int COUNTER = 0; | ||
|
||
public synchronized DefaultDataIDSource getInstance() { | ||
if (instance == null) { | ||
instance = new DefaultDataIDSource(); | ||
} | ||
return instance; | ||
} | ||
|
||
@Override | ||
public int createDataID() { | ||
COUNTER++; | ||
return COUNTER; | ||
} | ||
|
||
} |
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
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
56 changes: 38 additions & 18 deletions
56
jdeeco-network-plugin/src/cz/cuni/mff/d3s/jdeeco/network/l1/Layer1.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 |
---|---|---|
@@ -1,61 +1,81 @@ | ||
package cz.cuni.mff.d3s.jdeeco.network.l1; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import cz.cuni.mff.d3s.jdeeco.network.Device; | ||
import cz.cuni.mff.d3s.jdeeco.network.l2.L2Packet; | ||
import cz.cuni.mff.d3s.jdeeco.network.l2.L2ReceivedInfo; | ||
|
||
/** | ||
* Defines L1 methods that are called from the upper layer (L2) or L1 strategies. | ||
* Defines L1 methods that are called from the upper layer (L2) or L1 strategies. | ||
* | ||
* | ||
* @author Michal Kit <kit@d3s.mff.cuni.cz> | ||
* | ||
*/ | ||
public class Layer1 { | ||
|
||
private final Set<Strategy> strategies; | ||
private final Set<Device> devices; | ||
|
||
public Layer1() { | ||
private final int nodeId; | ||
private final DataIDSource dataIdSource; | ||
|
||
public Layer1(int nodeId, DataIDSource dataIdSource) { | ||
this.strategies = new HashSet<Strategy>(); | ||
this.devices = new HashSet<Device>(); | ||
this.nodeId = nodeId; | ||
this.dataIdSource = dataIdSource; | ||
} | ||
|
||
public void registerStrategy(Strategy strategy) { | ||
strategies.add(strategy); | ||
} | ||
|
||
public void registerDevice(Device device) { | ||
devices.add(device); | ||
} | ||
|
||
public boolean sendL2Packet(L2Packet packet, Address address) { | ||
if (packet != null) { | ||
for (Device device: devices) { | ||
for (Device device : devices) { | ||
if (device.canSend(address)) { | ||
packet.getData(); | ||
//device.send(encapsulate(packet), address); | ||
// device.send(encapsulate(packet), address); | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public boolean sendL1Packet(L1Packet packet, Address address) { | ||
//TODO | ||
// TODO | ||
return false; | ||
} | ||
public L1Packet processL0Packet(byte [] packet) { | ||
//TODO | ||
|
||
public L1Packet processL0Packet(byte[] packet) { | ||
// TODO | ||
return null; | ||
} | ||
|
||
protected L1Packet encapsulateL2(L2Packet packet) { | ||
//TODO | ||
return null; | ||
|
||
protected List<L1Packet> dissassembleL2ToL1(L2Packet packet, int mtu) { | ||
LinkedList<L1Packet> result = new LinkedList<L1Packet>(); | ||
if (packet.getData() != null && packet.getData().length > 0) { | ||
L2ReceivedInfo receivedInfo = packet.receivedInfo; | ||
int srcNode, dataId; | ||
if (receivedInfo == null) { | ||
srcNode = nodeId; | ||
dataId = dataIdSource.createDataID(); | ||
} else { | ||
srcNode = receivedInfo.srcNode; | ||
dataId = receivedInfo.dataId; | ||
} | ||
//L1Packet l1Packet = new L1Packet(packet.getData(), srcNode, dataId, startPos, payloadSize, totalSize, null); | ||
} | ||
return result; | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.