annotate extensions/test_rt_any/test_rt_any.c @ 1235:f937feb72734 1.2.0

Updated copyright information
author Sebastien Decugis <sdecugis@freediameter.net>
date Sat, 14 Sep 2013 18:09:01 +0800
parents 581bbd48524a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
118
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 120
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
118
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
1235
f937feb72734 Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1216
diff changeset
5 * Copyright (c) 2013, WIDE Project and NICT *
118
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 /*
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37 * Test-only extension for routing: gives a random positive score to any candidate peer.
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 */
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 #include <freeDiameter/extension.h>
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 #include <stdlib.h>
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 /* The callback */
1216
581bbd48524a Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents: 741
diff changeset
43 static int tra_out_cb(void * cbdata, struct msg ** pmsg, struct fd_list * candidates)
118
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44 {
1216
581bbd48524a Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents: 741
diff changeset
45 struct msg * msg = *pmsg;
118
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46 struct fd_list * li;
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50 for (li = candidates->next; li != candidates; li = li->next) {
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 struct rtd_candidate *c = (struct rtd_candidate *) li;
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52 c->score = (int)lrand48();
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 }
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 return 0;
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 }
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58 static struct fd_rt_out_hdl * out_hdl = NULL;
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 /* Register the callbacks to the daemon */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 118
diff changeset
61 static int tra_main(char * conffile)
118
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 {
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63 TRACE_ENTRY("%p", conffile);
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 118
diff changeset
64 CHECK_FCT( fd_rt_out_register ( tra_out_cb, NULL, 0 /* we call it late so that it replaces previous scores */, &out_hdl ) );
118
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
65 return 0;
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 }
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 /* Cleanup the callbacks */
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69 void fd_ext_fini(void)
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70 {
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 TRACE_ENTRY();
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 CHECK_FCT_DO( fd_rt_out_unregister ( out_hdl, NULL ), /* continue */ );
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 return ;
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74 }
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75
f6ea40e29f53 New rt_any extension for routing tests in Diameter mesh
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 /* Define the entry point function */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 118
diff changeset
77 EXTENSION_ENTRY("test_rt_any", tra_main);
"Welcome to our mercurial repository"