Thread: [Javanetsim-cvs] javaNetSim/core CommandProcessor.java, 1.23, 1.24 DeviceConfig.java, 1.19, 1.20 NA
Status: Beta
Brought to you by:
darkkey
|
From: QweR <qw...@us...> - 2008-10-13 19:37:05
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31542/core Modified Files: CommandProcessor.java DeviceConfig.java NATEngine.java Log Message: NAT refashioned Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** CommandProcessor.java 12 Oct 2008 21:45:47 -0000 1.23 --- CommandProcessor.java 13 Oct 2008 19:36:35 -0000 1.24 *************** *** 33,36 **** --- 33,37 ---- import core.CommandInterface.Modes; import core.NATEngine.NAT_rule; + import core.NATEngine.NAT_session; import core.WiFiPort.APClient; import core.AccessListEngine.access_list; *************** *** 101,105 **** private show_ip_CommandClass show_ip_Command = new show_ip_CommandClass(); private show_ip_route_CommandClass show_ip_route_Command = new show_ip_route_CommandClass(); ! private show_ip_nat_translation_CommandClass show_ip_nat_translation_Command = new show_ip_nat_translation_CommandClass(); private show_kron_CommandClass show_kron_Command = new show_kron_CommandClass(); private show_location_CommandClass show_location_Command = new show_location_CommandClass(); --- 102,106 ---- private show_ip_CommandClass show_ip_Command = new show_ip_CommandClass(); private show_ip_route_CommandClass show_ip_route_Command = new show_ip_route_CommandClass(); ! private show_ip_nat_translations_CommandClass show_ip_nat_translations_Command = new show_ip_nat_translations_CommandClass(); private show_kron_CommandClass show_kron_Command = new show_kron_CommandClass(); private show_location_CommandClass show_location_Command = new show_location_CommandClass(); *************** *** 217,221 **** commands.add("show ip route", show_ip_route_Command, "Print route table"); commands.addDescription("show ip nat","IP NAT information"); ! commands.add("show ip nat translation", show_ip_nat_translation_Command, "Translation entries"); commands.add("show kron", show_kron_Command, "Kron Subsystem"); commands.add("show location", show_location_Command, "Display the system location"); --- 218,222 ---- commands.add("show ip route", show_ip_route_Command, "Print route table"); commands.addDescription("show ip nat","IP NAT information"); ! commands.add("show ip nat translations", show_ip_nat_translations_Command, "Translation entries"); commands.add("show kron", show_kron_Command, "Kron Subsystem"); commands.add("show location", show_location_Command, "Display the system location"); *************** *** 2089,2093 **** if(overload){ NAT_rule rule = device.getNAT().new NAT_rule(); ! rule.dynamic = false; rule.pool = true; rule.acl = iacl; --- 2090,2094 ---- if(overload){ NAT_rule rule = device.getNAT().new NAT_rule(); ! rule.dynamic = true; rule.pool = true; rule.acl = iacl; *************** *** 2100,2106 **** } else{ ! Vector<Integer> finds = device.getNAT().findRules(false, true, iacl, "", 0, "", 0, poolname); if(finds.size()>0){ ! device.getNAT().removeRule(finds.get(0).intValue()); } else{ --- 2101,2107 ---- } else{ ! Vector<Integer> finds = device.getNAT().findRules(true, true, iacl, "", 0, "", 0, poolname); if(finds.size()>0){ ! device.getNAT().removeRule(finds.get(0).intValue(), true); } else{ *************** *** 2120,2124 **** if(overload){ NAT_rule rule = device.getNAT().new NAT_rule(); ! rule.dynamic = false; rule.pool = false; rule.acl = iacl; --- 2121,2125 ---- if(overload){ NAT_rule rule = device.getNAT().new NAT_rule(); ! rule.dynamic = true; rule.pool = false; rule.acl = iacl; *************** *** 2131,2137 **** } else{ ! Vector<Integer> finds = device.getNAT().findRules(false, false, iacl, "", 0, "", 0, intname); if(finds.size()>0){ ! device.getNAT().removeRule(finds.get(0).intValue()); } else{ --- 2132,2138 ---- } else{ ! Vector<Integer> finds = device.getNAT().findRules(true, false, iacl, "", 0, "", 0, intname); if(finds.size()>0){ ! device.getNAT().removeRule(finds.get(0).intValue(), true); } else{ *************** *** 2232,2236 **** finds = device.getNAT().findRules(false, false, 0, local_ip, local_port, global_ip, global_port, ""); if(finds.size()>0){ ! device.getNAT().removeRule(finds.get(0).intValue()); } else{ --- 2233,2237 ---- finds = device.getNAT().findRules(false, false, 0, local_ip, local_port, global_ip, global_port, ""); if(finds.size()>0){ ! device.getNAT().removeRule(finds.get(0).intValue(), false); } else{ *************** *** 2922,2927 **** } }; ! class show_ip_nat_translation_CommandClass extends CommandInterface{ ! public show_ip_nat_translation_CommandClass(){ modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); call_params = "<cr>"; --- 2923,2928 ---- } }; ! class show_ip_nat_translations_CommandClass extends CommandInterface{ ! public show_ip_nat_translations_CommandClass(){ modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); call_params = "<cr>"; *************** *** 2930,2949 **** String out = ""; if(params.size()==0){ - out += "Protocol Inside Outside\n"; NATEngine nat = device.getNAT(); ! for(int i=0; i<nat.countRules(); i++){ ! NAT_rule rule = nat.getRule(i); ! String inside = rule.in_ip; ! if(rule.in_port>0) inside += ":"+rule.in_port; ! String outside = rule.out_ip; ! if(rule.out_port>0) outside += ":"+rule.out_port; ! String protocol = ""; ! switch(rule.protocol){ ! case NAT_rule.IP: protocol="ip"; break; ! case NAT_rule.ICMP: protocol="icmp"; break; ! case NAT_rule.UDP: protocol="udp"; break; ! case NAT_rule.TCP: protocol="tcp"; break; } - out += String.format("%-12s%-23s%s\n", protocol, inside, outside); } } --- 2931,2955 ---- String out = ""; if(params.size()==0){ NATEngine nat = device.getNAT(); ! if(nat.countSessions()<1){ ! out += "found no sessions\n"; ! } ! else{ ! out += "Protocol Inside Outside\n"; ! for(int i=0; i<nat.countSessions(); i++){ ! NAT_session rule = nat.getSession(i); ! String inside = rule.in_ip; ! if(rule.in_port>0) inside += ":"+rule.in_port; ! String outside = rule.out_ip; ! if(rule.out_port>0) outside += ":"+rule.out_port; ! String protocol = ""; ! switch(rule.protocol){ ! case NAT_session.UNKNOWN: protocol="---"; break; ! case NAT_session.ICMP: protocol="icmp"; break; ! case NAT_session.UDP: protocol="udp"; break; ! case NAT_session.TCP: protocol="tcp"; break; ! } ! out += String.format("%-12s%-23s%s\n", protocol, inside, outside); } } } Index: NATEngine.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NATEngine.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** NATEngine.java 13 Oct 2008 12:41:31 -0000 1.5 --- NATEngine.java 13 Oct 2008 19:36:35 -0000 1.6 *************** *** 11,15 **** public class NAT_session{ ! public final static int UNKNOWN = 1; public final static int ICMP = 1; public final static int UDP = 2; --- 11,15 ---- public class NAT_session{ ! public final static int UNKNOWN = 0; public final static int ICMP = 1; public final static int UDP = 2; *************** *** 55,59 **** } ! Vector<NAT_rule> rules; Hashtable<String, Pair> pools; --- 55,60 ---- } ! Vector<NAT_rule> static_rules; ! Vector<NAT_rule> dynamic_rules; Hashtable<String, Pair> pools; *************** *** 61,65 **** parentNode = node; ! rules = new Vector<NAT_rule>(); pools = new Hashtable<String, Pair>(); } --- 62,68 ---- parentNode = node; ! static_rules = new Vector<NAT_rule>(); ! dynamic_rules = new Vector<NAT_rule>(); ! sessions = new Vector<NAT_session>(); pools = new Hashtable<String, Pair>(); } *************** *** 70,73 **** --- 73,78 ---- public int addRule(NAT_rule rule, int pos){ + Vector<NAT_rule> rules = static_rules; + if(rule.dynamic) rules = dynamic_rules; if(pos<0 || pos>=rules.size()){ rules.add(rule); *************** *** 78,82 **** } ! public boolean removeRule(int rnum){ if(rnum>=0 && rnum<rules.size()){ rules.remove(rnum); --- 83,89 ---- } ! public boolean removeRule(int rnum, boolean dynamic){ ! Vector<NAT_rule> rules = static_rules; ! if(dynamic) rules = dynamic_rules; if(rnum>=0 && rnum<rules.size()){ rules.remove(rnum); *************** *** 87,102 **** public boolean isOverloadIP(String ip){ ! for(int i=0; i<rules.size(); i++) ! if(rules.get(i).out_ip.equals(ip)) return true; return false; } ! public Vector<Integer> findRules(Boolean dynamic, Boolean pool, Integer acl, String in_ip, Integer in_port, String out_ip, Integer out_port, String out_int){ Vector<Integer> result = new Vector<Integer>(); for(int i=0; i<rules.size(); i++){ NAT_rule rule = rules.get(i); ! if((dynamic==null || rule.dynamic==dynamic.booleanValue()) ! && (pool==null || rule.pool==pool.booleanValue()) && (acl==null || rule.acl==acl.intValue()) && (in_ip==null || rule.in_ip.equalsIgnoreCase(in_ip)) --- 94,110 ---- public boolean isOverloadIP(String ip){ ! for(int i=0; i<static_rules.size(); i++) ! if(static_rules.get(i).out_ip.equals(ip)) return true; return false; } ! public Vector<Integer> findRules(boolean dynamic, Boolean pool, Integer acl, String in_ip, Integer in_port, String out_ip, Integer out_port, String out_int){ ! Vector<NAT_rule> rules = static_rules; ! if(dynamic) rules = dynamic_rules; Vector<Integer> result = new Vector<Integer>(); for(int i=0; i<rules.size(); i++){ NAT_rule rule = rules.get(i); ! if((pool==null || rule.pool==pool.booleanValue()) && (acl==null || rule.acl==acl.intValue()) && (in_ip==null || rule.in_ip.equalsIgnoreCase(in_ip)) *************** *** 114,119 **** IP_packet rp = p; ! for(int i=0; i<rules.size(); i++){ ! NAT_rule rule = rules.get(i); String NewIP = ""; int NewPort = 0; --- 122,127 ---- IP_packet rp = p; ! for(int i=0; i<static_rules.size(); i++){ ! NAT_rule rule = static_rules.get(i); String NewIP = ""; int NewPort = 0; *************** *** 176,181 **** IP_packet rp = p; ! for(int i=0; i<rules.size(); i++){ ! NAT_rule rule = rules.get(i); String NewIP = ""; int NewPort = 0; --- 184,189 ---- IP_packet rp = p; ! for(int i=0; i<static_rules.size(); i++){ ! NAT_rule rule = static_rules.get(i); String NewIP = ""; int NewPort = 0; *************** *** 223,227 **** } ! public NAT_rule getRule(int i){ if(i>=0 && i<rules.size()){ return rules.get(i); --- 231,237 ---- } ! public NAT_rule getRule(int i, boolean dynamic){ ! Vector<NAT_rule> rules = static_rules; ! if(dynamic) rules = dynamic_rules; if(i>=0 && i<rules.size()){ return rules.get(i); *************** *** 230,234 **** } ! public int countRules(){ return rules.size(); } --- 240,246 ---- } ! public int countRules(boolean dynamic){ ! Vector<NAT_rule> rules = static_rules; ! if(dynamic) rules = dynamic_rules; return rules.size(); } *************** *** 265,267 **** --- 277,290 ---- return pools.keys(); } + + public NAT_session getSession(int i){ + if(i>=0 && i<sessions.size()){ + return sessions.get(i); + } + return null; + } + + public int countSessions(){ + return sessions.size(); + } } Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** DeviceConfig.java 12 Oct 2008 21:45:47 -0000 1.19 --- DeviceConfig.java 13 Oct 2008 19:36:35 -0000 1.20 *************** *** 572,580 **** NetworkLayerDevice ndev = (NetworkLayerDevice)device; NATEngine nat = ndev.getNAT(); ! for(int i=0; i<nat.countRules(); i++){ ! String params; ! NAT_rule rule = nat.getRule(i); ! if(!rule.dynamic){ ! if(rule.acl>0){ params = " list "+rule.acl; params += (rule.pool?" pool ":" interface ")+rule.out_int; --- 572,580 ---- 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; |