Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ac90cc9581 | ||
![]() |
f4e0747e59 | ||
![]() |
313c51b76b | ||
![]() |
996c9fc346 | ||
![]() |
04c6618a68 | ||
![]() |
fa261c3042 | ||
![]() |
f9ae5db9f6 | ||
![]() |
3f97f9d8ac |
5 changed files with 166 additions and 104 deletions
|
@ -1,43 +1,60 @@
|
|||
package main;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.graphstream.graph.Edge;
|
||||
import org.graphstream.graph.Graph;
|
||||
import org.graphstream.graph.implementations.SingleGraph;
|
||||
import org.graphstream.ui.layout.springbox.EdgeSpring;
|
||||
import org.graphstream.ui.swingViewer.basicRenderer.EdgeRenderer;
|
||||
import org.graphstream.ui.util.EdgePoints;
|
||||
|
||||
import structure.Grid;
|
||||
import structure.MyGraph;
|
||||
import structure.Router;
|
||||
import structure.*;
|
||||
|
||||
/**
|
||||
* Main class
|
||||
* @author loic, adama, othmane, saad
|
||||
*
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
/**
|
||||
* Main
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Grid g=new Grid(Grid.Protocol.AODV);
|
||||
|
||||
// Build Graph for graphstream
|
||||
MyGraph gr=new MyGraph("Routage Oportuniste", g);
|
||||
gr.display();
|
||||
Grid g=new Grid(Grid.Protocol.AODV); // Graph for AODV
|
||||
Grid g2=new Grid(Grid.Protocol.DSDV); // Graph for DSDV
|
||||
Grid g3=new Grid(Grid.Protocol.CUSTOM); // Graph for custom
|
||||
|
||||
MyGraph gD=new MyGraph("AODV", g); // GUI for g
|
||||
MyGraph g2D=new MyGraph("DSDV", g2); // GUI for g2
|
||||
MyGraph g3D=new MyGraph("CUSTOM", g3); // GUI for g3
|
||||
|
||||
// Display all graph
|
||||
gD.display();
|
||||
g2D.display();
|
||||
g3D.display();
|
||||
|
||||
|
||||
// Update Graph
|
||||
while(true){
|
||||
for(int i=0;i<20;i++){
|
||||
|
||||
// Sleep
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Change radio conditions
|
||||
g.buildEdgeWithRandomWeigth();
|
||||
System.out.println("Update !");
|
||||
gr.update();
|
||||
g2.buildEdgeWithRandomWeigth();
|
||||
g3.buildEdgeWithRandomWeigth();
|
||||
|
||||
// Update graph on GUI
|
||||
gD.update();
|
||||
g2D.update();
|
||||
g3D.update();
|
||||
|
||||
// Display current debMoy for each graph
|
||||
System.out.println("AODV :"+g.getDebitMoy() + " DSDV :"+g2.getDebitMoy()+" CUSTOM :"+g3.getDebitMoy());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
BIN
resources/Graph.png
Normal file
BIN
resources/Graph.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
|
@ -1,25 +1,26 @@
|
|||
package structure;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* Grid structure
|
||||
* @author loic, adama
|
||||
*
|
||||
*/
|
||||
public class Grid {
|
||||
|
||||
// Define protocole name
|
||||
public enum Protocol {
|
||||
AODV, DSDV, CUSTOM
|
||||
}
|
||||
|
||||
private ArrayList<Router> routers=new ArrayList<>();
|
||||
private ArrayList<ArrayList<Integer>> links=new ArrayList<>();
|
||||
|
||||
|
||||
public ArrayList<ArrayList<Integer>> links=new ArrayList<>();
|
||||
private int bestLink;
|
||||
private Protocol protocol;
|
||||
private int counterCUSTOM=5;
|
||||
private Random rand = new Random();
|
||||
private final int maxWeight=100;
|
||||
|
||||
|
||||
private Random rand = new Random(); // Init rand
|
||||
int debitTotal=0,nbmesure=0; // To compute debit moyen
|
||||
|
||||
|
||||
|
||||
|
@ -33,11 +34,11 @@ public class Grid {
|
|||
this.routers.add(new Router());
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.buildEdgeWithRandomWeigth();
|
||||
|
||||
this.buildPath();
|
||||
|
||||
//Build fixed link
|
||||
//this.buildPath();
|
||||
|
||||
this.protocol=protocol;
|
||||
|
||||
|
@ -45,10 +46,13 @@ public class Grid {
|
|||
case AODV:
|
||||
this.bestLink=this.getBestLinkIndex();
|
||||
break;
|
||||
case DSDV:
|
||||
case CUSTOM:
|
||||
this.bestLink=this.getBestLinkIndex();
|
||||
break;
|
||||
case DSDV:
|
||||
// Change radio conditions 100 times
|
||||
HashMap<Integer,Integer> currentBestLink=new HashMap<>();
|
||||
for(int i=0;i<100000;i++){
|
||||
for(int i=0;i<100;i++){
|
||||
int current=this.getBestLinkIndex();
|
||||
if(currentBestLink.containsKey(current)){
|
||||
currentBestLink.put(current, currentBestLink.get(current)+1);
|
||||
|
@ -58,8 +62,8 @@ public class Grid {
|
|||
}
|
||||
this.buildEdgeWithRandomWeigth();
|
||||
}
|
||||
// Get Best Link
|
||||
Set<Integer> entryTMP = currentBestLink.keySet();
|
||||
|
||||
int max=currentBestLink.get(entryTMP.iterator().next());
|
||||
int maxId=0;
|
||||
entryTMP = currentBestLink.keySet();
|
||||
|
@ -71,12 +75,8 @@ public class Grid {
|
|||
max=entry;
|
||||
maxId=entryId;
|
||||
}
|
||||
|
||||
System.out.println("Id : "+ entryId + " max "+ entry);
|
||||
|
||||
}
|
||||
this.bestLink=maxId;
|
||||
System.out.println("Retenu :"+maxId);
|
||||
break;
|
||||
|
||||
|
||||
|
@ -85,34 +85,45 @@ public class Grid {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Build the 3x3 links with random weight
|
||||
*/
|
||||
public void buildEdgeWithRandomWeigth(){
|
||||
// First line
|
||||
this.buildLinkWithRandomWeight(routers.get(0), routers.get(1));
|
||||
this.buildLinkWithRandomWeight(routers.get(1), routers.get(2));
|
||||
this.buildLinkWithRandomWeight(routers.get(0), routers.get(1), 100);
|
||||
this.buildLinkWithRandomWeight(routers.get(1), routers.get(2),100);
|
||||
|
||||
// Second line
|
||||
this.buildLinkWithRandomWeight(routers.get(3), routers.get(4));
|
||||
this.buildLinkWithRandomWeight(routers.get(4), routers.get(5));
|
||||
this.buildLinkWithRandomWeight(routers.get(3), routers.get(4),100);
|
||||
this.buildLinkWithRandomWeight(routers.get(4), routers.get(5),50);
|
||||
|
||||
// Third line
|
||||
this.buildLinkWithRandomWeight(routers.get(6), routers.get(7));
|
||||
this.buildLinkWithRandomWeight(routers.get(7), routers.get(8));
|
||||
this.buildLinkWithRandomWeight(routers.get(6), routers.get(7),100);
|
||||
this.buildLinkWithRandomWeight(routers.get(7), routers.get(8),60);
|
||||
|
||||
// First column
|
||||
this.buildLinkWithRandomWeight(routers.get(0), routers.get(3));
|
||||
this.buildLinkWithRandomWeight(routers.get(3), routers.get(6));
|
||||
this.buildLinkWithRandomWeight(routers.get(0), routers.get(3),80);
|
||||
this.buildLinkWithRandomWeight(routers.get(3), routers.get(6),100);
|
||||
|
||||
// Second column
|
||||
this.buildLinkWithRandomWeight(routers.get(1), routers.get(4));
|
||||
this.buildLinkWithRandomWeight(routers.get(4), routers.get(7));
|
||||
this.buildLinkWithRandomWeight(routers.get(1), routers.get(4),100);
|
||||
this.buildLinkWithRandomWeight(routers.get(4), routers.get(7),10);
|
||||
|
||||
// Third column
|
||||
this.buildLinkWithRandomWeight(routers.get(2), routers.get(5));
|
||||
this.buildLinkWithRandomWeight(routers.get(5), routers.get(8));
|
||||
this.buildLinkWithRandomWeight(routers.get(2), routers.get(5),100);
|
||||
this.buildLinkWithRandomWeight(routers.get(5), routers.get(8),100);
|
||||
|
||||
this.buildPath();
|
||||
|
||||
//System.out.println(this.links.get(this.getBestLinkByProtocol()));
|
||||
this.debitTotal+=this.getMaxBottleneck(this.links.get(this.getBestLinkByProtocol()));
|
||||
this.nbmesure++;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build all paths (with chained router id)
|
||||
*/
|
||||
private void buildPath(){
|
||||
|
||||
// Link1
|
||||
|
@ -172,12 +183,21 @@ public class Grid {
|
|||
}
|
||||
|
||||
|
||||
private void buildLinkWithRandomWeight(Router router1, Router router2){
|
||||
router1.buildLink(router2, rand.nextInt(this.maxWeight));
|
||||
/**
|
||||
* Build link with a random weight
|
||||
* @param router1 router 1 to link to router 2
|
||||
* @param router2 router 2 to link to router 1
|
||||
* @param pMoy max weight
|
||||
*/
|
||||
private void buildLinkWithRandomWeight(Router router1, Router router2, int pMoy){
|
||||
router1.buildLink(router2, rand.nextInt(pMoy));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the best link by bottleneck
|
||||
* @return
|
||||
*/
|
||||
public int getBestLinkIndex(){
|
||||
int currentBestLink=0;
|
||||
int currentBestLinkBottleneck=0;
|
||||
|
@ -194,7 +214,12 @@ public class Grid {
|
|||
}
|
||||
|
||||
|
||||
private int getMaxBottleneck(ArrayList<Integer> link){
|
||||
/**
|
||||
* Get the bottleneck of the link
|
||||
* @param link
|
||||
* @return
|
||||
*/
|
||||
public int getMaxBottleneck(ArrayList<Integer> link){
|
||||
int max=this.getWeigthOfLink(link.get(0), link.get(1));
|
||||
for(int j=1;j<link.size()-1;j++){
|
||||
int currentMax=this.getWeigthOfLink(link.get(j), link.get(j+1));
|
||||
|
@ -206,11 +231,19 @@ public class Grid {
|
|||
return max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the weight of a link
|
||||
* @param router1
|
||||
* @param router2
|
||||
* @return
|
||||
*/
|
||||
private int getWeigthOfLink(int router1,int router2){
|
||||
return this.routers.get(router1).getWeight(this.routers.get(router2));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print infos
|
||||
*/
|
||||
public void printLinkWeight(){
|
||||
for(int i=0;i<this.links.size();i++){
|
||||
ArrayList<Integer> link=this.links.get(i);
|
||||
|
@ -219,13 +252,18 @@ public class Grid {
|
|||
System.out.print(this.getWeigthOfLink(link.get(j), link.get(j+1)) + " ");
|
||||
}
|
||||
System.out.println(" Goulot :"+this.getMaxBottleneck(link));
|
||||
//System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check if a link is part of an edge
|
||||
* @param link
|
||||
* @param src
|
||||
* @param dest
|
||||
* @return
|
||||
*/
|
||||
public boolean isEdgeOfLink(ArrayList<Integer>link, Router src, Router dest){
|
||||
for(int j=0;j<link.size()-1;j++){
|
||||
Router current=this.routers.get(link.get(j));
|
||||
|
@ -255,22 +293,34 @@ public class Grid {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Getter for grid
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<Router> getGrid() {
|
||||
return routers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setter for grid
|
||||
* @param grid
|
||||
*/
|
||||
public void setGrid(ArrayList<Router> grid) {
|
||||
this.routers = grid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Getter for links
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<ArrayList<Integer>> getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setter for links
|
||||
* @param links
|
||||
*/
|
||||
public void setLinks(ArrayList<ArrayList<Integer>> links) {
|
||||
this.links = links;
|
||||
}
|
||||
|
@ -281,11 +331,12 @@ public class Grid {
|
|||
* @return the bestLinkByProtocol
|
||||
*/
|
||||
public int getBestLinkByProtocol() {
|
||||
|
||||
if(this.protocol==Protocol.CUSTOM){
|
||||
this.counterCUSTOM--;
|
||||
if(this.counterCUSTOM==0){
|
||||
this.bestLink=this.getBestLinkIndex();
|
||||
this.counterCUSTOM=5;
|
||||
this.counterCUSTOM=2;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -293,7 +344,13 @@ public class Grid {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Getter for debitMoy
|
||||
* @return
|
||||
*/
|
||||
public int getDebitMoy(){
|
||||
return this.debitTotal/this.nbmesure;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2,27 +2,32 @@ package structure;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import org.graphstream.graph.Edge;
|
||||
import org.graphstream.graph.Graph;
|
||||
import org.graphstream.graph.Node;
|
||||
import org.graphstream.graph.*;
|
||||
import org.graphstream.graph.implementations.SingleGraph;
|
||||
import org.graphstream.ui.layout.springbox.EdgeSpring;
|
||||
import org.graphstream.ui.swingViewer.basicRenderer.EdgeRenderer;
|
||||
import org.graphstream.ui.util.EdgePoints;
|
||||
|
||||
|
||||
/**
|
||||
* Class for display graph with GraphStream
|
||||
* @author loic, adama
|
||||
*
|
||||
*/
|
||||
public class MyGraph extends SingleGraph{
|
||||
|
||||
|
||||
// Grid associate to the graph
|
||||
private Grid grid;
|
||||
|
||||
private int miss=0;
|
||||
private int success=0;
|
||||
|
||||
|
||||
/**
|
||||
* Build a graph with a grid
|
||||
*
|
||||
* @param title
|
||||
* @param grid
|
||||
*/
|
||||
public MyGraph(String title, Grid grid) {
|
||||
super(title);
|
||||
// Allow CSS on view
|
||||
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
|
||||
|
||||
// Set graph CSS
|
||||
this.addAttribute("ui.stylesheet", "url('resources/style.css')");
|
||||
|
||||
|
@ -60,20 +65,13 @@ public class MyGraph extends SingleGraph{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Build edges
|
||||
*/
|
||||
public void buildEdges(){
|
||||
|
||||
/*Iterator<Edge> edges=this.getEdgeIterator();
|
||||
while(edges.hasNext()){
|
||||
Edge edge=edges.next();
|
||||
this.removeEdge(edge);
|
||||
}*/
|
||||
|
||||
for(Router r : this.grid.getGrid()){
|
||||
|
||||
String current=r.name;
|
||||
|
||||
|
||||
HashMap<Router, Integer> relier=r.getLinks();
|
||||
Set<Router> k=relier.keySet();
|
||||
Iterator<Router> i=k.iterator();
|
||||
|
@ -86,14 +84,14 @@ public class MyGraph extends SingleGraph{
|
|||
toAdd.setAttribute("ui.label", relier.get(currentRouter));
|
||||
}
|
||||
catch(Exception e){
|
||||
// System.out.println("Bug de merde.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update best link on screen
|
||||
*/
|
||||
public void showBestLink(){
|
||||
ArrayList<Integer> bestLink=this.grid.getLinks().get(this.grid.getBestLinkByProtocol());
|
||||
for(int i=0;i<bestLink.size();i++){
|
||||
|
@ -105,7 +103,6 @@ public class MyGraph extends SingleGraph{
|
|||
Edge edge=edges.next();
|
||||
|
||||
if(i<(bestLink.size()-1)){
|
||||
int destIndex=bestLink.get(i+1);
|
||||
String src=this.grid.getGrid().get(bestLink.get(i)).name;
|
||||
String dest=this.grid.getGrid().get(bestLink.get(i+1)).name;
|
||||
if((edge.getNode0().getId().equals(src) && edge.getNode1().getId().equals(dest))||(edge.getNode1().getId().equals(src) && edge.getNode0().getId().equals(dest))){
|
||||
|
@ -118,6 +115,9 @@ public class MyGraph extends SingleGraph{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all the graph on screen
|
||||
*/
|
||||
public void update(){
|
||||
// Reset color
|
||||
Iterator<Edge> edges=this.getEdgeIterator();
|
||||
|
@ -143,19 +143,8 @@ public class MyGraph extends SingleGraph{
|
|||
edge.setAttribute("ui.label", relier.get(currentRouter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(this.grid.getBestLinkByProtocol()==this.grid.getBestLinkIndex()){
|
||||
this.success++;
|
||||
}
|
||||
else{
|
||||
this.miss++;
|
||||
}
|
||||
System.out.println("Success = " + this.success + " Miss = " + this.miss + " try number :"+(this.success+this.miss)) ;
|
||||
|
||||
//Build bestLink
|
||||
this.showBestLink();
|
||||
}
|
||||
|
|
@ -22,7 +22,6 @@ public class Router {
|
|||
public void buildLink(Router router, int weight){
|
||||
this.links.remove(router);
|
||||
router.removeLink(this);
|
||||
|
||||
|
||||
this.links.put(router, weight);
|
||||
router.addLink(this, weight);
|
||||
|
|
Loading…
Add table
Reference in a new issue