[Javanetsim-cvs] javaNetSim/core AccessListEngine.java, 1.6, 1.7 CommandInterface.java, 1.3, 1.4 Co
Status: Beta
Brought to you by:
darkkey
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); ! } } |