Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Kit committed Feb 9, 2015
1 parent 725479b commit df26089
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 43 deletions.
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();
}
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class L1Packet {
public final int startPos; /** in bytes*/
public final int payloadSize; /** in bytes*/
public final int totalSize; /** in bytes*/
public final ReceivedInfo receivedInfo; /** receival additaional information */
public final L1ReceivedInfo receivedInfo; /** receival additaional information */

public L1Packet(byte[] payload, int srcNode, int dataId, int startPos,
int payloadSize, int totalSize, ReceivedInfo receivedInfo) {
int payloadSize, int totalSize, L1ReceivedInfo receivedInfo) {
this.payload = payload;
this.srcNode = srcNode;
this.dataId = dataId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* @author Michal Kit <kit@d3s.mff.cuni.cz>
*
*/
public class ReceivedInfo {
public final String srcAddress; /** packet sending node address */
public class L1ReceivedInfo {
public final Address srcAddress; /** packet sending node address */

public ReceivedInfo(String srcAddress) {
public L1ReceivedInfo(Address srcAddress) {
this.srcAddress = srcAddress;
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* @author Michal Kit <kit@d3s.mff.cuni.cz>
*
*/
public class MANETReceivedInfo extends ReceivedInfo {
public class MANETReceivedInfo extends L1ReceivedInfo {

public final double rssi; /** Radio Signal Strength Indicator */

public MANETReceivedInfo(String srcAddress, double rssi) {
public MANETReceivedInfo(Address srcAddress, double rssi) {
super(srcAddress);
this.rssi = rssi;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
*/
public class L2Packet {
public final PacketHeader header;
public final ReceivedInfo receivedInfo;
public final L2ReceivedInfo receivedInfo;

private byte[] data;
private Object object;
private final Layer2 l2Layer;


private L2Packet(Layer2 l2Layer, PacketHeader header, ReceivedInfo receivedInfo) {
private L2Packet(Layer2 l2Layer, PacketHeader header, L2ReceivedInfo receivedInfo) {
this.l2Layer = l2Layer;
this.header = header;
this.receivedInfo = receivedInfo;
Expand All @@ -42,7 +42,7 @@ public L2Packet(Layer2 l2Layer, PacketHeader header, Object object) {
* @param data
* Source binary data for object
*/
public L2Packet(Layer2 l2Layer, PacketHeader header, byte[] data, ReceivedInfo receivedInfo) {
public L2Packet(Layer2 l2Layer, PacketHeader header, byte[] data, L2ReceivedInfo receivedInfo) {
this(l2Layer, header, receivedInfo);
this.data = data;
}
Expand Down Expand Up @@ -75,13 +75,4 @@ public byte[] getData() {
}
return data;
}

/**
* Gets packet received info
*
* @return Returns packet received info, or null when no packet received info is available.
*/
public ReceivedInfo getReceivedInfo() {
return receivedInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author Vladimir Matena <matena@d3s.mff.cuni.cz>
*
*/
public class ReceivedInfo {
public class L2ReceivedInfo {
/**
* Source L1 packets
*
Expand All @@ -33,7 +33,7 @@ public class ReceivedInfo {
public final int dataId;


public ReceivedInfo(Collection<L1Packet> srcFragments, int srcNode,
public L2ReceivedInfo(Collection<L1Packet> srcFragments, int srcNode,
int dataId) {
this.srcFragments = srcFragments;
this.srcNode = srcNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public L2Packet createPacket(PacketHeader header, Object object) {
* @param receifedInfo
* Information about received packet
*/
public L2Packet createPacket(PacketHeader header, byte[] data, ReceivedInfo receivedInfo) {
public L2Packet createPacket(PacketHeader header, byte[] data, L2ReceivedInfo receivedInfo) {
return new L2Packet(this, header, data, receivedInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import cz.cuni.mff.d3s.jdeeco.network.l2.L2Packet;
import cz.cuni.mff.d3s.jdeeco.network.l2.Layer2;
import cz.cuni.mff.d3s.jdeeco.network.l2.PacketHeader;
import cz.cuni.mff.d3s.jdeeco.network.l2.ReceivedInfo;
import cz.cuni.mff.d3s.jdeeco.network.l2.L2ReceivedInfo;
import cz.cuni.mff.d3s.jdeeco.network.l2.Strategy;
import cz.cuni.mff.d3s.jdeeco.network.marshaller.MarshallerRegistry;
import cz.cuni.mff.d3s.jdeeco.network.marshaller.SerializingMarshaller;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void testL2PacketMarshalling() {
assertPayload(srcPacket.getObject());

// Create destination packet from source packet binary data
ReceivedInfo info = new ReceivedInfo(new LinkedList<L1Packet>(), 1, 1);
L2ReceivedInfo info = new L2ReceivedInfo(new LinkedList<L1Packet>(), 1, 1);
L2Packet dstPacket = l2Layer.createPacket(new PacketHeader(PacketType.KNOWLEDGE), srcPacket.getData(), info);
assertPayload(dstPacket.getObject());
}
Expand Down Expand Up @@ -101,7 +101,7 @@ public void testL2PacketProcessing() {
Strategy strategy = Mockito.mock(Strategy.class);
l2Layer.registerL2Strategy(strategy);

ReceivedInfo info = new ReceivedInfo(new LinkedList<L1Packet>(), 1, 1);
L2ReceivedInfo info = new L2ReceivedInfo(new LinkedList<L1Packet>(), 1, 1);

// Create source packet (created with data and received packet info)
L2Packet srcPacket = l2Layer.createPacket(new PacketHeader(PacketType.KNOWLEDGE),
Expand Down
Loading

0 comments on commit df26089

Please sign in to comment.