anchor.diff:  
   -define(util, diameter_util).
   
  --define(BASE,    diameter_gen_base_rfc3588).
  --define(APPL_ID, diameter_gen_base_rfc3588:id()).
  --define(SUCCESS, 2001).  %% DIAMETER_SUCCESS
  -
  -%% Addresses for the local and remote diameter nodes. The values don't
  -%% matter since we're faking transport.
  --define(LOCALHOST, {127,0,0,1}).
  --define(REMOTEHOST, {10,0,0,1}).
  -
  --define(CAPS, #diameter_caps{origin_host = "node.innan.com",
  -                             origin_realm = "innan.com",
  -                             host_ip_address = [?LOCALHOST],
  -                             vendor_id = 1022,
  -                             product_name = "remote",
  -                             auth_application_id = [?APPL_ID]}).
  -
  --define(APPL, #diameter_app{alias = ?MODULE,
  -                            dictionary = ?BASE,
  -                            module = [?MODULE],
  -                            init_state = now(),
  -                            id = ?APPL_ID,
  -                            mutable = false}).
  -
  -%% Service record maintained by our faked service process.
  --define(SERVICE, #diameter_service{pid = self(),
  -                                   capabilities = ?CAPS,
  -                                   applications = [?APPL]}).
  +-define(BASE, ?DIAMETER_DICT_COMMON).
  +-define(REALM, "erlang.org").
  +-define(ADDR, {127,0,0,1}).
  +
  +%% Config for diameter:start_service/2.
  +-define(SERVICE(Name),
  +        [{'Origin-Host', Name ++ "." ++ ?REALM},
  +         {'Origin-Realm', ?REALM},
  +         {'Host-IP-Address', [?ADDR]},
  +         {'Vendor-Id', 42},
  +         {'Product-Name', "OTP/diameter"},
  +         {'Auth-Application-Id', [?DIAMETER_APP_ID_COMMON]},
  +         {application, [{alias, Name},
  +                        {dictionary, ?BASE},
  +                        {module, ?MODULE}]}]).
   
   %% Watchdog timer as a callback.
   -define(WD(T), {?MODULE, id, [T]}).
  
positive.code:     %%                 NumDWA == 2          NumDWA++
      %%                                      Failback()           OKAY
      %%
      %% Now the watchdog should require three received DWA's before
      %% taking the connection back up. The first DWR is sent directly
      %% after capabilities exchange so it should take no more than two
      %% watchdog expiries.
      ?RECV({connection_up, WPid2, _}, 2, WdL, WdH).
  
  %% ===========================================================================
  
  %% Start the fake transport process. From diameter's point of view
  %% it's started when diameter calls start/3. We start it before this
  %% happens since we use the same fake transport each time diameter
  %% calls start/3. The process lives and dies with the test case.
  start(Config) ->
      Pid = self(),
      spawn(fun() -> loop(init(Pid, Config)) end).
  
  %% Transport start from diameter. This may be called multiple times
  %% depending on the testcase.
  start({Type, _Ref}, #diameter_service{}, Pid) ->
      Ref = make_ref(),
      MRef = erlang:monitor(process, Pid),
      Pid ! {start, self(), Type, Ref},
      {Ref, TPid} = receive
                        {Ref, _} = T ->
                            T;
                        {'DOWN', MRef, process, _, _} = T ->
                            T
                    end,
      erlang:demonitor(MRef, [flush]),
      {ok, TPid}.
  
  %% id/1
  
  id(T) ->
      T.
  
  %% ===========================================================================
  
  choose(true, X, _)  -> X;
  choose(false, _, X) -> X.
  
  %% run/1
  %%
  %% A more useful badmatch in case of failure.
  
  run([F|A]) ->
      ok = try
               apply(?MODULE, F, A),
               ok
           catch
               E:R ->
                   {A, E, R, erlang:get_stacktrace()}
           end.
  
  %% now_diff/2
  
negative.code:                                  F_ <- [fun(T__) -> T__ end,
                                          fun(T__) -> ?WD(T__) end]]]).
  
  %% Watchdog timer of the misbehaving peer.
  -define(PEER_WD, 10000).
  
  %% Receive a watchdog event within a specified time.
  -define(EVENT(T, Tmo),
          receive #diameter_event{info = T} -> now()
          after Tmo -> ?ERROR({timeout, Tmo})
          end).
  
  %% Receive an event in a given number of watchdogs, plus or minus
  %% half. Note that the call to now_diff assumes left to right
  %% evaluation order.
  -define(EVENT(T, N, WdL, WdH),
          [?ERROR({received, _Elapsed_, _LowerBound_, N, WdL})
           || _UpperBound_ <- [(N)*(WdH) + (WdH) div 2],
              _Elapsed_    <- [now_diff(now(), ?EVENT(T, _UpperBound_))],
              _LowerBound_ <- [(N)*(WdL) - (WdL) div 2],
              _Elapsed_ =< _LowerBound_*1000]).
  
  -define(EVENT(T, N, Wd),
          ?EVENT(T, N, Wd, Wd)).
  
  %% A timeout that ensures one watchdog. The ensure only one watchdog
  %% requires (Wd + 2000) + 1000 < 2*(Wd - 2000) ==> 7000 < Wd for the
  