[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip/ospf OSPF.java,1.10,1.11
Status: Beta
Brought to you by:
darkkey
From: Alouette <alo...@us...> - 2006-02-27 21:33:41
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ospf In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4749/core/protocolsuite/tcp_ip/ospf Modified Files: OSPF.java Log Message: Index: OSPF.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/ospf/OSPF.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** OSPF.java 27 Feb 2006 17:33:45 -0000 1.10 --- OSPF.java 27 Feb 2006 21:33:33 -0000 1.11 *************** *** 523,528 **** */ ! ! --- 523,537 ---- */ ! // declaration element of vector, store path and correct length ! public class PathStorage ! { ! public int PathCost; // path length ! public Vector PathVertex = new Vector(); // vertex correct composing this path ! PathStorage() ! { ! PathCost = 0; ! } ! ! } // End PathStorage *************** *** 538,552 **** ! // declaration element of vector, store path and correct length ! public class PathStorage ! { ! public int PathCost; // path length ! public Vector PathVertex = new Vector(); // vertex correct composing this path ! PathStorage() ! { ! PathCost = 0; ! } ! ! } // End PathStorage --- 547,552 ---- ! ! *************** *** 574,579 **** --- 574,593 ---- + + } + public PathStorage MyClone(PathStorage inpar1) + { + PathStorage tmp = new PathStorage(); + tmp.PathCost=inpar1.PathCost; + int i=0; + for (i=0; i<inpar1.PathVertex.size(); i++) + { + tmp.PathVertex.insertElementAt(inpar1.PathVertex.elementAt(i),i); + } + return tmp; + } + public void SPF() { *************** *** 589,595 **** } } - // add all path consist of one rib to vector - // save current order :path with least cost add first } --- 603,668 ---- } } + // add all start path + i=0; + int flag=0; + while ((i<Graf.size()) && (flag==0)) // find line router neighbors + { + if (((RouterRecord)Graf.elementAt(i)).RouterID.equals(this.RouterID)) + { + flag=1; + int j=0; + for (j=0; j<((RouterRecord)Graf.elementAt(i)).NeighborRouters.size(); j++) + { + PathStorage a = new PathStorage(); // create element + a.PathVertex.insertElementAt(this.RouterID, 1); // add router + a.PathVertex.insertElementAt( ((RouterLink)((RouterRecord)Graf.elementAt(i)).NeighborRouters.elementAt(j)).RouterID, a.PathVertex.size()+1); + a.PathCost= ((RouterLink)((RouterRecord)Graf.elementAt(i)).NeighborRouters.elementAt(j)).Metric; + solution.AddPath(a); + } + } + i++; + } + // start algorithm + while (solution.Pathfinder.size()!=0) // not all path operated + { + PathStorage t = (PathStorage)solution.Pathfinder.elementAt(1); + if (!solution.Operated.contains(t.PathVertex.lastElement())) + { + // this path is shortest + // update table !!! + + // go on this path add all neighbors of last vertex + i=0; + int flag2=0; + while ((i<Graf.size()) && (flag2==0)) // find line router neighbors + { + if (((RouterRecord)Graf.elementAt(i)).RouterID.equals(t.PathVertex.lastElement())) + { + flag2=1; + int k=0; + for (k=0; k<((RouterRecord)Graf.elementAt(i)).NeighborRouters.size(); k++) + { + PathStorage v = MyClone(t); + v.PathVertex.insertElementAt(((RouterLink)((RouterRecord)Graf.elementAt(i)).NeighborRouters.elementAt(k)).RouterID, v.PathVertex.size()+1); + v.PathCost+=((RouterLink)((RouterRecord)Graf.elementAt(i)).NeighborRouters.elementAt(k)).Metric; + solution.AddPath(v); + } + + + } + i++; + } + + + + solution.Operated.addElement(t.PathVertex.lastElement()); //add vertex to vector + solution.Missed.removeElement(t.PathVertex.lastElement()); // remove vertex from vector + } + + solution.Pathfinder.removeElement(t); // remove path this step + } + + } |