]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - tests/tests_rtep_fna/test_c_rtep_frsh_fna.c
use frsh.h only, headers mess otherwise
[frescor/fna.git] / tests / tests_rtep_fna / test_c_rtep_frsh_fna.c
1 //----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 by the FRESCOR consortium:
3 //
4 //    Universidad de Cantabria,              SPAIN
5 //    University of York,                    UK
6 //    Scuola Superiore Sant'Anna,            ITALY
7 //    Kaiserslautern University,             GERMANY
8 //    Univ. Politecnica  Valencia,           SPAIN
9 //    Czech Technical University in Prague,  CZECH REPUBLIC
10 //    ENEA                                   SWEDEN
11 //    Thales Communication S.A.              FRANCE
12 //    Visual Tools S.A.                      SPAIN
13 //    Rapita Systems Ltd                     UK
14 //    Evidence                               ITALY
15 //
16 //    See http://www.frescor.org
17 //
18 //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
19 //        in part by the European Union Sixth Framework Programme
20 //        The European Union is not liable of any use that may be
21 //        made of this code.
22 //
23 //
24 //  based on previous work (FSF) done in the FIRST project
25 //
26 //   Copyright (C) 2005  Mälardalen University, SWEDEN
27 //                       Scuola Superiore S.Anna, ITALY
28 //                       Universidad de Cantabria, SPAIN
29 //                       University of York, UK
30 //
31 // This file is part of FNA (Frescor Network Adaptation)
32 //
33 // FNA is free software; you can redistribute it and/or modify it
34 // under terms of the GNU General Public License as published by the
35 // Free Software Foundation; either version 2, or (at your option) any
36 // later version.  FNA is distributed in the hope that it will be
37 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
38 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 // General Public License for more details. You should have received a
40 // copy of the GNU General Public License along with FNA; see file
41 // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
42 // Cambridge, MA 02139, USA.
43 //
44 // As a special exception, including FNA header files in a file,
45 // instantiating FNA generics or templates, or linking other files
46 // with FNA objects to produce an executable application, does not
47 // by itself cause the resulting executable application to be covered
48 // by the GNU General Public License. This exception does not
49 // however invalidate any other reasons why the executable file might be
50 // covered by the GNU Public License.
51 // -----------------------------------------------------------------------
52
53 /*
54  * test_c_rtep_frsh_fna.c
55  *
56  * Goal:
57  *
58  * The goal of this program is to test the RTEP functions defined at frsh_fna.h
59  * which is the public part of frsh_fna.h. The interface of this public part
60  * is dependent of the underlying network protocol. We are not trying here to
61  * make a very intense test but a simple and basic one to check the correct
62  * behaviour of the functions.
63  *
64  * Algorithm:
65  *
66  * First we check the conversions between frsh and rtep addresses and streams.
67  * Then, we check the renegotiation functions for the period of the internal
68  * negotiation messages. And finally, we check the renegotiation functions for
69  * the internal service thread.
70  *
71  */
72
73 #include <assert.h> // for assert
74 #include <stdio.h> // for printf
75 #include <stdbool.h> // for bool
76
77 #include "frsh.h" // for FRSH_RESOURCE_ID_DEFAULT, frsh_network_address_t, frsh_stream_id_t
78
79 #include "rtep_fna.h" // for rtep_fna_operations.fna_init
80 #include "rtep.h" // for rtep_station_id_t, rtep_channel_t
81 #include "frsh_fna.h" // for frsh_rtep_*
82
83 int main ()
84 {
85     int err;
86     rtep_station_id_t rtep_station = 3;
87     frsh_network_address_t frsh_address;
88     rtep_channel_t in_stream = 7;
89     frsh_stream_id_t out_stream;
90     struct timespec neg_period = {2,0};
91     struct timespec get_period = {0,0};
92 //     struct timespec rtep_serv_thread_budget = {1,0};
93 //     struct timespec rtep_serv_thread_period = {5,0};
94 //     bool serv_thread_renegotiation_accepted = false;
95 //     struct timespec current_serv_thread_budget = {0,0};
96 //     struct timespec current_serv_thread_period = {0,0};
97
98     printf("1.- fna_init\n");
99     err=rtep_fna_operations.fna_init(FRSH_RESOURCE_ID_DEFAULT);
100     assert(err == 0);
101
102     printf("2.- frsh_rtep_map_network_address\n");
103     err=frsh_rtep_map_network_address
104             (FRSH_RESOURCE_ID_DEFAULT, rtep_station, &frsh_address);
105     assert(err == 0);
106     printf("rtep_address:%d -> frsh_address:%d\n", rtep_station, frsh_address);
107     assert(rtep_station == frsh_address);
108
109     printf("3.- frsh_rtep_map_stream_id\n");
110     err=frsh_rtep_map_stream_id
111             (FRSH_RESOURCE_ID_DEFAULT, in_stream, &out_stream);
112     assert(err == 0);
113     printf("rtep_channel:%d -> frsh_stream:%d\n", in_stream, out_stream);
114     assert(in_stream == out_stream);
115
116     printf("4.- frsh_rtep_negotiation_messages_vres_renegotiate period\n");
117     err=frsh_rtep_negotiation_messages_vres_get_period
118             (FRSH_RESOURCE_ID_DEFAULT, &get_period);
119     assert(err == 0);
120     printf("period before renegotiation: sec=%d nsec=%d\n",
121             get_period.tv_sec, get_period.tv_nsec);
122
123     err=frsh_rtep_negotiation_messages_vres_renegotiate
124             (FRSH_RESOURCE_ID_DEFAULT, &neg_period);
125     if (err == 0) {
126         printf("renegotiation accepted (period negotiated: sec=%d nsec=%d)\n",
127                neg_period.tv_sec, neg_period.tv_nsec);
128     } else {
129         printf("renegotiation not accepted\n");
130     }
131     assert (err == 0);
132
133     err=frsh_rtep_negotiation_messages_vres_get_period
134             (FRSH_RESOURCE_ID_DEFAULT, &get_period);
135     assert(err == 0);
136     printf("period after renegotiation: sec=%d nsec=%d\n",
137            get_period.tv_sec, get_period.tv_nsec);
138
139 // TODO: uncomment step 5 when internal thread has a frescor contract
140 // printf("5.- frsh_rtep_service_thread_vres_renegotiate\n");
141 //
142 // err=frsh_rtep_service_thread_vres_get_budget_and_period
143 //         (FRSH_RESOURCE_ID_DEFAULT,
144 //             &current_serv_thread_budget,
145 //             &current_serv_thread_period);
146 // assert(err == 0);
147 // printf("service thread budget (before renegotiation): sec=%d nsec=%d\n",
148 //         current_serv_thread_budget.tv_sec,
149 //         current_serv_thread_budget.tv_nsec);
150 // printf("service thread period (before renegotiation): sec=%d nsec=%d\n",
151 //         current_serv_thread_period.tv_sec,
152 //         current_serv_thread_period.tv_nsec);
153 //
154 // err=frsh_rtep_service_thread_vres_renegotiate
155 //         (FRSH_RESOURCE_ID_DEFAULT,
156 //             &rtep_serv_thread_budget,
157 //             &rtep_serv_thread_period,
158 //             &serv_thread_renegotiation_accepted);
159 // assert(err == 0);
160 //
161 // if (serv_thread_renegotiation_accepted) {
162 //     printf("service_thread renegotiation accepted\n");
163 // } else {
164 //     printf("service_thread renegotiation not accepted\n");
165 // }
166 // assert (err == 0);
167 //
168 // err=frsh_rtep_service_thread_vres_get_budget_and_period
169 //         (FRSH_RESOURCE_ID_DEFAULT,
170 //             &current_serv_thread_budget,
171 //             &current_serv_thread_period);
172 // assert(err == 0);
173 // printf("service thread budget (after renegotiation): sec=%d nsec=%d\n",
174 //         current_serv_thread_budget.tv_sec,
175 //         current_serv_thread_budget.tv_nsec);
176 // printf("service thread period (after renegotiation): sec=%d nsec=%d\n",
177 //         current_serv_thread_period.tv_sec,
178 //         current_serv_thread_period.tv_nsec);
179
180     printf("\nEND of the TEST\n");
181     return 0;
182 }