summaryrefslogtreecommitdiff
path: root/src/testing/topo.sh
blob: 090c3053f7ebd0a9da8a583384e85fb380734882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash

declare -A K_PLUGIN
declare -A R_TCP
declare -A R_UDP
declare -A P_PLUGIN

extract_attributes()
{
    line_key=$1
    line=$2
    
    if [ "$line_key" = "P" ]
    then
	n=$(echo $line|cut -d \| -f 1|awk -F: '{print $2}')
	echo $n
	m=$(echo $line|cut -d \| -f 1|awk -F: '{print $3}')
	echo $m
    else
	number=$(echo $line|cut -d \| -f 1| cut -c 2-|cut -d : -f 2 )
	echo $number
    fi
	
    
    nf=$(echo $line|awk -F: '{print NF}')
    for ((i=2;i<=$nf;i++))
    do
	entry=$(echo $line |awk -v i=$i -F\| '{print $i}')
	key=$(echo $entry|cut -d { -f 2|cut -d } -f 1|cut -d : -f 1)
	value=$(echo $entry|cut -d { -f 2|cut -d } -f 1|cut -d : -f 2)
	if [ "$key" = "tcp_port" ]
	then
	    echo tcp port: $value
	    R_TCP[$number]=$value
	elif [ "$key" = "udp_port" ]
	then
	    echo udp port: $value
	    R_UDP[$number]=$value
	elif [ "$key" = "plugin" ]
	then
	    echo plugin: $value
	    echo $line_key
	    if [ "$line_key" = "P" ]
	    then
		P_PLUGIN[$n,$m]=$value
		echo $n $m ${P_PLUGIN[$n,$m]}
	    elif [ "$line_key" = "K" ]
	    then
		K_PLUGIN[$number]=$value
	    fi
	fi
    done
}

read_topology(){
    
local filename=$1
while read line; do
# reading each line
    echo $line
    key=$(cut -c -1 <<< $line)
    if [ "$key" = "M" ]
    then
	LOCAL_M=$(cut -d : -f 2 <<< $line)
	echo $LOCAL_M
    elif [ "$key" = "N" ]
    then
	GLOBAL_N=$(cut -d : -f 2 <<< $line)
	echo $GLOBAL_N
    elif [ "$key" = "X" ]
    then
	KNOWN=$(cut -d : -f 2 <<< $line)
	echo $KNOWN
    elif [ "$key" = "T" ]
    then
	PLUGIN=$(cut -d : -f 2 <<< $line)
	echo $PLUGIN
    elif [ "$key" = "K" ]
    then
	echo know node
	extract_attributes $key $line
    elif [ "$key" = "R" ]
    then
	echo router
	extract_attributes $key $line
    elif [ "$key" = "P" ]
    then
	echo node
	extract_attributes $key $line
    fi
done < $filename
}