javanetsim-cvs Mailing List for javaNetSim (Page 2)
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: QweR <qw...@us...> - 2008-11-02 00:10:36
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12084/core/protocolsuite/tcp_ip Modified Files: DHCPC.java Log Message: some fixes Index: DHCPC.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/DHCPC.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** DHCPC.java 24 Oct 2008 16:18:48 -0000 1.8 --- DHCPC.java 2 Nov 2008 00:10:29 -0000 1.9 *************** *** 334,336 **** --- 334,340 ---- return iface; } + + public String getDHCPServer() { + return DHCPServer; + } } |
From: QweR <qw...@us...> - 2008-11-02 00:10:36
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12084/core Modified Files: CommandProcessor.java Log Message: some fixes Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** CommandProcessor.java 29 Oct 2008 19:36:20 -0000 1.39 --- CommandProcessor.java 2 Nov 2008 00:10:29 -0000 1.40 *************** *** 520,524 **** modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); call_params = "(open|shared)"; - no_call_params = "<cr>"; } public String call(Vector<String> params){ --- 520,523 ---- *************** *** 3458,3462 **** public show_access_lists_CommandClass(){ modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); ! call_params = "<1-2699 | WORD>"; } public String call(Vector<String> params){ --- 3457,3461 ---- public show_access_lists_CommandClass(){ modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); ! call_params = "<1-2699>"; } public String call(Vector<String> params){ *************** *** 3685,3702 **** String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_SERVER_ID); ! if(dhcpd!=null){ if(params.size()==0){ ! out += "DHCP server is "+(dhcpd.running?"running\n":"stopped\n"); ! Enumeration<String> pools = dhcpd.pools.keys(); ! while(pools.hasMoreElements()){ ! String name = pools.nextElement(); ! DHCPD.pool pool = dhcpd.pools.get(name); ! out += " Pool '"+name+"'\n" + ! " Network: "+((pool.IP==null || pool.IP=="")?"(not set)":pool.IP)+"\n" + ! " Mask: "+((pool.Genmask==null || pool.Genmask=="")?"(not set)":pool.Genmask)+"\n" + ! " Gateway: "+((pool.Gateway==null || pool.Gateway=="")?"(not set)":pool.Gateway)+"\n" + ! " MAC: "+((pool.MAC==null || pool.MAC=="")?"(not set)":pool.MAC)+"\n"; ! } } else{ --- 3684,3694 ---- String out = ""; if(device instanceof ApplicationLayerDevice){ ! DHCPC dhcpc = (DHCPC)((ApplicationLayerDevice)device).getApp(core.ApplicationLayerDevice.DHCP_CLIENT_ID); ! if(dhcpc!=null){ if(params.size()==0){ ! if(dhcpc.running) ! out += "Server "+dhcpc.getDHCPServer()+" on interface "+dhcpc.getInterface()+" is using\n"; ! else ! out += "No servers found\n"; } else{ |
From: QweR <qw...@us...> - 2008-10-29 19:36:40
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12987/core/protocolsuite/tcp_ip Modified Files: DHCPD.java IPV4Address.java Log Message: dhcp exclude was added some commands was fixed Index: DHCPD.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/DHCPD.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** DHCPD.java 24 Oct 2008 17:46:42 -0000 1.12 --- DHCPD.java 29 Oct 2008 19:36:21 -0000 1.13 *************** *** 231,235 **** if(Network.equals(PoolNetwork)){ ! if(!leases.containsKey(IP)){ l.IP = IP; l.Genmask = p.Genmask; --- 231,235 ---- if(Network.equals(PoolNetwork)){ ! if(!leases.containsKey(IP) && !isExcludes(IP)){ l.IP = IP; l.Genmask = p.Genmask; *************** *** 419,421 **** --- 419,430 ---- } + private boolean isExcludes(String ip){ + boolean result = false; + for(int i=0; i<exclude.size() && !result; i++){ + Pair ips = exclude.get(i); + result = IPV4Address.isBetween(ip, (String)ips.getFirst(), (String)ips.getSecond()); + } + return result; + } + } Index: IPV4Address.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/IPV4Address.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** IPV4Address.java 26 Oct 2008 15:37:40 -0000 1.9 --- IPV4Address.java 29 Oct 2008 19:36:21 -0000 1.10 *************** *** 25,29 **** 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; --- 25,29 ---- 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; *************** *** 47,57 **** private static final String CLASS_B_BINARY ="11111111111111110000000000000000"; private static final String CLASS_C_BINARY ="11111111111111111111111100000000"; ! //These are the class types public static final int CLASS_A_TYPE = 1; public static final int CLASS_B_TYPE = 2; public static final int CLASS_C_TYPE = 3; ! public static final int NO_CLASS = 4; ! /** * Creates a new IPV4Address object containing the IP address saved in binary --- 47,57 ---- private static final String CLASS_B_BINARY ="11111111111111110000000000000000"; private static final String CLASS_C_BINARY ="11111111111111111111111100000000"; ! //These are the class types public static final int CLASS_A_TYPE = 1; public static final int CLASS_B_TYPE = 2; public static final int CLASS_C_TYPE = 3; ! public static final int NO_CLASS = 4; ! /** * Creates a new IPV4Address object containing the IP address saved in binary *************** *** 64,86 **** 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; ! } ! } ! ! ! public static boolean isValidIp(final String ip) ! { ! return ip.matches("^[\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}$"); ! } ! /** * This method returns the binary subnetmask in decimal --- 64,86 ---- 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; ! } ! } ! ! ! public static boolean isValidIp(final String ip) ! { ! return ip.matches("^[\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}$"); ! } ! /** * This method returns the binary subnetmask in decimal *************** *** 105,109 **** String decimalip = new String(); String[] binary = new String[4]; ! for (int i = 0, c = 0; i < 32; i=i+8, c++) { binary[c] = inBinaryIpAddress.substring(i,i+8); --- 105,109 ---- String decimalip = new String(); String[] binary = new String[4]; ! for (int i = 0, c = 0; i < 32; i=i+8, c++) { binary[c] = inBinaryIpAddress.substring(i,i+8); *************** *** 114,132 **** return decimalip; } ! ! public static boolean IPEqLower(String IP1, String IP2){ ! String IPOct1[] = IP1.split("\\."); String IPOct2[] = IP2.split("\\."); ! for(int i = 0; i < 4; i++){ if(Integer.valueOf(IPOct1[i]) - Integer.valueOf(IPOct2[i]) < 0) return false; } ! return true; } ! /** * This method will return the binary version of an IPV4 address or subnet mask --- 114,132 ---- return decimalip; } ! ! public static boolean IPEqLower(String IP1, String IP2){ ! String IPOct1[] = IP1.split("\\."); String IPOct2[] = IP2.split("\\."); ! for(int i = 0; i < 4; i++){ if(Integer.valueOf(IPOct1[i]) - Integer.valueOf(IPOct2[i]) < 0) return false; } ! return true; } ! /** * This method will return the binary version of an IPV4 address or subnet mask *************** *** 142,173 **** String[] ip = inDecimalIp.split("\\."); // Split string into array String binaryAddress = new String(); ! for (int i = 0; i < ip.length; i++) { ! Integer octet = new Integer(ip[i].trim()); ! ! //This tests every octet within the inDecimalIp ! //to make sure the user hasnt entered a Negative value. ! //This code fixs bug #1056000 ! if(octet.intValue() < 0) { ! throw new InvalidIPAddressException("Invalid IP Address, cant use Negative IP address"); ! } ! ! if (octet.intValue() <= 255){ ! ! StringBuffer temp = new StringBuffer(Integer.toBinaryString(octet.intValue())); ! if(temp.length() !=8){ ! ! while(temp.length() != 8){ ! temp.insert(0,0); ! } ! } ! binaryAddress = binaryAddress + temp; ! }else ! throw new InvalidIPAddressException("Invalid IP Address"); } ! return binaryAddress; } ! /** * This class is called when an ip address is set. It then set the default --- 142,173 ---- String[] ip = inDecimalIp.split("\\."); // Split string into array String binaryAddress = new String(); ! for (int i = 0; i < ip.length; i++) { ! Integer octet = new Integer(ip[i].trim()); ! ! //This tests every octet within the inDecimalIp ! //to make sure the user hasnt entered a Negative value. ! //This code fixs bug #1056000 ! if(octet.intValue() < 0) { ! throw new InvalidIPAddressException("Invalid IP Address, cant use Negative IP address"); } ! ! if (octet.intValue() <= 255){ ! ! StringBuffer temp = new StringBuffer(Integer.toBinaryString(octet.intValue())); ! if(temp.length() !=8){ ! ! while(temp.length() != 8){ ! temp.insert(0,0); ! } ! } ! binaryAddress = binaryAddress + temp; ! }else ! throw new InvalidIPAddressException("Invalid IP Address"); ! } ! return binaryAddress; } ! /** * This class is called when an ip address is set. It then set the default *************** *** 193,201 **** return CLASS_C_BINARY; } ! **/ return "00000000000000000000000000000000"; ! } ! /** --- 193,201 ---- return CLASS_C_BINARY; } ! **/ return "00000000000000000000000000000000"; ! } ! /** *************** *** 209,213 **** String[] ip = inDecimalIP.split("\\."); Integer firstoctet = new Integer(ip[0].trim()); ! if (firstoctet.intValue() >=1 && firstoctet.intValue() <=127){ //test for class A return IPV4Address.CLASS_A_TYPE; --- 209,213 ---- String[] ip = inDecimalIP.split("\\."); Integer firstoctet = new Integer(ip[0].trim()); ! if (firstoctet.intValue() >=1 && firstoctet.intValue() <=127){ //test for class A return IPV4Address.CLASS_A_TYPE; *************** *** 219,227 **** return IPV4Address.CLASS_C_TYPE; }else { ! return IPV4Address.NO_CLASS; ! } //return 0; UGLY FIX } ! /** * This method will return a Decimal Subnet Mask. --- 219,227 ---- return IPV4Address.CLASS_C_TYPE; }else { ! return IPV4Address.NO_CLASS; ! } //return 0; UGLY FIX } ! /** * This method will return a Decimal Subnet Mask. *************** *** 233,237 **** */ public static String getDefaultSubnetMask(String inDecimalIp){ ! if(IPV4Address.getDefaultSubnetMaskClassType(inDecimalIp) == IPV4Address.CLASS_A_TYPE) return IPV4Address.toDecimalString(IPV4Address.CLASS_A_BINARY); --- 233,237 ---- */ public static String getDefaultSubnetMask(String inDecimalIp){ ! if(IPV4Address.getDefaultSubnetMaskClassType(inDecimalIp) == IPV4Address.CLASS_A_TYPE) return IPV4Address.toDecimalString(IPV4Address.CLASS_A_BINARY); *************** *** 242,247 **** return null; //This should never happen } ! ! /** * This method set the ip address in binary form. It then sets --- 242,247 ---- return null; //This should never happen } ! ! /** * This method set the ip address in binary form. It then sets *************** *** 261,267 **** throw new InvalidIPAddressException("Invalid IP Address, this address is reserved for the loopback device"); } ! String[] ip = inDecimalIp.split("\\."); //split string into an array ! for (int i = 0; i < ip.length; i++) { try { --- 261,267 ---- throw new InvalidIPAddressException("Invalid IP Address, this address is reserved for the loopback device"); } ! String[] ip = inDecimalIp.split("\\."); //split string into an array ! for (int i = 0; i < ip.length; i++) { try { *************** *** 270,275 **** // 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 if (octet.intValue() == 0){ --- 270,275 ---- // 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 if (octet.intValue() == 0){ *************** *** 288,292 **** throw new InvalidIPAddressException("Invalid IP Address, invalid hostID"); } ! /** * This method returns the number of bits used for the network ID of an IP Address --- 288,292 ---- throw new InvalidIPAddressException("Invalid IP Address, invalid hostID"); } ! /** * This method returns the number of bits used for the network ID of an IP Address *************** *** 299,303 **** return inBinarySubnetMask.lastIndexOf("1")+1; } ! /** * This method check to see if the host ID of an IP address is valid --- 299,303 ---- return inBinarySubnetMask.lastIndexOf("1")+1; } ! /** * This method check to see if the host ID of an IP address is valid *************** *** 317,328 **** if(inBinaryIPAddress.length() == 32){ String temp = inBinaryIPAddress.substring(SubnetBits,32); ! if(temp.indexOf("1") != -1){ ! return true; //the address is valid ! } ! return false; } ! throw new InvalidIPAddressException("Invalid ip address"); } ! /** * This method returns the number of bits used in the network ID of an IP Address --- 317,328 ---- if(inBinaryIPAddress.length() == 32){ String temp = inBinaryIPAddress.substring(SubnetBits,32); ! if(temp.indexOf("1") != -1){ ! return true; //the address is valid ! } ! return false; } ! throw new InvalidIPAddressException("Invalid ip address"); } ! /** * This method returns the number of bits used in the network ID of an IP Address *************** *** 334,338 **** return binarySubnetMask.indexOf("0"); //-1 } ! /** * This method returns a decimal string containing the ip address --- 334,338 ---- return binarySubnetMask.indexOf("0"); //-1 } ! /** * This method returns a decimal string containing the ip address *************** *** 344,348 **** return IPV4Address.toDecimalString(binaryIpAddress); } ! /** * This method overrides the toString method. Please note that --- 344,348 ---- return IPV4Address.toDecimalString(binaryIpAddress); } ! /** * This method overrides the toString method. Please note that *************** *** 352,361 **** * @version v0.20 */ ! //TODO: Finish overriding to string method with more details about the object. @Override public String toString(){ return IPV4Address.toDecimalString(binaryIpAddress); } ! /** * This method returns the binary string of the IP address --- 352,361 ---- * @version v0.20 */ ! //TODO: Finish overriding to string method with more details about the object. @Override public String toString(){ return IPV4Address.toDecimalString(binaryIpAddress); } ! /** * This method returns the binary string of the IP address *************** *** 367,371 **** return binaryIpAddress; } ! /** * This method sets a custom subnetMask it will check if the current address --- 367,371 ---- return binaryIpAddress; } ! /** * This method sets a custom subnetMask it will check if the current address *************** *** 381,392 **** */ public void setCustomSubnetMask(String inDecimalSubnetIp) throws InvalidSubnetMaskException{ ! try{ ! String binSubnetMask = IPV4Address.toBinaryString(inDecimalSubnetIp); ! binarySubnetMask = binSubnetMask; ! }catch(Exception e){} /* try{ String binSubnetMask = toBinaryString(inDecimalSubnetIp); ! if(ClassType == CLASS_A_TYPE){ if(binSubnetMask.substring(0,8).equals("11111111")){ --- 381,392 ---- */ public void setCustomSubnetMask(String inDecimalSubnetIp) throws InvalidSubnetMaskException{ ! try{ ! String binSubnetMask = IPV4Address.toBinaryString(inDecimalSubnetIp); ! binarySubnetMask = binSubnetMask; ! }catch(Exception e){} /* try{ String binSubnetMask = toBinaryString(inDecimalSubnetIp); ! if(ClassType == CLASS_A_TYPE){ if(binSubnetMask.substring(0,8).equals("11111111")){ *************** *** 423,429 **** throw new InvalidSubnetMaskException("Invalid Subnet Mask"); } ! */ } ! /** * This method takes a substring of the Subnet mask and validates --- 423,429 ---- throw new InvalidSubnetMaskException("Invalid Subnet Mask"); } ! */ } ! /** * This method takes a substring of the Subnet mask and validates *************** *** 446,452 **** return true; } ! return false; } ! /** * This method returns a binary string of the subnet mask --- 446,452 ---- return true; } ! return false; } ! /** * This method returns a binary string of the subnet mask *************** *** 458,462 **** return binarySubnetMask; } ! /** * This method returns the subnet mask in a decmial string --- 458,462 ---- return binarySubnetMask; } ! /** * This method returns the subnet mask in a decmial string *************** *** 468,472 **** return IPV4Address.toDecimalString(binarySubnetMask); } ! /** * This is a static method that will validate the IP Address --- 468,472 ---- return IPV4Address.toDecimalString(binarySubnetMask); } ! /** * This is a static method that will validate the IP Address *************** *** 482,490 **** return false; } ! ! if(inDecIPAddress.contains("255.255.255.255")){ ! return true; ! } ! for (int i = 0; i < ip.length; i++){ try { --- 482,490 ---- return false; } ! ! if(inDecIPAddress.contains("255.255.255.255")){ ! return true; ! } ! for (int i = 0; i < ip.length; i++){ try { *************** *** 503,523 **** }catch(NumberFormatException e){ return false; ! } ! try { ! //This code check to make sure the host id of an ipaddress is also valid. boolean x = IPV4Address.checkHostId(IPV4Address.toBinaryString(IPV4Address.getDefaultSubnetMask(inDecIPAddress)), IPV4Address.toBinaryString(inDecIPAddress)); ! if(x){ return true; } return false; ! } catch (Exception e) {} //This should never happen! (fingers crossed) } return true; // if it has passed all of these tests return true } ! /** --- 503,523 ---- }catch(NumberFormatException e){ return false; ! } ! try { ! //This code check to make sure the host id of an ipaddress is also valid. boolean x = IPV4Address.checkHostId(IPV4Address.toBinaryString(IPV4Address.getDefaultSubnetMask(inDecIPAddress)), IPV4Address.toBinaryString(inDecIPAddress)); ! if(x){ return true; } return false; ! } catch (Exception e) {} //This should never happen! (fingers crossed) } return true; // if it has passed all of these tests return true } ! /** *************** *** 546,550 **** try { String binSubnetMask = toBinaryString(inDecimalSubnetIp); ! if(getDefaultSubnetMaskClassType(inDecIPAddress) == CLASS_A_TYPE){ if(binSubnetMask.substring(0,8).equals("11111111")){ --- 546,550 ---- try { String binSubnetMask = toBinaryString(inDecimalSubnetIp); ! if(getDefaultSubnetMaskClassType(inDecIPAddress) == CLASS_A_TYPE){ if(binSubnetMask.substring(0,8).equals("11111111")){ *************** *** 564,568 **** } return false; ! }else{ if(binSubnetMask.substring(0,24).equals("111111111111111111111111")){ --- 564,568 ---- } return false; ! }else{ if(binSubnetMask.substring(0,24).equals("111111111111111111111111")){ *************** *** 577,596 **** return false; } ! */ } ! ! public static String IPandMask(String binIP, String binMask){ ! String b1, b2, b3; ! String result = ""; ! for (int i = 0; i < 32; i++) { b1 = binIP.substring(i,i+1); ! b2 = binMask.substring(i,i+1); if(b1.contains("1") && b2.contains("1")) b3="1"; ! else b3="0"; ! result = result + b3; } ! return result; ! } ! /** * This method will test the passed in ipaddress to see --- 577,596 ---- return false; } ! */ } ! ! public static String IPandMask(String binIP, String binMask){ ! String b1, b2, b3; ! String result = ""; ! for (int i = 0; i < 32; i++) { b1 = binIP.substring(i,i+1); ! b2 = binMask.substring(i,i+1); if(b1.contains("1") && b2.contains("1")) b3="1"; ! else b3="0"; ! result = result + b3; } ! return result; ! } ! /** * This method will test the passed in ipaddress to see *************** *** 605,635 **** String subIP; //Substring of the current ip address String subInIP; //substring of the passed in ip address ! ! try { ! int i = getNetworkIDBits(); ! ! subIP = IPV4Address.IPandMask(binaryIpAddress, binarySubnetMask); //Create substring containing only the network bits of the binary address ! subInIP = IPV4Address.IPandMask(IPV4Address.toBinaryString(inIPAddress), binarySubnetMask); ! if(subIP.equals(subInIP)){ //Compare the two substrings return true; } ! return false; } catch (Exception e) { } return false; } ! ! /* ! * int i = getNetworkIDBits(); ! subIP = binaryIpAddress.substring(0,i); //Create substring containing only the network bits of the binary address subInIP = IPV4Address.toBinaryString(inIPAddress).substring(0,getNetworkIDBits()); ! if(subIP.equals(subInIP)){ //Compare the two substrings return true; } ! */ ! }//EOF --- 605,667 ---- String subIP; //Substring of the current ip address String subInIP; //substring of the passed in ip address ! ! try { ! int i = getNetworkIDBits(); ! ! subIP = IPV4Address.IPandMask(binaryIpAddress, binarySubnetMask); //Create substring containing only the network bits of the binary address ! subInIP = IPV4Address.IPandMask(IPV4Address.toBinaryString(inIPAddress), binarySubnetMask); ! if(subIP.equals(subInIP)){ //Compare the two substrings return true; } ! return false; } catch (Exception e) { } return false; } ! ! /* ! * int i = getNetworkIDBits(); ! subIP = binaryIpAddress.substring(0,i); //Create substring containing only the network bits of the binary address subInIP = IPV4Address.toBinaryString(inIPAddress).substring(0,getNetworkIDBits()); ! if(subIP.equals(subInIP)){ //Compare the two substrings return true; } ! */ ! ! public static long IPString2Number(String sip){ ! long nip = 0; ! String[] asip = sip.split("\\."); ! if(asip.length==4){ ! for(int i=0; i<4; i++){ ! try{ ! int val = Integer.parseInt(asip[i]); ! if(val>=0 && val<=255){ ! nip = (nip<<8) + val; ! } ! else return -1; ! } ! catch(NumberFormatException e){ ! return -1; ! } ! } ! } ! else return -1; ! return nip; ! } ! ! public static boolean isBetween(String ip, String low, String high){ ! boolean result = false; ! long nip = IPString2Number(ip); ! long nlow = IPString2Number(low); ! long nhigh = IPString2Number(high); ! if(nip>-1 && nlow>-1 && nhigh>-1){ ! result = (nip>=nlow && nip<=nhigh); ! } ! return result; ! } ! }//EOF |
From: QweR <qw...@us...> - 2008-10-29 19:36:38
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12987/core Modified Files: ApplicationLayerDevice.java CommandProcessor.java Log Message: dhcp exclude was added some commands was fixed Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** CommandProcessor.java 27 Oct 2008 21:22:11 -0000 1.38 --- CommandProcessor.java 29 Oct 2008 19:36:20 -0000 1.39 *************** *** 282,286 **** commands.add("telnet", telnet_Command, "Open a telnet connection"); commands.add("telnet-server", telnet_server_Command, "Enable TELNET server; Specify server port"); ! commands.add("no telnet-server", telnet_server_Command, "Disable TELNET server"); commands.add("username", username_Command, "Add User"); commands.add("vlan", vlan_Command, "Create VLAN"); --- 282,286 ---- commands.add("telnet", telnet_Command, "Open a telnet connection"); commands.add("telnet-server", telnet_server_Command, "Enable TELNET server; Specify server port"); ! //commands.add("no telnet-server", telnet_server_Command, "Disable TELNET server"); commands.add("username", username_Command, "Add User"); commands.add("vlan", vlan_Command, "Create VLAN"); *************** *** 405,409 **** class clock_set_CommandClass extends CommandInterface{ public clock_set_CommandClass (){ ! modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); call_params = "<hh:mm:ss> <1-31> <1-12> <1970-2100>"; } --- 405,409 ---- class clock_set_CommandClass extends CommandInterface{ public clock_set_CommandClass (){ ! modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NO_LAYER, CommandInterface.CALL_ONLY); call_params = "<hh:mm:ss> <1-31> <1-12> <1970-2100>"; } *************** *** 506,539 **** } }; - class location_CommandClass extends CommandInterface{ - public location_CommandClass(){ - modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NO_LAYER, CommandInterface.NO_CALL); - call_params = "<cr>"; - } - public String call(Vector<String> params){ - String out = ""; - if(params.size()>=1){ - String desc = params.get(1); - for(int i=1; i<params.size(); i++){ - desc += " "+params.get(i); - } - device.location = desc; - } - else{ - out += "error: invalid parameters\n"; - } - return out; - } - public String no_call(Vector<String> params){ - String out = ""; - if(params.size()==0){ - device.location = ""; - } - else{ - out += "error: invalid parameters\n"; - } - return out; - } - }; class reload_CommandClass extends CommandInterface{ public reload_CommandClass(){ --- 506,509 ---- *************** *** 2004,2008 **** } //device.getConfig().add("ip access-list "+iacl+" "+permit_deny+" "+hosts); ! if((IPV4Address.validateDecIP(ip) || ip.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask)){ if(add){ device.getACL().addACL(iacl, iline, action, ip, mask, log); --- 1974,1978 ---- } //device.getConfig().add("ip access-list "+iacl+" "+permit_deny+" "+hosts); ! if((IPV4Address.isValidIp(ip) || ip.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask)){ if(add){ device.getACL().addACL(iacl, iline, action, ip, mask, log); *************** *** 2163,2168 **** if(port >= 0){ ! if((IPV4Address.validateDecIP(ip1) || ip1.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask1) && ! (IPV4Address.validateDecIP(ip2) || ip2.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask2)){ if(port==0 || (protocol == AccessListEngine.access_list.TCP || protocol == AccessListEngine.access_list.UDP)){ if(add){ --- 2133,2138 ---- if(port >= 0){ ! if((IPV4Address.isValidIp(ip1) || ip1.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask1) && ! (IPV4Address.isValidIp(ip2) || ip2.compareTo("0.0.0.0")==0) && IPV4Address.validateDecSubnetMask(mask2)){ if(port==0 || (protocol == AccessListEngine.access_list.TCP || protocol == AccessListEngine.access_list.UDP)){ if(add){ *************** *** 2224,2228 **** String poolname = params.get(0); String defrouter = params.get(1); ! if(IPV4Address.validateDecIP(defrouter)){ if(!dhcpd.pools.containsKey(poolname)){ dhcpd.pools.put(poolname, dhcpd.new_pool()); --- 2194,2198 ---- String poolname = params.get(0); String defrouter = params.get(1); ! if(IPV4Address.isValidIp(defrouter)){ if(!dhcpd.pools.containsKey(poolname)){ dhcpd.pools.put(poolname, dhcpd.new_pool()); *************** *** 2456,2460 **** String low_ip = params.get(0); String high_ip = params.get(1); ! if(IPV4Address.validateDecIP(low_ip) && IPV4Address.validateDecIP(high_ip)){ dhcpd.excludeAddress(low_ip, high_ip); } --- 2426,2430 ---- String low_ip = params.get(0); String high_ip = params.get(1); ! if(IPV4Address.isValidIp(low_ip) && IPV4Address.isValidIp(high_ip)){ dhcpd.excludeAddress(low_ip, high_ip); } *************** *** 2484,2488 **** String low_ip = params.get(0); String high_ip = params.get(1); ! if(IPV4Address.validateDecIP(low_ip) && IPV4Address.validateDecIP(high_ip)){ dhcpd.no_excludeAddress(low_ip, high_ip); } --- 2454,2458 ---- String low_ip = params.get(0); String high_ip = params.get(1); ! if(IPV4Address.isValidIp(low_ip) && IPV4Address.isValidIp(high_ip)){ dhcpd.no_excludeAddress(low_ip, high_ip); } *************** *** 2628,2632 **** public ip_dns_server_CommandClass(){ modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); ! call_params = "(<port>|<cr>)"; no_call_params = "<cr>"; } --- 2598,2602 ---- public ip_dns_server_CommandClass(){ modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); ! call_params = "[<port>]"; no_call_params = "<cr>"; } *************** *** 2707,2711 **** String first = params.get(0); String second = params.get(1); ! if(IPV4Address.validateDecIP(first) && DNS.isValidName(second)){ if(add) dns.addRecord(DNS.toInAddrArpa(first), second, DNS_Message.PTR_QUERY_TYPE); --- 2677,2681 ---- String first = params.get(0); String second = params.get(1); ! if(IPV4Address.isValidIp(first) && DNS.isValidName(second)){ if(add) dns.addRecord(DNS.toInAddrArpa(first), second, DNS_Message.PTR_QUERY_TYPE); *************** *** 2713,2717 **** dns.removeRecord(DNS.toInAddrArpa(first), second, DNS_Message.PTR_QUERY_TYPE); } ! else if(IPV4Address.validateDecIP(second) && DNS.isValidName(first)){ if(add) dns.addRecord(first, second, DNS_Message.A_QUERY_TYPE); --- 2683,2687 ---- dns.removeRecord(DNS.toInAddrArpa(first), second, DNS_Message.PTR_QUERY_TYPE); } ! else if(IPV4Address.isValidIp(second) && DNS.isValidName(first)){ if(add) dns.addRecord(first, second, DNS_Message.A_QUERY_TYPE); *************** *** 2866,2870 **** if(params.size()==1){ String ns = params.get(0); ! if(IPV4Address.validateDecIP(ns)){ ((ApplicationLayerDevice)device).setNameServer(ns); } --- 2836,2840 ---- if(params.size()==1){ String ns = params.get(0); ! if(IPV4Address.isValidIp(ns)){ ((ApplicationLayerDevice)device).setNameServer(ns); } *************** *** 3098,3102 **** valid = false; } ! if(valid && IPV4Address.validateDecIP(local_ip) && IPV4Address.validateDecIP(global_ip)){ if(add){ NAT_rule rule = device.getNAT().new NAT_rule(); --- 3068,3072 ---- valid = false; } ! if(valid && IPV4Address.isValidIp(local_ip) && IPV4Address.isValidIp(global_ip)){ if(add){ NAT_rule rule = device.getNAT().new NAT_rule(); *************** *** 3156,3160 **** String low_ip = params.get(1); String high_ip = params.get(2); ! if(IPV4Address.validateDecIP(low_ip) && IPV4Address.validateDecIP(high_ip)){ device.getNAT().addPool(poolname, new Pair(low_ip,high_ip)); } --- 3126,3130 ---- String low_ip = params.get(1); String high_ip = params.get(2); ! if(IPV4Address.isValidIp(low_ip) && IPV4Address.isValidIp(high_ip)){ device.getNAT().addPool(poolname, new Pair(low_ip,high_ip)); } *************** *** 3300,3303 **** --- 3270,3304 ---- } }; + class location_CommandClass extends CommandInterface{ + public location_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NO_LAYER, CommandInterface.NO_CALL); + call_params = "<location>"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()>=1){ + String desc = params.get(1); + for(int i=1; i<params.size(); i++){ + desc += " "+params.get(i); + } + device.location = desc; + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==0){ + device.location = ""; + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class router_rip_CommandClass extends CommandInterface{ public router_rip_CommandClass(){ *************** *** 4556,4560 **** } }; - class vlan_CommandClass extends CommandInterface{ public vlan_CommandClass(){ --- 4557,4560 ---- Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ApplicationLayerDevice.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ApplicationLayerDevice.java 26 Oct 2008 22:02:46 -0000 1.13 --- ApplicationLayerDevice.java 29 Oct 2008 19:36:20 -0000 1.14 *************** *** 112,116 **** public boolean setNameServer(String ns){ ! if(IPV4Address.validateDecIP(ns)){ nameServer = ns; return true; --- 112,116 ---- public boolean setNameServer(String ns){ ! if(IPV4Address.isValidIp(ns)){ nameServer = ns; return true; |
From: QweR <qw...@us...> - 2008-10-27 21:22:17
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17633/guiUI Modified Files: MainScreen.java MenuBar.java Log Message: quit() was extended Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.104 retrieving revision 1.105 diff -C2 -d -r1.104 -r1.105 *** MainScreen.java 27 Oct 2008 16:09:02 -0000 1.104 --- MainScreen.java 27 Oct 2008 21:22:11 -0000 1.105 *************** *** 69,73 **** import java.awt.event.ComponentListener; import java.awt.image.BufferedImage; - import java.awt.image.RenderedImage; import java.io.BufferedReader; import java.io.BufferedWriter; --- 69,72 ---- *************** *** 120,124 **** import core.Node; import core.Simulation; - import core.protocolsuite.tcp_ip.DHCPC; import core.protocolsuite.tcp_ip.DHCPD; import core.protocolsuite.tcp_ip.Echo; --- 119,122 ---- *************** *** 609,613 **** this.setLocationRelativeTo(null); ! this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); --- 607,617 ---- this.setLocationRelativeTo(null); ! this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); ! ! this.addWindowListener(new java.awt.event.WindowAdapter() { ! public void windowClosing(java.awt.event.WindowEvent e) { ! quit(); ! } ! }); this.setVisible(true); *************** *** 1570,1574 **** public void quit() { ! System.exit(0); } --- 1574,1594 ---- public void quit() { ! if(isDirty){ ! int result = JOptionPane.showConfirmDialog(this, ! "Save changes"+(simSaveFile!=null?" as "+simSaveFile.getName():"")+"?"); ! switch(result){ ! case JOptionPane.YES_OPTION:{ ! if(Save()){ ! System.exit(0); ! } ! break; ! } ! case JOptionPane.NO_OPTION: System.exit(0); break; ! case JOptionPane.CANCEL_OPTION: break; ! } ! } ! else{ ! System.exit(0); ! } } *************** *** 1708,1720 **** } ! public void Save() { if (simSaveFile != null) ! SaveAs(simSaveFile.getPath()); else ! SaveAs(null); } ! public void SaveAs(String saveas) { ! JFileChooser chooser = new JFileChooser(); --- 1728,1740 ---- } ! public boolean Save() { if (simSaveFile != null) ! return SaveAs(simSaveFile.getPath()); else ! return SaveAs(null); } ! public boolean SaveAs(String saveas) { ! JFileChooser chooser = new JFileChooser(); *************** *** 1747,1752 **** if(JOptionPane.showConfirmDialog(this, "File exists! Overwrite?", "Confirm overwriting!", JOptionPane.YES_NO_OPTION, ! JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) ! return; } --- 1767,1772 ---- if(JOptionPane.showConfirmDialog(this, "File exists! Overwrite?", "Confirm overwriting!", JOptionPane.YES_NO_OPTION, ! JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) ! return false; } *************** *** 1923,1926 **** --- 1943,1948 ---- setStatus("Simulation was saved succesfully."); + + return true; } catch (IOException e) { *************** *** 1933,1936 **** --- 1955,1960 ---- } + + return false; } Index: MenuBar.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MenuBar.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** MenuBar.java 24 Oct 2008 18:13:48 -0000 1.22 --- MenuBar.java 27 Oct 2008 21:22:11 -0000 1.23 *************** *** 247,260 **** mnuExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ! int result = JOptionPane ! .showConfirmDialog(null, ! "Are you sure you wish to quit?", ! "Really Quit?", JOptionPane.YES_NO_OPTION, ! JOptionPane.QUESTION_MESSAGE); ! ! if (result == JOptionPane.YES_OPTION) { ! // Quit the program if Yes is selected. controller.quit(); ! } } }); --- 247,260 ---- mnuExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ! // int result = JOptionPane ! // .showConfirmDialog(null, ! // "Are you sure you wish to quit?", ! // "Really Quit?", JOptionPane.YES_NO_OPTION, ! // JOptionPane.QUESTION_MESSAGE); ! // ! // if (result == JOptionPane.YES_OPTION) { ! // // Quit the program if Yes is selected. controller.quit(); ! // } } }); |
From: QweR <qw...@us...> - 2008-10-27 21:22:17
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17633/core Modified Files: CommandProcessor.java DeviceConfig.java NetworkInterfacePort.java Log Message: quit() was extended Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** CommandProcessor.java 26 Oct 2008 22:06:51 -0000 1.37 --- CommandProcessor.java 27 Oct 2008 21:22:11 -0000 1.38 *************** *** 86,89 **** --- 86,90 ---- private interface__stopbits_CommandClass interface__stopbits_Command = new interface__stopbits_CommandClass(); private interface__switchport_access_vlan_CommandClass interface__switchport_access_vlan_Command = new interface__switchport_access_vlan_CommandClass(); + private interface__switchport_description_CommandClass interface__switchport_description_Command = new interface__switchport_description_CommandClass(); private interface__switchport_mode_access_CommandClass interface__switchport_mode_access_Command = new interface__switchport_mode_access_CommandClass(); private interface__switchport_mode_trunk_CommandClass interface__switchport_mode_trunk_Command = new interface__switchport_mode_trunk_CommandClass(); *************** *** 200,203 **** --- 201,205 ---- commands.addDescription("interface * switchport access","Configure a port access"); commands.add("interface * switchport access vlan", interface__switchport_access_vlan_Command, "Configure a port as a static-access port"); + commands.add("interface * switchport description", interface__switchport_description_Command, "Port specific description"); commands.addDescription("interface * switchport mode","Configure the VLAN membership mode of a port"); commands.add("interface * switchport mode access", interface__switchport_mode_access_Command, "Set the port to access mode"); *************** *** 1841,1844 **** --- 1843,1889 ---- } }; + class interface__switchport_description_CommandClass extends CommandInterface{ + public interface__switchport_description_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "<description>"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + return parse(params, true); + } + public String no_call(Vector<String> params){ + return parse(params, false); + } + private String parse(Vector<String> params, boolean add){ + String out = ""; + if((params.size()>1 && add) || (params.size()==1 && !add)){ + try{ + NetworkInterface ni = device.getNetworkInterface(params.get(0)); + if(ni instanceof NetworkInterfacePort){ + NetworkInterfacePort eni = (NetworkInterfacePort) ni; + if(add){ + String desc = params.get(1); + for(int i=2; i<params.size(); i++){ + desc += " "+params.get(i); + } + eni.description = desc; + } + else{ + eni.description = ""; + } + } + else{ + out += "error: only ethernet interfaces is allowed\n"; + } + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__switchport_mode_access_CommandClass extends CommandInterface{ public interface__switchport_mode_access_CommandClass(){ *************** *** 3768,3772 **** if(ni instanceof NetworkInterfacePort){ NetworkInterfacePort eni = (NetworkInterfacePort)ni; - //if(eni.vlan > 1){ out += " VLAN ID: "+eni.vlan+"\n"; String vmode = "unknown"; --- 3813,3816 ---- *************** *** 3776,3780 **** } out += " VLAN mode: "+vmode+"\n"; ! //} } if(ni instanceof WiFiPort){ --- 3820,3825 ---- } out += " VLAN mode: "+vmode+"\n"; ! if(eni.description!="") ! out += " VLAN description: "+eni.description+"\n"; } if(ni instanceof WiFiPort){ Index: NetworkInterfacePort.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterfacePort.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** NetworkInterfacePort.java 24 Oct 2008 16:18:48 -0000 1.13 --- NetworkInterfacePort.java 27 Oct 2008 21:22:11 -0000 1.14 *************** *** 121,124 **** --- 121,125 ---- final static int MODE_TRUNK = 1; public int mode = NetworkInterfacePort.MODE_ACCESS; + public String description = ""; protected NetworkInterfacePort(long UID, String inName, Node inParent) { Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** DeviceConfig.java 26 Oct 2008 22:06:51 -0000 1.28 --- DeviceConfig.java 27 Oct 2008 21:22:11 -0000 1.29 *************** *** 446,449 **** --- 446,452 ---- break; } + if(pni.description!=""){ + conf.add("interface "+intName+" switchport description "+pni.description); + } } |
From: Alexander B. <da...@us...> - 2008-10-27 18:44:49
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv27004/guiUI Added Files: ConsolePortProperties.java Log Message: --- NEW FILE: ConsolePortProperties.java --- /* Java Network Simulator (javaNetSim) Copyright (c) 2007, 2006, 2005, Ice Team; All rights reserved. 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 guiUI; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.WindowConstants; import core.NetworkLayerDevice; import core.Simulation; /** * * @author Key * * * This class is a dialog that shows Ethernet Port Props * */ public class ConsolePortProperties extends javax.swing.JDialog { /** * */ private static final long serialVersionUID = -8725131940909728774L; private JPanel backpanel; private JLabel lblInterface, cmbInterface; private JLabel lblNodeName, cmbNodeName; private JLabel lblError; private JButton btnOk; private JLabel lblUP; private JCheckBox chkUP; private JLabel lblBPS; private JComboBox cmbBPS; private JLabel lblDataBits; private JComboBox cmbDataBits; private JLabel lblParity; private JComboBox cmbParity; private JLabel lblStopBits; private JComboBox cmbStopBits; private JLabel lblFlowControl; private JComboBox cmbFlowControl; private MainScreen controller; private Simulation Sim; private String NodeName = ""; private String NodeInt = ""; public ConsolePortProperties(JFrame frame, String inNodeName, String inNodeInt, Simulation Sim) { super(frame); this.NodeName = inNodeName; this.NodeInt = inNodeInt; this.Sim = Sim; setResizable(false); controller = (MainScreen) frame; setTitle("WiFi Port Properties"); initGUI(inNodeName, inNodeInt); final JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.SOUTH); btnOk = new JButton(); btnOk.setEnabled(true); btnOk.setToolTipText("Set options!"); btnOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okButton(); } }); btnOk.setName("btnOK"); panel.add(btnOk); btnOk.setText("OK"); final JButton btnCancel = new JButton(); btnCancel.setToolTipText("Cancel changes"); btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton(); } }); btnCancel.setName("btnCancel"); panel.add(btnCancel); btnCancel.setText("Cancel"); this.getRootPane().setDefaultButton(btnOk); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setLocationRelativeTo(null); this.setModal(true); this.setVisible(true); } private void initGUI(String NodeName, String NodeInt) { try { setSize(350, 325); { backpanel = new JPanel(); backpanel.setMinimumSize(new Dimension(200, 10)); this.getContentPane().add(backpanel, BorderLayout.CENTER); GridBagLayout backpanelLayout = new GridBagLayout(); backpanel.setPreferredSize(new java.awt.Dimension(264, 253)); backpanelLayout.columnWeights = new double[] {}; backpanelLayout.columnWidths = new int[] {}; backpanelLayout.rowWeights = new double[] { 0.0 }; backpanelLayout.rowHeights = new int[] { 5, 5, 5, 5 }; backpanel.setLayout(backpanelLayout); { lblNodeName = new JLabel(); backpanel.add(lblNodeName, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 21, 0)); lblNodeName.setText("Node Name:"); } { lblInterface = new JLabel(); backpanel.add(lblInterface, new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblInterface.setText("Interface:"); } { lblBPS = new JLabel(); backpanel.add(lblBPS, new GridBagConstraints(0, 2, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblBPS.setText("Bits per second:"); } { lblDataBits = new JLabel(); backpanel.add(lblDataBits, new GridBagConstraints(0, 3, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblDataBits.setText("Data Bits:"); } { lblParity = new JLabel(); backpanel.add(lblParity, new GridBagConstraints(0, 4, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblParity.setText("Parity:"); } { lblStopBits = new JLabel(); backpanel.add(lblStopBits, new GridBagConstraints(0, 5, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblStopBits.setText("Stop Bits:"); } { lblFlowControl = new JLabel(); backpanel.add(lblFlowControl, new GridBagConstraints(0, 6, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblFlowControl.setText("Flow Control:"); } { lblUP = new JLabel(); backpanel.add(lblUP, new GridBagConstraints(0, 7, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblUP.setText("Administratively UP:"); } { cmbNodeName = new JLabel(); cmbNodeName.setMinimumSize(new Dimension(100, 0)); cmbNodeName.setText(NodeName); final GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.LINE_START; gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 1; backpanel.add(cmbNodeName, gridBagConstraints); } { cmbInterface = new JLabel(); cmbInterface.setText(NodeInt); final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints(); gridBagConstraints_1.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_1.anchor = GridBagConstraints.LINE_START; gridBagConstraints_1.gridy = 1; gridBagConstraints_1.gridx = 1; backpanel.add(cmbInterface, gridBagConstraints_1); } core.ConsoleNetworkInterface cint = (core.ConsoleNetworkInterface)Sim.getNode(NodeName).getNetworkInterface(NodeInt); cmbBPS = new JComboBox(); cmbBPS.setEnabled(true); final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints(); gridBagConstraints_6.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_6.anchor = GridBagConstraints.LINE_START; gridBagConstraints_6.gridy = 2; gridBagConstraints_6.gridx = 1; backpanel.add(cmbBPS, gridBagConstraints_6); cmbBPS.addItem(110); cmbBPS.addItem(300); cmbBPS.addItem(1200); cmbBPS.addItem(2400); cmbBPS.addItem(4800); cmbBPS.addItem(9600); cmbBPS.addItem(19200); cmbBPS.addItem(38400); cmbBPS.addItem(57600); cmbBPS.addItem(115200); cmbBPS.addItem(230400); cmbBPS.addItem(460800); cmbBPS.addItem(921600); for(int i=0; i<cmbBPS.getItemCount(); i++) if((Integer)(cmbBPS.getItemAt(i)) == cint.speed){ cmbBPS.setSelectedIndex(i); break; } cmbDataBits = new JComboBox(); cmbDataBits.setEnabled(true); final GridBagConstraints gridBagConstraints_12 = new GridBagConstraints(); gridBagConstraints_12.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_12.anchor = GridBagConstraints.LINE_START; gridBagConstraints_12.gridy = 3; gridBagConstraints_12.gridx = 1; backpanel.add(cmbDataBits, gridBagConstraints_12); cmbDataBits.addItem(5); cmbDataBits.addItem(6); cmbDataBits.addItem(7); cmbDataBits.addItem(8); cmbDataBits.setSelectedIndex( cint.databits - 5 ); //if(((core.WiFiPort)Sim.getNode(NodeName).getNetworkInterface(NodeInt)).getMode() == core.WiFiPort.MODE_AP) // cmbMode.setSelectedIndex(1); cmbParity = new JComboBox(); cmbParity.setEnabled(true); final GridBagConstraints gridBagConstraints_13 = new GridBagConstraints(); gridBagConstraints_13.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_13.anchor = GridBagConstraints.LINE_START; gridBagConstraints_13.gridy = 4; gridBagConstraints_13.gridx = 1; backpanel.add(cmbParity, gridBagConstraints_13); cmbParity.addItem("none"); cmbParity.addItem("even"); cmbParity.addItem("odd"); cmbParity.addItem("marker"); cmbParity.addItem("space"); cmbParity.setSelectedIndex(cint.parity - 1); //if(((core.WiFiPort)Sim.getNode(NodeName).getNetworkInterface(NodeInt)).getMode() == core.WiFiPort.MODE_AP) // cmbMode.setSelectedIndex(1); cmbStopBits = new JComboBox(); cmbStopBits.setEnabled(true); final GridBagConstraints gridBagConstraints_14 = new GridBagConstraints(); gridBagConstraints_14.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_14.anchor = GridBagConstraints.LINE_START; gridBagConstraints_14.gridy = 5; gridBagConstraints_14.gridx = 1; backpanel.add(cmbStopBits, gridBagConstraints_14); cmbStopBits.addItem("1"); cmbStopBits.addItem("1.5"); cmbStopBits.addItem("2"); cmbParity.setSelectedIndex(cint.stopbits - 1); cmbFlowControl = new JComboBox(); cmbFlowControl.setEnabled(true); final GridBagConstraints gridBagConstraints_15 = new GridBagConstraints(); gridBagConstraints_15.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_15.anchor = GridBagConstraints.LINE_START; gridBagConstraints_15.gridy = 6; gridBagConstraints_15.gridx = 1; backpanel.add(cmbFlowControl, gridBagConstraints_15); cmbFlowControl.addItem("none"); cmbFlowControl.addItem("hardware"); cmbFlowControl.addItem("software"); cmbParity.setSelectedIndex(cint.flowcontrol - 1); chkUP = new JCheckBox(); chkUP.setEnabled(true); final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints(); gridBagConstraints_4.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_4.anchor = GridBagConstraints.LINE_START; gridBagConstraints_4.gridy = 7; gridBagConstraints_4.gridx = 1; backpanel.add(chkUP, gridBagConstraints_4); chkUP.setSelected(Sim.getNode(NodeName).getNIC(NodeInt).isUP()); lblError = new JLabel(); lblError.setHorizontalTextPosition(SwingConstants.CENTER); lblError.setHorizontalAlignment(SwingConstants.CENTER); lblError.setAlignmentX(Component.CENTER_ALIGNMENT); lblError.setMinimumSize(new Dimension(100, 20)); lblError.setMaximumSize(new Dimension(100, 20)); lblError.setPreferredSize(new Dimension(100, 20)); lblError.setVisible(false); final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints(); gridBagConstraints_5.anchor = GridBagConstraints.WEST; gridBagConstraints_5.insets = new Insets(0, 1, 0, 0); gridBagConstraints_5.fill = GridBagConstraints.BOTH; gridBagConstraints_5.gridwidth = 2; gridBagConstraints_5.gridy = 8; gridBagConstraints_5.gridx = 0; backpanel.add(lblError, gridBagConstraints_5); lblError.setText("Invalid MAC!"); } } catch (Exception e) { e.printStackTrace(); } } /** * This method is executed when the user hit's the enter button. It will * delete the link on selected interface. * * @author Key * */ private void okButton() { try { /*String SC = txtMAC.getText(); if (!SC.matches("[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]")) { Error("Invalid MAC Address!"); return; } if(txtSSID.getText().length() < 2){ Error("Invalid SSID!"); }*/ NetworkLayerDevice tmpNode = (NetworkLayerDevice) Sim.getNode(NodeName); tmpNode.getConfig().executeCommand( "int " + NodeInt + " shutdown"); tmpNode.getConfig().executeCommand( "int " + NodeInt + " speed " + cmbBPS.getSelectedItem()); tmpNode.getConfig().executeCommand( "int " + NodeInt + " databits " + cmbDataBits.getSelectedItem()); tmpNode.getConfig().executeCommand( "int " + NodeInt + " parity " + cmbParity.getSelectedItem()); tmpNode.getConfig().executeCommand( "int " + NodeInt + " stopbits " + cmbStopBits.getSelectedItem()); tmpNode.getConfig().executeCommand( "int " + NodeInt + " flowcontrol " + cmbFlowControl.getSelectedItem()); if (chkUP.isSelected()) { tmpNode.getConfig().executeCommand( "no int " + NodeInt + " shutdown"); } else { tmpNode.getConfig().executeCommand( "int " + NodeInt + " shutdown"); } tmpNode.getConfig().executeCommand("write mem"); this.dispose(); } catch (Exception e) { e.printStackTrace(); } } /** * This method is executed when the user hits the cancel button * * @author luke_hamilton * @author Key * */ private void cancelButton() { this.dispose(); } private void Error(String txt){ lblError.setText(txt); lblError.setForeground(Color.RED); lblError.setVisible(true); controller.shakeDiaLog(this); } } |
From: Alexander B. <da...@us...> - 2008-10-27 18:28:00
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv25328/core Modified Files: MultilayerSwitch.java Switch.java Log Message: Index: Switch.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Switch.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Switch.java 24 Oct 2008 16:18:48 -0000 1.13 --- Switch.java 27 Oct 2008 18:27:53 -0000 1.14 *************** *** 1,37 **** /* ! Java Network Simulator (jNetSim) ! Copyright (c) 2005, Ice Team; All rights reserved. ! 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 Ice Team 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; import java.util.Enumeration; import java.util.Hashtable; ! /** ! * This class extends of the DataLinkLayerDevice and allows the ! * creation of switches * @author bevan_calliess * @author luke_hamilton --- 1,39 ---- /* ! Java Network Simulator (jNetSim) ! Copyright (c) 2005, Ice Team; All rights reserved. ! 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 Ice Team 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; + import java.util.Enumeration; import java.util.Hashtable; ! /** ! * This class extends of the DataLinkLayerDevice and allows the creation of ! * switches ! * * @author bevan_calliess * @author luke_hamilton *************** *** 39,46 **** * @since Nov 8, 2005 * @version v0.22 ! **/ public class Switch extends DataLinkLayerDevice { ! /** * --- 41,48 ---- * @since Nov 8, 2005 * @version v0.22 ! */ public class Switch extends DataLinkLayerDevice { ! /** * *************** *** 50,194 **** /** * This creates a layer 2 switch with a default of 5 interface (ports) * @author luke_hamilton ! * @param inName The name of the Switch * @param inProtocolStackLayers * @version v0.20 */ ! ! int sz = 0; ! ! int buffSize = 255; ! ! Hashtable IntCaches; ! ! public Switch(String inName, boolean inOn) { ! super(inName, 1, inOn); //pass name and protocolstack layer ! ! IntCaches = new Hashtable(); } ! ! @Override ! public void addNetworkInterface(String name, int type, boolean active){ ! if(!active){ ! super.addNetworkInterface(name, type, false, 0); ! IntCaches.put(name, new Hashtable()); ! } ! } ! ! @Override ! public void Reset(){ ! sz = 0; ! Enumeration it; ! String nic = ""; ! ! it = NetworkInterfacetable.elements(); ! ! while(it.hasMoreElements()){ ! NetworkInterface tempInterface = (NetworkInterface)it.nextElement(); ! nic = tempInterface.getName(); ! Hashtable outInt = (Hashtable) IntCaches.get(nic); ! outInt.clear(); ! } ! super.Reset(); ! } ! ! @Override ! public int getState(){ ! return sz; ! } ! ! public String getCache(){ ! Enumeration it, it2; ! String nic = ""; ! String result = ""; ! ! it = NetworkInterfacetable.elements(); ! ! while(it.hasMoreElements()){ ! NetworkInterface tempInterface = (NetworkInterface)it.nextElement(); nic = tempInterface.getName(); ! Hashtable outInt = (Hashtable) IntCaches.get(nic); ! ! result = result + nic + ": "; ! ! it2 = outInt.keys(); ! ! while(it2.hasMoreElements()){ ! String mac = (String)it2.nextElement(); ! result = result + mac + "\t"; ! } ! ! result = result + "\n"; ! } ! ! return result; ! } ! /** ! * This method will recieve a packet from any of the connected links and the copy ! * the Packet and distribute a copy to each of the other connected links. * @author bevan_calliess ! * @param inPacket - The packet to be transported ! * @param inLinkName - The name of the link that sent the packet eg: eth0 */ ! @Override ! protected void receivePacket(Packet inPacket,String inInterfaceName) throws LowLinkException{ ! if(sz!=1){ ! Ethernet_packet tempPacket = (Ethernet_packet)inPacket; ! Enumeration it; ! boolean intFound = false; ! String nic = ""; ! ! try{ ! Hashtable inInt = (Hashtable) IntCaches.get(inInterfaceName); ! inInt.put(tempPacket.getSourceMACAddress(), "1"); ! Ethernet_packet copyPacket = new Ethernet_packet(tempPacket.getData(), tempPacket.getDestinationMACAddress(),tempPacket.getSourceMACAddress()); ! // tag it ! copyPacket.vlan_id = tempPacket.vlan_id; ! ! it = NetworkInterfacetable.elements(); ! while(it.hasMoreElements()){ ! NetworkInterface tempInterface = (NetworkInterface)it.nextElement(); ! nic = tempInterface.getName(); ! Hashtable outInt = (Hashtable) IntCaches.get(nic); ! if(outInt.get(tempPacket.getDestinationMACAddress()) != null){ ! intFound = true; ! try{ ! tempInterface.sendPacket(copyPacket); ! }catch(NullPointerException e){ ! System.out.println("Switch.java: " + e.toString()); ! } ! } ! } ! ! it = NetworkInterfacetable.elements(); ! while(it.hasMoreElements() && !intFound){ ! //Test to see if the current Interface is the Interface that sent in the packet ! // if it is skip that interface ! NetworkInterface tempInterface = (NetworkInterface)it.nextElement(); ! if(!tempInterface.getName().equals(inInterfaceName)){ ! ! try{ ! tempInterface.sendPacket(copyPacket); ! }catch(NullPointerException e){ ! System.out.println("Switch.java: " + e.toString()); ! } ! } ! ! } ! ! }catch(Throwable th) ! { ! if(th.toString().contains("Packet lost due to physical link problems!")){ ! throw new LowLinkException(th.toString()); ! }else{ ! sz=1; ! System.out.println(th.toString()); ! throw new LowLinkException("Switch buffer overflow (packet loop flood?)."); ! } ! } ! } } } --- 52,214 ---- /** * This creates a layer 2 switch with a default of 5 interface (ports) + * * @author luke_hamilton ! * @param inName ! * The name of the Switch * @param inProtocolStackLayers * @version v0.20 */ ! ! int sz = 0; ! ! int buffSize = 255; ! ! Hashtable IntCaches; ! ! public Switch(String inName, boolean inOn) { ! super(inName, 1, inOn); // pass name and protocolstack layer ! ! IntCaches = new Hashtable(); } ! @Override ! public void addNetworkInterface(String name, int type, boolean active) { ! if (!active) { ! super.addNetworkInterface(name, type, false, 0); ! IntCaches.put(name, new Hashtable()); ! } ! } ! ! @Override ! public void Reset() { ! sz = 0; ! Enumeration it; ! String nic = ""; ! ! it = NetworkInterfacetable.elements(); ! ! while (it.hasMoreElements()) { ! NetworkInterface tempInterface = (NetworkInterface) it ! .nextElement(); nic = tempInterface.getName(); ! Hashtable outInt = (Hashtable) IntCaches.get(nic); ! outInt.clear(); ! } ! super.Reset(); ! } ! ! @Override ! public int getState() { ! return sz; ! } ! ! public String getCache() { ! Enumeration it, it2; ! String nic = ""; ! String result = ""; ! ! it = NetworkInterfacetable.elements(); ! ! while (it.hasMoreElements()) { ! NetworkInterface tempInterface = (NetworkInterface) it ! .nextElement(); ! nic = tempInterface.getName(); ! Hashtable outInt = (Hashtable) IntCaches.get(nic); ! ! result = result + nic + ": "; ! ! it2 = outInt.keys(); ! ! while (it2.hasMoreElements()) { ! String mac = (String) it2.nextElement(); ! result = result + mac + "\t"; ! } ! ! result = result + "\n"; ! } ! ! return result; ! } ! /** ! * This method will recieve a packet from any of the connected links and the ! * copy the Packet and distribute a copy to each of the other connected ! * links. ! * * @author bevan_calliess ! * @param inPacket - ! * The packet to be transported ! * @param inLinkName - ! * The name of the link that sent the packet eg: eth0 */ ! @Override ! protected void receivePacket(Packet inPacket, String inInterfaceName) ! throws LowLinkException { ! if (sz != 1) { ! Ethernet_packet tempPacket = (Ethernet_packet) inPacket; ! Enumeration it; ! boolean intFound = false; ! String nic = ""; ! ! try { ! Hashtable inInt = (Hashtable) IntCaches.get(inInterfaceName); ! inInt.put(tempPacket.getSourceMACAddress(), "1"); ! Ethernet_packet copyPacket = new Ethernet_packet(tempPacket ! .getData(), tempPacket.getDestinationMACAddress(), ! tempPacket.getSourceMACAddress()); ! // tag it ! copyPacket.vlan_id = tempPacket.vlan_id; ! ! it = NetworkInterfacetable.elements(); ! while (it.hasMoreElements()) { ! NetworkInterface tempInterface = (NetworkInterface) it ! .nextElement(); ! nic = tempInterface.getName(); ! Hashtable outInt = (Hashtable) IntCaches.get(nic); ! if (outInt.get(tempPacket.getDestinationMACAddress()) != null) { ! intFound = true; ! try { ! if(!tempInterface.getName().equals(inInterfaceName)) ! tempInterface.sendPacket(copyPacket); ! } catch (NullPointerException e) { ! System.out.println("Switch.java: " + e.toString()); ! } ! } ! } ! ! if (intFound) ! return; ! ! it = NetworkInterfacetable.elements(); ! while (it.hasMoreElements()) { ! // Test to see if the current Interface is the Interface ! // that sent in the packet ! // if it is skip that interface ! NetworkInterface tempInterface = (NetworkInterface) it ! .nextElement(); ! if (!tempInterface.getName().equals(inInterfaceName)) { ! ! try { ! tempInterface.sendPacket(copyPacket); ! } catch (NullPointerException e) { ! System.out.println("Switch.java: " + e.toString()); ! } ! } ! ! } ! ! } catch (Throwable th) { ! if (th.toString().contains( ! "Packet lost due to physical link problems!")) { ! throw new LowLinkException(th.toString()); ! } else { ! sz = 1; ! System.out.println(th.toString()); ! throw new LowLinkException( ! "Switch buffer overflow (packet loop flood?)."); ! } ! } ! } } } Index: MultilayerSwitch.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/MultilayerSwitch.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** MultilayerSwitch.java 24 Oct 2008 16:18:48 -0000 1.9 --- MultilayerSwitch.java 27 Oct 2008 18:27:52 -0000 1.10 *************** *** 122,132 **** if((tempInterface.mode == NetworkInterfacePort.MODE_TRUNK || tempInterface.vlan == tempPacket.vlan_id) && tempInterface.getConnectedLink()!=null){ ! Ethernet_packet copyPacket = new Ethernet_packet(tempPacket .getData(), tempPacket.getDestinationMACAddress(), tempPacket.getSourceMACAddress()); ! // tag it ! copyPacket.vlan_id = tempPacket.vlan_id; ! tempInterface.sendPacket(copyPacket); } } catch (NullPointerException e) { --- 122,135 ---- if((tempInterface.mode == NetworkInterfacePort.MODE_TRUNK || tempInterface.vlan == tempPacket.vlan_id) && tempInterface.getConnectedLink()!=null){ ! ! if(!tempInterface.getName().equals(inInterfaceName)){ ! Ethernet_packet copyPacket = new Ethernet_packet(tempPacket .getData(), tempPacket.getDestinationMACAddress(), tempPacket.getSourceMACAddress()); ! // tag it ! copyPacket.vlan_id = tempPacket.vlan_id; ! tempInterface.sendPacket(copyPacket); ! } } } catch (NullPointerException e) { |
From: Alexander B. <da...@us...> - 2008-10-27 16:09:12
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv8465/core Modified Files: ConsoleLink.java ConsoleNetworkInterface.java NetworkInterface.java Log Message: Index: ConsoleLink.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ConsoleLink.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ConsoleLink.java 24 Oct 2008 16:18:48 -0000 1.2 --- ConsoleLink.java 27 Oct 2008 16:09:02 -0000 1.3 *************** *** 64,66 **** --- 64,73 ---- } + public Node getParent(String nodeName){ + + if(NetworkInterfaces.get(0).getParentNode().getName().equals(nodeName)) + return NetworkInterfaces.get(1).getParentNode(); + else + return NetworkInterfaces.get(0).getParentNode(); + } } Index: ConsoleNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ConsoleNetworkInterface.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ConsoleNetworkInterface.java 26 Oct 2008 22:02:46 -0000 1.4 --- ConsoleNetworkInterface.java 27 Oct 2008 16:09:02 -0000 1.5 *************** *** 52,56 **** */ ! class ConsoleNetworkInterface extends NetworkInterface{ public final static int STOPBIT_1 = 1; --- 52,56 ---- */ ! public class ConsoleNetworkInterface extends NetworkInterface{ public final static int STOPBIT_1 = 1; Index: NetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterface.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** NetworkInterface.java 26 Oct 2008 22:02:46 -0000 1.22 --- NetworkInterface.java 27 Oct 2008 16:09:02 -0000 1.23 *************** *** 169,173 **** } ! public final static int Unknown = 0; public final static int Ethernet10T = 0; public final static int Console = 1; --- 169,173 ---- } ! public final static int Unknown = -1; public final static int Ethernet10T = 0; public final static int Console = 1; |
From: Alexander B. <da...@us...> - 2008-10-27 16:09:08
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv8465/guiUI Modified Files: ApplicationLayerDevice.java GuiLaptop.java GuiNode.java GuiPC.java MainScreen.java Log Message: Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.103 retrieving revision 1.104 diff -C2 -d -r1.103 -r1.104 *** MainScreen.java 26 Oct 2008 15:37:40 -0000 1.103 --- MainScreen.java 27 Oct 2008 16:09:02 -0000 1.104 *************** *** 1936,1939 **** --- 1936,1992 ---- } + public void Terminal(String nodeName){ + + core.Node node = Sim.getNode(nodeName); + + try{ + + if(!(node instanceof core.NetworkLayerDevice)){ + JOptionPane.showMessageDialog(this, + "Invalid device type!", "Terminal", JOptionPane.ERROR_MESSAGE); + + return; + } + + core.ConsoleNetworkInterface cint1 = (core.ConsoleNetworkInterface)node.getNIC("cua0"); + + core.ConsoleLink lnk = (core.ConsoleLink)(cint1).getConnectedLink(); + + if(lnk == null){ + JOptionPane.showMessageDialog(this, + "Console interface has no connection!", "Terminal", JOptionPane.ERROR_MESSAGE); + } + + core.NetworkLayerDevice device = (core.NetworkLayerDevice)lnk.getParent(nodeName); + + core.ConsoleNetworkInterface cint2 = (core.ConsoleNetworkInterface)device.getNIC("cua0"); + + if(!device.On || !cint2.isUP() || !cint1.isUP()){ + JOptionPane.showMessageDialog(this, + "Console interface has no connection or is down!", "Terminal", JOptionPane.ERROR_MESSAGE); + } + + if(cint1.databits == cint2.databits && + cint1.flowcontrol == cint2.flowcontrol && + cint1.parity == cint2.parity && + cint1.speed == cint2.speed && + cint1.stopbits == cint2.stopbits && + cint1.speed == 9600 && + cint1.flowcontrol == core.ConsoleNetworkInterface.FLOWCONTROL_NONE){ + + RunCmd(device.getName()); + }else{ + JOptionPane.showMessageDialog(this, + "Incorrect port params!", "Terminal", JOptionPane.ERROR_MESSAGE); + } + + }catch(Exception e){ + JOptionPane.showMessageDialog(this, + "Unrecoverable error!", "Terminal", JOptionPane.ERROR_MESSAGE); + + } + + } + public void Export(){ JFileChooser chooser = new JFileChooser(); *************** *** 4549,4552 **** --- 4602,4608 ---- new SerPortProperties(this, NodeName, IntName, Sim, Sandbox); break; + case core.NetworkInterface.Console: + new ConsolePortProperties(this, NodeName, IntName, Sim); + break; case core.NetworkInterface.WAN: /* Index: GuiNode.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiNode.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** GuiNode.java 26 Oct 2008 22:02:46 -0000 1.14 --- GuiNode.java 27 Oct 2008 16:09:02 -0000 1.15 *************** *** 338,342 **** int int_type = Simulation.Sim.getNode(this.strNodeName).getIntType((String)ints[i]); ! if(int_type != core.NetworkInterface.Console){ JMenuItem mnuI = new JMenuItem((String) ints[i]); mnuI.addActionListener(new ActionListener() { --- 338,342 ---- int int_type = Simulation.Sim.getNode(this.strNodeName).getIntType((String)ints[i]); ! if(int_type != core.NetworkInterface.Unknown){ JMenuItem mnuI = new JMenuItem((String) ints[i]); mnuI.addActionListener(new ActionListener() { Index: GuiPC.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiPC.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** GuiPC.java 24 Oct 2008 16:18:48 -0000 1.12 --- GuiPC.java 27 Oct 2008 16:09:02 -0000 1.13 *************** *** 197,200 **** --- 197,203 ---- mnuAppLayer.addSeparator(); mnuAppLayer.add(mnuDHCPD); + + mnuAppLayer.addSeparator(); + mnuAppLayer.add(mnuTerminal); } Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/ApplicationLayerDevice.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ApplicationLayerDevice.java 24 Oct 2008 16:18:48 -0000 1.14 --- ApplicationLayerDevice.java 27 Oct 2008 16:09:02 -0000 1.15 *************** *** 21,24 **** --- 21,26 ---- protected JMenu mnuAppLayer = new JMenu("Applications"); + + protected JMenuItem mnuTerminal = new JMenuItem("Terminal"); private JMenuItem mnuDHCPC = new JMenuItem("Run DHCP Client"); *************** *** 51,54 **** --- 53,62 ---- } }); + + mnuTerminal.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + controller.Terminal(lblNodeName.getText()); + } + }); mnuAppLayer.add(mnuSNMPStartAgent); Index: GuiLaptop.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiLaptop.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GuiLaptop.java 24 Oct 2008 16:18:48 -0000 1.3 --- GuiLaptop.java 27 Oct 2008 16:09:02 -0000 1.4 *************** *** 172,175 **** --- 172,177 ---- mnuAppLayer.add(mnuPosixTelnet); + mnuAppLayer.addSeparator(); + mnuAppLayer.add(mnuTerminal); } |
From: QweR <qw...@us...> - 2008-10-26 22:06:54
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv333/core Modified Files: CommandProcessor.java DeviceConfig.java Log Message: cosmetic changes Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** CommandProcessor.java 26 Oct 2008 22:02:46 -0000 1.36 --- CommandProcessor.java 26 Oct 2008 22:06:51 -0000 1.37 *************** *** 3801,3805 **** if(ni instanceof ConsoleNetworkInterface){ ConsoleNetworkInterface cni = (ConsoleNetworkInterface)ni; ! out += " Databits " + cni.databits + "\n"; String fc = ""; switch(cni.flowcontrol){ --- 3801,3805 ---- if(ni instanceof ConsoleNetworkInterface){ ConsoleNetworkInterface cni = (ConsoleNetworkInterface)ni; ! out += " Databits: " + cni.databits + "\n"; String fc = ""; switch(cni.flowcontrol){ *************** *** 3808,3812 **** case ConsoleNetworkInterface.FLOWCONTROL_SOFTWARE: fc = "software"; break; } ! out += " Flowcontrol " + fc + "\n"; String pa = ""; switch(cni.parity){ --- 3808,3812 ---- case ConsoleNetworkInterface.FLOWCONTROL_SOFTWARE: fc = "software"; break; } ! out += " Flowcontrol: " + fc + "\n"; String pa = ""; switch(cni.parity){ *************** *** 3817,3821 **** case ConsoleNetworkInterface.PARITY_SPACE: pa = "space"; break; } ! out += " Parity " + pa + "\n"; String sb = ""; switch(cni.stopbits){ --- 3817,3821 ---- case ConsoleNetworkInterface.PARITY_SPACE: pa = "space"; break; } ! out += " Parity: " + pa + "\n"; String sb = ""; switch(cni.stopbits){ *************** *** 3824,3829 **** case ConsoleNetworkInterface.STOPBIT_2: sb = "2"; break; } ! out += " Stopbits " + sb + "\n"; ! out += " Speed " + cni.speed + "\n"; } out += "\n"; --- 3824,3829 ---- case ConsoleNetworkInterface.STOPBIT_2: sb = "2"; break; } ! out += " Stopbits: " + sb + "\n"; ! out += " Speed: " + cni.speed + "\n"; } out += "\n"; Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** DeviceConfig.java 26 Oct 2008 22:02:46 -0000 1.27 --- DeviceConfig.java 26 Oct 2008 22:06:51 -0000 1.28 *************** *** 642,646 **** } } ! else conf.add("no router rip"); } --- 642,648 ---- } } ! else { ! //conf.add("no router rip"); ! } } |
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv32599/core Modified Files: ApplicationLayerDevice.java CommandProcessor.java ConsoleNetworkInterface.java DeviceConfig.java Link.java NetworkInterface.java Log Message: Added commands ip name-server int * databits int * flowcontrol int * parity int * speed int * stopbits Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** DeviceConfig.java 24 Oct 2008 17:46:42 -0000 1.26 --- DeviceConfig.java 26 Oct 2008 22:02:46 -0000 1.27 *************** *** 388,391 **** --- 388,392 ---- SerialNetworkInterface sni = null; NetworkInterfacePort pni = null; + ConsoleNetworkInterface cni = null; WiFiPort wfi = null; try{ *************** *** 399,402 **** --- 400,406 ---- } catch(ClassCastException e){}; try{ + cni = (ConsoleNetworkInterface) ni; + } catch(ClassCastException e){}; + try{ wfi = (WiFiPort) ni; } catch(ClassCastException e){}; *************** *** 443,446 **** --- 447,486 ---- } } + + if(cni!=null){ + if(cni.databits!=ConsoleNetworkInterface.DATABITS_DEFAULT) + conf.add("interface "+intName+" databits "+cni.databits); + if(cni.flowcontrol!=ConsoleNetworkInterface.FLOWCONTROL_DEFAULT){ + String fc = ""; + switch(cni.flowcontrol){ + case ConsoleNetworkInterface.FLOWCONTROL_NONE: fc = "none"; break; + case ConsoleNetworkInterface.FLOWCONTROL_HARDWARE: fc = "hardware"; break; + case ConsoleNetworkInterface.FLOWCONTROL_SOFTWARE: fc = "software"; break; + } + conf.add("interface "+intName+" flowcontrol "+fc); + } + if(cni.parity!=ConsoleNetworkInterface.PARITY_DEFAULT){ + String pa = ""; + switch(cni.parity){ + case ConsoleNetworkInterface.PARITY_NONE: pa = "none"; break; + case ConsoleNetworkInterface.PARITY_EVEN: pa = "even"; break; + case ConsoleNetworkInterface.PARITY_ODD: pa = "odd"; break; + case ConsoleNetworkInterface.PARITY_MARK: pa = "mark"; break; + case ConsoleNetworkInterface.PARITY_SPACE: pa = "space"; break; + } + conf.add("interface "+intName+" parity "+pa); + } + if(cni.stopbits!=ConsoleNetworkInterface.STOPBIT_DEFAULT){ + String sb = ""; + switch(cni.stopbits){ + case ConsoleNetworkInterface.STOPBIT_1: sb = "1"; break; + case ConsoleNetworkInterface.STOPBIT_15: sb = "1.5"; break; + case ConsoleNetworkInterface.STOPBIT_2: sb = "2"; break; + } + conf.add("interface "+intName+" stopbits "+sb); + } + if(cni.speed!=ConsoleNetworkInterface.SPEED_DEFAULT) + conf.add("interface "+intName+" speed "+cni.speed); + } if(ni.getACLin()!=0) conf.add("interface "+intName+" ip access-group "+ni.getACLin()+" in"); *************** *** 533,537 **** } if(device instanceof ApplicationLayerDevice){ ! DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ Enumeration<String> dhcppools = dhcpd.pools.keys(); --- 573,578 ---- } if(device instanceof ApplicationLayerDevice){ ! ApplicationLayerDevice adev = (ApplicationLayerDevice)device; ! DHCPD dhcpd = (DHCPD)adev.getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ Enumeration<String> dhcppools = dhcpd.pools.keys(); *************** *** 554,557 **** --- 595,601 ---- if(device.NodeProtocolStack.TCP().getWindowSize() != Tcp.DEFAULT_WINDOW_SIZE) conf.add("ip tcp window-size "+device.NodeProtocolStack.TCP().getWindowSize()); + if(adev.getNameServer()!=""){ + conf.add("ip name-server "+adev.getNameServer()); + } } } Index: Link.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Link.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Link.java 24 Oct 2008 16:18:48 -0000 1.4 --- Link.java 26 Oct 2008 22:02:46 -0000 1.5 *************** *** 25,29 **** 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; --- 25,29 ---- 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; *************** *** 49,104 **** * @since 14 June 2004 * @version v0.20 ! */ - abstract class Link implements Serializable{ /** The interfaceList holds all of the NetworkInterfaces that are connected to the Link */ ! ! /** * @link aggregation <{core.NetworkInterface}> * @directed directed * @supplierCardinality 0..* */ ! java.util.Vector NetworkInterfaces = null; ! /** Name of the link */ ! protected String name; ! ! protected double sievingCoefficient; ! ! /** *TODO*: javaDoc ! * ! */ ! public double getSC(){ ! return sievingCoefficient; ! } ! ! ! /** *TODO*: javaDoc ! * ! */ ! public void setSC(double SC){ ! sievingCoefficient = SC; ! } ! ! /** ! * Constructs a Link with the specified name. Conceptually this will simply create a cable ! * not connected to anything. You need to call the addInterface() method to 'plug' the cable ! * in to NetworkInterfaces. ! * @author luke_hamilton ! * @param inName - The name to give the Link. eg: LINK1 ! * @version v0.20 ! **/ ! protected Link(String inName) { ! NetworkInterfaces = new Vector(); name = inName; ! sievingCoefficient = 100; ! } - protected String getName() - { - return name; - } - /** * This method returns true is the link is not connected to any --- 49,109 ---- * @since 14 June 2004 * @version v0.20 ! */ ! ! public class Link implements Serializable{ ! /** ! * ! */ ! private static final long serialVersionUID = 4675052404278691897L; /** The interfaceList holds all of the NetworkInterfaces that are connected to the Link */ ! ! /** * @link aggregation <{core.NetworkInterface}> * @directed directed * @supplierCardinality 0..* */ ! Vector<NetworkInterface> NetworkInterfaces = null; ! /** Name of the link */ ! protected String name; ! protected double sievingCoefficient; ! ! ! /** *TODO*: javaDoc ! * ! */ ! public double getSC(){ ! return sievingCoefficient; ! } ! ! ! /** *TODO*: javaDoc ! * ! */ ! public void setSC(double SC){ ! sievingCoefficient = SC; ! } ! ! /** ! * Constructs a Link with the specified name. Conceptually this will simply create a cable ! * not connected to anything. You need to call the addInterface() method to 'plug' the cable ! * in to NetworkInterfaces. ! * @author luke_hamilton ! * @param inName - The name to give the Link. eg: LINK1 ! * @version v0.20 ! **/ ! protected Link(String inName) { ! NetworkInterfaces = new Vector<NetworkInterface>(); name = inName; ! sievingCoefficient = 100; ! } ! ! protected String getName() ! { ! return name; ! } /** * This method returns true is the link is not connected to any *************** *** 122,146 **** */ protected void disconnectLink() { ! for (int i = 0; i < NetworkInterfaces.size(); i++) { ! NetworkInterface temp = (NetworkInterface)NetworkInterfaces.elementAt(i); temp.resetConnectedLink(); } NetworkInterfaces.removeAllElements(); ! } ! /** ! * Displays all the interfaces in the interface list through System.out.println() calls. ! * @author tristan_veness ! * @author luke_hamilton ! * @version v0.20 ! */ protected void displayDetails(){ System.out.println(name); for (int i = 0; i < NetworkInterfaces.size(); i++) { ! NetworkInterface NIC = (NetworkInterface)NetworkInterfaces.elementAt(i); System.out.println("Connection " +i+ " "+NIC.getDetails()); } } }//EOF --- 127,161 ---- */ protected void disconnectLink() { ! for (int i = 0; i < NetworkInterfaces.size(); i++) { ! NetworkInterface temp = NetworkInterfaces.elementAt(i); temp.resetConnectedLink(); } NetworkInterfaces.removeAllElements(); ! } ! /** ! * Displays all the interfaces in the interface list through System.out.println() calls. ! * @author tristan_veness ! * @author luke_hamilton ! * @version v0.20 ! */ protected void displayDetails(){ System.out.println(name); for (int i = 0; i < NetworkInterfaces.size(); i++) { ! NetworkInterface NIC = NetworkInterfaces.elementAt(i); System.out.println("Connection " +i+ " "+NIC.getDetails()); } } + + public String getLinkedNodeName(String node, String iface){ + for (int i = 0; i < NetworkInterfaces.size(); i++) { + if(NetworkInterfaces.elementAt(i).getName().equalsIgnoreCase(iface) + && NetworkInterfaces.elementAt(i).getParentNode().getName().equalsIgnoreCase(node)){ + return NetworkInterfaces.elementAt(1-i).getParentNode().getName(); + } + } + return ""; + } }//EOF Index: ConsoleNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ConsoleNetworkInterface.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ConsoleNetworkInterface.java 24 Oct 2008 16:18:48 -0000 1.3 --- ConsoleNetworkInterface.java 26 Oct 2008 22:02:46 -0000 1.4 *************** *** 54,58 **** class ConsoleNetworkInterface extends NetworkInterface{ ! /** * --- 54,82 ---- class ConsoleNetworkInterface extends NetworkInterface{ ! public final static int STOPBIT_1 = 1; ! public final static int STOPBIT_15 = 2; ! public final static int STOPBIT_2 = 3; ! public final static int STOPBIT_DEFAULT = STOPBIT_1; ! ! public final static int PARITY_NONE = 1; ! public final static int PARITY_EVEN = 2; ! public final static int PARITY_ODD = 3; ! public final static int PARITY_MARK = 4; ! public final static int PARITY_SPACE = 5; ! public final static int PARITY_DEFAULT = PARITY_NONE; ! ! public final static int FLOWCONTROL_NONE = 1; ! public final static int FLOWCONTROL_HARDWARE = 2; ! public final static int FLOWCONTROL_SOFTWARE = 3; ! public final static int FLOWCONTROL_DEFAULT = FLOWCONTROL_NONE; ! ! public final static int SPEED_DEFAULT = 9600; ! public final static int DATABITS_DEFAULT = 8; ! ! public int speed = SPEED_DEFAULT; ! public int databits = DATABITS_DEFAULT; ! public int stopbits = STOPBIT_DEFAULT; ! public int parity = PARITY_DEFAULT; ! public int flowcontrol = FLOWCONTROL_DEFAULT; /** * Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** CommandProcessor.java 24 Oct 2008 18:13:48 -0000 1.35 --- CommandProcessor.java 26 Oct 2008 22:02:46 -0000 1.36 *************** *** 66,71 **** --- 66,73 ---- private interface__channel_CommandClass interface__channel_Command = new interface__channel_CommandClass(); private interface__clock_rate_CommandClass interface__clock_rate_Command = new interface__clock_rate_CommandClass(); + private interface__databits_CommandClass interface__databits_Command = new interface__databits_CommandClass(); private interface__description_CommandClass interface__description_Command = new interface__description_CommandClass(); private interface__encryption_key_CommandClass interface__encryption_key_Command = new interface__encryption_key_CommandClass(); + private interface__flowcontrol_CommandClass interface__flowcontrol_Command = new interface__flowcontrol_CommandClass(); private interface__ip_address_CommandClass interface__ip_address_Command = new interface__ip_address_CommandClass(); private interface__ip_access_group_CommandClass interface__ip_access_group_Command = new interface__ip_access_group_CommandClass(); *************** *** 77,83 **** --- 79,88 ---- private interface__ip_dhcp_client_CommandClass interface__ip_dhcp_client_Command = new interface__ip_dhcp_client_CommandClass(); private interface__mac_address_CommandClass interface__mac_address_Command = new interface__mac_address_CommandClass(); + private interface__parity_CommandClass interface__parity_Command = new interface__parity_CommandClass(); private interface__shutdown_CommandClass interface__shutdown_Command = new interface__shutdown_CommandClass(); + private interface__speed_CommandClass interface__speed_Command = new interface__speed_CommandClass(); private interface__ssid_CommandClass interface__ssid_Command = new interface__ssid_CommandClass(); private interface__station_role_CommandClass interface__station_role_Command = new interface__station_role_CommandClass(); + private interface__stopbits_CommandClass interface__stopbits_Command = new interface__stopbits_CommandClass(); private interface__switchport_access_vlan_CommandClass interface__switchport_access_vlan_Command = new interface__switchport_access_vlan_CommandClass(); private interface__switchport_mode_access_CommandClass interface__switchport_mode_access_Command = new interface__switchport_mode_access_CommandClass(); *************** *** 93,96 **** --- 98,102 ---- private ip_host_CommandClass ip_host_Command = new ip_host_CommandClass(); private ip_host_hinfo_CommandClass ip_host_hinfo_Command = new ip_host_hinfo_CommandClass(); + private ip_name_server_CommandClass ip_name_server_Command = new ip_name_server_CommandClass(); //private ip_nat_inside_destination_list_CommandClass ip_nat_inside_destination_list_Command = new ip_nat_inside_destination_list_CommandClass(); private ip_nat_inside_source_list_CommandClass ip_nat_inside_source_list_Command = new ip_nat_inside_source_list_CommandClass(); *************** *** 170,176 **** --- 176,184 ---- commands.add("interface * channel", interface__channel_Command, "Specify channel"); commands.add("interface * clock-rate", interface__clock_rate_Command, "Specify clock-rate"); + commands.add("interface * databits", interface__databits_Command, "Set number of data bits per character"); commands.add("interface * description", interface__description_Command, "Interface specific description"); commands.addDescription("interface * encryption","Configure encryption"); commands.add("interface * encryption key", interface__encryption_key_Command, "Configure encryption key"); + commands.add("interface * flowcontrol", interface__flowcontrol_Command, "Set the flow control"); commands.addDescription("interface * ip","Configure Internet Protocol"); commands.add("interface * ip address", interface__ip_address_Command, "Set the IP address of an interface"); *************** *** 184,190 **** --- 192,201 ---- commands.add("interface * ip dhcp client", interface__ip_dhcp_client_Command, "Enable DHCP client"); commands.add("interface * mac-address", interface__mac_address_Command, "Manually set interface MAC address"); + commands.add("interface * parity", interface__parity_Command, "Set terminal parity"); commands.add("interface * shutdown", interface__shutdown_Command, "Shutdown the selected interface"); + commands.add("interface * speed", interface__speed_Command, "Set the transmit and receive speeds"); commands.add("interface * ssid", interface__ssid_Command, "Set SSID"); commands.add("interface * station-role", interface__station_role_Command, "Specify station role"); + commands.add("interface * stopbits", interface__stopbits_Command, "Set async line stop bits"); commands.addDescription("interface * switchport access","Configure a port access"); commands.add("interface * switchport access vlan", interface__switchport_access_vlan_Command, "Configure a port as a static-access port"); *************** *** 209,212 **** --- 220,224 ---- commands.add("ip host", ip_host_Command, "Add an entry to the ip hostname table"); commands.add("ip host hinfo", ip_host_hinfo_Command, "Set system information record"); + commands.add("ip name-server", ip_name_server_Command, "Specify address of name server to use"); commands.addDescription("ip nat","NAT configuration commands"); commands.addDescription("ip nat inside","Inside address translation"); *************** *** 726,739 **** int cr = Integer.parseInt(params.get(1)); if(cr>SerialNetworkInterface.MIN_CLOCKRATE || cr<=SerialNetworkInterface.MAX_CLOCKRATE){ ! if(sni!=null){ ! sni.setClockRate(cr); ! } ! else{ ! out += "unsupposed instruction for this interface\n"; ! } } else{ out += "error: invalid clock rate"; } } catch (NumberFormatException ex) { out += "error: invalid clock rate"; --- 738,748 ---- int cr = Integer.parseInt(params.get(1)); if(cr>SerialNetworkInterface.MIN_CLOCKRATE || cr<=SerialNetworkInterface.MAX_CLOCKRATE){ ! sni.setClockRate(cr); } else{ out += "error: invalid clock rate"; } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; } catch (NumberFormatException ex) { out += "error: invalid clock rate"; *************** *** 752,761 **** try { SerialNetworkInterface sni = (SerialNetworkInterface)device.getNetworkInterface(params.get(0)); ! if(sni!=null){ ! sni.setClockRate(SerialNetworkInterface.DEFAULT_CLOCKRATE); ! } ! else{ ! out += "unsupposed instruction for this interface\n"; ! } } catch (InvalidNetworkInterfaceNameException ex) { out += "error: invalid inferface\n"; --- 761,767 ---- try { SerialNetworkInterface sni = (SerialNetworkInterface)device.getNetworkInterface(params.get(0)); ! sni.setClockRate(SerialNetworkInterface.DEFAULT_CLOCKRATE); ! } catch (ClassCastException ex){ ! out += "unsupposed instruction for this interface\n"; } catch (InvalidNetworkInterfaceNameException ex) { out += "error: invalid inferface\n"; *************** *** 807,810 **** --- 813,865 ---- } }; + class interface__databits_CommandClass extends CommandInterface{ + public interface__databits_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "<5-8>"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()==2){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + int val = Integer.parseInt(params.get(1)); + if(val>=5 && val<=8){ + cni.databits = val; + } + else{ + out += "error: invalid databits number\n"; + } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (NumberFormatException ex) { + out += "error: invalid clock rate"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + cni.databits = ConsoleNetworkInterface.DATABITS_DEFAULT; + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__encryption_key_CommandClass extends CommandInterface{ public interface__encryption_key_CommandClass(){ *************** *** 907,910 **** --- 962,1020 ---- } }; + class interface__flowcontrol_CommandClass extends CommandInterface{ + public interface__flowcontrol_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "(none|hardware|software)"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()==2){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + String val = params.get(1); + if(val.equalsIgnoreCase("none")){ + cni.flowcontrol = ConsoleNetworkInterface.FLOWCONTROL_NONE; + } + else if(val.equalsIgnoreCase("hardware")){ + cni.flowcontrol = ConsoleNetworkInterface.FLOWCONTROL_HARDWARE; + } + else if(val.equalsIgnoreCase("software")){ + cni.flowcontrol = ConsoleNetworkInterface.FLOWCONTROL_SOFTWARE; + } + else{ + out += "error: invalid flowcontrol value\n"; + } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (NumberFormatException ex) { + out += "error: invalid clock rate"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + cni.flowcontrol = ConsoleNetworkInterface.FLOWCONTROL_DEFAULT; + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__ip_access_group_CommandClass extends CommandInterface{ public interface__ip_access_group_CommandClass(){ *************** *** 1373,1376 **** --- 1483,1547 ---- } }; + class interface__parity_CommandClass extends CommandInterface{ + public interface__parity_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "(none|even|odd|mark|space)"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()==2){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + String val = params.get(1); + if(val.equalsIgnoreCase("none")){ + cni.parity = ConsoleNetworkInterface.PARITY_NONE; + } + else if(val.equalsIgnoreCase("even")){ + cni.parity = ConsoleNetworkInterface.PARITY_EVEN; + } + else if(val.equalsIgnoreCase("odd")){ + cni.parity = ConsoleNetworkInterface.PARITY_ODD; + } + else if(val.equalsIgnoreCase("mark")){ + cni.parity = ConsoleNetworkInterface.PARITY_MARK; + } + else if(val.equalsIgnoreCase("space")){ + cni.parity = ConsoleNetworkInterface.PARITY_SPACE; + } + else{ + out += "error: invalid parity value\n"; + } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (NumberFormatException ex) { + out += "error: invalid clock rate"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + cni.parity = ConsoleNetworkInterface.PARITY_DEFAULT; + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__shutdown_CommandClass extends CommandInterface{ public interface__shutdown_CommandClass(){ *************** *** 1408,1411 **** --- 1579,1631 ---- } }; + class interface__speed_CommandClass extends CommandInterface{ + public interface__speed_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "<1-2147483647>"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()==2){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + int val = Integer.parseInt(params.get(1)); + if(val>0){ + cni.speed = val; + } + else{ + out += "error: invalid speed\n"; + } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (NumberFormatException ex) { + out += "error: invalid clock rate"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + cni.speed = ConsoleNetworkInterface.SPEED_DEFAULT; + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__ssid_CommandClass extends CommandInterface{ public interface__ssid_CommandClass(){ *************** *** 1522,1525 **** --- 1742,1798 ---- } }; + class interface__stopbits_CommandClass extends CommandInterface{ + public interface__stopbits_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.NO_CALL); + call_params = "(1|1.5|2)"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(params.size()==2){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + String val = params.get(1); + if(val.equals("1")){ + cni.stopbits = ConsoleNetworkInterface.STOPBIT_1; + } + else if(val.equals("1.5")){ + cni.stopbits = ConsoleNetworkInterface.STOPBIT_15; + } + else if(val.equals("2")){ + cni.stopbits = ConsoleNetworkInterface.STOPBIT_2; + } + else{ + out += "error: invalid stopbits value\n"; + } + } catch (ClassCastException ex){ + out += "unsupposed instruction for this interface\n"; + } catch (NumberFormatException ex) { + out += "error: invalid clock rate"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)device.getNetworkInterface(params.get(0)); + cni.stopbits = ConsoleNetworkInterface.STOPBIT_DEFAULT; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + return out; + } + }; class interface__switchport_access_vlan_CommandClass extends CommandInterface{ public interface__switchport_access_vlan_CommandClass(){ *************** *** 2537,2540 **** --- 2810,2856 ---- } }; + class ip_name_server_CommandClass extends CommandInterface{ + public ip_name_server_CommandClass(){ + modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); + call_params = "<name-server ip-address>"; + no_call_params = "<cr>"; + } + public String call(Vector<String> params){ + String out = ""; + if(device instanceof ApplicationLayerDevice){ + if(params.size()==1){ + String ns = params.get(0); + if(IPV4Address.validateDecIP(ns)){ + ((ApplicationLayerDevice)device).setNameServer(ns); + } + else{ + out += "error: invalid IP address\n"; + } + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + public String no_call(Vector<String> params){ + String out = ""; + if(device instanceof ApplicationLayerDevice){ + if(params.size()==0){ + ((ApplicationLayerDevice)device).setNameServer(""); + } + else{ + out += "error: invalid parameters\n"; + } + } + else{ + out += "This instruction not supported by device\n"; + } + return out; + } + }; /*class ip_nat_inside_destination_list_CommandClass extends CommandInterface{ public ip_nat_inside_destination_list_CommandClass(){ *************** *** 3483,3486 **** --- 3799,3830 ---- out += " Clock-rate " + ((SerialNetworkInterface)ni).getClockRate() + "\n"; } + if(ni instanceof ConsoleNetworkInterface){ + ConsoleNetworkInterface cni = (ConsoleNetworkInterface)ni; + out += " Databits " + cni.databits + "\n"; + String fc = ""; + switch(cni.flowcontrol){ + case ConsoleNetworkInterface.FLOWCONTROL_NONE: fc = "none"; break; + case ConsoleNetworkInterface.FLOWCONTROL_HARDWARE: fc = "hardware"; break; + case ConsoleNetworkInterface.FLOWCONTROL_SOFTWARE: fc = "software"; break; + } + out += " Flowcontrol " + fc + "\n"; + String pa = ""; + switch(cni.parity){ + case ConsoleNetworkInterface.PARITY_NONE: pa = "none"; break; + case ConsoleNetworkInterface.PARITY_EVEN: pa = "even"; break; + case ConsoleNetworkInterface.PARITY_ODD: pa = "odd"; break; + case ConsoleNetworkInterface.PARITY_MARK: pa = "mark"; break; + case ConsoleNetworkInterface.PARITY_SPACE: pa = "space"; break; + } + out += " Parity " + pa + "\n"; + String sb = ""; + switch(cni.stopbits){ + case ConsoleNetworkInterface.STOPBIT_1: sb = "1"; break; + case ConsoleNetworkInterface.STOPBIT_15: sb = "1.5"; break; + case ConsoleNetworkInterface.STOPBIT_2: sb = "2"; break; + } + out += " Stopbits " + sb + "\n"; + out += " Speed " + cni.speed + "\n"; + } out += "\n"; } catch (InvalidNetworkInterfaceNameException ex) { Index: NetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterface.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** NetworkInterface.java 24 Oct 2008 16:18:48 -0000 1.21 --- NetworkInterface.java 26 Oct 2008 22:02:46 -0000 1.22 *************** *** 51,55 **** EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! */ package core; --- 51,55 ---- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! */ package core; *************** *** 95,99 **** * @version v0.20 ! */ --- 95,99 ---- * @version v0.20 ! */ *************** *** 105,245 **** protected String name; ! /** The Link that this NetworkInterface is connected to */ protected Link connectedLink; protected Node parentNode; - - protected boolean up; - - protected boolean dhcp; - - protected int acl_in = 0; - protected int acl_out = 0; - - public boolean unreachables = true; - public boolean redirects = true; - public boolean maskReplay = true; - public boolean informationReplay = true; - - public boolean getDHCP(){ - return dhcp; - } - - public void setDHCP(boolean inDHCP){ - dhcp = inDHCP; - } - - - protected String description = ""; - - public void setUP(){ - up = true; - } - - public void UP(){ - up = true; - LayerInfo pingInfo = new LayerInfo(getClass().getName()); - pingInfo.setObjectName(parentNode.getName()); - pingInfo.setDataType("Interface"); - pingInfo.setLayer("Link"); - pingInfo.setDescription("Interface " + name + " state set to up!"); - Simulation.addLayerInfo(pingInfo); - if( parentNode.NodeProtocolStack != null){ - parentNode.NodeProtocolStack.intUP(name); - } - } - - public void DOWN(){ - up = false; - LayerInfo pingInfo = new LayerInfo(getClass().getName()); - pingInfo.setObjectName(parentNode.getName()); - pingInfo.setDataType("Interface"); - pingInfo.setLayer("Link"); - pingInfo.setDescription("Interface " + name + " state set to down!"); - Simulation.addLayerInfo(pingInfo); - } - - public boolean isUP(){ - return up; - } - - public boolean isOn(){ - return parentNode.On; - } ! public final static int Unknown = 0; ! public final static int Ethernet10T = 0; ! public final static int Console = 1; ! public final static int Wireless = 2; ! public final static int WAN = 3; ! public final static int Serial = 4; ! public final static int Ethernet100FX = 5; ! ! public static String getIntName(int type){ ! switch(type){ ! case 0: ! return "eth"; ! case 1: ! return "cua"; ! case 2: ! return "wrl"; ! case 3: ! return "wan"; ! case 4: ! return "ser"; ! case 5: ! return "fib"; ! default: ! return "unk"; ! } ! } ! ! public final static int NO_NAT = 0; ! public final static int INSIDE_NAT = 1; ! public final static int OUTSIDE_NAT = 2; ! ! private int NAT_STATUS = 0; ! ! public void setNAT(int nat){ ! NAT_STATUS = nat; ! } ! ! public int getNAT(){ ! return NAT_STATUS; ! } ! ! public boolean isActive(){ ! return false; ! } ! ! public int getType(){ ! return -1; ! } ! ! /** ! * Constructs a NetworkInterface object with the name inName and a reference to it's parent Node. ! * @author tristan_veness ! * @param inName - The name to give the NetworkInterface eg: eth0 ! * @param parent - The Node that the NetworkInterface is to be added to, it's parent. ! * @version v0.10 - */ ! protected NetworkInterface(long UID, String inName, Node inParent) { ! super(UID); ! name = inName; parentNode = inParent; - - up = false; ! } --- 105,245 ---- protected String name; ! /** The Link that this NetworkInterface is connected to */ protected Link connectedLink; protected Node parentNode; ! protected boolean up; ! protected boolean dhcp; ! protected int acl_in = 0; ! protected int acl_out = 0; ! public boolean unreachables = true; ! public boolean redirects = true; ! public boolean maskReplay = true; ! public boolean informationReplay = true; ! public boolean getDHCP(){ ! return dhcp; ! } ! public void setDHCP(boolean inDHCP){ ! dhcp = inDHCP; ! } ! protected String description = ""; ! public void setUP(){ ! up = true; ! } ! ! public void UP(){ ! up = true; ! LayerInfo pingInfo = new LayerInfo(getClass().getName()); ! pingInfo.setObjectName(parentNode.getName()); ! pingInfo.setDataType("Interface"); ! pingInfo.setLayer("Link"); ! pingInfo.setDescription("Interface " + name + " state set to up!"); ! Simulation.addLayerInfo(pingInfo); ! if( parentNode.NodeProtocolStack != null){ ! parentNode.NodeProtocolStack.intUP(name); ! } ! } ! ! public void DOWN(){ ! up = false; ! LayerInfo pingInfo = new LayerInfo(getClass().getName()); ! pingInfo.setObjectName(parentNode.getName()); ! pingInfo.setDataType("Interface"); ! pingInfo.setLayer("Link"); ! pingInfo.setDescription("Interface " + name + " state set to down!"); ! Simulation.addLayerInfo(pingInfo); ! } ! ! public boolean isUP(){ ! return up; ! } ! ! public boolean isOn(){ ! return parentNode.On; ! } ! ! public final static int Unknown = 0; ! public final static int Ethernet10T = 0; ! public final static int Console = 1; ! public final static int Wireless = 2; ! public final static int WAN = 3; ! public final static int Serial = 4; ! public final static int Ethernet100FX = 5; ! ! public static String getIntName(int type){ ! switch(type){ ! case 0: ! return "eth"; ! case 1: ! return "cua"; ! case 2: ! return "wrl"; ! case 3: ! return "wan"; ! case 4: ! return "ser"; ! case 5: ! return "fib"; ! default: ! return "unk"; ! } ! } ! ! public final static int NO_NAT = 0; ! public final static int INSIDE_NAT = 1; ! public final static int OUTSIDE_NAT = 2; ! ! private int NAT_STATUS = 0; ! ! public void setNAT(int nat){ ! NAT_STATUS = nat; ! } ! ! public int getNAT(){ ! return NAT_STATUS; ! } ! ! public boolean isActive(){ ! return false; ! } ! ! public int getType(){ ! return -1; ! } ! ! /** ! ! * Constructs a NetworkInterface object with the name inName and a reference to it's parent Node. ! ! * @author tristan_veness ! ! * @param inName - The name to give the NetworkInterface eg: eth0 ! ! * @param parent - The Node that the NetworkInterface is to be added to, it's parent. ! ! * @version v0.10 ! ! */ ! ! protected NetworkInterface(long UID, String inName, Node inParent) { ! super(UID); ! ! name = inName; parentNode = inParent; ! up = false; ! ! } *************** *** 311,315 **** protected void receivePacket(Packet inPacket) throws LowLinkException {} ! /** --- 311,315 ---- protected void receivePacket(Packet inPacket) throws LowLinkException {} ! /** *************** *** 329,381 **** ! /** ! * Returns the NetworkInterface's name. ! * @author bevan_calliess ! * @return Name - The NetworkInterface's name ! * @version v0.20 ! */ - - public String getName() { ! return name; ! } ! - /** - * This method is used by interfaces to uniquely identify themselves ! * in the simulation it will return a combination of the ! * Parent naodes name and the Interfaces name ! * eg. Node name PC1 interface eth0 will return "PC1eth0" ! * @author bevan_calliess ! * @return Name - The Source name of this Node Interface ! * @version v0.20 ! */ ! protected String getSourceName() { ! return parentNode.getName()+":"+name; ! } ! ! /** * Sets the connectedLink attribute of the NetworkInterface with Link l. --- 329,381 ---- ! /** ! * Returns the NetworkInterface's name. ! * @author bevan_calliess ! * @return Name - The NetworkInterface's name ! * @version v0.20 ! */ ! public String getName() { ! return name; ! } ! /** ! * This method is used by interfaces to uniquely identify themselves ! * in the simulation it will return a combination of the ! * Parent naodes name and the Interfaces name ! * eg. Node name PC1 interface eth0 will return "PC1eth0" ! * @author bevan_calliess ! * @return Name - The Source name of this Node Interface ! * @version v0.20 ! */ ! protected String getSourceName() { ! return parentNode.getName()+":"+name; ! } ! ! ! ! /** * Sets the connectedLink attribute of the NetworkInterface with Link l. *************** *** 393,413 **** */ ! protected void setConnectedLink(Link l)throws InvalidLinkConnectionException { ! if(connectedLink == null){ ! connectedLink = l; ! }else ! throw new InvalidLinkConnectionException("Network Interface is already connected. Delete Connected link first"); - - } ! /** * Returns the Link that this NetworkInterface is connected to. --- 393,413 ---- */ ! protected void setConnectedLink(Link l)throws InvalidLinkConnectionException { ! if(connectedLink == null){ ! connectedLink = l; ! }else ! throw new InvalidLinkConnectionException("Network Interface is already connected. Delete Connected link first"); + } ! ! /** * Returns the Link that this NetworkInterface is connected to. *************** *** 421,539 **** */ ! public Link getConnectedLink() { ! return connectedLink; ! } - - protected String getConnectedLinkName() { ! if(connectedLink!=null) return connectedLink.getName(); ! else return null; ! } ! - /** - * This method returns the name of the network interface ! * @author tristan_veness ! * @return Name ! * @version v0.10 ! */ ! protected String getDetails(){ ! return name; ! } ! ! /** - * This method returns a string of information about if the network interface is connected of not. - * <P>This method is useful for a CLI or for debugging.</P> ! * @author tristan_veness ! * @return Name - Connection: link1 ! * @version v0.10 ! */ ! protected String getConnectLinkDetails(){ ! if(connectedLink != null){ ! return "Connection: "+ connectedLink.getName(); ! } ! return "Connection: Not connected"; ! } ! ! protected String getConnectLinkName() ! { - if(connectedLink !=null) - { ! return connectedLink.getName(); ! } ! return "Not Connected"; ! } ! ! public String getDescription(){ ! return description; ! } ! ! public void setDescription(String description){ ! this.description = description; ! } ! ! public int getACLin(){ ! return acl_in; ! } ! ! public void setACLin(int acl){ ! if(acl<0 || acl>2699){ ! acl_in = 0; ! } ! else{ ! acl_in = acl; ! } ! } ! ! public int getACLout(){ ! return acl_out; ! } ! ! public void setACLout(int acl){ ! if(acl<0 || acl>2699){ ! acl_out = 0; ! } ! else{ ! acl_out = acl; ! } ! } }//EOF --- 421,543 ---- */ ! public Link getConnectedLink() { ! return connectedLink; ! } ! public String getConnectedLinkName() { ! if(connectedLink!=null) return connectedLink.getName(); ! else return null; ! } ! /** ! * This method returns the name of the network interface ! * @author tristan_veness ! * @return Name ! * @version v0.10 ! */ ! protected String getDetails(){ ! return name; ! } ! /** ! * This method returns a string of information about if the network interface is connected of not. ! * <P>This method is useful for a CLI or for debugging.</P> ! * @author tristan_veness ! * @return Name - Connection: link1 ! * @version v0.10 ! */ ! protected String getConnectLinkDetails(){ ! if(connectedLink != null){ ! return "Connection: "+ connectedLink.getName(); ! } ! return "Connection: Not connected"; ! } ! public String getConnectLinkName() ! { ! if(connectedLink !=null) ! { ! ! return connectedLink.getName(); ! ! } ! ! return "Not Connected"; ! ! } ! ! public String getDescription(){ ! return description; ! } ! ! public void setDescription(String description){ ! this.description = description; ! } ! ! public int getACLin(){ ! return acl_in; ! } ! ! public void setACLin(int acl){ ! if(acl<0 || acl>2699){ ! acl_in = 0; ! } ! else{ ! acl_in = acl; ! } ! } ! ! public int getACLout(){ ! return acl_out; ! } ! ! public void setACLout(int acl){ ! if(acl<0 || acl>2699){ ! acl_out = 0; ! } ! else{ ! acl_out = acl; ! } ! } ! ! public Node getParentNode() { ! return parentNode; ! } }//EOF Index: ApplicationLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/ApplicationLayerDevice.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ApplicationLayerDevice.java 24 Oct 2008 16:18:48 -0000 1.12 --- ApplicationLayerDevice.java 26 Oct 2008 22:02:46 -0000 1.13 *************** *** 10,15 **** --- 10,19 ---- import java.util.Enumeration; import java.util.Hashtable; + import java.util.Vector; import core.protocolsuite.tcp_ip.Application; + import core.protocolsuite.tcp_ip.DNS; + import core.protocolsuite.tcp_ip.DNS_Message; + import core.protocolsuite.tcp_ip.IPV4Address; /** *************** *** 37,54 **** public final static int RIP_SERVER_ID = 520; ! protected Hashtable Apps = null; ! protected Hashtable userlist = new Hashtable(); /** Creates a new instance of ApplicationLayerDevice */ public ApplicationLayerDevice(String inName, int inProtocolStackLayers, boolean inOn) { super(inName, inProtocolStackLayers, inOn); ! Apps = new Hashtable(); if(inOn) initApplications(); } ! public void addApp(Object app, int code){ Apps.put(code, app); } ! public Object getApp(int code){ if(Apps==null) return null; return Apps.get(code); --- 41,59 ---- public final static int RIP_SERVER_ID = 520; ! protected Hashtable<Integer, Application> Apps = null; ! protected Hashtable<String,String> userlist = new Hashtable<String,String>(); ! private String nameServer = ""; /** Creates a new instance of ApplicationLayerDevice */ public ApplicationLayerDevice(String inName, int inProtocolStackLayers, boolean inOn) { super(inName, inProtocolStackLayers, inOn); ! Apps = new Hashtable<Integer, Application>(); if(inOn) initApplications(); } ! public void addApp(Application app, int code){ Apps.put(code, app); } ! public Application getApp(int code){ if(Apps==null) return null; return Apps.get(code); *************** *** 98,102 **** public String getUserPassword(String username){ if(userlist==null) return null; ! return (String)userlist.get(username); } --- 103,107 ---- public String getUserPassword(String username){ if(userlist==null) return null; ! return userlist.get(username); } *************** *** 105,108 **** --- 110,149 ---- return userlist.keys(); } + + public boolean setNameServer(String ns){ + if(IPV4Address.validateDecIP(ns)){ + nameServer = ns; + return true; + } + return false; + } + + public String getNameServer(){ + return nameServer; + } + + public Vector<String> resolve(String name){ + Vector<String> out = new Vector<String>(); + if(nameServer!=""){ + DNS dns = (DNS)this.getApp(core.ApplicationLayerDevice.DNS_CLIENT_ID); + int id; + try { + id = dns.SendMessage(nameServer, 53, name, DNS_Message.A_QUERY_TYPE); + if(dns.receivedMessages.containsKey(id)){ + DNS_Message dnsMes = dns.receivedMessages.get(id); + Vector<DNS_Message.Answer> answer = dnsMes.getAnswer(); + for(int i=0; i<answer.size(); i++){ + DNS_Message.Answer ans = answer.get(i); + out.add(ans.resource); + } + } + } catch (CommunicationException e) { + } catch (LowLinkException e) { + } catch (InvalidNetworkLayerDeviceException e) { + } catch (TransportLayerException e) { + } + } + return out; + } } |
From: QweR <qw...@us...> - 2008-10-26 22:03:03
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv32599/guiUI Modified Files: GuiNode.java Terminal.java Log Message: Added commands ip name-server int * databits int * flowcontrol int * parity int * speed int * stopbits Index: GuiNode.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiNode.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** GuiNode.java 25 Oct 2008 21:33:32 -0000 1.13 --- GuiNode.java 26 Oct 2008 22:02:46 -0000 1.14 *************** *** 95,98 **** --- 95,100 ---- import javax.swing.SwingConstants; + import core.Link; + import core.NetworkInterface; import core.Node; import core.Simulation; *************** *** 379,387 **** for (int i = 0; i < ints.length; i++) { int int_type = Simulation.Sim.getNode(this.strNodeName).getIntType((String)ints[i]); ! boolean lineIsConnected = (Simulation.Sim.getNode(this.strNodeName).getNetworkInterface((String)ints[i]).getConnectedLink()!=null); if(int_type != core.NetworkInterface.Wireless && lineIsConnected){ ! ! JMenuItem mnuDI = new JMenuItem((String) ints[i]); mnuDI.addActionListener(new ActionListener() { --- 381,390 ---- for (int i = 0; i < ints.length; i++) { int int_type = Simulation.Sim.getNode(this.strNodeName).getIntType((String)ints[i]); ! NetworkInterface ni = Simulation.Sim.getNode(this.strNodeName).getNetworkInterface((String)ints[i]); ! boolean lineIsConnected = ni.getConnectedLink()!=null; if(int_type != core.NetworkInterface.Wireless && lineIsConnected){ ! ! JMenuItem mnuDI = new JMenuItem((String)ints[i]+" ("+ni.getConnectedLink().getLinkedNodeName(getName(), (String)ints[i])+")"); mnuDI.addActionListener(new ActionListener() { Index: Terminal.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/Terminal.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Terminal.java 24 Oct 2008 16:18:48 -0000 1.21 --- Terminal.java 26 Oct 2008 22:02:46 -0000 1.22 *************** *** 644,648 **** if(params.size()==1){ String ip = params.get(0); ! if(IPV4Address.validateDecIP(ip)){ out += "Type escape sequence to abort.\n"; out += "Sending 5, 4-byte ICMP Echos to "+params.get(0)+", timeout is 1 second:\n"; --- 644,658 ---- if(params.size()==1){ String ip = params.get(0); ! String dest = null; ! if(!IPV4Address.isValidIp(ip)){ ! Vector<String> addrs = ((ApplicationLayerDevice)device).resolve(ip); ! if(addrs.size()>0){ ! dest = addrs.get(0); ! } ! } ! else{ ! dest = ip; ! } ! if(dest!=null){ out += "Type escape sequence to abort.\n"; out += "Sending 5, 4-byte ICMP Echos to "+params.get(0)+", timeout is 1 second:\n"; *************** *** 651,654 **** --- 661,667 ---- out += "\\\\"; } + else{ + out += "Name '"+ip+"' was not resolved\n"; + } } else{ |
From: QweR <qw...@us...> - 2008-10-26 22:03:03
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv32599/core/protocolsuite/tcp_ip Modified Files: DNS.java ProtocolStack.java socketLayer.java Log Message: Added commands ip name-server int * databits int * flowcontrol int * parity int * speed int * stopbits Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** ProtocolStack.java 26 Oct 2008 15:37:40 -0000 1.75 --- ProtocolStack.java 26 Oct 2008 22:02:46 -0000 1.76 *************** *** 59,62 **** --- 59,63 ---- import java.util.Vector; + import core.ApplicationLayerDevice; import core.CommunicationException; import core.InvalidDefaultGatewayException; *************** *** 668,684 **** LowLinkException { ICMP_packet pingPacket = null; ! if(!IPV4Address.isValidIp(inDestIPAddress)){ if(mParentNode instanceof core.ApplicationLayerDevice){ ! //inDestIPAddress = ResolveDNS } } ! if (IPV4Address.validateDecIP(inDestIPAddress)) { ! pingPacket = mICMPprotocol.sendPing(inDestIPAddress); sendPacket(pingPacket); } else throw new CommunicationException("Packet dropped host unreachable " ! + inDestIPAddress); return pingPacket; } --- 669,692 ---- LowLinkException { ICMP_packet pingPacket = null; ! String dest = null; ! if(!IPV4Address.isValidIp(inDestIPAddress)){ if(mParentNode instanceof core.ApplicationLayerDevice){ ! Vector<String> addrs = ((ApplicationLayerDevice)mParentNode).resolve(inDestIPAddress); ! if(addrs.size()>0){ ! dest = addrs.get(0); ! } } } + else{ + dest = inDestIPAddress; + } ! if (dest!="") { ! pingPacket = mICMPprotocol.sendPing(dest); sendPacket(pingPacket); } else throw new CommunicationException("Packet dropped host unreachable " ! + dest); return pingPacket; } Index: DNS.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/DNS.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DNS.java 24 Oct 2008 17:46:42 -0000 1.6 --- DNS.java 26 Oct 2008 22:02:46 -0000 1.7 *************** *** 167,172 **** if (Connect (host, port)) { ! SendData(mess.toLowerCase()+":"+Integer.toString(qType)); ! return last_sent_id; } return 0; --- 167,174 ---- if (Connect (host, port)) { ! if(DNS.isValidName(mess)){ ! SendData(mess.toLowerCase()+":"+Integer.toString(qType)); ! return last_sent_id; ! } } return 0; Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** socketLayer.java 26 Oct 2008 15:37:40 -0000 1.16 --- socketLayer.java 26 Oct 2008 22:02:46 -0000 1.17 *************** *** 2,6 **** --- 2,8 ---- import java.util.Hashtable; + import java.util.Vector; + import core.ApplicationLayerDevice; import core.CommunicationException; import core.LowLinkException; *************** *** 61,81 **** public boolean connect(int sock, String ipaddr, int port) throws LowLinkException, CommunicationException, TransportLayerException{ boolean result = false; if(!IPV4Address.isValidIp(ipaddr)){ ! //inDestIPAddress = ResolveDNS } ! jnSocket jnsock = get_socket(sock); ! if(jnsock.type == jnSocket.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 == jnSocket.UDP_socket){ ! jnsock.dst_IP = ipaddr; ! jnsock.dst_port = port; ! result = true; ! } return result; } --- 63,92 ---- public boolean connect(int sock, String ipaddr, int port) throws LowLinkException, CommunicationException, TransportLayerException{ boolean result = false; + String dest = null; if(!IPV4Address.isValidIp(ipaddr)){ ! Vector<String> addrs = ((ApplicationLayerDevice)mParentStack.getParentNode()).resolve(ipaddr); ! if(addrs.size()>0){ ! dest = addrs.get(0); ! } ! } ! else{ ! dest = ipaddr; } ! if(dest != null){ ! jnSocket jnsock = get_socket(sock); ! if(jnsock.type == jnSocket.TCP_socket){ ! jnsock.open_state = true; ! jnsock.dst_IP = dest; ! jnsock.dst_port = port; ! result = mParentStack.TCP().connect(sock, dest, port); ! } ! else if(jnsock.type == jnSocket.UDP_socket){ ! jnsock.dst_IP = dest; ! jnsock.dst_port = port; ! result = true; ! } ! } return result; } *************** *** 113,126 **** public void writeTo(int sock, String data, String IP, int port) throws LowLinkException, TransportLayerException{ ! if(!IPV4Address.isValidIp(IP)){ ! //inDestIPAddress = ResolveDNS } - // - //if() - // udp only write!!! - (sockTable.get(sock)).dst_IP = IP; - (sockTable.get(sock)).dst_port = port; - (sockTable.get(sock)).open_state = true; - mParentStack.UDP().sendUDPPacket(sock, IP, port, data); } --- 124,145 ---- public void writeTo(int sock, String data, String IP, int port) throws LowLinkException, TransportLayerException{ ! String dest = null; ! ! if(!IPV4Address.isValidIp(IP)){ ! Vector<String> addrs = ((ApplicationLayerDevice)mParentStack.getParentNode()).resolve(IP); ! if(addrs.size()>0){ ! dest = addrs.get(0); ! } ! } ! else{ ! dest = IP; ! } ! ! if(dest != null){ ! (sockTable.get(sock)).dst_IP = dest; ! (sockTable.get(sock)).dst_port = port; ! (sockTable.get(sock)).open_state = true; ! mParentStack.UDP().sendUDPPacket(sock, dest, port, data); } } |
From: Alexander B. <da...@us...> - 2008-10-26 15:37:49
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12670/guiUI Modified Files: MainScreen.java Log Message: Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.102 retrieving revision 1.103 diff -C2 -d -r1.102 -r1.103 *** MainScreen.java 25 Oct 2008 16:35:11 -0000 1.102 --- MainScreen.java 26 Oct 2008 15:37:40 -0000 1.103 *************** *** 1721,1724 **** --- 1721,1725 ---- chooser.setDialogTitle("Save As ..."); chooser.setAcceptAllFileFilterUsed(false); + //chooser.set chooser.addChoosableFileFilter(new JNSTFilter()); *************** *** 1742,1745 **** --- 1743,1753 ---- + MainScreen.SIM_PREFIX); } + + if(simSaveFile.exists() && saveas == null){ + if(JOptionPane.showConfirmDialog(this, "File exists! Overwrite?", + "Confirm overwriting!", JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) + return; + } // Save Simulation. *************** *** 1947,1950 **** --- 1955,1965 ---- String file = tempFile.getPath(); + if(tempFile.exists()){ + if(JOptionPane.showConfirmDialog(this, "File exists! Overwrite?", + "Confirm overwriting!", JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) + return; + } + if (chooser.getFileFilter() instanceof HTMLFilter) save_html_rep(file); *************** *** 2807,2810 **** --- 2822,2828 ---- String rts[] = rs.split("\\|"); + if(rts[0].equals("default")) + rts[2] = "0.0.0.0"; + /*r = new Route_entry(rts[0], rts[1], rts[2], rts[4], Integer.valueOf(rts[3]) |
From: Alexander B. <da...@us...> - 2008-10-26 15:37:48
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12670/core/protocolsuite/tcp_ip Modified Files: IPV4Address.java ProtocolStack.java socketLayer.java Log Message: Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -d -r1.74 -r1.75 *** ProtocolStack.java 24 Oct 2008 16:18:48 -0000 1.74 --- ProtocolStack.java 26 Oct 2008 15:37:40 -0000 1.75 *************** *** 668,671 **** --- 668,678 ---- LowLinkException { ICMP_packet pingPacket = null; + + if(!IPV4Address.isValidIp(inDestIPAddress)){ + if(mParentNode instanceof core.ApplicationLayerDevice){ + //inDestIPAddress = ResolveDNS + } + } + if (IPV4Address.validateDecIP(inDestIPAddress)) { pingPacket = mICMPprotocol.sendPing(inDestIPAddress); Index: socketLayer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/socketLayer.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** socketLayer.java 24 Oct 2008 16:18:48 -0000 1.15 --- socketLayer.java 26 Oct 2008 15:37:40 -0000 1.16 *************** *** 61,64 **** --- 61,69 ---- public boolean connect(int sock, String ipaddr, int port) throws LowLinkException, CommunicationException, TransportLayerException{ boolean result = false; + + if(!IPV4Address.isValidIp(ipaddr)){ + //inDestIPAddress = ResolveDNS + } + jnSocket jnsock = get_socket(sock); if(jnsock.type == jnSocket.TCP_socket){ *************** *** 107,110 **** --- 112,119 ---- public void writeTo(int sock, String data, String IP, int port) throws LowLinkException, TransportLayerException{ + + if(!IPV4Address.isValidIp(IP)){ + //inDestIPAddress = ResolveDNS + } // //if() Index: IPV4Address.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/IPV4Address.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** IPV4Address.java 24 Oct 2008 16:18:48 -0000 1.8 --- IPV4Address.java 26 Oct 2008 15:37:40 -0000 1.9 *************** *** 77,80 **** --- 77,86 ---- } + + public static boolean isValidIp(final String ip) + { + return ip.matches("^[\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}$"); + } + /** * This method returns the binary subnetmask in decimal |
From: Alexander B. <da...@us...> - 2008-10-26 15:37:48
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12670/core Modified Files: Version.java Log Message: Index: Version.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Version.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Version.java 6 Oct 2008 13:20:39 -0000 1.16 --- Version.java 26 Oct 2008 15:37:40 -0000 1.17 *************** *** 44,48 **** public static final String TEAM_MEMBERS[] = { ! "http://sf.net/projects/javanetsim","release date: 20 Nov 2007", "", "fork of jFirewallSim project (http://sf.net/projects/jfirewallsim/)", "from 03 Nov 2005","", --- 44,48 ---- public static final String TEAM_MEMBERS[] = { ! "http://sf.net/projects/javanetsim","release date: 1 Nov 2008", "", "fork of jFirewallSim project (http://sf.net/projects/jfirewallsim/)", "from 03 Nov 2005","", *************** *** 50,54 **** "Konstantin Karpov [QweR]", "Developer / Tester", "","Contributors & Old Developers:", ! "Ilgar Alekperov [Gift]", "\t First version of TCP, Echo TCP, Export to HTML, Testing & Bugfixinig", "Igor Goroshkov", "\t RIP protocol core & GUI", "", "If you found a bug, please post it to: http://sf.net/tracker/?atid=784685&group_id=152576", --- 50,54 ---- "Konstantin Karpov [QweR]", "Developer / Tester", "","Contributors & Old Developers:", ! "Ilgar Alekperov [Gift]", "\t First version of TCP, Echo TCP, Export to HTML, Testing & Bugfixing", "Igor Goroshkov", "\t RIP protocol core & GUI", "", "If you found a bug, please post it to: http://sf.net/tracker/?atid=784685&group_id=152576", |
From: Alexander B. <da...@us...> - 2008-10-26 15:37:46
|
Update of /cvsroot/javanetsim/javaNetSim/images In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12670/images Modified Files: firewall.gif Log Message: Index: firewall.gif =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/images/firewall.gif,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 Binary files /tmp/cvs74weHL and /tmp/cvsVe8X2I differ |
From: QweR <qw...@us...> - 2008-10-25 22:16:44
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31738/guiUI Modified Files: GuiNode.java SandBox.java Log Message: Drag'n'Drop was fixed Index: GuiNode.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiNode.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** GuiNode.java 25 Oct 2008 16:35:11 -0000 1.12 --- GuiNode.java 25 Oct 2008 21:33:32 -0000 1.13 *************** *** 111,119 **** public abstract class GuiNode extends JPanel implements MouseListener, ! MouseMotionListener, Serializable, DragGestureListener, ! DragSourceListener, DropTargetListener { // The node's name within a label protected JLabel lblNodeName = new JLabel(); --- 111,124 ---- public abstract class GuiNode extends JPanel implements MouseListener, ! MouseMotionListener, Serializable, DragGestureListener, ! DragSourceListener, DropTargetListener { // The node's name within a label + /** + * + */ + private static final long serialVersionUID = 3501858129186840165L; + protected JLabel lblNodeName = new JLabel(); *************** *** 130,134 **** protected String tmpName = ""; ! // A Refence to the MainScreen protected MainScreen controller; --- 135,139 ---- protected String tmpName = ""; ! // A Reference to the MainScreen protected MainScreen controller; *************** *** 154,158 **** private String strNodeName; ! private Vector vecConnectedLinks = new Vector(); boolean acceptDrop = true; --- 159,163 ---- private String strNodeName; ! private Vector<String> vecConnectedLinks = new Vector<String>(); boolean acceptDrop = true; *************** *** 166,176 **** private int SandBoxHeight; ! //private int lastX; ! ! //private int lastY; ! ! private int controlX; ! ! private int controlY; // These statics are only for sandbox class. These shouldn't be used --- 171,176 ---- private int SandBoxHeight; ! private int pressedX = 0; ! private int pressedY = 0; // These statics are only for sandbox class. These shouldn't be used *************** *** 328,332 **** mnuTurn.setText(controller.DeviceState(lblNodeName.getText())); } ! public void updateInterfacesMenu(){ try { --- 328,332 ---- mnuTurn.setText(controller.DeviceState(lblNodeName.getText())); } ! public void updateInterfacesMenu(){ try { *************** *** 335,339 **** for (int i = 0; i < ints.length; i++) { int int_type = Simulation.Sim.getNode(this.strNodeName).getIntType((String)ints[i]); ! if(int_type != core.NetworkInterface.Console){ JMenuItem mnuI = new JMenuItem((String) ints[i]); --- 335,339 ---- for (int i = 0; i < ints.length; i++) { int int_type = Simulation.Sim.getNode(this.strNodeName).getIntType((String)ints[i]); ! if(int_type != core.NetworkInterface.Console){ JMenuItem mnuI = new JMenuItem((String) ints[i]); *************** *** 343,347 **** controller.showIntProps(lblNodeName.getText(), ! ((JMenuItem) e.getSource()).getText()); } --- 343,347 ---- controller.showIntProps(lblNodeName.getText(), ! ((JMenuItem) e.getSource()).getText()); } *************** *** 350,354 **** mnuInt.add(mnuI); } ! if(int_type != core.NetworkInterface.Wireless){ --- 350,354 ---- mnuInt.add(mnuI); } ! if(int_type != core.NetworkInterface.Wireless){ *************** *** 359,363 **** controller.breakLink(lblNodeName.getText(), ! ((JMenuItem) e.getSource()).getText()); } --- 359,363 ---- controller.breakLink(lblNodeName.getText(), ! ((JMenuItem) e.getSource()).getText()); } *************** *** 372,376 **** } } ! public void updateConnectedLinkMenu(){ try { --- 372,376 ---- } } ! public void updateConnectedLinkMenu(){ try { *************** *** 380,384 **** int int_type = Simulation.Sim.getNode(this.strNodeName).getIntType((String)ints[i]); boolean lineIsConnected = (Simulation.Sim.getNode(this.strNodeName).getNetworkInterface((String)ints[i]).getConnectedLink()!=null); ! if(int_type != core.NetworkInterface.Wireless && lineIsConnected){ --- 380,384 ---- int int_type = Simulation.Sim.getNode(this.strNodeName).getIntType((String)ints[i]); boolean lineIsConnected = (Simulation.Sim.getNode(this.strNodeName).getNetworkInterface((String)ints[i]).getConnectedLink()!=null); ! if(int_type != core.NetworkInterface.Wireless && lineIsConnected){ *************** *** 389,393 **** controller.breakLink(lblNodeName.getText(), ! ((JMenuItem) e.getSource()).getText()); } --- 389,393 ---- controller.breakLink(lblNodeName.getText(), ! ((JMenuItem) e.getSource()).getText()); } *************** *** 402,409 **** } } ! public abstract void addInterfaces(MainScreen parent, Node node); ! ! /** * --- 402,409 ---- } } ! public abstract void addInterfaces(MainScreen parent, Node node); ! ! /** * *************** *** 555,559 **** (this.getX() + this.getWidth() / 2), (this.getY() + ! this.getHeight() / 2)); controller.addFakeLine(tempPoint); --- 555,559 ---- (this.getX() + this.getWidth() / 2), (this.getY() + ! this.getHeight() / 2)); controller.addFakeLine(tempPoint); *************** *** 707,715 **** for (int i = 2; i < GuiNodePopMenu.getSubElements().length; i++) { ((JMenuItem) GuiNodePopMenu.getSubElements()[i]) ! .setEnabled(ena); } updateConnectedLinkMenu(); GuiNodePopMenu.show(e.getComponent(), e.getX(), e.getY()); } } --- 707,719 ---- for (int i = 2; i < GuiNodePopMenu.getSubElements().length; i++) { ((JMenuItem) GuiNodePopMenu.getSubElements()[i]) ! .setEnabled(ena); } updateConnectedLinkMenu(); GuiNodePopMenu.show(e.getComponent(), e.getX(), e.getY()); } + else if (e.getModifiers() == InputEvent.BUTTON1_MASK) { + pressedX = e.getX(); + pressedY = e.getY(); + } } *************** *** 751,792 **** else { ! //lastX = this.getX() + e.getX() - this.getWidth(); ! ! //lastY = this.getY() + e.getY() - this.getHeight(); ! ! controlX = this.getX() + e.getX() + this.getWidth() / 2; ! ! controlY = this.getY() + e.getY() + this.getHeight() / 2; ! ! if (controlX < SandBoxWidth && controlX > this.getWidth()) ! ! { ! ! if (controlY < SandBoxHeight ! && controlY > this.getHeight()) ! ! { ! ! this.setLocation(this.getX() + e.getX() ! - this.getWidth() / 2, this.getY() ! + e.getY() - this.getHeight() / 2); ! ! Point position = new Point(this.getX() + e.getX(), ! this.getY() + e.getY()); ! Iterator it = vecConnectedLinks.iterator(); ! while (it.hasNext()) { ! String linkString = (String) it.next(); ! String LinkDetails[] = linkString.split(":"); ! controller.moveLink(LinkDetails[0], Integer ! .parseInt(LinkDetails[1]), position); ! } ! } } --- 755,779 ---- else { ! int controlX = this.getX() + e.getX();// + this.getWidth() / 2; ! int controlY = this.getY() + e.getY();// + this.getHeight() / 2; ! if (controlX > SandBoxWidth) controlX = SandBoxWidth; ! else if (controlX < 0) controlX = 0; ! if (controlY > SandBoxHeight) controlY = SandBoxHeight; ! else if (controlY < 0) controlY = 0; ! this.setLocation(controlX-pressedX, controlY-pressedY); ! Point position = new Point(this.getX()+this.getWidth()/2, this.getY()+this.getHeight()/2); ! Iterator<String> it = vecConnectedLinks.iterator(); ! while (it.hasNext()) { ! String linkString = it.next(); ! String LinkDetails[] = linkString.split(":"); ! controller.moveLink(LinkDetails[0], Integer ! .parseInt(LinkDetails[1]), position); } *************** *** 886,898 **** */ ! public Vector getConnectedLinks() { ! Vector linkList = new Vector(); ! Iterator it = vecConnectedLinks.iterator(); while (it.hasNext()) { ! String linkString = (String) it.next(); String LinkDetails[] = linkString.split(":"); --- 873,885 ---- */ ! public Vector<String> getConnectedLinks() { ! Vector<String> linkList = new Vector<String>(); ! Iterator<String> it = vecConnectedLinks.iterator(); while (it.hasNext()) { ! String linkString = it.next(); String LinkDetails[] = linkString.split(":"); *************** *** 921,929 **** { ! Iterator it = vecConnectedLinks.iterator(); while (it.hasNext()) { ! String linkString = (String) it.next(); String LinkDetails[] = linkString.split(":"); --- 908,916 ---- { ! Iterator<String> it = vecConnectedLinks.iterator(); while (it.hasNext()) { ! String linkString = it.next(); String LinkDetails[] = linkString.split(":"); Index: SandBox.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/SandBox.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** SandBox.java 24 Oct 2008 16:18:48 -0000 1.12 --- SandBox.java 25 Oct 2008 21:33:32 -0000 1.13 *************** *** 209,213 **** this.setCursor(csrDefault); ! controller.addNode(cursorClass, new Point(e.getX(), e.getY())); cursorClass = ""; } --- 209,213 ---- this.setCursor(csrDefault); ! controller.addNode(cursorClass, new Point(e.getX()-GuiNode.NodeWidth/2, e.getY()-GuiNode.NodeHeight/2)); cursorClass = ""; } |
From: Alexander B. <da...@us...> - 2008-10-25 16:35:27
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv3252/guiUI Modified Files: GuiMultilayerSwitch.java GuiNode.java GuiRouter.java GuiWirelessAP.java MainScreen.java Added Files: WiFiPortProperties.java Log Message: Index: GuiMultilayerSwitch.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiMultilayerSwitch.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GuiMultilayerSwitch.java 24 Oct 2008 16:18:48 -0000 1.3 --- GuiMultilayerSwitch.java 25 Oct 2008 16:35:11 -0000 1.4 *************** *** 60,63 **** --- 60,64 ---- import javax.swing.JMenuItem; + import core.NetworkInterface; import core.Node; *************** *** 143,146 **** --- 144,151 ---- node.addNetworkInterface(core.NetworkInterface.getIntName(core.NetworkInterface.Ethernet100FX) + String.valueOf(i), core.NetworkInterface.Ethernet100FX, false); } + + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Console) + + "0", NetworkInterface.Console, false); } --- NEW FILE: WiFiPortProperties.java --- /* Java Network Simulator (javaNetSim) Copyright (c) 2007, 2006, 2005, Ice Team; All rights reserved. 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 guiUI; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.WindowConstants; import core.NetworkLayerDevice; import core.Simulation; /** * * @author Key * * * This class is a dialog that shows Ethernet Port Props * */ public class WiFiPortProperties extends javax.swing.JDialog { /** * */ private static final long serialVersionUID = -8725131940909728774L; private JPanel backpanel; private JLabel lblInterface, cmbInterface; private JLabel lblNodeName, cmbNodeName; private JLabel lblError; private JButton btnOk; private JTextField txtMAC; private JLabel lblMAC; private JTextField txtSSID; private JLabel lblSSID; private JTextField txtWEPKey; private JLabel lblWEPKey; private JLabel lblAuthMode; private JComboBox cmbAuthMode; private JLabel lblChannel; private JComboBox cmbChannel; private JLabel lblMode; private JComboBox cmbMode; private JLabel lblUP; private JCheckBox chkUP; private MainScreen controller; private Simulation Sim; private String NodeName = ""; private String NodeInt = ""; public WiFiPortProperties(JFrame frame, String inNodeName, String inNodeInt, Simulation Sim) { super(frame); this.NodeName = inNodeName; this.NodeInt = inNodeInt; this.Sim = Sim; setResizable(false); controller = (MainScreen) frame; setTitle("WiFi Port Properties"); initGUI(inNodeName, inNodeInt); final JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.SOUTH); btnOk = new JButton(); btnOk.setEnabled(true); btnOk.setToolTipText("Set options!"); btnOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okButton(); } }); btnOk.setName("btnOK"); panel.add(btnOk); btnOk.setText("OK"); final JButton btnCancel = new JButton(); btnCancel.setToolTipText("Cancel changes"); btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton(); } }); btnCancel.setName("btnCancel"); panel.add(btnCancel); btnCancel.setText("Cancel"); this.getRootPane().setDefaultButton(btnOk); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setLocationRelativeTo(null); this.setModal(true); this.setVisible(true); } private void initGUI(String NodeName, String NodeInt) { try { setSize(350, 325); { backpanel = new JPanel(); backpanel.setMinimumSize(new Dimension(200, 10)); this.getContentPane().add(backpanel, BorderLayout.CENTER); GridBagLayout backpanelLayout = new GridBagLayout(); backpanel.setPreferredSize(new java.awt.Dimension(264, 253)); backpanelLayout.columnWeights = new double[] {}; backpanelLayout.columnWidths = new int[] {}; backpanelLayout.rowWeights = new double[] { 0.0 }; backpanelLayout.rowHeights = new int[] { 5, 5, 5, 5 }; backpanel.setLayout(backpanelLayout); { lblNodeName = new JLabel(); backpanel.add(lblNodeName, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 21, 0)); lblNodeName.setText("Node Name:"); } { lblInterface = new JLabel(); backpanel.add(lblInterface, new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblInterface.setText("Interface:"); } { lblMAC = new JLabel(); backpanel.add(lblMAC, new GridBagConstraints(0, 2, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblMAC.setText("MAC Address:"); } { lblChannel = new JLabel(); backpanel.add(lblChannel, new GridBagConstraints(0, 3, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblChannel.setText("Channel:"); } { lblMode = new JLabel(); backpanel.add(lblMode, new GridBagConstraints(0, 4, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblMode.setText("Mode:"); } { lblSSID = new JLabel(); backpanel.add(lblSSID, new GridBagConstraints(0, 5, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblSSID.setText("SSID:"); } { lblAuthMode = new JLabel(); backpanel.add(lblAuthMode, new GridBagConstraints(0, 6, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblAuthMode.setText("Authentication:"); } { lblWEPKey = new JLabel(); backpanel.add(lblWEPKey, new GridBagConstraints(0, 7, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblWEPKey.setText("WEP Key(1,40b):"); } { lblUP = new JLabel(); backpanel.add(lblUP, new GridBagConstraints(0, 8, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblUP.setText("Administratively UP:"); } { cmbNodeName = new JLabel(); cmbNodeName.setMinimumSize(new Dimension(100, 0)); cmbNodeName.setText(NodeName); final GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.LINE_START; gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 1; backpanel.add(cmbNodeName, gridBagConstraints); } { cmbInterface = new JLabel(); cmbInterface.setText(NodeInt); final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints(); gridBagConstraints_1.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_1.anchor = GridBagConstraints.LINE_START; gridBagConstraints_1.gridy = 1; gridBagConstraints_1.gridx = 1; backpanel.add(cmbInterface, gridBagConstraints_1); } txtMAC = new JTextField(); txtMAC.addFocusListener(new FocusAdapter() { public void actionPerformed(ActionEvent e) { lblError.setVisible(false); } }); txtMAC.setEnabled(true); final GridBagConstraints gridBagConstraints_3 = new GridBagConstraints(); gridBagConstraints_3.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_3.anchor = GridBagConstraints.LINE_START; gridBagConstraints_3.gridy = 2; gridBagConstraints_3.gridx = 1; backpanel.add(txtMAC, gridBagConstraints_3); txtMAC.setText(Sim.getNode(NodeName).getMACAddress(NodeInt)); cmbChannel = new JComboBox(); cmbChannel.setEnabled(true); final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints(); gridBagConstraints_6.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_6.anchor = GridBagConstraints.LINE_START; gridBagConstraints_6.gridy = 3; gridBagConstraints_6.gridx = 1; backpanel.add(cmbChannel, gridBagConstraints_6); for(int i = 0; i<=15; i++) cmbChannel.addItem(i); cmbChannel.setSelectedIndex(((core.WiFiPort)Sim.getNode(NodeName).getNetworkInterface(NodeInt)).getChannel()); cmbMode = new JComboBox(); cmbMode.setEnabled(true); final GridBagConstraints gridBagConstraints_12 = new GridBagConstraints(); gridBagConstraints_12.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_12.anchor = GridBagConstraints.LINE_START; gridBagConstraints_12.gridy = 4; gridBagConstraints_12.gridx = 1; backpanel.add(cmbMode, gridBagConstraints_12); cmbMode.addItem("Station"); if(Sim.getNode(NodeName) instanceof core.Router || Sim.getNode(NodeName) instanceof core.WirelessAP) cmbMode.addItem("AP"); if(((core.WiFiPort)Sim.getNode(NodeName).getNetworkInterface(NodeInt)).getMode() == core.WiFiPort.MODE_AP) cmbMode.setSelectedIndex(1); txtSSID = new JTextField(); /*txtSSID.addFocusListener(new FocusAdapter() { public void actionPerformed(ActionEvent e) { //lblError.setVisible(false); } });*/ txtSSID.setEnabled(true); final GridBagConstraints gridBagConstraints_9 = new GridBagConstraints(); gridBagConstraints_9.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_9.anchor = GridBagConstraints.LINE_START; gridBagConstraints_9.gridy = 5; gridBagConstraints_9.gridx = 1; backpanel.add(txtSSID, gridBagConstraints_9); txtSSID.setText(((core.WiFiPort)Sim.getNode(NodeName).getNetworkInterface(NodeInt)).getSSID()); cmbAuthMode = new JComboBox(); cmbAuthMode.setEnabled(true); final GridBagConstraints gridBagConstraints_8 = new GridBagConstraints(); gridBagConstraints_8.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_8.anchor = GridBagConstraints.LINE_START; gridBagConstraints_8.gridy = 6; gridBagConstraints_8.gridx = 1; backpanel.add(cmbAuthMode, gridBagConstraints_8); cmbAuthMode.addItem("Open"); cmbAuthMode.addItem("Shared"); if(((core.WiFiPort)Sim.getNode(NodeName).getNetworkInterface(NodeInt)).isSharedAuth()) cmbChannel.setSelectedIndex(1); txtWEPKey = new JTextField(); /*txtWEPKey.addFocusListener(new FocusAdapter() { public void actionPerformed(ActionEvent e) { //lblError.setVisible(false); } });*/ txtWEPKey.setEnabled(true); final GridBagConstraints gridBagConstraints_10 = new GridBagConstraints(); gridBagConstraints_10.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_10.anchor = GridBagConstraints.LINE_START; gridBagConstraints_10.gridy = 7; gridBagConstraints_10.gridx = 1; backpanel.add(txtWEPKey, gridBagConstraints_10); txtWEPKey.setText(((core.WiFiPort)Sim.getNode(NodeName).getNetworkInterface(NodeInt)).getWEPKey(1)); chkUP = new JCheckBox(); chkUP.setEnabled(true); final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints(); gridBagConstraints_4.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_4.anchor = GridBagConstraints.LINE_START; gridBagConstraints_4.gridy = 8; gridBagConstraints_4.gridx = 1; backpanel.add(chkUP, gridBagConstraints_4); chkUP.setSelected(Sim.getNode(NodeName).getNIC(NodeInt).isUP()); lblError = new JLabel(); lblError.setHorizontalTextPosition(SwingConstants.CENTER); lblError.setHorizontalAlignment(SwingConstants.CENTER); lblError.setAlignmentX(Component.CENTER_ALIGNMENT); lblError.setMinimumSize(new Dimension(100, 20)); lblError.setMaximumSize(new Dimension(100, 20)); lblError.setPreferredSize(new Dimension(100, 20)); lblError.setVisible(false); final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints(); gridBagConstraints_5.anchor = GridBagConstraints.WEST; gridBagConstraints_5.insets = new Insets(0, 1, 0, 0); gridBagConstraints_5.fill = GridBagConstraints.BOTH; gridBagConstraints_5.gridwidth = 2; gridBagConstraints_5.gridy = 9; gridBagConstraints_5.gridx = 0; backpanel.add(lblError, gridBagConstraints_5); lblError.setText("Invalid MAC!"); } } catch (Exception e) { e.printStackTrace(); } } /** * This method is executed when the user hit's the enter button. It will * delete the link on selected interface. * * @author Key * */ private void okButton() { try { String SC = txtMAC.getText(); if (!SC.matches("[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]")) { Error("Invalid MAC Address!"); return; } if(txtSSID.getText().length() < 2){ Error("Invalid SSID!"); } NetworkLayerDevice tmpNode = (NetworkLayerDevice) Sim.getNode(NodeName); tmpNode.getConfig().executeCommand( "int " + NodeInt + " shutdown"); tmpNode.getConfig().executeCommand( "int " + NodeInt + " mac-address " + SC); tmpNode.getConfig().executeCommand( "int " + NodeInt + " ssid " + txtSSID.getText()); tmpNode.getConfig().executeCommand( "int " + NodeInt + " int wrl0 encryption key 1 size 40bit " + txtWEPKey.getText()); if(cmbAuthMode.getSelectedIndex() == 1) tmpNode.getConfig().executeCommand( "int " + NodeInt + " authentication open"); else tmpNode.getConfig().executeCommand( "int " + NodeInt + " authentication shared"); if(cmbMode.getItemAt(cmbMode.getSelectedIndex()).equals("Station")) tmpNode.getConfig().executeCommand( "int " + NodeInt + "station-role client"); else tmpNode.getConfig().executeCommand( "int " + NodeInt + " station-role root access-point"); if (chkUP.isSelected()) { tmpNode.getConfig().executeCommand( "no int " + NodeInt + " shutdown"); } else { tmpNode.getConfig().executeCommand( "int " + NodeInt + " shutdown"); } tmpNode.getConfig().executeCommand("write mem"); this.dispose(); } catch (Exception e) { e.printStackTrace(); } } /** * This method is executed when the user hits the cancel button * * @author luke_hamilton * @author Key * */ private void cancelButton() { this.dispose(); } private void Error(String txt){ lblError.setText(txt); lblError.setForeground(Color.RED); lblError.setVisible(true); controller.shakeDiaLog(this); } } Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.101 retrieving revision 1.102 diff -C2 -d -r1.101 -r1.102 *** MainScreen.java 24 Oct 2008 18:13:48 -0000 1.101 --- MainScreen.java 25 Oct 2008 16:35:11 -0000 1.102 *************** *** 1934,1938 **** --- 1934,1940 ---- chooser.setAcceptAllFileFilterUsed(false); chooser.addChoosableFileFilter(new HTMLFilter()); + chooser.addChoosableFileFilter(new JPGFilter()); chooser.addChoosableFileFilter(new PNGFilter()); + int returnVal = chooser.showSaveDialog(this); *************** *** 4523,4526 **** --- 4525,4531 ---- } break; + case core.NetworkInterface.Wireless: + new WiFiPortProperties(this, NodeName, IntName, Sim); + break; case core.NetworkInterface.Serial: new SerPortProperties(this, NodeName, IntName, Sim, Sandbox); Index: GuiNode.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiNode.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GuiNode.java 24 Oct 2008 16:18:48 -0000 1.11 --- GuiNode.java 25 Oct 2008 16:35:11 -0000 1.12 *************** *** 336,340 **** int int_type = Simulation.Sim.getNode(this.strNodeName).getIntType((String)ints[i]); ! if(int_type != core.NetworkInterface.Console && int_type != core.NetworkInterface.Wireless){ JMenuItem mnuI = new JMenuItem((String) ints[i]); mnuI.addActionListener(new ActionListener() { --- 336,340 ---- int int_type = Simulation.Sim.getNode(this.strNodeName).getIntType((String)ints[i]); ! if(int_type != core.NetworkInterface.Console){ JMenuItem mnuI = new JMenuItem((String) ints[i]); mnuI.addActionListener(new ActionListener() { Index: GuiWirelessAP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiWirelessAP.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GuiWirelessAP.java 24 Oct 2008 16:18:48 -0000 1.4 --- GuiWirelessAP.java 25 Oct 2008 16:35:11 -0000 1.5 *************** *** 107,110 **** --- 107,114 ---- .getIntName(core.NetworkInterface.Wireless) + "0", NetworkInterface.Wireless, false, 0); + + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Console) + + "0", NetworkInterface.Console, false); } Index: GuiRouter.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/GuiRouter.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GuiRouter.java 24 Oct 2008 16:18:48 -0000 1.8 --- GuiRouter.java 25 Oct 2008 16:35:11 -0000 1.9 *************** *** 130,134 **** "Router with 2 Ethernet-TX ports and 1 Ethernet-FX port.", "Router with 3 Ethernet-FX ports.", ! "Multi-enviroment router with 1 Ethernet-TX, 2 Serial and 1 Ethernet-FX ports." }; --- 130,137 ---- "Router with 2 Ethernet-TX ports and 1 Ethernet-FX port.", "Router with 3 Ethernet-FX ports.", ! "WAN router with 1 Ethernet-TX, 2 Serial and 1 Ethernet-FX ports.", ! "Wireless router with 1 Ethernet-TX and 1 WiFi ports.", ! "Multi-enviroment router with 3 Ethernet-TX, 2 Serial, 1 WiFi and 1 Ethernet-FX ports."/*, ! "Router with embbeded switch"*/ }; *************** *** 186,190 **** --- 189,228 ---- .getIntName(NetworkInterface.Ethernet100FX) + "0", NetworkInterface.Ethernet100FX, true); + } else if (choice.contains(choices[5])) { + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Ethernet10T) + + "0", NetworkInterface.Ethernet10T, true); + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Wireless) + + "0", NetworkInterface.Wireless, true); + + } else if (choice.contains(choices[6])) { + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Ethernet10T) + + "0", NetworkInterface.Ethernet10T, true, 0); + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Ethernet10T) + + "1", NetworkInterface.Ethernet10T, true); + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Ethernet10T) + + "2", NetworkInterface.Ethernet10T, true); + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Serial) + + "0", NetworkInterface.Serial, true); + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Serial) + + "1", NetworkInterface.Serial, true); + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Ethernet100FX) + + "0", NetworkInterface.Ethernet100FX, true); + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Wireless) + + "0", NetworkInterface.Wireless, true); } + + + node.addNetworkInterface(NetworkInterface + .getIntName(NetworkInterface.Console) + + "0", NetworkInterface.Console, false); } |
From: Alexander B. <da...@us...> - 2008-10-25 16:35:16
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv3252/core Modified Files: Router.java Log Message: Index: Router.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Router.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Router.java 24 Oct 2008 16:18:48 -0000 1.12 --- Router.java 25 Oct 2008 16:35:11 -0000 1.13 *************** *** 43,47 **** **/ ! class Router extends ApplicationLayerDevice { /** --- 43,47 ---- **/ ! public class Router extends ApplicationLayerDevice { /** |
From: Alexander B. <da...@us...> - 2008-10-24 18:13:53
|
Update of /cvsroot/javanetsim/javaNetSim In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12939 Modified Files: README.txt Log Message: Index: README.txt =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/README.txt,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** README.txt 17 Oct 2008 09:10:16 -0000 1.18 --- README.txt 24 Oct 2008 18:13:48 -0000 1.19 *************** *** 40,43 **** --- 40,47 ---- 1. Fixed some bugs with interface and console. + + Simulation Issues - + + 1. Fixed DHCP bugs. New Features *************** *** 50,53 **** --- 54,59 ---- 5. Dynamic and Static NAT added. 6. New device: laptop. + 7. Added Export to PNG & JPEG. + 8. Added VLANs and Multilayer switches. |
From: Alexander B. <da...@us...> - 2008-10-24 18:13:53
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12939/guiUI Modified Files: MainScreen.java MenuBar.java Log Message: Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.100 retrieving revision 1.101 diff -C2 -d -r1.100 -r1.101 *** MainScreen.java 24 Oct 2008 16:18:48 -0000 1.100 --- MainScreen.java 24 Oct 2008 18:13:48 -0000 1.101 *************** *** 159,162 **** --- 159,166 ---- private static final String HTM_PREFIX = "htm"; + + private static final String PNG_PREFIX = "png"; + + private static final String JPG_PREFIX = "png"; // File used to save simulation *************** *** 617,630 **** 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); --- 621,645 ---- mConsole.setColumnIdentifiers(new Object[] { "Time", "Node", "Packet", "Layer", "Info" }); + + pnlConsole.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + //pnlConsole.se ! //pnlConsole.getColumnModel().getColumn(0).setPreferredWidth(100); ! pnlConsole.getColumnModel().getColumn(0).setMinWidth(90); ! pnlConsole.getColumnModel().getColumn(0).setMaxWidth(200); ! //pnlConsole.getColumnModel().getColumn(1).setPreferredWidth(100); ! pnlConsole.getColumnModel().getColumn(1).setMinWidth(85); ! pnlConsole.getColumnModel().getColumn(1).setMaxWidth(200); ! //pnlConsole.getColumnModel().getColumn(2).setPreferredWidth(100); ! pnlConsole.getColumnModel().getColumn(2).setMinWidth(175); pnlConsole.getColumnModel().getColumn(2).setMaxWidth(200); ! //pnlConsole.getColumnModel().getColumn(3).setPreferredWidth(100); ! pnlConsole.getColumnModel().getColumn(3).setMinWidth(75); ! pnlConsole.getColumnModel().getColumn(3).setMaxWidth(200); ! ! pnlConsole.getColumnModel().getColumn(4).setMinWidth(400); ! ! ! //pnlConsole.setAutoResizeMode(; // pnlConsole.setEnabled(false); *************** *** 1912,1915 **** --- 1927,1981 ---- } + + public void Export(){ + JFileChooser chooser = new JFileChooser(); + + chooser.setDialogTitle("Export to..."); + chooser.setAcceptAllFileFilterUsed(false); + chooser.addChoosableFileFilter(new HTMLFilter()); + chooser.addChoosableFileFilter(new PNGFilter()); + + int returnVal = chooser.showSaveDialog(this); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + + // Get Selected file for saving GUI information + File tempFile = chooser.getSelectedFile(); + + String file = tempFile.getPath(); + + if (chooser.getFileFilter() instanceof HTMLFilter) + save_html_rep(file); + else if (chooser.getFileFilter() instanceof PNGFilter) + save_image(file, MainScreen.PNG_PREFIX); + else if (chooser.getFileFilter() instanceof JPGFilter) + save_image(file, MainScreen.JPG_PREFIX); + + } + } + + /** + * Generate and save png + * + * @author key + */ + private void save_image(String saveas, String prefix) { + // Get image to write to a file + BufferedImage bufferedImage = getDesktop(); + File file; + + if (saveas.contains("." + prefix)) + file = new File(saveas); + else + file = new File(saveas + "." + + prefix); + + // Save as PNG + try{ + ImageIO.write(bufferedImage, prefix, file); + }catch(IOException e){ e.printStackTrace(); } + + setStatus(prefix + " file was saved succesfully."); + } /** *************** *** 1918,1922 **** * @author gift (sourceforge.net user) */ ! public void save_html_rep(String saveas) { JFileChooser chooser = new JFileChooser(); --- 1984,1988 ---- * @author gift (sourceforge.net user) */ ! private void save_html_rep(String saveas) { JFileChooser chooser = new JFileChooser(); *************** *** 3342,3345 **** --- 3408,3452 ---- } } + + class PNGFilter extends FileFilter { + /** + * This method returns the Description that is in the File choosers + * Dialog + */ + public String getDescription() { + return "Portable Network Graphics image (*." + MainScreen.PNG_PREFIX + ")"; + } + + /** + * This method returns true or false if a file has the prefix + */ + public boolean accept(File f) { + if (f.isDirectory() || f.getName().endsWith(MainScreen.PNG_PREFIX)) { + return true; + } + return false; + } + } + + class JPGFilter extends FileFilter { + /** + * This method returns the Description that is in the File choosers + * Dialog + */ + public String getDescription() { + return "JPEG image (*." + MainScreen.JPG_PREFIX + ")"; + } + + /** + * This method returns true or false if a file has the prefix + */ + public boolean accept(File f) { + if (f.isDirectory() || f.getName().endsWith(MainScreen.JPG_PREFIX)) { + return true; + } + return false; + } + } + /** *************** *** 3524,3565 **** // 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); ! ! // Create a graphics contents on the buffered image ! 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 --- 3631,3635 ---- // Get image to write to a file ! BufferedImage bufferedImage = getDesktop(); // Save as PNG *************** *** 3569,3573 **** // Save as JPEG g_out = new File(gr_path); ! ImageIO.write((RenderedImage) bufferedImage2, "jpg", g_out); } catch (IOException ex) { --- 3639,3643 ---- // Save as JPEG g_out = new File(gr_path); ! ImageIO.write(bufferedImage, "jpg", g_out); } catch (IOException ex) { *************** *** 3575,3578 **** --- 3645,3691 ---- } } + + public BufferedImage getDesktop(){ + int width = this.getWidth(); + int height = this.getHeight(); + BufferedImage bufferedImage = new BufferedImage(width, height, + BufferedImage.TYPE_INT_RGB); + + // Create a graphics contents on the buffered image + 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(); + + return bufferedImage2; + } public void clearSaveAs() *************** *** 3934,3940 **** JOptionPane.PLAIN_MESSAGE, null, Sim.getNode(inNodeName).getActiveInterfaces() , (Sim.getNode(inNodeName).getActiveInterfaces())[0]); ! if(choice != null) ! ((DHCPC) ((core.ApplicationLayerDevice) Sim.getNode(inNodeName)) ! .getApp(68)).StartDHCPC(choice, ""); } catch (Exception e) { e.printStackTrace(); --- 4047,4057 ---- JOptionPane.PLAIN_MESSAGE, null, Sim.getNode(inNodeName).getActiveInterfaces() , (Sim.getNode(inNodeName).getActiveInterfaces())[0]); ! if(choice != null){ ! /*((DHCPC) ((core.ApplicationLayerDevice) Sim.getNode(inNodeName)) ! .getApp(68)).StartDHCPC(choice, "");*/ ! ! ((core.NetworkLayerDevice)Sim.getNode(inNodeName)).getConfig().executeCommand("interface " + choice + " ip dhcp client"); ! ((core.NetworkLayerDevice)Sim.getNode(inNodeName)).getConfig().executeCommand("write mem"); ! } } catch (Exception e) { e.printStackTrace(); Index: MenuBar.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MenuBar.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** MenuBar.java 24 Oct 2008 16:18:48 -0000 1.21 --- MenuBar.java 24 Oct 2008 18:13:48 -0000 1.22 *************** *** 49,53 **** // simulation ! private JMenuItem mnuGenRep = new JMenuItem("Export to HTML ..."); private JMenuItem mnuExit = new JMenuItem("Exit"); // Exit appliction --- 49,53 ---- // simulation ! private JMenuItem mnuGenRep = new JMenuItem("Export ..."); private JMenuItem mnuExit = new JMenuItem("Exit"); // Exit appliction *************** *** 198,202 **** mnuGenRep.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ! controller.save_html_rep(null); } }); --- 198,202 ---- mnuGenRep.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ! controller.Export(); } }); |
From: Alexander B. <da...@us...> - 2008-10-24 18:13:52
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12939/core Modified Files: CommandProcessor.java NetworkLayerDevice.java Log Message: Index: NetworkLayerDevice.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkLayerDevice.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** NetworkLayerDevice.java 24 Oct 2008 16:18:48 -0000 1.30 --- NetworkLayerDevice.java 24 Oct 2008 18:13:48 -0000 1.31 *************** *** 386,390 **** } ! public void removeARP(String inIPAddress){ NodeProtocolStack.removeARP(inIPAddress); } --- 386,390 ---- } ! public void removeARP(String inIPAddress){ NodeProtocolStack.removeARP(inIPAddress); } Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** CommandProcessor.java 24 Oct 2008 17:46:42 -0000 1.34 --- CommandProcessor.java 24 Oct 2008 18:13:48 -0000 1.35 *************** *** 3628,3632 **** Integer key = keys.nextElement(); jnSocket jnsock = device.NodeProtocolStack.SL().get_socket(key.intValue()); ! out += jnsock.dst_IP+":"+jnsock.dst_port+"\t"+telser.connections.get(key).user+"\n"; } } --- 3628,3632 ---- Integer key = keys.nextElement(); jnSocket jnsock = device.NodeProtocolStack.SL().get_socket(key.intValue()); ! out += jnsock.dst_IP+":"+jnsock.dst_port+"\t"+(telser.connections.get(key)).user+"\n"; } } |
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv10773/core Modified Files: AccessListEngine.java CommandInterface.java CommandProcessor.java CommandsTree.java DeviceConfig.java Node.java Log Message: Warnings was corrected Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** DeviceConfig.java 24 Oct 2008 16:18:48 -0000 1.25 --- DeviceConfig.java 24 Oct 2008 17:46:42 -0000 1.26 *************** *** 87,91 **** return config; } ! public String toString(int config_name){ String out = ""; --- 87,91 ---- return config; } ! public String toString(int config_name){ String out = ""; *************** *** 124,134 **** } - private void initStartupConfig(){ - clearStartupConfig(); - startup_config.add(DeviceConfig.EXEC+"COMMON"); - startup_config.add(DeviceConfig.EXEC+"INTERFACES"); - startup_config.add(DeviceConfig.EXEC+"ROUTE"); - } - public boolean writeMemory(){ boolean result = false; --- 124,127 ---- *************** *** 169,176 **** } for(int i=0; i<config.size() && !found; i++){ ! if(beforeCommand!=null && p.matcher((String)config.get(i)).find()){ index = i; } ! if(command.compareToIgnoreCase((String)config.get(i))==0){ found = true; } --- 162,169 ---- } for(int i=0; i<config.size() && !found; i++){ ! if(beforeCommand!=null && p.matcher(config.get(i)).find()){ index = i; } ! if(command.compareToIgnoreCase(config.get(i))==0){ found = true; } *************** *** 245,272 **** } - private String getCommandPart(String command, int paramc){ - String result = ""; - if(paramc>0){ - String args[] = command.split(" "); - result += args[0]; - for(int i=1; i<paramc && i<args.length; i++){ - result += " " + args[i]; - } - } - return result; - } - - private String createCommand(String command, Vector<String> params){ - for(int i=0; i<params.size(); i++){ - command += " " + params.get(i); - } - return command; - } - private LinkedList<String> prepareConfig(LinkedList<String> in, boolean fullConfig){ LinkedList<String> out = new LinkedList<String>(); Iterator<String> it = in.iterator(); while(it.hasNext()){ ! String nc = (String)it.next(); if(nc.startsWith(DeviceConfig.EXEC)){ nc = nc.substring(DeviceConfig.EXEC.length()); --- 238,246 ---- } private LinkedList<String> prepareConfig(LinkedList<String> in, boolean fullConfig){ LinkedList<String> out = new LinkedList<String>(); Iterator<String> it = in.iterator(); while(it.hasNext()){ ! String nc = it.next(); if(nc.startsWith(DeviceConfig.EXEC)){ nc = nc.substring(DeviceConfig.EXEC.length()); *************** *** 313,405 **** protected void fillConfigACLS(LinkedList<String> conf){ ! final int ERROR = 0; final int STANDART = 1; final int EXTENDED = 2; ! if(device instanceof NetworkLayerDevice){ ! Hashtable acls = device.getACL().ACLs; ! Enumeration<Integer> aclkeys = acls.keys(); ! while(aclkeys.hasMoreElements()){ ! Hashtable acl = (Hashtable)acls.get((Integer)aclkeys.nextElement()); ! Enumeration<Integer> rulekeys = acl.keys(); ! while(rulekeys.hasMoreElements()){ ! access_list rule = (access_list)acl.get((Integer)rulekeys.nextElement()); ! String type = "unsupported_acl_type"; ! int itype = 0; ! if(rule.number>=1 && rule.number<=99){ ! type = "standart"; ! itype = STANDART; ! } ! else if(rule.number>=100 && rule.number<=2699){ ! type = "extended"; ! itype = EXTENDED; ! } ! String permit_deny = "unsupported_action"; ! if(rule.action==access_list.DENY){ ! permit_deny = "deny "; ! } ! else if(rule.action==access_list.PERMIT){ ! permit_deny = "permit"; ! } ! String hosts1 = "unsupported_hosts_1"; ! if(rule.IP1.equals("0.0.0.0") && rule.SubnetMask1.equals("0.0.0.0")){ ! hosts1 = "any"; } ! else if(rule.SubnetMask1.equals("255.255.255.255")){ ! hosts1 = "host "+rule.IP1; } else{ ! hosts1 = rule.IP1+" "+rule.SubnetMask1; ! } ! ! String hosts2 = "unsupported_hosts_2"; ! if(itype==EXTENDED){ ! if(rule.IP2.equals("0.0.0.0") && rule.SubnetMask2.equals("0.0.0.0")){ ! hosts2 = "any"; ! } ! else if(rule.SubnetMask2.equals("255.255.255.255")){ ! hosts2 = "host "+rule.IP2; ! } ! else{ ! hosts2 = rule.IP2+" "+rule.SubnetMask2; ! } } ! String protocol = "unsupported_protocol"; ! if(rule.protocol==access_list.IP){ ! protocol = "ip "; ! } ! else if(rule.protocol==access_list.TCP){ ! protocol = "tcp "; ! } ! else if(rule.protocol==access_list.UDP){ ! protocol = "udp "; ! } ! else if(rule.protocol==access_list.ICMP){ ! protocol = "icmp"; ! } ! String port = "unsupported_port"; ! if(rule.Port2 == 0){ ! port = ""; ! } ! else{ ! port = "eq "+rule.Port2; ! } ! String log = ""; ! if(rule.log){ ! log = "log"; ! } ! switch(itype){ ! case STANDART: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+hosts1+" "+log); break; ! case EXTENDED: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+protocol+" "+hosts1+" "+hosts2+" "+port+" "+log); break; ! default: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+protocol+" "+hosts1+" "+hosts2+" "+rule.Port2+" "+log); ! } } } --- 287,377 ---- protected void fillConfigACLS(LinkedList<String> conf){ ! //final int ERROR = 0; final int STANDART = 1; final int EXTENDED = 2; ! Hashtable<Integer, Hashtable<Integer,access_list>> acls = device.getACL().ACLs; ! Enumeration<Integer> aclkeys = acls.keys(); ! while(aclkeys.hasMoreElements()){ ! Hashtable<Integer,access_list> acl = acls.get(aclkeys.nextElement()); ! Enumeration<Integer> rulekeys = acl.keys(); ! while(rulekeys.hasMoreElements()){ ! access_list rule = acl.get(rulekeys.nextElement()); ! String type = "unsupported_acl_type"; ! int itype = 0; ! if(rule.number>=1 && rule.number<=99){ ! type = "standart"; ! itype = STANDART; ! } ! else if(rule.number>=100 && rule.number<=2699){ ! type = "extended"; ! itype = EXTENDED; ! } ! String permit_deny = "unsupported_action"; ! if(rule.action==access_list.DENY){ ! permit_deny = "deny "; ! } ! else if(rule.action==access_list.PERMIT){ ! permit_deny = "permit"; ! } ! String hosts1 = "unsupported_hosts_1"; ! if(rule.IP1.equals("0.0.0.0") && rule.SubnetMask1.equals("0.0.0.0")){ ! hosts1 = "any"; ! } ! else if(rule.SubnetMask1.equals("255.255.255.255")){ ! hosts1 = "host "+rule.IP1; ! } ! else{ ! hosts1 = rule.IP1+" "+rule.SubnetMask1; ! } ! ! String hosts2 = "unsupported_hosts_2"; ! if(itype==EXTENDED){ ! if(rule.IP2.equals("0.0.0.0") && rule.SubnetMask2.equals("0.0.0.0")){ ! hosts2 = "any"; } ! else if(rule.SubnetMask2.equals("255.255.255.255")){ ! hosts2 = "host "+rule.IP2; } else{ ! hosts2 = rule.IP2+" "+rule.SubnetMask2; } + } ! String protocol = "unsupported_protocol"; ! if(rule.protocol==access_list.IP){ ! protocol = "ip "; ! } ! else if(rule.protocol==access_list.TCP){ ! protocol = "tcp "; ! } ! else if(rule.protocol==access_list.UDP){ ! protocol = "udp "; ! } ! else if(rule.protocol==access_list.ICMP){ ! protocol = "icmp"; ! } ! String port = "unsupported_port"; ! if(rule.Port2 == 0){ ! port = ""; ! } ! else{ ! port = "eq "+rule.Port2; ! } ! String log = ""; ! if(rule.log){ ! log = "log"; ! } ! switch(itype){ ! case STANDART: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+hosts1+" "+log); break; ! case EXTENDED: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+protocol+" "+hosts1+" "+hosts2+" "+port+" "+log); break; ! default: conf.add("ip access-list "+type+" "+rule.number+" "+permit_deny+" "+protocol+" "+hosts1+" "+hosts2+" "+rule.Port2+" "+log); } } *************** *** 408,512 **** protected void fillInterfaces(LinkedList<String> conf){ ! if(device instanceof NetworkLayerDevice){ ! Object[] ins = device.getAllInterfaces(); ! ! for(int i=0; i<ins.length; i++){ ! try { ! NetworkInterface ni = device.getNetworkInterface((String)ins[i]); ! EthernetNetworkInterface eni = null; ! SerialNetworkInterface sni = null; ! NetworkInterfacePort pni = null; ! WiFiPort wfi = null; ! try{ ! eni = (EthernetNetworkInterface) ni; ! } catch(ClassCastException e){}; ! try{ ! sni = (SerialNetworkInterface) ni; ! } catch(ClassCastException e){}; ! try{ ! pni = (NetworkInterfacePort) ni; ! } catch(ClassCastException e){}; ! try{ ! wfi = (WiFiPort) ni; ! } catch(ClassCastException e){}; ! ! String intName = (String)ins[i]; ! if(ni.getDescription()!=null && !ni.getDescription().equals("")) ! conf.add("interface "+intName+" description "+ni.getDescription()); ! if(eni!=null && !eni.getMACAddress().equalsIgnoreCase(eni.defaultMACAddress)) ! conf.add("interface "+intName+" mac-address "+eni.getMACAddress()); ! if((eni!=null || sni!=null || wfi!=null) && device.getIPAddress((String)ins[i])!=null && !device.getIPAddress((String)ins[i]).equals("") && ni.isActive()) ! conf.add("interface "+intName+" ip address "+device.getIPAddress((String)ins[i])+" "+device.getSubnetMask((String)ins[i])); ! if(sni!=null && sni.getClockRate()!=SerialNetworkInterface.DEFAULT_CLOCKRATE) ! conf.add("interface "+intName+" clock-rate "+sni.getClockRate()); ! if(wfi!=null){ ! if(wfi.getBSSID()!=null && !wfi.getBSSID().equals("")) ! conf.add("interface "+intName+" bssid "+wfi.getBSSID()); ! if(wfi.getSSID()!=null && !wfi.getSSID().equals("")) ! conf.add("interface "+intName+" ssid "+wfi.getSSID()); ! if(wfi.getChannel()==0) ! conf.add("no interface "+intName+" channel"); ! else ! conf.add("interface "+intName+" channel "+wfi.getChannel()); ! if(wfi.getMode()==WiFiPort.MODE_AP) ! conf.add("interface "+intName+" station-role root access-point"); ! else if(wfi.getMode()==WiFiPort.MODE_REPEATER) ! conf.add("interface "+intName+" station-role repeater"); ! else if(wfi.getMode()==WiFiPort.MODE_STATION) ! conf.add("interface "+intName+" station-role client"); ! conf.add("interface "+intName+" authentication "+(wfi.isSharedAuth()?"shared":"open")); ! for(int j=1; j<=4; j++){ ! if(wfi.getWEPKey(j)!=null && !wfi.getWEPKey(j).equals("")) ! conf.add("interface "+intName+" encryption key "+j+" size "+wfi.getWEPKey(j).length()*4+"bit "+wfi.getWEPKey(j)); ! } ! } ! if(pni!=null){ ! if(pni.vlan > 1){ ! conf.add("interface "+intName+" switchport access vlan "+pni.vlan); ! } ! switch(pni.mode){ ! case NetworkInterfacePort.MODE_ACCESS: break; ! case NetworkInterfacePort.MODE_TRUNK: ! conf.add("interface "+intName+" switchport mode trunk"); ! break; ! } } ! if(ni.getACLin()!=0) ! conf.add("interface "+intName+" ip access-group "+ni.getACLin()+" in"); ! if(ni.getACLout()!=0) ! conf.add("interface "+intName+" ip access-group "+ni.getACLout()+" out"); ! switch(ni.getNAT()){ ! case NetworkInterface.NO_NAT: break; ! case NetworkInterface.INSIDE_NAT: conf.add("interface "+intName+" ip nat inside"); break; ! case NetworkInterface.OUTSIDE_NAT: conf.add("interface "+intName+" ip nat outside"); break; } ! if(!ni.unreachables) ! conf.add("no interface "+intName+" ip unreachables"); ! if(!ni.redirects) ! conf.add("no interface "+intName+" ip redirects"); ! if(!ni.maskReplay) ! conf.add("no interface "+intName+" ip mask-replay"); ! if(!ni.informationReplay) ! conf.add("no interface "+intName+" ip information-replay"); ! ! if(ni.isUP()){ ! if(ni.isActive()){ ! conf.add("no interface "+intName+" shutdown"); ! } } ! else{ ! conf.add("interface "+intName+" shutdown"); } ! ! if(device instanceof ApplicationLayerDevice){ ! DHCPC dhcpc = (DHCPC)((ApplicationLayerDevice)device).getApp(PC.DHCP_CLIENT_ID); ! if(dhcpc!=null && dhcpc.running && dhcpc.getInterface().equalsIgnoreCase(intName)){ ! conf.add("interface "+intName+" ip dhcp client"); ! } } - } catch (InvalidNetworkInterfaceNameException ex) { - System.out.println("Internal error: "+ex.getMessage()); - ex.printStackTrace(); } } } --- 380,482 ---- protected void fillInterfaces(LinkedList<String> conf){ ! Object[] ins = device.getAllInterfaces(); ! ! for(int i=0; i<ins.length; i++){ ! try { ! NetworkInterface ni = device.getNetworkInterface((String)ins[i]); ! EthernetNetworkInterface eni = null; ! SerialNetworkInterface sni = null; ! NetworkInterfacePort pni = null; ! WiFiPort wfi = null; ! try{ ! eni = (EthernetNetworkInterface) ni; ! } catch(ClassCastException e){}; ! try{ ! sni = (SerialNetworkInterface) ni; ! } catch(ClassCastException e){}; ! try{ ! pni = (NetworkInterfacePort) ni; ! } catch(ClassCastException e){}; ! try{ ! wfi = (WiFiPort) ni; ! } catch(ClassCastException e){}; ! ! String intName = (String)ins[i]; ! if(ni.getDescription()!=null && !ni.getDescription().equals("")) ! conf.add("interface "+intName+" description "+ni.getDescription()); ! if(eni!=null && !eni.getMACAddress().equalsIgnoreCase(eni.defaultMACAddress)) ! conf.add("interface "+intName+" mac-address "+eni.getMACAddress()); ! if((eni!=null || sni!=null || wfi!=null) && device.getIPAddress((String)ins[i])!=null && !device.getIPAddress((String)ins[i]).equals("") && ni.isActive()) ! conf.add("interface "+intName+" ip address "+device.getIPAddress((String)ins[i])+" "+device.getSubnetMask((String)ins[i])); ! if(sni!=null && sni.getClockRate()!=SerialNetworkInterface.DEFAULT_CLOCKRATE) ! conf.add("interface "+intName+" clock-rate "+sni.getClockRate()); ! if(wfi!=null){ ! if(wfi.getBSSID()!=null && !wfi.getBSSID().equals("")) ! conf.add("interface "+intName+" bssid "+wfi.getBSSID()); ! if(wfi.getSSID()!=null && !wfi.getSSID().equals("")) ! conf.add("interface "+intName+" ssid "+wfi.getSSID()); ! if(wfi.getChannel()==0) ! conf.add("no interface "+intName+" channel"); ! else ! conf.add("interface "+intName+" channel "+wfi.getChannel()); ! if(wfi.getMode()==WiFiPort.MODE_AP) ! conf.add("interface "+intName+" station-role root access-point"); ! else if(wfi.getMode()==WiFiPort.MODE_REPEATER) ! conf.add("interface "+intName+" station-role repeater"); ! else if(wfi.getMode()==WiFiPort.MODE_STATION) ! conf.add("interface "+intName+" station-role client"); ! conf.add("interface "+intName+" authentication "+(wfi.isSharedAuth()?"shared":"open")); ! for(int j=1; j<=4; j++){ ! if(wfi.getWEPKey(j)!=null && !wfi.getWEPKey(j).equals("")) ! conf.add("interface "+intName+" encryption key "+j+" size "+wfi.getWEPKey(j).length()*4+"bit "+wfi.getWEPKey(j)); } ! } ! if(pni!=null){ ! if(pni.vlan > 1){ ! conf.add("interface "+intName+" switchport access vlan "+pni.vlan); } ! switch(pni.mode){ ! case NetworkInterfacePort.MODE_ACCESS: break; ! case NetworkInterfacePort.MODE_TRUNK: ! conf.add("interface "+intName+" switchport mode trunk"); ! break; } ! } ! if(ni.getACLin()!=0) ! conf.add("interface "+intName+" ip access-group "+ni.getACLin()+" in"); ! if(ni.getACLout()!=0) ! conf.add("interface "+intName+" ip access-group "+ni.getACLout()+" out"); ! switch(ni.getNAT()){ ! case NetworkInterface.NO_NAT: break; ! case NetworkInterface.INSIDE_NAT: conf.add("interface "+intName+" ip nat inside"); break; ! case NetworkInterface.OUTSIDE_NAT: conf.add("interface "+intName+" ip nat outside"); break; ! } ! if(!ni.unreachables) ! conf.add("no interface "+intName+" ip unreachables"); ! if(!ni.redirects) ! conf.add("no interface "+intName+" ip redirects"); ! if(!ni.maskReplay) ! conf.add("no interface "+intName+" ip mask-replay"); ! if(!ni.informationReplay) ! conf.add("no interface "+intName+" ip information-replay"); ! ! if(ni.isUP()){ ! if(ni.isActive()){ ! conf.add("no interface "+intName+" shutdown"); } ! } ! else{ ! conf.add("interface "+intName+" shutdown"); ! } ! ! if(device instanceof ApplicationLayerDevice){ ! DHCPC dhcpc = (DHCPC)((ApplicationLayerDevice)device).getApp(PC.DHCP_CLIENT_ID); ! if(dhcpc!=null && dhcpc.running && dhcpc.getInterface().equalsIgnoreCase(intName)){ ! conf.add("interface "+intName+" ip dhcp client"); } } + } catch (InvalidNetworkInterfaceNameException ex) { + System.out.println("Internal error: "+ex.getMessage()); + ex.printStackTrace(); } } *************** *** 514,525 **** protected void fillARP(LinkedList<String> conf){ ! if(device instanceof NetworkLayerDevice){ ! Vector<Vector<String>> ArpTable = device.getARPTable(); ! if(ArpTable.size()>0){ ! for(int i=0;i<ArpTable.size();i++) ! { ! if(ArpTable.get(i).get(2).compareTo("Static")==0) ! conf.add("arp "+ArpTable.get(i).get(0)+" "+ArpTable.get(i).get(1)); ! } } } --- 484,493 ---- protected void fillARP(LinkedList<String> conf){ ! Vector<Vector<String>> ArpTable = device.getARPTable(); ! if(ArpTable.size()>0){ ! for(int i=0;i<ArpTable.size();i++) ! { ! if(ArpTable.get(i).get(2).compareTo("Static")==0) ! conf.add("arp "+ArpTable.get(i).get(0)+" "+ArpTable.get(i).get(1)); } } *************** *** 531,577 **** conf.add("location "+device.location); } ! protected void fillIP(LinkedList<String> conf){ ! if(device instanceof NetworkLayerDevice){ ! NetworkLayerDevice ndev = (NetworkLayerDevice)device; ! NATEngine nat = ndev.getNAT(); ! for(int dyn=0; dyn<2; dyn++){ ! for(int i=0; i<nat.countRules(dyn==1); i++){ ! String params; ! NAT_rule rule = nat.getRule(i,dyn==1); // dyn==0 -- static_rules, dyn==1 -- dynamic_rules ! if(rule.dynamic){ ! params = " list "+rule.acl; ! params += (rule.pool?" pool ":" interface ")+rule.out_int+" overload"; ! } ! else{ ! params = " static"; ! switch(rule.protocol){ ! case NAT_rule.IP: params+=" ip"; break; ! case NAT_rule.ICMP: params+=" icmp"; break; ! case NAT_rule.UDP: params+=" udp"; break; ! case NAT_rule.TCP: params+=" tcp"; break; ! } ! params += " "+rule.in_ip; ! if(rule.in_port>0) params += " "+rule.in_port; ! params += " "+rule.out_ip; ! if(rule.out_port>0) params += " "+rule.out_port; } ! conf.add("ip nat inside source"+params); } } ! Enumeration<String> pools = nat.getPools(); ! while(pools.hasMoreElements()){ ! String name = pools.nextElement(); ! Pair pool = nat.getPool(name); ! conf.add("ip nat pool "+name+" "+(String)pool.getFirst()+" "+(String)pool.getSecond()); ! } } if(device instanceof ApplicationLayerDevice){ DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ ! Enumeration<String> pools = dhcpd.pools.keys(); ! while(pools.hasMoreElements()){ ! String poolname = pools.nextElement(); ! DHCPD.pool pool = (DHCPD.pool) dhcpd.pools.get(poolname); if(pool.Gateway!="") conf.add("ip dhcp pool "+poolname+" default-router "+pool.Gateway); --- 499,542 ---- conf.add("location "+device.location); } ! protected void fillIP(LinkedList<String> conf){ ! NATEngine nat = device.getNAT(); ! for(int dyn=0; dyn<2; dyn++){ ! for(int i=0; i<nat.countRules(dyn==1); i++){ ! String params; ! NAT_rule rule = nat.getRule(i,dyn==1); // dyn==0 -- static_rules, dyn==1 -- dynamic_rules ! if(rule.dynamic){ ! params = " list "+rule.acl; ! params += (rule.pool?" pool ":" interface ")+rule.out_int+" overload"; ! } ! else{ ! params = " static"; ! switch(rule.protocol){ ! case NAT_rule.IP: params+=" ip"; break; ! case NAT_rule.ICMP: params+=" icmp"; break; ! case NAT_rule.UDP: params+=" udp"; break; ! case NAT_rule.TCP: params+=" tcp"; break; } ! params += " "+rule.in_ip; ! if(rule.in_port>0) params += " "+rule.in_port; ! params += " "+rule.out_ip; ! if(rule.out_port>0) params += " "+rule.out_port; } + conf.add("ip nat inside source"+params); } ! } ! Enumeration<String> natpools = nat.getPools(); ! while(natpools.hasMoreElements()){ ! String name = natpools.nextElement(); ! Pair pool = nat.getPool(name); ! conf.add("ip nat pool "+name+" "+(String)pool.getFirst()+" "+(String)pool.getSecond()); } if(device instanceof ApplicationLayerDevice){ DHCPD dhcpd = (DHCPD)((ApplicationLayerDevice)device).getApp(PC.DHCP_SERVER_ID); if(dhcpd!=null){ ! Enumeration<String> dhcppools = dhcpd.pools.keys(); ! while(dhcppools.hasMoreElements()){ ! String poolname = dhcppools.nextElement(); ! DHCPD.pool pool = dhcpd.pools.get(poolname); if(pool.Gateway!="") conf.add("ip dhcp pool "+poolname+" default-router "+pool.Gateway); *************** *** 635,639 **** else conf.add("no router rip"); } ! //DNS DNS dns = (DNS) appdevice.getApp(core.ApplicationLayerDevice.DNS_SERVER_ID); --- 600,604 ---- else conf.add("no router rip"); } ! //DNS DNS dns = (DNS) appdevice.getApp(core.ApplicationLayerDevice.DNS_SERVER_ID); *************** *** 692,701 **** protected void fillRoute(LinkedList<String> conf){ ! if(device instanceof NetworkLayerDevice){ ! String routes[] = device.getRouteTableEntries(); ! for(int i=0; i<routes.length - 1; i++){ ! Route_entry r = device.getRouteTableEntry(routes[i]); ! conf.add("ip route "+routes[i]+" "+r.genMask+" "+r.gateway+" "+r.iFace); ! } } } --- 657,664 ---- protected void fillRoute(LinkedList<String> conf){ ! String routes[] = device.getRouteTableEntries(); ! for(int i=0; i<routes.length - 1; i++){ ! Route_entry r = device.getRouteTableEntry(routes[i]); ! conf.add("ip route "+routes[i]+" "+r.genMask+" "+r.gateway+" "+r.iFace); } } Index: CommandsTree.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandsTree.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CommandsTree.java 24 Oct 2008 16:18:48 -0000 1.8 --- CommandsTree.java 24 Oct 2008 17:46:42 -0000 1.9 *************** *** 26,33 **** CommandNode root = new CommandNode("."); ! private class CommandNode implements Comparable{ private String name; ! private LinkedList tree; private CommandInterface function; public Modes modes; --- 26,33 ---- CommandNode root = new CommandNode("."); ! private class CommandNode implements Comparable<CommandNode>{ private String name; ! private LinkedList<CommandNode> tree; private CommandInterface function; public Modes modes; *************** *** 70,74 **** CommandNode anywordNode = null; for(int i=0; i<tree.size() && !allFounds; i++){ ! CommandNode node = (CommandNode)tree.get(i); String nodename = node.getName(); if(!nodename.equals(CommandsTree.ANYWORD)){ --- 70,74 ---- CommandNode anywordNode = null; for(int i=0; i<tree.size() && !allFounds; i++){ ! CommandNode node = tree.get(i); String nodename = node.getName(); if(!nodename.equals(CommandsTree.ANYWORD)){ *************** *** 76,80 **** int cmp = command.compareToIgnoreCase(nodename); if(cmp == 0 && node.modes.isContain(mode)){ ! nodes.add((CommandNode)tree.get(i)); } else if(cmp < 0){ --- 76,80 ---- int cmp = command.compareToIgnoreCase(nodename); if(cmp == 0 && node.modes.isContain(mode)){ ! nodes.add(tree.get(i)); } else if(cmp < 0){ *************** *** 83,87 **** } else{ ! anywordNode = (CommandNode)tree.get(i);; } } --- 83,87 ---- } else{ ! anywordNode = tree.get(i);; } } *************** *** 131,135 **** if(tree == null){ ! tree = new LinkedList(); } boolean Found = false; --- 131,135 ---- if(tree == null){ ! tree = new LinkedList<CommandNode>(); } boolean Found = false; *************** *** 168,173 **** // } ! public int compareTo(Object o){ ! return (name.compareToIgnoreCase(((CommandNode)o).name)); } } --- 168,173 ---- // } ! public int compareTo(CommandNode o){ ! return (name.compareToIgnoreCase(o.name)); } } *************** *** 281,285 **** CommandInterface func = null; Modes modes = new Modes(0,0,0); - String params = ""; Vector<String> vprms = new Vector<String>(0); --- 281,284 ---- *************** *** 294,308 **** func = node.getFunction(); modes = node.modes; - if(func!=null){ - if(cmds[0].equalsIgnoreCase("no")){ - params = node.getFunction().no_call_params; - } - else{ - params = node.getFunction().call_params; - } - } - else{ - params = ""; - } } } --- 293,296 ---- Index: CommandInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandInterface.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CommandInterface.java 24 Oct 2008 16:18:48 -0000 1.3 --- CommandInterface.java 24 Oct 2008 17:46:42 -0000 1.4 *************** *** 75,79 **** abstract public String call(Vector<String> params); ! public String no_call(Vector<String> params){ return "Function not implemented!!!"; } --- 75,79 ---- abstract public String call(Vector<String> params); ! public String no_call(@SuppressWarnings("unused") Vector<String> params){ return "Function not implemented!!!"; } Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** CommandProcessor.java 24 Oct 2008 16:18:48 -0000 1.33 --- CommandProcessor.java 24 Oct 2008 17:46:42 -0000 1.34 *************** *** 50,54 **** private CommandsTree commands = new CommandsTree(); ! private NoCommandClass noCommand = new NoCommandClass(); private arp_CommandClass arp_Command = new arp_CommandClass(); private clear_arp_CommandClass clear_arp_Command = new clear_arp_CommandClass(); --- 50,54 ---- private CommandsTree commands = new CommandsTree(); ! //private NoCommandClass noCommand = new NoCommandClass(); private arp_CommandClass arp_Command = new arp_CommandClass(); [...1041 lines suppressed...] } else{ ! if(name.equals("")){ ! device.removeVlan(vlanid); } ! else if(device.getVlanName(vlanid).equals(name)){ ! device.removeVlan(vlanid); } } } } ! catch(NumberFormatException e){ ! out += "error: invalid vlan number\n"; } + } else{ ! out += "error: invalid parameters\n"; } return out; Index: Node.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Node.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Node.java 24 Oct 2008 16:18:48 -0000 1.30 --- Node.java 24 Oct 2008 17:46:42 -0000 1.31 *************** *** 823,837 **** ! public ArrayList getAllInterfacesNames(){ ! ArrayList interfaceArray = new ArrayList(); ! Enumeration keys = NetworkInterfacetable.keys(); while(keys.hasMoreElements()){ ! String strInterfaceName = (String) keys.nextElement(); interfaceArray.add(strInterfaceName); --- 823,837 ---- ! public ArrayList<String> getAllInterfacesNames(){ ! ArrayList<String> interfaceArray = new ArrayList<String>(); ! Enumeration<String> keys = NetworkInterfacetable.keys(); while(keys.hasMoreElements()){ ! String strInterfaceName = keys.nextElement(); interfaceArray.add(strInterfaceName); Index: AccessListEngine.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/AccessListEngine.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AccessListEngine.java 24 Oct 2008 16:18:48 -0000 1.6 --- AccessListEngine.java 24 Oct 2008 17:46:42 -0000 1.7 *************** *** 15,270 **** */ public class AccessListEngine { ! public class access_list{ ! public final static int PERMIT = 1; ! public final static int DENY = 2; ! public final static int REMARK = 0; ! ! public final static int IP = 0; ! public final static int ICMP = 1; ! public final static int UDP = 2; ! public final static int TCP = 3; ! ! public int number = 0; ! public int line = 0; ! public short action = -1; ! public int protocol = -1; ! public boolean log = false; ! ! public String IP1 = null; ! public String SubnetMask1 = null; ! public int Port1 = 0; ! ! public String IP2 = null; ! public String SubnetMask2 = null; ! public int Port2 = 0; ! } ! ! Node parentNode; ! ! Hashtable ACLs = new Hashtable(); ! ! public AccessListEngine(Node inParentNode){ ! parentNode = inParentNode; ! } ! ! public int addACL(int number, int line, short action, String IP1, String SubnetMask1, boolean log){ ! return addACL(number, line, action, -1, IP1, SubnetMask1, null, null, 0, log); ! } ! ! public int addACL(int number, int line, short action, int protocol, String IP1, String SubnetMask1, String IP2, String SubnetMask2, int port, boolean log){ ! Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); ! boolean new_acl = false; ! ! if(ACLl == null){ ! ACLl = new Hashtable(); ! new_acl = true; ! } ! ! if(ACLl.get(Integer.valueOf(line)) != null) return -1; ! ! if(line < 0){ ! line = 0; ! Integer temp; ! Enumeration e = ACLl.keys(); ! while(e.hasMoreElements()){ ! temp = (Integer)e.nextElement(); ! if(line < Integer.valueOf(temp)){ ! line = Integer.valueOf(temp); ! } ! } ! line += 10; ! } ! ! access_list al = new access_list(); ! al.number = number; ! al.line = line; ! al.action = action; ! al.protocol = protocol; ! al.IP1 = IP1; ! al.SubnetMask1 = SubnetMask1; ! al.IP2 = IP2; ! al.SubnetMask2 = SubnetMask2; ! al.Port2 = port; ! al.log = log; ! ! ACLl.put(Integer.valueOf(line), al); ! ! if(new_acl) ACLs.put(Integer.valueOf(number), ACLl); ! ! return line; ! } ! ! public boolean removeACL(int number, int line){ ! Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); ! ! if(ACLl == null) return false; ! ! if(ACLl.get(Integer.valueOf(line)) == null) return false; ! ! ACLl.remove(Integer.valueOf(line)); ! ! if(ACLl.size() < 1) ACLs.remove(Integer.valueOf(number)); ! ! return true; ! } ! ! public boolean removeACL(int number, int action, String IP1, String SubnetMask1){ ! Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); ! boolean found = false; ! ! if(ACLl == null) return false; ! access_list temp_acl = null; ! Enumeration e = ACLl.keys(); ! while(e.hasMoreElements()){ ! temp_acl = (access_list)ACLl.get(e.nextElement()); ! if(temp_acl.action == action && ! temp_acl.IP1.equals(IP1) && ! temp_acl.SubnetMask1.equals(SubnetMask1)){ ! found = true; ! break; ! } ! } ! ! if(found) ACLl.remove(Integer.valueOf(temp_acl.line)); ! ! if(ACLl.size() < 1) ACLs.remove(Integer.valueOf(number)); ! ! return found; ! } ! ! public boolean removeACL(int number, int action, int protocol, String IP1, String SubnetMask1, String IP2, String SubnetMask2, int port){ ! Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); ! boolean found = false; ! ! if(ACLl == null) return false; ! access_list temp_acl = null; ! Enumeration e = ACLl.keys(); ! while(e.hasMoreElements()){ ! temp_acl = (access_list)ACLl.get(e.nextElement()); ! if(temp_acl.action == action && ! (protocol==-1 || temp_acl.protocol == protocol) && ! temp_acl.IP1.equals(IP1) && ! temp_acl.SubnetMask1.equals(SubnetMask1) && ! (IP2==null || temp_acl.IP2.equals(IP2)) && ! (SubnetMask2==null || SubnetMask2.equals(temp_acl.SubnetMask2)) && ! (port==0 || temp_acl.Port2 == port) ! ){ ! found = true; ! break; ! } ! } ! ! if(found) ACLl.remove(Integer.valueOf(temp_acl.line)); ! ! if(ACLl.size() < 1) ACLs.remove(Integer.valueOf(number)); ! ! return found; ! } ! ! public boolean isACLExists(int number, int line){ ! Hashtable acllist = (Hashtable)ACLs.get(new Integer(number)); ! if(acllist==null) return false; ! return (acllist.containsKey(new Integer(line))); ! } ! public boolean passACL(int number, Packet packet){ ! Hashtable ACLl = (Hashtable)ACLs.get(Integer.valueOf(number)); ! ! if(ACLl == null) return true; ! ! try{ ! int port1 = 0; ! int port2 = 0; ! int protocol = -1; ! String IP1 = null; ! String IP2 = null; ! if(packet instanceof IP_packet){ ! IP_packet ippacket = (IP_packet) packet; ! IP1 = ippacket.getSourceIPAddress(); ! IP2 = ippacket.getDestIPAddress(); ! protocol = access_list.IP; ! if(ippacket instanceof TCP_packet){ ! protocol = AccessListEngine.access_list.TCP; ! port1 = ((TCP_packet)ippacket).get_srcPort(); ! port2 = ((TCP_packet)ippacket).get_destPort(); ! } ! else if(ippacket instanceof UDP_packet){ ! protocol = AccessListEngine.access_list.UDP; ! port1 = ((UDP_packet)ippacket).get_srcPort(); ! port2 = ((UDP_packet)ippacket).get_destPort(); ! } ! else if(ippacket instanceof ICMP_packet){ ! protocol = AccessListEngine.access_list.ICMP; ! } ! String binIP1 = IPV4Address.toBinaryString(IP1); ! String binNetwork1 = ""; ! String binMask1 = ""; ! String binIP2 = null; ! if(IP2!=null){ ! binIP2 = IPV4Address.toBinaryString(IP2); ! } ! String binNetwork2 = null; ! String binMask2 = null; ! access_list temp_acl = null; ! Enumeration e = ACLl.keys(); ! while(e.hasMoreElements()){ ! temp_acl = (access_list)ACLl.get(e.nextElement()); ! if(temp_acl.action>0){ ! binNetwork1 = IPV4Address.toBinaryString(temp_acl.IP1); ! binMask1 = IPV4Address.toBinaryString(temp_acl.SubnetMask1); ! if(temp_acl.IP2!=null && temp_acl.SubnetMask2!=null){ ! binNetwork2 = IPV4Address.toBinaryString(temp_acl.IP2); ! binMask2 = IPV4Address.toBinaryString(temp_acl.SubnetMask2); ! } ! if((temp_acl.protocol==-1 || temp_acl.protocol==access_list.IP || temp_acl.protocol==protocol) && ! IPV4Address.IPandMask(binNetwork1, binMask1).equals(IPV4Address.IPandMask(binIP1,binMask1)) && ! (binNetwork2==null || (binIP2!=null || IPV4Address.IPandMask(binNetwork2, binMask2).equals(IPV4Address.IPandMask(binIP2,binMask2)))) && ! (temp_acl.Port2 == 0 || temp_acl.Port2 == port2) ! ){ ! if(temp_acl.log){ ! String src = IP1; ! String dst = IP2; ! if(port1>0 && port2>0){ ! src += ":"+port1; ! dst += ":"+port2; ! } ! if(temp_acl.action == access_list.PERMIT){ ! printLayerInfo("Packet from "+src+" to "+dst+" permited"); ! } ! else{ ! printLayerInfo("Packet from "+src+" to "+dst+" denied"); ! } ! } ! if(temp_acl.action == access_list.PERMIT) return true; ! else return false; ! } ! } ! } ! } ! }catch(Exception ex){ ! ex.printStackTrace(); ! } ! ! return false; ! } ! ! public void clear(){ ! ACLs.clear(); ! ! } ! ! protected void printLayerInfo(String s) { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(parentNode.getName()); ! protInfo.setDataType("ACL rule"); ! protInfo.setLayer("ACL"); ! protInfo.setDescription(s); ! Simulation.addLayerInfo(protInfo); ! } } --- 15,271 ---- */ public class AccessListEngine { ! public class access_list{ ! public final static int PERMIT = 1; ! public final static int DENY = 2; ! public final static int REMARK = 0; ! public final static int IP = 0; ! public final static int ICMP = 1; ! public final static int UDP = 2; ! public final static int TCP = 3; ! public int number = 0; ! public int line = 0; ! public short action = -1; ! public int protocol = -1; ! public boolean log = false; ! public String IP1 = null; ! public String SubnetMask1 = null; ! public int Port1 = 0; ! public String IP2 = null; ! public String SubnetMask2 = null; ! public int Port2 = 0; ! } ! Node parentNode; ! Hashtable<Integer, Hashtable<Integer,access_list>> ACLs = new Hashtable<Integer, Hashtable<Integer,access_list>>(); ! public AccessListEngine(Node inParentNode){ ! parentNode = inParentNode; ! } ! ! public int addACL(int number, int line, short action, String IP1, String SubnetMask1, boolean log){ ! return addACL(number, line, action, -1, IP1, SubnetMask1, null, null, 0, log); ! } ! ! public int addACL(int number, int line, short action, int protocol, String IP1, String SubnetMask1, String IP2, String SubnetMask2, int port, boolean log){ ! int new_line = line; ! Hashtable<Integer,access_list> ACLl = ACLs.get(Integer.valueOf(number)); ! boolean new_acl = false; ! ! if(ACLl == null){ ! ACLl = new Hashtable<Integer,access_list>(); ! new_acl = true; ! } ! ! if(ACLl.get(Integer.valueOf(new_line)) != null) return -1; ! ! if(new_line < 0){ ! new_line = 0; ! Integer temp; ! Enumeration<Integer> e = ACLl.keys(); ! while(e.hasMoreElements()){ ! temp = e.nextElement(); ! if(new_line < Integer.valueOf(temp)){ ! new_line = Integer.valueOf(temp); ! } ! } ! new_line += 10; ! } ! ! access_list al = new access_list(); ! al.number = number; ! al.line = new_line; ! al.action = action; ! al.protocol = protocol; ! al.IP1 = IP1; ! al.SubnetMask1 = SubnetMask1; ! al.IP2 = IP2; ! al.SubnetMask2 = SubnetMask2; ! al.Port2 = port; ! al.log = log; ! ! ACLl.put(Integer.valueOf(new_line), al); ! ! if(new_acl) ACLs.put(Integer.valueOf(number), ACLl); ! ! return new_line; ! } ! ! public boolean removeACL(int number, int line){ ! Hashtable<Integer,access_list> ACLl = ACLs.get(Integer.valueOf(number)); ! ! if(ACLl == null) return false; ! ! if(ACLl.get(Integer.valueOf(line)) == null) return false; ! ! ACLl.remove(Integer.valueOf(line)); ! ! if(ACLl.size() < 1) ACLs.remove(Integer.valueOf(number)); ! ! return true; ! } ! ! public boolean removeACL(int number, int action, String IP1, String SubnetMask1){ ! Hashtable<Integer,access_list> ACLl = ACLs.get(Integer.valueOf(number)); ! boolean found = false; ! ! if(ACLl == null) return false; ! ! access_list temp_acl = null; ! Enumeration<Integer> e = ACLl.keys(); ! while(e.hasMoreElements()){ ! temp_acl = ACLl.get(e.nextElement()); ! if(temp_acl.action == action && ! temp_acl.IP1.equals(IP1) && ! temp_acl.SubnetMask1.equals(SubnetMask1)){ ! found = true; ! break; ! } ! } ! ! if(found) ACLl.remove(Integer.valueOf(temp_acl.line)); ! ! if(ACLl.size() < 1) ACLs.remove(Integer.valueOf(number)); ! ! return found; ! } ! ! public boolean removeACL(int number, int action, int protocol, String IP1, String SubnetMask1, String IP2, String SubnetMask2, int port){ ! Hashtable<Integer,access_list> ACLl = ACLs.get(Integer.valueOf(number)); ! boolean found = false; ! ! if(ACLl == null) return false; ! ! access_list temp_acl = null; ! Enumeration<Integer> e = ACLl.keys(); ! while(e.hasMoreElements()){ ! temp_acl = ACLl.get(e.nextElement()); ! if(temp_acl.action == action && ! (protocol==-1 || temp_acl.protocol == protocol) && ! temp_acl.IP1.equals(IP1) && ! temp_acl.SubnetMask1.equals(SubnetMask1) && ! (IP2==null || temp_acl.IP2.equals(IP2)) && ! (SubnetMask2==null || SubnetMask2.equals(temp_acl.SubnetMask2)) && ! (port==0 || temp_acl.Port2 == port) ! ){ ! found = true; ! break; ! } ! } ! ! if(found) ACLl.remove(Integer.valueOf(temp_acl.line)); ! ! if(ACLl.size() < 1) ACLs.remove(Integer.valueOf(number)); ! ! return found; ! } ! ! public boolean isACLExists(int number, int line){ ! Hashtable<Integer,access_list> acllist = ACLs.get(new Integer(number)); ! if(acllist==null) return false; ! return (acllist.containsKey(new Integer(line))); ! } ! ! public boolean passACL(int number, Packet packet){ ! Hashtable<Integer,access_list> ACLl = ACLs.get(Integer.valueOf(number)); ! ! if(ACLl == null) return true; ! ! try{ ! int port1 = 0; ! int port2 = 0; ! int protocol = -1; ! String IP1 = null; ! String IP2 = null; ! if(packet instanceof IP_packet){ ! IP_packet ippacket = (IP_packet) packet; ! IP1 = ippacket.getSourceIPAddress(); ! IP2 = ippacket.getDestIPAddress(); ! protocol = access_list.IP; ! if(ippacket instanceof TCP_packet){ ! protocol = AccessListEngine.access_list.TCP; ! port1 = ((TCP_packet)ippacket).get_srcPort(); ! port2 = ((TCP_packet)ippacket).get_destPort(); ! } ! else if(ippacket instanceof UDP_packet){ ! protocol = AccessListEngine.access_list.UDP; ! port1 = ((UDP_packet)ippacket).get_srcPort(); ! port2 = ((UDP_packet)ippacket).get_destPort(); ! } ! else if(ippacket instanceof ICMP_packet){ ! protocol = AccessListEngine.access_list.ICMP; ! } ! String binIP1 = IPV4Address.toBinaryString(IP1); ! String binNetwork1 = ""; ! String binMask1 = ""; ! ! String binIP2 = null; ! if(IP2!=null){ ! binIP2 = IPV4Address.toBinaryString(IP2); ! } ! String binNetwork2 = null; ! String binMask2 = null; ! ! access_list temp_acl = null; ! Enumeration<Integer> e = ACLl.keys(); ! while(e.hasMoreElements()){ ! temp_acl = ACLl.get(e.nextElement()); ! ! if(temp_acl.action>0){ ! binNetwork1 = IPV4Address.toBinaryString(temp_acl.IP1); ! binMask1 = IPV4Address.toBinaryString(temp_acl.SubnetMask1); ! if(temp_acl.IP2!=null && temp_acl.SubnetMask2!=null){ ! binNetwork2 = IPV4Address.toBinaryString(temp_acl.IP2); ! binMask2 = IPV4Address.toBinaryString(temp_acl.SubnetMask2); ! } ! ! if((temp_acl.protocol==-1 || temp_acl.protocol==access_list.IP || temp_acl.protocol==protocol) && ! IPV4Address.IPandMask(binNetwork1, binMask1).equals(IPV4Address.IPandMask(binIP1,binMask1)) && ! (binNetwork2==null || (binIP2!=null || IPV4Address.IPandMask(binNetwork2, binMask2).equals(IPV4Address.IPandMask(binIP2,binMask2)))) && ! (temp_acl.Port2 == 0 || temp_acl.Port2 == port2) ! ){ ! if(temp_acl.log){ ! String src = IP1; ! String dst = IP2; ! if(port1>0 && port2>0){ ! src += ":"+port1; ! dst += ":"+port2; ! } ! if(temp_acl.action == access_list.PERMIT){ ! printLayerInfo("Packet from "+src+" to "+dst+" permited"); ! } ! else{ ! printLayerInfo("Packet from "+src+" to "+dst+" denied"); ! } ! } ! if(temp_acl.action == access_list.PERMIT) return true; ! else return false; ! } ! } ! } ! } ! }catch(Exception ex){ ! ex.printStackTrace(); ! } ! ! return false; ! } ! ! public void clear(){ ! ACLs.clear(); ! ! } ! ! protected void printLayerInfo(String s) { ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(parentNode.getName()); ! protInfo.setDataType("ACL rule"); ! protInfo.setLayer("ACL"); ! protInfo.setDescription(s); ! Simulation.addLayerInfo(protInfo); ! } } |