#!/bin/bash -x echo "Args = $@" usage() { echo "Usage: runmetis [OPTION]..." echo "Generate CCNx metis.cfg file according to the specified links and routes" echo "and then start the metis_daemon with that config. Optionally, this script" echo "can start the metis_daemon with no links and start one or more ccnx_server" echo "processes to provide object data" echo "" echo "OPTIONS:" echo " -h" echo " Show this help message" echo " -r =" echo " Associates the given link alias with the routable" echo " prefix . Can be specified more than once. When this" echo " option is present, all -s options will be ignored." echo " -s =" echo " Run a ccnx_server process on this node that will return the" echo " contents of the object identified by and run" echo " the program to generate the data" echo "" } declare -a servers declare -A ROUTES while getopts ":hs:r:" opt; do case $opt in h) usage exit 0 ;; s) servers=("${servers[@]}" "$OPTARG") ;; r) IFS='=' read -ra ROUTE <<< $OPTARG link=${ROUTE[0]} route=${ROUTE[1]} # Convert link name to uppercase for matching with environment variables link=${link^^} # Either append or set the value in the associative array if [ ${ROUTES[$link]+_} ]; then ROUTES[$link]=${ROUTES[$link]}" $route" else ROUTES[$link]=$route fi servers=() ;; \?) echo "Invalid option: -$OPTARG" >&2 usage exit 1 ;; :) echo "Missing options argument for -$OPTARG" >&2 usage exit 1 ;; esac done shift $((OPTIND - 1)) # Get names of all links declare -a links names=$(env | grep "\(.*\)_NAME") for name in $names; do links=("${links[@]}" $(echo $name | sed -e 's/\(.*\)_NAME=.*/\1/g')) done # Validate routes passed on command line against available links for link in "${!ROUTES[@]}"; do if [[ ! ${links[@]} =~ $link ]]; then echo "Link name specified on the command line ($link) is not availabe in this container" exit 1 fi done # Metis Config File metiscfg=metis.cfg truncate -s 0 $metiscfg # Get local ip localip=$(ifconfig eth0 2>/dev/null | awk '/inet addr:/ {print $2}' | sed 's/addr://') # Start out local ports for connections at 5000 localport=5000 # Add connection and route entries to our metis.cfg for each # outgoing link for link in "${links[@]}"; do ports=$(env | grep "${link}_PORT_" | sed -e "s/${link}_PORT_\([[:digit:]]\+\).*/\1/g") # Remove duplicates ports=$(echo $ports | xargs -n1 | sort -u | xargs) for port in $ports; do if (( $port == 2001 )); then # Ignore the metis control port continue else # Get IP Address of remote listener remoteip=$(printenv "${link}_PORT_${port}_TCP_ADDR") # Add the connection command echo "add connection tcp $link $remoteip $port $localip $((localport++))" >> $metiscfg # Add each route for route in ${ROUTES[$link]}; do echo "add route $link $route 10" >> $metiscfg done fi done done # Finally, add interest connection listener echo "add listener tcp LISTENER $localip 9695" >> $metiscfg echo "add listener tcp LISTENER 127.0.0.1 9695" >> $metiscfg # For debugging, list all the connections and routes we added echo "list connections" >> $metiscfg echo "list routes" >> $metiscfg echo "Running metis..." metis_daemon --daemon --capacity 0 --log all=debug --log-file /var/log/metis.log --config $metiscfg & # Give a few seconds for metis to come up sleep 2 # Run servers echo "Running servers..." for server in "${servers[@]}"; do echo "Server = $server" IFS='=' read -ra SERVER <<< $server lciuri=${SERVER[0]} prog=${SERVER[1]} echo "Running server for ( "$lciuri","$prog" )..." ccnx_server --identity /etc/ccnx/ccnx_keystore.p12 --password 1234 $lciuri "$prog" & done sleep infinity