removed unused ipdistributor code: was previously used to assign IP addresses to simulated motes,

a decision better made by Contiki
ico
Fredrik Osterlind 2012-06-11 15:52:20 +02:00
parent 8947c7a3bb
commit 947f3322ba
7 changed files with 39 additions and 384 deletions

View File

@ -1,5 +1,4 @@
se.sics.cooja.GUI.MOTETYPES = se.sics.cooja.motes.DisturberMoteType se.sics.cooja.contikimote.ContikiMoteType se.sics.cooja.mspmote.ESBMoteType se.sics.cooja.mspmote.SkyMoteType
se.sics.cooja.GUI.PLUGINS = se.sics.cooja.plugins.Visualizer se.sics.cooja.plugins.LogListener se.sics.cooja.plugins.MoteInformation se.sics.cooja.plugins.MoteInterfaceViewer se.sics.cooja.plugins.VariableWatcher se.sics.cooja.plugins.EventListener se.sics.cooja.plugins.RadioLogger se.sics.cooja.mspmote.plugins.MspCodeWatcher se.sics.cooja.mspmote.plugins.MspStackWatcher se.sics.cooja.mspmote.plugins.MspCycleWatcher
se.sics.cooja.GUI.IP_DISTRIBUTORS = se.sics.cooja.ipdistributors.RandomIPDistributor se.sics.cooja.ipdistributors.SpatialIPDistributor se.sics.cooja.ipdistributors.IdIPDistributor
se.sics.cooja.GUI.POSITIONERS = se.sics.cooja.positioners.RandomPositioner se.sics.cooja.positioners.LinearPositioner se.sics.cooja.positioners.EllipsePositioner se.sics.cooja.positioners.ManualPositioner
se.sics.cooja.GUI.RADIOMEDIUMS = se.sics.cooja.radiomediums.UDGM se.sics.cooja.radiomediums.UDGMConstantLoss se.sics.cooja.radiomediums.DirectedGraphMedium se.sics.mrm.MRM se.sics.cooja.radiomediums.SilentRadioMedium

View File

@ -4,6 +4,5 @@ se.sics.cooja.contikimote.ContikiMoteType.MOTE_INTERFACES = se.sics.cooja.interf
se.sics.cooja.contikimote.ContikiMoteType.C_SOURCES =
se.sics.cooja.GUI.MOTETYPES = se.sics.cooja.motes.ImportAppMoteType se.sics.cooja.motes.DisturberMoteType se.sics.cooja.contikimote.ContikiMoteType
se.sics.cooja.GUI.PLUGINS = se.sics.cooja.plugins.Visualizer se.sics.cooja.plugins.LogListener se.sics.cooja.plugins.TimeLine se.sics.cooja.plugins.MoteInformation se.sics.cooja.plugins.MoteInterfaceViewer se.sics.cooja.plugins.VariableWatcher se.sics.cooja.plugins.EventListener se.sics.cooja.plugins.RadioLogger se.sics.cooja.plugins.ScriptRunner se.sics.cooja.plugins.Notes se.sics.cooja.plugins.BufferListener
se.sics.cooja.GUI.IP_DISTRIBUTORS = se.sics.cooja.ipdistributors.RandomIPDistributor se.sics.cooja.ipdistributors.SpatialIPDistributor se.sics.cooja.ipdistributors.IdIPDistributor
se.sics.cooja.GUI.POSITIONERS = se.sics.cooja.positioners.RandomPositioner se.sics.cooja.positioners.LinearPositioner se.sics.cooja.positioners.EllipsePositioner se.sics.cooja.positioners.ManualPositioner
se.sics.cooja.GUI.RADIOMEDIUMS = se.sics.cooja.radiomediums.UDGM se.sics.cooja.radiomediums.UDGMConstantLoss se.sics.cooja.radiomediums.DirectedGraphMedium se.sics.cooja.radiomediums.SilentRadioMedium

View File

@ -1,76 +0,0 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of the
* Institute nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: IPDistributor.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $
*/
package se.sics.cooja;
import java.lang.reflect.Constructor;
import java.util.Vector;
import org.apache.log4j.Logger;
/**
* A IP distributor is used for determining IP addresses of newly created motes.
*
* @see se.sics.cooja.Positioner
* @author Fredrik Osterlind
*/
public abstract class IPDistributor {
private static Logger logger = Logger.getLogger(IPDistributor.class);
/**
* This method creates an instance of the given class with the given vector as
* constructor argument. Instead of calling the constructors directly this
* method may be used.
*
* @param ipDistClass
* Class
* @param newMotes
* All motes that later should be assigned IP numbers
* @return IP distributor instance
*/
public static final IPDistributor generateIPDistributor(
Class<? extends IPDistributor> ipDistClass, Vector<Mote> newMotes) {
try {
// Generating IP distributor
Constructor constr = ipDistClass
.getConstructor(new Class[] { Vector.class });
return (IPDistributor) constr.newInstance(new Object[] { newMotes });
} catch (Exception e) {
logger.fatal("Exception when creating " + ipDistClass + ": " + e);
return null;
}
}
/**
* Returns the next mote IP address.
*
* @return IP Address
*/
public abstract String getNextIPAddress();
}

View File

@ -31,16 +31,45 @@
package se.sics.cooja.dialogs;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
import se.sics.cooja.*;
import se.sics.cooja.interfaces.*;
import se.sics.cooja.GUI;
import se.sics.cooja.Mote;
import se.sics.cooja.MoteType;
import se.sics.cooja.Positioner;
import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.MoteID;
import se.sics.cooja.interfaces.Position;
/**
* A dialog for adding motes.
@ -66,7 +95,7 @@ public class AddMoteDialog extends JDialog {
private JFormattedTextField numberOfMotesField, startX, endX, startY, endY,
startZ, endZ;
private JComboBox positionDistributionBox /*, ipDistributionBox*/;
private JComboBox positionDistributionBox;
/**
@ -176,36 +205,6 @@ public class AddMoteDialog extends JDialog {
mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
// IP address distribution
/*smallPane = new JPanel();
smallPane.setAlignmentX(Component.LEFT_ALIGNMENT);
smallPane.setLayout(new BoxLayout(smallPane, BoxLayout.X_AXIS));
label = new JLabel("IP Addressing");
label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT));
Vector<Class<? extends IPDistributor>> ipDistributors = simulation.getGUI()
.getRegisteredIPDistributors();
String[] ipDistributions = new String[ipDistributors.size()];
for (int i = 0; i < ipDistributions.length; i++) {
ipDistributions[i] = GUI.getDescriptionOf(ipDistributors.get(i));
}
comboBox = new JComboBox(ipDistributions);
comboBox.setSelectedIndex(0);
comboBox.addActionListener(myEventHandler);
comboBox.addFocusListener(myEventHandler);
ipDistributionBox = comboBox;
label.setLabelFor(comboBox);
smallPane.add(label);
smallPane.add(Box.createHorizontalStrut(10));
smallPane.add(comboBox);
mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
*/
// Position distribution
smallPane = new JPanel();
smallPane.setAlignmentX(Component.LEFT_ALIGNMENT);
@ -504,7 +503,7 @@ public class AddMoteDialog extends JDialog {
}
}
/* Set unique mote id's for all new motes
/* Set unique mote id's for all new motes
* TODO ID should be provided differently; not rely on the unsafe MoteID interface */
int nextMoteID = 1;
for (Mote m: simulation.getMotes()) {
@ -522,33 +521,6 @@ public class AddMoteDialog extends JDialog {
}
}
// IP address new motes
/*Class<? extends IPDistributor> ipDistClass = null;
for (Class<? extends IPDistributor> ipDistributor : simulation.getGUI()
.getRegisteredIPDistributors()) {
if (GUI.getDescriptionOf(ipDistributor).equals(
ipDistributionBox.getSelectedItem())) {
ipDistClass = ipDistributor;
}
}
IPDistributor ipDistributor = IPDistributor.generateIPDistributor(
ipDistClass, newMotes);
if (ipDistributor == null) {
logger.fatal("Could not create IP distributor");
dispose();
return;
}
for (int i = 0; i < newMotes.size(); i++) {
String newIPString = ipDistributor.getNextIPAddress();
if (newMotes.get(i).getInterfaces().getIPAddress() != null) {
newMotes.get(i).getInterfaces().getIPAddress().setIPString(
newIPString);
}
}*/
dispose();
} catch (OutOfMemoryError e2) {
newMotes = null;

View File

@ -1,74 +0,0 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: IdIPDistributor.java,v 1.2 2009/09/17 13:20:03 fros4943 Exp $
*/
package se.sics.cooja.ipdistributors;
import java.util.Vector;
import se.sics.cooja.*;
/**
* Generates IP addresses on the form 10.[id/256 mod 256*256].[id mod 256].1.
*
* Observe!
* - ID must be set before this is called (otherwise IP=0.0.0.0).
* - Only supports 256*256 motes, (IPs will wrap if above).
*
* @author Fredrik Osterlind
*/
@ClassDescription("From ID (10.id.id.1)")
public class IdIPDistributor extends IPDistributor {
private Vector<String> generatedIPAddresses;
/**
* Creates a Id IP distributor.
* @param newMotes All motes which later will be assigned IP numbers.
*/
public IdIPDistributor(Vector<Mote> newMotes) {
generatedIPAddresses = new Vector<String>();
for (int i=0; i < newMotes.size(); i++) {
int moteId = newMotes.get(i).getID();
generatedIPAddresses.add("10." +
(moteId / 256 % (256*256))
+ "." +
(moteId % 256)
+ ".1");
}
}
public String getNextIPAddress() {
if (generatedIPAddresses.size() > 0)
return generatedIPAddresses.remove(0);
else
return "0.0.0.0";
}
}

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: RandomIPDistributor.java,v 1.2 2009/02/18 12:07:19 fros4943 Exp $
*/
package se.sics.cooja.ipdistributors;
import java.util.Random;
import java.util.Vector;
import se.sics.cooja.*;
/**
* Generates IP addresses randomly on the form 10.10.[1-20].[1-20].
* Nothing prevents several motes from getting the same IP number.
*
* @author Fredrik Osterlind
*/
@ClassDescription("Random (10.10.?.?)")
public class RandomIPDistributor extends IPDistributor {
private Random random = new Random(); /* Do not use main random generator for setup */
/**
* Creates a random IP distributor.
* @param newMotes All motes which later will be assigned IP numbers.
*/
public RandomIPDistributor(Vector<Mote> newMotes) {
}
public String getNextIPAddress() {
return "" + 10 + "." + 10 + "." + (1+random.nextInt(20)) + "." + (1+random.nextInt(20));
}
}

View File

@ -1,106 +0,0 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: SpatialIPDistributor.java,v 1.1 2006/08/21 12:13:07 fros4943 Exp $
*/
package se.sics.cooja.ipdistributors;
import java.util.Vector;
import se.sics.cooja.*;
/**
* Generates spatial IP addresses on the form 10.[z-coord].[y-coord].[x-coord].
* The smallest coordinate in each interval will be mapped onto address 1,
* and the biggest coordinate onto address 200.
* Nothing prevents several motes from getting the same IP number.
*
* @author Fredrik Osterlind
*/
@ClassDescription("Spatial (10.x.y.z)")
public class SpatialIPDistributor extends IPDistributor {
private double lowestX, biggestX, lowestY, biggestY, lowestZ, biggestZ;
private Vector<String> generatedIPAddresses;
/**
* Creates a random IP distributor.
* @param newMotes All motes which later will be assigned IP numbers.
*/
public SpatialIPDistributor(Vector<Mote> newMotes) {
lowestX = newMotes.get(0).getInterfaces().getPosition().getXCoordinate();
biggestX = newMotes.get(0).getInterfaces().getPosition().getXCoordinate();
lowestY = newMotes.get(0).getInterfaces().getPosition().getYCoordinate();
biggestY = newMotes.get(0).getInterfaces().getPosition().getYCoordinate();
lowestZ = newMotes.get(0).getInterfaces().getPosition().getZCoordinate();
biggestZ = newMotes.get(0).getInterfaces().getPosition().getZCoordinate();
for (int i=0; i < newMotes.size(); i++) {
if (newMotes.get(i).getInterfaces().getPosition().getXCoordinate() < lowestX)
lowestX = newMotes.get(i).getInterfaces().getPosition().getXCoordinate();
if (newMotes.get(i).getInterfaces().getPosition().getXCoordinate() > biggestX)
biggestX = newMotes.get(i).getInterfaces().getPosition().getXCoordinate();
if (newMotes.get(i).getInterfaces().getPosition().getYCoordinate() < lowestY)
lowestY = newMotes.get(i).getInterfaces().getPosition().getYCoordinate();
if (newMotes.get(i).getInterfaces().getPosition().getYCoordinate() > biggestY)
biggestY = newMotes.get(i).getInterfaces().getPosition().getYCoordinate();
if (newMotes.get(i).getInterfaces().getPosition().getZCoordinate() < lowestZ)
lowestZ = newMotes.get(i).getInterfaces().getPosition().getZCoordinate();
if (newMotes.get(i).getInterfaces().getPosition().getZCoordinate() > biggestZ)
biggestZ = newMotes.get(i).getInterfaces().getPosition().getZCoordinate();
}
generatedIPAddresses = new Vector<String>();
for (int i=0; i < newMotes.size(); i++) {
String ipAddress = "10.";
int partIP;
// Z coord
partIP = (int) (1 + 199*(newMotes.get(i).getInterfaces().getPosition().getZCoordinate() - lowestZ) / (biggestZ - lowestZ));
ipAddress = ipAddress.concat(partIP + ".");
// Y coord
partIP = (int) (1 + 199*(newMotes.get(i).getInterfaces().getPosition().getYCoordinate() - lowestY) / (biggestY - lowestY));
ipAddress = ipAddress.concat(partIP + ".");
// X coord
partIP = (int) (1 + 199*(newMotes.get(i).getInterfaces().getPosition().getXCoordinate() - lowestX) / (biggestX - lowestX));
ipAddress = ipAddress.concat(partIP + "");
generatedIPAddresses.add(ipAddress);
}
}
public String getNextIPAddress() {
if (generatedIPAddresses.size() > 0)
return generatedIPAddresses.remove(0);
else
return "0.0.0.0";
}
}