Skip to content

Commit

Permalink
Refactor network interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
vladamatena committed Feb 11, 2015
1 parent d8aa5ee commit 101809e
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cz.cuni.mff.d3s.jdeeco.network;

import cz.cuni.mff.d3s.jdeeco.network.l2.L2Packet;

/**
* Interface for passing L2 packets to Layer 2 from Layer 1
*
* @author Vladimir Matena <matena@d3s.mff.cuni.cz>
*
*/
public interface L2PacketProcessor {
/**
* Processes L2 packet Layer 2
*
* @param packet
* Packet to be processed
*/
public void processL2Packet(L2Packet packet);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cz.cuni.mff.d3s.jdeeco.network;

import cz.cuni.mff.d3s.jdeeco.network.l2.L2Packet;

/**
* Interface for processing L2 packets from Layer 2 by Layer 1
*
* @author Vladimir Matena <matena@d3s.mff.cuni.cz>
*
*/
public interface L2PacketSender {
/**
* Sends L2 packet by Layer 1
*
* @param l2Packet
* Packet to send
* @param address
* Destination address
* @return True if the packet has been processed, false otherwise
*/
public boolean sendL2Packet(L2Packet l2Packet, Address address);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Vladimir Matena <matena@d3s.mff.cuni.cz>
*
*/
public interface ILayer1 {
public interface Layer1Manager {
/**
* Registers L1 strategy for processing L1 packets
*
Expand Down
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 interface ILayer2 {
public interface Layer2Manager {
/**
* Registers L2 strategy for processing L2 packets
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cz.cuni.mff.d3s.jdeeco.network.l0.Device;
import cz.cuni.mff.d3s.jdeeco.network.l1.L1Strategy;
import cz.cuni.mff.d3s.jdeeco.network.l1.Layer1;
import cz.cuni.mff.d3s.jdeeco.network.l2.L2Packet;
import cz.cuni.mff.d3s.jdeeco.network.l2.L2Strategy;
import cz.cuni.mff.d3s.jdeeco.network.l2.Layer2;

Expand All @@ -14,7 +15,7 @@
* @author Vladimir Matena <matena@d3s.mff.cuni.cz>
*
*/
public class Network implements INetworkToDevice, INetworkToGossip, ILayer1, ILayer2 {
public class Network implements NetworkPlugin, L2PacketProcessor, L2PacketSender {
private Layer1 l1;
private Layer2 l2;

Expand Down Expand Up @@ -64,4 +65,16 @@ public void processDevicePacket(byte[] l0Packet, Address srcAddress) {
// l1.processL0Packet(l0Packet, srcAddress);
throw new UnsupportedOperationException();
}

// Interlayer interface

@Override
public void processL2Packet(L2Packet packet) {
l2.processL2Packet(packet);
}

@Override
public boolean sendL2Packet(L2Packet l2Packet, Address address) {
return l1.sendL2Packet(l2Packet, address);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cz.cuni.mff.d3s.jdeeco.network;

public interface NetworkPlugin extends NetworkToDevice, NetworkToGossip, Layer1Manager, Layer2Manager {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author Vladimir Matena <matena@d3s.mff.cuni.cz>
*
*/
public interface INetworkToDevice {
public interface NetworkToDevice {
/**
* Registers network device
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Vladimir Matena <matena@d3s.mff.cuni.cz>
*
*/
public interface INetworkToGossip {
public interface NetworkToGossip {
/**
* Processes knowledge to be send to network from gossip
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Set;

import cz.cuni.mff.d3s.jdeeco.network.Address;
import cz.cuni.mff.d3s.jdeeco.network.L2PacketSender;
import cz.cuni.mff.d3s.jdeeco.network.l0.Device;
import cz.cuni.mff.d3s.jdeeco.network.l0.Layer0;
import cz.cuni.mff.d3s.jdeeco.network.l2.L2Packet;
Expand All @@ -23,7 +24,7 @@
* @author Michal Kit <kit@d3s.mff.cuni.cz>
*
*/
public class Layer1 {
public class Layer1 implements L2PacketSender {

private final Set<L1Strategy> strategies;
private final int nodeId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package cz.cuni.mff.d3s.jdeeco.network.l2;

import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;

import cz.cuni.mff.d3s.jdeeco.network.Address;
import cz.cuni.mff.d3s.jdeeco.network.ILayer2;
import cz.cuni.mff.d3s.jdeeco.network.l1.Layer1;
import cz.cuni.mff.d3s.jdeeco.network.l2.L2Strategy;
import cz.cuni.mff.d3s.jdeeco.network.L2PacketProcessor;
import cz.cuni.mff.d3s.jdeeco.network.L2PacketSender;
import cz.cuni.mff.d3s.jdeeco.network.Layer2Manager;
import cz.cuni.mff.d3s.jdeeco.network.marshaller.MarshallerRegistry;

/**
Expand All @@ -14,20 +16,20 @@
* @author Vladimir Matena <matena@d3s.mff.cuni.cz>
*
*/
public class Layer2 implements ILayer2 {
public class Layer2 implements Layer2Manager, L2PacketProcessor {
private final Collection<L2Strategy> strategies = new HashSet<L2Strategy>();
private final MarshallerRegistry marshallers;
private final Layer1 layer1;
private final L2PacketSender l2Sender;

/**
* Creates L2 layer
*
* @param marshallerRegistry
* MarshallerRegistry to be used by L2 and L2 packets
*/
public Layer2(Layer1 layer1, MarshallerRegistry marshallerRegistry) {
public Layer2(L2PacketSender l2Sender, MarshallerRegistry marshallerRegistry) {
marshallers = marshallerRegistry;
this.layer1 = layer1;
this.l2Sender = l2Sender;
}

/**
Expand Down Expand Up @@ -61,8 +63,7 @@ public void processL2Packet(L2Packet packet) {
*/
public void sendL2Packet(L2Packet packet, Address address) {
// Pass packet to lower layer
// TODO: Missing the address parameter
layer1.sendL2Packet(packet, address);
l2Sender.sendL2Packet(packet, address);
}

/**
Expand Down

0 comments on commit 101809e

Please sign in to comment.