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: <jo...@us...> - 2009-09-07 15:06:09
|
Revision: 587 http://mspsim.svn.sourceforge.net/mspsim/?rev=587&view=rev Author: joxe Date: 2009-09-07 15:05:58 +0000 (Mon, 07 Sep 2009) Log Message: ----------- added API for adding/removing call listeners to profilers Modified Paths: -------------- mspsim/se/sics/mspsim/core/Profiler.java mspsim/se/sics/mspsim/util/SimpleProfiler.java Added Paths: ----------- mspsim/se/sics/mspsim/profiler/ mspsim/se/sics/mspsim/profiler/CallListener.java Modified: mspsim/se/sics/mspsim/core/Profiler.java =================================================================== --- mspsim/se/sics/mspsim/core/Profiler.java 2009-09-07 14:37:06 UTC (rev 586) +++ mspsim/se/sics/mspsim/core/Profiler.java 2009-09-07 15:05:58 UTC (rev 587) @@ -43,6 +43,7 @@ import java.io.PrintStream; import java.util.Properties; +import se.sics.mspsim.profiler.CallListener; import se.sics.mspsim.util.MapEntry; public interface Profiler { @@ -60,6 +61,9 @@ public void clearProfile(); + public void addCallListener(CallListener listener); + public void removeCallListener(CallListener listener); + public void printProfile(PrintStream out); public void printProfile(PrintStream out, Properties parameters); Added: mspsim/se/sics/mspsim/profiler/CallListener.java =================================================================== --- mspsim/se/sics/mspsim/profiler/CallListener.java (rev 0) +++ mspsim/se/sics/mspsim/profiler/CallListener.java 2009-09-07 15:05:58 UTC (rev 587) @@ -0,0 +1,12 @@ +package se.sics.mspsim.profiler; + +import se.sics.mspsim.core.Profiler; +import se.sics.mspsim.util.MapEntry; + +public interface CallListener { + + public void functionCall(Profiler source, MapEntry entry); + + public void functionReturn(Profiler source, MapEntry entry); + +} Modified: mspsim/se/sics/mspsim/util/SimpleProfiler.java =================================================================== --- mspsim/se/sics/mspsim/util/SimpleProfiler.java 2009-09-07 14:37:06 UTC (rev 586) +++ mspsim/se/sics/mspsim/util/SimpleProfiler.java 2009-09-07 15:05:58 UTC (rev 587) @@ -45,6 +45,8 @@ import se.sics.mspsim.core.EventSource; import se.sics.mspsim.core.MSP430Core; import se.sics.mspsim.core.Profiler; +import se.sics.mspsim.profiler.CallListener; + import java.io.PrintStream; import java.util.Arrays; import java.util.Collections; @@ -449,4 +451,14 @@ } } } + + @Override + public void addCallListener(CallListener listener) { + // TODO + } + + @Override + public void removeCallListener(CallListener listener) { + // TODO + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-09-07 14:37:20
|
Revision: 586 http://mspsim.svn.sourceforge.net/mspsim/?rev=586&view=rev Author: joxe Date: 2009-09-07 14:37:06 +0000 (Mon, 07 Sep 2009) Log Message: ----------- added possibility to install plugins Modified Paths: -------------- mspsim/se/sics/mspsim/cli/CommandHandler.java mspsim/se/sics/mspsim/cli/MiscCommands.java mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/platform/GenericNode.java mspsim/se/sics/mspsim/util/ActiveComponent.java mspsim/se/sics/mspsim/util/ComponentRegistry.java mspsim/se/sics/mspsim/util/IHexReader.java mspsim/se/sics/mspsim/util/Test.java Modified: mspsim/se/sics/mspsim/cli/CommandHandler.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandHandler.java 2009-09-07 13:36:35 UTC (rev 585) +++ mspsim/se/sics/mspsim/cli/CommandHandler.java 2009-09-07 14:37:06 UTC (rev 586) @@ -166,7 +166,7 @@ return cmds; } - public void setComponentRegistry(ComponentRegistry registry) { + public void init(String name, ComponentRegistry registry) { this.registry = registry; } Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-09-07 13:36:35 UTC (rev 585) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-09-07 14:37:06 UTC (rev 586) @@ -54,6 +54,7 @@ import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.TimeEvent; +import se.sics.mspsim.util.ActiveComponent; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.Utils; @@ -307,6 +308,28 @@ context.executeCommand(command); } }); + + handler.registerCommand("install", new BasicCommand("install and start a plugin", "ClassName") { + @Override + public int executeCommand(CommandContext context) { + String className = context.getArgument(0); + Class pluginClass = null; + try { + try { + pluginClass = Class.forName(className); + } catch (ClassNotFoundException e) { + pluginClass = Class.forName("se.sics.mspsim.plugin." + className); + } + ActiveComponent component = (ActiveComponent) pluginClass.newInstance(); + registry.registerComponent(className, component); + return 0; + } catch (Exception e1) { // TODO Auto-generated catch block + e1.printStackTrace(context.err); + } + // TODO Auto-generated method stub + return 1; + } + }); handler.registerCommand("rflistener", new BasicLineCommand("an rflisteer", "[input|output] <rf-chip>") { CommandContext context; Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2009-09-07 13:36:35 UTC (rev 585) +++ mspsim/se/sics/mspsim/core/MSP430.java 2009-09-07 14:37:06 UTC (rev 586) @@ -74,8 +74,8 @@ * Creates a new <code>MSP430</code> instance. * */ - public MSP430(int type) { - super(type); + public MSP430(int type, ComponentRegistry registry) { + super(type, registry); disAsm = new DisAsm(); addChip(this); } Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-09-07 13:36:35 UTC (rev 585) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-09-07 14:37:06 UTC (rev 586) @@ -43,6 +43,7 @@ import java.io.PrintStream; import java.util.ArrayList; +import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.MapEntry; import se.sics.mspsim.util.MapTable; import se.sics.mspsim.util.Utils; @@ -126,12 +127,14 @@ private BasicClockModule bcs; private ArrayList<Chip> chips = new ArrayList<Chip>(); + ComponentRegistry registry; Profiler profiler; private Flash flash; - public MSP430Core(int type) { + public MSP430Core(int type, ComponentRegistry registry) { // Ignore type for now... setModeNames(MODE_NAMES); + this.registry = registry; int passIO = 0; // IOUnits should likely be placed in a hashtable? // Maybe for debugging purposes... @@ -258,7 +261,9 @@ } public void setProfiler(Profiler prof) { + registry.registerComponent("profiler", prof); profiler = prof; + profiler.setCPU(this); } /* returns port 1 ... 6 */ Modified: mspsim/se/sics/mspsim/platform/GenericNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/GenericNode.java 2009-09-07 13:36:35 UTC (rev 585) +++ mspsim/se/sics/mspsim/platform/GenericNode.java 2009-09-07 14:37:06 UTC (rev 586) @@ -74,7 +74,7 @@ protected ConfigManager config; protected ComponentRegistry registry = new ComponentRegistry(); - protected MSP430 cpu = new MSP430(0); + protected MSP430 cpu = new MSP430(0, registry); protected String firmwareFile = null; protected ELF elf; protected OperatingModeStatistics stats; Modified: mspsim/se/sics/mspsim/util/ActiveComponent.java =================================================================== --- mspsim/se/sics/mspsim/util/ActiveComponent.java 2009-09-07 13:36:35 UTC (rev 585) +++ mspsim/se/sics/mspsim/util/ActiveComponent.java 2009-09-07 14:37:06 UTC (rev 586) @@ -1,6 +1,6 @@ package se.sics.mspsim.util; public interface ActiveComponent { - public void setComponentRegistry(ComponentRegistry registry); + public void init(String name, ComponentRegistry registry); public void start(); } Modified: mspsim/se/sics/mspsim/util/ComponentRegistry.java =================================================================== --- mspsim/se/sics/mspsim/util/ComponentRegistry.java 2009-09-07 13:36:35 UTC (rev 585) +++ mspsim/se/sics/mspsim/util/ComponentRegistry.java 2009-09-07 14:37:06 UTC (rev 586) @@ -4,13 +4,17 @@ public class ComponentRegistry { private ArrayList<ComponentEntry> components = new ArrayList<ComponentEntry>(); + private boolean running = false; public void registerComponent(String name, Object component) { synchronized (components) { components.add(new ComponentEntry(name, component)); } if (component instanceof ActiveComponent) { - ((ActiveComponent)component).setComponentRegistry(this); + ((ActiveComponent)component).init(name, this); + if (running) { + ((ActiveComponent)component).start(); + } } } @@ -59,6 +63,7 @@ public void start() { ComponentEntry[] plugs; synchronized (this) { + running = true; plugs = components.toArray(new ComponentEntry[components.size()]); } for (int i = 0; i < plugs.length; i++) { Modified: mspsim/se/sics/mspsim/util/IHexReader.java =================================================================== --- mspsim/se/sics/mspsim/util/IHexReader.java 2009-09-07 13:36:35 UTC (rev 585) +++ mspsim/se/sics/mspsim/util/IHexReader.java 2009-09-07 14:37:06 UTC (rev 586) @@ -138,7 +138,7 @@ // System.out.println("T ^ T => " + (true ^ true) + // " T ^ F => " + (false ^ true)); - MSP430 cpu = new MSP430(0); + MSP430 cpu = new MSP430(0, new ComponentRegistry()); int[] memory = cpu.getMemory(); reader.readFile(memory, args[0]); cpu.reset(); Modified: mspsim/se/sics/mspsim/util/Test.java =================================================================== --- mspsim/se/sics/mspsim/util/Test.java 2009-09-07 13:36:35 UTC (rev 585) +++ mspsim/se/sics/mspsim/util/Test.java 2009-09-07 14:37:06 UTC (rev 586) @@ -83,7 +83,7 @@ } public static void main(String[] args) { - MSP430 cpu = new MSP430(0); + MSP430 cpu = new MSP430(0, new ComponentRegistry()); int index = 0; if (args[index].startsWith("-")) { // Flag This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-09-07 13:36:46
|
Revision: 585 http://mspsim.svn.sourceforge.net/mspsim/?rev=585&view=rev Author: joxe Date: 2009-09-07 13:36:35 +0000 (Mon, 07 Sep 2009) Log Message: ----------- applied patch for profiler and added sort modes plus arguments to the CLI profile command - thanks to Conrado PLG Modified Paths: -------------- mspsim/se/sics/mspsim/cli/ProfilerCommands.java mspsim/se/sics/mspsim/core/Profiler.java mspsim/se/sics/mspsim/util/SimpleProfiler.java Modified: mspsim/se/sics/mspsim/cli/ProfilerCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/ProfilerCommands.java 2009-09-06 21:59:23 UTC (rev 584) +++ mspsim/se/sics/mspsim/cli/ProfilerCommands.java 2009-09-07 13:36:35 UTC (rev 585) @@ -39,6 +39,8 @@ */ package se.sics.mspsim.cli; +import java.util.Properties; + import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.EventListener; import se.sics.mspsim.core.EventSource; @@ -56,27 +58,51 @@ final MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); if (cpu != null) { ch.registerCommand("profile", new BasicCommand("show profile information", - "[-clear] [regexp]") { + "[-clear] [-sort column] [-showcallers] [regexp]") { public int executeCommand(final CommandContext context) { Profiler profiler = cpu.getProfiler(); if (profiler == null) { context.err.println("No profiler found."); return 1; } - if (context.getArgumentCount() > 1) { - context.err.println("Too many arguments. Either clear or show profile information."); - return 1; - } String namematch = null; - if (context.getArgumentCount() > 0) { - namematch = context.getArgument(0); - if ("-clear".equals(namematch)) { + String sortMode = null; + String showCaller = null; + + for (int i = 0; i < context.getArgumentCount(); i++) { + String value = context.getArgument(i); + if ("-clear".equals(value)) { profiler.clearProfile(); context.out.println("Cleared profile information."); return 0; + } else if ("-sort".equals(value)) { + if (context.getArgumentCount() > i + 1) { + sortMode = context.getArgument(i + 1); + i++; + } else { + context.err.println("Missing mode argument for -sort."); + return 1; + } + } else if ("-showcallers".equals(value)) { + showCaller = value; + } else if (namematch != null) { + context.err.println("Too many arguments. Either clear or show profile information."); + } else { + namematch = value; } } - profiler.printProfile(context.out, namematch); + + Properties params = new Properties(); + if (namematch != null) { + params.put(Profiler.PARAM_FUNCTION_NAME_REGEXP, namematch); + } + if (showCaller != null) { + params.put(Profiler.PARAM_PROFILE_CALLERS, showCaller); + } + if (sortMode != null) { + params.put(Profiler.PARAM_SORT_MODE, sortMode); + } + profiler.printProfile(context.out, params); return 0; } }); Modified: mspsim/se/sics/mspsim/core/Profiler.java =================================================================== --- mspsim/se/sics/mspsim/core/Profiler.java 2009-09-06 21:59:23 UTC (rev 584) +++ mspsim/se/sics/mspsim/core/Profiler.java 2009-09-07 13:36:35 UTC (rev 585) @@ -41,10 +41,16 @@ package se.sics.mspsim.core; import java.io.PrintStream; +import java.util.Properties; + import se.sics.mspsim.util.MapEntry; public interface Profiler { + public static final String PARAM_FUNCTION_NAME_REGEXP = "function.regexp"; + public static final String PARAM_PROFILE_CALLERS = "showcallers"; + public static final String PARAM_SORT_MODE = "sortmode"; + public void setCPU(MSP430Core cpu); public void profileCall(MapEntry entry, long cycles); @@ -56,7 +62,7 @@ public void printProfile(PrintStream out); - public void printProfile(PrintStream out, String functionNameRegexp); + public void printProfile(PrintStream out, Properties parameters); public void printStackTrace(PrintStream out); Modified: mspsim/se/sics/mspsim/util/SimpleProfiler.java =================================================================== --- mspsim/se/sics/mspsim/util/SimpleProfiler.java 2009-09-06 21:59:23 UTC (rev 584) +++ mspsim/se/sics/mspsim/util/SimpleProfiler.java 2009-09-07 13:36:35 UTC (rev 585) @@ -47,12 +47,18 @@ import se.sics.mspsim.core.Profiler; import java.io.PrintStream; import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; +import java.util.Map.Entry; import java.util.regex.Pattern; public class SimpleProfiler implements Profiler, EventListener { - + private HashMap<MapEntry,CallEntry> profileData; private HashMap<String, TagEntry> tagProfiles; private HashMap<String, TagEntry> startTags; @@ -124,6 +130,7 @@ ce.function = entry; ce.calls = 0; ce.cycles = cycles; + ce.exclusiveCycles = cycles; ce.hide = hide; newIRQ = false; } @@ -139,6 +146,10 @@ // System.out.println("Profiler: return / call stack: " + cSP + ", " + fkn); long elapsed = cycles - cspEntry.cycles; + long exElapsed = cycles - cspEntry.exclusiveCycles; + if (cSP != 0) { + callStack[cSP-1].exclusiveCycles += elapsed; + } if (cspEntry.calls >= 0) { CallEntry ce = profileData.get(fkn); if (ce == null) { @@ -146,7 +157,18 @@ ce.function = fkn; } ce.cycles += elapsed; + ce.exclusiveCycles += exElapsed; ce.calls++; + if (cSP != 0) { + MapEntry caller = callStack[cSP-1].function; + HashMap<MapEntry,Integer> callers = ce.callers; + Integer numCalls = callers.get(caller); + if (numCalls == null) { + callers.put(caller, 1); + } else { + callers.put(caller, numCalls + 1); + } + } if (logger != null) { if ((cspEntry.hide <= 1) && (!hideIRQ || servicedInterrupt == -1)) { @@ -202,16 +224,20 @@ } } public void printProfile(PrintStream out) { - printProfile(out, null); + printProfile(out, new Properties()); } - public void printProfile(PrintStream out, String functionNameRegexp) { + public void printProfile(PrintStream out, Properties parameters) { + String functionNameRegexp = parameters.getProperty(PARAM_FUNCTION_NAME_REGEXP); + String profSort = parameters.getProperty(PARAM_SORT_MODE); + boolean profCallers = parameters.getProperty(PARAM_PROFILE_CALLERS) != null; Pattern pattern = null; CallEntry[] entries = profileData.values().toArray(new CallEntry[profileData.size()]); - Arrays.sort(entries); + Arrays.sort(entries, new CallEntryComparator(profSort)); + out.println("************************* Profile Data **************************************"); - out.println("Function Average Calls Tot.Cycles"); + out.println("Function Calls Average Total Exclusive"); if (functionNameRegexp != null && functionNameRegexp.length() > 0) { pattern = Pattern.compile(functionNameRegexp); @@ -222,17 +248,23 @@ String functionName = entries[i].function.getName(); if (pattern == null || pattern.matcher(functionName).find()) { String cyclesS = "" + entries[i].cycles; + String exCyclesS = "" + entries[i].exclusiveCycles; String callS = "" + c; String avgS = "" + (c > 0 ? (entries[i].cycles / c) : 0); out.print(functionName); - printSpace(out, 56 - functionName.length() - avgS.length()); + printSpace(out, 43 - functionName.length() - callS.length()); + out.print(callS); + out.print(' '); + printSpace(out, 10 - avgS.length()); out.print(avgS); out.print(' '); - printSpace(out, 8 - callS.length()); - out.print(callS); - out.print(' '); - printSpace(out, 10 - cyclesS.length()); - out.println(cyclesS); + printSpace(out, 11 - cyclesS.length()); + out.print(cyclesS); + printSpace(out, 11 - exCyclesS.length()); + out.println(exCyclesS); + if (profCallers) { + printCallers(entries[i], out); + } } } } @@ -246,6 +278,26 @@ } } + private void printCallers(CallEntry callEntry, PrintStream out) { + HashMap<MapEntry,Integer> callers = callEntry.callers; + List<Entry<MapEntry, Integer>> list = new LinkedList<Entry<MapEntry, Integer>>(callers.entrySet()); + Collections.sort(list, new Comparator<Entry<MapEntry, Integer>>() { + @Override + public int compare(Entry<MapEntry, Integer> o1, Entry<MapEntry, Integer> o2) { + return o2.getValue().compareTo(o1.getValue()); + } + }); + for (Entry<MapEntry, Integer> entry : list) { + String functionName = entry.getKey().getName(); + String callS = "" + entry.getValue(); + printSpace(out, 12 - callS.length()); + out.print(callS); + printSpace(out, 2); + out.print(functionName); + out.println(); + } + } + private void printSpace(PrintStream out, int len) { for (int i = 0; i < len; i++) { out.print(' '); @@ -259,17 +311,57 @@ } } - private static class CallEntry implements Comparable<CallEntry> { + private static class CallEntryComparator implements Comparator<CallEntry> { + private int mode; + + public CallEntryComparator(String modeS) { + if ("exclusive".equalsIgnoreCase(modeS)) { + mode = 1; + } else if ("calls".equalsIgnoreCase(modeS)) { + mode = 2; + } else if ("average".equalsIgnoreCase(modeS)) { + mode = 3; + } else if ("function".equalsIgnoreCase(modeS)) { + mode = 4; + } else { + mode = 0; + } + } + + public int compare(CallEntry o1, CallEntry o2) { + long diff; + switch (mode) { + case 1: + diff = o2.exclusiveCycles - o1.exclusiveCycles; + break; + case 2: + diff = o2.calls - o1.calls; + break; + case 3: + diff = (o2.calls > 0 ? (o2.cycles / o2.calls) : 0) - + (o1.calls > 0 ? (o1.cycles / o1.calls) : 0); + break; + case 4: + return o1.function.getName().compareTo(o2.function.getName()); + default: + diff = o2.cycles - o1.cycles; + } + if (diff > 0) return 1; + if (diff < 0) return -1; + return 0; + } + } + + private static class CallEntry { MapEntry function; long cycles; + long exclusiveCycles; int calls; int hide; - - public int compareTo(CallEntry o) { - long diff = o.cycles - cycles; - if (diff > 0) return 1; - if (diff < 0) return -1; - return 0; + HashMap<MapEntry, Integer> callers; + + public CallEntry() { + callers = new HashMap<MapEntry, Integer>(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-09-06 22:23:13
|
Revision: 584 http://mspsim.svn.sourceforge.net/mspsim/?rev=584&view=rev Author: joxe Date: 2009-09-06 21:59:23 +0000 (Sun, 06 Sep 2009) Log Message: ----------- applied patch for bugfixing Multiplier - thanks to Conrado PLG Modified Paths: -------------- mspsim/se/sics/mspsim/core/Multiplier.java Modified: mspsim/se/sics/mspsim/core/Multiplier.java =================================================================== --- mspsim/se/sics/mspsim/core/Multiplier.java 2009-09-06 21:49:57 UTC (rev 583) +++ mspsim/se/sics/mspsim/core/Multiplier.java 2009-09-06 21:59:23 UTC (rev 584) @@ -170,9 +170,11 @@ if (accumulating) { res += ((long) resHi << 16) + resLo; - if (!signed && res > 0xffffffff) { - sumext = 1; + if (!signed) { + sumext = res > 0xffffffffL ? 1 : 0; } + } else if (!signed) { + sumext = 0; } resHi = (int) ((res >> 16) & 0xffff); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-09-06 22:22:48
|
Revision: 583 http://mspsim.svn.sourceforge.net/mspsim/?rev=583&view=rev Author: joxe Date: 2009-09-06 21:49:57 +0000 (Sun, 06 Sep 2009) Log Message: ----------- fixed printout of ps Modified Paths: -------------- mspsim/se/sics/mspsim/cli/CommandHandler.java mspsim/se/sics/mspsim/cli/MiscCommands.java Modified: mspsim/se/sics/mspsim/cli/CommandHandler.java =================================================================== --- mspsim/se/sics/mspsim/cli/CommandHandler.java 2009-08-31 19:09:54 UTC (rev 582) +++ mspsim/se/sics/mspsim/cli/CommandHandler.java 2009-09-06 21:49:57 UTC (rev 583) @@ -236,11 +236,16 @@ } }); - registerCommand("ps", new BasicCommand("list current executing commands", "") { + registerCommand("ps", new BasicCommand("list current executing commands/processes", "") { public int executeCommand(CommandContext context) { - for (int i = 0; i < currentAsyncCommands.size(); i++) { - CommandContext cmd = currentAsyncCommands.get(i)[0]; - context.out.println(" " + cmd); + if (currentAsyncCommands.size() > 0) { + context.out.println(" PID\tCommand"); + for (int i = 0; i < currentAsyncCommands.size(); i++) { + CommandContext cmd = currentAsyncCommands.get(i)[0]; + context.out.println(" " + cmd); + } + } else { + context.out.println("No executing commands."); } return 0; } Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-08-31 19:09:54 UTC (rev 582) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-09-06 21:49:57 UTC (rev 583) @@ -54,13 +54,6 @@ import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.TimeEvent; -import se.sics.mspsim.net.CC2420PacketHandler; -import se.sics.mspsim.net.ICMP6Packet; -import se.sics.mspsim.net.ICMP6PacketHandler; -import se.sics.mspsim.net.IEEE802154Handler; -import se.sics.mspsim.net.IPStack; -import se.sics.mspsim.net.IPv6Packet; -import se.sics.mspsim.net.LoWPANHandler; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.Utils; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-08-31 19:10:06
|
Revision: 582 http://mspsim.svn.sourceforge.net/mspsim/?rev=582&view=rev Author: joxe Date: 2009-08-31 19:09:54 +0000 (Mon, 31 Aug 2009) Log Message: ----------- fixed bug with interrupt handling - clear SR when interrupt 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-08-31 18:42:49 UTC (rev 581) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-08-31 19:09:54 UTC (rev 582) @@ -739,14 +739,14 @@ memory[sp] = sr & 0xff; memory[sp + 1] = (sr >> 8) & 0xff; } - // Clear SR - except ... + // Clear SR + writeRegister(SR, 0); // sr & ~CPUOFF & ~SCG1 & ~OSCOFF); + // Jump to the address specified in the interrupt vector writeRegister(PC, pc = memory[0xffe0 + interruptMax * 2] + (memory[0xffe0 + interruptMax * 2 + 1] << 8)); - writeRegister(SR, sr & ~CPUOFF & ~SCG1 & ~OSCOFF); - servicedInterrupt = interruptMax; servicedInterruptUnit = interruptSource[servicedInterrupt]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-08-31 18:42:56
|
Revision: 581 http://mspsim.svn.sourceforge.net/mspsim/?rev=581&view=rev Author: joxe Date: 2009-08-31 18:42:49 +0000 (Mon, 31 Aug 2009) Log Message: ----------- fixed timing and status bug in M25P80 Modified Paths: -------------- mspsim/se/sics/mspsim/chip/M25P80.java Modified: mspsim/se/sics/mspsim/chip/M25P80.java =================================================================== --- mspsim/se/sics/mspsim/chip/M25P80.java 2009-08-31 16:35:04 UTC (rev 580) +++ mspsim/se/sics/mspsim/chip/M25P80.java 2009-08-31 18:42:49 UTC (rev 581) @@ -64,6 +64,10 @@ private int state = 0; public static final int CHIP_SELECT = 0x10; + + private static final double PROGRAM_PAGE_MILLIS = 1.0; // 0.8 - 5 ms + private static final double SECTOR_ERASE_MILLIS = 1400; // 800 - 3 000 ms + private boolean chipSelect; private int pos; @@ -103,6 +107,9 @@ System.out.println("M25P80: byte received: " + data); } switch(state) { + case READ_STATUS: + source.byteReceived(status); + return; case READ_IDENT: source.byteReceived(identity[pos]); pos++; @@ -184,14 +191,15 @@ } state = READ_IDENT; pos = 0; - source.byteReceived(identity[pos++]); + source.byteReceived(0); return; case READ_STATUS: status = (status & (0xff - 1 - 2)) | (writeEnable ? 0x02 : 0x00) | (writing ? 0x01 : 0x00); - source.byteReceived(status); + state = READ_STATUS; + source.byteReceived(0); if (DEBUG) { - System.out.println("M25P80: Read status => " + status); + System.out.println("M25P80: Read status => " + status + " " + cpu.getPC()); } return; case WRITE_STATUS: @@ -319,12 +327,13 @@ } private void writeStatus(double time) { - writing = true; - cpu.scheduleTimeEventMillis(writeEvent, time); + writing = true; + cpu.scheduleTimeEventMillis(writeEvent, time); } private void programPage() { - writeStatus(0.64); + if (writing) System.out.println("Can not set program page while already writing... " + cpu.getPC()); + writeStatus(PROGRAM_PAGE_MILLIS); ensureLoaded(blockWriteAddress); for (int i = 0; i < readMemory.length; i++) { readMemory[i] &= buffer[i]; @@ -333,7 +342,7 @@ } private void sectorErase(int address) { - writeStatus(600); + writeStatus(SECTOR_ERASE_MILLIS); int sectorAddress = address & 0xf0000; loadedAddress = -1; for (int i = 0; i < buffer.length; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-08-31 16:35:13
|
Revision: 580 http://mspsim.svn.sourceforge.net/mspsim/?rev=580&view=rev Author: joxe Date: 2009-08-31 16:35:04 +0000 (Mon, 31 Aug 2009) Log Message: ----------- fixed shift register in USART for improved timing Modified Paths: -------------- mspsim/se/sics/mspsim/core/USART.java Modified: mspsim/se/sics/mspsim/core/USART.java =================================================================== --- mspsim/se/sics/mspsim/core/USART.java 2009-08-19 12:27:51 UTC (rev 579) +++ mspsim/se/sics/mspsim/core/USART.java 2009-08-31 16:35:04 UTC (rev 580) @@ -43,7 +43,7 @@ public class USART extends IOUnit implements SFRModule { - public static final boolean DEBUG = false;//true; + public static final boolean DEBUG = false; //true; // USART 0/1 register offset (0x70 / 0x78) public static final int UCTL = 0; @@ -93,6 +93,8 @@ private int tickPerByte = 1000; private long nextTXReady = -1; private int nextTXByte = -1; + private int txShiftReg = -1; + private boolean transmitting = false; private MSP430Core cpu; private SFR sfr; @@ -153,7 +155,8 @@ public void reset(int type) { nextTXReady = cpu.cycles + 100; - nextTXByte = -1; + txShiftReg = nextTXByte = -1; + transmitting = false; clrBitIFG(utxifg | urxifg); utctl |= UTCTL_TXEMPTY; cpu.scheduleCycleEvent(txTrigger, nextTXReady); @@ -244,6 +247,7 @@ if (txEnabled || (spiMode && rxEnabled)) { // Interruptflag not set! clrBitIFG(utxifg); + /* the TX is no longer empty ! */ utctl &= ~UTCTL_TXEMPTY; /* should the interrupt be flagged off here ? - or only the flags */ if (DEBUG) System.out.println(getName() + " flagging off transmit interrupt"); @@ -252,9 +256,14 @@ // Schedule on cycles here // TODO: adding 3 extra cycles here seems to give // slightly better timing in some test... - nextTXReady = cycles + tickPerByte + 3; + nextTXByte = data; - cpu.scheduleCycleEvent(txTrigger, nextTXReady); + if (!transmitting) { + /* how long time will the copy from the TX_BUF to the shift reg take? */ + /* assume 3 cycles? */ + nextTXReady = cycles + 3; //tickPerByte + 3; + cpu.scheduleCycleEvent(txTrigger, nextTXReady); + } } else { System.out.println("Ignoring UTXBUF data since TX not active..."); } @@ -344,12 +353,27 @@ System.out.println(getName() + " Warning: USART transmission during LPM!!! " + nextTXByte); } - if (listener != null && nextTXByte != -1) { - listener.dataReceived(this, nextTXByte); - nextTXByte = -1; + if (transmitting) { + /* in this case we have shifted out the last character */ + if (listener != null && txShiftReg != -1) { + listener.dataReceived(this, txShiftReg); + } + /* nothing more to transmit after this - stop transmission */ + if (nextTXByte == -1) { + utctl |= UTCTL_TXEMPTY; + transmitting = false; + txShiftReg = -1; + } } - - utctl |= UTCTL_TXEMPTY; + /* any more chars to transmit? */ + if (nextTXByte != -1) { + txShiftReg = nextTXByte; + nextTXByte = -1; + transmitting = true; + nextTXReady = cycles + tickPerByte + 1; + cpu.scheduleCycleEvent(txTrigger, nextTXReady); + } + /* txbuf always empty after this?! */ setBitIFG(utxifg); if (DEBUG) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-08-19 12:27:59
|
Revision: 579 http://mspsim.svn.sourceforge.net/mspsim/?rev=579&view=rev Author: joxe Date: 2009-08-19 12:27:51 +0000 (Wed, 19 Aug 2009) Log Message: ----------- removed unused constants Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2009-08-19 12:22:45 UTC (rev 578) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2009-08-19 12:27:51 UTC (rev 579) @@ -198,22 +198,6 @@ } }; - public static final int STATE_VREG_OFF = -1; - public static final int STATE_POWER_DOWN = 0; - public static final int STATE_IDLE = 1; - public static final int STATE_RX_CALIBRATE = 2; - public static final int STATE_RX_SFD_SEARCH = 3; - public static final int STATE_RX_WAIT = 14; - public static final int STATE_RX_FRAME = 16; - public static final int STATE_RX_OVERFLOW = 17; - public static final int STATE_TX_CALIBRATE = 32; - public static final int STATE_TX_PREAMBLE = 34; - public static final int STATE_TX_FRAME = 37; - public static final int STATE_TX_ACK_CALIBRATE = 48; - public static final int STATE_TX_ACK_PREABLE = 49; - public static final int STATE_TX_ACK = 52; - public static final int STATE_TX_UNDERFLOW = 56; - // FCF High public static final int FRAME_TYPE = 0xC0; public static final int SECURITY_ENABLED = (1<<6); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-08-19 12:22:53
|
Revision: 578 http://mspsim.svn.sourceforge.net/mspsim/?rev=578&view=rev Author: joxe Date: 2009-08-19 12:22:45 +0000 (Wed, 19 Aug 2009) Log Message: ----------- implemented FSM state register in CC2420 Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2009-08-02 16:28:39 UTC (rev 577) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2009-08-19 12:22:45 UTC (rev 578) @@ -172,21 +172,30 @@ // State Machine - Datasheet Figure 25 page 44 public enum RadioState { - VREG_OFF, // -1; - POWER_DOWN, // 0; - IDLE, // 1; - RX_CALIBRATE, // 2; - RX_SFD_SEARCH, // 3; - RX_WAIT, // 14; - RX_FRAME, // 16; - RX_OVERFLOW, // 17; - TX_CALIBRATE, // 32; - TX_PREAMBLE, // 34; - TX_FRAME, // 37; - TX_ACK_CALIBRATE, // 48; - TX_ACK_PREABLE, // 49; - TX_ACK, // 52; - TX_UNDERFLOW// 56; + VREG_OFF(-1), + POWER_DOWN(0), + IDLE(1), + RX_CALIBRATE(2), + RX_SFD_SEARCH(3), + RX_WAIT(14), + RX_FRAME(16), + RX_OVERFLOW(17), + TX_CALIBRATE(32), + TX_PREAMBLE(34), + TX_FRAME(37), + TX_ACK_CALIBRATE(48), + TX_ACK_PREABLE(49), + TX_ACK(52), + TX_UNDERFLOW(56); + + private final int state; + RadioState(int stateNo) { + state = stateNo; + } + + public int getFSMState() { + return state; + } }; public static final int STATE_VREG_OFF = -1; @@ -373,6 +382,8 @@ private boolean setState(RadioState state) { if(DEBUG) log("State transition from " + stateMachine + " to " + state); stateMachine = state; + /* write to FSM state register */ + registers[REG_FSMSTATE] = state.getFSMState(); switch(stateMachine) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-08-02 16:29:15
|
Revision: 577 http://mspsim.svn.sourceforge.net/mspsim/?rev=577&view=rev Author: joxe Date: 2009-08-02 16:28:39 +0000 (Sun, 02 Aug 2009) Log Message: ----------- removed some debug printout Modified Paths: -------------- mspsim/se/sics/mspsim/net/BytePayload.java mspsim/se/sics/mspsim/net/IPStack.java mspsim/se/sics/mspsim/net/TSPClient.java mspsim/se/sics/mspsim/net/UDPPacket.java Modified: mspsim/se/sics/mspsim/net/BytePayload.java =================================================================== --- mspsim/se/sics/mspsim/net/BytePayload.java 2009-08-01 11:10:16 UTC (rev 576) +++ mspsim/se/sics/mspsim/net/BytePayload.java 2009-08-02 16:28:39 UTC (rev 577) @@ -23,9 +23,6 @@ public void parsePacketData(IPv6Packet packet) { dispatch = packet.getDispatch(); payloadData = packet.getPayload(); - int len = 0; - if (payloadData != null) len = payloadData.length; - System.out.println("BytePayload: got " + len + " bytes data"); } public void printPacket(PrintStream out) { Modified: mspsim/se/sics/mspsim/net/IPStack.java =================================================================== --- mspsim/se/sics/mspsim/net/IPStack.java 2009-08-01 11:10:16 UTC (rev 576) +++ mspsim/se/sics/mspsim/net/IPStack.java 2009-08-02 16:28:39 UTC (rev 577) @@ -235,11 +235,13 @@ linkLayerHandler.sendPacket(packet); } } else { - 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 (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); } @@ -290,25 +292,24 @@ } } else if (!isOnLink(packet.getDestinationAddress()) && packet.netInterface != tunnel) { - System.out.println("**** Should go out on tunnel!!!!" + tunnel); + if (DEBUG) System.out.println("**** Should go out on tunnel!!!!" + tunnel); if (packet.ipPayload == null) { - System.out.println("** Created byte payload for the packet..."); packet.setIPPayload(new BytePayload(packet)); - } else { - System.out.println("** Payload already set for packet..."); } /* will this work ??? */ - System.out.print("MyAddress: "); - IPv6Packet.printAddress(System.out, myIPAddress); - System.out.print(", Dest: "); - IPv6Packet.printAddress(System.out, packet.getDestinationAddress()); + 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... */ - System.out.println("#### PACKET FOR: " + packet.getDestinationAddress() + " sent to link"); + if (DEBUG) System.out.println("#### PACKET FOR: " + packet.getDestinationAddress() + " sent to link"); if (packet.ipPayload == null) { packet.setIPPayload(new BytePayload(packet)); if (findRoute(packet)) { Modified: mspsim/se/sics/mspsim/net/TSPClient.java =================================================================== --- mspsim/se/sics/mspsim/net/TSPClient.java 2009-08-01 11:10:16 UTC (rev 576) +++ mspsim/se/sics/mspsim/net/TSPClient.java 2009-08-02 16:28:39 UTC (rev 577) @@ -11,6 +11,8 @@ public class TSPClient implements NetworkInterface { + public static final boolean DEBUG = false; + public static final int DEFAULT_PORT = 3653; private static final byte[] VERSION = "VERSION=2.0.0\r\n".getBytes(); private static final byte[] AUTH_PLAIN = "AUTHENTICATE PLAIN\r\b".getBytes(); @@ -195,7 +197,7 @@ while(true) { System.out.println("Receiving packet..."); connection.receive(receiveP); - System.out.println("Packet received: " + receiveP.getLength()); + System.out.println("TSPClient: Packet received: " + receiveP.getLength()); byte[] data = receiveP.getData(); for (int i = 0, n = receiveP.getLength(); i < n; i++) { if (i < 8 || writerState == WriterState.TUNNEL_UP) { @@ -205,10 +207,12 @@ } } String sData = new String(data, 8, receiveP.getLength() - 8); - String[] parts = sData.split("\n"); - if (parts.length > 1) { - System.out.println("Response size: " + parts[0]); - System.out.println("Response code: " + parts[1]); + if (DEBUG) { + String[] parts = sData.split("\n"); + if ((parts.length > 1) && readerState != ReaderState.TUNNEL_UP) { + System.out.println("Response size: " + parts[0]); + System.out.println("Response code: " + parts[1]); + } } switch (readerState) { case CAP_EXPECTED: @@ -299,18 +303,22 @@ } DatagramPacket packet = new DatagramPacket(pData, pData.length, serverAddr, DEFAULT_PORT); connection.send(packet); - System.out.println("Packet sent... " + pData.length + " => C:" + - new String(packetData)); - + + if (DEBUG) { + System.out.println("Packet sent... " + pData.length + " => C:" + + new String(packetData)); + } } public void sendPacket(IPv6Packet packet) { byte[] data = packet.generatePacketData(packet); - System.out.println("Sending IPv6Packet on tunnel: " + data); - System.out.print("Packet: "); - packet.printPacket(System.out); - System.out.println(); + if (DEBUG) { + System.out.println("Sending IPv6Packet on tunnel: " + data); + System.out.print("Packet: "); + packet.printPacket(System.out); + System.out.println(); + } try { sendPacket(data); } catch (IOException e) { Modified: mspsim/se/sics/mspsim/net/UDPPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/UDPPacket.java 2009-08-01 11:10:16 UTC (rev 576) +++ mspsim/se/sics/mspsim/net/UDPPacket.java 2009-08-02 16:28:39 UTC (rev 577) @@ -6,6 +6,7 @@ public class UDPPacket implements IPPayload { + public final static boolean DEBUG = false; public final static int DISPATCH = 17; int sourcePort; @@ -91,8 +92,10 @@ int length = packet.get16(4); checkSum = packet.get16(6); - System.out.println("UDP Length: " + length); - System.out.println("UDP payload length: " + packet.getPayloadLength()); + if (DEBUG) { + System.out.println("UDP Length: " + length); + System.out.println("UDP payload length: " + packet.getPayloadLength()); + } /* this will *crash* if packet does not contain all data */ payload = new byte[length - 8]; /* length is total UDP length */ @@ -106,7 +109,7 @@ sum = IPv6Packet.checkSum(sum, data, data.length); sum = (~sum) & 0xffff; if (sum == checkSum) { - System.out.println("UDP: Checksum matches!!!"); + if (DEBUG) System.out.println("UDP: Checksum matches!!!"); } else { System.out.println("UDP: Checksum error: " + Utils.hex16(checkSum) + " <?> " + Utils.hex16(sum)); @@ -132,7 +135,7 @@ sum = IPv6Packet.checkSum(sum, payload, payload.length); sum = (~sum) & 0xffff; if (sum == checkSum) { - System.out.println("UDP: Checksum matches!!!"); + if (DEBUG) System.out.println("UDP: Checksum matches!!!"); } else { System.out.println("UDP: Checksum error: " + Utils.hex16(checkSum) + " <?> " + Utils.hex16(sum)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-08-01 11:10:25
|
Revision: 576 http://mspsim.svn.sourceforge.net/mspsim/?rev=576&view=rev Author: joxe Date: 2009-08-01 11:10:16 +0000 (Sat, 01 Aug 2009) Log Message: ----------- moved some ICMP code to network manager and fixed some bugs Modified Paths: -------------- mspsim/se/sics/mspsim/net/BytePayload.java mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java mspsim/se/sics/mspsim/net/IPStack.java mspsim/se/sics/mspsim/net/NeighborManager.java mspsim/se/sics/mspsim/net/UDPPacket.java Modified: mspsim/se/sics/mspsim/net/BytePayload.java =================================================================== --- mspsim/se/sics/mspsim/net/BytePayload.java 2009-07-10 06:34:19 UTC (rev 575) +++ mspsim/se/sics/mspsim/net/BytePayload.java 2009-08-01 11:10:16 UTC (rev 576) @@ -23,6 +23,9 @@ public void parsePacketData(IPv6Packet packet) { dispatch = packet.getDispatch(); payloadData = packet.getPayload(); + int len = 0; + if (payloadData != null) len = payloadData.length; + System.out.println("BytePayload: got " + len + " bytes data"); } public void printPacket(PrintStream out) { Modified: mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java 2009-07-10 06:34:19 UTC (rev 575) +++ mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java 2009-08-01 11:10:16 UTC (rev 576) @@ -36,6 +36,7 @@ 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; @@ -62,31 +63,7 @@ ipStack.sendPacket(ipp, packet.netInterface); break; case ICMP6Packet.ROUTER_SOLICITATION: - if (ipStack.isRouter()) { - p = new ICMP6Packet(); - p.targetAddress = icmpPacket.targetAddress; - p.type = ICMP6Packet.ROUTER_ADVERTISEMENT; - p.flags = ICMP6Packet.FLAG_SOLICITED | - ICMP6Packet.FLAG_OVERRIDE; - - /* ensure that the RA is updated... */ - p.updateRA(ipStack); - - ipp = new IPv6Packet(); - ipp.setIPPayload(p); - // is this ok? - //ipp.destAddress = packet.sourceAddress; - ipp.destAddress = IPStack.ALL_NODES; //packet.sourceAddress; - ipp.sourceAddress = ipStack.myLocalIPAddress; - System.out.print("Created ICMP6 RA for "); - IPv6Packet.printAddress(System.out, ipp.destAddress); - packet.printPacket(System.out); - ipStack.getNeighborManager().receiveNDMessage(packet); - - ipStack.sendPacket(ipp, packet.netInterface); - - } break; case ICMP6Packet.ROUTER_ADVERTISEMENT: if (!ipStack.isRouter()) { Modified: mspsim/se/sics/mspsim/net/IPStack.java =================================================================== --- mspsim/se/sics/mspsim/net/IPStack.java 2009-07-10 06:34:19 UTC (rev 575) +++ mspsim/se/sics/mspsim/net/IPStack.java 2009-08-01 11:10:16 UTC (rev 576) @@ -292,7 +292,10 @@ packet.netInterface != tunnel) { System.out.println("**** Should go out on tunnel!!!!" + tunnel); if (packet.ipPayload == null) { - packet.setIPPayload(new BytePayload(packet)); + System.out.println("** Created byte payload for the packet..."); + packet.setIPPayload(new BytePayload(packet)); + } else { + System.out.println("** Payload already set for packet..."); } /* will this work ??? */ System.out.print("MyAddress: "); Modified: mspsim/se/sics/mspsim/net/NeighborManager.java =================================================================== --- mspsim/se/sics/mspsim/net/NeighborManager.java 2009-07-10 06:34:19 UTC (rev 575) +++ mspsim/se/sics/mspsim/net/NeighborManager.java 2009-08-01 11:10:16 UTC (rev 576) @@ -44,6 +44,29 @@ if (nei != null) { nei.setState(Neighbor.REACHABLE); } + + if (ipStack.isRouter()) { + ICMP6Packet p = new ICMP6Packet(); + p.targetAddress = payload.targetAddress; + p.type = ICMP6Packet.ROUTER_ADVERTISEMENT; + p.flags = ICMP6Packet.FLAG_SOLICITED | + ICMP6Packet.FLAG_OVERRIDE; + + /* ensure that the RA is updated... */ + p.updateRA(ipStack); + + IPv6Packet ipp = new IPv6Packet(); + ipp.setIPPayload(p); + // is this ok? + //ipp.destAddress = packet.sourceAddress; + ipp.destAddress = IPStack.ALL_NODES; //packet.sourceAddress; + ipp.sourceAddress = ipStack.myLocalIPAddress; + System.out.print("Created ICMP6 RA for "); + IPv6Packet.printAddress(System.out, ipp.destAddress); + packet.printPacket(System.out); + + ipStack.sendPacket(ipp, packet.netInterface); + } break; case ICMP6Packet.ROUTER_ADVERTISEMENT: nei = neigborTable.addNeighbor(packet.sourceAddress, packet.getLinkSource()); Modified: mspsim/se/sics/mspsim/net/UDPPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/UDPPacket.java 2009-07-10 06:34:19 UTC (rev 575) +++ mspsim/se/sics/mspsim/net/UDPPacket.java 2009-08-01 11:10:16 UTC (rev 576) @@ -45,9 +45,34 @@ this.destinationPort = destinationPort; } + /* generate RAW UDP packet */ public byte[] generatePacketData(IPv6Packet packet) { - /* TODO: needs to be done!!! */ - return null; + int size = payload != null ? payload.length : 0; + size += 8; + byte[] data = new byte[size]; + int pos = 0; + data[pos++] = (byte)(sourcePort >> 8); + data[pos++] = (byte)(sourcePort & 0xff); + data[pos++] = (byte)(destinationPort >> 8); + data[pos++] = (byte)(destinationPort & 0xff); + data[pos++] = (byte)(size >> 8); + data[pos++] = (byte)(size & 0xff); + data[pos++] = 0; + data[pos++] = 0; + + if (payload != null) { + System.arraycopy(payload, 0, data, pos, payload.length); + } + + packet.payloadLen = size; + int sum = packet.upperLayerHeaderChecksum(); + + sum = IPv6Packet.checkSum(sum, data, size); + sum = (~sum) & 0xffff; + data[6] = (byte) (sum >> 8); + data[7] = (byte) (sum & 0xff); + + return data; } public byte getDispatch() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-07-10 06:34:21
|
Revision: 575 http://mspsim.svn.sourceforge.net/mspsim/?rev=575&view=rev Author: joxe Date: 2009-07-10 06:34:19 +0000 (Fri, 10 Jul 2009) Log Message: ----------- fixed bugs in the TCP/IP stack and httpserver Modified Paths: -------------- mspsim/se/sics/mspsim/net/HttpServer.java mspsim/se/sics/mspsim/net/IPStack.java mspsim/se/sics/mspsim/net/IPv6Packet.java mspsim/se/sics/mspsim/net/TCPConnection.java mspsim/se/sics/mspsim/net/TCPHandler.java mspsim/se/sics/mspsim/net/TCPInputStream.java Modified: mspsim/se/sics/mspsim/net/HttpServer.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServer.java 2009-07-08 16:57:41 UTC (rev 574) +++ mspsim/se/sics/mspsim/net/HttpServer.java 2009-07-10 06:34:19 UTC (rev 575) @@ -3,6 +3,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintStream; import java.util.Hashtable; import java.util.Vector; @@ -12,6 +13,7 @@ private TCPConnection serverConnection; private Hashtable servlets = new Hashtable(); private Vector pending = new Vector(); + private String status = ""; public HttpServer(IPStack stack) { ipStack = stack; @@ -48,6 +50,7 @@ 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..."); @@ -55,6 +58,7 @@ // TODO Auto-generated catch block e.printStackTrace(); } + status = "got connection"; connection = (TCPConnection) pending.firstElement(); pending.removeElementAt(0); } @@ -64,51 +68,59 @@ try { /* read a line */ System.out.println("%%% HttpServer: reading req line from: " + input); + status = "reading request line"; String reqLine = readLine(input); reqLine = reqLine.trim(); - int space = reqLine.indexOf(' '); - if (space == -1) { - return; - } - 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); - } - HttpServlet servlet = (HttpServlet) servlets.get(path); - if (servlet == null) { + if (!handleRequest(reqLine, input, output, connection)) { output.write("HTTP/1.0 404 NOT FOUND\r\n\r\n".getBytes()); - output.close(); - input.close(); - connection.close(); - } else { - 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); - servlet.service(req, resp); } - } 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..."); @@ -125,4 +137,8 @@ return null; } + public void printStatus(PrintStream out) { + out.println("HttpServer status: " + status); + } + } Modified: mspsim/se/sics/mspsim/net/IPStack.java =================================================================== --- mspsim/se/sics/mspsim/net/IPStack.java 2009-07-08 16:57:41 UTC (rev 574) +++ mspsim/se/sics/mspsim/net/IPStack.java 2009-07-10 06:34:19 UTC (rev 575) @@ -43,6 +43,7 @@ package se.sics.mspsim.net; import java.io.IOException; +import java.io.PrintStream; import java.util.Timer; import se.sics.mspsim.util.Utils; @@ -362,5 +363,9 @@ public boolean isRouter() { return isRouter ; - } + } + + public void printTCPStatus(PrintStream out) { + tcpHandler.printStatus(out); + } } \ No newline at end of file Modified: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-07-08 16:57:41 UTC (rev 574) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-07-10 06:34:19 UTC (rev 575) @@ -286,7 +286,7 @@ } /* parse a hex x:y:z... address */ - public byte[] parseAddress(String addressStr) { + public static byte[] parseAddress(String addressStr) { byte[] address = new byte[16]; int hexVal = 0; int pos = 0; Modified: mspsim/se/sics/mspsim/net/TCPConnection.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPConnection.java 2009-07-08 16:57:41 UTC (rev 574) +++ mspsim/se/sics/mspsim/net/TCPConnection.java 2009-07-10 06:34:19 UTC (rev 575) @@ -7,315 +7,339 @@ 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; + // 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; - /* position in connection array - debug */ - byte pos; + public static final long TIME_WAIT_MILLIS = 1000; + private static final int OUT_BUFFER = 128; - int state; - - /* sent unacked and nextSend byte */ - int sentUnack; - int sendNext; - int sendWindow = TCPPacket.DEFAULT_WINDOW; + /* retransmission time in milliseconds */ + int retransmissionTime = 1000; - /* 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); + // 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; } - return outputStream; - } - - public void setTCPListener(TCPListener listener) { - if (tcpListener == null) { - tcpListener = listener; - } else { - throw new IllegalStateException("TCPListener already set: " + tcpListener); + + 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 void newConnection(TCPConnection c) { - if (tcpListener != null) { - tcpListener.newConnection(c); + + public OutputStream getOutputStream() { + if (outputStream == null) { + outputStream = new TCPOutputStream(this); + } + return outputStream; } - } - - /* 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; + + public void setTCPListener(TCPListener listener) { + if (tcpListener == null) { + tcpListener = listener; + } else { + throw new IllegalStateException("TCPListener already set: " + tcpListener); + } } - 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)); + public void newConnection(TCPConnection c) { + if (tcpListener != null) { + tcpListener.newConnection(c); + } } - /* fin also is a payload byte */ - if (tcpPacket.isFin()) { - sendNext++; + + /* 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; } - 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(); + /* 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); } - for (int i = 0; i < data.length; i++) { - outgoingBuffer[bufNextEmpty++] = data[i]; - if (bufNextEmpty >= outgoingBuffer.length) - bufNextEmpty = 0; + + /* number of currently un-acked bytes in buffer */ + int outSize() { + int bytesToSend = bufNextEmpty - bufPos; + if (bytesToSend < 0) bytesToSend += outgoingBuffer.length; + return bytesToSend; } - } - - synchronized void resend() { - 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; + + 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; + } } - 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; - } + + 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); } - - System.out.println("**** TCPConnection resending data: size = " + size); - - TCPPacket tcpPacket = createPacket(); - IPv6Packet packet = new IPv6Packet(tcpPacket, localIP, externalIP); - tcpPacket.seqNo = sentUnack; - tcpPacket.payload = data; - 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) { - state = FIN_WAIT_1; - sendFIN(); + 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(); + } + } } - } 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); + } } - - 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; + void sendAck(TCPPacket tcpPacket) { + TCPPacket tcpReply = TCPHandler.createAck(tcpPacket, 0); + try { + send(tcpReply); + } catch (IOException e) { + e.printStackTrace(); + } + } - /* 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); + public void send(byte[] bytes) throws IOException { + if (closing) throw new IOException("TCPConnection closing..."); + TCPPacket tcpPacket = createPacket(); + tcpPacket.payload = bytes; + send(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); + /* 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 sendAck(TCPPacket tcpPacket) { - TCPPacket tcpReply = TCPHandler.createAck(tcpPacket, 0); - try { - send(tcpReply); - } catch (IOException e) { - e.printStackTrace(); + void closed() { + if (tcpListener != null) + tcpListener.connectionClosed(this); } - } - public void send(byte[] bytes) throws IOException { - if (closing) throw new IOException("TCPConnection closing..."); - TCPPacket tcpPacket = createPacket(); - tcpPacket.payload = bytes; - send(tcpPacket); - } + void sendFIN() { + System.out.println("Sending FIN!!!!"); + TCPPacket packet = createPacket(); + packet.flags |= TCPPacket.FIN; + try { + send(packet); + } catch (IOException e) { + e.printStackTrace(); + } + } - /* 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(); - } - } - } + public TCPPacket createPacket() { + TCPPacket tcpPacket = new TCPPacket(); + tcpPacket.sourcePort = localPort; + tcpPacket.destinationPort = externalPort; + return tcpPacket; + } - 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; + } - 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 Modified: mspsim/se/sics/mspsim/net/TCPHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPHandler.java 2009-07-08 16:57:41 UTC (rev 574) +++ mspsim/se/sics/mspsim/net/TCPHandler.java 2009-07-10 06:34:19 UTC (rev 575) @@ -1,5 +1,6 @@ package se.sics.mspsim.net; import java.io.IOException; +import java.io.PrintStream; import java.util.Timer; import java.util.TimerTask; @@ -36,46 +37,56 @@ 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); + TCPPacket tcpPacket = (TCPPacket) packet.getIPPayload(); + + TCPConnection connection = findConnection(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); + 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); + addConnection(tc); - /* established => report to listeners... */ - connection.newConnection(tc); - - tcpReply.ackNo = tc.receiveNext; - try { - tc.send(tcpReply); - } catch (IOException e) { - e.printStackTrace(); + /* 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); + } } - tc.sentUnack = tc.sendNext = tc.sendNext + 1; - tc.serverConnection = connection; - } else { - System.out.println("TCPHandler: dropping packet - likely for old connection?"); - } + } else { + if (tcpPacket.isReset()) { + /* something is very wrong - just close and remove... */ + connection.state = TCPConnection.CLOSED; } - } else { switch(connection.state) { case TCPConnection.SYN_RECEIVED: if (tcpPacket.isAck()) { @@ -91,6 +102,7 @@ break; case TCPConnection.ESTABLISHED: if (tcpPacket.isFin()) { + System.out.println("TCPConnection: received FIN => CLOSE_WAIT!!!"); connection.state = TCPConnection.CLOSE_WAIT; } @@ -105,14 +117,11 @@ case TCPConnection.FIN_WAIT_1: if (tcpPacket.isAck()) { connection.state = TCPConnection.FIN_WAIT_2; - connection.receive(tcpPacket); } if (tcpPacket.isFin()) { connection.state = TCPConnection.TIME_WAIT; - connection.lastSendTime = System.currentTimeMillis(); - connection.receiveNext++; - connection.sendAck(tcpPacket); } + connection.receive(tcpPacket); break; case TCPConnection.FIN_WAIT_2: if (tcpPacket.isFin()) { @@ -121,10 +130,13 @@ connection.lastSendTime = System.currentTimeMillis(); connection.receiveNext++; connection.sendAck(tcpPacket); + } else { + connection.sendReset(); } break; case TCPConnection.CLOSE_WAIT: /* ignore... */ + connection.sendReset(); break; } } @@ -186,6 +198,13 @@ 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) { @@ -210,4 +229,12 @@ } } } + + 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); + } + } + } Modified: mspsim/se/sics/mspsim/net/TCPInputStream.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPInputStream.java 2009-07-08 16:57:41 UTC (rev 574) +++ mspsim/se/sics/mspsim/net/TCPInputStream.java 2009-07-10 06:34:19 UTC (rev 575) @@ -11,6 +11,7 @@ private int firstByte = 0; private int nextEmpty = 0; boolean closed = false; + long lastReadCall = 0; TCPListener listener = new TCPListener() { public void connectionClosed(TCPConnection connection) { @@ -59,20 +60,27 @@ public void close() { connection.close(); closed = true; + notifyReader(); } public int read() throws IOException { if (closed) { return -1; } - if (firstByte == nextEmpty) { - synchronized(this) { - try { - wait(); - } catch (InterruptedException e) { - e.printStackTrace(); + 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++]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2009-07-08 16:57:43
|
Revision: 574 http://mspsim.svn.sourceforge.net/mspsim/?rev=574&view=rev Author: nifi Date: 2009-07-08 16:57:41 +0000 (Wed, 08 Jul 2009) Log Message: ----------- delay warning for wrapped TX cursor until first write after wrap (allow the TX buffer to be filled) Modified Paths: -------------- mspsim/se/sics/mspsim/chip/CC2420.java Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2009-06-26 11:33:39 UTC (rev 573) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2009-07-08 16:57:41 UTC (rev 574) @@ -631,14 +631,16 @@ } if (DEBUG) log("Writing data: " + data + " to tx: " + txCursor); - if(txCursor == 0 && (data & 0xff) > 127) { - logger.warning(this, "CC2420: Warning - packet size too large"); + if(txCursor == 0) { + if ((data & 0xff) > 127) { + logger.warning(this, "CC2420: Warning - packet size too large"); + } + } else if (txCursor > 127) { + logger.warning(this, "CC2420: Warning - TX Cursor wrapped"); + txCursor = 0; } memory[RAM_TXFIFO + txCursor] = data & 0xff; - txCursor = (txCursor + 1) & 127; - if (txCursor == 0) { - logger.warning(this, "CC2420: Warning - TX Cursor wrapped"); - } + txCursor++; if (sendEvents) { sendEvent("WRITE_TXFIFO", null); } @@ -795,8 +797,7 @@ } txfifoPos++; // Two symbol periods to send a byte... - long time = cpu.scheduleTimeEventMillis(sendEvent, SYMBOL_PERIOD * 2); -// log("Scheduling 2 SYMB at: " + time + " getTime(now): " + cpu.getTime()); + cpu.scheduleTimeEventMillis(sendEvent, SYMBOL_PERIOD * 2); } else { if (DEBUG) log("Completed Transmission."); status &= ~STATUS_TX_ACTIVE; @@ -1093,3 +1094,4 @@ } } // CC2420 + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-26 11:33:51
|
Revision: 572 http://mspsim.svn.sourceforge.net/mspsim/?rev=572&view=rev Author: joxe Date: 2009-06-26 11:32:20 +0000 (Fri, 26 Jun 2009) Log Message: ----------- fixed ELF loader Modified Paths: -------------- mspsim/se/sics/mspsim/util/ELF.java Modified: mspsim/se/sics/mspsim/util/ELF.java =================================================================== --- mspsim/se/sics/mspsim/util/ELF.java 2009-06-26 09:56:20 UTC (rev 571) +++ mspsim/se/sics/mspsim/util/ELF.java 2009-06-26 11:32:20 UTC (rev 572) @@ -362,7 +362,7 @@ } } else if (!sn.startsWith("_")) { // System.out.println("Adding entry: " + sn + " at " + sAddr); - map.setEntry(new MapEntry(MapEntry.TYPE.variable, sAddr, sn, currentFile, + map.setEntry(new MapEntry(MapEntry.TYPE.variable, sAddr, 0, sn, currentFile, false)); } } @@ -393,14 +393,14 @@ if (file == null) { file = currentFile; } - map.setEntry(new MapEntry(MapEntry.TYPE.function, sAddr, symbolName, file, + map.setEntry(new MapEntry(MapEntry.TYPE.function, sAddr, 0, symbolName, file, bind == ELFSection.SYMBIND_LOCAL)); } else if (type == ELFSection.SYMTYPE_OBJECT) { String file = lookupFile(sAddr); if (file == null) { file = currentFile; } - map.setEntry(new MapEntry(MapEntry.TYPE.variable, sAddr, symbolName, file, + map.setEntry(new MapEntry(MapEntry.TYPE.variable, sAddr, 0, symbolName, file, bind == ELFSection.SYMBIND_LOCAL)); } else { if (DEBUG) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-26 11:33:41
|
Revision: 573 http://mspsim.svn.sourceforge.net/mspsim/?rev=573&view=rev Author: joxe Date: 2009-06-26 11:33:39 +0000 (Fri, 26 Jun 2009) Log Message: ----------- fixed MapEntry usage in Core 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-06-26 11:32:20 UTC (rev 572) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-06-26 11:33:39 UTC (rev 573) @@ -1350,7 +1350,7 @@ } MapEntry getFunction(MapTable map, int address) { - MapEntry function = new MapEntry(MapEntry.TYPE.function, address, + MapEntry function = new MapEntry(MapEntry.TYPE.function, address, 0, "fkn at $" + Utils.hex16(address), null, true); map.setEntry(function); return function; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-26 09:56:38
|
Revision: 571 http://mspsim.svn.sourceforge.net/mspsim/?rev=571&view=rev Author: joxe Date: 2009-06-26 09:56:20 +0000 (Fri, 26 Jun 2009) Log Message: ----------- added modules to map parser Modified Paths: -------------- mspsim/se/sics/mspsim/util/MapEntry.java mspsim/se/sics/mspsim/util/MapTable.java Modified: mspsim/se/sics/mspsim/util/MapEntry.java =================================================================== --- mspsim/se/sics/mspsim/util/MapEntry.java 2009-06-23 06:29:41 UTC (rev 570) +++ mspsim/se/sics/mspsim/util/MapEntry.java 2009-06-26 09:56:20 UTC (rev 571) @@ -43,22 +43,28 @@ public class MapEntry { - public static enum TYPE {function, variable} + public static enum TYPE {function, variable, module} private TYPE type; private int address; + private int size; private String name; private String file; private boolean isLocal; - public MapEntry(TYPE type, int address, String name, String file, boolean isLocal) { + public MapEntry(TYPE type, int address, int size, String name, String file, boolean isLocal) { this.type = type; this.address = address; this.name = name; this.file = file; this.isLocal = isLocal; + this.size = size; } + public int getSize() { + return size; + } + public TYPE getType() { return type; } Modified: mspsim/se/sics/mspsim/util/MapTable.java =================================================================== --- mspsim/se/sics/mspsim/util/MapTable.java 2009-06-23 06:29:41 UTC (rev 570) +++ mspsim/se/sics/mspsim/util/MapTable.java 2009-06-26 09:56:20 UTC (rev 571) @@ -67,6 +67,7 @@ public int heapStartAddress = -1; public int stackStartAddress = -1; + private ArrayList<MapEntry> modules = new ArrayList<MapEntry>(); private MapEntry[] entries; public MapTable() { @@ -94,7 +95,10 @@ System.out.println("Data Mode!"); } else if (line.startsWith(" .text")) { if (parts.length > 3) { - // System.out.println("Code " + parts[2] + " Name:" + parts[4]); + int addr = Integer.parseInt(parts[2].substring(2), 16); + int size = Integer.parseInt(parts[3].substring(2), 16); + System.out.println("Module add: " + addr + " Size:" + size + " file:" + parts[4]); + modules.add(new MapEntry(MapEntry.TYPE.module, addr, size, parts[4], null, false)); } } else if (mode == Mode.CODE && line.startsWith(" ")) { if (parts.length > 2) { @@ -104,7 +108,7 @@ Utils.hex16(val)); // Add the file part later some time... // After the demo... - setEntry(new MapEntry(MapEntry.TYPE.function, val, parts[2], null, false)); + setEntry(new MapEntry(MapEntry.TYPE.function, val, 0, parts[2], null, false)); } } else if (line.contains(" _end = .") && parts.length > 2) { @@ -167,14 +171,16 @@ // Should be any symbol... not just function... public void setFunctionName(int address, String name) { - setEntry(new MapEntry(MapEntry.TYPE.function, address, name, null, false)); + setEntry(new MapEntry(MapEntry.TYPE.function, address, 0, name, null, false)); } public void setEntry(MapEntry entry) { if (entries == null) { entries = new MapEntry[0x10000]; } - entries[entry.getAddress()] = entry; + if (entry.getAddress() < 0x10000) { + entries[entry.getAddress()] = entry; + } } // Really slow way to find a specific function address!!!! @@ -197,6 +203,13 @@ } public static void main(String[] args) throws IOException { - new MapTable(args[0]); + MapTable map = new MapTable(args[0]); + int totsize = 0; + for (int i = 0; i < map.modules.size(); i++) { + MapEntry module = map.modules.get(i); + totsize += module.getSize(); + System.out.println("Module: " + module.getName() + " addr: " + module.getAddress() + " size: " + module.getSize()); + } + System.out.println("Total size: " + totsize + " " + Integer.toHexString(totsize)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-23 06:30:39
|
Revision: 570 http://mspsim.svn.sourceforge.net/mspsim/?rev=570&view=rev Author: joxe Date: 2009-06-23 06:29:41 +0000 (Tue, 23 Jun 2009) Log Message: ----------- added UDPHandler Modified Paths: -------------- mspsim/se/sics/mspsim/net/IPStack.java mspsim/se/sics/mspsim/net/IPv6Packet.java Added Paths: ----------- mspsim/se/sics/mspsim/net/UDPHandler.java mspsim/se/sics/mspsim/net/UDPListener.java Modified: mspsim/se/sics/mspsim/net/IPStack.java =================================================================== --- mspsim/se/sics/mspsim/net/IPStack.java 2009-06-21 22:08:34 UTC (rev 569) +++ mspsim/se/sics/mspsim/net/IPStack.java 2009-06-23 06:29:41 UTC (rev 570) @@ -42,6 +42,7 @@ */ package se.sics.mspsim.net; +import java.io.IOException; import java.util.Timer; import se.sics.mspsim.util.Utils; @@ -79,6 +80,7 @@ private IPPacketer defaultPacketer = new HC01Packeter(); private ICMP6PacketHandler icmp6Handler; private TCPHandler tcpHandler = null; + private UDPHandler udpHandler = null; /* is router -> router behavior */ private boolean isRouter = false; @@ -101,6 +103,7 @@ configureIPAddress(); neighborManager = new NeighborManager(this, neighborTable); tcpHandler = new TCPHandler(this); + udpHandler = new UDPHandler(); } public Timer getTimer() { @@ -112,6 +115,10 @@ return tcpHandler.addListenConnection(port); } + public void listen(UDPListener listener, int port) throws IOException { + udpHandler.addUDPListener(listener, port); + } + public NeighborTable getNeighborTable() { return neighborTable; } @@ -257,11 +264,13 @@ // 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); Modified: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-06-21 22:08:34 UTC (rev 569) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-06-23 06:29:41 UTC (rev 570) @@ -284,6 +284,36 @@ out.print(":"); } } + + /* parse a hex x:y:z... address */ + public 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"); Added: mspsim/se/sics/mspsim/net/UDPHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/UDPHandler.java (rev 0) +++ mspsim/se/sics/mspsim/net/UDPHandler.java 2009-06-23 06:29:41 UTC (rev 570) @@ -0,0 +1,30 @@ +package se.sics.mspsim.net; + +import java.io.IOException; + +public class UDPHandler { + private static final int MAX_LISTENERS = 16; + public UDPListener[] listeners = new UDPListener[MAX_LISTENERS]; + public int[] listenPorts = new int[MAX_LISTENERS]; + int noListeners = 0; + + public void addUDPListener(UDPListener listener, int port) throws IOException { + if (noListeners < MAX_LISTENERS) { + System.out.println("UDPHandler: adding listener for " + port); + listeners[noListeners] = listener; + listenPorts[noListeners++] = port; + } else { + throw new IOException("Too many open connections..."); + } + } + + public void handlePacket(IPv6Packet packet, UDPPacket udpPacket) { + for (int i = 0; i < noListeners; i++) { + if (listenPorts[i] == udpPacket.destinationPort) { + listeners[i].packetReceived(packet, udpPacket); + /* only one connection per port... */ + return; + } + } + } +} Property changes on: mspsim/se/sics/mspsim/net/UDPHandler.java ___________________________________________________________________ Added: svn:executable + * Added: mspsim/se/sics/mspsim/net/UDPListener.java =================================================================== --- mspsim/se/sics/mspsim/net/UDPListener.java (rev 0) +++ mspsim/se/sics/mspsim/net/UDPListener.java 2009-06-23 06:29:41 UTC (rev 570) @@ -0,0 +1,5 @@ +package se.sics.mspsim.net; + +public interface UDPListener { + public void packetReceived(IPv6Packet ip, UDPPacket upd); +} Property changes on: mspsim/se/sics/mspsim/net/UDPListener.java ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-21 22:08:52
|
Revision: 569 http://mspsim.svn.sourceforge.net/mspsim/?rev=569&view=rev Author: joxe Date: 2009-06-21 22:08:34 +0000 (Sun, 21 Jun 2009) Log Message: ----------- fixed some bugs - improved stability Modified Paths: -------------- mspsim/se/sics/mspsim/net/HttpServer.java mspsim/se/sics/mspsim/net/TCPConnection.java mspsim/se/sics/mspsim/net/TCPHandler.java mspsim/se/sics/mspsim/net/TCPInputStream.java Modified: mspsim/se/sics/mspsim/net/HttpServer.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServer.java 2009-06-15 22:11:54 UTC (rev 568) +++ mspsim/se/sics/mspsim/net/HttpServer.java 2009-06-21 22:08:34 UTC (rev 569) @@ -60,12 +60,16 @@ } InputStream input = connection.getInputStream(); OutputStream output = connection.getOutputStream(); + connection.setTimeout(5000); try { /* read a line */ System.out.println("%%% HttpServer: reading req line from: " + input); String reqLine = readLine(input); reqLine = reqLine.trim(); int space = reqLine.indexOf(' '); + if (space == -1) { + return; + } String method = reqLine.substring(0, space); String path = reqLine.substring(space + 1, reqLine.lastIndexOf(' ')); System.out.println("Method: " + method); @@ -94,7 +98,7 @@ servlet.service(req, resp); } - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); } finally { try { Modified: mspsim/se/sics/mspsim/net/TCPConnection.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-15 22:11:54 UTC (rev 568) +++ mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-21 22:08:34 UTC (rev 569) @@ -33,6 +33,9 @@ int externalPort = -1; byte[] externalIP; + /* position in connection array - debug */ + byte pos; + int state; /* sent unacked and nextSend byte */ @@ -58,8 +61,11 @@ private TCPInputStream inputStream; private TCPOutputStream outputStream; -private boolean closing; + private boolean closing; + /* no read timeout */ + int timeout = -1; + TCPConnection(IPStack stack, NetworkInterface nIf) { ipStack = stack; netInterface = nIf; @@ -109,10 +115,11 @@ /* send packet + update sendNext - this should take into account ext window */ /* is this what mess up the stuff */ - public void send(TCPPacket tcpPacket) { + 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; @@ -120,6 +127,10 @@ " 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); @@ -127,17 +138,20 @@ /* number of currently un-acked bytes in buffer */ int outSize() { - int bytesToSend = bufNextEmpty - bufPos; - if (bytesToSend < 0) bytesToSend += outgoingBuffer.length; - return bytesToSend; + int bytesToSend = bufNextEmpty - bufPos; + if (bytesToSend < 0) bytesToSend += outgoingBuffer.length; + return bytesToSend; } - private synchronized void copyToBuffer(byte[] data) { + private synchronized void copyToBuffer(byte[] data) throws IOException { int empty = outgoingBuffer.length - outSize(); - while (empty < data.length || state != TCPConnection.ESTABLISHED) { + 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..."); + System.out.println("blocking output... state: " + state); wait(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block @@ -157,7 +171,7 @@ int size = outSize(); System.out.println("### Bytes to resend: " + outSize() + " seqDiff: " + (sendNext - sentUnack)); - /* nothing to resend... */ + /* nothing to resend... TODO: this should handle resend of FIN also! */ if (size == 0) return; if (outSize() < size) size = outSize(); @@ -203,7 +217,8 @@ " seqDiff: " + (sendNext - sentUnack) + " plen: " + plen); notify(); /* this means that we can send more data !!*/ - if (closing && sentUnack == sendNext) { + if (state == ESTABLISHED && closing && outSize() == 0) { + state = FIN_WAIT_1; sendFIN(); } } else { @@ -224,6 +239,12 @@ /* 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); @@ -241,26 +262,15 @@ Integer.toString(tcpPacket.seqNo & 0xffff, 16)); sendAck(tcpPacket); } - - if (tcpPacket.isFin()) { - if (plen == 0) { - /* send ack if plen = 0 - since we did not send ack above !!! */ - sendAck(tcpPacket); - } - - if (tcpListener != null && plen > 0) { - /* notify app that the other side is closing... */ - tcpListener.connectionClosed(this); - } - } } void sendAck(TCPPacket tcpPacket) { TCPPacket tcpReply = TCPHandler.createAck(tcpPacket, 0); - tcpReply.ackNo = receiveNext; - tcpReply.seqNo = sendNext; - - send(tcpReply); + try { + send(tcpReply); + } catch (IOException e) { + e.printStackTrace(); + } } public void send(byte[] bytes) throws IOException { @@ -272,21 +282,30 @@ /* should close autoflush??? */ public void close() { - if (state == ESTABLISHED) { - System.out.println("=== Closing connection... outSize: " + outSize()); - closing = true; - if (outSize() == 0) { + if (state == ESTABLISHED) { + System.out.println("=== Closing connection... outSize: " + outSize()); + closing = true; + if (outSize() == 0) { + state = FIN_WAIT_1; sendFIN(); - } - } + } + } } - private void sendFIN() { + void closed() { + if (tcpListener != null) + tcpListener.connectionClosed(this); + } + + void sendFIN() { System.out.println("Sending FIN!!!!"); TCPPacket packet = createPacket(); packet.flags |= TCPPacket.FIN; - state = FIN_WAIT_1; - send(packet); + try { + send(packet); + } catch (IOException e) { + e.printStackTrace(); + } } public TCPPacket createPacket() { @@ -294,5 +313,9 @@ tcpPacket.sourcePort = localPort; tcpPacket.destinationPort = externalPort; return tcpPacket; - } + } + + public void setTimeout(int tms) { + timeout = tms; + } } \ No newline at end of file Modified: mspsim/se/sics/mspsim/net/TCPHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPHandler.java 2009-06-15 22:11:54 UTC (rev 568) +++ mspsim/se/sics/mspsim/net/TCPHandler.java 2009-06-21 22:08:34 UTC (rev 569) @@ -1,4 +1,5 @@ package se.sics.mspsim.net; +import java.io.IOException; import java.util.Timer; import java.util.TimerTask; @@ -32,7 +33,8 @@ } private synchronized void addConnection(TCPConnection c) { - activeConnections[connectionNo++] = c; + c.pos = (byte) connectionNo; + activeConnections[connectionNo++] = c; } public void handlePacket(IPv6Packet packet) { @@ -62,16 +64,22 @@ connection.newConnection(tc); tcpReply.ackNo = tc.receiveNext; - tc.send(tcpReply); + 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 - likely for old connection?"); } } } else { switch(connection.state) { case TCPConnection.SYN_RECEIVED: if (tcpPacket.isAck()) { - System.out.println("TCPConnection: gotten ACK on syn! => ESTABLISHED!!"); + System.out.println("TCPConnection: gotten ACK on syn! => ESTABLISHED!! " + connection.pos); connection.state = TCPConnection.ESTABLISHED; connection.receive(tcpPacket); @@ -89,9 +97,10 @@ connection.receive(tcpPacket); break; case TCPConnection.LAST_ACK: - if (tcpPacket.isAck()) { - connection.state = TCPConnection.CLOSED; - } + 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()) { @@ -107,7 +116,7 @@ break; case TCPConnection.FIN_WAIT_2: if (tcpPacket.isFin()) { - System.out.println("TCPHandler: setting connection in TIME_WAIT..."); + System.out.println("TCPHandler: setting connection in TIME_WAIT... " + connection.pos); connection.state = TCPConnection.TIME_WAIT; connection.lastSendTime = System.currentTimeMillis(); connection.receiveNext++; @@ -159,35 +168,44 @@ 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.bufPos == connection.bufNextEmpty) { - System.out.println("Closing - sending FIN"); - TCPPacket packet = connection.createPacket(); - packet.flags |= TCPPacket.FIN; - connection.state = TCPConnection.LAST_ACK; - connection.send(packet); - } else { - /* send something from the buffer */ + /* 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.TIME_WAIT: - /* wait for a while ... */ - if (connection.lastSendTime < time + TCPConnection.TIME_WAIT_MILLIS) { - System.out.println("TCPHandler: Connection is closed..."); - connection.state = TCPConnection.CLOSED; - + /* 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 (i > 0) { - /* move the last connection to this position - we do not need - * this any more ??!! - */ - activeConnections[i] = activeConnections[connectionNo]; - i--; /* allow processing of that connection too */ + 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; + break; } } } Modified: mspsim/se/sics/mspsim/net/TCPInputStream.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPInputStream.java 2009-06-15 22:11:54 UTC (rev 568) +++ mspsim/se/sics/mspsim/net/TCPInputStream.java 2009-06-21 22:08:34 UTC (rev 569) @@ -14,8 +14,12 @@ 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 newConnection(TCPConnection connection) { + } public void tcpDataReceived(TCPConnection source, TCPPacket packet) { byte[] payload = packet.payload; if (payload == null || payload.length == 0) return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-15 22:12:11
|
Revision: 568 http://mspsim.svn.sourceforge.net/mspsim/?rev=568&view=rev Author: joxe Date: 2009-06-15 22:11:54 +0000 (Mon, 15 Jun 2009) Log Message: ----------- minor fix to FIN handling Modified Paths: -------------- mspsim/se/sics/mspsim/net/TCPConnection.java mspsim/se/sics/mspsim/net/TCPHandler.java Modified: mspsim/se/sics/mspsim/net/TCPConnection.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-15 20:54:17 UTC (rev 567) +++ mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-15 22:11:54 UTC (rev 568) @@ -1,5 +1,6 @@ package se.sics.mspsim.net; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -57,6 +58,7 @@ private TCPInputStream inputStream; private TCPOutputStream outputStream; +private boolean closing; TCPConnection(IPStack stack, NetworkInterface nIf) { ipStack = stack; @@ -201,6 +203,9 @@ " seqDiff: " + (sendNext - sentUnack) + " plen: " + plen); notify(); /* this means that we can send more data !!*/ + if (closing && sentUnack == sendNext) { + sendFIN(); + } } else { System.out.println("TCPHandler: Unexpected ACK no: " + Integer.toString(tcpPacket.ackNo & 0xffff, 16) + @@ -238,6 +243,11 @@ } if (tcpPacket.isFin()) { + if (plen == 0) { + /* send ack if plen = 0 - since we did not send ack above !!! */ + sendAck(tcpPacket); + } + if (tcpListener != null && plen > 0) { /* notify app that the other side is closing... */ tcpListener.connectionClosed(this); @@ -245,7 +255,7 @@ } } - private void sendAck(TCPPacket tcpPacket) { + void sendAck(TCPPacket tcpPacket) { TCPPacket tcpReply = TCPHandler.createAck(tcpPacket, 0); tcpReply.ackNo = receiveNext; tcpReply.seqNo = sendNext; @@ -253,19 +263,30 @@ send(tcpReply); } - public void send(byte[] bytes) { + 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) { + sendFIN(); + } + } + } + + private void sendFIN() { + System.out.println("Sending FIN!!!!"); TCPPacket packet = createPacket(); packet.flags |= TCPPacket.FIN; state = FIN_WAIT_1; send(packet); - } } public TCPPacket createPacket() { Modified: mspsim/se/sics/mspsim/net/TCPHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPHandler.java 2009-06-15 20:54:17 UTC (rev 567) +++ mspsim/se/sics/mspsim/net/TCPHandler.java 2009-06-15 22:11:54 UTC (rev 568) @@ -96,13 +96,22 @@ case TCPConnection.FIN_WAIT_1: if (tcpPacket.isAck()) { connection.state = TCPConnection.FIN_WAIT_2; + connection.receive(tcpPacket); } + if (tcpPacket.isFin()) { + connection.state = TCPConnection.TIME_WAIT; + connection.lastSendTime = System.currentTimeMillis(); + connection.receiveNext++; + connection.sendAck(tcpPacket); + } break; case TCPConnection.FIN_WAIT_2: if (tcpPacket.isFin()) { System.out.println("TCPHandler: setting connection in TIME_WAIT..."); connection.state = TCPConnection.TIME_WAIT; connection.lastSendTime = System.currentTimeMillis(); + connection.receiveNext++; + connection.sendAck(tcpPacket); } break; case TCPConnection.CLOSE_WAIT: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-15 20:54:35
|
Revision: 567 http://mspsim.svn.sourceforge.net/mspsim/?rev=567&view=rev Author: joxe Date: 2009-06-15 20:54:17 +0000 (Mon, 15 Jun 2009) Log Message: ----------- minor fixes Modified Paths: -------------- mspsim/se/sics/mspsim/net/HttpServer.java mspsim/se/sics/mspsim/net/TCPPacket.java Modified: mspsim/se/sics/mspsim/net/HttpServer.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServer.java 2009-06-15 19:47:19 UTC (rev 566) +++ mspsim/se/sics/mspsim/net/HttpServer.java 2009-06-15 20:54:17 UTC (rev 567) @@ -81,6 +81,14 @@ input.close(); connection.close(); } else { + 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); servlet.service(req, resp); Modified: mspsim/se/sics/mspsim/net/TCPPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPPacket.java 2009-06-15 19:47:19 UTC (rev 566) +++ mspsim/se/sics/mspsim/net/TCPPacket.java 2009-06-15 20:54:17 UTC (rev 567) @@ -13,8 +13,8 @@ */ public class TCPPacket implements IPPayload { - public static final int DEFAULT_WINDOW = 60; - public static final int DEFAULT_MSS = 60; + public static final int DEFAULT_WINDOW = 45; + public static final int DEFAULT_MSS = 45; public static final int DISPATCH = 6; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-15 19:47:52
|
Revision: 566 http://mspsim.svn.sourceforge.net/mspsim/?rev=566&view=rev Author: joxe Date: 2009-06-15 19:47:19 +0000 (Mon, 15 Jun 2009) Log Message: ----------- very basic http server Modified Paths: -------------- 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/TCPPacket.java Added Paths: ----------- 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 Added: mspsim/se/sics/mspsim/net/HttpServer.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServer.java (rev 0) +++ mspsim/se/sics/mspsim/net/HttpServer.java 2009-06-15 19:47:19 UTC (rev 566) @@ -0,0 +1,116 @@ +package se.sics.mspsim.net; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +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(); + + 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..."); + wait(); + /* take first and handle... */ + System.out.println("%%% HttpServer: worker notified..."); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + connection = (TCPConnection) pending.firstElement(); + pending.removeElementAt(0); + } + InputStream input = connection.getInputStream(); + OutputStream output = connection.getOutputStream(); + try { + /* read a line */ + System.out.println("%%% HttpServer: reading req line from: " + input); + String reqLine = readLine(input); + reqLine = reqLine.trim(); + int space = reqLine.indexOf(' '); + 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); + } + HttpServlet servlet = (HttpServlet) servlets.get(path); + if (servlet == null) { + output.write("HTTP/1.0 404 NOT FOUND\r\n\r\n".getBytes()); + output.close(); + input.close(); + connection.close(); + } else { + HttpServletRequest req = new HttpServletRequest(connection, method, path); + HttpServletResponse resp = new HttpServletResponse(connection); + servlet.service(req, resp); + } + + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + output.close(); + } catch (IOException e) { + } + connection.close(); + } + } + } + + 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; + } + +} Added: mspsim/se/sics/mspsim/net/HttpServlet.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServlet.java (rev 0) +++ mspsim/se/sics/mspsim/net/HttpServlet.java 2009-06-15 19:47:19 UTC (rev 566) @@ -0,0 +1,9 @@ +package se.sics.mspsim.net; + +public class HttpServlet { + + public void service(HttpServletRequest req, + HttpServletResponse resp) { + } + +} Added: mspsim/se/sics/mspsim/net/HttpServletRequest.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServletRequest.java (rev 0) +++ mspsim/se/sics/mspsim/net/HttpServletRequest.java 2009-06-15 19:47:19 UTC (rev 566) @@ -0,0 +1,28 @@ +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(); + } +} Added: mspsim/se/sics/mspsim/net/HttpServletResponse.java =================================================================== --- mspsim/se/sics/mspsim/net/HttpServletResponse.java (rev 0) +++ mspsim/se/sics/mspsim/net/HttpServletResponse.java 2009-06-15 19:47:19 UTC (rev 566) @@ -0,0 +1,18 @@ +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(); + } + + +} Modified: mspsim/se/sics/mspsim/net/TCPConnection.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-13 21:58:29 UTC (rev 565) +++ mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-15 19:47:19 UTC (rev 566) @@ -21,7 +21,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; @@ -43,6 +46,7 @@ private IPStack ipStack; private NetworkInterface netInterface; private TCPListener tcpListener; + TCPConnection serverConnection; long lastSendTime; @@ -60,12 +64,13 @@ } public InputStream getInputStream() { - if (inputStream == null) { - inputStream = new TCPInputStream(this); - /* steal the listener... */ - tcpListener = inputStream.listener; - } - return inputStream; + 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() { @@ -105,6 +110,7 @@ public void send(TCPPacket tcpPacket) { IPv6Packet packet = new IPv6Packet(tcpPacket, localIP, externalIP); tcpPacket.seqNo = sendNext; + tcpPacket.ackNo = receiveNext; if (tcpPacket.payload != null) { copyToBuffer(tcpPacket.payload); sendNext += tcpPacket.payload.length; @@ -117,7 +123,8 @@ ipStack.sendPacket(packet, netInterface); } - private int outSize() { + /* number of currently un-acked bytes in buffer */ + int outSize() { int bytesToSend = bufNextEmpty - bufPos; if (bytesToSend < 0) bytesToSend += outgoingBuffer.length; return bytesToSend; @@ -125,7 +132,7 @@ private synchronized void copyToBuffer(byte[] data) { int empty = outgoingBuffer.length - outSize(); - while (empty < data.length) { + while (empty < data.length || state != TCPConnection.ESTABLISHED) { /* need to block this tread until place for data is available...*/ try { System.out.println("blocking output..."); @@ -144,10 +151,13 @@ } } - private synchronized void resend() { + synchronized void resend() { int size = outSize(); System.out.println("### Bytes to resend: " + outSize() + " seqDiff: " + (sendNext - sentUnack)); + /* nothing to resend... */ + if (size == 0) return; + if (outSize() < size) size = outSize(); /* ensure small payload size... this should be handled at IP level...*/ if (size > 40) { @@ -178,7 +188,7 @@ if (tcpPacket.isAck()) { /* check if correct ack - this is the "max" case*/ - if (sentUnack < tcpPacket.ackNo && sendNext >= tcpPacket.ackNo) { + if (sentUnack <= tcpPacket.ackNo && sendNext >= tcpPacket.ackNo) { /* no more unacked data */ int noAcked = tcpPacket.ackNo - sentUnack; sentUnack = tcpPacket.ackNo; @@ -188,7 +198,7 @@ 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)); + " seqDiff: " + (sendNext - sentUnack) + " plen: " + plen); notify(); /* this means that we can send more data !!*/ } else { @@ -204,15 +214,28 @@ 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; + + 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??? */ - System.out.println("TCPHandler: seq error: expSeq: " + - Integer.toString(receiveNext & 0xffff, 16) + " != seqNo: " + - Integer.toString(tcpPacket.seqNo & 0xffff, 16)); + /* 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); } - - /* update what to expect next - after this packet! */ - receiveNext = tcpPacket.seqNo + plen; if (tcpPacket.isFin()) { if (tcpListener != null && plen > 0) { @@ -220,20 +243,14 @@ tcpListener.connectionClosed(this); } } + } - /* only ack if new data arrived! */ - if (plen > 0) { - /* ack the new data! - this could be done from the connection itself!!*/ + private void sendAck(TCPPacket tcpPacket) { TCPPacket tcpReply = TCPHandler.createAck(tcpPacket, 0); - tcpReply.ackNo = tcpPacket.seqNo + plen; + tcpReply.ackNo = receiveNext; tcpReply.seqNo = sendNext; send(tcpReply); - - if (tcpListener != null) { - tcpListener.tcpDataReceived(this, tcpPacket); - } - } } public void send(byte[] bytes) { Modified: mspsim/se/sics/mspsim/net/TCPHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPHandler.java 2009-06-13 21:58:29 UTC (rev 565) +++ mspsim/se/sics/mspsim/net/TCPHandler.java 2009-06-15 19:47:19 UTC (rev 566) @@ -7,7 +7,7 @@ /* 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]; @@ -44,7 +44,7 @@ if (connection == null) { System.out.println("TCPHandler: can not find active or listen connection for this packet"); } else { - if ((tcpPacket.flags & TCPPacket.SYN) > 0) { + if (tcpPacket.isSyn()) { TCPPacket tcpReply = createAck(tcpPacket, TCPPacket.SYN); TCPConnection tc = new TCPConnection(ipStack, packet.netInterface); /* setup the connection */ @@ -58,10 +58,13 @@ addConnection(tc); - tcpReply.ackNo = tcpPacket.seqNo + 1; + /* established => report to listeners... */ + connection.newConnection(tc); + + tcpReply.ackNo = tc.receiveNext; tc.send(tcpReply); tc.sentUnack = tc.sendNext = tc.sendNext + 1; - connection.newConnection(tc); + tc.serverConnection = connection; } } } else { @@ -70,9 +73,15 @@ if (tcpPacket.isAck()) { System.out.println("TCPConnection: gotten ACK on syn! => ESTABLISHED!!"); connection.state = TCPConnection.ESTABLISHED; + connection.receive(tcpPacket); + + synchronized(connection) { + /* for any early outputter to the output stream */ + connection.notify(); + } } break; - case TCPConnection.ESTABLISHED: + case TCPConnection.ESTABLISHED: if (tcpPacket.isFin()) { connection.state = TCPConnection.CLOSE_WAIT; } @@ -136,6 +145,11 @@ 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(); + } break; case TCPConnection.CLOSE_WAIT: /* if nothing in buffer - close it! */ Modified: mspsim/se/sics/mspsim/net/TCPInputStream.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPInputStream.java 2009-06-13 21:58:29 UTC (rev 565) +++ mspsim/se/sics/mspsim/net/TCPInputStream.java 2009-06-15 19:47:19 UTC (rev 566) @@ -19,7 +19,6 @@ 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; Modified: mspsim/se/sics/mspsim/net/TCPPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPPacket.java 2009-06-13 21:58:29 UTC (rev 565) +++ mspsim/se/sics/mspsim/net/TCPPacket.java 2009-06-15 19:47:19 UTC (rev 566) @@ -175,7 +175,7 @@ if (payload != null) { System.out.print("|"); int len = 8; - if (payload.length < len) len = payload.length; + if (payload.length < len) len = payload.length; for (int i = 0; i < len; i++) { out.print((char) payload[i]); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-13 21:58:46
|
Revision: 565 http://mspsim.svn.sourceforge.net/mspsim/?rev=565&view=rev Author: joxe Date: 2009-06-13 21:58:29 +0000 (Sat, 13 Jun 2009) Log Message: ----------- fixed bug in resend Modified Paths: -------------- mspsim/se/sics/mspsim/net/TCPConnection.java Modified: mspsim/se/sics/mspsim/net/TCPConnection.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-13 00:19:54 UTC (rev 564) +++ mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-13 21:58:29 UTC (rev 565) @@ -108,6 +108,9 @@ if (tcpPacket.payload != null) { copyToBuffer(tcpPacket.payload); sendNext += tcpPacket.payload.length; + System.out.println("SEND: Updated sendNext: " + sendNext + + " outSize: " + outSize() + " seqDiff: " + + (sendNext - sentUnack)); } lastSendTime = System.currentTimeMillis(); tcpPacket.printPacket(System.out); @@ -181,10 +184,11 @@ sentUnack = tcpPacket.ackNo; bufPos += noAcked; if (bufPos >= outgoingBuffer.length) - bufPos = 0; + 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)); + + Integer.toString(sendNext & 0xffff, 16) + " outSize: " + outSize() + + " seqDiff: " + (sendNext - sentUnack)); notify(); /* this means that we can send more data !!*/ } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-13 01:13:11
|
Revision: 564 http://mspsim.svn.sourceforge.net/mspsim/?rev=564&view=rev Author: joxe Date: 2009-06-13 00:19:54 +0000 (Sat, 13 Jun 2009) Log Message: ----------- improved TCP with resend but still with some buffer management bugs Modified Paths: -------------- mspsim/se/sics/mspsim/net/TCPConnection.java mspsim/se/sics/mspsim/net/TCPHandler.java mspsim/se/sics/mspsim/net/TCPPacket.java Modified: mspsim/se/sics/mspsim/net/TCPConnection.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-12 18:33:43 UTC (rev 563) +++ mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-13 00:19:54 UTC (rev 564) @@ -116,16 +116,17 @@ private int outSize() { int bytesToSend = bufNextEmpty - bufPos; - if (bytesToSend < 0) bytesToSend = -bytesToSend; + if (bytesToSend < 0) bytesToSend += outgoingBuffer.length; return bytesToSend; } private synchronized void copyToBuffer(byte[] data) { int empty = outgoingBuffer.length - outSize(); while (empty < data.length) { - /* need to block this tread until data is available...*/ + /* need to block this tread until place for data is available...*/ try { - wait(1000); + System.out.println("blocking output..."); + wait(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -133,11 +134,22 @@ } empty = outgoingBuffer.length - outSize(); } + for (int i = 0; i < data.length; i++) { + outgoingBuffer[bufNextEmpty++] = data[i]; + if (bufNextEmpty >= outgoingBuffer.length) + bufNextEmpty = 0; + } } private synchronized void resend() { int size = outSize(); + System.out.println("### Bytes to resend: " + outSize() + " seqDiff: " + + (sendNext - sentUnack)); 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++) { @@ -147,7 +159,7 @@ } } - System.out.println("**** TCPConnection resending data"); + System.out.println("**** TCPConnection resending data: size = " + size); TCPPacket tcpPacket = createPacket(); IPv6Packet packet = new IPv6Packet(tcpPacket, localIP, externalIP); @@ -168,19 +180,21 @@ int noAcked = tcpPacket.ackNo - sentUnack; sentUnack = tcpPacket.ackNo; bufPos += noAcked; - System.out.println("ACK for " + noAcked + " bytes... pos: " + bufPos + - " nxtE:" + bufNextEmpty + " unack: " + sentUnack + " sendNext: " - + sendNext); + if (bufPos >= outgoingBuffer.length) + bufPos = 0; + System.out.println("ACK for " + noAcked + " bytes. pos: " + bufPos + + " nxtE:" + bufNextEmpty + " unack: " + Integer.toString(sentUnack & 0xffff, 16) + " sendNext: " + + Integer.toString(sendNext & 0xffff, 16)); notify(); /* this means that we can send more data !!*/ } else { - System.out.println("TCPHandler: Unexpected ACK no: " + - Integer.toString(tcpPacket.ackNo, 16) + - " sendNext: " + Integer.toString(sendNext, 16) + " sentUnack: " + - Integer.toString(sentUnack,16)); - if (tcpPacket.ackNo == sentUnack) { - resend(); - } + 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(); + } } } @@ -189,8 +203,8 @@ } else { /* error - did we miss a packet??? */ System.out.println("TCPHandler: seq error: expSeq: " + - Integer.toString(receiveNext, 16) + " != seqNo: " + - Integer.toString(tcpPacket.seqNo, 16)); + Integer.toString(receiveNext & 0xffff, 16) + " != seqNo: " + + Integer.toString(tcpPacket.seqNo & 0xffff, 16)); } /* update what to expect next - after this packet! */ Modified: mspsim/se/sics/mspsim/net/TCPHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPHandler.java 2009-06-12 18:33:43 UTC (rev 563) +++ mspsim/se/sics/mspsim/net/TCPHandler.java 2009-06-13 00:19:54 UTC (rev 564) @@ -134,6 +134,9 @@ for (int i = 0; i < connectionNo; i++) { TCPConnection connection = activeConnections[i]; switch (connection.state) { + case TCPConnection.ESTABLISHED: + /* here we should check for retransmissions... */ + break; case TCPConnection.CLOSE_WAIT: /* if nothing in buffer - close it! */ if (connection.bufPos == connection.bufNextEmpty) { Modified: mspsim/se/sics/mspsim/net/TCPPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPPacket.java 2009-06-12 18:33:43 UTC (rev 563) +++ mspsim/se/sics/mspsim/net/TCPPacket.java 2009-06-13 00:19:54 UTC (rev 564) @@ -170,8 +170,8 @@ public void printPacket(PrintStream out) { out.print("[TCP " + sourcePort + " -> " + destinationPort + " Flag: " + Utils.hex8(flags) + - " seq: " + Integer.toString(seqNo, 16) + - " ack:" + Integer.toString(ackNo, 16)); + " seq: " + Long.toString(seqNo & 0xffffL, 16) + + " ack:" + Long.toString(ackNo & 0xffffL, 16)); if (payload != null) { System.out.print("|"); int len = 8; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-06-12 18:34:26
|
Revision: 563 http://mspsim.svn.sourceforge.net/mspsim/?rev=563&view=rev Author: joxe Date: 2009-06-12 18:33:43 +0000 (Fri, 12 Jun 2009) Log Message: ----------- added CPU execution trace + CLI command Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/net/TCPConnection.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-06-09 22:27:22 UTC (rev 562) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-06-12 18:33:43 UTC (rev 563) @@ -41,6 +41,8 @@ package se.sics.mspsim.cli; import se.sics.mspsim.core.CPUMonitor; import se.sics.mspsim.core.Chip; +import se.sics.mspsim.core.DbgInstruction; +import se.sics.mspsim.core.DisAsm; import se.sics.mspsim.core.EmulationException; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430Constants; @@ -435,7 +437,7 @@ return 0; } }); - + ch.registerCommand("log", new BasicAsyncCommand("log a loggable object", "<loggable>" ) { Chip chip = null; @Override @@ -453,6 +455,24 @@ } }); + ch.registerCommand("trace", new BasicCommand("store a trace of execution positions.", "<trace size | show>") { + @Override + public int executeCommand(CommandContext context) { + if ("show".equals(context.getArgument(0))) { + int size = cpu.getTraceSize(); + DisAsm disAsm = cpu.getDisAsm(); + for (int i = 0; i < size; i++) { + int pc = cpu.getBackTrace(i); + DbgInstruction inst = disAsm.getDbgInstruction(pc, cpu); + inst.setPos(pc); + System.out.println(inst); + } + } else { + cpu.setTrace(context.getArgumentAsInt(0)); + } + return 0; + } + }); } } } Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2009-06-09 22:27:22 UTC (rev 562) +++ mspsim/se/sics/mspsim/core/MSP430.java 2009-06-12 18:33:43 UTC (rev 563) @@ -47,9 +47,11 @@ public class MSP430 extends MSP430Core { public static final int RETURN = 0x4130; - + private int[] execCounter; - + private int[] trace; + private int tracePos; + private boolean debug = false; private boolean running = false; private long sleepRate = 50000; @@ -120,6 +122,11 @@ if (execCounter != null) { execCounter[reg[PC]]++; } + if (trace != null) { + trace[tracePos++] = reg[PC]; + if (tracePos >= trace.length) + tracePos = 0; + } } /* Just a test to see if it gets down to a reasonable speed */ @@ -167,6 +174,11 @@ if (execCounter != null) { execCounter[reg[PC]]++; } + if (trace != null) { + trace[tracePos++] = reg[PC]; + if (tracePos > trace.length) + tracePos = 0; + } } } setRunning(false); @@ -213,6 +225,11 @@ if (execCounter != null) { execCounter[reg[PC]]++; } + if (trace != null) { + trace[tracePos++] = reg[PC]; + if (tracePos > trace.length) + tracePos = 0; + } } return cycles; } @@ -238,6 +255,28 @@ } } + public void setTrace(int size) { + if (size == 0) { + trace = null; + } else { + trace = new int[size]; + } + tracePos = 0; + } + + public int getBackTrace(int pos) { + int tPos = tracePos - pos; + if (tPos < 0) { + tPos += trace.length; + } + return trace[tPos]; + } + + public int getTraceSize() { + return trace == null ? 0 : trace.length; + } + + private void printCPUSpeed(int pc) { // Passed time int td = (int)(System.currentTimeMillis() - time); @@ -322,5 +361,6 @@ public synchronized void removeSimEventListener(SimEventListener l) { simEventListeners = (SimEventListener[]) ArrayUtils.remove(simEventListeners, l); } + } Modified: mspsim/se/sics/mspsim/net/TCPConnection.java =================================================================== --- mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-09 22:27:22 UTC (rev 562) +++ mspsim/se/sics/mspsim/net/TCPConnection.java 2009-06-12 18:33:43 UTC (rev 563) @@ -162,14 +162,15 @@ int plen = tcpPacket.payload == null ? 0 : tcpPacket.payload.length; if (tcpPacket.isAck()) { - /* check if correct ack - we are only sending a packet a time... */ - if (sendNext == tcpPacket.ackNo) { + /* 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; System.out.println("ACK for " + noAcked + " bytes... pos: " + bufPos + - " nxtE:" + bufNextEmpty); + " nxtE:" + bufNextEmpty + " unack: " + sentUnack + " sendNext: " + + sendNext); notify(); /* this means that we can send more data !!*/ } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |