101 lines
1.9 KiB
Bash
Executable file
101 lines
1.9 KiB
Bash
Executable file
#!/usr/bin/env zsh
|
|
|
|
marker=19000000
|
|
|
|
typeset -A geo
|
|
typeset -A ixps
|
|
ixps=(
|
|
[nlix]=34307
|
|
[houix]=35920
|
|
[f4ix]=36090
|
|
[kcix]=40542
|
|
[stlix]=46389
|
|
[fogixp]=47498
|
|
[gpc]=51818
|
|
[onix]=57369
|
|
[locix]=202409
|
|
)
|
|
|
|
# this can definitely also be auto detected
|
|
typeset -A ix_presence
|
|
ix_presence=(
|
|
[fra1]="nlix fogixp locix"
|
|
[yto1]="onix"
|
|
[mci1]="houix f4ix kcix stlix gpc"
|
|
)
|
|
|
|
typeset -a filenames
|
|
filenames=(
|
|
transit
|
|
rs
|
|
peer
|
|
downstream
|
|
own
|
|
transit4
|
|
rs4
|
|
peer4
|
|
downstream4
|
|
own4
|
|
)
|
|
|
|
file_prefix="thei.rs/"
|
|
|
|
function get_root_dir {
|
|
local curr=$(dirname $1)
|
|
|
|
printf '%s' $(realpath "$curr/..")
|
|
}
|
|
|
|
function discover_geo {
|
|
local pop_confs=$(find "$root_dir/conf" -type f -name 'const.conf')
|
|
local pop_name geo_code
|
|
|
|
for pop_conf (${(f)pop_confs})
|
|
do
|
|
pop_name=$(_discover_geo_extract_pop "$pop_conf")
|
|
geo_code=$(_discover_geo_grep_code "$pop_conf")
|
|
|
|
geo[$pop_name]=$geo_code
|
|
done
|
|
}
|
|
|
|
function _discover_geo_extract_pop {
|
|
sed -EH 's#.+?/?(\w+)/const\.conf#\1#' <<< "$1"
|
|
}
|
|
|
|
function _discover_geo_grep_code {
|
|
sed -EHn 's#^.*GEO\s*=\s*(\d+).*$#\1#p' $1
|
|
}
|
|
|
|
function community {
|
|
local pop_name=$1
|
|
local geo_code=$2
|
|
local via=$3
|
|
local ix_name=$4
|
|
|
|
for ((i = 0; i < $#filenames; i++)); do
|
|
local filename=${filenames[i+1]}
|
|
if [[ $filename =~ "own.?$" ]] && [[ ! -z $ix_name ]]; then continue; fi
|
|
if [[ $filename =~ "rs.?$" ]] && [[ -z $ix_name ]]; then continue; fi
|
|
|
|
local key=$(( marker + (10 * geo_code) + i))
|
|
local fullpath="${file_prefix}${pop_name}${ix_name:+:$ix_name}:${filename}"
|
|
echo "200242:$key:$via,$fullpath"
|
|
done
|
|
}
|
|
|
|
root_dir=$(get_root_dir $0)
|
|
discover_geo
|
|
|
|
for pop_name geo_code in ${(kv)geo}; do
|
|
community $pop_name $geo_code 0
|
|
|
|
local -a pop_presence=(${=ix_presence[$pop_name]})
|
|
if [[ ! -z $pop_presence ]]; then
|
|
for ix_name in $pop_presence; do
|
|
ix_asn=${ixps[$ix_name]}
|
|
|
|
community $pop_name $geo_code $ix_asn $ix_name
|
|
done
|
|
fi
|
|
done
|