Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convenient scripts to generate platforms
[simgrid.git] / tools / platform_generation / tiers.pm
1 #!/usr/bin/perl -w
2 use strict;
3
4 use graph_viz;
5 use graph_tbx;
6
7
8 ##############################
9 ###    GRAPH GENERATION    ###
10 ##############################
11
12 sub parse_tiers_file {
13     my($filename);
14     my($nodes,$edges)=G_new_graph(); # a new graph...
15     $filename=shift or die "Need a tiers file!";
16     
17     open INPUT, $filename;
18
19     my($state) = 0;
20     my($line);
21
22     while(defined($line=<INPUT>)){
23         if($line =~ /^\# NODES/) {$state=1; next;}
24         if($line =~ /^\# EDGES/) {$state=2; next;}
25         if(($line=~/^\s*$/) || ($line=~/^\#/)) {next;}
26         if ($state==1){ # Getting the nodes
27             # Node X Y Type (0 = WAN, 1 = MAN, 2 = LAN)
28             my($name,$X,$Y,$type) = split(/\s+/,$line);
29             G_new_node($nodes,$edges,$name);
30             $$nodes{$name}{X} = $X;
31             $$nodes{$name}{Y} = $Y;
32             $$nodes{$name}{type} = $type;
33             $$nodes{$name}{using_path} = [];
34             print STDERR "$name [$X $Y $type]\n";
35             next;
36         }
37         if ($state==2){ # Getting the edges 
38             # From   To    Delay Band-  From  To    State (1:active, 2:redundant
39             # Node  Node         width  Type  Type  3:internetwork, 4:red.inter.)
40             my($src,$dst,$delay,$bw,$srct,$dstt,$type) = split(/\s+/,$line);
41             if(!defined($$nodes{$src}{out}{$dst})) {
42                 # links are symetric and simple
43                 my($edge_count)=G_connect($nodes,$edges,$src,$dst);
44                 $$edges{$edge_count}{delay} = $delay;
45                 $$edges{$edge_count}{bw} = $bw;
46                 $$edges{$edge_count}{type} = $type;
47                 $$edges{$edge_count}{using_path} = [];
48                 print STDERR "($dst,$src) [$delay $bw $type]\n";
49             }
50             next;
51         }
52     }
53     close(INPUT);
54     return($nodes,$edges);
55 }
56
57 sub generate_host_list{
58     my($nodes,$edges,$proba) = @_;
59     my($u);
60     my(@host_list)=();
61     foreach $u (sort (keys %$nodes)){ # type 0 = WAN, 1 = MAN, 2 = LAN
62         if(($$nodes{$u}{type}==2) && (rand() < $proba)) { 
63             $$nodes{$u}{host}=1;
64             push @host_list, $u;
65         } else { 
66             $$nodes{$u}{host}=0;
67         }
68     }
69     @host_list = sort {$a <=> $b} @host_list;
70     return(\@host_list);
71 }
72
73 1;