anchor.diff:  %% Internal functions
   %% ===================================================================
   
  -run(Config, Options) ->
  +run(Case, Config, Options) ->
       lists:foreach(
           fun(EvalNumber) ->
  -            configure(
  +            Nodes = start(
  +              Case,
                 Config,
                 [{evaluation_number, EvalNumber} | Options]
               ),
  -            wait_for_completion()
  +            wait_for_completion(Nodes),
  +            stop(Nodes)
           end,
           lists:seq(1, ?EVAL_NUMBER)
       ),
   
       %% Generate transmission plot.
       lasp_plot_gen:generate_plots(Options),
  -    ok.
  -
  -configure(Config, Options) ->
  -    lager:info("Configuring nodes; options: ~p", [Options]),
  -    Nodes = proplists:get_value(nodes, Config),
  -
  -    %% Settings ads
  -    lager:info("Enabling ad client simulation on all nodes."),
  -    lists:foreach(fun(Node) ->
  -                        ok = rpc:call(Node, lasp_config, set,
  -                                      [ad_counter_simulation_client, true])
  -                  end, Nodes),
  -
  -    %% Setting number of impressions
  -    lager:info("Setting the number of impressions: ~p", [?IMPRESSION_NUMBER]),
  -    lists:foreach(fun(Node) ->
  -                        ok = rpc:call(Node, lasp_config, set,
  -                                      [simulation_event_number, ?IMPRESSION_NUMBER])
  -                  end, Nodes),
  -
  -    lager:info("Enabling ad server simulation on local node."),
  -    ok = lasp_config:set(ad_counter_simulation_server, true),
  -
  -
  -    %% Setting mode
  -    Mode = proplists:get_value(mode, Options),
  -
  -    lager:info("Setting mode locally: ~p", [Mode]),
  -    ok = lasp_config:set(mode, Mode),
  -
  -    lager:info("Setting mode on all nodes: ~p", [Mode]),
  -    lists:foreach(fun(Node) ->
  -                        ok = rpc:call(Node, lasp_config, set,
  -                                      [mode, Mode])
  -                  end, Nodes),
  -
  -
  -    %% Setting broadcast
  -    Broadcast = proplists:get_value(broadcast, Options),
  -
  -    lager:info("Setting broadcast locally: ~p", [Broadcast]),
  -    ok = lasp_config:set(broadcast, Broadcast),
  -
  -    lager:info("Setting broadcast on all nodes: ~p", [Broadcast]),
  -    lists:foreach(fun(Node) ->
  -                        ok = rpc:call(Node, lasp_config, set,
  -                                      [broadcast, Broadcast])
  -                  end, Nodes),
  -
  -
  -    %% Setting evaluation identifier
  -    EvalIdentifier = proplists:get_value(evaluation_identifier, Options),
  -
  -    lager:info("Setting evaluation identifier locally: ~p", [EvalIdentifier]),
  -    ok = lasp_config:set(evaluation_identifier, EvalIdentifier),
  -
  -    lager:info("Setting evaluation identifier on all nodes: ~p", [EvalIdentifier]),
  -    lists:foreach(fun(Node) ->
  -                        ok = rpc:call(Node, lasp_config, set,
  -                                      [evaluation_identifier, EvalIdentifier])
  -                  end, Nodes),
  -
  -
  -    %% Setting evaluation number
  -    EvalNumber = proplists:get_value(evaluation_number, Options),
  -
  -    lager:info("Setting evaluation number locally: ~p", [EvalNumber]),
  -    ok = lasp_config:set(evaluation_number, EvalNumber),
  -
  -    lager:info("Setting evaluation number on all nodes: ~p", [EvalNumber]),
  -    lists:foreach(fun(Node) ->
  -                        ok = rpc:call(Node, lasp_config, set,
  -                                      [evaluation_number, EvalNumber])
  -                  end, Nodes),
  -
  -
  -    %% Enabling instrumentation
  -    lager:info("Enabling instrumentation locally."),
  -    ok = lasp_config:set(instrumentation, true),
  -
  -    lager:info("Enabling instrumentation on all nodes."),
  -    lists:foreach(fun(Node) ->
  +
  +    ok.
  +
  +%% @private
  +start(Case, Config, Options) ->
  +    %% Launch distribution for the test runner.
  +    ct:pal("Launching Erlang distribution..."),
  +
  +    os:cmd(os:find_executable("epmd") ++ " -daemon"),
  +    {ok, Hostname} = inet:gethostname(),
  +    case net_kernel:start([list_to_atom("runner@" ++ Hostname), shortnames]) of
  +        {ok, _} ->
  +            ok;
  +        {error, {already_started, _}} ->
  +            ok
  +    end,
  +
  +    %% Three nodes.
  +    SlavesToStart = [rita, sue, bob],
  +
  +    %% Start all three nodes.
  +    InitializerFun = fun(Name) ->
  +                            ct:pal("Starting node: ~p", [Name]),
  +
  +                            NodeConfig = [{monitor_master, true},
  +                                          {startup_functions, [{code, set_path, [codepath()]}]}],
  +
  +                            case ct_slave:start(Name, NodeConfig) of
  +                                {ok, Node} ->
  +                                    Node;
  +                                Error ->
  +                                    ct:fail(Error)
  +                            end
  +                     end,
  +    [First|_] = Nodes = lists:map(InitializerFun, SlavesToStart),
  +
  +    %% Load Lasp on all of the nodes.
  +    LoaderFun = fun(Node) ->
  +                            ct:pal("Loading lasp on node: ~p", [Node]),
  +
  +                            PrivDir = proplists:get_value(priv_dir, Config),
  +                            NodeDir = filename:join([PrivDir, Node, Case]),
  +
  +                            %% Manually force sasl loading, and disable the logger.
  +                            ok = rpc:call(Node, application, load, [sasl]),
  +                            ok = rpc:call(Node, application, set_env,
  +                                          [sasl, sasl_error_logger, false]),
  +                            ok = rpc:call(Node, application, start, [sasl]),
  +
  +                            ok = rpc:call(Node, application, load, [plumtree]),
  +                            ok = rpc:call(Node, application, load, [partisan]),
  +                            ok = rpc:call(Node, application, load, [lager]),
  +                            ok = rpc:call(Node, application, load, [lasp]),
  +                            ok = rpc:call(Node, application, set_env, [sasl,
  +                                                                       sasl_error_logger,
  +                                                                       false]),
  +                            ok = rpc:call(Node, application, set_env, [lasp,
  +                                                                       instrumentation,
  +                                                                       false]),
  +                            ok = rpc:call(Node, application, set_env, [lager,
  +                                                                       log_root,
  +                                                                       NodeDir]),
  +                            ok = rpc:call(Node, application, set_env, [plumtree,
  +                                                                       plumtree_data_dir,
  +                                                                       NodeDir]),
  +                            ok = rpc:call(Node, application, set_env, [plumtree,
  +                                                                       peer_service,
  +                                                                       partisan_peer_service]),
  +                            ok = rpc:call(Node, application, set_env, [plumtree,
  +                                                                       broadcast_exchange_timer,
  +                                                                       ?EXCHANGE_TIMER]),
  +                            ok = rpc:call(Node, application, set_env, [plumtree,
  +                                                                       broadcast_mods,
  +                                                                       [lasp_plumtree_broadcast_distribution_backend]]),
  +                            ok = rpc:call(Node, application, set_env, [lasp,
  +                                                                       data_root,
  +                                                                       NodeDir])
  +                     end,
  +    lists:map(LoaderFun, Nodes),
  +
  +    %% Configure Lasp settings.
  +    ConfigureFun = fun(Node) ->
  +                        %% Always enable advertisement clients on the nodes.
  +                        ok = rpc:call(Node, lasp_config, set,
  +                                      [ad_counter_simulation_client, true]),
  +
  +                        %% Configure number of impressions.
  +                        ok = rpc:call(Node, lasp_config, set,
  +                                      [simulation_event_number, ?IMPRESSION_NUMBER]),
  +
  +                        %% Configure who should be the server.
  +                        case First of
  +                            Node ->
  +                                ok = rpc:call(Node, lasp_config, set,
  +                                              [ad_counter_simulation_server, true]);
  +                            _ ->
  +                                ok
  +                        end,
  +
  +                        %% Configure the operational mode.
  +                        Mode = proplists:get_value(mode, Options),
  +                        ok = rpc:call(Node, lasp_config, set, [mode, Mode]),
  +
  +                        %% Configure broadcast settings.
  +                        Broadcast = proplists:get_value(broadcast, Options),
  +                        ok = rpc:call(Node, lasp_config, set,
  +                                      [broadcast, Broadcast]),
  +
  +                        %% Configure evaluation identifier.
  +                        EvalIdentifier = proplists:get_value(evaluation_identifier, Options),
  +                        ok = rpc:call(Node, lasp_config, set,
  +                                      [evaluation_identifier, EvalIdentifier]),
  +
  +                        %% Configure evaluation number.
  +                        EvalNumber = proplists:get_value(evaluation_number, Options),
  +                        ok = rpc:call(Node, lasp_config, set,
  +                                      [evaluation_number, EvalNumber]),
  +
  +                        %% Configure instrumentation.
                           ok = rpc:call(Node, lasp_config, set,
                                         [instrumentation, true])
  -                  end, Nodes),
  -
  -
  -    lager:info("Restarting Lasp on all nodes."),
  -    lists:foreach(fun(Node) ->
  -                        lager:info("Restarting ~p and re-joining...", [Node]),
  -                        ok = rpc:call(Node, application, stop, [lasp]),
  -                        {ok, _} = rpc:call(Node, application, ensure_all_started,
  -                                           [lasp]),
  -                        RunnerNode = lasp_support:runner_node(),
  -                        lasp_support:join_to(Node, RunnerNode),
  -                        timer:sleep(4000),
  -                        {ok, Members} = rpc:call(Node, lasp_peer_service, members, []),
  -                        {ok, LocalMembers} = lasp_peer_service:members(),
  -                        lager:info("* Members; ~p", [Members]),
  -                        lager:info("* LocalMembers; ~p", [LocalMembers])
  -                  end, Nodes),
  -
  -    ok.
  -
  -wait_for_completion() ->
  +                   end,
  +    lists:map(ConfigureFun, Nodes),
  +
  +    ct:pal("Starting lasp."),
  +
  +    StartFun = fun(Node) ->
  +                        %% Start lasp.
  +                        {ok, _} = rpc:call(Node, application, ensure_all_started, [lasp])
  +                   end,
  +    lists:map(StartFun, Nodes),
  +
  +    ct:pal("Custering nodes..."),
  +    ClusterFun = fun(Node) ->
  +                        PeerPort = rpc:call(Node,
  +                                            partisan_config,
  +                                            get,
  +                                            [peer_port, ?PEER_PORT]),
  +                        ct:pal("Joining node: ~p to ~p at port ~p",
  +                               [Node, First, PeerPort]),
  +                        ok = rpc:call(First,
  +                                      lasp_peer_service,
  +                                      join,
  +                                      [{Node, {127, 0, 0, 1}, PeerPort}])
  +                   end,
  +    lists:map(ClusterFun, Nodes),
  +
  +    ct:pal("Lasp fully initialized."),
  +
  +    ok.
  +
  +%% @private
  +stop(Nodes) ->
  +    StopFun = fun(Node) ->
  +                      ct_slave:stop(Node)
  +              end,
  +    lists:foreach(StopFun, Nodes),
  +    ok.
  +
  +%% @private
  +wait_for_completion(_Nodes) ->
       timer:sleep(?EVAL_TIME).
  +
  +%% @private
  +codepath() ->
  +    lists:filter(fun filelib:is_dir/1, code:get_path()).
  
positive.code:     ok.
  
  state_based_with_aae_test(Config) ->
      run(Config, [{mode, state_based},
                   {broadcast, false},
                   {evaluation_identifier, state_based_with_aae}]),
      ok.
  
  state_based_with_aae_and_tree_test(Config) ->
      run(Config, [{mode, state_based},
                   {broadcast, true},
                   {evaluation_identifier, state_based_with_aae_and_tree}]),
      ok.
  
  delta_based_with_aae_test(Config) ->
      run(Config, [{mode, delta_based},
                   {broadcast, false},
                   {evaluation_identifier, delta_based_with_aae}]),
      ok.
  
  
  
negative.code: %% tests
  -compile([export_all]).
  
  -include("lasp.hrl").
  
  -include_lib("common_test/include/ct.hrl").
  -include_lib("eunit/include/eunit.hrl").
  -include_lib("kernel/include/inet.hrl").
  
  -define(EXCHANGE_TIMER, 120).
  
  %% ===================================================================
  %% common_test callbacks
  %% ===================================================================
  
  init_per_suite(_Config) ->
      _Config.
  
  end_per_suite(_Config) ->
      _Config.
  
  init_per_testcase(Case, _Config) ->
      ct:pal("Beginning test case ~p", [Case]),
  
      _Config.
  
  end_per_testcase(Case, _Config) ->
      ct:pal("Ending test case ~p", [Case]),
  
      _Config.
  
  all() ->
      [
  