[Javanetsim-cvs] javaNetSim/core CommandProcessor.java, 1.28, 1.29 DeviceConfig.java, 1.22, 1.23 E
Status: Beta
Brought to you by:
darkkey
Update of /cvsroot/javanetsim/javaNetSim/core In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20370/core Modified Files: CommandProcessor.java DeviceConfig.java EthernetNetworkInterface.java MultilayerSwitch.java NetworkInterfacePort.java Log Message: DHCP + VLAN commands was corrected Index: CommandProcessor.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/CommandProcessor.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** CommandProcessor.java 19 Oct 2008 21:40:19 -0000 1.28 --- CommandProcessor.java 20 Oct 2008 23:46:56 -0000 1.29 *************** *** 26,29 **** --- 26,30 ---- import java.util.ArrayList; + import java.util.Calendar; import java.util.Enumeration; import java.util.Hashtable; *************** *** 1543,1551 **** try{ NetworkInterface ni = device.getNetworkInterface(params.get(0)); ! if(ni instanceof EthernetNetworkInterface){ ! EthernetNetworkInterface eni = (EthernetNetworkInterface) ni; if(add){ try{ int vlanid = Integer.parseInt(params.get(1)); eni.vlan = vlanid; } --- 1544,1553 ---- try{ NetworkInterface ni = device.getNetworkInterface(params.get(0)); ! if(ni instanceof NetworkInterfacePort){ ! NetworkInterfacePort eni = (NetworkInterfacePort) ni; if(add){ try{ int vlanid = Integer.parseInt(params.get(1)); + if(vlanid<=0) throw new NumberFormatException(); eni.vlan = vlanid; } *************** *** 1587,1593 **** try{ NetworkInterface ni = device.getNetworkInterface(params.get(0)); ! if(ni instanceof EthernetNetworkInterface){ ! EthernetNetworkInterface eni = (EthernetNetworkInterface) ni; ! eni.mode = EthernetNetworkInterface.MODE_ACCESS; } else{ --- 1589,1595 ---- try{ NetworkInterface ni = device.getNetworkInterface(params.get(0)); ! if(ni instanceof NetworkInterfacePort){ ! NetworkInterfacePort eni = (NetworkInterfacePort) ni; ! eni.mode = NetworkInterfacePort.MODE_ACCESS; } else{ *************** *** 1620,1626 **** try{ NetworkInterface ni = device.getNetworkInterface(params.get(0)); ! if(ni instanceof EthernetNetworkInterface){ ! EthernetNetworkInterface eni = (EthernetNetworkInterface) ni; ! eni.mode = EthernetNetworkInterface.MODE_TRUNK; } else{ --- 1622,1628 ---- try{ NetworkInterface ni = device.getNetworkInterface(params.get(0)); ! if(ni instanceof NetworkInterfacePort){ ! NetworkInterfacePort eni = (NetworkInterfacePort) ni; ! eni.mode = NetworkInterfacePort.MODE_TRUNK; } else{ *************** *** 2049,2053 **** modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); call_params = "<network ip> <netmask>"; ! no_call_params = "<network ip> <netmask>"; } public String call(Vector<String> params){ --- 2051,2055 ---- modes = new Modes(CommandInterface.CONF_MODE, CommandInterface.APPLICATION_LAYER, CommandInterface.NO_CALL); call_params = "<network ip> <netmask>"; ! no_call_params = "<cr>"; } public String call(Vector<String> params){ *************** *** 3293,3299 **** } public String call(Vector<String> params){ ! String out = "Command not supported yet.\n"; if(device instanceof ApplicationLayerDevice){ ! } else{ --- 3295,3330 ---- } public String call(Vector<String> params){ ! 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> leases = dhcpd.leases.keys(); ! while(leases.hasMoreElements()){ ! String name = leases.nextElement(); ! DHCPD.lease lease = (DHCPD.lease) dhcpd.leases.get(name); ! out += " Lease at '"+name+"' is "+(lease.completed?"complete":"not complete")+"\n" + ! " Network: "+((lease.IP==null || lease.IP=="")?"(not set)":lease.IP)+"\n" + ! " Mask: "+((lease.Genmask==null || lease.Genmask=="")?"(not set)":lease.Genmask)+"\n" + ! " Gateway: "+((lease.Gateway==null || lease.Gateway=="")?"(not set)":lease.Gateway)+"\n" + ! " MAC: "+((lease.MAC==null || lease.MAC=="")?"(not set)":lease.MAC)+"\n"; ! if(lease.leased>0){ ! Calendar lt = Calendar.getInstance(); ! lt.setTimeInMillis(lease.leased); ! out += " Leased: "+String.format("%1$tT", lt)+"\n"; ! } ! else{ ! out += " Leased: (none)\n"; ! } ! } ! } ! else{ ! out += "error: invalid parameters\n"; ! } ! } ! else{ ! out += "This instruction not supported by device\n"; ! } } else{ *************** *** 3309,3315 **** } public String call(Vector<String> params){ ! String out = "Command not supported yet.\n"; if(device instanceof ApplicationLayerDevice){ ! } else{ --- 3340,3367 ---- } public String call(Vector<String> params){ ! 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.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{ ! out += "error: invalid parameters\n"; ! } ! } ! else{ ! out += "This instruction not supported by device\n"; ! } } else{ *************** *** 3381,3438 **** public show_interfaces_CommandClass(){ modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); ! call_params = "<cr>"; } public String call(Vector<String> params){ String out = ""; ! Object[] ins = device.getAllInterfaces(); ! ! for(int i=0; i<ins.length; i++){ ! try { ! NetworkInterface ni = device.getNetworkInterface((String)ins[i]); ! boolean isLineUp = false; ! if(ni instanceof WiFiPort){ ! isLineUp = ((WiFiPort) ni).associated; ! } ! else{ ! isLineUp = ni.getConnectedLink() != null; ! } ! boolean isUp = ni.isUP(); ! out += "Interface " + (String)ins[i] + " is " + (isUp?"up":"down") + ", line protocol is " + (isLineUp?"up":"down") + "\n"; ! out += " Description: \"" + ni.getDescription() + "\"\n"; ! out += " Hardware address " + device.getMACAddress((String)ins[i]) + "\n"; ! String ip = device.getIPAddress((String)ins[i]); ! String mask = device.getSubnetMask((String)ins[i]); ! out += " Internet address " + (ip==null || ip.equals("")?"Not set":ip) + "/" + (mask==null || mask.equals("")?"Not set":mask) + "\n"; ! if(ni instanceof EthernetNetworkInterface){ ! EthernetNetworkInterface eni = (EthernetNetworkInterface)ni; ! if(eni.vlan > 1){ ! out += " VLAN ID: "+eni.vlan+"\n"; ! } ! } ! if(ni instanceof WiFiPort){ ! WiFiPort wfi = (WiFiPort) ni; ! if(device instanceof WirelessAP || device instanceof Router){ ! out += " BSSID: " + wfi.getBSSID() + "\n"; ! } ! else{ ! out += " Access point BSSID: " + wfi.getAPBSSID() + "\n"; } ! out += " SSID: " + wfi.getSSID() + "\n"; ! out += " Channel: " + wfi.getChannel() + "\n"; ! if(wfi.getMode()==WiFiPort.MODE_AP) ! out += " Station-role is access point\n"; ! else if(wfi.getMode()==WiFiPort.MODE_REPEATER) ! out += " Station-role is repeater\n"; ! else if(wfi.getMode()==WiFiPort.MODE_STATION) ! out += " Station-role is client\n"; ! out += " Authentication type: " + (wfi.isSharedAuth()?"shared":"open") + "\n"; } ! if(ni instanceof SerialNetworkInterface){ ! out += " Clock-rate " + ((SerialNetworkInterface)ni).getClockRate() + "\n"; } ! out += "\n"; ! } catch (InvalidNetworkInterfaceNameException ex) { ! out += "internal error: invalid network interface\n"; } } return out; --- 3433,3508 ---- public show_interfaces_CommandClass(){ modes = new Modes(CommandInterface.STD_CONF_MODE, CommandInterface.NETWORK_LAYER, CommandInterface.CALL_ONLY); ! call_params = "[<interface name>]"; } public String call(Vector<String> params){ String out = ""; ! if(params.size()==1){ ! out += sh_int(params.get(0)); ! } ! else if(params.size()==0){ ! Object[] ins = device.getAllInterfaces(); ! for(int i=0; i<ins.length; i++){ ! out += sh_int((String)ins[i]); ! } ! } ! else{ ! out += "error: invalid parameters\n"; ! } ! return out; ! } ! private String sh_int(String iface){ ! String out = ""; ! try { ! NetworkInterface ni = device.getNetworkInterface(iface); ! boolean isLineUp = false; ! if(ni instanceof WiFiPort){ ! isLineUp = ((WiFiPort) ni).associated; ! } ! else{ ! isLineUp = ni.getConnectedLink() != null; ! } ! boolean isUp = ni.isUP(); ! out += "Interface " + iface + " is " + (isUp?"up":"down") + ", line protocol is " + (isLineUp?"up":"down") + "\n"; ! out += " Description: \"" + ni.getDescription() + "\"\n"; ! out += " Hardware address " + device.getMACAddress(iface) + "\n"; ! String ip = device.getIPAddress(iface); ! String mask = device.getSubnetMask(iface); ! out += " Internet address " + (ip==null || ip.equals("")?"Not set":ip) + "/" + (mask==null || mask.equals("")?"Not set":mask) + "\n"; ! if(ni instanceof NetworkInterfacePort){ ! NetworkInterfacePort eni = (NetworkInterfacePort)ni; ! //if(eni.vlan > 1){ ! out += " VLAN ID: "+eni.vlan+"\n"; ! String vmode = "unknown"; ! switch(eni.mode){ ! case NetworkInterfacePort.MODE_ACCESS: vmode = "access"; break; ! case NetworkInterfacePort.MODE_TRUNK: vmode = "trunk"; break; } ! out += " VLAN mode: "+vmode+"\n"; ! //} ! } ! if(ni instanceof WiFiPort){ ! WiFiPort wfi = (WiFiPort) ni; ! if(device instanceof WirelessAP || device instanceof Router){ ! out += " BSSID: " + wfi.getBSSID() + "\n"; } ! else{ ! out += " Access point BSSID: " + wfi.getAPBSSID() + "\n"; } ! out += " SSID: " + wfi.getSSID() + "\n"; ! out += " Channel: " + wfi.getChannel() + "\n"; ! if(wfi.getMode()==WiFiPort.MODE_AP) ! out += " Station-role is access point\n"; ! else if(wfi.getMode()==WiFiPort.MODE_REPEATER) ! out += " Station-role is repeater\n"; ! else if(wfi.getMode()==WiFiPort.MODE_STATION) ! out += " Station-role is client\n"; ! out += " Authentication type: " + (wfi.isSharedAuth()?"shared":"open") + "\n"; } + if(ni instanceof SerialNetworkInterface){ + out += " Clock-rate " + ((SerialNetworkInterface)ni).getClockRate() + "\n"; + } + out += "\n"; + } catch (InvalidNetworkInterfaceNameException ex) { + out += "invalid network interface\n"; } return out; *************** *** 3813,3829 **** vlans.add(keys.nextElement()); } ! String[] ints = (String[]) device.getAllInterfaces(); for(int i=0; i<ints.length; i++){ try{ ! NetworkInterface ni = device.getNetworkInterface(ints[i]); ! if(ni instanceof EthernetNetworkInterface){ ! EthernetNetworkInterface eni = (EthernetNetworkInterface) ni; int vlanid = eni.vlan; if(vlanport.containsKey(vlanid)){ ! vlanport.get(vlanid).add(ints[i]); } else{ Vector<String> ports = new Vector<String>(1); ! ports.add(ints[i]); vlanport.put(vlanid, ports); if(!vlans.contains(vlanid)){ --- 3883,3899 ---- vlans.add(keys.nextElement()); } ! Object[] ints = device.getAllInterfaces(); for(int i=0; i<ints.length; i++){ try{ ! NetworkInterface ni = device.getNetworkInterface((String)ints[i]); ! if(ni instanceof NetworkInterfacePort){ ! NetworkInterfacePort eni = (NetworkInterfacePort) ni; int vlanid = eni.vlan; if(vlanport.containsKey(vlanid)){ ! vlanport.get(vlanid).add((String)ints[i]); } else{ Vector<String> ports = new Vector<String>(1); ! ports.add((String)ints[i]); vlanport.put(vlanid, ports); if(!vlans.contains(vlanid)){ *************** *** 3838,3842 **** int vlanid = vlansi.next(); String vlanname = msdev.getVlanName(vlanid); ! if(vlanname==null) vlanname = "-vlan not exists-"; String ports = ""; if(vlanport.containsKey(vlanid)){ --- 3908,3912 ---- int vlanid = vlansi.next(); String vlanname = msdev.getVlanName(vlanid); ! if(vlanname==null) vlanname = "(vlan not exists)"; String ports = ""; if(vlanport.containsKey(vlanid)){ *************** *** 3849,3853 **** ports = "no ports found"; } ! out += vlanid+"\t"+String.format("%25s", vlanname)+"\t"+ports+"\n"; } } --- 3919,3923 ---- ports = "no ports found"; } ! out += vlanid+" "+String.format("%20s", vlanname)+" "+ports+"\n"; } } *************** *** 4139,4156 **** if(device instanceof MultilayerSwitch){ MultilayerSwitch msdev = (MultilayerSwitch) device; ! if(params.size()==2 || params.size()==3){ try{ ! int vlanid = Integer.parseInt(params.get(1)); ! String name = ""; ! if(params.size()==3) name = params.get(2); ! if(add){ ! msdev.addVlan(vlanid, name); } else{ ! if(name.equals("")){ ! msdev.removeVlan(vlanid); } ! else if(msdev.getVlanName(vlanid).equals(name)){ ! msdev.removeVlan(vlanid); } } --- 4209,4232 ---- if(device instanceof MultilayerSwitch){ MultilayerSwitch msdev = (MultilayerSwitch) device; ! if(params.size()==1 || params.size()==2){ try{ ! int vlanid = Integer.parseInt(params.get(0)); ! if(vlanid<=0) throw new NumberFormatException(); ! else if(vlanid==1){ ! out += "error: VLAN 1 is reserved!\n"; } else{ ! String name = ""; ! if(params.size()==2) name = params.get(1); ! if(add){ ! msdev.addVlan(vlanid, name); } ! else{ ! if(name.equals("")){ ! msdev.removeVlan(vlanid); ! } ! else if(msdev.getVlanName(vlanid).equals(name)){ ! msdev.removeVlan(vlanid); ! } } } Index: NetworkInterfacePort.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/NetworkInterfacePort.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** NetworkInterfacePort.java 5 Oct 2008 19:12:31 -0000 1.9 --- NetworkInterfacePort.java 20 Oct 2008 23:46:56 -0000 1.10 *************** *** 112,115 **** --- 112,121 ---- */ + + + public int vlan = 1; + final static int MODE_ACCESS = 0; + final static int MODE_TRUNK = 1; + public int mode = MODE_ACCESS; protected NetworkInterfacePort(long UID, String inName, Node inParent) { *************** *** 150,155 **** protected void receivePacket(Packet inPacket) throws LowLinkException { if(!parentNode.On) return; ! ! parentNode.receivePacket(inPacket, name); return; --- 156,165 ---- protected void receivePacket(Packet inPacket) throws LowLinkException { if(!parentNode.On) return; ! ! boolean drop = false; ! if(mode == MODE_ACCESS && (((Ethernet_packet)inPacket).vlan_id != vlan)) ! drop = true; ! ! if(!drop) parentNode.receivePacket(inPacket, name); return; Index: DeviceConfig.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/DeviceConfig.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** DeviceConfig.java 18 Oct 2008 19:55:31 -0000 1.22 --- DeviceConfig.java 20 Oct 2008 23:46:56 -0000 1.23 *************** *** 415,418 **** --- 415,419 ---- EthernetNetworkInterface eni = null; SerialNetworkInterface sni = null; + NetworkInterfacePort pni = null; WiFiPort wfi = null; try{ *************** *** 423,426 **** --- 424,430 ---- } catch(ClassCastException e){}; try{ + pni = (NetworkInterfacePort) ni; + } catch(ClassCastException e){}; + try{ wfi = (WiFiPort) ni; } catch(ClassCastException e){}; *************** *** 456,459 **** --- 460,474 ---- } } + 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"); *************** *** 474,481 **** conf.add("no interface "+intName+" ip information-replay"); ! if(ni.isUP()) ! conf.add("no interface "+intName+" shutdown"); ! else conf.add("interface "+intName+" shutdown"); if(device instanceof ApplicationLayerDevice){ --- 489,500 ---- 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){ Index: MultilayerSwitch.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/MultilayerSwitch.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MultilayerSwitch.java 19 Oct 2008 21:40:19 -0000 1.2 --- MultilayerSwitch.java 20 Oct 2008 23:46:56 -0000 1.3 *************** *** 177,181 **** it = NetworkInterfacetable.elements(); while (it.hasMoreElements()) { ! EthernetNetworkInterface tempInterface = (EthernetNetworkInterface) it .nextElement(); nic = tempInterface.getName(); --- 177,181 ---- it = NetworkInterfacetable.elements(); while (it.hasMoreElements()) { ! NetworkInterfacePort tempInterface = (NetworkInterfacePort) it .nextElement(); nic = tempInterface.getName(); *************** *** 184,188 **** intFound = true; try { ! if(tempInterface.mode == EthernetNetworkInterface.MODE_TRUNK || tempInterface.vlan == copyPacket.vlan_id) tempInterface.sendPacket(copyPacket); --- 184,188 ---- intFound = true; try { ! if(tempInterface.mode == NetworkInterfacePort.MODE_TRUNK || tempInterface.vlan == copyPacket.vlan_id) tempInterface.sendPacket(copyPacket); *************** *** 198,202 **** // that sent in the packet // if it is skip that interface ! EthernetNetworkInterface tempInterface = (EthernetNetworkInterface) it .nextElement(); --- 198,202 ---- // that sent in the packet // if it is skip that interface ! NetworkInterfacePort tempInterface = (NetworkInterfacePort) it .nextElement(); *************** *** 204,208 **** try { ! if(tempInterface.mode == EthernetNetworkInterface.MODE_TRUNK || tempInterface.vlan == copyPacket.vlan_id) tempInterface.sendPacket(copyPacket); --- 204,208 ---- try { ! if(tempInterface.mode == NetworkInterfacePort.MODE_TRUNK || tempInterface.vlan == copyPacket.vlan_id) tempInterface.sendPacket(copyPacket); Index: EthernetNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/EthernetNetworkInterface.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** EthernetNetworkInterface.java 17 Oct 2008 09:10:16 -0000 1.18 --- EthernetNetworkInterface.java 20 Oct 2008 23:46:56 -0000 1.19 *************** *** 64,71 **** protected String MACAddress; public String defaultMACAddress; - public int vlan = 1; - final static int MODE_ACCESS = 0; - final static int MODE_TRUNK = 1; - public int mode = MODE_ACCESS; /** --- 64,67 ---- *************** *** 115,120 **** drop = true; - if(mode == MODE_ACCESS && (tempPacket.vlan_id != vlan)) - drop = true; //Test if this packet is for this interface or a broadcast --- 111,114 ---- |