[Javanetsim-cvs] javaNetSim/core ExternalNAT.java, NONE, 1.1 PC.java, 1.10, 1.11 Simulation.java, 1
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2006-11-08 14:27:37
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv1984/core Modified Files: PC.java Simulation.java Added Files: ExternalNAT.java Log Message: Index: PC.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/PC.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PC.java 25 Feb 2006 00:00:02 -0000 1.10 --- PC.java 8 Nov 2006 14:27:29 -0000 1.11 *************** *** 61,64 **** --- 61,65 ---- import core.protocolsuite.tcp_ip.Telnet_client; import core.protocolsuite.tcp_ip.Echo_tcp; + import core.protocolsuite.tcp_ip.PosixTelnetClient; import core.protocolsuite.tcp_ip.SNMP; *************** *** 119,124 **** --- 120,129 ---- Telnet_client telnetClient = new Telnet_client((ApplicationLayerDevice)this, NodeProtocolStack, 0, 0, core.ProtocolStack.UIDGen++); + + PosixTelnetClient ptc = new PosixTelnetClient(NodeProtocolStack, core.ProtocolStack.UIDGen++); addApp(echoServer, 7); + + addApp(ptc, 10023); addApp(echoClient, 30007); --- NEW FILE: ExternalNAT.java --- /* Java Firewall Simulator (jFirewallSim) 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 core; import core.protocolsuite.tcp_ip.*; import java.util.*; import java.io.*; import java.net.*; /** * Represents a Router Node in a network. A Router is the backbone of the internet. Routers * are responsible for Packets being able to reach their final destination. * @author tristan_veness * @since 13 June 2004 * @version v0.10 **/ public class ExternalNAT extends NetworkLayerDevice { int externalPort; String externalIP; NATEcho_tcp NE; boolean busy; protected Hashtable Apps = null; public void addApp(Object app, int code){ Apps.put(code, app); } public Object getApp(int code){ return Apps.get(code); } /** * Constructs a new Router with the specified name and is given two * Network Interfaces * @author tristan_veness * @param inName A name to give the new Router Node eg: Router1. * @version v0.10 **/ protected ExternalNAT(String inName) { super(inName,3); NodeProtocolStack.initNAT(); addNetworkInterface("eth0"); externalIP = null; Apps = new Hashtable(); busy = false; } public void NATDisconnect(Object application){ externalIP = null; } public void receivePacket(Packet inPacket) throws LowLinkException { if(inPacket instanceof IP_packet){ if(busy) return; IP_packet IPP = (IP_packet) inPacket; if(!NodeProtocolStack.isInternalIP(IPP.getDestIPAddress())){ System.out.println("Activating NAT when recieving..."); if(IPP instanceof TCP_packet){ busy = true; if(externalIP == null){ externalIP = IPP.getDestIPAddress(); externalPort = ((TCP_packet) IPP).get_destPort(); try { Socket NAT = new Socket(externalIP, externalPort); NE = null; NE = new NATEcho_tcp(NodeProtocolStack, this, NAT, externalIP, externalPort, core.ProtocolStack.UIDGen++); System.out.println("NAT step 2"); //addApp(NE, 1); ((TCP_packet) IPP).setDestIPAddress(NodeProtocolStack.getIPAddress("eth0")); NodeProtocolStack.recieveTCP_packet((TCP_packet) IPP); busy = false; }catch (IOException e) { e.printStackTrace(); externalIP = null; } }else{ ((TCP_packet) IPP).setDestIPAddress(NodeProtocolStack.getIPAddress("eth0")); NodeProtocolStack.recieveTCP_packet((TCP_packet) IPP); busy = false; } } }else{ NodeProtocolStack.receivePacket(inPacket); } }else{ NodeProtocolStack.receivePacket(inPacket); } } public void sendPacket(String inDestMACAddress, Packet inPacket, String inInterfaceKey) throws InvalidNetworkInterfaceNameException, CommunicationException, LowLinkException{ if (NetworkInterfacetable.containsKey(inInterfaceKey)) { EthernetNetworkInterface temp = (EthernetNetworkInterface)NetworkInterfacetable.get(inInterfaceKey); if(inPacket instanceof IP_packet){ IP_packet IPP = (IP_packet) inPacket; System.out.println("Activating NAT when sending..."); //if(!NodeProtocolStack.isInternalIP(IPP.getSourceIPAddress())){ //System.out.println("Activating NAT when sending..."); if(IPP instanceof TCP_packet){ ((TCP_packet) IPP).setSourceIPAddress(externalIP); } //} } temp.sendPacket(inPacket,inDestMACAddress); } else { throw new InvalidNetworkInterfaceNameException("Inteface does not exist."); } } }//EOF Index: Simulation.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/Simulation.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Simulation.java 12 Oct 2006 17:38:41 -0000 1.11 --- Simulation.java 8 Nov 2006 14:27:29 -0000 1.12 *************** *** 919,922 **** --- 919,931 ---- } + public void addExternalNAT(String inRouterName)throws InvalidNodeNameException { + if (!nodeTable.containsKey(inRouterName)) { + nodeTable.put(inRouterName, new ExternalNAT(inRouterName)); + } else { + throw new InvalidNodeNameException("Node already exists with same name"); + } + return; + } + /** * This method is for creating a PC within the simulation. |