/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see .
*
*/
package de.tud.kom.p2psim.impl.topology.placement;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.zip.GZIPInputStream;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
public class BonnMotionPositionDistribution extends PositionDistribution {
private Vector mobilityTraceFiles;
private Vector offsets;
private List availablePositions;
private int counter;
private int fileCounter = 1;
public BonnMotionPositionDistribution() {
super();
this.mobilityTraceFiles = new Vector();
this.offsets = new Vector();
Map variables = Simulator.getConfigurator()
.getVariables();
System.out.println(variables.toString());
String traceFile = variables.get("mobilityTraceFile-File-"+fileCounter);
String configFile = variables.get("mobilityConfigFile-File-"+fileCounter);
String xString = variables.get("xOffset-File-"+fileCounter);
String yString = variables.get("yOffset-File-"+fileCounter);
while (traceFile != null && configFile != null && xString != null
&& yString != null) {
Integer xOffset = Integer.parseInt(xString);
Integer yOffset = Integer.parseInt(yString);
this.mobilityTraceFiles.add(traceFile);
this.offsets.add(new PositionVector(xOffset.intValue(), yOffset
.intValue()));
fileCounter++;
traceFile = variables.get("mobilityTraceFile-File-"+fileCounter);
configFile = variables.get("mobilityConfigFile-File-"+fileCounter);
xString = variables.get("xOffset-File-"+fileCounter);
yString = variables.get("yOffset-File-"+fileCounter);
}
availablePositions = new LinkedList();
extractPositions();
counter = 0;
}
@Override
public PositionVector getNextPosition() {
if (counter >= availablePositions.size()) {
throw new RuntimeException(
"There are more Hosts configured than available in the corresponding BonnMotionTraceFile."
+ " Please configure less hosts or run BonnMotion with the correct number of hosts.");
}
PositionVector pos = availablePositions.get(counter);
counter++;
return pos;
}
private void extractPositions() {
for (int a =0;a