anchor.diff:  
   %% diameter-specific
   -export([lport/2,
  -         lport/3]).
  +         lport/3,
  +         service/1,
  +         listen/2,
  +         connect/3]).
   
   %% common_test-specific
   -export([write_priv/3,
  -         read_priv/2]).
  +         read_priv/2,
  +         map_priv/3]).
   
   -define(L, atom_to_list).
   
  +%% ---------------------------------------------------------------------------
   %% consult/2
   %%
   %% Extract info from the app/appup file (presumably) of the named
  
positive.code:     {H, [T|Rest]} = lists:split(random:uniform(length(L)) - 1, L),
      s([T|Acc], H ++ Rest).
  
  %% eval/1
  
  eval({M,[F|A]})
    when is_atom(F) ->
  
negative.code:             lp(M, Ref, T-1)
      end.
  
  %% ---------------------------------------------------------------------------
  %% service/1
  %%
  %% Start a new diameter service and return its generated name.
  
  service(Opts) ->
      Name = make_ref(),
  
      case diameter:start_service(Name, Opts) of
          ok ->
              {ok, Name};
          {error, _} = No ->
              No
      end.
  
  %% ---------------------------------------------------------------------------
  %% listen/2
  %%
  %% Add a listening transport on the loopback address and a free port.
  
  listen(SvcName, Prot) ->
      add_transport(SvcName, {listen, transport(Prot, listen)}).
  
  %% ---------------------------------------------------------------------------
  %% connect/3
  %%
  %% Add a connecting transport on and connect to a listening transport
  %% with the specified reference.
  
  connect(SvcName, Prot, LRef) ->
      [PortNr] = lport(Prot, LRef),
      Ref = add_transport(SvcName, {connect, transport(Prot, PortNr)}),
      true = diameter:subscribe(SvcName),
      receive
          {diameter_event, SvcName, {up, Ref, _, _, _}} -> Ref
      after 2000 ->
              error({up, SvcName, Prot, PortNr})
      end.
  
  %% ---------------------------------------------------------------------------
  
  -define(ADDR, {127,0,0,1}).
  
  add_transport(SvcName, T) ->
      {ok, Ref} = diameter:add_transport(SvcName, T),
      Ref.
  
  tmod(tcp) ->
      diameter_tcp;
  tmod(sctp) ->
      diameter_sctp.
  
  transport(Prot, T) ->
      {tag(T), opts(Prot, T)}.
  
  tag(listen = T) ->
      T;
  tag(_PortNr) ->
      connect.
  
  opts(Prot, T) ->
      [{transport_module, tmod(Prot)},
       {transport_config, [{ip, ?ADDR}, {port, 0} | opts(T)]}].
  
  opts(listen) ->
      [];
  opts(PortNr) ->
      [{raddr, ?ADDR}, {rport, PortNr}].
  