[Javanetsim-cvs] javaNetSim/core .emptyDir, NONE, 1.1 ExternalProxy.java, NONE, 1.1 Simulation.java
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2006-11-22 21:18:42
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22200/core Modified Files: Simulation.java Added Files: .emptyDir ExternalProxy.java Removed Files: ExternalNAT.java Log Message: --- ExternalNAT.java DELETED --- --- NEW FILE: .emptyDir --- This file was generated by Together to prevent this folder from being deleted during synchronization with the CVS repositiory. Please do not delete this file. --- NEW FILE: ExternalProxy.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 ExternalProxy extends NetworkLayerDevice { int externalPort; String externalIP; ExternalProxyApp 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 ExternalProxy(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 ExternalProxyApp(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.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Simulation.java 8 Nov 2006 14:27:29 -0000 1.12 --- Simulation.java 22 Nov 2006 21:18:38 -0000 1.13 *************** *** 921,925 **** 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"); --- 921,925 ---- public void addExternalNAT(String inRouterName)throws InvalidNodeNameException { if (!nodeTable.containsKey(inRouterName)) { ! nodeTable.put(inRouterName, new ExternalProxy(inRouterName)); } else { throw new InvalidNodeNameException("Node already exists with same name"); |