[Javanetsim-cvs] javaNetSim/core TimerApp.java, NONE, 1.1 EthernetNetworkInterface.java, 1.9, 1.10
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2007-10-20 13:27:25
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv20961/core Modified Files: EthernetNetworkInterface.java FiberEthernetNetworkInterface.java Node.java Simulation.java WANSocket.java Added Files: TimerApp.java Log Message: Node timers; DHCPC resendings; TCP to bytes packing. Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Node.java 19 Oct 2007 17:40:33 -0000 1.17 --- Node.java 20 Oct 2007 13:27:20 -0000 1.18 *************** *** 132,135 **** --- 132,203 ---- + class app_timer_task{ + core.TimerApp app; + int interval; + long lastcall; + Node n; + + public app_timer_task(Node inN, core.TimerApp inApp, int inInterval){ + interval = inInterval; + app = inApp; + n = inN; + } + + public void call(){ + try{ + if(n.On){ + if(System.currentTimeMillis() >= (lastcall+interval) ){ + lastcall = System.currentTimeMillis(); + app.Timer(0); + } + } + }catch(Exception e){ + + } + } + + } + + public class AppTasks extends TimerTask + { + private java.util.Hashtable timerTable; + + public AppTasks(java.util.Hashtable inTimerTable) + { + this.timerTable=inTimerTable; + + } + + + public void run() + { + java.util.Enumeration e = timerTable.keys(); + + for(;e.hasMoreElements();){ + Integer i = (Integer)e.nextElement(); + ((app_timer_task)timerTable.get(i)).call(); + } + } + } + + private java.util.Hashtable timerTable = null; + Timer appTimer = null; + + public void startTimerTask(core.TimerApp app, int interval){ + timerTable.put(Integer.valueOf(app.getUID()), new app_timer_task(this, app, interval)); + } + + public void cancelTimerTask(core.TimerApp app){ + if(timerTable.get(app.getUID())!=null){ + timerTable.remove(app.getUID()); + } + } + + public void stopTimers(){ + if(appTimer!=null){ + appTimer.cancel(); + } + appTimer = null; + } /** *************** *** 162,166 **** this.On = inOn; ! } --- 230,237 ---- this.On = inOn; ! ! timerTable = new Hashtable(); ! appTimer=new Timer(); ! appTimer.schedule(new AppTasks(timerTable),500,500); } Index: Simulation.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Simulation.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Simulation.java 19 Oct 2007 17:40:33 -0000 1.23 --- Simulation.java 20 Oct 2007 13:27:20 -0000 1.24 *************** *** 121,126 **** private static LayerInfoHandler Info = new LayerInfoHandler(); private static int PROTOCOL_TYPE; ! ! // A script is just a Vector containing Strings right now // Each String being a representation of a method to be run such as sendAppData() --- 121,125 ---- private static LayerInfoHandler Info = new LayerInfoHandler(); private static int PROTOCOL_TYPE; ! // A script is just a Vector containing Strings right now // Each String being a representation of a method to be run such as sendAppData() *************** *** 892,895 **** --- 891,901 ---- **/ public void removeAllObjects(){ + Enumeration e = nodeTable.elements(); + while(e.hasMoreElements()) + { + Node temp = (Node)e.nextElement(); + temp.stopTimers(); + } + // nodeTable.clear(); linkTable.clear(); *************** *** 908,911 **** --- 914,918 ---- Node deletedNode = (Node) nodeTable.get(inNodeName); + deletedNode.stopTimers(); deletedNode.removeAllLinks(); nodeTable.remove(inNodeName); //remove node from hashtable Index: WANSocket.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/WANSocket.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WANSocket.java 15 Oct 2007 18:25:54 -0000 1.2 --- WANSocket.java 20 Oct 2007 13:27:20 -0000 1.3 *************** *** 118,121 **** --- 118,124 ---- break; case 'T': + TCP_packet tcp = new TCP_packet("","",0,0); + tcp.fromBytes(inPacket); + parentInterface.receivePacket(tcp); break; case 'U': Index: EthernetNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/EthernetNetworkInterface.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EthernetNetworkInterface.java 18 Oct 2007 22:22:09 -0000 1.9 --- EthernetNetworkInterface.java 20 Oct 2007 13:27:20 -0000 1.10 *************** *** 52,61 **** */ ! class EthernetNetworkInterface extends NetworkInterface{ /** * Stores The MAC address for each instance of this class * */ protected String MACAddress; ! protected String defaultMACAddress; /** --- 52,61 ---- */ ! public class EthernetNetworkInterface extends NetworkInterface{ /** * Stores The MAC address for each instance of this class * */ protected String MACAddress; ! public String defaultMACAddress; /** --- NEW FILE: TimerApp.java --- package core; /** * * @author key */ public abstract class TimerApp { protected int UID; public TimerApp(int UID){ this.UID = UID; } public int getUID(){ return this.UID; } public abstract void Timer(int code); } Index: FiberEthernetNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/FiberEthernetNetworkInterface.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FiberEthernetNetworkInterface.java 19 Oct 2007 15:57:01 -0000 1.1 --- FiberEthernetNetworkInterface.java 20 Oct 2007 13:27:20 -0000 1.2 *************** *** 2,6 **** ! class FiberEthernetNetworkInterface extends EthernetNetworkInterface{ protected FiberEthernetNetworkInterface(String inName, Node parent) { --- 2,6 ---- ! public class FiberEthernetNetworkInterface extends EthernetNetworkInterface{ protected FiberEthernetNetworkInterface(String inName, Node parent) { |