Thread: [Javanetsim-cvs] javaNetSim/core EthernetLink.java, 1.13, 1.14 WANCorbaServer.java, 1.1, 1.2 WANNet
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2007-11-19 15:10:33
|
Update of /cvsroot/javanetsim/javaNetSim/core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21171/core Modified Files: EthernetLink.java WANCorbaServer.java WANNetworkInterface.java WANSocket.java Log Message: CORBA interface for WAN fully added. Index: EthernetLink.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/EthernetLink.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** EthernetLink.java 11 Nov 2007 19:51:57 -0000 1.13 --- EthernetLink.java 19 Nov 2007 15:10:28 -0000 1.14 *************** *** 42,45 **** --- 42,46 ---- public class EthernetLink extends Link { java.security.SecureRandom rng; + /** * Constructor to be used by the Simulation when connecting 2 PC's *************** *** 51,57 **** * @param inInterface2 The Seceond Interface to connect this link to eg: eth1 * @throws InvalidLinkConnectionException ! */ ! ! public EthernetLink(String inName, NetworkInterface inFirstNodeInterface, NetworkInterface inSecondNodeInterface)throws InvalidLinkConnectionException { super(inName); NetworkInterfaces.add(inFirstNodeInterface); --- 52,57 ---- * @param inInterface2 The Seceond Interface to connect this link to eg: eth1 * @throws InvalidLinkConnectionException ! */ ! public EthernetLink(String inName, NetworkInterface inFirstNodeInterface, NetworkInterface inSecondNodeInterface)throws InvalidLinkConnectionException { super(inName); NetworkInterfaces.add(inFirstNodeInterface); *************** *** 68,71 **** --- 68,72 ---- inFirstNodeInterface.setConnectedLink(this); inSecondNodeInterface.setConnectedLink(this); + rng = new java.security.SecureRandom(); this.setSC(sieveCoeff); rng = new java.security.SecureRandom(); Index: WANNetworkInterface.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/WANNetworkInterface.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WANNetworkInterface.java 10 Nov 2007 13:25:38 -0000 1.5 --- WANNetworkInterface.java 19 Nov 2007 15:10:28 -0000 1.6 *************** *** 57,62 **** --- 57,67 ---- protected WANRMI RMIClient; + protected WANCorbaServer CORBAServer; + protected WANCorbaClient CORBAClient; + protected WANSocket s; + /* Interface properties setup functions */ + public void setServer(boolean inServer){ server = inServer; *************** *** 99,102 **** --- 104,111 ---- } + /* /Interface properties setup functions */ + + /* Standart javaNetSim interface functions */ + public void UP(){ up = listen(); *************** *** 112,115 **** --- 121,139 ---- } + public int getType(){ + return NetworkInterface.WAN; + } + + public boolean isActive(){ + return true; + } + + + protected String getDetails(){ + return "Interface: "+name; + } + + /* /Standart javaNetSim interface functions */ + public WANNetworkInterface(String inName, Node parent) { super(inName, parent); *************** *** 125,131 **** } public void receivePacket(Packet inPacket) throws LowLinkException { - // cast the packet to an EthernetPacket - //Ethernet_packet tempPacket = (Ethernet_packet)inPacket; switch(type){ case RMI: --- 149,154 ---- } + // forwards packet to device stack public void receivePacket(Packet inPacket) throws LowLinkException { switch(type){ case RMI: *************** *** 136,139 **** --- 159,169 ---- } break; + case Corba: + { + if(!connected){ + connect(); + } + } + break; case SocketTCP: case SocketUDP: *************** *** 143,150 **** addLayerInfo("WAN Packet","Recieved and accepted packet at interface " + name); ! parentNode.receivePacket(inPacket, name); } public void receivePacket(String inPacket) throws LowLinkException{ System.out.println(inPacket); --- 173,181 ---- addLayerInfo("WAN Packet","Recieved and accepted packet at interface " + name); ! parentNode.receivePacket(inPacket, name); } + // decode recieved packet to Packet class public void receivePacket(String inPacket) throws LowLinkException{ System.out.println(inPacket); *************** *** 180,188 **** } ! ! public int getType(){ ! return NetworkInterface.WAN; ! } ! protected void sendPacket(Packet inPacket) throws LowLinkException { if(!connected){ --- 211,216 ---- } ! ! // sending packet through WAN interface protected void sendPacket(Packet inPacket) throws LowLinkException { if(!connected){ *************** *** 199,205 **** case SocketTCP: case SocketUDP: ! ! s.sendPacket(inPacket); break; } }catch(Exception e){ --- 227,235 ---- case SocketTCP: case SocketUDP: ! s.sendPacket(inPacket.toBytes()); break; + case Corba: + CORBAClient.sendPacket(inPacket.toBytes()); + break; } }catch(Exception e){ *************** *** 210,217 **** --- 240,249 ---- } + // this is the same as upper function, MAC is ignored here protected void sendPacket(Packet inPacket, String inMacAddress) throws CommunicationException, LowLinkException { sendPacket(inPacket); } + // adding layerInfo public void addLayerInfo(String DataType, String Msg){ LayerInfo pingInfo = new LayerInfo(getClass().getName()); *************** *** 223,235 **** } ! public boolean isActive(){ ! return true; ! } ! ! ! protected String getDetails(){ ! return "Interface: "+name; ! } ! protected boolean listen(){ try{ --- 255,260 ---- } ! ! // starts listening on transport protected boolean listen(){ try{ *************** *** 242,245 **** --- 267,276 ---- } + case Corba: + { + CORBAServer = new WANCorbaServer(this, name); + return true; + } + case SocketTCP: case SocketUDP: *************** *** 252,255 **** --- 283,287 ---- } }catch(Exception e){ + addLayerInfo("Wan interface", "Unknown error during connect: " + e.toString()); e.printStackTrace(); } *************** *** 258,261 **** --- 290,294 ---- + // starts connecting through transport public boolean connect(){ try{ *************** *** 276,279 **** --- 309,326 ---- return true; } + case Corba: + { + if(Service == ""){ + //Error + return false; + } + CORBAClient = new WANCorbaClient(this); + CORBAClient.Connect(Service); + CORBAClient.setServiceName(name); + + connected = true; + + return true; + } case SocketTCP: if(!server){ *************** *** 294,297 **** --- 341,345 ---- } + // closing transport protected void close(){ try{ *************** *** 303,309 **** RMIServer = null; break; case SocketTCP: case SocketUDP: ! if(s!= null) s.Close(); s = null; break; --- 351,367 ---- RMIServer = null; break; + case Corba: + if(CORBAServer != null){ + CORBAServer.close(); + CORBAServer = null; + } + if(CORBAClient != null){ + CORBAClient.close(); + CORBAClient = null; + } + break; case SocketTCP: case SocketUDP: ! if(s!= null) s.close(); s = null; break; Index: WANCorbaServer.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/WANCorbaServer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WANCorbaServer.java 10 Nov 2007 13:25:39 -0000 1.1 --- WANCorbaServer.java 19 Nov 2007 15:10:28 -0000 1.2 *************** *** 11,14 **** --- 11,20 ---- class WANCorbaImpl extends WANCorbaPOA { private ORB orb; + WANNetworkInterface parentInterface; + + public WANCorbaImpl(WANNetworkInterface inParentInterface){ + super(); + parentInterface = inParentInterface; + } public void setORB(ORB orb_val) { *************** *** 17,24 **** public void receivePacket (String inPacket){ System.out.println(inPacket); } public void setServiceName (String inService){ ! System.out.println(inService); } --- 23,37 ---- public void receivePacket (String inPacket){ + parentInterface.addLayerInfo("Wan interface", "Recieved packet from remote peer."); + try{ + parentInterface.receivePacket(inPacket); + }catch(Exception e){ + parentInterface.addLayerInfo("Wan interface", "LowLink Exception: " + e.toString()); + } System.out.println(inPacket); } public void setServiceName (String inService){ ! parentInterface.addLayerInfo("Wan interface", "Recieved peer service name " + inService); ! parentInterface.setConnService(inService); } *************** *** 32,40 **** public class WANCorbaServer { ORB orb; ! public WANCorbaServer(String name) { ! String args[] = {"",""}; orb = ORB.init(args, null); ! WANCorbaServerHandler wh = new WANCorbaServerHandler(orb, name); wh.start(); } --- 45,56 ---- public class WANCorbaServer { ORB orb; + WANNetworkInterface parentInterface; ! public WANCorbaServer(WANNetworkInterface inParentInterface, String name) { ! parentInterface = inParentInterface; ! String args[] = {"","-ORBInitialPort","1050","-ORBInitialHost","localhost"}; ! parentInterface.addLayerInfo("Wan interface", "Starting CORBA Server..."); orb = ORB.init(args, null); ! WANCorbaServerHandler wh = new WANCorbaServerHandler(orb, name, parentInterface); wh.start(); } *************** *** 42,45 **** --- 58,62 ---- public void close(){ if(orb!=null){ + parentInterface.addLayerInfo("Wan interface", "Shutting down CORBA Server..."); orb.shutdown(false); orb = null; *************** *** 49,54 **** class WANCorbaServerHandler extends Thread { ORB orb; ! WANCorbaServerHandler(ORB orb, String name) { try{ this.orb = orb; --- 66,75 ---- class WANCorbaServerHandler extends Thread { ORB orb; + boolean error; + WANNetworkInterface parentInterface; ! WANCorbaServerHandler(ORB orb, String name, WANNetworkInterface inParentInterface) { ! parentInterface = inParentInterface; ! error = false; try{ this.orb = orb; *************** *** 56,60 **** rootpoa.the_POAManager().activate(); ! WANCorbaImpl wImpl = new WANCorbaImpl(); wImpl.setORB(orb); --- 77,81 ---- rootpoa.the_POAManager().activate(); ! WANCorbaImpl wImpl = new WANCorbaImpl(parentInterface); wImpl.setORB(orb); *************** *** 70,84 **** NameComponent path[] = ncRef.to_name( name ); ncRef.rebind(path, href); } catch (Exception e) { e.printStackTrace(System.out); } } ! public void run() { try{ orb.run(); }catch (Exception e) { e.printStackTrace(System.out); } --- 91,115 ---- NameComponent path[] = ncRef.to_name( name ); ncRef.rebind(path, href); + + parentInterface.addLayerInfo("Wan interface", "Registered in NameService as " + name); } catch (Exception e) { + parentInterface.addLayerInfo("Wan interface", "Error during register in NameService as " + name + "; error: " + e.toString()); + error = true; e.printStackTrace(System.out); } } ! public void run() { ! if(error){ ! parentInterface.DOWN(); ! return; ! } try{ orb.run(); }catch (Exception e) { + parentInterface.addLayerInfo("Wan interface", "Error in CORBA Server: " + e.toString()); + parentInterface.DOWN(); e.printStackTrace(System.out); } Index: WANSocket.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/WANSocket.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WANSocket.java 10 Nov 2007 13:25:38 -0000 1.4 --- WANSocket.java 19 Nov 2007 15:10:28 -0000 1.5 *************** *** 74,78 **** } ! public void Close(){ try{ if(s!=null){ --- 74,78 ---- } ! public void close(){ try{ if(s!=null){ *************** *** 98,104 **** } ! public void sendPacket(Packet inPacket){ if(c != null){ ! out.println(inPacket.toBytes()); out.flush(); } --- 98,104 ---- } ! public void sendPacket(String inPacket){ if(c != null){ ! out.println(inPacket); out.flush(); } |