private NetworkInformation() {
   System.setProperty(
       "org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
   network_graph = new SingleGraph("OpenFlow Network");
   network_graph.addAttribute("ui.quality");
   URL myUrl = null;
   try {
     myUrl = new File("Stylesheet.css").toURI().toURL();
   } catch (MalformedURLException e) {
     e.printStackTrace();
   }
   network_graph.addAttribute("ui.stylesheet", "url('" + myUrl.toString() + "')");
   network_graph.setStrict(false);
   network_graph.setAutoCreate(true);
   switches = new HashMap<String, Switch>();
   links = new HashMap<String, Link>();
   hosts = new HashMap<String, Host>();
   SearchIP = NetworkInformation.Gateway;
   SearchIP = SearchIP.substring(0, SearchIP.indexOf(".0"));
 };
Esempio n. 2
0
  public Graph tree2graph(SimpleNode node) {

    Graph graph = new DefaultGraph("Sample graph");
    graph.setStrict(false);
    graph.addAttribute("ui.stylesheet", style);
    graph.addNode(node.getId()).addAttribute("label", node.getName());
    graph.getNode(node.getId()).addAttribute("ui.class", "root");

    this.iterateGraph(node, graph);

    return graph;
  }
  public void execute() {
    // Toolkit.c
    final Graph graph = new SingleGraph("roberto");
    graph.setStrict(false);
    graph.addAttribute("ui.stylesheet", "node.important {fill-color: red;}");
    graph.addAttribute("ui.quality");
    graph.addAttribute("ui.antialias");

    BaseGenerator gen = null;

    // Between 1 and 3 new links per node added.
    // gen = new BarabasiAlbertGenerator(1);//talvez
    // gen = new DorogovtsevMendesGenerator();//talvez

    // gen = new PointsOfInterestGenerator();//gera desconexo
    // gen = new PreferentialAttachmentGenerator();//parece com lobster
    // gen = new RandomEuclideanGenerator(2);//+-
    // gen = new RandomFixedDegreeDynamicGraphGenerator(200, 9.0,
    // 0.5);//acho que não
    // gen = new WattsStrogatzGenerator(200, 4, 0.1);//+-

    // gen = new ClusterGeneratorOld(200);

    int n = 100;
    // gen = new LobsterGenerator(5, 5);// sim
    // gen = new CustomLobsterGenerator(500, 3, 5);// sim
    // gen = new CustomFlowerSnarkGenerator(100);//sim
    //		 gen = new ClusterGenerator(n, 3, 3); //sim
    // gen = new CustomGridGenerator(110, true, 0.9F, 15, 5);//usado para
    // gen = new WattsStrogatzGenerator(20, 10, 0.1);//pode ser mas tem que
    // rodar 2 vezes

    // gen = new BarabasiAlbertGenerator(1);//talvez - parecido com lobster
    // gen = new DorogovtsevMendesGenerator();//talvez

    gen.setRandomSeed(12345);
    gen.addSink(graph);
    gen.begin();
    while (gen.nextEvents()) ;
    gen.end();
    System.out.println("" + graph.getNodeCount() + " " + graph.getEdgeCount());

    // gen.configureNodes(graph);
    // System.out.println("Amount of important: " + gen.countImportant);

    Viewer viewer = graph.display(true);
    // Layout layoutAlgorithm = new SpringBox();
    // viewer.enableAutoLayout(layoutAlgorithm);
    viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.HIDE_ONLY);

    ViewerListener vl = new MyViewListener(graph, n, 2, gen);
    ViewerPipe fromViewer = viewer.newViewerPipe();
    fromViewer.addViewerListener(vl);
    fromViewer.addSink(graph);

    while (loop) {
      fromViewer.pump(); // or fromViewer.blockingPump();

      try {
        Thread.sleep(100);
      } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }

    // try {
    // Thread.sleep(10000);
    // } catch (InterruptedException e1) {
    // // TODO Auto-generated catch block
    // e1.printStackTrace();
    // }
  }