javanetsim-cvs Mailing List for javaNetSim (Page 10)
Status: Beta
Brought to you by:
darkkey
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(120) |
Dec
(62) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(1) |
Feb
(69) |
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(76) |
Oct
(28) |
Nov
(77) |
Dec
(186) |
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(36) |
Oct
(61) |
Nov
(23) |
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(17) |
Oct
(105) |
Nov
(5) |
Dec
(1) |
2009 |
Jan
|
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(8) |
Oct
(9) |
Nov
|
Dec
|
From: Alexander B. <da...@us...> - 2007-10-13 12:57:06
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30660/core/protocolsuite/tcp_ip Modified Files: ARP.java Application.java IPV4Address.java IpV4.java ProtocolStack.java Added Files: DHCPC.java DHCPD.java DHCPPacket.java Log Message: Multiple changes in Link Layer, added DHCP D/C prototype, broadcast packets (+ forwarding), changed menu structure, added MAC address editing, Serial link type and more... Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Application.java 1 Oct 2007 04:58:12 -0000 1.23 --- Application.java 13 Oct 2007 12:57:00 -0000 1.24 *************** *** 87,92 **** */ ! public abstract void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException; public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException --- 87,99 ---- */ ! public abstract void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException; + public void SendData(int sock, String host, int port, String Data) throws LowLinkException, TransportLayerException, CommunicationException { + try{ + if(Connect(host, port)){ + SendData(sock, Data); + } + }catch(InvalidNetworkLayerDeviceException e){ throw new CommunicationException(e.toString()); } + } public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException --- NEW FILE: DHCPPacket.java --- (This appears to be a binary file; contents omitted.) Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** ProtocolStack.java 23 Sep 2007 01:49:58 -0000 1.57 --- ProtocolStack.java 13 Oct 2007 12:57:00 -0000 1.58 *************** *** 77,80 **** --- 77,82 ---- import java.util.TimerTask; + import java.util.ArrayList; + import core.Error; *************** *** 740,745 **** */ ! public void receivePacket(Packet inPacket) throws LowLinkException{ if(inPacket instanceof ARP_packet){ packetARPCounter++; --- 742,748 ---- */ ! public void receivePacket(Packet inPacket, String inInterface) throws LowLinkException{ + try{ if(inPacket instanceof ARP_packet){ packetARPCounter++; *************** *** 779,783 **** //if it is then pass it to the appropriate protocol ! if(mIPprotocol.isInternalIP(destIPAddress)){ --- 782,788 ---- //if it is then pass it to the appropriate protocol ! IPV4Address ip = new IPV4Address(destIPAddress); ! ! if(mIPprotocol.isInternalIP(destIPAddress) || ip.isBroadcast()){ *************** *** 953,956 **** --- 958,999 ---- } + + if(ip.isBroadcast()){ + + NetworkLayerDevice temp = (NetworkLayerDevice)mParentNode; + + ArrayList nics = mParentNode.getAllInterfacesNames(); + + for(int i=0; i<nics.size(); i++){ + if(!inInterface.equals((String)nics.get(i)) && temp.isActiveInterface((String)nics.get(i))){ + LayerInfo routeInfo = new LayerInfo(getClass().getName()); + routeInfo.setObjectName(getParentNodeName()); + routeInfo.setDataType(trimClassName(inPacket.getClass().getName())); + routeInfo.setLayer("Network"); + routeInfo.setDescription("Packet Received: Network Layer Device is Routable forwarding packet to interface " + (String)nics.get(i) + "."); + Simulation.addLayerInfo(routeInfo); + temp.sendPacket("FF:FF:FF:FF:FF:FF", inPacket, (String)nics.get(i) ); + } + } + + + + } + + }catch(InvalidIPAddressException e){ + }catch(InvalidNetworkInterfaceNameException e){ + }catch(CommunicationException ex){ + + String myName = mParentNode.getName(); + + System.out.println(myName + " unable to forward packet due to the following error: " + ex.toString()); + + }catch(LowLinkException ex){ + + String myName = mParentNode.getName(); + + // System.out.println(myName + " unable to forward packet due to the following error: " + ex.toString()); + + } } *************** *** 1224,1227 **** --- 1267,1275 ---- } + public Node getParentNode(){ + + return mParentNode; + + } Index: IPV4Address.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/IPV4Address.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** IPV4Address.java 1 Dec 2005 15:04:55 -0000 1.4 --- IPV4Address.java 13 Oct 2007 12:57:00 -0000 1.5 *************** *** 63,66 **** --- 63,78 ---- setIp(inDecimal); } + + public boolean isBroadcast(){ + //binaryIpAddress + String[] ip = getDecimalIp().split("\\."); + Integer firstoctet = new Integer(ip[0].trim()); + + if(firstoctet.intValue() == 255){ + return true; + }else{ + return false; + } + } /** *************** *** 234,240 **** try { Integer octet = new Integer(ip[i].trim()); ! if (octet.intValue() == 255){ //test all octet's for 255 ! throw new InvalidIPAddressException("Invalid IP Address, cant use Subnet Mask as IP address"); ! } if (i == 0){ //test first octect for 0 eg 0.1.2.3 is an invalid address --- 246,253 ---- try { Integer octet = new Integer(ip[i].trim()); ! //if (octet.intValue() == 255){ //test all octet's for 255 ! // throw new InvalidIPAddressException("Invalid IP Address, cant use Subnet Mask as IP address"); ! //} ! // FIXME if (i == 0){ //test first octect for 0 eg 0.1.2.3 is an invalid address *************** *** 448,451 **** --- 461,468 ---- } + if(inDecIPAddress.contains("255.255.255.255")){ + return true; + } + for (int i = 0; i < ip.length; i++){ try { --- NEW FILE: DHCPC.java --- (This appears to be a binary file; contents omitted.) Index: IpV4.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/IpV4.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** IpV4.java 26 Oct 2006 18:47:38 -0000 1.10 --- IpV4.java 13 Oct 2007 12:57:00 -0000 1.11 *************** *** 1,452 **** ! /* ! Java Firewall Simulator (jFirewallSim) ! ! Copyright (c) 2004, jFirewallSim development team All rights reserved. ! ! Redistribution and use in source and binary forms, with or without modification, are ! permitted provided that the following conditions are met: ! ! - Redistributions of source code must retain the above copyright notice, this list ! of conditions and the following disclaimer. [...1332 lines suppressed...] ! * @version v0.20 ! ! */ ! ! public String getIPAddress(String inInterfaceKey){ ! ! if(ipAddress.containsKey(inInterfaceKey)){ ! ! IPV4Address temp = (IPV4Address)ipAddress.get(inInterfaceKey); ! ! return temp.getDecimalIp(); ! ! } ! ! return null; ! ! } ! ! }//EOF ! Index: ARP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ARP.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ARP.java 24 Feb 2006 15:41:43 -0000 1.7 --- ARP.java 13 Oct 2007 12:57:00 -0000 1.8 *************** *** 322,334 **** { String output= null; int tryings = 5; ! ! //this cleans out any entries older than 2 minutes ! ! cleanARPTable(); ! Iterator it = ARPTable.iterator(); --- 322,343 ---- { + + String output= null; int tryings = 5; ! ! IPV4Address ip; ! ! try{ ! ip = new IPV4Address(IPAddress); ! //this cleans out any entries older than 2 minutes + if(ip.isBroadcast()){ + return "FF:FF:FF:FF:FF:FF"; + } + }catch(Exception e){} + + cleanARPTable(); Iterator it = ARPTable.iterator(); --- NEW FILE: DHCPD.java --- (This appears to be a binary file; contents omitted.) |
From: Alexander B. <da...@us...> - 2007-10-13 12:57:05
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/ipx_spx In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30660/core/protocolsuite/ipx_spx Modified Files: ProtocolStack.java Log Message: Multiple changes in Link Layer, added DHCP D/C prototype, broadcast packets (+ forwarding), changed menu structure, added MAC address editing, Serial link type and more... Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/ipx_spx/ProtocolStack.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ProtocolStack.java 20 Nov 2005 20:30:53 -0000 1.2 --- ProtocolStack.java 13 Oct 2007 12:57:00 -0000 1.3 *************** *** 44,48 **** public void sendPacket(String inDestIPAddress, String inPacketType, String inPacketData){ } ! public void receivePacket(Packet inPacket){ } --- 44,48 ---- public void sendPacket(String inDestIPAddress, String inPacketType, String inPacketData){ } ! public void receivePacket(Packet inPacket, String inInterface){ } |
From: QweR <qw...@us...> - 2007-10-12 21:06:56
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6934/guiUI Modified Files: MainScreen.java Added Files: Terminal.java Removed Files: RunCMD.java Log Message: new cisco like console have been written Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** MainScreen.java 29 Sep 2007 20:33:36 -0000 1.66 --- MainScreen.java 12 Oct 2007 21:06:39 -0000 1.67 *************** *** 95,99 **** import core.protocolsuite.tcp_ip.Telnet_server; import core.protocolsuite.tcp_ip.Telnet_client; ! import guiUI.RunCMD; import javax.swing.JViewport; import javax.swing.table.*; --- 95,99 ---- import core.protocolsuite.tcp_ip.Telnet_server; import core.protocolsuite.tcp_ip.Telnet_client; ! import guiUI.Terminal; import javax.swing.JViewport; import javax.swing.table.*; *************** *** 4142,4146 **** public void RunCmd(String inNodeName){ try{ ! RunCMD r = new RunCMD(this, (core.NetworkLayerDevice)Sim.getNode(inNodeName)); r.pack(); r.setVisible(true); --- 4142,4146 ---- public void RunCmd(String inNodeName){ try{ ! Terminal r = new Terminal(this, (core.NetworkLayerDevice)Sim.getNode(inNodeName)); r.pack(); r.setVisible(true); --- NEW FILE: Terminal.java --- /* * TelnetEmulator.java * * Created on 22 Feb 2006, 16:38 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package guiUI; import core.CommunicationException; import core.DeviceConfig; import core.LowLinkException; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.InputVerifier; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.WindowEvent; import core.TransportLayerException; import java.awt.Font; import java.awt.event.KeyListener; import java.util.regex.*; import core.protocolsuite.tcp_ip.*; import java.util.Vector; import core.CommandsTree; import core.CommandInterface; import core.Version; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JComponent; import core.Pair; import core.CommandProcessor; /** * * @author qwer */ public class Terminal extends JFrame { private JPanel panel; private JScrollPane scrollpane; private JTextArea terminal; private JTextField cmdline; private String text = ""; private core.NetworkLayerDevice device; MainScreen parent; private Vector<String> history = new Vector<String>(0); private int pos_history=0; private final static int max_history = 128; CmdVerifier cmdverifier = new CmdVerifier(); private int current_mode; private int device_type; private int current_config; private CommandProcessor cmdproc; private clear_terminal_CommandClass clear_terminal_Command = new clear_terminal_CommandClass(); private configure_replace_CommandClass configure_replace_Command = new configure_replace_CommandClass(); private configure_memory_CommandClass configure_memory_Command = new configure_memory_CommandClass(); private configure_terminal_CommandClass configure_terminal_Command = new configure_terminal_CommandClass(); private exit_CommandClass exit_Command = new exit_CommandClass(); private logout_CommandClass logout_Command = new logout_CommandClass(); private ping_CommandClass ping_Command = new ping_CommandClass(); private show_history_CommandClass show_history_Command = new show_history_CommandClass(); // Creates a new instance of TelnetEmulator public Terminal(MainScreen parent, core.NetworkLayerDevice dev) { super("Console: " + dev.NodeProtocolStack.getParentNodeName()); device = dev; this.parent = parent; cmdproc = new CommandProcessor(dev); current_mode = CommandsTree.STD_MODE; device_type = CommandsTree.APPLICATION_LAYER; current_config = DeviceConfig.RUNNING_CONFIG; cmdproc.add("clear terminal", clear_terminal_Command, cmdproc.STD_CONF_MODE | cmdproc.NETWORK_LAYER, "<cr>", "Clear screen"); cmdproc.addDescription("configure","Enter configuration mode"); cmdproc.add("configure replace", configure_replace_Command, cmdproc.STD_MODE | cmdproc.NO_LAYER, "<cr>", "Replace configure from the terminal"); cmdproc.add("configure memory", configure_memory_Command, cmdproc.STD_MODE | cmdproc.NO_LAYER, "<cr>", "Configure from memory"); cmdproc.add("configure terminal", configure_terminal_Command, cmdproc.STD_MODE | cmdproc.NO_LAYER, "<cr>", "Configure from the terminal"); cmdproc.add("exit", exit_Command, cmdproc.STD_CONF_MODE | cmdproc.NO_LAYER, "<cr>", "Exit from current mode"); cmdproc.add("logout", logout_Command, cmdproc.STD_MODE | cmdproc.NO_LAYER, "<cr>", "Exit from the console"); cmdproc.add("ping", ping_Command, cmdproc.STD_CONF_MODE | cmdproc.NETWORK_LAYER, "<ip>", "Send echo messages"); cmdproc.add("show history", show_history_Command, cmdproc.STD_CONF_MODE | cmdproc.NO_LAYER, "<cr>", "Display the session command history"); panel = new JPanel(); scrollpane = new JScrollPane(); terminal = new JTextArea(text); cmdline = new JTextField(); this.setContentPane(panel); panel.setLayout(new java.awt.BorderLayout()); panel.add(cmdline, BorderLayout.SOUTH); panel.add(scrollpane, BorderLayout.CENTER); panel.setPreferredSize(new java.awt.Dimension(600,500)); scrollpane.setViewportView(terminal); terminal.setEnabled(true); terminal.setEditable(false); terminal.setFocusable(false); terminal.setBackground(Color.BLACK); terminal.setForeground(Color.WHITE); terminal.setFont(new Font("Courier New", Font.PLAIN, 12)); addToTerminal("javaNetSim console "+Version.CORE_VERSION+", "+Version.YEARS); cmdline.setVisible(true); cmdline.setEnabled(true); cmdline.setFocusable(true); cmdline.setFocusCycleRoot(true); cmdline.setFocusTraversalKeysEnabled(false); cmdline.setInputVerifier(cmdverifier); cmdline.addKeyListener(cmdverifier); this.addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent winEvt) { printInfo(); } }); } public void exitWindow() { printInfo(); this.dispose(); } public void printInfo(){ parent.printLayerInfo(false); //!!!!!: add more headers here } private String runcmd(String cmd) { String out=""; if(cmd.compareTo("")==0) { //nothing } else if(cmd.compareTo("?")==0 || cmd.compareToIgnoreCase("help")==0) { out += " route \t show/edit route table\n"; out += " arp \t show/edit arp table\n"; out += " snmp \t on/off snmp agent\n"; out += " counters\t show network counters\n"; out += " quit \t close terminal session\n"; out += " ? or help\tshow this screen\n"; } else if(cmd.compareToIgnoreCase("quit")==0) { this.dispose(); } else { String tokens[]=cmd.split(" "); Matcher m; if(tokens[0].compareTo("route")==0){ if((m=Pattern.compile(" +print$").matcher(cmd)).find()) { String routes[] = device.NodeProtocolStack.getRouteTableEntries(); out += "IP routing table:\n" + "Destination" + "\t" + "Gateway" + "\t" + "Genmask" + "\t" + "Type" + "\t" + "Iface\n"; for(int i=0; i<routes.length - 1; i++){ Route_entry r = device.NodeProtocolStack.getRouteTableEntry(routes[i]); out += routes[i] + "\t" + r.gateway + "\t" + r.genMask + "\t" + r.Type + "\t" + r.iFace + "\n"; } } else if((m=Pattern.compile(" +add +([^ ]+) +([^ ]+) +([^ ]+)( +([^ ]+|\\*))?$").matcher(cmd)).find()) { if(m.group(5)!=null) { device.NodeProtocolStack.addRoute(new Route_entry(m.group(1), m.group(5), m.group(3), m.group(2), 0)); } else { device.NodeProtocolStack.addRoute(new Route_entry(m.group(1), "", m.group(3), m.group(2), 0)); } out+="Route added.\n"; } else if((m=Pattern.compile(" +del +([^ ]+)$").matcher(cmd)).find()) { device.NodeProtocolStack.removeRoute(m.group(1)); out+="Route to " + tokens[2] + " removed.\n"; } else{ out+="Unknown route command. Usage:\n"; out+=" route add (<host ip>|<network ip>) <target interface> <netmask> [<gateway>|*]\n" + " add new route record\n"; out+=" route del (<host ip>|<network ip>) delete route record\n"; out+=" route print print route table\n"; } } else if(tokens[0].compareTo("snmp")==0){ if(device instanceof core.ApplicationLayerDevice) { if((m=Pattern.compile(" +(on|\\d+)( +([^ ]+))?$").matcher(cmd)).find()) { int l_port=161; String l_pass="public"; if(m.group(1).compareTo("on")!=0) l_port = Integer.parseInt(m.group(1)); if(m.group(3)!=null) { if(m.group(3).compareTo("")!=0) l_pass = m.group(3); } SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(161); try{ snmpa.Close(); snmpa.Disconnect(); out+="SNMP agent stoped\n"; snmpa.setPassword(l_pass); snmpa.setPort(l_port); try{ snmpa.Listen(); out+="Now SNMP agent listen on port " + String.valueOf(l_port) + "\n"; } catch(TransportLayerException e) { out+="Unable to open connection on SNMP agent\n"; } } catch(TransportLayerException e) { out+="Unable to close connection on SNMP agent\n"; } } else if((m=Pattern.compile(" +off$").matcher(cmd)).find()) { SNMP snmpa = (SNMP) ((core.ApplicationLayerDevice)device).getApp(161); try{ snmpa.Close(); out+="SNMP agent stoped\n"; } catch(TransportLayerException e) { out+="Unable to close connection on SNMP agent\n"; } } else { out+="Unknown snmp command. Usage:\n"; out+=" snmp (on|<port number>) [community name] Start SNMP agent\n"; out+=" snmp off Stop SNMP agent\n"; } } else { out += "Sorry, but this device not supported SNMP.\n"; } } else if(tokens[0].compareTo("counters")==0){ out += " Recieved IP Packets: " + Integer.valueOf(device.NodeProtocolStack.getinputIPCount()).toString() + "\n Sent IP Packets: " + Integer.valueOf(device.NodeProtocolStack.getoutputIPCount()).toString() + "\n ARP Packets: " + Integer.valueOf(device.NodeProtocolStack.getARPCount()).toString() + "\n Recieved TCP segments: " + Integer.valueOf(device.NodeProtocolStack.getTCPinputCount()).toString() + "\n Sent TCP segments: " + Integer.valueOf(device.NodeProtocolStack.getTCPoutputCount()).toString() + "\n Sent TCP ACK's: " + Integer.valueOf(device.NodeProtocolStack.getTCPACKCount()).toString() + "\n Sent TCP Dublicates: " + Integer.valueOf(device.NodeProtocolStack.getTCPSDCount()).toString() + "\n Recieved TCP Dublicates: " + Integer.valueOf(device.NodeProtocolStack.getTCPRDCount()).toString() + "\n Recieved UDP segments: " + Integer.valueOf(device.NodeProtocolStack.getUDPinputCount()).toString() + "\n Sent UDP segments: " + Integer.valueOf(device.NodeProtocolStack.getUDPoutputCount()).toString() + "\n"; } else if(tokens[0].compareTo("arp")==0){ if((m=Pattern.compile(" +-a$").matcher(cmd)).find()) { try{ String ArpTable[] = device.NodeProtocolStack.getARPTable(); for(int i=0;i<ArpTable.length;i++) { out += ArpTable[i] + "\n"; } } catch(Exception e) { //Should never get here. } } else if((m=Pattern.compile(" +-d +([^ ]+)$").matcher(cmd)).find()) { device.NodeProtocolStack.removeARP(m.group(1)); out += "Removed ARP entry for ip " + m.group(1) + "\n"; } else if((m=Pattern.compile(" +-s +([^ ]+) +([^ ]+)$").matcher(cmd)).find()) { device.NodeProtocolStack.addToARPStatic(m.group(1), m.group(2)); out += "Created new static ARP entry: " + m.group(1) + " is " + m.group(2) + "\n"; } else { out+="Unknown arp command. Usage:\n"; out+=" arp -a print ARP table\n"; out+=" arp -d <ip address> delete record from ARP table\n"; out+=" arp -s <ip address> <MAC address> add new ARP record\n"; } } else out = tokens[0] + ": command not found\n"; } addToTerminal(out); return out; } // // private String removeSpaces(String s) { // while(s.startsWith(" ")) s = s.substring(1); // while(s.endsWith(" ")) s = s.substring(0, s.length()-1); // return s; // } /** Add text and prompt to terminal * */ private void addToTerminal(String data){ text += data+"\n"+device.NodeProtocolStack.getParentNodeName(); if(current_mode == cmdproc.CONF_MODE){ text += "(config)"; } text += "# "; terminal.setText(text); } /** Add text to terminal * */ private void appendToTerminal(String data){ text += data; terminal.setText(text); } private void clearTerminal(){ text = ""; } public void sendSymbol(String symbol){ if(symbol.length()==1) switch(symbol.charAt(0)) { case 0x0A: { if(cmdline.getText().compareTo("")!=0) { if(history.size()>=max_history) history.remove(0); history.add(cmdline.getText()); pos_history = history.size(); } appendToTerminal(cmdline.getText() + "\n"); String tmptext = cmdproc.call(cmdline.getText(), current_mode | device_type); if(tmptext==null){ tmptext = "% Incomplete command.\n"; } addToTerminal(tmptext); cmdline.setText(""); printInfo(); break; } case 0x04: { exitWindow(); break; } case 0x1B: { cmdline.setText(""); break; } case '\t': { addToTerminal(cmdline.getText()); int caretPos = cmdline.getCaretPosition(); String compl_str = cmdproc.complete(cmdline.getText().substring(0,caretPos), current_mode | device_type); //String last_str = cmdline.getText().substring(caretPos); if(compl_str!=null){ cmdline.setText(compl_str+" "); //cmdline.setText(compl_str+last_str); } break; } case '?': { String tmptext = cmdline.getText() + "?\n"; Vector<Pair> tmpv = cmdproc.help(cmdline.getText().substring(0,cmdline.getCaretPosition()), current_mode | device_type); if(tmpv!=null){ for(int i=0; i<tmpv.size(); i++){ String first = (String)tmpv.get(i).getFirst(); for(int j=20-first.length(); j>0; j--){ first += " "; } tmptext += " "+first+(String)tmpv.get(i).getSecond()+"\n"; } } addToTerminal(tmptext); break; } default: { pos_history = history.size(); } } else if(symbol.length()==3 && symbol.startsWith("^[")) switch(symbol.charAt(2)){ case 0x26: { if(history.size()>0) { if(pos_history == history.size() && cmdline.getText().compareTo("")!=0) { if(history.size()>=max_history) history.remove(0); history.add(cmdline.getText()); pos_history = history.size()-1; } if(pos_history>0) { cmdline.setText(history.get(--pos_history)); } else if(pos_history>0) { cmdline.setText(history.get(pos_history-1)); } } break; } case 0x28: { if(history.size()>0) { if(pos_history+1<history.size()) { cmdline.setText(history.get(++pos_history)); } } break; } default: { pos_history = history.size(); //terminal.setText(text+"\n"+Integer.toHexString(i)); } } else{ pos_history = history.size(); } } class CmdVerifier extends InputVerifier implements KeyListener{ public boolean verify(JComponent input){ String text = ((JTextField)input).getText(); boolean res = !text.contains("?"); return res; } public boolean shouldYieldFocus(JComponent input) { if(!verify(input)) { String text = ((JTextField)input).getText(); ((JTextField)input).setText(text.replace("?","")); } return true; } public void keyTyped(KeyEvent e) { JTextField source = (JTextField)e.getSource(); shouldYieldFocus(source); } public void keyReleased(KeyEvent e) { JTextField source = (JTextField)e.getSource(); shouldYieldFocus(source); } public void keyPressed(KeyEvent e) { JTextField source = (JTextField)e.getSource(); shouldYieldFocus(source); char c = e.getKeyChar(); if(c>=65535) { sendSymbol("^["+(char)e.getKeyCode()); } else { sendSymbol(String.valueOf(c)); } } } class clear_terminal_CommandClass implements CommandInterface{ public String call(Vector<String> params){ clearTerminal(); return ""; } }; class configure_terminal_CommandClass implements CommandInterface{ public String call(Vector<String> params){ current_config = DeviceConfig.RUNNING_CONFIG; current_mode = cmdproc.CONF_MODE; return ""; } }; class configure_replace_CommandClass implements CommandInterface{ public String call(Vector<String> params){ current_config = DeviceConfig.RUNNING_CONFIG; current_mode = cmdproc.CONF_MODE; return "Running-config was erased"; } }; class configure_memory_CommandClass implements CommandInterface{ public String call(Vector<String> params){ current_config = DeviceConfig.STARTUP_CONFIG; current_mode = cmdproc.CONF_MODE; return "Starting-config editing"; } }; class exit_CommandClass implements CommandInterface{ public String call(Vector<String> params){ if(current_mode == cmdproc.CONF_MODE){ current_mode = cmdproc.STD_MODE; } else if(current_mode == cmdproc.STD_MODE){ exitWindow(); } return ""; } }; class logout_CommandClass implements CommandInterface{ public String call(Vector<String> params){ exitWindow(); return ""; } }; class ping_CommandClass implements CommandInterface{ public String call(Vector<String> params){ if(params.size()==1){ appendToTerminal("Type escape sequence to abort.\n"); appendToTerminal("Sending 5, 4-byte ICMP Echos to "+params.get(0)+", timeout is 2 seconds:\n"); int success = 0; for(int i=0; i<5; i++){ try { device.sendPing(params.get(0)); if(false){ success++; } }catch (LowLinkException ex) { ex.printStackTrace(); } catch (CommunicationException ex) { ex.printStackTrace(); } appendToTerminal("."); try{ Thread.sleep(1000); }catch (InterruptedException ex) { ex.printStackTrace(); } } appendToTerminal("\nSuccess rate is " +(int)(success*100/5)+ " percent ("+success+"/5)\n"); } return "Command not supported yet.\n"; } }; class show_history_CommandClass implements CommandInterface{ public String call(Vector<String> params){ String out = ""; for(int i=0; i<params.size(); i++){ out += params.get(i) + "\n"; } return out; } }; } --- RunCMD.java DELETED --- |
From: QweR <qw...@us...> - 2007-10-12 21:06:44
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6934/core/protocolsuite/tcp_ip Modified Files: SNMP.java Log Message: new cisco like console have been written Index: SNMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/SNMP.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** SNMP.java 1 Oct 2007 04:58:12 -0000 1.21 --- SNMP.java 12 Oct 2007 21:06:39 -0000 1.22 *************** *** 70,74 **** public final static int SNMP_RESPONSE = 5; private static int SNMPID = 0; ! private Vector<SNMPInstance> SNMPgroups = new Vector<SNMPInstance>(0); private String current_password = ""; private ApplicationLayerDevice current_device; --- 70,74 ---- public final static int SNMP_RESPONSE = 5; private static int SNMPID = 0; ! public Vector<SNMPInstance> SNMPgroups = new Vector<SNMPInstance>(0); private String current_password = ""; private ApplicationLayerDevice current_device; |
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6934/core Modified Files: NetworkLayerDevice.java Added Files: CommandInterface.java CommandProcessor.java CommandsTree.java DeviceConfig.java Pair.java Log Message: new cisco like console have been written --- NEW FILE: DeviceConfig.java --- (This appears to be a binary file; contents omitted.) --- NEW FILE: CommandsTree.java --- (This appears to be a binary file; contents omitted.) --- NEW FILE: CommandInterface.java --- (This appears to be a binary file; contents omitted.) Index: NetworkLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkLayerDevice.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** NetworkLayerDevice.java 22 Feb 2006 20:04:27 -0000 1.7 --- NetworkLayerDevice.java 12 Oct 2007 21:06:39 -0000 1.8 *************** *** 48,51 **** --- 48,53 ---- public abstract class NetworkLayerDevice extends Node { + private DeviceConfig config = new DeviceConfig(this); + /** * calls the super class (Node) and passes it inName and inProtocolStack *************** *** 306,308 **** --- 308,314 ---- } + public DeviceConfig getConfig(){ + return config; + } + }//EOF --- NEW FILE: CommandProcessor.java --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Pair.java --- (This appears to be a binary file; contents omitted.) |
From: QweR <qw...@us...> - 2007-10-01 04:58:24
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv20979/guiUI Modified Files: PosixTelnetClientGUI.java TelnetEmulator.java Log Message: Applications was corrected Index: TelnetEmulator.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/TelnetEmulator.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TelnetEmulator.java 29 Sep 2007 20:33:36 -0000 1.11 --- TelnetEmulator.java 1 Oct 2007 04:58:13 -0000 1.12 *************** *** 159,163 **** this.removeKeyListener(kl); telnet.Disconnect(); - recvData("\r\n Telnet client was closed"); Data = ""; } --- 159,162 ---- *************** *** 183,186 **** --- 182,190 ---- } + public void close(){ + this.removeKeyListener(kl); + recvData("\r\n Telnet client was closed"); + } + public void exitWindow(){ // this.dispose(); Index: PosixTelnetClientGUI.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/PosixTelnetClientGUI.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PosixTelnetClientGUI.java 8 Nov 2006 14:27:29 -0000 1.1 --- PosixTelnetClientGUI.java 1 Oct 2007 04:58:13 -0000 1.2 *************** *** 141,145 **** pos_history = history.size(); } ! String toSend = cmdline.getText() + "\n"; try{ ptc.SendData(toSend); --- 141,145 ---- pos_history = history.size(); } ! String toSend = cmdline.getText() + "\r\n"; try{ ptc.SendData(toSend); *************** *** 147,151 **** } ! text += cmdline.getText() + "\n"; cmdline.setText(""); --- 147,151 ---- } ! //text += cmdline.getText() + "\r\n"; cmdline.setText(""); |
From: QweR <qw...@us...> - 2007-10-01 04:58:23
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv20979/core Modified Files: Version.java Log Message: Applications was corrected Index: Version.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Version.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Version.java 14 Sep 2007 15:30:08 -0000 1.12 --- Version.java 1 Oct 2007 04:58:11 -0000 1.13 *************** *** 40,48 **** */ public class Version { ! public final static String CORE_VERSION = "v0.33"; //version of the simulation core public final static String YEARS = "2005 - 2007"; public static final String TEAM_MEMBERS[] = { ! "http://sf.net/projects/javanetsim","release date: 26 Sep 2007", "", "fork of jFirewallSim project (http://sf.net/projects/jfirewallsim/)", "from 03 Nov 2005","", --- 40,48 ---- */ public class Version { ! public final static String CORE_VERSION = "v0.34"; //version of the simulation core public final static String YEARS = "2005 - 2007"; public static final String TEAM_MEMBERS[] = { ! "http://sf.net/projects/javanetsim","release date: 01 Oct 2007", "", "fork of jFirewallSim project (http://sf.net/projects/jfirewallsim/)", "from 03 Nov 2005","", |
From: QweR <qw...@us...> - 2007-10-01 04:58:23
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv20979/core/protocolsuite/tcp_ip Modified Files: Application.java Echo.java ExternalProxyApp.java PosixTelnetClient.java SNMP.java TCP_session.java Tcp.java Telnet_client.java Telnet_server.java Udp.java socketLayer.java Log Message: Applications was corrected Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Telnet_client.java 29 Sep 2007 20:33:36 -0000 1.14 --- Telnet_client.java 1 Oct 2007 04:58:12 -0000 1.15 *************** *** 62,66 **** } ! public void Free() throws TransportLayerException{ mParentStack.SL().free(appSock); } --- 62,67 ---- } ! public void Free() throws TransportLayerException ! { mParentStack.SL().free(appSock); } *************** *** 105,108 **** --- 106,111 ---- public void OnDisconnect(int sock){ + terminal.recvData("Connection refused"); + terminal.close(); printLayerInfo("Client: disconnected"); } *************** *** 130,134 **** public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock, Data); } --- 133,137 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock, Data); } Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** socketLayer.java 29 Sep 2007 20:33:36 -0000 1.9 --- socketLayer.java 1 Oct 2007 04:58:13 -0000 1.10 *************** *** 41,45 **** jnsock.src_IP = srcIP; //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! ! //jnsock.open_state = true; //bind or connect or listen if(jnsock.type == jnsock.UDP_socket){ mParentStack.UDP().bindPort(sock, srcPort); --- 41,45 ---- jnsock.src_IP = srcIP; //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! ! //jnsock.open_state = true; //call listen(sock) to open socket if(jnsock.type == jnsock.UDP_socket){ mParentStack.UDP().bindPort(sock, srcPort); *************** *** 56,60 **** //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! if(jnsock.type == jnsock.UDP_socket){ ! //mParentStack.UDP().bindPort(sock, srcPort); } else if(jnsock.type == jnsock.TCP_socket){ --- 56,60 ---- //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! if(jnsock.type == jnsock.UDP_socket){ ! mParentStack.UDP().listen(sock); } else if(jnsock.type == jnsock.TCP_socket){ *************** *** 74,77 **** --- 74,79 ---- } else if(jnsock.type == jnsock.UDP_socket){ + jnsock.dst_IP = ipaddr; + jnsock.dst_port = port; result = true; } *************** *** 131,135 **** if(((jnSocket)sockTable.get(sock)).open_state == true){ //DEPRECATED IN SOON ! if(((jnSocket)sockTable.get(sock)).type != jnSocket.TCP_socket){ ((jnSocket)sockTable.get(sock)).dst_IP = IP; ((jnSocket)sockTable.get(sock)).dst_port = port; --- 133,137 ---- if(((jnSocket)sockTable.get(sock)).open_state == true){ //DEPRECATED IN SOON ! if(((jnSocket)sockTable.get(sock)).type == jnSocket.UDP_socket){ ((jnSocket)sockTable.get(sock)).dst_IP = IP; ((jnSocket)sockTable.get(sock)).dst_port = port; *************** *** 142,146 **** //^^^^^^^^^^^^^^^^ ! ((jnSocket)sockTable.get(sock)).app.OnConnect(sock); ((jnSocket)sockTable.get(sock)).app.RecvData(sock, data); } --- 144,148 ---- //^^^^^^^^^^^^^^^^ ! //((jnSocket)sockTable.get(sock)).app.OnConnect(sock); ((jnSocket)sockTable.get(sock)).app.RecvData(sock, data); } Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Udp.java 22 Sep 2007 23:06:44 -0000 1.38 --- Udp.java 1 Oct 2007 04:58:12 -0000 1.39 *************** *** 281,300 **** if ( mSL.get_socket(sock_num).src_port == 0 ) { ! if (in_Port>=0 && in_Port<=65535) ! { ! //create such a record in hashtable ! mSL.get_socket(sock_num).src_port = in_Port; ! addSession(jnSocket.genUDPkey(in_Port), sock_num); //hash table update ! ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! UDP_Info.setDataType("UDP Protocol"); ! UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("Local port " + in_Port + " binded."); ! Simulation.addLayerInfo(UDP_Info); ! } else // ! { ! throw new TransportLayerException("UDP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); ! } } else // { --- 281,293 ---- if ( mSL.get_socket(sock_num).src_port == 0 ) { ! if (in_Port>=0 && in_Port<=65535) ! { ! //create such a record in hashtable ! mSL.get_socket(sock_num).src_port = in_Port; ! printLayerInfo("Local port " + in_Port + " binded."); ! } else // ! { ! throw new TransportLayerException("UDP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); ! } } else // { *************** *** 304,307 **** --- 297,329 ---- } + // bind port to socket + public void listen(int sock_num) throws TransportLayerException + { + int in_Port = mSL.get_socket(sock_num).src_port; + if( in_Port != 0 ) { + if (in_Port>0 && in_Port<=65535){ + if(!mSL.get_socket(sock_num).open_state){ + addSession(jnSocket.genUDPkey(in_Port), sock_num); //hash table update + printLayerInfo("Local port " + in_Port + " is listening."); + } + else{ + if (mSL.get_socket(sock_num).src_port==in_Port){ + printLayerInfo("UDP error: can not double listen to port "+ in_Port +"! Server is already listening to this port"); + throw new TransportLayerException("error: can not double listen to port "+ in_Port +"! Server is already listening to this port"); + } + else{ + printLayerInfo("UDP error: can not listen to port "+ in_Port +"! Already listening to port " + mSL.get_socket(sock_num).src_port); + throw new TransportLayerException("TCP error: can not listen to port "+ in_Port +"! Already listening to port " + mSL.get_socket(sock_num).src_port); + } + } + } else { + throw new TransportLayerException("UDP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); + } + } else + { + throw new TransportLayerException("UDP error: can not listen to port 0! Use bind before to call listen!"); + } + } + /** * This method closes the UDP port for an application *************** *** 401,405 **** public int GetReceivedDatagrammsNumber() { ! return received_datagramms; } --- 423,427 ---- public int GetReceivedDatagrammsNumber() { ! return received_datagramms; } *************** *** 413,417 **** public int GetSentDatagrammsNumber() { ! return sent_datagramm; } --- 435,439 ---- public int GetSentDatagrammsNumber() { ! return sent_datagramm; } *************** *** 425,430 **** public void ResetCounters() { ! sent_datagramm=0; ! received_datagramms=0; } } //EOF --- 447,461 ---- public void ResetCounters() { ! sent_datagramm=0; ! received_datagramms=0; ! } ! ! protected void printLayerInfo(String s) { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("UDP Protocol"); ! protInfo.setLayer("Transport "); ! protInfo.setDescription(s); ! Simulation.addLayerInfo(protInfo); } } //EOF Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Telnet_server.java 29 Sep 2007 20:33:36 -0000 1.16 --- Telnet_server.java 1 Oct 2007 04:58:12 -0000 1.17 *************** *** 171,182 **** printLayerInfo("Server: recieving message '" + Data + "' from client."); while(Data.length()>0) { - String outData=""; int ch = (char)Data.charAt(0); switch(ch) { case 0x08: { if(cmdline.length() > 0) { ! outData="\b"; cmdline = cmdline.substring(0,cmdline.length()-1); } --- 171,182 ---- printLayerInfo("Server: recieving message '" + Data + "' from client."); + String outData=""; while(Data.length()>0) { int ch = (char)Data.charAt(0); switch(ch) { case 0x08: { if(cmdline.length() > 0) { ! outData += "\b"; cmdline = cmdline.substring(0,cmdline.length()-1); } *************** *** 189,198 **** temp = cmdline; ispass = true; ! outData = "\r\npassword: "; } else if(ispass) { ispass = false; if(temp.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData = "\r\nWelcome to " + mParentStack.getParentNodeName() + "\r\n" + runcmd(""); } else { --- 189,198 ---- temp = cmdline; ispass = true; ! outData += "\r\npassword: "; } else if(ispass) { ispass = false; if(temp.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData += "\r\nWelcome to " + mParentStack.getParentNodeName() + "\r\n" + runcmd(""); } else { *************** *** 209,221 **** if(temp.compareTo("")==0) { temp = cmdline; ! outData = "\r\nRetype new password: "; } else { if(temp.compareTo(cmdline)==0) { password = temp; ! outData = "\r\n" + runcmd(""); } else { ! outData = "\r\n Password is not identical\r\n" + runcmd(""); } isnewpass = false; --- 209,221 ---- if(temp.compareTo("")==0) { temp = cmdline; ! outData += "\r\nRetype new password: "; } else { if(temp.compareTo(cmdline)==0) { password = temp; ! outData += "\r\n" + runcmd(""); } else { ! outData += "\r\n Password is not identical\r\n" + runcmd(""); } isnewpass = false; *************** *** 224,228 **** } else { ! outData = "\r\n" + runcmd(removeSpaces(cmdline)); } cmdline = ""; --- 224,228 ---- } else { ! outData += "\r\n" + runcmd(removeSpaces(cmdline)); } cmdline = ""; *************** *** 236,263 **** { if(ispass || isnewpass) { ! outData = "*"; } else { ! outData = String.valueOf(Data.charAt(0)); } cmdline+=String.valueOf(Data.charAt(0)); } else { ! // outData = "<" + ( ch < 16 ? "0" : "" ) + Integer.toHexString(ch) + ">"; } } ! try{ ! if(outData.compareTo("")==0){ ! mParentStack.SL().disconnect(sock); ! } ! else{ ! printLayerInfo("Server: sending message '" + outData + "' to client."); ! SendData(sock, outData); ! } } ! catch(CommunicationException e){ ! printLayerInfo("Server: can not send data packet: communication error"); } ! Data = Data.substring(1); } } --- 236,263 ---- { if(ispass || isnewpass) { ! outData += "*"; } else { ! outData += String.valueOf(Data.charAt(0)); } cmdline+=String.valueOf(Data.charAt(0)); } else { ! // outData += "<" + ( ch < 16 ? "0" : "" ) + Integer.toHexString(ch) + ">"; } } ! Data = Data.substring(1); ! } ! try{ ! if(outData.compareTo("")==0){ ! mParentStack.SL().disconnect(sock); } ! else{ ! printLayerInfo("Server: sending message '" + outData + "' to client."); ! SendData(sock, outData); } ! } ! catch(CommunicationException e){ ! printLayerInfo("Server: can not send data packet: communication error"); } } Index: PosixTelnetClient.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/PosixTelnetClient.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PosixTelnetClient.java 25 Sep 2007 22:34:09 -0000 1.5 --- PosixTelnetClient.java 1 Oct 2007 04:58:12 -0000 1.6 *************** *** 3,21 **** import core.TransportLayerException; - import core.InvalidNetworkLayerDeviceException; - import core.CommunicationException; - import core.LowLinkException; - import core.LayerInfo; - - import core.Packet; - - import core.Error; - import core.Simulation; - import guiUI.PosixTelnetClientGUI; --- 3,11 ---- *************** *** 33,37 **** /** Creates a new instance of Echo */ public PosixTelnetClient(ProtocolStack inParentStack, int UID) { ! super(inParentStack, 0, 0, UID); } --- 23,28 ---- /** Creates a new instance of Echo */ public PosixTelnetClient(ProtocolStack inParentStack, int UID) { ! super(inParentStack, 0, 0, UID); ! appSock = mParentStack.SL().socket(jnSocket.TCP_socket, this); } *************** *** 57,67 **** */ public void Close() throws TransportLayerException ! { ! mParentStack.CloseTCP(this); } public void Free() throws TransportLayerException ! { ! mParentStack.FreeTCPApplication(this); } --- 48,58 ---- */ public void Close() throws TransportLayerException ! { ! mParentStack.SL().close(appSock); } public void Free() throws TransportLayerException ! { ! mParentStack.SL().free(appSock); } *************** *** 77,98 **** public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! sdHost = Host; ! sdPort = port; ! ! LayerInfo protInfo2 = new LayerInfo(getClass().getName()); ! protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Telnet Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription("Connecting to host " + Host + ":"+ port +". Please wait..."); ! Simulation.addLayerInfo(protInfo2); ! do ! { ! ConnectionAttempts--; ! clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); ! } ! while (ConnectionAttempts>0 && clientPort==-1); ! if (clientPort>-1) return true; else return false; } --- 68,76 ---- public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! printLayerInfo("Connecting to host " + Host + ":"+ port +". Please wait..."); ! boolean isconnected = mParentStack.SL().connect(appSock, Host, port); ! return isconnected; } *************** *** 112,135 **** */ ! public void Disconnect() throws TransportLayerException, LowLinkException{ ! try { ! mParentStack.FinalizeTCP(this); //will close client connection ! }catch(Exception e){ ! ///*TODO*: here to catch ! } ! ! LayerInfo protInfo3 = new LayerInfo(getClass().getName()); ! protInfo3.setObjectName(mParentStack.getParentNodeName()); ! protInfo3.setDataType("Telnet Protocol Data"); ! protInfo3.setLayer("Application "); ! if(appType==0){ ! protInfo3.setDescription("Application closing connection."); ! }else{ ! protInfo3.setDescription("Application closing connection. Now listening on " + listenPort + "."); ! } ! Simulation.addLayerInfo(protInfo3); ! ! mParentStack.CloseTCP(this); ! //mParentStack.freeTCPPort(this); } --- 90,96 ---- */ ! public boolean Disconnect() throws LowLinkException, CommunicationException, TransportLayerException ! { ! return mParentStack.SL().disconnect(appSock); } *************** *** 141,149 **** public void OnDisconnect(int sock) { ! } public void OnError(int sock, int error){ ! } --- 102,119 ---- public void OnDisconnect(int sock) { ! printLayerInfo("Client: disconnected"); } public void OnError(int sock, int error){ ! switch(error){ ! case -1: { ! printLayerInfo("Error: can not connect to " + mParentStack.SL().get_socket(sock).dst_IP + ":" + mParentStack.SL().get_socket(sock).dst_port); ! break; ! } ! case -2 :{ ! OnDisconnect(sock); ! break; ! } ! } } *************** *** 157,164 **** public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! ! mParentStack.SendTCP(this, Data,-1); ! ! //processing the protocol doings. } --- 127,131 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock, Data); } *************** *** 172,187 **** * @version v0.02 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! //processing the protocol doings. ! ! //client processing recieve ! // printing some ... ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Telnet Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving telnet data '" + Data + "' from server."); ! Simulation.addLayerInfo(protInfo); ! protInfo = null; while(ptcGUI.busy); --- 139,145 ---- * @version v0.02 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException ! { ! printLayerInfo("Recieving telnet data '" + Data + "' from server."); while(ptcGUI.busy); *************** *** 200,249 **** */ public void Telnet(PosixTelnetClientGUI ptcGUI, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ! this.ptcGUI = ptcGUI; ! mParentStack.FreeTCPApplication(this); if (Connect(Host, port)) { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Telnet Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Starting telnet connection to " + Host + ":" + port); ! Simulation.addLayerInfo(protInfo); ! ! ! } else { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Telnet Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Error: can not connect to " + Host + ":" + port + "!"); ! Simulation.addLayerInfo(protInfo); } } - - /** - * This method recieves source IP of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - */ - public void RecvIP(String IP) throws LowLinkException, TransportLayerException - { - - } - - /** - * This method recieves source port number of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - */ - public void RecvPrt(int port_num) throws LowLinkException, TransportLayerException - { } - } --- 158,175 ---- */ public void Telnet(PosixTelnetClientGUI ptcGUI, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ! this.ptcGUI = ptcGUI; if (Connect(Host, port)) { ! printLayerInfo("Starting telnet connection to " + Host + ":" + port); ! }else { ! printLayerInfo("Error: can not connect to " + Host + ":" + port + "!"); } } + public void printLayerInfo(String s) { + super.printLayerInfo("Posix Telnet Protocol Data", s); } } Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.97 retrieving revision 1.98 diff -C2 -d -r1.97 -r1.98 *** Tcp.java 29 Sep 2007 20:33:35 -0000 1.97 --- Tcp.java 1 Oct 2007 04:58:12 -0000 1.98 *************** *** 132,136 **** if(nt>=0){ try{ ! mParentStack.sendPacket(packet); }catch(LowLinkException e){ System.out.println(e.toString()); --- 132,140 ---- if(nt>=0){ try{ ! IncSentDuplicatesNumber(1); ! getSession(mParentStack.SL().get_socket(sock).genKey()).inc_sent_duplicates(); ! sendPacket(packet, getSession(mParentStack.SL().get_socket(sock).genKey())); ! }catch(TransportLayerException e){ ! System.out.println(e.toString()); }catch(LowLinkException e){ System.out.println(e.toString()); *************** *** 152,157 **** try{ removeTimer(getSession(mSL.get_socket(sock).genKey()).last_timer); ! mSL.get_socket(sock).app.OnDisconnect(sock); mSL.close(sock); }catch(TransportLayerException e){ System.out.println(e.toString()); --- 156,162 ---- try{ removeTimer(getSession(mSL.get_socket(sock).genKey()).last_timer); ! Application app = mSL.get_socket(sock).app; mSL.close(sock); + app.OnDisconnect(sock); }catch(TransportLayerException e){ System.out.println(e.toString()); *************** *** 160,166 **** } case -2:{ - mSL.get_socket(sock).app.OnError(sock, -1); //connect error try{ mSL.close(sock); }catch(TransportLayerException e){ System.out.println(e.toString()); --- 165,172 ---- } case -2:{ try{ + Application app = mSL.get_socket(sock).app; //connect error mSL.close(sock); + app.OnError(sock, -1); }catch(TransportLayerException e){ System.out.println(e.toString()); *************** *** 170,177 **** case -3:{ //acknowledgment have not recieved, close connection // send RST segment try{ boolean flags[] = genFlags(RST); TCP_packet rstpack = getTCPPacket_tosend(sock, "", flags, packet.get_acknowledgment_number(), packet.get_sequence_number()+1); ! mParentStack.sendPacket(rstpack); }catch(TransportLayerException e){ System.out.println(e.toString()); --- 176,184 ---- case -3:{ //acknowledgment have not recieved, close connection // send RST segment + printLayerInfo(">>> Sending RST segment"); try{ boolean flags[] = genFlags(RST); TCP_packet rstpack = getTCPPacket_tosend(sock, "", flags, packet.get_acknowledgment_number(), packet.get_sequence_number()+1); ! sendPacket(rstpack, getSession(mParentStack.SL().get_socket(sock).genKey())); }catch(TransportLayerException e){ System.out.println(e.toString()); *************** *** 183,188 **** // close seession try{ ! mSL.get_socket(sock).app.OnError(sock, -2); //disconnect on timeout, sending RST mSL.close(sock); }catch(TransportLayerException e){ System.out.println(e.toString()); --- 190,196 ---- // close seession try{ ! Application app = mSL.get_socket(sock).app; //disconnect on timeout, sending RST mSL.close(sock); + app.OnError(sock, -2); }catch(TransportLayerException e){ System.out.println(e.toString()); *************** *** 246,250 **** // private static final int resendtimes_SYNC_CLOSE[] = {75000, -1}; // synchronous closing private static final int resendtimes_SYN_ACK[] = {1000,1000,1000,1000,1000,1000,-2}; ! private static final int resendtimes_SYN[] = {1000,1000,1000,-2}; private static final int resendtimes_DEFAULT[] = {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,-3}; private static final int resendtimes_NULL[] = {}; --- 254,258 ---- // private static final int resendtimes_SYNC_CLOSE[] = {75000, -1}; // synchronous closing private static final int resendtimes_SYN_ACK[] = {1000,1000,1000,1000,1000,1000,-2}; ! private static final int resendtimes_SYN[] = {1000,1000,1000,1000,1000,1000,1000,-2}; private static final int resendtimes_DEFAULT[] = {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,-3}; private static final int resendtimes_NULL[] = {}; *************** *** 509,513 **** * @see TransportLayerException */ ! public void closePort(int sock) throws TransportLayerException //changes port status from 1 (listen) or (see proc ;) to 0 (free) { int portToClose=mSL.get_socket(sock).src_port; --- 517,521 ---- * @see TransportLayerException */ ! public void closePort(int sock) throws TransportLayerException { int portToClose=mSL.get_socket(sock).src_port; *************** *** 526,532 **** } removeSession(mSL.get_socket(sock).genKey()); ! mSL.close(Elm.sock); ! printLayerInfo("Local port " + portToClose + " closed and set to free."); } else --- 534,540 ---- } removeSession(mSL.get_socket(sock).genKey()); ! //mSL.close(Elm.sock); ! printLayerInfo("Local port " + portToClose + " closed."); } else *************** *** 587,598 **** } ! String pack_src = tosend.getSourceIPAddress()+":"+tosend.get_srcPort(); ! String pack_dst = tosend.getDestIPAddress()+":"+tosend.get_destPort(); ! String pack_flags = (tosend.get_ACK_flag()?"ACK,":"")+(tosend.get_SYN_flag()?"SYN,":"")+(tosend.get_FIN_flag()?"FIN,":"")+(tosend.get_RST_flag()?"RST":""); ! System.out.println("|| <<< TCP send pack: src="+pack_src+" dst="+pack_dst+" flags="+pack_flags+" seq="+tosend.get_sequence_number()+" ack="+tosend.get_acknowledgment_number()+" data='"+tosend.getTCP_message()+"'"); ! System.out.println("|| <<<< Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+sock+" state="+Elm.getState()); ! printLayerInfo("TCP packet send to "+pack_dst+" flags="+pack_flags+" seq="+tosend.get_sequence_number()+" ack="+tosend.get_acknowledgment_number()+" data='"+tosend.getTCP_message()+"'"); ! ! mParentStack.sendPacket(tosend); sended_at_last_one_packet = true; } --- 595,599 ---- } ! sendPacket(tosend, Elm); sended_at_last_one_packet = true; } *************** *** 600,603 **** --- 601,622 ---- } + private void sendPacket(TCP_packet packet, TCP_session Elm) throws TransportLayerException, LowLinkException, CommunicationException + { + String pack_src = packet.getSourceIPAddress()+":"+packet.get_srcPort(); + String pack_dst = packet.getDestIPAddress()+":"+packet.get_destPort(); + String pack_flags = (packet.get_ACK_flag()?"ACK,":"")+(packet.get_SYN_flag()?"SYN,":"")+(packet.get_FIN_flag()?"FIN,":"")+(packet.get_RST_flag()?"RST":""); + System.out.println("|| <<< TCP send pack: src="+pack_src+" dst="+pack_dst+" flags="+pack_flags+" seq="+packet.get_sequence_number()+" ack="+packet.get_acknowledgment_number()+" data='"+packet.getTCP_message()+"'"); + System.out.println("|| <<<< Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+Elm.getSocket()+" state="+Elm.getState()); + printLayerInfo("TCP packet send to "+pack_dst+" flags="+pack_flags+" seq="+packet.get_sequence_number()+" ack="+packet.get_acknowledgment_number()+" data='"+packet.getTCP_message()+"'"); + + IncSentSegmentsNumber(1); + Elm.inc_sent_segments(); + if(packet.get_ACK_flag()){ + IncSentACKSegmentsNumber(1); + Elm.inc_sent_ACK(); + } + mParentStack.sendPacket(packet); + } + /** * This method returns the TCP packet to send *************** *** 626,630 **** TCP_packet tosend = new TCP_packet(dstIP,srcIP,dstPort,srcPort); ! // try{ if(seq_num == -1 || seq_num > Elm.seq_number) seq_num = Elm.seq_number; if(acknow_num==-1) acknow_num = Elm.getLastACK(); --- 645,649 ---- TCP_packet tosend = new TCP_packet(dstIP,srcIP,dstPort,srcPort); ! try{ if(seq_num == -1 || seq_num > Elm.seq_number) seq_num = Elm.seq_number; if(acknow_num==-1) acknow_num = Elm.getLastACK(); *************** *** 648,655 **** if (!(flags[SYN_flag] && acknow_num==0) && flags[ACK_flag]) Elm.inc_sent_ACK(); //inc in case this is an ACK-segment (this is statistic) ! // } ! // catch(Exception e){ ! // System.out.println(e.toString()); ! // } --- 667,674 ---- if (!(flags[SYN_flag] && acknow_num==0) && flags[ACK_flag]) Elm.inc_sent_ACK(); //inc in case this is an ACK-segment (this is statistic) ! } ! catch(Exception e){ ! System.out.println(e.toString()); ! } *************** *** 712,716 **** } else{ ! int i = 0; } } --- 731,735 ---- } else{ ! //printLayerInfo(">>> Session not existed: "+jnSocket.genTCPkey(inPacket.get_destPort(), "0.0.0.0", 0)); } } *************** *** 719,722 **** --- 738,745 ---- //int sock = Elm.getSocket(); if(!inPacket.get_ACK_flag() || inPacket.get_acknowledgment_number() > Elm.getLastACK() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag()){ + if((inPacket.get_ACK_flag() && (inPacket.get_SYN_flag() || inPacket.get_FIN_flag() || inPacket.get_RST_flag())) || !inPacket.get_ACK_flag()) { + IncReceivedSegmentsNumber(1); + Elm.inc_received_segments(); + } if(inPacket.get_ACK_flag() && inPacket.get_acknowledgment_number() > Elm.getLastACK()){ long tid = Elm.removeSegmentToResend(inPacket.get_acknowledgment_number()-1); *************** *** 726,731 **** } if(inPacket.get_RST_flag() && !(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ // add chech flags ONLY RST ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } else{ --- 749,755 ---- } if(inPacket.get_RST_flag() && !(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ // add chech flags ONLY RST ! Application app = mSL.get_socket(Elm.getSocket()).app; mSL.close(Elm.getSocket()); + app.OnDisconnect(Elm.getSocket()); } else{ *************** *** 809,816 **** } else if(inPacket.get_SYN_flag() && !(inPacket.get_ACK_flag() || inPacket.get_FIN_flag())){ ! //do nothing, resending works :) } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! Elm.addReceivedSegment(inPacket); // save received segments, although connection have not established yet } else --- 833,846 ---- } else if(inPacket.get_SYN_flag() && !(inPacket.get_ACK_flag() || inPacket.get_FIN_flag())){ ! IncReceivedDuplicatesNumber(1); ! Elm.inc_received_duplicates(); ! // boolean flags[] = genFlags(ACK | SYN); ! // sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_SYN_ACK); } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! if(!Elm.addReceivedSegment(inPacket)){ // save received segments, although connection have not established yet ! IncReceivedDuplicatesNumber(1); ! Elm.inc_received_duplicates(); ! } } else *************** *** 830,833 **** --- 860,865 ---- } else if(inPacket.get_SYN_flag() && inPacket.get_ACK_flag()){ + IncReceivedDuplicatesNumber(1); + Elm.inc_received_duplicates(); boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); *************** *** 854,861 **** { if(inPacket.get_ACK_flag()){ ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } else if(inPacket.get_FIN_flag()){ boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); --- 886,896 ---- { if(inPacket.get_ACK_flag()){ ! Application app = mSL.get_socket(Elm.getSocket()).app; mSL.close(Elm.getSocket()); + app.OnDisconnect(Elm.getSocket()); } else if(inPacket.get_FIN_flag()){ + IncReceivedDuplicatesNumber(1); + Elm.inc_received_duplicates(); boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); *************** *** 875,880 **** sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); if(!USE_2MSL){ ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } } --- 910,916 ---- sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); if(!USE_2MSL){ ! Application app = mSL.get_socket(Elm.getSocket()).app; mSL.close(Elm.getSocket()); + app.OnDisconnect(Elm.getSocket()); } } *************** *** 907,912 **** sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); if(!USE_2MSL){ ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } } --- 943,949 ---- sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); if(!USE_2MSL){ ! Application app = mSL.get_socket(Elm.getSocket()).app; mSL.close(Elm.getSocket()); + app.OnDisconnect(Elm.getSocket()); } } *************** *** 927,932 **** } else{ ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } } --- 964,970 ---- } else{ ! Application app = mSL.get_socket(Elm.getSocket()).app; mSL.close(Elm.getSocket()); + app.OnDisconnect(Elm.getSocket()); } } *************** *** 943,947 **** { if(packet!=null && !(packet.get_SYN_flag() || packet.get_FIN_flag())) { ! Elm.addReceivedSegment(packet); } String out = ""; --- 981,988 ---- { if(packet!=null && !(packet.get_SYN_flag() || packet.get_FIN_flag())) { ! if(!Elm.addReceivedSegment(packet)){ ! IncReceivedDuplicatesNumber(1); ! Elm.inc_received_duplicates(); ! } } String out = ""; *************** *** 999,1002 **** --- 1040,1044 ---- sessionTable.put(key, tcps); } + //printLayerInfo(">>> Session added: "+key+" sock="+sock); return tcps; } *************** *** 1007,1010 **** --- 1049,1053 ---- tcps = (TCP_session) sessionTable.remove(key); } + //printLayerInfo(">>> Session removed: "+key); return tcps; } Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Application.java 29 Sep 2007 20:33:35 -0000 1.22 --- Application.java 1 Oct 2007 04:58:12 -0000 1.23 *************** *** 24,29 **** protected ProtocolStack mParentStack; - protected String sdHost; - protected int sdPort; protected int appType; protected int appSock; --- 24,27 ---- Index: TCP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_session.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TCP_session.java 28 Sep 2007 22:15:51 -0000 1.8 --- TCP_session.java 1 Oct 2007 04:58:12 -0000 1.9 *************** *** 214,217 **** --- 214,220 ---- } } + else{ + Found = true; + } return !Found; } *************** *** 283,287 **** sent_ACK++; } ! public void inv_received_duplicates(){ received_duplicates++; } --- 286,290 ---- sent_ACK++; } ! public void inc_received_duplicates(){ received_duplicates++; } Index: Echo.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Echo.java 25 Sep 2007 22:34:09 -0000 1.27 --- Echo.java 1 Oct 2007 04:58:12 -0000 1.28 *************** *** 7,23 **** package core.protocolsuite.tcp_ip; - import core.TransportLayerException; - import core.InvalidNetworkLayerDeviceException; - import core.CommunicationException; - import core.LowLinkException; - import core.LayerInfo; - - import core.Packet; - import core.Simulation; --- 7,15 ---- *************** *** 46,50 **** // try{ ! mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), listenPort); printLayerInfo("Echo app", "Echo server starts listening in port " + listenPort + "."); } catch (Exception e) --- 38,43 ---- // try{ ! mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), listenPort); ! mParentStack.SL().listen(appSock); printLayerInfo("Echo app", "Echo server starts listening in port " + listenPort + "."); } catch (Exception e) *************** *** 69,73 **** public void Close() throws TransportLayerException { ! printLayerInfo("Echo app", "Echo app closed socket."); mParentStack.SL().close(appSock); } --- 62,66 ---- public void Close() throws TransportLayerException { ! printLayerInfo("Echo application", "Echo application closed socket."); mParentStack.SL().close(appSock); } *************** *** 75,79 **** public void Free() throws TransportLayerException { ! printLayerInfo("Echo app", "Echo app freed socket."); mParentStack.SL().free(appSock); } --- 68,72 ---- public void Free() throws TransportLayerException { ! printLayerInfo("Echo application", "Echo application freed socket."); mParentStack.SL().free(appSock); } *************** *** 88,97 **** */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! sdHost = Host; ! sdPort = port; //clientPort = mParentStack.SL().reserveUDPPort(this, sdHost, sdPort); //if (clientPort>0) return true; else return false; ! return true; } --- 81,88 ---- */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { //clientPort = mParentStack.SL().reserveUDPPort(this, sdHost, sdPort); //if (clientPort>0) return true; else return false; ! return mParentStack.SL().connect(appSock, Host, port); } *************** *** 103,108 **** */ public void OnConnect(int sock){ - sdHost = mParentStack.SL().get_socket(sock).dst_IP; - sdPort = mParentStack.SL().get_socket(sock).dst_port; } --- 94,97 ---- *************** *** 130,133 **** --- 119,124 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { + String sdHost = mParentStack.SL().get_socket(sock).dst_IP; + int sdPort = mParentStack.SL().get_socket(sock).dst_port; mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); *************** *** 156,164 **** Simulation.addLayerInfo(protInfo); ! mParentStack.UDP().closePort(sock); }else{ //server processing recieve try{ LayerInfo protInfo = new LayerInfo(getClass().getName()); protInfo.setObjectName(mParentStack.getParentNodeName()); --- 147,158 ---- Simulation.addLayerInfo(protInfo); ! //mParentStack.UDP().closePort(sock); }else{ //server processing recieve try{ + String sdHost = mParentStack.SL().get_socket(sock).dst_IP; + int sdPort = mParentStack.SL().get_socket(sock).dst_port; + LayerInfo protInfo = new LayerInfo(getClass().getName()); protInfo.setObjectName(mParentStack.getParentNodeName()); *************** *** 235,261 **** Simulation.addLayerInfo(protInfo2); } - - /** - * This method recieves source IP of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - * WARNING: Soon this 'll be DEPRECATED! - */ - public void RecvIP(String IP) throws LowLinkException, TransportLayerException - { - sdHost = IP; - } - - /** - * This method recieves source port number of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - * WARNING: Soon this 'll be DEPRECATED! - */ - public void RecvPrt(int port_num) throws LowLinkException, TransportLayerException { - - sdPort = port_num; - } } --- 229,231 ---- Index: ExternalProxyApp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ExternalProxyApp.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ExternalProxyApp.java 25 Sep 2007 22:34:09 -0000 1.5 --- ExternalProxyApp.java 1 Oct 2007 04:58:12 -0000 1.6 *************** *** 113,127 **** public boolean Connect(String s, int i){ return false; } - - - /** - * This method should be called from UDP when client connects to server - * @author key - * @version v0.01 - */ - public void Connected(String Host, int port){ - sdHost = Host; - sdPort = port; - } /** --- 113,116 ---- Index: SNMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/SNMP.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** SNMP.java 25 Sep 2007 22:34:09 -0000 1.20 --- SNMP.java 1 Oct 2007 04:58:12 -0000 1.21 *************** *** 94,98 **** private String lastPacket=""; //last recieved packet private Vector<String> tVectorString = new Vector<String>(0); - int sock; public SNMP(ApplicationLayerDevice device,ProtocolStack inParentStack, int listenPort, int appType, int UID) { --- 94,97 ---- *************** *** 131,135 **** SNMPgroups.get(i).add("revision","0"); //ro SNMPgroups.get(i).add("version","2"); //ro ! sock = mParentStack.SL().socket(jnSocket.UDP_socket, this); } /** --- 130,134 ---- SNMPgroups.get(i).add("revision","0"); //ro SNMPgroups.get(i).add("version","2"); //ro ! appSock = mParentStack.SL().socket(jnSocket.UDP_socket, this); } /** *************** *** 141,145 **** try{ //mParentStack.ListenUDP(this, listenPort); ! mParentStack.SL().bind(sock, mParentStack.getSrcIP(), listenPort); printInfo("SNMP agent starts listening on port " + listenPort); //<<-- FIXME!!! } --- 140,145 ---- try{ //mParentStack.ListenUDP(this, listenPort); ! mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), listenPort); ! mParentStack.SL().listen(appSock); printInfo("SNMP agent starts listening on port " + listenPort); //<<-- FIXME!!! } *************** *** 161,170 **** public void Close() throws TransportLayerException { //mParentStack.CloseUDP(this); ! mParentStack.SL().close(sock); printInfo("SNMP agent closed socket."); //<--- FIXME!!! } public void Free() throws TransportLayerException{ ! mParentStack.SL().free(sock); printInfo("SNMP agent freed socket."); //<--- FIXME!!! } --- 161,170 ---- public void Close() throws TransportLayerException { //mParentStack.CloseUDP(this); ! mParentStack.SL().close(appSock); printInfo("SNMP agent closed socket."); //<--- FIXME!!! } public void Free() throws TransportLayerException{ ! mParentStack.SL().free(appSock); printInfo("SNMP agent freed socket."); //<--- FIXME!!! } *************** *** 177,210 **** * @version v0.01 */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! sdHost = Host; ! sdPort = port; //clientPort = mParentStack.reserveUDPPort(this, sdHost, sdPort); //if (clientPort>0) return true; //else return false; ! return true; ! } ! ! ! /** ! * This method recieves source IP of a packet ! * @param data to receive ! * @author QweR ! * @version v0.01 ! */ ! public void RecvIP(String IP) throws LowLinkException, TransportLayerException { ! retIP = IP; ! sdHost = IP; ! } ! ! /** ! * This method recieves source port number of a packet ! * @param data to receive ! * @author QweR ! * @version v0.01 ! */ ! public void RecvPrt(int port_num) throws LowLinkException, TransportLayerException { ! retPort = port_num; ! sdPort = port_num; } --- 177,185 ---- * @version v0.01 */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { //clientPort = mParentStack.reserveUDPPort(this, sdHost, sdPort); //if (clientPort>0) return true; //else return false; ! return mParentStack.SL().connect(appSock, Host, port); } *************** *** 236,240 **** public void Disconnect()throws TransportLayerException { //mParentStack.freeUDPPort(this); ! mParentStack.SL().close(sock); } --- 211,215 ---- public void Disconnect()throws TransportLayerException { //mParentStack.freeUDPPort(this); ! mParentStack.SL().close(appSock); } *************** *** 247,251 **** public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { //mParentStack.sendUDP(this, Data); ! mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); } --- 222,228 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { //mParentStack.sendUDP(this, Data); ! String sdHost = mParentStack.SL().get_socket(sock).dst_IP; ! int sdPort = mParentStack.SL().get_socket(sock).dst_port; ! mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); } |
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21244/core/protocolsuite/tcp_ip Modified Files: Application.java Echo_tcp.java Tcp.java Telnet_client.java Telnet_server.java socketLayer.java Log Message: TCP again Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Telnet_client.java 25 Sep 2007 22:34:09 -0000 1.13 --- Telnet_client.java 29 Sep 2007 20:33:36 -0000 1.14 *************** *** 28,34 **** private ApplicationLayerDevice mDevice; private TelnetEmulator terminal; - private int counts; private boolean already_closed = false; - private boolean connected; /** Creates a new instance of Telnet Server */ --- 28,32 ---- *************** *** 36,41 **** super(inParentStack, listenPort, appType, UID); mDevice = dev; ! counts = 0; ! connected = false; } --- 34,38 ---- super(inParentStack, listenPort, appType, UID); mDevice = dev; ! appSock = mParentStack.SL().socket(jnSocket.TCP_socket, this); } *************** *** 62,76 **** public void Close() throws TransportLayerException { ! if(!already_closed){ ! mParentStack.CloseTCP(this); ! already_closed = true; ! } } public void Free() throws TransportLayerException{ ! if(!already_closed){ ! mParentStack.FreeTCPApplication(this); ! already_closed = true; ! } } --- 59,67 ---- public void Close() throws TransportLayerException { ! mParentStack.SL().close(appSock); } public void Free() throws TransportLayerException{ ! mParentStack.SL().free(appSock); } *************** *** 86,103 **** public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! sdHost = Host; ! sdPort = port; ! ! printInfo("Client: connecting to host " + Host + ":"+ port +". Please wait..."); ! do ! { ! ConnectionAttempts--; ! clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); ! } ! while (ConnectionAttempts>0 && clientPort==-1); ! if (clientPort>-1){ connected = true; return true; }else{ connected = false; return false; } ! } --- 77,91 ---- public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! printLayerInfo("Connecting to host " + Host + ":"+ port +". Please wait..."); ! boolean isconnected = mParentStack.SL().connect(appSock, Host, port); ! return isconnected; ! } ! ! public boolean Disconnect() throws LowLinkException, CommunicationException, TransportLayerException ! { ! return mParentStack.SL().disconnect(appSock); ! } *************** *** 117,168 **** public void OnDisconnect(int sock){ ! connected = false; ! printInfo("Client: receive disconnect event"); ! terminal.recvData("\r\nServer closed connection.\r\n"); ! terminal.recvData("\r\nQUIT"); ! // try{ ! // printInfo("Client: receive disconnect event"); ! // Disconnect(); ! // } ! // catch(TransportLayerException e) { ! // printInfo("Client: can not disconnected: transport problem"); ! // } ! // catch(LowLinkException e) { ! // printInfo("Client: can not disconnected: low link problem"); ! // } ! // try{ ! // mParentStack.CloseTCP(this); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Client: can not close port"); ! // } } public void OnError(int sock, int error){ ! ! } ! ! /** ! * This method disconnects from server. ! * @author key ! * @version v0.01 ! */ ! ! public void Disconnect() throws TransportLayerException, LowLinkException{ ! if(connected){ ! try{ ! mParentStack.FinalizeTCP(this); //will close client connection } - catch(CommunicationException e){ - printInfo("Client: can not disconnected: communication problem"); - } - printInfo("Client: closing connection."); - mParentStack.CloseTCP(this); - //mParentStack.freeTCPPort(this); - connected = false; } } - /** * This method sends data to the other side. --- 105,124 ---- public void OnDisconnect(int sock){ ! printLayerInfo("Client: disconnected"); } public void OnError(int sock, int error){ ! switch(error){ ! case -1: { ! printLayerInfo("Error: can not connect to " + mParentStack.SL().get_socket(sock).dst_IP + ":" + mParentStack.SL().get_socket(sock).dst_port); ! break; ! } ! case -2 :{ ! OnDisconnect(sock); ! break; } } } /** * This method sends data to the other side. *************** *** 174,181 **** public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! ! mParentStack.SendTCP(this, Data,-1); ! ! //processing the protocol doings. } --- 130,134 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock, Data); } *************** *** 190,213 **** */ public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! //processing the protocol doings. ! // if(appType == 0){ ! //client processing recieve ! // printing some ... ! printInfo("Client: Recieving message '" + Data + "' from server."); ! ! if(Data.compareTo("\r\nQUIT")==0) { ! //System.out.println("\n\n\n-----------------------\nTelnet: RecvData: QUIT\n-------------------------------\n\n\n"); ! // connected = false; ! // Disconnect(); ! // terminal.recvData("Client: closing connection\n"); ! } ! terminal.recvData(Data); // } } - public void telnetCommand(String cmd){ - - } - /** * This method processes a telnet sending by client --- 143,151 ---- */ public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! printLayerInfo("Client: Recieving message '" + Data + "' from server."); ! terminal.recvData(Data); // } } /** * This method processes a telnet sending by client *************** *** 220,275 **** */ public void TelnetConnect(TelnetEmulator emul, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ - int i = 0; - i++; - mParentStack.FreeTCPApplication(this); - this.counts = counts; this.terminal = emul; if (Connect(Host, port)) { ! ! SendData("\r\n"); ! //SendData("!"); ! //terminal.recvData("Connected!\n"); ! //connected.... } else { ! printInfo("Client: error: can not connect to " + Host + ":" + port + "!"); terminal.recvData("Client: error: cannot connect to " + Host + ":" + port + "!"); - this.counts=0; } } ! /** ! * This method recieves source IP of a packet ! * @param data to receive ! * @author gift (sourceforge.net user) ! * @version v0.01 ! */ ! public void RecvIP(String IP) throws LowLinkException, TransportLayerException ! { ! ! } ! ! /** ! * This method recieves source port number of a packet ! * @param data to receive ! * @author gift (sourceforge.net user) ! * @version v0.01 ! */ ! public void RecvPrt(int port_num) throws LowLinkException, TransportLayerException ! { ! ! } ! ! public void printInfo(String s) { ! LayerInfo protInfo2 = new LayerInfo(getClass().getName()); ! protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Telnet Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription(s); ! Simulation.addLayerInfo(protInfo2); } --- 158,177 ---- */ public void TelnetConnect(TelnetEmulator emul, String Host, int port) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ this.terminal = emul; if (Connect(Host, port)) { ! //SendData("\r\n"); } else { ! printLayerInfo("Client: error: can not connect to " + Host + ":" + port + "!"); terminal.recvData("Client: error: cannot connect to " + Host + ":" + port + "!"); } } ! public void printLayerInfo(String s) { ! super.printLayerInfo("Telnet Protocol Data", s); } Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** socketLayer.java 28 Sep 2007 22:15:51 -0000 1.8 --- socketLayer.java 29 Sep 2007 20:33:36 -0000 1.9 *************** *** 73,77 **** result = mParentStack.TCP().connect(sock, ipaddr, port); } ! else if(jnsock.type == jnsock.TCP_socket){ result = true; } --- 73,90 ---- result = mParentStack.TCP().connect(sock, ipaddr, port); } ! else if(jnsock.type == jnsock.UDP_socket){ ! result = true; ! } ! return result; ! } ! ! public boolean disconnect(int sock) throws LowLinkException, CommunicationException, TransportLayerException{ ! boolean result = false; ! jnSocket jnsock = get_socket(sock); ! if(jnsock.type == jnsock.TCP_socket){ ! result = mParentStack.TCP().disconnect(sock); ! } ! else if(jnsock.type == jnsock.UDP_socket){ ! close(sock); result = true; } Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Telnet_server.java 25 Sep 2007 22:34:09 -0000 1.15 --- Telnet_server.java 29 Sep 2007 20:33:36 -0000 1.16 *************** *** 7,26 **** package core.protocolsuite.tcp_ip; - import core.TransportLayerException; - - import core.InvalidNetworkLayerDeviceException; - import core.CommunicationException; - import core.LowLinkException; - - import core.LayerInfo; - - import core.Packet; import core.ApplicationLayerDevice; - import core.Simulation; import java.util.regex.*; import core.Error; /** --- 7,17 ---- package core.protocolsuite.tcp_ip; import core.TransportLayerException; import core.CommunicationException; import core.LowLinkException; import core.ApplicationLayerDevice; import java.util.regex.*; import core.Error; + import java.util.Vector; /** *************** *** 31,39 **** public class Telnet_server extends Application{ - private int ConnectionAttempts=1; private ApplicationLayerDevice mDevice; ! private int counts; ! private String cmdline=""; ! private boolean isenter=true; private boolean islogin=false; private boolean ispass=false; --- 22,27 ---- public class Telnet_server extends Application{ private ApplicationLayerDevice mDevice; ! private String cmdline = ""; private boolean islogin=false; private boolean ispass=false; *************** *** 43,47 **** private String login = "root"; private String temp = ""; ! private boolean connected; /** Creates a new instance of Telnet Server */ --- 31,35 ---- private String login = "root"; private String temp = ""; ! private Vector<Integer> connections = new Vector<Integer>(1); /** Creates a new instance of Telnet Server */ *************** *** 49,57 **** super(inParentStack, listenPort, appType, UID); mDevice = dev; - counts = 0; - connected = false; - isenter=true; islogin=false; ispass=false; } --- 37,43 ---- super(inParentStack, listenPort, appType, UID); mDevice = dev; islogin=false; ispass=false; + appSock = mParentStack.SL().socket(jnSocket.TCP_socket, this); } *************** *** 63,68 **** public void Listen() throws TransportLayerException{ //throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! mParentStack.ListenTCP(this, listenPort); ! isenter=true; islogin=false; ispass=false; --- 49,58 ---- public void Listen() throws TransportLayerException{ //throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! try{ ! mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), listenPort); ! mParentStack.SL().listen(appSock); ! }catch (TransportLayerException e){ ! System.out.println(e.toString());; ! } islogin=false; ispass=false; *************** *** 70,74 **** public void Accept(int listenSock, int sessionSock){ ! } --- 60,64 ---- public void Accept(int listenSock, int sessionSock){ ! connections.add(new Integer(sessionSock)); } *************** *** 82,87 **** public void Close() throws TransportLayerException { ! mParentStack.CloseTCP(this); ! isenter=true; islogin=false; ispass=false; --- 72,79 ---- public void Close() throws TransportLayerException { ! mParentStack.SL().close(appSock); ! for(int i=0; i<connections.size(); i++){ ! mParentStack.SL().close(connections.get(i).intValue()); ! } islogin=false; ispass=false; *************** *** 90,95 **** public void Free() throws TransportLayerException { ! mParentStack.FreeTCPApplication(this); ! isenter=true; islogin=false; ispass=false; --- 82,89 ---- public void Free() throws TransportLayerException { ! mParentStack.SL().free(appSock); ! for(int i=0; i<connections.size(); i++){ ! mParentStack.SL().free(connections.get(i).intValue()); ! } islogin=false; ispass=false; *************** *** 107,111 **** */ public void OnConnect(int sock){ ! connected = true; } --- 101,116 ---- */ public void OnConnect(int sock){ ! islogin = true; ! temp = ""; ! cmdline = ""; ! try{ ! SendData(sock, "\r\nlogin: "); ! }catch(LowLinkException e){ ! printLayerInfo(e.toString()); ! }catch(TransportLayerException e){ ! printLayerInfo(e.toString()); ! }catch(CommunicationException e){ ! printLayerInfo(e.toString()); ! } } *************** *** 117,165 **** public void OnDisconnect(int sock){ ! connected = false; ! ! printInfo("Server: client closed connection"); ! try{ ! Listen(); ! }catch(Exception e){ ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Cannot listen on port: " + e.toString()); ! Simulation.addLayerInfo(protInfo); ! protInfo = null; ! } } public void OnError(int sock, int error){ ! ! } ! ! /** ! * This method disconnects from server. ! * @author key ! * @version v0.01 ! */ ! ! public void Disconnect() throws TransportLayerException, LowLinkException{ ! connected = false; ! try { ! mParentStack.FinalizeTCP(this); //will close client connection ! }catch(CommunicationException e){ ! printInfo("Server: can not finalize TCP connection"); ! } ! Close(); ! Listen(); ! if(appType==0){ ! printInfo("Server: closing connection."); ! }else{ ! printInfo("Server: closing connection. Now listening on port " + listenPort + "."); } ! // mParentStack.CloseTCP(this); ! // mParentStack.freeTCPPort(this); ! } ! ! /** * This method sends data to the other side. --- 122,150 ---- public void OnDisconnect(int sock){ ! printLayerInfo("Server: client closed connection"); ! islogin=false; ! ispass=false; ! temp = ""; ! cmdline = ""; ! try{ ! connections.remove(new Integer(sock)); ! }catch(Exception e){ ! printLayerInfo("Cannot listen on port: " + e.toString()); ! } } public void OnError(int sock, int error){ ! switch(error){ ! case -1: { ! printLayerInfo("Error: can not connect to " + mParentStack.SL().get_socket(sock).dst_IP + ":" + mParentStack.SL().get_socket(sock).dst_port); ! break; ! } ! case -2 :{ ! OnDisconnect(sock); ! break; ! } } ! } ! /** * This method sends data to the other side. *************** *** 171,178 **** public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! ! mParentStack.SendTCP(this, Data,-1); ! ! //processing the protocol doings. } --- 156,160 ---- public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock,Data); } *************** *** 187,337 **** */ public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! //processing the protocol doings. ! //server processing recieve ! ! printInfo("Server: recieving message '" + Data + "' from client."); while(Data.length()>0) { String outData=""; ! if(isenter && Data.compareTo("\r\n")==0) { ! outData = "\r\nlogin: "; ! islogin = true; ! isenter = false; ! Data = Data.substring(1); ! } ! else ! { ! int ch = (char)Data.charAt(0); ! switch(ch) { ! case 0x04: { ! outData = "\r\nQUIT"; ! break; } ! case 0x08: { ! if(cmdline.length() > 0) { ! outData="\b"; ! cmdline = cmdline.substring(0,cmdline.length()-1); ! } ! break; ! } ! case 0xA: ! case 0xD: { ! if(islogin) { ! islogin = false; ! temp = cmdline; ! ispass = true; ! outData = "\r\npassword: "; } ! else if(ispass) { ! ispass = false; ! if(temp.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData = "\r\nWelcome to " + mParentStack.getParentNodeName() + "\r\n" + runcmd(""); } ! else { ! try { ! SendData("\r\nLogin or password is incorrect"); ! outData = "\r\nQUIT"; ! } ! catch(Exception e) { ! Error.Report(e); ! } } } ! else if(isnewpass) { ! if(temp.compareTo("")==0) { ! temp = cmdline; ! outData = "\r\nRetype new password: "; } else { ! if(temp.compareTo(cmdline)==0) { ! password = temp; ! outData = "\r\n" + runcmd(""); ! } ! else { ! outData = "\r\n Password is not identical\r\n" + runcmd(""); ! } ! isnewpass = false; ! temp=""; } } ! else { ! outData = "\r\n" + runcmd(removeSpaces(cmdline)); ! } ! cmdline = ""; ! if(ch==0xD && (char)Data.charAt(1)==0xA) ! Data = Data.substring(1); ! break; ! } // case 0x1B: outData="ESC"; break; ! default: ! if(ch>=0x20 && ch<0x80) ! { ! if(ispass || isnewpass) { ! outData = "*"; ! } ! else { ! outData = String.valueOf(Data.charAt(0)); ! } ! cmdline+=String.valueOf(Data.charAt(0)); } else { ! // outData = "<" + ( ch < 16 ? "0" : "" ) + Integer.toHexString(ch) + ">"; } ! } ! } ! if(outData.compareTo("\r\nQUIT")==0) { ! Disconnect(); ! // try{ ! // Close(); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Server: can not close application port"); ! // } ! // printInfo("Server: closed connection"); ! // try{ ! // Listen(); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Server: can not listen on application port"); ! // } ! // printInfo("Server: listening on port " + listenPort); ! isenter = true; } ! else{ ! printInfo("Server: sending message '" + outData + "' to client."); ! try{ ! SendData(outData); } ! catch(CommunicationException e){ ! printInfo("Server: can not send data packet: communication error"); } } Data = Data.substring(1); } } - - /** - * This method recieves source IP of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - */ - public void RecvIP(String IP) throws LowLinkException, TransportLayerException - { - - } - - /** - * This method recieves source port number of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - */ - public void RecvPrt(int port_num) throws LowLinkException, TransportLayerException - { - - } - private String runcmd(String cmd) { String out=""; --- 169,266 ---- */ public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { ! ! printLayerInfo("Server: recieving message '" + Data + "' from client."); while(Data.length()>0) { String outData=""; ! int ch = (char)Data.charAt(0); ! switch(ch) { ! case 0x08: { ! if(cmdline.length() > 0) { ! outData="\b"; ! cmdline = cmdline.substring(0,cmdline.length()-1); } ! break; ! } ! case 0xA: ! case 0xD: { ! if(islogin) { ! islogin = false; ! temp = cmdline; ! ispass = true; ! outData = "\r\npassword: "; ! } ! else if(ispass) { ! ispass = false; ! if(temp.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData = "\r\nWelcome to " + mParentStack.getParentNodeName() + "\r\n" + runcmd(""); } ! else { ! try { ! SendData(sock,"\r\nLogin or password is incorrect"); ! outData = ""; } ! catch(Exception e) { ! Error.Report(e); } } ! } ! else if(isnewpass) { ! if(temp.compareTo("")==0) { ! temp = cmdline; ! outData = "\r\nRetype new password: "; ! } ! else { ! if(temp.compareTo(cmdline)==0) { ! password = temp; ! outData = "\r\n" + runcmd(""); } else { ! outData = "\r\n Password is not identical\r\n" + runcmd(""); } + isnewpass = false; + temp=""; } ! } ! else { ! outData = "\r\n" + runcmd(removeSpaces(cmdline)); ! } ! cmdline = ""; ! if(ch==0xD && (char)Data.charAt(1)==0xA) ! Data = Data.substring(1); ! break; ! } // case 0x1B: outData="ESC"; break; ! default: ! if(ch>=0x20 && ch<0x80) ! { ! if(ispass || isnewpass) { ! outData = "*"; } else { ! outData = String.valueOf(Data.charAt(0)); } ! cmdline+=String.valueOf(Data.charAt(0)); ! } ! else { ! // outData = "<" + ( ch < 16 ? "0" : "" ) + Integer.toHexString(ch) + ">"; ! } } ! try{ ! if(outData.compareTo("")==0){ ! mParentStack.SL().disconnect(sock); } ! else{ ! printLayerInfo("Server: sending message '" + outData + "' to client."); ! SendData(sock, outData); } } + catch(CommunicationException e){ + printLayerInfo("Server: can not send data packet: communication error"); + } Data = Data.substring(1); } } private String runcmd(String cmd) { String out=""; *************** *** 349,353 **** } else if(cmd.compareToIgnoreCase("quit")==0) { ! return "QUIT"; } else { --- 278,282 ---- } else if(cmd.compareToIgnoreCase("quit")==0) { ! return ""; } else { *************** *** 488,498 **** } ! private void printInfo(String s) { ! LayerInfo protInfo3 = new LayerInfo(getClass().getName()); ! protInfo3.setObjectName(mParentStack.getParentNodeName()); ! protInfo3.setDataType("Telnet Protocol Data"); ! protInfo3.setLayer("Application "); ! protInfo3.setDescription(s); ! Simulation.addLayerInfo(protInfo3); } --- 417,422 ---- } ! protected void printLayerInfo(String s) { ! super.printLayerInfo("Telnet Protocol Data", s); } Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.96 retrieving revision 1.97 diff -C2 -d -r1.96 -r1.97 *** Tcp.java 28 Sep 2007 22:15:51 -0000 1.96 --- Tcp.java 29 Sep 2007 20:33:35 -0000 1.97 *************** *** 536,541 **** public void sendTCPData(int sock, String data) throws TransportLayerException, LowLinkException, CommunicationException { ! boolean flags[] = genFlags(NOFLAGS); ! sendTCPSegment(sock, data, flags, -1, resendtimes_DEFAULT); } --- 536,543 ---- public void sendTCPData(int sock, String data) throws TransportLayerException, LowLinkException, CommunicationException { ! if(data.length()>0){ ! boolean flags[] = genFlags(NOFLAGS); ! sendTCPSegment(sock, data, flags, -1, resendtimes_DEFAULT); ! } } *************** *** 557,563 **** private boolean sendTCPSegment(int sock, String inTCPMessage, boolean flags[], int acknow_num, int resendtimes[]) throws TransportLayerException, LowLinkException, CommunicationException ! { TCP_packet tosend = getTCPPacket_tosend(sock,inTCPMessage,flags,acknow_num, -1); ! jnSocket jnsock = mSL.get_socket(sock); int srcPort = jnsock.src_port; --- 559,565 ---- private boolean sendTCPSegment(int sock, String inTCPMessage, boolean flags[], int acknow_num, int resendtimes[]) throws TransportLayerException, LowLinkException, CommunicationException ! { TCP_packet tosend = getTCPPacket_tosend(sock,inTCPMessage,flags,acknow_num, -1); ! jnSocket jnsock = mSL.get_socket(sock); int srcPort = jnsock.src_port; *************** *** 565,569 **** int dstPort = jnsock.dst_port; TCP_session Elm = getSession(jnsock.genKey()); ! Elm.addSendingSegment(tosend, resendtimes); trySendSegments(Elm); --- 567,571 ---- int dstPort = jnsock.dst_port; TCP_session Elm = getSession(jnsock.genKey()); ! Elm.addSendingSegment(tosend, resendtimes); trySendSegments(Elm); *************** *** 624,649 **** TCP_packet tosend = new TCP_packet(dstIP,srcIP,dstPort,srcPort); ! //s_num = (flags[1] && !flags[4] && !flags[5]) ? -1 : Elm.seq_number; //getting sequence number 0-for SYN, -1 for ACK ! if(seq_num == -1 || seq_num > Elm.seq_number) seq_num = Elm.seq_number; //getting sequence number 0-for SYN, -1 for ACK ! if(acknow_num==-1) acknow_num = Elm.getLastACK(); ! //now we set all the flags ! /* URG, ACK, PSH, RST, SYN, FIN */ ! tosend.set_URG_flag(flags[URG_flag]); ! tosend.set_ACK_flag(flags[ACK_flag]); ! tosend.set_PSH_flag(flags[PSH_flag]); ! tosend.set_RST_flag(flags[RST_flag]); ! tosend.set_SYN_flag(flags[SYN_flag]); ! tosend.set_FIN_flag(flags[FIN_flag]); ! tosend.set_sequence_number(seq_num); ! tosend.set_acknowledgment_number(acknow_num); ! tosend.setTCP_message(inMessage); ! //counters inc ! Elm.inc_sent_segments(); ! if(seq_num == Elm.seq_number && (!(flags[ACK_flag] || flags[RST_flag]) || flags[SYN_flag] || flags[FIN_flag])) ! Elm.seq_number++; ! if (!(flags[SYN_flag] && acknow_num==0) && flags[ACK_flag]) Elm.inc_sent_ACK(); //inc in case this is an ACK-segment (this is statistic) --- 626,655 ---- TCP_packet tosend = new TCP_packet(dstIP,srcIP,dstPort,srcPort); ! // try{ ! if(seq_num == -1 || seq_num > Elm.seq_number) seq_num = Elm.seq_number; ! if(acknow_num==-1) acknow_num = Elm.getLastACK(); ! //now we set all the flags ! /* URG, ACK, PSH, RST, SYN, FIN */ ! tosend.set_URG_flag(flags[URG_flag]); ! tosend.set_ACK_flag(flags[ACK_flag]); ! tosend.set_PSH_flag(flags[PSH_flag]); ! tosend.set_RST_flag(flags[RST_flag]); ! tosend.set_SYN_flag(flags[SYN_flag]); ! tosend.set_FIN_flag(flags[FIN_flag]); ! tosend.set_sequence_number(seq_num); ! tosend.set_acknowledgment_number(acknow_num); ! tosend.setTCP_message(inMessage); ! //counters inc ! Elm.inc_sent_segments(); ! if(seq_num == Elm.seq_number && (!(flags[ACK_flag] || flags[RST_flag]) || flags[SYN_flag] || flags[FIN_flag])) ! Elm.seq_number++; ! if (!(flags[SYN_flag] && acknow_num==0) && flags[ACK_flag]) Elm.inc_sent_ACK(); //inc in case this is an ACK-segment (this is statistic) ! // } ! // catch(Exception e){ ! // System.out.println(e.toString()); ! // } *************** *** 705,708 **** --- 711,717 ---- Elm.setState(Elm.LISTEN); } + else{ + int i = 0; + } } if (Elm !=null) Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Application.java 25 Sep 2007 22:34:09 -0000 1.21 --- Application.java 29 Sep 2007 20:33:35 -0000 1.22 *************** *** 94,98 **** public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! SendData(appSock, Data); } --- 94,99 ---- public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! if(Data.length() > 0) ! SendData(appSock, Data); } Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** Echo_tcp.java 28 Sep 2007 22:15:51 -0000 1.37 --- Echo_tcp.java 29 Sep 2007 20:33:35 -0000 1.38 *************** *** 60,64 **** public void Accept(int listenSock, int sessionSock){ connections.add(new Integer(sessionSock)); ! System.out.println("Accepted socket="+sessionSock+" for listen socket="+listenSock); } --- 60,64 ---- public void Accept(int listenSock, int sessionSock){ connections.add(new Integer(sessionSock)); ! //System.out.println("Accepted socket="+sessionSock+" for listen socket="+listenSock); } *************** *** 160,164 **** } } - } --- 160,163 ---- *************** *** 203,207 **** printLayerInfo("Connection time: " + (long)(System.currentTimeMillis () - utc1) + " ms. Total recieved messages: " + recieved + "."); try{ ! mParentStack.TCP().disconnect(sock); }catch(CommunicationException e){ System.out.println(e.toString()); --- 202,206 ---- printLayerInfo("Connection time: " + (long)(System.currentTimeMillis () - utc1) + " ms. Total recieved messages: " + recieved + "."); try{ ! mParentStack.SL().disconnect(sock); }catch(CommunicationException e){ System.out.println(e.toString()); |
From: QweR <qw...@us...> - 2007-09-29 20:33:40
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21244/guiUI Modified Files: MainScreen.java TelnetEmulator.java Log Message: TCP again Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** MainScreen.java 21 Sep 2007 22:42:32 -0000 1.65 --- MainScreen.java 29 Sep 2007 20:33:36 -0000 1.66 *************** *** 3764,3768 **** telnet1.setPort(Integer.valueOf(port).intValue()); telnet1.setPassword(pass); ! telnet1.Listen(); printLayerInfo(true); }catch(Exception e){ --- 3764,3768 ---- telnet1.setPort(Integer.valueOf(port).intValue()); telnet1.setPassword(pass); ! telnet1.Listen(); printLayerInfo(true); }catch(Exception e){ Index: TelnetEmulator.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/TelnetEmulator.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TelnetEmulator.java 18 Sep 2007 22:29:47 -0000 1.10 --- TelnetEmulator.java 29 Sep 2007 20:33:36 -0000 1.11 *************** *** 12,71 **** import javax.swing.JFrame; - import javax.swing.JPanel; - - import java.awt.GridBagLayout; - - import javax.swing.JDialog; - - import javax.swing.JLabel; - - import javax.swing.JTextField; import javax.swing.JScrollPane; - import javax.swing.JTextArea; - - import java.awt.Insets; - - import java.awt.GridBagConstraints; - - import java.awt.BorderLayout; - - import javax.swing.JButton; - - import java.awt.Dimension; - - import java.awt.event.ActionListener; - - import java.awt.event.ActionEvent; - - import javax.swing.JComboBox; - - import core.Simulation; - - import java.awt.event.MouseAdapter; - - import java.awt.event.MouseEvent; - import java.awt.Color; - - import java.awt.event.WindowAdapter; - import java.awt.event.WindowEvent; - import java.awt.event.KeyAdapter; - import java.awt.event.KeyEvent; - - import java.awt.event.FocusAdapter; - - import java.awt.event.FocusEvent; - - import java.util.Arrays; - - import java.awt.Component; - - import javax.swing.SwingConstants; - import core.protocolsuite.tcp_ip.Telnet_client; import core.CommunicationException; --- 12,22 ---- *************** *** 73,77 **** import core.InvalidNetworkLayerDeviceException; import core.TransportLayerException; - import java.awt.Font; import java.awt.event.KeyListener; --- 24,27 ---- *************** *** 88,91 **** --- 38,42 ---- private String text; private String Host; + private String cmdline; private int Port; private KeyListener kl; *************** *** 99,102 **** --- 50,54 ---- this.Host = Host; this.Port = Port; + cmdline = ""; *************** *** 121,124 **** --- 73,81 ---- String s; switch(c){ + case 0x4:{ + cmdline = "quit"; + s = "\r\n"; + break; + } case 0xD: case 0xA: { *************** *** 129,133 **** } sendData(s); - printInfo(); } else { --- 86,89 ---- *************** *** 143,147 **** public void windowClosing(WindowEvent winEvt) { exitWindow(); - printInfo(); } }); --- 99,102 ---- *************** *** 189,226 **** public void recvData(String Data){ ! if(Data.compareTo("\r\nQUIT")==0) { ! this.removeKeyListener(kl); ! } ! else { ! if(Data.compareTo("\b")==0) text = text.substring(0, text.length()-1); ! else text += Data; ! terminal.setText(text + "_"); ! } } public void sendData(String Data){ try{ ! telnet.SendData(Data); ! }catch(Exception e){ ! System.out.println(e.toString()); } } - public void printInfo(){ - parent.printLayerInfo(false); - //!!!!!: add more headers here - } - public void exitWindow(){ // this.dispose(); try { telnet.Disconnect(); } ! catch(TransportLayerException e) { ! telnet.printInfo("Client: can not disconnected: transport problem"); ! } ! catch(LowLinkException e) { ! telnet.printInfo("Client: can not disconnected: low link problem"); ! } } } --- 144,202 ---- public void recvData(String Data){ ! // if(Data.compareTo("\r\nQUIT")==0) { ! // this.removeKeyListener(kl); ! // } ! if(Data.compareTo("\b")==0) text = text.substring(0, text.length()-1); ! else text += Data; ! terminal.setText(text + "_"); } public void sendData(String Data){ try{ ! if(Data.length()>0){ ! if(Data.compareTo("\r\n")==0) { ! if(cmdline.compareToIgnoreCase("quit")==0){ ! this.removeKeyListener(kl); ! telnet.Disconnect(); ! recvData("\r\n Telnet client was closed"); ! Data = ""; ! } ! else{ ! cmdline = ""; ! } ! } ! else if(Data.compareTo("\b")==0){ ! cmdline = cmdline.substring(0, cmdline.length()-1); ! } ! else{ ! cmdline += Data; ! } ! telnet.SendData(Data); ! } ! }catch(LowLinkException e){ ! printLayerInfo(e.toString()); ! }catch(TransportLayerException e){ ! printLayerInfo(e.toString()); ! }catch(CommunicationException e){ ! printLayerInfo(e.toString()); } } public void exitWindow(){ // this.dispose(); try { + this.removeKeyListener(kl); telnet.Disconnect(); + }catch(LowLinkException e){ + printLayerInfo(e.toString()); + }catch(TransportLayerException e){ + printLayerInfo(e.toString()); + }catch(CommunicationException e){ + printLayerInfo(e.toString()); } ! } ! ! protected void printLayerInfo(String s) { ! telnet.printLayerInfo(s); } } |
From: QweR <qw...@us...> - 2007-09-28 22:15:59
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv7803/core/protocolsuite/tcp_ip Modified Files: Echo_tcp.java TCP_session.java Tcp.java socketLayer.java Log Message: TCP without RTT works (I hope at least). Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** Tcp.java 25 Sep 2007 22:34:09 -0000 1.95 --- Tcp.java 28 Sep 2007 22:15:51 -0000 1.96 *************** *** 45,48 **** --- 45,49 ---- import java.util.concurrent.ConcurrentLinkedQueue; import java.util.Vector; + import java.util.concurrent.SynchronousQueue; /** *************** *** 78,91 **** */ public void run() { synchronized(tcp_timers_lock){ while(!tcp_timers.isEmpty() && current_time > ((Resender)tcp_timers.peek()).getResendTime()){ Resender rs = (Resender)tcp_timers.poll(); ! if(rs.resend(current_time)){ tcp_timers.add(rs); } } - current_time += TCP_TIMER_DELAY; //System.out.println("Host: "+mParentStack.getHostName()+", time: " + current_time); } } } --- 79,108 ---- */ public void run() { + try{ + LinkedList q_rs = new LinkedList(); + LinkedList q_nt = new LinkedList(); synchronized(tcp_timers_lock){ while(!tcp_timers.isEmpty() && current_time > ((Resender)tcp_timers.peek()).getResendTime()){ Resender rs = (Resender)tcp_timers.poll(); ! int nt = rs.nextTime(current_time); ! if(nt>0){ tcp_timers.add(rs); } + q_rs.add(rs); + q_nt.add(new Integer(nt)); + //printLayerInfo(">>> Timer "+mParentStack.getHostName()+":"+rs.timerID+" was reistalled"); } //System.out.println("Host: "+mParentStack.getHostName()+", time: " + current_time); } + while(!q_rs.isEmpty()){ + Resender rs = (Resender) q_rs.poll(); + int nt = ((Integer)q_nt.poll()).intValue(); + rs.resend(nt); + } + if(!q_nt.isEmpty()) printLayerInfo(">>> TCP timer: synchronization ERROR!!!!"); + }catch(Exception e){ + e.printStackTrace(); + } + current_time += TCP_TIMER_DELAY; } } *************** *** 95,99 **** private TCP_packet packet; private int sock; ! private int nearest_resend; public long timerID; --- 112,116 ---- private TCP_packet packet; private int sock; ! public int nearest_resend; public long timerID; *************** *** 111,119 **** } ! public boolean resend(int cur_time){ boolean res = false; - int nt = nextTime(cur_time); if(nt>=0){ - System.out.println("pack resend"); try{ mParentStack.sendPacket(packet); --- 128,134 ---- } ! public boolean resend(int nt){ boolean res = false; if(nt>=0){ try{ mParentStack.sendPacket(packet); *************** *** 128,136 **** } else{ switch(nt){ case 0:{ //normal quit, do nothing break; } ! case -1:{ //acknowledgment have not recieved, close connection // send RST segment try{ --- 143,172 ---- } else{ + TCP_session tcps = getSession(mParentStack.SL().get_socket(sock).genKey()); + tcps.removeSegmentToResend(packet.get_sequence_number()); switch(nt){ case 0:{ //normal quit, do nothing break; } ! case -1:{ ! try{ ! removeTimer(getSession(mSL.get_socket(sock).genKey()).last_timer); ! mSL.get_socket(sock).app.OnDisconnect(sock); ! mSL.close(sock); ! }catch(TransportLayerException e){ ! System.out.println(e.toString()); ! } ! break; ! } ! case -2:{ ! mSL.get_socket(sock).app.OnError(sock, -1); //connect error ! try{ ! mSL.close(sock); ! }catch(TransportLayerException e){ ! System.out.println(e.toString()); ! } ! break; ! } ! case -3:{ //acknowledgment have not recieved, close connection // send RST segment try{ *************** *** 147,169 **** // close seession try{ - mSL.close(sock); mSL.get_socket(sock).app.OnError(sock, -2); //disconnect on timeout, sending RST - }catch(TransportLayerException e){ - System.out.println(e.toString()); - } - break; - } - case -2:{ - mSL.get_socket(sock).app.OnError(sock, -1); //connect error - break; - } - case -3:{ - try{ - removeTimer(getSession(mSL.get_socket(sock).genKey()).last_timer); - mSL.get_socket(sock).app.OnDisconnect(sock); mSL.close(sock); }catch(TransportLayerException e){ System.out.println(e.toString()); } } default: System.out.println("TCP error: unsupported resend time"); --- 183,192 ---- // close seession try{ mSL.get_socket(sock).app.OnError(sock, -2); //disconnect on timeout, sending RST mSL.close(sock); }catch(TransportLayerException e){ System.out.println(e.toString()); } + break; } default: System.out.println("TCP error: unsupported resend time"); *************** *** 182,186 **** } ! private int nextTime(int cur_time){ if(resend_time.isEmpty()) nearest_resend = 0; else{ --- 205,209 ---- } ! public int nextTime(int cur_time){ if(resend_time.isEmpty()) nearest_resend = 0; else{ *************** *** 214,225 **** private long nextTimerID = 0; private static final boolean USE_2MSL = false; ! private static final int MSL_TIME = 5000; ! private static final int resendtimes_SYN_ACK[] = {1500,3000,6000,12000,24000,28000,-2}; ! private static final int resendtimes_SYN[] = {6000,24000,45000,-2}; ! private static final int resendtimes_DEFAULT[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; private static final int resendtimes_NULL[] = {}; ! private static final int resendtimes_2MSL[] = {2*MSL_TIME,-3}; // 2MSL ! private static final int resendtimes_EXIT[] = {75000,-3}; // non-RFC exit ! private static final int resendtimes_SYNC_CLOSE[] = {75000, -3}; // synchronous closing --- 237,255 ---- private long nextTimerID = 0; private static final boolean USE_2MSL = false; ! private static final int MSL_TIME = 2500; ! // private static final int resendtimes_SYN_ACK[] = {1500,3000,6000,12000,24000,28000,-2}; ! // private static final int resendtimes_SYN[] = {6000,24000,45000,-2}; ! // private static final int resendtimes_DEFAULT[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-3}; ! // private static final int resendtimes_NULL[] = {}; ! // private static final int resendtimes_2MSL[] = {2*MSL_TIME,-1}; // 2MSL ! // private static final int resendtimes_EXIT[] = {75000,-1}; // non-RFC exit ! // private static final int resendtimes_SYNC_CLOSE[] = {75000, -1}; // synchronous closing ! private static final int resendtimes_SYN_ACK[] = {1000,1000,1000,1000,1000,1000,-2}; ! private static final int resendtimes_SYN[] = {1000,1000,1000,-2}; ! private static final int resendtimes_DEFAULT[] = {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,-3}; private static final int resendtimes_NULL[] = {}; ! private static final int resendtimes_2MSL[] = {2*MSL_TIME,-1}; // 2MSL ! private static final int resendtimes_EXIT[] = {15000,-1}; // non-RFC exit ! private static final int resendtimes_SYNC_CLOSE[] = {15000, -1}; // synchronous closing *************** *** 323,327 **** Reserved=true; mSL.get_socket(sock).src_port = number; ! printLayerInfo("Local port " + number + " reserved for client app."); } --- 353,357 ---- Reserved=true; mSL.get_socket(sock).src_port = number; ! addSession(jnSocket.genTCPkey(number,"0.0.0.0",0), sock); printLayerInfo("Local port " + number + " reserved for client app."); } *************** *** 331,334 **** --- 361,365 ---- if (!Reserved) //all ports are busy :( { + printLayerInfo("TCP Error: all ports are busy! Cannot reserve port for socket!"); throw new TransportLayerException("TCP Error: all ports are busy! Cannot reserve port for socket!"); } *************** *** 339,361 **** // bind port to socket public void bindPort(int sock_num, int in_Port) throws TransportLayerException ! { ! if( mSL.get_socket(sock_num).src_port == 0 ) ! { ! if (in_Port>0 && in_Port<=65535){ ! //create such a record in hashtable ! mSL.get_socket(sock_num).src_port = in_Port; ! printLayerInfo("Local port " + in_Port + " binded."); ! } ! else if(in_Port == 0){ ! reserveFreePort(sock_num); ! } ! else { ! throw new TransportLayerException("TCP error: can not bind to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); ! } ! } else // ! { ! if (mSL.get_socket(sock_num).src_port==in_Port) throw new TransportLayerException("error: can not double bind to port "+ in_Port +"! Server is already listening to this port"); ! throw new TransportLayerException("TCP error: can not bind to port "+ in_Port +"! Already listening to port " + mSL.get_socket(sock_num).src_port); ! } } --- 370,398 ---- // bind port to socket public void bindPort(int sock_num, int in_Port) throws TransportLayerException ! { ! if(!mSL.get_socket(sock_num).open_state){ ! if (in_Port>0 && in_Port<=65535){ ! //create such a record in hashtable ! mSL.get_socket(sock_num).src_port = in_Port; ! printLayerInfo("Local port " + in_Port + " binded."); ! } ! else if(in_Port == 0){ ! reserveFreePort(sock_num); ! } ! else { ! printLayerInfo("TCP error: can not bind to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); ! throw new TransportLayerException("TCP error: can not bind to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); ! } ! } ! else{ ! if (mSL.get_socket(sock_num).src_port==in_Port){ ! printLayerInfo("TCP error: can not double bind to port "+ in_Port +"! Server is already listening to this port"); ! throw new TransportLayerException("error: can not bind listen to port "+ in_Port +"! Server is already listening to this port"); ! } ! else{ ! printLayerInfo("TCP error: can not bind to port "+ in_Port +"! Already listening to port " + mSL.get_socket(sock_num).src_port); ! throw new TransportLayerException("TCP error: can not bind to port "+ in_Port +"! Already listening to port " + mSL.get_socket(sock_num).src_port); ! } ! } } *************** *** 364,372 **** { int in_Port = mSL.get_socket(sock_num).src_port; ! if( in_Port!= 0 ) { if (in_Port>0 && in_Port<=65535){ ! TCP_session tcps = addSession(jnSocket.genTCPkey(in_Port,"0.0.0.0",0), sock_num); ! tcps.setState(tcps.LISTEN); ! printLayerInfo("Local port " + in_Port + " is listening."); } else { throw new TransportLayerException("TCP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); --- 401,421 ---- { int in_Port = mSL.get_socket(sock_num).src_port; ! if( in_Port != 0 ) { if (in_Port>0 && in_Port<=65535){ ! if(!mSL.get_socket(sock_num).open_state){ ! TCP_session tcps = addSession(jnSocket.genTCPkey(in_Port,"0.0.0.0",0), sock_num); ! tcps.setState(tcps.LISTEN); ! printLayerInfo("Local port " + in_Port + " is listening."); ! } ! else{ ! if (mSL.get_socket(sock_num).src_port==in_Port){ ! printLayerInfo("TCP error: can not double listen to port "+ in_Port +"! Server is already listening to this port"); ! throw new TransportLayerException("error: can not double listen to port "+ in_Port +"! Server is already listening to this port"); ! } ! else{ ! printLayerInfo("TCP error: can not listen to port "+ in_Port +"! Already listening to port " + mSL.get_socket(sock_num).src_port); ! throw new TransportLayerException("TCP error: can not listen to port "+ in_Port +"! Already listening to port " + mSL.get_socket(sock_num).src_port); ! } ! } } else { throw new TransportLayerException("TCP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); *************** *** 412,416 **** else{ Elm.setState(Elm.CLOSED); - System.out.println(">> TCP: sendTCPSegment false"); } } --- 461,464 ---- *************** *** 468,474 **** if(portToClose!=0 && Elm!=null){ TCP_session mainses = getSession(jnSocket.genTCPkey(portToClose,"0.0.0.0",0)); ! if(mainses != null && mainses.getSocket() == sock){ // remove listening session on client size only removeSession(jnSocket.genTCPkey(portToClose,"0.0.0.0",0)); } removeSession(mSL.get_socket(sock).genKey()); mSL.close(Elm.sock); --- 516,528 ---- if(portToClose!=0 && Elm!=null){ TCP_session mainses = getSession(jnSocket.genTCPkey(portToClose,"0.0.0.0",0)); ! if(mainses != null && mainses.getSocket() == sock){ // remove listening session on client side only removeSession(jnSocket.genTCPkey(portToClose,"0.0.0.0",0)); } + Enumeration<Integer> segs = Elm.getAllSegmentToResendNumbers(); + while(segs.hasMoreElements()){ + int segment = segs.nextElement().intValue(); + long tid = Elm.removeSegmentToResend(segment); + removeTimer(tid); + } removeSession(mSL.get_socket(sock).genKey()); mSL.close(Elm.sock); *************** *** 535,540 **** String pack_flags = (tosend.get_ACK_flag()?"ACK,":"")+(tosend.get_SYN_flag()?"SYN,":"")+(tosend.get_FIN_flag()?"FIN,":"")+(tosend.get_RST_flag()?"RST":""); System.out.println("|| <<< TCP send pack: src="+pack_src+" dst="+pack_dst+" flags="+pack_flags+" seq="+tosend.get_sequence_number()+" ack="+tosend.get_acknowledgment_number()+" data='"+tosend.getTCP_message()+"'"); - System.out.println("|| <<<< Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+sock+" state="+Elm.getState()); mParentStack.sendPacket(tosend); --- 589,594 ---- String pack_flags = (tosend.get_ACK_flag()?"ACK,":"")+(tosend.get_SYN_flag()?"SYN,":"")+(tosend.get_FIN_flag()?"FIN,":"")+(tosend.get_RST_flag()?"RST":""); System.out.println("|| <<< TCP send pack: src="+pack_src+" dst="+pack_dst+" flags="+pack_flags+" seq="+tosend.get_sequence_number()+" ack="+tosend.get_acknowledgment_number()+" data='"+tosend.getTCP_message()+"'"); System.out.println("|| <<<< Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+sock+" state="+Elm.getState()); + printLayerInfo("TCP packet send to "+pack_dst+" flags="+pack_flags+" seq="+tosend.get_sequence_number()+" ack="+tosend.get_acknowledgment_number()+" data='"+tosend.getTCP_message()+"'"); mParentStack.sendPacket(tosend); *************** *** 657,662 **** if(!inPacket.get_ACK_flag() || inPacket.get_acknowledgment_number() > Elm.getLastACK() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag()){ if(inPacket.get_ACK_flag() && inPacket.get_acknowledgment_number() > Elm.getLastACK()){ ! removeTimer(Elm.getSegmentToResend(inPacket.get_acknowledgment_number()-1)); ! Elm.removeSegmentToResend(inPacket.get_acknowledgment_number()-1); Elm.setLastACK(inPacket.get_acknowledgment_number()); trySendSegments(Elm); --- 711,716 ---- if(!inPacket.get_ACK_flag() || inPacket.get_acknowledgment_number() > Elm.getLastACK() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag()){ if(inPacket.get_ACK_flag() && inPacket.get_acknowledgment_number() > Elm.getLastACK()){ ! long tid = Elm.removeSegmentToResend(inPacket.get_acknowledgment_number()-1); ! removeTimer(tid); Elm.setLastACK(inPacket.get_acknowledgment_number()); trySendSegments(Elm); *************** *** 698,702 **** // rstpack.setTCP_message(""); // mParentStack.sendPacket(rstpack); ! throw new TransportLayerPortException("TCP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); } --- 752,756 ---- // rstpack.setTCP_message(""); // mParentStack.sendPacket(rstpack); ! printLayerInfo("TCP packet received from "+ pack_src +" flags: "+pack_flags+" message: \"" +inPacket.getTCP_message() + "\"."); throw new TransportLayerPortException("TCP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); } *************** *** 743,750 **** --- 797,808 ---- Elm.setState(Elm.ESTABLISHED); mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); + processSegment(Elm, null); // pass already reveived segments to application } else if(inPacket.get_SYN_flag() && !(inPacket.get_ACK_flag() || inPacket.get_FIN_flag())){ //do nothing, resending works :) } + else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ + Elm.addReceivedSegment(inPacket); // save received segments, although connection have not established yet + } else throw new TransportLayerException("TCP: recv_SYN_RCVD: unexpected packet"); *************** *** 762,768 **** sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_DEFAULT); } else if(inPacket.get_ACK_flag()){ //do nothing, segment have been already processed - int i = 0; } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ --- 820,829 ---- sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_DEFAULT); } + else if(inPacket.get_SYN_flag() && inPacket.get_ACK_flag()){ + boolean flags[] = genFlags(ACK); + sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); + } else if(inPacket.get_ACK_flag()){ //do nothing, segment have been already processed } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ *************** *** 799,808 **** if(inPacket.get_ACK_flag() && inPacket.get_FIN_flag()){ Elm.setState(Elm.TIME_WAIT); - boolean flags[] = genFlags(ACK); - sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); if(USE_2MSL){ Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_2MSL); } ! else{ mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); --- 860,869 ---- if(inPacket.get_ACK_flag() && inPacket.get_FIN_flag()){ Elm.setState(Elm.TIME_WAIT); if(USE_2MSL){ Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_2MSL); } ! boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); ! if(!USE_2MSL){ mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); *************** *** 815,821 **** else if(inPacket.get_FIN_flag()){ Elm.setState(Elm.CLOSING); boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); - Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_SYNC_CLOSE); } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ --- 876,882 ---- else if(inPacket.get_FIN_flag()){ Elm.setState(Elm.CLOSING); + Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_SYNC_CLOSE); boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ *************** *** 830,840 **** if(inPacket.get_FIN_flag()){ Elm.setState(Elm.TIME_WAIT); - boolean flags[] = genFlags(ACK); - sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); removeTimer(Elm.last_timer); if(USE_2MSL){ Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_2MSL); } ! else{ mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); --- 891,901 ---- if(inPacket.get_FIN_flag()){ Elm.setState(Elm.TIME_WAIT); removeTimer(Elm.last_timer); if(USE_2MSL){ Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_2MSL); } ! boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); ! if(!USE_2MSL){ mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); *************** *** 872,876 **** private void processSegment(TCP_session Elm, TCP_packet packet) throws LowLinkException, TransportLayerException, CommunicationException { ! Elm.addReceivedSegment(packet); String out = ""; int readySegments = 0; --- 933,939 ---- private void processSegment(TCP_session Elm, TCP_packet packet) throws LowLinkException, TransportLayerException, CommunicationException { ! if(packet!=null && !(packet.get_SYN_flag() || packet.get_FIN_flag())) { ! Elm.addReceivedSegment(packet); ! } String out = ""; int readySegments = 0; *************** *** 893,896 **** --- 956,964 ---- synchronized(tcp_timers_lock){ tcp_timers.add(rsnd); + String ttt=""; + for(int i=0; i<times.length; i++){ + ttt += times[i]+","; + } + //printLayerInfo(">>> Timer "+mParentStack.getHostName()+":"+rsnd.timerID+" was added {"+ttt+"}"); } } *************** *** 900,909 **** private void removeTimer(long timerid){ ! Iterator<Resender> it = tcp_timers.iterator(); ! boolean notFound = true; ! while(notFound && it.hasNext()){ ! if(it.next().timerID == timerid){ ! notFound = false; ! it.remove(); } } --- 968,984 ---- private void removeTimer(long timerid){ ! synchronized(tcp_timers_lock){ ! Iterator<Resender> it = tcp_timers.iterator(); ! boolean notFound = true; ! while(notFound && it.hasNext()){ ! if(it.next().timerID == timerid){ ! notFound = false; ! it.remove(); ! //printLayerInfo(">>> Timer "+mParentStack.getHostName()+":"+timerid+" was removed"); ! } ! } ! if(notFound){ ! printLayerInfo(">>> TCP error: timer "+mParentStack.getHostName()+":"+timerid+" removing failed"); ! System.out.println(">>> TCP error: timer "+mParentStack.getHostName()+":"+timerid+" removing failed"); } } Index: TCP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_session.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TCP_session.java 25 Sep 2007 22:34:09 -0000 1.7 --- TCP_session.java 28 Sep 2007 22:15:51 -0000 1.8 *************** *** 13,16 **** --- 13,17 ---- import java.util.PriorityQueue; import java.util.Iterator; + import java.util.Enumeration; /** *************** *** 171,174 **** --- 172,179 ---- } + public Enumeration<Integer> getAllSegmentToResendNumbers(){ + return segmentsToResend.keys(); + } + /** * Pop expected segment from buffer Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** socketLayer.java 25 Sep 2007 22:34:09 -0000 1.7 --- socketLayer.java 28 Sep 2007 22:15:51 -0000 1.8 *************** *** 41,45 **** jnsock.src_IP = srcIP; //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! ! jnsock.open_state = true; //bind or connect or listen if(jnsock.type == jnsock.UDP_socket){ mParentStack.UDP().bindPort(sock, srcPort); --- 41,45 ---- jnsock.src_IP = srcIP; //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! ! //jnsock.open_state = true; //bind or connect or listen if(jnsock.type == jnsock.UDP_socket){ mParentStack.UDP().bindPort(sock, srcPort); *************** *** 55,59 **** jnSocket jnsock = get_socket(sock); //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! - jnsock.open_state = true; //bind or connect or listen if(jnsock.type == jnsock.UDP_socket){ //mParentStack.UDP().bindPort(sock, srcPort); --- 55,58 ---- *************** *** 62,65 **** --- 61,65 ---- mParentStack.TCP().listen(sock); } + jnsock.open_state = true; //bind or connect or listen } Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** Echo_tcp.java 25 Sep 2007 22:34:09 -0000 1.36 --- Echo_tcp.java 28 Sep 2007 22:15:51 -0000 1.37 *************** *** 113,116 **** --- 113,117 ---- public void OnConnect(int sock){ System.out.println("ECHO_TCP: Connected "+sock+" !"); + printLayerInfo("Connected "+sock+" !"); try{ if(appType == 0){ |
From: QweR <qw...@us...> - 2007-09-25 22:40:06
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31956/core/protocolsuite/tcp_ip Modified Files: Application.java Echo.java Echo_tcp.java ExternalProxyApp.java PosixTelnetClient.java SNMP.java TCP_packet.java TCP_session.java Tcp.java Telnet_client.java Telnet_server.java socketLayer.java Log Message: TCP almost works on bad lines (resending timers not killed) Index: TCP_packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_packet.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TCP_packet.java 21 Sep 2007 22:42:31 -0000 1.4 --- TCP_packet.java 25 Sep 2007 22:34:09 -0000 1.5 *************** *** 45,49 **** * @version v0.20 */ ! public class TCP_packet extends IP_packet { /* DO NOT forget about pseudo UDP header fields --- 45,49 ---- * @version v0.20 */ ! public class TCP_packet extends IP_packet implements Comparable { /* DO NOT forget about pseudo UDP header fields *************** *** 416,419 **** --- 416,423 ---- return new TCP_packet(this); } + + public int compareTo(Object o) { + return ( sequence_number - ((TCP_packet)o).sequence_number ); + } }//EOF Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Telnet_client.java 23 Sep 2007 20:24:43 -0000 1.12 --- Telnet_client.java 25 Sep 2007 22:34:09 -0000 1.13 *************** *** 49,53 **** } ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ } --- 49,53 ---- } ! public void Accept(int listenSock, int sessionSock){ } *************** *** 172,176 **** */ ! public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { --- 172,176 ---- */ ! public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { *************** *** 189,193 **** * @version v0.02 */ ! public void RecvData(String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. // if(appType == 0){ --- 189,193 ---- * @version v0.02 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. // if(appType == 0){ Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** socketLayer.java 23 Sep 2007 22:12:23 -0000 1.6 --- socketLayer.java 25 Sep 2007 22:34:09 -0000 1.7 *************** *** 88,91 **** --- 88,92 ---- new_jnsock.dst_port = dstPort; new_jnsock.open_state = true; + new_jnsock.app.Accept(sock, new_sock); return new_sock; } *************** *** 108,112 **** if(sock < lastSock){ if(((jnSocket)sockTable.get(sock)).open_state == true){ ! ((jnSocket)sockTable.get(sock)).app.RecvData(data); } } --- 109,113 ---- if(sock < lastSock){ if(((jnSocket)sockTable.get(sock)).open_state == true){ ! ((jnSocket)sockTable.get(sock)).app.RecvData(sock, data); } } *************** *** 129,133 **** ((jnSocket)sockTable.get(sock)).app.OnConnect(sock); ! ((jnSocket)sockTable.get(sock)).app.RecvData(data); } } --- 130,134 ---- ((jnSocket)sockTable.get(sock)).app.OnConnect(sock); ! ((jnSocket)sockTable.get(sock)).app.RecvData(sock, data); } } Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Telnet_server.java 23 Sep 2007 20:24:43 -0000 1.14 --- Telnet_server.java 25 Sep 2007 22:34:09 -0000 1.15 *************** *** 69,73 **** } ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ } --- 69,73 ---- } ! public void Accept(int listenSock, int sessionSock){ } *************** *** 169,173 **** */ ! public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { --- 169,173 ---- */ ! public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { *************** *** 186,190 **** * @version v0.02 */ ! public void RecvData(String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. //server processing recieve --- 186,190 ---- * @version v0.02 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. //server processing recieve Index: PosixTelnetClient.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/PosixTelnetClient.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PosixTelnetClient.java 23 Sep 2007 20:24:43 -0000 1.4 --- PosixTelnetClient.java 25 Sep 2007 22:34:09 -0000 1.5 *************** *** 45,49 **** } ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ } --- 45,49 ---- } ! public void Accept(int listenSock, int sessionSock){ } *************** *** 155,159 **** */ ! public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { --- 155,159 ---- */ ! public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { *************** *** 172,176 **** * @version v0.02 */ ! public void RecvData(String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. --- 172,176 ---- * @version v0.02 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** Tcp.java 23 Sep 2007 22:12:23 -0000 1.94 --- Tcp.java 25 Sep 2007 22:34:09 -0000 1.95 *************** *** 44,47 **** --- 44,48 ---- import java.util.PriorityQueue; import java.util.concurrent.ConcurrentLinkedQueue; + import java.util.Vector; /** *************** *** 85,89 **** } current_time += TCP_TIMER_DELAY; ! System.out.println("Host: "+mParentStack.getHostName()+", time: " + current_time); } } --- 86,90 ---- } current_time += TCP_TIMER_DELAY; ! //System.out.println("Host: "+mParentStack.getHostName()+", time: " + current_time); } } *************** *** 133,138 **** case -1:{ //acknowledgment have not recieved, close connection // send RST segment - boolean flags[] = genFlags(RST); try{ TCP_packet rstpack = getTCPPacket_tosend(sock, "", flags, packet.get_acknowledgment_number(), packet.get_sequence_number()+1); mParentStack.sendPacket(rstpack); --- 134,139 ---- case -1:{ //acknowledgment have not recieved, close connection // send RST segment try{ + boolean flags[] = genFlags(RST); TCP_packet rstpack = getTCPPacket_tosend(sock, "", flags, packet.get_acknowledgment_number(), packet.get_sequence_number()+1); mParentStack.sendPacket(rstpack); *************** *** 214,218 **** private static final boolean USE_2MSL = false; private static final int MSL_TIME = 5000; ! /*statistic block*/ --- 215,226 ---- private static final boolean USE_2MSL = false; private static final int MSL_TIME = 5000; ! private static final int resendtimes_SYN_ACK[] = {1500,3000,6000,12000,24000,28000,-2}; ! private static final int resendtimes_SYN[] = {6000,24000,45000,-2}; ! private static final int resendtimes_DEFAULT[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; ! private static final int resendtimes_NULL[] = {}; ! private static final int resendtimes_2MSL[] = {2*MSL_TIME,-3}; // 2MSL ! private static final int resendtimes_EXIT[] = {75000,-3}; // non-RFC exit ! private static final int resendtimes_SYNC_CLOSE[] = {75000, -3}; // synchronous closing ! /*statistic block*/ *************** *** 229,233 **** * Used in timer */ ! private static final long TCP_TIMER_DELAY = 1000; // private static final long TCP_SERVER_TIME = 1000; //msec //server closing idle connection time --- 237,241 ---- * Used in timer */ ! private static final long TCP_TIMER_DELAY = 500; // private static final long TCP_SERVER_TIME = 1000; //msec //server closing idle connection time *************** *** 264,268 **** mSL = inSL; timer=new Timer(); ! //timer.schedule(new TCPTask(),TCP_TIMER_DELAY,TCP_TIMER_DELAY); } --- 272,276 ---- mSL = inSL; timer=new Timer(); ! timer.schedule(new TCPTask(),TCP_TIMER_DELAY,TCP_TIMER_DELAY); } *************** *** 389,393 **** { //int CONNECTION_DELAY_EXAM = (int)TCP_TIMER_DELAY/4; //examination delay is 10ms, but may be any number - int resendtimes[] = {6000,24000,45000,-2}; boolean flags[] = genFlags(SYN); boolean connected = false; --- 397,400 ---- *************** *** 399,403 **** Elm.setState(Elm.SYN_SENT); ! if (sendTCPSegment(sock, "", flags, -1, resendtimes)) { connected = true; --- 406,410 ---- Elm.setState(Elm.SYN_SENT); ! if (sendTCPSegment(sock, "", flags, -1, resendtimes_SYN)) { connected = true; *************** *** 436,442 **** if(Elm != null){ Elm.setState(Elm.FIN_WAIT_1); - int resendtimes[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; boolean flags[] = genFlags(FIN); ! sendTCPSegment(Elm.getSocket(), "", flags, -1, resendtimes); } else { --- 443,448 ---- if(Elm != null){ Elm.setState(Elm.FIN_WAIT_1); boolean flags[] = genFlags(FIN); ! sendTCPSegment(Elm.getSocket(), "", flags, -1, resendtimes_DEFAULT); } else { *************** *** 477,482 **** { boolean flags[] = genFlags(NOFLAGS); ! int resendtimes[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; ! sendTCPSegment(sock, data, flags, -1, resendtimes); } --- 483,487 ---- { boolean flags[] = genFlags(NOFLAGS); ! sendTCPSegment(sock, data, flags, -1, resendtimes_DEFAULT); } *************** *** 507,526 **** TCP_session Elm = getSession(jnsock.genKey()); ! if(resendtimes.length > 0){ ! long tid = createTimer(sock, (TCP_packet)tosend.clone(), resendtimes); ! Elm.addSegmentToResend(tosend.get_sequence_number(),tid); ! } ! ! String pack_src = tosend.getSourceIPAddress()+":"+tosend.get_srcPort(); ! String pack_dst = tosend.getDestIPAddress()+":"+tosend.get_destPort(); ! String pack_flags = (tosend.get_ACK_flag()?"ACK,":"")+(tosend.get_SYN_flag()?"SYN,":"")+(tosend.get_FIN_flag()?"FIN,":"")+(tosend.get_RST_flag()?"RST":""); ! System.out.println("|| <<< TCP send pack: src="+pack_src+" dst="+pack_dst+" flags="+pack_flags+" seq="+tosend.get_sequence_number()+" ack="+tosend.get_acknowledgment_number()+" data='"+tosend.getTCP_message()+"'"); ! ! System.out.println("|| <<<< Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+sock+" state="+Elm.getState()); ! ! mParentStack.sendPacket(tosend); return true; } /** * This method returns the TCP packet to send --- 512,547 ---- TCP_session Elm = getSession(jnsock.genKey()); ! Elm.addSendingSegment(tosend, resendtimes); ! trySendSegments(Elm); ! return true; } + private boolean trySendSegments(TCP_session Elm) throws TransportLayerException, LowLinkException, CommunicationException + { + boolean sended_at_last_one_packet = false; + int sock = Elm.getSocket(); + while(Elm.hasNextSendingSegment()){ + + TCP_session.TCPPacketTimesPair sendpair = Elm.getNextSendingSegment(); + TCP_packet tosend = sendpair.packet; + if(sendpair.resendtimes.length > 0){ + long tid = createTimer(sock, (TCP_packet)tosend.clone(), sendpair.resendtimes); + Elm.addSegmentToResend(tosend.get_sequence_number(),tid); + } + + String pack_src = tosend.getSourceIPAddress()+":"+tosend.get_srcPort(); + String pack_dst = tosend.getDestIPAddress()+":"+tosend.get_destPort(); + String pack_flags = (tosend.get_ACK_flag()?"ACK,":"")+(tosend.get_SYN_flag()?"SYN,":"")+(tosend.get_FIN_flag()?"FIN,":"")+(tosend.get_RST_flag()?"RST":""); + System.out.println("|| <<< TCP send pack: src="+pack_src+" dst="+pack_dst+" flags="+pack_flags+" seq="+tosend.get_sequence_number()+" ack="+tosend.get_acknowledgment_number()+" data='"+tosend.getTCP_message()+"'"); + + System.out.println("|| <<<< Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+sock+" state="+Elm.getState()); + + mParentStack.sendPacket(tosend); + sended_at_last_one_packet = true; + } + return sended_at_last_one_packet; + } + /** * This method returns the TCP packet to send *************** *** 629,633 **** Elm = addSession(jnSocket.genTCPkey(inPacket.get_destPort(), inPacket.getSourceIPAddress(), inPacket.get_srcPort()), sock); Elm.setState(Elm.LISTEN); - jnsock.app.Accept(listensock, sock); } } --- 650,653 ---- *************** *** 635,643 **** { //int sock = Elm.getSocket(); ! if(inPacket.get_acknowledgment_number() >= Elm.getLastACK()){ if(inPacket.get_ACK_flag() && inPacket.get_acknowledgment_number() > Elm.getLastACK()){ removeTimer(Elm.getSegmentToResend(inPacket.get_acknowledgment_number()-1)); Elm.removeSegmentToResend(inPacket.get_acknowledgment_number()-1); Elm.setLastACK(inPacket.get_acknowledgment_number()); } if(inPacket.get_RST_flag() && !(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ // add chech flags ONLY RST --- 655,664 ---- { //int sock = Elm.getSocket(); ! if(!inPacket.get_ACK_flag() || inPacket.get_acknowledgment_number() > Elm.getLastACK() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag()){ if(inPacket.get_ACK_flag() && inPacket.get_acknowledgment_number() > Elm.getLastACK()){ removeTimer(Elm.getSegmentToResend(inPacket.get_acknowledgment_number()-1)); Elm.removeSegmentToResend(inPacket.get_acknowledgment_number()-1); Elm.setLastACK(inPacket.get_acknowledgment_number()); + trySendSegments(Elm); } if(inPacket.get_RST_flag() && !(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ // add chech flags ONLY RST *************** *** 647,651 **** else{ System.out.println("|| >>>> Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+Elm.getSocket()+" state="+Elm.getState()); ! printLayerInfo("TCP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getTCP_message() + "\"."); switch(Elm.getState()){ --- 668,672 ---- else{ System.out.println("|| >>>> Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+Elm.getSocket()+" state="+Elm.getState()); ! printLayerInfo("TCP packet received from "+ pack_src +" flags: "+pack_flags+" message: \"" +inPacket.getTCP_message() + "\"."); switch(Elm.getState()){ *************** *** 669,673 **** else { //throw new TransportLayerPortException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); ! //send RST throw new TransportLayerPortException("TCP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); } --- 690,702 ---- else { //throw new TransportLayerPortException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); ! // send RST segment ! // boolean flags[] = genFlags(RST); ! // TCP_packet rstpack = new TCP_packet(inPacket.getDestIPAddress(), inPacket.getSourceIPAddress(), inPacket.get_destPort(), inPacket.get_srcPort()); ! // rstpack.set_RST_flag(true); ! // rstpack.set_sequence_number(0); ! // rstpack.set_acknowledgment_number(inPacket.get_sequence_number()+1); ! // rstpack.setTCP_message(""); ! // mParentStack.sendPacket(rstpack); ! throw new TransportLayerPortException("TCP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); } *************** *** 688,694 **** if(inPacket.get_SYN_flag()){ Elm.setState(Elm.SYN_RCVD); - int resendtimes[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; boolean flags[] = genFlags(ACK | SYN); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); } else --- 717,722 ---- if(inPacket.get_SYN_flag()){ Elm.setState(Elm.SYN_RCVD); boolean flags[] = genFlags(ACK | SYN); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_SYN_ACK); } else *************** *** 700,706 **** if(inPacket.get_SYN_flag() && inPacket.get_ACK_flag()){ Elm.setState(Elm.ESTABLISHED); - int resendtimes[] = {}; boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); //mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); jnSocket jns = mSL.get_socket(Elm.getSocket()); --- 728,733 ---- if(inPacket.get_SYN_flag() && inPacket.get_ACK_flag()){ Elm.setState(Elm.ESTABLISHED); boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); //mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); jnSocket jns = mSL.get_socket(Elm.getSocket()); *************** *** 713,720 **** private void recv_SYN_RCVD(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(inPacket.get_ACK_flag()){ Elm.setState(Elm.ESTABLISHED); mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); } else throw new TransportLayerException("TCP: recv_SYN_RCVD: unexpected packet"); --- 740,750 ---- private void recv_SYN_RCVD(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(inPacket.get_ACK_flag() && !(inPacket.get_FIN_flag() || inPacket.get_SYN_flag())){ Elm.setState(Elm.ESTABLISHED); mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); } + else if(inPacket.get_SYN_flag() && !(inPacket.get_ACK_flag() || inPacket.get_FIN_flag())){ + //do nothing, resending works :) + } else throw new TransportLayerException("TCP: recv_SYN_RCVD: unexpected packet"); *************** *** 723,739 **** private void recv_ESTABLISHED(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(inPacket.get_FIN_flag()){ Elm.setState(Elm.CLOSE_WAIT); - int resendtimes1[] = {}; boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes1); Elm.setState(Elm.LAST_ACK); - int resendtimes2[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; //to resend or not to resend ? flags = genFlags(FIN); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes2); } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! //normal data processing } else --- 753,771 ---- private void recv_ESTABLISHED(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(inPacket.get_FIN_flag() && !inPacket.get_ACK_flag()){ Elm.setState(Elm.CLOSE_WAIT); boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); Elm.setState(Elm.LAST_ACK); flags = genFlags(FIN); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_DEFAULT); ! } ! else if(inPacket.get_ACK_flag()){ ! //do nothing, segment have been already processed ! int i = 0; } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! processSegment(Elm, inPacket); } else *************** *** 756,762 **** } else if(inPacket.get_FIN_flag()){ - int resendtimes[] = {}; boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); } else --- 788,793 ---- } else if(inPacket.get_FIN_flag()){ boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); } else *************** *** 768,777 **** if(inPacket.get_ACK_flag() && inPacket.get_FIN_flag()){ Elm.setState(Elm.TIME_WAIT); - int resendtimes[] = {}; boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); if(USE_2MSL){ ! int resendtimes2[] = {2*MSL_TIME,-3}; // 2MSL ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes2); } else{ --- 799,806 ---- if(inPacket.get_ACK_flag() && inPacket.get_FIN_flag()){ Elm.setState(Elm.TIME_WAIT); boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); if(USE_2MSL){ ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_2MSL); } else{ *************** *** 782,798 **** else if(inPacket.get_ACK_flag()){ Elm.setState(Elm.FIN_WAIT_2); ! int resendtimes[] = {75000,-3}; // non-RFC exit ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes); } else if(inPacket.get_FIN_flag()){ Elm.setState(Elm.CLOSING); - int resendtimes[] = {}; boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); ! int resendtimes2[] = {75000, -3}; // synchronous closing ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes2); } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! //normal data processing } else --- 811,824 ---- else if(inPacket.get_ACK_flag()){ Elm.setState(Elm.FIN_WAIT_2); ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_EXIT); } else if(inPacket.get_FIN_flag()){ Elm.setState(Elm.CLOSING); boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_SYNC_CLOSE); } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! processSegment(Elm, inPacket); } else *************** *** 804,814 **** if(inPacket.get_FIN_flag()){ Elm.setState(Elm.TIME_WAIT); - int resendtimes[] = {}; boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); removeTimer(Elm.last_timer); if(USE_2MSL){ ! int resendtimes2[] = {2*MSL_TIME, -3}; // 2MSL ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes2); } else{ --- 830,838 ---- if(inPacket.get_FIN_flag()){ Elm.setState(Elm.TIME_WAIT); boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes_NULL); removeTimer(Elm.last_timer); if(USE_2MSL){ ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_2MSL); } else{ *************** *** 818,822 **** } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! //normal data processing } else --- 842,846 ---- } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! processSegment(Elm, inPacket); } else *************** *** 830,835 **** removeTimer(Elm.last_timer); if(USE_2MSL){ ! int resendtimes2[] = {2*MSL_TIME, -3}; // 2MSL ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes2); } else{ --- 854,858 ---- removeTimer(Elm.last_timer); if(USE_2MSL){ ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes_2MSL); } else{ *************** *** 844,863 **** private void recv_TIME_WAIT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(false){ ! } ! else ! throw new TransportLayerException("TCP: recv_TIME_WAIT: unexpected packet"); } ! private void passUpstairs(TCP_session Elm, String data){ ! } - - - - - - private long createTimer(int sock, TCP_packet pack, int times[]){ Resender rsnd = new Resender(sock,pack,times); --- 867,890 ---- private void recv_TIME_WAIT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! throw new TransportLayerException("TCP: recv_TIME_WAIT: unexpected packet"); } ! private void processSegment(TCP_session Elm, TCP_packet packet) throws LowLinkException, TransportLayerException, CommunicationException ! { ! Elm.addReceivedSegment(packet); ! String out = ""; ! int readySegments = 0; ! while(Elm.hasNextReceivedSegment()){ ! TCP_packet tcpp = Elm.getNextReceivedSegment(); ! out += tcpp.getTCP_message(); ! readySegments = tcpp.get_sequence_number(); ! } ! if(readySegments>0){ ! boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, readySegments+1, resendtimes_NULL); ! mSL.recv(Elm.getSocket(), out); ! } } private long createTimer(int sock, TCP_packet pack, int times[]){ Resender rsnd = new Resender(sock,pack,times); *************** *** 1089,1182 **** Simulation.addLayerInfo(protInfo); } ! ! ! ! ! ! ! ! ! /** ! ****************************************************************** ! * ! * Below code was created by gift and not checked yet ! * ! ****************************************************************** ! **/ ! ! ! // ! // /** ! // * This method sends to application all consequent segments from OutputBuffer ! // * @author gift (sourceforge.net user) ! // * @param listener target application ! // * @param Elm TCP_Hashtable contains necessary info ! // * @return Nothing. ! // * @exception LowLinkException ! // * @exception TransportLayerException ! // * @version v0.20 ! // * @see LowLinkException ! // * @see TransportLayerException ! // */ ! // private void PassUpstairs(Application listener, TCP_HashTableElement Elm) throws LowLinkException, TransportLayerException { ! // Integer kkey=Elm.last_passed+1;//=new Integer(Elm.last_passed+1); ! // ! //// System.out.println(" [*** TCP ***] Pass upstairs call."); ! //// System.out.println(" [*** TCP ***] Last passed: " + Elm.last_passed + ", going to pass: " + kkey + "."); ! //// ! //// System.out.println(" [*** TCP ***] Buffer isEmpty: " + Elm.OutputBuffer.isEmpty() + "."); ! //// System.out.println(" [*** TCP ***] While condition: " + Elm.OutputBuffer.containsKey(kkey) + "."); ! //// ! // while(Elm.OutputBuffer.containsKey(kkey)) { ! // Elm.last_passed=kkey; ! // TCP_packet Packet=(TCP_packet) Elm.OutputBuffer.remove(kkey); ! // kkey++; ! // ! // if((!Packet.get_ACK_flag()) && (!Packet.get_SYN_flag()) && (!Packet.get_FIN_flag())) ! // { ! // //if(!Packet.get_ACK_flag()) ! // listener.RecvData(Packet.getTCP_message()); ! // // System.out.println(" [*** TCP ***] [*P*] Passed packet SEQ: " + Packet.get_sequence_number() + ", packet destination: " + Packet.getDestIPAddress() + "."); ! // } else ! // { ! // // System.out.println(" [*** TCP ***] [S] Skipped packet SEQ: " + Packet.get_sequence_number() + ", packet destination: " + Packet.getDestIPAddress() + "."); ! // } ! // } ! // ! //// System.out.println(" [*** TCP ***] Pass upstairs end of call."); ! // } ! // ! // /** ! // * This adds segment to OutputBuffer ! // * @author gift (sourceforge.net user) ! // * @param Elm TCP_Hashtable contains necessary info ! // * @param Packet TCP_packet which clone has to be stored in OutputBuffer ! // * @return Nothing. ! // * @exception TransportLayerException ! // * @version v0.20 ! // * @see TransportLayerException ! // */ ! // private void AddOutputBuffer(TCP_HashTableElement Elm, TCP_packet Packet) throws TransportLayerException { ! // if (Elm.OutputBuffer.size()==2000) { ! // throw new TransportLayerException("TCP Error: maximum buffer size reached! Can not keep on receiving TCP segments. Bad connection to: " + Elm.connectedtoIP + ":" + Elm.connectedtoPort + "."); ! // } else { ! // TCP_packet to_buff=new TCP_packet(Packet.getDestIPAddress(), Packet.getSourceIPAddress(), Packet.get_destPort(), Packet.get_srcPort()); ! // try { ! // to_buff.setTCP_message(Packet.getTCP_message()); ! // } catch(TransportLayerException e) {} //will never be thrown from here ;) ! // ! // to_buff.set_sequence_number(Packet.get_sequence_number()); ! // to_buff.set_acknowledgment_number(Packet.get_acknowledgment_number()); ! // ! // to_buff.set_URG_flag(Packet.get_URG_flag()); ! // to_buff.set_ACK_flag(Packet.get_ACK_flag()); ! // to_buff.set_PSH_flag(Packet.get_PSH_flag()); ! // to_buff.set_RST_flag(Packet.get_RST_flag()); ! // to_buff.set_SYN_flag(Packet.get_SYN_flag()); ! // to_buff.set_FIN_flag(Packet.get_FIN_flag()); ! // ! // Elm.OutputBuffer.put(new Integer(Packet.get_sequence_number()), to_buff); ! // } ! // } ! // ! } //EOF --- 1116,1118 ---- Simulation.addLayerInfo(protInfo); } ! } Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Echo_tcp.java 23 Sep 2007 22:12:23 -0000 1.35 --- Echo_tcp.java 25 Sep 2007 22:34:09 -0000 1.36 *************** *** 31,35 **** public int recieved; - private int sock; private Vector<Integer> connections = new Vector<Integer>(0); --- 31,34 ---- *************** *** 38,42 **** super(inParentStack, listenPort, appType, UID); counts = 0; ! sock = mParentStack.SL().socket(jnSocket.TCP_socket, this); } --- 37,41 ---- super(inParentStack, listenPort, appType, UID); counts = 0; ! appSock = mParentStack.SL().socket(jnSocket.TCP_socket, this); } *************** *** 51,56 **** try{ if(appType == 1){ ! mParentStack.SL().bind(sock, mParentStack.getSrcIP(), listenPort); ! mParentStack.SL().listen(sock); } }catch (TransportLayerException e){ --- 50,55 ---- try{ if(appType == 1){ ! mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), listenPort); ! mParentStack.SL().listen(appSock); } }catch (TransportLayerException e){ *************** *** 59,63 **** } ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ connections.add(new Integer(sessionSock)); System.out.println("Accepted socket="+sessionSock+" for listen socket="+listenSock); --- 58,62 ---- } ! public void Accept(int listenSock, int sessionSock){ connections.add(new Integer(sessionSock)); System.out.println("Accepted socket="+sessionSock+" for listen socket="+listenSock); *************** *** 73,77 **** public void Close() throws TransportLayerException { ! mParentStack.SL().close(sock); for(int i=0; i<connections.size(); i++){ mParentStack.SL().close(connections.get(i).intValue()); --- 72,76 ---- public void Close() throws TransportLayerException { ! mParentStack.SL().close(appSock); for(int i=0; i<connections.size(); i++){ mParentStack.SL().close(connections.get(i).intValue()); *************** *** 82,86 **** public void Free() throws TransportLayerException{ Close(); ! mParentStack.SL().free(sock); for(int i=0; i<connections.size(); i++){ mParentStack.SL().free(connections.get(i).intValue()); --- 81,85 ---- public void Free() throws TransportLayerException{ Close(); ! mParentStack.SL().free(appSock); for(int i=0; i<connections.size(); i++){ mParentStack.SL().free(connections.get(i).intValue()); *************** *** 101,105 **** printLayerInfo("Connecting to host " + Host + ":"+ port +". Please wait..."); ! boolean isconnected = mParentStack.SL().connect(sock, Host, port); return isconnected; --- 100,104 ---- printLayerInfo("Connecting to host " + Host + ":"+ port +". Please wait..."); ! boolean isconnected = mParentStack.SL().connect(appSock, Host, port); return isconnected; *************** *** 118,123 **** printLayerInfo("Start sending echo message '" + data + "' to " + mParentStack.SL().get_socket(sock).dst_IP + ":" + mParentStack.SL().get_socket(sock).dst_port); this.counts--; ! //SendData(Data); ! mParentStack.TCP().disconnect(sock); } }catch(LowLinkException e){ --- 117,122 ---- printLayerInfo("Start sending echo message '" + data + "' to " + mParentStack.SL().get_socket(sock).dst_IP + ":" + mParentStack.SL().get_socket(sock).dst_port); this.counts--; ! SendData(data); ! //mParentStack.TCP().disconnect(sock); } }catch(LowLinkException e){ *************** *** 138,141 **** --- 137,141 ---- public void OnDisconnect(int sock) { System.out.println("ECHO_TCP: Disconnected "+sock+" !"); + printLayerInfo("Disconnected"); try{ if(appType == 1){ *************** *** 169,173 **** */ ! public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { mParentStack.SL().write(sock, Data); --- 169,173 ---- */ ! public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { mParentStack.SL().write(sock, Data); *************** *** 184,188 **** * @version v0.02 */ ! public void RecvData(String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. recieved++; --- 184,188 ---- * @version v0.02 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. recieved++; *************** *** 201,204 **** --- 201,209 ---- if(this.counts==0){ printLayerInfo("Connection time: " + (long)(System.currentTimeMillis () - utc1) + " ms. Total recieved messages: " + recieved + "."); + try{ + mParentStack.TCP().disconnect(sock); + }catch(CommunicationException e){ + System.out.println(e.toString()); + } }else{ this.counts--; *************** *** 206,212 **** printLayerInfo("Sending echo message '" + Data + "' to server..."); SendData(Data); ! }catch(Exception e){ ! Error.Report(e); ! ///*TODO*: here to catch } } --- 211,220 ---- printLayerInfo("Sending echo message '" + Data + "' to server..."); SendData(Data); ! }catch(LowLinkException e){ ! System.out.println(e.toString()); ! }catch(TransportLayerException e){ ! System.out.println(e.toString()); ! }catch(CommunicationException e){ ! System.out.println(e.toString()); } } *************** *** 220,224 **** try { ! SendData(Data); }catch(CommunicationException e){ System.out.println(e.toString()); --- 228,232 ---- try { ! SendData(sock, Data); }catch(CommunicationException e){ System.out.println(e.toString()); *************** *** 239,249 **** public void SendEcho(String Data, String Host, int port, int counts) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ recieved = 0; - - utc1 = System.currentTimeMillis (); if (Connect(Host, port)){ - this.counts = counts; - this.data = Data; } else{ --- 247,255 ---- public void SendEcho(String Data, String Host, int port, int counts) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ recieved = 0; utc1 = System.currentTimeMillis (); + this.counts = counts; + this.data = Data; if (Connect(Host, port)){ } else{ Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Application.java 23 Sep 2007 20:24:43 -0000 1.20 --- Application.java 25 Sep 2007 22:34:09 -0000 1.21 *************** *** 27,30 **** --- 27,31 ---- protected int sdPort; protected int appType; + protected int appSock; protected int UID; *************** *** 46,50 **** public abstract void Listen() throws TransportLayerException; ! public abstract void Accept(int listenSock, int sessionSock) throws TransportLayerException; /** --- 47,51 ---- public abstract void Listen() throws TransportLayerException; ! public abstract void Accept(int listenSock, int sessionSock); /** *************** *** 88,92 **** */ ! public abstract void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException; /** --- 89,99 ---- */ ! public abstract void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException; ! ! ! public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException ! { ! SendData(appSock, Data); ! } /** *************** *** 96,100 **** * @version v0.01 */ ! public abstract void RecvData(String Data) throws LowLinkException, TransportLayerException; --- 103,107 ---- * @version v0.01 */ ! public abstract void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException; Index: TCP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_session.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TCP_session.java 23 Sep 2007 22:12:23 -0000 1.6 --- TCP_session.java 25 Sep 2007 22:34:09 -0000 1.7 *************** *** 11,14 **** --- 11,16 ---- import java.util.Hashtable; + import java.util.PriorityQueue; + import java.util.Iterator; /** *************** *** 18,21 **** --- 20,39 ---- public class TCP_session extends jnSession{ + public class TCPPacketTimesPair implements Comparable{ + public TCP_packet packet; + public int resendtimes[]; + + public TCPPacketTimesPair(TCP_packet pack, int times[]){ + packet = pack; + resendtimes = new int[times.length]; + for(int i=0; i<times.length; i++) + resendtimes[i] = times[i]; + } + + public int compareTo(Object o){ + return packet.compareTo(((TCPPacketTimesPair)o).packet); + } + } + private int window_size=10; //2000; //25 *************** *** 28,32 **** /*end of statistic block*/ ! public int seq_number=0; private int last_ack_number=0; //last sequence number value of the segment that has been passed upstairs private int state = CLOSED; --- 46,51 ---- /*end of statistic block*/ ! public int seq_number = 0; ! private int next_pass_seq_num = -1; private int last_ack_number=0; //last sequence number value of the segment that has been passed upstairs private int state = CLOSED; *************** *** 53,56 **** --- 72,79 ---- private Hashtable segmentsToResend = new Hashtable(); + private PriorityQueue receivedSegments = new PriorityQueue(); + + private PriorityQueue sendingSegments = new PriorityQueue(); + /** *************** *** 148,151 **** --- 171,244 ---- } + /** + * Pop expected segment from buffer + * @result null if expected segment have not received yet + */ + public TCP_packet getNextReceivedSegment(){ + TCP_packet result = null; + if(!receivedSegments.isEmpty() && ((TCP_packet)receivedSegments.peek()).get_sequence_number() == next_pass_seq_num){ + result = (TCP_packet)receivedSegments.poll(); + next_pass_seq_num++; + } + return result; + } + + public boolean hasNextReceivedSegment(){ + boolean result = false; + if(!receivedSegments.isEmpty() && ((TCP_packet)receivedSegments.peek()).get_sequence_number() == next_pass_seq_num){ + result = true; + } + return result; + } + + /** + * + * @result true if segment have been added in buffer, false if segment have been already contained in buffer + */ + public boolean addReceivedSegment(TCP_packet pack){ + boolean Found = false; + if(pack.get_sequence_number() >= next_pass_seq_num){ + Iterator<TCP_packet> it = receivedSegments.iterator(); + while(it.hasNext() && !Found){ + TCP_packet p = it.next(); + Found = p.get_sequence_number() == pack.get_sequence_number(); + } + if(!Found){ + receivedSegments.add(pack); + if(next_pass_seq_num == -1) next_pass_seq_num = pack.get_sequence_number(); + } + } + return !Found; + } + + /** + * Pop expected segment from buffer + * @result null if expected segment have not received yet + */ + public TCPPacketTimesPair getNextSendingSegment(){ + TCPPacketTimesPair result = null; + if(!sendingSegments.isEmpty() && ((TCPPacketTimesPair)sendingSegments.peek()).packet.get_sequence_number() < getLastACK()+getWindowSize()){ + result = (TCPPacketTimesPair)sendingSegments.poll(); + } + return result; + } + + public boolean hasNextSendingSegment(){ + boolean result = false; + if(!sendingSegments.isEmpty() && ((TCPPacketTimesPair)sendingSegments.peek()).packet.get_sequence_number() < getLastACK()+getWindowSize()){ + result = true; + } + return result; + } + + /** + * + * @result true if segment have been added in buffer, false if segment have been already contained in buffer + */ + public boolean addSendingSegment(TCP_packet pack, int resendtimes[]){ + sendingSegments.add(new TCPPacketTimesPair(pack, resendtimes)); + return true; + } + public int getState(){ return state; *************** *** 168,171 **** --- 261,272 ---- } + public int getWindowSize(){ + return window_size; + } + + public void setWindowSize(int windowSize){ + window_size = windowSize>0 ? windowSize : 0; + } + public void inc_received_segments(){ received_segments++; Index: Echo.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Echo.java 23 Sep 2007 20:24:43 -0000 1.26 --- Echo.java 25 Sep 2007 22:34:09 -0000 1.27 *************** *** 30,39 **** long utc1; public int recieved; - int sock; /** Creates a new instance of Echo */ public Echo(ProtocolStack inParentStack, int listenPort, int appType, int UID) { super(inParentStack, listenPort, appType, UID); ! sock = mParentStack.SL().socket(jnSocket.UDP_socket, this); int fake = 0; } --- 30,38 ---- long utc1; public int recieved; /** Creates a new instance of Echo */ public Echo(ProtocolStack inParentStack, int listenPort, int appType, int UID) { super(inParentStack, listenPort, appType, UID); ! appSock = mParentStack.SL().socket(jnSocket.UDP_socket, this); int fake = 0; } *************** *** 47,51 **** // try{ ! mParentStack.SL().bind(sock, mParentStack.getSrcIP(), listenPort); printLayerInfo("Echo app", "Echo server starts listening in port " + listenPort + "."); } catch (Exception e) --- 46,50 ---- // try{ ! mParentStack.SL().bind(appSock, mParentStack.getSrcIP(), listenPort); printLayerInfo("Echo app", "Echo server starts listening in port " + listenPort + "."); } catch (Exception e) *************** *** 57,61 **** ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ } --- 56,60 ---- ! public void Accept(int listenSock, int sessionSock){ } *************** *** 71,75 **** { printLayerInfo("Echo app", "Echo app closed socket."); ! mParentStack.SL().close(sock); } --- 70,74 ---- { printLayerInfo("Echo app", "Echo app closed socket."); ! mParentStack.SL().close(appSock); } *************** *** 77,81 **** { printLayerInfo("Echo app", "Echo app freed socket."); ! mParentStack.SL().free(sock); } --- 76,80 ---- { printLayerInfo("Echo app", "Echo app freed socket."); ! mParentStack.SL().free(appSock); } *************** *** 129,133 **** */ ! public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); --- 128,132 ---- */ ! public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); *************** *** 144,148 **** * @version v0.01 */ ! public void RecvData(String Data) throws LowLinkException, TransportLayerException { recieved++; //processing the protocol doings. --- 143,147 ---- * @version v0.01 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { recieved++; //processing the protocol doings. Index: ExternalProxyApp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ExternalProxyApp.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ExternalProxyApp.java 23 Sep 2007 20:24:43 -0000 1.4 --- ExternalProxyApp.java 25 Sep 2007 22:34:09 -0000 1.5 *************** *** 88,92 **** } ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ } --- 88,92 ---- } ! public void Accept(int listenSock, int sessionSock){ } *************** *** 230,234 **** */ ! public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { --- 230,234 ---- */ ! public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { *************** *** 247,251 **** * @version v0.02 */ ! public void RecvData(String Data) throws LowLinkException, TransportLayerException { --- 247,251 ---- * @version v0.02 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { Index: SNMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/SNMP.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** SNMP.java 23 Sep 2007 20:24:43 -0000 1.19 --- SNMP.java 25 Sep 2007 22:34:09 -0000 1.20 *************** *** 150,154 **** } ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ //do nothing, UDP application } --- 150,154 ---- } ! public void Accept(int listenSock, int sessionSock){ //do nothing, UDP application } *************** *** 245,249 **** * @version v0.01 */ ! public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { //mParentStack.sendUDP(this, Data); mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); --- 245,249 ---- * @version v0.01 */ ! public void SendData(int sock, String Data) throws LowLinkException, TransportLayerException, CommunicationException { //mParentStack.sendUDP(this, Data); mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); *************** *** 256,260 **** * @version v0.01 */ ! public void RecvData(String Data) throws LowLinkException, TransportLayerException { //appType = 0 - agent //appType = 1 - network management systems --- 256,260 ---- * @version v0.01 */ ! public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException { //appType = 0 - agent //appType = 1 - network management systems |
From: QweR <qw...@us...> - 2007-09-23 22:12:26
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6626/core/protocolsuite/tcp_ip Modified Files: Echo_tcp.java TCP_session.java Tcp.java socketLayer.java Log Message: function 'listen' was added in TCP & socketLayer removed some useless variables & functions Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** Tcp.java 23 Sep 2007 20:24:43 -0000 1.93 --- Tcp.java 23 Sep 2007 22:12:23 -0000 1.94 *************** *** 94,98 **** private TCP_packet packet; private int sock; ! private int first_resend; public long timerID; --- 94,98 ---- private TCP_packet packet; private int sock; ! private int nearest_resend; public long timerID; [...1186 lines suppressed...] - // tosend_clone.set_RST_flag(flags[3]); - // tosend_clone.set_SYN_flag(flags[4]); - // tosend_clone.set_FIN_flag(flags[5]); - // - // //here we push out segment in Hashtable SegmentsToResend and increment counters - // s_num=Elm.seq_number; //getting sequence number 0-for SYN - // if (Elm.ReceivedSegments.isEmpty()) a_num=0; else a_num=acknow_num; //(Integer)Elm.ReceivedSegments.lastElement()+1; //getting ACK number 0 - for SYN, 1 - as a reply for SYN ... so on - // - // tosend_clone.set_sequence_number(s_num); - // tosend_clone.set_acknowledgment_number(a_num); - // - // Elm=null; - // - // return tosend_clone; - // } - // - // // /** // * This method sends to application all consequent segments from OutputBuffer --- 1104,1110 ---- Index: TCP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_session.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TCP_session.java 23 Sep 2007 20:24:43 -0000 1.5 --- TCP_session.java 23 Sep 2007 22:12:23 -0000 1.6 *************** *** 30,34 **** public int seq_number=0; private int last_ack_number=0; //last sequence number value of the segment that has been passed upstairs - public static int Element_id = 0; private int state = CLOSED; public long last_timer = -1; --- 30,33 ---- *************** *** 199,209 **** return sent_duplicates; } - public void ResetCounters(){ - received_segments = 0; - sent_segments = 0; - sent_ACK = 0; - received_duplicates = 0; - sent_duplicates = 0; - } } --- 198,201 ---- Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** socketLayer.java 23 Sep 2007 20:24:43 -0000 1.5 --- socketLayer.java 23 Sep 2007 22:12:23 -0000 1.6 *************** *** 52,55 **** --- 52,67 ---- } + public void listen(int sock) throws TransportLayerException{ + jnSocket jnsock = get_socket(sock); + //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! + jnsock.open_state = true; //bind or connect or listen + if(jnsock.type == jnsock.UDP_socket){ + //mParentStack.UDP().bindPort(sock, srcPort); + } + else if(jnsock.type == jnsock.TCP_socket){ + mParentStack.TCP().listen(sock); + } + } + public boolean connect(int sock, String ipaddr, int port) throws LowLinkException, CommunicationException, TransportLayerException{ boolean result = false; Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** Echo_tcp.java 23 Sep 2007 20:24:43 -0000 1.34 --- Echo_tcp.java 23 Sep 2007 22:12:23 -0000 1.35 *************** *** 52,56 **** if(appType == 1){ mParentStack.SL().bind(sock, mParentStack.getSrcIP(), listenPort); ! } }catch (TransportLayerException e){ System.out.println(e.toString());; --- 52,57 ---- if(appType == 1){ mParentStack.SL().bind(sock, mParentStack.getSrcIP(), listenPort); ! mParentStack.SL().listen(sock); ! } }catch (TransportLayerException e){ System.out.println(e.toString());; |
From: QweR <qw...@us...> - 2007-09-23 20:24:48
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22036/core/protocolsuite/tcp_ip Modified Files: Application.java Echo.java Echo_tcp.java ExternalProxyApp.java PosixTelnetClient.java SNMP.java TCP_session.java Tcp.java Telnet_client.java Telnet_server.java socketLayer.java Log Message: opening/closing TCP connection works on good line Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Telnet_client.java 22 Sep 2007 23:06:44 -0000 1.11 --- Telnet_client.java 23 Sep 2007 20:24:43 -0000 1.12 *************** *** 139,143 **** } ! public void OnError(int sock){ } --- 139,143 ---- } ! public void OnError(int sock, int error){ } Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** socketLayer.java 22 Sep 2007 23:06:45 -0000 1.4 --- socketLayer.java 23 Sep 2007 20:24:43 -0000 1.5 *************** *** 37,41 **** } ! public void bind(int sock, String srcIP, int srcPort) throws LowLinkException, TransportLayerException{ jnSocket jnsock = get_socket(sock); jnsock.src_IP = srcIP; --- 37,41 ---- } ! public void bind(int sock, String srcIP, int srcPort) throws TransportLayerException{ jnSocket jnsock = get_socket(sock); jnsock.src_IP = srcIP; *************** *** 52,66 **** } - public void listen(int sock) throws TransportLayerException{ - jnSocket jnsock = get_socket(sock); - jnsock.open_state = true; - if(jnsock.type == jnsock.UDP_socket){ - mParentStack.UDP().bindPort(sock, jnsock.src_port); - } - else if(jnsock.type == jnsock.TCP_socket){ - mParentStack.TCP().bindPort(sock, jnsock.src_port); - } - } - public boolean connect(int sock, String ipaddr, int port) throws LowLinkException, CommunicationException, TransportLayerException{ boolean result = false; --- 52,55 ---- *************** *** 147,152 **** } public void free(int sock) throws TransportLayerException{ ! ((jnSocket)sockTable.get(sock)).app = null; ! ((jnSocket)sockTable.get(sock)).open_state = false; } } --- 136,150 ---- } public void free(int sock) throws TransportLayerException{ ! jnSocket jnsock = (jnSocket)sockTable.get(sock); ! jnsock.app = null; ! jnsock.open_state = false; ! if(jnsock.type == jnsock.UDP_socket){ ! mParentStack.UDP().closePort(sock); ! } ! else if(jnsock.type == jnsock.TCP_socket){ ! mParentStack.TCP().closePort(sock); ! } ! jnsock.src_port = 0; ! jnsock.src_IP = ""; } } Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Telnet_server.java 22 Sep 2007 23:06:44 -0000 1.13 --- Telnet_server.java 23 Sep 2007 20:24:43 -0000 1.14 *************** *** 133,137 **** } ! public void OnError(int sock){ } --- 133,137 ---- } ! public void OnError(int sock, int error){ } Index: PosixTelnetClient.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/PosixTelnetClient.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PosixTelnetClient.java 22 Sep 2007 23:06:42 -0000 1.3 --- PosixTelnetClient.java 23 Sep 2007 20:24:43 -0000 1.4 *************** *** 144,148 **** } ! public void OnError(int sock){ } --- 144,148 ---- } ! public void OnError(int sock, int error){ } Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -d -r1.92 -r1.93 *** Tcp.java 23 Sep 2007 01:49:58 -0000 1.92 --- Tcp.java 23 Sep 2007 20:24:43 -0000 1.93 *************** *** 118,124 **** mParentStack.sendPacket(packet); }catch(LowLinkException e){ ! e.toString(); }catch(CommunicationException e){ ! e.toString(); } } --- 118,124 ---- mParentStack.sendPacket(packet); }catch(LowLinkException e){ ! System.out.println(e.toString()); }catch(CommunicationException e){ ! System.out.println(e.toString()); } } *************** *** 138,164 **** mParentStack.sendPacket(rstpack); }catch(TransportLayerException e){ ! e.toString(); }catch(LowLinkException e){ ! e.toString(); }catch(CommunicationException e){ ! e.toString(); } // close seession try{ mSL.close(sock); }catch(TransportLayerException e){ ! e.toString(); } break; } case -2:{ ! mSL.get_socket(sock).app.OnError(sock); break; } case -3:{ try{ mSL.close(sock); }catch(TransportLayerException e){ ! e.toString(); } } --- 138,167 ---- mParentStack.sendPacket(rstpack); }catch(TransportLayerException e){ ! System.out.println(e.toString()); }catch(LowLinkException e){ ! System.out.println(e.toString()); }catch(CommunicationException e){ ! System.out.println(e.toString()); } // close seession try{ mSL.close(sock); + mSL.get_socket(sock).app.OnError(sock, -2); //disconnect on timeout, sending RST }catch(TransportLayerException e){ ! System.out.println(e.toString()); } break; } case -2:{ ! mSL.get_socket(sock).app.OnError(sock, -1); //connect error break; } case -3:{ try{ + removeTimer(getSession(mSL.get_socket(sock).genKey()).last_timer); + mSL.get_socket(sock).app.OnDisconnect(sock); mSL.close(sock); }catch(TransportLayerException e){ ! System.out.println(e.toString()); } } *************** *** 209,212 **** --- 212,217 ---- private int current_time = 0; private long nextTimerID = 0; + private static final boolean USE_2MSL = false; + private static final int MSL_TIME = 5000; *************** *** 262,266 **** mSL = inSL; timer=new Timer(); ! timer.schedule(new TCPTask(),TCP_TIMER_DELAY,TCP_TIMER_DELAY); } --- 267,271 ---- mSL = inSL; timer=new Timer(); ! //timer.schedule(new TCPTask(),TCP_TIMER_DELAY,TCP_TIMER_DELAY); } *************** *** 293,297 **** sessionID = (String)LocalSessions.nextElement(); Elm = getSession(sessionID); ! if ( sock == Elm.sock && Elm.sock >=0 ) { Found=true; --- 298,302 ---- sessionID = (String)LocalSessions.nextElement(); Elm = getSession(sessionID); ! if ( sock == Elm.sock && mSL.get_socket(Elm.sock).open_state ) { Found=true; *************** *** 334,338 **** int lsPort=PORT_INIT; ! if ( mSL.get_socket(sock_num).src_port == 0 ) { if (in_Port>0 && in_Port<=65535){ --- 339,343 ---- int lsPort=PORT_INIT; ! if( mSL.get_socket(sock_num).src_port == 0 ) { if (in_Port>0 && in_Port<=65535){ *************** *** 388,392 **** if (sendTCPSegment(sock, "", flags, -1, resendtimes)) { ! } else{ --- 393,397 ---- if (sendTCPSegment(sock, "", flags, -1, resendtimes)) { ! connected = true; } else{ *************** *** 423,427 **** if(Elm != null){ Elm.setState(Elm.FIN_WAIT_1); - mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); int resendtimes[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; boolean flags[] = genFlags(FIN); --- 428,431 ---- *************** *** 447,452 **** int portToClose=mSL.get_socket(sock).src_port; TCP_session Elm = getSession(mSL.get_socket(sock).genKey()); ! if(portToClose!=0 && Elm!=null){ removeSession(mSL.get_socket(sock).genKey()); mSL.close(Elm.sock); --- 451,460 ---- int portToClose=mSL.get_socket(sock).src_port; TCP_session Elm = getSession(mSL.get_socket(sock).genKey()); ! if(portToClose!=0 && Elm!=null){ + TCP_session mainses = getSession(jnSocket.genTCPkey(portToClose,"0.0.0.0",0)); + if(mainses != null && mainses.getSocket() == sock){ // remove listening session on client size only + removeSession(jnSocket.genTCPkey(portToClose,"0.0.0.0",0)); + } removeSession(mSL.get_socket(sock).genKey()); mSL.close(Elm.sock); *************** *** 495,498 **** --- 503,514 ---- Elm.addSegmentToResend(tosend.get_sequence_number(),tid); } + + String pack_src = tosend.getSourceIPAddress()+":"+tosend.get_srcPort(); + String pack_dst = tosend.getDestIPAddress()+":"+tosend.get_destPort(); + String pack_flags = (tosend.get_ACK_flag()?"ACK,":"")+(tosend.get_SYN_flag()?"SYN,":"")+(tosend.get_FIN_flag()?"FIN,":"")+(tosend.get_RST_flag()?"RST":""); + System.out.println("|| <<< TCP send pack: src="+pack_src+" dst="+pack_dst+" flags="+pack_flags+" seq="+tosend.get_sequence_number()+" ack="+tosend.get_acknowledgment_number()+" data='"+tosend.getTCP_message()+"'"); + + System.out.println("|| <<<< Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+sock+" state="+Elm.getState()); + mParentStack.sendPacket(tosend); return true; *************** *** 521,527 **** int dstPort = jnsock.dst_port; TCP_session Elm = getSession(jnsock.genKey()); - - System.out.println(" [*** TCP ***] GetTCPPacket_tosend call on host " + srcIP + "."); - System.out.println(" [*** TCP ***] Going to send SEQ=" + Elm.seq_number + " ACK=" + acknow_num + "."); int reps=50; --- 537,540 ---- *************** *** 580,585 **** // Simulation.addLayerInfo(TCP_Info); - System.out.println(" [*** TCP ***] GetTCPPacket_tosend end of call on host " + srcIP + "."); - return tosend; } --- 593,596 ---- *************** *** 593,597 **** // test if this packet is for a local Address. if(mParentStack.isInternalIP(inPacket.getDestIPAddress())){ ! // test if TCP sesssion exists on this NeworkLayerDevice TCP_session Elm; --- 604,613 ---- // test if this packet is for a local Address. if(mParentStack.isInternalIP(inPacket.getDestIPAddress())){ ! ! String pack_src = inPacket.getSourceIPAddress()+":"+inPacket.get_srcPort(); ! String pack_dst = inPacket.getDestIPAddress()+":"+inPacket.get_destPort(); ! String pack_flags = (inPacket.get_ACK_flag()?"ACK,":"")+(inPacket.get_SYN_flag()?"SYN,":"")+(inPacket.get_FIN_flag()?"FIN,":"")+(inPacket.get_RST_flag()?"RST":""); ! System.out.println("|| >>> TCP recv pack: src="+pack_src+" dst="+pack_dst+" flags="+pack_flags+" seq="+inPacket.get_sequence_number()+" ack="+inPacket.get_acknowledgment_number()+" data='"+inPacket.getTCP_message()+"'"); ! // test if TCP sesssion exists on this NeworkLayerDevice TCP_session Elm; *************** *** 599,604 **** if(Elm == null && inPacket.get_SYN_flag()){ Elm = getSession(jnSocket.genTCPkey(inPacket.get_destPort(), "0.0.0.0", 0)); - int listensock = Elm.getSocket(); if(Elm != null){ int sock = mSL.accept(Elm.getSocket(), inPacket.getSourceIPAddress(), inPacket.get_srcPort()); jnSocket jnsock = mSL.get_socket(sock); --- 615,620 ---- if(Elm == null && inPacket.get_SYN_flag()){ Elm = getSession(jnSocket.genTCPkey(inPacket.get_destPort(), "0.0.0.0", 0)); if(Elm != null){ + int listensock = Elm.getSocket(); int sock = mSL.accept(Elm.getSocket(), inPacket.getSourceIPAddress(), inPacket.get_srcPort()); jnSocket jnsock = mSL.get_socket(sock); *************** *** 618,624 **** --- 634,642 ---- } if(inPacket.get_RST_flag()){ + mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } else{ + System.out.println("|| >>>> Host="+mParentStack.getHostName()+" IP="+mParentStack.getSrcIP()+" sock="+Elm.getSocket()+" state="+Elm.getState()); printLayerInfo("TCP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getTCP_message() + "\"."); *************** *** 654,658 **** { // hm... it is bug! ! throw new TransportLayerException("Session exists, but port "+ mSL.get_socket(Elm.getSocket()).dst_port +" not binded!"); } --- 672,676 ---- { // hm... it is bug! ! throw new TransportLayerException("Session exists, but port "+ mSL.get_socket(Elm.getSocket()).dst_port +" not binded! It is scary bug!"); } *************** *** 676,680 **** boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); ! mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); } else --- 694,700 ---- boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); ! //mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); ! jnSocket jns = mSL.get_socket(Elm.getSocket()); ! jns.app.OnConnect(Elm.getSocket()); } else *************** *** 699,706 **** boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes1); - mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); Elm.setState(Elm.LAST_ACK); - mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); int resendtimes2[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; //to resend or not to resend ? flags = genFlags(FIN); --- 719,724 ---- *************** *** 725,728 **** --- 743,747 ---- { if(inPacket.get_ACK_flag()){ + mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); mSL.close(Elm.getSocket()); } *************** *** 740,759 **** if(inPacket.get_ACK_flag() && inPacket.get_FIN_flag()){ Elm.setState(Elm.TIME_WAIT); - mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); int resendtimes[] = {}; boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); } else if(inPacket.get_ACK_flag()){ Elm.setState(Elm.FIN_WAIT_2); ! int resendtimes[] = {75000,-3}; ! Elm.fin_wait_2_timer = createTimer(Elm.getSocket(), null, resendtimes); } else if(inPacket.get_FIN_flag()){ Elm.setState(Elm.CLOSING); - mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); int resendtimes[] = {}; boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ --- 759,786 ---- if(inPacket.get_ACK_flag() && inPacket.get_FIN_flag()){ Elm.setState(Elm.TIME_WAIT); int resendtimes[] = {}; boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); + if(USE_2MSL){ + int resendtimes2[] = {2*MSL_TIME,-3}; // 2MSL + Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes2); + } + else{ + mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); + mSL.close(Elm.getSocket()); + } } else if(inPacket.get_ACK_flag()){ Elm.setState(Elm.FIN_WAIT_2); ! int resendtimes[] = {75000,-3}; // non-RFC exit ! Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes); } else if(inPacket.get_FIN_flag()){ Elm.setState(Elm.CLOSING); int resendtimes[] = {}; boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); + int resendtimes2[] = {75000, -3}; // synchronous closing + Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes2); } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ *************** *** 767,775 **** { if(inPacket.get_FIN_flag()){ ! Elm.setState(Elm.CLOSING); int resendtimes[] = {}; boolean flags[] = genFlags(ACK); - mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ --- 794,810 ---- { if(inPacket.get_FIN_flag()){ ! Elm.setState(Elm.TIME_WAIT); int resendtimes[] = {}; boolean flags[] = genFlags(ACK); sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); + removeTimer(Elm.last_timer); + if(USE_2MSL){ + int resendtimes2[] = {2*MSL_TIME, -3}; // 2MSL + Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes2); + } + else{ + mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); + mSL.close(Elm.getSocket()); + } } else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ *************** *** 784,787 **** --- 819,831 ---- if(inPacket.get_ACK_flag()){ Elm.setState(Elm.TIME_WAIT); + removeTimer(Elm.last_timer); + if(USE_2MSL){ + int resendtimes2[] = {2*MSL_TIME, -3}; // 2MSL + Elm.last_timer = createTimer(Elm.getSocket(), null, resendtimes2); + } + else{ + mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); + mSL.close(Elm.getSocket()); + } } else Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** Echo_tcp.java 22 Sep 2007 23:06:42 -0000 1.33 --- Echo_tcp.java 23 Sep 2007 20:24:43 -0000 1.34 *************** *** 25,29 **** private byte ConnectionAttempts=1; ! private int counts; private int crecv; private long utc1; --- 25,30 ---- private byte ConnectionAttempts=1; ! private int counts = 1; ! private String data = ""; private int crecv; private long utc1; *************** *** 53,65 **** } }catch (TransportLayerException e){ ! e.toString(); ! }catch (LowLinkException e){ ! e.toString(); } - //mParentStack.SL().listen(sock); } public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ connections.add(new Integer(sessionSock)); } --- 54,64 ---- } }catch (TransportLayerException e){ ! System.out.println(e.toString());; } } public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ connections.add(new Integer(sessionSock)); + System.out.println("Accepted socket="+sessionSock+" for listen socket="+listenSock); } *************** *** 99,119 **** public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! sdHost = Host; ! sdPort = port; ! ! LayerInfo protInfo2 = new LayerInfo(getClass().getName()); ! protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Echo Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription("Connecting to host " + Host + ":"+ port +". Please wait..."); ! Simulation.addLayerInfo(protInfo2); ! // do ! // { ! // ConnectionAttempts--; ! // clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); ! // } ! // while (ConnectionAttempts>0 && clientPort==-1); ! boolean isconnected = mParentStack.SL().connect(sock, sdHost, sdPort); return isconnected; --- 98,104 ---- public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { ! printLayerInfo("Connecting to host " + Host + ":"+ port +". Please wait..."); ! boolean isconnected = mParentStack.SL().connect(sock, Host, port); return isconnected; *************** *** 128,131 **** --- 113,130 ---- public void OnConnect(int sock){ System.out.println("ECHO_TCP: Connected "+sock+" !"); + try{ + if(appType == 0){ + printLayerInfo("Start sending echo message '" + data + "' to " + mParentStack.SL().get_socket(sock).dst_IP + ":" + mParentStack.SL().get_socket(sock).dst_port); + this.counts--; + //SendData(Data); + mParentStack.TCP().disconnect(sock); + } + }catch(LowLinkException e){ + System.out.println(e.toString()); + }catch(CommunicationException e){ + System.out.println(e.toString()); + }catch(TransportLayerException e){ + System.out.println(e.toString()); + } } *************** *** 137,157 **** public void OnDisconnect(int sock) { try{ - Listen(); if(appType == 1){ connections.remove(new Integer(sock)); } }catch(Exception e){ ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Cannot listen on port: " + e.toString()); ! Simulation.addLayerInfo(protInfo); ! protInfo = null; } } ! public void OnError(int sock){ } --- 136,161 ---- public void OnDisconnect(int sock) { + System.out.println("ECHO_TCP: Disconnected "+sock+" !"); try{ if(appType == 1){ connections.remove(new Integer(sock)); + //Listen(); } }catch(Exception e){ ! printLayerInfo("Cannot listen on port: " + e.toString()); } } ! public void OnError(int sock, int error){ ! switch(error){ ! case -1: { ! printLayerInfo("Error: can not connect to " + mParentStack.SL().get_socket(sock).dst_IP + ":" + mParentStack.SL().get_socket(sock).dst_port); ! break; ! } ! case -2 :{ ! OnDisconnect(sock); ! break; ! } ! } } *************** *** 166,172 **** public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! ! mParentStack.SL().write(sock, Data); ! //processing the protocol doings. } --- 170,174 ---- public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().write(sock, Data); //processing the protocol doings. } *************** *** 186,198 **** if(appType == 0){ ! //client processing recieve ! // printing some ... ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving echo message '" + Data + "' from server."); ! Simulation.addLayerInfo(protInfo); ! protInfo = null; /* --- 188,192 ---- if(appType == 0){ ! printLayerInfo("Recieving echo message '" + Data + "' from server."); /* *************** *** 205,225 **** if(this.counts==0){ ! mParentStack.SL().close(sock); ! LayerInfo protInfo2 = new LayerInfo(getClass().getName()); ! protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Echo Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription("Connection time: " + (long)(System.currentTimeMillis () - utc1) + " ms. Total recieved messages: " + recieved + "."); ! Simulation.addLayerInfo(protInfo2); }else{ this.counts--; ! try { ! LayerInfo protInfo3 = new LayerInfo(getClass().getName()); ! protInfo3.setObjectName(mParentStack.getParentNodeName()); ! protInfo3.setDataType("Echo Protocol Data"); ! protInfo3.setLayer("Application "); ! protInfo3.setDescription("Sending echo message '" + Data + "' to server..."); ! Simulation.addLayerInfo(protInfo3); ! SendData(Data); }catch(Exception e){ --- 199,207 ---- if(this.counts==0){ ! printLayerInfo("Connection time: " + (long)(System.currentTimeMillis () - utc1) + " ms. Total recieved messages: " + recieved + "."); }else{ this.counts--; ! try { ! printLayerInfo("Sending echo message '" + Data + "' to server..."); SendData(Data); }catch(Exception e){ *************** *** 232,254 **** //server processing recieve ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving echo message '" + Data + "' from client. Total recieved messages: " + recieved + "."); ! Simulation.addLayerInfo(protInfo); ! LayerInfo protInfo2 = new LayerInfo(getClass().getName()); ! protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Echo Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription("Sending echo message '" + Data + "' to client."); ! Simulation.addLayerInfo(protInfo2); try { SendData(Data); ! }catch(Exception e){ ! Error.Report(e); ! ///*TODO*: here to catch } --- 214,225 ---- //server processing recieve ! printLayerInfo("Recieving echo message '" + Data + "' from client. Total recieved messages: " + recieved + "."); ! printLayerInfo("Sending echo message '" + Data + "' to client."); try { SendData(Data); ! }catch(CommunicationException e){ ! System.out.println(e.toString()); } *************** *** 266,299 **** */ public void SendEcho(String Data, String Host, int port, int counts) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ - mParentStack.SL().free(sock); - recieved = 0; - this.counts = counts; utc1 = System.currentTimeMillis (); ! if (Connect(Host, port)) ! { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Start sending echo message '" + Data + "' to " + Host + ":" + port); ! Simulation.addLayerInfo(protInfo); ! ! this.counts--; ! //SendData(Data); ! ! } else ! { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Error: can not connect to " + Host + ":" + port + "!"); ! Simulation.addLayerInfo(protInfo); ! this.counts=0; } } } --- 237,258 ---- */ public void SendEcho(String Data, String Host, int port, int counts) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ recieved = 0; utc1 = System.currentTimeMillis (); ! if (Connect(Host, port)){ ! this.counts = counts; ! this.data = Data; ! } ! else{ ! printLayerInfo("Error: can not connect to " + Host + ":" + port + "!"); } } + + protected void printLayerInfo(String s) { + super.printLayerInfo("Echo Protocol Data", s); + } + + } Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Application.java 22 Sep 2007 23:06:42 -0000 1.19 --- Application.java 23 Sep 2007 20:24:43 -0000 1.20 *************** *** 79,83 **** public abstract void OnConnect(int sock); ! public abstract void OnError(int sock); /** --- 79,83 ---- public abstract void OnConnect(int sock); ! public abstract void OnError(int sock, int error); /** Index: TCP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_session.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TCP_session.java 23 Sep 2007 01:49:58 -0000 1.4 --- TCP_session.java 23 Sep 2007 20:24:43 -0000 1.5 *************** *** 32,36 **** public static int Element_id = 0; private int state = CLOSED; ! public long fin_wait_2_timer = -1; public static final int CLOSED = 0; --- 32,36 ---- public static int Element_id = 0; private int state = CLOSED; ! public long last_timer = -1; public static final int CLOSED = 0; Index: Echo.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Echo.java 22 Sep 2007 23:06:42 -0000 1.25 --- Echo.java 23 Sep 2007 20:24:43 -0000 1.26 *************** *** 118,122 **** } ! public void OnError(int sock){ } --- 118,122 ---- } ! public void OnError(int sock, int error){ } Index: ExternalProxyApp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ExternalProxyApp.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ExternalProxyApp.java 22 Sep 2007 23:06:42 -0000 1.3 --- ExternalProxyApp.java 23 Sep 2007 20:24:43 -0000 1.4 *************** *** 176,180 **** } ! public void OnError(int sock){ } --- 176,180 ---- } ! public void OnError(int sock, int error){ } Index: SNMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/SNMP.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** SNMP.java 22 Sep 2007 23:06:43 -0000 1.18 --- SNMP.java 23 Sep 2007 20:24:43 -0000 1.19 *************** *** 225,229 **** ! public void OnError(int sock){ } --- 225,229 ---- ! public void OnError(int sock, int error){ } |
From: QweR <qw...@us...> - 2007-09-23 01:50:06
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv10582/core/protocolsuite/tcp_ip Modified Files: ProtocolStack.java TCP_session.java Tcp.java Log Message: third test version of TCP Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** ProtocolStack.java 21 Sep 2007 22:42:31 -0000 1.56 --- ProtocolStack.java 23 Sep 2007 01:49:58 -0000 1.57 *************** *** 839,843 **** }catch(TransportLayerException te){} catch(NullPointerException e){ ! System.out.println("ProtocolStack.java: " + e.toString()); } catch (CommunicationException ce) {} --- 839,844 ---- }catch(TransportLayerException te){} catch(NullPointerException e){ ! System.out.println("ProtocolStack.java: receivePacket" + e.toString()); ! e.printStackTrace(); } catch (CommunicationException ce) {} *************** *** 960,964 **** }catch(TransportLayerException te){} catch(NullPointerException e){ ! System.out.println("ProtocolStack.java: " + e.toString()); } catch (CommunicationException ce) {} --- 961,965 ---- }catch(TransportLayerException te){} catch(NullPointerException e){ ! System.out.println("ProtocolStack.java: receiveTCP_packet " + e.toString()); } catch (CommunicationException ce) {} Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.91 retrieving revision 1.92 diff -C2 -d -r1.91 -r1.92 *** Tcp.java 22 Sep 2007 23:06:44 -0000 1.91 --- Tcp.java 23 Sep 2007 01:49:58 -0000 1.92 *************** *** 146,150 **** // close seession try{ ! closePort(sock); }catch(TransportLayerException e){ e.toString(); --- 146,150 ---- // close seession try{ ! mSL.close(sock); }catch(TransportLayerException e){ e.toString(); *************** *** 156,159 **** --- 156,166 ---- break; } + case -3:{ + try{ + mSL.close(sock); + }catch(TransportLayerException e){ + e.toString(); + } + } default: System.out.println("TCP error: unsupported resend time"); } *************** *** 369,373 **** { int CONNECTION_DELAY_EXAM = (int)TCP_TIMER_DELAY/4; //examination delay is 10ms, but may be any number ! int resendtimes[] = {6000,24000,-2}; boolean flags[] = genFlags(SYN); boolean connected = false; --- 376,380 ---- { int CONNECTION_DELAY_EXAM = (int)TCP_TIMER_DELAY/4; //examination delay is 10ms, but may be any number ! int resendtimes[] = {6000,24000,45000,-2}; boolean flags[] = genFlags(SYN); boolean connected = false; *************** *** 381,401 **** if (sendTCPSegment(sock, "", flags, -1, resendtimes)) { ! int time = 0; ! while(Elm.getState()!=Elm.ESTABLISHED && time < 40000){ ! try{ ! Thread.sleep(CONNECTION_DELAY_EXAM); ! } ! catch(InterruptedException e){ ! System.out.println("TCP: InterruptedException raised"); ! } ! time += CONNECTION_DELAY_EXAM; ! if(time%TCP_TIMER_DELAY==0) System.out.println("TCP: connection wait "+time); ! } ! if(Elm.getState()==Elm.ESTABLISHED){ ! System.out.println(">> TCP: connected"); ! connected = true; ! } ! else ! System.out.println(">> TCP: connect false"); } else{ --- 388,392 ---- if (sendTCPSegment(sock, "", flags, -1, resendtimes)) { ! } else{ *************** *** 428,431 **** --- 419,434 ---- public boolean disconnect(int sock) throws LowLinkException, CommunicationException, TransportLayerException { + TCP_session Elm = getSession(mSL.get_socket(sock).genKey()); + + if(Elm != null){ + Elm.setState(Elm.FIN_WAIT_1); + mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); + int resendtimes[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; + boolean flags[] = genFlags(FIN); + sendTCPSegment(Elm.getSocket(), "", flags, -1, resendtimes); + } + else { + throw new TransportLayerException("TCP Error: no session exists for socket '"+sock+"'"); + } return true; } *************** *** 614,633 **** Elm.setLastACK(inPacket.get_acknowledgment_number()); } ! printLayerInfo("TCP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getTCP_message() + "\"."); ! ! switch(Elm.getState()){ ! case TCP_session.CLOSED: revc_CLOSED(Elm, inPacket); break; ! case TCP_session.LISTEN: revc_LISTEN(Elm, inPacket); break; ! case TCP_session.SYN_SENT: revc_SYN_SENT(Elm, inPacket); break; ! case TCP_session.SYN_RCVD: revc_SYN_RCVD(Elm, inPacket); break; ! case TCP_session.ESTABLISHED: revc_ESTABLISHED(Elm, inPacket); break; ! case TCP_session.CLOSE_WAIT: revc_CLOSE_WAIT(Elm, inPacket); break; ! case TCP_session.LAST_ACK: revc_LAST_ACK(Elm, inPacket); break; ! case TCP_session.FIN_WAIT_1: revc_FIN_WAIT_1(Elm, inPacket); break; ! case TCP_session.FIN_WAIT_2: revc_FIN_WAIT_2(Elm, inPacket); break; ! case TCP_session.CLOSING: revc_CLOSING(Elm, inPacket); break; ! case TCP_session.TIME_WAIT: revc_TIME_WAIT(Elm, inPacket); break; ! default: } } --- 617,640 ---- Elm.setLastACK(inPacket.get_acknowledgment_number()); } + if(inPacket.get_RST_flag()){ + mSL.close(Elm.getSocket()); + } + else{ + printLayerInfo("TCP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getTCP_message() + "\"."); ! switch(Elm.getState()){ ! case TCP_session.CLOSED: recv_CLOSED(Elm, inPacket); break; ! case TCP_session.LISTEN: recv_LISTEN(Elm, inPacket); break; ! case TCP_session.SYN_SENT: recv_SYN_SENT(Elm, inPacket); break; ! case TCP_session.SYN_RCVD: recv_SYN_RCVD(Elm, inPacket); break; ! case TCP_session.ESTABLISHED: recv_ESTABLISHED(Elm, inPacket); break; ! case TCP_session.CLOSE_WAIT: recv_CLOSE_WAIT(Elm, inPacket); break; ! case TCP_session.LAST_ACK: recv_LAST_ACK(Elm, inPacket); break; ! case TCP_session.FIN_WAIT_1: recv_FIN_WAIT_1(Elm, inPacket); break; ! case TCP_session.FIN_WAIT_2: recv_FIN_WAIT_2(Elm, inPacket); break; ! case TCP_session.CLOSING: recv_CLOSING(Elm, inPacket); break; ! case TCP_session.TIME_WAIT: recv_TIME_WAIT(Elm, inPacket); break; ! default: ! } } } *************** *** 635,641 **** } else { ! //throw new TransportLayerPortException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); ! throw new TransportLayerPortException("TCP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); ! } } } else { --- 642,648 ---- } else { ! //throw new TransportLayerPortException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); ! throw new TransportLayerPortException("TCP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); ! } } } else { *************** *** 644,653 **** } ! private void revc_CLOSED(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { // hm... it is bug! throw new TransportLayerException("Session exists, but port "+ mSL.get_socket(Elm.getSocket()).dst_port +" not binded!"); } ! private void revc_LISTEN(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { if(inPacket.get_SYN_flag()){ --- 651,661 ---- } ! private void recv_CLOSED(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { // hm... it is bug! throw new TransportLayerException("Session exists, but port "+ mSL.get_socket(Elm.getSocket()).dst_port +" not binded!"); } ! ! private void recv_LISTEN(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { if(inPacket.get_SYN_flag()){ *************** *** 657,662 **** sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); } } ! private void revc_SYN_SENT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { if(inPacket.get_SYN_flag() && inPacket.get_ACK_flag()){ --- 665,673 ---- sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); } + else + throw new TransportLayerException("TCP: recv_LISTEN: unexpected packet"); } ! ! private void recv_SYN_SENT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { if(inPacket.get_SYN_flag() && inPacket.get_ACK_flag()){ *************** *** 667,672 **** mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); } } ! private void revc_SYN_RCVD(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { if(inPacket.get_ACK_flag()){ --- 678,686 ---- mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); } + else + throw new TransportLayerException("TCP: recv_SYN_SENT: unexpected packet"); } ! ! private void recv_SYN_RCVD(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { if(inPacket.get_ACK_flag()){ *************** *** 674,705 **** mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); } } ! private void revc_ESTABLISHED(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! } ! private void revc_CLOSE_WAIT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! } ! private void revc_LAST_ACK(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! } ! private void revc_FIN_WAIT_1(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! } ! private void revc_FIN_WAIT_2(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! } ! private void revc_CLOSING(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! } ! private void revc_TIME_WAIT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! } --- 688,799 ---- mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); } + else + throw new TransportLayerException("TCP: recv_SYN_RCVD: unexpected packet"); } ! ! private void recv_ESTABLISHED(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(inPacket.get_FIN_flag()){ ! Elm.setState(Elm.CLOSE_WAIT); ! int resendtimes1[] = {}; ! boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes1); ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); ! ! Elm.setState(Elm.LAST_ACK); ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); ! int resendtimes2[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; //to resend or not to resend ? ! flags = genFlags(FIN); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes2); ! } ! else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! //normal data processing ! } ! else ! throw new TransportLayerException("TCP: recv_ESTABLISHED: unexpected packet"); } ! ! private void recv_CLOSE_WAIT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(false){ ! } ! else ! throw new TransportLayerException("TCP: recv_CLOSE_WAIT: unexpected packet"); } ! ! private void recv_LAST_ACK(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(inPacket.get_ACK_flag()){ ! mSL.close(Elm.getSocket()); ! } ! else if(inPacket.get_FIN_flag()){ ! int resendtimes[] = {}; ! boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); ! } ! else ! throw new TransportLayerException("TCP: recv_LAST_ACK: unexpected packet"); } ! ! private void recv_FIN_WAIT_1(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(inPacket.get_ACK_flag() && inPacket.get_FIN_flag()){ ! Elm.setState(Elm.TIME_WAIT); ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); ! int resendtimes[] = {}; ! boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); ! } ! else if(inPacket.get_ACK_flag()){ ! Elm.setState(Elm.FIN_WAIT_2); ! int resendtimes[] = {75000,-3}; ! Elm.fin_wait_2_timer = createTimer(Elm.getSocket(), null, resendtimes); ! } ! else if(inPacket.get_FIN_flag()){ ! Elm.setState(Elm.CLOSING); ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); ! int resendtimes[] = {}; ! boolean flags[] = genFlags(ACK); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); ! } ! else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! //normal data processing ! } ! else ! throw new TransportLayerException("TCP: recv_FIN_WAIT_1: unexpected packet"); } ! ! private void recv_FIN_WAIT_2(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(inPacket.get_FIN_flag()){ ! Elm.setState(Elm.CLOSING); ! int resendtimes[] = {}; ! boolean flags[] = genFlags(ACK); ! mSL.get_socket(Elm.getSocket()).app.OnDisconnect(Elm.getSocket()); ! sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); ! } ! else if(!(inPacket.get_ACK_flag() || inPacket.get_SYN_flag() || inPacket.get_FIN_flag())){ ! //normal data processing ! } ! else ! throw new TransportLayerException("TCP: recv_FIN_WAIT_2: unexpected packet"); } ! ! private void recv_CLOSING(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(inPacket.get_ACK_flag()){ ! Elm.setState(Elm.TIME_WAIT); ! } ! else ! throw new TransportLayerException("TCP: recv_CLOSING: unexpected packet"); } ! ! private void recv_TIME_WAIT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { ! if(true){ ! ! } ! else ! throw new TransportLayerException("TCP: recv_TIME_WAIT: unexpected packet"); } Index: TCP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_session.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TCP_session.java 22 Sep 2007 23:06:44 -0000 1.3 --- TCP_session.java 23 Sep 2007 01:49:58 -0000 1.4 *************** *** 32,35 **** --- 32,36 ---- public static int Element_id = 0; private int state = CLOSED; + public long fin_wait_2_timer = -1; public static final int CLOSED = 0; |
From: QweR <qw...@us...> - 2007-09-22 23:06:57
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19629/core/protocolsuite/tcp_ip Modified Files: Application.java Echo.java Echo_tcp.java ExternalProxyApp.java PosixTelnetClient.java SNMP.java TCP_session.java Tcp.java Telnet_client.java Telnet_server.java Udp.java jnSocket.java socketLayer.java Log Message: second test version of TCP Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Telnet_client.java 18 Sep 2007 22:29:46 -0000 1.10 --- Telnet_client.java 22 Sep 2007 23:06:44 -0000 1.11 *************** *** 139,142 **** --- 139,146 ---- } + public void OnError(int sock){ + + } + /** * This method disconnects from server. Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** socketLayer.java 21 Sep 2007 22:42:31 -0000 1.3 --- socketLayer.java 22 Sep 2007 23:06:45 -0000 1.4 *************** *** 38,42 **** public void bind(int sock, String srcIP, int srcPort) throws LowLinkException, TransportLayerException{ ! jnSocket jnsock = (jnSocket)sockTable.get(sock); jnsock.src_IP = srcIP; //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! --- 38,42 ---- public void bind(int sock, String srcIP, int srcPort) throws LowLinkException, TransportLayerException{ ! jnSocket jnsock = get_socket(sock); jnsock.src_IP = srcIP; //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! *************** *** 53,57 **** public void listen(int sock) throws TransportLayerException{ ! jnSocket jnsock = (jnSocket)sockTable.get(sock); jnsock.open_state = true; if(jnsock.type == jnsock.UDP_socket){ --- 53,57 ---- public void listen(int sock) throws TransportLayerException{ ! jnSocket jnsock = get_socket(sock); jnsock.open_state = true; if(jnsock.type == jnsock.UDP_socket){ *************** *** 63,69 **** } ! public void write(int sock, String msg){ ! //if() ! //tcp only write!!! } --- 63,95 ---- } ! public boolean connect(int sock, String ipaddr, int port) throws LowLinkException, CommunicationException, TransportLayerException{ ! boolean result = false; ! jnSocket jnsock = get_socket(sock); ! if(jnsock.type == jnsock.TCP_socket){ ! jnsock.open_state = true; ! jnsock.dst_IP = ipaddr; ! jnsock.dst_port = port; ! result = mParentStack.TCP().connect(sock, ipaddr, port); ! } ! else if(jnsock.type == jnsock.TCP_socket){ ! result = true; ! } ! return result; ! } ! ! public int accept(int sock, String dstIP, int dstPort){ ! jnSocket jnsock = get_socket(sock); ! int new_sock = socket(jnsock.type, jnsock.app); ! jnSocket new_jnsock = get_socket(new_sock); ! new_jnsock.src_IP = jnsock.src_IP; ! new_jnsock.src_port = jnsock.src_port; ! new_jnsock.dst_IP = dstIP; ! new_jnsock.dst_port = dstPort; ! new_jnsock.open_state = true; ! return new_sock; ! } ! ! public void write(int sock, String msg) throws TransportLayerException, LowLinkException, CommunicationException{ ! mParentStack.TCP().sendTCPData(sock, msg); } Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** Udp.java 21 Sep 2007 22:42:31 -0000 1.37 --- Udp.java 22 Sep 2007 23:06:44 -0000 1.38 *************** *** 61,65 **** public class Udp implements Serializable { ! private Hashtable sessionTable = new Hashtable(); private ProtocolStack mParentStack; private socketLayer mSL; --- 61,66 ---- public class Udp implements Serializable { ! private Hashtable sessionTable = new Hashtable(); ! private Object sessionTable_lock = new Object(); private ProtocolStack mParentStack; private socketLayer mSL; *************** *** 114,126 **** // test if destination UDP port exists on this NeworkLayerDevice ! if (sessionTable.get(jnSocket.genUDPkey(inPacket.get_destPort())) !=null) { ! ! //let's check all the things dealing with destination port number ! //UDP_HashTableElement Elm = null; ! UDP_session Elm = null; ! Elm=(UDP_session) sessionTable.get(jnSocket.genUDPkey(inPacket.get_destPort())); ! ! int sock = Elm.sock; //now we decompose UDP datagram --- 115,122 ---- // test if destination UDP port exists on this NeworkLayerDevice ! UDP_session Elm=getSession(jnSocket.genUDPkey(inPacket.get_destPort())); ! if (Elm !=null) { ! int sock = Elm.getSocket(); //now we decompose UDP datagram *************** *** 170,174 **** try{ ! if(sessionTable.get(jnSocket.genUDPkey(mSL.get_socket(sock).src_port)) == null){ // we should reserve port for it reserveFreePort(sock); --- 166,170 ---- try{ ! if(getSession(jnSocket.genUDPkey(mSL.get_socket(sock).src_port)) == null){ // we should reserve port for it reserveFreePort(sock); *************** *** 192,198 **** IncSentDatagrammsNumber(); ! if (sessionTable.get(jnSocket.genUDPkey(insrcPort)) !=null) { ! ((UDP_session)sessionTable.get(jnSocket.genUDPkey(insrcPort))).IncSentDatagrammsNumber(); } --- 188,194 ---- IncSentDatagrammsNumber(); ! if (getSession(jnSocket.genUDPkey(insrcPort)) !=null) { ! getSession(jnSocket.genUDPkey(insrcPort)).IncSentDatagrammsNumber(); } *************** *** 229,233 **** String sessionID; boolean Found=false; ! Enumeration LocalSessions = sessionTable.keys(); --- 225,229 ---- String sessionID; boolean Found=false; ! Enumeration LocalSessions = getSessionKeys(); *************** *** 238,242 **** { sessionID = (String)LocalSessions.nextElement(); ! Elm = (UDP_session) sessionTable.get(sessionID); if ( sock == Elm.sock && Elm.sock >=0 ) { --- 234,238 ---- { sessionID = (String)LocalSessions.nextElement(); ! Elm = getSession(sessionID); if ( sock == Elm.sock && Elm.sock >=0 ) { *************** *** 254,264 **** while ( (number<PORT_START_NUMBER+PORT_QUANT) && !(Reserved) ) { ! Elm = (UDP_session) sessionTable.get(jnSocket.genUDPkey(number)); if (Elm == null) //free port { ! Reserved=true; ! Elm = new UDP_session(sock); mSL.get_socket(sock).src_port = number; ! sessionTable.put(jnSocket.genUDPkey(number),Elm); LayerInfo UDP_Info = new LayerInfo(getClass().getName()); --- 250,259 ---- while ( (number<PORT_START_NUMBER+PORT_QUANT) && !(Reserved) ) { ! Elm = getSession(jnSocket.genUDPkey(number)); if (Elm == null) //free port { ! Reserved=true; mSL.get_socket(sock).src_port = number; ! addSession(jnSocket.genUDPkey(number), sock); LayerInfo UDP_Info = new LayerInfo(getClass().getName()); *************** *** 289,295 **** { //create such a record in hashtable - UDP_session newElm = new UDP_session(sock_num); mSL.get_socket(sock_num).src_port = in_Port; ! sessionTable.put(jnSocket.genUDPkey(in_Port),newElm); //hash table update LayerInfo UDP_Info = new LayerInfo(getClass().getName()); --- 284,289 ---- { //create such a record in hashtable mSL.get_socket(sock_num).src_port = in_Port; ! addSession(jnSocket.genUDPkey(in_Port), sock_num); //hash table update LayerInfo UDP_Info = new LayerInfo(getClass().getName()); *************** *** 323,327 **** UDP_session Elm=null; int portToClose=mSL.get_socket(sock).src_port; ! Elm=(UDP_session) sessionTable.get(jnSocket.genUDPkey(portToClose)); if(portToClose!=0 && Elm!=null){ --- 317,321 ---- UDP_session Elm=null; int portToClose=mSL.get_socket(sock).src_port; ! Elm= getSession(jnSocket.genUDPkey(portToClose)); if(portToClose!=0 && Elm!=null){ *************** *** 332,339 **** UDP_Info.setDescription("Local port " + portToClose + " closed and set to free."); Simulation.addLayerInfo(UDP_Info); ! sessionTable.remove(jnSocket.genUDPkey(portToClose)); mSL.close(Elm.sock); } else throw new TransportLayerException("UDP Error: port "+ portToClose +" is not being LISTENED to by the application: \"" + mSL.get_socket(sock).app.toString() + "\"."); } /*STATISTIC PART */ --- 326,367 ---- UDP_Info.setDescription("Local port " + portToClose + " closed and set to free."); Simulation.addLayerInfo(UDP_Info); ! removeSession(jnSocket.genUDPkey(portToClose)); mSL.close(Elm.sock); } else throw new TransportLayerException("UDP Error: port "+ portToClose +" is not being LISTENED to by the application: \"" + mSL.get_socket(sock).app.toString() + "\"."); } + + private UDP_session addSession(String key, int sock){ + UDP_session udps = new UDP_session(sock); + synchronized(sessionTable_lock){ + sessionTable.put(key, udps); + } + return udps; + } + + private UDP_session removeSession(String key){ + UDP_session udps; + synchronized(sessionTable_lock){ + udps = (UDP_session) sessionTable.remove(key); + } + return udps; + } + + private UDP_session getSession(String key){ + UDP_session udps; + synchronized(sessionTable_lock){ + udps = (UDP_session) sessionTable.get(key); + } + return udps; + } + + private Enumeration getSessionKeys(){ + Enumeration keys; + synchronized(sessionTable_lock){ + keys = sessionTable.keys(); + } + return keys; + } + + /*STATISTIC PART */ Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Telnet_server.java 18 Sep 2007 22:29:46 -0000 1.12 --- Telnet_server.java 22 Sep 2007 23:06:44 -0000 1.13 *************** *** 133,136 **** --- 133,140 ---- } + public void OnError(int sock){ + + } + /** * This method disconnects from server. Index: PosixTelnetClient.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/PosixTelnetClient.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PosixTelnetClient.java 18 Sep 2007 22:29:46 -0000 1.2 --- PosixTelnetClient.java 22 Sep 2007 23:06:42 -0000 1.3 *************** *** 144,147 **** --- 144,151 ---- } + public void OnError(int sock){ + + } + /** * This method sends data to the other side. Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.90 retrieving revision 1.91 diff -C2 -d -r1.90 -r1.91 *** Tcp.java 21 Sep 2007 22:42:31 -0000 1.90 --- Tcp.java 22 Sep 2007 23:06:44 -0000 1.91 *************** *** 112,126 **** public boolean resend(int cur_time){ boolean res = false; - System.out.println("pack resend"); - try{ - mParentStack.sendPacket(packet); - }catch(LowLinkException e){ - e.toString(); - }catch(CommunicationException e){ - e.toString(); - } int nt = nextTime(cur_time); if(nt>0){ ! res = true; } else{ --- 112,128 ---- public boolean resend(int cur_time){ boolean res = false; int nt = nextTime(cur_time); + if(nt>=0){ + System.out.println("pack resend"); + try{ + mParentStack.sendPacket(packet); + }catch(LowLinkException e){ + e.toString(); + }catch(CommunicationException e){ + e.toString(); + } + } if(nt>0){ ! res = true; } else{ *************** *** 131,135 **** case -1:{ //acknowledgment have not recieved, close connection // send RST segment ! boolean flags[]={false,false,false,true,false,false}; /* URG, ACK, PSH, !RST!, SYN, FIN */ try{ TCP_packet rstpack = getTCPPacket_tosend(sock, "", flags, packet.get_acknowledgment_number(), packet.get_sequence_number()+1); --- 133,137 ---- case -1:{ //acknowledgment have not recieved, close connection // send RST segment ! boolean flags[] = genFlags(RST); try{ TCP_packet rstpack = getTCPPacket_tosend(sock, "", flags, packet.get_acknowledgment_number(), packet.get_sequence_number()+1); *************** *** 150,153 **** --- 152,159 ---- break; } + case -2:{ + mSL.get_socket(sock).app.OnError(sock); + break; + } default: System.out.println("TCP error: unsupported resend time"); } *************** *** 188,197 **** private Hashtable sessionTable = new Hashtable(); ! private Object sessionTable_lock = 0; //for locking Hashtable sessionTable private ProtocolStack mParentStack; private socketLayer mSL; private Timer timer; private PriorityQueue tcp_timers = new PriorityQueue(); ! private Object tcp_timers_lock = 0; //for locking queue tcp_timers private int current_time = 0; private long nextTimerID = 0; --- 194,203 ---- private Hashtable sessionTable = new Hashtable(); ! private Object sessionTable_lock = new Object(); //for locking Hashtable sessionTable private ProtocolStack mParentStack; private socketLayer mSL; private Timer timer; private PriorityQueue tcp_timers = new PriorityQueue(); ! private Object tcp_timers_lock = new Object(); //for locking queue tcp_timers private int current_time = 0; private long nextTimerID = 0; *************** *** 229,232 **** --- 235,246 ---- private static final int SYN_flag = 4; private static final int FIN_flag = 5; + + private static final int NOFLAGS = 0; + private static final int URG = 1; + private static final int ACK = 2; + private static final int PSH = 4; + private static final int RST = 8; + private static final int SYN = 16; + private static final int FIN = 32; /** *************** *** 292,296 **** Reserved=true; mSL.get_socket(sock).src_port = number; ! addSession(jnSocket.genTCPkey(number,"0.0.0.0",0), sock); printLayerInfo("Local port " + number + " reserved for client app."); } --- 306,312 ---- Reserved=true; mSL.get_socket(sock).src_port = number; ! TCP_session tcps = addSession(jnSocket.genTCPkey(number,"0.0.0.0",0), sock); ! tcps.setState(tcps.LISTEN); ! printLayerInfo("Local port " + number + " reserved for client app."); } *************** *** 313,323 **** if ( mSL.get_socket(sock_num).src_port == 0 ) { ! if (in_Port>=0 && in_Port<=65535){ //create such a record in hashtable mSL.get_socket(sock_num).src_port = in_Port; ! addSession(jnSocket.genTCPkey(in_Port,"0.0.0.0",0), sock_num); //hash table update printLayerInfo("Local port " + in_Port + " binded."); } else { throw new TransportLayerException("TCP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); --- 329,343 ---- if ( mSL.get_socket(sock_num).src_port == 0 ) { ! if (in_Port>0 && in_Port<=65535){ //create such a record in hashtable mSL.get_socket(sock_num).src_port = in_Port; ! TCP_session tcps = addSession(jnSocket.genTCPkey(in_Port,"0.0.0.0",0), sock_num); ! tcps.setState(tcps.LISTEN); printLayerInfo("Local port " + in_Port + " binded."); } + else if(in_Port == 0){ + reserveFreePort(sock_num); + } else { throw new TransportLayerException("TCP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); *************** *** 349,365 **** { int CONNECTION_DELAY_EXAM = (int)TCP_TIMER_DELAY/4; //examination delay is 10ms, but may be any number ! int resendtimes[] = {6000,24000}; ! boolean flags[]={false,false,false,false,true,false}; /* URG, ACK, PSH, RST, !SYN!, FIN */ boolean connected = false; if(IPV4Address.validateDecIP(dstIP)){ ! mSL.get_socket(sock).dst_IP = dstIP; ! mSL.get_socket(sock).dst_port = dstPort; TCP_session Elm = addSession(mSL.get_socket(sock).genKey(), sock); ! if (sendTCPSegment(sock, "", flags, 0, resendtimes)) { int time = 0; ! while(Elm.getState()!=Elm.ESTABLISHED && time < 78000){ try{ Thread.sleep(CONNECTION_DELAY_EXAM); --- 369,386 ---- { int CONNECTION_DELAY_EXAM = (int)TCP_TIMER_DELAY/4; //examination delay is 10ms, but may be any number ! int resendtimes[] = {6000,24000,-2}; ! boolean flags[] = genFlags(SYN); boolean connected = false; if(IPV4Address.validateDecIP(dstIP)){ ! mSL.get_socket(sock).src_IP = mParentStack.getSrcIP(); ! reserveFreePort(sock); TCP_session Elm = addSession(mSL.get_socket(sock).genKey(), sock); + Elm.setState(Elm.SYN_SENT); ! if (sendTCPSegment(sock, "", flags, -1, resendtimes)) { int time = 0; ! while(Elm.getState()!=Elm.ESTABLISHED && time < 40000){ try{ Thread.sleep(CONNECTION_DELAY_EXAM); *************** *** 378,383 **** System.out.println(">> TCP: connect false"); } ! else System.out.println(">> TCP: sendTCPSegment false"); } else{ --- 399,406 ---- System.out.println(">> TCP: connect false"); } ! else{ ! Elm.setState(Elm.CLOSED); System.out.println(">> TCP: sendTCPSegment false"); + } } else{ *************** *** 432,437 **** } ! /** * This method sends the TCP segments with certain flags * NOTE: DO <b>NOT</b> CALL this method from application use only <i>SendTCP(Object application, String inTCPMessage)</i> in the application to send TCP segments --- 455,466 ---- } + public void sendTCPData(int sock, String data) throws TransportLayerException, LowLinkException, CommunicationException + { + boolean flags[] = genFlags(NOFLAGS); + int resendtimes[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; + sendTCPSegment(sock, data, flags, -1, resendtimes); + } ! /** * This method sends the TCP segments with certain flags * NOTE: DO <b>NOT</b> CALL this method from application use only <i>SendTCP(Object application, String inTCPMessage)</i> in the application to send TCP segments *************** *** 449,453 **** */ ! public boolean sendTCPSegment(int sock, String inTCPMessage, boolean flags[], int acknow_num, int resendtimes[]) throws TransportLayerException, LowLinkException, CommunicationException { TCP_packet tosend = getTCPPacket_tosend(sock,inTCPMessage,flags,acknow_num, -1); --- 478,482 ---- */ ! private boolean sendTCPSegment(int sock, String inTCPMessage, boolean flags[], int acknow_num, int resendtimes[]) throws TransportLayerException, LowLinkException, CommunicationException { TCP_packet tosend = getTCPPacket_tosend(sock,inTCPMessage,flags,acknow_num, -1); *************** *** 459,464 **** TCP_session Elm = getSession(jnsock.genKey()); ! long tid = createTimer(sock, (TCP_packet)tosend.clone(), resendtimes); ! Elm.addSegmentToResend(tosend.get_sequence_number(),tid); mParentStack.sendPacket(tosend); return true; --- 488,495 ---- TCP_session Elm = getSession(jnsock.genKey()); ! if(resendtimes.length > 0){ ! long tid = createTimer(sock, (TCP_packet)tosend.clone(), resendtimes); ! Elm.addSegmentToResend(tosend.get_sequence_number(),tid); ! } mParentStack.sendPacket(tosend); return true; *************** *** 480,484 **** */ ! public TCP_packet getTCPPacket_tosend(int sock, String inMessage, boolean flags[], int acknow_num, int seq_num) throws TransportLayerException{ jnSocket jnsock = mSL.get_socket(sock); String srcIP = jnsock.src_IP; --- 511,515 ---- */ ! private TCP_packet getTCPPacket_tosend(int sock, String inMessage, boolean flags[], int acknow_num, int seq_num) throws TransportLayerException{ jnSocket jnsock = mSL.get_socket(sock); String srcIP = jnsock.src_IP; *************** *** 496,500 **** //s_num = (flags[1] && !flags[4] && !flags[5]) ? -1 : Elm.seq_number; //getting sequence number 0-for SYN, -1 for ACK if(seq_num == -1 || seq_num > Elm.seq_number) seq_num = Elm.seq_number; //getting sequence number 0-for SYN, -1 for ACK ! int a_num=acknow_num; //(Integer)Elm.ReceivedSegments.lastElement()+1; //getting ACK number 0 - for SYN, 1 - as a reply for SYN ... so on //now we set all the flags --- 527,531 ---- //s_num = (flags[1] && !flags[4] && !flags[5]) ? -1 : Elm.seq_number; //getting sequence number 0-for SYN, -1 for ACK if(seq_num == -1 || seq_num > Elm.seq_number) seq_num = Elm.seq_number; //getting sequence number 0-for SYN, -1 for ACK ! if(acknow_num==-1) acknow_num = Elm.getLastACK(); //now we set all the flags *************** *** 507,511 **** tosend.set_FIN_flag(flags[FIN_flag]); tosend.set_sequence_number(seq_num); ! tosend.set_acknowledgment_number(a_num); tosend.setTCP_message(inMessage); --- 538,542 ---- tosend.set_FIN_flag(flags[FIN_flag]); tosend.set_sequence_number(seq_num); ! tosend.set_acknowledgment_number(acknow_num); tosend.setTCP_message(inMessage); *************** *** 515,519 **** Elm.seq_number++; ! if (!(flags[SYN_flag] && a_num==0) && flags[ACK_flag]) Elm.inc_sent_ACK(); //inc in case this is an ACK-segment --- 546,550 ---- Elm.seq_number++; ! if (!(flags[SYN_flag] && acknow_num==0) && flags[ACK_flag]) Elm.inc_sent_ACK(); //inc in case this is an ACK-segment *************** *** 551,554 **** --- 582,707 ---- } + + + public void receiveTCPPacket( TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { + //test: check sum of UDP packet + if (inPacket.getCheck_Sum() == 1) + { + // test if this packet is for a local Address. + if(mParentStack.isInternalIP(inPacket.getDestIPAddress())){ + + // test if TCP sesssion exists on this NeworkLayerDevice + TCP_session Elm; + Elm = getSession(jnSocket.genTCPkey(inPacket.get_destPort(), inPacket.getSourceIPAddress(), inPacket.get_srcPort())); + if(Elm == null && inPacket.get_SYN_flag()){ + Elm = getSession(jnSocket.genTCPkey(inPacket.get_destPort(), "0.0.0.0", 0)); + int listensock = Elm.getSocket(); + if(Elm != null){ + int sock = mSL.accept(Elm.getSocket(), inPacket.getSourceIPAddress(), inPacket.get_srcPort()); + jnSocket jnsock = mSL.get_socket(sock); + Elm = addSession(jnSocket.genTCPkey(inPacket.get_destPort(), inPacket.getSourceIPAddress(), inPacket.get_srcPort()), sock); + Elm.setState(Elm.LISTEN); + jnsock.app.Accept(listensock, sock); + } + } + if (Elm !=null) + { + //int sock = Elm.getSocket(); + if(inPacket.get_acknowledgment_number() >= Elm.getLastACK()){ + if(inPacket.get_ACK_flag() && inPacket.get_acknowledgment_number() > Elm.getLastACK()){ + removeTimer(Elm.getSegmentToResend(inPacket.get_acknowledgment_number()-1)); + Elm.removeSegmentToResend(inPacket.get_acknowledgment_number()-1); + Elm.setLastACK(inPacket.get_acknowledgment_number()); + } + + printLayerInfo("TCP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getTCP_message() + "\"."); + + switch(Elm.getState()){ + case TCP_session.CLOSED: revc_CLOSED(Elm, inPacket); break; + case TCP_session.LISTEN: revc_LISTEN(Elm, inPacket); break; + case TCP_session.SYN_SENT: revc_SYN_SENT(Elm, inPacket); break; + case TCP_session.SYN_RCVD: revc_SYN_RCVD(Elm, inPacket); break; + case TCP_session.ESTABLISHED: revc_ESTABLISHED(Elm, inPacket); break; + case TCP_session.CLOSE_WAIT: revc_CLOSE_WAIT(Elm, inPacket); break; + case TCP_session.LAST_ACK: revc_LAST_ACK(Elm, inPacket); break; + case TCP_session.FIN_WAIT_1: revc_FIN_WAIT_1(Elm, inPacket); break; + case TCP_session.FIN_WAIT_2: revc_FIN_WAIT_2(Elm, inPacket); break; + case TCP_session.CLOSING: revc_CLOSING(Elm, inPacket); break; + case TCP_session.TIME_WAIT: revc_TIME_WAIT(Elm, inPacket); break; + default: + } + } + + } + else { + //throw new TransportLayerPortException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); + throw new TransportLayerPortException("TCP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); + } + } + } else { + throw new TransportLayerException("TCP Error: incorrect checksum on receiving!"); //comment this line if you have implemented check sum tests :) + } + } + + private void revc_CLOSED(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + // hm... it is bug! + throw new TransportLayerException("Session exists, but port "+ mSL.get_socket(Elm.getSocket()).dst_port +" not binded!"); + } + private void revc_LISTEN(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + if(inPacket.get_SYN_flag()){ + Elm.setState(Elm.SYN_RCVD); + int resendtimes[] = {1500,3000,6000,12000,24000,48000,64000,64000,64000,64000,64000,64000,-1}; + boolean flags[] = genFlags(ACK | SYN); + sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); + } + } + private void revc_SYN_SENT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + if(inPacket.get_SYN_flag() && inPacket.get_ACK_flag()){ + Elm.setState(Elm.ESTABLISHED); + int resendtimes[] = {}; + boolean flags[] = genFlags(ACK); + sendTCPSegment(Elm.getSocket(), "", flags, inPacket.get_sequence_number()+1, resendtimes); + mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); + } + } + private void revc_SYN_RCVD(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + if(inPacket.get_ACK_flag()){ + Elm.setState(Elm.ESTABLISHED); + mSL.get_socket(Elm.getSocket()).app.OnConnect(Elm.getSocket()); + } + } + private void revc_ESTABLISHED(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + + } + private void revc_CLOSE_WAIT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + + } + private void revc_LAST_ACK(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + + } + private void revc_FIN_WAIT_1(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + + } + private void revc_FIN_WAIT_2(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + + } + private void revc_CLOSING(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + + } + private void revc_TIME_WAIT(TCP_session Elm, TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException + { + + } + private long createTimer(int sock, TCP_packet pack, int times[]){ Resender rsnd = new Resender(sock,pack,times); *************** *** 606,609 **** --- 759,773 ---- } + public boolean[] genFlags(int flags){ + boolean f[] = {false, false, false, false, false, false}; + if((flags & URG) == URG) f[URG_flag] = true; + if((flags & ACK) == ACK) f[ACK_flag] = true; + if((flags & PSH) == PSH) f[PSH_flag] = true; + if((flags & RST) == RST) f[RST_flag] = true; + if((flags & SYN) == SYN) f[SYN_flag] = true; + if((flags & FIN) == FIN) f[FIN_flag] = true; + return f; + } + /*STATISTIC PART */ *************** *** 635,662 **** /** ! * This method returns the number of received segments * @author gift (sourceforge.net user) ! * @param Unused. ! * @return int the number of received segments * @version v0.20 */ ! public int GetReceivedSegmentsNumber() { ! return received_segments; } /** ! * This method returns the number of sent segments * @author gift (sourceforge.net user) ! * @param Unused. ! * @return int the number of sent segments * @version v0.20 */ ! public int GetSentSegmentsNumber() { ! return sent_segments; } - /** ! * This method increments sent ACK segments counter * @author gift (sourceforge.net user) * @param numb the number to add --- 799,825 ---- /** ! * This method increments sent ACK segments counter * @author gift (sourceforge.net user) ! * @param numb the number to add ! * @return Nothing * @version v0.20 */ ! public void IncSentACKSegmentsNumber(int numb) { ! sent_ACK+=numb; } /** ! * This method increments received duplicates counter * @author gift (sourceforge.net user) ! * @param numb the number to add ! * @return Nothing * @version v0.20 */ ! public void IncReceivedDuplicatesNumber(int numb) { ! received_duplicates+=numb; } /** ! * This method increments sent duplicates counter * @author gift (sourceforge.net user) * @param numb the number to add *************** *** 664,719 **** * @version v0.20 */ ! public void IncSentACKSegmentsNumber(int numb) { ! sent_ACK+=numb; } ! ! /** ! * This method returns the number of sent ACK segments * @author gift (sourceforge.net user) * @param Unused. ! * @return int the number of sent ACK segments * @version v0.20 */ ! public int GetSentACKSegmentsNumber() { ! return sent_ACK; } /** ! * This method increments received duplicates counter * @author gift (sourceforge.net user) ! * @param numb the number to add ! * @return Nothing * @version v0.20 */ ! public void IncReceivedDuplicatesNumber(int numb) { ! received_duplicates+=numb; } - /** ! * This method returns the number of received duplicates * @author gift (sourceforge.net user) * @param Unused. ! * @return int the number of received duplicates * @version v0.20 */ ! public int GetReceivedDuplicatesNumber() { ! return received_duplicates; } - /** ! * This method increments sent duplicates counter * @author gift (sourceforge.net user) ! * @param numb the number to add ! * @return Nothing * @version v0.20 */ ! public void IncSentDuplicatesNumber(int numb) { ! sent_duplicates+=numb; } - /** * This method returns the number of sent duplicates --- 827,878 ---- * @version v0.20 */ ! public void IncSentDuplicatesNumber(int numb) { ! sent_duplicates+=numb; } ! /** ! * This method returns the number of received segments * @author gift (sourceforge.net user) * @param Unused. ! * @return int the number of received segments * @version v0.20 */ ! public int GetReceivedSegmentsNumber() { ! return received_segments; } /** ! * This method returns the number of sent segments * @author gift (sourceforge.net user) ! * @param Unused. ! * @return int the number of sent segments * @version v0.20 */ ! public int GetSentSegmentsNumber() { ! return sent_segments; } /** ! * This method returns the number of sent ACK segments * @author gift (sourceforge.net user) * @param Unused. ! * @return int the number of sent ACK segments * @version v0.20 */ ! public int GetSentACKSegmentsNumber() { ! return sent_ACK; } /** ! * This method returns the number of received duplicates * @author gift (sourceforge.net user) ! * @param Unused. ! * @return int the number of received duplicates * @version v0.20 */ ! public int GetReceivedDuplicatesNumber() { ! return received_duplicates; } /** * This method returns the number of sent duplicates *************** *** 774,781 **** Simulation.addLayerInfo(protInfo); } - - public void receiveTCPPacket(TCP_packet inPacket) throws TransportLayerPortException, TransportLayerException, LowLinkException, CommunicationException { - - } --- 933,936 ---- Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Echo_tcp.java 21 Sep 2007 22:42:31 -0000 1.32 --- Echo_tcp.java 22 Sep 2007 23:06:42 -0000 1.33 *************** *** 15,18 **** --- 15,19 ---- import core.Error; import core.Simulation; + import java.util.Vector; /** *************** *** 30,33 **** --- 31,35 ---- private int sock; + private Vector<Integer> connections = new Vector<Integer>(0); /** Creates a new instance of Echo */ *************** *** 59,63 **** public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ ! } --- 61,65 ---- public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ ! connections.add(new Integer(sessionSock)); } *************** *** 72,75 **** --- 74,80 ---- { mParentStack.SL().close(sock); + for(int i=0; i<connections.size(); i++){ + mParentStack.SL().close(connections.get(i).intValue()); + } recieved = 0; } *************** *** 78,81 **** --- 83,89 ---- Close(); mParentStack.SL().free(sock); + for(int i=0; i<connections.size(); i++){ + mParentStack.SL().free(connections.get(i).intValue()); + } } *************** *** 107,111 **** // } // while (ConnectionAttempts>0 && clientPort==-1); ! boolean isconnected = mParentStack.TCP().connect(sock, sdHost, sdPort); return isconnected; --- 115,119 ---- // } // while (ConnectionAttempts>0 && clientPort==-1); ! boolean isconnected = mParentStack.SL().connect(sock, sdHost, sdPort); return isconnected; *************** *** 119,122 **** --- 127,131 ---- */ public void OnConnect(int sock){ + System.out.println("ECHO_TCP: Connected "+sock+" !"); } *************** *** 130,133 **** --- 139,145 ---- try{ Listen(); + if(appType == 1){ + connections.remove(new Integer(sock)); + } }catch(Exception e){ LayerInfo protInfo = new LayerInfo(getClass().getName()); *************** *** 141,144 **** --- 153,160 ---- } + public void OnError(int sock){ + + } + /** * This method sends data to the other side. *************** *** 268,272 **** this.counts--; ! SendData(Data); } else --- 284,288 ---- this.counts--; ! //SendData(Data); } else Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Application.java 18 Sep 2007 22:29:45 -0000 1.18 --- Application.java 22 Sep 2007 23:06:42 -0000 1.19 *************** *** 76,81 **** --- 76,84 ---- public abstract void OnDisconnect(int sock); + public abstract void OnConnect(int sock); + public abstract void OnError(int sock); + /** * This method sends data to the other side. Index: TCP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_session.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TCP_session.java 21 Sep 2007 22:42:31 -0000 1.2 --- TCP_session.java 22 Sep 2007 23:06:44 -0000 1.3 *************** *** 29,33 **** public int seq_number=0; ! public int last_passed=-1; //last sequence number value of the segment that has been passed upstairs public static int Element_id = 0; private int state = CLOSED; --- 29,33 ---- public int seq_number=0; ! private int last_ack_number=0; //last sequence number value of the segment that has been passed upstairs public static int Element_id = 0; private int state = CLOSED; *************** *** 36,40 **** public static final int LISTEN = 1; public static final int SYN_SENT = 2; ! public static final int SYB_RCVD = 3; public static final int ESTABLISHED = 4; public static final int FIN_WAIT_1 = 5; --- 36,40 ---- public static final int LISTEN = 1; public static final int SYN_SENT = 2; ! public static final int SYN_RCVD = 3; public static final int ESTABLISHED = 4; public static final int FIN_WAIT_1 = 5; *************** *** 133,137 **** } else ! System.out.println("TCP session error: segment is not exists"); return timerID; } --- 133,137 ---- } else ! System.out.println("TCP session error on remove: segment is not exists"); return timerID; } *************** *** 144,148 **** } else ! System.out.println("TCP session error: segment is not exists"); return timerID; } --- 144,148 ---- } else ! System.out.println("TCP session error on get: segment is not exists"); return timerID; } *************** *** 159,162 **** --- 159,171 ---- } + public int getLastACK(){ + return last_ack_number; + } + + public void setLastACK(int acknum){ + if(last_ack_number <= acknum) + last_ack_number = acknum; + } + public void inc_received_segments(){ received_segments++; Index: Echo.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Echo.java 21 Sep 2007 22:42:31 -0000 1.24 --- Echo.java 22 Sep 2007 23:06:42 -0000 1.25 *************** *** 114,118 **** */ ! public void OnDisconnect(int sock){ } /** --- 114,124 ---- */ ! public void OnDisconnect(int sock){ ! ! } ! ! public void OnError(int sock){ ! ! } /** Index: jnSocket.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/jnSocket.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** jnSocket.java 18 Sep 2007 22:29:46 -0000 1.2 --- jnSocket.java 22 Sep 2007 23:06:44 -0000 1.3 *************** *** 22,26 **** public short type; // 0 -- raw, 1 -- udp, 2 -- tcp public boolean open_state; - public short state; public Application app; --- 22,25 ---- *************** *** 34,38 **** public jnSocket(int _number, Application _app, short _type){ open_state = false; - state = 0; type = _type; app = _app; --- 33,36 ---- *************** *** 43,49 **** String key; switch(type){ ! case 0: key=src_IP+String.valueOf(src_port)+"_"+dst_IP+"_"+String.valueOf(dst_port); break; ! case 1: key=genTCPkey(src_port, dst_IP, dst_port); break; ! case 2: key=genUDPkey(src_port); break; default: key=""; } --- 41,47 ---- String key; switch(type){ ! case RAW_socket: key=src_IP+String.valueOf(src_port)+"_"+dst_IP+"_"+String.valueOf(dst_port); break; ! case UDP_socket: key=genUDPkey(src_port); break; ! case TCP_socket: key=genTCPkey(src_port, dst_IP, dst_port); break; default: key=""; } *************** *** 55,60 **** } ! static public String genUDPkey(int port){ ! return String.valueOf(port); } } --- 53,58 ---- } ! static public String genUDPkey(int dstport){ ! return String.valueOf(dstport); } } Index: ExternalProxyApp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ExternalProxyApp.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ExternalProxyApp.java 18 Sep 2007 22:29:46 -0000 1.2 --- ExternalProxyApp.java 22 Sep 2007 23:06:42 -0000 1.3 *************** *** 176,179 **** --- 176,183 ---- } + public void OnError(int sock){ + + } + public void OnConnect(int sock) { Index: SNMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/SNMP.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** SNMP.java 18 Sep 2007 22:29:46 -0000 1.17 --- SNMP.java 22 Sep 2007 23:06:43 -0000 1.18 *************** *** 215,222 **** */ ! public void OnDisconnect(int sock){ } ! public void OnConnect(int sock){ } /** --- 215,231 ---- */ ! public void OnDisconnect(int sock){ + } ! ! public void OnConnect(int sock){ ! ! } ! ! ! public void OnError(int sock){ ! ! } /** |
From: QweR <qw...@us...> - 2007-09-21 22:42:38
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13173/core/protocolsuite/tcp_ip Modified Files: Echo.java Echo_tcp.java ProtocolStack.java TCP_packet.java TCP_session.java Tcp.java UDP_session.java Udp.java jnSession.java socketLayer.java Log Message: first test version of TCP Index: TCP_packet.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_packet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TCP_packet.java 20 Nov 2006 17:20:20 -0000 1.3 --- TCP_packet.java 21 Sep 2007 22:42:31 -0000 1.4 *************** *** 2,60 **** Java Firewall Simulator (jFirewallSim) - - - Copyright (c) 2004, jFirewallSim development team All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, are - permitted provided that the following conditions are met: - - - Redistributions of source code must retain the above copyright notice, this list - of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, this list - of conditions and the following disclaimer in the documentation and/or other - materials provided with the distribution. - - Neither the name of the Canberra Institute of Technology nor the names of its - contributors may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - - - package core.protocolsuite.tcp_ip; --- 2,30 ---- *************** *** 62,67 **** import core.TransportLayerException; - - /** --- 32,35 ---- *************** *** 86,115 **** * that's why TCP_packet as well as UDP_packet extends IP_packet */ ! private int TCP_srcPort; ! ! private int TCP_destPort; ! ! private int TCP_MessageLength; ! ! private static final int RESERVED = 0; //not used ! ! private int sequence_number; //very very important field. It's value is used as an unique ID of each TCP_packet ! ! private int acknowledgment_number; //important field as well ;) ! ! private boolean flags[] = {false,false,false,false,false,false}; /* URG, ACK, PSH, RST, SYN, FIN */ ! ! private int TCP_window; //for future developing :) ! ! private Object URG_pointer; //for future developing :) ! ! private String TCP_message; ! ! private static final int PTCL = 6; //see RFC :) ! ! private static final int CHECK_SUM = 1; //for future developing :) ! ! private static final int HEAD_LENGTH = 22; //TCP header is 22 bytes ! private static final int MAX_LENGTH = 65535; //bytes will be maximum length --- 54,70 ---- * that's why TCP_packet as well as UDP_packet extends IP_packet */ ! private int TCP_srcPort; ! private int TCP_destPort; ! private int TCP_MessageLength; ! private static final int RESERVED = 0; //not used ! private int sequence_number; //very very important field. It's value is used as an unique ID of each TCP_packet ! private int acknowledgment_number; //important field as well ;) ! private boolean flags[] = {false,false,false,false,false,false}; /* URG, ACK, PSH, RST, SYN, FIN */ ! private int TCP_window; ! //private Object URG_pointer; //for future developing :) ! private String TCP_message; ! private static final int PTCL = 6; //see RFC :) ! private static final int CHECK_SUM = 1; //for future developing :) ! private static final int HEAD_LENGTH = 22; //TCP header is 22 bytes private static final int MAX_LENGTH = 65535; //bytes will be maximum length *************** *** 126,131 **** */ ! public TCP_packet(String inDestIPAddress, String inSourceIPAddress, int indestPort, int insrcPort) ! { super (inDestIPAddress); this.setSourceIPAddress(inSourceIPAddress); --- 81,85 ---- */ ! public TCP_packet(String inDestIPAddress, String inSourceIPAddress, int indestPort, int insrcPort){ super (inDestIPAddress); this.setSourceIPAddress(inSourceIPAddress); *************** *** 135,138 **** --- 89,106 ---- TCP_message = ""; } + + public TCP_packet(TCP_packet pack){ + super(pack.getDestIPAddress()); + setSourceIPAddress(pack.getSourceIPAddress()); + TCP_srcPort = pack.TCP_srcPort; + TCP_destPort = pack.TCP_destPort; + TCP_MessageLength = pack.TCP_MessageLength; + sequence_number = pack.sequence_number; + acknowledgment_number = pack.acknowledgment_number; + for(int i=0; i<flags.length; i++) + flags[i] = pack.flags[i]; + TCP_window = pack.TCP_window; + TCP_message = pack.TCP_message; + } /** *************** *** 444,447 **** --- 412,419 ---- flags[5]=inflg_val; } + + public Object clone(){ + return new TCP_packet(this); + } }//EOF Index: jnSession.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/jnSession.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** jnSession.java 18 Sep 2007 22:29:46 -0000 1.1 --- jnSession.java 21 Sep 2007 22:42:31 -0000 1.2 *************** *** 23,26 **** --- 23,30 ---- } + public jnSession(int sock){ + this.sock = sock; + } + public int getSocket(){ return sock; Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** Udp.java 18 Sep 2007 22:29:46 -0000 1.36 --- Udp.java 21 Sep 2007 22:42:31 -0000 1.37 *************** *** 60,85 **** public class Udp implements Serializable ! { ! ! /* ! * UDP_HashTableElement.java ! * ! * Created on 18 November 2005, 21:09 ! */ ! ! /** ! * @author gift (sourceforge.net user) ! * @version v0.10, 18 Nov 2005 ! */ ! public class UDP_HashTableElement ! { ! public byte PortStatus=0; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public Object application=null; //points to application that listens to this port | provided PortStatus==1 ! public String connectedtoIP=""; //contains IP of the other connected computer | provided PortStatus==2 ! public int connectedtoPort=0; //contains port number of the other connected computer | provided PortStatus==2 ! } ! private Hashtable sessionTable = new Hashtable(); private ProtocolStack mParentStack; /*statistic block*/ --- 60,67 ---- public class Udp implements Serializable ! { private Hashtable sessionTable = new Hashtable(); private ProtocolStack mParentStack; + private socketLayer mSL; /*statistic block*/ *************** *** 92,96 **** private static final int PORT_INIT = -1; //used in ListenPort && AlreadyListens - private socketLayer mSL; /** --- 74,77 ---- *************** *** 102,106 **** public Udp(ProtocolStack inParentStack, socketLayer inSL) { - //int i; mParentStack = inParentStack; mSL = inSL; --- 83,86 ---- *************** *** 192,196 **** if(sessionTable.get(jnSocket.genUDPkey(mSL.get_socket(sock).src_port)) == null){ // we should reserve port for it ! ReserveFreePort(sock); mSL.get_socket(sock).src_IP = mParentStack.getSrcIP(); } --- 172,176 ---- if(sessionTable.get(jnSocket.genUDPkey(mSL.get_socket(sock).src_port)) == null){ // we should reserve port for it ! reserveFreePort(sock); mSL.get_socket(sock).src_IP = mParentStack.getSrcIP(); } *************** *** 229,233 **** UDP_Info.setDescription("UDP sending error: \""+ e.toString() + "\"."); Simulation.addLayerInfo(UDP_Info); ! ClosePort(sock); //*TODO*: here we shall put some layerinfo for TransportException } catch (TransportLayerException te) --- 209,213 ---- UDP_Info.setDescription("UDP sending error: \""+ e.toString() + "\"."); Simulation.addLayerInfo(UDP_Info); ! closePort(sock); //*TODO*: here we shall put some layerinfo for TransportException } catch (TransportLayerException te) *************** *** 245,249 **** // if application tries to send, but no port binded, do it now.. ! public void ReserveFreePort(int sock) throws TransportLayerException { String sessionID; --- 225,229 ---- // if application tries to send, but no port binded, do it now.. ! public void reserveFreePort(int sock) throws TransportLayerException { String sessionID; *************** *** 252,256 **** ! UDP_session Elm = new UDP_session(); // check if socket already busy --- 232,236 ---- ! UDP_session Elm; // check if socket already busy *************** *** 278,285 **** { Reserved=true; ! Elm = new UDP_session(); ! Elm.sock = sock; mSL.get_socket(sock).src_port = number; sessionTable.put(jnSocket.genUDPkey(number),Elm); LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); --- 258,265 ---- { Reserved=true; ! Elm = new UDP_session(sock); mSL.get_socket(sock).src_port = number; sessionTable.put(jnSocket.genUDPkey(number),Elm); + LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); *************** *** 300,340 **** // bind port to socket ! public void BindPort(int sock_num, int in_Port) throws TransportLayerException { int lsPort=PORT_INIT; if ( mSL.get_socket(sock_num).src_port == 0 ) ! { if (in_Port>=0 && in_Port<=65535) ! { ! // UDP_session Elm = null; ! // ! // if ( (Elm =(UDP_session)sessionTable.get(jnSocket.genUDPkey(inPort))) !=null ) ! // { ! // switch(Elm.PortStatus) ! // { ! // case 0: //port is free => update such a record in hashtable ! // Elm.PortStatus=1; ! // Elm.sock = sock_num; ! // mSL.get_socket(sock_num).src_port = in_Port; ! // break; ! // case 1: // port is being listened to by whom? ! // if (sock_num==Elm.sock) ! // { ! // throw new TransportLayerException("error: already binded to port "+ inPort +"!"); ! // } else throw new TransportLayerException("error: port "+ inPort +" is binded by another application! Can bind only to free ports." ); ! // default: //unknown port status ! // throw new TransportLayerException("error: unknown port status! Port "+ inPort +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! // } ! // ! // } else ! // { ! //create such a record in hashtable ! UDP_session newElm = new UDP_session(); ! newElm.sock = sock_num; ! mSL.get_socket(sock_num).src_port = in_Port; ! ! sessionTable.put(jnSocket.genUDPkey(in_Port),newElm); //hash table update ! // } LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); --- 280,296 ---- // bind port to socket ! public void bindPort(int sock_num, int in_Port) throws TransportLayerException { int lsPort=PORT_INIT; if ( mSL.get_socket(sock_num).src_port == 0 ) ! { if (in_Port>=0 && in_Port<=65535) ! { ! //create such a record in hashtable ! UDP_session newElm = new UDP_session(sock_num); ! mSL.get_socket(sock_num).src_port = in_Port; ! sessionTable.put(jnSocket.genUDPkey(in_Port),newElm); //hash table update ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); *************** *** 345,355 **** } else // { ! throw new TransportLayerException("error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); } ! } else // ! { ! if (mSL.get_socket(sock_num).src_port==in_Port) throw new TransportLayerException("error: can not double listen to port "+ in_Port +"! Server is already listening to this port"); ! throw new TransportLayerException("error: can not listen to port "+ in_Port +"! Already listening to port " + lsPort); ! } } --- 301,311 ---- } else // { ! throw new TransportLayerException("UDP error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); } ! } else // ! { ! if (mSL.get_socket(sock_num).src_port==in_Port) throw new TransportLayerException("error: can not double listen to port "+ in_Port +"! Server is already listening to this port"); ! throw new TransportLayerException("UDP error: can not listen to port "+ in_Port +"! Already listening to port " + lsPort); ! } } *************** *** 363,367 **** * @see TransportLayerException */ ! public void ClosePort(int sock) throws TransportLayerException //changes port status from 1 (listen) or (see proc ;) to 0 (free) { UDP_session Elm=null; --- 319,323 ---- * @see TransportLayerException */ ! public void closePort(int sock) throws TransportLayerException //changes port status from 1 (listen) or (see proc ;) to 0 (free) { UDP_session Elm=null; Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** ProtocolStack.java 16 Sep 2007 19:38:04 -0000 1.55 --- ProtocolStack.java 21 Sep 2007 22:42:31 -0000 1.56 *************** *** 164,173 **** mICMPprotocol = new ICMP(this); - mTCPprotocol = new Tcp(this); //gift (sourceforge.net user) 25 Nov 2005 - mSL = new socketLayer(this); mUDPprotocol = new Udp(this, mSL); //gift (sourceforge.net user) 17 Nov 2005 --- 164,173 ---- mICMPprotocol = new ICMP(this); mSL = new socketLayer(this); mUDPprotocol = new Udp(this, mSL); //gift (sourceforge.net user) 17 Nov 2005 + mTCPprotocol = new Tcp(this, mSL); //gift (sourceforge.net user) 25 Nov 2005 + *************** *** 184,188 **** public void initNAT(){ ! mTCPprotocol = new Tcp(this); //gift (sourceforge.net user) 25 Nov 2005 mSL = new socketLayer(this); mUDPprotocol = new Udp(this, mSL); //gift (sourceforge.net user) 17 Nov 2005 --- 184,188 ---- public void initNAT(){ ! mTCPprotocol = new Tcp(this, mSL); //gift (sourceforge.net user) 25 Nov 2005 mSL = new socketLayer(this); mUDPprotocol = new Udp(this, mSL); //gift (sourceforge.net user) 17 Nov 2005 *************** *** 216,249 **** public void sendPacket(IP_packet inPacket) throws LowLinkException, CommunicationException{ ! ! String destMAC = null; ! String GatewayAddress = null; - String outInterface[] = new String[2]; - if(!IPV4Address.validateDecIP(inPacket.mDestIPAddress)){ throw new CommunicationException("Packet dropped host unreachable: " + inPacket.mDestIPAddress); } - try{ - - outInterface = mIPprotocol.router(inPacket.getDestIPAddress()); ! ! try{ ! if(outInterface[0] == null) - { - try{ ! ! //Create layer info ! LayerInfo protocolInfo = new LayerInfo(getClass().getName()); - protocolInfo.setObjectName(getParentNodeName()); - if(!(inPacket instanceof ARP_packet) && !(inPacket instanceof ICMP_packet)) protocolInfo.setDataType("IP_Packet"); --- 216,234 ---- public void sendPacket(IP_packet inPacket) throws LowLinkException, CommunicationException{ ! String destMAC = null; String GatewayAddress = null; String outInterface[] = new String[2]; if(!IPV4Address.validateDecIP(inPacket.mDestIPAddress)){ throw new CommunicationException("Packet dropped host unreachable: " + inPacket.mDestIPAddress); } try{ outInterface = mIPprotocol.router(inPacket.getDestIPAddress()); ! try{ if(outInterface[0] == null) { try{ ! //Create layer info LayerInfo protocolInfo = new LayerInfo(getClass().getName()); protocolInfo.setObjectName(getParentNodeName()); if(!(inPacket instanceof ARP_packet) && !(inPacket instanceof ICMP_packet)) protocolInfo.setDataType("IP_Packet"); *************** *** 252,332 **** protocolInfo.setLayer("Network"); ! ! protocolInfo.setDescription("No network interface subnet masks match default gateway provided. " + ! ! " Unabled to send"); ! Simulation.addLayerInfo(protocolInfo); - }catch(NullPointerException e){ System.out.println("ProtocolStack.java: SendPacket 1 " + e.toString()); } - } ! ! else ! ! { ! try{ ! ! String sourceIP = mIPprotocol.getIPAddress(outInterface[0]); ! ! inPacket.setSourceIPAddress(sourceIP); ! ! ! ! // test if on local of remote network ! ! if(outInterface[1]==null){ ! ! destMAC = mARPprotocol.getMACAddress(inPacket.getDestIPAddress(),outInterface[0]); ! ! }else{ ! //String GatewayAddress = mIPprotocol.getDefaultGateway(); ! GatewayAddress = mIPprotocol.getGateway(inPacket.getDestIPAddress()); - String outIface = mIPprotocol.getInterface(inPacket.getDestIPAddress()); - if(outIface!=null) outInterface[0] = outIface; if(GatewayAddress.contains("*")) GatewayAddress = inPacket.getDestIPAddress(); ! ! destMAC = mARPprotocol.getMACAddress(GatewayAddress,outInterface[0]); ! ! } ! ! ! ! if(destMAC == null){ //if there is no matching entry in arp throw an error ! ! throw new CommunicationException("Unable to Resolve Destination MAC Address"); ! ! } ! ! ! ! //Create layer info ! LayerInfo protocolInfo = new LayerInfo(getClass().getName()); ! protocolInfo.setObjectName(getParentNodeName()); ! ! if(!(inPacket instanceof ARP_packet) && !(inPacket instanceof ICMP_packet)) ! protocolInfo.setDataType("IP_Packet"); ! else ! protocolInfo.setDataType(trimClassName(inPacket.getClass().getName())); ! protocolInfo.setLayer("Network"); ! if(GatewayAddress==null) GatewayAddress=inPacket.getDestIPAddress(); ! ! protocolInfo.setDescription("Sending packet from ProtocolStack (to " + GatewayAddress + ")."); ! ! ! Simulation.addLayerInfo(protocolInfo); ! }catch(NullPointerException e){ System.out.println("ProtocolStack.java: SendPacket 1 " + e.toString()); } --- 237,284 ---- protocolInfo.setLayer("Network"); ! protocolInfo.setDescription("No network interface subnet masks match default gateway provided. " + " Unabled to send"); Simulation.addLayerInfo(protocolInfo); }catch(NullPointerException e){ System.out.println("ProtocolStack.java: SendPacket 1 " + e.toString()); } } ! else{ try{ ! String sourceIP = mIPprotocol.getIPAddress(outInterface[0]); ! inPacket.setSourceIPAddress(sourceIP); ! // test if on local of remote network ! if(outInterface[1]==null){ ! destMAC = mARPprotocol.getMACAddress(inPacket.getDestIPAddress(),outInterface[0]); ! } ! else{ ! //String GatewayAddress = mIPprotocol.getDefaultGateway(); GatewayAddress = mIPprotocol.getGateway(inPacket.getDestIPAddress()); String outIface = mIPprotocol.getInterface(inPacket.getDestIPAddress()); if(outIface!=null) outInterface[0] = outIface; if(GatewayAddress.contains("*")) GatewayAddress = inPacket.getDestIPAddress(); ! destMAC = mARPprotocol.getMACAddress(GatewayAddress,outInterface[0]); ! } ! if(destMAC == null){ //if there is no matching entry in arp throw an error ! throw new CommunicationException("Unable to Resolve Destination MAC Address"); ! } ! //Create layer info ! LayerInfo protocolInfo = new LayerInfo(getClass().getName()); ! protocolInfo.setObjectName(getParentNodeName()); ! if(!(inPacket instanceof ARP_packet) && !(inPacket instanceof ICMP_packet)) ! protocolInfo.setDataType("IP_Packet"); ! else ! protocolInfo.setDataType(trimClassName(inPacket.getClass().getName())); ! protocolInfo.setLayer("Network"); ! if(GatewayAddress==null) GatewayAddress=inPacket.getDestIPAddress(); ! protocolInfo.setDescription("Sending packet from ProtocolStack (to " + GatewayAddress + ")."); ! Simulation.addLayerInfo(protocolInfo); ! } ! catch(NullPointerException e){ System.out.println("ProtocolStack.java: SendPacket 1 " + e.toString()); } *************** *** 1680,1702 **** */ ! public int reserveTCPPort(Object application, String inDestIPAddress, int indestPort) throws InvalidNetworkLayerDeviceException, TransportLayerException, CommunicationException ! { ! ! if(IPV4Address.validateDecIP(inDestIPAddress)) ! { ! ! //lets get first network interface name ! String FirstInterfaceName; ! Node temp = (Node)mParentNode; ! FirstInterfaceName = temp.getFirstInterfaceName(); ! ! if (FirstInterfaceName!=null) ! { ! return mTCPprotocol.ReservePort(application,inDestIPAddress,indestPort); ! } else ! throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! }else ! throw new CommunicationException("Packet dropped host unreachable: " + inDestIPAddress); ! } --- 1632,1654 ---- */ ! // public int reserveTCPPort(Object application, String inDestIPAddress, int indestPort) throws InvalidNetworkLayerDeviceException, TransportLayerException, CommunicationException ! // { ! // ! // if(IPV4Address.validateDecIP(inDestIPAddress)) ! // { ! // ! // //lets get first network interface name ! // String FirstInterfaceName; ! // Node temp = (Node)mParentNode; ! // FirstInterfaceName = temp.getFirstInterfaceName(); ! // ! // if (FirstInterfaceName!=null) ! // { ! // return mTCPprotocol.ReservePort(application,inDestIPAddress,indestPort); ! // } else ! // throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! // }else ! // throw new CommunicationException("Packet dropped host unreachable: " + inDestIPAddress); ! // } *************** *** 1714,1728 **** public void CloseTCP(Object application) throws TransportLayerException { ! try { ! mTCPprotocol.ClosePort(application); ! } catch (TransportLayerException te) ! { ! /*LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Protocol"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("TCP port closing: \""+ te.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); */ ! } } --- 1666,1680 ---- public void CloseTCP(Object application) throws TransportLayerException { ! // try { ! // mTCPprotocol.ClosePort(application); ! // } catch (TransportLayerException te) ! // { ! // /*LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! // TCP_Info.setObjectName(getParentNodeName()); ! // TCP_Info.setDataType("TCP Protocol"); ! // TCP_Info.setLayer("Transport"); ! // TCP_Info.setDescription("TCP port closing: \""+ te.toString() + "\"."); ! // Simulation.addLayerInfo(TCP_Info); */ ! // } } *************** *** 1738,1742 **** public void FreeTCPApplication(Object application) throws TransportLayerException { ! mTCPprotocol.FreeApplication(application); } --- 1690,1694 ---- public void FreeTCPApplication(Object application) throws TransportLayerException { ! // mTCPprotocol.FreeApplication(application); } *************** *** 1753,1775 **** public void ListenTCP(Object application, int inPort) throws TransportLayerException { ! try{ ! mTCPprotocol.ListenPort(application,inPort); ! ! LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Application"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("Application is now listening on port " + inPort + "."); ! Simulation.addLayerInfo(TCP_Info); ! ! } catch (TransportLayerException te) ! { ! LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Application"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("Error: TCP port listening: \""+ te.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); ! } } --- 1705,1727 ---- public void ListenTCP(Object application, int inPort) throws TransportLayerException { ! // try{ ! // mTCPprotocol.ListenPort(application,inPort); ! // ! // LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! // TCP_Info.setObjectName(getParentNodeName()); ! // TCP_Info.setDataType("TCP Application"); ! // TCP_Info.setLayer("Transport"); ! // TCP_Info.setDescription("Application is now listening on port " + inPort + "."); ! // Simulation.addLayerInfo(TCP_Info); ! // ! // } catch (TransportLayerException te) ! // { ! // LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! // TCP_Info.setObjectName(getParentNodeName()); ! // TCP_Info.setDataType("TCP Application"); ! // TCP_Info.setLayer("Transport"); ! // TCP_Info.setDescription("Error: TCP port listening: \""+ te.toString() + "\"."); ! // Simulation.addLayerInfo(TCP_Info); ! // } } *************** *** 1794,1822 **** public int ConnectTCP(Object application, String inDestIPAddress, int indestPort) throws LowLinkException, CommunicationException, TransportLayerException { ! int rval; ! int ack_num=-1; ! String msg=""; ! boolean flags[]={false,false,false,false,true,false}; /* URG, ACK, PSH, RST, !SYN!, FIN */ ! rval=mTCPprotocol.ReservePort(application, inDestIPAddress, indestPort); ! byte code=0; //no status ! ! if (sendTCPSegment(application, msg, flags,ack_num)) ! { ! do ! { code = mTCPprotocol.getStatus(rval); } ! while (code==1); ! ! if(code==0 || code==3) //0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error ! { ! mTCPprotocol.FreeApplication(application); ! return -1; ! } else ! ! return rval; ! ! }else{ ! mTCPprotocol.FreeApplication(application); ! return -1; ! } } --- 1746,1775 ---- public int ConnectTCP(Object application, String inDestIPAddress, int indestPort) throws LowLinkException, CommunicationException, TransportLayerException { ! // int rval; ! // int ack_num=-1; ! // String msg=""; ! // boolean flags[]={false,false,false,false,true,false}; /* URG, ACK, PSH, RST, !SYN!, FIN */ ! // rval=mTCPprotocol.ReservePort(application, inDestIPAddress, indestPort); ! // byte code=0; //no status ! // ! // if (sendTCPSegment(application, msg, flags,ack_num)) ! // { ! // do ! // { code = mTCPprotocol.getStatus(rval); } ! // while (code==1); ! // ! // if(code==0 || code==3) //0 - no status; 1 - is being connected; 2 - is connected; 3 - connection error ! // { ! // mTCPprotocol.FreeApplication(application); ! // return -1; ! // } else ! // ! // return rval; ! // ! // }else{ ! // mTCPprotocol.FreeApplication(application); ! // return -1; ! // } ! return -1; } *************** *** 1837,1843 **** public void SendTCP(Object application, String inTCPMessage, int acknow_numb) throws LowLinkException, CommunicationException { ! boolean flags[]={false,true,false,false,false,false}; /* URG, !ACK!, PSH, RST, SYN, FIN */ ! if (acknow_numb==-1) flags[1]=false; ! sendTCPSegment(application, inTCPMessage, flags, acknow_numb); } --- 1790,1796 ---- public void SendTCP(Object application, String inTCPMessage, int acknow_numb) throws LowLinkException, CommunicationException { ! // boolean flags[]={false,true,false,false,false,false}; /* URG, !ACK!, PSH, RST, SYN, FIN */ ! // if (acknow_numb==-1) flags[1]=false; ! // sendTCPSegment(application, inTCPMessage, flags, acknow_numb); } *************** *** 1858,1865 **** public void FinalizeTCP(Object application) throws LowLinkException, CommunicationException { ! int ack_num=-1; ! String msg="EMPTY STRING the problem is in FinalizeTCP"; ! boolean flags[]={false,false,false,false,false,true}; /* URG, ACK, PSH, RST, SYN, !FIN! */ ! sendTCPSegment(application, msg, flags,ack_num); } --- 1811,1818 ---- public void FinalizeTCP(Object application) throws LowLinkException, CommunicationException { ! // int ack_num=-1; ! // String msg="EMPTY STRING the problem is in FinalizeTCP"; ! // boolean flags[]={false,false,false,false,false,true}; /* URG, ACK, PSH, RST, SYN, !FIN! */ ! // sendTCPSegment(application, msg, flags,ack_num); } *************** *** 1880,1942 **** */ ! public boolean sendTCPSegment(Object application, String inTCPMessage, boolean flags[], int acknow_num) throws LowLinkException, CommunicationException ! { ! String FirstInterfaceName; ! String DestIPAddress; ! String SourceIPAddress; ! int srcPort; ! int destPort; ! ! //lets get first network interface name ! Node temp = (Node)mParentNode; ! FirstInterfaceName = temp.getFirstInterfaceName(); ! ! try{ ! //let's get a reserved local port number for this application ! srcPort = (application != null) ? mTCPprotocol.getApplicationLocalPortNumber(application) : 0 ; ! //and destination IP of the other host ! DestIPAddress=mTCPprotocol.getApplicationDestIP(srcPort); ! //and destination port of the other host ! destPort=mTCPprotocol.getApplicationDestPortNumber(srcPort); ! ! if (FirstInterfaceName!=null) ! { ! if(IPV4Address.validateDecIP(DestIPAddress)) ! { ! //let's get first interface IP address ! SourceIPAddress=getIPAddress(FirstInterfaceName); ! TCP_packet tosend = mTCPprotocol.getTCPPacket_tosend(DestIPAddress,SourceIPAddress,destPort,srcPort,inTCPMessage,flags,acknow_num); ! //and sending out ;) ! sendPacket(tosend); ! }else ! throw new CommunicationException("Packet dropped host unreachable: " + DestIPAddress); ! } //else ! //throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! }catch(Exception e){ ! System.out.println("catch..."); ! //try { ! System.out.println("should never be here..."); ! LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Packet"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("TCP sending error: \""+ e.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); ! Error.Report(e); ! return false; ! /* mTCPprotocol.ClosePort(application); ! } catch (TransportLayerException te) ! { ! LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! TCP_Info.setObjectName(getParentNodeName()); ! TCP_Info.setDataType("TCP Packet"); ! TCP_Info.setLayer("Transport"); ! TCP_Info.setDescription("TCP port freeing: \""+ te.toString() + "\"."); ! Simulation.addLayerInfo(TCP_Info); ! } */ ! ! } ! return true; ! } /** --- 1833,1895 ---- */ ! // public boolean sendTCPSegment(Object application, String inTCPMessage, boolean flags[], int acknow_num) throws LowLinkException, CommunicationException ! // { ! // String FirstInterfaceName; ! // String DestIPAddress; ! // String SourceIPAddress; ! // int srcPort; ! // int destPort; ! // ! // //lets get first network interface name ! // Node temp = (Node)mParentNode; ! // FirstInterfaceName = temp.getFirstInterfaceName(); ! // ! // try{ ! // //let's get a reserved local port number for this application ! // srcPort = (application != null) ? mTCPprotocol.getApplicationLocalPortNumber(application) : 0 ; ! // //and destination IP of the other host ! // DestIPAddress=mTCPprotocol.getApplicationDestIP(srcPort); ! // //and destination port of the other host ! // destPort=mTCPprotocol.getApplicationDestPortNumber(srcPort); ! // ! // if (FirstInterfaceName!=null) ! // { ! // if(IPV4Address.validateDecIP(DestIPAddress)) ! // { ! // //let's get first interface IP address ! // SourceIPAddress=getIPAddress(FirstInterfaceName); ! // TCP_packet tosend = mTCPprotocol.getTCPPacket_tosend(DestIPAddress,SourceIPAddress,destPort,srcPort,inTCPMessage,flags,acknow_num); ! // //and sending out ;) ! // sendPacket(tosend); ! // }else ! // throw new CommunicationException("Packet dropped host unreachable: " + DestIPAddress); ! // } //else ! // //throw new InvalidNetworkLayerDeviceException("Network interface unavailable on host \"" + temp.getName() +"\"."); ! // }catch(Exception e){ ! // System.out.println("catch..."); ! // //try { ! // System.out.println("should never be here..."); ! // LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! // TCP_Info.setObjectName(getParentNodeName()); ! // TCP_Info.setDataType("TCP Packet"); ! // TCP_Info.setLayer("Transport"); ! // TCP_Info.setDescription("TCP sending error: \""+ e.toString() + "\"."); ! // Simulation.addLayerInfo(TCP_Info); ! // Error.Report(e); ! // return false; ! // /* mTCPprotocol.ClosePort(application); ! // } catch (TransportLayerException te) ! // { ! // LayerInfo TCP_Info = new LayerInfo(getClass().getName()); ! // TCP_Info.setObjectName(getParentNodeName()); ! // TCP_Info.setDataType("TCP Packet"); ! // TCP_Info.setLayer("Transport"); ! // TCP_Info.setDescription("TCP port freeing: \""+ te.toString() + "\"."); ! // Simulation.addLayerInfo(TCP_Info); ! // } */ ! // ! // } ! // return true; ! // } /** *************** *** 1958,1988 **** */ ! public TCP_packet getTCPSegment_clone(Object application, String inTCPMessage, boolean flags[], int acknow_num) throws LowLinkException, CommunicationException, TransportLayerException ! { ! String FirstInterfaceName; ! String DestIPAddress; ! String SourceIPAddress; ! int srcPort; ! int destPort; ! ! //lets get first network interface name ! Node temp = (Node)mParentNode; ! FirstInterfaceName = temp.getFirstInterfaceName(); ! ! // try{ ! //let's get a reserved local port number for this application ! srcPort=mTCPprotocol.getApplicationLocalPortNumber(application); ! //and destination IP of the other host ! DestIPAddress=mTCPprotocol.getApplicationDestIP(srcPort); ! //and destination port of the other host ! destPort=mTCPprotocol.getApplicationDestPortNumber(srcPort); ! ! ! SourceIPAddress=getIPAddress(FirstInterfaceName); ! TCP_packet tosend = mTCPprotocol.getTCPPacket_clone(DestIPAddress,SourceIPAddress,destPort,srcPort,inTCPMessage,flags,acknow_num); ! return tosend; ! ! // }catch(Exception e){} ! } --- 1911,1941 ---- */ ! // public TCP_packet getTCPSegment_clone(Object application, String inTCPMessage, boolean flags[], int acknow_num) throws LowLinkException, CommunicationException, TransportLayerException ! // { ! // String FirstInterfaceName; ! // String DestIPAddress; ! // String SourceIPAddress; ! // int srcPort; ! // int destPort; ! // ! // //lets get first network interface name ! // Node temp = (Node)mParentNode; ! // FirstInterfaceName = temp.getFirstInterfaceName(); ! // ! // // try{ ! // //let's get a reserved local port number for this application ! // srcPort=mTCPprotocol.getApplicationLocalPortNumber(application); ! // //and destination IP of the other host ! // DestIPAddress=mTCPprotocol.getApplicationDestIP(srcPort); ! // //and destination port of the other host ! // destPort=mTCPprotocol.getApplicationDestPortNumber(srcPort); ! // ! // ! // SourceIPAddress=getIPAddress(FirstInterfaceName); ! // TCP_packet tosend = mTCPprotocol.getTCPPacket_clone(DestIPAddress,SourceIPAddress,destPort,srcPort,inTCPMessage,flags,acknow_num); ! // return tosend; ! // ! // // }catch(Exception e){} ! // } Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.89 retrieving revision 1.90 diff -C2 -d -r1.89 -r1.90 *** Tcp.java 18 Sep 2007 22:29:46 -0000 1.89 --- Tcp.java 21 Sep 2007 22:42:31 -0000 1.90 *************** *** 1,87 **** ! /* ! ! Java Network Simulator (javaNetSim) ! Copyright (c) 2006, 2005, Ice Team; All rights reserved. ! Copyright (c) 2004, jFirewallSim development team; All rights reserved. ! ! ! [...3177 lines suppressed...] + // TCP_packet to_buff=new TCP_packet(Packet.getDestIPAddress(), Packet.getSourceIPAddress(), Packet.get_destPort(), Packet.get_srcPort()); + // try { + // to_buff.setTCP_message(Packet.getTCP_message()); + // } catch(TransportLayerException e) {} //will never be thrown from here ;) + // + // to_buff.set_sequence_number(Packet.get_sequence_number()); + // to_buff.set_acknowledgment_number(Packet.get_acknowledgment_number()); + // + // to_buff.set_URG_flag(Packet.get_URG_flag()); + // to_buff.set_ACK_flag(Packet.get_ACK_flag()); + // to_buff.set_PSH_flag(Packet.get_PSH_flag()); + // to_buff.set_RST_flag(Packet.get_RST_flag()); + // to_buff.set_SYN_flag(Packet.get_SYN_flag()); + // to_buff.set_FIN_flag(Packet.get_FIN_flag()); + // + // Elm.OutputBuffer.put(new Integer(Packet.get_sequence_number()), to_buff); + // } + // } + // } //EOF Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** Echo_tcp.java 18 Sep 2007 22:29:46 -0000 1.31 --- Echo_tcp.java 21 Sep 2007 22:42:31 -0000 1.32 *************** *** 7,25 **** package core.protocolsuite.tcp_ip; - import core.TransportLayerException; - import core.InvalidNetworkLayerDeviceException; - import core.CommunicationException; - import core.LowLinkException; - import core.LayerInfo; - import core.Packet; - import core.Error; - import core.Simulation; --- 7,17 ---- *************** *** 34,40 **** private int counts; private int crecv; ! private long ! utc1; ! public int recieved; /** Creates a new instance of Echo */ --- 26,33 ---- private int counts; private int crecv; ! private long utc1; ! public int recieved; ! ! private int sock; /** Creates a new instance of Echo */ *************** *** 42,45 **** --- 35,39 ---- super(inParentStack, listenPort, appType, UID); counts = 0; + sock = mParentStack.SL().socket(jnSocket.TCP_socket, this); } *************** *** 53,61 **** recieved = 0; try{ ! if(appType != 0) mParentStack.ListenTCP(this, listenPort); ! } catch (TransportLayerException e) ! { ! } } --- 47,59 ---- recieved = 0; try{ ! if(appType == 1){ ! mParentStack.SL().bind(sock, mParentStack.getSrcIP(), listenPort); ! } ! }catch (TransportLayerException e){ ! e.toString(); ! }catch (LowLinkException e){ ! e.toString(); } + //mParentStack.SL().listen(sock); } *************** *** 73,83 **** public void Close() throws TransportLayerException { ! mParentStack.CloseTCP(this); recieved = 0; } public void Free() throws TransportLayerException{ ! mParentStack.FreeTCPApplication(this); ! recieved = 0; } --- 71,81 ---- public void Close() throws TransportLayerException { ! mParentStack.SL().close(sock); recieved = 0; } public void Free() throws TransportLayerException{ ! Close(); ! mParentStack.SL().free(sock); } *************** *** 103,114 **** Simulation.addLayerInfo(protInfo2); ! do ! { ! ConnectionAttempts--; ! clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); ! } ! while (ConnectionAttempts>0 && clientPort==-1); ! if (clientPort>-1) return true; else return false; } --- 101,113 ---- Simulation.addLayerInfo(protInfo2); ! // do ! // { ! // ConnectionAttempts--; ! // clientPort = mParentStack.ConnectTCP(this, sdHost, sdPort); ! // } ! // while (ConnectionAttempts>0 && clientPort==-1); ! boolean isconnected = mParentStack.TCP().connect(sock, sdHost, sdPort); ! return isconnected; } *************** *** 121,152 **** public void OnConnect(int sock){ } - - /** - * This method disconnects from server. - * @author key - * @version v0.01 - */ - - public void Disconnect() throws TransportLayerException, LowLinkException{ - try { - mParentStack.FinalizeTCP(this); //will close client connection - }catch(Exception e){ - ///*TODO*: here to catch - } - - LayerInfo protInfo3 = new LayerInfo(getClass().getName()); - protInfo3.setObjectName(mParentStack.getParentNodeName()); - protInfo3.setDataType("Echo Protocol Data"); - protInfo3.setLayer("Application "); - if(appType==0){ - protInfo3.setDescription("Application closing connection."); - }else{ - protInfo3.setDescription("Application closing connection. Now listening on " + listenPort + "."); - } - Simulation.addLayerInfo(protInfo3); - - mParentStack.CloseTCP(this); - //mParentStack.freeTCPPort(this); - } /** --- 120,123 ---- *************** *** 157,163 **** public void OnDisconnect(int sock) { ! try{ ! Listen(); ! }catch(Exception e){ LayerInfo protInfo = new LayerInfo(getClass().getName()); protInfo.setObjectName(mParentStack.getParentNodeName()); --- 128,134 ---- public void OnDisconnect(int sock) { ! try{ ! Listen(); ! }catch(Exception e){ LayerInfo protInfo = new LayerInfo(getClass().getName()); protInfo.setObjectName(mParentStack.getParentNodeName()); *************** *** 167,171 **** Simulation.addLayerInfo(protInfo); protInfo = null; ! } } --- 138,142 ---- Simulation.addLayerInfo(protInfo); protInfo = null; ! } } *************** *** 180,184 **** { ! mParentStack.SendTCP(this, Data,-1); //processing the protocol doings. --- 151,155 ---- { ! mParentStack.SL().write(sock, Data); //processing the protocol doings. *************** *** 218,223 **** if(this.counts==0){ ! ! Disconnect(); LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); --- 189,193 ---- if(this.counts==0){ ! mParentStack.SL().close(sock); LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); *************** *** 280,284 **** */ public void SendEcho(String Data, String Host, int port, int counts) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ! mParentStack.FreeTCPApplication(this); recieved = 0; --- 250,254 ---- */ public void SendEcho(String Data, String Host, int port, int counts) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ! mParentStack.SL().free(sock); recieved = 0; *************** *** 311,337 **** } } - - /** - * This method recieves source IP of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - */ - public void RecvIP(String IP) throws LowLinkException, TransportLayerException - { - - } - - /** - * This method recieves source port number of a packet - * @param data to receive - * @author gift (sourceforge.net user) - * @version v0.01 - */ - public void RecvPrt(int port_num) throws LowLinkException, TransportLayerException - { - - } - - } --- 281,283 ---- Index: UDP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/UDP_session.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** UDP_session.java 18 Sep 2007 22:29:46 -0000 1.1 --- UDP_session.java 21 Sep 2007 22:42:31 -0000 1.2 *************** *** 22,26 **** /** Creates a new instance of UDP_session */ ! public UDP_session() { } --- 22,27 ---- /** Creates a new instance of UDP_session */ ! public UDP_session(int sock) { ! super(sock); } Index: TCP_session.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/TCP_session.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TCP_session.java 18 Sep 2007 22:29:46 -0000 1.1 --- TCP_session.java 21 Sep 2007 22:42:31 -0000 1.2 *************** *** 10,13 **** --- 10,15 ---- package core.protocolsuite.tcp_ip; + import java.util.Hashtable; + /** * *************** *** 26,31 **** /*end of statistic block*/ /** Creates a new instance of TCP_session */ ! public TCP_session() { } --- 28,198 ---- /*end of statistic block*/ + public int seq_number=0; + public int last_passed=-1; //last sequence number value of the segment that has been passed upstairs + public static int Element_id = 0; + private int state = CLOSED; + + public static final int CLOSED = 0; + public static final int LISTEN = 1; + public static final int SYN_SENT = 2; + public static final int SYB_RCVD = 3; + public static final int ESTABLISHED = 4; + public static final int FIN_WAIT_1 = 5; + public static final int FIN_WAIT_2 = 6; + public static final int CLOSING = 7; + public static final int TIME_WAIT = 8; + public static final int CLOSE_WAIT = 9; + public static final int LAST_ACK = 10; + + /** + * Contains segments that will be resent in case no ACK for them will be received + * <p>Key: Sequence number of the segment that we are se... [truncated message content] |
From: QweR <qw...@us...> - 2007-09-21 22:42:38
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13173/guiUI Modified Files: MainScreen.java Log Message: first test version of TCP Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** MainScreen.java 16 Sep 2007 19:38:04 -0000 1.64 --- MainScreen.java 21 Sep 2007 22:42:32 -0000 1.65 *************** *** 56,126 **** import java.awt.BorderLayout; - import java.awt.*; - import java.awt.event.*; - import java.awt.Cursor; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; - import java.io.File; - import java.io.*; - import java.util.ArrayList; - import java.util.Date; - import java.util.Enumeration; - import java.io.FileInputStream; - import java.io.FileNotFoundException; - import java.io.FileOutputStream; - import java.io.IOException; - import java.io.ObjectInputStream; - import java.io.ObjectOutputStream; - import java.util.Hashtable; - import java.util.Vector; - import java.util.Iterator; - import java.util.Arrays; - import javax.imageio.*; - - import javax.swing.*; - import javax.swing.filechooser.FileFilter; - - import core.CommunicationException; - import core.LowLinkException; - import core.InvalidNetworkLayerDeviceException; - import core.InvalidNodeNameException; - import core.Simulation; - import core.Node; - import core.protocolsuite.tcp_ip.Route_entry; - import java.util.Timer; - import java.util.TimerTask; - import core.protocolsuite.tcp_ip.Echo; import core.protocolsuite.tcp_ip.Echo_tcp; --- 56,93 ---- |
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv29666/core/protocolsuite/tcp_ip Modified Files: Application.java Echo.java Echo_tcp.java ExternalProxyApp.java PosixTelnetClient.java SNMP.java Tcp.java Telnet_client.java Telnet_server.java Udp.java jnSocket.java socketLayer.java Added Files: TCP_session.java UDP_session.java jnSession.java Log Message: sessions was added partially Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Telnet_client.java 5 Sep 2006 21:04:36 -0000 1.9 --- Telnet_client.java 18 Sep 2007 22:29:46 -0000 1.10 *************** *** 46,50 **** */ public void Listen() throws TransportLayerException{ ! throw new TransportLayerException("Cannot bind port " + listenPort + "."); } --- 46,54 ---- */ public void Listen() throws TransportLayerException{ ! throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! } ! ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ ! } *************** *** 59,62 **** --- 63,73 ---- { if(!already_closed){ + mParentStack.CloseTCP(this); + already_closed = true; + } + } + + public void Free() throws TransportLayerException{ + if(!already_closed){ mParentStack.FreeTCPApplication(this); already_closed = true; *************** *** 73,77 **** */ ! public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; --- 84,88 ---- */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; *************** *** 96,102 **** * @version v0.01 */ ! public void Connected(String Host, int port){ ! sdHost = Host; ! sdPort = port; } --- 107,111 ---- * @version v0.01 */ ! public void OnConnect(int sock){ } *************** *** 107,115 **** */ ! public void DisconnectEvent(){ connected = false; printInfo("Client: receive disconnect event"); ! terminal.recvData("\nServer closed connection.\n"); ! terminal.recvData("\nQUIT"); // try{ // printInfo("Client: receive disconnect event"); --- 116,124 ---- */ ! public void OnDisconnect(int sock){ connected = false; printInfo("Client: receive disconnect event"); ! terminal.recvData("\r\nServer closed connection.\r\n"); ! terminal.recvData("\r\nQUIT"); // try{ // printInfo("Client: receive disconnect event"); *************** *** 183,188 **** printInfo("Client: Recieving message '" + Data + "' from server."); ! if(Data.compareTo("\nQUIT")==0) { ! System.out.println("\n\n\n-----------------------\nTelnet: RecvData: QUIT\n-------------------------------\n\n\n"); // connected = false; // Disconnect(); --- 192,197 ---- printInfo("Client: Recieving message '" + Data + "' from server."); ! if(Data.compareTo("\r\nQUIT")==0) { ! //System.out.println("\n\n\n-----------------------\nTelnet: RecvData: QUIT\n-------------------------------\n\n\n"); // connected = false; // Disconnect(); *************** *** 214,221 **** this.terminal = emul; ! if (ClientConnect(Host, port)) { ! SendData("\n"); //SendData("!"); //terminal.recvData("Connected!\n"); --- 223,230 ---- this.terminal = emul; ! if (Connect(Host, port)) { ! SendData("\r\n"); //SendData("!"); //terminal.recvData("Connected!\n"); Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** socketLayer.java 16 Sep 2007 19:39:35 -0000 1.1 --- socketLayer.java 18 Sep 2007 22:29:46 -0000 1.2 *************** *** 2,22 **** import java.io.Serializable; - import java.util.*; - import core.CommunicationException; - import core.LowLinkException; - import core.LayerInfo; - import core.Simulation; - import core.TransportLayerException; - import core.TransportLayerPortException; - import core.InvalidNetworkLayerDeviceException; - import core.protocolsuite.tcp_ip.ProtocolStack; /** --- 2,13 ---- *************** *** 29,34 **** int lastSock; - - /** Creates a new instance of socketLayer */ public socketLayer(ProtocolStack inParentStack) { --- 20,23 ---- *************** *** 80,83 **** --- 69,80 ---- } + public void recv(int sock, String data) throws LowLinkException, TransportLayerException{ + if(sock < lastSock){ + if(((jnSocket)sockTable.get(sock)).open_state == true){ + ((jnSocket)sockTable.get(sock)).app.RecvData(data); + } + } + } + public void recvFrom(int sock, String IP, int port, String data) throws LowLinkException, TransportLayerException{ if(sock < lastSock){ *************** *** 91,98 **** //DEPRECATED IN SOON ! ((jnSocket)sockTable.get(sock)).app.RecvIP(IP); ! ((jnSocket)sockTable.get(sock)).app.RecvPrt(port); //^^^^^^^^^^^^^^^^ ((jnSocket)sockTable.get(sock)).app.RecvData(data); } --- 88,96 ---- //DEPRECATED IN SOON ! //((jnSocket)sockTable.get(sock)).app.RecvIP(IP); ! //((jnSocket)sockTable.get(sock)).app.RecvPrt(port); //^^^^^^^^^^^^^^^^ + ((jnSocket)sockTable.get(sock)).app.OnConnect(sock); ((jnSocket)sockTable.get(sock)).app.RecvData(data); } *************** *** 112,115 **** ((jnSocket)sockTable.get(sock)).app = null; ((jnSocket)sockTable.get(sock)).open_state = false; ! } } --- 110,113 ---- ((jnSocket)sockTable.get(sock)).app = null; ((jnSocket)sockTable.get(sock)).open_state = false; ! } } Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Udp.java 16 Sep 2007 19:38:04 -0000 1.35 --- Udp.java 18 Sep 2007 22:29:46 -0000 1.36 *************** *** 1,108 **** /* - Java Firewall Simulator (jFirewallSim) - - Copyright (c) 2004, jFirewallSim development team All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, are - permitted provided that the following conditions are met: - - - Redistributions of source code must retain the above copyright notice, this list - of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, this list - of conditions and the following disclaimer in the documentation and/or other - materials provided with the distribution. - - Neither the name of the Canberra Institute of Technology nor the names of its - contributors may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ package core.protocolsuite.tcp_ip; - - import java.io.Serializable; - import java.util.*; - import core.CommunicationException; - import core.LowLinkException; - import core.LayerInfo; - import core.Simulation; - import core.TransportLayerException; - import core.TransportLayerPortException; - import core.InvalidNetworkLayerDeviceException; - import core.protocolsuite.tcp_ip.ProtocolStack; /** - * This UDP class is constructed in a way that it represents its real world cousin (the UDP protocol) as accurately - * as possible. - - * <P>This class contains methods which allow the transfer of packets to and from the lower layer. (Network Layer - IP - * only at this stage). During a packets stay in this class, UDP headers are added, removed and examined - * depending on wether the packet is in compilation or decompilation. During compilation, a packet is created, headers are added (all based - * on real world UDP specification) and the packet is passed onto NetworkLayer (IP). During decompilation - * UDP headers are removed and the data that was contained in the packet is passed onto the ProtocolStack. Relavent - * information about what is happening in this class is added to the LayerInfo object so that it can be displayed - * to the user in a clear and concise way.</P> - * - * @author james_nikolaidis - * @since 10/06/2004 - * @author gift (sourceforge.net user) * @since 17 Nov 2005 --- 1,57 ---- *************** *** 110,115 **** */ - - public class Udp implements Serializable { --- 59,62 ---- *************** *** 133,142 **** } ! public class UDP_session{ ! public byte PortStatus=0; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public int sock=-1; // socket... ! } ! ! private Hashtable PortTable = new Hashtable(); private ProtocolStack mParentStack; --- 80,84 ---- } ! private Hashtable sessionTable = new Hashtable(); private ProtocolStack mParentStack; *************** *** 192,196 **** // test if destination UDP port exists on this NeworkLayerDevice ! if (PortTable.get((Integer)inPacket.get_destPort()) !=null) { --- 134,138 ---- // test if destination UDP port exists on this NeworkLayerDevice ! if (sessionTable.get(jnSocket.genUDPkey(inPacket.get_destPort())) !=null) { *************** *** 198,237 **** //UDP_HashTableElement Elm = null; UDP_session Elm = null; ! Elm=(UDP_session)PortTable.get(inPacket.get_destPort()); int sock = Elm.sock; ! switch(Elm.PortStatus) ! { ! case 0: //port is free => Error: no application to receive UDP ! //have to disconnect listener from port ! throw new TransportLayerPortException("UDP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); ! //no break needed ;) ! case 1: // port is binded ! //now we decompose UDP datagram ! ! IncReceivedDatagrammsNumber(); ! ! //Create Layer info ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! ! UDP_Info.setDataType("UDP Protocol"); ! ! UDP_Info.setLayer("Transport"); ! ! UDP_Info.setDescription("UDP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getUDP_message() + "\"."); // + " UDP Port " + inPacket.get_destPort() + " has status \"busy\" from now."); ! ! Simulation.addLayerInfo(UDP_Info); ! mSL.recvFrom(sock, inPacket.getSourceIPAddress(), inPacket.get_srcPort(), inPacket.getUDP_message()); ! break; ! default: //UDP Error: unknown port status :( ! //have to disconnect listener from port ! throw new TransportLayerPortException("UDP Error: unknown port status! Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! } } else { ! throw new TransportLayerPortException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); } } --- 140,162 ---- //UDP_HashTableElement Elm = null; UDP_session Elm = null; ! Elm=(UDP_session) sessionTable.get(jnSocket.genUDPkey(inPacket.get_destPort())); int sock = Elm.sock; ! //now we decompose UDP datagram ! IncReceivedDatagrammsNumber(); ! Elm.IncReceivedDatagrammsNumber(); ! //Create Layer info ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! UDP_Info.setDataType("UDP Protocol"); ! UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("UDP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getUDP_message() + "\"."); // + " UDP Port " + inPacket.get_destPort() + " has status \"busy\" from now."); ! Simulation.addLayerInfo(UDP_Info); ! mSL.recvFrom(sock, inPacket.getSourceIPAddress(), inPacket.get_srcPort(), inPacket.getUDP_message()); } else { ! //throw new TransportLayerPortException("UDP Error: port " + inPacket.get_destPort() + " does not exist. Host \"" + mParentStack.getParentNodeName()+"\"."); ! throw new TransportLayerPortException("UDP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); } } *************** *** 265,269 **** try{ ! if(mSL.get_socket(sock).src_port == 0){ // we should reserve port for it ReserveFreePort(sock); --- 190,194 ---- try{ ! if(sessionTable.get(jnSocket.genUDPkey(mSL.get_socket(sock).src_port)) == null){ // we should reserve port for it ReserveFreePort(sock); *************** *** 286,290 **** Simulation.addLayerInfo(UDP_Info); ! IncSentDatagrammsNumber(); mParentStack.sendPacket(tosend); --- 211,219 ---- Simulation.addLayerInfo(UDP_Info); ! IncSentDatagrammsNumber(); ! if (sessionTable.get(jnSocket.genUDPkey(insrcPort)) !=null) ! { ! ((UDP_session)sessionTable.get(jnSocket.genUDPkey(insrcPort))).IncSentDatagrammsNumber(); ! } mParentStack.sendPacket(tosend); *************** *** 318,325 **** public void ReserveFreePort(int sock) throws TransportLayerException { ! Integer number = new Integer(0); boolean Found=false; ! boolean Reserved=false; ! Enumeration LocalPorts = PortTable.keys(); --- 247,253 ---- public void ReserveFreePort(int sock) throws TransportLayerException { ! String sessionID; boolean Found=false; ! Enumeration LocalSessions = sessionTable.keys(); *************** *** 327,343 **** // check if socket already busy ! while ( (LocalPorts.hasMoreElements()) && !(Found) ) { ! number = (Integer) LocalPorts.nextElement(); ! ! ! Elm = (UDP_session) PortTable.get(number); ! ! if ( sock == Elm.sock && Elm.sock >=0 ) { Found=true; throw new TransportLayerException("UDP Error: socket is already busy (have port)!"); ! } } --- 255,267 ---- // check if socket already busy ! while ( (LocalSessions.hasMoreElements()) && !(Found) ) { ! sessionID = (String)LocalSessions.nextElement(); ! Elm = (UDP_session) sessionTable.get(sessionID); if ( sock == Elm.sock && Elm.sock >=0 ) { Found=true; throw new TransportLayerException("UDP Error: socket is already busy (have port)!"); ! } } *************** *** 346,362 **** { //lets try to reserve any free port ! number=PORT_START_NUMBER; while ( (number<PORT_START_NUMBER+PORT_QUANT) && !(Reserved) ) { ! Elm = (UDP_session) PortTable.get((Integer)number); ! if (Elm == null) //free port { Reserved=true; ! Elm = new UDP_session(); ! Elm.PortStatus=1; //port will be busy from now Elm.sock = sock; mSL.get_socket(sock).src_port = number; ! PortTable.put(new Integer(number),Elm); LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); --- 270,285 ---- { //lets try to reserve any free port ! int number=PORT_START_NUMBER; ! boolean Reserved=false; while ( (number<PORT_START_NUMBER+PORT_QUANT) && !(Reserved) ) { ! Elm = (UDP_session) sessionTable.get(jnSocket.genUDPkey(number)); if (Elm == null) //free port { Reserved=true; ! Elm = new UDP_session(); Elm.sock = sock; mSL.get_socket(sock).src_port = number; ! sessionTable.put(jnSocket.genUDPkey(number),Elm); LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); *************** *** 365,371 **** UDP_Info.setDescription("Local port " + number + " reserved for client app."); Simulation.addLayerInfo(UDP_Info); ! } ! ! if (!Reserved) number++; } --- 288,293 ---- UDP_Info.setDescription("Local port " + number + " reserved for client app."); Simulation.addLayerInfo(UDP_Info); ! } ! number++; } *************** *** 381,420 **** { int lsPort=PORT_INIT; - Integer inPort = new Integer(in_Port); if ( mSL.get_socket(sock_num).src_port == 0 ) { ! if (inPort>=0 && inPort<=10000) { ! UDP_session Elm = null; ! ! if ( (Elm =(UDP_session)PortTable.get(inPort)) !=null ) ! { ! switch(Elm.PortStatus) ! { ! case 0: //port is free => update such a record in hashtable ! Elm.PortStatus=1; ! Elm.sock = sock_num; ! mSL.get_socket(sock_num).src_port = in_Port; ! break; ! case 1: // port is being listened to by whom? ! if (sock_num==Elm.sock) ! { ! throw new TransportLayerException("error: already binded to port "+ inPort +"!"); ! } else throw new TransportLayerException("error: port "+ inPort +" is binded by another application! Can bind only to free ports." ); ! default: //unknown port status ! throw new TransportLayerException("error: unknown port status! Port "+ inPort +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! } ! ! } else ! { //create such a record in hashtable UDP_session newElm = new UDP_session(); - newElm.PortStatus=1; newElm.sock = sock_num; mSL.get_socket(sock_num).src_port = in_Port; ! PortTable.put(inPort,newElm); //hash table update ! } LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); --- 303,340 ---- { int lsPort=PORT_INIT; if ( mSL.get_socket(sock_num).src_port == 0 ) { ! if (in_Port>=0 && in_Port<=65535) { ! // UDP_session Elm = null; ! // ! // if ( (Elm =(UDP_session)sessionTable.get(jnSocket.genUDPkey(inPort))) !=null ) ! // { ! // switch(Elm.PortStatus) ! // { ! // case 0: //port is free => update such a record in hashtable ! // Elm.PortStatus=1; ! // Elm.sock = sock_num; ! // mSL.get_socket(sock_num).src_port = in_Port; ! // break; ! // case 1: // port is being listened to by whom? ! // if (sock_num==Elm.sock) ! // { ! // throw new TransportLayerException("error: already binded to port "+ inPort +"!"); ! // } else throw new TransportLayerException("error: port "+ inPort +" is binded by another application! Can bind only to free ports." ); ! // default: //unknown port status ! // throw new TransportLayerException("error: unknown port status! Port "+ inPort +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! // } ! // ! // } else ! // { //create such a record in hashtable UDP_session newElm = new UDP_session(); newElm.sock = sock_num; mSL.get_socket(sock_num).src_port = in_Port; ! sessionTable.put(jnSocket.genUDPkey(in_Port),newElm); //hash table update ! // } LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); *************** *** 425,434 **** } else // { ! throw new TransportLayerException("error: can not listen to port "+ inPort +"! Use port range from 0 to 10000 to listen to."); } } else // { ! if (mSL.get_socket(sock_num).src_port==inPort) throw new TransportLayerException("error: can not double listen to port "+ inPort +"! Server is already listening to this port"); ! throw new TransportLayerException("error: can not listen to port "+ inPort +"! Already listening to port " + lsPort); } } --- 345,354 ---- } else // { ! throw new TransportLayerException("error: can not listen to port "+ in_Port +"! Use port range from 1 to 65535 to listen to."); } } else // { ! if (mSL.get_socket(sock_num).src_port==in_Port) throw new TransportLayerException("error: can not double listen to port "+ in_Port +"! Server is already listening to this port"); ! throw new TransportLayerException("error: can not listen to port "+ in_Port +"! Already listening to port " + lsPort); } } *************** *** 446,466 **** { UDP_session Elm=null; ! Integer PortToClose=mSL.get_socket(sock).src_port; ! Elm=(UDP_session) PortTable.get((Integer)PortToClose); ! if(PortToClose!=0 && Elm!=null){ ! if (Elm.PortStatus==1) ! { ! Elm.PortStatus=0; ! Elm.sock = -1; LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); UDP_Info.setDataType("UDP Protocol"); UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("Local port " + PortToClose + " closed and set to free."); Simulation.addLayerInfo(UDP_Info); ! PortTable.remove((Integer)PortToClose); ! } else throw new TransportLayerException("UDP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + mSL.get_socket(sock).app.toString() + "\"."); ! } else throw new TransportLayerException("UDP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + mSL.get_socket(sock).app.toString() + "\"."); } /*STATISTIC PART */ --- 366,382 ---- { UDP_session Elm=null; ! int portToClose=mSL.get_socket(sock).src_port; ! Elm=(UDP_session) sessionTable.get(jnSocket.genUDPkey(portToClose)); ! if(portToClose!=0 && Elm!=null){ LayerInfo UDP_Info = new LayerInfo(getClass().getName()); UDP_Info.setObjectName(mParentStack.getParentNodeName()); UDP_Info.setDataType("UDP Protocol"); UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("Local port " + portToClose + " closed and set to free."); Simulation.addLayerInfo(UDP_Info); ! sessionTable.remove(jnSocket.genUDPkey(portToClose)); ! mSL.close(Elm.sock); ! } else throw new TransportLayerException("UDP Error: port "+ portToClose +" is not being LISTENED to by the application: \"" + mSL.get_socket(sock).app.toString() + "\"."); } /*STATISTIC PART */ *************** *** 476,480 **** public void IncReceivedDatagrammsNumber() { ! received_datagramms++; } --- 392,396 ---- public void IncReceivedDatagrammsNumber() { ! received_datagramms++; } *************** *** 489,493 **** public void IncSentDatagrammsNumber() { ! sent_datagramm++; } --- 405,409 ---- public void IncSentDatagrammsNumber() { ! sent_datagramm++; } Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Telnet_server.java 8 Nov 2006 14:27:29 -0000 1.11 --- Telnet_server.java 18 Sep 2007 22:29:46 -0000 1.12 *************** *** 51,54 **** --- 51,57 ---- counts = 0; connected = false; + isenter=true; + islogin=false; + ispass=false; } *************** *** 61,65 **** //throw new TransportLayerException("Cannot bind port " + listenPort + "."); mParentStack.ListenTCP(this, listenPort); ! isenter = true; } --- 64,74 ---- //throw new TransportLayerException("Cannot bind port " + listenPort + "."); mParentStack.ListenTCP(this, listenPort); ! isenter=true; ! islogin=false; ! ispass=false; ! } ! ! public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ ! } *************** *** 73,84 **** public void Close() throws TransportLayerException { mParentStack.FreeTCPApplication(this); ! isenter = true; } ! public boolean ClientConnect(String temp1, int temp2){ return false; } /** * This method should be called from TCP when client connects to server --- 82,104 ---- public void Close() throws TransportLayerException { + mParentStack.CloseTCP(this); + isenter=true; + islogin=false; + ispass=false; + } + + public void Free() throws TransportLayerException + { mParentStack.FreeTCPApplication(this); ! isenter=true; ! islogin=false; ! ispass=false; } ! public boolean Connect(String temp1, int temp2){ return false; } + /** * This method should be called from TCP when client connects to server *************** *** 86,92 **** * @version v0.01 */ ! public void Connected(String Host, int port){ ! sdHost = Host; ! sdPort = port; connected = true; } --- 106,110 ---- * @version v0.01 */ ! public void OnConnect(int sock){ connected = true; } *************** *** 98,102 **** */ ! public void DisconnectEvent(){ connected = false; --- 116,120 ---- */ ! public void OnDisconnect(int sock){ connected = false; *************** *** 172,179 **** while(Data.length()>0) { String outData=""; ! if(isenter && Data.compareTo("\n")==0) { ! outData = "login: "; islogin = true; isenter = false; } else --- 190,198 ---- while(Data.length()>0) { String outData=""; ! if(isenter && Data.compareTo("\r\n")==0) { ! outData = "\r\nlogin: "; islogin = true; isenter = false; + Data = Data.substring(1); } else *************** *** 182,186 **** switch(ch) { case 0x04: { ! outData = "\nQUIT"; break; } --- 201,205 ---- switch(ch) { case 0x04: { ! outData = "\r\nQUIT"; break; } *************** *** 192,211 **** break; } ! case 0xA: { if(islogin) { islogin = false; temp = cmdline; ispass = true; ! outData = "\npassword: "; } else if(ispass) { ispass = false; if(temp.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData = "\nWelcome to " + mParentStack.getParentNodeName() + "\n" + runcmd(""); } else { try { ! SendData("\nLogin or password is incorrect"); ! outData = "\nQUIT"; } catch(Exception e) { --- 211,231 ---- break; } ! case 0xA: ! case 0xD: { if(islogin) { islogin = false; temp = cmdline; ispass = true; ! outData = "\r\npassword: "; } else if(ispass) { ispass = false; if(temp.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData = "\r\nWelcome to " + mParentStack.getParentNodeName() + "\r\n" + runcmd(""); } else { try { ! SendData("\r\nLogin or password is incorrect"); ! outData = "\r\nQUIT"; } catch(Exception e) { *************** *** 217,229 **** if(temp.compareTo("")==0) { temp = cmdline; ! outData = "\nRetype new password: "; } else { if(temp.compareTo(cmdline)==0) { password = temp; ! outData = "\n" + runcmd(""); } else { ! outData = "\n Password is not identical\n" + runcmd(""); } isnewpass = false; --- 237,249 ---- if(temp.compareTo("")==0) { temp = cmdline; ! outData = "\r\nRetype new password: "; } else { if(temp.compareTo(cmdline)==0) { password = temp; ! outData = "\r\n" + runcmd(""); } else { ! outData = "\r\n Password is not identical\r\n" + runcmd(""); } isnewpass = false; *************** *** 232,238 **** } else { ! outData = "\n" + runcmd(removeSpaces(cmdline)); } cmdline = ""; break; } --- 252,260 ---- } else { ! outData = "\r\n" + runcmd(removeSpaces(cmdline)); } cmdline = ""; + if(ch==0xD && (char)Data.charAt(1)==0xA) + Data = Data.substring(1); break; } *************** *** 254,258 **** } } ! if(outData.compareTo("\nQUIT")==0) { Disconnect(); // try{ --- 276,280 ---- } } ! if(outData.compareTo("\r\nQUIT")==0) { Disconnect(); // try{ *************** *** 314,324 **** } else if(cmd.compareTo("?")==0 || cmd.compareToIgnoreCase("help")==0) { ! out += " route \t show/edit route table\n"; ! out += " arp \t show/edit arp table\n"; ! out += " snmp \t on/off snmp agent\n"; ! out += " counters\t show network counters\n"; ! out += " passwd \t change password\n"; ! out += " quit \t close terminal session\n"; ! out += " ? or help\tshow this screen\n"; } else if(cmd.compareToIgnoreCase("quit")==0) { --- 336,346 ---- } else if(cmd.compareTo("?")==0 || cmd.compareToIgnoreCase("help")==0) { ! out += " route \t show/edit route table\r\n"; ! out += " arp \t show/edit arp table\r\n"; ! out += " snmp \t on/off snmp agent\r\n"; ! out += " counters\t show network counters\r\n"; ! out += " passwd \t change password\r\n"; ! out += " quit \t close terminal session\r\n"; ! out += " ? or help\tshow this screen\r\n"; } else if(cmd.compareToIgnoreCase("quit")==0) { *************** *** 332,339 **** String routes[] = mParentStack.getRouteTableEntries(); ! out += "IP routing table:\n" + "Destination" + "\t" + "Gateway" + "\t" + "Genmask" + "\t" + "Type" + "\t" + "Iface\n"; for(int i=0; i<routes.length - 1; i++){ Route_entry r = mParentStack.getRouteTableEntry(routes[i]); ! out += routes[i] + "\t" + r.gateway + "\t" + r.genMask + "\t" + r.Type + "\t" + r.iFace + "\n"; } } --- 354,361 ---- String routes[] = mParentStack.getRouteTableEntries(); ! out += "IP routing table:\r\n" + "Destination" + "\t" + "Gateway" + "\t" + "Genmask" + "\t" + "Type" + "\t" + "Iface\r\n"; for(int i=0; i<routes.length - 1; i++){ Route_entry r = mParentStack.getRouteTableEntry(routes[i]); ! out += routes[i] + "\t" + r.gateway + "\t" + r.genMask + "\t" + r.Type + "\t" + r.iFace + "\r\n"; } } *************** *** 345,360 **** mParentStack.addRoute(new Route_entry(m.group(1), "", m.group(3), m.group(2), 0)); } ! out+="Route added.\n"; } else if((m=Pattern.compile(" +del +([^ ]+)$").matcher(cmd)).find()) { mParentStack.removeRoute(m.group(1)); ! out+="Route to " + tokens[2] + "removed.\n"; } else{ ! out+="Unknown route command. Usage:\n"; ! out+=" route add (<host ip>|<network ip>) <target interface> <netmask> [<gateway>|*]\n" + ! " add new route record\n"; ! out+=" route del (<host ip>|<network ip>) delete route record\n"; ! out+=" route print print route table\n"; } } --- 367,382 ---- mParentStack.addRoute(new Route_entry(m.group(1), "", m.group(3), m.group(2), 0)); } ! out+="Route added.\r\n"; } else if((m=Pattern.compile(" +del +([^ ]+)$").matcher(cmd)).find()) { mParentStack.removeRoute(m.group(1)); ! out+="Route to " + tokens[2] + "removed.\r\n"; } else{ ! out+="Unknown route command. Usage:\r\n"; ! out+=" route add (<host ip>|<network ip>) <target interface> <netmask> [<gateway>|*]\r\n" + ! " add new route record\r\n"; ! out+=" route del (<host ip>|<network ip>) delete route record\r\n"; ! out+=" route print print route table\r\n"; } } *************** *** 371,387 **** snmpa.Close(); snmpa.Disconnect(); ! out+="SNMP agent stoped\n"; snmpa.setPassword(l_pass); snmpa.setPort(l_port); try{ snmpa.Listen(); ! out+="Now SNMP agent listen on port " + String.valueOf(l_port) + "\n"; } catch(TransportLayerException e) { ! out+="Unable to open connection on SNMP agent\n"; } } catch(TransportLayerException e) { ! out+="Unable to close connection on SNMP agent\n"; } } --- 393,409 ---- snmpa.Close(); snmpa.Disconnect(); ! out+="SNMP agent stoped\r\n"; snmpa.setPassword(l_pass); snmpa.setPort(l_port); try{ snmpa.Listen(); ! out+="Now SNMP agent listen on port " + String.valueOf(l_port) + "\r\n"; } catch(TransportLayerException e) { ! out+="Unable to open connection on SNMP agent\r\n"; } } catch(TransportLayerException e) { ! out+="Unable to close connection on SNMP agent\r\n"; } } *************** *** 390,403 **** try{ snmpa.Close(); ! out+="SNMP agent stoped\n"; } catch(TransportLayerException e) { ! out+="Unable to close connection on SNMP agent\n"; } } else { ! out+="Unknown snmp command. Usage:\n"; ! out+=" snmp (on|<port number>) [community name] Start SNMP agent\n"; ! out+=" snmp off Stop SNMP agent\n"; } } --- 412,425 ---- try{ snmpa.Close(); ! out+="SNMP agent stoped\r\n"; } catch(TransportLayerException e) { ! out+="Unable to close connection on SNMP agent\r\n"; } } else { ! out+="Unknown snmp command. Usage:\r\n"; ! out+=" snmp (on|<port number>) [community name] Start SNMP agent\r\n"; ! out+=" snmp off Stop SNMP agent\r\n"; } } *************** *** 410,423 **** else if(tokens[0].compareTo("counters")==0){ out += " Recieved IP Packets: " + Integer.valueOf(mParentStack.getinputIPCount()).toString() + ! "\n Sent IP Packets: " + Integer.valueOf(mParentStack.getoutputIPCount()).toString() + ! "\n ARP Packets: " + Integer.valueOf(mParentStack.getARPCount()).toString() + ! "\n Recieved TCP segments: " + Integer.valueOf(mParentStack.getTCPinputCount()).toString() + ! "\n Sent TCP segments: " + Integer.valueOf(mParentStack.getTCPoutputCount()).toString() + ! "\n Sent TCP ACK's: " + Integer.valueOf(mParentStack.getTCPACKCount()).toString() + ! "\n Sent TCP Dublicates: " + Integer.valueOf(mParentStack.getTCPSDCount()).toString() + ! "\n Recieved TCP Dublicates: " + Integer.valueOf(mParentStack.getTCPRDCount()).toString() + ! "\n Recieved UDP segments: " + Integer.valueOf(mParentStack.getUDPinputCount()).toString() + ! "\n Sent UDP segments: " + Integer.valueOf(mParentStack.getUDPoutputCount()).toString() + ! "\n"; } else if(tokens[0].compareTo("arp")==0){ --- 432,445 ---- else if(tokens[0].compareTo("counters")==0){ out += " Recieved IP Packets: " + Integer.valueOf(mParentStack.getinputIPCount()).toString() + ! "\r\n Sent IP Packets: " + Integer.valueOf(mParentStack.getoutputIPCount()).toString() + ! "\r\n ARP Packets: " + Integer.valueOf(mParentStack.getARPCount()).toString() + ! "\r\n Recieved TCP segments: " + Integer.valueOf(mParentStack.getTCPinputCount()).toString() + ! "\r\n Sent TCP segments: " + Integer.valueOf(mParentStack.getTCPoutputCount()).toString() + ! "\r\n Sent TCP ACK's: " + Integer.valueOf(mParentStack.getTCPACKCount()).toString() + ! "\r\n Sent TCP Dublicates: " + Integer.valueOf(mParentStack.getTCPSDCount()).toString() + ! "\r\n Recieved TCP Dublicates: " + Integer.valueOf(mParentStack.getTCPRDCount()).toString() + ! "\r\n Recieved UDP segments: " + Integer.valueOf(mParentStack.getUDPinputCount()).toString() + ! "\r\n Sent UDP segments: " + Integer.valueOf(mParentStack.getUDPoutputCount()).toString() + ! "\r\n"; } else if(tokens[0].compareTo("arp")==0){ *************** *** 427,431 **** for(int i=0;i<ArpTable.length;i++) { ! out += ArpTable[i] + "\n"; } } --- 449,453 ---- for(int i=0;i<ArpTable.length;i++) { ! out += ArpTable[i] + "\r\n"; } } *************** *** 437,454 **** else if((m=Pattern.compile(" +-d +([^ ]+)$").matcher(cmd)).find()) { mParentStack.removeARP(m.group(1)); ! out += "Removed ARP entry for ip " + m.group(1) + "\n"; } else if((m=Pattern.compile(" +-s +([^ ]+) +([^ ]+)$").matcher(cmd)).find()) { mParentStack.addToARPStatic(m.group(1), m.group(2)); ! out += "Created new static ARP entry: " + m.group(1) + " is " + m.group(2) + "\n"; } else { ! out+="Unknown arp command. Usage:\n"; ! out+=" arp -a print ARP table\n"; ! out+=" arp -d <ip address> delete record from ARP table\n"; ! out+=" arp -s <ip address> <MAC address> add new ARP record\n"; } } ! else out = tokens[0] + ": command not found\n"; } out+=mParentStack.getParentNodeName() + " # "; --- 459,476 ---- else if((m=Pattern.compile(" +-d +([^ ]+)$").matcher(cmd)).find()) { mParentStack.removeARP(m.group(1)); ! out += "Removed ARP entry for ip " + m.group(1) + "\r\n"; } else if((m=Pattern.compile(" +-s +([^ ]+) +([^ ]+)$").matcher(cmd)).find()) { mParentStack.addToARPStatic(m.group(1), m.group(2)); ! out += "Created new static ARP entry: " + m.group(1) + " is " + m.group(2) + "\r\n"; } else { ! out+="Unknown arp command. Usage:\r\n"; ! out+=" arp -a print ARP table\r\n"; ! out+=" arp -d <ip address> delete record from ARP table\r\n"; ! out+=" arp -s <ip address> <MAC address> add new ARP record\r\n"; } } ! else out = tokens[0] + ": command not found\r\n"; } out+=mParentStack.getParentNodeName() + " # "; Index: PosixTelnetClient.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/PosixTelnetClient.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PosixTelnetClient.java 8 Nov 2006 14:27:29 -0000 1.1 --- PosixTelnetClient.java 18 Sep 2007 22:29:46 -0000 1.2 *************** *** 45,48 **** --- 45,52 ---- } + public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ + + } + /** * This method stop listening on application port *************** *** 54,57 **** --- 58,66 ---- public void Close() throws TransportLayerException { + mParentStack.CloseTCP(this); + } + + public void Free() throws TransportLayerException + { mParentStack.FreeTCPApplication(this); } *************** *** 66,70 **** */ ! public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; --- 75,79 ---- */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; *************** *** 94,100 **** * @version v0.01 */ ! public void Connected(String Host, int port){ ! sdHost = Host; ! sdPort = port; } --- 103,107 ---- * @version v0.01 */ ! public void OnConnect(int sock){ } *************** *** 133,137 **** */ ! public void DisconnectEvent() { } --- 140,144 ---- */ ! public void OnDisconnect(int sock) { } *************** *** 192,196 **** mParentStack.FreeTCPApplication(this); ! if (ClientConnect(Host, port)) { LayerInfo protInfo = new LayerInfo(getClass().getName()); --- 199,203 ---- mParentStack.FreeTCPApplication(this); ! if (Connect(Host, port)) { LayerInfo protInfo = new LayerInfo(getClass().getName()); Index: Tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Tcp.java,v retrieving revision 1.88 retrieving revision 1.89 diff -C2 -d -r1.88 -r1.89 *** Tcp.java 8 Nov 2006 14:27:29 -0000 1.88 --- Tcp.java 18 Sep 2007 22:29:46 -0000 1.89 *************** *** 272,276 **** Simulation.addLayerInfo(TCP_Info); Elm.addstats(TCPptr); ! if(Elm.application != null) ((Application)Elm.application).DisconnectEvent(); Elm.reset(); } else { //nothing to resend, but numRepeat>0 --- 272,276 ---- Simulation.addLayerInfo(TCP_Info); Elm.addstats(TCPptr); ! if(Elm.application != null) ((Application)Elm.application).OnDisconnect(-1); // <<-- FIXME!!! Elm.reset(); } else { //nothing to resend, but numRepeat>0 *************** *** 353,357 **** // System.out.println("SERVER TIMEtoLIVE - OUT - awaiting connection timeout!"); Elm.addstats(TCPptr); ! ((Application)Elm.application).DisconnectEvent(); Elm.reset(); try{ --- 353,357 ---- // System.out.println("SERVER TIMEtoLIVE - OUT - awaiting connection timeout!"); Elm.addstats(TCPptr); ! ((Application)Elm.application).OnDisconnect(-1); // <<-- FIXME!!! Elm.reset(); try{ *************** *** 1263,1267 **** ClosePort(serv); //FIN sent and confirmed!!! Closing connection in case isPassive==true //serv.Listen(); ! serv.DisconnectEvent(); } --- 1263,1267 ---- ClosePort(serv); //FIN sent and confirmed!!! Closing connection in case isPassive==true //serv.Listen(); ! serv.OnDisconnect(-1); // <<-- FIXME!!! } *************** *** 1287,1291 **** Application client; client=(Application)Elm.application; ! client.DisconnectEvent(); } } --- 1287,1291 ---- Application client; client=(Application)Elm.application; ! client.OnDisconnect(-1); // <<-- FIXME!!! } } Index: Echo_tcp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo_tcp.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Echo_tcp.java 8 Nov 2006 14:27:29 -0000 1.30 --- Echo_tcp.java 18 Sep 2007 22:29:46 -0000 1.31 *************** *** 60,63 **** --- 60,67 ---- } + public void Accept(int listenSock, int sessionSock) throws TransportLayerException{ + + } + /** * This method stop listening on application port *************** *** 69,72 **** --- 73,81 ---- public void Close() throws TransportLayerException { + mParentStack.CloseTCP(this); + recieved = 0; + } + + public void Free() throws TransportLayerException{ mParentStack.FreeTCPApplication(this); recieved = 0; *************** *** 82,86 **** */ ! public boolean ClientConnect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; --- 91,95 ---- */ ! public boolean Connect(String Host, int port) throws TransportLayerException, InvalidNetworkLayerDeviceException, CommunicationException, LowLinkException { sdHost = Host; *************** *** 110,116 **** * @version v0.01 */ ! public void Connected(String Host, int port){ ! sdHost = Host; ! sdPort = port; } --- 119,123 ---- * @version v0.01 */ ! public void OnConnect(int sock){ } *************** *** 149,153 **** */ ! public void DisconnectEvent() { try{ Listen(); --- 156,160 ---- */ ! public void OnDisconnect(int sock) { try{ Listen(); *************** *** 281,285 **** utc1 = System.currentTimeMillis (); ! if (ClientConnect(Host, port)) { LayerInfo protInfo = new LayerInfo(getClass().getName()); -... [truncated message content] |
From: QweR <qw...@us...> - 2007-09-18 22:29:53
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv29666/guiUI Modified Files: TelnetEmulator.java Log Message: sessions was added partially Index: TelnetEmulator.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/TelnetEmulator.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TelnetEmulator.java 8 Nov 2006 14:27:29 -0000 1.9 --- TelnetEmulator.java 18 Sep 2007 22:29:47 -0000 1.10 *************** *** 102,106 **** text = ""; ! text += "Opening " + Host + ":" + Port + "...\n"; //terminal = new JLabel(text); --- 102,106 ---- text = ""; ! text += "Opening " + Host + ":" + Port + "...\r\n"; //terminal = new JLabel(text); *************** *** 119,123 **** char c = e.getKeyChar(); if((int)c<65535) { ! String s = String.valueOf(c).toString(); sendData(s); printInfo(); --- 119,131 ---- char c = e.getKeyChar(); if((int)c<65535) { ! String s; ! switch(c){ ! case 0xD: ! case 0xA: { ! s = "\r\n"; ! break; ! } ! default: s = String.valueOf(c).toString(); ! } sendData(s); printInfo(); *************** *** 150,154 **** } - public void start(){ try{ --- 158,161 ---- *************** *** 182,189 **** public void recvData(String Data){ ! if(Data.compareTo("\nQUIT")==0) { this.removeKeyListener(kl); } ! else { if(Data.compareTo("\b")==0) text = text.substring(0, text.length()-1); else text += Data; --- 189,196 ---- public void recvData(String Data){ ! if(Data.compareTo("\r\nQUIT")==0) { this.removeKeyListener(kl); } ! else { if(Data.compareTo("\b")==0) text = text.substring(0, text.length()-1); else text += Data; |
From: Alexander B. <da...@us...> - 2007-09-16 19:39:38
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv32503/core/protocolsuite/tcp_ip Added Files: jnSocket.java socketLayer.java Log Message: Socket layer classes added. --- NEW FILE: jnSocket.java --- (This appears to be a binary file; contents omitted.) --- NEW FILE: socketLayer.java --- package core.protocolsuite.tcp_ip; import java.io.Serializable; import java.util.*; import core.CommunicationException; import core.LowLinkException; import core.LayerInfo; import core.Simulation; import core.TransportLayerException; import core.TransportLayerPortException; import core.InvalidNetworkLayerDeviceException; import core.protocolsuite.tcp_ip.ProtocolStack; /** * * @author key */ public class socketLayer { ProtocolStack mParentStack; private Vector sockTable = new Vector(); int lastSock; /** Creates a new instance of socketLayer */ public socketLayer(ProtocolStack inParentStack) { mParentStack= inParentStack; sockTable.clear(); lastSock = 0; } public int socket(short type, Application app){ sockTable.add(new jnSocket(lastSock, app, type)); lastSock++; return (lastSock - 1); } public jnSocket get_socket(int sock){ return (jnSocket)sockTable.get(sock); } public void bind(int sock, String srcIP, int srcPort) throws LowLinkException, TransportLayerException{ ((jnSocket)sockTable.get(sock)).src_IP = srcIP; //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! //if(udp){ ((jnSocket)sockTable.get(sock)).open_state = true; //bind or connect or listen mParentStack.UDP().BindPort(sock, srcPort); //} //((jnSocket)sockTable.get(sock)).type // bind tcp or udp... } public void listen(int sock){ //if(tcp){ ((jnSocket)sockTable.get(sock)).open_state = true; //} } public void write(int sock, String msg){ //if() //tcp only write!!! } public void writeTo(int sock, String data, String IP, int port) throws LowLinkException, TransportLayerException{ // //if() // udp only write!!! ((jnSocket)sockTable.get(sock)).dst_IP = IP; ((jnSocket)sockTable.get(sock)).dst_port = port; ((jnSocket)sockTable.get(sock)).open_state = true; mParentStack.UDP().sendUDPPacket(sock, IP, port, data); } public void recvFrom(int sock, String IP, int port, String data) throws LowLinkException, TransportLayerException{ if(sock < lastSock){ if(((jnSocket)sockTable.get(sock)).open_state == true){ //DEPRECATED IN SOON if(((jnSocket)sockTable.get(sock)).type != jnSocket.TCP_socket){ ((jnSocket)sockTable.get(sock)).dst_IP = IP; ((jnSocket)sockTable.get(sock)).dst_port = port; } //^^^^^^^^^^^^^^^^ //DEPRECATED IN SOON ((jnSocket)sockTable.get(sock)).app.RecvIP(IP); ((jnSocket)sockTable.get(sock)).app.RecvPrt(port); //^^^^^^^^^^^^^^^^ ((jnSocket)sockTable.get(sock)).app.RecvData(data); } } } public void close(int sock) throws TransportLayerException{ //((jnSocket)sockTable.get(sock)).app = null; ((jnSocket)sockTable.get(sock)).open_state = false; //if(udp){ mParentStack.UDP().ClosePort(sock); //else{ ((jnSocket)sockTable.get(sock)).src_port = 0; ((jnSocket)sockTable.get(sock)).src_IP = ""; } public void free(int sock) throws TransportLayerException{ ((jnSocket)sockTable.get(sock)).app = null; ((jnSocket)sockTable.get(sock)).open_state = false; } } |
From: Alexander B. <da...@us...> - 2007-09-16 19:38:10
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31679/guiUI Modified Files: MainScreen.java Log Message: First attempt to create simple socket layer: modfied UDP protocol... Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** MainScreen.java 16 Sep 2007 17:44:14 -0000 1.63 --- MainScreen.java 16 Sep 2007 19:38:04 -0000 1.64 *************** *** 260,263 **** --- 260,268 ---- return c; } + + public boolean isCellEditable(int row, int column) + { + return false; + } }; *************** *** 564,567 **** --- 569,584 ---- mConsole.setColumnIdentifiers(new Object[]{"Time","Node","Packet","Layer","Info"}); + + pnlConsole.getColumnModel().getColumn(0).setMaxWidth(100); + pnlConsole.getColumnModel().getColumn(0).setMinWidth(100); + pnlConsole.getColumnModel().getColumn(1).setMaxWidth(100); + pnlConsole.getColumnModel().getColumn(1).setMinWidth(100); + pnlConsole.getColumnModel().getColumn(2).setMaxWidth(200); + pnlConsole.getColumnModel().getColumn(2).setMinWidth(200); + pnlConsole.getColumnModel().getColumn(3).setMaxWidth(100); + pnlConsole.getColumnModel().getColumn(3).setMinWidth(100); + pnlConsole.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + //pnlConsole.setEnabled(false); + // pnlConsole.getColumnModel().getColumn(0).setMaxWidth(100); // pnlConsole.getColumnModel().getColumn(0).setMinWidth(100); *************** *** 578,582 **** // pnlConsole.getColumnModel().getColumn(3).sizeWidthToFit(); // pnlConsole.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); ! --- 595,599 ---- // pnlConsole.getColumnModel().getColumn(3).sizeWidthToFit(); // pnlConsole.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); ! *************** *** 1431,1435 **** --- 1448,1454 ---- if(filters2[1]) layer = pad(recording[4],15,' '); else layer=""; + //pnlConsole.append(pad(recording[1],15,' ')+packet+pad(recording[3],10,' ')+layer+recording[5]+ "\n"); + System.out.println(pad(recording[1],15,' ')+packet+pad(recording[3],10,' ')+layer+recording[5]+ "\n"); insertInConsole(recording[1], packet, layer, recording[5]); } |
From: Alexander B. <da...@us...> - 2007-09-16 19:38:08
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31679/core/protocolsuite/tcp_ip Modified Files: Application.java Echo.java ProtocolStack.java SNMP.java Udp.java Log Message: First attempt to create simple socket layer: modfied UDP protocol... Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** ProtocolStack.java 22 Nov 2006 21:39:45 -0000 1.54 --- ProtocolStack.java 16 Sep 2007 19:38:04 -0000 1.55 *************** *** 124,127 **** --- 124,129 ---- private Node mParentNode = null; + private socketLayer mSL = null; + private int packetinputIPCounter; // counter for input IP Packets *************** *** 163,168 **** mTCPprotocol = new Tcp(this); //gift (sourceforge.net user) 25 Nov 2005 ! mUDPprotocol = new Udp(this); //gift (sourceforge.net user) 17 Nov 2005 } --- 165,174 ---- mTCPprotocol = new Tcp(this); //gift (sourceforge.net user) 25 Nov 2005 + + mSL = new socketLayer(this); ! mUDPprotocol = new Udp(this, mSL); //gift (sourceforge.net user) 17 Nov 2005 ! ! } *************** *** 179,184 **** public void initNAT(){ mTCPprotocol = new Tcp(this); //gift (sourceforge.net user) 25 Nov 2005 ! ! mUDPprotocol = new Udp(this); //gift (sourceforge.net user) 17 Nov 2005 } --- 185,190 ---- public void initNAT(){ mTCPprotocol = new Tcp(this); //gift (sourceforge.net user) 25 Nov 2005 ! mSL = new socketLayer(this); ! mUDPprotocol = new Udp(this, mSL); //gift (sourceforge.net user) 17 Nov 2005 } *************** *** 207,210 **** --- 213,218 ---- */ + + public void sendPacket(IP_packet inPacket) throws LowLinkException, CommunicationException{ *************** *** 214,217 **** --- 222,229 ---- String outInterface[] = new String[2]; + + if(!IPV4Address.validateDecIP(inPacket.mDestIPAddress)){ + throw new CommunicationException("Packet dropped host unreachable: " + inPacket.mDestIPAddress); + } try{ *************** *** 1435,1439 **** { ! if(IPV4Address.validateDecIP(inDestIPAddress)) { --- 1447,1451 ---- { ! /*if(IPV4Address.validateDecIP(inDestIPAddress)) { *************** *** 1450,1456 **** --- 1462,1481 ---- }else throw new CommunicationException("Packet dropped host unreachable: " + inDestIPAddress); + */ + return 0; } + public Udp UDP(){ + return mUDPprotocol; + } + + public Tcp TCP(){ + return mTCPprotocol; + } + + public socketLayer SL(){ + return mSL; + } /** *************** *** 1466,1470 **** public void CloseUDP(Object application) throws TransportLayerException { ! try { mUDPprotocol.ClosePort(application); } catch (TransportLayerException te) --- 1491,1495 ---- public void CloseUDP(Object application) throws TransportLayerException { ! /*try { mUDPprotocol.ClosePort(application); } catch (TransportLayerException te) *************** *** 1476,1480 **** UDP_Info.setDescription("UDP port closing: \""+ te.toString() + "\"."); Simulation.addLayerInfo(UDP_Info); ! } } --- 1501,1505 ---- UDP_Info.setDescription("UDP port closing: \""+ te.toString() + "\"."); Simulation.addLayerInfo(UDP_Info); ! }*/ } *************** *** 1491,1495 **** public void freeUDPPort(Object application) throws TransportLayerException { ! try { mUDPprotocol.FreePort(application); } catch (TransportLayerException te) --- 1516,1520 ---- public void freeUDPPort(Object application) throws TransportLayerException { ! /*try { mUDPprotocol.FreePort(application); } catch (TransportLayerException te) *************** *** 1501,1505 **** UDP_Info.setDescription("UDP port freeing: \""+ te.toString() + "\"."); Simulation.addLayerInfo(UDP_Info); ! } } --- 1526,1530 ---- UDP_Info.setDescription("UDP port freeing: \""+ te.toString() + "\"."); Simulation.addLayerInfo(UDP_Info); ! }*/ } *************** *** 1515,1519 **** public void FreeUDPApplication(Object application) throws TransportLayerException { ! mUDPprotocol.FreeApplication(application); } --- 1540,1544 ---- public void FreeUDPApplication(Object application) throws TransportLayerException { ! //mUDPprotocol.FreeApplication(application); } *************** *** 1530,1534 **** public void ListenUDP(Object application, int inPort) throws TransportLayerException { ! try{ mUDPprotocol.ListenPort(application,inPort); --- 1555,1559 ---- public void ListenUDP(Object application, int inPort) throws TransportLayerException { ! /* try{ mUDPprotocol.ListenPort(application,inPort); *************** *** 1548,1554 **** UDP_Info.setDescription("Error: UDP port listening: \""+ te.toString() + "\"."); Simulation.addLayerInfo(UDP_Info); ! } } ! /** * This method sends the UDP packet --- 1573,1593 ---- UDP_Info.setDescription("Error: UDP port listening: \""+ te.toString() + "\"."); Simulation.addLayerInfo(UDP_Info); ! }*/ } ! ! public String getSrcIP(){ ! Node temp = (Node)mParentNode; ! String FirstInterfaceName = temp.getFirstInterfaceName(); ! ! if (FirstInterfaceName!=null) ! { ! return getIPAddress(FirstInterfaceName); ! }else{ ! return ""; ! } ! } ! ! ! /** * This method sends the UDP packet *************** *** 1566,1570 **** public void sendUDP(Object application, String inUDPMessage) throws LowLinkException, CommunicationException { ! String FirstInterfaceName; String DestIPAddress; String SourceIPAddress; --- 1605,1609 ---- public void sendUDP(Object application, String inUDPMessage) throws LowLinkException, CommunicationException { ! /*String FirstInterfaceName; String DestIPAddress; String SourceIPAddress; *************** *** 1620,1624 **** } ! } } --- 1659,1663 ---- } ! }*/ } Index: Application.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Application.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Application.java 24 Feb 2006 10:20:11 -0000 1.16 --- Application.java 16 Sep 2007 19:38:04 -0000 1.17 *************** *** 15,18 **** --- 15,22 ---- import core.LowLinkException; + import core.LayerInfo; + + import core.Simulation; + /** * *************** *** 129,131 **** --- 133,144 ---- } + protected void printLayerInfo(String DataType, String s) { + LayerInfo protInfo = new LayerInfo(getClass().getName()); + protInfo.setObjectName(mParentStack.getParentNodeName()); + protInfo.setDataType(DataType); + protInfo.setLayer("Application "); + protInfo.setDescription(s); + Simulation.addLayerInfo(protInfo); + } + } Index: Udp.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Udp.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** Udp.java 5 Feb 2006 14:01:51 -0000 1.34 --- Udp.java 16 Sep 2007 19:38:04 -0000 1.35 *************** *** 128,137 **** { public byte PortStatus=0; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public Object application=null; //points to application that listens to this port | provided PortStatus==1 public String connectedtoIP=""; //contains IP of the other connected computer | provided PortStatus==2 public int connectedtoPort=0; //contains port number of the other connected computer | provided PortStatus==2 } ! private Hashtable PortTable = new Hashtable(); private ProtocolStack mParentStack; --- 128,142 ---- { public byte PortStatus=0; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public Object application=null; //points to application that listens to this port | provided PortStatus==1 public String connectedtoIP=""; //contains IP of the other connected computer | provided PortStatus==2 public int connectedtoPort=0; //contains port number of the other connected computer | provided PortStatus==2 } ! public class UDP_session{ ! public byte PortStatus=0; // 0 - free port; 1 - port is being listened to; 2 - busy. ! public int sock=-1; // socket... ! } ! ! private Hashtable PortTable = new Hashtable(); private ProtocolStack mParentStack; *************** *** 145,148 **** --- 150,155 ---- private static final int PORT_INIT = -1; //used in ListenPort && AlreadyListens + private socketLayer mSL; + /** * This method assigns the ParentStack *************** *** 151,168 **** * @version v0.20 */ ! public Udp(ProtocolStack inParentStack) { ! int i; mParentStack = inParentStack; ! for(i=0;i<PORT_QUANT;i++) ! { ! UDP_HashTableElement Elm = new UDP_HashTableElement(); ! ! Elm.PortStatus=0; ! Elm.application=null; ! Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; ! PortTable.put(new Integer((PORT_START_NUMBER+i)),Elm); // DANGEROUS PLACE! Check before change. ! } } --- 158,166 ---- * @version v0.20 */ ! public Udp(ProtocolStack inParentStack, socketLayer inSL) { ! //int i; mParentStack = inParentStack; ! mSL = inSL; } *************** *** 194,218 **** // test if destination UDP port exists on this NeworkLayerDevice ! if (PortTable.get(inPacket.get_destPort()) !=null) { //let's check all the things dealing with destination port number ! UDP_HashTableElement Elm = null; ! Elm=(UDP_HashTableElement)PortTable.get(inPacket.get_destPort()); switch(Elm.PortStatus) { case 0: //port is free => Error: no application to receive UDP //have to disconnect listener from port ! throw new TransportLayerPortException("UDP Error: no server application listening to port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); //no break needed ;) ! case 1: // port is being listened to by a new application. Have to "establish" (in UDP no connections are being established) a new connection by updating hashtable element information //now we decompose UDP datagram ! ! // everything is OK, one more ! Elm.PortStatus=2; //port will be busy from now ! Elm.connectedtoIP=inPacket.getSourceIPAddress(); ! Elm.connectedtoPort=inPacket.get_srcPort(); ! IncReceivedDatagrammsNumber(); --- 192,214 ---- // test if destination UDP port exists on this NeworkLayerDevice ! if (PortTable.get((Integer)inPacket.get_destPort()) !=null) { //let's check all the things dealing with destination port number ! //UDP_HashTableElement Elm = null; ! UDP_session Elm = null; ! Elm=(UDP_session)PortTable.get(inPacket.get_destPort()); + int sock = Elm.sock; + switch(Elm.PortStatus) { case 0: //port is free => Error: no application to receive UDP //have to disconnect listener from port ! throw new TransportLayerPortException("UDP Error: no application binded port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"!"); //no break needed ;) ! case 1: // port is binded //now we decompose UDP datagram ! IncReceivedDatagrammsNumber(); *************** *** 226,270 **** UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("UDP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getUDP_message() + "\"." + " UDP Port " + inPacket.get_destPort() + " has status \"busy\" from now."); Simulation.addLayerInfo(UDP_Info); ! Application listener; ! listener = (Application)Elm.application; ! listener.RecvData(inPacket.getUDP_message()); ! break; ! ! case 2: //busy port, let's check whether it's busy by sender ;) ! if ((Elm.connectedtoIP.equals(inPacket.getSourceIPAddress())) && (Elm.connectedtoPort==inPacket.get_srcPort())) ! { ! //now we decompose UDP datagram ! // everything is OK ! //Create Layer info ! ! UDP_Info = new LayerInfo(getClass().getName()); ! ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! ! UDP_Info.setDataType("UDP Protocol"); ! ! UDP_Info.setLayer("Transport"); ! ! UDP_Info.setDescription("UDP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getUDP_message() + "\"."); ! ! Simulation.addLayerInfo(UDP_Info); ! ! IncReceivedDatagrammsNumber(); ! ! listener = (Application)Elm.application; ! listener.RecvIP(inPacket.getSourceIPAddress()); ! listener.RecvPrt(inPacket.get_srcPort()); ! listener.RecvData(inPacket.getUDP_message()); ! ! } else { ! //have to disconnect listener from port ! throw new TransportLayerPortException("UDP Error: port is busy! Port is connected to another host or/and port and is busy by another application." + "Port "+inPacket.get_destPort() +" on host \""+ mParentStack.getParentNodeName()+"\"."); ! } ! break; ! default: //UDP Error: unknown port status :( //have to disconnect listener from port --- 222,231 ---- UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("UDP packet received from "+ inPacket.getSourceIPAddress() + ":" + inPacket.get_srcPort() + " message: \"" +inPacket.getUDP_message() + "\"."); // + " UDP Port " + inPacket.get_destPort() + " has status \"busy\" from now."); Simulation.addLayerInfo(UDP_Info); ! mSL.recvFrom(sock, inPacket.getSourceIPAddress(), inPacket.get_srcPort(), inPacket.getUDP_message()); ! break; default: //UDP Error: unknown port status :( //have to disconnect listener from port *************** *** 295,332 **** */ ! public UDP_packet sendUDPPacket(String inDestIPAddress,String inSourceIPAddress, int indestPort, int insrcPort, String inMessage) throws TransportLayerException, LowLinkException { - - UDP_packet tosend = new UDP_packet(inDestIPAddress,inSourceIPAddress,indestPort,insrcPort); ! tosend.setUDP_message(inMessage); ! ! //Create Layer info ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! UDP_Info.setDataType("UDP Protocol"); ! UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("Created UDP packet for " + inDestIPAddress + ":" + indestPort +"."); ! Simulation.addLayerInfo(UDP_Info); ! ! IncSentDatagrammsNumber(); ! return tosend; } ! ! /** ! * This method reserves LOCAL port number for an application in case reserved. Port number range: [PORT_START_NUMBER; PORT_START_NUMBER+PORT_QUANT] ! * if not found then we reserve a new number ! * @author gift (sourceforge.net user) ! * @param application that will: take free port or take already occupied port (only by itself) or tell that all ports are busy :( ! * @param inDestIPAddress destination IP address ! * @param indestPort destination port number ! * @return int port number that has been reserved for application ! * @exception TransportLayerException in several cases ! * @version v0.10 ! * @see TransportLayerException ! */ ! public int ReservePort(Object application,String inDestIPAddress, int indestPort) throws TransportLayerException { Integer number = new Integer(0); --- 256,320 ---- */ ! public void sendUDPPacket(int sock, String inDestIPAddress, int indestPort, String inMessage) throws TransportLayerException, LowLinkException { ! String inSourceIPAddress; ! int insrcPort; ! ! insrcPort = 0; + try{ + if(mSL.get_socket(sock).src_port == 0){ + // we should reserve port for it + ReserveFreePort(sock); + mSL.get_socket(sock).src_IP = mParentStack.getSrcIP(); + } + + inSourceIPAddress = mSL.get_socket(sock).src_IP; + insrcPort = mSL.get_socket(sock).src_port; + + UDP_packet tosend = new UDP_packet(inDestIPAddress,inSourceIPAddress,indestPort,insrcPort); + + tosend.setUDP_message(inMessage); + + //Create Layer info + LayerInfo UDP_Info = new LayerInfo(getClass().getName()); + UDP_Info.setObjectName(mParentStack.getParentNodeName()); + UDP_Info.setDataType("UDP Protocol"); + UDP_Info.setLayer("Transport"); + UDP_Info.setDescription("Created UDP packet for " + inDestIPAddress + ":" + indestPort +". (Local is " + inSourceIPAddress + ":" + insrcPort + ", socket " + sock + " )."); + Simulation.addLayerInfo(UDP_Info); + + IncSentDatagrammsNumber(); + + mParentStack.sendPacket(tosend); + + }catch(Exception e){ + + try { + + LayerInfo UDP_Info = new LayerInfo(getClass().getName()); + UDP_Info.setObjectName(mParentStack.getParentNodeName()); + UDP_Info.setDataType("UDP Packet"); + UDP_Info.setLayer("Transport"); + UDP_Info.setDescription("UDP sending error: \""+ e.toString() + "\"."); + Simulation.addLayerInfo(UDP_Info); + ClosePort(sock); + //*TODO*: here we shall put some layerinfo for TransportException + } catch (TransportLayerException te) + { + LayerInfo UDP_Info = new LayerInfo(getClass().getName()); + UDP_Info.setObjectName(mParentStack.getParentNodeName()); + UDP_Info.setDataType("UDP Packet"); + UDP_Info.setLayer("Transport"); + UDP_Info.setDescription("UDP port freeing: \""+ te.toString() + "\"."); + Simulation.addLayerInfo(UDP_Info); + } + + } } ! // if application tries to send, but no port binded, do it now.. ! public void ReserveFreePort(int sock) throws TransportLayerException { Integer number = new Integer(0); *************** *** 336,341 **** ! UDP_HashTableElement Elm = new UDP_HashTableElement(); while ( (LocalPorts.hasMoreElements()) && !(Found) ) { --- 324,330 ---- ! UDP_session Elm = new UDP_session(); + // check if socket already busy while ( (LocalPorts.hasMoreElements()) && !(Found) ) { *************** *** 343,378 **** ! Elm = (UDP_HashTableElement) PortTable.get(number); ! ! int UID1 = -2; ! int UID2 = -1; - if(Elm.application!=null && application!=null){ - UID1 = ((Application)Elm.application).getUID(); - UID2 = ((Application)application).getUID(); - } ! if ( UID1 == UID2) { Found=true; ! //we have found our application; let's check whom we are connected to ! if (Elm.connectedtoIP.equals(inDestIPAddress)) ! { ! //now goes port number ! if (Elm.connectedtoPort==indestPort) ! { ! //everything is OK, need to return "number" ! ! } else { ! throw new TransportLayerException("UDP Error: application is already connected to another port number! Connected to host: " + Elm.connectedtoIP + ":" + Elm.connectedtoPort + "."); ! } ! } else { ! throw new TransportLayerException("UDP Error: application is already connected to another IP! Connected to host: " + Elm.connectedtoIP + "."); ! } ! } } ! //in case we have not found our application in hash table..... if (!Found) { --- 332,346 ---- ! Elm = (UDP_session) PortTable.get(number); ! if ( sock == Elm.sock && Elm.sock >=0 ) { Found=true; ! throw new TransportLayerException("UDP Error: socket is already busy (have port)!"); } } ! //in case we have not found socket in hash table..... if (!Found) { *************** *** 381,554 **** while ( (number<PORT_START_NUMBER+PORT_QUANT) && !(Reserved) ) { ! Elm = (UDP_HashTableElement) PortTable.get((Integer)number); ! if (Elm.PortStatus == 0) //free port { ! Reserved=true; ! Elm.PortStatus=2; //port will be busy from now ! Elm.connectedtoIP=inDestIPAddress; ! Elm.connectedtoPort=indestPort; ! Elm.application = application; ! } ! if (!Reserved) number++; } if (!Reserved) //all ports are busy :( { ! throw new TransportLayerException("UDP Error: all ports are busy! Can not send UDP datagram to host " + inDestIPAddress + ":" + indestPort +"."); } ! ! } ! ! //For debugging ! // UDP_HashTableElement Elm2 = new UDP_HashTableElement();//For debugging ! // Elm2 = (UDP_HashTableElement) PortTable.get((Integer)number+1);//For debugging ! ! return (number); //do not change here! if you want to change here scan again the code ! ! ! } ! ! /** ! * This method finds port number for an application. Port number range: [PORT_START_NUMBER; PORT_START_NUMBER+PORT_QUANT] ! * @author gift (sourceforge.net user) ! * @param inSrcPort port number that has been reserved for the applicaion ! * @return int port number of the other host (that the application is connected to) ! * @exception TransportLayerException ! * @version v0.20 ! * @see TransportLayerException ! */ ! public int getApplicationDestPortNumber(int inSrcPort) throws TransportLayerException ! { ! int number=0; ! UDP_HashTableElement Elm = null; ! ! Elm=(UDP_HashTableElement)PortTable.get((Integer)inSrcPort); ! number=Elm.connectedtoPort; ! ! return number; ! } ! ! /** ! * This method closes the UDP port for an application ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void ClosePort(Object application) throws TransportLayerException //changes port status from 1 (listen) or (see proc ;) to 0 (free) ! { ! UDP_HashTableElement Elm=null; ! Integer PortToClose=getApplicationLocalPortNumber(application); ! ! Elm=(UDP_HashTableElement) PortTable.get((Integer)PortToClose); ! ! if (Elm.PortStatus==1 || (Elm.PortStatus==2 && PortToClose<PORT_START_NUMBER)) ! { ! Elm.PortStatus=0; ! Elm.application=null; ! Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; ! } else throw new TransportLayerException("UDP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + application.toString() + "\"."); ! } ! ! /** ! * This method sets the UDP port free ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void FreePort(Object application) throws TransportLayerException //changes port status from 2 (busy) to 0 (free) ! { ! UDP_HashTableElement Elm=null; ! Integer PortToFree=getApplicationLocalPortNumber(application); ! ! Elm=(UDP_HashTableElement) PortTable.get((Integer)PortToFree); ! ! if (Elm.PortStatus==2) ! { ! Elm.PortStatus=0; ! Elm.application=null; ! Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; ! } else throw new TransportLayerException("UDP Error: port "+ PortToFree +" is not BUSY by the application: \"" + application.toString() + "\"."); ! } ! ! /** ! * This method sets the UDP port totally free ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void FreeApplication(Object application) throws TransportLayerException //changes any port status to 0 (free) ! { ! UDP_HashTableElement Elm=null; ! ! try{ ! Integer PortToFree=getApplicationLocalPortNumber(application); ! Elm=(UDP_HashTableElement) PortTable.get((Integer)PortToFree); ! ! Elm.PortStatus=0; ! Elm.application=null; ! Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; ! ! }catch(Exception e){} ! } ! ! /** ! * This method checks whether server is already listening to port ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return int - port number if listens or PORT_INIT if not listens ! * @version v0.10 ! */ ! public int AlreadyListens(Object application) ! { ! boolean bo=false; ! int listensto=PORT_INIT; ! int localPort; ! ! try { ! localPort=getApplicationLocalPortNumber(application); ! listensto=localPort; ! } catch (TransportLayerException e) ! {} ! ! return listensto; ! } ! ! ! /** ! * This method sets the UDP port status to 1 (is being listened to) ! * NOTE: server must listen to UDP port numbers from 0 to 10000 ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @param in_Port port that the application want to listen to ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void ListenPort(Object application, int in_Port) throws TransportLayerException { int lsPort=PORT_INIT; Integer inPort = new Integer(in_Port); ! if ( (lsPort=AlreadyListens(application)) == PORT_INIT ) { if (inPort>=0 && inPort<=10000) { ! UDP_HashTableElement Elm = null; ! if ( (Elm =(UDP_HashTableElement)PortTable.get(inPort)) !=null ) { switch(Elm.PortStatus) --- 349,393 ---- while ( (number<PORT_START_NUMBER+PORT_QUANT) && !(Reserved) ) { ! Elm = (UDP_session) PortTable.get((Integer)number); ! if (Elm == null) //free port { ! Reserved=true; ! Elm = new UDP_session(); ! Elm.PortStatus=1; //port will be busy from now ! Elm.sock = sock; ! mSL.get_socket(sock).src_port = number; ! PortTable.put(new Integer(number),Elm); ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! UDP_Info.setDataType("UDP Protocol"); ! UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("Local port " + number + " reserved for client app."); ! Simulation.addLayerInfo(UDP_Info); ! } ! ! if (!Reserved) number++; } if (!Reserved) //all ports are busy :( { ! throw new TransportLayerException("UDP Error: all ports are busy! Cannot reserve port for socket!"); } ! } ! } ! ! // bind port to socket ! public void BindPort(int sock_num, int in_Port) throws TransportLayerException { int lsPort=PORT_INIT; Integer inPort = new Integer(in_Port); ! if ( mSL.get_socket(sock_num).src_port == 0 ) { if (inPort>=0 && inPort<=10000) { ! UDP_session Elm = null; ! if ( (Elm =(UDP_session)PortTable.get(inPort)) !=null ) { switch(Elm.PortStatus) *************** *** 556,576 **** case 0: //port is free => update such a record in hashtable Elm.PortStatus=1; ! Elm.application=application; ! Elm.connectedtoIP=""; ! Elm.connectedtoPort=0; break; case 1: // port is being listened to by whom? ! int UID1=-2; ! int UID2=-1; ! UID1=((Application)Elm.application).getUID(); ! UID2=((Application)application).getUID(); ! ! if (UID1==UID2) { ! throw new TransportLayerException("error: already listening to port "+ inPort +"!"); ! } else throw new TransportLayerException("error: port "+ inPort +" is being listened to by another application! Can listen only to free ports." ); ! case 2: //port is busy => error ! throw new TransportLayerException("error: port "+ inPort +" is busy! Can listen only to free ports." ); ! // no "break" needed ;) default: //unknown port status throw new TransportLayerException("error: unknown port status! Port "+ inPort +" on host \""+ mParentStack.getParentNodeName()+"\"."); --- 395,406 ---- case 0: //port is free => update such a record in hashtable Elm.PortStatus=1; ! Elm.sock = sock_num; ! mSL.get_socket(sock_num).src_port = in_Port; break; case 1: // port is being listened to by whom? ! if (sock_num==Elm.sock) { ! throw new TransportLayerException("error: already binded to port "+ inPort +"!"); ! } else throw new TransportLayerException("error: port "+ inPort +" is binded by another application! Can bind only to free ports." ); default: //unknown port status throw new TransportLayerException("error: unknown port status! Port "+ inPort +" on host \""+ mParentStack.getParentNodeName()+"\"."); *************** *** 580,692 **** { //create such a record in hashtable ! UDP_HashTableElement newElm = new UDP_HashTableElement(); ! newElm.PortStatus=1; ! newElm.application=application; ! newElm.connectedtoIP=""; ! newElm.connectedtoPort=0; ! PortTable.put(inPort,newElm); //hash table update } } else // { - /* LayerInfo UDP_Info = new LayerInfo(getClass().getName()); - UDP_Info.setObjectName(mParentStack.getParentNodeName()); - UDP_Info.setDataType("UDP Applicaion"); - UDP_Info.setLayer("Transport"); - UDP_Info.setDescription("UDP port listening: \"UDP Error: can not listen to port "+ inPort +"! Use port range from 0 to 10000 to listen to."); - Simulation.addLayerInfo(UDP_Info); */ throw new TransportLayerException("error: can not listen to port "+ inPort +"! Use port range from 0 to 10000 to listen to."); } } else // { ! /* LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! UDP_Info.setDataType("UDP Applicaion"); ! UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("UDP port listening: \"UDP Error: can not listen to port "+ inPort +"! Already listening to port " + lsPort + ".\"."); ! Simulation.addLayerInfo(UDP_Info); */ ! if (lsPort==inPort) throw new TransportLayerException("error: can not double listen to port "+ inPort +"! Server is already listening to this port"); throw new TransportLayerException("error: can not listen to port "+ inPort +"! Already listening to port " + lsPort); } ! ! /* LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! UDP_Info.setDataType("UDP Applicaion"); ! UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("UDP application is now listening on UDP port "+ inPort +"."); ! Simulation.addLayerInfo(UDP_Info); */ ! } ! ! ! ! /** ! * This method finds destination IP (host) for an application. ! * @author gift (sourceforge.net user) ! * @param inSrcPort port number that has been reserved for the applicaion ! * @return String destination IP (other host IP that the application is connected to) ! * @exception TransportLayerException ! * @version v0.20 ! * @see TransportLayerException ! */ ! public String getApplicationDestIP(int inSrcPort) throws TransportLayerException ! { ! String dIP=null; ! UDP_HashTableElement Elm = null; ! ! Elm=(UDP_HashTableElement)PortTable.get((Integer)inSrcPort); ! dIP=Elm.connectedtoIP; ! ! return dIP; ! } ! ! ! /** ! * This method finds LOCAL port number for an application. Port number range: [PORT_START_NUMBER; PORT_START_NUMBER+PORT_QUANT] ! * @author gift (sourceforge.net user) ! * @param application which local port will be returned ! * @return int port number that has been reserved for application ! * @exception TransportLayerException in several cases ! * @version v0.10 ! * @see TransportLayerException ! */ ! public int getApplicationLocalPortNumber(Object application) throws TransportLayerException ! { ! Integer number= new Integer(0); ! boolean Found=false; ! boolean Reserved=false; ! Enumeration LocalPorts = PortTable.keys(); ! UDP_HashTableElement Elm = null; ! ! while ( (LocalPorts.hasMoreElements()) && !(Found) ) ! { ! number = (Integer)LocalPorts.nextElement(); ! Elm = (UDP_HashTableElement) PortTable.get(number); ! ! int UID1 = -2; ! int UID2 = -1; ! ! if(Elm.application!=null && application!=null){ ! UID1 = ((Application)Elm.application).getUID(); ! UID2 = ((Application)application).getUID(); ! } ! ! if ( UID1 == UID2 ) ! { ! Found=true; ! //we have found our application ! //everything is OK, need to return "number" ! } ! } ! ! //in case we have not found our application in hash table..... ! if (!Found) ! { ! throw new TransportLayerException("UDP Error: no local port reserved for the application: \"" + application.toString() + "\"! Can not get local reserved port number."); ! } ! ! return (number); //do not change here! if you want to change here scan again the code } - /*STATISTIC PART */ --- 410,467 ---- { //create such a record in hashtable ! UDP_session newElm = new UDP_session(); ! newElm.PortStatus=1; ! newElm.sock = sock_num; ! mSL.get_socket(sock_num).src_port = in_Port; ! PortTable.put(inPort,newElm); //hash table update } + LayerInfo UDP_Info = new LayerInfo(getClass().getName()); + UDP_Info.setObjectName(mParentStack.getParentNodeName()); + UDP_Info.setDataType("UDP Protocol"); + UDP_Info.setLayer("Transport"); + UDP_Info.setDescription("Local port " + in_Port + " binded."); + Simulation.addLayerInfo(UDP_Info); } else // { throw new TransportLayerException("error: can not listen to port "+ inPort +"! Use port range from 0 to 10000 to listen to."); } } else // { ! if (mSL.get_socket(sock_num).src_port==inPort) throw new TransportLayerException("error: can not double listen to port "+ inPort +"! Server is already listening to this port"); throw new TransportLayerException("error: can not listen to port "+ inPort +"! Already listening to port " + lsPort); } ! } ! /** ! * This method closes the UDP port for an application ! * @author gift (sourceforge.net user) ! * @param application application that uses port ! * @return Nothing ! * @exception TransportLayerException ! * @version v0.10 ! * @see TransportLayerException ! */ ! public void ClosePort(int sock) throws TransportLayerException //changes port status from 1 (listen) or (see proc ;) to 0 (free) ! { ! UDP_session Elm=null; ! Integer PortToClose=mSL.get_socket(sock).src_port; ! Elm=(UDP_session) PortTable.get((Integer)PortToClose); ! ! if(PortToClose!=0 && Elm!=null){ ! if (Elm.PortStatus==1) ! { ! Elm.PortStatus=0; ! Elm.sock = -1; ! LayerInfo UDP_Info = new LayerInfo(getClass().getName()); ! UDP_Info.setObjectName(mParentStack.getParentNodeName()); ! UDP_Info.setDataType("UDP Protocol"); ! UDP_Info.setLayer("Transport"); ! UDP_Info.setDescription("Local port " + PortToClose + " closed and set to free."); ! Simulation.addLayerInfo(UDP_Info); ! PortTable.remove((Integer)PortToClose); ! } else throw new TransportLayerException("UDP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + mSL.get_socket(sock).app.toString() + "\"."); ! } else throw new TransportLayerException("UDP Error: port "+ PortToClose +" is not being LISTENED to by the application: \"" + mSL.get_socket(sock).app.toString() + "\"."); } /*STATISTIC PART */ Index: Echo.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Echo.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Echo.java 9 Sep 2006 13:43:58 -0000 1.21 --- Echo.java 16 Sep 2007 19:38:04 -0000 1.22 *************** *** 30,37 **** --- 30,40 ---- long utc1; public int recieved; + int sock; /** Creates a new instance of Echo */ public Echo(ProtocolStack inParentStack, int listenPort, int appType, int UID) { super(inParentStack, listenPort, appType, UID); + sock = mParentStack.SL().socket(jnSocket.UDP_socket, this); + int fake = 0; } *************** *** 42,51 **** */ public void Listen() throws TransportLayerException{ ! //throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! try{ ! mParentStack.ListenUDP(this, listenPort); ! } catch (TransportLayerException e) { ! } } --- 45,56 ---- */ public void Listen() throws TransportLayerException{ ! // ! try{ ! mParentStack.SL().bind(sock, mParentStack.getSrcIP(), listenPort); ! printLayerInfo("Echo app", "Echo server starts listening in port " + listenPort + "."); ! } catch (Exception e) { ! printLayerInfo("Echo app", "Error: cannot bind port " + listenPort + "."); ! throw new TransportLayerException("Cannot bind port " + listenPort + "."); } } *************** *** 60,68 **** public void Close() throws TransportLayerException { ! mParentStack.CloseUDP(this); } /** * This method connects to server on the other side (imaginations from the other side.... :+) * @author key * @param Host - hostname or ip of server. --- 65,75 ---- public void Close() throws TransportLayerException { ! printLayerInfo("Echo app", "Echo app closed socket."); ! mParentStack.SL().close(sock); } /** * This method connects to server on the other side (imaginations from the other side.... :+) + * This is "fake" method cos of UDP * @author key * @param Host - hostname or ip of server. *************** *** 74,79 **** sdHost = Host; sdPort = port; ! clientPort = mParentStack.reserveUDPPort(this, sdHost, sdPort); ! if (clientPort>0) return true; else return false; } --- 81,87 ---- sdHost = Host; sdPort = port; ! //clientPort = mParentStack.SL().reserveUDPPort(this, sdHost, sdPort); ! //if (clientPort>0) return true; else return false; ! return true; } *************** *** 85,90 **** */ public void Connected(String Host, int port){ ! sdHost = Host; ! sdPort = port; } --- 93,98 ---- */ public void Connected(String Host, int port){ ! /*sdHost = Host; ! sdPort = port;*/ } *************** *** 104,108 **** public void Disconnect() throws TransportLayerException { ! mParentStack.freeUDPPort(this); } --- 112,116 ---- public void Disconnect() throws TransportLayerException { ! mParentStack.SL().close(sock); } *************** *** 117,122 **** public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! ! mParentStack.sendUDP(this, Data); //processing the protocol doings. --- 125,129 ---- public void SendData(String Data) throws LowLinkException, TransportLayerException, CommunicationException { ! mParentStack.SL().writeTo(sock, Data, sdHost, sdPort); //processing the protocol doings. *************** *** 143,153 **** protInfo.setDescription("Recieving echo message '" + Data + "' from server."); Simulation.addLayerInfo(protInfo); ! /* ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving echo message '" + Data + "' from server."); ! Simulation.addLayerInfo(protInfo);*/ Disconnect(); --- 150,154 ---- protInfo.setDescription("Recieving echo message '" + Data + "' from server."); Simulation.addLayerInfo(protInfo); ! Disconnect(); *************** *** 159,163 **** protInfo.setDataType("Echo Protocol Data"); protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving echo message '" + Data + "' from client. Total recieved messages: " + recieved); Simulation.addLayerInfo(protInfo); --- 160,164 ---- protInfo.setDataType("Echo Protocol Data"); protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving echo message '" + Data + "' from client " + sdHost + ":" + sdPort + ". Total recieved messages by server: " + recieved); Simulation.addLayerInfo(protInfo); *************** *** 171,184 **** SendData(Data); ! LayerInfo protInfo3 = new LayerInfo(getClass().getName()); protInfo3.setObjectName(mParentStack.getParentNodeName()); protInfo3.setDataType("Echo Protocol Data"); protInfo3.setLayer("Application "); protInfo3.setDescription("Server closing connection. Now listening on " + listenPort + "."); ! Simulation.addLayerInfo(protInfo3); ! Close(); ! Listen(); }catch(Exception e){ ///*TODO*: here to catch } --- 172,186 ---- SendData(Data); ! /*LayerInfo protInfo3 = new LayerInfo(getClass().getName()); protInfo3.setObjectName(mParentStack.getParentNodeName()); protInfo3.setDataType("Echo Protocol Data"); protInfo3.setLayer("Application "); protInfo3.setDescription("Server closing connection. Now listening on " + listenPort + "."); ! Simulation.addLayerInfo(protInfo3);*/ ! //Close(); ! //Listen(); }catch(Exception e){ + System.out.println(e.toString()); ///*TODO*: here to catch } *************** *** 195,199 **** */ public void SendEcho(String Data, String Host, int port, int counts) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ! mParentStack.FreeUDPApplication(this); utc1 = System.currentTimeMillis () ; --- 197,201 ---- */ public void SendEcho(String Data, String Host, int port, int counts) throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException, TransportLayerException{ ! //mParentStack.FreeUDPApplication(this); utc1 = System.currentTimeMillis () ; *************** *** 201,231 **** for(int c=0; c<counts; c++){ ! if (ClientConnect(Host, port)) ! { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Start sending echo message '" + Data + "' to " + Host + ":" + port); ! Simulation.addLayerInfo(protInfo); ! SendData(Data); ! } else ! { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Error: can not connect to " + Host + ":" + port + "!"); ! Simulation.addLayerInfo(protInfo); ! c=counts; ! } } ! LayerInfo protInfo2 = new LayerInfo(getClass().getName()); ! protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Echo Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription("Connection time: " + (long)(System.currentTimeMillis () - utc1) + " ms. Sent messages: " + counts + " Recieved messages: " + recieved); ! Simulation.addLayerInfo(protInfo2); } --- 203,232 ---- for(int c=0; c<counts; c++){ ! if (ClientConnect(Host, port)) ! { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Start sending echo message '" + Data + "' to " + Host + ":" + port); ! Simulation.addLayerInfo(protInfo); ! SendData(Data); ! } else { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Error: can not connect to " + Host + ":" + port + "!"); ! Simulation.addLayerInfo(protInfo); ! c=counts; ! } } ! LayerInfo protInfo2 = new LayerInfo(getClass().getName()); ! protInfo2.setObjectName(mParentStack.getParentNodeName()); ! protInfo2.setDataType("Echo Protocol Data"); ! protInfo2.setLayer("Application "); ! protInfo2.setDescription("Connection time: " + (long)(System.currentTimeMillis () - utc1) + " ms. Sent messages: " + counts + " Recieved messages: " + recieved); ! Simulation.addLayerInfo(protInfo2); } *************** *** 235,242 **** * @author gift (sourceforge.net user) * @version v0.01 */ public void RecvIP(String IP) throws LowLinkException, TransportLayerException { ! } --- 236,244 ---- * @author gift (sourceforge.net user) * @version v0.01 + * WARNING: Soon this 'll be DEPRECATED! */ public void RecvIP(String IP) throws LowLinkException, Trans... [truncated message content] |
From: Alexander B. <da...@us...> - 2007-09-16 19:22:21
|
Update of /cvsroot/javanetsim/javaNetSim In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv25469 Added Files: CVS_STRUCT.txt Log Message: CVS structure. --- NEW FILE: CVS_STRUCT.txt --- javaNetSim CVS structure as on 16-09-2007 Tags: * HEAD tag. We're not using tags at all now. Branches: * MAIN branch. Current (new, exprimental, non-stable) sources. Experiments should be made here. * STABLE* -- stable releases. Stabling here. * STABLE-0_33 |
From: gift <gi...@us...> - 2007-09-16 17:44:31
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13944/guiUI Modified Files: MainScreen.java SandBox.java Log Message: Image saving implemented. Bugs removed. Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** MainScreen.java 16 Sep 2007 15:27:26 -0000 1.62 --- MainScreen.java 16 Sep 2007 17:44:14 -0000 1.63 *************** *** 2256,2260 **** //Generate report and save Simulation. ! generate_html_report(simSaveFile.getAbsolutePath(), tempFile.getPath()+".jpg"); System.out.println("Generating HTML report file"); --- 2256,2260 ---- //Generate report and save Simulation. ! generate_html_report(simSaveFile.getAbsolutePath(), tempFile.getAbsolutePath()+".jpg"); System.out.println("Generating HTML report file"); *************** *** 3385,3388 **** --- 3385,3406 ---- FileWriter f_out; //html file File g_out; //graphics file + String gr_path2 = ""; // to insert in HTML file + + ///////////////////////////////////////////////// + //PART 1. Generate HTML file. + ///////////////////////////////////////////////// + + //Process gr_path: remove everything up to last / or \ + if (gr_path.contains("\\")) + { + gr_path2 = gr_path.substring(gr_path.lastIndexOf('\\') + 1, gr_path.length()); + } else + if (gr_path.contains("/")) + { + gr_path2 = gr_path.substring(gr_path.lastIndexOf('/') + 1, gr_path.length()); + } else + { + gr_path2 = gr_path; + } try { f_out = new FileWriter(path); *************** *** 3399,3403 **** f_out.write("<P>Welcome to javaNetSim report page!</P>\r\n" + "<P>Simulation printscreen: <BR/>"+ ! "<IMG SRC=\""+ gr_path +"\"></P>\r\n" + "<P>Here is the summary of the devices you used in your simulation." + "</P>\r\n<P>"); --- 3417,3421 ---- f_out.write("<P>Welcome to javaNetSim report page!</P>\r\n" + "<P>Simulation printscreen: <BR/>"+ ! "<IMG SRC=\""+ gr_path2 +"\"></P>\r\n" + "<P>Here is the summary of the devices you used in your simulation." + "</P>\r\n<P>"); *************** *** 3413,3419 **** f_out.close(); ! // Get image to write to a file ! int width = 1000; ! int height = 1000; BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); --- 3431,3441 ---- f_out.close(); ! ///////////////////////////////////////////////// ! //PART 2. Generate image file. ! ///////////////////////////////////////////////// ! ! // Get image to write to a file ! int width = this.getWidth(); ! int height = this.getHeight(); BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); *************** *** 3421,3440 **** Graphics2D g2d = bufferedImage.createGraphics(); ! // Draw graphics ! java.awt.Component c[] = this.Sandbox.getComponentsInLayer(3); ! g2d = (Graphics2D) c[0].getGraphics(); ! ! // Graphics context no longer needed so dispose it g2d.dispose(); - - // Save as PNG - //File file = new File("newimage.png"); - //ImageIO.write(rendImage, "png", file); // Save as JPEG g_out = new File(gr_path); ! ImageIO.write((RenderedImage) bufferedImage, "jpg", g_out); ! } catch (IOException ex) { addToConsole(ex.toString()); --- 3443,3480 ---- Graphics2D g2d = bufferedImage.createGraphics(); ! // Draw graphics var1: printscreen ! //g2d.setColor(new Color(0xEEEEEE)); ! //g2d.setColor(new Color(0xFFFFFF)); ! //g2d.fillRect(0,0, width, height); ! //this.paint(g2d); ! //g2d.dispose(); ! // Draw graphics var2: cropped to work area ! this.paint(g2d); ! ! // Graphics context no longer needed so dispose of it g2d.dispose(); + int w = scroller.getWidth(); + int h = scroller.getHeight(); + int x = (int) (scroller.getLocationOnScreen().getX() - this.getLocationOnScreen().getX()); + int y = (int) (scroller.getLocationOnScreen().getY() - this.getLocationOnScreen().getY()); + + BufferedImage bufferedImage2 = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + Graphics2D g2_2d = bufferedImage2.createGraphics(); + + //key's shamanism + g2_2d.drawImage(bufferedImage,0,0,w,h,x + 5, y + 5,x + w - scroller.getVerticalScrollBar().getWidth() - 5,y + h - scroller.getHorizontalScrollBar().getHeight() - 5,this); + + g2_2d.dispose(); + + // Save as PNG + //File file = new File(gr_path); + //ImageIO.write((RenderedImage) bufferedImage, "png", file); + // Save as JPEG g_out = new File(gr_path); ! ImageIO.write((RenderedImage) bufferedImage2, "jpg", g_out); ! } catch (IOException ex) { addToConsole(ex.toString()); Index: SandBox.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/SandBox.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SandBox.java 16 Sep 2007 15:27:26 -0000 1.5 --- SandBox.java 16 Sep 2007 17:44:14 -0000 1.6 *************** *** 247,257 **** public void componentMoved(ComponentEvent arg0){} public void componentShown(ComponentEvent arg0) { ! } ! - public Graphics getGraphics() - { - return this.controller.getGraphics(); - } - } --- 247,251 ---- public void componentMoved(ComponentEvent arg0){} public void componentShown(ComponentEvent arg0) { ! } } |