You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(12) |
Dec
(41) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(25) |
Feb
(54) |
Mar
(63) |
Apr
(52) |
May
(17) |
Jun
(3) |
Jul
(3) |
Aug
(5) |
Sep
(49) |
Oct
(50) |
Nov
(34) |
Dec
(14) |
2009 |
Jan
(9) |
Feb
(15) |
Mar
(38) |
Apr
(12) |
May
(35) |
Jun
(20) |
Jul
(2) |
Aug
(7) |
Sep
(36) |
Oct
(24) |
Nov
(2) |
Dec
(2) |
2010 |
Jan
(14) |
Feb
(1) |
Mar
(36) |
Apr
(2) |
May
(4) |
Jun
(6) |
Jul
(35) |
Aug
(11) |
Sep
(8) |
Oct
(3) |
Nov
|
Dec
(1) |
2011 |
Jan
(11) |
Feb
(12) |
Mar
(3) |
Apr
(7) |
May
(12) |
Jun
(8) |
Jul
|
Aug
(3) |
Sep
(4) |
Oct
|
Nov
(2) |
Dec
(4) |
2012 |
Jan
(2) |
Feb
(1) |
Mar
(14) |
Apr
(5) |
May
(28) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(4) |
Dec
(1) |
2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <ni...@us...> - 2009-10-27 00:37:00
|
Revision: 637 http://mspsim.svn.sourceforge.net/mspsim/?rev=637&view=rev Author: nifi Date: 2009-10-27 00:36:52 +0000 (Tue, 27 Oct 2009) Log Message: ----------- * added kill() to CommandContext to kill a command chain * fixed CommandHandler to set exited flag in CommandContext after a command has been stopped Modified Paths: -------------- mspsim/se/sics/mspsim/cli/CommandContext.java mspsim/se/sics/mspsim/cli/CommandHandler.java Modified: mspsim/se/sics/mspsim/cli/CommandContext.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandContext.java 2009-10-27 00:36:38 UTC (rev 636) +++ mspsim/se/sics/mspsim/cli/CommandContext.java 2009-10-27 00:36:52 UTC (rev 637) @@ -39,10 +39,22 @@ this.err = err; } - Command getCommand( ) { + Command getCommand() { return command; } - + + // Called by CommandHandler to stop this command. + void stopCommand() { + if (!exited) { + exited = true; + + if (command instanceof AsyncCommand) { + AsyncCommand ac = (AsyncCommand) command; + ac.stopCommand(this); + } + } + } + String getCommandLine() { return commandLine; } @@ -65,6 +77,14 @@ commandHandler.exit(this, exitCode, pid); } + // Requests that this command chain should be killed. Used by for example + // FileTarget to close all connected commands when the file is closed. + void kill() { + if (!exited) { + commandHandler.exit(this, -9, pid); + } + } + public MapTable getMapTable() { return mapTable; } @@ -112,12 +132,11 @@ int register = Integer.parseInt(reg); if (register >= 0 && register <= 15) { return register; - } else { - err.println("illegal register: " + symbol); } } catch (Exception e) { - err.println("illegal register: " + symbol); + // Ignore } + err.println("illegal register: " + symbol); return -1; } Modified: mspsim/se/sics/mspsim/cli/CommandHandler.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandHandler.java 2009-10-27 00:36:38 UTC (rev 636) +++ mspsim/se/sics/mspsim/cli/CommandHandler.java 2009-10-27 00:36:52 UTC (rev 637) @@ -98,11 +98,7 @@ if (error) { // Stop any commands that have been started for (index++; index < commands.length; index++) { - Command command = commands[index].getCommand(); - if (command instanceof AsyncCommand && !commands[index].hasExited()) { - AsyncCommand ac = (AsyncCommand) command; - ac.stopCommand(commands[index]); - } + commands[index].stopCommand(); } return 1; } else if (pid >= 0) { @@ -275,8 +271,8 @@ } public void exit(CommandContext commandContext, int exitCode, int pid) { - if (pid >= 0) { - removePid(pid); + if (pid < 0 || !removePid(pid)) { + commandContext.stopCommand(); } } @@ -298,12 +294,7 @@ private boolean exitCommands(CommandContext[] contexts) { if (contexts != null) { for (int i = 0; i < contexts.length; i++) { - Command command = contexts[i].getCommand(); - // Stop any commands that have not yet been stopped... - if (command instanceof AsyncCommand && !contexts[i].hasExited()) { - AsyncCommand ac = (AsyncCommand) command; - ac.stopCommand(contexts[i]); - } + contexts[i].stopCommand(); } return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2009-10-27 00:36:47
|
Revision: 636 http://mspsim.svn.sourceforge.net/mspsim/?rev=636&view=rev Author: nifi Date: 2009-10-27 00:36:38 +0000 (Tue, 27 Oct 2009) Log Message: ----------- added window name Modified Paths: -------------- mspsim/se/sics/mspsim/platform/AbstractNodeGUI.java mspsim/se/sics/mspsim/platform/esb/ESBGui.java mspsim/se/sics/mspsim/platform/sky/SkyGui.java Modified: mspsim/se/sics/mspsim/platform/AbstractNodeGUI.java =================================================================== --- mspsim/se/sics/mspsim/platform/AbstractNodeGUI.java 2009-10-26 23:03:19 UTC (rev 635) +++ mspsim/se/sics/mspsim/platform/AbstractNodeGUI.java 2009-10-27 00:36:38 UTC (rev 636) @@ -58,6 +58,7 @@ private static final long serialVersionUID = 1435276301923987019L; + private final String windowName; private final String nodeImageName; private String name; @@ -68,7 +69,9 @@ private ServiceComponent.Status status = Status.STOPPED; - protected AbstractNodeGUI(String imageName) { + + protected AbstractNodeGUI(String windowName, String imageName) { + this.windowName = windowName; this.nodeImageName = imageName; setBackground(Color.black); setOpaque(true); @@ -120,7 +123,7 @@ nodeImage.getIconHeight())); WindowManager wm = (WindowManager) registry.getComponent("windowManager"); - window = wm.createWindow("NodeGUI"); + window = wm.createWindow(windowName); window.add(this); startGUI(); Modified: mspsim/se/sics/mspsim/platform/esb/ESBGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBGui.java 2009-10-26 23:03:19 UTC (rev 635) +++ mspsim/se/sics/mspsim/platform/esb/ESBGui.java 2009-10-27 00:36:38 UTC (rev 636) @@ -96,7 +96,7 @@ private TargetDataLine inDataLine; public ESBGui(ESBNode esbNode) { - super("images/esb.jpg"); + super("ESBGui", "images/esb.jpg"); this.node = esbNode; } Modified: mspsim/se/sics/mspsim/platform/sky/SkyGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2009-10-26 23:03:19 UTC (rev 635) +++ mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2009-10-27 00:36:38 UTC (rev 636) @@ -75,7 +75,7 @@ private MoteIVNode node; public SkyGui(MoteIVNode node) { - super("images/sky.jpg"); + super("SkyGui", "images/sky.jpg"); this.node = node; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2009-10-26 23:03:35
|
Revision: 635 http://mspsim.svn.sourceforge.net/mspsim/?rev=635&view=rev Author: nifi Date: 2009-10-26 23:03:19 +0000 (Mon, 26 Oct 2009) Log Message: ----------- added base class for node gui and fixed ESBGui to work with managed windows Modified Paths: -------------- mspsim/se/sics/mspsim/platform/esb/ESBGui.java mspsim/se/sics/mspsim/platform/esb/ESBNode.java mspsim/se/sics/mspsim/platform/sky/SkyGui.java Added Paths: ----------- mspsim/se/sics/mspsim/platform/AbstractNodeGUI.java Added: mspsim/se/sics/mspsim/platform/AbstractNodeGUI.java =================================================================== --- mspsim/se/sics/mspsim/platform/AbstractNodeGUI.java (rev 0) +++ mspsim/se/sics/mspsim/platform/AbstractNodeGUI.java 2009-10-26 23:03:19 UTC (rev 635) @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2009, 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. + * + * This file is part of MSPSim. + * + * $Id$ + * + * ----------------------------------------------------------------- + * + * AbstractNodeGUI + * + * Authors : Joakim Eriksson, Niclas Finne + * Created : 9 okt 2009 + * Updated : $Date$ + * $Revision$ + */ + +package se.sics.mspsim.platform; +import java.awt.Color; +import java.awt.Dimension; +import java.io.File; +import java.net.URL; + +import javax.swing.ImageIcon; +import javax.swing.JComponent; + +import se.sics.mspsim.ui.ManagedWindow; +import se.sics.mspsim.ui.WindowManager; +import se.sics.mspsim.util.ComponentRegistry; +import se.sics.mspsim.util.ServiceComponent; + +public abstract class AbstractNodeGUI extends JComponent implements ServiceComponent { + + private static final long serialVersionUID = 1435276301923987019L; + + private final String nodeImageName; + + private String name; + private ComponentRegistry registry; + + private ImageIcon nodeImage; + private ManagedWindow window; + + private ServiceComponent.Status status = Status.STOPPED; + + protected AbstractNodeGUI(String imageName) { + this.nodeImageName = imageName; + setBackground(Color.black); + setOpaque(true); + } + + public Status getStatus() { + return status; + } + + public String getName() { + return name; + } + + protected ImageIcon getNodeImage() { + return nodeImage; + } + + protected ComponentRegistry getRegistry() { + return registry; + } + + public final void init(String name, ComponentRegistry registry) { + this.name = name; + this.registry = registry; + } + + public final void start() { + File fp = new File(nodeImageName); + if (!fp.canRead()) { + URL imageURL = getImageURL(nodeImageName); + if (imageURL == null + && !nodeImageName.startsWith("images/") + && !nodeImageName.startsWith("/images/")) { + imageURL = getImageURL("images/" + nodeImageName); + } + if (imageURL != null) { + nodeImage = new ImageIcon(imageURL); + } else { + throw new IllegalStateException("image not found: " + nodeImageName); + } + } else { + nodeImage = new ImageIcon(nodeImageName); + } + if (nodeImage.getIconWidth() == 0 || nodeImage.getIconHeight() == 0) { + // Image not found + throw new IllegalStateException("image not found: " + nodeImageName); + } + setPreferredSize(new Dimension(nodeImage.getIconWidth(), + nodeImage.getIconHeight())); + + WindowManager wm = (WindowManager) registry.getComponent("windowManager"); + window = wm.createWindow("NodeGUI"); + window.add(this); + + startGUI(); + + status = Status.STARTED; + window.setVisible(true); + } + + private URL getImageURL(String image) { + URL imageURL = getClass().getResource(image); + if (imageURL == null && !image.startsWith("/")) { + imageURL = getClass().getResource("/" + image); + } + return imageURL; + } + + public final void stop() { + status = Status.STOPPED; + stopGUI(); + } + + protected abstract void startGUI(); + + protected abstract void stopGUI(); + +} Property changes on: mspsim/se/sics/mspsim/platform/AbstractNodeGUI.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + LF Modified: mspsim/se/sics/mspsim/platform/esb/ESBGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBGui.java 2009-10-26 22:51:29 UTC (rev 634) +++ mspsim/se/sics/mspsim/platform/esb/ESBGui.java 2009-10-26 23:03:19 UTC (rev 635) @@ -41,38 +41,36 @@ package se.sics.mspsim.platform.esb; import java.awt.Color; -import java.awt.Dimension; import java.awt.Graphics; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; +import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; -import java.net.URL; + import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.TargetDataLine; import javax.swing.ImageIcon; -import javax.swing.JComponent; -import javax.swing.JFrame; + import se.sics.mspsim.chip.Beeper; import se.sics.mspsim.core.ADC12; import se.sics.mspsim.core.ADCInput; import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.USART; +import se.sics.mspsim.platform.AbstractNodeGUI; import se.sics.mspsim.ui.SerialMon; -import se.sics.mspsim.ui.WindowUtils; -public class ESBGui extends JComponent implements ADCInput { +public class ESBGui extends AbstractNodeGUI implements ADCInput { private static final long serialVersionUID = -139331418649524704L; - public static final int GREEN_X = 3; - public static final int YELLOW_X = 10; - public static final int RED_X = 17; + public static final int GREEN_X = 2; + public static final int YELLOW_X = 9; + public static final int RED_X = 16; public static final int LED_Y = 4; + private static final Rectangle LED_BOUNDS = new Rectangle(GREEN_X - 2, LED_Y - 4, RED_X + 6, LED_Y + 10); public static final Color RED_TRANS = new Color(0xff,0x40,0x40,0xa0); public static final Color YELLOW_TRANS = new Color(0xff, 0xff, 0x00, 0xa0); @@ -85,11 +83,12 @@ private static final float SAMPLE_RATE = 22050; private static final int DL_BUFFER_SIZE = 2200; + private MouseMotionAdapter mouseMotionListener; + private MouseAdapter mouseListener; + private SerialMon serial; Beeper beeper; - private ImageIcon esbImage; - private JFrame window; private ESBNode node; private boolean buttonDown = false; private boolean resetDown = false; @@ -97,45 +96,13 @@ private TargetDataLine inDataLine; public ESBGui(ESBNode esbNode) { - this.node = esbNode; + super("images/esb.jpg"); + this.node = esbNode; + } - setBackground(Color.black); - setOpaque(true); - - URL imageURL = ESBGui.class.getResource("images/esb.jpg"); - if (imageURL == null) { - imageURL = ESBGui.class.getResource("/images/esb.jpg"); - } - if (imageURL != null) { - esbImage = new ImageIcon(imageURL); - } else { - esbImage = new ImageIcon("images/esb.jpg"); - } - if (esbImage.getIconWidth() == 0 || esbImage.getIconHeight() == 0) { - // Image not found - throw new IllegalStateException("image not found"); - } - setPreferredSize(new Dimension(esbImage.getIconWidth(), - esbImage.getIconHeight())); - - window = new JFrame("ESB"); -// window.setSize(190,240); - window.add(this); - WindowUtils.restoreWindowBounds("ESBGui", window); - WindowUtils.addSaveOnShutdown("ESBGui", window); - window.setVisible(true); - - window.addKeyListener(new KeyAdapter() { - - public void keyPressed(KeyEvent key) { - if (key.getKeyChar() == 'd') { - node.setDebug(!node.getDebug()); - } - } - - }); - - addMouseMotionListener(new MouseMotionAdapter() { + @Override + protected void startGUI() { + mouseMotionListener = new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { // System.out.println("Mouse moved: " + e.getX() + "," + e.getY()); int x = e.getX(); @@ -143,46 +110,62 @@ node.setPIR(x > 18 && x < 80 && y > 35 && y < 100); node.setVIB(x > 62 && x < 95 && y > 160 && y < 178); } - }); - addMouseListener(new MouseAdapter() { + }; + addMouseMotionListener(mouseMotionListener); + + mouseListener = new MouseAdapter() { // For the button sensor on the ESB nodes. public void mousePressed(MouseEvent e) { - int x = e.getX(); - int y = e.getY(); - if (y > 152 && y < 168) { - if (x > 0 && x < 19) { - node.setButton(buttonDown = true); - } else { - int w = esbImage.getIconWidth(); - if (x > w - 20 && x < w) { - resetDown = true; + if (e.getButton() == MouseEvent.BUTTON1) { + int x = e.getX(); + int y = e.getY(); +// System.err.println("PRESSED AT " + x + "," + y +// + " IMAGE=" + getNodeImage().getIconWidth() +// + "x" + getNodeImage().getIconHeight() + +// " SIZE=" + getWidth() + "x" + getHeight()); + + if (y > 152 && y < 168) { + if (x > 0 && x < 19) { + buttonDown = true; + node.setButton(true); + } else { + int w = getNodeImage().getIconWidth(); + if (x > w - 20 && x < w) { + resetDown = true; + } } } } } public void mouseReleased(MouseEvent e) { - if (buttonDown) { - node.setButton(buttonDown = false); - } else if (resetDown) { - int x = e.getX(); - int y = e.getY(); - if (y > 152 && y < 168) { - int w = esbImage.getIconWidth(); - if (x > w - 20 && x < w) { - node.getCPU().reset(); + if (e.getButton() == MouseEvent.BUTTON1) { + if (buttonDown) { + buttonDown = false; + node.setButton(false); + } else if (resetDown) { + int x = e.getX(); + int y = e.getY(); + if (y > 152 && y < 168) { + int w = getNodeImage().getIconWidth(); + if (x > w - 20 && x < w) { + node.getCPU().reset(); + } } + resetDown = false; } - resetDown = false; } } - }); + }; + addMouseListener(mouseListener); // Add some windows for listening to serial output MSP430 cpu = node.getCPU(); IOUnit usart = cpu.getIOUnit("USART 1"); if (usart instanceof USART) { - serial = new SerialMon((USART)usart, "RS232 Port Output"); + if (serial == null) { + serial = new SerialMon((USART)usart, "RS232 Port Output"); + } ((USART) usart).setUSARTListener(serial); } @@ -190,31 +173,41 @@ if (adc instanceof ADC12) { ((ADC12) adc).setADCInput(0, this); } - + beeper = new Beeper(); - - // Just a test... TODO: remove!!! - AudioFormat af = new AudioFormat(SAMPLE_RATE, 16, 1, true, false); - DataLine.Info dlin = - new DataLine.Info(TargetDataLine.class, af, DL_BUFFER_SIZE); + // Just a test... TODO: remove!!! try { + AudioFormat af = new AudioFormat(SAMPLE_RATE, 16, 1, true, false); + DataLine.Info dlin = + new DataLine.Info(TargetDataLine.class, af, DL_BUFFER_SIZE); inDataLine = (TargetDataLine) AudioSystem.getLine(dlin); if (inDataLine == null) { - System.out.println("No in dataline"); + System.out.println("No input dataline"); } else { System.out.println("Format: " + inDataLine.getFormat()); inDataLine.open(inDataLine.getFormat(), DL_BUFFER_SIZE); inDataLine.start(); } } catch (Exception e) { - System.out.println("Problem while getting data line "); - e.printStackTrace(); + System.err.println("Failed to get audio data line: " + e.getMessage()); } } - byte[] data = new byte[4]; + @Override + protected void stopGUI() { + removeMouseMotionListener(mouseMotionListener); + removeMouseListener(mouseListener); + + // TODO cleanup + } + + public void ledsChanged() { + repaint(LED_BOUNDS); + } + + private byte[] data = new byte[4]; public int nextData() { if (inDataLine != null) { inDataLine.read(data, 0, 4); @@ -226,6 +219,7 @@ protected void paintComponent(Graphics g) { Color old = g.getColor(); int w = getWidth(), h = getHeight(); + ImageIcon esbImage = getNodeImage(); int iw = esbImage.getIconWidth(), ih = esbImage.getIconHeight(); esbImage.paintIcon(this, g, 0, 0); // Clear all areas not covered by the image Modified: mspsim/se/sics/mspsim/platform/esb/ESBNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2009-10-26 22:51:29 UTC (rev 634) +++ mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2009-10-26 23:03:19 UTC (rev 635) @@ -51,6 +51,7 @@ import se.sics.mspsim.extutil.jfreechart.DataSourceSampler; import se.sics.mspsim.platform.GenericNode; import se.sics.mspsim.util.ArgumentManager; +import se.sics.mspsim.util.OperatingModeStatistics; public class ESBNode extends GenericNode implements PortListener { @@ -75,9 +76,8 @@ public boolean yellowLed; private TR1001 radio; - public ESBGui gui; + private ESBGui gui; - /** * Creates a new <code>ESBNode</code> instance. * @@ -109,16 +109,10 @@ if (source == port2) { // System.out.println("ESBNode.PORT2: 0x" + Integer.toString(data,16)); redLed = (data & RED_LED) == 0; - if (DEBUG && greenLed != ((data & GREEN_LED) == 0)) { - System.out.println("Green toggled!"); - } greenLed = (data & GREEN_LED) == 0; - if (DEBUG && yellowLed != ((data & YELLOW_LED) == 0)) { - System.out.println("Yellow toggled!"); - } yellowLed = (data & YELLOW_LED) == 0; if (gui != null) { - gui.repaint(); + gui.ledsChanged(); gui.beeper.beepOn((data & BEEPER) != 0); } @@ -167,10 +161,13 @@ if (!config.getPropertyAsBoolean("nogui", true)) { gui = new ESBGui(this); + registry.registerComponent("nodegui", gui); // A HACK for some "graphs"!!! DataChart dataChart = new DataChart(registry, "Duty Cycle", "Duty Cycle"); + registry.registerComponent("dutychart", dataChart); DataSourceSampler dss = dataChart.setupChipFrame(cpu); + dataChart.addDataSource(dss, "LEDS", stats.getDataSource(getName(), 0, OperatingModeStatistics.OP_INVERT)); dataChart.addDataSource(dss, "Listen", stats.getDataSource("TR1001", TR1001.MODE_RX_ON)); dataChart.addDataSource(dss, "Transmit", stats.getDataSource("TR1001", TR1001.MODE_TXRX_ON)); dataChart.addDataSource(dss, "CPU", stats.getDataSource("MSP430 Core", MSP430.MODE_ACTIVE)); Modified: mspsim/se/sics/mspsim/platform/sky/SkyGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2009-10-26 22:51:29 UTC (rev 634) +++ mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2009-10-26 23:03:19 UTC (rev 635) @@ -41,31 +41,22 @@ package se.sics.mspsim.platform.sky; import java.awt.Color; -import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.net.URL; + import javax.swing.ImageIcon; -import javax.swing.JComponent; + import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.USART; -import se.sics.mspsim.ui.ManagedWindow; +import se.sics.mspsim.platform.AbstractNodeGUI; import se.sics.mspsim.ui.SerialMon; -import se.sics.mspsim.ui.WindowManager; -import se.sics.mspsim.util.ComponentRegistry; -import se.sics.mspsim.util.ServiceComponent; -public class SkyGui extends JComponent implements ServiceComponent { +public class SkyGui extends AbstractNodeGUI { - /** - * - */ private static final long serialVersionUID = 7753659717805292786L; - private ServiceComponent.Status status = Status.STOPPED; - public static final int GREEN_Y = 40; public static final int BLUE_Y = 46; public static final int RED_Y = 34; @@ -81,47 +72,14 @@ private SerialMon serial; - private ImageIcon skyImage; - private ManagedWindow window; private MoteIVNode node; - private ComponentRegistry registry; - - private String name; - public SkyGui(MoteIVNode node) { + super("images/sky.jpg"); this.node = node; } - public String getName() { - return name; - } - - public void start() { - setBackground(Color.black); - setOpaque(true); - - URL imageURL = SkyGui.class.getResource("images/sky.jpg"); - if (imageURL == null) { - imageURL = SkyGui.class.getResource("/images/sky.jpg"); - } - if (imageURL != null) { - skyImage = new ImageIcon(imageURL); - } else { - skyImage = new ImageIcon("images/sky.jpg"); - } - if (skyImage.getIconWidth() == 0 || skyImage.getIconHeight() == 0) { - // Image not found - throw new IllegalStateException("image not found"); - } - setPreferredSize(new Dimension(skyImage.getIconWidth(), - skyImage.getIconHeight())); - - WindowManager wm = (WindowManager) registry.getComponent("windowManager"); - window = wm.createWindow("SkyGui"); - window.add(this); - window.setVisible(true); - + protected void startGUI() { MouseAdapter mouseHandler = new MouseAdapter() { private boolean buttonDown = false; @@ -166,11 +124,11 @@ serial = new SerialMon((USART)usart, "USART1 Port Output"); ((USART) usart).setUSARTListener(serial); } - status = Status.STARTED; } protected void paintComponent(Graphics g) { Color old = g.getColor(); + ImageIcon skyImage = getNodeImage(); int w = getWidth(), h = getHeight(); int iw = skyImage.getIconWidth(), ih = skyImage.getIconHeight(); skyImage.paintIcon(this, g, 0, 0); @@ -205,16 +163,7 @@ g.setColor(old); } - public Status getStatus() { - return status; + protected void stopGUI() { } - public void init(String name, ComponentRegistry registry) { - this.name = name; - this.registry = registry; - } - - public void stop() { - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2009-10-26 22:51:51
|
Revision: 634 http://mspsim.svn.sourceforge.net/mspsim/?rev=634&view=rev Author: nifi Date: 2009-10-26 22:51:29 +0000 (Mon, 26 Oct 2009) Log Message: ----------- only clear profiler if profiler has been set Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-10-26 11:08:13 UTC (rev 633) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-10-26 22:51:29 UTC (rev 634) @@ -580,7 +580,9 @@ // Needs to be last since these can add events... resetIOUnits(); - profiler.clearProfile(); + if (profiler != null) { + profiler.clearProfile(); + } } public void setWarningMode(EmulationLogger.WarningMode mode) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-26 11:08:22
|
Revision: 633 http://mspsim.svn.sourceforge.net/mspsim/?rev=633&view=rev Author: joxe Date: 2009-10-26 11:08:13 +0000 (Mon, 26 Oct 2009) Log Message: ----------- moved event execution to after CPU instruction execution Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-10-26 10:53:49 UTC (rev 632) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-10-26 11:08:13 UTC (rev 633) @@ -814,12 +814,6 @@ int pc = readRegister(PC); long startCycles = cycles; - // ------------------------------------------------------------------- - // Event processing - // ------------------------------------------------------------------- - while (cycles >= nextEventCycles) { - executeEvents(); - } // ------------------------------------------------------------------- // Interrupt processing [after the last instruction was executed] @@ -832,6 +826,16 @@ if (cpuOff || flash.blocksCPU()) { // System.out.println("Jumping: " + (nextIOTickCycles - cycles)); // nextEventCycles must exist, otherwise CPU can not wake up!? + + // If CPU is not active we must run the events here!!! + // this can trigger interrupts that wake the CPU + // ------------------------------------------------------------------- + // Event processing + // ------------------------------------------------------------------- + while (cycles >= nextEventCycles) { + executeEvents(); + } + if (maxCycles >= 0 && maxCycles < nextEventCycles) { // Should it just freeze or take on extra cycle step if cycles > max? cycles = cycles < maxCycles ? maxCycles : cycles; @@ -1363,6 +1367,13 @@ } //System.out.println("CYCLES AFTER: " + cycles); + + // ------------------------------------------------------------------- + // Event processing (when CPU is awake) + // ------------------------------------------------------------------- + while (cycles >= nextEventCycles) { + executeEvents(); + } cpuCycles += cycles - startCycles; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-26 10:54:02
|
Revision: 632 http://mspsim.svn.sourceforge.net/mspsim/?rev=632&view=rev Author: joxe Date: 2009-10-26 10:53:49 +0000 (Mon, 26 Oct 2009) Log Message: ----------- fixed while around event execution to avoid delayed execution of events Modified Paths: -------------- mspsim/se/sics/mspsim/core/ADC12.java mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/core/ADC12.java =================================================================== --- mspsim/se/sics/mspsim/core/ADC12.java 2009-10-25 22:27:59 UTC (rev 631) +++ mspsim/se/sics/mspsim/core/ADC12.java 2009-10-26 10:53:49 UTC (rev 632) @@ -244,6 +244,7 @@ adc12Pos = (adc12Pos + 1) & 0x0f; } int delay = adcDiv * (shTime0 + 13); + core.scheduleTimeEvent(adcTrigger, adcTrigger.time + delay); } Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-10-25 22:27:59 UTC (rev 631) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-10-26 10:53:49 UTC (rev 632) @@ -43,6 +43,7 @@ import java.io.PrintStream; import java.util.ArrayList; +import se.sics.mspsim.core.EmulationLogger.WarningMode; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.MapEntry; import se.sics.mspsim.util.MapTable; @@ -524,6 +525,11 @@ if (nextEventCycles > nextVTimeEventCycles) { nextEventCycles = nextVTimeEventCycles; } + /* Warn if someone schedules a time backwards in time... */ + if (cycles > nextVTimeEventCycles) { + logger.warning(this, "Scheduling time event backwards in time!!!"); + throw new IllegalStateException("Cycles are passed desired future time..."); + } } } @@ -811,7 +817,7 @@ // ------------------------------------------------------------------- // Event processing // ------------------------------------------------------------------- - if (cycles >= nextEventCycles) { + while (cycles >= nextEventCycles) { executeEvents(); } @@ -1357,8 +1363,9 @@ } //System.out.println("CYCLES AFTER: " + cycles); - + cpuCycles += cycles - startCycles; + return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2009-10-25 22:28:07
|
Revision: 631 http://mspsim.svn.sourceforge.net/mspsim/?rev=631&view=rev Author: nifi Date: 2009-10-25 22:27:59 +0000 (Sun, 25 Oct 2009) Log Message: ----------- Changed simulator thread to normal priority since it is sometimes started from the event dispatcher Modified Paths: -------------- mspsim/se/sics/mspsim/platform/GenericNode.java Modified: mspsim/se/sics/mspsim/platform/GenericNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/GenericNode.java 2009-10-25 22:07:20 UTC (rev 630) +++ mspsim/se/sics/mspsim/platform/GenericNode.java 2009-10-25 22:27:59 UTC (rev 631) @@ -239,7 +239,11 @@ public void start() { if (!cpu.isRunning()) { - new Thread(this).start(); + Thread thread = new Thread(this); + // Set this thread to normal priority in case the start method was called + // from the higher priority AWT thread. + thread.setPriority(Thread.NORM_PRIORITY); + thread.start(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-25 22:07:31
|
Revision: 630 http://mspsim.svn.sourceforge.net/mspsim/?rev=630&view=rev Author: joxe Date: 2009-10-25 22:07:20 +0000 (Sun, 25 Oct 2009) Log Message: ----------- fixed bug in stepmicros Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430.java Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2009-10-23 22:28:31 UTC (rev 629) +++ mspsim/se/sics/mspsim/core/MSP430.java 2009-10-25 22:07:20 UTC (rev 630) @@ -259,31 +259,25 @@ boolean emuOP = false; - if (maxCycles > 0) { - /* max one emulated instruction or maxCycles if in LPM */ - while (cycles < maxCycles && !(emuOP = emulateOP(maxCycles))) { - } + while (cycles < maxCycles) { + if (emuOP = emulateOP(maxCycles)) { + if (execCounter != null) { + execCounter[reg[PC]]++; + } + if (trace != null) { + trace[tracePos++] = reg[PC]; + if (tracePos > trace.length) + tracePos = 0; + } + } } - if (emuOP) { - if ((instCtr % 10000007) == 0 && !debug) { - printCPUSpeed(reg[PC]); - } - - if (execCounter != null) { - execCounter[reg[PC]]++; - } - if (trace != null) { - trace[tracePos++] = reg[PC]; - if (tracePos > trace.length) - tracePos = 0; - } - } if (cpuOff) { lastReturnedMicros = (1000000 * (nextEventCycles - cycles)) / dcoFrq; } else { lastReturnedMicros = 0; } + return lastReturnedMicros; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-23 22:28:37
|
Revision: 629 http://mspsim.svn.sourceforge.net/mspsim/?rev=629&view=rev Author: joxe Date: 2009-10-23 22:28:31 +0000 (Fri, 23 Oct 2009) Log Message: ----------- fixed minor bug in microsecond scheduling Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/cli/NetCommands.java mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-23 15:33:01 UTC (rev 628) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-23 22:28:31 UTC (rev 629) @@ -529,7 +529,7 @@ int size = cpu.getTraceSize(); DisAsm disAsm = cpu.getDisAsm(); for (int i = 0; i < size; i++) { - int pc = cpu.getBackTrace(i); + int pc = cpu.getBackTrace(size - 1 - i); DbgInstruction inst = disAsm.getDbgInstruction(pc, cpu); inst.setPos(pc); System.out.println(inst); Modified: mspsim/se/sics/mspsim/cli/NetCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/NetCommands.java 2009-10-23 15:33:01 UTC (rev 628) +++ mspsim/se/sics/mspsim/cli/NetCommands.java 2009-10-23 22:28:31 UTC (rev 629) @@ -20,7 +20,6 @@ private IPStack ipStack; public void setupCommands(final ComponentRegistry registry, CommandHandler handler) { - handler.registerCommand("ipstack", new BasicLineCommand("setup 802.15.4/IP stack", "") { CC2420PacketHandler listener; CommandContext context; Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2009-10-23 15:33:01 UTC (rev 628) +++ mspsim/se/sics/mspsim/core/MSP430.java 2009-10-23 22:28:31 UTC (rev 629) @@ -193,6 +193,13 @@ */ long lastReturnedMicros; long lastMicrosCycles; + boolean microClockReady = false; + + /* when DCO has changed speed, this method will be called */ + protected void dcoReset() { + microClockReady = false; + } + /* * Perform a single step (even if in LPM) but no longer than to maxCycles + 1 instr * Note: jumpMicros just jump the clock until that time @@ -204,14 +211,15 @@ } if (jumpMicros < 0) { - throw new IllegalArgumentException("Can not execute a shorter time than 1 micro second: " + + throw new IllegalArgumentException("Can not jump a negative time: " + jumpMicros); } /* quick hack - if microdelta == 0 => ensure that we have correct zery cycles */ - if (lastMicrosDelta == 0) { + if (!microClockReady) { System.out.println("Setting cycles to zero at " + cycles); lastMicrosCycles = cycles; + microClockReady = true; } // Note: will be reset during DCO-syncs... => problems ??? Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-10-23 15:33:01 UTC (rev 628) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-10-23 22:28:31 UTC (rev 629) @@ -416,8 +416,13 @@ // " current: " + frequency + " DCO_FAC = " + currentDCOFactor); if (DEBUG) System.out.println("Set smclkFrq: " + smclkFrq); + dcoReset(); } + /* called after dcoReset */ + protected void dcoReset() { + } + // returns global time counted in max speed of DCOs (~5Mhz) public long getTime() { long diff = cycles - lastCyclesTime; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-23 15:33:12
|
Revision: 628 http://mspsim.svn.sourceforge.net/mspsim/?rev=628&view=rev Author: joxe Date: 2009-10-23 15:33:01 +0000 (Fri, 23 Oct 2009) Log Message: ----------- added stepMicro CLI command + method for more efficient scheduling from simulation frameworks Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-09 21:30:05 UTC (rev 627) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-23 15:33:01 UTC (rev 628) @@ -265,6 +265,28 @@ return 0; } }); + + ch.registerCommand("stepmicro", new BasicCommand("single the CPU specified no micros", "<micro skip> <micro step>") { + public int executeCommand(CommandContext context) { + int nr = context.getArgumentCount() > 0 ? context.getArgumentAsInt(0) : 1; + long cyc = cpu.cycles; + if (cpu.isRunning()) { + context.err.println("Can not single step when emulation is running."); + return -1; + } + long nxt = 0; + try { + nxt = cpu.stepMicros(context.getArgumentAsLong(0), context.getArgumentAsLong(1)); + } catch (Exception e) { + e.printStackTrace(context.out); + } + context.out.println("CPU stepped to: $" + Utils.hex16(cpu.readRegister(0)) + + " in " + (cpu.cycles - cyc) + " cycles (" + cpu.cycles + ") - next exec time: " + nxt); + return 0; + } + }); + + ch.registerCommand("stack", new BasicCommand("show stack info", "") { public int executeCommand(CommandContext context) { int stackEnd = context.getMapTable().heapStartAddress; Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2009-10-09 21:30:05 UTC (rev 627) +++ mspsim/se/sics/mspsim/core/MSP430.java 2009-10-23 15:33:01 UTC (rev 628) @@ -42,7 +42,10 @@ package se.sics.mspsim.core; import java.io.PrintStream; -import se.sics.mspsim.util.*; +import se.sics.mspsim.util.ArrayUtils; +import se.sics.mspsim.util.ComponentRegistry; +import se.sics.mspsim.util.MapTable; +import se.sics.mspsim.util.SimpleProfiler; public class MSP430 extends MSP430Core { @@ -147,7 +150,7 @@ } public long step() throws EmulationException { - return step(0); + return stepMicros(1, 1); } public long stepInstructions(int count) throws EmulationException { @@ -185,14 +188,56 @@ return cycles; } + /* this represents the micros time that was "promised" last time */ + /* NOTE: this is a delta compared to "current micros" + */ + long lastReturnedMicros; + long lastMicrosCycles; /* * Perform a single step (even if in LPM) but no longer than to maxCycles + 1 instr + * Note: jumpMicros just jump the clock until that time + * executeMicros also check eventQ, etc and executes instructions */ - public long step(long maxCycles) throws EmulationException { + public long stepMicros(long jumpMicros, long executeMicros) throws EmulationException { if (isRunning()) { throw new IllegalStateException("step not possible when CPU is running"); } + if (jumpMicros < 0) { + throw new IllegalArgumentException("Can not execute a shorter time than 1 micro second: " + + jumpMicros); + } + /* quick hack - if microdelta == 0 => ensure that we have correct zery cycles + */ + if (lastMicrosDelta == 0) { + System.out.println("Setting cycles to zero at " + cycles); + lastMicrosCycles = cycles; + } + + // Note: will be reset during DCO-syncs... => problems ??? + lastMicrosDelta += jumpMicros; + + /* check that we did not miss any events (by comparing with last return value) */ + long maxCycles = lastMicrosCycles + (lastMicrosDelta * dcoFrq) / 1000000; + if (cpuOff) { + if(maxCycles > nextEventCycles) { + /* back this time again... */ + lastMicrosDelta -= jumpMicros; + throw new IllegalArgumentException("Jumping to a time that is further than possible in LPM maxCycles:" + + maxCycles + " cycles: " + cycles); + } + } else if (maxCycles > cycles) { + /* back this time again... */ + lastMicrosDelta -= jumpMicros; + throw new IllegalArgumentException("Jumping to a time that is further than possible not LPM maxCycles:" + + maxCycles + " cycles: " + cycles); + } + + /* run until this cycle time */ + maxCycles = lastMicrosCycles + ((lastMicrosDelta + executeMicros) * dcoFrq) / 1000000; + System.out.println("Current cycles: " + cycles + " additional micros: " + (jumpMicros) + + " exec micros: " + executeMicros + " => Execute until cycles: " + maxCycles); + // ------------------------------------------------------------------- // Debug information // ------------------------------------------------------------------- @@ -210,11 +255,6 @@ /* max one emulated instruction or maxCycles if in LPM */ while (cycles < maxCycles && !(emuOP = emulateOP(maxCycles))) { } - } else { - int ctr = 0; - while (!(emuOP = emulateOP(-1)) && ctr++ < 10000) { - /* Stuck in LPM - hopefully not more than 10000 times*/ - } } if (emuOP) { @@ -231,9 +271,14 @@ tracePos = 0; } } - return cycles; -} - + if (cpuOff) { + lastReturnedMicros = (1000000 * (nextEventCycles - cycles)) / dcoFrq; + } else { + lastReturnedMicros = 0; + } + return lastReturnedMicros; + } + public void stop() { setRunning(false); } Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-10-09 21:30:05 UTC (rev 627) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-10-23 15:33:01 UTC (rev 628) @@ -102,22 +102,23 @@ InterruptHandler servicedInterruptUnit = null; private boolean interruptsEnabled = false; - private boolean cpuOff = false; + protected boolean cpuOff = false; // Not private since they are needed (for fast access...) - private int dcoFrq = 2500000; + protected int dcoFrq = 2500000; int aclkFrq = 32768; int smclkFrq = dcoFrq; long lastCyclesTime = 0; long lastVTime = 0; long currentTime = 0; + long lastMicrosDelta; double currentDCOFactor = 1.0; // Clk A can be "captured" by timers - needs to be handled close to CPU...? private int clkACaptureMode = CLKCAPTURE_NONE; // Other clocks too... - private long nextEventCycles; + long nextEventCycles; private EventQueue vTimeEventQueue = new EventQueue(); private long nextVTimeEventCycles; @@ -407,6 +408,7 @@ // update last virtual time before updating DCOfactor lastVTime = getTime(); lastCyclesTime = cycles; + lastMicrosDelta = 0; currentDCOFactor = 1.0 * BasicClockModule.MAX_DCO_FRQ / frequency; @@ -436,6 +438,15 @@ } + /** + * getCyclesToNext - returns the number of cycles that it will take before next + * execution of an event or zero if CPU is running. + * @return number of cycles left before next event executes or 0 if CPU is on. + */ + public long getCyclesToNext() { + if (!cpuOff) return 0; + return cycles - nextEventCycles; + } private void executeEvents() { if (cycles >= nextVTimeEventCycles) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2009-10-09 21:30:22
|
Revision: 627 http://mspsim.svn.sourceforge.net/mspsim/?rev=627&view=rev Author: nifi Date: 2009-10-09 21:30:05 +0000 (Fri, 09 Oct 2009) Log Message: ----------- updated button positions for managed window Modified Paths: -------------- mspsim/se/sics/mspsim/platform/sky/SkyGui.java Modified: mspsim/se/sics/mspsim/platform/sky/SkyGui.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2009-10-09 19:33:46 UTC (rev 626) +++ mspsim/se/sics/mspsim/platform/sky/SkyGui.java 2009-10-09 21:30:05 UTC (rev 627) @@ -119,7 +119,6 @@ WindowManager wm = (WindowManager) registry.getComponent("windowManager"); window = wm.createWindow("SkyGui"); - setSize(190, 240); window.add(this); window.setVisible(true); @@ -132,10 +131,11 @@ public void mousePressed(MouseEvent e) { int x = e.getX(); int y = e.getY(); - if (x > 126 && x < 138) { - if (y > 65 && y < 76) { - SkyGui.this.node.setButton(buttonDown = true); - } else if (y > 95 && y < 107) { + if (x > 122 && x < 135) { + if (y > 41 && y < 55) { + buttonDown = true; + SkyGui.this.node.setButton(true); + } else if (y > 72 && y < 85) { resetDown = true; } } @@ -143,13 +143,14 @@ public void mouseReleased(MouseEvent e) { if (buttonDown) { - SkyGui.this.node.setButton(buttonDown = false); + buttonDown = false; + SkyGui.this.node.setButton(false); } else if (resetDown) { int x = e.getX(); int y = e.getY(); resetDown = false; - if (x > 126 && x < 138 && y > 95 && y < 107) { + if (x > 122 && x < 135 && y > 72 && y < 85) { SkyGui.this.node.getCPU().reset(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2009-10-09 19:33:54
|
Revision: 626 http://mspsim.svn.sourceforge.net/mspsim/?rev=626&view=rev Author: nifi Date: 2009-10-09 19:33:46 +0000 (Fri, 09 Oct 2009) Log Message: ----------- changed Makefile to include all libraries in 'lib' Modified Paths: -------------- mspsim/Makefile Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2009-10-09 12:12:55 UTC (rev 625) +++ mspsim/Makefile 2009-10-09 19:33:46 UTC (rev 626) @@ -15,7 +15,6 @@ JAVA=java JAR=jar RM=rm -f -CP=cp ############################################################### # System dependent @@ -45,7 +44,10 @@ # Arguments ############################################################### -CLASSPATH=.$(SEPARATOR)lib/jfreechart-1.0.11.jar$(SEPARATOR)lib/jcommon-1.0.14.jar +EMPTY := +SPACE := ${EMPTY} ${EMPTY} +LIBS := ${wildcard lib/*.jar} +CLASSPATH=${subst ${SPACE},${SEPARATOR},. ${LIBS}} CCARGS=-deprecation -classpath "${CLASSPATH}" JAVAARGS=-classpath "${CLASSPATH}" @@ -68,7 +70,7 @@ SCRIPTS := ${addprefix scripts/,autorun.sc duty.sc} BINARY := README.txt license.txt CHANGE_LOG.txt images/*.jpg firmware/*/*.firmware ${SCRIPTS} -PACKAGES := se/sics/mspsim ${addprefix se/sics/mspsim/,core platform platform/esb platform/sky cli ui util chip net plugin extutil/highlight extutil/jfreechart} +PACKAGES := se/sics/mspsim ${addprefix se/sics/mspsim/,core chip cli platform platform/esb platform/sky plugin profiler net ui util extutil/highlight extutil/jfreechart} SOURCES := ${wildcard *.java $(addsuffix /*.java,$(PACKAGES))} @@ -94,7 +96,7 @@ @echo >>$@ "Manifest-Version: 1.0" @echo >>$@ "Sealed: true" @echo >>$@ "Main-Class: se.sics.mspsim.Main" - @echo >>$@ "Class-path: lib/jfreechart-1.0.11.jar lib/jcommon-1.0.14.jar" + @echo >>$@ "Class-path: ${LIBS}" help: @echo "Usage: make [all,compile,clean,run,runsky,runesb]" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-09 12:14:39
|
Revision: 625 http://mspsim.svn.sourceforge.net/mspsim/?rev=625&view=rev Author: joxe Date: 2009-10-09 12:12:55 +0000 (Fri, 09 Oct 2009) Log Message: ----------- removed IP stack from MSPSim to enable usage of jipv6 Modified Paths: -------------- mspsim/scripts/autorun.sc mspsim/se/sics/mspsim/cli/NetCommands.java mspsim/se/sics/mspsim/util/TSPTest.java Added Paths: ----------- mspsim/lib/jipv6.jar Added: mspsim/lib/jipv6.jar =================================================================== (Binary files differ) Property changes on: mspsim/lib/jipv6.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: mspsim/scripts/autorun.sc =================================================================== --- mspsim/scripts/autorun.sc 2009-10-09 12:11:58 UTC (rev 624) +++ mspsim/scripts/autorun.sc 2009-10-09 12:12:55 UTC (rev 625) @@ -12,4 +12,5 @@ service controlgui start service nodegui start #service stackchart start +rflistener output CC2420 > rfdata.txt start Modified: mspsim/se/sics/mspsim/cli/NetCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/NetCommands.java 2009-10-09 12:11:58 UTC (rev 624) +++ mspsim/se/sics/mspsim/cli/NetCommands.java 2009-10-09 12:12:55 UTC (rev 625) @@ -5,10 +5,10 @@ import se.sics.mspsim.core.MSP430; import se.sics.mspsim.net.CC2420PacketHandler; -import se.sics.mspsim.net.IEEE802154Handler; -import se.sics.mspsim.net.IPStack; -import se.sics.mspsim.net.LoWPANHandler; -import se.sics.mspsim.net.TSPClient; +import se.sics.jipv6.mac.IEEE802154Handler; +import se.sics.jipv6.mac.LoWPANHandler; +import se.sics.jipv6.core.IPStack; +import se.sics.jipv6.tunnel.TSPClient; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.Utils; @@ -33,6 +33,8 @@ listener.addUpperLayerHandler(0, ieeeHandler); ieeeHandler.setLowerLayerHandler(listener); ipStack = new IPStack(); + byte[] macAddr = new byte[] {0x2,0x12,0x74,0x00,0x11,0x11,0x12,0x12}; + ipStack.setLinkLayerAddress(macAddr); ipStack.setRouter(true); LoWPANHandler lowpanHandler = new LoWPANHandler(); lowpanHandler.setIPStack(ipStack); Modified: mspsim/se/sics/mspsim/util/TSPTest.java =================================================================== --- mspsim/se/sics/mspsim/util/TSPTest.java 2009-10-09 12:11:58 UTC (rev 624) +++ mspsim/se/sics/mspsim/util/TSPTest.java 2009-10-09 12:12:55 UTC (rev 625) @@ -1,11 +1,11 @@ package se.sics.mspsim.util; -import se.sics.mspsim.net.AbstractPacketHandler; -import se.sics.mspsim.net.ICMP6Packet; -import se.sics.mspsim.net.IPStack; -import se.sics.mspsim.net.IPv6Packet; -import se.sics.mspsim.net.Packet; -import se.sics.mspsim.net.TSPClient; +import se.sics.jipv6.core.AbstractPacketHandler; +import se.sics.jipv6.core.ICMP6Packet; +import se.sics.jipv6.core.IPStack; +import se.sics.jipv6.core.IPv6Packet; +import se.sics.jipv6.core.Packet; +import se.sics.jipv6.tunnel.TSPClient; public class TSPTest extends AbstractPacketHandler implements Runnable { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-09 12:14:13
|
Revision: 624 http://mspsim.svn.sourceforge.net/mspsim/?rev=624&view=rev Author: joxe Date: 2009-10-09 12:11:58 +0000 (Fri, 09 Oct 2009) Log Message: ----------- removed more IP related classes Removed Paths: ------------- mspsim/se/sics/mspsim/net/AbstractPacketHandler.java mspsim/se/sics/mspsim/net/BytePayload.java mspsim/se/sics/mspsim/net/HC01Packeter.java mspsim/se/sics/mspsim/net/HttpServer.java mspsim/se/sics/mspsim/net/HttpServlet.java mspsim/se/sics/mspsim/net/HttpServletRequest.java mspsim/se/sics/mspsim/net/HttpServletResponse.java mspsim/se/sics/mspsim/net/ICMP6Packet.java mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java mspsim/se/sics/mspsim/net/IEEE802154Handler.java mspsim/se/sics/mspsim/net/LoWPANHandler.java mspsim/se/sics/mspsim/net/Neighbor.java mspsim/se/sics/mspsim/net/NeighborManager.java mspsim/se/sics/mspsim/net/NeighborTable.java mspsim/se/sics/mspsim/net/NetworkEventListener.java mspsim/se/sics/mspsim/net/NetworkInterface.java Deleted: mspsim/se/sics/mspsim/net/AbstractPacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacketHandler.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/AbstractPacketHandler.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,97 +0,0 @@ -/** - * Copyright (c) 2009, 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. - * - * This file is part of MSPSim. - * - * $Id: $ - * - * ----------------------------------------------------------------- - * - * - * Author : Joakim Eriksson - * Created : mar 2009 - * Updated : $Date:$ - * $Revision:$ - */ - -package se.sics.mspsim.net; - -import java.io.PrintStream; -import java.util.Vector; - -public abstract class AbstractPacketHandler implements PacketHandler { - - boolean debug = true; - - Vector upperLayers = new Vector(); - PacketHandler lowerLayer; - - public PacketHandler getLowerLayerHandler() { - return lowerLayer; - } - - public void addUpperLayerHandler(int protoID, PacketHandler handler) { - PacketHandlerDispatch layer = new PacketHandlerDispatch(); - layer.dispatch = protoID; - layer.packetHandler = handler; - upperLayers.addElement(layer); - } - - public void setLowerLayerHandler(PacketHandler handler) { - lowerLayer = handler; - } - - /* incoming packets ... */ - void dispatch(int dispatch, Packet packet) { - if (debug) { - printPacket(System.out, packet); - } - if (dispatch != -1) { - for (int i = 0; i < upperLayers.size(); i++) { - if (((PacketHandlerDispatch)upperLayers.elementAt(i)).dispatch == dispatch) { - ((PacketHandlerDispatch)upperLayers.elementAt(i)).packetHandler.packetReceived(packet); - return; - } - } - System.out.println("**** no dispatch handler for " + dispatch + " found..."); - } else if (upperLayers.size() > 0){ - ((PacketHandlerDispatch)upperLayers.elementAt(0)).packetHandler.packetReceived(packet); - } - } - - public abstract void packetReceived(Packet container); - - public abstract void sendPacket(Packet packet); - - public void printPacket(PrintStream out, Packet packet) { - } - - private static class PacketHandlerDispatch { - int dispatch; - PacketHandler packetHandler; - } -} \ No newline at end of file Deleted: mspsim/se/sics/mspsim/net/BytePayload.java =================================================================== --- mspsim/se/sics/mspsim/net/BytePayload.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/BytePayload.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,30 +0,0 @@ -package se.sics.mspsim.net; - -import java.io.PrintStream; - -/* keep the packet payload untouched ... */ -public class BytePayload implements IPPayload { - - byte[] payloadData; - byte dispatch; - - public BytePayload(IPv6Packet packet) { - parsePacketData(packet); - } - - public byte[] generatePacketData(IPv6Packet packet) { - return payloadData; - } - - public byte getDispatch() { - return dispatch; - } - - public void parsePacketData(IPv6Packet packet) { - dispatch = packet.getDispatch(); - payloadData = packet.getPayload(); - } - - public void printPacket(PrintStream out) { - } -} Deleted: mspsim/se/sics/mspsim/net/HC01Packeter.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01Packeter.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/HC01Packeter.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,633 +0,0 @@ -/** - * Copyright (c) 2009, 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. - * - * This file is part of MSPSim. - * - * $Id: $ - * - * ----------------------------------------------------------------- - * - * AbstractPacket - * - * Author : Joakim Eriksson - * Original Authors (Contiki Code): - * - * Created : mar 2009 - * Updated : $Date:$ - * $Revision:$ - */ - -package se.sics.mspsim.net; - - -import se.sics.mspsim.util.Utils; - -public class HC01Packeter implements IPPacketer { - - private boolean DEBUG = false;//true; - /* - * Values of fields within the IPHC encoding first byte - * (C stands for compressed and I for inline) - */ - public final static int IPHC_TC_C = 0x80; - public final static int IPHC_VF_C = 0x40; - public final static int IPHC_NH_C = 0x20; - public final static int IPHC_TTL_1 = 0x08; - public final static int IPHC_TTL_64 = 0x10; - public final static int IPHC_TTL_255 = 0x18; - public final static int IPHC_TTL_I = 0x00; - - /* Values of fields within the IPHC encoding second byte */ - public final static int IPHC_SAM_I = 0x00; - public final static int IPHC_SAM_64 = 0x40; - public final static int IPHC_SAM_16 = 0x80; - public final static int IPHC_SAM_0 = 0xC0; - public final static int IPHC_DAM_I = 0x00; - public final static int IPHC_DAM_64 = 0x04; - public final static int IPHC_DAM_16 = 0x08; - public final static int IPHC_DAM_0 = 0x0C; - - public final static int NHC_UDP_ID = 0xF8; - public final static int NHC_UDP_C = 0xFB; - public final static int NHC_UDP_I = 0xF8; - - /* Link local context number */ - public final static int IPHC_ADDR_CONTEXT_LL = 0; - /* 16-bit multicast addresses compression */ - public final static int IPHC_MCAST_RANGE = 0xA0; - - /* Min and Max compressible UDP ports */ - public final static int UDP_PORT_MIN = 0xF0B0; - public final static int UDP_PORT_MAX = 0xF0BF; /* F0B0 + 15 */ - - public static final int HC01_DISPATCH = 0x03; - - /* move these to IPv6 Packet !! */ - public final static int PROTO_ICMP = 1; - public final static int PROTO_TCP = 6; - public final static int PROTO_UDP = 17; - public final static int PROTO_ICMP6 = 58; - - private static class AddrContext { - int used; - int number; - byte[] prefix = new byte[8]; - - public boolean matchPrefix(byte[] address) { - for (int i = 0; i < prefix.length; i++) { - if (prefix[i] != address[i]) - return false; - } - return true; - } - } - - private AddrContext[] contexts = new AddrContext[4]; - - public HC01Packeter() { - // set-up some fake contexts just to get started... - contexts[0] = new AddrContext(); - contexts[1] = new AddrContext(); -// contexts[2] = new AddrContext(); -// contexts[3] = new AddrContext(); - - contexts[0].number = 0; - contexts[0].prefix[0] = (byte) 0xfe; - contexts[0].prefix[1] = (byte) 0x80; - - contexts[1].number = 1; - contexts[1].prefix[0] = (byte) 0xaa; - contexts[1].prefix[1] = (byte) 0xaa; - - } - - public byte getDispatch() { - return HC01_DISPATCH; - } - - /** - * \brief check whether we can compress the IID in - * address to 16 bits. - * This is used for unicast addresses only, and is true - * if first 49 bits of IID are 0 - * @return - */ - private boolean is16bitCompressable(byte[] address) { - return ((address[8] | address[9] | address[10] | address[11] | - address[12] | address[13]) == 0) && - (address[14] & 0x80) == 0; - } - - /** - * \brief check whether the 9-bit group-id of the - * compressed multicast address is known. It is true - * if the 9-bit group is the all nodes or all routers - * group. - * \param a is typed u8_t * - */ -// #define sicslowpan_is_mcast_addr_decompressable(a) \ -// (((*a & 0x01) == 0) && \ -// ((*(a + 1) == 0x01) || (*(a + 1) == 0x02))) - - /** - * \brief check whether the 112-bit group-id of the - * multicast address is mappable to a 9-bit group-id - * It is true if the group is the all nodes or all - * routers group. - */ -// #define sicslowpan_is_mcast_addr_compressable(a) \ -// ((((a)->u16[1]) == 0) && \ -// (((a)->u16[2]) == 0) && \ -// (((a)->u16[3]) == 0) && \ -// (((a)->u16[4]) == 0) && \ -// (((a)->u16[5]) == 0) && \ -// (((a)->u16[6]) == 0) && \ -// (((a)->u8[14]) == 0) && \ -// ((((a)->u8[15]) == 1) || (((a)->u8[15]) == 2))) - - /* before calling this a call to the routing mechanism needs to be done - * to get the LL addresses. */ - /* HC01 header compression from 40 bytes to less... */ - public byte[] generatePacketData(IPv6Packet packet) { - int enc1 = 0, enc2 = 0; - byte[] data = new byte[40 + 8]; - int pos = 2; - - if (packet.flowLabel == 0) { - /* compress version and flow label! */ - enc1 |= IPHC_VF_C; - } - if (packet.trafficClass == 0) { - enc1 |= IPHC_TC_C; - } - - /* write version and flow if needed */ - if ((enc1 & IPHC_VF_C) == 0) { - pos += writeVFlow(packet, data, pos); - } - /* write traffic class if needed */ - if ((enc1 & IPHC_TC_C) == 0) { - data[pos++] = (byte) (packet.trafficClass & 0xff); - } - - /* Note that the payload length is always compressed */ - - /* Compress NextHeader if UDP!!! */ - if (packet.nextHeader == UDPPacket.DISPATCH) { - enc1 |= IPHC_NH_C; - } else { - data[pos++] = (byte) (packet.nextHeader & 0xff); - } - - switch (packet.hopLimit) { - case 1: - enc1 |= IPHC_TTL_1; - break; - case 64: - enc1 |= IPHC_TTL_64; - break; - case 255: - enc1 |= IPHC_TTL_255; - break; - default: - data[pos++] = (byte) (packet.hopLimit & 0xff); - } - - int context; - if ((context = lookupContext(packet.sourceAddress)) != -1) { - if (DEBUG) System.out.println("HC01: Found context (SRC): " + context); - /* elide the prefix */ - enc2 |= context << 4; - if (packet.isSourceMACBased()) { - /* elide the IID */ - enc2 |= IPHC_SAM_0; - } else if (is16bitCompressable(packet.sourceAddress)){ - enc2 |= IPHC_SAM_16; - data[pos++] = packet.sourceAddress[14]; - data[pos++] = packet.sourceAddress[15]; - } else { - enc2 |= IPHC_SAM_64; - System.arraycopy(packet.sourceAddress, 8, data, pos, 8); - pos += 8; - } - } else { - if (DEBUG) System.out.println("HC01: no context - use full addr (SRC)"); - enc2 |= IPHC_SAM_I; - System.arraycopy(packet.sourceAddress, 0, data, pos, 16); - pos += 16; - } - - /* destination compression */ - // System.out.print("isMulticastCompressable?: "); - // IPv6Packet.printAddress(System.out, packet.destAddress); - - if(packet.isMulticastDestination()) { - /* Address is multicast, try to compress */ - if(isMulticastCompressable(packet.destAddress)) { - enc2 |= IPHC_DAM_16; - /* 3 first bits = 101 */ - data[pos] = (byte) IPHC_MCAST_RANGE; - /* bits 3-6 = scope = bits 8-11 in 128 bits address */ - data[pos++] |= (packet.destAddress[1] & 0x0F) << 1; - /* - * bits 7 - 15 = 9-bit group - * We just copy the last byte because it works - * with currently supported groups - */ - data[pos++] = packet.destAddress[15]; - } else { - /* send the full address */ - enc2 |= IPHC_DAM_I; - System.arraycopy(packet.destAddress, 0, data, pos, 16); - pos += 16; - } - } else { - /* Address is unicast, try to compress */ - if((context = lookupContext(packet.destAddress)) != -1) { - if (DEBUG) System.out.println("HC01: Found context (DST): " + context); - /* elide the prefix */ - enc2 |= context; - if(packet.isDestinationMACBased()) { - /* elide the IID */ - enc2 |= IPHC_DAM_0; - } else { - if(is16bitCompressable(packet.destAddress)) { - /* compress IID to 16 bits */ - enc2 |= IPHC_DAM_16; - data[pos++] = packet.destAddress[14]; - data[pos++] = packet.destAddress[15]; - } else { - /* do not compress IID */ - enc2 |= IPHC_DAM_64; - System.arraycopy(packet.destAddress, 8, data, pos, 8); - pos += 8; - } - } - } else { - /* send the full address */ - if (DEBUG) System.out.println("HC01: full destination address"); - enc2 |= IPHC_DAM_I; - System.arraycopy(packet.destAddress, 0, data, pos, 16); - pos += 16; - } - } - - // uncomp_hdr_len = UIP_IPH_LEN; - // TODO: add udp header compression!!! - - /* UDP header compression */ - if(packet.nextHeader == UDPPacket.DISPATCH) { - UDPPacket udp = (UDPPacket) packet.getIPPayload(); - if( udp.sourcePort >= UDP_PORT_MIN && - udp.sourcePort < UDP_PORT_MAX && - udp.destinationPort >= UDP_PORT_MIN && - udp.destinationPort < UDP_PORT_MAX) { - /* we can compress. Copy compressed ports, full chcksum */ - data[pos++] = (byte) NHC_UDP_C; - data[pos++] = (byte) (((udp.sourcePort - UDP_PORT_MIN) << 4) + - (udp.destinationPort - UDP_PORT_MIN)); - int checksum = udp.doVirtualChecksum(packet); - data[pos++] = (byte) (checksum >> 8); - data[pos++] = (byte) (checksum & 0xff); - } else { - /* we cannot compress. Copy uncompressed ports, full chcksum */ - data[pos++] = (byte) NHC_UDP_I; - data[pos++] = (byte) (udp.sourcePort >> 8); - data[pos++] = (byte) (udp.sourcePort & 0xff); - data[pos++] = (byte) (udp.destinationPort >> 8); - data[pos++] = (byte) (udp.destinationPort & 0xff); - int checksum = udp.doVirtualChecksum(packet); - data[pos++] = (byte) (checksum >> 8); - data[pos++] = (byte) (checksum & 0xff); - } - } - - - // data[0] = HC01_DISPATCH; - layer below does this!!! - data[0] = (byte) (enc1 & 0xff); - data[1] = (byte) (enc2 & 0xff); - - if (DEBUG) System.out.println("HC01 Header compression: size " + pos + - " enc1: " + Utils.hex8(enc1) + " enc2: " + Utils.hex8(enc2)); - if (DEBUG) { - System.out.print("HC01: From "); - IPv6Packet.printAddress(System.out, packet.sourceAddress); - System.out.print("HC01: To "); - IPv6Packet.printAddress(System.out, packet.destAddress); - } - byte[] pload; - if (packet.nextHeader == UDPPacket.DISPATCH) { - UDPPacket udp = (UDPPacket) packet.getIPPayload(); - /* already have the udp header */ - pload = udp.payload; - } else { - IPPayload payload = packet.getIPPayload(); - pload = payload.generatePacketData(packet); - } - if (DEBUG) System.out.println("HC01 Payload size: " + pload.length); - - byte[] dataPacket = new byte[pos + pload.length]; - System.arraycopy(data, 0, dataPacket, 0, pos); - System.arraycopy(pload, 0, dataPacket, pos, pload.length); - return dataPacket; - } - - public int writeVFlow(IPv6Packet packet, byte[] data, int pos) { - data[pos++] = (byte) (0x60 | (packet.flowLabel >> 16) & 0x0f); - data[pos++] = (byte)((packet.flowLabel >> 8) & 0xff); - data[pos++] = (byte) (packet.flowLabel & 0xff); - return 3; - } - - - public void parsePacketData(IPv6Packet packet) { - /* first two is ... */ - UDPPacket udp = null; - int pos = 2; - int enc1 = packet.getData(0); - int enc2 = packet.getData(1); - if ((enc1 & 0x40) == 0) { - if ((enc1 & 0x80) == 0) { - packet.version = (packet.getData(pos) & 0xf0) >> 4; - packet.trafficClass = ((packet.getData(pos) & 0x0f)<<4) + ((packet.getData(pos + 1) & 0xff) >> 4); - packet.flowLabel = (packet.getData(pos + 1) & 0x0f) << 16 + (packet.getData(pos + 2) & 0xff) << 8 + - packet.getData(pos + 3) & 0xff; - pos += 4; - } else { - packet.version = 6; - packet.trafficClass = 0; - packet.flowLabel = (packet.getData(pos) & 0x0f) << 16 - + (packet.getData(pos + 1) & 0xff) << 8 + packet.getData(pos + 2) & 0xff;; - pos += 3; - } - } else { - packet.version = 6; - packet.flowLabel = 0; - if ((enc1 & 0x80) == 0) { - packet.trafficClass = (packet.getData(pos) & 0xff); - pos++; - } else { - packet.trafficClass = 0; - } - } - - /* next header not compressed -> get it */ - if ((enc1 & 0x20) == 0) { - packet.nextHeader = packet.getData(pos++); - } - - /* encoding of TTL */ - switch (enc1 & 0x18) { - case IPHC_TTL_1: - packet.hopLimit = 1; - break; - case IPHC_TTL_64: - packet.hopLimit = 64; - break; - case IPHC_TTL_255: - packet.hopLimit = 0xff; - break; - case IPHC_TTL_I: - packet.hopLimit = packet.getData(pos++); - break; - } - - /* 0, 1, 2, 3 as source address ??? */ - int srcAddress = (enc2 & 0x30) >> 4; - AddrContext context = lookupContext(srcAddress); - if (DEBUG) { - System.out.println("HC01: uncompress (SRC) enc2 & c0 = " + (enc2 & 0xc0) + - " ctx =" + srcAddress); - } - switch (enc2 & 0xc0) { - case IPHC_SAM_0: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* set hi address as prefix from context */ - System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); - /* infer IID from L2 address */ - byte[] linkAddress = packet.getLinkSource();//getLinkSourceAddress(packet); - System.arraycopy(linkAddress, 0, packet.sourceAddress, 8, 8); - /* TODO: clean autoconf stuff up */ - packet.sourceAddress[8] ^= 0x02; - break; - case IPHC_SAM_16: - if((packet.getData(pos) & 0x80) == 0) { - /* unicast address */ - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* set hi address as prefix from context */ - System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); - /* copy 6 NULL bytes then 2 last bytes of IID */ - Utils.fill(packet.sourceAddress, 8, 14, (byte)0); - packet.sourceAddress[14] = packet.getData(pos); - packet.sourceAddress[15] = packet.getData(pos + 1); - pos += 2; - } else { - /* [ignore] multicast address check the 9-bit group-id is known */ - Utils.fill(packet.sourceAddress, 0, 16, (byte)0); - packet.sourceAddress[0] = (byte)0xff; - packet.sourceAddress[1] = (byte)(((packet.getData(pos) & 0xff) >> 1) & 0x0f); - packet.sourceAddress[15] = packet.getData(pos + 1); - pos += 2; - } - break; - case IPHC_SAM_64: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); - /* copy IID from packet */ - packet.copy(pos, packet.sourceAddress, 8, 8); - pos += 8; - break; - case IPHC_SAM_I: - if (DEBUG) System.out.println("HC01: full address used (SRC)"); - /* copy whole address from packet */ - packet.copy(pos, packet.sourceAddress, 0, 16); - pos += 16; - break; - } - - /* Destination address */ - context = lookupContext(enc2 & 0x03); - if (DEBUG) { - System.out.println("HC01: uncompress (DST) enc2 & 0x0c = " + (enc2 & 0x0c) + - " ctx =" + (enc2 & 0x03)); - } - - switch(enc2 & 0x0C) { - case IPHC_DAM_0: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); - /* infer IID from L2 address */ - byte[] destAddress = packet.getLinkDestination(); - System.arraycopy(destAddress, 0, packet.destAddress, 8, 8); - /* cleanup autoconf stuff later ... */ - packet.destAddress[8] ^= 0x02; - break; - case IPHC_DAM_16: - if((packet.getData(pos) & 0x80) == 0) { - /* unicast address */ - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); - /* copy 6 NULL bytes then 2 last bytes of IID */ - packet.destAddress[14] = packet.getData(pos); - packet.destAddress[15] = packet.getData(pos + 1); - pos += 2; - } else { - /* [ignore] multicast address check the 9-bit group-id is known */ - //System.out.println("*** Multicast address!!! HC01: " + packet.getData(pos) + "," + packet.getData(pos + 1)); - Utils.fill(packet.destAddress, 0, 16, (byte)0); - packet.destAddress[0] = (byte) 0xff; - packet.destAddress[1] = (byte)(((packet.getData(pos) & 0xff) >> 1) & 0x0F); - packet.destAddress[15] = (byte) (packet.getData(pos + 1) & 0xff); - pos += 2; - } - break; - case IPHC_DAM_64: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); - /* copy IID from packet */ - packet.copy(pos, packet.destAddress, 8, 8); - pos += 8; - break; - case IPHC_DAM_I: - /* copy whole address from packet */ - packet.copy(pos, packet.destAddress, 0, 16); - pos += 16; - break; - } - - if ((enc1 & 0x20) != 0) { - /* The next header is compressed, NHC is following */ - if ((packet.getData(pos) & 0xfc) == NHC_UDP_ID) { - if (DEBUG) System.out.println("HC01: Next header UDP!"); - packet.nextHeader = PROTO_UDP; - int srcPort = 0; - int destPort = 0; - int checkSum = 0; - switch(packet.getData(pos) & 0xff) { - case NHC_UDP_C: - /* 1 byte for NHC, 1 byte for ports, 2 bytes chksum */ - srcPort = UDP_PORT_MIN + ((packet.getData(pos + 1) & 0xff) >> 4); - destPort = UDP_PORT_MIN + (packet.getData(pos + 1) & 0x0F); - checkSum = ((packet.getData(pos + 2) & 0xff) << 8) + (packet.getData(pos + 3) & 0xff); - pos += 4; - break; - case NHC_UDP_I: - /* 1 byte for NHC, 4 byte for ports, 2 bytes chksum */ - srcPort = ((packet.getData(pos + 1) & 0xff)<< 8) + (packet.getData(pos + 2) & 0xff); - destPort = ((packet.getData(pos + 3) & 0xff)<< 8) + (packet.getData(pos + 4) & 0xff); - checkSum = ((packet.getData(pos + 5) & 0xff)<< 8) + (packet.getData(pos + 6) & 0xff); - pos += 7; - break; - default: - System.out.println("sicslowpan uncompress_hdr: error unsupported UDP compression\n"); - return; - } - udp = new UDPPacket(); - udp.sourcePort = srcPort; - udp.destinationPort = destPort; - udp.checkSum = checkSum; - } - } - - boolean frag = false; - /* fragment handling ... */ - if (!frag) { - /* this does not handle the UDP header compression yet... */ - /* move cursor pos steps forward */ - packet.incPos(pos); - } else { - } - - if (DEBUG) { - System.out.println("Encoding 0: " + Utils.hex8(enc1) + - " Encoding 1: " + Utils.hex8(enc2)); - System.out.println("TTL: " + packet.hopLimit); - System.out.print("Src Addr: "); - IPv6Packet.printAddress(System.out, packet.sourceAddress); - System.out.print("Dst Addr: "); - IPv6Packet.printAddress(System.out, packet.destAddress); - System.out.println(); - } - // packet.setPayload(data, 40, ???); - packet.payloadLen = packet.getPayloadLength(); - - if (udp != null) { - /* if we have a udp payload we already have the udp headers in place */ - /* the rest is only the payload */ - udp.payload = packet.getPayload(); - udp.length = udp.payload.length + 8; - /* add 8 to the payload length of the UDP packet */ - packet.payloadLen += 8; - udp.doVirtualChecksum(packet); - packet.setIPPayload(udp); - } - } - - private boolean isMulticastCompressable(byte[] address) { - for (int i = 2; i < 15; i++) { - if (address[i] != 0) return false; - } - return (address[15] == 1 || address[15] == 2); - } - - - private AddrContext lookupContext(int index) { - if (index < contexts.length) - return contexts[index]; - return null; - } - - private int lookupContext(byte[] address) { - for (int i = 0; i < contexts.length; i++) { - if (contexts[i] != null && contexts[i].matchPrefix(address)) { - return i; - } - } - return -1; - } -} \ No newline at end of file Deleted: mspsim/se/sics/mspsim/net/HttpServer.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServer.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/HttpServer.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,144 +0,0 @@ -package se.sics.mspsim.net; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.Hashtable; -import java.util.Vector; - -public class HttpServer implements TCPListener, Runnable{ - - private IPStack ipStack; - private TCPConnection serverConnection; - private Hashtable servlets = new Hashtable(); - private Vector pending = new Vector(); - private String status = ""; - - public HttpServer(IPStack stack) { - ipStack = stack; - serverConnection = ipStack.listen(80); - serverConnection.setTCPListener(this); - new Thread(this).start(); - } - - public void connectionClosed(TCPConnection connection) { - } - - public void newConnection(TCPConnection connection) { - handleConnection(connection); - } - - public void tcpDataReceived(TCPConnection source, TCPPacket packet) { - } - - public void registerServlet(String path, HttpServlet servlet) { - servlets.put(path, servlet); - } - - private synchronized void handleConnection(TCPConnection connection) { - /* add and notify worker thread */ - System.out.println("%%% HttpServer: gotten new connection, adding to pending..."); - pending.addElement(connection); - notify(); - } - - private void handlePendingConnections() { - while(true) { - TCPConnection connection = null; - synchronized(this) { - while(pending.size() == 0) - try { - System.out.println("%%% HttpServer: worker waiting..."); - status = "waiting for connections"; - wait(); - /* take first and handle... */ - System.out.println("%%% HttpServer: worker notified..."); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - status = "got connection"; - connection = (TCPConnection) pending.firstElement(); - pending.removeElementAt(0); - } - InputStream input = connection.getInputStream(); - OutputStream output = connection.getOutputStream(); - connection.setTimeout(5000); - try { - /* read a line */ - System.out.println("%%% HttpServer: reading req line from: " + input); - status = "reading request line"; - String reqLine = readLine(input); - reqLine = reqLine.trim(); - if (!handleRequest(reqLine, input, output, connection)) { - output.write("HTTP/1.0 404 NOT FOUND\r\n\r\n".getBytes()); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - output.close(); - input.close(); - } catch (IOException e) { - } - connection.close(); - } - } - } - - private boolean handleRequest(String reqLine, InputStream input, - OutputStream output, TCPConnection connection) throws IOException { - int space = reqLine.indexOf(' '); - if (space != -1) { - String method = reqLine.substring(0, space); - String path = reqLine.substring(space + 1, reqLine.lastIndexOf(' ')); - System.out.println("Method: " + method); - System.out.println("Path: " + path); - int query = reqLine.indexOf('?'); - if (query > 0) { - path = path.substring(0, query); - } - status = "finding servlet: " + path; - HttpServlet servlet = (HttpServlet) servlets.get(path); - if (servlet != null) { - // ignore headers for speed... - // - // String line = null; - // while((line = readLine(input)) != null) { - // line = line.trim(); - // System.out.println("/// HTTP Header: " + line); - // if (line.length() == 0) { - // break; - // } - // } - HttpServletRequest req = new HttpServletRequest(connection, method, path); - HttpServletResponse resp = new HttpServletResponse(connection); - status = "Servicing servlet"; - servlet.service(req, resp); - return true; - } - } - return false; - } - - public void run() { - System.out.println("%%% HttpServer: worker thread started..."); - handlePendingConnections(); - } - - private String readLine(InputStream input) throws IOException { - StringBuffer sb = new StringBuffer(); - int c; - while(((c = input.read()) != -1)) { - if (c != '\r') sb.append((char) c); - if (c == '\n') return sb.toString(); - } - return null; - } - - public void printStatus(PrintStream out) { - out.println("HttpServer status: " + status); - } - -} Deleted: mspsim/se/sics/mspsim/net/HttpServlet.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServlet.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/HttpServlet.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,9 +0,0 @@ -package se.sics.mspsim.net; - -public class HttpServlet { - - public void service(HttpServletRequest req, - HttpServletResponse resp) { - } - -} Deleted: mspsim/se/sics/mspsim/net/HttpServletRequest.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServletRequest.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/HttpServletRequest.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,28 +0,0 @@ -package se.sics.mspsim.net; - -import java.io.InputStream; - -public class HttpServletRequest { - - private TCPConnection connection; - private String method; - private String path; - - public HttpServletRequest(TCPConnection connection, String method, String path) { - this.connection = connection; - this.method = method; - this.path = path; - } - - public String getMethod() { - return method; - } - - public String getPath() { - return path; - } - - public InputStream getInputStream() { - return connection.getInputStream(); - } -} Deleted: mspsim/se/sics/mspsim/net/HttpServletResponse.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServletResponse.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/HttpServletResponse.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,18 +0,0 @@ -package se.sics.mspsim.net; - -import java.io.OutputStream; - -public class HttpServletResponse { - - private TCPConnection tcpConnection; - - public HttpServletResponse(TCPConnection c) { - tcpConnection = c; - } - - public OutputStream getOutputStream() { - return tcpConnection.getOutputStream(); - } - - -} Deleted: mspsim/se/sics/mspsim/net/ICMP6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,348 +0,0 @@ -package se.sics.mspsim.net; -import java.io.PrintStream; -import java.util.Vector; - -import se.sics.mspsim.util.Utils; - -public class ICMP6Packet implements IPPayload { - - public static final int DISPATCH = 58; - - public static final int ECHO_REQUEST = 128; - public static final int ECHO_REPLY = 129; - public static final int GROUP_QUERY = 130; - public static final int GROUP_REPORT = 131; - public static final int GROUP_REDUCTION = 132; - public static final int ROUTER_SOLICITATION = 133; - public static final int ROUTER_ADVERTISEMENT = 134; - public static final int NEIGHBOR_SOLICITATION = 135; - public static final int NEIGHBOR_ADVERTISEMENT = 136; - - public static final int FLAG_ROUTER = 0x80; - public static final int FLAG_SOLICITED = 0x40; - public static final int FLAG_OVERRIDE = 0x20; - - public static final int ON_LINK = 0x80; - public static final int AUTOCONFIG = 0x40; - - public static final int SOURCE_LINKADDR = 1; - public static final int TARGET_LINKADDR = 2; - public static final int PREFIX_INFO = 3; - public static final int MTU_INFO = 5; - - public static final String[] TYPE_NAME = new String[] { - "ECHO_REQUEST", "ECHO_REPLY", - "GROUP_QUERY", "GROUP_REPORT", "GROUP_REDUCTION", - "ROUTER_SOLICITATION", "ROUTER_ADVERTISEMENT", - "NEIGHBOR_SOLICITATION", "NEIGHBOR_ADVERTISEMENT"}; - - int type; - - int code; - int checksum; - byte[] targetAddress; - int id; - int seqNo; - - int flags; - - byte hopLimit = (byte) 128; - byte autoConfigFlags; - int routerLifetime = 100; /* time in seconds for keeping the router as default */ - int reachableTime = 360000; /* time in millis when node still should be counted as reachable */ - int retransmissionTimer = 0; /* time in millis between solicitations */ - int mtuSize = 1280; - - byte[] echoData; - - // for 1.3 compatibility - private Vector options = new Vector(); - - /* prefix info option - type = 3, len = 4 (64x4 bits), prefix = 64 bits */ - private final static byte[] defaultPrefixInfo = - new byte[] {3, 4, 64, (byte) (ON_LINK | AUTOCONFIG), - (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, /* valid lifetime -1 seconds for now*/ - (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, /* prefered lifetime -1 seconds lifetime of autoconf addr */ - 0, 0, 0, 0, /* reserved */ - /* the prefix ... */ - (byte)0xaa, (byte)0xaa, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - - /* default MTU is 1280 (5x256) which also is the smallest allowed */ - byte[] mtuOption = new byte[] {5, 1, 0, 0, 0, 0, 5, 0}; - - public ICMP6Packet() { - } - public ICMP6Packet(int type) { - this.type = type; - } - - void updateRA(IPStack stack) { - byte[] llAddr = stack.getLinkLayerAddress(); - options.removeAllElements(); - byte[] prefixInfo = new byte[defaultPrefixInfo.length]; - System.arraycopy(defaultPrefixInfo, 0, prefixInfo, 0, defaultPrefixInfo.length); - byte[] prefix = stack.prefix; - System.arraycopy(prefix, 0, prefixInfo, 16, prefix.length); - options.addElement(prefixInfo); - options.addElement(mtuOption); - addLinkOption(SOURCE_LINKADDR, llAddr); - } - - void addLinkOption(int type, byte[] llAddr) { - byte[] opt; - if (llAddr.length > 6) { - opt = new byte[16]; - } else { - opt = new byte[8]; - } - opt[0] = (byte) type; - opt[1] = (byte) (opt.length / 8); - System.arraycopy(llAddr, 0, opt, 2, llAddr.length); - options.addElement(opt); - } - - public int getType() { - return type; - } - public void setType(int type) { - this.type = type; - } - - public int getFlags() { - return flags; - } - public void setFlags(int flags) { - this.flags = flags; - } - - public byte[] getOption(int type) { - for (int i = 0; i < options.size(); i++) { - if (((byte[])options.elementAt(i))[0] == type) { - return (byte[]) options.elementAt(i); - } - } - return null; - } - - public byte[] getEchoData() { - return echoData; - } - - public void setEchoData(byte[] edata) { - echoData = edata; - } - - public void printPacket(PrintStream out) { - String typeS = "" + type; - if (type >= 128) { - int tS = type - 128; - if (tS < TYPE_NAME.length) { - typeS = TYPE_NAME[tS]; - } - } - out.println("ICMPv6 Type: " + type + " (" + typeS + ") Code: " + code + " id: " + - id + " seq: " + seqNo); - if (targetAddress != null) { - out.print("ICMPv6 Target address: "); - IPv6Packet.printAddress(out, targetAddress); - out.println(); - } - if (type == ROUTER_ADVERTISEMENT) { - System.out.println("ICMPv6 Route Advertisement"); - System.out.println(" Hop Limit: " + (hopLimit & 0xff)); - System.out.println(" autoConfig: " + (autoConfigFlags & 0xff)); - System.out.println(" routerLifeTime: " + routerLifetime + " (sec)"); - System.out.println(" reachableTime: " + reachableTime + " (msec)"); - System.out.println(" retransmissionTimer: " + retransmissionTimer + " (msec)"); - System.out.println(" autoConf: " + autoConfigFlags); - byte[] prefixInfo = getOption(PREFIX_INFO); - int bits = prefixInfo[2]; - int bytes = bits / 8; - out.print("RA Prefix: "); - for (int i = 0; i < bytes; i++) { - out.print(Utils.hex8(prefixInfo[16 + i])); - if ((i & 1) == 1) out.print(":"); - } - out.println("/" + bits); - out.println("RA Valid Lifetime: " + Packet.get32(prefixInfo, 4)); - out.println("RA Pref. Lifetime: " + Packet.get32(prefixInfo, 8)); - byte[] srcLink = getOption(SOURCE_LINKADDR); - if (srcLink != null) { - /* assuming 8 bytes for the mac ??? */ - System.out.print("Source Link: "); - IPv6Packet.printMACAddress(out, srcLink, 2, 8); - System.out.println(); - } - } - /* ICMP can not have payload ?! */ - } - - public void parsePacketData(IPv6Packet packet) { - if (packet.nextHeader == 58) { - type = packet.getData(0) & 0xff; - code = packet.getData(1) & 0xff; - checksum = ((packet.getData(2) & 0xff) << 8) | packet.getData(3) & 0xff; - /* test the checksum ... - set checksum to zero*/ - packet.setData(2, (byte) 0); - packet.setData(3, (byte) 0); - - switch (type) { - case ECHO_REQUEST: - case ECHO_REPLY: - id = packet.get16(4); - seqNo = packet.get16(6); - int dataLen = packet.getPayloadLength() - 8; - if (dataLen > 0) { - echoData = new byte[dataLen]; - packet.copy(8, echoData, 0, dataLen); - } - break; - case NEIGHBOR_SOLICITATION: - case NEIGHBOR_ADVERTISEMENT: - if (type == NEIGHBOR_ADVERTISEMENT) { - flags = packet.getData(4) & 0xff; - } - targetAddress = new byte[16]; - packet.copy(8, targetAddress, 0, 16); - handleOptions(packet, 24); - break; - case ROUTER_SOLICITATION: - break; - case ROUTER_ADVERTISEMENT: - hopLimit = packet.getData(4); - autoConfigFlags = packet.getData(5); - routerLifetime = packet.get16(6); - reachableTime = packet.get32(8); - retransmissionTimer = packet.get32(12); - handleOptions(packet, 16); - break; - } - - byte[] data = packet.getPayload(); - System.out.println("Payloadsize: " + data.length); - int sum = packet.upperLayerHeaderChecksum(); - sum = IPv6Packet.checkSum(sum, data, data.length); - sum = (~sum) & 0xffff; - if (sum == checksum) { - System.out.println("ICMPv6: Checksum matches!!!"); - } else { - System.out.println("ICMPv6: Checksum error: " + - Utils.hex16(checksum) + " <?> " + Utils.hex16(sum)); - } - } - } - - /* create generic options array instead... */ - private void handleOptions(IPv6Packet packet, int pos) { - int size = packet.getPayloadLength(); - System.out.println("ICMPv6 Options: total size: " + size + " pos: " + pos); - while (pos < size) { - int type = packet.getData(pos); - int oSize = (packet.getData(pos + 1) & 0xff) * 8; - System.out.println("Handling option: " + type + " size " + oSize); - if (oSize == 0) return; - byte[] option = new byte[oSize]; - packet.copy(pos, option, 0, oSize); - options.addElement(option); - pos += oSize; - } - } - - public byte[] generatePacketData(IPv6Packet packet) { - byte[] buffer = new byte[127]; - buffer[0] = (byte) type; - buffer[1] = (byte) code; - /* crc goes at 2/3 */ - int pos = 4; - switch (type) { - case ECHO_REQUEST: - case ECHO_REPLY: - buffer[pos++] = (byte) (id >> 8); - buffer[pos++] = (byte) (id & 0xff); - buffer[pos++] = (byte) (seqNo >> 8); - buffer[pos++] = (byte) (seqNo & 0xff); - if (echoData != null) { - for (int i = 0; i < echoData.length; i++) { - buffer[pos++] = echoData[i]; - } - } - break; - case NEIGHBOR_SOLICITATION: - case NEIGHBOR_ADVERTISEMENT: - if (type == NEIGHBOR_ADVERTISEMENT) { - buffer[pos++] = (byte) flags; - } - pos = 8; - for (int i = 0; i < targetAddress.length; i++) { - buffer[pos++] = targetAddress[i]; - } - pos = addOptions(buffer, pos); - break; - case ROUTER_SOLICITATION: - buffer[pos++] = 0; - buffer[pos++] = 0; - buffer[pos++] = 0; - buffer[pos++] = 0; - pos = addOptions(buffer, pos); - break; - case ROUTER_ADVERTISEMENT: - buffer[pos++] = hopLimit; - buffer[pos++] = autoConfigFlags; - buffer[pos++] = (byte) ((routerLifetime >> 8) & 0xff); - buffer[pos++] = (byte) (routerLifetime & 0xff); - IPv6Packet.set32(buffer, pos, reachableTime); - pos += 4; - IPv6Packet.set32(buffer, pos, retransmissionTimer); - pos += 4; - /* add options */ - pos = addOptions(buffer, pos); - break; - } - - byte[] packetData = new byte[pos]; - System.arraycopy(buffer, 0, packetData, 0, pos); - - /* TODO: this should probably be taken care of in another way - - * for example by allowing the IPPayload packets to set the data - * into the payload which sets the payload length... - */ - packet.payloadLen = pos; - int sum = packet.upperLayerHeaderChecksum(); - sum = IPv6Packet.checkSum(sum, packetData, packetData.length); - sum = (~sum) & 0xffff; - - packetData[2] = (byte) (sum >> 8); - packetData[3] = (byte) (sum & 0xff); - - return packetData; - } - - private int addOptions(byte[] buffer, int pos) { - for (int i = 0; i < options.size(); i++) { - byte[] option = (byte[]) options.elementAt(i); - System.out.println("Adding option: " + option[0] + " len: " + option[1] + - "/" + option.length + " at " + pos); - System.arraycopy(option, 0, buffer, pos, option.length); - pos += option.length; - } - return pos; - } - - public byte getDispatch() { - return DISPATCH; - } - - - public static void main(String[] args) { - byte[] pData = Utils.hexconv("6000000000403a3f200105c01000000a00000000000001ad200105c011024e000212740504030201800070e3de1b00011b87194ad859000008090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637"); - IPv6Packet packet = new IPv6Packet(); - packet.setBytes(pData); - packet.parsePacketData(packet); - if (packet.nextHeader == 58) { - ICMP6Packet icmpPacket = new ICMP6Packet(); - icmpPacket.parsePacketData(packet); - icmpPacket.printPacket(System.out); - } - } -} Deleted: mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,83 +0,0 @@ -package se.sics.mspsim.net; - -public class ICMP6PacketHandler { - - IPStack ipStack; - - public ICMP6PacketHandler(IPStack stack) { - ipStack = stack; - } - - public void handlePacket(IPv6Packet packet) { - ICMP6Packet icmpPacket = new ICMP6Packet(); - icmpPacket.parsePacketData(packet); - packet.setIPPayload(icmpPacket); - - icmpPacket.printPacket(System.out); - - /* handle packet - just a test for now */ - ICMP6Packet p; - IPv6Packet ipp; - switch (icmpPacket.type) { - case ICMP6Packet.ECHO_REQUEST: - p = new ICMP6Packet(); - p.type = ICMP6Packet.ECHO_REPLY; - p.seqNo = icmpPacket.seqNo; - p.id = icmpPacket.id; - p.echoData = icmpPacket.echoData; - ipp = new IPv6Packet(); - ipp.setIPPayload(p); - // is this ok? - ipp.destAddress = packet.sourceAddress; - ipp.sourceAddress = ipStack.myIPAddress; - - ipStack.sendPacket(ipp, packet.netInterface); - break; - case ICMP6Packet.ECHO_REPLY: - System.out.println("ICMP6 got echo reply!!"); - break; - /* this should be handled by the neighbor manager */ - case ICMP6Packet.NEIGHBOR_SOLICITATION: - p = new ICMP6Packet(); - p.targetAddress = icmpPacket.targetAddress; - p.type = ICMP6Packet.NEIGHBOR_ADVERTISEMENT; - p.flags = ICMP6Packet.FLAG_SOLICITED | - ICMP6Packet.FLAG_OVERRIDE; - if (ipStack.isRouter()) { - p.flags |= ICMP6Packet.FLAG_ROUTER; - } - /* always send the linkaddr option */ - p.addLinkOption(ICMP6Packet.TARGET_LINKADDR, ipStack.getLinkLayerAddress()); - ipp = new IPv6Packet(); - ipp.setIPPayload(p); - // is this ok? - ipp.destAddress = packet.sourceAddress; - if (ipp.destAddress[0] == 0xfe && ipp.destAddress[1] == 0x80) { - System.out.print("**** Dest address is link local: "); - IPv6Packet.printAddress(System.out, ipp.destAddress); - System.out.println(); - ipp.sourceAddress = ipStack.myLocalIPAddress; - } else { - ipp.sourceAddress = ipStack.myIPAddress; - } - ipStack.sendPacket(ipp, packet.netInterface); - break; - case ICMP6Packet.ROUTER_SOLICITATION: - ipStack.getNeighborManager().receiveNDMessage(packet); - break; - case ICMP6Packet.ROUTER_ADVERTISEMENT: - if (!ipStack.isRouter()) { - byte[] prefixInfo = icmpPacket.getOption(ICMP6Packet.PREFIX_INFO); - if (prefixInfo != null) { - byte[] prefix = new byte[16]; - System.arraycopy(prefixInfo, 16, prefix, 0, prefix.length); - int size = prefixInfo[2]; - ipStack.setPrefix(prefix, size); - - ipStack.getNeighborManager().receiveNDMessage(packet); - } - } - break; - } - } -} Deleted: mspsim/se/sics/mspsim/net/IEEE802154Handler.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Handler.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/IEEE802154Handler.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,219 +0,0 @@ -/** - * Copyright (c) 2009, 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. - * - * This file is part of MSPSim. - * - * $Id: $ - * - * ----------------------------------------------------------------- - * - * - * Author : Joakim Eriksson - * Created : mar 2009 - * Updated : $Date:$ - * $Revision:$ - */ - -package se.sics.mspsim.net; - -import java.io.PrintStream; - -import se.sics.mspsim.util.Utils; - -public class IEEE802154Handler extends AbstractPacketHandler { - - public static final String SOURCE_PAN_ID = "802154.sourcePAN"; - public static final String SOURCE_MODE = "802154.sourceMode"; - public static final String DESTINATION_PAN_ID = "802154.destPAN"; - public static final String DESTINATION_MODE = "802154.destMode"; - public static final String VERSION = "802154.version"; - - public static final String SEQ_NO = "802154.seqno"; - public static final String PAYLOAD_LEN = "802154.len"; - - public static final int BEACONFRAME = 0x00; - public static final int DATAFRAME = 0x01; - public static final int ACKFRAME = 0x02; - public static final int CMDFRAME = 0x03; - - - public static final int SHORT_ADDRESS = 2; - public static final int LONG_ADDRESS = 3; - - private static final byte[] BROADCAST_ADDR = {(byte)0xff, (byte)0xff}; - - private int defaultAddressMode = LONG_ADDRESS; - private byte seqNo = 0; - - private int myPanID = 0xabcd; - - /* create a 802.15.4 packet of the bytes and "dispatch" to the - * next handler - */ - public void packetReceived(Packet packet) { -// IEEE802154Packet newPacket = new IEEE802154Packet(packet); - /* no dispatch at this level ?! */ - - int type = packet.getData(0) & 7; - int security = (packet.getData(0) >> 3) & 1; - int pending = (packet.getData(0) >> 4) & 1; - int ackRequired = (packet.getData(0) >> 5) & 1; - int panCompression = (packet.getData(0)>> 6) & 1; - int destAddrMode = (packet.getData(1) >> 2) & 3; - int frameVersion = (packet.getData(1) >> 4) & 3; - int srcAddrMode = (packet.getData(1) >> 6) & 3; - int seqNumber = packet.getData(2); - - int pos = 3; - int destPanID = 0; - if (destAddrMode > 0) { - destPanID = (packet.getData(pos) & 0xff) + ((packet.getData(pos + 1) & 0xff) << 8); - packet.setAttribute(DESTINATION_PAN_ID, destPanID); - byte[] destAddress = null; - pos += 2; - if (destAddrMode == SHORT_ADDRESS) { - destAddress = new byte[2]; - destAddress[1] = packet.getData(pos); - destAddress[0] = packet.getData(pos + 1); - pos += 2; - } else if (destAddrMode == LONG_ADDRESS) { - destAddress = new byte[8]; - for (int i = 0; i < 8; i++) { - destAddress[i] = packet.getData(pos + 7 - i); - } - pos += 8; - } - packet.setAttribute(DESTINATION_MODE, destAddrMode); - packet.setAttribute(Packet.LL_DESTINATION, destAddress); - } - - if (srcAddrMode > 0) { - int srcPanID = 0; - if (panCompression == 0){ - srcPanID = (packet.getData(pos) & 0xff) + ((packet.getData(pos + 1) & 0xff) << 8); - pos += 2; - } else { - srcPanID = destPanID; - } - packet.setAttribute(SOURCE_PAN_ID, srcPanID); - byte[] sourceAddress = null; - if (srcAddrMode == SHORT_ADDRESS) { - sourceAddress = new byte[2]; - sourceAddress[1] = packet.getData(pos); - sourceAddress[0] = packet.getData(pos + 1); - pos += 2; - } else if (srcAddrMode == LONG_ADDRESS) { - sourceAddress = new byte[8]; - for (int i = 0; i < 8; i++) { - sourceAddress[i] = packet.getData(pos + 7 - i); - } - pos += 8; - } - packet.setAttribute(SOURCE_MODE, srcAddrMode); - packet.setAttribute(Packet.LL_SOURCE, sourceAddress); - } - packet.incPos(pos); - packet.setAttribute(PAYLOAD_LEN, packet.getPayloadLength()); - packet.setAttribute(VERSION, frameVersion); - packet.setAttribute(SEQ_NO, seqNumber); - System.out.println("802.15.4 Consumed " + pos + " bytes"); - dispatch(-1, packet); - } - - /* create a 802.15.4 packet with the given packet as payload, and - * deliver to the lower layer handler */ - public void sendPacket(Packet packet) { - System.out.println("Packet should be sent!!!"); - byte[] buffer = new byte[127]; - int pos = 0; - int destPanID = 0xabcd; - /* construct a default packet... needs fixing later */ - /* no security, no compression, etc */ - buffer[0] = DATAFRAME; - - int destMode = defaultAddressMode; - int srcMode = defaultAddressMode; - int frameVersion = 0; - - if (Utils.equals(packet.getLinkDestination(), BROADCAST_ADDR)) { - destMode = SHORT_ADDRESS; - destPanID = 0xffff; - } - - buffer[1] = (byte)((destMode << 2) | - (frameVersion << 4) | (srcMode << 6)); - buffer[2] = seqNo++; - - pos = 3; - /* Destination PAN */ - buffer[pos++] = (byte) (destPanID & 0xff); - buffer[pos++] = (byte) (destPanID >> 8); - - byte[] dest = packet.getLinkDestination(); - for (int i = 0; i < dest.length; i++) { - buffer[pos++] = dest[dest.length - i - 1]; - } - - /* Source PAN */ - buffer[pos++] = (byte) (myPanID & 0xff); - buffer[pos++] = (byte) (myPanID >> 8); - - byte[] src = packet.getLinkSource(); - for (int i = 0; i < src.length; i++) { - buffer[pos++] = src[src.length - i - 1]; - } - - byte[] pHeader = new byte[pos]; - System.arraycopy(buffer, 0, pHeader, 0, pos); - packet.prependBytes(pHeader); - - lowerLayer.sendPacket(packet); - } - - public void printPacket(PrintStream out, Packet packet) { - out.print("802.15.4 from " + Utils.hex16(packet.getAttributeAsInt(SOURCE_PAN_ID)) + "/"); - printAddress(out, packet.getAttributeAsInt(SOURCE_MODE), - (byte[]) packet.getAttribute(Packet.LL_SOURCE)); - out.print(" to " + Utils.hex16(packet.getAttributeAsInt(DESTINATION_PAN_ID)) + "/"); - printAddress(out, packet.getAttributeAsInt(DESTINATION_MODE), - (byte[]) packet.getAttribute(Packet.LL_DESTINATION)); - out.println(" seqNo: " + packet.getAttributeAsInt(SEQ_NO) + " vers: " + - packet.getAttributeAsInt(VERSION) + " len: " + - packet.getAttributeAsInt(PAYLOAD_LEN)); - } - - private void printAddress(PrintStream out, int type, byte[] addr) { - if (type == SHORT_ADDRESS) { - out.print(Utils.hex8(addr[0]) + Utils.hex8(addr[1])); - } else if (type == LONG_ADDRESS) { - out.print(Utils.hex8(addr[0]) + Utils.hex8(addr[1]) + ":" + - Utils.hex8(addr[2]) + Utils.hex8(addr[3]) + ":" + - Utils.hex8(addr[4]) + Utils.hex8(addr[5]) + ":" + - Utils.hex8(addr[6]) + Utils.hex8(addr[7])); - } - } -} \ No newline at end of file Deleted: mspsim/se/sics/mspsim/net/LoWPANHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/LoWPANHandler.java 2009-10-09 12:07:11 UTC (rev 623) +++ mspsim/se/sics/mspsim/net/LoWPANHandler.java 2009-10-09 12:11:58 UTC (rev 624) @@ -1,95 +0,0 @@ -/** - * Copyright (c) 2009, 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 ... [truncated message content] |
From: <jo...@us...> - 2009-10-09 12:07:23
|
Revision: 623 http://mspsim.svn.sourceforge.net/mspsim/?rev=623&view=rev Author: joxe Date: 2009-10-09 12:07:11 +0000 (Fri, 09 Oct 2009) Log Message: ----------- removed IP stack from mspsim Modified Paths: -------------- mspsim/se/sics/mspsim/net/CC2420PacketHandler.java Removed Paths: ------------- mspsim/se/sics/mspsim/net/IPPacketer.java mspsim/se/sics/mspsim/net/IPPayload.java mspsim/se/sics/mspsim/net/IPStack.java mspsim/se/sics/mspsim/net/IPv6Packet.java mspsim/se/sics/mspsim/net/Packet.java mspsim/se/sics/mspsim/net/PacketHandler.java mspsim/se/sics/mspsim/net/TCPConnection.java mspsim/se/sics/mspsim/net/TCPHandler.java mspsim/se/sics/mspsim/net/TCPInputStream.java mspsim/se/sics/mspsim/net/TCPListener.java mspsim/se/sics/mspsim/net/TCPOutputStream.java mspsim/se/sics/mspsim/net/TCPPacket.java mspsim/se/sics/mspsim/net/TSPClient.java mspsim/se/sics/mspsim/net/UDPHandler.java mspsim/se/sics/mspsim/net/UDPListener.java mspsim/se/sics/mspsim/net/UDPPacket.java Modified: mspsim/se/sics/mspsim/net/CC2420PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/CC2420PacketHandler.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/CC2420PacketHandler.java 2009-10-09 12:07:11 UTC (rev 623) @@ -41,6 +41,9 @@ package se.sics.mspsim.net; import java.io.PrintStream; + +import se.sics.jipv6.core.AbstractPacketHandler; +import se.sics.jipv6.core.Packet; import se.sics.mspsim.chip.RFListener; import se.sics.mspsim.core.MSP430Core; import se.sics.mspsim.core.TimeEvent; @@ -105,10 +108,6 @@ } - public void packetReceived(Packet container) { - // Never any packets received here... - } - public void printPacket(PrintStream out, Packet packet) { int payloadLen = packet.getAttributeAsInt(CC2420_LEN); out.print("CC2420 | len:" + payloadLen + " | "); @@ -121,7 +120,6 @@ out.println(); } - public void sendPacket(Packet packet) { final Packet sendPacket = packet; byte[] size = new byte[1]; @@ -153,4 +151,7 @@ public void setOutput(PrintStream out) { this.out = out; } + + public void packetReceived(Packet container) { + } } Deleted: mspsim/se/sics/mspsim/net/IPPacketer.java =================================================================== --- mspsim/se/sics/mspsim/net/IPPacketer.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/IPPacketer.java 2009-10-09 12:07:11 UTC (rev 623) @@ -1,20 +0,0 @@ -package se.sics.mspsim.net; - -/* creates and parser IP packets */ -public interface IPPacketer { - - public byte getDispatch(); - - - /* before calling this method a call to route is needed to get - * the link layer addresses into the IPv6Packet - */ - public byte[] generatePacketData(IPv6Packet packet); - - - /* before calling this method the IPv6Packet needs to have its - * link layer addresses added from the link layer - */ - public void parsePacketData(IPv6Packet packet); - -} Deleted: mspsim/se/sics/mspsim/net/IPPayload.java =================================================================== --- mspsim/se/sics/mspsim/net/IPPayload.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/IPPayload.java 2009-10-09 12:07:11 UTC (rev 623) @@ -1,20 +0,0 @@ -package se.sics.mspsim.net; - -import java.io.PrintStream; - -public interface IPPayload { - - public byte getDispatch(); - - /* Call this when payload needs to be externalized - */ - public byte[] generatePacketData(IPv6Packet packet); - - /* - * Call this to parse the IP packet - */ - public void parsePacketData(IPv6Packet packet); - - public void printPacket(PrintStream out); -} - Deleted: mspsim/se/sics/mspsim/net/IPStack.java =================================================================== --- mspsim/se/sics/mspsim/net/IPStack.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/IPStack.java 2009-10-09 12:07:11 UTC (rev 623) @@ -1,375 +0,0 @@ -/** - * Copyright (c) 2009, 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. - * - * This file is part of MSPSim. - * - * $Id: $ - * - * ----------------------------------------------------------------- - * - * IPStack - * - * An IPStack with configurable link layer, etc. - * - * Author : Joakim Eriksson - * Created : mar 2009 - * Updated : $Date:$ - * $Revision:$ - */ - -package se.sics.mspsim.net; -import java.io.IOException; -import java.io.PrintStream; -import java.util.Timer; -import se.sics.mspsim.util.Utils; - -public class IPStack { - - private static final boolean DEBUG = false; - - public static final byte[] ALL_NODES = {(byte) 0xff, 0x02, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1}; - public static final byte[] ALL_ROUTERS = {(byte) 0xff, 0x02, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 2}; - public static final byte[] UNSPECIFIED = {(byte) 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0}; - - byte[] prefix = null; - int prefixSize = 0; - - byte[] myIPAddress = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00}; - byte[] myLocalIPAddress = new byte[] { (byte)0xfe, (byte)0x80, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00}; - - byte[] myLocalSolicited = new byte[] {(byte) 0xff, 0x02, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0x01, (byte) 0xff, 0, 0, 0}; - - /* currently assumes only one link-layer and one address */ - byte[] myLinkAddress = new byte[] {0x00, 0x12, 0x75, 0x04, 0x05, 0x06, 0x07, 0x08}; - - - - byte[] linkBroadcast = new byte[] {(byte) 0xff, (byte) 0xff}; - - private PacketHandler linkLayerHandler; - private IPPacketer defaultPacketer = new HC01Packeter(); - private ICMP6PacketHandler icmp6Handler; - private TCPHandler tcpHandler = null; - private UDPHandler udpHandler = null; - - /* is router -> router behavior */ - private boolean isRouter = false; - - private NetworkInterface tunnel; - //TSPClient - /* this needs to be generalized later... and down to lowpan too... */ - //private HC01Packeter ipPacketer = new HC01Packeter(); - - private NeighborTable neighborTable = new NeighborTable(); - private NeighborManager neighborManager; - private NetworkEventListener networkEventListener; - private Timer timer = new Timer(); - // TODO: read from configfile... - - public IPStack() { - icmp6Handler = new ICMP6PacketHandler(this); - prefix = new byte[] {(byte) 0xaa, (byte)0xaa, 0, 0, 0, 0, 0, 0}; - prefixSize = 64; /* link size */ - configureIPAddress(); - neighborManager = new NeighborManager(this, neighborTable); - tcpHandler = new TCPHandler(this); - udpHandler = new UDPHandler(); - } - - public Timer getTimer() { - return timer; - } - - /* this needs some error handling!!! */ - public TCPConnection listen(int port) { - return tcpHandler.addListenConnection(port); - } - - public void listen(UDPListener listener, int port) throws IOException { - udpHandler.addUDPListener(listener, port); - } - - public NeighborTable getNeighborTable() { - return neighborTable; - } - - public NeighborManager getNeighborManager() { - return neighborManager; - } - - public void setLinkLayerHandler(PacketHandler handler) { - linkLayerHandler = handler; - } - - public void setNetworkEventListener(NetworkEventListener li) { - networkEventListener = li; - } - - public void setTunnel(NetworkInterface tunnel) { - this.tunnel = tunnel; - } - - public void setPrefix(byte[] prefix, int size) { - this.prefix = prefix; - prefixSize = size; - configureIPAddress(); - } - - public boolean isOnLink(byte[] address) { - /* bc or link local */ - if (address[0] == ((byte) 0xff) || (address[0] == ((byte) 0xfe) && - address[1] == ((byte)0x80))) { - return true; - } - - /* unspecified - on link ?? */ - if (Utils.equals(UNSPECIFIED, address)) return true; - /* prefix match? */ - for (int i = 0; i < prefixSize / 8; i++) { - if (address[i] != prefix[i]) return false; - } - return true; - } - - public void configureIPAddress() { - if (prefix != null) { - System.arraycopy(prefix, 0, myIPAddress, 0, prefixSize / 8); - } - for (int i = 0; i < 8; i++) { - myLocalIPAddress[8 + i] = myIPAddress[8 + i] = myLinkAddress[i]; - } - /* autoconfig ?? */ - myLocalIPAddress[8] = myIPAddress[8] = (byte) (myIPAddress[8] ^ 0x02); - - /* create multicast solicited address */ - for (int i = 13; i < 16; i++) { - myLocalSolicited[i] = myIPAddress[i]; - } - - System.out.print("***** Configured IP address: "); - IPv6Packet.printAddress(System.out, myIPAddress); - System.out.println(); - System.out.print("***** Configured Local IP address: "); - IPv6Packet.printAddress(System.out, myLocalIPAddress); - System.out.println(); - System.out.print("***** Configured Solicited IP address: "); - IPv6Packet.printAddress(System.out, myLocalSolicited); - System.out.println(); - } - - private boolean findRoute(IPv6Packet packet) { - // this does not do anything yet... we assume that the low 8 byte is MAC - if (packet.getLinkDestination() == null) { - /* find a MAC address for this packets destination... */ - byte[] destAddr = packet.getDestinationAddress(); - /* is it a bc to all nodes? */ - if (Utils.equals(ALL_ROUTERS, destAddr)) { - packet.setAttribute("link.destination", linkBroadcast); - } else if (Utils.equals(ALL_NODES, destAddr)) { - packet.setAttribute("link.destination", linkBroadcast); - } else { - byte[] destMAC; - Neighbor n = neighborTable.getNeighbor(destAddr); - if (n == null) { - if (neighborTable.getDefrouter() != null) { - destMAC = neighborTable.getDefrouter().linkAddress; - } else { - /* fill the array with a autoconf address ... */ - destMAC = new byte[8]; - makeLLAddress(destAddr, destMAC); - } - } else { - destMAC = n.linkAddress; - } - packet.setAttribute("link.destination", destMAC); - } - } - packet.setAttribute("link.source", myLinkAddress); - return true; - } - - public void makeLLAddress(byte[] ipAddr, byte[] macAddr) { - for (int i = 0; i < macAddr.length; i++) { - macAddr[i] = ipAddr[8 + i]; - } - macAddr[0] = (byte) (macAddr[0] ^ 0x02); - } - - /* send a packet - can be bound for specific interface */ - public void sendPacket(IPv6Packet packet, NetworkInterface nIf) { - /* find route checks if there are link addr, and otherwise sets them */ - if (nIf == linkLayerHandler || - (nIf == null && isOnLink(packet.getDestinationAddress()))) { - if (findRoute(packet)) { - linkLayerHandler.sendPacket(packet); - } - } else { - if (DEBUG) { - System.out.println("*** Should go out on tunnel: " + tunnel); - System.out.print("MyAddress: "); - IPv6Packet.printAddress(System.out, myIPAddress); - System.out.print(", Dest: "); - IPv6Packet.printAddress(System.out, packet.getDestinationAddress()); - } - if (tunnel != null && tunnel.isReady()) { - tunnel.sendPacket(packet); - } - } - } - - public void receivePacket(IPv6Packet packet) { - if (DEBUG) { - System.out.println("IPv6 packet received!"); - packet.printPacket(System.out); - } - - if (isForMe(packet.getDestinationAddress())){ - if (DEBUG) System.out.println("#### PACKET FOR ME!!! " + packet.getDispatch()); - switch (packet.nextHeader) { - case ICMP6Packet.DISPATCH: - icmp6Handler.handlePacket(packet); - if (networkEventListener != null) { - networkEventListener.packetHandled(packet); - } - break; - case UDPPacket.DISPATCH: - // TODO: move to HC01 compression handler... => generate raw UDP - if (packet.getIPPayload() != null) { - packet.getIPPayload().printPacket(System.out); - udpHandler.handlePacket(packet, (UDPPacket) packet.getIPPayload()); - } else { - UDPPacket p = new UDPPacket(); - p.parsePacketData(packet); - p.printPacket(System.out); - packet.setIPPayload(p); - udpHandler.handlePacket(packet, p); - } - if (networkEventListener != null) { - networkEventListener.packetHandled(packet); - } - break; - case TCPPacket.DISPATCH: - TCPPacket p = new TCPPacket(); - p.parsePacketData(packet); - p.printPacket(System.out); - packet.setIPPayload(p); - tcpHandler.handlePacket(packet); - if (networkEventListener != null) { - networkEventListener.packetHandled(packet); - } - break; - } - } else if (!isOnLink(packet.getDestinationAddress()) && - packet.netInterface != tunnel) { - if (DEBUG) System.out.println("**** Should go out on tunnel!!!!" + tunnel); - if (packet.ipPayload == null) { - packet.setIPPayload(new BytePayload(packet)); - } - /* will this work ??? */ - if (DEBUG) { - System.out.print("MyAddress: "); - IPv6Packet.printAddress(System.out, myIPAddress); - System.out.print(", Dest: "); - IPv6Packet.printAddress(System.out, packet.getDestinationAddress()); - } - if (tunnel != null && tunnel.isReady()) { - tunnel.sendPacket(packet); - } - } else if (packet.netInterface != linkLayerHandler) { - /* Can not be from link layer (default) -- */ - /* if HC01 - we need to handle UDP at least... */ - if (DEBUG) System.out.println("#### PACKET FOR: " + packet.getDestinationAddress() + " sent to link"); - if (packet.ipPayload == null) { - packet.setIPPayload(new BytePayload(packet)); - if (findRoute(packet)) { - linkLayerHandler.sendPacket(packet); - } - } - } else { - System.out.println("#### PACKET ignored..."); - } - } - - /* is the packet for me ? */ - private boolean isForMe(byte[] address) { - if (Utils.equals(myIPAddress, address) || - Utils.equals(myLocalIPAddress, address) || - Utils.equals(myLocalSolicited, address)) return true; - if (isRouter && Utils.equals(ALL_ROUTERS, address)) return true; - if (Utils.equals(ALL_NODES, address)) return true; - if (Utils.equals(UNSPECIFIED, address)) return true; - return false; - } - - public void setLinkLayerAddress(byte[] addr) { - myLinkAddress = addr; - configureIPAddress(); - } - - public void setIPAddress(byte[] addr) { - myIPAddress = addr; - } - - public byte[] getLinkLayerAddress() { - return myLinkAddress; - } - - public byte[] getIPAddress() { - return myIPAddress; - } - - public IPPacketer getPacketer() { - return getDefaultPacketer(); - } - - public void setDefaultPacketer(IPPacketer defaultPacketer) { - this.defaultPacketer = defaultPacketer; - } - - public IPPacketer getDefaultPacketer() { - return defaultPacketer; - } - - public void setRouter(boolean isRouter) { - this.isRouter = isRouter; - } - - public boolean isRouter() { - return isRouter ; - } - - public void printTCPStatus(PrintStream out) { - tcpHandler.printStatus(out); - } -} \ No newline at end of file Deleted: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-10-09 12:07:11 UTC (rev 623) @@ -1,326 +0,0 @@ -/** - * Copyright (c) 2009, 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. - * - * This file is part of MSPSim. - * - * $Id: $ - * - * ----------------------------------------------------------------- - * - * IPv6Packet - * - * Author : Joakim Eriksson - * Created : mar 2009 - * Updated : $Date:$ - * $Revision:$ - */ - -package se.sics.mspsim.net; - -import java.io.PrintStream; - -import se.sics.mspsim.util.Utils; - -/** - * @author Joakim Eriksson, SICS - * - */ -public class IPv6Packet extends Packet implements IPPacketer { - - public static final int ICMP6_DISPATCH = 58; - public static final boolean DEBUG = true; - - int version; - int trafficClass; - int flowLabel; - byte nextHeader; - int hopLimit; - byte[] sourceAddress = new byte[16]; - byte[] destAddress = new byte[16]; - - int ipLen = 0; - int payloadLen = 0; - IPPayload ipPayload; - public NetworkInterface netInterface; - - public IPv6Packet() { - version = 6; - flowLabel = 0; - hopLimit = 255; - } - - public IPv6Packet(Packet packet) { - this(); - // copy over all the data from the packet... - // is this the right way to do this??? - this.currentPos = packet.currentPos; - this.attributes = packet.attributes; - this.packetData = packet.packetData; - ipLen = packetData.length - currentPos; - } - - public IPv6Packet(IPPayload pl) { - this(); - nextHeader = pl.getDispatch(); - ipPayload = pl; - } - - public IPv6Packet(IPPayload pl, byte[] source, byte[] dest) { - this(pl); - this.sourceAddress = source; - this.destAddress = dest; - } - - - public IPv6Packet replyPacket(IPPayload payload) { - IPv6Packet ipPacket = new IPv6Packet(); - ipPacket.destAddress = sourceAddress; - ipPacket.ipPayload = payload; - ipPacket.nextHeader = payload.getDispatch(); - return ipPacket; - } - - public byte[] getSourceAddress() { - return sourceAddress; - } - - public void setSourceAddress(byte[] addr) { - sourceAddress = addr; - } - - public byte[] getDestinationAddress() { - return destAddress; - } - - public void setDestinationAddress(byte[] addr) { - destAddress = addr; - } - - public void printPacket(PrintStream out) { - out.print("IPv6: from "); - printAddress(out, sourceAddress); - out.print(" to "); - printAddress(out, destAddress); - out.println(" NxHdr: " + nextHeader); - } - - public static void printAddress(PrintStream out, byte[] address) { - for (int i = 0; i < 16; i+=2) { - out.print(Utils.hex16((((address[i] & 0xff) << 8) | address[i + 1] & 0xff))); - if (i < 14) { - out.print(":"); - } - } - out.println(); - } - - /* this is for setting raw packet data */ -//TODO: should not take an argument here??? it should parse its own -// data array??? - public void parsePacketData(IPv6Packet packet) { - version = (packet.getData(0) & 0xff) >> 4; - if (DEBUG) { - System.out.println("IPv6Packet: version: " + version); - } - if (version != 6) { - return; - } - trafficClass = ((packet.getData(0) & 0x0f)<<4) + - ((packet.getData(1) & 0xff) >> 4); - flowLabel = (packet.getData(1) & 0x0f) << 16 + - (packet.getData(2) & 0xff) << 8 + - packet.getData(3) & 0xff; - payloadLen = ((packet.getData(4) & 0xff) << 8) + packet.getData(5); - nextHeader = packet.getData(6); - hopLimit = packet.getData(7) & 0xff; - packet.copy(8, sourceAddress, 0, 16); - packet.copy(24, destAddress, 0, 16); - // move position 40 bytes forward for handling next headers / payload - packet.incPos(40); - } - - public static void set32(byte[] data, int pos, long value) { - data[pos++] = (byte) ((value >> 24) & 0xff); - data[pos++] = (byte) ((value >> 16) & 0xff); - data[pos++] = (byte) ((value >> 8) & 0xff); - data[pos++] = (byte) (value & 0xff); - } - - public static long getLong(byte[] data, int pos) { - long lval = data[pos] + ((data[pos + 1] & 0xffL) << 8) + - ((data[pos + 2] & 0xffL) << 16) + ((data[pos + 3] & 0xffL) << 24) + - ((data[pos + 4] & 0xffL) << 32) + ((data[pos + 5] & 0xffL)<< 40) + - ((data[pos + 6] & 0xffL) << 48) + ((data[pos + 7] & 0xffL) << 56); - return lval; - } - - /* not yet working checksum code... */ - public int upperLayerHeaderChecksum() { - /* First sum pseudoheader. */ - /* IP protocol and length fields. This addition cannot carry. */ - if (payloadLen == 0) throw new IllegalStateException("No payload length when calculating upper layer checksum."); - int sum = payloadLen + nextHeader; - /* Sum IP source and destination addresses. */ - sum = checkSum(sum, sourceAddress, 16); - sum = checkSum(sum, destAddress, 16); - - /* Sum upper layer header and data is done separately.... */ - /* -- needs to get hold of uncompressed payload for that ... */ - - return sum; - } - - public static int checkSum(int sum, byte[] data, int size) { - for (int i = 0; i < size - 1; i+= 2) { - int dsum = ((data[i] & 0xff) << 8) | (data[i + 1] & 0xff); - sum = (sum + dsum) & 0xffff; - if (sum < dsum) sum++; - } - /* final byte - if any*/ - if ((size & 1) > 0) { - int dsum = ((data[size - 1] & 0xff) << 8); - sum = (sum + dsum) & 0xffff; - if (sum < dsum) sum++; - } - return sum; - } - - public static boolean isMACBased(byte[] address, byte[] macAddress) { - if (address[8] == (macAddress[0] ^ 0x02)) { - for (int i = 1; i < macAddress.length; i++) { - if (address[8 + i] != macAddress[i]) - return false; - } - return true; - } - return false; - } - - public boolean isSourceMACBased() { - byte[] macAddress = getLinkSource(); - return isMACBased(sourceAddress, macAddress); - } - - public boolean isMulticastDestination() { - return (destAddress[0] == (byte)0xff); - } - - /* how can we check this before we know the MAC address??? */ - public boolean isDestinationMACBased() { - byte[] macAddress = getLinkDestination(); - return isMACBased(destAddress, macAddress); - } - - public byte getDispatch() { - return nextHeader; - } - - // TODO: should not take an argument here - should be this packet - // that should be generating the data??? - public byte[] generatePacketData(IPv6Packet packet) { - byte[] payload = ipPayload.generatePacketData(packet); - int size = 40 + payload.length; - byte[] dataPacket = new byte[size]; - - dataPacket[0] = (byte) (0x60 | (trafficClass >> 4) & 0x0f); - dataPacket[1] = (byte) (((trafficClass & 0xf) << 4) | - ((flowLabel >> 16) & 0xf)); - dataPacket[2] = (byte) ((trafficClass >> 8) & 0xff); - dataPacket[3] = (byte) (trafficClass & 0xff); - - dataPacket[4] = (byte) ((payload.length >> 8) & 0xff); - dataPacket[5] = (byte) (payload.length & 0xff); - - dataPacket[6] = (byte) (nextHeader & 0xff); - dataPacket[7] = (byte) (hopLimit & 0xff); - - int pos = 8; - System.arraycopy(packet.getSourceAddress(), 0, dataPacket, pos, 16); - pos += 16; - System.arraycopy(packet.getDestinationAddress(), 0, dataPacket, pos, 16); - pos += 16; - System.arraycopy(payload, 0, dataPacket, 40, payload.length); - return dataPacket; - } - - public IPPayload getIPPayload() { - return ipPayload; - } - - public void setIPPayload(IPPayload ipp) { - ipPayload = ipp; - nextHeader = ipp.getDispatch(); - } - - public static void printMACAddress(PrintStream out, byte[] data, - int pos, int size) { - for (int i = 0; i < size; i++) { - out.print(Utils.hex8(data[i + pos])); - if (i < size - 1) - out.print(":"); - } - } - - /* parse a hex x:y:z... address */ - public static byte[] parseAddress(String addressStr) { - byte[] address = new byte[16]; - int hexVal = 0; - int pos = 0; - int splitPos = 0; - addressStr = addressStr.toLowerCase(); - for (int i = 0; i < addressStr.length() && pos < 16; i++) { - char c = addressStr.charAt(i); - if (c == ':') { - address[pos++] = (byte)(hexVal >> 8); - address[pos++] = (byte)(hexVal & 0xff); - if (i + 1 < addressStr.length() && - addressStr.charAt(i + 1) == ':') { - splitPos = pos; - } - hexVal = 0; - } else if (c >= '0' && c <= '9') { - hexVal = (hexVal << 4) + c - '0'; - } else if (c >= 'a' && c <= 'f') { - hexVal = (hexVal << 4) + c - 'a' + 10; - } - } - if (splitPos != 0) { - // we should move some bytes forward... - } - - return address; - } - - public static void main(String[] args) { - byte[] data = Utils.hexconv("6000000000200001fe80000000000000023048fffe904cd2ff02000000000000000000026c5b5f303a000100050200008300527800000000ff02000000000000000000026c5b5f30"); - IPv6Packet packet = new IPv6Packet(); - packet.setBytes(data); - packet.parsePacketData(packet); - packet.printPacket(System.out); - } - -} \ No newline at end of file Deleted: mspsim/se/sics/mspsim/net/Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/Packet.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/Packet.java 2009-10-09 12:07:11 UTC (rev 623) @@ -1,198 +0,0 @@ -/** - * Copyright (c) 2008, 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. - * - * This file is part of MSPSim. - * - * $Id: $ - * - * ----------------------------------------------------------------- - * - * Packet - * - * Author : Joakim Eriksson - * Created : mar 2009 - * Updated : $Date:$ - * $Revision:$ - */ - -package se.sics.mspsim.net; - -import java.util.Hashtable; - -public class Packet { - - public static final String LL_SOURCE = "link.source"; - public static final String LL_DESTINATION = "link.destination"; - - protected Hashtable attributes = new Hashtable(); - - /* this is the packet data array */ - protected byte[] packetData; - /* current position of packet data cursor */ - int currentPos = 0; - - public void setBytes(byte[] data) { - packetData = data; - currentPos = 0; - } - - public void setBytes(byte[] data, int startPos, int len) { - byte[] payload = new byte[len]; - System.arraycopy(data, startPos, payload, 0, len); - packetData = payload; - /* reset cursor in this case !!! */ - currentPos = 0; - } - - public void appendBytes(byte[] data) { - if (packetData == null) { - packetData = data; - } else { - setPacketData(packetData, data); - } - } - - public void prependBytes(byte[] data) { - if (packetData == null) { - packetData = data; - } else { - setPacketData(data, packetData); - } - } - - private void setPacketData(byte[] data1, byte[] data2) { - byte[] newData = new byte[data1.length + data2.length]; - System.arraycopy(data1, 0, newData, 0, data1.length); - System.arraycopy(data2, 0, newData, data1.length, data2.length); - packetData = newData; - } - - public byte[] getBytes() { - return packetData; - } - - /* total packet length */ - public int getTotalLength() { - return packetData.length; - } - - /* called when headers are parsed to get current payload lenght - * only useful when parsing messages... */ - public int getPayloadLength() { - return packetData.length - currentPos; - } - - public void setAttribute(String name, Object object) { - attributes.put(name, object); - } - - public void setAttribute(String name, int data) { - attributes.put(name, new Integer(data)); - } - - public Object getAttribute(String name) { - return attributes.get(name); - } - - public byte[] getLinkSource() { - return (byte[]) attributes.get(LL_SOURCE); - } - - public byte[] getLinkDestination() { - return (byte[]) attributes.get(LL_DESTINATION); - } - - public int get32(int pos) { - pos = currentPos + pos; - if (packetData.length >= pos + 3) { - return ((packetData[pos] & 0xff) << 24) | - ((packetData[pos + 1] & 0xff) << 16) | - ((packetData[pos + 2] & 0xff) << 8) | - (packetData[pos + 3] & 0xff); - } - return 0; - } - - static int get32(byte[] data, int pos) { - if (data.length >= pos + 3) { - return ((data[pos] & 0xff) << 24) | - ((data[pos + 1] & 0xff) << 16) | - ((data[pos + 2] & 0xff) << 8) | - (data[pos + 3] & 0xff); - } - return 0; - } - - static int get16(byte[] data, int pos) { - if (data.length >= pos + 1) { - return ((data[pos] & 0xff) << 8) | - ((data[pos + 1] & 0xff) << 0); - } - return 0; - } - - - public int get16(int pos) { - pos = currentPos + pos; - if (packetData.length > pos + 1) - return ((packetData[pos] & 0xff) << 8) | packetData[pos + 1] & 0xff; - return 0; - } - - public byte getData(int pos) { - return packetData[currentPos + pos]; - } - - public void incPos(int delta) { - currentPos += delta; - } - - public byte[] getPayload() { - // payload is from pos to end... - byte[] payload = new byte[packetData.length - currentPos]; - System.arraycopy(packetData, currentPos, payload, 0, payload.length); - return payload; - } - - public int getAttributeAsInt(String attr) { - Object val = attributes.get(attr); - if (val instanceof Integer) return ((Integer)val).intValue(); - if (val instanceof String) return Integer.parseInt((String) val); - return -1; - } - - /* copies bytes from currentPos + pos to the given array */ - public void copy(int pos, byte[] dst, int dstPos, int len) { - // TODO Auto-generated method stub - int tPos = pos + currentPos; - System.arraycopy(packetData, tPos, dst, dstPos, len); - } - - public void setData(int pos, byte val) { - packetData[currentPos + pos] = val; - } -} \ No newline at end of file Deleted: mspsim/se/sics/mspsim/net/PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/PacketHandler.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/PacketHandler.java 2009-10-09 12:07:11 UTC (rev 623) @@ -1,10 +0,0 @@ -package se.sics.mspsim.net; - -public interface PacketHandler { - - public void addUpperLayerHandler(int protoID,PacketHandler handler); - public void setLowerLayerHandler(PacketHandler handler); - public void packetReceived(Packet container); - public void sendPacket(Packet packet); - -} Deleted: mspsim/se/sics/mspsim/net/TCPConnection.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPConnection.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/TCPConnection.java 2009-10-09 12:07:11 UTC (rev 623) @@ -1,345 +0,0 @@ -package se.sics.mspsim.net; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import se.sics.mspsim.util.Utils; - -public class TCPConnection { - // States of the connection - public static final int CLOSED = 0; - public static final int LISTEN = 1; - public static final int SYN_SENT = 2; - public static final int SYN_RECEIVED = 3; - public static final int ESTABLISHED = 4; - public static final int CLOSE_WAIT = 5; - public static final int LAST_ACK = 6; - public static final int FIN_WAIT_1 = 7; - public static final int FIN_WAIT_2 = 8; - public static final int CLOSING = 9; - public static final int TIME_WAIT = 10; - - public static final long TIME_WAIT_MILLIS = 1000; - private static final int OUT_BUFFER = 128; - - /* retransmission time in milliseconds */ - int retransmissionTime = 1000; - - // my port & IP (IP can be null here...) - int localPort; - byte[] localIP; - // other port - int externalPort = -1; - byte[] externalIP; - - /* position in connection array - debug */ - byte pos; - - int state; - - /* sent unacked and nextSend byte */ - int sentUnack; - int sendNext; - int sendWindow = TCPPacket.DEFAULT_WINDOW; - - /* last received seqNo + payloadLen*/ - int receiveNext; - int receiveWindow = TCPPacket.DEFAULT_WINDOW; - - private IPStack ipStack; - private NetworkInterface netInterface; - private TCPListener tcpListener; - TCPConnection serverConnection; - - long lastSendTime; - - private byte[] outgoingBuffer = new byte[OUT_BUFFER]; - int bufPos = 0; - int bufNextEmpty = 0; - /* sentUnack == bufPos */ - - private TCPInputStream inputStream; - private TCPOutputStream outputStream; - private boolean closing; - - /* no read timeout */ - int timeout = -1; - - TCPConnection(IPStack stack, NetworkInterface nIf) { - ipStack = stack; - netInterface = nIf; - } - - public InputStream getInputStream() { - if (inputStream == null) { - System.out.println("TCPConnection: creating new input stream..."); - inputStream = new TCPInputStream(this); - /* steal the listener... */ - tcpListener = inputStream.listener; - } - return inputStream; - } - - public OutputStream getOutputStream() { - if (outputStream == null) { - outputStream = new TCPOutputStream(this); - } - return outputStream; - } - - public void setTCPListener(TCPListener listener) { - if (tcpListener == null) { - tcpListener = listener; - } else { - throw new IllegalStateException("TCPListener already set: " + tcpListener); - } - } - - public void newConnection(TCPConnection c) { - if (tcpListener != null) { - tcpListener.newConnection(c); - } - } - - /* check if incoming packet matches */ - public boolean matches(IPv6Packet packet, TCPPacket tcpPacket) { - if ((externalPort == -1 || tcpPacket.sourcePort == externalPort) && - tcpPacket.destinationPort == localPort && - (localIP == null || Utils.equals(localIP, packet.destAddress)) && - (externalIP == null || Utils.equals(externalIP, packet.sourceAddress))) { - return true; - } - return false; - } - - /* send packet + update sendNext - this should take into account ext window */ - /* is this what mess up the stuff */ - public void send(TCPPacket tcpPacket) throws IOException { - IPv6Packet packet = new IPv6Packet(tcpPacket, localIP, externalIP); - tcpPacket.seqNo = sendNext; - tcpPacket.ackNo = receiveNext; - - if (tcpPacket.payload != null) { - copyToBuffer(tcpPacket.payload); - sendNext += tcpPacket.payload.length; - System.out.println("SEND: Updated sendNext: " + sendNext + - " outSize: " + outSize() + " seqDiff: " + - (sendNext - sentUnack)); - } - /* fin also is a payload byte */ - if (tcpPacket.isFin()) { - sendNext++; - } - lastSendTime = System.currentTimeMillis(); - tcpPacket.printPacket(System.out); - ipStack.sendPacket(packet, netInterface); - } - - /* number of currently un-acked bytes in buffer */ - int outSize() { - int bytesToSend = bufNextEmpty - bufPos; - if (bytesToSend < 0) bytesToSend += outgoingBuffer.length; - return bytesToSend; - } - - private synchronized void copyToBuffer(byte[] data) throws IOException { - int empty = outgoingBuffer.length - outSize(); - while (empty < data.length || state == TCPConnection.SYN_RECEIVED - || state == TCPConnection.SYN_SENT) { - /* if closed... just return */ - if (state == TCPConnection.CLOSED) throw new IOException("Connection closed"); - /* need to block this tread until place for data is available...*/ - try { - System.out.println("blocking output... state: " + state); - wait(1000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return; - } - empty = outgoingBuffer.length - outSize(); - } - for (int i = 0; i < data.length; i++) { - outgoingBuffer[bufNextEmpty++] = data[i]; - if (bufNextEmpty >= outgoingBuffer.length) - bufNextEmpty = 0; - } - } - - synchronized void resend() { - TCPPacket tcpPacket; - if (state == FIN_WAIT_1 || state == FIN_WAIT_2) { - /* FIN WAIT 2 should have received ack... but... */ - System.out.println("Resending FIN!!!!"); - tcpPacket = createPacket(); - tcpPacket.flags |= TCPPacket.FIN; - } else { - int size = outSize(); - System.out.println("### Bytes to resend: " + outSize() + " seqDiff: " + - (sendNext - sentUnack)); - /* nothing to resend... TODO: this should handle resend of FIN also! */ - if (size == 0) return; - - if (outSize() < size) size = outSize(); - /* ensure small payload size... this should be handled at IP level...*/ - if (size > 40) { - size = 40; - } - byte[] data = new byte[size]; - int pos = bufPos; - for (int i = 0; i < data.length; i++) { - data[i] = outgoingBuffer[pos++]; - if (pos >= outgoingBuffer.length) { - pos = 0; - } - } - tcpPacket = createPacket(); - tcpPacket.payload = data; - System.out.println("**** TCPConnection resending data: size = " + size); - } - - - IPv6Packet packet = new IPv6Packet(tcpPacket, localIP, externalIP); - tcpPacket.seqNo = sentUnack; - lastSendTime = System.currentTimeMillis(); - tcpPacket.printPacket(System.out); - ipStack.sendPacket(packet, netInterface); - } - - synchronized void receive(TCPPacket tcpPacket) { - int plen = tcpPacket.payload == null ? 0 : tcpPacket.payload.length; - - if (tcpPacket.isAck()) { - /* check if correct ack - this is the "max" case*/ - if (sentUnack <= tcpPacket.ackNo && sendNext >= tcpPacket.ackNo) { - /* no more unacked data */ - int noAcked = tcpPacket.ackNo - sentUnack; - sentUnack = tcpPacket.ackNo; - bufPos += noAcked; - if (bufPos >= outgoingBuffer.length) - bufPos -= outgoingBuffer.length; - System.out.println("ACK for " + noAcked + " bytes. pos: " + bufPos + - " nxtE:" + bufNextEmpty + " unack: " + Integer.toString(sentUnack & 0xffff, 16) + " sendNext: " - + Integer.toString(sendNext & 0xffff, 16) + " outSize: " + outSize() + - " seqDiff: " + (sendNext - sentUnack) + " plen: " + plen); - notify(); - /* this means that we can send more data !!*/ - if (state == ESTABLISHED && closing && outSize() == 0) { - System.out.println("==== Closing connection..."); - state = FIN_WAIT_1; - sendFIN(); - } - } else { - System.out.println("TCPHandler: Unexpected ACK no: " + - Integer.toString(tcpPacket.ackNo & 0xffff, 16) + - " sendNext: " + Integer.toString(sendNext & 0xffff, 16) + " sentUnack: " + - Integer.toString(sentUnack & 0xffff,16)); - if (tcpPacket.ackNo == sentUnack) { - resend(); - } - } - } - - if (tcpPacket.isFin()) { - System.out.println("***** FIN RECEIVED!!!!!"); - } - - if (receiveNext == tcpPacket.seqNo) { - //System.out.println("TCPHandler: data received ok!!!"); - /* only ack if new data arrived! */ - - /* update what to expect next - after this packet! */ - receiveNext = tcpPacket.seqNo + plen; - - /* fin is equal to a packet of 1 additional byte */ - if (tcpPacket.isFin()) { - receiveNext++; - if (plen == 0) sendAck(tcpPacket); - } - - if (plen > 0) { - /* ack the new data! - this could be done from the connection itself!!*/ - sendAck(tcpPacket); - - if (tcpListener != null) { - tcpListener.tcpDataReceived(this, tcpPacket); - } else { - System.out.println("*** ERROR: dropped data: did not have listener..."); - } - } - } else { - /* error - did we miss a packet??? - send ack to say where we are...*/ - System.out.println("TCPHandler: seq error: expSeq: " + - Integer.toString(receiveNext & 0xffff, 16) + " != seqNo: " + - Integer.toString(tcpPacket.seqNo & 0xffff, 16)); - sendAck(tcpPacket); - } - } - - void sendAck(TCPPacket tcpPacket) { - TCPPacket tcpReply = TCPHandler.createAck(tcpPacket, 0); - try { - send(tcpReply); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void send(byte[] bytes) throws IOException { - if (closing) throw new IOException("TCPConnection closing..."); - TCPPacket tcpPacket = createPacket(); - tcpPacket.payload = bytes; - send(tcpPacket); - } - - /* should close autoflush??? */ - public void close() { - if (state == ESTABLISHED) { - System.out.println("=== Closing connection... outSize: " + outSize()); - closing = true; - if (outSize() == 0) { - state = FIN_WAIT_1; - sendFIN(); - } - } - } - - void closed() { - if (tcpListener != null) - tcpListener.connectionClosed(this); - } - - void sendFIN() { - System.out.println("Sending FIN!!!!"); - TCPPacket packet = createPacket(); - packet.flags |= TCPPacket.FIN; - try { - send(packet); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public TCPPacket createPacket() { - TCPPacket tcpPacket = new TCPPacket(); - tcpPacket.sourcePort = localPort; - tcpPacket.destinationPort = externalPort; - return tcpPacket; - } - - public void setTimeout(int tms) { - timeout = tms; - } - - void sendReset() { - System.out.println("Sending RESET!!!!"); - TCPPacket packet = createPacket(); - packet.flags |= TCPPacket.RST; - try { - send(packet); - } catch (IOException e) { - e.printStackTrace(); - } - } -} \ No newline at end of file Deleted: mspsim/se/sics/mspsim/net/TCPHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPHandler.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/TCPHandler.java 2009-10-09 12:07:11 UTC (rev 623) @@ -1,240 +0,0 @@ -package se.sics.mspsim.net; -import java.io.IOException; -import java.io.PrintStream; -import java.util.Timer; -import java.util.TimerTask; - - -public class TCPHandler extends TimerTask { - /* MAX 16 simult. connections for now */ - private static final int MAX_CONNECTIONS = 16; - private static final int MAX_LISTEN = 16; - - TCPConnection[] activeConnections = new TCPConnection[MAX_CONNECTIONS]; - TCPConnection[] listenConnections = new TCPConnection[MAX_LISTEN]; - - int connectionNo = 0; - int listenNo = 0; - IPStack ipStack; - Timer timer; - - public TCPHandler(IPStack stack) { - this.ipStack = stack; - timer = ipStack.getTimer(); - timer.schedule(this, 100, 100); - } - - public synchronized TCPConnection addListenConnection(int port) { - TCPConnection conn = listenConnections[listenNo++] = - new TCPConnection(ipStack, null); - - conn.localPort = port; - conn.state = TCPConnection.LISTEN; - return conn; - } - - private synchronized void addConnection(TCPConnection c) { - c.pos = (byte) connectionNo; - activeConnections[connectionNo++] = c; - } - - public void handlePacket(IPv6Packet packet) { - TCPPacket tcpPacket = (TCPPacket) packet.getIPPayload(); - - TCPConnection connection = findConnection(packet, tcpPacket); - if (connection == null) { - connection = findListenConnection(packet, tcpPacket); - if (connection == null) { - System.out.println("TCPHandler: can not find active or listen connection for this packet"); - } else { - if (tcpPacket.isSyn()) { - TCPPacket tcpReply = createAck(tcpPacket, TCPPacket.SYN); - TCPConnection tc = new TCPConnection(ipStack, packet.netInterface); - /* setup the connection */ - tc.externalIP = packet.sourceAddress; - tc.externalPort = tcpPacket.sourcePort; - tc.localIP = ipStack.myIPAddress; - tc.localPort = tcpPacket.destinationPort; - tc.state = TCPConnection.SYN_RECEIVED; - tc.receiveNext = tcpPacket.seqNo + 1; - tc.sentUnack = tc.sendNext = tcpReply.seqNo = (int) (System.currentTimeMillis() * 7); - - addConnection(tc); - - /* established => report to listeners... */ - connection.newConnection(tc); - - tcpReply.ackNo = tc.receiveNext; - try { - tc.send(tcpReply); - } catch (IOException e) { - e.printStackTrace(); - } - tc.sentUnack = tc.sendNext = tc.sendNext + 1; - tc.serverConnection = connection; - } else { - System.out.println("TCPHandler: dropping packet & sending RST - likely for old connection?"); - TCPPacket tcpReply = tcpPacket.replyPacket(); - tcpReply.flags = TCPPacket.RST | TCPPacket.ACK; - tcpReply.seqNo = tcpPacket.ackNo; - tcpReply.ackNo = tcpPacket.seqNo + 1; - IPv6Packet ipReply = packet.replyPacket(tcpReply); - ipStack.sendPacket(ipReply, packet.netInterface); - } - } - } else { - if (tcpPacket.isReset()) { - /* something is very wrong - just close and remove... */ - connection.state = TCPConnection.CLOSED; - } - switch(connection.state) { - case TCPConnection.SYN_RECEIVED: - if (tcpPacket.isAck()) { - System.out.println("TCPConnection: gotten ACK on syn! => ESTABLISHED!! " + connection.pos); - connection.state = TCPConnection.ESTABLISHED; - connection.receive(tcpPacket); - - synchronized(connection) { - /* for any early outputter to the output stream */ - connection.notify(); - } - } - break; - case TCPConnection.ESTABLISHED: - if (tcpPacket.isFin()) { - System.out.println("TCPConnection: received FIN => CLOSE_WAIT!!!"); - connection.state = TCPConnection.CLOSE_WAIT; - } - - connection.receive(tcpPacket); - break; - case TCPConnection.LAST_ACK: - if (tcpPacket.isAck()) { - System.out.println("Received ACK on FIN => CLOSED! " + connection.pos); - connection.state = TCPConnection.CLOSED; - } - break; - case TCPConnection.FIN_WAIT_1: - if (tcpPacket.isAck()) { - connection.state = TCPConnection.FIN_WAIT_2; - } - if (tcpPacket.isFin()) { - connection.state = TCPConnection.TIME_WAIT; - } - connection.receive(tcpPacket); - break; - case TCPConnection.FIN_WAIT_2: - if (tcpPacket.isFin()) { - System.out.println("TCPHandler: setting connection in TIME_WAIT... " + connection.pos); - connection.state = TCPConnection.TIME_WAIT; - connection.lastSendTime = System.currentTimeMillis(); - connection.receiveNext++; - connection.sendAck(tcpPacket); - } else { - connection.sendReset(); - } - break; - case TCPConnection.CLOSE_WAIT: - /* ignore... */ - connection.sendReset(); - break; - } - } - } - - static TCPPacket createAck(TCPPacket tcpPacket, int flags) { - TCPPacket tcpReply = tcpPacket.replyPacket(); - tcpReply.flags |= flags | TCPPacket.ACK; - return tcpReply; - } - - private TCPConnection findConnection(IPv6Packet packet, TCPPacket tcpPacket) { - for (int i = 0; i < connectionNo; i++) { - if (activeConnections[i].matches(packet, tcpPacket)) { - return activeConnections[i]; - } - } - return null; - } - - private TCPConnection findListenConnection(IPv6Packet packet, TCPPacket tcpPacket) { - for (int i = 0; i < listenNo; i++) { - if (listenConnections[i].matches(packet, tcpPacket)) { - return listenConnections[i]; - } - } - return null; - } - - /* The run method for checking connections, etc */ - public synchronized void run() { - if (connectionNo > 0) { - long time = System.currentTimeMillis(); - for (int i = 0; i < connectionNo; i++) { - TCPConnection connection = activeConnections[i]; - switch (connection.state) { - case TCPConnection.ESTABLISHED: - /* here we should check for retransmissions... */ - if (connection.outSize() > 0 && - (connection.lastSendTime + connection.retransmissionTime < time)) { - System.out.println("### Timeout - retransmitting..."); - connection.resend(); - } - if (connection.timeout != -1) { - /* assume that we acked last incoming packet...? */ - if (connection.lastSendTime + connection.timeout < time) { - connection.close(); - } - } - break; - case TCPConnection.CLOSE_WAIT: - /* if nothing in buffer - close it! */ - if (connection.outSize() == 0) { - System.out.println("Closing - sending FIN"); - connection.state = TCPConnection.LAST_ACK; - connection.sendFIN(); - } else { - /* send something from the buffer */ - connection.resend(); - } - break; - case TCPConnection.FIN_WAIT_1: - case TCPConnection.FIN_WAIT_2: - if (connection.lastSendTime + connection.retransmissionTime < time) { - /* should probably resend the FIN! */ - connection.resend(); - } - break; - case TCPConnection.TIME_WAIT: - /* wait for a while ... */ - if (connection.lastSendTime + TCPConnection.TIME_WAIT_MILLIS < time) { - System.out.println("TCPHandler: TIME_WAIT over => CLOSED!"); - connection.state = TCPConnection.CLOSED; - } - break; - case TCPConnection.CLOSED: - System.out.println("TCPHandler: Connection is closed... removing connection " + connection.pos); - connection.closed(); - connectionNo--; - if (connectionNo > 0) { - /* move the last connection to this position - we do not need - * this any more ??!! - */ - activeConnections[i] = activeConnections[connectionNo]; - activeConnections[i].pos = (byte) i; - i--; /* allow processing of that connection too */ - } - break; - } - } - } - } - - public void printStatus(PrintStream out) { - out.println("---- TCP Connection info ----"); - for (int i = 0; i < connectionNo; i++) { - out.println("* Connection " + i + " in state: " + activeConnections[i].state); - } - } - -} Deleted: mspsim/se/sics/mspsim/net/TCPInputStream.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPInputStream.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/TCPInputStream.java 2009-10-09 12:07:11 UTC (rev 623) @@ -1,94 +0,0 @@ -package se.sics.mspsim.net; - -import java.io.IOException; -import java.io.InputStream; - -public class TCPInputStream extends InputStream { - - private TCPConnection connection; - /* buffer 128 bytes for input... */ - private byte[] inputBuffer = new byte[128]; - private int firstByte = 0; - private int nextEmpty = 0; - boolean closed = false; - long lastReadCall = 0; - - TCPListener listener = new TCPListener() { - public void connectionClosed(TCPConnection connection) { - closed = true; - System.out.println("InputStream - connection closed..."); - notifyReader(); - } - public void newConnection(TCPConnection connection) { - } - public void tcpDataReceived(TCPConnection source, TCPPacket packet) { - byte[] payload = packet.payload; - if (payload == null || payload.length == 0) return; - /* add to cyclic buffer... */ - /* what if we can not accept all data??? */ - int pos = 0; - /* check if it fits!!! */ - if (inputBuffer.length - available() > payload.length) { - while (pos < payload.length) { - inputBuffer[nextEmpty++] = payload[pos++]; - if (nextEmpty >= inputBuffer.length) { - nextEmpty = 0; - } - } - /* notify the possibly sleeping threads that we have data!!! */ - notifyReader(); - } else { - System.out.println("ERROR!!!! packet does not fit buffer... should not ack!!!"); - } - } - }; - - TCPInputStream(TCPConnection connection) { - this.connection = connection; - } - - private synchronized void notifyReader() { - notify(); - } - - public int available() { - int ava = nextEmpty - firstByte; - if (ava < 0) ava += inputBuffer.length; - return ava; - } - - public void close() { - connection.close(); - closed = true; - notifyReader(); - } - - public int read() throws IOException { - if (closed) { - return -1; - } - synchronized(this) { - lastReadCall = System.currentTimeMillis(); - while (!closed && firstByte == nextEmpty) { - try { - wait(1000); - System.out.println("TCPInputStream: waiting for input..."); - if ((connection.timeout != -1) && - lastReadCall + connection.timeout < System.currentTimeMillis()) { - throw new IOException("I/O operation: Read timed out..."); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - if (!closed) { - int data = inputBuffer[firstByte++]; - if (firstByte >= inputBuffer.length) - firstByte = 0; - return (data & 0xff); - } else { - return -1; - } - } -} \ No newline at end of file Deleted: mspsim/se/sics/mspsim/net/TCPListener.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPListener.java 2009-10-09 11:02:00 UTC (rev 622) +++ mspsim/se/sics/mspsim/net/TCPListener.java 2009-10-09 12:07:11 UTC (rev 623) @@ -1,10 +0,0 @@ -package se.sics.mspsim.net; - -public interface TCPListener { - /* only for notifying if this is a listen connection and someone connect... */ - public void newConnection(TCPConnection connection); - /* called whenever this connection was disconnected/closed */ - public void connectionClosed(TCPConnection connection); - /* called when there is new TCP data on the connection */ - public void tcpDataReceived(TCPConnection source, TCPPacket packet); -} Deleted: mspsim/se/sics/mspsim/net/TCPOutputStream.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPOutputStre... [truncated message content] |
From: <jo...@us...> - 2009-10-09 11:02:10
|
Revision: 622 http://mspsim.svn.sourceforge.net/mspsim/?rev=622&view=rev Author: joxe Date: 2009-10-09 11:02:00 +0000 (Fri, 09 Oct 2009) Log Message: ----------- fixed mset Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-09 08:51:54 UTC (rev 621) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-09 11:02:00 UTC (rev 622) @@ -375,11 +375,15 @@ mode = Utils.ASCII; typeRead = true; } + if ("word".equals(arg2)) { + type = Utils.WORD; + typeRead = true; + } } for (int i = typeRead ? 2 : 1; i < count; i++) { if (mode == Utils.DEC) { int val = context.getArgumentAsInt(i); - boolean word = val > 0xff; + boolean word = Utils.size(type) == 2 | val > 0xff; try { cpu.write(adr, val, word); adr += word ? 2 : 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-09 08:52:54
|
Revision: 621 http://mspsim.svn.sourceforge.net/mspsim/?rev=621&view=rev Author: joxe Date: 2009-10-09 08:51:54 +0000 (Fri, 09 Oct 2009) Log Message: ----------- minor fix of mset command Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-09 08:44:04 UTC (rev 620) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-09 08:51:54 UTC (rev 621) @@ -362,7 +362,7 @@ } }); - ch.registerCommand("mset", new BasicCommand("set memory", "<address> [type] <value> ... <value>") { + ch.registerCommand("mset", new BasicCommand("set memory", "<address> [type] <value> [value ...]") { public int executeCommand(final CommandContext context) { int count = context.getArgumentCount(); int adr = context.getArgumentAsAddress(0); @@ -374,7 +374,6 @@ if ("char".equals(arg2)) { mode = Utils.ASCII; typeRead = true; - System.out.println("Found type char"); } } for (int i = typeRead ? 2 : 1; i < count; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-09 08:44:12
|
Revision: 620 http://mspsim.svn.sourceforge.net/mspsim/?rev=620&view=rev Author: joxe Date: 2009-10-09 08:44:04 +0000 (Fri, 09 Oct 2009) Log Message: ----------- fixed mset to accept char and multiple values Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-04 21:51:44 UTC (rev 619) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-09 08:44:04 UTC (rev 620) @@ -219,6 +219,10 @@ public int executeCommand(final CommandContext context) { int adr = context.getArgumentAsAddress(0); DebugInfo di = getELF().getDebugInfo(adr); + if (di == null) { + /* quick hack to test next address too... - since something seems to be off by one sometimes... */ + di = getELF().getDebugInfo(adr + 1); + } if (di != null) { di.getLine(); context.out.println(di); @@ -358,16 +362,38 @@ } }); - ch.registerCommand("mset", new BasicCommand("set memory", "<address> <value> [type]") { + ch.registerCommand("mset", new BasicCommand("set memory", "<address> [type] <value> ... <value>") { public int executeCommand(final CommandContext context) { + int count = context.getArgumentCount(); int adr = context.getArgumentAsAddress(0); - int val = context.getArgumentAsInt(1); - boolean word = val > 0xff; - try { - cpu.write(adr, val, word); - } catch (EmulationException e) { - e.printStackTrace(context.out); + String arg2 = context.getArgument(1); + int type = Utils.BYTE; + int mode = Utils.DEC; + boolean typeRead = false; + if (count > 2) { + if ("char".equals(arg2)) { + mode = Utils.ASCII; + typeRead = true; + System.out.println("Found type char"); + } } + for (int i = typeRead ? 2 : 1; i < count; i++) { + if (mode == Utils.DEC) { + int val = context.getArgumentAsInt(i); + boolean word = val > 0xff; + try { + cpu.write(adr, val, word); + adr += word ? 2 : 1; + } catch (EmulationException e) { + e.printStackTrace(context.out); + } + } else if (mode == Utils.ASCII) { + String data = context.getArgument(i); + for (int j = 0; j < data.length(); j++) { + cpu.write(adr++, data.charAt(j) & 0xff, false); + } + } + } return 0; }}); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-10-04 21:52:29
|
Revision: 619 http://mspsim.svn.sourceforge.net/mspsim/?rev=619&view=rev Author: joxe Date: 2009-10-04 21:51:44 +0000 (Sun, 04 Oct 2009) Log Message: ----------- modified several CLI commands for consistency and improved output Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/cli/MiscCommands.java mspsim/se/sics/mspsim/util/ArgumentManager.java mspsim/se/sics/mspsim/util/ConfigManager.java mspsim/se/sics/mspsim/util/Utils.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-09-28 09:40:09 UTC (rev 618) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-10-04 21:51:44 UTC (rev 619) @@ -316,38 +316,49 @@ } }); - ch.registerCommand("mem", new BasicCommand("dump memory", "<start address> <num_entries> [type]") { + ch.registerCommand("mem", new BasicCommand("dump memory", "<start address> <num_entries> [type] [hex|char]") { public int executeCommand(final CommandContext context) { int start = context.getArgumentAsAddress(0); int count = context.getArgumentAsInt(1); - int size = 1; // unsigned byte + int mode = Utils.DEC; + int type = Utils.UBYTE; boolean signed = false; if (context.getArgumentCount() > 2) { - String tS = context.getArgument(2); - if ("byte".equals(tS)) { - signed = true; - } else if ("word".equals(tS)) { - signed = true; - size = 2; - } else if ("uword".equals(tS)) { - size = 2; - } + int pos = 2; + int acount = context.getArgumentCount(); + if (acount > 4) acount = 4; + while (pos < acount) { + String tS = context.getArgument(pos++); + if ("ubyte".equals(tS)) { + } else if ("byte".equals(tS)) { + type = Utils.BYTE; + } else if ("word".equals(tS)) { + type = Utils.WORD; + } else if ("uword".equals(tS)) { + type = Utils.UWORD; + } else if ("hex".equals(tS)) { + mode = Utils.HEX; + } else if ("char".equals(tS)) { + mode = Utils.ASCII; + type = Utils.BYTE; + } + } } // Does not yet handle signed data... for (int i = 0; i < count; i++) { - int data = 0; - data = cpu.memory[start++]; - if (size == 2) { - data = data + (cpu.memory[start++] << 8); - } - context.out.print(" " + data); + int data = 0; + data = cpu.memory[start++]; + if (Utils.size(type) == 2) { + data = data + (cpu.memory[start++] << 8); + } + context.out.print((mode != Utils.ASCII ? " " : "") + Utils.toString(data, type, mode)); } context.out.println(); return 0; } }); - ch.registerCommand("set", new BasicCommand("set memory", "<address> <value> [type]") { + ch.registerCommand("mset", new BasicCommand("set memory", "<address> <value> [type]") { public int executeCommand(final CommandContext context) { int adr = context.getArgumentAsAddress(0); int val = context.getArgumentAsInt(1); @@ -399,7 +410,7 @@ } }); - ch.registerCommand("xset", new BasicCommand("set memory", "<address> <value> [type]") { + ch.registerCommand("xmset", new BasicCommand("set memory", "<address> <value> [type]") { public int executeCommand(final CommandContext context) { Memory xmem = (Memory) DebugCommands.this.registry.getComponent("xmem"); if (xmem == null) { Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-09-28 09:40:09 UTC (rev 618) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-10-04 21:51:44 UTC (rev 619) @@ -58,6 +58,7 @@ import se.sics.mspsim.util.ActiveComponent; import se.sics.mspsim.util.ArgumentManager; import se.sics.mspsim.util.ComponentRegistry; +import se.sics.mspsim.util.ConfigManager; import se.sics.mspsim.util.PluginRepository; import se.sics.mspsim.util.ServiceComponent; import se.sics.mspsim.util.Utils; @@ -388,7 +389,7 @@ } }); - handler.registerCommand("sysinfo", new BasicCommand("show info about the MSPSim system", "[-registry]") { + handler.registerCommand("sysinfo", new BasicCommand("show info about the MSPSim system", "[-registry] [-config]") { public int executeCommand(CommandContext context) { ArgumentManager config = (ArgumentManager) registry.getComponent("config"); context.out.println("--------- System info ----------\n"); @@ -402,6 +403,10 @@ context.out.println("--------- Registry info --------\n"); registry.printRegistry(context.out); } + if (context.getOption("config")) { + context.out.println("--------- Configuration ---------\n"); + config.print(context.out); + } return 0; } }); @@ -421,6 +426,16 @@ } }); + handler.registerCommand("set", new BasicCommand("set a config parameter", "<parameter> <value>") { + public int executeCommand(CommandContext context) { + ConfigManager config = (ConfigManager) registry.getComponent("config"); + config.setProperty(context.getArgument(0), context.getArgument(1)); + context.out.println("set " + context.getArgument(0) + " to " + context.getArgument(1)); + return 0; + } + }); + + } private static ServiceComponent getServiceForName(ComponentRegistry registry, String name) { Modified: mspsim/se/sics/mspsim/util/ArgumentManager.java =================================================================== --- mspsim/se/sics/mspsim/util/ArgumentManager.java 2009-09-28 09:40:09 UTC (rev 618) +++ mspsim/se/sics/mspsim/util/ArgumentManager.java 2009-10-04 21:51:44 UTC (rev 619) @@ -39,6 +39,7 @@ * $Revision$ */ package se.sics.mspsim.util; +import java.io.PrintStream; import java.util.ArrayList; /** Modified: mspsim/se/sics/mspsim/util/ConfigManager.java =================================================================== --- mspsim/se/sics/mspsim/util/ConfigManager.java 2009-09-28 09:40:09 UTC (rev 618) +++ mspsim/se/sics/mspsim/util/ConfigManager.java 2009-10-04 21:51:44 UTC (rev 619) @@ -47,6 +47,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintStream; import java.net.URL; import java.util.Properties; import java.util.StringTokenizer; @@ -332,4 +333,9 @@ return "true".equals(value) || "yes".equals(value) || "1".equals(value); } + public void print(PrintStream out) { + properties.list(out); + } + + } // ConfigManager Modified: mspsim/se/sics/mspsim/util/Utils.java =================================================================== --- mspsim/se/sics/mspsim/util/Utils.java 2009-09-28 09:40:09 UTC (rev 618) +++ mspsim/se/sics/mspsim/util/Utils.java 2009-10-04 21:51:44 UTC (rev 619) @@ -43,6 +43,34 @@ public class Utils { private static final String str16 = "0000000000000000"; + public static final int BYTE = 0; + public static final int UBYTE = 1; + public static final int WORD = 2; + public static final int UWORD = 3; + + public static final int ASCII = 1; + public static final int HEX = 2; + public static final int DEC = 3; + + public static int size(int type) { + return 1 + (type / 2); + } + + public static String toString(int data, int type, int mode) { + int size = 1 + type / 2; + switch (mode) { + case ASCII: + if (data >= 32 && data <= 127) { + return "" + ((char) data); + } else { + return "."; + } + case HEX: + return (size == 2 ? Utils.hex16(data):Utils.hex8(data)); + } + return "" + data; + } + public static String binary8(int data) { String s = Integer.toString(data, 2); if (s.length() < 8) { @@ -197,6 +225,7 @@ return true; } + // public static void main(String[] args) { // System.out.println("Hex 47 = " + hex8(47)); // } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-09-28 09:40:43
|
Revision: 618 http://mspsim.svn.sourceforge.net/mspsim/?rev=618&view=rev Author: joxe Date: 2009-09-28 09:40:09 +0000 (Mon, 28 Sep 2009) Log Message: ----------- small fixes on UI + fixed warning on RAM access in CC2420 Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/ui/ControlUI.java mspsim/se/sics/mspsim/ui/DebugUI.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2009-09-23 21:13:35 UTC (rev 617) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2009-09-28 09:40:09 UTC (rev 618) @@ -652,6 +652,10 @@ } else { if (!ramRead) { memory[address++] = data; + if (address >= 0x180) { + logger.warning(this, "CC2420: Warning - RAM position too big - wrapping!"); + address = 0; + } if (DEBUG && address == RAM_PANID + 2) { log("Pan ID set to: 0x" + Utils.hex8(memory[RAM_PANID]) + @@ -660,6 +664,10 @@ } else { //log("Read RAM Addr: " + address + " Data: " + memory[address]); source.byteReceived(memory[address++]); + if (address >= 0x180) { + logger.warning(this, "CC2420: Warning - RAM position too big - wrapping!"); + address = 0; + } return; } } Modified: mspsim/se/sics/mspsim/ui/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/ui/ControlUI.java 2009-09-23 21:13:35 UTC (rev 617) +++ mspsim/se/sics/mspsim/ui/ControlUI.java 2009-09-28 09:40:09 UTC (rev 618) @@ -79,12 +79,12 @@ private Action stepAction; private ComponentRegistry registry; -private Status status = Status.STOPPED; + private Status status = Status.STOPPED; -private String name; + private String name; public ControlUI() { - super(new GridLayout(0, 1)); + super(new GridLayout(0, 1)); }; private void setup() { @@ -241,7 +241,6 @@ } } - @Override public Status getStatus() { return status; } Modified: mspsim/se/sics/mspsim/ui/DebugUI.java =================================================================== --- mspsim/se/sics/mspsim/ui/DebugUI.java 2009-09-23 21:13:35 UTC (rev 617) +++ mspsim/se/sics/mspsim/ui/DebugUI.java 2009-09-28 09:40:09 UTC (rev 618) @@ -43,6 +43,7 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; +import java.awt.Dimension; import java.awt.Font; import java.awt.GridLayout; import javax.swing.AbstractListModel; @@ -80,6 +81,7 @@ disList = new JList(listModel = new DbgListModel()); disList.setFont(new Font("courier", 0, 12)); disList.setCellRenderer(new MyCellRenderer()); + disList.setPreferredSize(new Dimension(500, 350)); add(disList, BorderLayout.CENTER); if (showRegs) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-09-23 21:13:45
|
Revision: 617 http://mspsim.svn.sourceforge.net/mspsim/?rev=617&view=rev Author: joxe Date: 2009-09-23 21:13:35 +0000 (Wed, 23 Sep 2009) Log Message: ----------- added error for singlestepping when CPU already runs Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/core/Chip.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-09-23 17:34:28 UTC (rev 616) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-09-23 21:13:35 UTC (rev 617) @@ -247,6 +247,10 @@ public int executeCommand(CommandContext context) { int nr = context.getArgumentCount() > 0 ? context.getArgumentAsInt(0) : 1; long cyc = cpu.cycles; + if (cpu.isRunning()) { + context.err.println("Can not single step when emulation is running."); + return -1; + } try { node.step(nr); } catch (Exception e) { Modified: mspsim/se/sics/mspsim/core/Chip.java =================================================================== --- mspsim/se/sics/mspsim/core/Chip.java 2009-09-23 17:34:28 UTC (rev 616) +++ mspsim/se/sics/mspsim/core/Chip.java 2009-09-23 21:13:35 UTC (rev 617) @@ -44,8 +44,11 @@ import se.sics.mspsim.util.ArrayUtils; /** - * @author Joakim - * + * @author Joakim Eriksson, SICS + * TODO: add a detailed state too (including a listener). State is not necessarily + * related to energy consumption, etc. but more detailed state of the Chip. + * LPM1,2,3 / ON is OperatingModes as well as Transmitting, Listening and Off. + * State can be things such as search for SFD (which is in mode Listen for CC2420). */ public abstract class Chip implements Loggable, EventSource { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-09-23 17:35:06
|
Revision: 616 http://mspsim.svn.sourceforge.net/mspsim/?rev=616&view=rev Author: joxe Date: 2009-09-23 17:34:28 +0000 (Wed, 23 Sep 2009) Log Message: ----------- fixed compilation error for ESB platform - still problems with opening window on ESB Modified Paths: -------------- mspsim/se/sics/mspsim/platform/esb/ESBNode.java Modified: mspsim/se/sics/mspsim/platform/esb/ESBNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2009-09-18 12:05:06 UTC (rev 615) +++ mspsim/se/sics/mspsim/platform/esb/ESBNode.java 2009-09-23 17:34:28 UTC (rev 616) @@ -169,7 +169,7 @@ gui = new ESBGui(this); // A HACK for some "graphs"!!! - DataChart dataChart = new DataChart("Duty Cycle", "Duty Cycle"); + DataChart dataChart = new DataChart(registry, "Duty Cycle", "Duty Cycle"); DataSourceSampler dss = dataChart.setupChipFrame(cpu); dataChart.addDataSource(dss, "Listen", stats.getDataSource("TR1001", TR1001.MODE_RX_ON)); dataChart.addDataSource(dss, "Transmit", stats.getDataSource("TR1001", TR1001.MODE_TXRX_ON)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-09-18 12:05:15
|
Revision: 615 http://mspsim.svn.sourceforge.net/mspsim/?rev=615&view=rev Author: joxe Date: 2009-09-18 12:05:06 +0000 (Fri, 18 Sep 2009) Log Message: ----------- fixed break command to break/stop CPU Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/cli/MiscCommands.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-09-13 21:34:02 UTC (rev 614) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-09-18 12:05:06 UTC (rev 615) @@ -82,6 +82,7 @@ new CPUMonitor() { public void cpuAction(int type, int adr, int data) { context.out.println("*** Break at $" + Utils.hex16(adr)); + cpu.stop(); } }); context.out.println("Breakpoint set at $" + Utils.hex16(baddr)); Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-09-13 21:34:02 UTC (rev 614) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-09-18 12:05:06 UTC (rev 615) @@ -260,7 +260,7 @@ handler.registerCommand("exec", new ExecCommand()); - handler.registerCommand("trig", new BasicLineCommand("trigg command when input match regexp", "<command>") { + handler.registerCommand("trig", new BasicLineCommand("trigg command when getting input", "<command>") { String command = null; CommandContext context; public int executeCommand(CommandContext context) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-09-13 21:34:09
|
Revision: 614 http://mspsim.svn.sourceforge.net/mspsim/?rev=614&view=rev Author: joxe Date: 2009-09-13 21:34:02 +0000 (Sun, 13 Sep 2009) Log Message: ----------- made duty window a service and fixed some minor bugs Modified Paths: -------------- mspsim/scripts/autorun.sc mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java mspsim/se/sics/mspsim/platform/GenericNode.java mspsim/se/sics/mspsim/platform/sky/MoteIVNode.java mspsim/se/sics/mspsim/ui/ControlUI.java mspsim/se/sics/mspsim/ui/StackUI.java Modified: mspsim/scripts/autorun.sc =================================================================== --- mspsim/scripts/autorun.sc 2009-09-13 20:59:29 UTC (rev 613) +++ mspsim/scripts/autorun.sc 2009-09-13 21:34:02 UTC (rev 614) @@ -8,8 +8,8 @@ # install ContikiChecker # contikichecker -#start the nodegui serice +#start the nodegui service service controlgui start service nodegui start -service stackui start +#service stackchart start start Modified: mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java =================================================================== --- mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java 2009-09-13 20:59:29 UTC (rev 613) +++ mspsim/se/sics/mspsim/extutil/jfreechart/DataChart.java 2009-09-13 21:34:02 UTC (rev 614) @@ -2,7 +2,6 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; -import javax.swing.JFrame; import javax.swing.JPanel; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; @@ -14,16 +13,29 @@ import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import se.sics.mspsim.core.MSP430; -import se.sics.mspsim.ui.WindowUtils; +import se.sics.mspsim.ui.ManagedWindow; +import se.sics.mspsim.ui.WindowManager; +import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.DataSource; +import se.sics.mspsim.util.ServiceComponent; import se.sics.mspsim.util.StackMonitor; +import se.sics.mspsim.util.ServiceComponent.Status; @SuppressWarnings("serial") -public class DataChart extends JPanel { +public class DataChart extends JPanel implements ServiceComponent { + private enum Mode {NONE, STACK, DUTY}; + private Mode mode = Mode.NONE; + private TimeSeriesCollection dataset; - - public DataChart(String title, String yaxis) { + private ComponentRegistry registry; + private ManagedWindow jw; + private MSP430 cpu; + private DataSourceSampler dss; + private Status status = Status.STOPPED; + private String name = null; + + public DataChart(ComponentRegistry registry, String title, String yaxis) { DateAxis domain = new DateAxis("Time"); NumberAxis range = new NumberAxis(yaxis); XYPlot xyplot = new XYPlot(); @@ -64,36 +76,43 @@ dataset.addSeries(ts); } - private JFrame openFrame(String name) { - JFrame jw = new JFrame(name); + private ManagedWindow openFrame(String name) { + WindowManager wm = (WindowManager) registry.getComponent("windowManager"); + ManagedWindow jw = wm.createWindow(name); jw.add(this); - WindowUtils.restoreWindowBounds(name, jw); - WindowUtils.addSaveOnShutdown(name, jw); -// jw.setBounds(100, 100, 400, 200); return jw; } + + public void setupStackFrame(MSP430 cpu) { - JFrame jw = openFrame("Stack Monitor"); - StackMonitor sm = new StackMonitor(cpu); - DataSourceSampler dss = new DataSourceSampler(cpu); - TimeSeries ts = new TimeSeries("Max Stack", Millisecond.class); - ts.setMaximumItemCount(200); - addTimeSeries(ts); - dss.addDataSource(sm.getMaxSource(), ts); - ts = new TimeSeries("Stack", Millisecond.class); - ts.setMaximumItemCount(200); - addTimeSeries(ts); - dss.addDataSource(sm.getSource(), ts); - jw.setVisible(true); + mode = Mode.STACK; + this.cpu = cpu; } + + private void openStackFrame() { + if (jw == null) { + jw = openFrame("Stack Monitor"); + StackMonitor sm = new StackMonitor(cpu); + DataSourceSampler dss = new DataSourceSampler(cpu); + TimeSeries ts = new TimeSeries("Max Stack", Millisecond.class); + ts.setMaximumItemCount(200); + addTimeSeries(ts); + dss.addDataSource(sm.getMaxSource(), ts); + ts = new TimeSeries("Stack", Millisecond.class); + ts.setMaximumItemCount(200); + addTimeSeries(ts); + dss.addDataSource(sm.getSource(), ts); + } + } public DataSourceSampler setupChipFrame(MSP430 cpu) { - JFrame jw = openFrame("Duty-Cycle Monitor"); - DataSourceSampler dss = new DataSourceSampler(cpu); - dss.setInterval(50); - jw.setVisible(true); - return dss; + mode = Mode.DUTY; + this.cpu = cpu; + jw = openFrame("Duty-Cycle Monitor"); + dss = new DataSourceSampler(cpu); + dss.setInterval(50); + return dss; } public void addDataSource(DataSourceSampler dss, String name, DataSource src) { @@ -102,4 +121,37 @@ addTimeSeries(ts); dss.addDataSource(src, ts); } -} + + public Status getStatus() { + return status; + } + + public void init(String name, ComponentRegistry registry) { + this.registry = registry; + this.name = name; + } + + public void start() { + if (mode == Mode.STACK) { + openStackFrame(); + } else { + dss.start(); + } + jw.setVisible(true); + status = Status.STARTED; + } + + public void stop() { + jw.setVisible(false); + if (mode == Mode.STACK) { + // ? + } else { + dss.stop(); + } + status = Status.STOPPED; + } + + public String getName() { + return name; + } +} \ No newline at end of file Modified: mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java =================================================================== --- mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java 2009-09-13 20:59:29 UTC (rev 613) +++ mspsim/se/sics/mspsim/extutil/jfreechart/DataSourceSampler.java 2009-09-13 21:34:02 UTC (rev 614) @@ -25,7 +25,15 @@ timer = new Timer(interval, this); timer.start(); } + + public void stop() { + timer.stop(); + } + public void start() { + timer.start(); + } + public TimeSource addDataSource(DataSource source, TimeSeries ts) { TimeSource times = new TimeSource(cpu, source, ts); sources.add(times); Modified: mspsim/se/sics/mspsim/platform/GenericNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/GenericNode.java 2009-09-13 20:59:29 UTC (rev 613) +++ mspsim/se/sics/mspsim/platform/GenericNode.java 2009-09-13 21:34:02 UTC (rev 614) @@ -147,7 +147,7 @@ // Setup control and other UI components ControlUI control = new ControlUI(); registry.registerComponent("controlgui", control); - registry.registerComponent("stackui", new StackUI(cpu)); + registry.registerComponent("stackchart", new StackUI(cpu)); HighlightSourceViewer sourceViewer = new HighlightSourceViewer(); if (firmwareFile != null) { // Add the firmware location to the search path Modified: mspsim/se/sics/mspsim/platform/sky/MoteIVNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/MoteIVNode.java 2009-09-13 20:59:29 UTC (rev 613) +++ mspsim/se/sics/mspsim/platform/sky/MoteIVNode.java 2009-09-13 21:34:02 UTC (rev 614) @@ -194,7 +194,8 @@ registry.registerComponent("nodegui", gui); // A HACK for some "graphs"!!! - DataChart dataChart = new DataChart("Duty Cycle", "Duty Cycle"); + DataChart dataChart = new DataChart(registry, "Duty Cycle", "Duty Cycle"); + registry.registerComponent("dutychart", dataChart); DataSourceSampler dss = dataChart.setupChipFrame(cpu); dataChart.addDataSource(dss, "LEDS", stats.getDataSource(getName(), 0, OperatingModeStatistics.OP_INVERT)); dataChart.addDataSource(dss, "Listen", stats.getDataSource("CC2420", CC2420.MODE_RX_ON)); Modified: mspsim/se/sics/mspsim/ui/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/ui/ControlUI.java 2009-09-13 20:59:29 UTC (rev 613) +++ mspsim/se/sics/mspsim/ui/ControlUI.java 2009-09-13 21:34:02 UTC (rev 614) @@ -79,7 +79,7 @@ private Action stepAction; private ComponentRegistry registry; -private Status status; +private Status status = Status.STOPPED; private String name; Modified: mspsim/se/sics/mspsim/ui/StackUI.java =================================================================== --- mspsim/se/sics/mspsim/ui/StackUI.java 2009-09-13 20:59:29 UTC (rev 613) +++ mspsim/se/sics/mspsim/ui/StackUI.java 2009-09-13 21:34:02 UTC (rev 614) @@ -80,7 +80,7 @@ private boolean update = false; -private Status status; +private Status status = Status.STOPPED; private ComponentRegistry registry; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-09-13 20:59:37
|
Revision: 613 http://mspsim.svn.sourceforge.net/mspsim/?rev=613&view=rev Author: joxe Date: 2009-09-13 20:59:29 +0000 (Sun, 13 Sep 2009) Log Message: ----------- fixed minor bugs Modified Paths: -------------- mspsim/se/sics/mspsim/cli/MiscCommands.java Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-09-13 19:37:19 UTC (rev 612) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-09-13 20:59:29 UTC (rev 613) @@ -312,7 +312,7 @@ } }); - handler.registerCommand("service", new BasicCommand("handle service plugins", "[class name|service name] [start|stop|install]") { + handler.registerCommand("service", new BasicCommand("handle service plugins", "[class name|service name] [start|stop]") { @Override public int executeCommand(CommandContext context) { if (context.getArgumentCount() == 0) { @@ -342,8 +342,8 @@ } else if ("stop".equals(operation)) { ServiceComponent sc = getServiceForName(registry, name); if (sc != null) { - sc.start(); - context.out.println("service " + sc.getName() + " started"); + sc.stop(); + context.out.println("service " + sc.getName() + " stopped"); } else { context.out.println("can not find service" + name); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |