[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip IPV4Address.java,1.2,1.3 IpV4.java,1.2,1.3 Pro
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2005-12-01 14:54:53
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8407/core/protocolsuite/tcp_ip Modified Files: IPV4Address.java IpV4.java ProtocolStack.java Route_entry.java Log Message: Rout tables almost done! Please test them and send me bugs ;). Index: Route_entry.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Route_entry.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Route_entry.java 16 Nov 2005 20:25:40 -0000 1.3 --- Route_entry.java 1 Dec 2005 14:54:37 -0000 1.4 *************** *** 24,27 **** --- 24,29 ---- /** Creates a new instance of Route_entry */ + public Route_entry() {} + public Route_entry(String destIP, String gateway, String genMask, String iFace, int Type) { this.destIP = destIP; Index: ProtocolStack.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ProtocolStack.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** ProtocolStack.java 30 Nov 2005 13:02:32 -0000 1.24 --- ProtocolStack.java 1 Dec 2005 14:54:37 -0000 1.25 *************** *** 231,234 **** --- 231,236 ---- inPacket.setSourceIPAddress(sourceIP); + + String GatewayAddress = null; // test if on local of remote network *************** *** 240,245 **** }else{ ! String GatewayAddress = mIPprotocol.getDefaultGateway(); destMAC = mARPprotocol.getMACAddress(GatewayAddress,outInterface[0]); --- 242,253 ---- }else{ ! //String GatewayAddress = mIPprotocol.getDefaultGateway(); ! ! GatewayAddress = mIPprotocol.getGateway(inPacket.getDestIPAddress()); + String outIface = mIPprotocol.getInterface(inPacket.getDestIPAddress()); + + if(outIface!=null) outInterface[0] = outIface; + destMAC = mARPprotocol.getMACAddress(GatewayAddress,outInterface[0]); *************** *** 266,270 **** protocolInfo.setLayer("Network"); ! protocolInfo.setDescription("Sending packet from ProtocolStack."); Simulation.addLayerInfo(protocolInfo); --- 274,280 ---- protocolInfo.setLayer("Network"); ! if(GatewayAddress==null) GatewayAddress=inPacket.getDestIPAddress(); ! ! protocolInfo.setDescription("Sending packet from ProtocolStack (to " + GatewayAddress + ")."); Simulation.addLayerInfo(protocolInfo); *************** *** 294,298 **** }catch(CommunicationException ex){ throw ex; ! } } --- 304,310 ---- }catch(CommunicationException ex){ throw ex; ! }catch(InvalidIPAddressException e){ //UGLY!!! FIXME!!! ! System.out.println(e.toString()); ! } } *************** *** 332,336 **** String outInterface[] = mIPprotocol.router(inPacket.getDestIPAddress()); ! //test if on local of remote network --- 344,348 ---- String outInterface[] = mIPprotocol.router(inPacket.getDestIPAddress()); ! String GatewayAddress = null; //test if on local of remote network *************** *** 341,348 **** }else{ ! String GatewayAddress = mIPprotocol.getDefaultGateway(); ! ! destMAC = mARPprotocol.getMACAddress(GatewayAddress,outInterface[0]); } --- 353,369 ---- }else{ + try{ + GatewayAddress = mIPprotocol.getGateway(inPacket.getDestIPAddress()); ! String outIface = mIPprotocol.getInterface(inPacket.getDestIPAddress()); ! ! if(outIface!=null) outInterface[0] = outIface; ! }catch(Exception e){} //UGLY!!! FIXME!!! ! ! ! destMAC = mARPprotocol.getMACAddress(GatewayAddress,outInterface[0]); ! ! //String GatewayAddress = mIPprotocol.getDefaultGateway(); ! //destMAC = mARPprotocol.getMACAddress(GatewayAddress,outInterface[0]); } *************** *** 371,375 **** protocolInfo.setLayer("Network"); ! protocolInfo.setDescription("Forwarding packet from ProtocolStack."); Simulation.addLayerInfo(protocolInfo); --- 392,398 ---- protocolInfo.setLayer("Network"); ! if(GatewayAddress==null) GatewayAddress=inPacket.getDestIPAddress(); ! ! protocolInfo.setDescription("Forwarding packet from ProtocolStack(to " + GatewayAddress + ")."); Simulation.addLayerInfo(protocolInfo); Index: IpV4.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/IpV4.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IpV4.java 8 Nov 2005 20:58:14 -0000 1.2 --- IpV4.java 1 Dec 2005 14:54:37 -0000 1.3 *************** *** 283,291 **** public void setDefaultGateway(String inGatewayIPAddress)throws InvalidDefaultGatewayException { try { ! defaultGateway = IPV4Address.toBinaryString(inGatewayIPAddress); } catch (InvalidIPAddressException e) { throw new InvalidDefaultGatewayException("Invaild Default Gateway Address."); } } /** * Gets the defaultgateway. --- 283,353 ---- public void setDefaultGateway(String inGatewayIPAddress)throws InvalidDefaultGatewayException { try { ! defaultGateway = IPV4Address.toBinaryString(inGatewayIPAddress); ! Route_entry r = new Route_entry(); ! r.destIP = "default"; ! r.gateway = inGatewayIPAddress; ! r.genMask = IPV4Address.getDefaultSubnetMask(inGatewayIPAddress); ! r.iFace = "eth0"; ! r.Type = 0; ! addRoute(r); } catch (InvalidIPAddressException e) { throw new InvalidDefaultGatewayException("Invaild Default Gateway Address."); } } + + /** + * Return the route gateway for this packet... + * @param Destination IP + * @author Key + * @return gateway IP + * @throws InvalidDefaultGatewayException + * @version 0.20 + */ + public String getGateway(String inIPAddress)throws InvalidIPAddressException{ + String binIP = IPV4Address.toBinaryString(inIPAddress); + String binMask; + String destNetwork; + String curdestNetwork; + Route_entry r; + + Enumeration keys1 = routingTable.keys(); + while(keys1.hasMoreElements()){ + curdestNetwork = (String)keys1.nextElement(); + r = (Route_entry)routingTable.get(curdestNetwork); + binMask = IPV4Address.toBinaryString(r.genMask); + destNetwork = IPV4Address.toDecimalString(IPV4Address.IPandMask(binIP,binMask)); + if(destNetwork.contains(curdestNetwork)) return r.gateway; + } + + return getDefaultGateway(); + } + + /* + * Return the route interface for this packet... + * @param Destination IP + * @author Key + * @return gateway IP + * @throws InvalidDefaultGatewayException + * @version 0.20 + */ + public String getInterface(String inIPAddress)throws InvalidIPAddressException{ + String binIP = IPV4Address.toBinaryString(inIPAddress); + String binMask; + String destNetwork; + String curdestNetwork; + Route_entry r; + + Enumeration keys1 = routingTable.keys(); + while(keys1.hasMoreElements()){ + curdestNetwork = (String)keys1.nextElement(); + r = (Route_entry)routingTable.get(curdestNetwork); + binMask = IPV4Address.toBinaryString(r.genMask); + destNetwork = IPV4Address.toDecimalString(IPV4Address.IPandMask(binIP,binMask)); + if(destNetwork.contains(curdestNetwork)) return r.iFace; + } + + return null; + } + /** * Gets the defaultgateway. *************** *** 297,304 **** */ public String getDefaultGateway(){ ! if(defaultGateway != null){ return IPV4Address.toDecimalString(defaultGateway); } ! return null; } --- 359,374 ---- */ public String getDefaultGateway(){ ! /* ! if(defaultGateway != null){ return IPV4Address.toDecimalString(defaultGateway); } ! return null; ! */ ! try{ ! Route_entry r = getRouteTableEntry("default"); ! return r.gateway; ! }catch(Exception e){ ! return null; ! } } Index: IPV4Address.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/IPV4Address.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IPV4Address.java 20 Nov 2005 20:30:53 -0000 1.2 --- IPV4Address.java 1 Dec 2005 14:54:37 -0000 1.3 *************** *** 531,535 **** } ! public String IPandMask(String binIP, String binMask){ String b1, b2, b3; String result = ""; --- 531,535 ---- } ! public static String IPandMask(String binIP, String binMask){ String b1, b2, b3; String result = ""; |