<commit_before>#!/usr/bin/env bash

batfish_confirm_analyze() {
   BATFISH_CONFIRM=batfish_confirm batfish_analyze $@
}
export -f batfish_confirm_analyze
   
batfish_analyze() {
   local TEST_RIG_RELATIVE=$1
   shift
   local PREFIX=$1
   shift
   local MACHINES="$@"
   local NUM_MACHINES="$#"
   if [ -z "$PREFIX" ]; then
         echo "ERROR: Empty prefix" 1>&2
         return 1
   fi
   if [ -z "$BATFISH_CONFIRM" ]; then
      local BATFISH_CONFIRM=true
   fi
   local OLD_PWD=$PWD
   if [ "$(echo $TEST_RIG_RELATIVE | head -c1)" = "/" ]; then
      local TEST_RIG=$TEST_RIG_RELATIVE
   else
      local TEST_RIG=$PWD/$TEST_RIG_RELATIVE
   fi
   local QUERY_PATH=$OLD_PWD/$PREFIX-query
   local MPI_QUERY_BASE_PATH=$QUERY_PATH/multipath-inconsistency-query

   local BGP=$OLD_PWD/$PREFIX-bgp
   local DP_DIR=$OLD_PWD/$PREFIX-dp
   local DUMP_DIR=$OLD_PWD/$PREFIX-dump
   local FLOWS=$OLD_PWD/$PREFIX-flows
   local INDEP_SERIAL_DIR=$OLD_PWD/$PREFIX-indep
   local NODE_SET_PATH=$OLD_PWD/$PREFIX-node-set
   local OSPF=$OLD_PWD/$PREFIX-ospf
   local POLICY=$OLD_PWD/$PREFIX-policy
   local REACH_PATH=$OLD_PWD/$PREFIX-reach.smt2
   local ROUTES=$OLD_PWD/$PREFIX-routes
   local VENDOR_SERIAL_DIR=$OLD_PWD/$PREFIX-vendor
   local WORKSPACE=batfish-$USER-$PREFIX

   echo "Parse vendor configuration files and serialize vendor structures"
   $BATFISH_CONFIRM && { batfish_serialize_vendor $TEST_RIG $VENDOR_SERIAL_DIR || return 1 ; }

   echo "Parse vendor structures and serialize vendor-independent structures"
   $BATFISH_CONFIRM && { batfish_serialize_independent $VENDOR_SERIAL_DIR $INDEP_SERIAL_DIR || return 1 ; }

   echo "Compute the fixed point of the control plane"
   $BATFISH_CONFIRM && { batfish_compile $WORKSPACE $TEST_RIG $DUMP_DIR $INDEP_SERIAL_DIR || return 1 ; }

   echo "Query bgp"
   $BATFISH_CONFIRM && { batfish_query_bgp $BGP $WORKSPACE || return 1 ; }

   echo "Query ospf"
   $BATFISH_CONFIRM && { batfish_query_ospf $OSPF $WORKSPACE || return 1 ; }

   echo "Query policy"
   $BATFISH_CONFIRM && { batfish_query_policy $POLICY $WORKSPACE || return 1 ; }

   echo "Query routes"
   $BATFISH_CONFIRM && { batfish_query_routes $ROUTES $WORKSPACE || return 1 ; }

   echo "Query data plane predicates"
   $BATFISH_CONFIRM && { batfish_query_data_plane $WORKSPACE $DP_DIR || return 1 ; }

   echo "Extract z3 reachability relations"
   $BATFISH_CONFIRM && { batfish_generate_z3_reachability $DP_DIR $INDEP_SERIAL_DIR $REACH_PATH $NODE_SET_PATH || return 1 ; }

   echo "Find multipath-inconsistent packet constraints"
   $BATFISH_CONFIRM && { batfish_find_multipath_inconsistent_packet_constraints $REACH_PATH $QUERY_PATH $MPI_QUERY_BASE_PATH $NODE_SET_PATH "$MACHINES" "$NUM_MACHINES" || return 1 ; }

   echo "Generate multipath-inconsistency concretizer queries"
   $BATFISH_CONFIRM && { batfish_generate_multipath_inconsistency_concretizer_queries $MPI_QUERY_BASE_PATH $NODE_SET_PATH "$MACHINES" "$NUM_MACHINES"|| return 1 ; }

   echo "Inject concrete packets into network model"
   $BATFISH_CONFIRM && { batfish_inject_packets $WORKSPACE $QUERY_PATH $DUMP_DIR || return 1 ; }

   echo "Query flow results from LogicBlox"
   $BATFISH_CONFIRM && { batfish_query_flows $FLOWS $WORKSPACE || return 1 ; }
}
export -f batfish_analyze

batfish_find_multipath_inconsistent_packet_constraints() {
   batfish_date
   echo ": START: Find inconsistent packet constraints"
   batfish_expect_args 6 $# || return 1
   local REACH_PATH=$1<commit_msg>renamed batfish_analyze to batfish_analyze_multipath<commit_after>#!/usr/bin/env bash

batfish_confirm_analyze_multipath() {
   BATFISH_CONFIRM=batfish_confirm batfish_analyze_multipath $@
}
export -f batfish_confirm_analyze_multipath
   
batfish_analyze_multipath() {
   local TEST_RIG_RELATIVE=$1
   shift
   local PREFIX=$1
   shift
   local MACHINES="$@"
   local NUM_MACHINES="$#"
   if [ -z "$PREFIX" ]; then
         echo "ERROR: Empty prefix" 1>&2
         return 1
   fi
   if [ -z "$BATFISH_CONFIRM" ]; then
      local BATFISH_CONFIRM=true
   fi
   local OLD_PWD=$PWD
   if [ "$(echo $TEST_RIG_RELATIVE | head -c1)" = "/" ]; then
      local TEST_RIG=$TEST_RIG_RELATIVE
   else
      local TEST_RIG=$PWD/$TEST_RIG_RELATIVE
   fi
   local QUERY_PATH=$OLD_PWD/$PREFIX-query
   local MPI_QUERY_BASE_PATH=$QUERY_PATH/multipath-inconsistency-query

   local BGP=$OLD_PWD/$PREFIX-bgp
   local DP_DIR=$OLD_PWD/$PREFIX-dp
   local DUMP_DIR=$OLD_PWD/$PREFIX-dump
   local FLOWS=$OLD_PWD/$PREFIX-flows
   local INDEP_SERIAL_DIR=$OLD_PWD/$PREFIX-indep
   local NODE_SET_PATH=$OLD_PWD/$PREFIX-node-set
   local OSPF=$OLD_PWD/$PREFIX-ospf
   local POLICY=$OLD_PWD/$PREFIX-policy
   local REACH_PATH=$OLD_PWD/$PREFIX-reach.smt2
   local ROUTES=$OLD_PWD/$PREFIX-routes
   local VENDOR_SERIAL_DIR=$OLD_PWD/$PREFIX-vendor
   local WORKSPACE=batfish-$USER-$PREFIX

   echo "Parse vendor configuration files and serialize vendor structures"
   $BATFISH_CONFIRM && { batfish_serialize_vendor $TEST_RIG $VENDOR_SERIAL_DIR || return 1 ; }

   echo "Parse vendor structures and serialize vendor-independent structures"
   $BATFISH_CONFIRM && { batfish_serialize_independent $VENDOR_SERIAL_DIR $INDEP_SERIAL_DIR || return 1 ; }

   echo "Compute the fixed point of the control plane"
   $BATFISH_CONFIRM && { batfish_compile $WORKSPACE $TEST_RIG $DUMP_DIR $INDEP_SERIAL_DIR || return 1 ; }

   echo "Query bgp"
   $BATFISH_CONFIRM && { batfish_query_bgp $BGP $WORKSPACE || return 1 ; }

   echo "Query ospf"
   $BATFISH_CONFIRM && { batfish_query_ospf $OSPF $WORKSPACE || return 1 ; }

   echo "Query policy"
   $BATFISH_CONFIRM && { batfish_query_policy $POLICY $WORKSPACE || return 1 ; }

   echo "Query routes"
   $BATFISH_CONFIRM && { batfish_query_routes $ROUTES $WORKSPACE || return 1 ; }

   echo "Query data plane predicates"
   $BATFISH_CONFIRM && { batfish_query_data_plane $WORKSPACE $DP_DIR || return 1 ; }

   echo "Extract z3 reachability relations"
   $BATFISH_CONFIRM && { batfish_generate_z3_reachability $DP_DIR $INDEP_SERIAL_DIR $REACH_PATH $NODE_SET_PATH || return 1 ; }

   echo "Find multipath-inconsistent packet constraints"
   $BATFISH_CONFIRM && { batfish_find_multipath_inconsistent_packet_constraints $REACH_PATH $QUERY_PATH $MPI_QUERY_BASE_PATH $NODE_SET_PATH "$MACHINES" "$NUM_MACHINES" || return 1 ; }

   echo "Generate multipath-inconsistency concretizer queries"
   $BATFISH_CONFIRM && { batfish_generate_multipath_inconsistency_concretizer_queries $MPI_QUERY_BASE_PATH $NODE_SET_PATH "$MACHINES" "$NUM_MACHINES"|| return 1 ; }

   echo "Inject concrete packets into network model"
   $BATFISH_CONFIRM && { batfish_inject_packets $WORKSPACE $QUERY_PATH $DUMP_DIR || return 1 ; }

   echo "Query flow results from LogicBlox"
   $BATFISH_CONFIRM && { batfish_query_flows $FLOWS $WORKSPACE || return 1 ; }
}
export -f batfish_analyze_multipath

batfish_find_multipath_inconsistent_packet_constraints() {
   batfish_date
   echo ": START: Find inconsistent packet constraints"
   batfish_expect_args 6 $# || return 1
   local REACH_PATH=$1
{'fraction_non_alphanumeric': 0.09710949736579809, 'fraction_numerical': 0.007119464616260857, 'mean_word_length': 4.692058346839546, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1831255', 'n_tokens_mistral': 2653, 'n_tokens_neox': 2578, 'n_words': 516}