Skip to content

Commit

Permalink
Use position plugin in the OMNeT plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vladamatena committed Apr 15, 2015
1 parent fece46a commit 05a9687
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@
import cz.cuni.mff.d3s.jdeeco.network.l1.MANETReceivedInfo;

public class OMNeTBroadcastDevice extends OMNeTDevice {
public final Position position;

public OMNeTBroadcastDevice(/* , address, frequency, ... */) {
position = new Position(0, 0, 0);
}

public OMNeTBroadcastDevice(int x, int y, int z) {
this(new Position(x, y, z));
}

public OMNeTBroadcastDevice(final Position position) {
this.position = position;
}

@Override
public int getMTU() {
// TODO: Read from OMNeT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.Set;

import cz.cuni.mff.d3s.deeco.simulation.omnet.OMNeTNative;
import cz.cuni.mff.d3s.jdeeco.position.Position;
import cz.cuni.mff.d3s.jdeeco.position.PositionPlugin;

public class OMNeTConfigGenerator {
class Node {
Expand Down Expand Up @@ -53,9 +55,9 @@ public void addNode(OMNeTSimulation.OMNeTHost host) {
// Determine node position
Position position = new Position(0, 0, 0);
if (host.broadcastDevice != null) {
position = host.broadcastDevice.position;
position = host.container.getPluginInstance(PositionPlugin.class).getInitialPosition();
}
addNode(new Node(host.id, ip, position));
addNode(new Node(host.getId(), ip, position));
}

public String getContent() throws IOException {
Expand All @@ -80,9 +82,9 @@ public String getContent() throws IOException {
for (Node node : nodes) {
node.ordinal = counter++;
content.append(String.format("%n%n# Node %d definition%n", node.id));
content.append(String.format("**.node[%d].mobility.initialX = %dm%n", node.ordinal, node.position.x));
content.append(String.format("**.node[%d].mobility.initialY = %dm%n", node.ordinal, node.position.y));
content.append(String.format("**.node[%d].mobility.initialZ = %dm%n", node.ordinal, node.position.z));
content.append(String.format("**.node[%d].mobility.initialX = %dm%n", node.ordinal, (int)node.position.x));
content.append(String.format("**.node[%d].mobility.initialY = %dm%n", node.ordinal, (int)node.position.y));
content.append(String.format("**.node[%d].mobility.initialZ = %dm%n", node.ordinal, (int)node.position.z));
content.append(String.format("**.node[%d].appl.id = %d", node.ordinal, node.id));
}

Expand All @@ -103,7 +105,8 @@ public String getContent() throws IOException {

public File writeToTemp() throws IOException {
// Note: OMNeT finds its parts relative to configuration file
File temp = new File(String.format("%s%somnentpp-%d.ini", OMNeTNative.LIB_PATH, File.separator, System.currentTimeMillis()));
File temp = new File(String.format("%s%somnentpp-%d.ini", OMNeTNative.LIB_PATH, File.separator,
System.currentTimeMillis()));
temp.deleteOnExit();

FileWriter writer = new FileWriter(temp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
public class OMNeTInfrastructureDevice extends OMNeTDevice {
public final IPAddress address;

public OMNeTInfrastructureDevice(IPAddress address /* , address, virtual lan, ... */) {
public OMNeTInfrastructureDevice(IPAddress address /* , virtual lan, ... */) {
this.address = address;
}

@Override
public String getId() {
return String.valueOf(host.id);
return String.format("%d (%s)", host.getId(), address);
}

@Override
Expand All @@ -33,7 +33,7 @@ public void send(byte[] data, Address address) {
if(!(address instanceof IPAddress)) {
throw new UnsupportedOperationException();
}
System.out.println("Sending ip packet, from host " + host.getId() + " to host " + address);
System.out.println("Sending ip packet, from host " + getId() + " to " + address);
host.sendInfrastructurePacket(data, (IPAddress) address);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ public void start(long duration) {
}

class OMNeTHost implements OMNeTNativeListener {
final int id;
public final DEECoContainer container;

TimerEventListener eventListener = null;
OMNeTBroadcastDevice broadcastDevice = null;
OMNeTInfrastructureDevice infrastructureDevice = null;

OMNeTHost(int id) {
this.id = id;
OMNeTHost(DEECoContainer container) {
this.container = container;
}

public int getId() {
return id;
return container.getId();
}

public void setEventListener(long time, TimerEventListener listener) {
// Register listener and schedule event
eventListener = listener;
OMNeTNative.nativeCallAt(OMNeTNative.timeToOmnet(time), id);
OMNeTNative.nativeCallAt(OMNeTNative.timeToOmnet(time), getId());
}

public void setBroadcastDevice(OMNeTBroadcastDevice device) {
Expand All @@ -72,11 +72,11 @@ public void setInfrastructureDevice(OMNeTInfrastructureDevice device) {
}

public void sendInfrastructurePacket(byte[] packet, IPAddress address) {
OMNeTNative.nativeSendPacket(id, packet, address.ipAddress/*"MANET.node[" + address.ipAddress + "]"*/);
OMNeTNative.nativeSendPacket(getId(), packet, address.ipAddress/*"MANET.node[" + address.ipAddress + "]"*/);
}

public void sendBroadcastPacket(byte[] packet) {
OMNeTNative.nativeSendPacket(id, packet, "");
OMNeTNative.nativeSendPacket(getId(), packet, "");
}

@Override
Expand Down Expand Up @@ -125,7 +125,7 @@ public List<Class<? extends DEECoPlugin>> getDependencies() {
@Override
public void init(DEECoContainer container) {
if (!hosts.containsKey(container.getId())) {
OMNeTHost host = new OMNeTHost(container.getId());
OMNeTHost host = new OMNeTHost(container);
hosts.put(host.getId(), host);
OMNeTNative.nativeRegister(host, host.getId());
System.out.println("Registered host " + host.getId());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import cz.cuni.mff.d3s.jdeeco.network.l2.strategy.KnowledgeInsertingStrategy;
import cz.cuni.mff.d3s.jdeeco.network.omnet.OMNeTBroadcastDevice;
import cz.cuni.mff.d3s.jdeeco.network.omnet.OMNeTSimulation;
import cz.cuni.mff.d3s.jdeeco.network.omnet.Position;
import cz.cuni.mff.d3s.jdeeco.position.PositionPlugin;
import cz.cuni.mff.d3s.jdeeco.publishing.DefaultKnowledgePublisher;

/**
Expand Down Expand Up @@ -37,8 +37,8 @@ public void testConvoyOmnet() throws AnnotationProcessorException, InterruptedEx
simulation.addPlugin(DefaultKnowledgePublisher.class);
simulation.addPlugin(omnet);

DEECoNode node0 = simulation.createNode(new OMNeTBroadcastDevice(new Position(100, 0, 0)));
DEECoNode node1 = simulation.createNode(new OMNeTBroadcastDevice(new Position(0, 100, 0)));
DEECoNode node0 = simulation.createNode(new OMNeTBroadcastDevice(), new PositionPlugin(100, 0));
DEECoNode node1 = simulation.createNode(new OMNeTBroadcastDevice(), new PositionPlugin(0, 100));

// Deploy components and ensembles
node0.deployComponent(new Leader());
Expand Down

0 comments on commit 05a9687

Please sign in to comment.