]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/commitdiff
Add 'src/fna/' from commit '493e9e8be9c3761691b96e8366d036d6b3c314fb'
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 27 Jan 2011 13:43:13 +0000 (14:43 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 27 Jan 2011 13:43:13 +0000 (14:43 +0100)
git-subtree-dir: src/fna
git-subtree-mainline: c78e31229e23ee7fad600a405a2621d8076e3784
git-subtree-split: 493e9e8be9c3761691b96e8366d036d6b3c314fb

104 files changed:
1  2 
src/fna/COPYING
src/fna/Changelog
src/fna/INSTALL
src/fna/Makefile
src/fna/Makefile.omk
src/fna/README
src/fna/TODO
src/fna/config.mk_example
src/fna/doc/api_fna_html.tar.gz
src/fna/doc/fna-refman.pdf
src/fna/include/Makefile.omk
src/fna/include/fna.h
src/fna/include/fna_configuration.h
src/fna/include/frsh_fna.h
src/fna/rules.mk
src/fna/src/Makefile
src/fna/src/fna_configuration.c
src/fna/src_frescan/Makefile
src/fna/src_frescan/README
src/fna/src_frescan/TODO
src/fna/src_frescan/frescan.c
src/fna/src_frescan/frescan.h
src/fna/src_frescan/frescan_bwres.c
src/fna/src_frescan/frescan_bwres.h
src/fna/src_frescan/frescan_bwres_analysis.c
src/fna/src_frescan/frescan_bwres_analysis.h
src/fna/src_frescan/frescan_bwres_fna.c
src/fna/src_frescan/frescan_bwres_fna.h
src/fna/src_frescan/frescan_bwres_frsh_fna.c
src/fna/src_frescan/frescan_bwres_messages.c
src/fna/src_frescan/frescan_bwres_messages.h
src/fna/src_frescan/frescan_bwres_mode_change.c
src/fna/src_frescan/frescan_bwres_mode_change.h
src/fna/src_frescan/frescan_bwres_requests.c
src/fna/src_frescan/frescan_bwres_requests.h
src/fna/src_frescan/frescan_bwres_robjs.c
src/fna/src_frescan/frescan_bwres_robjs.h
src/fna/src_frescan/frescan_bwres_threads.c
src/fna/src_frescan/frescan_bwres_threads.h
src/fna/src_frescan/frescan_config.h
src/fna/src_frescan/frescan_data.c
src/fna/src_frescan/frescan_data.h
src/fna/src_frescan/frescan_debug.h
src/fna/src_frescan/frescan_hw_buffer.c
src/fna/src_frescan/frescan_hw_buffer.h
src/fna/src_frescan/frescan_id.c
src/fna/src_frescan/frescan_id.h
src/fna/src_frescan/frescan_packets.c
src/fna/src_frescan/frescan_packets.h
src/fna/src_frescan/frescan_queues.c
src/fna/src_frescan/frescan_queues.h
src/fna/src_frescan/frescan_servers.c
src/fna/src_frescan/frescan_servers.c_posix
src/fna/src_frescan/frescan_servers.h
src/fna/src_frescan/frescan_servers_replenishments.c
src/fna/src_frescan/frescan_servers_replenishments.c_posix
src/fna/src_frescan/frescan_servers_replenishments.h
src/fna/src_frescan/frescan_types.h
src/fna/src_rtep/Makefile
src/fna/src_rtep/rtep_fna.h
src/fna/src_rtep/rtep_fna_c.c
src/fna/src_rtep/rtep_frsh_fna_c.c
src/fna/src_unix/Makefile
src/fna/src_unix/Makefile.omk
src/fna/src_unix/unix_fna.c
src/fna/src_unix/unix_fna.h
src/fna/tests/tests_frescan/Makefile
src/fna/tests/tests_frescan/test_frescan_bwres_cancel_in_master.c
src/fna/tests/tests_frescan/test_frescan_bwres_cancel_in_slave.c
src/fna/tests/tests_frescan/test_frescan_bwres_gn_vs_single_measures.c
src/fna/tests/tests_frescan/test_frescan_bwres_init.c
src/fna/tests/tests_frescan/test_frescan_bwres_messages_req_gn.c
src/fna/tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c
src/fna/tests/tests_frescan/test_frescan_bwres_negotiate_in_master_not_accepted.c
src/fna/tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c
src/fna/tests/tests_frescan/test_frescan_bwres_negotiate_in_slave_not_accepted.c
src/fna/tests/tests_frescan/test_frescan_bwres_negotiate_in_slave_with_sc.c
src/fna/tests/tests_frescan/test_frescan_bwres_negotiate_in_slave_with_sc_and_mode_change.c
src/fna/tests/tests_frescan/test_frescan_bwres_renegotiate_in_master.c
src/fna/tests/tests_frescan/test_frescan_bwres_renegotiate_in_slave.c
src/fna/tests/tests_frescan/test_frescan_bwres_robjs_timedwait.c
src/fna/tests/tests_frescan/test_frescan_bwres_robjs_wait.c
src/fna/tests/tests_frescan/test_frescan_fp_send_basic.c
src/fna/tests/tests_frescan/test_frescan_fp_send_basic_pp_measures.c
src/fna/tests/tests_frescan/test_frescan_fp_send_receive_measures.c
src/fna/tests/tests_frescan/test_frescan_init.c
src/fna/tests/tests_frescan/test_frescan_queues.c
src/fna/tests/tests_frescan/test_frescan_servers_current_budget.c
src/fna/tests/tests_frescan/test_frescan_servers_destroy.c
src/fna/tests/tests_frescan/test_frescan_servers_perceived_commit.c
src/fna/tests/tests_frescan/test_frescan_servers_send_basic.c
src/fna/tests/tests_frescan/test_frescan_servers_send_fast.c
src/fna/tests/tests_frescan/test_frescan_servers_send_receive_measures.c
src/fna/tests/tests_frescan/test_frescan_servers_update.c
src/fna/tests/tests_rtep_fna/Makefile
src/fna/tests/tests_rtep_fna/test_c_rtep_fna.c
src/fna/tests/tests_rtep_fna/test_c_rtep_fna_measurement.c
src/fna/tests/tests_rtep_fna/test_c_rtep_fna_with_frsh.c
src/fna/tests/tests_rtep_fna/test_c_rtep_frsh_fna.c
src/fna/tests/tests_unix_fna/Makefile
src/fna/tests/tests_unix_fna/test_unix_address.c
src/fna/tests/tests_unix_fna/test_unix_fna_send_receive.c
src/fna/tests/tests_unix_fna/test_unix_fna_send_receive_script
src/fna/tests/tests_unix_fna/test_unix_send_receive.c

diff --combined src/fna/COPYING
index 0000000000000000000000000000000000000000,ce822398ca91cba754b40921858b1334ef684de3..ce822398ca91cba754b40921858b1334ef684de3
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,345 +1,345 @@@
+ NOTE:  The text below develops the terms of the GNU General Public
+       License in detail which serves as the basis for distribution of
+       this software.  Please check the source code files themselves
+       for the final exceptions on the GPL license.
+                   GNU GENERAL PUBLIC LICENSE
+                        Version 2, June 1991
+  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+                        59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  Everyone is permitted to copy and distribute verbatim copies
+  of this license document, but changing it is not allowed.
+                             Preamble
+   The licenses for most software are designed to take away your
+ freedom to share and change it.  By contrast, the GNU General Public
+ License is intended to guarantee your freedom to share and change free
+ software--to make sure the software is free for all its users.  This
+ General Public License applies to most of the Free Software
+ Foundation's software and to any other program whose authors commit to
+ using it.  (Some other Free Software Foundation software is covered by
+ the GNU Library General Public License instead.)  You can apply it to
+ your programs, too.
+   When we speak of free software, we are referring to freedom, not
+ price.  Our General Public Licenses are designed to make sure that you
+ have the freedom to distribute copies of free software (and charge for
+ this service if you wish), that you receive source code or can get it
+ if you want it, that you can change the software or use pieces of it
+ in new free programs; and that you know you can do these things.
+   To protect your rights, we need to make restrictions that forbid
+ anyone to deny you these rights or to ask you to surrender the rights.
+ These restrictions translate to certain responsibilities for you if you
+ distribute copies of the software, or if you modify it.
+   For example, if you distribute copies of such a program, whether
+ gratis or for a fee, you must give the recipients all the rights that
+ you have.  You must make sure that they, too, receive or can get the
+ source code.  And you must show them these terms so they know their
+ rights.
+   We protect your rights with two steps: (1) copyright the software, and
+ (2) offer you this license which gives you legal permission to copy,
+ distribute and/or modify the software.
+   Also, for each author's protection and ours, we want to make certain
+ that everyone understands that there is no warranty for this free
+ software.  If the software is modified by someone else and passed on, we
+ want its recipients to know that what they have is not the original, so
+ that any problems introduced by others will not reflect on the original
+ authors' reputations.
+   Finally, any free program is threatened constantly by software
+ patents.  We wish to avoid the danger that redistributors of a free
+ program will individually obtain patent licenses, in effect making the
+ program proprietary.  To prevent this, we have made it clear that any
+ patent must be licensed for everyone's free use or not licensed at all.
+   The precise terms and conditions for copying, distribution and
+ modification follow.
+                     GNU GENERAL PUBLIC LICENSE
+    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+   0. This License applies to any program or other work which contains
+ a notice placed by the copyright holder saying it may be distributed
+ under the terms of this General Public License.  The "Program", below,
+ refers to any such program or work, and a "work based on the Program"
+ means either the Program or any derivative work under copyright law:
+ that is to say, a work containing the Program or a portion of it,
+ either verbatim or with modifications and/or translated into another
+ language.  (Hereinafter, translation is included without limitation in
+ the term "modification".)  Each licensee is addressed as "you".
+ Activities other than copying, distribution and modification are not
+ covered by this License; they are outside its scope.  The act of
+ running the Program is not restricted, and the output from the Program
+ is covered only if its contents constitute a work based on the
+ Program (independent of having been made by running the Program).
+ Whether that is true depends on what the Program does.
+   1. You may copy and distribute verbatim copies of the Program's
+ source code as you receive it, in any medium, provided that you
+ conspicuously and appropriately publish on each copy an appropriate
+ copyright notice and disclaimer of warranty; keep intact all the
+ notices that refer to this License and to the absence of any warranty;
+ and give any other recipients of the Program a copy of this License
+ along with the Program.
+ You may charge a fee for the physical act of transferring a copy, and
+ you may at your option offer warranty protection in exchange for a fee.
+   2. You may modify your copy or copies of the Program or any portion
+ of it, thus forming a work based on the Program, and copy and
+ distribute such modifications or work under the terms of Section 1
+ above, provided that you also meet all of these conditions:
+     a) You must cause the modified files to carry prominent notices
+     stating that you changed the files and the date of any change.
+     b) You must cause any work that you distribute or publish, that in
+     whole or in part contains or is derived from the Program or any
+     part thereof, to be licensed as a whole at no charge to all third
+     parties under the terms of this License.
+     c) If the modified program normally reads commands interactively
+     when run, you must cause it, when started running for such
+     interactive use in the most ordinary way, to print or display an
+     announcement including an appropriate copyright notice and a
+     notice that there is no warranty (or else, saying that you provide
+     a warranty) and that users may redistribute the program under
+     these conditions, and telling the user how to view a copy of this
+     License.  (Exception: if the Program itself is interactive but
+     does not normally print such an announcement, your work based on
+     the Program is not required to print an announcement.)
+ These requirements apply to the modified work as a whole.  If
+ identifiable sections of that work are not derived from the Program,
+ and can be reasonably considered independent and separate works in
+ themselves, then this License, and its terms, do not apply to those
+ sections when you distribute them as separate works.  But when you
+ distribute the same sections as part of a whole which is a work based
+ on the Program, the distribution of the whole must be on the terms of
+ this License, whose permissions for other licensees extend to the
+ entire whole, and thus to each and every part regardless of who wrote it.
+ Thus, it is not the intent of this section to claim rights or contest
+ your rights to work written entirely by you; rather, the intent is to
+ exercise the right to control the distribution of derivative or
+ collective works based on the Program.
+ In addition, mere aggregation of another work not based on the Program
+ with the Program (or with a work based on the Program) on a volume of
+ a storage or distribution medium does not bring the other work under
+ the scope of this License.
+   3. You may copy and distribute the Program (or a work based on it,
+ under Section 2) in object code or executable form under the terms of
+ Sections 1 and 2 above provided that you also do one of the following:
+     a) Accompany it with the complete corresponding machine-readable
+     source code, which must be distributed under the terms of Sections
+     1 and 2 above on a medium customarily used for software interchange; or,
+     b) Accompany it with a written offer, valid for at least three
+     years, to give any third party, for a charge no more than your
+     cost of physically performing source distribution, a complete
+     machine-readable copy of the corresponding source code, to be
+     distributed under the terms of Sections 1 and 2 above on a medium
+     customarily used for software interchange; or,
+     c) Accompany it with the information you received as to the offer
+     to distribute corresponding source code.  (This alternative is
+     allowed only for noncommercial distribution and only if you
+     received the program in object code or executable form with such
+     an offer, in accord with Subsection b above.)
+ The source code for a work means the preferred form of the work for
+ making modifications to it.  For an executable work, complete source
+ code means all the source code for all modules it contains, plus any
+ associated interface definition files, plus the scripts used to
+ control compilation and installation of the executable.  However, as a
+ special exception, the source code distributed need not include
+ anything that is normally distributed (in either source or binary
+ form) with the major components (compiler, kernel, and so on) of the
+ operating system on which the executable runs, unless that component
+ itself accompanies the executable.
+ If distribution of executable or object code is made by offering
+ access to copy from a designated place, then offering equivalent
+ access to copy the source code from the same place counts as
+ distribution of the source code, even though third parties are not
+ compelled to copy the source along with the object code.
+   4. You may not copy, modify, sublicense, or distribute the Program
+ except as expressly provided under this License.  Any attempt
+ otherwise to copy, modify, sublicense or distribute the Program is
+ void, and will automatically terminate your rights under this License.
+ However, parties who have received copies, or rights, from you under
+ this License will not have their licenses terminated so long as such
+ parties remain in full compliance.
+   5. You are not required to accept this License, since you have not
+ signed it.  However, nothing else grants you permission to modify or
+ distribute the Program or its derivative works.  These actions are
+ prohibited by law if you do not accept this License.  Therefore, by
+ modifying or distributing the Program (or any work based on the
+ Program), you indicate your acceptance of this License to do so, and
+ all its terms and conditions for copying, distributing or modifying
+ the Program or works based on it.
+   6. Each time you redistribute the Program (or any work based on the
+ Program), the recipient automatically receives a license from the
+ original licensor to copy, distribute or modify the Program subject to
+ these terms and conditions.  You may not impose any further
+ restrictions on the recipients' exercise of the rights granted herein.
+ You are not responsible for enforcing compliance by third parties to
+ this License.
+   7. If, as a consequence of a court judgment or allegation of patent
+ infringement or for any other reason (not limited to patent issues),
+ conditions are imposed on you (whether by court order, agreement or
+ otherwise) that contradict the conditions of this License, they do not
+ excuse you from the conditions of this License.  If you cannot
+ distribute so as to satisfy simultaneously your obligations under this
+ License and any other pertinent obligations, then as a consequence you
+ may not distribute the Program at all.  For example, if a patent
+ license would not permit royalty-free redistribution of the Program by
+ all those who receive copies directly or indirectly through you, then
+ the only way you could satisfy both it and this License would be to
+ refrain entirely from distribution of the Program.
+ If any portion of this section is held invalid or unenforceable under
+ any particular circumstance, the balance of the section is intended to
+ apply and the section as a whole is intended to apply in other
+ circumstances.
+ It is not the purpose of this section to induce you to infringe any
+ patents or other property right claims or to contest validity of any
+ such claims; this section has the sole purpose of protecting the
+ integrity of the free software distribution system, which is
+ implemented by public license practices.  Many people have made
+ generous contributions to the wide range of software distributed
+ through that system in reliance on consistent application of that
+ system; it is up to the author/donor to decide if he or she is willing
+ to distribute software through any other system and a licensee cannot
+ impose that choice.
+ This section is intended to make thoroughly clear what is believed to
+ be a consequence of the rest of this License.
+   8. If the distribution and/or use of the Program is restricted in
+ certain countries either by patents or by copyrighted interfaces, the
+ original copyright holder who places the Program under this License
+ may add an explicit geographical distribution limitation excluding
+ those countries, so that distribution is permitted only in or among
+ countries not thus excluded.  In such case, this License incorporates
+ the limitation as if written in the body of this License.
+   9. The Free Software Foundation may publish revised and/or new versions
+ of the General Public License from time to time.  Such new versions will
+ be similar in spirit to the present version, but may differ in detail to
+ address new problems or concerns.
+ Each version is given a distinguishing version number.  If the Program
+ specifies a version number of this License which applies to it and "any
+ later version", you have the option of following the terms and conditions
+ either of that version or of any later version published by the Free
+ Software Foundation.  If the Program does not specify a version number of
+ this License, you may choose any version ever published by the Free Software
+ Foundation.
+   10. If you wish to incorporate parts of the Program into other free
+ programs whose distribution conditions are different, write to the author
+ to ask for permission.  For software which is copyrighted by the Free
+ Software Foundation, write to the Free Software Foundation; we sometimes
+ make exceptions for this.  Our decision will be guided by the two goals
+ of preserving the free status of all derivatives of our free software and
+ of promoting the sharing and reuse of software generally.
+                             NO WARRANTY
+   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+ REPAIR OR CORRECTION.
+   12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGES.
+                      END OF TERMS AND CONDITIONS
+             How to Apply These Terms to Your New Programs
+   If you develop a new program, and you want it to be of the greatest
+ possible use to the public, the best way to achieve this is to make it
+ free software which everyone can redistribute and change under these terms.
+   To do so, attach the following notices to the program.  It is safest
+ to attach them to the start of each source file to most effectively
+ convey the exclusion of warranty; and each file should have at least
+ the "copyright" line and a pointer to where the full notice is found.
+     <one line to give the program's name and a brief idea of what it does.>
+     Copyright (C) <year>  <name of author>
+     This program is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published by
+     the Free Software Foundation; either version 2 of the License, or
+     (at your option) any later version.
+     This program is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+     GNU General Public License for more details.
+     You should have received a copy of the GNU General Public License
+     along with this program; if not, write to the Free Software
+     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Also add information on how to contact you by electronic and paper mail.
+ If the program is interactive, make it output a short notice like this
+ when it starts in an interactive mode:
+     Gnomovision version 69, Copyright (C) year name of author
+     Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+     This is free software, and you are welcome to redistribute it
+     under certain conditions; type `show c' for details.
+ The hypothetical commands `show w' and `show c' should show the appropriate
+ parts of the General Public License.  Of course, the commands you use may
+ be called something other than `show w' and `show c'; they could even be
+ mouse-clicks or menu items--whatever suits your program.
+ You should also get your employer (if you work as a programmer) or your
+ school, if any, to sign a "copyright disclaimer" for the program, if
+ necessary.  Here is a sample; alter the names:
+   Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+   `Gnomovision' (which makes passes at compilers) written by James Hacker.
+   <signature of Ty Coon>, 1 April 1989
+   Ty Coon, President of Vice
+ This General Public License does not permit incorporating your program into
+ proprietary programs.  If your program is a subroutine library, you may
+ consider it more useful to permit linking proprietary applications with the
+ library.  If this is what you want to do, use the GNU Library General
+ Public License instead of this License.
diff --combined src/fna/Changelog
index 0000000000000000000000000000000000000000,3209ef037ff9d325669b78f23c82170e0422cc6d..3209ef037ff9d325669b78f23c82170e0422cc6d
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,801 +1,801 @@@
+ 2008-05-03 10:11  sangorrin
+       * Changelog: added Changelog file
+ 2008-05-03 10:10  sangorrin
+       * INSTALL, TODO, doc/TODO, src_frescan/TODO, src_frescan/frescan.c,
+         src_frescan/frescan_data.c, src_frescan/frescan_data.h,
+         tests/tests_frescan/test_frescan_send_basic.c,
+         tests/tests_frescan/test_frescan_servers_send_basic.c: added the
+         SRC param for the fragmentation layer and a INSTALL file
+ 2008-04-23 16:09  sangorrin
+       * src_frescan/frescan.c, src_frescan/frescan_bwres_messages.c,
+         src_frescan/frescan_config.h: found the bug.. actually it was a
+         very serious bug that affected fragmentation of messages.. i
+         forgot to change in a function that frag_id==0 is not for fp
+         messages anymore.. now frag_id==MX_IDS is for fp messages, so we
+         can use the rest 0..MX_IDS-1 for the servers
+ 2008-04-23 09:23  sangorrin
+       * src_frescan/frescan_bwres.c, src_frescan/frescan_bwres.h,
+         src_frescan/frescan_bwres_analysis.c,
+         src_frescan/frescan_bwres_analysis.h,
+         src_frescan/frescan_bwres_messages.c,
+         src_frescan/frescan_bwres_threads.c,
+         tests/tests_frescan/test_frescan_bwres_cancel_in_master.c,
+         tests/tests_frescan/test_frescan_bwres_cancel_in_slave.c,
+         tests/tests_frescan/test_frescan_bwres_renegotiate_in_master.c,
+         tests/tests_frescan/test_frescan_bwres_renegotiate_in_slave.c:
+         added the functions to renegotiate and cancel a contract. TODO:
+         there is a bug when cancelling contracts, reneg async,
+         reserve-commit, spare capacity, measurements
+ 2008-04-22 11:10  sangorrin
+       * src_frescan/frescan_bwres_analysis.c,
+         src_frescan/frescan_config.h: make a simplified utilization
+         analysis for the moment
+ 2008-04-22 09:27  sangorrin
+       * src_frescan/frescan_bwres.c, src_frescan/frescan_bwres.h,
+         src_frescan/frescan_bwres_analysis.c,
+         src_frescan/frescan_bwres_analysis.h,
+         src_frescan/frescan_bwres_fna.c,
+         src_frescan/frescan_bwres_messages.c,
+         src_frescan/frescan_bwres_requests.h,
+         src_frescan/frescan_bwres_threads.c,
+         src_frescan/frescan_config.h, src_frescan/frescan_data.h,
+         src_frescan/frescan_debug.h,
+         tests/tests_frescan/test_frescan_bwres_init.c,
+         tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c,
+         tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c: add
+         the infraestructure for storing the negotiated contracts and
+         performing the analysis through the analysis module. TODO:
+         perform a test with those contracts to admit them. In the end the
+         module implementation could be replaced by the cpu
+         implementation.
+         Spare capacity is not done yet. Now we have to implement
+         negotiation and cancel of contracts.
+ 2008-04-21 17:35  sangorrin
+       * src_frescan/frescan.c, src_frescan/frescan_data.h,
+         src_frescan/frescan_debug.h, src_frescan/frescan_queues.c,
+         src_frescan/frescan_servers.c,
+         src_frescan/frescan_servers.c_posix,
+         src_frescan/frescan_servers.h,
+         src_frescan/frescan_servers_replenishments.c,
+         src_frescan/frescan_servers_replenishments.c_posix,
+         src_frescan/frescan_servers_replenishments.h: michael found an
+         error in the definition of the posix sporadic servers so i
+         replaced them with new rules designed by michael... I still keep
+         them because they are still analyzable (they dont behave like
+         periodic tasks though) to compare them
+ 2008-04-18 10:50  sangorrin
+       * src_frescan/frescan.c, src_frescan/frescan_packets.h,
+         src_frescan/frescan_queues.c,
+         src_frescan/frescan_servers_replenishments.c,
+         src_frescan/frescan_servers_replenishments.h: corrected an error
+         in the sporadic servers... the activation time is the timestamp
+         when the packet is enqueued, not when the frame is sent!!!
+ 2008-04-18 08:50  sangorrin
+       * src_frescan/frescan_bwres.c,
+         src_frescan/frescan_bwres_messages.c,
+         src_frescan/frescan_bwres_requests.c,
+         src_frescan/frescan_bwres_threads.c: tested negotiation in slave
+         and in master.. it seems to work good with the new structures
+         too. And its much simpler and clear! wohooo!! TODO: do the
+         scheduling analysis with the API that is already done but for the
+         moment use a utilization analysis, then allow renegotiations and
+         cancelling of contracts... finally implement modifications to the
+         posix sporadic server... do testing, measures and the
+         deliverable... (the spare capacity will have to wait i guess..)
+ 2008-04-17 18:54  sangorrin
+       * src_frescan/frescan_bwres.c,
+         src_frescan/frescan_bwres_messages.c,
+         src_frescan/frescan_bwres_messages.h,
+         src_frescan/frescan_bwres_requests.h,
+         src_frescan/frescan_bwres_robjs.c,
+         src_frescan/frescan_bwres_threads.c, src_frescan/frescan_debug.h,
+         src_frescan/frescan_servers_replenishments.c: some
+         reorganization... now the acceptor is simpler.. everything goes
+         through requests and these are sent and received directly through
+         the messages module... TODO: sched analysis, test negotiations,
+         then add renegotiations and cancel..
+ 2008-04-17 15:52  sangorrin
+       * src/fna_configuration.c: rename the file
+ 2008-04-17 15:51  sangorrin
+       * tests/tests_frescan/Makefile,
+         tests/tests_frescan/test_frescan_bwres_init.c,
+         tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c,
+         tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c,
+         tests/tests_frescan/test_frescan_bwres_robjs_timedwait.c,
+         tests/tests_frescan/test_frescan_bwres_robjs_wait.c,
+         tests/tests_frescan/test_frescan_replyobj_timedwait.c,
+         tests/tests_frescan/test_frescan_replyobj_wait_signal.c,
+         tests/tests_frescan/test_frescan_servers_send_basic.c: tests
+         adapted to new names.. now the compile.. in makefile i add a
+         target 'tests' to build them all in one shot
+ 2008-04-17 15:31  sangorrin
+       * src_frescan/frescan_bwres.c,
+         src_frescan/frescan_bwres_requests.h,
+         src_frescan/frescan_bwres_threads.c, src_frescan/frescan_data.h,
+         src_frescan/frescan_debug.h: updated everything to the new
+         structure... it compiles ok... next step, make sure that the
+         tests compile, then check that the corresponding messages are
+         sent and find possible bugs (very probable to have forgotten some
+         info in the requests..) and then adapt it to do sched analysis
+ 2008-04-17 10:49  sangorrin
+       * src_frescan/frescan.c, src_frescan/frescan_bwres.c,
+         src_frescan/frescan_bwres_messages.c,
+         src_frescan/frescan_bwres_messages.h,
+         src_frescan/frescan_bwres_requests.c,
+         src_frescan/frescan_bwres_requests.h,
+         src_frescan/frescan_bwres_robjs.c,
+         src_frescan/frescan_bwres_robjs.h,
+         src_frescan/frescan_bwres_threads.c,
+         src_frescan/frescan_bwres_threads.h, src_frescan/frescan_data.h,
+         src_frescan/frescan_reply_objs.c,
+         src_frescan/frescan_reply_objs.h, src_frescan/frescan_requests.c,
+         src_frescan/frescan_requests.h: renamings... redo the request and
+         messages part... also now there will be two threads in each node
+         like in the dtm... still not compile.. i have to finish it in the
+         afternoon
+ 2008-04-16 15:55  sangorrin
+       * src_frescan/frescan.c,
+         src_frescan/frescan_bandwidth_reservation.c,
+         src_frescan/frescan_bandwidth_reservation.h,
+         src_frescan/frescan_bwres.c, src_frescan/frescan_bwres.h,
+         src_frescan/frescan_bwres_analysis.c,
+         src_frescan/frescan_bwres_analysis.h,
+         src_frescan/frescan_bwres_fna.c, src_frescan/frescan_bwres_fna.h,
+         src_frescan/frescan_bwres_frsh_fna.c,
+         src_frescan/frescan_bwres_messages.c,
+         src_frescan/frescan_bwres_messages.h,
+         src_frescan/frescan_bwres_threads.c,
+         src_frescan/frescan_bwres_threads.h, src_frescan/frescan_fna.c,
+         src_frescan/frescan_fna.h, src_frescan/frescan_frsh_fna.c,
+         src_frescan/frescan_negotiation_messages.c,
+         src_frescan/frescan_negotiation_messages.h,
+         src_frescan/frescan_negotiation_threads.c,
+         src_frescan/frescan_negotiation_threads.h,
+         src_frescan/frescan_reply_objects.c,
+         src_frescan/frescan_reply_objects.h,
+         src_frescan/frescan_reply_objs.c,
+         src_frescan/frescan_reply_objs.h, src_frescan/frescan_requests.c,
+         src_frescan/frescan_requests.h,
+         src_frescan/frescan_requests_queue.c,
+         src_frescan/frescan_requests_queue.h,
+         src_frescan/frescan_sched_analysis.c,
+         src_frescan/frescan_sched_analysis.h: renaming
+ 2008-04-16 15:27  sangorrin
+       * src_frescan/frescan_bandwidth_reservation.c,
+         src_frescan/frescan_data.h,
+         src_frescan/frescan_negotiation_messages.c,
+         src_frescan/frescan_negotiation_messages.h,
+         src_frescan/frescan_queues.c,
+         src_frescan/frescan_requests_queue.c,
+         src_frescan/frescan_requests_queue.h: i break the svn for one day
+         to change the name of files, redo the negotiation messages system
+         and implement renegotiations and canceling of contracts
+ 2008-04-15 11:47  sangorrin
+       * tests/tests_frescan/test_frescan_servers_send_basic.c: update
+         values
+ 2008-04-15 11:42  sangorrin
+       * src_frescan/frescan_queues.c: add a lock for the queue structures
+         when dequeued, for th moment is hardwired to network 0
+ 2008-04-15 11:42  sangorrin
+       * src_frescan/frescan.c: this lock was wrong.. it worked because of
+         an error in marte os: if u block after enter in the critical
+         section, the idle task enters unblocking the irqs again. An error
+         should be returned i think
+ 2008-04-15 08:51  sangorrin
+       * src_frescan/frescan_negotiation_messages.c: lock for the (future)
+         negotiation
+ 2008-04-15 08:51  sangorrin
+       * src_frescan/frescan_negotiation_threads.c: net
+ 2008-04-15 08:50  sangorrin
+       * src_frescan/frescan_servers.c: locks for server functions
+ 2008-04-15 08:20  sangorrin
+       * src_frescan/TODO, src_frescan/frescan_sched_analysis.c,
+         src_frescan/frescan_sched_analysis.h: add the modules for the
+         frescan sched analysis with an initial API that we are discussing
+         at the moment so it might change soon... it is not applied yet..
+         TODO: we will need new messages for the spare capacity
+         distribution and structures to apply them at the right moment..
+         this is also ongoing work and research must be done on when is
+         the right moment.
+ 2008-04-15 07:47  sangorrin
+       * src_frescan/frescan_bandwidth_reservation.c,
+         src_frescan/frescan_data.h: update the names and add acceptor
+         thread id to the general data
+ 2008-04-15 07:44  sangorrin
+       * src_frescan/frescan_acceptor_threads.c,
+         src_frescan/frescan_acceptor_threads.h,
+         src_frescan/frescan_negotiation_threads.c,
+         src_frescan/frescan_negotiation_threads.h,
+         src_frescan/frescan_negotiator_thread.c,
+         src_frescan/frescan_negotiator_thread.h: renaming to neg threads
+ 2008-04-15 07:43  sangorrin
+       * src_frescan/frescan_acceptor_threads.c,
+         src_frescan/frescan_acceptor_threads.h: joining threads module
+ 2008-04-14 16:58  sangorrin
+       * src_frescan/TODO, src_frescan/frescan.c,
+         src_frescan/frescan_debug.h, src_frescan/frescan_hw_buffer.c:
+         abort when higher prio frame
+ 2008-04-09 11:19  sangorrin
+       * tests/tests_frescan/test_frescan_servers_send_receive_measures.c:
+         add a test to obtain measures of a round trip
+ 2008-04-09 11:19  sangorrin
+       * rules.mk: apps need to link to libfosa too
+ 2008-04-08 15:37  sangorrin
+       * config.mk_example: network enabling is now in fna_configuration.h
+ 2008-04-08 15:37  sangorrin
+       * src_frescan/frescan_servers_replenishments.c: initialize pointer
+         to null to avoid warning.. this is because the compiler does not
+         know that im checking that a list is not empty before using it
+         etc..
+ 2008-04-08 15:36  sangorrin
+       * src_frescan/frescan_requests_queue.c: initialize pointer to null
+         to avoid warning.. this is because the compiler does not know
+         that im checking that a list is not empty before using it etc..
+ 2008-04-08 15:36  sangorrin
+       * src_frescan/frescan_queues.c: initialize pointer to null to avoid
+         warning.. this is because the compiler does not know that im
+         checking that a list is not empty before using it etc..
+ 2008-04-08 15:35  sangorrin
+       * src_frescan/frescan_negotiator_thread.c: create a server in the
+         negotiator thread... this thread should be renamed to MASTER
+         local negotiator thread or sth like that cause the rest of
+         negotiations are performed by the acceptor thread.. which also
+         should be renamed to SLAVE negotiations or sth like that
+ 2008-04-08 15:34  sangorrin
+       * src_frescan/frescan_fna.c: implement send and receive in fna and
+         bytes<->budget conversion functions... the test is in
+         frsh/tests_distributed/test send receive basic
+ 2008-04-08 15:33  sangorrin
+       * src_frescan/frescan_config.h: put neg channel to 0 by default so
+         i dont forget it
+ 2008-04-08 15:32  sangorrin
+       * include/frsh_fna.h: tab
+ 2008-04-08 15:32  sangorrin
+       * include/fna_configuration.h: networks are enabled in
+         fna_configuration.h now, not in CFLAGS... i keep the enables in
+         config.mk for the moment but just rules.mk to know which
+         directories should be compiled... with the future omk system i
+         guess this is easier
+ 2008-04-08 08:45  sangorrin
+       * tests/tests_frescan/Makefile: now libfrescan.o instead of .a
+ 2008-04-08 08:45  sangorrin
+       * src_frescan/Makefile: now libfrescan is a relocatable object file
+         instead of a library .a
+ 2008-04-08 08:44  sangorrin
+       * src_frescan/frescan_fna.c, src_frescan/frescan_fna.h,
+         src_frescan/frescan_frsh_fna.c: added fna files, starting its
+         implementation, the rest return an error and write not
+         implemented so far
+ 2008-04-08 08:44  sangorrin
+       * src_frescan/frescan_debug.h: add flag for debugging frescan fna
+         layer
+ 2008-04-08 08:44  sangorrin
+       * src/fna_configuration.c: add frescan operations
+ 2008-04-08 08:43  sangorrin
+       * include/frsh_fna.h: add prototypes for frescan
+ 2008-04-08 08:43  sangorrin
+       * config.mk_example: now im working on frescan.. ill update rtep if
+         i broke the compilation later
+ 2008-04-08 08:42  sangorrin
+       * rules.mk: now all will be included in libfna.a, the rest will be
+         relocatable linked objects
+ 2008-04-07 15:58  sangorrin
+       * tests/tests_rtep_fna/Makefile,
+         tests/tests_rtep_fna/test_c_rtep_fna.c,
+         tests/tests_rtep_fna/test_c_rtep_fna_measurement.c,
+         tests/tests_rtep_fna/test_c_rtep_fna_with_frsh.c,
+         tests/tests_rtep_fna/test_c_rtep_frsh_fna.c: use frsh.h only,
+         headers mess otherwise
+ 2008-04-07 15:49  sangorrin
+       * include/fna.h, include/frsh_fna.h: include frsh.h to include
+         everything because there were headers problems and miguel has
+         thought it to include only this file
+ 2008-04-07 15:48  sangorrin
+       * src_rtep/Makefile, src_rtep/rtep_fna_c.c: frsh_freelist is now
+         part of utils as fadt_freelist
+ 2008-04-07 15:47  sangorrin
+       * config.mk_example, rules.mk: utils
+ 2008-04-07 08:22  sangorrin
+       * tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c: neg
+         in slave, receive results
+ 2008-04-07 08:21  sangorrin
+       * src_frescan/frescan_bandwidth_reservation.c,
+         src_frescan/frescan_data.h,
+         src_frescan/frescan_negotiation_messages.c,
+         src_frescan/frescan_negotiation_messages.h,
+         src_frescan/frescan_servers.c,
+         src_frescan/frescan_servers_replenishments.c: negotiation reply
+         (TODO: integrate the scheduling test component)
+ 2008-04-03 16:04  sangorrin
+       * src_frescan/frescan.c, src_frescan/frescan_acceptor_threads.c,
+         src_frescan/frescan_acceptor_threads.h,
+         src_frescan/frescan_bandwidth_reservation.c,
+         src_frescan/frescan_config.h, src_frescan/frescan_data.h,
+         src_frescan/frescan_debug.h,
+         src_frescan/frescan_negotiation_messages.c,
+         src_frescan/frescan_negotiation_messages.h,
+         src_frescan/frescan_negotiator_thread.c,
+         src_frescan/frescan_requests_queue.c,
+         src_frescan/frescan_requests_queue.h,
+         tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c,
+         tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c,
+         tests/tests_frescan/test_frescan_send_basic.c: negotiation
+         messages, so far a slave call negotiate which sends a negotiate
+         msg which arrives to the master and sends a reply
+ 2008-04-01 16:09  sangorrin
+       * tests/tests_frescan/test_frescan_bwres_init.c,
+         tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c,
+         tests/tests_frescan/test_frescan_init.c,
+         tests/tests_frescan/test_frescan_send_basic.c,
+         tests/tests_frescan/test_frescan_servers_send_basic.c: tests for
+         bwres basic
+ 2008-04-01 16:09  sangorrin
+       * src_frescan/frescan.c,
+         src_frescan/frescan_bandwidth_reservation.c,
+         src_frescan/frescan_bandwidth_reservation.h,
+         src_frescan/frescan_config.h, src_frescan/frescan_data.h,
+         src_frescan/frescan_debug.h,
+         src_frescan/frescan_negotiator_thread.c,
+         src_frescan/frescan_negotiator_thread.h,
+         src_frescan/frescan_requests_queue.c,
+         src_frescan/frescan_requests_queue.h,
+         src_frescan/frescan_servers_replenishments.c: negotiator thread
+         and bwres layer
+ 2008-04-01 09:55  sangorrin
+       * tests/tests_frescan/Makefile: makefile for the tests
+ 2008-04-01 09:55  sangorrin
+       * tests/tests_frescan/test_frescan_replyobj_timedwait.c,
+         tests/tests_frescan/test_frescan_replyobj_wait_signal.c: some
+         tests
+ 2008-04-01 09:55  sangorrin
+       * src_frescan/frescan.c, src_frescan/frescan.h,
+         src_frescan/frescan_config.h, src_frescan/frescan_data.h,
+         src_frescan/frescan_hw_buffer.h, src_frescan/frescan_packets.h,
+         src_frescan/frescan_queues.h,
+         src_frescan/frescan_reply_objects.c,
+         src_frescan/frescan_reply_objects.h,
+         src_frescan/frescan_requests_queue.c,
+         src_frescan/frescan_requests_queue.h,
+         src_frescan/frescan_servers.h,
+         src_frescan/frescan_servers_replenishments.h: starting to build
+         the negotiations infrastructure
+ 2008-03-31 11:21  sangorrin
+       * config.mk_example, src_frescan/Makefile: frescan compiles
+ 2008-03-31 11:16  sangorrin
+       * doc/TODO, rules.mk, src/fna_configuration.c,
+         src_frescan/Makefile, src_frescan/frescan_config.h,
+         src_frescan/frescan_data.h,
+         src_frescan/frescan_servers_replenishments.c,
+         src_frescan/test_frescan_init.c,
+         src_frescan/test_frescan_queues.c,
+         src_frescan/test_frescan_send_basic.c,
+         src_frescan/test_frescan_servers_send_basic.c,
+         tests/tests_frescan, tests/tests_frescan/test_frescan_init.c,
+         tests/tests_frescan/test_frescan_queues.c,
+         tests/tests_frescan/test_frescan_send_basic.c,
+         tests/tests_frescan/test_frescan_servers_send_basic.c: starting
+         adaptation to fosa of frescan.. some reordering..
+ 2008-03-31 10:24  sangorrin
+       * src_frescan, src_frescan/Makefile, src_frescan/README,
+         src_frescan/frescan.c, src_frescan/frescan_config.h,
+         src_frescan/frescan_data.c, src_frescan/frescan_data.h,
+         src_frescan/frescan_debug.h, src_frescan/frescan_hw_buffer.c,
+         src_frescan/frescan_hw_buffer.h, src_frescan/frescan_id.c,
+         src_frescan/frescan_id.h, src_frescan/frescan_packets.c,
+         src_frescan/frescan_packets.h, src_frescan/frescan_queues.c,
+         src_frescan/frescan_queues.h, src_frescan/frescan_servers.c,
+         src_frescan/frescan_servers.h,
+         src_frescan/frescan_servers_replenishments.c,
+         src_frescan/frescan_servers_replenishments.h,
+         src_frescan/test_frescan_init.c,
+         src_frescan/test_frescan_queues.c,
+         src_frescan/test_frescan_send_basic.c,
+         src_frescan/test_frescan_servers_send_basic.c: added frescan
+         sources
+ 2008-01-03 11:00  sangorrin
+       * tests/tests_rtep_fna/test_c_rtep_fna_measurement.c: changed to N
+         measures
+ 2008-01-03 10:59  sangorrin
+       * src_rtep/rtep_fna_c.c: added send sync operation
+ 2007-12-13 11:58  sangorrin
+       * Makefile, src_rtep/rtep_fna_c.c: some debugging flags and the
+         target of the makefile
+ 2007-12-11 11:06  sangorrin
+       * tests/tests_rtep_fna/test_c_rtep_fna_measurement.c: new test for
+         measuring the neg time in rtep fna
+ 2007-12-11 11:05  sangorrin
+       * rules.mk, tests/tests_rtep_fna/Makefile: makefile changes
+ 2007-11-27 17:53  sangorrin
+       * src_rtep/rtep_fna_c.c: debug flags
+ 2007-11-26 12:06  sangorrin
+       * tests/qemu: no qemu image in svn
+ 2007-11-26 12:04  sangorrin
+       * config.mk_example, src/fna_configuration.c,
+         tests/tests_rtep_fna/test_c_rtep_fna_with_frsh.c: backup
+ 2007-10-31 12:28  sangorrin
+       * src_unix/unix_fna.c, src_unix/unix_fna.h,
+         tests/tests_unix_fna/Makefile,
+         tests/tests_unix_fna/test_unix_address.c,
+         tests/tests_unix_fna/test_unix_fna_send_receive.c,
+         tests/tests_unix_fna/test_unix_fna_send_receive_script: change to
+         unix fna, now we encode streams... but i found a problem in dtm
+         so it wont be useful because multithreaded apps in linux_lib_arch
+         cannot sleep
+ 2007-10-29 18:17  sangorrin
+       * src_unix/unix_fna.c: debug function
+ 2007-10-29 10:38  sangorrin
+       * include/fna.h, src_rtep/rtep_fna_c.c, src_unix/unix_fna.c,
+         src_unix/unix_fna.h,
+         tests/tests_unix_fna/test_unix_fna_send_receive.c,
+         tests/tests_unix_fna/test_unix_send_receive.c: unix fna, it seems
+         to work
+ 2007-10-26 17:46  sangorrin
+       * config.mk_example, include/frsh_fna.h, rules.mk,
+         src/fna_configuration.c, src_unix/unix_fna.c,
+         src_unix/unix_fna.h, tests/tests_rtep_fna/test_c_rtep_fna.c,
+         tests/tests_unix_fna, tests/tests_unix_fna/Makefile,
+         tests/tests_unix_fna/test_unix_fna_send_receive.c,
+         tests/tests_unix_fna/test_unix_send_receive.c: preparing to do
+         unix fna
+ 2007-10-26 10:23  sangorrin
+       * config.mk_example, rules.mk, src/fna_configuration.c, src_unix,
+         src_unix/Makefile, src_unix/unix_fna.c, src_unix/unix_fna.h,
+         tests, tests/qemu, tests/qemu/Makefile, tests/qemu/base_disk.img,
+         tests/qemu/mkvirtualdisk, tests/qemu/mnt, tests/tests_rtep_fna,
+         tests/tests_rtep_fna/Makefile,
+         tests/tests_rtep_fna/test_c_rtep_fna.c,
+         tests/tests_rtep_fna/test_c_rtep_fna_with_frsh.c,
+         tests/tests_rtep_fna/test_c_rtep_frsh_fna.c: start to do the unix
+         fna
+ 2007-10-26 09:31  sangorrin
+       * src_rtep/tests:
+ 2007-10-19 11:44  sangorrin
+       * config.mk_example: config
+ 2007-10-19 11:43  sangorrin
+       * include/fna_configuration.h: rtep is defined in config.mk
+ 2007-10-19 11:43  sangorrin
+       * rules.mk: ifdef rtep
+ 2007-10-19 10:22  sangorrin
+       * src/fna_configuration.c: define rtep
+ 2007-10-19 10:22  sangorrin
+       * include/fna_configuration.h: define rtep
+ 2007-10-19 09:22  sangorrin
+       * src_rtep/tests/Makefile: new makefile
+ 2007-10-19 09:22  sangorrin
+       * src_rtep/Makefile: clean images in tests
+ 2007-10-19 09:20  sangorrin
+       * src_rtep/Makefile: makefile update
+ 2007-10-19 09:20  sangorrin
+       * src_rtep/rtep_fna_c.c: the table is now in fna_configuration.c
+ 2007-10-19 09:20  sangorrin
+       * Makefile, config.mk_example, rules.mk: new makefile system
+ 2007-10-19 09:19  sangorrin
+       * src, src/Makefile, src/fna_configuration.c: to store the fna
+         table
+ 2007-10-19 09:18  sangorrin
+       * include/frsh_fna.h: no elif
+ 2007-10-19 09:18  sangorrin
+       * include/fna_configuration.h: define rtep
+ 2007-10-19 09:15  sangorrin
+       * doc/license_fna.txt: que no
+ 2007-09-28 11:44  telleriam
+       * doc/license_fna.txt, include/fna.h, include/fna_configuration.h,
+         include/frsh_fna.h, src_rtep/rtep_fna.h, src_rtep/rtep_fna_c.c,
+         src_rtep/rtep_frsh_fna_c.c, src_rtep/tests/test_c_rtep_fna.c,
+         src_rtep/tests/test_c_rtep_fna_with_frsh.c,
+         src_rtep/tests/test_c_rtep_frsh_fna.c: Global update in FNA to
+         update license text
+ 2007-09-06 15:15  sangorrin
+       * src_rtep/rtep_fna_c.c: no messages
+ 2007-09-03 17:38  sangorrin
+       * src_rtep/tests/Makefile, src_rtep/tests/test_c_frsh.c,
+         src_rtep/tests/test_c_rtep_fna.c.old: makefile with frsh
+ 2007-09-03 17:38  sangorrin
+       * src_rtep/tests/test_c_rtep_fna.c: send receive
+ 2007-09-03 17:37  sangorrin
+       * src_rtep/tests/test_c_rtep_fna_with_frsh.c: check fna with frsh
+         running
+ 2007-09-03 17:37  sangorrin
+       * src_rtep/tests/test_c_rtep_frsh_fna.c: comment until implemented
+ 2007-09-03 17:36  sangorrin
+       * src_rtep/rtep_fna_c.c: chan
+ 2007-08-10 17:05  sangorrin
+       * src_rtep/rtep_fna_c.c: renegotiate_sync
+ 2007-08-09 11:47  sangorrin
+       * src_rtep/Makefile, src_rtep/rtep_fna.h, src_rtep/rtep_fna_c.c,
+         src_rtep/rtep_frsh_fna_c.c, src_rtep/tests/Makefile,
+         src_rtep/tests/test_c_rtep_fna.c,
+         src_rtep/tests/test_c_rtep_frsh_fna.c: big commint with a lot of
+         changes, see files
+ 2007-08-09 11:46  sangorrin
+       * lib: lib for rtepfna
+ 2007-08-09 11:40  sangorrin
+       * include/fna.h, include/fna_configuration.h: hooks for fna
+ 2007-08-02 10:23  sangorrin
+       * src_rtep/tests/test_c_rtep_fna.c,
+         src_rtep/tests/test_c_rtep_frsh_fna.c: assert
+ 2007-06-25 15:34  sangorrin
+       * src_rtep/Makefile, src_rtep/rtep_fna_c.c,
+         src_rtep/rtep_frsh_fna_c.c, src_rtep/tests,
+         src_rtep/tests/Makefile, src_rtep/tests/base_disk.img,
+         src_rtep/tests/mkvirtualdisk, src_rtep/tests/mnt,
+         src_rtep/tests/test_c_frsh.c, src_rtep/tests/test_c_rtep_fna.c,
+         src_rtep/tests/test_c_rtep_fna.c.old,
+         src_rtep/tests/test_c_rtep_frsh_fna.c: fna tests
+ 2007-06-25 15:32  sangorrin
+       * include/fna.h, include/frsh_fna.h, src, src_rtep:
+ 2007-06-19 07:46  sangorrin
+       * include/fna.h: i add FROM when receiving
+ 2007-05-15 17:40  sangorrin
+       * doc/api_fna_html.tar.gz, doc/fna-refman.pdf: update doc
+ 2007-03-22 10:33  sangorrin
+       * include/fna.h: create_callback
+ 2007-03-20 17:27  sangorrin
+       * include/fna.h: maxsize
+ 2007-03-20 10:27  sangorrin
+       * doc/api_fna_html.tar.gz, doc/fna-refman.pdf: doc update
+ 2007-03-20 10:26  sangorrin
+       * include/fna.h: correct network functions
+ 2007-03-19 16:16  sangorrin
+       * include/fna.h: functions to map bytes to budgets changed and a
+         new function for effective budget
+ 2007-03-14 18:03  sangorrin
+       * doc/api_fna_html.tar.gz, doc/fna-refman.pdf, include/fna.h:
+         Changes in names of spare capacity functions. Change in
+         message_get_tx_time (tx_time is the physical time without
+         overheads)
+ 2007-03-13 18:16  sangorrin
+       * doc/api_fna_html.tar.gz, doc/fna-refman.pdf: update doc
+ 2007-03-13 11:20  sangorrin
+       * include/fna.h: changes in get_status functions and add receive
+         create endpoint
+ 2007-03-09 09:11  sangorrin
+       * COPYING, README, doc/TODO: copying, readme, todo..
+ 2007-03-09 09:04  sangorrin
+       * ftt-se_fna, rtep_fna, src: src is source common for all
+         protocols. each protocol has its source in its own dir
+ 2007-03-09 08:53  sangorrin
+       * ftt-se_fna, rtep_fna, src_ftt-se, src_rtep: change source names
+         because they don't contain the whole code of the protocols
+ 2007-03-07 09:30  sangorrin
+       * doc, doc/api_fna_html.tar.gz, doc/fna-refman.pdf, include,
+         include/fna.h, include/frsh_fna.h, src_ftt-se, src_rtep: first
+         upload of fna
+ 2007-03-07 09:19  sangorrin
+       * .: creating trunk
diff --combined src/fna/INSTALL
index 0000000000000000000000000000000000000000,ab95b6e42ca8d5e25bd43ba896354c43b2fa5e06..ab95b6e42ca8d5e25bd43ba896354c43b2fa5e06
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,13 +1,13 @@@
+ INSTALL
+ =======
+ 1.- Enable / Disable the FNA modules (RT-EP, FRESCAN, etc..) in the config.mk and in
+     the fna_configuration.h files
+ 2.- Compile the FNA library with 'make'
+ 3.- Build and example from the 'tests/' directory (i.e.: make test_frescan_send_basic.exe)
+ 4.- Tests using the modules from FRSH distributed interface are located at 'tests/tests_distributed'
+     in the FRSH module, not in FNA.
diff --combined src/fna/Makefile
index 0000000000000000000000000000000000000000,a39a28eef1adc84d4bbdecafe1c728a10efde926..a39a28eef1adc84d4bbdecafe1c728a10efde926
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,5 +1,5 @@@
+ all: libfna
+ include config.mk
+ include rules.mk
diff --combined src/fna/Makefile.omk
index 0000000000000000000000000000000000000000,c80ed079f8b4eed37c93d0bae15fb2555df393db..c80ed079f8b4eed37c93d0bae15fb2555df393db
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,25 +1,25 @@@
+ SUBDIRS=include
+ default_CONFIG = CONFIG_FNA_RTEP=n CONFIG_FNA_UNIX=n CONFIG_FNA_FRESCAN=n
+ lib_LIBRARIES = fna
+ fna_SOURCES = src/fna_configuration.c
+ ifeq ($(CONFIG_FNA_RTEP),y)
+ SUBDIRS+=src_rtep
+ CFLAGS+=-DRTEP_FNA_ENABLED
+ endif
+ ifeq ($(CONFIG_FNA_UNIX),y)
+ SUBDIRS+=src_unix
+ CFLAGS+=-DUNIX_FNA_ENABLED
+ endif
+ ifeq ($(CONFIG_FNA_FRESCAN),y)
+ SUBDIRS+=src_frescan
+ CFLAGS+=-DFRESCAN_FNA_ENABLED
+ endif
+ ifeq ($(CONFIG_FWP),y)
+ CFLAGS+=-DFWP_FNA_ENABLED
+ endif
diff --combined src/fna/README
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..8b76ec525845ed3eb3e6f8395345196532c39455
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,48 @@@
++FNA
++=====================
++Name:
++FNA
++
++Version:
++May 2008
++
++Status:
++Alpha
++
++Authors:
++Daniel Sangorrin [daniel.sangorrin@unican.es] (UC),
++Michael Gonzalez Harbour [mgh@unican.es] (UC)
++Martin Molnar (CTU)
++Michal Sojka (CTU)
++
++Licence:
++FRESCOR Lincece (see COPYING)
++
++Brief description:
++This is FNA (Frescor Network Adaptation layer) module, the layer that allows
++to plug-in different network protocols to FRESCOR by means of a clear interface.
++
++URL:
++svn co http://www.frescor.org/private/svn/frescor/fna/trunk/
++
++Bugs:
++See TODO
++
++Description:
++
++This is FNA (Frescor Network Adaptation layer) module, the layer that allows
++to plug-in different network protocols to FRESCOR by means of a clear interface.
++
++- README: This file
++
++- COPYING: FRESCOR license
++
++- INSTALL: Installation instructions
++
++- include/: FNA API C header files.
++
++- src/ : source code of FNA that is common to all protocols
++
++- src_xxx/ : source code of 'xxx' protocols
++
++- doc/: documentation directory
diff --combined src/fna/TODO
index 0000000000000000000000000000000000000000,5f37f41b29b9c982c6c076e3345ccddfa49e1961..5f37f41b29b9c982c6c076e3345ccddfa49e1961
mode 000000,100644..100644
--- /dev/null
--- 2/TODO
@@@ -1,0 -1,4 +1,4 @@@
+ *  rtep spare capacity
+ *  make the unix platform working with a linux external thread
+ *  finish frescan
index 0000000000000000000000000000000000000000,1d2c8abb0e200b1be2fd0daca59562f9a03961af..1d2c8abb0e200b1be2fd0daca59562f9a03961af
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,78 +1,78 @@@
+ # Platform:  MARTE_OS, DUMMY_OS, RT_LINUX, OSE, AQuoSA
+ PLATFORM      = MARTE_OS
+ PLATFORM_PATH = $(HOME)/marte
+ EXPORT_PATH   = $(HOME)/export
+ # utilization or response time
+ SA_VERSION = utilization
+ # the gcc to use
+ CC = mgcc
+ FRESCOR_ROOT = $(HOME)/frescor
+ FRSH_PATH    = $(FRESCOR_ROOT)/frsh
+ FOSA_PATH    = $(FRESCOR_ROOT)/fosa
+ FNA_PATH     = $(FRESCOR_ROOT)/fna
+ UTILS_PATH   = $(FRESCOR_ROOT)/utils
+ FSA_PATH     = $(FRESCOR_ROOT)/fsa
+ # the compilation flags
+ CFLAGS = -Wall -g -O1 -Wuninitialized \
+        -D$(PLATFORM) \
+        -I$(FNA_PATH)/include \
+        -I$(FRSH_PATH)/include \
+        -I$(FOSA_PATH)/include \
+        -I$(UTILS_PATH)/include \
+        -I$(FSA_PATH)/include
+ # fna networks configuration
+ CONFIG_FNA_RTEP=n
+ CONFIG_FNA_UNIX=n
+ CONFIG_FNA_FRESCAN=n
+ CONFIG_FWP=n
+ ifeq ($(CONFIG_FNA_RTEP),y)
+ CFLAGS += -DRTEP_FNA_ENABLED -I$(FNA_PATH)/src_rtep/ -I$(PLATFORM_PATH)/arch/drivers/rt-ep/
+ endif
+ ifeq ($(CONFIG_FNA_UNIX),y)
+ CFLAGS += -DUNIX_FNA_ENABLED
+ endif
+ ifeq ($(CONFIG_FNA_FRESCAN),y)
+ CFLAGS += -DFRESCAN_FNA_ENABLED -I$(FNA_PATH)/src_frescan/
+ endif
+ ifeq ($(CONFIG_FWP),y)
+ CFLAGS += -DFWP_FNA_ENABLED
+ endif
+ # fna network connected
+ CONFIG_FNA_RTEP_CONNECTED=n
+ CONFIG_FNA_UNIX_CONNECTED=n
+ CONFIG_FNA_FRESCAN_CONNECTED=n
+ CONFIG_FWP_CONNECTED=n
+ ifeq ($(CONFIG_FNA_RTEP_CONNECTED),y)
+ CFLAGS += -DCONFIG_FNA_RTEP_CONNECTED
+ endif
+ ifeq ($(CONFIG_FNA_UNIX_CONNECTED),y)
+ CFLAGS += -DCONFIG_FNA_UNIX_CONNECTED
+ endif
+ ifeq ($(CONFIG_FNA_FRESCAN_CONNECTED),y)
+ CFLAGS += -DCONFIG_FNA_FRESCAN_CONNECTED
+ endif
+ ifeq ($(CONFIG_FWP_CONNECTED),y)
+ CFLAGS += -DCONFIG_FWP_CONNECTED
+ endif
+ # the library flags
+ LDFLAGS = -L$(FRSH_PATH)/lib -L$(FSA_PATH)/lib -L$(FOSA_PATH)/lib \
+            -L$(UTILS_PATH)/lib -L$(FNA_PATH)/lib
+ LDFLAGS += -Wl,--start-group -lfrsh -lfsa_$(SA_VERSION) -lfosa_$(PLATFORM) -lutils -lfna -lm
+ LDFLAGS += -Wl,--end-group
index 0000000000000000000000000000000000000000,9e4e027e4891ff9ed960e742cb3be5d0d5b4ea5e..9e4e027e4891ff9ed960e742cb3be5d0d5b4ea5e
mode 000000,100644..100644
Binary files differ
index 0000000000000000000000000000000000000000,bacc6f14de45723a0de31f04b7f968bddf931769..bacc6f14de45723a0de31f04b7f968bddf931769
mode 000000,100644..100644
Binary files differ
index 0000000000000000000000000000000000000000,9aa9efeec31f427240988465d9ce35ada83cdedf..9aa9efeec31f427240988465d9ce35ada83cdedf
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,1 +1,1 @@@
+ include_HEADERS = $(notdir $(wildcard $(SOURCES_DIR)/*.h))
diff --combined src/fna/include/fna.h
index 0000000000000000000000000000000000000000,3892b3d0696d76f1126b4b4ac96299ad6222afc3..3892b3d0696d76f1126b4b4ac96299ad6222afc3
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,1078 +1,1078 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ //==============================================
+ //  ******** ****     **     **
+ //  **///// /**/**   /**    ****
+ //  **      /**//**  /**   **//**
+ //  ******* /** //** /**  **  //**
+ //  **////  /**  //**/** **********
+ //  **      /**   //****/**//////**
+ //  **      /**    //***/**     /**
+ //  /       //      /// //      //
+ //
+ // FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
+ //==============================================================
+ #ifndef _FNA_H_
+ #define _FNA_H_
+ /* for frsh_resource_id_t, frsh_contract_t, for frsh_network_address_t,
+    frsh_stream_id_t, ... */
+ #include "frsh.h"
+ /* for timespec */
+ #include <time.h>
+ /* for ERROR constants */
+ // #include "fna_error.h"
+ /* for uint32_t, UINT32_MAX */
+ #include <stdint.h>
+ /**
+  * @defgroup fna FNA Private Interface
+  *
+  * FNA is a Network adaption layer that allows to plugin new
+  * network protocols to the distributed module.
+  *
+  * It is divided in two parts:
+  *  - FRSH_FNA:  public types and functions for the FRSH API
+  *  - FNA: private functions only used within FRSH.
+  *
+  **/
+ //////////////////////////////////////////////////////////////////////
+ //           INITIALIZATION
+ //////////////////////////////////////////////////////////////////////
+ /**
+  * @defgroup fnainit FNA Initialization
+  * @ingroup fna
+  *
+  * These functions need to be called before using any network
+  *
+  * @{
+  **/
+ /**
+  * fna_init()
+  *
+  * This function will be hooked to the frsh_init function and it is
+  * intented to initialize the protocol and its structures.
+  *
+  * @param[in]  resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_ALREADY_INITIALIZED:
+  *      if the function has already been called before (with success) \n
+  *
+  **/
+ typedef int fna_init_t(const frsh_resource_id_t resource_id);
+ /*@}*/
+ ///////////////////////////////////////////////////////////////////
+ //           VIRTUAL RESOURCES
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * @defgroup fnavres FNA Virtual Resources
+  * @ingroup fna
+  *
+  * The following functions are used to negotiate, renegotiate and cancel
+  * virtual network resources.
+  *
+  * @{
+  **/
+ #ifndef FRSH_FORB
+ /**
+  * fna_vres_id_t
+  *
+  * Internal virtual resource id. In the current implementation it is a 16 bits
+  * value (up to 65536 vres) so it can be integrated easily with the
+  * frsh_vres_id_t type (see frsh_internal_data.h)
+  *
+  **/
+ typedef uint16_t fna_vres_id_t;
+ #else
+ /**
+  * In FRSH_FORB implementation, we do not distinguish between vreses
+  * of different resources.
+  */
+ typedef frsh_vres_id_t fna_vres_id_t;
+ #endif
+ typedef  struct {
+         int            size;
+         fna_vres_id_t  vres[FRSH_MAX_GROUP_OPS];
+ } fna_vres_group_t;
+ /**
+  * frsh_group_change_mode_sync()
+  *
+  * This function performs a set of negotiation operations which can
+  * include: adding new contracts (neg), modifying existing vres (reneg)
+  * or cancelling existing vres (cancel).
+  *
+  * If one of the group operations has a NULL value, unless it causes an
+  * inconsistency the system will suppose that no operation of that
+  * type (neg, reneg or cancel) should be done.
+  *
+  * The virtual resources resulting from negotiations of new contracts are
+  * returned in the parameter 'new_vres' which must be provided by the user.
+  *
+  * If the on-line admission test is enabled, FRSH analizes the
+  * schedulability of the context that would  result in the new
+  * contract situation with removed, changed and added contracts.
+  *
+  * A successful return code will mean that all contracts have been
+  * accepted  and all required operations (creation, cancellation or
+  * update of vres) have been carried out to reach the new running
+  * context.
+  *
+  * If any of the contracts is not accepted a corresponding error shall be
+  * returned and no changes will be made to the previously running context.
+  *
+  * This call is a synchronous, potentially blocking operation.  It
+  * returns when the system has rejected the contracts or accepted
+  * and made them effective.
+  *
+  * @param[in] contracts_to_neg    List of new contracts to negotiate
+  * @param[in] contracts_to_reneg  List of contracts to renegotiate
+  * @param[in] vres_to_reneg       List of vres to renegotiate
+  * @param[in] vres_to_cancel      List of vres to cancel
+  * @param[out] new_vres           List of vres of new contracts.
+  *
+  * @return 0 if no error \n
+  *   0 if there are no errors (in this case it also means contract accepted) \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_TOO_MANY_VRES: if there is no space for more vres \n
+  *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+  *   FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_group_change_mode_sync_t
+                 (const frsh_resource_id_t     resource_id,
+                  const frsh_contracts_group_t *contracts_to_neg,
+                  const frsh_contracts_group_t *contracts_to_reneg,
+                  const fna_vres_group_t       *vres_to_reneg,
+                  const fna_vres_group_t       *vres_to_cancel,
+                  fna_vres_group_t             *new_vres);
+ /**
+  * fna_contract_negotiate()
+  *
+  * The operation negotiates a contract and if accepted it will return
+  * a fna_vres_id_t. It will also check that the given contract_id is unique
+  * within the network.
+  *
+  * If the on-line admission test is enabled, it determines whether the
+  * contract can be admitted or not based on the current contracts
+  * established in the network. Then it creates the vres and
+  * recalculates all necessary parameters for the contracts already
+  * present in the system.
+  *
+  * This is a potentially blocking operation, it returns when the
+  * system has either rejected the contract, or admitted it and made it
+  * effective.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] contract  The contract parameters to negotiate
+  * @param[out] vres The internal virtual resource id
+  *
+  * @return
+  *   0 if there are no errors (in this case it also means contract accepted) \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_TOO_MANY_VRES: if there is no space for more vres \n
+  *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+  *   FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_contract_negotiate_t
+    (const frsh_resource_id_t resource_id,
+     const frsh_contract_t *contract,
+     fna_vres_id_t *vres);
+ /**
+  * fna_contract_renegotiate_sync()
+  *
+  * The operation renegotiates a contract for an existing vres. If
+  * the on-line admission test is enabled it determines whether the
+  * contract can be admitted or not based on the current contracts
+  * established in the system. If it cannot be admitted, the old
+  * contract remains in effect and an error is returned. If it can be
+  * admitted, it recalculates all necessary parameters for the
+  * contracts already present in the system and returns zero. This is a
+  * potentially blocking operation; it returns when the system has
+  * either rejected the new contract, or admitted it and made it
+  * effective.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id to renegotiate
+  * @param[in] new_contract The new contract
+  *
+  *  @return
+  *   0 if there are no errors (in this case it also means contract accepted) \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+  *   FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_contract_renegotiate_sync_t
+    (const frsh_resource_id_t resource_id,
+     const fna_vres_id_t vres,
+     const frsh_contract_t *new_contract);
+ /**
+  * fna_contract_renegotiate_async()
+  *
+  * The operation enqueues a renegotiate operation for an existing
+  * vres, and returns immediately. The renegotiate operation is
+  * performed asynchronously, as soon as it is practical; meanwhile the
+  * system operation will continue normally. When the renegotiation is
+  * made, if the on-line admission test is enabled it determines
+  * whether the contract can be admitted or not based on the current
+  * contracts established in the system. If it cannot be admitted, the
+  * old contract remains in effect. If it can be admitted, it
+  * recalculates all necessary parameters for the contracts already
+  * present in the system.
+  *
+  * When the operation is completed, notification is made to the
+  * caller, if requested, via a signal. The status of the operation (in
+  * progress, admitted, rejected) can be checked with the
+  * frsh_vres_get_renegotiation_status() operation.  The argument
+  * sig_notify can be FRSH_NULL_SIGNAL (no notification), or any FRSH
+  * signal value and in this case signal_info is to be sent with the signal.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id to renegotiate
+  * @param[in] new_contract The new contract
+  * @param[in] signal_to_notify  Signal number to use to notify vres of
+  * the negotiation result. If FRSH_NULL_SIGNAL,  no signal will be raised.
+  * @param[in] signal_info: Associated info that will come with the signal.
+  * This parameter will be ignored if signal_to_notify == FRSH_NULL_SIGNAL.
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL, or sig_notify is neither
+  *      NULL nor a valid POSIX signal \n
+  *
+  **/
+ typedef int fna_contract_renegotiate_async_t
+    (const frsh_resource_id_t resource_id,
+     const fna_vres_id_t vres,
+     const frsh_contract_t *new_contract,
+     frsh_signal_t signal_to_notify,
+     frsh_signal_info_t signal_info);
+ /**
+  * fna_vres_get_renegotiation_status()
+  *
+  * The operation reports on the status of the last renegotiation
+  * operation enqueued for the specified vres. It is callable even
+  * after notification of the completion of such operation, if
+  * requested.
+  *
+  * If the vres is not and has not been involved in any of the
+  * frsh_contract_renegotiate_async() or frsh_group_change_mode_async()
+  * operations, the status returned is FNA_NOT_REQUESTED
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id we want the status from
+  * @param[in] renegotiation_status The status of the last renegotiation on
+  * vres (FRSH_RS_IN_PROGRESS, FRSH_RS_REJECTED, FRSH_RS_ADMITTED,
+  * FRSH_RS_NOT_REQUESTED)
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_vres_get_renegotiation_status_t
+    (const frsh_resource_id_t resource_id,
+     const fna_vres_id_t vres,
+     frsh_renegotiation_status_t *renegotiation_status);
+ /**
+  * fna_vres_destroy()
+  *
+  * The operation eliminates the specified vres
+  * and recalculates all necessary parameters for the contracts
+  * remaining in the system. This is a potentially blocking operation;
+  * it returns when the system has made the changes effective.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id to destroy
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_vres_destroy_t
+    (const frsh_resource_id_t resource_id,
+     const fna_vres_id_t vres);
+ /**
+  * fna_vres_get_contract()
+  *
+  * This operation stores the contract parameters currently associated
+  * with the specified vres in the variable pointed to by
+  * contract. It returns an error if the vres_id is not recognised.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] contract  The contract parameters that we want
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_vres_get_contract_t
+    (const frsh_resource_id_t resource_id,
+     const fna_vres_id_t vres,
+     frsh_contract_t *contract);
+ /**
+  * fna_vres_get_usage()
+  *
+  * This function gets the execution time spent by all messages that have been
+  * sent through the specified vres.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] usage  Execution time spent by this vres
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_vres_get_usage_t
+    (const frsh_resource_id_t resource_id,
+     const fna_vres_id_t vres,
+     struct timespec *usage);
+ /**
+  * fna_vres_get_remaining_budget()
+  *
+  * This function stores in the variable pointed to by budget the
+  * remaining execution-time budget associated with the specified
+  * vres in the present period.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] remaining_budget  The remaining budget for this period
+  *
+  *  @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_vres_get_remaining_budget_t
+    (const frsh_resource_id_t resource_id,
+     const fna_vres_id_t vres,
+     struct timespec *remaining_budget);
+ /**
+  * fna_vres_get_budget_and_period()
+  *
+  * This function gets the budget and period associated with the specified vres
+  * for each period. If one of these pointers is NULL, the corresponding
+  * information is not stored.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] budget The budget associated to vres
+  * @param[out] period  The period associated to vres
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if both pointers are NULL \n
+  *
+  **/
+ typedef int fna_vres_get_budget_and_period_t
+    (const frsh_resource_id_t resource_id,
+     const fna_vres_id_t vres,
+     struct timespec *budget,
+     struct timespec *period);
+ /*@}*/
+ ///////////////////////////////////////////////////////////////////
+ //           SPARE CAPACITY FUNCIONS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * @defgroup fnaspare FNA Spare Capacity
+  * @ingroup fna
+  *
+  * The following functions are used to get spare capacity data
+  *
+  * @{
+  **/
+ /**
+  * fna_resource_get_capacity()
+  *
+  * This operation gets the spare capacity currently assigned to a importance
+  * level. If we divide this value by UINT32_MAX we will get the network
+  * utilization associated to the spare capacity of a importance level.
+  *
+  * The following is typically in stdint.h: \n
+  *  - typedef unsigned int uint32_t;  \n
+  *  - # define UINT32_MAX  (4294967295U)  \n
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] importance The importance we want the capacity of
+  * @param[out] capacity The spare capacity for that importance level
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_resource_get_capacity_t
+    (const frsh_resource_id_t resource_id,
+     const int importance,
+     uint32_t *capacity);
+ /**
+  * fna_resource_get_total_weight()
+  *
+  * This function gets the sum of the weight parameters for all vres in a
+  * network of an importance level.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] importance The importance we want the total weight of
+  * @param[out] total_weight The total weight for that importance level
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_resource_get_total_weight_t
+    (const frsh_resource_id_t resource_id,
+     const int importance,
+     int *total_weight);
+ /**
+  * fna_vres_decrease_capacity()
+  *
+  * This function allows to ask for less budget and period than what we
+  * received. The request must be compatible with the rest of contract
+  * parameters of the vres. If we want to recover the released capacity
+  * we will need to renegotiate.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[in] new_budget The new_budget
+  * @param[in] new_period The new Period
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_CONTRACT_REJECTED: if it is incompatible with the current
+  *      contract \n
+  *
+  **/
+ typedef int fna_vres_decrease_capacity_t
+    (const frsh_resource_id_t resource_id,
+     const fna_vres_id_t vres,
+     const struct timespec new_budget,
+     const struct timespec new_period);
+ /*@}*/
+ ///////////////////////////////////////////////////////////////////
+ //           SEND RECEIVE OPERATIONS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * @defgroup fnasendrecv FNA Send and Receive
+  * @ingroup fna
+  *
+  * The following functions are used to send and receive
+  *
+  * @{
+  **/
+ typedef enum {
+     FRSH_SEND_ENDPOINT_TYPE,
+     FRSH_RECEIVE_ENDPOINT_TYPE
+ } frsh_endpoint_type_t;
+ typedef struct fna_endpoint_data {
+     frsh_endpoint_type_t endpoint_type; // send_endpoint or receive_endpoint
+     fna_vres_id_t vres;                 // only for send_endpoints
+     bool is_bound;                      // only for send_endpoints
+     frsh_network_address_t destination; // only for send_endpoints
+     frsh_resource_id_t resource_id;
+     frsh_stream_id_t stream_id;
+     frsh_protocol_info_t protocol_info;
+     frsh_endpoint_queueing_info_t queue_info;
+     union {
+         frsh_send_endpoint_protocol_info_t send;
+         frsh_receive_endpoint_protocol_info_t receive;
+     } endpoint_protocol_info;
+ } fna_endpoint_data_t;
+ /**
+  * fna_send_sync()
+  *
+  * Similar to previous function but now the sending thread gets blocked
+  * until the message is already sent to the network.
+  *
+  * @param[in] endpoint The send endpoint we are sending through. It must
+  *    be bound to a virtual resource (resource_id is in the endpoint).
+  * @param[in] msg The message we want to send
+  * @param[in] size The size in bytes of the message
+  *
+  * @returns
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_BOUND: if endpoint is not bound to a valid vres \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_TOO_LARGE: if the message is too large for the network protocol \n
+  *   FNA_ERR_BUFFER_FULL: if the message has been discarded because
+  *   the queue is full (and does not have the policy FNA_QP_OLDEST) \n
+  *
+  **/
+ typedef int fna_send_sync_t
+    (const fna_endpoint_data_t *endpoint,
+     const void *msg,
+     const size_t size);
+ /**
+  * fna_send_async()
+  *
+  * This operation sends a message stored in msg and of length size
+  * through the given send endpoint. The operation is non-blocking and
+  * returns immediately.
+  *
+  * @param[in] endpoint The send endpoint we are sending through. It must
+  *    be bound to a virtual resource (resource_id is in the endpoint).
+  * @param[in] msg The message we want to send
+  * @param[in] size The size in bytes of the message
+  *
+  * @returns
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_BOUND: if endpoint is not bound to a valid vres \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_TOO_LARGE: if the message is too large for the network protocol \n
+  *   FNA_ERR_BUFFER_FULL: if the message has been discarded because
+  *   the queue is full (and does not have the policy FNA_QP_OLDEST) \n
+  *
+  **/
+ typedef int fna_send_async_t
+    (const fna_endpoint_data_t *endpoint,
+     const void *msg,
+     const size_t size);
+ /**
+  * fna_receive_sync()
+  *
+  * This operation is used to receive messages from the network with a
+  * blocking behavior (if there are no messages this operation blocks
+  * the calling thread).
+  *
+  * When a message is available, it is copied to buffer (up to its size).
+  * The number of bytes copied is returned in received_bytes. The rest
+  * of the bytes of that message will be lost or not depending on the
+  * protocol (FNA_ERR_NO_SPACE will be returned if it is).
+  *
+  * The function fails with FNA_ERR_NO_SPACE if the buffersize is
+  * too small for the message received.  In this case the message is
+  * lost.
+  *
+  * Messages arriving at a receiver buffer that is full will be handled
+  * according to the queueing policy of the endpoint (overwrite oldest,
+  * discard it,etc).
+  *
+  * @param[in] endpoint The receive endpoint we are receiving from.
+  *    (resource_id is in the endpoint).
+  * @param[out] buffer Buffer for storing the received message
+  * @param[in] buffer_size The size in bytes of this buffer
+  * @param[out] received_bytes The actual number of received bytes
+  * @param[out] from Address of the sender node
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_NO_SPACE: if the message size is bigger than the
+  *      provided buffer. \n
+  *
+  **/
+ typedef int fna_receive_sync_t
+    (const fna_endpoint_data_t *endpoint,
+     void *buffer,
+     const size_t buffer_size,
+     size_t *received_bytes,
+     frsh_network_address_t *from);
+ /**
+  * fna_receive_async()
+  *
+  * This operation is similar to the previous one but it works in a non
+  * blocking (asynchronous) fashion.  If no message is available it
+  * returns with error FNA_NO_MESSAGE.
+  *
+  * @param[in] endpoint The receive endpoint we are receiving from.
+  *    (resource_id is in the endpoint).
+  * @param[out] buffer Buffer for storing the received message
+  * @param[in] buffer_size The size in bytes of this buffer
+  * @param[out] received_bytes The actual number of received bytes
+  * @param[out] from Address of the sender node
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_NO_SPACE: if the message size is bigger than the
+  *      provided buffer. \n
+  *   FNA_NO_MESSAGE: if no messages are available in the queue. \n
+  *
+  **/
+ typedef int fna_receive_async_t
+    (const fna_endpoint_data_t *endpoint,
+     void *buffer,
+     const size_t buffer_size,
+     size_t *received_bytes,
+     frsh_network_address_t *from);
+ /**
+  * fna_send_endpoint_get_status()
+  *
+  * This function tells the number of messages still pending in the
+  * endpoint queue, whether the network is up or down with some
+  * optional information which is protocol_dependent.
+  *
+  * @param[in] endpoint The send endpoint (resource_id is in the endpoint).
+  * @param[out] number_of_pending_messages The number of pending messages
+  * @param[out] network_status How is the network (up, down..)
+  * @param[out] protocol_status Protocol dependent status info
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_send_endpoint_get_status_t
+    (const fna_endpoint_data_t *endpoint,
+     int *number_of_pending_messages,
+     frsh_endpoint_network_status_t *network_status,
+     frsh_protocol_status_t *protocol_status);
+ /**
+  * fna_send_endpoint_bind_t()
+  *
+  * This operation is a called from frsh_send_endpoint_bind and binds send
+  * edpoint to vres.
+  *
+  * @param[in] endpoint the endpoint object.
+  * @param[in] vres The internal virtual resource id
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  **/
+ typedef
+ int fna_send_endpoint_bind_t(fna_endpoint_data_t *endpoint, fna_vres_id_t vres);
+ /**
+  * fna_send_endpoint_unbind_t()
+  *
+  * This operation is a called from frsh_send_endpoint_bind.
+  *
+  * @param[in] endpoint the endpoint object.
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  **/
+ typedef
+ int fna_send_endpoint_unbind_t(fna_endpoint_data_t *endpoint);
+ /**
+  * fna_send_endpoint_create_callback()
+  *
+  * This operation is a called from frsh_send_endpoint_create with a
+  * send_endpoint structure already filled.
+  *
+  * @param[in] endpoint the endpoint object.
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  **/
+ typedef int fna_send_endpoint_create_callback_t
+    (fna_endpoint_data_t *endpoint);
+ /**
+  * fna_receive_endpoint_create_callback()
+  *
+  * This operation is a called from frsh_receive_endpoint_create with a
+  * receive_endpoint structure already filled.
+  *
+  * Receiving endpoints are not bound to any network vres, this is
+  * because don't originate any traffic.
+  *
+  * @param[in] endpoint the endpoint object.
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  **/
+ typedef int fna_receive_endpoint_create_callback_t
+    (fna_endpoint_data_t *endpoint);
+ /**
+  * fna_endpoint_destroy()
+  *
+  * This operation is a called from frsh_send(receive)_endpoint_destroy.
+  *
+  * @param[in] endpoint the endpoint object.
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  **/
+ typedef int fna_endpoint_destroy_t
+    (fna_endpoint_data_t *endpoint);
+ /**
+  * fna_receive_endpoint_get_pending_messages
+  *
+  * This function tells the number of messages still pending in the
+  * endpoint queue, whether the network is up or down and some optional
+  * information which is protocol dependent.
+  *
+  * @param[in] endpoint The receive endpoint (resource_id is in the endpoint).
+  * @param[out] number_of_pending_messages The number of pending messages
+  * @param[out] network_status How is the network (up, down..)
+  * @param[out] protocol_status Protocol dependent status info
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_receive_endpoint_get_status_t
+    (const fna_endpoint_data_t *endpoint,
+     int *number_of_pending_messages,
+     frsh_endpoint_network_status_t *network_status,
+     frsh_protocol_status_t *protocol_status);
+ /*@}*/
+ //////////////////////////////////////////////////////////////////////
+ //           NETWORK CONFIGURATION FUNCTIONS
+ //////////////////////////////////////////////////////////////////////
+ /**
+  * @defgroup frshfnaconfig FNA Network Configuration
+  * @ingroup fna
+  *
+  * These functions are needed to set/get some network dependent values
+  *
+  * @{
+  **/
+ /**
+  * fna_network_get_max_message_size()
+  *
+  * This operation gives the maximum number of bytes that can be sent
+  * at a time through the send function when using the network designated by
+  * 'resource_id' and sending it to 'destination'.
+  *
+  * If the application needs to send bigger messages it will have to
+  * split them.
+  *
+  * Some protocols, like IP, are capable of sending large messages
+  * (and use fragmentation internally) but other protocols don't.
+  *
+  * @param[in] resource_id The network we want the tx time from.
+  * @param[in] destination The destination address
+  * @param[out] max_size The maximum number of bytes for each message
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or destination is
+  *   invalid \n
+  *
+  **/
+ typedef int fna_network_get_max_message_size_t
+    (const frsh_resource_id_t resource_id,
+     const frsh_network_address_t destination,
+     size_t *max_size);
+ /**
+  * fna_network_bytes_to_budget()
+  *
+  * This operation converts a number of bytes into a temporal budget for
+  * a specific network. Network overheads are not included here but are
+  * considered internally when negotiating a specific contract.
+  *
+  * @param[in] resource_id The network
+  * @param[in] nbytes Number of bytes
+  * @param[out] budget The network budget for nbytes
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or nbytes is less
+  *   than zero \n
+  *
+  **/
+ typedef int fna_network_bytes_to_budget_t
+    (const frsh_resource_id_t resource_id,
+     const size_t nbytes,
+     frsh_rel_time_t *budget);
+ /**
+  * fna_network_budget_to_bytes()
+  *
+  * This operation converts a temporal budget into a number of bytes for
+  * a specific network. Network overheads are not included.
+  *
+  * @param[in] resource_id The network
+  * @param[in] budget The network budget for nbytes
+  * @param[out] nbytes Number of bytes
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or budget refers to
+  *   an invalid time value \n
+  *
+  **/
+ typedef int fna_network_budget_to_bytes_t
+    (const frsh_resource_id_t resource_id,
+     const frsh_rel_time_t *budget,
+     size_t *nbytes);
+ /**
+  * fna_network_get_min_effective_budget()
+  *
+  * This operation gets the minimum effective budget for a network. Each message
+  * consumes a contracted budget in "chunks" (i.e: packets) that we call
+  * minimum effective budget.
+  *
+  * A negotiated contract, for N bytes in a period T, means that there is a
+  * virtual resource that reserves for the user:
+  *
+  *   Ceiling ((N bytes) / budget_to_bytes (min_effective_budget)) "CHUNKS"
+  *
+  * Note that if the user decides not to send these N bytes at once but, say,
+  * one byte at a time, it will consume one "CHUNK" at a time and the reserved
+  * budget will become exhausted before sending all the bytes.
+  *
+  * @param[in] resource_id The network
+  * @param[out] budget The network budget
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ typedef int fna_network_get_min_effective_budget_t
+    (const frsh_resource_id_t resource_id,
+     frsh_rel_time_t *budget);
+ /*@}*/
+ typedef struct {
+     fna_init_t *fna_init;
+     fna_group_change_mode_sync_t *fna_group_change_mode_sync;
+     fna_contract_negotiate_t *fna_contract_negotiate;
+     fna_contract_renegotiate_sync_t *fna_contract_renegotiate_sync;
+     fna_contract_renegotiate_async_t *fna_contract_renegotiate_async;
+     fna_vres_get_renegotiation_status_t *fna_vres_get_renegotiation_status;
+     fna_vres_destroy_t *fna_vres_destroy;
+     fna_vres_get_contract_t *fna_vres_get_contract;
+     fna_vres_get_usage_t *fna_vres_get_usage;
+     fna_vres_get_remaining_budget_t *fna_vres_get_remaining_budget;
+     fna_vres_get_budget_and_period_t *fna_vres_get_budget_and_period;
+     fna_resource_get_capacity_t *fna_resource_get_capacity;
+     fna_resource_get_total_weight_t *fna_resource_get_total_weight;
+     fna_vres_decrease_capacity_t *fna_vres_decrease_capacity;
+     fna_send_sync_t *fna_send_sync;
+     fna_send_async_t *fna_send_async;
+     fna_receive_sync_t *fna_receive_sync;
+     fna_receive_async_t *fna_receive_async;
+     fna_send_endpoint_get_status_t *fna_send_endpoint_get_status;
+     fna_send_endpoint_bind_t *fna_send_endpoint_bind;
+     fna_send_endpoint_unbind_t *fna_send_endpoint_unbind;
+     fna_endpoint_destroy_t *fna_endpoint_destroy;
+     fna_send_endpoint_create_callback_t *fna_send_endpoint_created;
+     fna_receive_endpoint_create_callback_t *fna_receive_endpoint_created;
+     fna_receive_endpoint_get_status_t *fna_receive_endpoint_get_status;
+     fna_network_get_max_message_size_t *fna_network_get_max_message_size;
+     fna_network_bytes_to_budget_t *fna_network_bytes_to_budget;
+     fna_network_budget_to_bytes_t *fna_network_budget_to_bytes;
+     fna_network_get_min_effective_budget_t *fna_network_get_min_eff_budget;
+ } fna_operations_t;
+ #endif // _FNA_H_
index 0000000000000000000000000000000000000000,348797ec454697c323da917f5a95f177f36dd908..348797ec454697c323da917f5a95f177f36dd908
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,79 +1,79 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ //==============================================
+ //  ******** ****     **     **
+ //  **///// /**/**   /**    ****
+ //  **      /**//**  /**   **//**
+ //  ******* /** //** /**  **  //**
+ //  **////  /**  //**/** **********
+ //  **      /**   //****/**//////**
+ //  **      /**    //***/**     /**
+ //  /       //      /// //      //
+ //
+ // FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
+ //==============================================================
+ #ifndef _FNA_CONFIGURATION_H_
+ #define _FNA_CONFIGURATION_H_
+ #include "fna.h"
+ /** Maximum number of networks in the system (each network will have a
+  *  different resource_id)
+  **/
+ #define FNA_MAX_NETWORKS 4
+ extern fna_operations_t  *fna_operations[FNA_MAX_NETWORKS];
+ #endif // _FNA_CONFIGURATION_H_
index 0000000000000000000000000000000000000000,fafe228e008cb6193d26a8b609d062010655e11f..fafe228e008cb6193d26a8b609d062010655e11f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,328 +1,328 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ //==============================================
+ //  ******** ****     **     **
+ //  **///// /**/**   /**    ****
+ //  **      /**//**  /**   **//**
+ //  ******* /** //** /**  **  //**
+ //  **////  /**  //**/** **********
+ //  **      /**   //****/**//////**
+ //  **      /**    //***/**     /**
+ //  /       //      /// //      //
+ //
+ // FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
+ //==============================================================
+ #ifndef _FRSH_FNA_H_
+ #define _FRSH_FNA_H_
+ #include "frsh.h" /* for frsh_resource_id_t, network_address_t, stream_id_t*/
+ #include <time.h> /* for timespec */
+ #include <stdbool.h> /* for bool */
+ #include "fna_configuration.h"
+ #ifdef RTEP_FNA_ENABLED
+    #include "rtep.h"
+ #endif
+ #ifdef FRESCAN_FNA_ENABLED
+    #include "../src_frescan/frescan.h"
+ #endif
+ /**
+  * @defgroup frshfna FNA Public Interface
+  *
+  * FNA is a Network adaption layer that allows to plugin new
+  * network protocols to the distributed module.
+  *
+  * It is divided in two parts:
+  *  - FRSH_FNA: public types and functions for the FRSH API
+  *  - FNA: private functions only used within FRSH.
+  *
+  **/
+ ////////////////////////////////////////////////////////////////////
+ //          MAPPING FUNCTIONS
+ ////////////////////////////////////////////////////////////////////
+ /**
+  * @defgroup frshfnamap FNA Mapping Functions
+  * @ingroup frshfna
+  *
+  * These functions are needed to map network specific types to FRSH types.
+  * Instead of providing this mapping functions a static hardwired configuration
+  * could be used.
+  *
+  * @{
+  **/
+ /**
+  * frsh_XXXX_map_network_address()
+  *
+  * To map a XXXX protocol network address into a FRSH address.
+  * The protocol must keep this mapping consistent. Instead of using a function
+  * a hardwired mapping could be used.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] in_address The network address we want to map to a frsh address
+  * @param[out] out_address The FRSH abstract network address
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ #ifdef RTEP_FNA_ENABLED
+ int frsh_rtep_map_network_address(const frsh_resource_id_t resource_id,
+                                   const rtep_station_id_t in_address,
+                                   frsh_network_address_t *out_address);
+ #endif
+ #ifdef FRESCAN_FNA_ENABLED
+ int frsh_frescan_map_network_address(const frsh_resource_id_t resource_id,
+                                      const frescan_node_t in_address,
+                                      frsh_network_address_t *out_address);
+ #endif
+ /**
+  * frsh_XXXX_map_stream_id()
+  *
+  * To map a XXXX protocol network stream, port, channel... into a FRSH stream.
+  * The protocol must keep this mapping consistent. Instead of using a function
+  * a hardwired mapping could be used.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] in_stream The network stream we want to map to a FRSH stream
+  * @param[out] out_stream The FRSH abstract network stream
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ #ifdef RTEP_FNA_ENABLED
+ int frsh_rtep_map_stream_id(const frsh_resource_id_t resource_id,
+                             const rtep_channel_t in_stream,
+                             frsh_stream_id_t *out_stream);
+ #endif
+ #ifdef FRESCAN_FNA_ENABLED
+ int frsh_frescan_map_stream_id(const frsh_resource_id_t resource_id,
+                                const frescan_channel_t in_stream,
+                                frsh_stream_id_t *out_stream);
+ #endif
+ /*@}*/
+ ///////////////////////////////////////////////////////////////////
+ //           NEGOTIATION SERVICE PARAMETERS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * @defgroup frshfnaserv FNA Negotiation Service Parameters
+  * @ingroup frshfna
+  *
+  * These functions are needed to set/get the negotiation service parameters.
+  *
+  * @{
+  **/
+ /**
+  * frsh_XXXX_negotiation_messages__vres_renegotiate()
+  *
+  * This function allows the application to change the minimum period
+  * of the negotiation messages sent through the network. It is similar
+  * to the service thread but for the network messages. We do not provide
+  * budget here because the size of the negotiation messages is fixed.
+  *
+  * This change is similar to a renegotiation so a schedulability test
+  * must be done to see if the change can be accepted or not.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] period The new period for negotiation messages
+  * @param[out] accepted If the change has been accepted or not
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_REJECTED_CONTRACT : if the renegotiation fails \n
+  *
+  **/
+ #ifdef RTEP_FNA_ENABLED
+ int frsh_rtep_negotiation_messages_vres_renegotiate
+       (const frsh_resource_id_t resource_id,
+        const struct timespec *period);
+ #endif
+ #ifdef FRESCAN_FNA_ENABLED
+ int frsh_frescan_negotiation_messages_vres_renegotiate
+       (const frsh_resource_id_t resource_id,
+        const struct timespec *period);
+ #endif
+ /**
+  * frsh_XXXX_negotiation_messages_vres_get_period()
+  *
+  * This function gets the minimum period of the negotiation messages
+  * sent through the network.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[out] period The period for negotiation messages
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ #ifdef RTEP_FNA_ENABLED
+ int frsh_rtep_negotiation_messages_vres_get_period
+       (const frsh_resource_id_t resource_id,
+        struct timespec *period);
+ #endif
+ #ifdef FRESCAN_FNA_ENABLED
+ int frsh_frescan_negotiation_messages_vres_get_period
+       (const frsh_resource_id_t resource_id,
+        struct timespec *period);
+ #endif
+ /**
+  * frsh_XXXX_service_thread_vres_renegotiate()
+  *
+  * This function allows the application to change the period and
+  * budget of the service thread that makes the negotiations and
+  * schedulability tests in a network.
+  *
+  * The service thread starts with a default budget and period that
+  * should be configurable
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] budget The new budget for the service thread
+  * @param[in] period The new period for the service thread
+  * @param[out] accepted If the negotiation has been accepted or not
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ #ifdef RTEP_FNA_ENABLED
+ int frsh_rtep_service_thread_vres_renegotiate
+    (const frsh_resource_id_t resource_id,
+     const struct timespec *budget,
+     const struct timespec *period,
+     bool *accepted);
+ #endif
+ #ifdef FRESCAN_FNA_ENABLED
+ int frsh_frescan_service_thread_vres_renegotiate
+    (const frsh_resource_id_t resource_id,
+     const struct timespec *budget,
+     const struct timespec *period,
+     bool *accepted);
+ #endif
+ /**
+  * frsh_XXXX_service_thread_vres_get_budget_and_period()
+  *
+  * This function gets the budget and period of a service thread.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[out] budget The budget of the service thread
+  * @param[out] period The period of the service thread
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ #ifdef RTEP_FNA_ENABLED
+ int frsh_rtep_service_thread_vres_get_budget_and_period
+       (const frsh_resource_id_t resource_id,
+        struct timespec *budget,
+        struct timespec *period);
+ #endif
+ #ifdef FRESCAN_FNA_ENABLED
+ int frsh_frescan_service_thread_vres_get_budget_and_period
+       (const frsh_resource_id_t resource_id,
+        struct timespec *budget,
+        struct timespec *period);
+ #endif
+ /*@}*/
+ #endif /* _FRSH_FNA_H_ */
diff --combined src/fna/rules.mk
index 0000000000000000000000000000000000000000,28944eb47d0dae6409910ca6cebad3c975b82654..28944eb47d0dae6409910ca6cebad3c975b82654
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,59 +1,59 @@@
+ .PHONY: none clean libfna libfrsh libfosa libfsa libutils
+ none:
+       @exec echo -e "\nPlease introduce a target, i.e: 'make test_dtm_xxx.exe'";
+ %.exe: %.c libfna libfosa libfrsh libfosa libfsa libutils dependencies
+       @exec echo -e "\n>> Building $@: ";
+       @if [ -f $< ]; \
+       then \
+               $(CC) $(CFLAGS) $< $(LDFLAGS) -o $@; \
+       fi;
+       @exec echo ">> End Building $@";
+ libfna:
+       @exec echo -e "\n>> Compiling FNA library (lib/libfna.a):";
+       @rm -f $(FNA_PATH)/lib/*.o
+       @make -C $(FNA_PATH)/src all
+       @mv $(FNA_PATH)/src/*.o $(FNA_PATH)/lib/
+ ifeq ($(CONFIG_FNA_RTEP),y)
+       @make -C $(FNA_PATH)/src_rtep librtepfna.a
+ endif
+ ifeq ($(CONFIG_FNA_UNIX),y)
+       @make -C $(FNA_PATH)/src_unix libunixfna.a
+ endif
+ ifeq ($(CONFIG_FNA_FRESCAN),y)
+       @make -C $(FNA_PATH)/src_frescan libfrescan
+ endif
+ ifeq ($(CONFIG_FWP),y)
+       @make -C $(FNA_PATH)/src_fwp libfwp
+ endif
+       @ar -rc libfna.a $(FNA_PATH)/lib/*.o
+       @mv libfna.a $(FNA_PATH)/lib/
+       @rm -f $(FNA_PATH)/lib/*.o
+       @exec echo ">> End Compiling FNA library (lib/libfna.a)"
+ libfrsh:
+       make -C $(FRSH_PATH) libfrsh
+ libfosa:
+       make -C $(FOSA_PATH) libfosa
+ libutils:
+       make -C $(UTILS_PATH) libutils
+ libfsa:
+       make -C $(FSA_PATH) libfsa
+ dependencies:
+ clean:
+       @exec echo -e "\n>> Cleaning... ";
+       @find \( -name '*.[oa]' -or -name '*~*' -or -name 'lib*.a' \
+               -or -name '*.exe' -or -name 'mprogram' -or -name 'a.out' \) -print -delete
+       @exec echo ">> End Cleaning"
diff --combined src/fna/src/Makefile
index 0000000000000000000000000000000000000000,0c834ab423de1f8a7e04ffc500da1d66cbb3b206..0c834ab423de1f8a7e04ffc500da1d66cbb3b206
mode 000000,100755..100755
--- /dev/null
@@@ -1,0 -1,12 +1,12 @@@
+ all: objs
+ include ../config.mk
+ include ../rules.mk
+ SRCS := $(wildcard *.c)
+ OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
+ HDRS := $(wildcard $(FNA_PATH)/include/*.h)
+ objs: $(OBJS)
+ %.o: %.c $(SRCS) $(HDRS)
+       $(CC) $(CFLAGS) -c $<
index 0000000000000000000000000000000000000000,60d33c97a89be88528c90336e8715018b15d9b77..60d33c97a89be88528c90336e8715018b15d9b77
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,105 +1,105 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ //==============================================
+ //  ******** ****     **     **
+ //  **///// /**/**   /**    ****
+ //  **      /**//**  /**   **//**
+ //  ******* /** //** /**  **  //**
+ //  **////  /**  //**/** **********
+ //  **      /**   //****/**//////**
+ //  **      /**    //***/**     /**
+ //  /       //      /// //      //
+ //
+ // FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
+ //==============================================================
+ #include "fna_configuration.h"
+ #ifdef RTEP_FNA_ENABLED
+         #include "../src_rtep/rtep_fna.h" // for rtep_fna_operations
+ #endif
+ #ifdef UNIX_FNA_ENABLED
+         #include "../src_unix/unix_fna.h" // for unix_fna_operations
+ #endif
+ #ifdef FRESCAN_FNA_ENABLED
+         #include "../src_frescan/frescan_bwres_fna.h" // for frescan_fna_operations
+ #endif
+ #ifdef FWP_FNA_ENABLED
+         #include <fwp_fna.h> // for fwp_fna_operations
+ #endif
+ fna_operations_t  *fna_operations[FNA_MAX_NETWORKS] = {
+ #ifdef FRESCAN_FNA_ENABLED
+         &frescan_fna_operations,
+ #else
+         NULL,
+ #endif
+ #ifdef RTEP_FNA_ENABLED
+         &rtep_fna_operations,
+ #else
+         NULL,
+ #endif
+ #ifdef UNIX_FNA_ENABLED
+         &unix_fna_operations,
+ #else
+       NULL,
+ #endif
+ #ifdef FWP_FNA_ENABLED
+         &fwp_fna_operations
+ #else
+       NULL
+ #endif
+ };
index 0000000000000000000000000000000000000000,af1fd60a2f94e73b9061a63012aa0128e0859e9a..af1fd60a2f94e73b9061a63012aa0128e0859e9a
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,18 +1,18 @@@
+ .PHONY: none libfrescan clean cleanall
+ include ../config.mk
+ include ../rules.mk
+ SRCS := $(wildcard *.c)
+ OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
+ HDRS := $(wildcard *.h)
+ libfrescan:  $(OBJS)
+       @exec echo -e "\n>> Building FRESCAN:";
+       ld -r -o libfrescan.o *.o
+       @mv libfrescan.o $(FNA_PATH)/lib
+       @exec echo ">> [OK]"
+ %.o: %.c $(SRCS) $(HDRS)
+       @$(CC) $(CFLAGS) -c $< # 1> /dev/null
index 0000000000000000000000000000000000000000,3d5b637bd1496e264be36cfc744aebbf0eea13e9..3d5b637bd1496e264be36cfc744aebbf0eea13e9
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,35 +1,35 @@@
+ FRESCAN protocol
+ =====================
+ Name:
+ FRESCAN
+ Version:
+ May 2008
+ Status:
+ Alpha
+ Authors:
+ Daniel Sangorrin [daniel.sangorrin@unican.es] (UC),
+ Michael Gonzalez Harbour [mgh@unican.es] (UC)
+ Licence:
+ FRESCOR Licence (see COPYING)
+ Brief description:
+ Implementation of the FREScor on CAN (FRESCAN) protocol
+ URL:
+ svn co http://www.frescor.org/private/svn/frescor/fna/trunk/src_frescan/
+ Bugs:
+ See TODO
+ Description:
+ This folder contains the implementation of the FRESCAN protocol. The design,
+ arquitecture and description of the FRESCAN protocol is explained in the
+ FRESCOR D-ND1 deliverable about Fieldbus systems. The protocol is based on
+ the CAN bus, and it includes support for prioritized task-oriented message
+ communication either with fixed priorities or sporadic servers.
diff --combined src/fna/src_frescan/TODO
index 0000000000000000000000000000000000000000,41071a166a430fea1164c64ccdd7496dac60ee1f..41071a166a430fea1164c64ccdd7496dac60ee1f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,7 +1,7 @@@
+ - reserve commit functions
+ - use an internal thread as a bottom half for irq hooks
+ - corrections in fna
+        * CTU corrections
+        * fna_vres_id_t will be frsh_vres_index_T
+ - oh, i forgot CAN priorities are assigned inversely!! map them!
+ - when linking, hide symbols that are not needed externally (objcopy -G..)
index 0000000000000000000000000000000000000000,c9b142a31d1d66929ef84128c0f5fa7c61cf75a7..c9b142a31d1d66929ef84128c0f5fa7c61cf75a7
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,720 +1,720 @@@
+ /*!
+  * @file frescan.c
+  *
+  * @brief the FRESCAN protocol
+  *
+  * @version 0.01
+  *
+  * @date 20-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the implementation of the FRESCAN protocol
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include <sys/marte_configuration_parameters.h> // PATH_MX
+ #include <fcntl.h>  // open
+ #include <unistd.h> // ioctl
+ #include <stdlib.h> // malloc
+ #include <string.h> // memcpy
+ #include <assert.h>
+ #include <drivers/can.h>       // can_chip_t, can_frame_t
+ #include "frescan.h"           // frescan_init_params_t, frescan_send_params_t
+ #include "frescan_queues.h"    // init, enqueue, requeue
+ #include "frescan_data.h"      // init, frescan_data
+ #include "frescan_servers.h"   // init, frame_sent
+ #include "frescan_debug.h"     // DEBUG
+ #include "frescan_id.h"        // frescan_id_set_field, frescan_id_get_field
+ #include "frescan_hw_buffer.h" // frescan_hw_buffer_update
+ #include "frescan_packets.h"
+ static int frescan_hook_frame_recv (const struct can_chip_t *chip,
+                                     struct can_frame_t *frame);
+ static int frescan_hook_frame_sent(const struct can_chip_t *chip);
+ static int frescan_hook_frame_aborted(const struct can_chip_t *chip);
+ /**
+  * frescan_init - initializes the network and the internal structures
+  *
+  * @params: the initialization parameters
+  *
+  * This function initializes the frescan network protocol.
+  *
+  * First it opens and configures the corresponding CAN chip device. For the
+  * CAN chip acceptance filter we use a dual filter configuration. The first
+  * filter is to set my local address address and the second one is to allow
+  * broadcast messages.
+  *
+  * Once the CAN chip is configured we call the initialization functions of
+  * the rest of modules of frescan.
+  *
+  */
+ int frescan_init(frescan_init_params_t *params)
+ {
+         int fd, ret;
+         char can_path[PATH_MX];
+         struct ioctl_filters_t ioctl_filters;
+         struct can_filter_t filters[2];
+         snprintf(can_path, PATH_MX, "/dev/can%u", params->net);
+         DEBUG(FRESCAN_INIT_ENABLE_DEBUG, "open %s\n", can_path);
+         fd = open (can_path, O_RDWR);
+         if (fd == -1) {
+                 FRESCAN_ERROR ("could not open /dev/can%u\n", params->net);
+                 FRESCAN_ERROR ("hint: check driver or card installation\n");
+                 return -1;
+         }
+         DEBUG(FRESCAN_INIT_ENABLE_DEBUG, "set acceptance filters\n");
+         filters[0].mask = 0xFFFFFFFF;
+         frescan_id_set_field(&filters[0].mask, FRESCAN_FIELD_DEST,0x00);
+         filters[0].code = 0;
+         frescan_id_set_field(&filters[0].code, FRESCAN_FIELD_DEST,params->node);
+         filters[1].mask = filters[0].mask;
+         filters[1].code = 0;
+         frescan_id_set_field(&filters[1].code,
+                              FRESCAN_FIELD_DEST,
+                              FRESCAN_BROADCAST_ADDR);
+         ioctl_filters.filters = filters;
+         ioctl_filters.len = 2;
+         ret = ioctl(fd, CAN_IOCTL_SET_FILTERS, &ioctl_filters);
+         if (ret == -1) {
+                 FRESCAN_ERROR ("ioctl CAN_IOCTL_SET_FILTERS failed /dev/can%u\n",
+                        params->net);
+                 return -1;
+         }
+         DEBUG(FRESCAN_INIT_ENABLE_DEBUG, "set tx, rx, abort hooks\n");
+         ret = ioctl(fd, CAN_IOCTL_SET_TX_HOOK, frescan_hook_frame_sent);
+         if (ret == -1) {
+                 FRESCAN_ERROR ("ioctl CAN_IOCTL_SET_TX_HOOK failed /dev/can%u\n",
+                        params->net);
+                 return -1;
+         }
+         ret = ioctl(fd, CAN_IOCTL_SET_RX_HOOK, frescan_hook_frame_recv);
+         if (ret == -1) {
+                 FRESCAN_ERROR ("ioctl CAN_IOCTL_SET_RX_HOOK failed /dev/can%u\n",
+                        params->net);
+                 return -1;
+         }
+         ret = ioctl(fd, CAN_IOCTL_SET_AB_HOOK, frescan_hook_frame_aborted);
+         if (ret == -1) {
+                 FRESCAN_ERROR ("ioctl CAN_IOCTL_SET_AB_HOOK failed /dev/can%u\n",
+                        params->net);
+                 return -1;
+         }
+         DEBUG(FRESCAN_INIT_ENABLE_DEBUG, "init the rest of modules\n");
+         ret = frescan_data_init(fd, params);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not initialize the global data\n");
+                 return -1;
+         }
+         ret = frescan_packets_init();
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not initialize the packets pool\n");
+                 return -1;
+         }
+         ret = frescan_queues_init(&frescan_data[params->net].queues, params);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not initialize the queues\n");
+                 return -1;
+         }
+         ret = frescan_servers_init(params->net);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not initialize the servers\n");
+                 return -1;
+         }
+         return 0;
+ }
+ /**
+  * frescan_send - send a message
+  *
+  * @params: the parameters needed by the protocol to send the message
+  * @msg: the message buffer
+  * @size: the size of the message
+  *
+  * This is one of the main functions of the protocol and it provides the
+  * means to send a message through the protocol stack.
+  */
+ int frescan_send(const frescan_send_params_t *params,
+                  const uint8_t *msg,
+                  const size_t size)
+ {
+         int ret;
+         frescan_packet_t *packet;
+         frescan_prio_queue_t *pqueue;
+         DEBUG(FRESCAN_SEND_ENABLE_DEBUG || FRESCAN_FRAG_ENABLE_DEBUG,
+               "checking arguments (msg size=%d)\n", size);
+         if ((params == NULL) || (msg == NULL) || (size == 0)) {
+                 FRESCAN_ERROR("arguments are not ok\n");
+                 return -1;
+         }
+         DEBUG(FRESCAN_SEND_ENABLE_DEBUG, "allocating a packet\n");
+         FRESCAN_ACQUIRE_LOCK(&frescan_data[params->net].lock);
+         packet = frescan_packets_alloc();
+         FRESCAN_RELEASE_LOCK(&frescan_data[params->net].lock);
+         if (packet == NULL) {
+                 FRESCAN_ERROR("could not allocate packet\n");
+                 return -1;
+         }
+         packet->flags = params->flags; // set the flags (to remember them)
+         DEBUG(FRESCAN_SEND_ENABLE_DEBUG, "allocating a frame\n");
+         FRESCAN_ACQUIRE_LOCK(&frescan_data[params->net].lock);
+         packet->frame = can_framespool_alloc();
+         FRESCAN_RELEASE_LOCK(&frescan_data[params->net].lock);
+         if (packet->frame == NULL) {
+                 FRESCAN_ERROR("could not allocate frame\n");
+                 return -1;
+         }
+         DEBUG(FRESCAN_SEND_ENABLE_DEBUG, "set values for the frame header\n");
+         packet->frame->is_extended_format = true;
+         packet->frame->is_rtr = false;
+         if (params->flags & FRESCAN_FP) {
+                 // NOTE: frag id for fp is: FRESCAN_MX_IDS, so the servers can
+                 // have IDs in the range (0 .. FRESCAN_MX_IDS-1)
+                 frescan_id_set_field(&packet->frame->id,
+                                      FRESCAN_FIELD_FRAG_ID,
+                                      (uint32_t)FRESCAN_MX_IDS);
+                 frescan_id_set_field(&packet->frame->id,
+                                       FRESCAN_FIELD_PRIO,
+                                       (uint32_t)params->prio);
+         } else {
+                 // NOTE: the priority is put when the packet is dequeued
+                 // and it is the priority of th server
+                 frescan_id_set_field(&packet->frame->id,
+                                      FRESCAN_FIELD_FRAG_ID,
+                                      (uint32_t)params->ss);
+         }
+         frescan_id_set_field(&packet->frame->id,
+                              FRESCAN_FIELD_DEST,
+                              (uint32_t)params->to);
+         frescan_id_set_field(&packet->frame->id,
+                              FRESCAN_FIELD_SRC,
+                              (uint32_t)frescan_data[params->net].local_node);
+         frescan_id_set_field(&packet->frame->id,
+                               FRESCAN_FIELD_CHAN,
+                               (uint32_t)params->channel);
+         DEBUG(FRESCAN_SEND_ENABLE_DEBUG, "set the packet data bytes\n");
+         if (params->flags & FRESCAN_ASYNC) {
+                 // allocate a buffer and copy the data
+                 // NOTE: instead of this we could use a chain of frames but
+                 // i think it would be inefficient since each one can only
+                 // hold 8 user bytes and we need to write its headers.
+                 FRESCAN_ACQUIRE_LOCK(&frescan_data[params->net].lock);
+                 packet->buffer_head = (uint8_t *)malloc(size*sizeof(uint8_t)); // TODO: FREE IT!!!
+                 FRESCAN_RELEASE_LOCK(&frescan_data[params->net].lock);
+                 memcpy(packet->buffer_head, msg, size);
+         } else {
+                 packet->buffer_head = (uint8_t *)msg;
+         }
+         packet->buffer_read_pointer = packet->buffer_head;
+         packet->buffer_pending_bytes = size;
+         pqueue = frescan_data[params->net].queues.tx_fp_queue;
+         DEBUG(FRESCAN_SEND_ENABLE_DEBUG, "enqueue the packet\n");
+         if (packet->flags & FRESCAN_FP) {
+                 FRESCAN_ACQUIRE_LOCK(&frescan_data[params->net].lock);
+                 ret = frescan_pqueue_enqueue(pqueue, packet, params->prio);
+                 FRESCAN_RELEASE_LOCK(&frescan_data[params->net].lock);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("could not enqueue the packet\n");
+                         return -1;
+                 }
+         } else {
+                 FRESCAN_ACQUIRE_LOCK(&frescan_data[params->net].lock);
+                 ret = frescan_servers_enqueue(params->net, params->ss, packet);
+                 FRESCAN_RELEASE_LOCK(&frescan_data[params->net].lock);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("could not enqueue the packet\n");
+                         return -1;
+                 }
+         }
+         FRESCAN_ACQUIRE_LOCK(&frescan_data[params->net].lock);
+         ret = frescan_hw_buffer_update(params->net);
+         FRESCAN_RELEASE_LOCK(&frescan_data[params->net].lock);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not update hw buffer\n");
+                 return -1;
+         }
+         return 0;
+ }
+ /**
+  * frescan_recv - receive a message
+  *
+  * @params: the parameters needed by the protocol to receive the message
+  * @msg: the message buffer
+  * @size: the size of the message buffer
+  * @recv_bytes: the number of bytes received
+  * @from: the node that sent the message
+  * @prio: the priority of the message
+  *
+  * This is one of the main functions of the protocol and it provides the
+  * means to receive a message through the protocol stack.
+  */
+ int frescan_recv(const frescan_recv_params_t *params,
+                  uint8_t *msg,
+                  const size_t size,
+                  size_t *recv_bytes,
+                  frescan_node_t *from,
+                  frescan_prio_t *prio)
+ {
+         int ret;
+         frescan_prio_queue_t *pqueue;
+         bool blocking;
+         frescan_packet_t *head, *packet;
+         if (params->flags & FRESCAN_SYNC) {
+                 DEBUG(FRESCAN_RECV_ENABLE_DEBUG,
+                       "receive a packet in blocking mode\n");
+                 blocking = true;
+         } else {
+                 DEBUG(FRESCAN_RECV_ENABLE_DEBUG,
+                       "receive a packet in non-blocking mode\n");
+                 blocking = false;
+         }
+         pqueue = frescan_data[params->net].queues.rx_channel_queues
+                                                              [params->channel];
+         ret = frescan_pqueue_dequeue(pqueue, &head, prio, blocking);
+         if (ret != 0) {
+                 FRESCAN_ERROR ("could not dequeue packet\n");
+                 return -1;
+         }
+         if (head == NULL) {
+                 if (blocking == false) {
+                         DEBUG(FRESCAN_RECV_ENABLE_DEBUG,
+                               "blocking false, no packets\n");
+                         *recv_bytes = 0;
+                         return 0;
+                 } else {
+                         FRESCAN_ERROR ("blocking true, and packet = null\n");
+                         return -1;
+                 }
+         }
+         DEBUG(FRESCAN_RECV_ENABLE_DEBUG,
+               "traverse the list of packets for this message\n");
+         *recv_bytes = 0;
+         FRESCAN_ACQUIRE_LOCK(&frescan_data[params->net].lock);
+         list_for_each_entry(packet, &head->msg_list, msg_list) {
+                 // TODO: memory checks, delete the packets
+                 memcpy(msg + *recv_bytes,
+                        packet->frame->data,
+                        packet->frame->dlc);
+                 *recv_bytes += packet->frame->dlc;
+                 *from = (frescan_node_t)frescan_id_get_field(packet->frame->id,
+                                                              FRESCAN_FIELD_SRC);
+                 DEBUG(FRESCAN_RECV_ENABLE_DEBUG,
+                       "ID Packet, dlc: %u, frame pool pos: %u, from:%u\n",
+                       packet->frame->dlc, packet->frame->pool_pos, *from);
+                 ret = can_framespool_free(packet->frame);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("could not free frame\n");
+                         return -1;
+                 }
+                 ret = frescan_packets_free(packet);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("could not free packet\n");
+                         return -1;
+                 }
+         }
+         ret = frescan_packets_free(head);
+         FRESCAN_RELEASE_LOCK(&frescan_data[params->net].lock);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not free head packet\n");
+                 return -1;
+         }
+         DEBUG(FRESCAN_RECV_ENABLE_DEBUG,
+               "received bytes: %u\n", *recv_bytes);
+         return 0;
+ }
+ /**
+  * frescan_hook_frame_recv - frame received hook
+  *
+  * This function will be called by the CAN driver's IRQ handler when a frame
+  * is received so we can store it in an appropiate queue.
+  *
+  * NOTE: in the future it could consist simply of signaling a semaphore to
+  * let a bottom half thread do the hard work.
+  */
+ static int frescan_hook_frame_recv (const struct can_chip_t *chip,
+                                     struct can_frame_t *frame)
+ {
+         int i, ret;
+         uint32_t prio, dest, src, channel, frag_id, frag_flag;
+         frescan_packet_t *packet, *head;
+         frescan_prio_queue_t *pqueue;
+         int net;
+         net = chip->minor;
+         DEBUG(FRESCAN_RX_HOOK_ENABLE_DEBUG, "received a frame, net=%d\n", net);
+         DEBUG(FRESCAN_RX_HOOK_ENABLE_DEBUG || FRESCAN_FRAG_ENABLE_DEBUG,
+               "%s %s, id=0x%X, dlc=%u, pool:%u\n",
+               (frame->is_extended_format) ? "Ext" : "Stnd",
+               (frame->is_rtr) ? "RTR Frame" : "DATA Frame",
+               frame->id,
+               frame->dlc,
+               frame->pool_pos);
+         for (i=0; i<frame->dlc; i++) {
+                 DEBUG(FRESCAN_RX_HOOK_ENABLE_DEBUG,
+                       "data[%d] = 0x%X;\n", i, frame->data[i]);
+         }
+         prio      = frescan_id_get_field(frame->id, FRESCAN_FIELD_PRIO);
+         dest      = frescan_id_get_field(frame->id, FRESCAN_FIELD_DEST);
+         src       = frescan_id_get_field(frame->id, FRESCAN_FIELD_SRC);
+         channel   = frescan_id_get_field(frame->id, FRESCAN_FIELD_CHAN);
+         frag_id   = frescan_id_get_field(frame->id, FRESCAN_FIELD_FRAG_ID);
+         frag_flag = frescan_id_get_field(frame->id, FRESCAN_FIELD_FRAG_FLAG);
+         DEBUG(FRESCAN_RX_HOOK_ENABLE_DEBUG || FRESCAN_FRAG_ENABLE_DEBUG,
+               "prio:%u dest:%u src:%u chan:%u id:%u flag:%u\n",
+               prio, dest, src, channel, frag_id, frag_flag);
+         DEBUG(FRESCAN_RX_HOOK_ENABLE_DEBUG,
+               "enqueue the packet in ID queue\n");
+         packet = frescan_packets_alloc();
+         if (packet == NULL) {
+                 FRESCAN_ERROR("could not allocate packet\n");
+                 return -1;
+         }
+         packet->frame = frame;
+         if (frag_id == FRESCAN_MX_IDS) {
+                 head = frescan_data[net].id_fp_queues[src][prio];
+         } else {
+                 head = frescan_data[net].id_queues[src][frag_id];
+         }
+         if (head == NULL) {
+                 DEBUG(FRESCAN_RX_HOOK_ENABLE_DEBUG ||
+                                 FRESCAN_FRAG_ENABLE_DEBUG,
+                 "allocate head for id=%u\n", frag_id);
+                 head = frescan_packets_alloc();
+                 if (head == NULL) {
+                         FRESCAN_ERROR("could not allocate packet\n");
+                         return -1;
+                 }
+                 INIT_LIST_HEAD(&head->msg_list);
+                 if (frag_id == FRESCAN_MX_IDS) {
+                         frescan_data[net].id_fp_queues[src][prio] = head;
+                 } else {
+                         frescan_data[net].id_queues[src][frag_id] = head;
+                 }
+         }
+         list_add_tail(&packet->msg_list, &head->msg_list);
+         if (frag_flag == false) {
+                 DEBUG(FRESCAN_RX_HOOK_ENABLE_DEBUG ||
+                                 FRESCAN_FRAG_ENABLE_DEBUG,
+                 "message complete, move msg to channel\n");
+                 // TODO: select the highest priority??
+                 pqueue = frescan_data[net].queues.rx_channel_queues[channel];
+                 ret = frescan_pqueue_enqueue(pqueue, head, prio);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("could not enqueue message in channel queue\n");
+                         return -1;
+                 }
+                 if (frag_id == FRESCAN_MX_IDS) {
+                         frescan_data[net].id_fp_queues[src][prio] = NULL;
+                 } else {
+                         frescan_data[net].id_queues[src][frag_id] = NULL;
+                 }
+         } else {
+                 DEBUG(FRESCAN_RX_HOOK_ENABLE_DEBUG ||
+                                 FRESCAN_FRAG_ENABLE_DEBUG,
+                 "message not complete, wait for more fragments\n");
+         }
+         // NOTE: don't forget to free the frame and the packet when it is
+         // read by the user application
+         return 0;
+ };
+ /**
+  * frescan_hook_frame_sent - frame sent hook
+  *
+  * This function will be called by the CAN driver's IRQ handler when a frame
+  * is sent through the CAN bus so we can enqueue another one, signal a
+  * semaphore, consume sporadic server capacity...
+  */
+ static int frescan_hook_frame_sent(const struct can_chip_t *chip)
+ {
+         int ret;
+         frescan_packet_t *packet;
+         frescan_prio_queue_t *pqueue;
+         frescan_prio_t prio;
+         frescan_ss_t id;
+         packet = frescan_data[chip->minor].last_packet;
+         assert(packet != NULL);
+         id = frescan_id_get_field(packet->frame->id,
+                                   FRESCAN_FIELD_FRAG_ID);
+         DEBUG(FRESCAN_SENT_HOOK_ENABLE_DEBUG,
+               "frame sent, minor:%u flags:0x%X frag_id:0x%X\n",
+               chip->minor, packet->flags, id);
+         if (packet->flags & FRESCAN_SS) {
+                 DEBUG(FRESCAN_SENT_HOOK_ENABLE_DEBUG,
+                       "calling frame_sent + program repl for id:%u\n", id);
+                 ret = frescan_servers_frame_sent(chip->minor, id, packet);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("could not let the server a frame was sent\n");
+                         return -1;
+                 }
+         }
+         DEBUG(FRESCAN_SENT_HOOK_ENABLE_DEBUG || FRESCAN_FRAG_ENABLE_DEBUG,
+               "last packet buffer_pending_bytes=%u\n",
+               packet->buffer_pending_bytes);
+         if (packet->buffer_pending_bytes > 0) {
+                 if (packet->flags & FRESCAN_FP) {
+                         prio = frescan_id_get_field(packet->frame->id,
+                                         FRESCAN_FIELD_PRIO);
+                         DEBUG(FRESCAN_FRAG_ENABLE_DEBUG,
+                               "requeue fp packet, prio:%u\n", prio);
+                         pqueue = frescan_data[chip->minor].queues.tx_fp_queue;
+                         ret = frescan_pqueue_requeue(pqueue, packet, prio);
+                         if (ret != 0) {
+                                 FRESCAN_ERROR("could not requeue the packet packet:%p flags:0x%X\n", packet, packet->flags);
+                                 return -1;
+                         }
+                 } else if (packet->flags & FRESCAN_SS) {
+                         DEBUG(FRESCAN_FRAG_ENABLE_DEBUG,
+                               "requeue server %u packet\n", id);
+                         ret = frescan_servers_requeue(chip->minor, id, packet);
+                         if (ret != 0) {
+                                 FRESCAN_ERROR("could not requeue the packet\n");
+                                 return -1;
+                         }
+                 } else {
+                         FRESCAN_ERROR("flags are not correct\n");
+                         return -1;
+                 }
+         } else {
+                 DEBUG(FRESCAN_FRAG_ENABLE_DEBUG,
+                       "all packet fragmets sent, freeing the packet\n");
+                 ret = can_framespool_free(packet->frame);
+                 if (ret != 0)  {
+                         FRESCAN_ERROR ("could not free the frame\n");
+                         return ret;
+                 }
+                 ret = frescan_packets_free(packet);
+                 if (ret != 0)  {
+                         FRESCAN_ERROR ("could not free the packet\n");
+                         return ret;
+                 }
+                 // TODO: signal semaphore for send_sync
+         }
+         frescan_data[chip->minor].last_packet = NULL;
+         ret = frescan_hw_buffer_update(chip->minor);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not update hw buffer\n");
+                 return -1;
+         }
+         return 0;
+ };
+ /**
+  * frescan_hook_frame_aborted - frame frame aborted hook
+  *
+  * This function will be called by the CAN driver's IRQ handler when a frame
+  * is aborted (because another frame with higher priority is waiting). We
+  * have to requeue the frame and update the buffer.
+  */
+ static int frescan_hook_frame_aborted(const struct can_chip_t *chip)
+ {
+         int ret;
+         frescan_packet_t *packet;
+         frescan_prio_queue_t *pqueue;
+         frescan_prio_t prio;
+         frescan_ss_t id;
+         packet = frescan_data[chip->minor].last_packet;
+         id = frescan_id_get_field(packet->frame->id,
+                                   FRESCAN_FIELD_FRAG_ID);
+         DEBUG(FRESCAN_SENT_HOOK_ENABLE_DEBUG,
+               "frame aborted, minor:%u flags:0x%X frag_id:0x%X\n",
+               chip->minor, packet->flags, id);
+         if (packet->flags & FRESCAN_FP) {
+                 prio = frescan_id_get_field(packet->frame->id,
+                                             FRESCAN_FIELD_PRIO);
+                 DEBUG(FRESCAN_FRAG_ENABLE_DEBUG,
+                       "requeue fp packet, prio:%u\n", prio);
+                 pqueue = frescan_data[chip->minor].queues.tx_fp_queue;
+                 ret = frescan_pqueue_requeue(pqueue, packet, prio);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("could not requeue the packet\n");
+                         return -1;
+                 }
+         } else if (packet->flags & FRESCAN_SS) {
+                 DEBUG(FRESCAN_FRAG_ENABLE_DEBUG,
+                       "requeue server %u packet\n", id);
+                 ret = frescan_servers_requeue(chip->minor, id, packet);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("could not requeue the packet\n");
+                         return -1;
+                 }
+         } else {
+                 FRESCAN_ERROR("flags are not correct\n");
+                 return -1;
+         }
+         frescan_data[chip->minor].last_packet = NULL;
+         ret = frescan_hw_buffer_update(chip->minor);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not update hw buffer\n");
+                 return -1;
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,b5d7b450d1092e32a6de1b77396ae4ef94e6d255..b5d7b450d1092e32a6de1b77396ae4ef94e6d255
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,122 +1,122 @@@
+ /*!
+  * @file frescan.h
+  *
+  * @brief interface of the FRESCAN protocol
+  *
+  * @version 0.01
+  *
+  * @date 20-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the interface to the FRESCAN protocol
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_H_
+ #define _FRESCAN_H_
+ #include "frescan_types.h"
+ /**
+  * frescan_init - initializes the network and the internal structures
+  *
+  * @params: the initialization parameters
+  */
+ int frescan_init(frescan_init_params_t *params);
+ /**
+  * frescan_send - send a message
+  *
+  * @params: the parameters needed by the protocol to send the message
+  * @msg: the message buffer
+  * @size: the size of the message
+  *
+  * This is one of the main functions of the protocol and it provides the
+  * means to send a message through the protocol stack.
+  */
+ int frescan_send(const frescan_send_params_t *params,
+                  const uint8_t *msg,
+                  const size_t size);
+ /**
+  * frescan_recv - receive a message
+  *
+  * @params: the parameters needed by the protocol to receive the message
+  * @msg: the message buffer
+  * @size: the size of the message buffer
+  * @recv_bytes: the number of bytes received
+  * @from: the node that sent the message
+  * @prio: the priority of the message
+  *
+  * This is one of the main functions of the protocol and it provides the
+  * means to receive a message through the protocol stack.
+  */
+ int frescan_recv(const frescan_recv_params_t *params,
+                  uint8_t *msg,
+                  const size_t size,
+                  size_t *recv_bytes,
+                  frescan_node_t *from,
+                  frescan_prio_t *prio);
+ #endif // _FRESCAN_H_
index 0000000000000000000000000000000000000000,71ed086858817fcfccfa232eeddada55ff6937d6..71ed086858817fcfccfa232eeddada55ff6937d6
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,368 +1,368 @@@
+ /*!
+  * @file frescan_bwres.c
+  *
+  * @brief FRESCAN bandwidth reservation layer
+  *
+  * This module contains function to negotiate contracts and get the
+  * corresponding frescan sporadic servers.
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include "frsh.h"
+ #include "frescan_bwres.h"
+ #include "frescan_bwres_requests.h"
+ #include "frescan_bwres_robjs.h"
+ #include "frescan_bwres_messages.h"
+ #include "frescan_bwres_threads.h"
+ #include "frescan_bwres_analysis.h"
+ #include "frescan_data.h"
+ #include "frescan_debug.h"
+ #include "frescan_config.h"
+ #include "frescan_servers.h"
+ /**
+  * frescan_bwres_init()
+  *
+  * Init the frescan bandwidth reservation layer
+  */
+ int frescan_bwres_init(frescan_network_t net)
+ {
+         int ret;
+         frescan_node_t node;
+         frescan_ss_t neg_msg_ss_id;
+         frescan_server_params_t server_params;
+         frescan_bwres_sa_init_params_t init_params;
+         frsh_contract_t neg_msgs_contract;
+         frsh_rel_time_t neg_msgs_budget;
+         frsh_rel_time_t neg_msgs_period;
+         init_params.min_prio = FRESCAN_BWRES_SS_MIN_PRIO;
+         init_params.max_prio = FRESCAN_BWRES_SS_MAX_PRIO;
+         if (frescan_data[net].local_node == FRESCAN_BWRES_MASTER_NODE) {
+             ret = frescan_bwres_sa_init(&frescan_data[net].scenario,
+                                         &init_params);
+             if (ret != 0) return ret;
+             // Add contracts for the negotiation messages
+             ret = frsh_contract_init(&neg_msgs_contract);
+             if (ret != 0) return ret;
+             neg_msgs_budget = frsh_usec_to_rel_time(
+                                         (long)FRESCAN_FRAME_TX_TIME_US *
+                                               FRESCAN_BWRES_NEG_MSG_BUDGET);
+             neg_msgs_period = frsh_usec_to_rel_time(
+                                         (long)FRESCAN_BWRES_NEG_MSG_PERIOD);
+             ret = frsh_contract_set_basic_params(&neg_msgs_contract,
+                                                  &neg_msgs_budget,
+                                                  &neg_msgs_period,
+                                                  FRSH_WT_INDETERMINATE,
+                                                  FRSH_CT_REGULAR);
+             if (ret != 0) return ret;
+             ret = frsh_contract_set_preemption_level
+                             (&neg_msgs_contract, FRESCAN_BWRES_NEG_MSG_PRIO);
+             if (ret != 0) return ret;
+             for(node=0; node<FRESCAN_MX_NODES; node++) {
+                     ret = freelist_init(&frescan_data[net].scenario.
+                                                         ss_id_freelist[node],
+                                                         FRESCAN_MX_IDS);
+                     if (ret != 0) return ret;
+                     ret = freelist_alloc(&frescan_data[net].scenario.
+                                                         ss_id_freelist[node]);
+                     if (ret < 0) return -1;
+                     neg_msg_ss_id = (frescan_ss_t)ret;
+                     DEBUG(FRESCAN_BWRES_ENABLE_DEBUG,
+                           "manager node:%u b:(%d,%d) t:(%d,%d) p:%u ss:%u\n",
+                           node,
+                           neg_msgs_budget.tv_sec, neg_msgs_budget.tv_nsec,
+                           neg_msgs_period.tv_sec, neg_msgs_period.tv_nsec,
+                           FRESCAN_BWRES_NEG_MSG_PRIO,
+                           neg_msg_ss_id);
+                     ret = frescan_bwres_sa_add_contract
+                                     (&frescan_data[net].scenario,
+                                      neg_msg_ss_id,
+                                      node,
+                                      &neg_msgs_contract);
+                     if (ret != 0) return ret;
+             }
+         }
+         server_params.budget = FRESCAN_BWRES_NEG_MSG_BUDGET;
+         server_params.period = frsh_rel_time_to_timespec(
+                                         frsh_usec_to_rel_time(
+                                         (long)FRESCAN_BWRES_NEG_MSG_PERIOD));
+         server_params.prio   = FRESCAN_BWRES_NEG_MSG_PRIO;
+         ret = frescan_servers_create(net, &server_params,
+                                      &frescan_data[net].neg_messages_ss_id);
+         if (ret != 0) return ret;
+         DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "neg_msg_ss_id: %u\n",
+               frescan_data[net].neg_messages_ss_id);
+         ret = frescan_bwres_robjs_init(FRESCAN_BWRES_ROBJS_MX_CEILING);
+         if (ret != 0) return ret;
+         ret = frescan_bwres_requests_init(FRESCAN_BWRES_REQ_MX_CEILING);
+         if (ret != 0) return ret;
+         ret = frescan_messages_init(net);
+         if (ret != 0) return ret;
+         ret = frescan_manager_thread_create(net);
+         if (ret != 0) return ret;
+         ret = frescan_acceptor_thread_create(net);
+         if (ret != 0) return ret;
+         return 0;
+ }
+ /**
+  * frescan_bwres_group_change_mode_sync()
+  *
+  * 1.- allocate and prepare the GN request
+  * 2.- enqueue the request
+  * 3.- wait in the reply object for a reply
+  *     (unless there are only cancellations)
+  * 4.- free the request
+  */
+ int frescan_bwres_group_change_mode_sync
+                 (frescan_network_t            net,
+                  const frsh_contracts_group_t *contracts_to_neg,
+                  const frsh_contracts_group_t *contracts_to_reneg,
+                  const frescan_ss_group_t     *ss_to_reneg,
+                  const frescan_ss_group_t     *ss_to_cancel,
+                  frescan_ss_group_t           *ss_new,
+                  bool                         *accepted)
+ {
+         int ret;
+         frescan_bwres_request_id_t req;
+         frescan_bwres_request_data_t *req_data;
+         DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "preparing a GN request\n");
+         ret = frescan_bwres_requests_alloc(&req);
+         if (ret != 0) return ret;
+         ret = frescan_bwres_requests_get_data(req, &req_data);
+         if (ret != 0) return ret;
+         req_data->net          = net;
+         req_data->type         = FRESCAN_BWRES_REQ_GN;
+         req_data->req          = req;
+         req_data->request_node = frescan_data[net].local_node;
+         if (contracts_to_neg == NULL) {
+                 req_data->contracts_to_neg = &req_data->contracts_to_neg_data;
+                 req_data->contracts_to_neg->size = 0;
+         } else {
+                 req_data->contracts_to_neg =
+                                 (frsh_contracts_group_t *)contracts_to_neg;
+         }
+         if (contracts_to_reneg == NULL) {
+                 req_data->contracts_to_reneg = &req_data->
+                                                        contracts_to_reneg_data;
+                 req_data->contracts_to_reneg->size = 0;
+         } else {
+                 req_data->contracts_to_reneg = (frsh_contracts_group_t *)
+                                 contracts_to_reneg;
+         }
+         if (ss_to_reneg == NULL) {
+                 req_data->ss_to_reneg = &req_data->ss_to_reneg_data;
+                 req_data->ss_to_reneg->size = 0;
+         } else {
+                 req_data->ss_to_reneg = (frescan_ss_group_t *)ss_to_reneg;
+         }
+         if (ss_to_cancel == NULL) {
+                 req_data->ss_to_cancel = &req_data->ss_to_cancel_data;
+                 req_data->ss_to_cancel->size = 0;
+         } else {
+                 req_data->ss_to_cancel = (frescan_ss_group_t *)ss_to_cancel;
+         }
+         if (ss_new == NULL) {
+                 req_data->ss_new = &req_data->ss_new_data;
+                 req_data->ss_new->size = 0;
+         } else {
+                 req_data->ss_new = ss_new;
+         }
+         ret = frescan_bwres_robjs_alloc(&req_data->robj, FRESCAN_BWRES_MX_PRIO);
+         if (ret != 0) return ret;
+         DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "enqueue the negotiation request\n");
+         ret = frescan_bwres_requests_enqueue(req);
+         if (ret != 0) return ret;
+         DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "wait for a reply\n");
+         ret = frescan_bwres_robjs_wait(req_data->robj);
+         if (ret != 0) return ret;
+         ret = frescan_bwres_robjs_free(req_data->robj);
+         if (ret != 0) return ret;
+         switch (req_data->return_value) {
+                 case FRESCAN_BWRES_REQ_ACCEPTED:
+                         DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "negotiation OK\n");
+                         *accepted = true;
+                         break;
+                 case FRESCAN_BWRES_REQ_NOT_ACCEPTED:
+                         DEBUG(FRESCAN_BWRES_ENABLE_DEBUG, "negotiation FAIL\n");
+                         *accepted = false;
+                         break;
+                 default:
+                         FRESCAN_ERROR("return_value unknown\n");
+                         return -1;
+         }
+         ret = frescan_bwres_requests_free(req);
+         if (ret != 0) return ret;
+         return 0;
+ }
+ /**
+  * frescan_bwres_negotiate()
+  */
+ int frescan_bwres_negotiate(frescan_network_t net,
+                             const frsh_contract_t *contract,
+                             frescan_ss_t *ss,
+                             bool *accepted)
+ {
+         int ret;
+         frsh_contracts_group_t contracts_to_neg;
+         frescan_ss_group_t ss_new;
+         contracts_to_neg.size = 1;
+         contracts_to_neg.contracts[0] = *contract;
+         ret = frescan_bwres_group_change_mode_sync
+                         (net, &contracts_to_neg, NULL, NULL,
+                          NULL, &ss_new, accepted);
+         if (ret != 0) return ret;
+         if (*accepted) {
+                 *ss = ss_new.ss[0];
+         }
+         return 0;
+ }
+ /**
+  * frescan_bwres_renegotiate()
+  */
+ int frescan_bwres_renegotiate(frescan_network_t net,
+                               const frsh_contract_t *contract,
+                               frescan_ss_t ss,
+                               bool *accepted)
+ {
+         frsh_contracts_group_t contracts_to_reneg;
+         frescan_ss_group_t ss_to_reneg;
+         contracts_to_reneg.size = 1;
+         contracts_to_reneg.contracts[0] = *contract;
+         ss_to_reneg.size = 1;
+         ss_to_reneg.ss[0] = ss;
+         return frescan_bwres_group_change_mode_sync
+                 (net, NULL, &contracts_to_reneg, &ss_to_reneg,
+                  NULL, NULL, accepted);
+ }
+ /**
+  * frescan_bwres_cancel()
+  */
+ int frescan_bwres_cancel(frescan_network_t net,
+                          frescan_ss_t      ss)
+ {
+         frescan_ss_group_t ss_to_cancel;
+         ss_to_cancel.size = 1;
+         ss_to_cancel.ss[0] = ss;
+         return frescan_bwres_group_change_mode_sync
+                         (net, NULL, NULL, NULL, &ss_to_cancel, NULL, NULL);
+ }
index 0000000000000000000000000000000000000000,3b4c6767cefdcb5d61f02b249575303e41922eb8..3b4c6767cefdcb5d61f02b249575303e41922eb8
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,102 +1,102 @@@
+ /*!
+  * @file frescan_bwres.h
+  *
+  * @brief FRESCAN bandwidth reservation layer
+  *
+  * This module contains function to negotiate contracts and get the
+  * corresponding frescan sporadic servers.
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_BWRES_H_
+ #define _FRESCAN_BWRES_H_
+ #include "frescan_types.h"
+ extern int frescan_bwres_init(frescan_network_t net);
+ extern int frescan_bwres_group_change_mode_sync
+                 (frescan_network_t            net,
+                  const frsh_contracts_group_t *contracts_to_neg,
+                  const frsh_contracts_group_t *contracts_to_reneg,
+                  const frescan_ss_group_t     *ss_to_reneg,
+                  const frescan_ss_group_t     *ss_to_cancel,
+                  frescan_ss_group_t           *ss_new,
+                  bool *accepted);
+ extern int frescan_bwres_negotiate(frescan_network_t net,
+                                    const frsh_contract_t *contract,
+                                    frescan_ss_t *ss,
+                                    bool *accepted);
+ extern int frescan_bwres_renegotiate(frescan_network_t net,
+                                      const frsh_contract_t *contract,
+                                      frescan_ss_t ss,
+                                      bool *accepted);
+ extern int frescan_bwres_cancel(frescan_network_t net,
+                                 frescan_ss_t      ss);
+ // TODO: add functions for reservation requests
+ #endif // _FRESCAN_BWRES_H_
index 0000000000000000000000000000000000000000,7d369837b40039ef5885ae7f5fc37fb71f37300d..7d369837b40039ef5885ae7f5fc37fb71f37300d
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,281 +1,281 @@@
+ /*!
+  * @file frescan_bwres_analysis.c
+  *
+  * @brief FRESCAN bandwith reservation layer: sched analysis
+  *
+  * @version 0.02
+  *
+  * @date 3-Jul-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @comments
+  *
+  * This module contains the scheduling analysis functions for the
+  * admission tests and spare capacity distribution of the bandwith
+  * reservation (bwres) layer.
+  *
+  * The module "frescan_bwres_mode_change" must be used to apply finally this
+  * new parameters to the sporadic servers following an appropriate mode
+  * change protocol.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include <math.h>
+ #include <misc/timespec_operations.h>
+ #include <misc/linux_list.h>
+ #include <misc/freelist.h>
+ #include "frescan_bwres_analysis.h"
+ #include "frescan_debug.h"
+ /**
+  * frescan_bwres_sa_init() - init the scenario
+  *
+  * Initialize the vres list and copy the initialization parameters
+  */
+ int frescan_bwres_sa_init(frescan_bwres_sa_scenario_t          *scenario,
+                           const frescan_bwres_sa_init_params_t *params)
+ {
+         int ret;
+         frsh_sa_scenario_init_data_t fsa_scenario_init_data;
+         INIT_LIST_HEAD(&scenario->vres_head.list);
+         scenario->init_params = *params;
+         ret = freelist_init(&scenario->fsa_vres_global_id_freelist,
+                             FRESCAN_MX_NODES*FRESCAN_MX_IDS);
+         if (ret != 0) return ret;
+         fsa_scenario_init_data.min_priority = params->min_prio;
+         fsa_scenario_init_data.max_priority = params->max_prio;
+         fsa_scenario_init_data.ovhd_data.np =
+                         frsh_rel_time_to_sa_time(frsh_usec_to_rel_time(0));
+         DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG,
+               "init the scenario min_prio:%d max_prio:%d\n",
+               params->min_prio, params->max_prio);
+         ret = frsh_sa_scenario_init(&scenario->fsa_scenario,
+                                     &fsa_scenario_init_data);
+         if (ret != 0) return -1;
+         return 0;
+ }
+ /**
+  * frescan_bwres_sa_add_contract() - add a contract to the scenario
+  *
+  * create the corresponding vres structure and set its values, and add the
+  * vres to the vres list
+  */
+ int frescan_bwres_sa_add_contract(frescan_bwres_sa_scenario_t *scenario,
+                                   frescan_ss_t          ss,
+                                   frescan_node_t        node,
+                                   const frsh_contract_t *contract)
+ {
+         int ret;
+         frescan_bwres_vres_t *sa_vres = &scenario->vres_pool[node][ss];
+         sa_vres->contract = *contract;
+         sa_vres->node     = node;
+         sa_vres->ss       = ss;
+         sa_vres->old_c    = 0;
+         sa_vres->old_t    = 0;
+         sa_vres->old_p    = 0;
+         ret = freelist_alloc(&scenario->fsa_vres_global_id_freelist);
+         if (ret < 0) return -1;
+         sa_vres->fsa_vres_global_id = (frsh_sa_vres_id_t)ret;
+         list_add_tail(&sa_vres->list,
+                       &scenario->vres_head.list);
+         DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG,
+               "add contract, node:%d ss:%d globalid:%d\n",
+               node, ss, sa_vres->fsa_vres_global_id);
+         DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG,
+               "contract bmin=(%u,%u) tmax=(%u,%u) bmax=(%u,%u) tmin=(%u,%u) prio=%u\n",
+               contract->budget_min.tv_sec,
+               contract->budget_min.tv_nsec,
+               contract->period_max.tv_sec,
+               contract->period_max.tv_nsec,
+               contract->budget_max.tv_sec,
+               contract->budget_max.tv_nsec,
+               contract->period_min.tv_sec,
+               contract->period_min.tv_nsec,
+               contract->preemption_level);
+         ret = frsh_sa_scenario_add_vres(&scenario->fsa_scenario,
+                                         &sa_vres->contract,
+                                         sa_vres->fsa_vres_global_id);
+         if (ret != 0) return -1;
+         return 0;
+ }
+ /**
+  * frescan_bwres_sa_update_contract() - update a contract in the scenario
+  */
+ int frescan_bwres_sa_update_contract(frescan_bwres_sa_scenario_t  *scenario,
+                                      frescan_ss_t           ss,
+                                      frescan_node_t         node,
+                                      const frsh_contract_t  *contract,
+                                      frsh_contract_t        *old_contract)
+ {
+         int ret;
+         frescan_bwres_vres_t *sa_vres = &scenario->vres_pool[node][ss];
+         if (old_contract != NULL) {
+                 *old_contract = sa_vres->contract;
+         }
+         sa_vres->contract = *contract;
+         DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG,
+               "update contract node:%d ss:%d globalid:%d\n",
+               node, ss, sa_vres->fsa_vres_global_id);
+         ret = frsh_sa_scenario_modify_vres(&scenario->fsa_scenario,
+                                            sa_vres->fsa_vres_global_id,
+                                            &sa_vres->contract);
+         if (ret != 0) return -1;
+         return 0;
+ }
+ /**
+  * frescan_bwres_sa_remove_contract() - remove a contract from the scenario
+  */
+ int frescan_bwres_sa_remove_contract(frescan_bwres_sa_scenario_t *scenario,
+                                      frescan_ss_t                ss,
+                                      frescan_node_t              node,
+                                      frsh_contract_t             *contract)
+ {
+         int ret;
+         frescan_bwres_vres_t *sa_vres = &scenario->vres_pool[node][ss];
+         if (contract != NULL) {
+                 *contract = sa_vres->contract;
+         }
+         DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG,
+               "remove contract, node:%d ss:%d globalid:%d\n",
+               node, ss, sa_vres->fsa_vres_global_id);
+         ret = frsh_sa_scenario_del_vres(&scenario->fsa_scenario,
+                                         sa_vres->fsa_vres_global_id);
+         if (ret != 0) return -1;
+         ret = freelist_free(&scenario->fsa_vres_global_id_freelist,
+                             sa_vres->fsa_vres_global_id);
+         if (ret < 0) return -1;
+         list_del(&sa_vres->list);
+         return 0;
+ }
+ /**
+  * frescan_bwres_sa_sched_test() - perform a scheduling test on the scenario
+  *
+  */
+ int frescan_bwres_sa_sched_test(frescan_bwres_sa_scenario_t *scenario,
+                                 bool                        *is_schedulable)
+ {
+         int ret;
+         DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG, "init the fsa scenario\n");
+         ret = frsh_sa_init_analysis(&scenario->fsa_scenario);
+         if (ret != 0) return -1;
+         ret = frsh_sa_assign_priorities(&scenario->fsa_scenario);
+         if (ret != 0) return -1;
+         DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG, "do scheduling test\n");
+         ret = frsh_sa_sched_test(&scenario->fsa_scenario, is_schedulable);
+         if (ret != 0) return -1;
+         DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG, "%s\n",
+               (*is_schedulable) ? "OK" : "FAILED");
+         return 0;
+ }
+ /**
+  * frescan_bwres_sa_spare_capacity() - distribute the spare capacity
+  */
+ int frescan_bwres_sa_spare_capacity(frescan_bwres_sa_scenario_t *scenario)
+ {
+         int ret;
+         DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG, "distribute sc\n");
+         ret = frsh_sa_distribute_spare(&scenario->fsa_scenario);
+         if (ret != 0) return -1;
+         return 0;
+ }
index 0000000000000000000000000000000000000000,8ecfbfeb5ecc4e905cfa6bbeefb6bf5609cdc3b8..8ecfbfeb5ecc4e905cfa6bbeefb6bf5609cdc3b8
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,161 +1,161 @@@
+ /*!
+  * @file frescan_bwres_analysis.h
+  *
+  * @brief FRESCAN bandwith reservation layer: sched analysis
+  *
+  * @version 0.02
+  *
+  * @date 3-Jul-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @comments
+  *
+  * This module contains the scheduling analysis functions for the
+  * admission tests and spare capacity distribution of the bandwith
+  * reservation (bwres) layer.
+  *
+  * The module "frescan_bwres_mode_change" must be used to apply finally this
+  * new parameters to the sporadic servers following an appropriate mode
+  * change protocol.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_BWRES_ANALYSIS_H_
+ #define _FRESCAN_BWRES_ANALYSIS_H_
+ #include "frescan_types.h"
+ /**
+  * frescan_bwres_sa_init() - init the scenario
+  *
+  * @scenario: the scenario (in out)
+  * @params: init params (in)
+  */
+ extern int frescan_bwres_sa_init
+                           (frescan_bwres_sa_scenario_t *scenario,
+                            const frescan_bwres_sa_init_params_t *params);
+ /**
+  * frescan_bwres_sa_add_contract() - add a contract to the scenario
+  *
+  * @scenario: the scenario (in out)
+  * @ss: the preallocated ss identificator (in)
+  * @node: the node this contract belongs to (in)
+  * @contract: the new contract (in)
+  */
+ extern int frescan_bwres_sa_add_contract
+                                   (frescan_bwres_sa_scenario_t *scenario,
+                                    frescan_ss_t          ss,
+                                    frescan_node_t        node,
+                                    const frsh_contract_t *contract);
+ /**
+  * frescan_bwres_sa_update_contract() - update a contract in the scenario
+  *
+  * @scenario: the scenario (in out)
+  * @ss: the ss identificator (in)
+  * @node: the node this contract belongs to (in)
+  * @contract: the values to update the contract (in)
+  * @old_contract: the values of the previous contract. if NULL
+  *                no contract is returned (out)
+  */
+ extern int frescan_bwres_sa_update_contract
+                                      (frescan_bwres_sa_scenario_t  *scenario,
+                                       frescan_ss_t           ss,
+                                       frescan_node_t         node,
+                                       const frsh_contract_t  *contract,
+                                       frsh_contract_t        *old_contract);
+ /**
+  * frescan_bwres_sa_remove_contract() - remove a contract from the scenario
+  *
+  * @scenario: the scenario (in out)
+  * @ss: the ss to remove (in)
+  * @node: the node this contract belongs to (in)
+  * @contract: if not null, returns a copy of the contract (out)
+  */
+ extern int frescan_bwres_sa_remove_contract
+                                      (frescan_bwres_sa_scenario_t *scenario,
+                                       frescan_ss_t                ss,
+                                       frescan_node_t              node,
+                                       frsh_contract_t             *contract);
+ /**
+  * frescan_bwres_sa_sched_test() - perform a scheduling test on the scenario
+  *
+  * @scenario: the scenario (in out)
+  * @is_schedulable: if the scenario is schedulable or not (out)
+  */
+ extern int frescan_bwres_sa_sched_test(frescan_bwres_sa_scenario_t *scenario,
+                                        bool *is_schedulable);
+ /**
+  * frescan_bwres_sa_spare_capacity() - distribute the spare capacity
+  *
+  * @scenario: the scenario (in out)
+  */
+ extern int frescan_bwres_sa_spare_capacity
+                 (frescan_bwres_sa_scenario_t *scenario);
+ #endif // _FRESCAN_BWRES_ANALYSIS_H_
index 0000000000000000000000000000000000000000,0c4ca6e1cdb35069e8b073127a14e47c4ca42acd..0c4ca6e1cdb35069e8b073127a14e47c4ca42acd
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,1169 +1,1169 @@@
+ /*!
+  * @file frescan_bwres_fna.c
+  *
+  * @brief FRESCAN bandwidth reservation layer: FNA hooks
+  *
+  * This module contains hooks to integrate the FRESCAN protocol in FRSH
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include <math.h> /* ceil */
+ #include "frsh.h" /* frsh_resource_id_t, .. */
+ #include "frescan.h" /* frescan_init, ... */
+ #include "frescan_bwres.h" /* frescan_bwres_init, ... */
+ #include "frescan_types.h"
+ #include "frescan_config.h"
+ #include "fna.h" /* fna_vres_id_t, fna_endpoint_data_t */
+ #include "frescan_debug.h" /* DEBUG, FRESCAN_ERROR */
+ #include "frescan_servers.h"
+ //////////////////////////////////////////////////////////////////////
+ //           INITIALIZATION
+ //////////////////////////////////////////////////////////////////////
+ /**
+  * frescan_fna_init()
+  *
+  * This function will be hooked to the frsh_init function and it is
+  * intented to initialize the protocol and its structures.
+  *
+  * @param[in]  resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_ALREADY_INITIALIZED:
+  *      if the function has already been called before (with success) \n
+  *
+  **/
+ int frescan_fna_init(const frsh_resource_id_t resource_id)
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         init_params.net = resource_id - FRESCAN_BWRES_FNA_NET_BASE;
+         init_params.node = FRESCAN_BWRES_FNA_LOCAL_NODE;
+         init_params.tx_fp_max_prio = FRESCAN_BWRES_TX_FP_MX_PRIO;
+         init_params.rx_num_of_channels = FRESCAN_BWRES_RX_NUM_CHANNELS;
+         init_params.rx_channel_max_prio = FRESCAN_BWRES_RX_CHAN_MX_PRIO;
+         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG,
+               "Initializing FRESCAN FNA node%u\n", init_params.node);
+         ret = frescan_init(&init_params);
+         if (ret != 0) {
+                 FRESCAN_ERROR ("could not init FRESCAN\n");
+                 return ret;
+         }
+         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG, "Initializing BWRES\n");
+         ret = frescan_bwres_init(init_params.net);
+         if (ret != 0) {
+                 FRESCAN_ERROR ("could not init BWRES\n");
+                 return ret;
+         }
+         return 0;
+ }
+ ///////////////////////////////////////////////////////////////////
+ //           VIRTUAL RESOURCES
+ ///////////////////////////////////////////////////////////////////
+ int frescan_fna_group_change_mode_sync
+                 (const frsh_resource_id_t     resource_id,
+                  const frsh_contracts_group_t *contracts_to_neg,
+                  const frsh_contracts_group_t *contracts_to_reneg,
+                  const fna_vres_group_t       *vres_to_reneg,
+                  const fna_vres_group_t       *vres_to_cancel,
+                  fna_vres_group_t             *new_vres)
+ {
+         int ret, i;
+         bool accepted;
+         frescan_ss_group_t ss_to_reneg, ss_to_cancel, ss_new;
+         // convert fna_vres to ss
+         if (vres_to_reneg == NULL) {
+                 ss_to_reneg.size = 0;
+         } else {
+                 ss_to_reneg.size = vres_to_reneg->size;
+                 if (ss_to_reneg.size > FRESCAN_BWRES_MAX_GROUP_OPS) {
+                         FRESCAN_ERROR("FRESCAN_BWRES_MAX_GROUP_OPS small\n");
+                         return -1;
+                 }
+                 for(i=0; i<ss_to_reneg.size; i++) {
+                         ss_to_reneg.ss[i] =
+                                         (frescan_ss_t)vres_to_reneg->vres[i];
+                 }
+         }
+         if (vres_to_cancel == NULL) {
+                 ss_to_cancel.size = 0;
+         } else {
+                 ss_to_cancel.size = vres_to_cancel->size;
+                 if (ss_to_cancel.size > FRESCAN_BWRES_MAX_GROUP_OPS) {
+                         FRESCAN_ERROR("FRESCAN_BWRES_MAX_GROUP_OPS small\n");
+                         return -1;
+                 }
+                 for(i=0; i<ss_to_cancel.size; i++) {
+                         ss_to_cancel.ss[i] =
+                                         (frescan_ss_t)vres_to_cancel->vres[i];
+                 }
+         }
+         if ((contracts_to_neg != NULL) && (new_vres == NULL)) {
+                 FRESCAN_ERROR("new_vres is NULL\n");
+                 return -1;
+         }
+         // negotiate
+         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG,
+               "calling frescan_bwres_group_change_mode_sync\n");
+         ret = frescan_bwres_group_change_mode_sync
+                                         ((frescan_network_t)resource_id,
+                                          contracts_to_neg,
+                                          contracts_to_reneg,
+                                          &ss_to_reneg,
+                                          &ss_to_cancel,
+                                          &ss_new,
+                                          &accepted);
+         if (ret != 0) return -1;
+         if (accepted == false) {
+                 DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG, "negotiation not accepted\n");
+                 return -1; // TODO: change to constant FNA_REJECTED
+         }
+         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG, "negotiation accepted\n");
+         // convert new ss to fna_vres
+         if (contracts_to_neg != NULL) {
+                 new_vres->size = ss_new.size;
+                 DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG,
+                       "new_vres->size:%d\n", new_vres->size);
+                 for(i=0; i<new_vres->size; i++) {
+                         new_vres->vres[i] = (fna_vres_id_t)ss_new.ss[i];
+                         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG,
+                               "new_vres->vres[%d]:%u\n", i, new_vres->vres[i]);
+                 }
+         }
+         return 0;
+ }
+ /**
+  * frescan_fna_contract_negotiate()
+  *
+  * The operation negotiates a contract and if accepted it will return
+  * a fna_vres_id_t. It will also check that the given contract_id is unique
+  * within the network.
+  *
+  * If the on-line admission test is enabled, it determines whether the
+  * contract can be admitted or not based on the current contracts
+  * established in the network. Then it creates the vres and
+  * recalculates all necessary parameters for the contracts already
+  * present in the system.
+  *
+  * This is a potentially blocking operation, it returns when the
+  * system has either rejected the contract, or admitted it and made it
+  * effective.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] contract  The contract parameters to negotiate
+  * @param[out] vres The internal virtual resource id
+  *
+  * @return
+  *   0 if there are no errors (in this case it also means contract accepted) \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_TOO_MANY_VRES: if there is no space for more vres \n
+  *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+  *   FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_contract_negotiate
+                 (const frsh_resource_id_t resource_id,
+                  const frsh_contract_t *contract,
+                  fna_vres_id_t *vres)
+ {
+         int ret;
+         frsh_contracts_group_t contracts_to_neg;
+         fna_vres_group_t       new_vres;
+         contracts_to_neg.size = 1;
+         contracts_to_neg.contracts[0] = *contract;
+         ret = frescan_fna_group_change_mode_sync
+                 (resource_id, &contracts_to_neg, NULL, NULL, NULL, &new_vres);
+         if (ret != 0) return ret;
+         *vres = new_vres.vres[0];
+         return 0;
+ }
+ /**
+  * frescan_fna_contract_renegotiate_sync()
+  *
+  * The operation renegotiates a contract for an existing vres. If
+  * the on-line admission test is enabled it determines whether the
+  * contract can be admitted or not based on the current contracts
+  * established in the system. If it cannot be admitted, the old
+  * contract remains in effect and an error is returned. If it can be
+  * admitted, it recalculates all necessary parameters for the
+  * contracts already present in the system and returns zero. This is a
+  * potentially blocking operation; it returns when the system has
+  * either rejected the new contract, or admitted it and made it
+  * effective.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id to renegotiate
+  * @param[in] new_contract The new contract
+  *
+  *  @return
+  *   0 if there are no errors (in this case it also means contract accepted) \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+  *   FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_contract_renegotiate_sync
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  const frsh_contract_t *new_contract)
+ {
+         frsh_contracts_group_t contracts_to_reneg;
+         fna_vres_group_t       vres_to_reneg;
+         contracts_to_reneg.size = 1;
+         contracts_to_reneg.contracts[0] = *new_contract;
+         vres_to_reneg.size = 1;
+         vres_to_reneg.vres[0] = vres;
+         return frescan_fna_group_change_mode_sync
+                                 (resource_id, NULL, &contracts_to_reneg,
+                                  &vres_to_reneg, NULL, NULL);
+ }
+ /**
+  * frescan_fna_contract_renegotiate_async()
+  *
+  * The operation enqueues a renegotiate operation for an existing
+  * vres, and returns immediately. The renegotiate operation is
+  * performed asynchronously, as soon as it is practical; meanwhile the
+  * system operation will continue normally. When the renegotiation is
+  * made, if the on-line admission test is enabled it determines
+  * whether the contract can be admitted or not based on the current
+  * contracts established in the system. If it cannot be admitted, the
+  * old contract remains in effect. If it can be admitted, it
+  * recalculates all necessary parameters for the contracts already
+  * present in the system.
+  *
+  * When the operation is completed, notification is made to the
+  * caller, if requested, via a signal. The status of the operation (in
+  * progress, admitted, rejected) can be checked with the
+  * frsh_vres_get_renegotiation_status() operation.  The argument
+  * sig_notify can be FRSH_NULL_SIGNAL (no notification), or any FRSH
+  * signal value and in this case signal_info is to be sent with the signal.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id to renegotiate
+  * @param[in] new_contract The new contract
+  * @param[in] signal_to_notify  Signal number to use to notify vres of
+  * the negotiation result. If FRSH_NULL_SIGNAL,  no signal will be raised.
+  * @param[in] signal_info: Associated info that will come with the signal.
+  * This parameter will be ignored if signal_to_notify == FRSH_NULL_SIGNAL.
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL, or sig_notify is neither
+  *      NULL nor a valid POSIX signal \n
+  *
+  **/
+ int frescan_fna_contract_renegotiate_async
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  const frsh_contract_t *new_contract,
+                  frsh_signal_t signal_to_notify,
+                  frsh_signal_info_t signal_info)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_vres_get_renegotiation_status()
+  *
+  * The operation reports on the status of the last renegotiation
+  * operation enqueued for the specified vres. It is callable even
+  * after notification of the completion of such operation, if
+  * requested.
+  *
+  * If the vres is not and has not been involved in any of the
+  * frsh_contract_renegotiate_async() or frsh_group_change_mode_async()
+  * operations, the status returned is FNA_NOT_REQUESTED
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id we want the status from
+  * @param[in] renegotiation_status The status of the last renegotiation on
+  * vres (FRSH_RS_IN_PROGRESS, FRSH_RS_REJECTED, FRSH_RS_ADMITTED,
+  * FRSH_RS_NOT_REQUESTED)
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_vres_get_renegotiation_status
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  frsh_renegotiation_status_t *renegotiation_status)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_vres_destroy()
+  *
+  * The operation eliminates the specified vres
+  * and recalculates all necessary parameters for the contracts
+  * remaining in the system. This is a potentially blocking operation;
+  * it returns when the system has made the changes effective.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id to destroy
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_vres_destroy
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres)
+ {
+         fna_vres_group_t  vres_to_cancel;
+         vres_to_cancel.size = 1;
+         vres_to_cancel.vres[0] = vres;
+         return frescan_fna_group_change_mode_sync
+                        (resource_id, NULL, NULL, NULL, &vres_to_cancel, NULL);
+ }
+ /**
+  * frescan_fna_vres_get_contract()
+  *
+  * This operation stores the contract parameters currently associated
+  * with the specified vres in the variable pointed to by
+  * contract. It returns an error if the vres_id is not recognised.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] contract  The contract parameters that we want
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_vres_get_contract
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  frsh_contract_t *contract)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_vres_get_usage()
+  *
+  * This function gets the execution time spent by all messages that have been
+  * sent through the specified vres.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] usage  Execution time spent by this vres
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_vres_get_usage
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  struct timespec *usage)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_vres_get_remaining_budget()
+  *
+  * This function stores in the variable pointed to by budget the
+  * remaining execution-time budget associated with the specified
+  * vres in the present period.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] remaining_budget  The remaining budget for this period
+  *
+  *  @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_vres_get_remaining_budget
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  struct timespec *remaining_budget)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_vres_get_budget_and_period()
+  *
+  * This function gets the budget and period associated with the specified vres
+  * for each period. If one of these pointers is NULL, the corresponding
+  * information is not stored.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] budget The budget associated to vres
+  * @param[out] period  The period associated to vres
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if both pointers are NULL \n
+  *
+  **/
+ int frescan_fna_vres_get_budget_and_period
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  struct timespec *budget,
+                  struct timespec *period)
+ {
+         int ret;
+         frescan_server_params_t server_params;
+         ret =  frescan_servers_get_data((frescan_network_t)resource_id,
+                                          &server_params,
+                                          (frescan_ss_t)vres);
+         if (ret != 0) return ret;
+         *budget = frsh_usec_to_rel_time((long)FRESCAN_FRAME_TX_TIME_US *
+                                         server_params.budget);
+         *period = server_params.period;
+         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG,
+               "budget(%d packets %ld us\n",
+               server_params.budget, frsh_rel_time_to_usec(*budget));
+         return 0;
+ }
+ /*@}*/
+ ///////////////////////////////////////////////////////////////////
+ //           SPARE CAPACITY FUNCIONS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * @defgroup fnaspare FNA Spare Capacity
+  * @ingroup fna
+  *
+  * The following functions are used to get spare capacity data
+  *
+  * @{
+  **/
+ /**
+  * frescan_fna_resource_get_capacity()
+  *
+  * This operation gets the spare capacity currently assigned to a importance
+  * level. If we divide this value by UINT32_MAX we will get the network
+  * utilization associated to the spare capacity of a importance level.
+  *
+  * The following is typically in stdint.h: \n
+  *  - typedef unsigned int uint32_t;  \n
+  *  - # define UINT32_MAX  (4294967295U)  \n
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] importance The importance we want the capacity of
+  * @param[out] capacity The spare capacity for that importance level
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_resource_get_capacity
+                 (const frsh_resource_id_t resource_id,
+                  const int importance,
+                  uint32_t *capacity)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_resource_get_total_weight()
+  *
+  * This function gets the sum of the weight parameters for all vres in a
+  * network of an importance level.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] importance The importance we want the total weight of
+  * @param[out] total_weight The total weight for that importance level
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_resource_get_total_weight
+                 (const frsh_resource_id_t resource_id,
+                  const int importance,
+                  int *total_weight)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_vres_decrease_capacity()
+  *
+  * This function allows to ask for less budget and period than what we
+  * received. The request must be compatible with the rest of contract
+  * parameters of the vres. If we want to recover the released capacity
+  * we will need to renegotiate.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[in] new_budget The new_budget
+  * @param[in] new_period The new Period
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_CONTRACT_REJECTED: if it is incompatible with the current
+  *      contract \n
+  *
+  **/
+ int frescan_fna_vres_decrease_capacity
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  const struct timespec new_budget,
+                  const struct timespec new_period)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ ///////////////////////////////////////////////////////////////////
+ //           SEND RECEIVE OPERATIONS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * frescan_fna_send_sync()
+  *
+  * Similar to previous function but now the sending thread gets blocked
+  * until the message is already sent to the network.
+  *
+  * @param[in] endpoint The send endpoint we are sending through. It must
+  *    be bound to a virtual resource (resource_id is in the endpoint).
+  * @param[in] msg The message we want to send
+  * @param[in] size The size in bytes of the message
+  *
+  * @returns
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_BOUND: if endpoint is not bound to a valid vres \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_TOO_LARGE: if the message is too large for the network protocol \n
+  *   FNA_ERR_BUFFER_FULL: if the message has been discarded because
+  *   the queue is full (and does not have the policy FNA_QP_OLDEST) \n
+  *
+  **/
+ int frescan_fna_send_sync
+                 (const fna_endpoint_data_t *endpoint,
+                  const void *msg,
+                  const size_t size)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_send_async()
+  *
+  * This operation sends a message stored in msg and of length size
+  * through the given send endpoint. The operation is non-blocking and
+  * returns immediately.
+  *
+  * @param[in] endpoint The send endpoint we are sending through. It must
+  *    be bound to a virtual resource (resource_id is in the endpoint).
+  * @param[in] msg The message we want to send
+  * @param[in] size The size in bytes of the message
+  *
+  * @returns
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_BOUND: if endpoint is not bound to a valid vres \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_TOO_LARGE: if the message is too large for the network protocol \n
+  *   FNA_ERR_BUFFER_FULL: if the message has been discarded because
+  *   the queue is full (and does not have the policy FNA_QP_OLDEST) \n
+  *
+  **/
+ int frescan_fna_send_async
+                 (const fna_endpoint_data_t *endpoint,
+                  const void *msg,
+                  const size_t size)
+ {
+         int ret;
+         frescan_send_params_t params;
+         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG,
+               "net:%u dest:%u chan:%u size:%u ss:%u\n",
+               endpoint->resource_id, endpoint->destination,
+               endpoint->stream_id, size, endpoint->vres);
+         params.net      = (frescan_network_t)endpoint->resource_id;
+         params.to       = (frescan_node_t)endpoint->destination;
+         params.channel  = (frescan_channel_t)endpoint->stream_id;
+         params.flags    = FRESCAN_SS | FRESCAN_ASYNC;
+         params.ss       = endpoint->vres;
+         ret = frescan_send(&params, (uint8_t *)msg, size);
+         if (ret != 0) {
+                 FRESCAN_ERROR ("could not send message\n");
+                 return -1;
+         }
+         return 0;
+ }
+ /**
+  * frescan_fna_receive_sync()
+  *
+  * This operation is used to receive messages from the network with a
+  * blocking behavior (if there are no messages this operation blocks
+  * the calling thread).
+  *
+  * When a message is available, it is copied to buffer (up to its size).
+  * The number of bytes copied is returned in received_bytes. The rest
+  * of the bytes of that message will be lost or not depending on the
+  * protocol (FNA_ERR_NO_SPACE will be returned if it is).
+  *
+  * The function fails with FNA_ERR_NO_SPACE if the buffersize is
+  * too small for the message received.  In this case the message is
+  * lost.
+  *
+  * Messages arriving at a receiver buffer that is full will be handled
+  * according to the queueing policy of the endpoint (overwrite oldest,
+  * discard it,etc).
+  *
+  * @param[in] endpoint The receive endpoint we are receiving from.
+  *    (resource_id is in the endpoint).
+  * @param[out] buffer Buffer for storing the received message
+  * @param[in] buffer_size The size in bytes of this buffer
+  * @param[out] received_bytes The actual number of received bytes
+  * @param[out] from Address of the sender node
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_NO_SPACE: if the message size is bigger than the
+  *      provided buffer. \n
+  *
+  **/
+ int frescan_fna_receive_sync
+                 (const fna_endpoint_data_t *endpoint,
+                  void *buffer,
+                  const size_t buffer_size,
+                  size_t *received_bytes,
+                  frsh_network_address_t *from)
+ {
+         int ret;
+         frescan_recv_params_t params;
+         frescan_node_t frescan_from;
+         frescan_prio_t prio;
+         params.net      = (frescan_network_t)endpoint->resource_id;
+         params.channel  = (frescan_channel_t)endpoint->stream_id;
+         params.flags    = FRESCAN_SYNC;
+         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG,
+               "net:%u chan:%u size:%u\n",
+               endpoint->resource_id, endpoint->stream_id, buffer_size);
+         ret = frescan_recv(&params, (uint8_t *)buffer, buffer_size,
+                            received_bytes, &frescan_from, &prio);
+         if (ret != 0) {
+                 FRESCAN_ERROR ("error while receiving message");
+                 return -1;
+         }
+         *from = (frsh_network_address_t)frescan_from;
+         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG,
+               "msg received, from:%u bytes:%u prio:%u\n",
+               *from, *received_bytes, prio);
+         return 0;
+ }
+ /**
+  * frescan_fna_receive_async()
+  *
+  * This operation is similar to the previous one but it works in a non
+  * blocking (asynchronous) fashion.  If no message is available it
+  * returns with error FNA_NO_MESSAGE.
+  *
+  * @param[in] endpoint The receive endpoint we are receiving from.
+  *    (resource_id is in the endpoint).
+  * @param[out] buffer Buffer for storing the received message
+  * @param[in] buffer_size The size in bytes of this buffer
+  * @param[out] received_bytes The actual number of received bytes
+  * @param[out] from Address of the sender node
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_NO_SPACE: if the message size is bigger than the
+  *      provided buffer. \n
+  *   FNA_NO_MESSAGE: if no messages are available in the queue. \n
+  *
+  **/
+ int frescan_fna_receive_async
+                 (const fna_endpoint_data_t *endpoint,
+                  void *buffer,
+                  const size_t buffer_size,
+                  size_t *received_bytes,
+                  frsh_network_address_t *from)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_send_endpoint_get_status()
+  *
+  * This function tells the number of messages still pending in the
+  * endpoint queue, whether the network is up or down with some
+  * optional information which is protocol_dependent.
+  *
+  * @param[in] endpoint The send endpoint (resource_id is in the endpoint).
+  * @param[out] number_of_pending_messages The number of pending messages
+  * @param[out] network_status How is the network (up, down..)
+  * @param[out] protocol_status Protocol dependent status info
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_send_endpoint_get_status
+                 (const fna_endpoint_data_t *endpoint,
+                  int *number_of_pending_messages,
+                  frsh_endpoint_network_status_t *network_status,
+                  frsh_protocol_status_t *protocol_status)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_receive_endpoint_created()
+  *
+  * This operation is a called from frsh_receive_endpoint_create with a
+  * receive_endpoint structure already filled.
+  *
+  * Receiving endpoints are not bound to any network vres, this is
+  * because don't originate any traffic.
+  *
+  * @param[in] endpoint the endpoint object.
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  **/
+ int frescan_fna_receive_endpoint_created
+                 (fna_endpoint_data_t *endpoint)
+ {
+         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG, "receive endpoint created\n");
+         return 0;
+ }
+ /**
+  * frescan_fna_receive_endpoint_get_pending_messages
+  *
+  * This function tells the number of messages still pending in the
+  * endpoint queue, whether the network is up or down and some optional
+  * information which is protocol dependent.
+  *
+  * @param[in] endpoint The receive endpoint (resource_id is in the endpoint).
+  * @param[out] number_of_pending_messages The number of pending messages
+  * @param[out] network_status How is the network (up, down..)
+  * @param[out] protocol_status Protocol dependent status info
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_receive_endpoint_get_status
+                 (const fna_endpoint_data_t *endpoint,
+                  int *number_of_pending_messages,
+                  frsh_endpoint_network_status_t *network_status,
+                  frsh_protocol_status_t *protocol_status)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ //////////////////////////////////////////////////////////////////////
+ //           NETWORK CONFIGURATION FUNCTIONS
+ //////////////////////////////////////////////////////////////////////
+ /**
+  * frescan_fna_network_get_max_message_size()
+  *
+  * This operation gives the maximum number of bytes that can be sent
+  * at a time through the send function when using the network designated by
+  * 'resource_id' and sending it to 'destination'.
+  *
+  * If the application needs to send bigger messages it will have to
+  * split them.
+  *
+  * Some protocols, like IP, are capable of sending large messages
+  * (and use fragmentation internally) but other protocols don't.
+  *
+  * @param[in] resource_id The network we want the tx time from.
+  * @param[in] destination The destination address
+  * @param[out] max_size The maximum number of bytes for each message
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or destination is
+  *   invalid \n
+  *
+  **/
+ int frescan_fna_network_get_max_message_size
+                 (const frsh_resource_id_t resource_id,
+                  const frsh_network_address_t destination,
+                  size_t *max_size)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frescan_fna_network_bytes_to_budget()
+  *
+  * This operation converts a number of bytes into a temporal budget for
+  * a specific network. Network overheads are not included here but are
+  * considered internally when negotiating a specific contract.
+  *
+  * @param[in] resource_id The network
+  * @param[in] nbytes Number of bytes
+  * @param[out] budget The network budget for nbytes
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or nbytes is less
+  *   than zero \n
+  *
+  **/
+ int frescan_fna_network_bytes_to_budget
+                 (const frsh_resource_id_t resource_id,
+                  const size_t nbytes,
+                  frsh_rel_time_t *budget)
+ {
+         int number_of_packets;
+         if (budget == NULL || nbytes < 0) {
+                 return -1;
+         }
+         // number of FRESCAN frames (8 bytes)
+         number_of_packets = (int) ceil((double)nbytes / 8.0);
+         *budget = frsh_usec_to_rel_time((long)FRESCAN_FRAME_TX_TIME_US *
+                                               number_of_packets);
+         DEBUG(FRESCAN_BWRES_FNA_ENABLE_DEBUG,
+               "bytes: %d -> budget: %ld us\n",
+                nbytes, frsh_rel_time_to_usec(*budget));
+         return 0;
+ }
+ /**
+  * frescan_fna_network_budget_to_bytes()
+  *
+  * This operation converts a temporal budget into a number of bytes for
+  * a specific network. Network overheads are not included.
+  *
+  * @param[in] resource_id The network
+  * @param[in] budget The network budget for nbytes
+  * @param[out] nbytes Number of bytes
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or budget refers to
+  *   an invalid time value \n
+  *
+  **/
+ int frescan_fna_network_budget_to_bytes
+                 (const frsh_resource_id_t resource_id,
+                  const frsh_rel_time_t *budget,
+                  size_t *nbytes)
+ {
+         int number_of_packets;
+         if (budget == NULL || nbytes == NULL) {
+                 return -1;
+         }
+         number_of_packets = frsh_rel_time_to_usec(*budget) /
+                             FRESCAN_FRAME_TX_TIME_US;
+         *nbytes = number_of_packets * 8;
+         return 0;
+ }
+ /**
+  * frescan_fna_network_get_min_eff_budget()
+  *
+  * This operation gets the minimum effective budget for a network. Each message
+  * consumes a contracted budget in "chunks" (i.e: packets) that we call
+  * minimum effective budget.
+  *
+  * A negotiated contract, for N bytes in a period T, means that there is a
+  * virtual resource that reserves for the user:
+  *
+  *   Ceiling ((N bytes) / budget_to_bytes (min_effective_budget)) "CHUNKS"
+  *
+  * Note that if the user decides not to send these N bytes at once but, say,
+  * one byte at a time, it will consume one "CHUNK" at a time and the reserved
+  * budget will become exhausted before sending all the bytes.
+  *
+  * @param[in] resource_id The network
+  * @param[out] budget The network budget
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frescan_fna_network_get_min_eff_budget
+                 (const frsh_resource_id_t resource_id,
+                  struct timespec *budget)
+ {
+         if (budget == NULL) {
+                 return -1;
+         }
+         *budget = frsh_usec_to_rel_time((long)FRESCAN_FRAME_TX_TIME_US);
+         return 0;
+ }
+ // GLOBAL variable to install the network protocol in FRESCOR
+ fna_operations_t frescan_fna_operations = {
+ #ifdef CONFIG_FNA_FRESCAN_CONNECTED
+         .fna_init = frescan_fna_init,
+         .fna_group_change_mode_sync = frescan_fna_group_change_mode_sync,
+         .fna_contract_negotiate = frescan_fna_contract_negotiate,
+         .fna_contract_renegotiate_sync = frescan_fna_contract_renegotiate_sync,
+         .fna_contract_renegotiate_async = frescan_fna_contract_renegotiate_async,
+         .fna_vres_get_renegotiation_status = frescan_fna_vres_get_renegotiation_status,
+         .fna_vres_destroy = frescan_fna_vres_destroy,
+         .fna_vres_get_contract = frescan_fna_vres_get_contract,
+         .fna_vres_get_usage = frescan_fna_vres_get_usage,
+         .fna_vres_get_remaining_budget = frescan_fna_vres_get_remaining_budget,
+         .fna_vres_get_budget_and_period = frescan_fna_vres_get_budget_and_period,
+         .fna_resource_get_capacity = frescan_fna_resource_get_capacity,
+         .fna_resource_get_total_weight = frescan_fna_resource_get_total_weight,
+         .fna_vres_decrease_capacity = frescan_fna_vres_decrease_capacity,
+         .fna_send_sync = frescan_fna_send_sync,
+         .fna_send_async = frescan_fna_send_async,
+         .fna_receive_sync = frescan_fna_receive_sync,
+         .fna_receive_async = frescan_fna_receive_async,
+         .fna_send_endpoint_get_status = frescan_fna_send_endpoint_get_status,
+         .fna_receive_endpoint_created = frescan_fna_receive_endpoint_created,
+         .fna_receive_endpoint_get_status = frescan_fna_receive_endpoint_get_status,
+ #endif
+         .fna_network_get_max_message_size = frescan_fna_network_get_max_message_size,
+         .fna_network_bytes_to_budget = frescan_fna_network_bytes_to_budget,
+         .fna_network_budget_to_bytes = frescan_fna_network_budget_to_bytes,
+         .fna_network_get_min_eff_budget = frescan_fna_network_get_min_eff_budget
+ };
index 0000000000000000000000000000000000000000,e1c13c6c4b5d1ac4f5b3b56bf973b7ddfa45c01f..e1c13c6c4b5d1ac4f5b3b56bf973b7ddfa45c01f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,78 +1,78 @@@
+ /*!
+  * @file frescan_bwres_fna.h
+  *
+  * @brief FRESCAN bandwidth reservation layer: FNA hooks
+  *
+  * This module contains hooks to integrate the FRESCAN protocol in FRSH
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_FNA_H_
+ #define _FRESCAN_FNA_H_
+ #include "fna.h" // for fna_operations_t
+ extern fna_operations_t frescan_fna_operations;
+ #endif // _FRESCAN_FNA_H_
index 0000000000000000000000000000000000000000,67e10cdafbfd4822fd793e40a9dbbc7711a0ede7..67e10cdafbfd4822fd793e40a9dbbc7711a0ede7
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,261 +1,261 @@@
+ /*!
+  * @file frescan_bwres_frsh_fna.h
+  *
+  * @brief FRESCAN bandwidth reservation layer: FRSH FNA public functions
+  *
+  * This module contains FNA functions that need to be public mainly
+  * for mapping between network types and FNA or FRSH types.
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include "frsh_fna.h"
+ #include "frescan.h"
+ #include "frescan_debug.h"
+ //////////////////////////////////////////////////////////////////////
+ //           MAPPING FUNCTIONS
+ //////////////////////////////////////////////////////////////////////
+ /**
+  * frsh_XXXX_map_network_address()
+  *
+  * To map a XXXX protocol network address into a FRSH address.
+  * The protocol must keep this mapping consistent. Instead of using a function
+  * a hardwired mapping could be used.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] in_address The network address we want to map to a frsh address
+  * @param[out] out_address The FRSH abstract network address
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_frescan_map_network_address
+       (const frsh_resource_id_t resource_id,
+        const frescan_node_t in_address,
+        frsh_network_address_t *out_address)
+ {
+     if (out_address == NULL) return -1;
+     *out_address = in_address;
+     return 0;
+ }
+ /**
+  * frsh_XXXX_map_stream_id()
+  *
+  * To map a XXXX protocol network stream, port, channel... into a FRSH stream.
+  * The protocol must keep this mapping consistent. Instead of using a function
+  * a hardwired mapping could be used.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] in_stream The network stream we want to map to a FRSH stream
+  * @param[out] out_stream The FRSH abstract network stream
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_frescan_map_stream_id
+       (const frsh_resource_id_t resource_id,
+        const frescan_channel_t in_stream,
+        frsh_stream_id_t *out_stream)
+ {
+     if (out_stream == NULL) return -1;
+     *out_stream = in_stream;
+     return 0;
+ }
+ ///////////////////////////////////////////////////////////////////
+ //           NEGOTIATION SERVICE PARAMETERS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * frsh_XXXX_negotiation_messages__vres_renegotiate()
+  *
+  * This function allows the application to change the minimum period
+  * of the negotiation messages sent through the network. It is similar
+  * to the service thread but for the network messages. We do not provide
+  * budget here because the size of the negotiation messages is fixed.
+  *
+  * This change is similar to a renegotiation so a schedulability test
+  * must be done to see if the change can be accepted or not.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] period The new period for negotiation messages
+  * @param[out] accepted If the change has been accepted or not
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_frescan_negotiation_messages_vres_renegotiate
+       (const frsh_resource_id_t resource_id,
+        const struct timespec *period)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frsh_XXXX_negotiation_messages_vres_get_period()
+  *
+  * This function gets the minimum period of the negotiation messages
+  * sent through the network.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[out] period The period for negotiation messages
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_frescan_negotiation_messages_vres_get_period
+       (const frsh_resource_id_t resource_id,
+        struct timespec *period)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frsh_XXXX_service_thread_vres_renegotiate()
+  *
+  * This function allows the application to change the period and
+  * budget of the service thread that makes the negotiations and
+  * schedulability tests in a network.
+  *
+  * The service thread starts with a default budget and period that
+  * should be configurable
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] budget The new budget for the service thread
+  * @param[in] period The new period for the service thread
+  * @param[out] accepted If the negotiation has been accepted or not
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_frescan_service_thread_vres_renegotiate
+    (const frsh_resource_id_t resource_id,
+     const struct timespec *budget,
+     const struct timespec *period,
+     bool *accepted)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
+ /**
+  * frsh_XXXX_service_thread_vres_get_budget_and_period()
+  *
+  * This function gets the budget and period of a service thread.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[out] budget The budget of the service thread
+  * @param[out] period The period of the service thread
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_frescan_service_thread_vres_get_budget_and_period
+       (const frsh_resource_id_t resource_id,
+        struct timespec *budget,
+        struct timespec *period)
+ {
+         FRESCAN_ERROR("not implemented\n");
+         return -1;
+ }
index 0000000000000000000000000000000000000000,cc0bffda7b78faf4535258f20e217ca2d99e4d8b..cc0bffda7b78faf4535258f20e217ca2d99e4d8b
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,790 +1,790 @@@
+ /*!
+  * @file frescan_bwres_messages.c
+  *
+  * @brief FRESCAN bandwidth reservation layer: negotiation messages formating
+  *
+  * This module contains the data types that define the FRESCAN negotiation
+  * message format and operations to convert them into or from negotiation
+  * requests
+  *
+  * @version 0.01
+  *
+  * @date 2-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include <string.h>
+ #include "frescan_bwres_messages.h"
+ #include "frescan_bwres_requests.h"
+ #include "frescan.h"
+ #include "frescan_servers.h"
+ #include "frescan_data.h"
+ #include "frescan_config.h"
+ #include "frescan_debug.h"
+ #include "frsh_distributed.h"
+ #define FRESCAN_BWRES_MX_MSG_SIZE 5000  // TODO: adjust to the accurate value
+ /**
+  * frescan_messages_init()
+  */
+ static frescan_send_params_t send_params[FRESCAN_MX_NETWORKS];
+ static frescan_recv_params_t recv_params[FRESCAN_MX_NETWORKS];
+ int frescan_messages_init(frescan_network_t net)
+ {
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG, "initialization\n");
+         send_params[net].net     = net;
+         send_params[net].channel = FRESCAN_BWRES_NEG_MSG_CHAN;
+         send_params[net].flags   = FRESCAN_SS | FRESCAN_ASYNC;
+         send_params[net].ss      = frescan_data[net].neg_messages_ss_id;
+         send_params[net].to      = FRESCAN_BWRES_MASTER_NODE;
+         recv_params[net].net     = net;
+         recv_params[net].channel = FRESCAN_BWRES_NEG_MSG_CHAN;
+         recv_params[net].flags   = FRESCAN_SYNC;
+         return 0;
+ }
+ /**
+  *  FRESCAN_BWRES_REQ_GN
+  *  ====================
+  *  This message is sent from a SLAVE to the MASTER when the slave wants
+  *  to make a negotiation (including creating new vres, renegotiations and
+  *  cancellations).
+  */
+ static int frescan_request_to_gn_message
+                                 (const frescan_bwres_request_data_t *data,
+                                  uint8_t *msg,
+                                  size_t  *size)
+ {
+         int ret, i;
+         uint8_t *msg_begin, *msg_tmp;
+         size_t bytes_written;
+         msg_begin = msg;
+         // type: FRESCAN_GN_MESSAGE
+         *((uint8_t *)msg) = (uint8_t)FRESCAN_BWRES_REQ_GN;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         // req
+         *((frescan_bwres_request_id_t *)msg) = data->req;
+         bytes_written = sizeof(frescan_bwres_request_id_t);
+         msg = msg + bytes_written;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "GN message req:%u\n", data->req);
+         // NEG-GROUP
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "NEG-GROUP num contracts:%d\n", data->contracts_to_neg->size);
+         *((uint8_t *)msg) = (uint8_t)data->contracts_to_neg->size;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         for (i=0; i<data->contracts_to_neg->size; i++) {
+                 // reserve 2 bytes for the size of the marshalled contract
+                 msg_tmp = msg;
+                 msg     = msg + sizeof(uint16_t);
+                 // marshal the contract
+                 ret = frsh_contract_marshal
+                                 (&data->contracts_to_neg->contracts[i],
+                                  msg,
+                                  FRESCAN_BWRES_MX_MSG_SIZE - (msg - msg_begin),
+                                  &bytes_written);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("frsh_contract_marshal return -1\n");
+                         return -1;
+                 }
+                 // write the size and update the message pointer msg
+                 *((uint16_t *)msg_tmp) = (uint16_t)bytes_written;
+                 msg = msg + bytes_written;
+                 DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                       "contract[%d].size:%u\n", i, bytes_written);
+         }
+         // RENEG-GROUP
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "RENEG-GROUP num contracts:%d\n",data->contracts_to_reneg->size);
+         *((uint8_t *)msg) = (uint8_t)data->contracts_to_reneg->size;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         for (i=0; i<data->contracts_to_reneg->size; i++) {
+                 // write the ss
+                 *((uint16_t *)msg) = (uint16_t)data->ss_to_reneg->ss[i];
+                 bytes_written = sizeof(uint16_t);
+                 msg = msg + bytes_written;
+                 // reserve 2 bytes for the size of the marshalled contract
+                 msg_tmp = msg;
+                 msg     = msg + sizeof(uint16_t);
+                 // marshal the contract
+                 ret = frsh_contract_marshal
+                                 (&data->contracts_to_reneg->contracts[i],
+                                  msg,
+                                  FRESCAN_BWRES_MX_MSG_SIZE - (msg - msg_begin),
+                                  &bytes_written);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("frsh_contract_marshal return -1\n");
+                         return -1;
+                 }
+                 // write the size and update the message pointer msg
+                 *((uint16_t *)msg_tmp) = (uint16_t)bytes_written;
+                 msg = msg + bytes_written;
+                 DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                       "contract[%d].size:%u ss[%d]:%u\n",
+                       i, bytes_written, i, data->ss_to_reneg->ss[i]);
+         }
+         // CANCEL-GROUP
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG, "CANCEL-GROUP num ss:%d\n",
+               data->ss_to_cancel->size);
+         *((uint8_t *)msg) = (uint8_t)data->ss_to_cancel->size;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         for (i=0; i<data->ss_to_cancel->size; i++) {
+                 // write the ss
+                 *((uint16_t *)msg) = (uint16_t)data->ss_to_cancel->ss[i];
+                 bytes_written = sizeof(uint16_t);
+                 msg = msg + bytes_written;
+                 DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                       "ss[%d]:%u\n", i, data->ss_to_cancel->ss[i]);
+         }
+         *size = msg - msg_begin;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG, "size:%u\n", *size);
+         return 0;
+ }
+ static int frescan_gn_message_to_request(const uint8_t *msg_to_parse,
+                                          frescan_bwres_request_data_t *data,
+                                          size_t size)
+ {
+         int ret, i;
+         uint8_t *msg;
+         size_t bytes_read, contract_size;
+         msg = (uint8_t *)msg_to_parse;
+         data->contracts_to_neg   = &data->contracts_to_neg_data;
+         data->contracts_to_reneg = &data->contracts_to_reneg_data;
+         data->ss_to_reneg        = &data->ss_to_reneg_data;
+         data->ss_to_cancel       = &data->ss_to_cancel_data;
+         data->ss_new             = &data->ss_new_data;
+         // req
+         data->req = *((frescan_bwres_request_id_t *)msg);
+         bytes_read = sizeof(frescan_bwres_request_id_t);
+         msg = msg + bytes_read;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "GN message req:%u\n", data->req);
+         // NEG-GROUP
+         data->contracts_to_neg->size = *((uint8_t *)msg);
+         bytes_read = sizeof(uint8_t);
+         msg = msg + bytes_read;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "NEG-GROUP num contracts:%u\n", data->contracts_to_neg->size);
+         for (i=0; i<data->contracts_to_neg->size; i++) {
+                 contract_size = *((uint16_t *)msg);
+                 bytes_read = sizeof(uint16_t);
+                 msg = msg + bytes_read;
+                 // unmarshal the contract
+                 ret = frsh_contract_unmarshal
+                                 (&data->contracts_to_neg->contracts[i],
+                                  msg,
+                                  contract_size);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("frsh_contract_unmarshal return -1\n");
+                         return -1;
+                 }
+                 bytes_read = contract_size;
+                 msg = msg + bytes_read;
+                 DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                       "contract[%d].size:%u\n", i, contract_size);
+         }
+          // RENEG-GROUP
+         data->contracts_to_reneg->size = *((uint8_t *)msg);
+         bytes_read = sizeof(uint8_t);
+         msg = msg + bytes_read;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "RENEG-GROUP num contracts:%u\n",data->contracts_to_reneg->size);
+         for (i=0; i<data->contracts_to_reneg->size; i++) {
+                 data->ss_to_reneg->ss[i] = *((uint16_t *)msg);
+                 bytes_read = sizeof(uint16_t);
+                 msg = msg + bytes_read;
+                 contract_size = *((uint16_t *)msg);
+                 bytes_read = sizeof(uint16_t);
+                 msg = msg + bytes_read;
+                 // unmarshal the contract
+                 ret = frsh_contract_unmarshal
+                                 (&data->contracts_to_reneg->contracts[i],
+                                  msg,
+                                  contract_size);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("frsh_contract_unmarshal return -1\n");
+                         return -1;
+                 }
+                 bytes_read = contract_size;
+                 msg = msg + bytes_read;
+                 DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                       "contract[%d].size:%u ss[%d]:%u\n",
+                       i, contract_size, i, data->ss_to_reneg->ss[i]);
+         }
+         // CANCEL-GROUP
+         data->ss_to_cancel->size = *((uint8_t *)msg);
+         bytes_read = sizeof(uint8_t);
+         msg = msg + bytes_read;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "CANCEL-GROUP num ss:%u\n", data->ss_to_cancel->size);
+         for (i=0; i<data->ss_to_cancel->size; i++) {
+                 // write the ss
+                 data->ss_to_cancel->ss[i] = *((uint16_t *)msg);
+                 bytes_read = sizeof(uint16_t);
+                 msg = msg + bytes_read;
+                 DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                       "ss[%d]:%u\n", i, data->ss_to_cancel->ss[i]);
+         }
+         return 0;
+ }
+ /**
+  *  FRESCAN_BWRES_REQ_MC
+  *  ====================
+  *  This message is sent from the MASTER to a slave when there is a change
+  *  in the budget value assigned by the spare capacity algorithm.
+  */
+ static int frescan_request_to_mc_message
+                                 (const frescan_bwres_request_data_t *data,
+                                  uint8_t *msg,
+                                  size_t  *size)
+ {
+         frescan_bwres_vres_t *vres;
+         uint8_t *msg_begin;
+         size_t bytes_written;
+         msg_begin = msg;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "MC send mode_change_type:0x%X\n", data->mode_change_type);
+         // type: FRESCAN_GN_MESSAGE
+         *((uint8_t *)msg) = (uint8_t)FRESCAN_BWRES_REQ_MC;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         // write the SS-mode_change_type-values fields
+         list_for_each_entry(vres,
+                             &frescan_data[data->net].mode_change_list
+                                                         [data->request_node],
+                             mode_change_list)
+         {
+                 if ((vres->mode_change_type & data->mode_change_type) !=
+                      data->mode_change_type) continue;
+                 *((frescan_ss_t *)msg) = vres->ss;
+                 bytes_written = sizeof(frescan_ss_t);
+                 msg = msg + bytes_written;
+                 *((uint8_t *)msg) = (uint8_t)data->mode_change_type;
+                 bytes_written = sizeof(uint8_t);
+                 msg = msg + bytes_written;
+                 if (data->mode_change_type & (FRESCAN_BWRES_MC_BUDGET_INC |
+                                               FRESCAN_BWRES_MC_BUDGET_DEC)) {
+                         *((frsh_sa_time_t *)msg) = vres->old_c;
+                         bytes_written = sizeof(frsh_sa_time_t);
+                         msg = msg + bytes_written;
+                 }
+                 if (data->mode_change_type & (FRESCAN_BWRES_MC_PERIOD_INC |
+                                               FRESCAN_BWRES_MC_PERIOD_DEC)) {
+                         *((frsh_sa_time_t *)msg) = vres->old_t;
+                         bytes_written = sizeof(frsh_sa_time_t);
+                         msg = msg + bytes_written;
+                 }
+                 if (data->mode_change_type & (FRESCAN_BWRES_MC_PRIO_INC |
+                                               FRESCAN_BWRES_MC_PRIO_DEC)) {
+                         *((frsh_sa_prio_t *)msg) = vres->old_p;
+                         bytes_written = sizeof(frsh_sa_prio_t);
+                         msg = msg + bytes_written;
+                 }
+                 DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                       "ss:%d c:%d t:%d p:%d\n",
+                       vres->ss, vres->old_c, vres->old_t, vres->old_p);
+         }
+         *size = msg - msg_begin;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG, "size:%u\n", *size);
+         return 0;
+ }
+ static int frescan_mc_message_to_request(const uint8_t *msg_to_parse,
+                                          frescan_bwres_request_data_t *data,
+                                          size_t size)
+ {
+         uint8_t *msg;
+         size_t bytes_read;
+         frescan_ss_t ss;
+         frescan_bwres_vres_t *vres;
+         frescan_node_t me;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG, "MC message received\n");
+         msg = (uint8_t *)msg_to_parse;
+         me = frescan_data[data->net].local_node;
+         data->mode_change_type = 0;
+         INIT_LIST_HEAD(&frescan_data[data->net].mode_change_list[me]);
+         while(msg < msg_to_parse + size) {
+                 ss = *((frescan_ss_t *)msg);
+                 bytes_read = sizeof(frescan_ss_t);
+                 msg = msg + bytes_read;
+                 vres = &frescan_data[data->net].scenario.vres_pool[me][ss];
+                 vres->mode_change_type = *((uint8_t *)msg);
+                 bytes_read = sizeof(uint8_t);
+                 msg = msg + bytes_read;
+                 if (vres->mode_change_type & (FRESCAN_BWRES_MC_BUDGET_INC |
+                                               FRESCAN_BWRES_MC_BUDGET_DEC)) {
+                         vres->old_c = *((frsh_sa_time_t *)msg);
+                         bytes_read = sizeof(frsh_sa_time_t);
+                         msg = msg + bytes_read;
+                 }
+                 if (vres->mode_change_type & (FRESCAN_BWRES_MC_PERIOD_INC |
+                                               FRESCAN_BWRES_MC_PERIOD_DEC)) {
+                         vres->old_t = *((frsh_sa_time_t *)msg);
+                         bytes_read = sizeof(frsh_sa_time_t);
+                         msg = msg + bytes_read;
+                 }
+                 if (vres->mode_change_type & (FRESCAN_BWRES_MC_PRIO_INC |
+                                               FRESCAN_BWRES_MC_PRIO_DEC)) {
+                         vres->old_p = *((frsh_sa_prio_t *)msg);
+                         bytes_read = sizeof(frsh_sa_prio_t);
+                         msg = msg + bytes_read;
+                 }
+                 if (vres->mode_change_type != 0) {
+                         list_add_tail(&(vres->mode_change_list),
+                                       &(frescan_data[data->net].
+                                                       mode_change_list[me]));
+                 }
+                 data->mode_change_type |= vres->mode_change_type;
+                 DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                       "mc:0x%X ss:%d vres->ss:%d c:%d t:%d p:%d\n",
+                       vres->mode_change_type, ss, vres->ss,
+                       vres->old_c, vres->old_t, vres->old_p);
+         }
+         return 0;
+ }
+ /**
+  *  FRESCAN_BWRES_REP_GN
+  *  ====================
+  *  This message is sent from the MASTER to a slave as a reply to a
+  *  FRESCAN_BWRES_REQ_GN message
+  */
+ static int frescan_request_to_rep_gn_message
+                         (const frescan_bwres_request_data_t *data,
+                          uint8_t *msg,
+                          size_t  *size)
+ {
+         int i;
+         uint8_t *msg_begin;
+         size_t bytes_written;
+         frescan_bwres_vres_t *vres;
+         msg_begin = msg;
+         // type
+         *((uint8_t *)msg) = (uint8_t)FRESCAN_BWRES_REP_GN;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         // req
+         *((frescan_bwres_request_id_t *)msg) = data->req;
+         bytes_written = sizeof(frescan_bwres_request_id_t);
+         msg = msg + bytes_written;
+         // return value
+         *((uint8_t *)msg) = data->return_value;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "req:%d return:%s\n", data->req,
+                (data->return_value == FRESCAN_BWRES_REQ_ACCEPTED)?"OK":"FAIL");
+         if (data->return_value == FRESCAN_BWRES_REQ_ACCEPTED) {
+                 // new ss values
+                 for(i=0; i<data->contracts_to_neg->size; i++) {
+                         // SS
+                         *((uint16_t *)msg) = data->ss_new->ss[i];
+                         bytes_written = sizeof(uint16_t);
+                         msg = msg + bytes_written;
+                         // B - T - P
+                         vres = &frescan_data[data->net].scenario.
+                                                 vres_pool[data->request_node]
+                                                          [data->ss_new->ss[i]];
+                         *((frsh_sa_time_t *)msg) = vres->old_c;
+                         bytes_written = sizeof(frsh_sa_time_t);
+                         msg = msg + bytes_written;
+                         *((frsh_sa_time_t *)msg) = vres->old_t;
+                         bytes_written = sizeof(frsh_sa_time_t);
+                         msg = msg + bytes_written;
+                         *((frsh_sa_prio_t *)msg) = vres->old_p;
+                         bytes_written = sizeof(frsh_sa_prio_t);
+                         msg = msg + bytes_written;
+                         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                               "ss[%d]:%u b:%d t:%d p:%d\n",
+                               i, data->ss_new->ss[i],
+                               vres->old_c, vres->old_t, vres->old_p);
+                 }
+         }
+         *size = msg - msg_begin;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG, "size:%u\n", *size);
+         return 0;
+ }
+ static int frescan_rep_gn_message_to_request
+                                         (const uint8_t *msg_to_parse,
+                                          frescan_bwres_request_data_t *data,
+                                          size_t size)
+ {
+         int ret;
+         uint8_t *msg;
+         size_t bytes_read;
+         frescan_ss_t ss;
+         frescan_server_params_t server_params;
+         frescan_bwres_vres_t *vres;
+         frescan_node_t me;
+         me = frescan_data[data->net].local_node;
+         msg = (uint8_t *)msg_to_parse;
+         // req
+         data->req = *((frescan_bwres_request_id_t *)msg);
+         bytes_read = sizeof(frescan_bwres_request_id_t);
+         msg = msg + bytes_read;
+         // return_value
+         data->return_value = *((uint8_t *)msg);
+         bytes_read = sizeof(uint8_t);
+         msg = msg + bytes_read;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "req:%d return:%s\n", data->req,
+               (data->return_value == FRESCAN_BWRES_REQ_ACCEPTED)?"OK":"FAIL");
+         if (data->return_value != FRESCAN_BWRES_REQ_ACCEPTED) return 0;
+         // create the new sporadic servers
+         data->ss_new->size = 0;
+         while(msg < msg_to_parse + size) {
+                 // SS
+                 data->ss_new->ss[data->ss_new->size] = *((uint16_t *)msg);
+                 bytes_read = sizeof(uint16_t);
+                 msg = msg + bytes_read;
+                 // Set values in the scenario (for mode changes)
+                 vres = &frescan_data[data->net].scenario.vres_pool[me]
+                                 [data->ss_new->ss[data->ss_new->size]];
+                 vres->ss       = data->ss_new->ss[data->ss_new->size];
+                 vres->node     = me;
+                 // Budget
+                 vres->old_c    = *((frsh_sa_time_t *)msg);
+                 bytes_read = sizeof(frsh_sa_time_t);
+                 msg = msg + bytes_read;
+                 // Period
+                 vres->old_t    = *((frsh_sa_time_t *)msg);
+                 bytes_read = sizeof(frsh_sa_time_t);
+                 msg = msg + bytes_read;
+                 // Prio
+                 vres->old_p    = *((frsh_sa_prio_t *)msg);
+                 bytes_read = sizeof(frsh_sa_prio_t);
+                 msg = msg + bytes_read;
+                 // Create server
+                 server_params.budget = frsh_rel_time_to_usec
+                                 (frsh_sa_time_to_rel_time(vres->old_c)) /
+                                 FRESCAN_FRAME_TX_TIME_US;
+                 server_params.period = frsh_sa_time_to_rel_time(vres->old_t);
+                 server_params.prio = vres->old_p;
+                 DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                       "ss_master[%d]:%u ss[%d]:%u b:%d t:%d p:%d\n",
+                       data->ss_new->size, data->ss_new->ss[data->ss_new->size],
+                       data->ss_new->size, ss,
+                       vres->old_c, vres->old_t, vres->old_p);
+                 DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+                       "server_params[%d] b:%d t:(%d,%d) p:%d\n",
+                       data->ss_new->size, server_params.budget,
+                       server_params.period.tv_sec,
+                       server_params.period.tv_nsec,
+                       server_params.prio);
+                 ret = frescan_servers_create(data->net, &server_params, &ss);
+                 if (ret != 0) return ret;
+                 if (ss != data->ss_new->ss[data->ss_new->size]) {
+                         FRESCAN_ERROR("ss from master(%u) != ss created(%u)\n",
+                                       data->ss_new->ss[data->ss_new->size], ss);
+                         return -1;
+                 }
+                 data->ss_new->size++;
+         }
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "data->ss_new->size:%u\n", data->ss_new->size);
+         return 0;
+ }
+ /**
+  * frescan_messages_send_request()
+  *
+  * this function converts a request with the necessary data into a message
+  * and sends it.
+  *
+  * @req_data: the request to be sent (NOTE: the network is in req_data)
+  *
+  */
+ int frescan_messages_send_request(const frescan_bwres_request_data_t *req_data)
+ {
+         int ret;
+         uint8_t msg[FRESCAN_BWRES_MX_MSG_SIZE];
+         size_t size;
+         switch(req_data->type) {
+                 case FRESCAN_BWRES_REQ_GN:
+                         ret = frescan_request_to_gn_message
+                                                         (req_data, msg, &size);
+                         if (ret != 0) return ret;
+                         send_params[req_data->net].to =
+                                                 FRESCAN_BWRES_MASTER_NODE;
+                         break;
+                 case FRESCAN_BWRES_REQ_MC:
+                         ret = frescan_request_to_mc_message
+                                                         (req_data, msg, &size);
+                         if (ret != 0) return ret;
+                         send_params[req_data->net].to = req_data->request_node;
+                         break;
+                 case FRESCAN_BWRES_REP_GN:
+                         ret = frescan_request_to_rep_gn_message
+                                                         (req_data, msg, &size);
+                         if (ret != 0) return ret;
+                         send_params[req_data->net].to = req_data->request_node;
+                         break;
+                 case FRESCAN_BWRES_REQ_RES:
+                 case FRESCAN_BWRES_REQ_RES_GET:
+                 case FRESCAN_BWRES_REP_RES_GET:
+                 case FRESCAN_BWRES_REQ_RES_SET:
+                 case FRESCAN_BWRES_REQ_RES_COMMIT:
+                 case FRESCAN_BWRES_REQ_RES_CANCEL:
+                 default:
+                         FRESCAN_ERROR("request type not supported\n");
+                         return -1;
+         }
+         ret = frescan_send(&send_params[req_data->net], msg, size);
+         if (ret != 0) return ret;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "sent request, type:%X size:%u\n",
+               req_data->type, size);
+         return 0;
+ }
+ /**
+  * frescan_messages_recv_request()
+  *
+  * this function BLOCKS the calling thread until receives a message
+  * and transforms it into a request.
+  *
+  * @req_data: the request data to fill from the message bytes (out)
+  *
+  */
+ int frescan_messages_recv_request(frescan_network_t    net,
+                                   frescan_bwres_request_id_t *req)
+ {
+         int ret;
+         uint8_t msg[FRESCAN_BWRES_MX_MSG_SIZE];
+         uint8_t *msg_to_parse;
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_prio_t prio;
+         frescan_bwres_request_data_t *req_data;
+         ret = frescan_bwres_requests_alloc(req);
+         if (ret != 0) return ret;
+         ret = frescan_bwres_requests_get_data(*req, &req_data);
+         if (ret != 0) return ret;
+         ret = frescan_recv(&recv_params[net],
+                             msg,
+                             sizeof(msg),
+                             &recv_bytes,
+                             &from,
+                             &prio);
+         if (ret != 0) return ret;
+         DEBUG(FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG,
+               "msg received! from:%u size:%u prio:%u chan:%u flags:%X\n",
+               from, recv_bytes, prio, recv_params[net].channel,
+               recv_params[net].flags);
+         req_data->request_node = from;
+         req_data->net          = net;
+         req_data->type         = *((uint8_t *)msg);
+         msg_to_parse = msg + sizeof(uint8_t);
+         recv_bytes   = recv_bytes - sizeof(uint8_t);
+         switch(req_data->type) {
+                 case FRESCAN_BWRES_REQ_GN:
+                         return frescan_gn_message_to_request(msg_to_parse,
+                                                              req_data,
+                                                              recv_bytes);
+                 case FRESCAN_BWRES_REQ_MC:
+                         return frescan_mc_message_to_request(msg_to_parse,
+                                                              req_data,
+                                                              recv_bytes);
+                 case FRESCAN_BWRES_REP_GN:
+                         return frescan_rep_gn_message_to_request(msg_to_parse,
+                                                                  req_data,
+                                                                  recv_bytes);
+                 case FRESCAN_BWRES_REQ_RES:
+                 case FRESCAN_BWRES_REQ_RES_GET:
+                 case FRESCAN_BWRES_REP_RES_GET:
+                 case FRESCAN_BWRES_REQ_RES_SET:
+                 case FRESCAN_BWRES_REQ_RES_COMMIT:
+                 case FRESCAN_BWRES_REQ_RES_CANCEL:
+                 default:
+                         FRESCAN_ERROR("request type %d not supported\n",
+                                       req_data->type);
+                         return -1;
+         }
+ }
index 0000000000000000000000000000000000000000,393bd9664490396aa54b6ab028cba29158e0b07d..393bd9664490396aa54b6ab028cba29158e0b07d
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,110 +1,110 @@@
+ /*!
+  * @file frescan_bwres_messages.h
+  *
+  * @brief FRESCAN bandwidth reservation layer: negotiation messages formating
+  *
+  * This module contains the data types that define the FRESCAN negotiation
+  * message format and operations to convert them into or from negotiation
+  * requests
+  *
+  * @version 0.01
+  *
+  * @date 2-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_BWRES_MESSAGES_H_
+ #define _FRESCAN_BWRES_MESSAGES_H_
+ #include "frescan_types.h"
+ /**
+  * frescan_messages_init() - initialization function for the module
+  */
+ extern int frescan_messages_init(frescan_network_t net);
+ /**
+  * frescan_messages_send_request()
+  *
+  * this function converts a request with the necessary data into a message
+  * and sends it.
+  *
+  * @req_data: the request to be sent (NOTE: the network is in req_data)
+  *
+  */
+ extern int frescan_messages_send_request
+                         (const frescan_bwres_request_data_t *req_data);
+ /**
+  * frescan_messages_recv_request()
+  *
+  * this function BLOCKS the calling thread until receives a message
+  * and transforms it into a request.
+  *
+  * @net: network from where we want to wait messages
+  * @req: the request received (it must be freed)
+  *
+  */
+ extern int frescan_messages_recv_request(frescan_network_t    net,
+                                          frescan_bwres_request_id_t *req);
+ #endif // _FRESCAN_BWRES_MESSAGES_H_
index 0000000000000000000000000000000000000000,2eeadf04308021c6ef3acecd71a4f8201a62d86f..2eeadf04308021c6ef3acecd71a4f8201a62d86f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,362 +1,362 @@@
+ /*!
+  * @file frescan_bwres_analysis.h
+  *
+  * @brief FRESCAN bandwith reservation layer: mode change protocol
+  *
+  * @version 0.02
+  *
+  * @date 19-Jul-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @comments
+  *
+  * This module contains the mode change protocol
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include <misc/linux_list.h>
+ #include <stdbool.h>
+ #include "frescan_data.h"
+ #include "frescan_servers.h"
+ #include "frescan_bwres_messages.h"
+ #include "frescan_bwres_mode_change.h"
+ #include "frescan_debug.h"
+ #include "frescan_config.h"
+ static int frescan_bwres_send_mc_messages
+                         (frescan_network_t net,
+                          frescan_bwres_mode_change_type_t mode_change_type,
+                          frescan_ss_group_t *ss_to_cancel);
+ /**
+  * frescan_bwres_mode_change_protocol() - performs the mode change protocol
+  */
+ int frescan_bwres_mode_change_protocol(frescan_bwres_request_data_t *req_data)
+ {
+         int ret;
+         frescan_node_t node;
+         frescan_bwres_vres_t *vres;
+         frsh_sa_vres_data_t *sa_vres_data;
+         frsh_sa_time_t max_period_in_budget_dec;
+         frsh_sa_time_t max_period_in_budget_inc;
+         struct timespec start_timestamp, next_activation;
+         DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG, "START MODE CHANGE PROTOCOL\n");
+         for(node=0; node<FRESCAN_MX_NODES; node++) {
+                 INIT_LIST_HEAD(&frescan_data[req_data->net].
+                                                 mode_change_list[node]);
+                 frescan_data[req_data->net].mode_change_type[node] = 0;
+         }
+         max_period_in_budget_dec = (frsh_sa_time_t)0;
+         max_period_in_budget_inc = (frsh_sa_time_t)0;
+         DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG, "1.- adding vres to mc list\n");
+         list_for_each_entry
+                         (vres,
+                          &frescan_data[req_data->net].scenario.vres_head.list,
+                          list)
+         {
+                 sa_vres_data = &frescan_data[req_data->net].
+                                 scenario.fsa_scenario.sa_vres_alloc
+                                                 [vres->fsa_vres_global_id];
+                 vres->mode_change_type = 0;
+                 if ((vres->old_c == 0) &&
+                     (vres->old_t == 0) &&
+                     (vres->old_p == 0)) {
+                         //new vres (transmitted in the reply message)
+                         vres->old_c = sa_vres_data->c;
+                         vres->old_t = sa_vres_data->t;
+                         vres->old_p = sa_vres_data->p;
+                         continue;
+                 }
+                 if (sa_vres_data->c > vres->old_c) {
+                         vres->mode_change_type |= FRESCAN_BWRES_MC_BUDGET_INC;
+                         if (sa_vres_data->t > max_period_in_budget_inc) {
+                                 max_period_in_budget_inc = sa_vres_data->t;
+                         }
+                 } else if (sa_vres_data->c < vres->old_c) {
+                         vres->mode_change_type |= FRESCAN_BWRES_MC_BUDGET_DEC;
+                         if (sa_vres_data->t > max_period_in_budget_dec) {
+                                 max_period_in_budget_dec = sa_vres_data->t;
+                         }
+                 }
+                 if (sa_vres_data->t > vres->old_t) {
+                         vres->mode_change_type |= FRESCAN_BWRES_MC_PERIOD_INC;
+                 } else if (sa_vres_data->t < vres->old_t) {
+                         vres->mode_change_type |= FRESCAN_BWRES_MC_PERIOD_DEC;
+                 }
+                 if (sa_vres_data->p > vres->old_p) {
+                         vres->mode_change_type |= FRESCAN_BWRES_MC_PRIO_INC;
+                 } else if (sa_vres_data->p < vres->old_p) {
+                         vres->mode_change_type |= FRESCAN_BWRES_MC_PRIO_DEC;
+                 }
+                 if (vres->mode_change_type == 0) continue;
+                 vres->old_c = sa_vres_data->c;
+                 vres->old_t = sa_vres_data->t;
+                 vres->old_p = sa_vres_data->p;
+                 list_add_tail(&(vres->mode_change_list),
+                               &(frescan_data[req_data->net].
+                                         mode_change_list[vres->node]));
+                 frescan_data[req_data->net].mode_change_type[vres->node] |=
+                                 vres->mode_change_type;
+                 DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG,
+                       "vres:%u node:%u ss:%u mc_type:0x%X\n",
+                       vres->fsa_vres_global_id, vres->node,
+                       vres->ss, vres->mode_change_type);
+         }
+         DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG, "2.- Budget decrease\n");
+         ret = frescan_bwres_send_mc_messages(req_data->net,
+                                              FRESCAN_BWRES_MC_BUDGET_DEC,
+                                              req_data->ss_to_cancel);
+         if (ret != 0) return -1;
+         ret = frescan_bwres_mode_change_local(req_data->net,
+                                               FRESCAN_BWRES_MC_BUDGET_DEC,
+                                               req_data->ss_to_cancel);
+         if (ret != 0) return -1;
+         DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG, "3.- Wait max_period\n");
+         ret = clock_gettime(CLOCK_MONOTONIC, &start_timestamp);
+         if (ret != 0) return -1;
+         add_timespec(next_activation,
+                      frsh_rel_time_to_timespec(frsh_sa_time_to_rel_time
+                                                 (max_period_in_budget_inc)),
+                      frsh_rel_time_to_timespec(frsh_sa_time_to_rel_time
+                                                 (max_period_in_budget_dec)));
+         incr_timespec(next_activation, start_timestamp);
+         ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,
+                               &next_activation, NULL);
+         if (ret != 0) return -1;
+         DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG, "4.- Budget increase\n");
+         ret = frescan_bwres_send_mc_messages(req_data->net,
+                                              FRESCAN_BWRES_MC_BUDGET_INC,
+                                              NULL);
+         if (ret != 0) return -1;
+         ret = frescan_bwres_mode_change_local(req_data->net,
+                                               FRESCAN_BWRES_MC_BUDGET_INC,
+                                               NULL);
+         if (ret != 0) return -1;
+         return 0;
+ }
+ /**
+  * frescan_bwres_send_mc_messages()
+  *
+  * This function is executed at the master node to send mode change
+  * messages to the slaves
+  */
+ static int frescan_bwres_send_mc_messages
+                         (frescan_network_t net,
+                          frescan_bwres_mode_change_type_t mode_change_type,
+                          frescan_ss_group_t *ss_to_cancel)
+ {
+         int ret;
+         frescan_node_t node;
+         frescan_bwres_request_data_t tmp_req_data;
+         tmp_req_data.net              = net;
+         tmp_req_data.type             = FRESCAN_BWRES_REQ_MC;
+         tmp_req_data.mode_change_type = mode_change_type;
+         for(node=0; node<FRESCAN_MX_NODES; node++) {
+                 if (node == FRESCAN_BWRES_MASTER_NODE) continue;
+                 if ((frescan_data[net].mode_change_type[node] &
+                      mode_change_type) != mode_change_type) continue;
+                 DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG,
+                       "send MC message to node:%u\n", node);
+                 tmp_req_data.request_node = node;
+                 tmp_req_data.ss_to_cancel = ss_to_cancel;
+                 ret = frescan_messages_send_request(&tmp_req_data);
+                 if (ret != 0) return -1;
+         }
+         return 0;
+ }
+ /**
+  * frescan_bwres_mode_change_local()
+  *
+  * This function updates local vres. When a slave receives a change mode
+  * message to change the values of any vres this function is called.
+  */
+ int frescan_bwres_mode_change_local
+                 (frescan_network_t net,
+                  frescan_bwres_mode_change_type_t mode_change_type,
+                  frescan_ss_group_t *ss_to_cancel)
+ {
+         int ret, i;
+         frescan_server_params_t server_params;
+         frescan_bwres_vres_t *vres;
+         struct timespec start_timestamp, next_activation;
+         frescan_node_t me = frescan_data[net].local_node;
+         list_for_each_entry(vres,
+                             &frescan_data[net].mode_change_list[me],
+                             mode_change_list)
+         {
+                 if ((vres->mode_change_type & mode_change_type) !=
+                      mode_change_type) continue;
+                 server_params.budget = frsh_rel_time_to_usec(
+                                 frsh_sa_time_to_rel_time(vres->old_c)) /
+                                 FRESCAN_FRAME_TX_TIME_US;
+                 server_params.period = frsh_sa_time_to_rel_time(vres->old_t);
+                 server_params.prio   = vres->old_p;
+                 if (mode_change_type == FRESCAN_BWRES_MC_BUDGET_INC) {
+                         DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG,
+                               "commit ss:%u\n", vres->ss);
+                         ret = frescan_servers_update(net,
+                                                      &server_params,
+                                                      vres->ss);
+                         if (ret != 0) return ret;
+                 } else {
+                         DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG,
+                               "set perceived ss:%u\n", vres->ss);
+                         ret = frescan_servers_set_perceived(net,
+                                                             &server_params,
+                                                             vres->ss);
+                         if (ret != 0) return ret;
+                 }
+         }
+         if (mode_change_type == FRESCAN_BWRES_MC_BUDGET_INC) return 0;
+         // for ss cancelled set the perceived capacity to cero
+         if (ss_to_cancel != NULL) {
+                 for(i=0; i<ss_to_cancel->size; i++) {
+                         server_params.budget = 0;
+                         server_params.period = frsh_usec_to_rel_time(0);
+                         server_params.prio   = 0;
+                         ret = frescan_servers_set_perceived
+                                                         (net,
+                                                         &server_params,
+                                                         ss_to_cancel->ss[i]);
+                         if (ret != 0) return ret;
+                 }
+         }
+         ret = clock_gettime(CLOCK_MONOTONIC, &start_timestamp);
+         if (ret != 0) return -1;
+         list_for_each_entry(vres,
+                             &frescan_data[net].mode_change_list[me],
+                             mode_change_list)
+         {
+                 if ((vres->mode_change_type & mode_change_type) !=
+                      mode_change_type) continue;
+                 DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG,
+                       "wait ss:%u period\n", vres->ss);
+                 add_timespec(next_activation, start_timestamp,
+                                 frsh_rel_time_to_timespec(
+                                        frsh_sa_time_to_rel_time(vres->old_t)));
+                 ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,
+                                       &next_activation, NULL);
+                 if (ret != 0) return -1;
+                 DEBUG(FRESCAN_BWRES_MC_ENABLE_DEBUG,
+                       "commit ss:%u\n", vres->ss);
+                 ret = frescan_servers_commit_perceived(net, vres->ss);
+                 if (ret != 0) return ret;
+         }
+         if (ss_to_cancel != NULL) {
+                 for(i=0; i<ss_to_cancel->size; i++) {
+                         ret = frescan_servers_destroy
+                                         (net, ss_to_cancel->ss[i]);
+                         if (ret != 0) return ret;
+                 }
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,04bfeb4b6463f8511c5ac1bc9e77556574dc42ef..04bfeb4b6463f8511c5ac1bc9e77556574dc42ef
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,99 +1,99 @@@
+ /*!
+  * @file frescan_bwres_analysis.h
+  *
+  * @brief FRESCAN bandwith reservation layer: mode change protocol
+  *
+  * @version 0.02
+  *
+  * @date 19-Jul-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @comments
+  *
+  * This module contains the mode change protocol
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_BWRES_MODE_CHANGE_H_
+ #define _FRESCAN_BWRES_MODE_CHANGE_H_
+ #include "frescan_types.h"
+ /**
+  * frescan_bwres_mode_change_protocol()
+  *
+  * Performs the mode change protocol. This function is called by the master
+  * node who coordinates all the process.
+  */
+ extern int frescan_bwres_mode_change_protocol
+                                 (frescan_bwres_request_data_t *req_data);
+ /**
+  * frescan_bwres_mode_change_local()
+  *
+  * This function updates local vres. When a slave receives a change mode
+  * message to change the values of any vres this function is called.
+  */
+ extern int frescan_bwres_mode_change_local
+                 (frescan_network_t net,
+                  frescan_bwres_mode_change_type_t mode_change_type,
+                  frescan_ss_group_t *ss_to_cancel);
+ #endif // _FRESCAN_BWRES_MODE_CHANGE_H_
index 0000000000000000000000000000000000000000,4c995ac7f802c2f8ba5a4c42eaa45ae89796bf2e..4c995ac7f802c2f8ba5a4c42eaa45ae89796bf2e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,288 +1,288 @@@
+ /*!
+  * @file frescan_bwres_requests.c
+  *
+  * @brief FRESCAN bandwith reservation layer: requests
+  *
+  * This module contains an operation to create the queue, an operation to
+  * enqueue a message (with a request), and an operation to
+  * dequeue a message.
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include <misc/freelist.h>
+ #include <misc/linux_list.h>
+ #include "frescan.h"
+ #include "frescan_bwres_requests.h"
+ #include "frescan_config.h"
+ #include "frescan_debug.h"
+ #include "fosa_mutexes_and_condvars.h"
+ static bool is_initialized = false;
+ /**
+  * the_requests_pool
+  *
+  * We will use a freelist to allocate and free the requests.
+  *
+  **/
+ struct request_t {
+         frescan_bwres_request_data_t request_data;
+         struct list_head       request_list;
+         int pool_pos;
+ };
+ static fosa_mutex_t requests_mutex;
+ static fosa_cond_t  requests_cond;
+ static struct request_t the_requests_pool[FRESCAN_BWRES_MX_REQUESTS];
+ static freelist_t freelist;
+ static struct request_t the_requests_list;
+ /**
+  * frescan_bwres_requests_init()
+  *
+  * Init the freelist, requests list, cond var and mutex.
+  *
+  **/
+ int frescan_bwres_requests_init(int max_ceiling)
+ {
+         int err;
+         err = fosa_mutex_init(&requests_mutex, max_ceiling);
+         if (err != 0) return err;
+         err = fosa_cond_init(&requests_cond);
+         if (err != 0) return err;
+         err = freelist_init(&freelist, FRESCAN_BWRES_MX_REQUESTS);
+         if (err != 0) return err;
+         INIT_LIST_HEAD(&the_requests_list.request_list);
+         is_initialized = true;
+         return 0;
+ }
+ /**
+  * frescan_bwres_requests_alloc()
+  *
+  * Allocate a request with the mutex locked
+  *
+  **/
+ int frescan_bwres_requests_alloc(frescan_bwres_request_id_t *req)
+ {
+         int err, pos;
+         DEBUG(FRESCAN_BWRES_REQUESTS_ENABLE_DEBUG, "alloc\n");
+         if (is_initialized == false) return -1;
+         err = fosa_mutex_lock(&requests_mutex);
+         if (err != 0) return err;
+                 pos = freelist_alloc(&freelist);
+                 if (pos < 0) goto locked_error;
+         err = fosa_mutex_unlock(&requests_mutex);
+         if (err != 0) return err;
+         *req = (unsigned int)pos;
+         the_requests_pool[*req].pool_pos = pos;
+         return 0;
+ locked_error:
+         fosa_mutex_unlock(&requests_mutex);
+         return pos;
+ }
+ /**
+  * frescan_bwres_requests_free()
+  *
+  * free the request from the pool
+  *
+  **/
+ int frescan_bwres_requests_free(frescan_bwres_request_id_t req)
+ {
+         int err;
+         DEBUG(FRESCAN_BWRES_REQUESTS_ENABLE_DEBUG, "free\n");
+         if (is_initialized == false) return -1;
+         err = fosa_mutex_lock(&requests_mutex);
+         if (err != 0) return err;
+                 err = freelist_free(&freelist, req);
+                 if (err != 0) goto locked_error;
+         err = fosa_mutex_unlock(&requests_mutex);
+         if (err != 0) return err;
+         return 0;
+ locked_error:
+         fosa_mutex_unlock(&requests_mutex);
+         return err;
+ }
+ /**
+  * frescan_bwres_requests_get_data() - gets the data of the request
+  *
+  */
+ int frescan_bwres_requests_get_data(frescan_bwres_request_id_t   req,
+                               frescan_bwres_request_data_t **data)
+ {
+         DEBUG(FRESCAN_BWRES_REQUESTS_ENABLE_DEBUG, "request id:%d\n", req);
+         *data = &the_requests_pool[req].request_data;
+         return 0;
+ }
+ /**
+  * frescan_bwres_requests_enqueue()
+  *
+  **/
+ int frescan_bwres_requests_enqueue(frescan_bwres_request_id_t req)
+ {
+         int err;
+         err = fosa_mutex_lock(&requests_mutex);
+         if (err != 0) return err;
+         DEBUG(FRESCAN_BWRES_REQUESTS_ENABLE_DEBUG,
+               "is list empty A? %d\n",
+               list_empty(&the_requests_list.request_list));
+         list_add_tail(&the_requests_pool[req].request_list,
+                       &the_requests_list.request_list);
+         DEBUG(FRESCAN_BWRES_REQUESTS_ENABLE_DEBUG,
+               "is list empty B? %d\n",
+               list_empty(&the_requests_list.request_list));
+         err = fosa_cond_signal(&requests_cond);
+         if (err != 0) goto locked_error;
+         err = fosa_mutex_unlock(&requests_mutex);
+         if (err != 0) return err;
+         return 0;
+ locked_error:
+         fosa_mutex_unlock(&requests_mutex);
+         return err;
+ }
+ /**
+  * frescan_bwres_requestqueue_dequeue()
+  *
+  **/
+ int frescan_bwres_requests_dequeue(frescan_bwres_request_id_t *req)
+ {
+         int err;
+         struct list_head *pos;
+         struct request_t *request = NULL;
+         err = fosa_mutex_lock(&requests_mutex);
+         if (err != 0) return err;
+         DEBUG(FRESCAN_BWRES_REQUESTS_ENABLE_DEBUG, "entering\n");
+         while (list_empty(&the_requests_list.request_list)) {
+                 err = fosa_cond_wait(&requests_cond, &requests_mutex);
+                 if (err != 0) goto locked_error;
+                 DEBUG(FRESCAN_BWRES_REQUESTS_ENABLE_DEBUG, "received signal\n");
+         }
+         DEBUG(FRESCAN_BWRES_REQUESTS_ENABLE_DEBUG, "dequeueing a request\n");
+         list_for_each(pos, &the_requests_list.request_list) {
+                 request = list_entry(pos, struct request_t, request_list);
+                 break;
+         }
+         list_del(&request->request_list);
+         *req = request->pool_pos;
+         DEBUG(FRESCAN_BWRES_REQUESTS_ENABLE_DEBUG,
+               "is list empty now? %d\n",
+               list_empty(&the_requests_list.request_list));
+         err = fosa_mutex_unlock(&requests_mutex);
+         if (err != 0) return err;
+         return 0;
+ locked_error:
+         fosa_mutex_unlock(&requests_mutex);
+         return err;
+ }
index 0000000000000000000000000000000000000000,e5dde6fc808eb55bb385e1cc867bff986276fbfc..e5dde6fc808eb55bb385e1cc867bff986276fbfc
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,94 +1,94 @@@
+ /*!
+  * @file frescan_bwres_requests.h
+  *
+  * @brief FRESCAN bandwith reservation layer: requests
+  *
+  * This module contains the request type definition and queues. They are used
+  * to ask negotiation, renegotiation or cancel contracts.
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_BWRES_REQUESTS_H_
+ #define _FRESCAN_BWRES_REQUESTS_H_
+ #include "frescan_types.h"
+ extern int frescan_bwres_requests_init(int max_ceiling);
+ extern int frescan_bwres_requests_alloc(frescan_bwres_request_id_t *req);
+ extern int frescan_bwres_requests_free(frescan_bwres_request_id_t req);
+ extern int frescan_bwres_requests_enqueue(frescan_bwres_request_id_t req);
+ extern int frescan_bwres_requests_dequeue(frescan_bwres_request_id_t *req);
+ /**
+  * frescan_bwres_requests_get_data() - gets the data of the request
+  *
+  * @data: the data is obtained as a pointer an manipulated directly
+  *        accesing to the members of the structure. Note that this is
+  *        just an internal API so instead of using get/set functions we
+  *        will just access to the members of the struc directly
+  */
+ extern int frescan_bwres_requests_get_data(frescan_bwres_request_id_t   req,
+                                            frescan_bwres_request_data_t **data);
+ #endif // _FRESCAN_BWRES_REQUESTS_H_
index 0000000000000000000000000000000000000000,34c50e7a15d279fbe500cab30a9542bea3583e77..34c50e7a15d279fbe500cab30a9542bea3583e77
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,318 +1,318 @@@
+ /*!
+  * @file frescan_bwres_robjs.c
+  *
+  * @brief FRESCAN bandwith reservation layer: reply objects
+  *
+  * This module contains the definition of the data object and operations to
+  * create a pool of objects, obtain the id of an unused object, wait upon it,
+  * signal it, and finish using it.
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include <misc/freelist.h>
+ #include "frescan_bwres_robjs.h"
+ #include "fosa_mutexes_and_condvars.h"
+ #include "frescan_config.h"
+ #include "frescan_debug.h"
+ static bool is_initialized = false;
+ /**
+  * the_reply_objects
+  *
+  * We will use a freelist to allocate and free the reply object. Reply objects
+  * are FOSA conditional variables (we can't use synchobjects because they are
+  * only for bound-workload) stored in an array together with their condition
+  * and a mutex variable to control the access and to be able to wait and
+  * signal the conditional variables. We could have used semaphores instead, but
+  * it would introduce a dependency on the OS because they are not in FOSA.
+  *
+  **/
+ static fosa_mutex_t freelist_mutex;
+ struct replyobj_t {
+         bool is_work_done;
+         fosa_cond_t cond;
+         fosa_mutex_t mutex;
+ };
+ static struct replyobj_t the_reply_objects[FRESCAN_BWRES_MX_REPLY_OBJECTS];
+ static freelist_t freelist;
+ /**
+  * frescan_bwres_robjs_init()
+  *
+  * Init the freelist and its mutex. The conditional variables are not
+  * initialized here but when allocating a reply object. This can be more
+  * efficient for memory usage in some OS (not in MaRTE OS though).
+  *
+  **/
+ int frescan_bwres_robjs_init(int max_ceiling)
+ {
+         int err;
+         err = fosa_mutex_init(&freelist_mutex, max_ceiling);
+         if (err != 0) return err;
+         err = freelist_init(&freelist, FRESCAN_BWRES_MX_REPLY_OBJECTS);
+         if (err != 0) return err;
+         is_initialized = true;
+         return 0;
+ }
+ /**
+  * frescan_bwres_robjs_alloc()
+  *
+  * Allocate an reply object with the freelist_mutex locked and then initialize
+  * its cond variable, condition (predicate) and mutex. The ID of the allocated
+  * reply object represents the position in the array the_reply_objects.
+  *
+  **/
+ int frescan_bwres_robjs_alloc(frescan_bwres_robj_id_t *id, int ceiling)
+ {
+         int err, pos;
+         DEBUG(FRESCAN_BWRES_ROBJS_ENABLE_DEBUG,
+               "allocating reply object, is_initialized=%d\n", is_initialized);
+         if (is_initialized == false) return -1;
+         err = fosa_mutex_lock(&freelist_mutex);
+         if (err != 0) return err;
+                 pos = freelist_alloc(&freelist);
+                 if (pos < 0) goto locked_error;
+         err = fosa_mutex_unlock(&freelist_mutex);
+         if (err != 0) return err;
+         err = fosa_cond_init(&the_reply_objects[pos].cond);
+         if (err != 0) return err;
+         the_reply_objects[pos].is_work_done = false;
+         *id = (unsigned int)pos;
+         err = fosa_mutex_init(&the_reply_objects[pos].mutex, ceiling);
+         if (err != 0) return err;
+         DEBUG(FRESCAN_BWRES_ROBJS_ENABLE_DEBUG,
+               "reply object allocated, id=%d\n", *id);
+         return 0;
+ locked_error:
+         fosa_mutex_unlock(&freelist_mutex);
+         return pos;
+ }
+ /**
+  * frescan_bwres_robjs_free()
+  *
+  * Destroy the cond variable and then free the replyobject
+  *
+  **/
+ int frescan_bwres_robjs_free(frescan_bwres_robj_id_t id)
+ {
+         int err;
+         DEBUG(FRESCAN_BWRES_ROBJS_ENABLE_DEBUG,
+               "free reply id=%d, is_initialized=%d\n", id, is_initialized);
+         if (is_initialized == false) return -1;
+         err = fosa_mutex_lock(&freelist_mutex);
+         if (err != 0) return err;
+                 err = freelist_free(&freelist, id);
+                 if (err != 0) goto locked_error;
+                 err = fosa_cond_destroy(&the_reply_objects[id].cond);
+                 if (err != 0) return err;
+                 err = fosa_mutex_destroy(&the_reply_objects[id].mutex);
+                 if (err != 0) return err;
+                 the_reply_objects[id].is_work_done = false;
+         err = fosa_mutex_unlock(&freelist_mutex);
+         if (err != 0) return err;
+         return 0;
+ locked_error:
+         fosa_mutex_unlock(&freelist_mutex);
+         return err;
+ }
+ /**
+  * frescan_bwres_robjs_signal()
+  *
+  * Signal the cond variable
+  *
+  **/
+ int frescan_bwres_robjs_signal(frescan_bwres_robj_id_t id)
+ {
+         int err;
+         DEBUG(FRESCAN_BWRES_ROBJS_ENABLE_DEBUG,
+               "is_initialized=%d\n", is_initialized);
+         if (is_initialized == false) return -1;
+         DEBUG(FRESCAN_BWRES_ROBJS_ENABLE_DEBUG,
+               "taking mutex of the reply id=%d\n", id);
+         err = fosa_mutex_lock(&the_reply_objects[id].mutex);
+         if (err != 0) return err;
+                 the_reply_objects[id].is_work_done = true;
+                 DEBUG(FRESCAN_BWRES_ROBJS_ENABLE_DEBUG,
+                       "signal the cond variable\n");
+                 err = fosa_cond_signal(&the_reply_objects[id].cond);
+                 if (err != 0) goto locked_error;
+         err = fosa_mutex_unlock(&the_reply_objects[id].mutex);
+         if (err != 0) return err;
+         return 0;
+ locked_error:
+         FRESCAN_ERROR("locked error %d\n", err);
+         fosa_mutex_unlock(&the_reply_objects[id].mutex);
+         return err;
+ }
+ /**
+  * frescan_bwres_robjs_wait()
+  *
+  * Wait on the cond variable.
+  *
+  **/
+ int frescan_bwres_robjs_wait(frescan_bwres_robj_id_t id)
+ {
+         int err;
+         if (is_initialized == false) return -1;
+         err = fosa_mutex_lock(&the_reply_objects[id].mutex);
+         if (err != 0) return err;
+                 while (the_reply_objects[id].is_work_done == false) {
+                         err = fosa_cond_wait(&the_reply_objects[id].cond,
+                                              &the_reply_objects[id].mutex);
+                         if (err != 0) goto locked_error;
+                 }
+                 the_reply_objects[id].is_work_done = false;
+         err = fosa_mutex_unlock(&the_reply_objects[id].mutex);
+         if (err != 0) return err;
+         return 0;
+ locked_error:
+         fosa_mutex_unlock(&the_reply_objects[id].mutex);
+         return err;
+ }
+ /**
+  * frescan_bwres_robjs_timedwait()
+  *
+  * Wait on the cond variable with a timeout.
+  *
+  **/
+ int frescan_bwres_robjs_timedwait(frescan_bwres_robj_id_t id,
+                                   const struct timespec *abstime)
+ {
+         int err;
+         if (is_initialized == false) return -1;
+         err = fosa_mutex_lock(&the_reply_objects[id].mutex);
+         if (err != 0) return err;
+         while (the_reply_objects[id].is_work_done == false) {
+                 err = fosa_cond_timedwait(&the_reply_objects[id].cond,
+                                           &the_reply_objects[id].mutex,
+                                           abstime);
+                 if (err != 0) goto locked_error;
+         }
+         the_reply_objects[id].is_work_done = false;
+         err = fosa_mutex_unlock(&the_reply_objects[id].mutex);
+         if (err != 0) return err;
+         return 0;
+ locked_error:
+         fosa_mutex_unlock(&the_reply_objects[id].mutex);
+         return err;
+ }
index 0000000000000000000000000000000000000000,94eddb60e2f2e1c0c987e6ed8a1cfc60c66f7407..94eddb60e2f2e1c0c987e6ed8a1cfc60c66f7407
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,85 +1,85 @@@
+ /*!
+  * @file frescan_bwres_robjs.h
+  *
+  * @brief FRESCAN bandwith reservation layer: reply objects
+  *
+  * This module contains the definition of the data object and operations to
+  * create a pool of objects, obtain the id of an unused object, wait upon it,
+  * signal it, and finish using it.
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_BWRES_ROBJS_H_
+ #define _FRESCAN_BWRES_ROBJS_H_
+ #include "frescan_types.h"
+ extern int frescan_bwres_robjs_init(int max_ceiling);
+ extern int frescan_bwres_robjs_alloc(frescan_bwres_robj_id_t *id, int ceiling);
+ extern int frescan_bwres_robjs_free(frescan_bwres_robj_id_t id);
+ extern int frescan_bwres_robjs_signal(frescan_bwres_robj_id_t id);
+ extern int frescan_bwres_robjs_wait(frescan_bwres_robj_id_t id);
+ extern int frescan_bwres_robjs_timedwait(frescan_bwres_robj_id_t id,
+                                          const struct timespec *abstime);
+ #endif // _FRESCAN_BWRES_ROBJS_H_
index 0000000000000000000000000000000000000000,20df2b71e1fdfcf5b180507bbf951e90b5ab1cbc..20df2b71e1fdfcf5b180507bbf951e90b5ab1cbc
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,478 +1,478 @@@
+ /*!
+  * @file frescan_bwres_threads.c
+  *
+  * @brief FRESCAN bandwidth reservation layer: negotiation threads
+  *
+  * This module contains the acceptor threads and the master thread for local
+  * negotiations, with functions to create them.
+  *
+  * @version 0.01
+  *
+  * @date 2-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include <assert.h>
+ #include "fosa_threads_and_signals.h" // fosa_thread_attr_init...
+ #include "frescan_bwres_threads.h"
+ #include "frescan_bwres_messages.h"
+ #include "frescan_bwres_requests.h"
+ #include "frescan_bwres_robjs.h"
+ #include "frescan_bwres_analysis.h"
+ #include "frescan_bwres_mode_change.h"
+ #include "frescan_config.h"
+ #include "frescan_debug.h"
+ #include "frescan_data.h"
+ #include "frescan_servers.h"
+ static void *frescan_manager_thread(void *arg);
+ static void *frescan_acceptor_thread(void *arg);
+ static void frescan_manager_gn_prepare_scenario
+                                 (frescan_bwres_sa_scenario_t  *scenario,
+                                  frescan_bwres_request_data_t *req_data);
+ static void frescan_manager_gn_restore_scenario
+                                 (frescan_bwres_sa_scenario_t  *scenario,
+                                  frescan_bwres_request_data_t *req_data);
+ static void frescan_manager_req_gn(frescan_bwres_request_data_t *req_data);
+ static void frescan_manager_rep_gn(frescan_bwres_request_data_t *req_data);
+ static void frescan_manager_req_mc(frescan_bwres_request_data_t *req_data);
+ /**
+  * frescan_manager_thread_create()
+  *
+  * This call creates the manager thread at each node which will be waiting
+  * in a request queue for LOCAL or EXTERNAL requests.
+  */
+ int frescan_manager_thread_create(frescan_network_t net)
+ {
+         int ret;
+         fosa_thread_attr_t attr;
+         ret = fosa_thread_attr_init(&attr);
+         if (ret != 0) return ret;
+         ret = fosa_thread_attr_set_prio(&attr, FRESCAN_BWRES_NEG_THREAD_PRIO);
+         if (ret != 0) return ret;
+         ret = fosa_thread_create(&frescan_data[net].manager_thread_id,
+                                  &attr,
+                                  frescan_manager_thread,
+                                  (void *)(uint32_t)net);
+         if (ret != 0) return ret;
+         ret = fosa_thread_attr_destroy(&attr);
+         if (ret != 0) return ret;
+         return 0;
+ }
+ /**
+  * frescan_acceptor_thread_create()
+  *
+  * This call creates the acceptor thread which will be waiting negotiation
+  * messages from the network and converting them into requests.
+  */
+ int frescan_acceptor_thread_create(frescan_network_t net)
+ {
+         int ret;
+         fosa_thread_attr_t attr;
+         ret = fosa_thread_attr_init(&attr);
+         if (ret != 0) return ret;
+         ret = fosa_thread_attr_set_prio(&attr, FRESCAN_BWRES_ACCEPTOR_PRIO);
+         if (ret != 0) return ret;
+         ret = fosa_thread_create(&frescan_data[net].acceptor_thread_id,
+                                  &attr,
+                                  frescan_acceptor_thread,
+                                  (void *)(uint32_t)net);
+         if (ret != 0) return ret;
+         ret = fosa_thread_attr_destroy(&attr);
+         if (ret != 0) return ret;
+         return 0;
+ }
+ /**
+  * frescan_manager_thread
+  */
+ static void *frescan_manager_thread(void *arg)
+ {
+         int ret;
+         frescan_bwres_request_id_t   req;
+         frescan_bwres_request_data_t *req_data;
+         frescan_network_t net = (uint32_t)arg;
+         DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG, "manager thread starts\n");
+         while(1) {
+                 DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG, "wait for a request\n");
+                 ret = frescan_bwres_requests_dequeue(&req);
+                 assert(ret == 0);
+                 ret = frescan_bwres_requests_get_data(req, &req_data);
+                 assert(ret == 0);
+                 switch(req_data->type) {
+                         case FRESCAN_BWRES_REQ_GN:
+                                 frescan_manager_req_gn(req_data);
+                                 break;
+                         case FRESCAN_BWRES_REP_GN:
+                                 frescan_manager_rep_gn(req_data);
+                                 break;
+                         case FRESCAN_BWRES_REQ_MC:
+                                 frescan_manager_req_mc(req_data);
+                                 break;
+                         case FRESCAN_BWRES_REQ_RES:
+                         case FRESCAN_BWRES_REQ_RES_GET:
+                         case FRESCAN_BWRES_REP_RES_GET:
+                         case FRESCAN_BWRES_REQ_RES_SET:
+                         case FRESCAN_BWRES_REQ_RES_COMMIT:
+                         case FRESCAN_BWRES_REQ_RES_CANCEL:
+                         default:
+                                 FRESCAN_ERROR("request type not supported\n");
+                                 assert(0);
+                 }
+                 if(req_data->request_node != frescan_data[net].local_node) {
+                         ret = frescan_bwres_requests_free(req);
+                         assert(ret == 0);
+                 }
+         }
+ }
+ /**
+  * frescan_acceptor_thread()
+  */
+ static void *frescan_acceptor_thread(void *arg)
+ {
+         int ret;
+         frescan_bwres_request_id_t req;
+         frescan_network_t net = (uint32_t)arg;
+         DEBUG(FRESCAN_BWRES_ACCEPTOR_ENABLE_DEBUG, "acceptor thread starts\n");
+         while(1) {
+                 ret = frescan_messages_recv_request(net, &req);
+                 assert(ret == 0);
+                 ret = frescan_bwres_requests_enqueue(req);
+                 assert(ret == 0);
+         }
+         return NULL;
+ }
+ /**
+  * frescan_manager_req_gn
+  */
+ static void frescan_manager_req_gn(frescan_bwres_request_data_t *req_data)
+ {
+         int ret, i;
+         frescan_node_t me;
+         bool accepted;
+         frescan_bwres_sa_scenario_t *scenario;
+         frescan_ss_t ss;
+         frescan_server_params_t server_params;
+         frescan_bwres_vres_t *vres;
+         me = frescan_data[req_data->net].local_node;
+         if (me != FRESCAN_BWRES_MASTER_NODE) {
+                 DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG,
+                       "send gn req to master\n");
+                 ret = frescan_messages_send_request(req_data);
+                 assert(ret == 0);
+                 return;
+         }
+         scenario = &frescan_data[req_data->net].scenario;
+         DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG, "prepare new scenario\n");
+         frescan_manager_gn_prepare_scenario(scenario, req_data);
+         DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG, "perform sched analysis\n");
+         ret = frescan_bwres_sa_sched_test(scenario, &accepted);
+         assert(ret == 0);
+         if (accepted) {
+                 DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG, "ACCEPTED!\n");
+                 req_data->return_value = FRESCAN_BWRES_REQ_ACCEPTED;
+                 DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG,
+                       "spare capacity and mode change\n");
+                 ret = frescan_bwres_sa_spare_capacity(scenario);
+                 assert(ret == 0);
+                 ret = frescan_bwres_mode_change_protocol(req_data);
+                 assert(ret == 0);
+         } else {
+                 DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG, "FAILED!\n");
+                 req_data->return_value = FRESCAN_BWRES_REQ_NOT_ACCEPTED;
+                 frescan_manager_gn_restore_scenario(scenario, req_data);
+         }
+         if (req_data->request_node != me) {
+                 DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG, "send reply\n");
+                 req_data->type = FRESCAN_BWRES_REP_GN;
+                 ret = frescan_messages_send_request(req_data);
+                 assert(ret == 0);
+                 return;
+         }
+         if (req_data->return_value == FRESCAN_BWRES_REQ_ACCEPTED) {
+                 // create servers for new contracts
+                 req_data->ss_new->size = req_data->contracts_to_neg->size;
+                 for(i=0; i<req_data->ss_new->size; i++) {
+                         vres = &frescan_data[req_data->net].scenario.
+                                         vres_pool[me]
+                                                 [req_data->ss_new->ss[i]];
+                         server_params.budget = frsh_rel_time_to_usec(
+                                         frsh_sa_time_to_rel_time(vres->old_c)) /
+                                         FRESCAN_FRAME_TX_TIME_US;
+                         server_params.period = frsh_sa_time_to_rel_time
+                                                                 (vres->old_t);
+                         server_params.prio   = vres->old_p;
+                         // Create server
+                         ret = frescan_servers_create(req_data->net,
+                                                 &server_params,
+                                                 &ss);
+                         assert(ret == 0);
+                         assert (req_data->ss_new->ss[i] == ss);
+                 }
+         }
+         DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG, "signal robj\n");
+         ret = frescan_bwres_robjs_signal(req_data->robj);
+         assert(ret == 0);
+ }
+ /**
+  * frescan_manager_gn_prepare_scenario
+  */
+ static void frescan_manager_gn_prepare_scenario
+                                 (frescan_bwres_sa_scenario_t  *scenario,
+                                  frescan_bwres_request_data_t *req_data)
+ {
+         int ret, i;
+         // NEG-GROUP
+         for(i=0; i<req_data->contracts_to_neg->size; i++) {
+                 ret = freelist_alloc(&frescan_data[req_data->net].scenario.
+                                       ss_id_freelist[req_data->request_node]);
+                 assert(ret >= 0);
+                 req_data->ss_new->ss[i] = (frescan_ss_t)ret;
+                 DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG,
+                       "prealloc net:%d node:%d ss_new->ss[%d]:%d\n",
+                       req_data->net, req_data->request_node,
+                       i, req_data->ss_new->ss[i]);
+                 ret = frescan_bwres_sa_add_contract
+                                 (scenario,
+                                  req_data->ss_new->ss[i],
+                                  req_data->request_node,
+                                  &req_data->contracts_to_neg->contracts[i]);
+                 assert(ret == 0);
+         }
+         req_data->ss_new->size = req_data->contracts_to_neg->size;
+         // RENEG-GROUP
+         scenario->backup_contracts_to_reneg.size =
+                                         req_data->contracts_to_reneg->size;
+         for(i=0; i<req_data->contracts_to_reneg->size; i++) {
+                 ret = frescan_bwres_sa_update_contract
+                         (scenario,
+                          req_data->ss_to_reneg->ss[i],
+                          req_data->request_node,
+                          &req_data->contracts_to_reneg->contracts[i],
+                          &scenario->backup_contracts_to_reneg.contracts[i]);
+                 assert(ret == 0);
+         }
+         // CANCEL-GROUP
+         scenario->backup_contracts_to_cancel.size =
+                                                 req_data->ss_to_cancel->size;
+         for(i=0; i<req_data->ss_to_cancel->size; i++) {
+                 ret = frescan_bwres_sa_remove_contract
+                         (scenario,
+                          req_data->ss_to_cancel->ss[i],
+                          req_data->request_node,
+                          &scenario->backup_contracts_to_cancel.contracts[i]);
+                 assert(ret == 0);
+         }
+ }
+ /**
+  * frescan_manager_gn_restore_scenario
+  */
+ static void frescan_manager_gn_restore_scenario
+                 (frescan_bwres_sa_scenario_t  *scenario,
+                  frescan_bwres_request_data_t *req_data)
+ {
+         int ret, i;
+         // NEG-GROUP
+         for(i=0; i<req_data->contracts_to_neg->size; i++) {
+                 ret = frescan_bwres_sa_remove_contract
+                                 (scenario,
+                                  req_data->ss_new->ss[i],
+                                  req_data->request_node,
+                                  NULL);
+                 assert(ret == 0);
+                 ret = freelist_free(&frescan_data[req_data->net].scenario.
+                                         ss_id_freelist[req_data->request_node],
+                                     req_data->ss_new->ss[i]);
+                 assert(ret == 0);
+         }
+         // RENEG-GROUP
+         for(i=0; i<req_data->contracts_to_reneg->size; i++) {
+                 ret = frescan_bwres_sa_update_contract
+                         (scenario,
+                          req_data->ss_to_reneg->ss[i],
+                          req_data->request_node,
+                          &scenario->backup_contracts_to_reneg.contracts[i],
+                          NULL);
+                 assert(ret == 0);
+         }
+         // CANCEL-GROUP
+         for(i=0; i<req_data->ss_to_cancel->size; i++) {
+                 ret = frescan_bwres_sa_add_contract
+                         (scenario,
+                          req_data->ss_to_cancel->ss[i],
+                          req_data->request_node,
+                          &scenario->backup_contracts_to_cancel.contracts[i]);
+                 assert(ret == 0);
+         }
+ }
+ /**
+  * frescan_manager_rep_gn
+  */
+ static void frescan_manager_rep_gn(frescan_bwres_request_data_t *req_data)
+ {
+         int ret, i;
+         frescan_bwres_request_data_t *caller_req;
+         ret = frescan_bwres_requests_get_data(req_data->req, &caller_req);
+         assert(ret == 0);
+         caller_req->return_value = req_data->return_value;
+         DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG,
+               "ret:%d -> %s\n", req_data->return_value,
+               (req_data->return_value ==
+                FRESCAN_BWRES_REQ_ACCEPTED) ? "OK" : "FAIL");
+         if (req_data->return_value == FRESCAN_BWRES_REQ_ACCEPTED) {
+                 assert (req_data->ss_new->size ==
+                         caller_req->contracts_to_neg->size);
+                 caller_req->ss_new->size = req_data->ss_new->size;
+                 DEBUG(FRESCAN_BWRES_MANAGER_ENABLE_DEBUG,
+                       "ss_new->size:%u\n", caller_req->ss_new->size);
+                 for (i=0; i<caller_req->ss_new->size; i++) {
+                         caller_req->ss_new->ss[i] = req_data->ss_new->ss[i];
+                 }
+         }
+         ret = frescan_bwres_robjs_signal(caller_req->robj);
+         assert(ret == 0);
+ }
+ /**
+  * frescan_manager_req_mc
+  */
+ static void frescan_manager_req_mc(frescan_bwres_request_data_t *req_data)
+ {
+         int ret;
+         ret = frescan_bwres_mode_change_local(req_data->net,
+                                               req_data->mode_change_type,
+                                               req_data->ss_to_cancel);
+         assert(ret == 0);
+ }
index 0000000000000000000000000000000000000000,998b1d9cfcc4f02e1604182ad6d5891b7f6f5b3a..998b1d9cfcc4f02e1604182ad6d5891b7f6f5b3a
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,95 +1,95 @@@
+ /*!
+  * @file frescan_bwres_threads.h
+  *
+  * @brief FRESCAN bandwidth reservation layer: negotiation threads
+  *
+  * This module contains the acceptor threads and the master thread for local
+  * negotiations, with functions to create them.
+  *
+  * @version 0.01
+  *
+  * @date 2-Apr-2008
+  *
+  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_BWRES_THREADS_H_
+ #define _FRESCAN_BWRES_THREADS_H_
+ #include "frescan_types.h"
+ /**
+  * frescan_manager_thread_create()
+  *
+  * This call creates the manager thread at each node which will be waiting
+  * in a request queue for LOCAL or EXTERNAL requests.
+  */
+ extern int frescan_manager_thread_create(frescan_network_t net);
+ /**
+  * frescan_acceptor_thread_create()
+  *
+  * This call creates the acceptor thread which will be waiting negotiation
+  * messages from the network and converting them into EXTERNAL requests for
+  * the manager thread.
+  */
+ extern int frescan_acceptor_thread_create(frescan_network_t net);
+ #endif // _FRESCAN_BWRES_THREADS_H_
index 0000000000000000000000000000000000000000,ef7723738a7f2fb68bee5632d4122701d36f964a..ef7723738a7f2fb68bee5632d4122701d36f964a
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,125 +1,125 @@@
+ /*!
+  * @file frecan_config.h
+  *
+  * @brief constants to configure the frescan protocol
+  *
+  * @version 0.01
+  *
+  * @date 12-Mar-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This module contains some constants and macros to configure the
+  * frescan protocol. For example, the size of the packets pool, etc...
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _MARTE_FRESCAN_CONFIG_H_
+ #define _MARTE_FRESCAN_CONFIG_H_
+ #include "fosa_threads_and_signals.h" // FOSA_SIGNAL_MIN
+ #include <sys/kernel.h>  // kernel_enter_critic_section
+ #define FRESCAN_MX_PACKETS        200
+ #define FRESCAN_MX_NETWORKS       2
+ #define FRESCAN_BROADCAST_ADDR    0xF
+ #define FRESCAN_MX_IDS            255
+ #define FRESCAN_MX_PRIOS          32
+ #define FRESCAN_BACKGROUND_PRIO   0
+ #define FRESCAN_REPL_SIGNAL_NUM   FOSA_SIGNAL_MIN + 10 // real-time signal
+ #define FRESCAN_REPL_THREAD_PRIO  60
+ #define FRESCAN_MX_NODES          4
+ #define FRESCAN_MX_REPL_OPS       FRESCAN_MX_IDS*10
+ // Configuration values for FRESCAN_BWRES
+ #define FRESCAN_BWRES_MX_REPLY_OBJECTS  40
+ #define FRESCAN_BWRES_MX_REQUESTS       40
+ #define FRESCAN_BWRES_MASTER_NODE       0
+ #define FRESCAN_BWRES_ROBJS_MX_CEILING  90
+ #define FRESCAN_BWRES_REQ_MX_CEILING    90
+ #define FRESCAN_BWRES_MX_PRIO           60
+ #define FRESCAN_BWRES_NEG_THREAD_PRIO   50
+ #define FRESCAN_BWRES_ACCEPTOR_PRIO     FRESCAN_BWRES_NEG_THREAD_PRIO - 1
+ #define FRESCAN_BWRES_NEG_MSG_PRIO      4
+ #define FRESCAN_BWRES_NEG_MSG_BUDGET    5 // packets
+ #define FRESCAN_BWRES_NEG_MSG_PERIOD    1000000 // us
+ #define FRESCAN_BWRES_NEG_MSG_CHAN      0
+ #define FRESCAN_BWRES_MX_CONTRACTS      (FRESCAN_MX_NODES*FRESCAN_MX_IDS)
+ #define FRESCAN_BWRES_MAX_GROUP_OPS     5
+ #define FRESCAN_BWRES_SS_MIN_PRIO       1
+ #define FRESCAN_BWRES_SS_MAX_PRIO       FRESCAN_MX_PRIOS
+ // Configuration values for FRESCAN_BWRES_FNA
+ #define FRESCAN_BWRES_FNA_NET_BASE      0
+ #define FRESCAN_BWRES_FNA_LOCAL_NODE    3
+ #define FRESCAN_BWRES_TX_FP_MX_PRIO     10
+ #define FRESCAN_BWRES_RX_NUM_CHANNELS   10
+ #define FRESCAN_BWRES_RX_CHAN_MX_PRIO   NULL
+ // FRESCAN_FRAME_TX_TIME_US: measured transmission time of an 8byte frame
+ #define FRESCAN_FRAME_TX_TIME_US        200
+ #define FRESCAN_MLOCK_T            unsigned
+ #define FRESCAN_CREATE_LOCK(l)
+ #define FRESCAN_DESTROY_LOCK(l)
+ #define FRESCAN_ACQUIRE_LOCK(l)    kernel_enter_critic_section(l)
+ #define FRESCAN_RELEASE_LOCK(l)    kernel_leave_critic_section(*(l))
+ #endif // _MARTE_FRESCAN_CONFIG_H_
index 0000000000000000000000000000000000000000,f87ef86c88c2c8b31f4ea313c5aae925c7fc8f95..f87ef86c88c2c8b31f4ea313c5aae925c7fc8f95
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,104 +1,104 @@@
+ /*!
+  * @file frescan_data.c
+  *
+  * @brief global data used from different modules in frescan
+  *
+  * @version 0.01
+  *
+  * @date 12-Mar-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * In frescan_data module we store global data to FRESCAN to make the protocol
+  * easier and efficient to implement.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include "frescan_data.h"
+ frescan_network_data_t frescan_data[FRESCAN_MX_NETWORKS];
+ int frescan_data_init(int fd, frescan_init_params_t *params)
+ {
+         frescan_ss_t id;
+         frescan_prio_t prio;
+         frescan_node_t src;
+         frescan_data[params->net].fd = fd;
+         frescan_data[params->net].local_node = params->node;
+         frescan_data[params->net].last_packet = NULL;
+         frescan_data[params->net].last_packet_prio = 0;
+         FRESCAN_CREATE_LOCK(&frescan_data[params->net].lock);
+         for(id=0; id<FRESCAN_MX_IDS; id++) {
+                 for(src=0; src<FRESCAN_MX_NODES; src++) {
+                       frescan_data[params->net].id_queues[src][id] = NULL;
+                 }
+         }
+         for(prio=0; prio<FRESCAN_MX_PRIOS; prio++) {
+                 for(src=0; src<FRESCAN_MX_NODES; src++) {
+                       frescan_data[params->net].id_fp_queues[src][prio] = NULL;
+                 }
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,394fcbaaf64c9c7a2a11267089d6da171372b21d..394fcbaaf64c9c7a2a11267089d6da171372b21d
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,84 +1,84 @@@
+ /*!
+  * @file frescan_data.h
+  *
+  * @brief global data used from different modules in frescan
+  *
+  * @version 0.01
+  *
+  * @date 12-Mar-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * In order to simplify we have a single module, frescan_data, to store the
+  * main internal structures and global data of the FRESCAN protocol.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _MARTE_FRESCAN_DATA_H_
+ #define _MARTE_FRESCAN_DATA_H_
+ #include "frescan_types.h"   // frescan_node_t, _prio_t, _budget_t
+ #include "frescan_config.h"  // FRESCAN_MLOCK_T, FRESCAN_MX_XXX
+ extern frescan_network_data_t frescan_data[FRESCAN_MX_NETWORKS];
+ extern int frescan_data_init(int fd, frescan_init_params_t *params);
+ #endif // _MARTE_FRESCAN_DATA_H_
index 0000000000000000000000000000000000000000,65e22b53c215801268e4c7e11d05f785e7c2df84..65e22b53c215801268e4c7e11d05f785e7c2df84
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,126 +1,126 @@@
+ /*!
+  * @file frecan_debug.h
+  *
+  * @brief debuggin macros and flags for the frescan protocol
+  *
+  * @version 0.01
+  *
+  * @date 21-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This module contains macros and flags to enable debugging in the
+  * frescan protocol for MaRTE OS
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _MARTE_FRESCAN_DEBUG_H_
+ #define _MARTE_FRESCAN_DEBUG_H_
+ #include <stdio.h>
+ #include <stdbool.h>
+ #include <stdlib.h>
+ /**
+  * DEBUG macros
+  **/
+ #define DEBUG(enable,x,args...) \
+         if(enable) printc("DEBUG (%s): " x, __func__ , ##args)
+ #define FRESCAN_ERROR(x,args...) \
+         printe("ERROR (%s:%u): " x, __func__ , __LINE__ , ##args)
+ #define FRESCAN_WARNING(x,args...) \
+         printe("WARNING (%s): " x, __func__ , ##args)
+ /**
+  * DEBUGGING FLAGS to enable/disable debugging messages
+  **/
+ #define FRESCAN_SERVERS_ENABLE_DEBUG    false
+ #define FRESCAN_PACKETPOOL_ENABLE_DEBUG false
+ #define FRESCAN_FRAG_ENABLE_DEBUG       false
+ #define FRESCAN_INIT_ENABLE_DEBUG       false
+ #define FRESCAN_SEND_ENABLE_DEBUG       false
+ #define FRESCAN_RECV_ENABLE_DEBUG       false
+ #define FRESCAN_RX_HOOK_ENABLE_DEBUG    false
+ #define FRESCAN_SENT_HOOK_ENABLE_DEBUG  false
+ #define FRESCAN_QUEUES_ENABLE_DEBUG     false
+ #define FRESCAN_HW_BUFFER_ENABLE_DEBUG  false
+ #define FRESCAN_REPLENSH_ENABLE_DEBUG   false
+ #define FRESCAN_BWRES_ENABLE_DEBUG            false
+ #define FRESCAN_BWRES_ROBJS_ENABLE_DEBUG      false
+ #define FRESCAN_BWRES_REQUESTS_ENABLE_DEBUG   false
+ #define FRESCAN_BWRES_MANAGER_ENABLE_DEBUG    false
+ #define FRESCAN_BWRES_ACCEPTOR_ENABLE_DEBUG   false
+ #define FRESCAN_BWRES_MC_ENABLE_DEBUG         false
+ #define FRESCAN_BWRES_FNA_ENABLE_DEBUG        false
+ #define FRESCAN_BWRES_MESSAGES_ENABLE_DEBUG   false
+ #define FRESCAN_BWRES_SA_ENABLE_DEBUG         false
+ /**
+  * MEASUREMENT FLAGS
+  */
+ #define FRESCAN_MEASURE_REPL_TH         false
+ #define FRESCAN_MEASURE_REPL_PROGRAM    false
+ #endif // _MARTE_FRESCAN_DEBUG_H_
index 0000000000000000000000000000000000000000,67bb5809072b4b9f7d96d8d2c4c668c1cd7b76fe..67bb5809072b4b9f7d96d8d2c4c668c1cd7b76fe
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,225 +1,225 @@@
+ /*!
+  * @file frescan_hw_buffer.c
+  *
+  * @brief functions to manage the hw transmission buffer
+  *
+  * @version 0.01
+  *
+  * @date 12-Mar-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the functions needed to manage the hw transmission buffer.
+  * This is needed to update the transmission buffer of the CAN chip with the
+  * message with highest priority. This could involve having to abort the
+  * frame that is currently in the buffer.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include "frescan_hw_buffer.h"
+ #include <string.h> // memcpy
+ #include <assert.h>
+ #include "frescan_data.h"    // frescan_data
+ #include "frescan_debug.h"   // DEBUG, FRESCAN_ERROR
+ #include "frescan_servers.h" // frescan_servers_get_highest_prio
+ #include "frescan_queues.h"  // frescan_pqueue_xxx, frescan_servers_dequeue
+ #include "frescan_id.h"      // frescan_id_set_field
+ /**
+  * frescan_hw_buffer_abort - abort the packet in the hw tx buffer
+  *
+  * This function aborts the packet that is currently in the hw transmission
+  * buffer of the chip. It is useful to prevent priority inversion when there
+  * is another packet with highest priority waiting in the frescan queues.
+  *
+  * NOTE: if the frame is already being transmitted it won't abort it. In both
+  * cases a IRQ will be raised and either 'frescan_hook_frame_sent' or
+  * 'frescan_hook_frame_aborted' will be called.
+  */
+ int frescan_hw_buffer_abort(frescan_network_t net)
+ {
+         int ret;
+         ret = ioctl(frescan_data[net].fd, CAN_IOCTL_ABORT_FRAME, NULL);
+         if (ret == -1) {
+                 FRESCAN_ERROR ("could not abort the frame\n");
+                 return -1;
+         }
+         return 0;
+ }
+ /**
+  * frescan_hw_buffer_update - update the hw tx buffer
+  *
+  * This function updates the hw tx buffer with the packet with highest
+  * priority (including fp packets and server packets).
+  *
+  * TODO: use copy of pointer
+  */
+ int frescan_hw_buffer_update(frescan_network_t net)
+ {
+         int ret;
+         bool is_frame_in_chip, is_fp_highest_prio;
+         uint32_t frag_flag;
+         frescan_packet_t *packet;
+         frescan_prio_queue_t *pqueue;
+         frescan_prio_t fprio, sprio, prio;
+         frescan_ss_t id;
+         ret = frescan_servers_get_highest_prio(net, &id, &sprio);
+         assert(ret == 0);
+         pqueue = frescan_data[net].queues.tx_fp_queue;
+         ret = frescan_pqueue_get_highest_prio(pqueue, &packet, &fprio);
+         assert(ret == 0);
+         if ((id == FRESCAN_MX_IDS) && (packet == NULL)) {
+                 DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG, "(ss:0 fp:0)\n");
+                 return 0;
+         }
+         if ((id != FRESCAN_MX_IDS) && (packet == NULL)) {
+                 DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG, "(ss:1 fp:0)\n");
+                 is_fp_highest_prio = false;
+         }
+         if ((id == FRESCAN_MX_IDS) && (packet != NULL)) {
+                 DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG, "(ss:0 fp:1)\n");
+                 is_fp_highest_prio = true;
+         }
+         if ((id != FRESCAN_MX_IDS) && (packet != NULL)) {
+                 DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG, "(ss:1 fp:1)\n");
+                 is_fp_highest_prio = (fprio > sprio);
+         }
+         prio = (is_fp_highest_prio) ? fprio : sprio;
+         is_frame_in_chip = (frescan_data[net].last_packet != NULL);
+         if (is_frame_in_chip) {
+                 if (prio > frescan_data[net].last_packet_prio) {
+                         // TODO: if same server, dont abort
+                         DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG, "abort frame\n");
+                         ret = frescan_hw_buffer_abort(net);
+                         assert(ret == 0);
+                         return 0;
+                 } else {
+                         DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG,
+                               "frame in chip with highest or equal prio\n");
+                         return 0;
+                 }
+         }
+         if (is_fp_highest_prio) {
+                 ret = frescan_pqueue_dequeue(pqueue, &packet, &prio, 0);
+                 assert(ret == 0);
+         } else {
+                 ret = frescan_servers_dequeue(net, id, &packet, &prio);
+                 assert(ret == 0);
+                 frescan_id_set_field(&packet->frame->id,
+                                       FRESCAN_FIELD_PRIO,
+                                       (uint32_t)prio);
+         }
+         if (packet->buffer_pending_bytes > 8) {
+                 packet->frame->dlc = 8;
+         } else {
+                 packet->frame->dlc = packet->buffer_pending_bytes;
+         }
+         memcpy(packet->frame->data,
+                packet->buffer_read_pointer,
+                packet->frame->dlc);
+         packet->buffer_pending_bytes -= packet->frame->dlc;
+         packet->buffer_read_pointer  += packet->frame->dlc;
+         frag_flag = (packet->buffer_pending_bytes > 0) ? 1 : 0;
+         frescan_id_set_field
+                         (&packet->frame->id, FRESCAN_FIELD_FRAG_FLAG, frag_flag);
+         frescan_data[net].last_packet = packet;
+         frescan_data[net].last_packet_prio = prio;
+         DEBUG(FRESCAN_HW_BUFFER_ENABLE_DEBUG,
+               "frame->id:0x%X pend_bytes:%u dlc:%u fflag:%u\n",
+               packet->frame->id,
+               packet->buffer_pending_bytes,
+               packet->frame->dlc,
+               frag_flag);
+         ret = write(frescan_data[net].fd,
+                     (void *)packet->frame,
+                     sizeof(struct can_frame_t));
+         if (ret != sizeof(struct can_frame_t)) {
+                 FRESCAN_ERROR ("could not send frame\n");
+                 return ret;
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,3824c18ee0d90f64dbd3c5fac5365327c0fe2545..3824c18ee0d90f64dbd3c5fac5365327c0fe2545
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,83 +1,83 @@@
+ /*!
+  * @file frescan_hw_buffer.h
+  *
+  * @brief functions to manage the hw transmission buffer
+  *
+  * @version 0.01
+  *
+  * @date 12-Mar-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the functions needed to manage the hw transmission buffer.
+  * This is needed to update the transmission buffer of the CAN chip with the
+  * message with highest priority. This could involve having to abort the
+  * frame that is currently in the buffer.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _MARTE_FRESCAN_HW_BUFFER_H_
+ #define _MARTE_FRESCAN_HW_BUFFER_H_
+ #include "frescan_types.h"
+ extern int frescan_hw_buffer_update(frescan_network_t net);
+ #endif // _MARTE_FRESCAN_HW_BUFFER_H_
index 0000000000000000000000000000000000000000,b583619f22e8c10b83a713ccd6938f4ef41b4e69..b583619f22e8c10b83a713ccd6938f4ef41b4e69
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,105 +1,105 @@@
+ /*!
+  * @file frescan_id.c
+  *
+  * @brief functions to manage the fields of the FRESCAN Identifier
+  *
+  * @version 0.01
+  *
+  * @date 27-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the functions needed to manage the fields of a
+  * FRESCAN identifier. That is, how the 29 CAN ID bits of each frame are
+  * allocated in the FRESCAN protocol. If this configuration was to
+  * be changed (for example, the bits per field or the position  of the
+  * fields inside the ID), then only these functions need to be modified
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include "frescan_id.h"
+ typedef struct {
+         uint32_t bit_offset; // offset of the field in the CAN id
+         uint32_t bit_mask;   // the number of bits of the field in a mask
+ } frescan_field_t;
+ static frescan_field_t the_fields[] = {
+         {.bit_offset = 21, .bit_mask = 0xFF},
+         {.bit_offset = 17, .bit_mask = 0x0F},
+         {.bit_offset = 13, .bit_mask = 0x0F},
+         {.bit_offset =  9, .bit_mask = 0x0F},
+         {.bit_offset =  1, .bit_mask = 0xFF},
+         {.bit_offset =  0, .bit_mask = 0x01},
+ };
+ void frescan_id_set_field(uint32_t *id, uint32_t field, uint32_t value)
+ {
+         frescan_field_t *f = &the_fields[field];
+         *id = *id & ~(f->bit_mask << f->bit_offset);
+         *id = *id | ((value & f->bit_mask) << f->bit_offset);
+ }
+ uint32_t frescan_id_get_field(uint32_t id, uint32_t field)
+ {
+         frescan_field_t *f = &the_fields[field];
+         return ((id >> f->bit_offset) & f->bit_mask);
+ }
index 0000000000000000000000000000000000000000,3ee7eefc13583861f5518d58f1b5a385778ec98a..3ee7eefc13583861f5518d58f1b5a385778ec98a
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,101 +1,101 @@@
+ /*!
+  * @file frescan_id.h
+  *
+  * @brief functions to manage the fields of the FRESCAN Identifier
+  *
+  * @version 0.01
+  *
+  * @date 27-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the functions needed to manage the fields of a
+  * FRESCAN identifier. That is, how the 29 CAN ID bits of each frame are
+  * allocated in the FRESCAN protocol. If this configuration was to
+  * be changed (for example, the bits per field or the position  of the
+  * fields inside the ID), then only these functions need to be modified
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _MARTE_FRESCAN_ID_H_
+ #define _MARTE_FRESCAN_ID_H_
+ #include <stdint.h>  // uint32_t
+ /**
+  *        8          4      4     4          8               1     bytes
+  * +----------------------------------------------------------------+
+  * |     prio     | dest | src | chan |     frag_id     | frag_flag |
+  * +----------------------------------------------------------------+
+  *
+  */
+ #define FRESCAN_FIELD_PRIO      0
+ #define FRESCAN_FIELD_DEST      1
+ #define FRESCAN_FIELD_SRC       2
+ #define FRESCAN_FIELD_CHAN      3
+ #define FRESCAN_FIELD_FRAG_ID   4
+ #define FRESCAN_FIELD_FRAG_FLAG 5
+ extern void frescan_id_set_field(uint32_t *id, uint32_t field, uint32_t value);
+ extern uint32_t frescan_id_get_field(uint32_t id, uint32_t field);
+ #endif // _MARTE_FRESCAN_ID_H_
index 0000000000000000000000000000000000000000,6734d3ff0a5332b3f5d4e66ced1cc4659a69df49..6734d3ff0a5332b3f5d4e66ced1cc4659a69df49
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,149 +1,149 @@@
+ /*!
+  * @file frescan_packets.h
+  *
+  * @brief FRESCAN packets definition and pool
+  *
+  * @version 0.01
+  *
+  * @date 27-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the FRESCAN packets definition and functions to
+  * allocate and free them from a global pool of packets statically
+  * preallocated.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include "frescan_packets.h"
+ #include "frescan_debug.h"
+ #include "frescan_config.h"
+ #include <misc/freelist.h>
+ /**
+  * the_packet_pool - pool of frescan packets
+  *
+  * Like in the CAN driver, in FRESCAN we have a statically preallocated pool
+  * of packets that we will manage through a freelist in O(1) time.
+  */
+ static frescan_packet_t the_packet_pool[FRESCAN_MX_PACKETS];
+ static freelist_t the_packet_pool_freelist;
+ #ifdef FRESCAN_PACKETPOOL_ENABLE_DEBUG
+         static int allocated_total = 0;
+ #endif
+ /**
+  * frescan_packets_init
+  *
+  * Initializes a pool of packets that will be managed internally
+  * TODO: initalization flag
+  */
+ int frescan_packets_init() {
+         DEBUG(FRESCAN_PACKETPOOL_ENABLE_DEBUG, "initialize freelist\n");
+         return freelist_init(&the_packet_pool_freelist, FRESCAN_MX_PACKETS);
+ }
+ /**
+  * frescan_packets_alloc
+  *
+  * Allocates a frame from the pool of packets. On error it returns NULL
+  */
+ frescan_packet_t *frescan_packets_alloc() {
+         int pos;
+         pos = freelist_alloc(&the_packet_pool_freelist);
+         if (pos == -1) {
+                 FRESCAN_ERROR("could not allocate packet\n");
+                 FRESCAN_ERROR("hint: configure FRESCAN_MX_PACKETS\n");
+                 return NULL;
+         }
+ #ifdef FRESCAN_PACKETPOOL_ENABLE_DEBUG
+         allocated_total++;
+ #endif
+         DEBUG(FRESCAN_PACKETPOOL_ENABLE_DEBUG,
+               "allocating packet, pos:%d, total:%d\n", pos, allocated_total);
+         the_packet_pool[pos].pool_pos = pos; // to know how to free it
+         return &the_packet_pool[pos];
+ }
+ /**
+  * frescan_packets_free
+  *
+  * Frees a frame and returns it to the pool of packets.
+  */
+ int frescan_packets_free(frescan_packet_t *packet)
+ {
+ #ifdef FRESCAN_PACKETPOOL_ENABLE_DEBUG
+         allocated_total--;
+ #endif
+         DEBUG(FRESCAN_PACKETPOOL_ENABLE_DEBUG,
+               "freeing packet, pos:%d, total:%d\n",
+               packet->pool_pos, allocated_total);
+         return freelist_free(&the_packet_pool_freelist, packet->pool_pos);
+ }
index 0000000000000000000000000000000000000000,171c6e2177efc94773722e248b61fbe2046d0b0a..171c6e2177efc94773722e248b61fbe2046d0b0a
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,84 +1,84 @@@
+ /*!
+  * @file frescan_packets.h
+  *
+  * @brief FRESCAN packets definition and pool
+  *
+  * @version 0.01
+  *
+  * @date 27-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the FRESCAN packets definition and functions to
+  * allocate and free them from a global pool of packets statically
+  * preallocated.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_PACKETS_H_
+ #define _FRESCAN_PACKETS_H_
+ #include "frescan_types.h"
+ extern int frescan_packets_init();
+ extern frescan_packet_t *frescan_packets_alloc();
+ extern int frescan_packets_free(frescan_packet_t *packet);
+ #endif // _FRESCAN_PACKETS_H_
index 0000000000000000000000000000000000000000,757fc6de6ae484eb474f7dbb2d105afd6c132934..757fc6de6ae484eb474f7dbb2d105afd6c132934
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,441 +1,441 @@@
+ /*!
+  * @file frescan_queues.c
+  *
+  * @brief FRESCAN queues to manage the packets by prio and servers
+  *
+  * @version 0.01
+  *
+  * @date 27-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the FRESCAN queues where frescan packets are stored and
+  * managed.
+  *
+  * TODO: disable interrupts for mutual exclusion!!!
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include <stdlib.h>
+ #include <time.h>
+ #include "frescan_queues.h"
+ #include "frescan_packets.h"
+ #include "frescan_debug.h"
+ #include "frescan_id.h"
+ #include "frescan_data.h"
+ /**
+  * frescan_pqueue_create() - creates a priority queue
+  */
+ static inline frescan_prio_queue_t *frescan_pqueue_create(uint32_t max_prio,
+                                                           frescan_network_t net)
+ {
+         int ret, prio;
+         frescan_prio_queue_t *pq; // priority queue
+         pq = (frescan_prio_queue_t *)malloc(sizeof(frescan_prio_queue_t));
+         if (pq == NULL) {
+                 FRESCAN_ERROR("could not allocate memory for prio queue\n");
+                 return NULL;
+         }
+         pq->max_prio = max_prio;
+         pq->net      = net;
+         ret = sem_init (&pq->sem, 0, 0);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not init the semaphore\n");
+                 free(pq);
+                 return NULL;
+         }
+         pq->fifo_queues = (frescan_packet_t *)
+                         malloc(max_prio * sizeof(frescan_packet_t));
+         for(prio=0; prio<max_prio; prio++) {
+                 INIT_LIST_HEAD(&(pq->fifo_queues[prio].fifo_list));
+         }
+         return pq;
+ }
+ /**
+  * frescan_queues_init() - initialize the queues
+  *
+  * 1.- create the transmission fixed priority queue
+  * 2.- create the rx channels and its associated priority queues
+  *
+  * TODO: when error free memory
+  */
+ int frescan_queues_init(frescan_queues_t *queues,
+                         frescan_init_params_t *params)
+ {
+         int i;
+         uint32_t max_prio;
+         // create transmission fixed priority queue
+         queues->tx_fp_queue = frescan_pqueue_create(params->tx_fp_max_prio,
+                                                     params->net);
+         if (queues->tx_fp_queue == NULL)  {
+                 FRESCAN_ERROR("could not allocate memory for tx fp queue\n");
+                 return -1;
+         }
+         // create receiving channels
+         queues->rx_channel_queues = (frescan_prio_queue_t **)
+                 malloc(params->rx_num_of_channels *
+                        sizeof(frescan_prio_queue_t *));
+         if (queues->rx_channel_queues == NULL) {
+                 FRESCAN_ERROR
+                         ("could not allocate memory for receiving channels\n");
+                 return -1;
+         }
+         queues->num_rx_channels = params->rx_num_of_channels;
+         // create a priority queue for each channel
+         for(i=0; i<params->rx_num_of_channels; i++) {
+                 if (params->rx_channel_max_prio == NULL) {
+                         max_prio = params->tx_fp_max_prio;
+                 } else {
+                         max_prio = params->rx_channel_max_prio[i];
+                 }
+                 queues->rx_channel_queues[i] = frescan_pqueue_create
+                                                        (max_prio, params->net);
+                 if (queues->rx_channel_queues[i] == NULL)  {
+                         FRESCAN_ERROR
+                                ("could not allocate memory for rx pq %d\n", i);
+                         return -1;
+                 }
+         }
+         return 0;
+ }
+ /**
+  * frescan_pqueue_enqueue() - enqueue a packet
+  *
+  * check the packet flags and enqueue the packet in the appropiate queue
+  */
+ int frescan_pqueue_enqueue(frescan_prio_queue_t *pqueue,
+                            frescan_packet_t *packet,
+                            frescan_prio_t prio)
+ {
+         int ret;
+         if (prio >= pqueue->max_prio) {
+                 FRESCAN_ERROR("priority of the packet is too high\n");
+                 return -1;
+         }
+         DEBUG(FRESCAN_QUEUES_ENABLE_DEBUG,
+               "enqueue packet with prio %u, pending %u\n",
+               prio, packet->buffer_pending_bytes);
+         list_add_tail(&(packet->fifo_list),
+                       &(pqueue->fifo_queues[prio].fifo_list));
+         ret = sem_post(&pqueue->sem);
+         if (ret != 0) return ret;
+         return 0;
+ }
+ /**
+  * frescan_pqueue_requeue() - requeue a packet
+  */
+ int frescan_pqueue_requeue(frescan_prio_queue_t *pqueue,
+                            frescan_packet_t *packet,
+                            frescan_prio_t prio)
+ {
+         int ret;
+         if (prio >= pqueue->max_prio) {
+                 FRESCAN_ERROR("priority of the packet is too high\n");
+                 return -1;
+         }
+         list_add(&packet->fifo_list, &(pqueue->fifo_queues[prio].fifo_list));
+         ret = sem_post(&pqueue->sem);
+         if (ret != 0) return ret;
+         return 0;
+ }
+ /**
+  * frescan_pqueue_dequeue() - dequeue the packet with highest priority
+  */
+ int frescan_pqueue_dequeue(frescan_prio_queue_t *pqueue,
+                            frescan_packet_t **packet,
+                            frescan_prio_t *packet_prio,
+                            bool blocking)
+ {
+         int prio;
+         int ret;
+         frescan_packet_t *tmp = NULL;
+         struct list_head *pos;
+         *packet = NULL;
+         if (blocking) {
+                 DEBUG(FRESCAN_QUEUES_ENABLE_DEBUG, "calling sem_wait\n");
+                 sem_wait(&pqueue->sem);
+         } else {
+                 ret = sem_trywait (&pqueue->sem);
+                 if (ret != 0) {
+                         DEBUG(FRESCAN_QUEUES_ENABLE_DEBUG,
+                               "sem_trywait was locked (no packets)\n");
+                         return 0;
+                 }
+         }
+         DEBUG(FRESCAN_QUEUES_ENABLE_DEBUG,
+               "check priority fifo queues (max_prio=%u)\n", pqueue->max_prio);
+         // NOTE: we only acquire the lock if we block because non-blocking
+         // calls are made from a context with no interrupts (when updating
+         // the buffer at 'frescan_hw_buffer_update' which is always called
+         // with interrupts disabled)
+         if (blocking) FRESCAN_ACQUIRE_LOCK(&frescan_data[pqueue->net].lock);
+         for(prio=pqueue->max_prio-1; prio >= 0; prio--) {
+                 if (!list_empty(&pqueue->fifo_queues[prio].fifo_list)) {
+                         list_for_each(pos,
+                                       &pqueue->fifo_queues[prio].fifo_list) {
+                                 tmp = list_entry(pos, frescan_packet_t,
+                                                  fifo_list);
+                                 break;
+                         }
+                         *packet = tmp;
+                         list_del(&tmp->fifo_list);
+                         break;
+                 }
+         }
+         if (blocking) FRESCAN_RELEASE_LOCK(&frescan_data[pqueue->net].lock);
+         DEBUG(FRESCAN_QUEUES_ENABLE_DEBUG, "dequeued prio %u\n", prio);
+         *packet_prio = prio;
+         return 0;
+ }
+ /**
+  * frescan_pqueue_get_highest_prio() - returns the packet with highest prio
+  * but not extracting it from the queue.
+  */
+ int frescan_pqueue_get_highest_prio(frescan_prio_queue_t *pqueue,
+                                     frescan_packet_t **packet,
+                                     frescan_prio_t *packet_prio)
+ {
+         int prio;
+         frescan_packet_t *tmp = NULL;
+         struct list_head *pos;
+         *packet = NULL;
+         for(prio=pqueue->max_prio-1; prio >= 0; prio--) {
+                 if (!list_empty(&pqueue->fifo_queues[prio].fifo_list)) {
+                         list_for_each(pos,
+                                       &pqueue->fifo_queues[prio].fifo_list) {
+                                 tmp = list_entry(pos, frescan_packet_t,
+                                                  fifo_list);
+                                 break;
+                         }
+                         *packet = tmp;
+                         break;
+                 }
+         }
+         DEBUG(FRESCAN_QUEUES_ENABLE_DEBUG, "highest prio %u\n", prio);
+         *packet_prio = prio;
+         return 0;
+ }
+ /**
+  * frescan_servers_enqueue() - enqueue a packet through a server
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @packet: the packet being enqueued
+  *
+  */
+ int frescan_servers_enqueue(frescan_network_t net,
+                             frescan_ss_t id,
+                             frescan_packet_t *packet)
+ {
+         frescan_ss_data_t *server = &frescan_data[net].ss_data[id];
+         clock_gettime (CLOCK_MONOTONIC, &packet->timestamp);
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG, "id:%u timestamp:(%d, %d)\n",
+               id, packet->timestamp.tv_sec, packet->timestamp.tv_nsec);
+         // add the packet to the server fifo list
+         list_add_tail(&packet->fifo_list, &server->packet_list.fifo_list);
+         // if the server was inactive (no packets) put it in the active list
+         if (server->pending_packets == 0) {
+                 DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+                       "ss becomes active act_time=timestamp\n");
+                 list_add_tail(&server->servers_list,
+                                &frescan_data[net].ss_active_head.servers_list);
+                 server->act_time = packet->timestamp;
+         }
+         server->pending_packets++;
+         return 0;
+ }
+ /**
+  * frescan_servers_requeue() - requeue a packet through a server
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @packet: the packet being requeued
+  *
+  */
+ int frescan_servers_requeue(frescan_network_t net,
+                             frescan_ss_t id,
+                             frescan_packet_t *packet)
+ {
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+               "requeue packet for id:%u\n", id);
+         // add the packet to the server fifo list
+         list_add(&packet->fifo_list,
+                   &frescan_data[net].ss_data[id].packet_list.fifo_list);
+         // if the server was inactive (no packets to send) put it active
+         // (in the active list)
+         if (frescan_data[net].ss_data[id].pending_packets == 0) {
+                 DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+                       "server was inactive, put in the active list\n");
+                 list_add(&frescan_data[net].ss_data[id].servers_list,
+                           &frescan_data[net].ss_active_head.servers_list);
+         }
+         frescan_data[net].ss_data[id].pending_packets++;
+         return 0;
+ }
+ /**
+  * frescan_servers_dequeue() - dequeue a packet from a server
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @packet: the packet dequeued
+  * @packet_prio: the priority current of the server
+  *
+  */
+ int frescan_servers_dequeue(frescan_network_t net,
+                             frescan_ss_t id,
+                             frescan_packet_t **packet,
+                             frescan_prio_t *packet_prio)
+ {
+         struct list_head *pos;
+         frescan_ss_data_t *server;
+         server = &frescan_data[net].ss_data[id];
+         if (list_empty(&server->packet_list.fifo_list)) {
+                 FRESCAN_ERROR("no packet in server %d fifo list\n", id);
+                 return -1;
+         }
+         list_for_each(pos, &server->packet_list.fifo_list) {
+                 *packet = list_entry(pos, frescan_packet_t, fifo_list);
+                 break;
+         }
+         list_del(&((*packet)->fifo_list));
+         *packet_prio = server->current_priority;
+         server->pending_packets--;
+         if (server->pending_packets == 0) {
+                 DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+                       "no more packets, delete from active list\n");
+                 list_del(&server->servers_list);
+         }
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+               "dequeued packet server:%u cur_prio:%u pending:%u\n",
+               id, *packet_prio, server->pending_packets);
+         return 0;
+ }
index 0000000000000000000000000000000000000000,901e764045260415644176bb6065052a2190064e..901e764045260415644176bb6065052a2190064e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,204 +1,204 @@@
+ /*!
+  * @file frescan_queues.h
+  *
+  * @brief FRESCAN queues to manage the packets by prio and servers
+  *
+  * @version 0.01
+  *
+  * @date 27-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the FRESCAN queues where frescan packets are stored and
+  * managed.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _MARTE_FRESCAN_QUEUES_H_
+ #define _MARTE_FRESCAN_QUEUES_H_
+ #include "frescan_types.h"
+ /**
+  * frescan_queues_init() - initialize the queues
+  *
+  * This function initializes the queue structures for an instance of frescan
+  * protocol. We provide different sizes and constants so, at initialization
+  * time, the structures are allocated from the heap. Note, that this approach
+  * is not conflicting with real-time systems where typically static allocation
+  * is used because we only do it at the initialization and also because we
+  * are using a real-time memory allocator. The advantage is that we have the
+  * flexibility of using different values for different instances of the
+  * protocol and that we can also supply the protocol compiled as a library.
+  *
+  * @queues: the queues structures
+  * @frescan_init_params_t: some init parameters for the queues
+  *
+  * TODO: add maximum number of packets per queue?? so far they are taken from
+  *       the same pool.
+  * TODO: add policy for overwritting
+  */
+ int frescan_queues_init(frescan_queues_t *queues,
+                         frescan_init_params_t *params);
+ /**
+  * frescan_pqueue_enqueue() - enqueue a packet
+  *
+  * this function enqueues a frescan_packet into the a priority queue. For the
+  * case of same priority packets they are stored at the tail, following a FIFO
+  * enqueuing policy.
+  *
+  * @pqueue: the priority queue
+  * @packet: the packet that we want to store
+  *
+  */
+ int frescan_pqueue_enqueue(frescan_prio_queue_t *pqueue,
+                            frescan_packet_t *packet,
+                            frescan_prio_t prio);
+ /**
+  * frescan_pqueue_requeue() - requeue a packet
+  *
+  * this function requeues a previously extracted frescan_packet. It puts
+  * the packet at the head of the fifo queue. This is useful when you abort
+  * the transmission of the packet beacuse another one with highest priority
+  * has arrived, and you still want to preserve the order in which the packets
+  * where enqueued
+  *
+  * @pqueue: the priority queue
+  * @packet: the packet that we want to store
+  *
+  */
+ int frescan_pqueue_requeue(frescan_prio_queue_t *pqueue,
+                            frescan_packet_t *packet,
+                            frescan_prio_t prio);
+ /**
+  * frescan_pqueue_dequeue() - dequeue the packet with highest priority
+  *
+  * @pqueue: the priority queue
+  * @packet: the packet extracted
+  * @blocking: if there are no packets we can choose to block or not. In
+  * a non-blocking mode, if there are no packets 'packet' will be NULL
+  *
+  */
+ int frescan_pqueue_dequeue(frescan_prio_queue_t *pqueue,
+                            frescan_packet_t **packet,
+                            frescan_prio_t *packet_prio,
+                            bool blocking);
+ /**
+  * frescan_pqueue_get_highest_prio() - returns the packet with highest prio
+  * but not extracting it from the queue.
+  *
+  * @pqueue: the priority queue
+  * @packet: the packet with highest prio (not extracted from the pqueue)
+  *
+  */
+ int frescan_pqueue_get_highest_prio(frescan_prio_queue_t *pqueue,
+                                     frescan_packet_t **packet,
+                                     frescan_prio_t *packet_prio);
+ /**
+  * frescan_servers_enqueue() - enqueue a packet through a server
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @packet: the packet being enqueued
+  *
+  */
+ int frescan_servers_enqueue(frescan_network_t net,
+                             frescan_ss_t id,
+                             frescan_packet_t *packet);
+ /**
+  * frescan_servers_requeue() - requeue a packet through a server
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @packet: the packet being requeued
+  *
+  */
+ int frescan_servers_requeue(frescan_network_t net,
+                             frescan_ss_t id,
+                             frescan_packet_t *packet);
+ /**
+  * frescan_servers_dequeue() - dequeue a packet from a server
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @packet: the packet dequeued
+  *
+  */
+ int frescan_servers_dequeue(frescan_network_t net,
+                             frescan_ss_t id,
+                             frescan_packet_t **packet,
+                             frescan_prio_t *packet_prio);
+ #endif // _MARTE_FRESCAN_QUEUES_H_
index 0000000000000000000000000000000000000000,a20811b23ac28e24ff2ee6ff98eafd410e77e53c..a20811b23ac28e24ff2ee6ff98eafd410e77e53c
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,486 +1,486 @@@
+ /*!
+  * @file frescan_servers.c
+  *
+  * @brief FRESCAN sporadic servers
+  *
+  * @version 0.01
+  *
+  * @date 27-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the FRESCAN sporadic servers that allow to isolate
+  * different streams of data by assigning them a budget and replenishment
+  * period.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include "frescan_servers.h"
+ #include "frescan_servers_replenishments.h" // frescan_replenishments_xxx
+ #include "frescan_debug.h"
+ #include "frescan_packets.h"
+ #include "frescan_data.h"
+ #include <signal.h>
+ #include <time.h>
+ #include <misc/linux_list.h>
+ #include "fosa_time_timespec.h" // smaller_timespec
+ /**
+  * frescan_servers_init() - initialize server structures
+  *
+  * @net: the network instance
+  */
+ int frescan_servers_init(frescan_network_t net)
+ {
+         int ret, i;
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG, "initializing servers\n");
+         ret = freelist_init(&frescan_data[net].ss_id_freelist, FRESCAN_MX_IDS);
+         if (ret != 0) return ret;
+         for (i=0; i<FRESCAN_MX_NETWORKS; i++) {
+                 INIT_LIST_HEAD(&frescan_data[net].ss_active_head.servers_list);
+         }
+         ret = frescan_replenishments_init(net);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not initialize the replenishments\n");
+                 return -1;
+         }
+         return 0;
+ }
+ /**
+  * frescan_servers_create() - create a sporadic server
+  *
+  * @net: the network instance
+  * @params: the parameters for the server
+  * @id: the identificator for the server as a return value
+  *
+  */
+ int frescan_servers_create(frescan_network_t net,
+                            const frescan_server_params_t *params,
+                            frescan_ss_t *id)
+ {
+         int i, ret, pos;
+         struct sigevent evp;
+         frescan_ss_data_t *server;
+         frescan_repl_op_t *repl;
+         FRESCAN_ACQUIRE_LOCK(&frescan_data[net].lock);
+         pos = freelist_alloc(&frescan_data[net].ss_id_freelist);
+         FRESCAN_RELEASE_LOCK(&frescan_data[net].lock);
+         if (pos == -1) {
+                 FRESCAN_ERROR("could not allocate servers\n");
+                 return -1;
+         }
+         *id = (frescan_ss_t)pos;
+         server = &frescan_data[net].ss_data[*id];
+         server->net = net;
+         server->id  = *id;
+         server->committed_params = *params;
+         server->perceived_params = server->committed_params;
+         server->current_priority = params->prio;
+         server->pending_packets  = 0;
+         // the first act_time is set to the server creation time
+         clock_gettime (CLOCK_MONOTONIC, &server->act_time);
+         // init the list of packets associated to the server
+         INIT_LIST_HEAD(&server->packet_list.fifo_list);
+         // allocate the replenishment capacity queue
+         INIT_LIST_HEAD(&server->replenishments.repl_list);
+         for (i=0; i < params->budget; i++) {
+                 repl = frescan_repl_op_alloc();
+                 repl->when = server->act_time;
+                 repl->amount = 1;
+                 list_add_tail(&repl->repl_list,
+                               &server->replenishments.repl_list);
+         }
+         // the repl timer sends a signal when it expires with the server id
+         evp.sigev_notify = SIGEV_SIGNAL;
+         evp.sigev_signo  = FRESCAN_REPL_SIGNAL_NUM;
+         evp.sigev_value.sival_int  = (int)*id;
+         ret = timer_create (CLOCK_MONOTONIC, &evp, &server->repl_timer);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not create timer\n");
+                 return ret;
+         }
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+               "server created, id:%u budget:%u prio:%u\n",
+               *id, server->committed_params.budget,
+               server->committed_params.prio);
+         return 0;
+ }
+ /**
+  * frescan_servers_set_perceived() - update a sporadic server perceived data
+  *
+  * @net: the network instance
+  * @params: the parameters for the server
+  * @id: the identificator for the server
+  *
+  */
+ int frescan_servers_set_perceived(frescan_network_t net,
+                                   const frescan_server_params_t *params,
+                                   frescan_ss_t id)
+ {
+         frescan_data[net].ss_data[id].perceived_params = *params;
+         return 0;
+ }
+ /**
+  * frescan_servers_commit_perceived() - commit sporadic server perceived data
+  *
+  * Add or remove repl operations according to the budget change
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  *
+  */
+ int frescan_servers_commit_perceived(frescan_network_t net,
+                                      frescan_ss_t id)
+ {
+         int i, ret;
+         frescan_ss_data_t *server;
+         int budget_variation;
+         frescan_repl_op_t *repl = NULL;
+         struct list_head *pos;
+         server = &frescan_data[net].ss_data[id];
+         budget_variation = server->perceived_params.budget -
+                            server->committed_params.budget;
+         if (budget_variation > 0) {
+                 // we have more budget: add repl ops to the tail
+                 for (i=0; i < budget_variation; i++) {
+                         repl = frescan_repl_op_alloc();
+                         repl->when = server->act_time; // TODO: check when!
+                         repl->amount = 1;
+                         list_add_tail(&repl->repl_list,
+                                       &server->replenishments.repl_list);
+                 }
+         } else {
+                 // we have less budget: remove repl ops from the tail
+                 for (i=0; i > budget_variation; i--) {
+                         list_for_each_prev(pos,
+                                            &server->replenishments.repl_list) {
+                                 repl = list_entry(pos,
+                                                   frescan_repl_op_t,
+                                                   repl_list);
+                                 break;
+                         }
+                         list_del(&repl->repl_list);
+                         ret = frescan_repl_op_free(repl);
+                         if (ret != 0) return ret;
+                 }
+         }
+         server->committed_params = server->perceived_params;
+         return 0;
+ }
+ /**
+  * frescan_servers_update() - update a sporadic server data
+  *
+  * @net: the network instance
+  * @params: the parameters for the server
+  * @id: the identificator for the server
+  *
+  */
+ int frescan_servers_update(frescan_network_t net,
+                            const frescan_server_params_t *params,
+                            frescan_ss_t id)
+ {
+         int ret;
+         ret = frescan_servers_set_perceived(net, params, id);
+         if (ret != 0) return ret;
+         ret = frescan_servers_commit_perceived(net, id);
+         if (ret != 0) return ret;
+         return 0;
+ }
+ /**
+  * frescan_servers_destroy() - delete a sporadic server
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  *
+  */
+ int frescan_servers_destroy(frescan_network_t net, frescan_ss_t id)
+ {
+         int ret;
+         frescan_repl_op_t *repl;
+         frescan_packet_t *packet;
+         frescan_ss_data_t *server;
+         server = &frescan_data[net].ss_data[id];
+         ret = timer_delete (server->repl_timer);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not delete timer\n");
+                 return ret;
+         }
+         // remove packets associated to the server
+         if (!list_empty(&server->packet_list.fifo_list)) {
+                 FRESCAN_WARNING("destroying a server with packets enqueued\n");
+                 list_for_each_entry(packet,
+                                     &server->packet_list.fifo_list,
+                                     fifo_list) {
+                         ret = frescan_packets_free(packet);
+                         if (ret != 0) return ret;
+                 }
+                 INIT_LIST_HEAD(&server->packet_list.fifo_list);
+         }
+         // remove the servers replenishment capacity queue
+         list_for_each_entry(repl,
+                             &server->replenishments.repl_list,
+                             repl_list) {
+                 ret = frescan_repl_op_free(repl);
+                 if (ret != 0) return ret;
+         }
+         INIT_LIST_HEAD(&server->replenishments.repl_list);
+         FRESCAN_ACQUIRE_LOCK(&frescan_data[net].lock);
+         list_del(&server->servers_list);
+         ret = freelist_free(&frescan_data[net].ss_id_freelist, id);
+         FRESCAN_RELEASE_LOCK(&frescan_data[net].lock);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not free server data from pool\n");
+                 return ret;
+         }
+         return 0;
+ }
+ /**
+  * frescan_servers_get_data() - get a sporadic server data
+  *
+  * @net: the network instance
+  * @params: the parameters of the server
+  * @id: the identificator for the server
+  *
+  */
+ int frescan_servers_get_data(frescan_network_t net,
+                              frescan_server_params_t *params,
+                              frescan_ss_t id)
+ {
+         *params = frescan_data[net].ss_data[id].perceived_params;
+         return 0;
+ }
+ /**
+  * frescan_servers_get_current_budget() - get the current ss budget
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @current_budget: the current budget of the server
+  *
+  * Traverse the capacity queue until we find a replenishment operation
+  * that was programmed for a time later than now. The number of iterations
+  * is the budget in the capacity queue.
+  *
+  * That budget must be modified if the perceived budget has not been
+  * committed yet.
+  *
+  */
+ int frescan_servers_get_current_budget(frescan_network_t net,
+                                        frescan_ss_t id,
+                                        frescan_budget_t *current_budget)
+ {
+         struct timespec now;
+         frescan_repl_op_t *repl;
+         frescan_ss_data_t *server;
+         int count;
+         server = &frescan_data[net].ss_data[id];
+         // first we get the current real budget in the capacity queue
+         clock_gettime (CLOCK_MONOTONIC, &now);
+         count = 0;
+         list_for_each_entry(repl,
+                             &server->replenishments.repl_list,
+                             repl_list) {
+                 if (smaller_timespec(now, repl->when)) break;
+                 count = count + 1;
+         }
+         // if the perceived budget is less than the real budget
+         // we have to give a _perceived_ current budget
+         if (server->perceived_params.budget < server->committed_params.budget) {
+                 count = server->perceived_params.budget -
+                         (server->committed_params.budget - count);
+                 if (count < 0) count = 0;
+         }
+         *current_budget = (frescan_budget_t)count;
+         return 0;
+ }
+ /**
+  * frescan_servers_get_highest_prio() - get the server with highest priority
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @prio: the priority of that server
+  *
+  * For each active server, check the priority.
+  * If "id" is returned with a value of FRESCAN_MX_IDS,
+  * there are no active servers.
+  * NOTE: id=FRESCAN_MX_IDS is the identifier for fixed priority messages
+  * TODO: use a priority queue of active servers
+  *
+  */
+ int frescan_servers_get_highest_prio(frescan_network_t net,
+                                      frescan_ss_t *id,
+                                      frescan_prio_t *prio)
+ {
+         frescan_ss_data_t *server;
+         if (list_empty(&frescan_data[net].ss_active_head.servers_list)) {
+                 DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG, "server list is empty\n");
+                 *id = FRESCAN_MX_IDS;
+                 return 0;
+         }
+         *prio = 0;
+         list_for_each_entry(server,
+                             &frescan_data[net].ss_active_head.servers_list,
+                             servers_list) {
+                 if (server->current_priority >= *prio) {
+                         *id = server->id;
+                         *prio = server->current_priority;
+                 }
+         }
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+               "highest prio:%u id:%u\n", *prio, *id);
+         return 0;
+ }
+ /**
+  * frescan_servers_frame_sent() - hook to control the server budget and prio
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  *
+  * This function is called when a frame has been effectively sent through the
+  * CAN bus and that frame is associated to a certain server. The function
+  * decreases the capacity of the server and sets the priority to background
+  * in case the budget is exhausted.
+  *
+  * NOTE: the replenishment operation is programmed using the corresponding
+  * function at frescan_servers_replenishments module
+  */
+ int frescan_servers_frame_sent(frescan_network_t net,
+                                frescan_ss_t id,
+                                frescan_packet_t *packet)
+ {
+         int ret;
+         struct timespec *repl_time;
+         frescan_ss_data_t *server;
+         server = &frescan_data[net].ss_data[id];
+         if (server->current_priority != FRESCAN_BACKGROUND_PRIO) {
+                 if (smaller_timespec(packet->timestamp, server->act_time)) {
+                         repl_time = &server->act_time;
+                 } else {
+                         repl_time = &packet->timestamp;
+                 }
+                 ret = frescan_replenishment_program(net, id, repl_time);
+                 if (ret != 0) return -1;
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,6298a12dc0e97701d37d3b044cd765e04213954e..6298a12dc0e97701d37d3b044cd765e04213954e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,347 +1,347 @@@
+ /*!
+  * @file frescan_servers.c
+  *
+  * @brief FRESCAN sporadic servers
+  *
+  * @version 0.01
+  *
+  * @date 27-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the FRESCAN sporadic servers that allow to isolate
+  * different streams of data by assigning them a budget and replenishment
+  * period.
+  *
+  * @license
+  *
+  * -----------------------------------------------------------------------
+  *  Copyright (C) 2006 - 2008 FRESCOR consortium partners:
+  *
+  *    Universidad de Cantabria,              SPAIN
+  *    University of York,                    UK
+  *    Scuola Superiore Sant'Anna,            ITALY
+  *    Kaiserslautern University,             GERMANY
+  *    Univ. Politécnica  Valencia,           SPAIN
+  *    Czech Technical University in Prague,  CZECH REPUBLIC
+  *    ENEA                                   SWEDEN
+  *    Thales Communication S.A.              FRANCE
+  *    Visual Tools S.A.                      SPAIN
+  *    Rapita Systems Ltd                     UK
+  *    Evidence                               ITALY
+  *
+  *    See http://www.frescor.org for a link to partners' websites
+  *
+  *           FRESCOR project (FP6/2005/IST/5-034026) is funded
+  *        in part by the European Union Sixth Framework Programme
+  *        The European Union is not liable of any use that may be
+  *        made of this code.
+  *
+  *  This file is part of FRESCAN
+  *
+  *  FRESCAN is free software; you can  redistribute it and/or  modify
+  *  it under the terms of  the GNU General Public License as published by
+  *  the Free Software Foundation;  either  version 2, or (at  your option)
+  *  any later version.
+  *
+  *  FRESCAN  is distributed  in  the hope  that  it  will  be useful,  but
+  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
+  *  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
+  *  General Public License for more details.
+  *
+  *  You should have  received a  copy of  the  GNU  General Public License
+  *  distributed  with  FRESCAN;  see file COPYING.   If not,  write to the
+  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
+  *  02111-1307, USA.
+  *
+  * As a special exception, including FRESCAN header files in a file,
+  * instantiating FRESCAN generics or templates, or linking other files
+  * with FRESCAN objects to produce an executable application, does not
+  * by itself cause the resulting executable application to be covered
+  * by the GNU General Public License. This exception does not
+  * however invalidate any other reasons why the executable file might be
+  * covered by the GNU Public License.
+  * -----------------------------------------------------------------------
+  *
+  */
+ #include "frescan_servers.h"
+ #include "frescan_servers_replenishments.h" // frescan_replenishments_xxx
+ #include "frescan_debug.h"
+ #include "frescan_data.h"
+ #include <misc/linux_list.h>
+ #include <misc/timespec_operations.h>
+ #include <signal.h>
+ #include <time.h>
+ /**
+  * frescan_servers_init() - initialize server structures
+  *
+  * @net: the network instance
+  */
+ int frescan_servers_init(frescan_network_t net)
+ {
+         int ret, i;
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG, "initializing servers\n");
+         ret = freelist_init(&the_servers_pool_freelist[net], FRESCAN_MX_IDS);
+         if (ret != 0) return ret;
+         for (i=0; i<FRESCAN_MX_NETWORKS; i++) {
+                 INIT_LIST_HEAD(&the_active_servers[net].servers_list);
+         }
+         ret = frescan_replenishments_init(net);
+         if (ret != 0) {
+                 ERROR("could not initialize the replenishments\n");
+                 return -1;
+         }
+         return 0;
+ }
+ /**
+  * frescan_servers_create() - create a sporadic server
+  *
+  * @net: the network instance
+  * @params: the parameters for the server
+  * @id: the identificator for the server as a return value
+  *
+  */
+ int frescan_servers_create(frescan_network_t net,
+                            const frescan_server_params_t *params,
+                            frescan_ss_t *id)
+ {
+         int ret, pos;
+         struct sigevent evp;
+         FRESCAN_ACQUIRE_LOCK(&the_networks[net].lock);
+         pos = freelist_alloc(&the_servers_pool_freelist[net]);
+         FRESCAN_RELEASE_LOCK(&the_networks[net].lock);
+         if (pos == -1) {
+                 ERROR("could not allocate servers\n");
+                 return -1;
+         }
+         *id = (frescan_ss_t)pos;
+         the_servers_pool[net][*id].net = net;
+         the_servers_pool[net][*id].id  = *id;
+         the_servers_pool[net][*id].params = *params;
+         the_servers_pool[net][*id].current_budget = params->values.budget;
+         the_servers_pool[net][*id].current_priority = params->prio;
+         the_servers_pool[net][*id].pending_packets = 0;
+         // the first act_time is set to the server creation time
+         clock_gettime (CLOCK_MONOTONIC, &the_servers_pool[net][*id].act_time);
+         INIT_LIST_HEAD(&the_servers_pool[net][*id].replenishments.repl_list);
+         INIT_LIST_HEAD(&the_servers_pool[net][*id].packet_list.fifo_list);
+         // the repl timer sends a signal when it expires with the server id
+         evp.sigev_notify = SIGEV_SIGNAL;
+         evp.sigev_signo  = FRESCAN_REPL_SIGNAL_NUM;
+         evp.sigev_value.sival_int  = (int)*id;
+         ret = timer_create (CLOCK_MONOTONIC,
+                             &evp, &the_servers_pool[net][*id].repl_timer);
+         if (ret != 0) {
+                 ERROR("could not create timer\n");
+                 return ret;
+         }
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+               "server created, id:%u budget:%u prio:%u\n",
+               *id,
+               the_servers_pool[net][*id].params.values.budget,
+               the_servers_pool[net][*id].params.prio);
+         return 0;
+ }
+ /**
+  * frescan_servers_update() - update a sporadic server data
+  *
+  * @net: the network instance
+  * @params: the parameters for the server
+  * @id: the identificator for the server
+  *
+  */
+ int frescan_servers_update(frescan_network_t net,
+                            const frescan_server_params_t *params,
+                            frescan_ss_t id)
+ {
+         the_servers_pool[net][id].params = *params;
+         return 0;
+ }
+ /**
+  * frescan_servers_destroy() - delete a sporadic server
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  *
+  */
+ int frescan_servers_destroy(frescan_network_t net, frescan_ss_t id)
+ {
+         int ret;
+         // TODO: free the replenishment operations and the packets for the
+         // server.
+         ret = timer_delete (the_servers_pool[net][id].repl_timer);
+         if (ret != 0) {
+                 ERROR("could not delete timer\n");
+                 return ret;
+         }
+         FRESCAN_ACQUIRE_LOCK(&the_networks[net].lock);
+         list_del(&the_servers_pool[net][id].servers_list);
+         ret = freelist_free(&the_servers_pool_freelist[net], id);
+         FRESCAN_RELEASE_LOCK(&the_networks[net].lock);
+         if (ret != 0) {
+                 ERROR("could not free server data from pool\n");
+                 return ret;
+         }
+         return 0;
+ }
+ /**
+  * frescan_servers_get_data() - get a sporadic server data
+  *
+  * @net: the network instance
+  * @params: the parameters of the server
+  * @id: the identificator for the server
+  *
+  */
+ int frescan_servers_get_data(frescan_network_t net,
+                              frescan_server_params_t *params,
+                              frescan_ss_t id)
+ {
+         *params = the_servers_pool[net][id].params;
+         return 0;
+ }
+ /**
+  * frescan_servers_get_current_budget() - get the current sporadic server budget
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @current_budget: the current budget of the server
+  *
+  */
+ int frescan_servers_get_current_budget(frescan_network_t net,
+                                        frescan_ss_t id,
+                                        frescan_budget_t *current_budget)
+ {
+         *current_budget = the_servers_pool[net][id].current_budget;
+         return 0;
+ }
+ /**
+  * frescan_servers_get_highest_prio() - get the server with highest priority
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @prio: the priority of that server
+  *
+  * For each active server, check the priority.
+  * If "id" is returned with a value of FRESCAN_MX_IDS,
+  * there are no active servers.
+  * NOTE: id=FRESCAN_MX_IDS is the identifier for fixed priority messages
+  * TODO: use a priority queue of active servers
+  *
+  */
+ int frescan_servers_get_highest_prio(frescan_network_t net,
+                                      frescan_ss_t *id,
+                                      frescan_prio_t *prio)
+ {
+         frescan_server_data_t *server;
+         if (list_empty(&the_active_servers->servers_list)) {
+                 DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG, "server list is empty\n");
+                 *id = FRESCAN_MX_IDS;
+                 return 0;
+         }
+         *prio = 0;
+         list_for_each_entry(server, &the_active_servers[net].servers_list,
+                             servers_list) {
+                 if (server->current_priority >= *prio) {
+                         *id = server->id;
+                         *prio = server->current_priority;
+                 }
+         }
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+               "highest prio:%u id:%u\n", *prio, *id);
+         return 0;
+ }
+ /**
+  * frescan_servers_frame_sent() - hook to control the server budget and prio
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  *
+  * This function is called when a frame has been effectively sent through the
+  * CAN bus and that frame is associated to a certain server. The function
+  * decreases the capacity of the server and sets the priority to background
+  * in case the budget is exhausted.
+  *
+  * NOTE: the replenishment operation is programmed using the corresponding
+  * function at frescan_servers_replenishments module
+  */
+ int frescan_servers_frame_sent(frescan_network_t net,
+                                frescan_ss_t id,
+                                frescan_packet_t *packet)
+ {
+         int ret;
+         struct timespec *repl_time;
+         frescan_server_data_t *server;
+         server = &the_servers_pool[net][id];
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+               "before.. id:%u, current_budget:%u, current_priority:%u\n",
+               id, server->current_budget, server->current_priority);
+         if (server->current_budget > 0) {
+                 server->current_budget--;
+                 if (server->current_budget == 0) {
+                         server->current_priority = FRESCAN_BACKGROUND_PRIO;
+                 }
+                 if (smaller_timespec(&packet->timestamp, &server->act_time)) {
+                         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG, "using act_time\n");
+                         repl_time = &server->act_time;
+                 } else {
+                         repl_time = &packet->timestamp;
+                 }
+                 ret = frescan_replenishment_program(net, id, repl_time);
+                 if (ret != 0) return -1;
+         }
+         DEBUG(FRESCAN_SERVERS_ENABLE_DEBUG,
+               "after.. id:%u, current_budget:%u, current_priority:%u\n",
+               id, server->current_budget, server->current_priority);
+         return 0;
+ }
index 0000000000000000000000000000000000000000,dc84bc798fe0f4d7182a65096761dcc42cc0de2d..dc84bc798fe0f4d7182a65096761dcc42cc0de2d
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,215 +1,215 @@@
+ /*!
+  * @file frescan_servers.h
+  *
+  * @brief FRESCAN sporadic servers
+  *
+  * @version 0.01
+  *
+  * @date 27-Feb-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the FRESCAN sporadic servers that allow to isolate
+  * different streams of data by assigning them a budget and replenishment
+  * period.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _MARTE_FRESCAN_SERVERS_H_
+ #define _MARTE_FRESCAN_SERVERS_H_
+ #include "frescan_types.h"
+ /**
+  * frescan_servers_init() - initialize server structures
+  *
+  * @net: the network instance
+  */
+ extern int frescan_servers_init(frescan_network_t net);
+ /**
+  * frescan_servers_create() - create a sporadic server
+  *
+  * @net: the network instance
+  * @params: the parameters for the server
+  * @id: the identificator for the server as a return value
+  *
+  */
+ extern int frescan_servers_create(frescan_network_t net,
+                                   const frescan_server_params_t *params,
+                                   frescan_ss_t *id);
+ /**
+  * frescan_servers_set_perceived() - update a sporadic server perceived data
+  *
+  * @net: the network instance
+  * @params: the parameters for the server
+  * @id: the identificator for the server
+  *
+  */
+ extern int frescan_servers_set_perceived(frescan_network_t net,
+                                          const frescan_server_params_t *params,
+                                          frescan_ss_t id);
+ /**
+  * frescan_servers_commit_perceived() - commit sporadic server perceived data
+  *
+  * @net: the network instance
+  * @params: the parameters for the server
+  * @id: the identificator for the server
+  *
+  */
+ extern int frescan_servers_commit_perceived(frescan_network_t net,
+                                             frescan_ss_t id);
+ /**
+  * frescan_servers_update() - update a sporadic server data
+  *
+  * It is similar to call 'frescan_servers_set_perceived' and then
+  * 'frescan_servers_commit_perceived'
+  *
+  * @net: the network instance
+  * @params: the parameters for the server
+  * @id: the identificator for the server
+  *
+  */
+ extern int frescan_servers_update(frescan_network_t net,
+                                   const frescan_server_params_t *params,
+                                   frescan_ss_t id);
+ /**
+  * frescan_servers_destroy() - delete a sporadic server
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  *
+  */
+ extern int frescan_servers_destroy(frescan_network_t net, frescan_ss_t id);
+ /**
+  * frescan_servers_get_data() - get a sporadic server data
+  *
+  * @net: the network instance
+  * @params: the parameters of the server
+  * @id: the identificator for the server
+  *
+  */
+ extern  int frescan_servers_get_data(frescan_network_t net,
+                                      frescan_server_params_t *params,
+                                      frescan_ss_t id);
+ /**
+  * frescan_servers_get_current_budget() - get the current sporadic server budget
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @current_budget: the current budget of the server
+  *
+  */
+ extern int frescan_servers_get_current_budget(frescan_network_t net,
+                                               frescan_ss_t id,
+                                               frescan_budget_t *current_budget);
+ /**
+  * frescan_servers_get_highest_prio() - get the server with highest priority
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @prio: the priority of that server
+  *
+  * If "id" is returned with a value of FRESCAN_MX_IDS,
+  * there are no active servers.
+  * NOTE: id=FRESCAN_MX_IDS is the identifier for fixed priority messages
+  *
+  */
+ extern int frescan_servers_get_highest_prio(frescan_network_t net,
+                                             frescan_ss_t *id,
+                                             frescan_prio_t *prio);
+ /**
+  * frescan_servers_frame_sent() - hook to control the server budget and prio
+  *
+  * @net: the network instance
+  * @id: the identificator for the server
+  * @packet: the packet sent (with its timestamp)
+  *
+  * This function is called when a frame has been effectively sent through the
+  * CAN bus and that frame is associated to a certain server. The function
+  * decreases the capacity of the server and sets the priority to background
+  * in case the budget is exhausted.
+  *
+  * NOTE: the replenishment operation is programmed using the corresponding
+  * function at frescan_servers_replenishments module
+  */
+ extern int frescan_servers_frame_sent(frescan_network_t net,
+                                       frescan_ss_t id,
+                                       frescan_packet_t *packet);
+ #endif // _MARTE_FRESCAN_SERVERS_H_
index 0000000000000000000000000000000000000000,b07f6bad56c60fd0467dc45e2a6b06dfc272dedb..b07f6bad56c60fd0467dc45e2a6b06dfc272dedb
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,339 +1,339 @@@
+ /*!
+  * @file frescan_servers_replenishments.c
+  *
+  * @brief the replenishment data and thread for the servers
+  *
+  * @version 0.01
+  *
+  * @date 12-Mar-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This module contains the thread that waits for server's replenishment
+  * timer signals and perform the necessary replenishments.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #include <time.h>            // clock_gettime
+ #include <assert.h>          // assert
+ #include <misc/freelist.h>   // freelist_t
+ #include <misc/linux_list.h> // list_add_tail
+ #include "frescan_servers_replenishments.h"
+ #include "frescan_config.h"  // FRESCAN_MX_REPL_OPS
+ #include "frescan_debug.h"   // FRESCAN_ERROR
+ #include "frescan_data.h"    // frescan_repl_op_t
+ #include "fosa.h" // fosa_thread_attr_init, smaller_timespec, incr_timespec
+ #if (FRESCAN_MEASURE_REPL_TH || FRESCAN_MEASURE_REPL_PROGRAM)
+ #include <misc/time_measurement_posix.h>
+ #include <misc/logger.h>
+ static time_measure_id_t measure_id;
+ #endif
+ /**
+  * the_repl_op_pool - pool of replenishment operations
+  *
+  * We have a pool of replenishment operation structures and an associated
+  * freelist where we can get/put replenishment operations in O(1) time
+  *
+  * @the_repl_op_pool: array with the replenishment operations allocated
+  * @the_repl_op_pool_freelist: freelist for the_repl_op_pool
+  * @frescan_repl_op_init: initializes the freelist
+  * @frescan_repl_op_alloc: get a free replenishment operation structure
+  * @frescan_repl_op_free: free a replenishment operation structure
+  *
+  */
+ static frescan_repl_op_t the_repl_op_pool[FRESCAN_MX_REPL_OPS];
+ static freelist_t the_repl_op_pool_freelist;
+ static int frescan_repl_op_init()
+ {
+         return freelist_init(&the_repl_op_pool_freelist, FRESCAN_MX_REPL_OPS);
+ }
+ frescan_repl_op_t *frescan_repl_op_alloc()
+ {
+         int pos;
+         pos = freelist_alloc(&the_repl_op_pool_freelist);
+         if (pos == -1) {
+                 FRESCAN_ERROR("could not allocate repl op\n");
+                 return NULL;
+         }
+         the_repl_op_pool[pos].pool_pos = pos; // to know how to free it
+         return &the_repl_op_pool[pos];
+ }
+ int frescan_repl_op_free(frescan_repl_op_t *repl_op)
+ {
+         return freelist_free(&the_repl_op_pool_freelist, repl_op->pool_pos);
+ }
+ /**
+  * frescan_repl_thread - the thread that executes the replenishments
+  */
+ static void *frescan_repl_thread(void *arg)
+ {
+         int ret;
+         sigset_t set;
+         siginfo_t siginfo;
+         frescan_ss_t id;
+         frescan_network_t net;
+         frescan_ss_data_t *server;
+         struct itimerspec timerdata;
+         net = (frescan_network_t)(uint32_t)arg;
+         timerdata.it_interval.tv_sec  = 0;
+         timerdata.it_interval.tv_nsec = 0;
+         sigemptyset(&set);
+         sigaddset(&set, FRESCAN_REPL_SIGNAL_NUM);
+         while (1) {
+ #if FRESCAN_MEASURE_REPL_TH
+                 ret = time_measure_posix_begin(measure_id);
+                 assert(ret == 0);
+ #endif
+                 ret = sigwaitinfo(&set, &siginfo);
+                 assert(ret != -1);
+                 if (siginfo.si_signo != FRESCAN_REPL_SIGNAL_NUM) continue;
+                 DEBUG(FRESCAN_REPLENSH_ENABLE_DEBUG,
+                       "net:%u signal:%d code:%d value(server_id):%d\n",
+                       net,
+                       siginfo.si_signo,            // FRESCAN_REPL_SIGNAL_NUM
+                       siginfo.si_code,             // SI_TIMER
+                       siginfo.si_value.sival_int); // the server id
+                 id = siginfo.si_value.sival_int;
+                 server = &frescan_data[net].ss_data[id];
+                 DEBUG(FRESCAN_REPLENSH_ENABLE_DEBUG,
+                       "id:%u current_prio:%u\n", id, server->current_priority);
+                 server->current_priority = server->committed_params.prio;
+                 if (!list_empty(&server->packet_list.fifo_list)) {
+                         clock_gettime (CLOCK_MONOTONIC, &server->act_time);
+                 }
+ #if FRESCAN_MEASURE_REPL_TH
+                 ret = time_measure_posix_end(measure_id, "thread");
+                 assert(ret == 0);
+                 while (logger_manual_call() > 0);
+ #endif
+         }
+         return NULL;
+ }
+ /**
+  * frescan_replenishments_init - init the replenishment structures and thread
+  *
+  * @net: the network instance
+  *
+  * Initialize the repl_op pool, set the mask for the timer signals and create
+  * the thread that will await for those signals and replenish the appropiate
+  * sporadic server.
+  */
+ int frescan_replenishments_init(frescan_network_t net)
+ {
+         int ret;
+         fosa_signal_t signal_set[1];
+         fosa_thread_attr_t attr;
+         ret = frescan_repl_op_init();
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not init repl_op pool\n");
+                 return ret;
+         }
+         signal_set[0] = FRESCAN_REPL_SIGNAL_NUM;
+         ret = fosa_set_accepted_signals(signal_set, 1);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not set the repl signal\n");
+                 return ret;
+         }
+         // create the replenishment thread
+ #if (FRESCAN_MEASURE_REPL_TH || FRESCAN_MEASURE_REPL_PROGRAM)
+         ret = logger_init(LOG_ETHERNET);
+         assert(ret == 0);
+         ret = time_measure_posix_create("repl",
+                                         CLOCK_THREAD_CPUTIME_ID,
+                                         &measure_id);
+         assert(ret == 0);
+ #endif
+         ret = fosa_thread_attr_init(&attr);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not init thread attributes\n");
+                 return ret;
+         }
+         ret = fosa_thread_attr_set_prio(&attr, FRESCAN_REPL_THREAD_PRIO);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not set repl thread prio %d\n",
+                       FRESCAN_REPL_THREAD_PRIO);
+                 return ret;
+         }
+         ret = fosa_thread_create(&frescan_data[net].repl_thread_id,
+                                  &attr,
+                                  frescan_repl_thread,
+                                  (void *)(uint32_t)net);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not create the replenishment thread\n");
+                 return ret;
+         }
+         ret = fosa_thread_attr_destroy(&attr);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not destroy thread attributes\n");
+                 return ret;
+         }
+         return 0;
+ }
+ /**
+  * frescan_replenishment_program - set a replenishment operation
+  *
+  * @net: the network instance
+  * @ss: the server
+  */
+ int frescan_replenishment_program(frescan_network_t net,
+                                   frescan_ss_t id,
+                                   const struct timespec *timestamp)
+ {
+         int ret;
+         frescan_repl_op_t *repl = NULL;
+         struct itimerspec timerdata;
+         frescan_ss_data_t *server;
+         struct list_head *pos;
+         struct timespec now;
+ #if FRESCAN_MEASURE_REPL_PROGRAM
+         ret = time_measure_posix_begin(measure_id);
+         assert(ret == 0);
+ #endif
+         server = &frescan_data[net].ss_data[id];
+         // extract the head
+         list_for_each(pos, &server->replenishments.repl_list) {
+                 repl = list_entry(pos, frescan_repl_op_t, repl_list);
+                 break;
+         }
+         list_del(&repl->repl_list);
+         // move to tail with new repl value
+         repl->when = *timestamp;
+         incr_timespec(repl->when, server->committed_params.period);
+         repl->amount = 1;
+         list_add_tail(&repl->repl_list,
+                        &server->replenishments.repl_list);
+         // check the new head
+         list_for_each(pos, &server->replenishments.repl_list) {
+                 repl = list_entry(pos, frescan_repl_op_t, repl_list);
+                 break;
+         }
+         clock_gettime (CLOCK_MONOTONIC, &now);
+         if (smaller_timespec(now, repl->when)) {
+                 server->current_priority = FRESCAN_BACKGROUND_PRIO;
+                 timerdata.it_interval.tv_sec  = 0;
+                 timerdata.it_interval.tv_nsec = 0;
+                 timerdata.it_value = repl->when;
+                 DEBUG(FRESCAN_REPLENSH_ENABLE_DEBUG,
+                       "set timer to %d sec, %d nsec\n",
+                       repl->when.tv_sec, repl->when.tv_nsec);
+                 ret = timer_settime(server->repl_timer,
+                                     TIMER_ABSTIME, &timerdata, NULL);
+                 if (ret != 0) {
+                         FRESCAN_ERROR("could not set the replenishment timer\n");
+                         return ret;
+                 }
+         }
+ #if FRESCAN_MEASURE_REPL_PROGRAM
+                 ret = time_measure_posix_end(measure_id, "program");
+                 assert(ret == 0);
+                 while (logger_manual_call() > 0);
+ #endif
+         return 0;
+ }
index 0000000000000000000000000000000000000000,7923c357586069d0a7eabe00d4946a21b65d89f2..7923c357586069d0a7eabe00d4946a21b65d89f2
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,379 +1,379 @@@
+ /*!
+  * @file frescan_servers_replenishments.c
+  *
+  * @brief the replenishment data and thread for the servers
+  *
+  * @version 0.01
+  *
+  * @date 12-Mar-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This module contains the thread that waits for server's replenishment
+  * timer signals and perform the necessary replenishments.
+  *
+  * @license
+  *
+  * -----------------------------------------------------------------------
+  *  Copyright (C) 2006 - 2008 FRESCOR consortium partners:
+  *
+  *    Universidad de Cantabria,              SPAIN
+  *    University of York,                    UK
+  *    Scuola Superiore Sant'Anna,            ITALY
+  *    Kaiserslautern University,             GERMANY
+  *    Univ. Politécnica  Valencia,           SPAIN
+  *    Czech Technical University in Prague,  CZECH REPUBLIC
+  *    ENEA                                   SWEDEN
+  *    Thales Communication S.A.              FRANCE
+  *    Visual Tools S.A.                      SPAIN
+  *    Rapita Systems Ltd                     UK
+  *    Evidence                               ITALY
+  *
+  *    See http://www.frescor.org for a link to partners' websites
+  *
+  *           FRESCOR project (FP6/2005/IST/5-034026) is funded
+  *        in part by the European Union Sixth Framework Programme
+  *        The European Union is not liable of any use that may be
+  *        made of this code.
+  *
+  *  This file is part of FRESCAN
+  *
+  *  FRESCAN is free software; you can  redistribute it and/or  modify
+  *  it under the terms of  the GNU General Public License as published by
+  *  the Free Software Foundation;  either  version 2, or (at  your option)
+  *  any later version.
+  *
+  *  FRESCAN  is distributed  in  the hope  that  it  will  be useful,  but
+  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
+  *  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
+  *  General Public License for more details.
+  *
+  *  You should have  received a  copy of  the  GNU  General Public License
+  *  distributed  with  FRESCAN;  see file COPYING.   If not,  write to the
+  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
+  *  02111-1307, USA.
+  *
+  * As a special exception, including FRESCAN header files in a file,
+  * instantiating FRESCAN generics or templates, or linking other files
+  * with FRESCAN objects to produce an executable application, does not
+  * by itself cause the resulting executable application to be covered
+  * by the GNU General Public License. This exception does not
+  * however invalidate any other reasons why the executable file might be
+  * covered by the GNU Public License.
+  * -----------------------------------------------------------------------
+  *
+  */
+ #include <time.h>            // clock_gettime
+ #include <assert.h>          // assert
+ #include <misc/freelist.h>   // freelist_t
+ #include <misc/linux_list.h> // list_add_tail
+ #include <misc/timespec_operations.h>
+ #include "frescan_servers_replenishments.h"
+ #include "frescan_config.h"  // FRESCAN_MX_REPL_OPS
+ #include "frescan_debug.h"   // ERROR
+ #include "frescan_data.h"    // frescan_repl_op_t
+ #include "fosa_threads_and_signals.h" // fosa_thread_attr_init...
+ #if (FRESCAN_MEASURE_REPL_TH || FRESCAN_MEASURE_REPL_PROGRAM)
+ #include <misc/time_measurement_posix.h>
+ #include <misc/logger.h>
+ static time_measure_id_t measure_id;
+ #endif
+ /**
+  * the_repl_op_pool - pool of replenishment operations
+  *
+  * We have a pool of replenishment operation structures and an associated
+  * freelist where we can get/put replenishment operations in O(1) time
+  *
+  * @the_repl_op_pool: array with the replenishment operations allocated
+  * @the_repl_op_pool_freelist: freelist for the_repl_op_pool
+  * @frescan_repl_op_init: initializes the freelist
+  * @frescan_repl_op_alloc: get a free replenishment operation structure
+  * @frescan_repl_op_free: free a replenishment operation structure
+  *
+  */
+ static frescan_repl_op_t the_repl_op_pool[FRESCAN_MX_REPL_OPS];
+ static freelist_t the_repl_op_pool_freelist;
+ static int frescan_repl_op_init()
+ {
+         return freelist_init(&the_repl_op_pool_freelist, FRESCAN_MX_REPL_OPS);
+ }
+ frescan_repl_op_t *frescan_repl_op_alloc()
+ {
+         int pos;
+         pos = freelist_alloc(&the_repl_op_pool_freelist);
+         if (pos == -1) {
+                 ERROR("could not allocate repl op\n");
+                 return NULL;
+         }
+         the_repl_op_pool[pos].pool_pos = pos; // to know how to free it
+         return &the_repl_op_pool[pos];
+ }
+ int frescan_repl_op_free(frescan_repl_op_t *repl_op)
+ {
+         return freelist_free(&the_repl_op_pool_freelist, repl_op->pool_pos);
+ }
+ /**
+  * frescan_repl_thread - the thread that executes the replenishments
+  */
+ static void *frescan_repl_thread(void *arg)
+ {
+         int ret;
+         sigset_t set;
+         siginfo_t siginfo;
+         frescan_ss_t id;
+         frescan_network_t net;
+         struct list_head *pos;
+         frescan_repl_op_t *repl = NULL;
+         frescan_server_data_t *server;
+         struct itimerspec timerdata;
+         net = (frescan_network_t)(uint32_t)arg;
+         timerdata.it_interval.tv_sec  = 0;
+         timerdata.it_interval.tv_nsec = 0;
+         sigemptyset(&set);
+         sigaddset(&set, FRESCAN_REPL_SIGNAL_NUM);
+         while (1) {
+ #if FRESCAN_MEASURE_REPL_TH
+                 ret = time_measure_posix_begin(measure_id);
+                 assert(ret == 0);
+ #endif
+                 ret = sigwaitinfo(&set, &siginfo);
+                 if (ret == -1) {
+                         ERROR("sigwaitinfo failed\n");
+                         return NULL;
+                 }
+                 if (siginfo.si_signo != FRESCAN_REPL_SIGNAL_NUM) continue;
+                 DEBUG(FRESCAN_REPLENSH_ENABLE_DEBUG,
+                       "net:%u signal:%d code:%d value(server_id):%d\n",
+                       net,
+                       siginfo.si_signo,            // FRESCAN_REPL_SIGNAL_NUM
+                       siginfo.si_code,             // SI_TIMER
+                       siginfo.si_value.sival_int); // the server id
+                 id = siginfo.si_value.sival_int;
+                 server = &the_servers_pool[net][id];
+                 DEBUG(FRESCAN_REPLENSH_ENABLE_DEBUG,
+                       "id:%u, current_budget:%u, budget:%u, current_prio:%u\n",
+                       id,
+                       server->current_budget,
+                       server->params.values.budget,
+                       server->current_priority);
+                 server->current_budget++;
+                 if (server->current_priority == FRESCAN_BACKGROUND_PRIO) {
+                         server->current_priority = server->params.prio;
+                         if (!list_empty(&server->packet_list.fifo_list)) {
+                                 clock_gettime (CLOCK_MONOTONIC,
+                                                &server->act_time);
+                         }
+                 }
+                 DEBUG(FRESCAN_REPLENSH_ENABLE_DEBUG,
+                       "now... current_budget:%u, current_prio:%u\n",
+                       server->current_budget,
+                       server->current_priority);
+                 // delete the replenishment of this call
+                 list_for_each(pos, &server->replenishments.repl_list) {
+                         repl = list_entry(pos, frescan_repl_op_t, repl_list);
+                         break;
+                 }
+                 list_del(&repl->repl_list);
+                 ret = frescan_repl_op_free(repl);
+                 if (ret != 0) {
+                         ERROR("could not free replenishment op\n");
+                         return NULL;
+                 }
+                 // check if there are pending replenishments
+                 if (list_empty(&server->replenishments.repl_list)) continue;
+                 list_for_each(pos, &server->replenishments.repl_list) {
+                         repl = list_entry(pos, frescan_repl_op_t, repl_list);
+                         break;
+                 }
+                 timerdata.it_value = repl->when;
+                 DEBUG(FRESCAN_REPLENSH_ENABLE_DEBUG,
+                       "set timer to (%d, %d)\n",
+                       repl->when.tv_sec, repl->when.tv_nsec);
+                 ret = timer_settime(server->repl_timer,
+                                     TIMER_ABSTIME, &timerdata, NULL);
+                 if (ret != 0) {
+                         ERROR("could not set replenishment timer\n");
+                         return NULL;
+                 }
+ #if FRESCAN_MEASURE_REPL_TH
+                 ret = time_measure_posix_end(measure_id, "thread");
+                 assert(ret == 0);
+                 while (logger_manual_call() > 0);
+ #endif
+         }
+         return NULL;
+ }
+ /**
+  * frescan_replenishments_init - init the replenishment structures and thread
+  *
+  * @net: the network instance
+  *
+  * Initialize the repl_op pool, set the mask for the timer signals and create
+  * the thread that will await for those signals and replenish the appropiate
+  * sporadic server.
+  */
+ int frescan_replenishments_init(frescan_network_t net)
+ {
+         int ret;
+         fosa_signal_t signal_set[1];
+         fosa_thread_attr_t attr;
+         ret = frescan_repl_op_init();
+         if (ret != 0) {
+                 ERROR("could not init repl_op pool\n");
+                 return ret;
+         }
+         signal_set[0] = FRESCAN_REPL_SIGNAL_NUM;
+         ret = fosa_set_accepted_signals(signal_set, 1);
+         if (ret != 0) {
+                 ERROR("could not set the repl signal\n");
+                 return ret;
+         }
+         // create the replenishment thread
+ #if (FRESCAN_MEASURE_REPL_TH || FRESCAN_MEASURE_REPL_PROGRAM)
+         ret = logger_init(LOG_ETHERNET);
+         assert(ret == 0);
+         ret = time_measure_posix_create("repl",
+                                         CLOCK_THREAD_CPUTIME_ID,
+                                         &measure_id);
+         assert(ret == 0);
+ #endif
+         ret = fosa_thread_attr_init(&attr);
+         if (ret != 0) {
+                 ERROR("could not init thread attributes\n");
+                 return ret;
+         }
+         ret = fosa_thread_attr_set_prio(&attr, FRESCAN_REPL_THREAD_PRIO);
+         if (ret != 0) {
+                 ERROR("could not set repl thread prio %d\n",
+                       FRESCAN_REPL_THREAD_PRIO);
+                 return ret;
+         }
+         ret = fosa_thread_create(&the_networks[net].repl_thread_id,
+                                  &attr,
+                                  frescan_repl_thread,
+                                  (void *)(uint32_t)net);
+         if (ret != 0) {
+                 ERROR("could not create the replenishment thread\n");
+                 return ret;
+         }
+         ret = fosa_thread_attr_destroy(&attr);
+         if (ret != 0) {
+                 ERROR("could not destroy thread attributes\n");
+                 return ret;
+         }
+         return 0;
+ }
+ /**
+  * frescan_replenishment_program - set a replenishment operation
+  *
+  * @net: the network instance
+  * @ss: the server
+  */
+ int frescan_replenishment_program(frescan_network_t net,
+                                   frescan_ss_t ss,
+                                   const struct timespec *timestamp)
+ {
+         int ret;
+         frescan_repl_op_t *repl;
+         bool empty;
+         struct itimerspec timerdata;
+         frescan_server_data_t *server;
+ #if FRESCAN_MEASURE_REPL_PROGRAM
+         ret = time_measure_posix_begin(measure_id);
+         assert(ret == 0);
+ #endif
+         server = &the_servers_pool[net][ss];
+         repl = frescan_repl_op_alloc();
+         if (repl == NULL) {
+                 ERROR("could not allocate a repl operation\n");
+                 return -1;
+         }
+         repl->when = *timestamp;
+         incr_timespec (&repl->when, &server->params.values.period);
+         repl->amount = 1;
+         empty = list_empty(&server->replenishments.repl_list);
+         DEBUG(FRESCAN_REPLENSH_ENABLE_DEBUG, "ss:%u, empty:%u\n", ss, empty);
+         list_add_tail(&repl->repl_list,
+                       &server->replenishments.repl_list);
+         if (empty) {
+                 timerdata.it_interval.tv_sec  = 0;
+                 timerdata.it_interval.tv_nsec = 0;
+                 timerdata.it_value = repl->when;
+                 DEBUG(FRESCAN_REPLENSH_ENABLE_DEBUG,
+                       "set timer to %d sec, %d nsec\n",
+                       repl->when.tv_sec, repl->when.tv_nsec);
+                 ret = timer_settime(server->repl_timer,
+                                     TIMER_ABSTIME, &timerdata, NULL);
+                 if (ret != 0) {
+                         ERROR("could not set the replenishment timer\n");
+                         return ret;
+                 }
+         }
+ #if FRESCAN_MEASURE_REPL_PROGRAM
+                 ret = time_measure_posix_end(measure_id, "program");
+                 assert(ret == 0);
+                 while (logger_manual_call() > 0);
+ #endif
+         return 0;
+ }
index 0000000000000000000000000000000000000000,d0a12fe5b416f42c000560ba4094ba94f55a939b..d0a12fe5b416f42c000560ba4094ba94f55a939b
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,109 +1,109 @@@
+ /*!
+  * @file frescan_servers_replenishments.h
+  *
+  * @brief the replenishment data and thread for the servers
+  *
+  * @version 0.01
+  *
+  * @date 12-Mar-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This module contains the thread that waits for server's replenishment
+  * timer signals and perform the necessary replenishments.
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _MARTE_FRESCAN_SERVERS_REPLENISHMENTS_H_
+ #define _MARTE_FRESCAN_SERVERS_REPLENISHMENTS_H_
+ #include "frescan_types.h"
+ /**
+  * frescan_replenishments_init - init the replenishment structures and thread
+  *
+  * @net: the network instance
+  *
+  * Initialize the repl_op pool, set the mask for the timer signals and create
+  * the thread that will await for those signals and replenish the appropiate
+  * sporadic server.
+  *
+  * NOTE: it must be called from the MAIN because it sets the signal mask
+  */
+ extern int frescan_replenishments_init(frescan_network_t net);
+ extern frescan_repl_op_t *frescan_repl_op_alloc();
+ extern int frescan_repl_op_free(frescan_repl_op_t *repl_op);
+ /**
+  * frescan_replenishment_program - set a replenishment operation
+  *
+  * @net: the network instance
+  * @ss: the server
+  * @timestamp: timestamp
+  */
+ extern int frescan_replenishment_program(frescan_network_t net,
+                                          frescan_ss_t id,
+                                          const struct timespec *timestamp);
+ #endif // _MARTE_FRESCAN_SERVERS_REPLENISHMENTS_H_
index 0000000000000000000000000000000000000000,c42dc7175f7ab858031cf8490460362150bb6c73..c42dc7175f7ab858031cf8490460362150bb6c73
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,505 +1,505 @@@
+ /*!
+  * @file frescan_types.h
+  *
+  * @brief types used in FRESCAN
+  *
+  * @version 0.01
+  *
+  * @date 16-Nov-2008
+  *
+  * @author
+  *      Daniel Sangorrin
+  *
+  * @comments
+  *
+  * This file contains the types used in FRESCAN protocol
+  *
+  * @license
+  *
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+  *
+  */
+ #ifndef _FRESCAN_TYPES_H_
+ #define _FRESCAN_TYPES_H_
+ #include <stdint.h>  // uint8_t, uint32_t..
+ #include <stdbool.h> // bool
+ #include <unistd.h>  // size_t
+ #include <time.h>    // struct timespec, timer_t
+ #include <semaphore.h> // sem_t
+ #include "frsh.h" // for frsh_contract_t
+ #include "fsa.h"  // for frsh_sa_scenario_t
+ #include "fosa_opaque_types.h" // for FOSA_ETIMEDOUT
+ #include "fosa_threads_and_signals.h"   // fosa_thread_id_t
+ #include "frescan_config.h"
+ #include <misc/linux_list.h> // struct list_head
+ #include <drivers/can.h>     // can_frame_t
+ #include <misc/freelist.h>   // freelist_t
+ typedef uint8_t frescan_network_t;
+ typedef uint8_t frescan_node_t;
+ typedef uint8_t frescan_channel_t;
+ typedef uint8_t frescan_prio_t;
+ typedef uint8_t frescan_ss_t;
+ typedef uint32_t frescan_budget_t;
+ typedef struct {
+         int           size;
+         frescan_ss_t  ss[FRESCAN_BWRES_MAX_GROUP_OPS];
+ } frescan_ss_group_t;
+ /**
+  * frescan_flags_t - frescan flags
+  *
+  * @FRESCAN_SS: send the message using sporadic servers
+  * @FRESCAN_FP: send the message using fixed priorities
+  * @FRESCAN_POLL: no buffer copy, only pointer and use the ID to poll status
+  * @FRESCAN_SYNC: no buffer copy, only pointer and block until it is sent
+  * @FRESCAN_ASYNC: use buffer copy and return immediately
+  */
+ typedef enum {
+         FRESCAN_SS    = 1<<4,  // sporadic server
+         FRESCAN_FP    = 1<<3,  // fixed priorities
+         FRESCAN_POLL  = 1<<2,  // polling
+         FRESCAN_SYNC  = 1<<1,  // synchronous
+         FRESCAN_ASYNC = 1      // asynchronous
+ } frescan_flags_t;
+ /**
+  * frescan_send_params_t - send parameters
+  *
+  * @net: the network to use
+  * @to: the node where the message shoud be sent to
+  * @channel: the channel in 'to' where the message shoud be sent to
+  * @flags: the flags (see frescan_flags_t)
+  * @prio: the priority for the message if (flags & FRESCAN_FP)
+  * @ss: the sporadic server for the message if (flags & FRESCAN_SS)
+  */
+ typedef struct {
+         frescan_network_t net;
+         frescan_node_t to;
+         frescan_channel_t channel;
+         frescan_flags_t flags;
+         union {
+                 frescan_prio_t prio;
+                 frescan_ss_t ss;
+         };
+ } frescan_send_params_t;
+ /**
+  * frescan_recv_params_t - receive parameters
+  *
+  * @net: the network to use
+  * @channel: the channel from which we want to extract a message
+  * @flags: FRESCAN_SYNC/ASYNC
+  */
+ typedef struct {
+         frescan_network_t net;
+         frescan_channel_t channel;
+         frescan_flags_t flags;
+ } frescan_recv_params_t;
+ /**
+  * frescan_init_params_t - initialization parameters
+  *
+  * @net: network to initialize (minor number ie: /dev/can0 -> 0)
+  * @node: set the local node identificator
+  * @tx_fp_max_prio: maximum number of priorities for the fixed priority
+  *                  transmission queues. (prio = 0 .. max_prio - 1)
+  * @rx_num_of_channels: number of rx channels (0 .. rx_num_of_channels - 1)
+  * @rx_channel_max_prio: array (range rx_num_of_channels) saying the number
+  *                       of priorities for each channel. If this parameter is
+  *                       NULL tx_fp_max_prio will be used for all queues.
+  */
+ typedef struct {
+         frescan_network_t net;
+         frescan_node_t node;
+         uint32_t tx_fp_max_prio;
+         uint32_t rx_num_of_channels;
+         uint32_t *rx_channel_max_prio;
+ } frescan_init_params_t;
+ /**
+  * frescan_packet_t - a frescan packet
+  *
+  * This structure is very important and it is used to store a FRESCAN packet.
+  * As we support fragmentation, a FRESCAN packet can be composed of several
+  * CAN frames. This 'frescan_packet_t' structure is used in two main cases:
+  *
+  * 1.- When we are sending data. In this case, the buffer pointers store the
+  *     real data we want to sent and we use a 'buffer_read_pointer' to know
+  *     how many bytes of the buffer we already sent. In 'frame', we store the
+  *     last sent frame (with the corresponding CAN id fields). We will have
+  *     to update the fragmentation fields as long as we send more packets.
+  *     The 'fifo_list' is used to chained frescan packets of the same priority
+  *     or that belong to the same sporadic server. Finally, 'flags', specify
+  *     if we are sending ASYNC or SYNC. If we are sending SYNC the buffer
+  *     pointers are pointing to the buffer sent by the user (zero copying),
+  *     while if we use ASYNC, a copy of the data is done to the buffer.
+  *
+  * 2.- When we are receiving data, we only use 'frame' and 'fifo_list' fields.
+  *     The IRQ handler of the chip allocates a CAN frame and calls to our hook.
+  *     We store the pointer to that frame in 'frame' and we make a chain with
+  *     frames of the same message (using the fragmentation fields). When we
+  *     have all of them, we move the packet list to the corresponding
+  *     receiving channel to wait for the user to perform a receive operation
+  *     when we will copy the data and free both the packets and the frames.
+  *
+  * @flags: to know if the packet is to be sent SYNC or ASYNC, FP or SERVER...
+  * @frame: pointer to the last sent frame or the received frame
+  * @fifo_list: list to put several packets together
+  * @msg_list: list to put packets of the same message together
+  * @buffer_head: pointer to first byte of the buffer that is going to be sent
+  * @buffer_read_pointer: pointer to the part of the buffer being read
+  * @buffer_pending_bytes: bytes waiting to be sent
+  * @timestamp: time when the packet was enqueued (activation time)
+  * @pool_pos: position in the packets pool to know how to free it
+  *
+  * NOTE: the buffers could also be used on the receiving part to support
+  * sequential reads, instead of reading the whole message at once.
+  *
+  */
+ typedef struct {
+         frescan_flags_t flags;
+         struct can_frame_t *frame;
+         struct list_head fifo_list;
+         struct list_head msg_list;
+         uint8_t *buffer_head;         // only for sending packets
+         uint8_t *buffer_read_pointer; // only for sending packets
+         uint32_t buffer_pending_bytes; // only for sending packets
+         struct timespec timestamp;
+         int pool_pos;
+ } frescan_packet_t;
+ /**
+  * frescan_repl_op_t - a replenishment operation
+  *
+  * @when: when the replenishment operation is programmed at
+  * @amount: number of frames to add to the available budget
+  * @repl_list: to chain the replenishments for a certain sporadic server
+  * @pool_pos: to know how to free it from the replenishment pool
+  */
+ typedef struct {
+         struct timespec when;
+         frescan_budget_t amount;
+         struct list_head repl_list;
+         int pool_pos;
+ } frescan_repl_op_t;
+ /**
+  * frescan_server_params_t - server parameters
+  *
+  * @budget: the budget in CAN 8-byte frames
+  * @period: the replenishment period for the server
+  * @prio: the priority of the server
+  */
+ typedef struct {
+         frescan_budget_t budget;
+         struct timespec  period;
+         frescan_prio_t prio;
+ } frescan_server_params_t;
+ /**
+  * frescan_ss_data_t - sporadic server data
+  *
+  * @committed_params: the committed params (C,T,Prio) for the server
+  * @perceived_params: the params perceived by the user (we can lie to him)
+  * @current_priority: the current priority (0=background)
+  * @repl_list: the list of pending replenishment operations
+  * @repl_timer: the timer for the replenishments associated to this server
+  *     NOTE: we could use a single timer for all but for now this is simpler
+  * @act_time: the last activation time for the server
+  * @packet_list: the packets enqueued on this server
+  * @servers_list: the list of servers
+  */
+ typedef struct {
+         frescan_server_params_t committed_params;
+         frescan_server_params_t perceived_params;
+         frescan_network_t       net;
+         frescan_ss_t            id;
+         frescan_prio_t          current_priority;
+         frescan_budget_t        pending_packets;
+         frescan_repl_op_t       replenishments; // TODO: use struct list_head
+         timer_t                 repl_timer;
+         struct timespec         act_time;
+         frescan_packet_t        packet_list; // TODO: use struct list_head
+         struct list_head        servers_list;
+ } frescan_ss_data_t;
+ /**
+  * frescan_prio_queue_t - priority queue
+  *
+  * FRESCAN priority queues are implemented as an array of one 'fifo_queue' for
+  * each priority. Where the 'fifo_queues' are implemented using the
+  * 'struct list_head fifo_list;' field of each packet structure (Linux lists).
+  *
+  * So far mutual exclusion is achieved by disabling interrupts and
+  * synchronization is done using a semaphore. This is because the queues
+  * are accesed concurrently from user threads and the IRQ handler.
+  *
+  * @net: the network this priority queue belongs to (mainly for locking)
+  * @fifo_queues: an array of packets for each priority where each packet
+  *               is just the head of a fifo_list. The array is allocated
+  *               from the heap, using malloc, at initialization with range
+  *               0..max_prio-1
+  * @max_prio: defines the number of priorities as (0 .. max_prio - 1)
+  * @sem: semaphore used for synchronization
+  */
+ typedef struct {
+         frescan_network_t net;
+         frescan_packet_t *fifo_queues;
+         uint32_t max_prio;
+         sem_t sem;
+ } frescan_prio_queue_t;
+ /**
+  * frescan_queues_t - the set of FRESCAN queues for each instance of a protocol
+  *
+  * @tx_fp_queue: priority queue for the fixed priority packets
+  * @rx_channel_queues: a priority queue for each receiving channel
+  *
+  * TODO: add here the sporadic server queues...
+  */
+ typedef struct {
+         frescan_prio_queue_t *tx_fp_queue;
+         frescan_prio_queue_t **rx_channel_queues;
+         uint32_t num_rx_channels;
+ } frescan_queues_t;
+ // BWRES TYPES
+ typedef unsigned int frescan_bwres_robj_id_t; /* 0 .. MX_REPLY_OBJECTS-1 */
+ #define FRESCAN_ETIMEDOUT FOSA_ETIMEDOUT
+ /**
+  * frescan_bwres_vres_t - a frescan virtual resource
+  *
+  * @contract: the contract of the virtual resource
+  * @node: the node where the vres belongs to
+  * @ss: the sporadic server identifier
+  * @list: the list of vres. Note that this is the list of all the vres
+  *      in the network instace. As this is a master-slave protocol the master
+  *      knows everything about the contracts of the rest of nodes.
+  */
+ typedef enum {
+         FRESCAN_BWRES_MC_PERIOD_DEC = 1<<5,
+         FRESCAN_BWRES_MC_PERIOD_INC = 1<<4,
+         FRESCAN_BWRES_MC_BUDGET_DEC = 1<<3,
+         FRESCAN_BWRES_MC_BUDGET_INC = 1<<2,
+         FRESCAN_BWRES_MC_PRIO_DEC   = 1<<1,
+         FRESCAN_BWRES_MC_PRIO_INC   = 1
+ } frescan_bwres_mode_change_type_t;
+ typedef struct {
+         frsh_contract_t    contract;
+         frescan_node_t     node;
+         frescan_ss_t       ss;
+         frsh_sa_vres_id_t  fsa_vres_global_id;
+         struct list_head   list;
+         // mode change variables
+         frsh_sa_time_t old_c;
+         frsh_sa_time_t old_t;
+         frsh_sa_prio_t old_p;
+         frescan_bwres_mode_change_type_t mode_change_type;
+         struct list_head                 mode_change_list;
+ } frescan_bwres_vres_t;
+ /**
+  * frescan_bwres_request_data_t
+  *
+  * This are the data contained in a request to perform the negotiation of
+  * contracts.
+  *
+  * @type: indicates the type of the request
+  * @contract: a contract to (re)negotiate
+  * @contract_ref: a pointer to the contract to (re)negotiate (optimization)
+  * @ss: the local sporadic server ID
+  * @request_node: the node that performed the request
+  * @req: the request id of the SLAVE to identify the request in the reply
+  * @return_value: the value returned in a Reply (accepted or not)
+  * @final_values: the values for the ss after the negotiation
+  * @net: the network instance where this request belongs to
+  * @robj: a reply object to wait until a negotiation is completed
+  *
+  */
+ typedef uint16_t frescan_bwres_request_id_t; /* 0 .. MX_REQUESTS */
+ typedef enum {
+         FRESCAN_BWRES_REQ_GN         =  0,  // group negotiation
+         FRESCAN_BWRES_REP_GN         =  1,  // negotiation reply
+         FRESCAN_BWRES_REQ_MC         =  2,  // mode change
+         FRESCAN_BWRES_REQ_RES        =  3,  // reservation negotiation
+         FRESCAN_BWRES_REQ_RES_GET    =  4,  // reservation get values
+         FRESCAN_BWRES_REP_RES_GET    =  5,  // reservation get values reply
+         FRESCAN_BWRES_REQ_RES_SET    =  6,  // reservation set values
+         FRESCAN_BWRES_REQ_RES_COMMIT =  7,  // reservation commit
+         FRESCAN_BWRES_REQ_RES_CANCEL =  8,  // reservation cancel
+ } frescan_bwres_request_type_t;
+ typedef enum {
+         FRESCAN_BWRES_REQ_ACCEPTED      =  0,  // negotiation accepted
+         FRESCAN_BWRES_REQ_NOT_ACCEPTED  =  1,  // negotiation not accepted
+         FRESCAN_BWRES_REQ_ERROR         =  2,  // there was an error
+ } frescan_bwres_request_retval_t;
+ typedef struct {
+         frescan_network_t               net;
+         frescan_bwres_request_type_t    type;
+         frescan_bwres_request_id_t      req;
+         frescan_node_t                  request_node;
+         frescan_bwres_request_retval_t  return_value;
+         frescan_bwres_robj_id_t         robj;
+         // contracts and ss groups
+         frsh_contracts_group_t  *contracts_to_neg;
+         frsh_contracts_group_t  *contracts_to_reneg;
+         frescan_ss_group_t      *ss_to_reneg;
+         frescan_ss_group_t      *ss_to_cancel;
+         frescan_ss_group_t      *ss_new;
+         // contracts and ss groups data (to store the info at master node)
+         frsh_contracts_group_t  contracts_to_neg_data;
+         frsh_contracts_group_t  contracts_to_reneg_data;
+         frescan_ss_group_t      ss_to_reneg_data;
+         frescan_ss_group_t      ss_to_cancel_data;
+         frescan_ss_group_t      ss_new_data;
+         // for FRESCAN_BWRES_REQ_MC
+         frescan_bwres_mode_change_type_t mode_change_type;
+ } frescan_bwres_request_data_t;
+ /**
+  * frescan_bwres_sa_scenario_t - the scheduling analysis scenario
+  */
+ typedef struct {
+         frescan_prio_t    max_prio;
+         frescan_prio_t    min_prio;
+ } frescan_bwres_sa_init_params_t;
+ typedef struct {
+         frescan_bwres_sa_init_params_t init_params;
+         frescan_bwres_vres_t vres_pool[FRESCAN_MX_NODES][FRESCAN_MX_IDS];
+         frescan_bwres_vres_t vres_head; // TODO: use struct list_head
+         freelist_t fsa_vres_global_id_freelist;
+         freelist_t ss_id_freelist[FRESCAN_MX_NODES];
+         frsh_sa_scenario_t fsa_scenario;
+         frsh_contracts_group_t backup_contracts_to_reneg;
+         frsh_contracts_group_t backup_contracts_to_cancel;
+ } frescan_bwres_sa_scenario_t;
+ /**
+  * frescan_network_data_t - data for each network instance
+  *
+  * @local_node: the local node id for that network. The implementation does not
+  * support several interfaces for the same network.
+  * @fd: file descriptor associated to /dev/canXX
+  * @repl_thread_id: replenishment thread id
+  * @manager_thread_id: manager thread id
+  * @acceptor_thread_id: acceptor thread id
+  * @neg_messages_ss_id: sporadic server for negotiation messages
+  * @queues: the queues of this network instance
+  * @last_packet: pointer to the last packet from which a frame was inserted
+  *               in the chip and its transmission is not complete.
+  * @last_packet_prio: prio of the packet in the buffer
+  * @id_queues: queues to store received packets while the whole message is
+  *             not complete (fragmentation). (id = 0 .. FRESCAN_MX_IDS - 1)
+  * @id_fp_queues: the same as id_queues but for fp messages, which have
+  *                id=FRESCAN_MX_IDS and are distinguised through their
+  *                priorities.
+  * @scenario: the scheduling analysis scenario for the network
+  * @mode_change_list: list of sa_vres that have changes to commit
+  * @mode_change_type: what type of changes are to commit
+  *
+  * the implementation can handle several FRESCAN networks at the same time
+  * in the same node, so we need a place to store its internal data. The data
+  * is allocated as an array where the index is the MINOR number (which also
+  * identifies the /dev/canx device for that network)
+  */
+ typedef struct {
+         FRESCAN_MLOCK_T lock;
+         frescan_node_t local_node;
+         int fd;
+         fosa_thread_id_t repl_thread_id;
+         frescan_packet_t *last_packet;
+         frescan_prio_t last_packet_prio;
+         frescan_queues_t queues;
+         frescan_packet_t *id_queues[FRESCAN_MX_NODES][FRESCAN_MX_IDS];      // TODO: alloc at init
+         frescan_packet_t *id_fp_queues[FRESCAN_MX_NODES][FRESCAN_MX_PRIOS]; // TODO: alloc at init
+         frescan_ss_data_t ss_data[FRESCAN_MX_IDS];
+         freelist_t ss_id_freelist;
+         frescan_ss_data_t ss_active_head; // TODO: use struct list_head
+         // BWRES data
+         fosa_thread_id_t manager_thread_id;
+         fosa_thread_id_t acceptor_thread_id;
+         frescan_ss_t neg_messages_ss_id;
+         frescan_bwres_sa_scenario_t scenario;
+         struct list_head mode_change_list[FRESCAN_MX_NODES];
+         frescan_bwres_mode_change_type_t mode_change_type[FRESCAN_MX_NODES];
+ } frescan_network_data_t;
+ #endif // _FRESCAN_TYPES_H_
index 0000000000000000000000000000000000000000,f4a3de06c35263491fbc519755922b631337abd1..f4a3de06c35263491fbc519755922b631337abd1
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,22 +1,22 @@@
+ .PHONY: all objs librtepfna.a
+ all: librtepfna.a
+ include ../config.mk
+ include ../rules.mk
+ SRCS := $(wildcard *.c)
+ OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
+ HDRS := $(wildcard $(FNA_PATH)/include/*.h)
+ CFLAGS += -I$(PLATFORM_PATH)/arch/drivers/rt-ep/
+ objs: $(OBJS)
+ %.o: %.c $(SRCS) $(HDRS)
+       $(CC) $(CFLAGS) -c $<
+ librtepfna.a: objs
+       @exec echo -e "\n>> Building RTEP FNA:";
+       ld -r -o librtepfna.o *.o
+       @mv librtepfna.o $(FNA_PATH)/lib
+       @exec echo ">> end Building RTEP FNA  [OK]"
index 0000000000000000000000000000000000000000,89287134bcaa069c10c78ec4fe9d7720f7a686ba..89287134bcaa069c10c78ec4fe9d7720f7a686ba
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,74 +1,74 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ //==============================================
+ //  ******** ****     **     **
+ //  **///// /**/**   /**    ****
+ //  **      /**//**  /**   **//**
+ //  ******* /** //** /**  **  //**
+ //  **////  /**  //**/** **********
+ //  **      /**   //****/**//////**
+ //  **      /**    //***/**     /**
+ //  /       //      /// //      //
+ //
+ // FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
+ //==============================================================
+ #ifndef _RTEP_FNA_H_
+ #define _RTEP_FNA_H_
+ #include "fna.h" // for fna_operations_t
+ extern fna_operations_t rtep_fna_operations;
+ #endif // _RTEP_FNA_H_
index 0000000000000000000000000000000000000000,1fa15e626755beef48d75d8b0ccba10cba486ba9..1fa15e626755beef48d75d8b0ccba10cba486ba9
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,1079 +1,1079 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ //==============================================
+ //  ******** ****     **     **
+ //  **///// /**/**   /**    ****
+ //  **      /**//**  /**   **//**
+ //  ******* /** //** /**  **  //**
+ //  **////  /**  //**/** **********
+ //  **      /**   //****/**//////**
+ //  **      /**    //***/**     /**
+ //  /       //      /// //      //
+ //
+ // FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
+ //==============================================================
+ #include <malloc.h> // for malloc and free
+ #include "rtep.h" // for rtep_adainit, rtep_valid_multicast_id, ..
+ #include "rtep_bandwith_reservation.h" // for rtep_bwres_*
+ #include "rtep_fna.h" // function prototypes
+ #include "fadt_freelist.h"
+ #if 0
+ #include <stdio.h>
+ #define DEBUG(x,args...) printf("%s: " x, __func__ , ##args)
+ #else
+ #define DEBUG(x,args...)
+ #endif
+ // TODO: add a mutex for concurrent access if necessary
+ static rtep_bwres_vres_t rtep_vres_list[MAX_N_RTEP_BWRES_VRES];
+ static fadt_freelist_t rtep_vres_freelist;
+ //////////////////////////////////////////////////////////////////////
+ //           INITIALIZATION
+ //////////////////////////////////////////////////////////////////////
+ /**
+  * rtep_fna_init()
+  *
+  * This function will be hooked to the frsh_init function and it is
+  * intented to initialize the protocol and its structures.
+  *
+  * @param[in]  resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_ALREADY_INITIALIZED:
+  *      if the function has already been called before (with success) \n
+  *
+  **/
+ int rtep_fna_init(const frsh_resource_id_t resource_id)
+ {
+         int err = 0;
+         DEBUG("calling rtep_adainit\n");
+         // init Ada bindings
+         rtep_adainit();
+         DEBUG("calling freelist_init\n");
+         // initialize the freelist to handle the rtep_vres
+         err = fadt_freelist_init(&rtep_vres_freelist, NULL, MAX_N_RTEP_BWRES_VRES);
+         if (err != 0) return -1;
+         DEBUG("calling rtep_bwres_init\n");
+         return rtep_bwres_init();
+ }
+ ///////////////////////////////////////////////////////////////////
+ //           VIRTUAL RESOURCES
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * rtep_fna_contract_negotiate()
+  *
+  * The operation negotiates a contract and if accepted it will return
+  * a fna_vres_id_t. It will also check that the given contract_id is unique
+  * within the network.
+  *
+  * If the on-line admission test is enabled, it determines whether the
+  * contract can be admitted or not based on the current contracts
+  * established in the network. Then it creates the vres and
+  * recalculates all necessary parameters for the contracts already
+  * present in the system.
+  *
+  * This is a potentially blocking operation, it returns when the
+  * system has either rejected the contract, or admitted it and made it
+  * effective.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] contract  The contract parameters to negotiate
+  * @param[out] vres The internal virtual resource id
+  *
+  * @return
+  *   0 if there are no errors (in this case it also means contract accepted) \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_TOO_MANY_VRES: if there is no space for more vres \n
+  *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+  *   FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_contract_negotiate
+                 (const frsh_resource_id_t resource_id,
+                  const frsh_contract_t *contract,
+                  fna_vres_id_t *vres)
+ {
+         rtep_bwres_contract_t rtep_contract;
+         int accepted;
+         int pos;
+          // convert FRSH contract to RTEP BWRES contract
+         rtep_contract.period_max = contract->period_max;
+         rtep_contract.deadline = contract->deadline;
+         rtep_contract.prio = contract->preemption_level;
+         // in RTEP BWRES, budget is given in number of packets. We do a little trick
+         // in the function bytes_to_network_budget to use a the field tv_sec from
+         // the timespec in frsh_contract to store the budget in bytes directly
+         rtep_contract.budget_min = contract->budget_min.tv_sec;
+         // allocate a free internal vres.
+         pos = fadt_freelist_alloc(&rtep_vres_freelist);
+         if (pos < 0) {
+                 DEBUG("not enough resources\n");
+                 return -1;
+         }
+         DEBUG("calling rtep_bwres_contract_negotiate\n");
+         // negotiate the contract
+         accepted = rtep_bwres_contract_negotiate
+                         (&rtep_contract, &rtep_vres_list[pos]);
+         // if accepted assign the vres, if not deallocate the rtep_vres
+         if (accepted == 0) {
+                 DEBUG("contract accepted\n");
+                 *vres = (fna_vres_id_t)pos;
+         } else {
+                 DEBUG("contract not accepted\n");
+                 fadt_freelist_free(&rtep_vres_freelist, pos);
+         }
+         return accepted;
+ }
+ /**
+  * rtep_fna_contract_renegotiate_sync()
+  *
+  * The operation renegotiates a contract for an existing vres. If
+  * the on-line admission test is enabled it determines whether the
+  * contract can be admitted or not based on the current contracts
+  * established in the system. If it cannot be admitted, the old
+  * contract remains in effect and an error is returned. If it can be
+  * admitted, it recalculates all necessary parameters for the
+  * contracts already present in the system and returns zero. This is a
+  * potentially blocking operation; it returns when the system has
+  * either rejected the new contract, or admitted it and made it
+  * effective.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id to renegotiate
+  * @param[in] new_contract The new contract
+  *
+  *  @return
+  *   0 if there are no errors (in this case it also means contract accepted) \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+  *   FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_contract_renegotiate_sync
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  const frsh_contract_t *new_contract)
+ {
+         rtep_bwres_contract_t rtep_contract;
+         int accepted;
+         int pos = (int) vres;
+         // convert FRSH contract to RTEP BWRES contract
+         rtep_contract.period_max = new_contract->period_max;
+         rtep_contract.deadline = new_contract->deadline;
+         rtep_contract.prio = new_contract->preemption_level;
+         // in RTEP BWRES, budget is given in number of packets. We do a little trick
+         // in the function bytes_to_network_budget to use a the field tv_sec from
+         // the timespec in frsh_contract to store the budget in bytes directly
+         rtep_contract.budget_min = new_contract->budget_min.tv_sec;
+         // renegotiate the contract
+         accepted = rtep_bwres_contract_renegotiate_sync
+                         (&rtep_vres_list[pos], &rtep_contract);
+         return accepted;
+ }
+ /**
+  * rtep_fna_contract_renegotiate_async()
+  *
+  * The operation enqueues a renegotiate operation for an existing
+  * vres, and returns immediately. The renegotiate operation is
+  * performed asynchronously, as soon as it is practical; meanwhile the
+  * system operation will continue normally. When the renegotiation is
+  * made, if the on-line admission test is enabled it determines
+  * whether the contract can be admitted or not based on the current
+  * contracts established in the system. If it cannot be admitted, the
+  * old contract remains in effect. If it can be admitted, it
+  * recalculates all necessary parameters for the contracts already
+  * present in the system.
+  *
+  * When the operation is completed, notification is made to the
+  * caller, if requested, via a signal. The status of the operation (in
+  * progress, admitted, rejected) can be checked with the
+  * frsh_vres_get_renegotiation_status() operation.  The argument
+  * sig_notify can be FRSH_NULL_SIGNAL (no notification), or any FRSH
+  * signal value and in this case signal_info is to be sent with the signal.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id to renegotiate
+  * @param[in] new_contract The new contract
+  * @param[in] signal_to_notify  Signal number to use to notify vres of
+  * the negotiation result. If FRSH_NULL_SIGNAL,  no signal will be raised.
+  * @param[in] signal_info: Associated info that will come with the signal.
+  * This parameter will be ignored if signal_to_notify == FRSH_NULL_SIGNAL.
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL, or sig_notify is neither
+  *      NULL nor a valid POSIX signal \n
+  *
+  **/
+ int rtep_fna_contract_renegotiate_async
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  const frsh_contract_t *new_contract,
+                  frsh_signal_t signal_to_notify,
+                  frsh_signal_info_t signal_info)
+ {
+         return 0;
+ }
+ /**
+  * rtep_fna_vres_get_renegotiation_status()
+  *
+  * The operation reports on the status of the last renegotiation
+  * operation enqueued for the specified vres. It is callable even
+  * after notification of the completion of such operation, if
+  * requested.
+  *
+  * If the vres is not and has not been involved in any of the
+  * frsh_contract_renegotiate_async() or frsh_group_change_mode_async()
+  * operations, the status returned is FNA_NOT_REQUESTED
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id we want the status from
+  * @param[in] renegotiation_status The status of the last renegotiation on
+  * vres (FRSH_RS_IN_PROGRESS, FRSH_RS_REJECTED, FRSH_RS_ADMITTED,
+  * FRSH_RS_NOT_REQUESTED)
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_vres_get_renegotiation_status
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  frsh_renegotiation_status_t *renegotiation_status)
+ {
+         return 0;
+ }
+ /**
+  * rtep_fna_vres_destroy()
+  *
+  * The operation eliminates the specified vres
+  * and recalculates all necessary parameters for the contracts
+  * remaining in the system. This is a potentially blocking operation;
+  * it returns when the system has made the changes effective.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id to destroy
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_vres_destroy
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres)
+ {
+         int err = 0;
+         int pos = (int) vres;
+         // cancel de negotiated contract (the function spread results
+         // among nodes)
+         err = rtep_bwres_vres_destroy (&rtep_vres_list[pos]);
+         if (err != 0) return -1;
+         // free the element in the rtep_vres list
+         err = fadt_freelist_free(&rtep_vres_freelist, pos);
+         if (err != 0) return -1;
+         return 0;
+ }
+ /**
+  * rtep_fna_vres_get_contract()
+  *
+  * This operation stores the contract parameters currently associated
+  * with the specified vres in the variable pointed to by
+  * contract. It returns an error if the vres_id is not recognised.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] contract  The contract parameters that we want
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_vres_get_contract
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  frsh_contract_t *contract)
+ {
+         return 0;
+ }
+ /**
+  * rtep_fna_vres_get_usage()
+  *
+  * This function gets the execution time spent by all messages that have been
+  * sent through the specified vres.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] usage  Execution time spent by this vres
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_vres_get_usage
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  struct timespec *usage)
+ {
+         return 0;
+ }
+ /**
+  * rtep_fna_vres_get_remaining_budget()
+  *
+  * This function stores in the variable pointed to by budget the
+  * remaining execution-time budget associated with the specified
+  * vres in the present period.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] remaining_budget  The remaining budget for this period
+  *
+  *  @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_vres_get_remaining_budget
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  struct timespec *remaining_budget)
+ {
+         return 0;
+ }
+ /**
+  * rtep_fna_vres_get_budget_and_period()
+  *
+  * This function gets the budget and period associated with the specified vres
+  * for each period. If one of these pointers is NULL, the corresponding
+  * information is not stored.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[out] budget The budget associated to vres
+  * @param[out] period  The period associated to vres
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if both pointers are NULL \n
+  *
+  **/
+ int rtep_fna_vres_get_budget_and_period
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  struct timespec *budget,
+                  struct timespec *period)
+ {
+         return 0;
+ }
+ /*@}*/
+ ///////////////////////////////////////////////////////////////////
+ //           SPARE CAPACITY FUNCIONS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * @defgroup fnaspare FNA Spare Capacity
+  * @ingroup fna
+  *
+  * The following functions are used to get spare capacity data
+  *
+  * @{
+  **/
+ /**
+  * rtep_fna_resource_get_capacity()
+  *
+  * This operation gets the spare capacity currently assigned to a importance
+  * level. If we divide this value by UINT32_MAX we will get the network
+  * utilization associated to the spare capacity of a importance level.
+  *
+  * The following is typically in stdint.h: \n
+  *  - typedef unsigned int uint32_t;  \n
+  *  - # define UINT32_MAX  (4294967295U)  \n
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] importance The importance we want the capacity of
+  * @param[out] capacity The spare capacity for that importance level
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_resource_get_capacity
+                 (const frsh_resource_id_t resource_id,
+                  const int importance,
+                  uint32_t *capacity)
+ {
+         return 0;
+ }
+ /**
+  * rtep_fna_resource_get_total_weight()
+  *
+  * This function gets the sum of the weight parameters for all vres in a
+  * network of an importance level.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] importance The importance we want the total weight of
+  * @param[out] total_weight The total weight for that importance level
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_resource_get_total_weight
+                 (const frsh_resource_id_t resource_id,
+                  const int importance,
+                  int *total_weight)
+ {
+         return 0;
+ }
+ /**
+  * rtep_fna_vres_decrease_capacity()
+  *
+  * This function allows to ask for less budget and period than what we
+  * received. The request must be compatible with the rest of contract
+  * parameters of the vres. If we want to recover the released capacity
+  * we will need to renegotiate.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] vres The internal virtual resource id
+  * @param[in] new_budget The new_budget
+  * @param[in] new_period The new Period
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_CONTRACT_REJECTED: if it is incompatible with the current
+  *      contract \n
+  *
+  **/
+ int rtep_fna_vres_decrease_capacity
+                 (const frsh_resource_id_t resource_id,
+                  const fna_vres_id_t vres,
+                  const struct timespec new_budget,
+                  const struct timespec new_period)
+ {
+         return 0;
+ }
+ ///////////////////////////////////////////////////////////////////
+ //           SEND RECEIVE OPERATIONS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * rtep_fna_send_sync()
+  *
+  * Similar to previous function but now the sending thread gets blocked
+  * until the message is already sent to the network.
+  *
+  * @param[in] endpoint The send endpoint we are sending through. It must
+  *    be bound to a virtual resource (resource_id is in the endpoint).
+  * @param[in] msg The message we want to send
+  * @param[in] size The size in bytes of the message
+  *
+  * @returns
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_BOUND: if endpoint is not bound to a valid vres \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_TOO_LARGE: if the message is too large for the network protocol \n
+  *   FNA_ERR_BUFFER_FULL: if the message has been discarded because
+  *   the queue is full (and does not have the policy FNA_QP_OLDEST) \n
+  *
+  **/
+ int rtep_fna_send_sync
+                 (const fna_endpoint_data_t *endpoint,
+                  const void *msg,
+                  const size_t size)
+ {
+         DEBUG("dest: %d, chan: %d, size: %d, server: %d\n",
+               endpoint->destination, endpoint->stream_id, size,
+               rtep_vres_list[endpoint->vres].server_id);
+         // TODO: check errors
+         rtep_server_send_info
+                         ((rtep_station_id_t) endpoint->destination,
+                          (rtep_channel_t) endpoint->stream_id,
+                          (uint8_t *) msg,
+                          size,
+                          rtep_vres_list[endpoint->vres].server_id,
+                          1); // blocking
+         return 0;
+ }
+ /**
+  * rtep_fna_send_async()
+  *
+  * This operation sends a message stored in msg and of length size
+  * through the given send endpoint. The operation is non-blocking and
+  * returns immediately.
+  *
+  * @param[in] endpoint The send endpoint we are sending through. It must
+  *    be bound to a virtual resource (resource_id is in the endpoint).
+  * @param[in] msg The message we want to send
+  * @param[in] size The size in bytes of the message
+  *
+  * @returns
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_BOUND: if endpoint is not bound to a valid vres \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_TOO_LARGE: if the message is too large for the network protocol \n
+  *   FNA_ERR_BUFFER_FULL: if the message has been discarded because
+  *   the queue is full (and does not have the policy FNA_QP_OLDEST) \n
+  *
+  **/
+ int rtep_fna_send_async
+                 (const fna_endpoint_data_t *endpoint,
+                  const void *msg,
+                  const size_t size)
+ {
+         DEBUG("dest: %d, chan: %d, size: %d, server: %d\n",
+               endpoint->destination, endpoint->stream_id, size,
+               rtep_vres_list[endpoint->vres].server_id);
+         // TODO: check errors
+         rtep_server_send_info
+                         ((rtep_station_id_t) endpoint->destination,
+                           (rtep_channel_t) endpoint->stream_id,
+                           (uint8_t *) msg,
+                           size,
+                           rtep_vres_list[endpoint->vres].server_id,
+                           0); // not blocking
+         return 0;
+ }
+ /**
+  * rtep_fna_receive_sync()
+  *
+  * This operation is used to receive messages from the network with a
+  * blocking behavior (if there are no messages this operation blocks
+  * the calling thread).
+  *
+  * When a message is available, it is copied to buffer (up to its size).
+  * The number of bytes copied is returned in received_bytes. The rest
+  * of the bytes of that message will be lost or not depending on the
+  * protocol (FNA_ERR_NO_SPACE will be returned if it is).
+  *
+  * The function fails with FNA_ERR_NO_SPACE if the buffersize is
+  * too small for the message received.  In this case the message is
+  * lost.
+  *
+  * Messages arriving at a receiver buffer that is full will be handled
+  * according to the queueing policy of the endpoint (overwrite oldest,
+  * discard it,etc).
+  *
+  * @param[in] endpoint The receive endpoint we are receiving from.
+  *    (resource_id is in the endpoint).
+  * @param[out] buffer Buffer for storing the received message
+  * @param[in] buffer_size The size in bytes of this buffer
+  * @param[out] received_bytes The actual number of received bytes
+  * @param[out] from Address of the sender node
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_NO_SPACE: if the message size is bigger than the
+  *      provided buffer. \n
+  *
+  **/
+ int rtep_fna_receive_sync
+                 (const fna_endpoint_data_t *endpoint,
+                  void *buffer,
+                  const size_t buffer_size,
+                  size_t *received_bytes,
+                  frsh_network_address_t *from)
+ {
+         rtep_priority_t prio;
+         rtep_station_id_t rtep_from;
+         rtep_channel_t chan = (rtep_channel_t) endpoint->stream_id;
+         // TODO: checks for errors
+         rtep_recv_info
+                         (&rtep_from,
+                           chan,
+                           (uint8_t *) buffer,
+                           buffer_size,
+                           received_bytes,
+                           &prio);
+         *from = rtep_from;
+         DEBUG(" %u bytes, from %u, prio %u\n",
+               *received_bytes, rtep_from, prio);
+         return 0;
+ }
+ /**
+  * rtep_fna_receive_async()
+  *
+  * This operation is similar to the previous one but it works in a non
+  * blocking (asynchronous) fashion.  If no message is available it
+  * returns with error FNA_NO_MESSAGE.
+  *
+  * @param[in] endpoint The receive endpoint we are receiving from.
+  *    (resource_id is in the endpoint).
+  * @param[out] buffer Buffer for storing the received message
+  * @param[in] buffer_size The size in bytes of this buffer
+  * @param[out] received_bytes The actual number of received bytes
+  * @param[out] from Address of the sender node
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *   FNA_ERR_NO_SPACE: if the message size is bigger than the
+  *      provided buffer. \n
+  *   FNA_NO_MESSAGE: if no messages are available in the queue. \n
+  *
+  **/
+ int rtep_fna_receive_async
+                 (const fna_endpoint_data_t *endpoint,
+                  void *buffer,
+                  const size_t buffer_size,
+                  size_t *received_bytes,
+                  frsh_network_address_t *from)
+ {
+         return 0;
+ }
+ /**
+  * rtep_fna_send_endpoint_get_status()
+  *
+  * This function tells the number of messages still pending in the
+  * endpoint queue, whether the network is up or down with some
+  * optional information which is protocol_dependent.
+  *
+  * @param[in] endpoint The send endpoint (resource_id is in the endpoint).
+  * @param[out] number_of_pending_messages The number of pending messages
+  * @param[out] network_status How is the network (up, down..)
+  * @param[out] protocol_status Protocol dependent status info
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_send_endpoint_get_status
+                 (const fna_endpoint_data_t *endpoint,
+                  int *number_of_pending_messages,
+                  frsh_endpoint_network_status_t *network_status,
+                  frsh_protocol_status_t *protocol_status)
+ {
+         return 0;
+ }
+ /**
+  * rtep_fna_receive_endpoint_created()
+  *
+  * This operation is a called from frsh_receive_endpoint_create with a
+  * receive_endpoint structure already filled.
+  *
+  * Receiving endpoints are not bound to any network vres, this is
+  * because don't originate any traffic.
+  *
+  * @param[in] endpoint the endpoint object.
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  **/
+ int rtep_fna_receive_endpoint_created
+                 (fna_endpoint_data_t *endpoint)
+ {
+         return 0;
+ }
+ /**
+  * rtep_fna_receive_endpoint_get_pending_messages
+  *
+  * This function tells the number of messages still pending in the
+  * endpoint queue, whether the network is up or down and some optional
+  * information which is protocol dependent.
+  *
+  * @param[in] endpoint The receive endpoint (resource_id is in the endpoint).
+  * @param[out] number_of_pending_messages The number of pending messages
+  * @param[out] network_status How is the network (up, down..)
+  * @param[out] protocol_status Protocol dependent status info
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_receive_endpoint_get_status
+                 (const fna_endpoint_data_t *endpoint,
+                  int *number_of_pending_messages,
+                  frsh_endpoint_network_status_t *network_status,
+                  frsh_protocol_status_t *protocol_status)
+ {
+         return 0;
+ }
+ //////////////////////////////////////////////////////////////////////
+ //           NETWORK CONFIGURATION FUNCTIONS
+ //////////////////////////////////////////////////////////////////////
+ /**
+  * rtep_fna_network_get_max_message_size()
+  *
+  * This operation gives the maximum number of bytes that can be sent
+  * at a time through the send function when using the network designated by
+  * 'resource_id' and sending it to 'destination'.
+  *
+  * If the application needs to send bigger messages it will have to
+  * split them.
+  *
+  * Some protocols, like IP, are capable of sending large messages
+  * (and use fragmentation internally) but other protocols don't.
+  *
+  * @param[in] resource_id The network we want the tx time from.
+  * @param[in] destination The destination address
+  * @param[out] max_size The maximum number of bytes for each message
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or destination is
+  *   invalid \n
+  *
+  **/
+ int rtep_fna_network_get_max_message_size
+                 (const frsh_resource_id_t resource_id,
+                  const frsh_network_address_t destination,
+                  size_t *max_size)
+ {
+         int is_multicast;
+         if (max_size == NULL) {
+                 return -1;
+         }
+         is_multicast = rtep_valid_multicast_id((rtep_station_id_t) destination);
+         if (is_multicast) {
+                 *max_size = MULTICAST_MTU;
+         } else {
+                 *max_size = MAX_RTEP_MTU;
+         }
+         return 0;
+ }
+ /**
+  * rtep_fna_network_bytes_to_budget()
+  *
+  * This operation converts a number of bytes into a temporal budget for
+  * a specific network. Network overheads are not included here but are
+  * considered internally when negotiating a specific contract.
+  *
+  * @param[in] resource_id The network
+  * @param[in] nbytes Number of bytes
+  * @param[out] budget The network budget for nbytes
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or nbytes is less
+  *   than zero \n
+  *
+  **/
+ int rtep_fna_network_bytes_to_budget
+                 (const frsh_resource_id_t resource_id,
+                  const size_t nbytes,
+                  struct timespec *budget)
+ {
+         int number_of_packets;
+         if (budget == NULL || nbytes < 0) {
+                 return -1;
+         }
+         // we measure the budget in number of RTEP packets of maximum size
+         number_of_packets = nbytes / MAX_RTEP_MTU + 1;
+         // we store the budget in number of packets instead of in time. We
+         // use a field in the timespec structure.
+         budget->tv_sec = number_of_packets;
+         DEBUG("bytes: %d -> budget: %d\n", nbytes, budget->tv_sec);
+         return 0;
+ }
+ /**
+  * rtep_fna_network_budget_to_bytes()
+  *
+  * This operation converts a temporal budget into a number of bytes for
+  * a specific network. Network overheads are not included.
+  *
+  * @param[in] resource_id The network
+  * @param[in] budget The network budget for nbytes
+  * @param[out] nbytes Number of bytes
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or budget refers to
+  *   an invalid time value \n
+  *
+  **/
+ int rtep_fna_network_budget_to_bytes
+                 (const frsh_resource_id_t resource_id,
+                  const struct timespec *budget,
+                  size_t *nbytes)
+ {
+         int number_of_packets;
+         if (budget == NULL || nbytes == NULL) {
+                 return -1;
+         }
+         number_of_packets = budget->tv_sec;
+         *nbytes = number_of_packets * MAX_RTEP_MTU;
+         return 0;
+ }
+ /**
+  * rtep_fna_network_get_min_eff_budget()
+  *
+  * This operation gets the minimum effective budget for a network. Each message
+  * consumes a contracted budget in "chunks" (i.e: packets) that we call
+  * minimum effective budget.
+  *
+  * A negotiated contract, for N bytes in a period T, means that there is a
+  * virtual resource that reserves for the user:
+  *
+  *   Ceiling ((N bytes) / budget_to_bytes (min_effective_budget)) "CHUNKS"
+  *
+  * Note that if the user decides not to send these N bytes at once but, say,
+  * one byte at a time, it will consume one "CHUNK" at a time and the reserved
+  * budget will become exhausted before sending all the bytes.
+  *
+  * @param[in] resource_id The network
+  * @param[out] budget The network budget
+  *
+  * @return
+  *   0 if there are no errors \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+  *   a network accessible from the current processing node \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int rtep_fna_network_get_min_eff_budget
+                 (const frsh_resource_id_t resource_id,
+                  struct timespec *budget)
+ {
+         if (budget == NULL) {
+                 return -1;
+         }
+         budget->tv_sec = 1;
+         return 0;
+ }
+ // GLOBAL variable to install the network protocol in FRESCOR
+ fna_operations_t rtep_fna_operations = {
+ #ifdef CONFIG_FNA_RTEP_CONNECTED
+         .fna_init = rtep_fna_init,
+         .fna_contract_negotiate = rtep_fna_contract_negotiate,
+         .fna_contract_renegotiate_sync = rtep_fna_contract_renegotiate_sync,
+         .fna_contract_renegotiate_async = rtep_fna_contract_renegotiate_async,
+         .fna_vres_get_renegotiation_status = rtep_fna_vres_get_renegotiation_status,
+         .fna_vres_destroy = rtep_fna_vres_destroy,
+         .fna_vres_get_contract = rtep_fna_vres_get_contract,
+         .fna_vres_get_usage = rtep_fna_vres_get_usage,
+         .fna_vres_get_remaining_budget = rtep_fna_vres_get_remaining_budget,
+         .fna_vres_get_budget_and_period = rtep_fna_vres_get_budget_and_period,
+         .fna_resource_get_capacity = rtep_fna_resource_get_capacity,
+         .fna_resource_get_total_weight = rtep_fna_resource_get_total_weight,
+         .fna_vres_decrease_capacity = rtep_fna_vres_decrease_capacity,
+         .fna_send_sync = rtep_fna_send_sync,
+         .fna_send_async = rtep_fna_send_async,
+         .fna_receive_sync = rtep_fna_receive_sync,
+         .fna_receive_async = rtep_fna_receive_async,
+         .fna_send_endpoint_get_status = rtep_fna_send_endpoint_get_status,
+         .fna_receive_endpoint_created = rtep_fna_receive_endpoint_created,
+         .fna_receive_endpoint_get_status = rtep_fna_receive_endpoint_get_status,
+ #endif
+         .fna_network_get_max_message_size = rtep_fna_network_get_max_message_size,
+         .fna_network_bytes_to_budget = rtep_fna_network_bytes_to_budget,
+         .fna_network_budget_to_bytes = rtep_fna_network_budget_to_bytes,
+         .fna_network_get_min_eff_budget = rtep_fna_network_get_min_eff_budget
+ };
index 0000000000000000000000000000000000000000,f2c549fad56b5058bb96e50a02f20de1b2677278..f2c549fad56b5058bb96e50a02f20de1b2677278
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,240 +1,240 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include "frsh_fna.h"
+ #include "rtep_bandwith_reservation.h"
+ //////////////////////////////////////////////////////////////////////
+ //           MAPPING FUNCTIONS
+ //////////////////////////////////////////////////////////////////////
+ /**
+  * frsh_XXXX_map_network_address()
+  *
+  * To map a XXXX protocol network address into a FRSH address.
+  * The protocol must keep this mapping consistent. Instead of using a function
+  * a hardwired mapping could be used.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] in_address The network address we want to map to a frsh address
+  * @param[out] out_address The FRSH abstract network address
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_rtep_map_network_address
+       (const frsh_resource_id_t resource_id,
+        const rtep_station_id_t in_address,
+        frsh_network_address_t *out_address)
+ {
+     if (out_address == NULL) return -1;
+     *out_address = in_address;
+     return 0;
+ }
+ /**
+  * frsh_XXXX_map_stream_id()
+  *
+  * To map a XXXX protocol network stream, port, channel... into a FRSH stream.
+  * The protocol must keep this mapping consistent. Instead of using a function
+  * a hardwired mapping could be used.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] in_stream The network stream we want to map to a FRSH stream
+  * @param[out] out_stream The FRSH abstract network stream
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_rtep_map_stream_id
+       (const frsh_resource_id_t resource_id,
+        const rtep_channel_t in_stream,
+        frsh_stream_id_t *out_stream)
+ {
+     if (out_stream == NULL) return -1;
+     *out_stream = in_stream;
+     return 0;
+ }
+ ///////////////////////////////////////////////////////////////////
+ //           NEGOTIATION SERVICE PARAMETERS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * frsh_XXXX_negotiation_messages__vres_renegotiate()
+  *
+  * This function allows the application to change the minimum period
+  * of the negotiation messages sent through the network. It is similar
+  * to the service thread but for the network messages. We do not provide
+  * budget here because the size of the negotiation messages is fixed.
+  *
+  * This change is similar to a renegotiation so a schedulability test
+  * must be done to see if the change can be accepted or not.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] period The new period for negotiation messages
+  * @param[out] accepted If the change has been accepted or not
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_rtep_negotiation_messages_vres_renegotiate
+       (const frsh_resource_id_t resource_id,
+        const struct timespec *period)
+ {
+     return rtep_bwres_renegotiate_negotiation_period(period);
+ }
+ /**
+  * frsh_XXXX_negotiation_messages_vres_get_period()
+  *
+  * This function gets the minimum period of the negotiation messages
+  * sent through the network.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[out] period The period for negotiation messages
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_rtep_negotiation_messages_vres_get_period
+       (const frsh_resource_id_t resource_id,
+        struct timespec *period)
+ {
+     return rtep_bwres_get_negotiation_period (period);
+ }
+ /**
+  * frsh_XXXX_service_thread_vres_renegotiate()
+  *
+  * This function allows the application to change the period and
+  * budget of the service thread that makes the negotiations and
+  * schedulability tests in a network.
+  *
+  * The service thread starts with a default budget and period that
+  * should be configurable
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[in] budget The new budget for the service thread
+  * @param[in] period The new period for the service thread
+  * @param[out] accepted If the negotiation has been accepted or not
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_rtep_service_thread_vres_renegotiate
+    (const frsh_resource_id_t resource_id,
+     const struct timespec *budget,
+     const struct timespec *period,
+     bool *accepted)
+ {
+     return -1;
+ }
+ /**
+  * frsh_XXXX_service_thread_vres_get_budget_and_period()
+  *
+  * This function gets the budget and period of a service thread.
+  *
+  * @param[in] resource_id The network we are referring to (a protocol
+  * could be able to handle several networks at the same time)
+  * @param[out] budget The budget of the service thread
+  * @param[out] period The period of the service thread
+  *
+  * @return
+  *   FNA_NO_ERROR: in this case it also means contract accepted \n
+  *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+  *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+  *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+  *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+  *
+  **/
+ int frsh_rtep_service_thread_vres_get_budget_and_period
+       (const frsh_resource_id_t resource_id,
+        struct timespec *budget,
+        struct timespec *period)
+ {
+     return -1;
+ }
index 0000000000000000000000000000000000000000,84e259d98fa833529a75390ba8f6e8885f85896a..84e259d98fa833529a75390ba8f6e8885f85896a
mode 000000,100755..100755
--- /dev/null
@@@ -1,0 -1,20 +1,20 @@@
+ .PHONY: all objs libunixfna.a
+ all: libunixfna.a
+ include ../config.mk
+ include ../rules.mk
+ SRCS := $(wildcard *.c)
+ OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
+ HDRS := $(wildcard $(FNA_PATH)/include/*.h)
+ objs: $(OBJS)
+ %.o: %.c $(SRCS) $(HDRS)
+       $(CC) $(CFLAGS) -c $<
+ libunixfna.a: objs
+       @exec echo -e "\n>> Building UNIX FNA:";
+       @ar -rc libunixfna.a *.o
+       @mv libunixfna.a $(FNA_PATH)/lib
+       @exec echo ">> end Building UNIX FNA  [OK]"
index 0000000000000000000000000000000000000000,3b41e85e9adebe4c5d23b69ccbcb210aca44e6f8..3b41e85e9adebe4c5d23b69ccbcb210aca44e6f8
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,2 +1,2 @@@
+ lib_LIBRARIES=unixfna
+ unixfna_SOURCES=$(notdir $(wildcard $(SOURCES_DIR)/*.c))
index 0000000000000000000000000000000000000000,472c009b81d396a92043161ab45cc22695c05344..472c009b81d396a92043161ab45cc22695c05344
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,588 +1,588 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ //==============================================
+ //  ******** ****     **     **
+ //  **///// /**/**   /**    ****
+ //  **      /**//**  /**   **//**
+ //  ******* /** //** /**  **  //**
+ //  **////  /**  //**/** **********
+ //  **      /**   //****/**//////**
+ //  **      /**    //***/**     /**
+ //  /       //      /// //      //
+ //
+ // FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
+ //==============================================================
+ /**
+  * unix fna implementation
+  *
+  * In the following functions we implement a DUMMY FNA implementation without
+  * contracts or real-time requirements just for testing purposes. We provide
+  * send/receive capabilities between Linux processes through UNIX domain
+  * datagram sockets.
+  *
+  * The goal is to run FRSH on several processes by using the Linux_lib arch
+  * of MaRTE OS or Partikle to simulate a distributed system in a single PC.
+  *
+  * The main tricks of the implementation are the following:
+  *
+  *   - We encode the address and stream in the Unix socket path as:
+  *                    '/tmp/unix_fna-address-stream'
+  *   - At initialization we create MX_UNIX_STREAM_IDS sockets for our address
+  *     (our address number is defined by FRSH_CPU_ID_DEFAULT)
+  *   - When the user SENDS we obtain the address creating the mentioned string
+  *     from the destination address and the stream.
+  *   - When the user RECEIVES we use the appropiate socket by using the
+  *     stream_id information.
+  *
+  **/
+ #include <malloc.h>   /* for malloc and free */
+ #include <assert.h>
+ #include <string.h>   /* for string functions: strtok, strcpy, ... */
+ #include "frsh_distributed_types.h" /* for frsh_network_address_t, frsh_stream_id_t */
+ #include "unix_fna.h" /* function prototypes */
+ #include <sys/socket.h>
+ #include <sys/un.h>
+ /* DEBUGGING FLAGS and MACROS */
+ #include <stdio.h>
+ #define DEBUG(enable,x,args...) if(enable) printf("\t>> Called %s: " x, __func__ , ##args)
+ #define DBG_UNIX_FNA_NOT_IMPLEMENTED true
+ /**
+  * to_unix_path()
+  *
+  **/
+ static int to_unix_path(const frsh_network_address_t addr,
+                         const frsh_stream_id_t       stream,
+                         char                         *str,
+                         size_t                       mx_size)
+ {
+         return snprintf(str, mx_size, "/tmp/unix_fna-%d-%d", addr, stream);
+ }
+ /**
+  * to_addr_stream()
+  *
+  **/
+ static int to_addr_stream(frsh_network_address_t *addr,
+                           frsh_stream_id_t       *stream,
+                           char                   *str,
+                           size_t                 size)
+ {
+         char *token;
+         char *search = "-";
+         token = strtok(str, search);
+         token = strtok(NULL, search);
+         *addr = atoi(token);
+         token = strtok(NULL, search);
+         *stream = atoi(token);
+         return 0;
+ }
+ //////////////////////////////////////////////////////////////////////
+ //           INITIALIZATION
+ //////////////////////////////////////////////////////////////////////
+ int the_unix_sockets[MX_UNIX_STREAM_IDS];
+ /**
+  * unix_fna_init()
+  *
+  * for each stream_id create a socket and bind it to the address obtained
+  * from "/tmp/unix_fna-addr-stream"
+  *
+  **/
+ int unix_fna_init(const frsh_resource_id_t resource_id)
+ {
+         int i, err;
+         struct sockaddr_un sock_addr;
+         DEBUG(true, "creating unix sockets\n");
+         for(i=0; i<MX_UNIX_STREAM_IDS; i++) {
+                 the_unix_sockets[i] = socket(AF_UNIX, SOCK_DGRAM, 0);
+                 assert(the_unix_sockets[i] >= 0);
+                 memset(&sock_addr, 0, sizeof(sock_addr));
+                 sock_addr.sun_family = AF_UNIX;
+                 err = to_unix_path(FRSH_CPU_ID_DEFAULT,
+                                    (frsh_stream_id_t) i,
+                                    sock_addr.sun_path,
+                                    sizeof(sock_addr.sun_path));
+                 assert(err >= 0);
+                 err = bind(the_unix_sockets[i],
+                            (struct sockaddr *)&sock_addr,
+                            sizeof(sock_addr));
+                 assert(err >= 0);
+         }
+         return 0;
+ }
+ ///////////////////////////////////////////////////////////////////
+ //           VIRTUAL RESOURCES
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * unix_fna_contract_negotiate()
+  *
+  **/
+ int unix_fna_contract_negotiate(const frsh_resource_id_t resource_id,
+                                 const frsh_contract_t *contract,
+                                 fna_vres_id_t *vres)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_contract_renegotiate_sync()
+  *
+  **/
+ int unix_fna_contract_renegotiate_sync(const frsh_resource_id_t resource_id,
+                                        const fna_vres_id_t vres,
+                                        const frsh_contract_t *new_contract)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_contract_renegotiate_async()
+  *
+  **/
+ int unix_fna_contract_renegotiate_async(const frsh_resource_id_t resource_id,
+                                         const fna_vres_id_t vres,
+                                         const frsh_contract_t *new_contract,
+                                         frsh_signal_t signal_to_notify,
+                                         frsh_signal_info_t signal_info)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_vres_get_renegotiation_status()
+  *
+  **/
+ int unix_fna_vres_get_renegotiation_status(const frsh_resource_id_t resource_id,
+                                            const fna_vres_id_t vres,
+                                            frsh_renegotiation_status_t *renegotiation_status)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_vres_destroy()
+  *
+  **/
+ int unix_fna_vres_destroy(const frsh_resource_id_t resource_id,
+                           const fna_vres_id_t vres)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_vres_get_contract()
+  *
+  **/
+ int unix_fna_vres_get_contract(const frsh_resource_id_t resource_id,
+                                const fna_vres_id_t vres,
+                                frsh_contract_t *contract)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_vres_get_usage()
+  *
+  **/
+ int unix_fna_vres_get_usage(const frsh_resource_id_t resource_id,
+                             const fna_vres_id_t vres,
+                             struct timespec *usage)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_vres_get_remaining_budget()
+  *
+  **/
+ int unix_fna_vres_get_remaining_budget(const frsh_resource_id_t resource_id,
+                                        const fna_vres_id_t vres,
+                                        struct timespec *remaining_budget)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_vres_get_budget_and_period()
+  *
+  **/
+ int unix_fna_vres_get_budget_and_period(const frsh_resource_id_t resource_id,
+                                         const fna_vres_id_t vres,
+                                         struct timespec *budget,
+                                         struct timespec *period)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ ///////////////////////////////////////////////////////////////////
+ //           SPARE CAPACITY FUNCIONS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * unix_fna_resource_get_capacity()
+  *
+  **/
+ int unix_fna_resource_get_capacity(const frsh_resource_id_t resource_id,
+                                    const int importance,
+                                    uint32_t *capacity)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_resource_get_total_weight()
+  *
+  **/
+ int unix_fna_resource_get_total_weight(const frsh_resource_id_t resource_id,
+                                        const int importance,
+                                        int *total_weight)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_vres_decrease_capacity()
+  *
+  **/
+ int unix_fna_vres_decrease_capacity(const frsh_resource_id_t resource_id,
+                                     const fna_vres_id_t vres,
+                                     const struct timespec new_budget,
+                                     const struct timespec new_period)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ ///////////////////////////////////////////////////////////////////
+ //           SEND RECEIVE OPERATIONS
+ ///////////////////////////////////////////////////////////////////
+ /**
+  * unix_fna_send_sync()
+  *
+  **/
+ int unix_fna_send_sync(const fna_endpoint_data_t *endpoint,
+                        const void *msg,
+                        const size_t size)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_send_async()
+  *
+  * To send we use one of our sockets (it doesn't matter which one so we use
+  * the first one). The destination is obtained from the endpoint values for
+  * dest and stream.
+  *
+  **/
+ int unix_fna_send_async(const fna_endpoint_data_t *endpoint,
+                         const void *msg,
+                         const size_t size)
+ {
+         int err;
+         struct sockaddr_un to;
+         ssize_t sent_bytes;
+         DEBUG(true, "send async\n");
+         assert(endpoint->is_bound);
+         memset(&to, 0, sizeof(to));
+         to.sun_family = AF_UNIX;
+         err = to_unix_path(endpoint->destination,
+                            endpoint->stream_id,
+                            to.sun_path,
+                            sizeof(to.sun_path));
+         assert(err >= 0);
+         sent_bytes = sendto(the_unix_sockets[0],
+                             msg,
+                             size,
+                             0,
+                             (struct sockaddr *) &to,
+                             sizeof(to));
+         assert(sent_bytes >= 0);
+         return 0;
+ }
+ /**
+  * unix_fna_receive_sync()
+  *
+  * We call recvfrom using the socket associated to the corresponding stream_id.
+  * The "from" address is obtained by parsing the unix address path.
+  *
+  **/
+ int unix_fna_receive_sync(const fna_endpoint_data_t *endpoint,
+                           void *buffer,
+                           const size_t buffer_size,
+                           size_t *received_bytes,
+                           frsh_network_address_t *from)
+ {
+         int err;
+         struct sockaddr_un sender_addr;
+         ssize_t recv_bytes;
+         socklen_t from_len;
+         frsh_network_address_t addr;
+         frsh_stream_id_t       stream;
+         DEBUG(true, "receive sync\n");
+         from_len = sizeof(sender_addr);
+         recv_bytes = recvfrom(the_unix_sockets[endpoint->stream_id],
+                               buffer,
+                               buffer_size,
+                               0,
+                               (struct sockaddr *)&sender_addr,
+                               &from_len);
+         assert(recv_bytes >= 0);
+         *received_bytes = recv_bytes;
+         err = to_addr_stream(&addr,
+                              &stream,
+                              sender_addr.sun_path,
+                              sizeof(sender_addr.sun_path));
+         assert(err == 0);
+         *from = addr;
+         return 0;
+ }
+ /**
+  * unix_fna_receive_async()
+  *
+  **/
+ int unix_fna_receive_async(const fna_endpoint_data_t *endpoint,
+                            void *buffer,
+                            const size_t buffer_size,
+                            size_t *received_bytes,
+                            frsh_network_address_t *from)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_send_endpoint_get_status()
+  *
+  **/
+ int unix_fna_send_endpoint_get_status(const fna_endpoint_data_t *endpoint,
+                                       int *number_of_pending_messages,
+                                       frsh_endpoint_network_status_t *network_status,
+                                       frsh_protocol_status_t *protocol_status)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_receive_endpoint_created()
+  *
+  **/
+ int unix_fna_receive_endpoint_created(fna_endpoint_data_t *endpoint)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_receive_endpoint_get_pending_messages
+  *
+  **/
+ int unix_fna_receive_endpoint_get_status(const fna_endpoint_data_t *endpoint,
+                                          int *number_of_pending_messages,
+                                          frsh_endpoint_network_status_t *network_status,
+                                          frsh_protocol_status_t *protocol_status)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ //////////////////////////////////////////////////////////////////////
+ //           NETWORK CONFIGURATION FUNCTIONS
+ //////////////////////////////////////////////////////////////////////
+ /**
+  * unix_fna_network_get_max_message_size()
+  *
+  **/
+ int unix_fna_network_get_max_message_size(const frsh_resource_id_t resource_id,
+                                           const frsh_network_address_t destination,
+                                           size_t *max_size)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_network_bytes_to_budget()
+  *
+  **/
+ int unix_fna_network_bytes_to_budget(const frsh_resource_id_t resource_id,
+                                      const size_t nbytes,
+                                      struct timespec *budget)
+ {
+         DEBUG(true, "let's put 1 microsecond for all\n");
+         budget->tv_sec  = 0;
+         budget->tv_nsec = 1000;
+         return 0;
+ }
+ /**
+  * unix_fna_network_budget_to_bytes()
+  *
+  **/
+ int unix_fna_network_budget_to_bytes(const frsh_resource_id_t resource_id,
+                                      const struct timespec *budget,
+                                      size_t *nbytes)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ /**
+  * unix_fna_network_get_min_eff_budget()
+  *
+  **/
+ int unix_fna_network_get_min_eff_budget(const frsh_resource_id_t resource_id,
+                                         struct timespec *budget)
+ {
+         DEBUG(DBG_UNIX_FNA_NOT_IMPLEMENTED, "NOT IMPLEMENTED\n");
+         return 0;
+ }
+ // GLOBAL variable to install the network protocol in FRESCOR
+ fna_operations_t unix_fna_operations = {
+         .fna_init = unix_fna_init,
+         .fna_contract_negotiate = unix_fna_contract_negotiate,
+         .fna_contract_renegotiate_sync = unix_fna_contract_renegotiate_sync,
+         .fna_contract_renegotiate_async = unix_fna_contract_renegotiate_async,
+         .fna_vres_get_renegotiation_status = unix_fna_vres_get_renegotiation_status,
+         .fna_vres_destroy = unix_fna_vres_destroy,
+         .fna_vres_get_contract = unix_fna_vres_get_contract,
+         .fna_vres_get_usage = unix_fna_vres_get_usage,
+         .fna_vres_get_remaining_budget = unix_fna_vres_get_remaining_budget,
+         .fna_vres_get_budget_and_period = unix_fna_vres_get_budget_and_period,
+         .fna_resource_get_capacity = unix_fna_resource_get_capacity,
+         .fna_resource_get_total_weight = unix_fna_resource_get_total_weight,
+         .fna_vres_decrease_capacity = unix_fna_vres_decrease_capacity,
+         .fna_send_sync = unix_fna_send_sync,
+         .fna_send_async = unix_fna_send_async,
+         .fna_receive_sync = unix_fna_receive_sync,
+         .fna_receive_async = unix_fna_receive_async,
+         .fna_send_endpoint_get_status = unix_fna_send_endpoint_get_status,
+         .fna_receive_endpoint_created = unix_fna_receive_endpoint_created,
+         .fna_receive_endpoint_get_status = unix_fna_receive_endpoint_get_status,
+         .fna_network_get_max_message_size = unix_fna_network_get_max_message_size,
+         .fna_network_bytes_to_budget = unix_fna_network_bytes_to_budget,
+         .fna_network_budget_to_bytes = unix_fna_network_budget_to_bytes,
+         .fna_network_get_min_eff_budget = unix_fna_network_get_min_eff_budget
+ };
index 0000000000000000000000000000000000000000,91cc63964e188cb344840264e04d0cd56c64c7c5..91cc63964e188cb344840264e04d0cd56c64c7c5
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,76 +1,76 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ //==============================================
+ //  ******** ****     **     **
+ //  **///// /**/**   /**    ****
+ //  **      /**//**  /**   **//**
+ //  ******* /** //** /**  **  //**
+ //  **////  /**  //**/** **********
+ //  **      /**   //****/**//////**
+ //  **      /**    //***/**     /**
+ //  /       //      /// //      //
+ //
+ // FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
+ //==============================================================
+ #ifndef _UNIX_FNA_H_
+ #define _UNIX_FNA_H_
+ #include "fna.h" // for fna_operations_t
+ extern fna_operations_t unix_fna_operations;
+ #define MX_UNIX_STREAM_IDS      6
+ #define MX_UNIX_NETWORK_ADDR    3
+ #endif // _UNIX_FNA_H_
index 0000000000000000000000000000000000000000,de7908c3699cc6bfdc985dc7262808451d02f39a..de7908c3699cc6bfdc985dc7262808451d02f39a
mode 000000,100755..100755
--- /dev/null
@@@ -1,0 -1,7 +1,7 @@@
+ .PHONY: tests
+ include ../../config.mk
+ include ../../rules.mk
+ EXES := $(patsubst %.c,%.exe,$(wildcard *.c))
+ tests: $(EXES)
index 0000000000000000000000000000000000000000,c5a24104e02babcedd48ab7eecdf3f97df940238..c5a24104e02babcedd48ab7eecdf3f97df940238
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,203 +1,203 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 0
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         frescan_ss_t ss1, ss2, ss3;
+         frsh_contract_t contract;
+         bool accepted;
+         frescan_server_params_t server_params;
+         frsh_rel_time_t budget_min, period_max;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         ret = frsh_contract_init(&contract);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         budget_min.tv_sec = 5;
+         period_max = frsh_msec_to_rel_time(3333);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 7);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss1, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss1);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss1);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         budget_min.tv_sec = 6;
+         period_max = frsh_msec_to_rel_time(2600);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                           &budget_min,
+                           &period_max,
+                           FRSH_WT_INDETERMINATE,
+                           FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 4);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss2, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss2);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss2);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         ret = frescan_bwres_cancel(NETWORK, ss1);
+         if (ret != 0) PUT_ERROR ("could not cancel server");
+         budget_min.tv_sec = 1;
+         period_max = frsh_msec_to_rel_time(6666);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 3);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss3, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss3);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss3);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         while (1) {
+                 sleep(1);
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,01fcaea6c329ba2ae583d6e03d57cb2722a2f946..01fcaea6c329ba2ae583d6e03d57cb2722a2f946
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,207 +1,207 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 1
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         frescan_ss_t ss1, ss2, ss3;
+         frsh_contract_t contract;
+         frescan_server_params_t server_params;
+         bool accepted;
+         frsh_rel_time_t budget_min, period_max;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         ret = frsh_contract_init(&contract);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         budget_min.tv_sec = 5;
+         period_max = frsh_msec_to_rel_time(3000);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 5);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         printf("Negotiating a contract 1\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss1, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss1);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss1);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         budget_min.tv_sec = 6;
+         period_max = frsh_msec_to_rel_time(2600);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                           &budget_min,
+                           &period_max,
+                           FRSH_WT_INDETERMINATE,
+                           FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 4);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         printf("Negotiating a contract 2\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss2, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss2);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss2);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         printf("cancelling contract for ss:%u\n", ss1);
+         ret = frescan_bwres_cancel(NETWORK, ss1);
+         if (ret != 0) PUT_ERROR ("could not cancel server");
+         budget_min.tv_sec = 1;
+         period_max = frsh_msec_to_rel_time(6666);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                           &budget_min,
+                           &period_max,
+                           FRSH_WT_INDETERMINATE,
+                           FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 3);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         printf("Negotiating a contract 3\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss3, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss3);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss3);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         while (1) {
+                 sleep(1);
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,9336daac0273829de2d95d1419af38c8eaa409c0..9336daac0273829de2d95d1419af38c8eaa409c0
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,203 +1,203 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include <assert.h>
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define ENABLE_MEASURES
+ #ifdef ENABLE_MEASURES
+ #include <misc/time_measurement_hwtime.h>
+ #include <misc/logger.h>
+ static const trace_point_id_t BEGIN_GN_NEG = 0;
+ static const trace_point_id_t END_GN_NEG   = 1;
+ #endif
+ #define NETWORK 0
+ #define LOCAL_NODE 0
+ #define NUM_CONTRACTS 2 // 1 .. FRESCAN_BWRES_MAX_GROUP_OPS
+ // #define USE_GN
+ #if 0
+ #include <stdio.h>
+ #define DEBUG(x,args...) printf("%s: " x, __func__ , ##args)
+ #else
+ #define DEBUG(x,args...)
+ #endif
+ extern int frescan_fna_network_bytes_to_budget
+                                     (const frsh_resource_id_t resource_id,
+                                     const size_t nbytes,
+                                     frsh_rel_time_t *budget);
+ static void create_contract(frsh_contract_t *contract);
+ int main ()
+ {
+         int ret, i;
+         frescan_init_params_t init_params;
+         frescan_ss_group_t ss_new;
+         frsh_contracts_group_t contracts_to_neg;
+         bool accepted;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+ #ifdef ENABLE_MEASURES
+         ret = logger_init(LOG_ETHERNET);
+         assert(ret == 0);
+ #if (LOCAL_NODE == 0)
+         ret = time_measure_hwtime_init(BEGIN_GN_NEG, "master_begin");
+         assert(ret == 0);
+         ret = time_measure_hwtime_init(END_GN_NEG, "master_end");
+         assert(ret == 0);
+ #else
+         ret = time_measure_hwtime_init(BEGIN_GN_NEG, "slave_begin");
+         assert(ret == 0);
+         ret = time_measure_hwtime_init(END_GN_NEG, "slave_end");
+         assert(ret == 0);
+ #endif
+ #endif
+         DEBUG("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         assert(ret == 0);
+         DEBUG("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         assert(ret == 0);
+         DEBUG("Creating contracts\n");
+         for(i=0; i<NUM_CONTRACTS; i++) {
+                 contracts_to_neg.size = i + 1;
+                 DEBUG("Creating contract %d\n", contracts_to_neg.size);
+                 create_contract(&contracts_to_neg.contracts[i]);
+         }
+ #ifdef ENABLE_MEASURES
+         time_measure_hwtime_set_timestamp(BEGIN_GN_NEG);
+ #endif
+ #ifdef USE_GN
+         DEBUG("Negotiating GN\n");
+         ret = frescan_bwres_group_change_mode_sync(NETWORK, &contracts_to_neg,
+                                                    NULL, NULL, NULL, &ss_new,
+                                                    &accepted);
+         assert(ret == 0);
+         assert(accepted == true);
+ #else
+         for(i=0; i<NUM_CONTRACTS; i++) {
+                 DEBUG("Negotiating contract %d\n", contracts_to_neg.size);
+                 ret = frescan_bwres_negotiate(NETWORK,
+                                               &contracts_to_neg.contracts[i],
+                                               &ss_new.ss[i],
+                                               &accepted);
+                 assert(ret == 0);
+                 assert(accepted == true);
+         }
+ #endif
+ #ifdef ENABLE_MEASURES
+         time_measure_hwtime_set_timestamp(END_GN_NEG);
+         ret = time_measure_hwtime_write_membuffer(BEGIN_GN_NEG);
+         assert(ret == 0);
+         ret = time_measure_hwtime_write_membuffer(END_GN_NEG);
+         assert(ret == 0);
+         while (logger_manual_call() > 0);
+ #endif
+         DEBUG("MAIN DONE\n");
+         while(1) sleep(10);
+ }
+ static void create_contract(frsh_contract_t *contract)
+ {
+         int ret;
+         frsh_rel_time_t budget_min, period_max;
+         ret = frsh_contract_init(contract);
+         assert(ret == 0);
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 10, &budget_min);
+         assert(ret == 0);
+         period_max = frsh_msec_to_rel_time(3369); // 3,369 secs
+         ret = frsh_contract_set_basic_params
+                         (contract,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         assert(ret == 0);
+ //         DEBUG("Setting preemption level manually to the contract\n");
+ //         ret = frsh_contract_set_preemption_level(contract, 7);
+ //         assert(ret == 0);
+ }
index 0000000000000000000000000000000000000000,d2c041420a7037588b80d9b8086c5c274eacd855..d2c041420a7037588b80d9b8086c5c274eacd855
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,92 +1,92 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 0
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         printf("BWRES Initialized\n");
+         while (1) {
+                 sleep(1);
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,9440fd476b88aae9b45394ffa185a3ecf8f64b7b..9440fd476b88aae9b45394ffa185a3ecf8f64b7b
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,505 +1,505 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include <assert.h>
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_types.h"
+ #include "frescan_bwres_requests.h"
+ #include "frescan_bwres_robjs.h"
+ #include "frescan_bwres_fna.h"
+ #define NETWORK 0
+ #define LOCAL_NODE 1
+ #if 0
+ #include <stdio.h>
+ #define DEBUG(x,args...) printf("%s: " x, __func__ , ##args)
+ #else
+ #define DEBUG(x,args...)
+ #endif
+ #include <misc/time_measurement_hwtime.h>
+ #include <misc/logger.h>
+ static const trace_point_id_t BEGIN_MEASURE = 0;
+ static const trace_point_id_t END_MEASURE = 1;
+ static int frescan_request_to_gn_message
+                 (const frescan_bwres_request_data_t *data,
+                  uint8_t *msg,
+                  size_t  *size);
+ static int frescan_gn_message_to_request(const uint8_t *msg_to_parse,
+                                          frescan_bwres_request_data_t *data,
+                                          size_t size);
+ static void create_contract(frsh_contract_t *contract);
+ #define FRESCAN_BWRES_MX_MSG_SIZE 5000  // TODO: adjust to the accurate value
+ int main ()
+ {
+         int ret, i, j;
+         frescan_init_params_t init_params;
+         uint8_t msg[FRESCAN_BWRES_MX_MSG_SIZE];
+         size_t size;
+         frescan_bwres_request_data_t *req_in;
+         frescan_bwres_request_id_t req;
+         frescan_send_params_t send_params;
+         frescan_node_t from;
+         frescan_prio_t prio;
+         size_t recv_bytes;
+         frescan_recv_params_t recv_params;
+         frescan_bwres_request_data_t *req_out;
+         uint8_t *msg_to_parse;
+         ret = logger_init(LOG_ETHERNET);
+         assert(ret == 0);
+         ret = time_measure_hwtime_init(BEGIN_MEASURE, "measure_begin");
+         assert(ret == 0);
+         ret = time_measure_hwtime_init(END_MEASURE, "measure_end");
+         assert(ret == 0);
+         DEBUG("TEST for FRESCAN messages (NODE: %d)\n", LOCAL_NODE);
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         recv_params.net     = 0;
+         recv_params.channel = 5;
+         recv_params.flags   = FRESCAN_SYNC;
+         send_params.net = 0;
+         send_params.to = 1;
+         send_params.channel = 5;
+         send_params.flags = FRESCAN_FP | FRESCAN_ASYNC;;
+         send_params.prio = 3;
+         DEBUG("Calling frescan_init\n");
+         ret = frescan_init(&init_params);
+         assert(ret == 0);
+         ret = frescan_bwres_robjs_init(FRESCAN_BWRES_ROBJS_MX_CEILING);
+         assert(ret == 0);
+         ret = frescan_bwres_requests_init(FRESCAN_BWRES_REQ_MX_CEILING);
+         assert(ret == 0);
+         if (LOCAL_NODE == 0) {
+                 DEBUG("Preparing a GN request\n");
+                 ret = frescan_bwres_requests_alloc(&req);
+                 assert(ret == 0);
+                 ret = frescan_bwres_requests_get_data(req, &req_in);
+                 assert(ret == 0);
+                 req_in->net          = NETWORK;
+                 req_in->type         = FRESCAN_BWRES_REQ_GN;
+                 req_in->req          = req;
+                 req_in->request_node = LOCAL_NODE;
+                 for(i=0;i<FRESCAN_BWRES_MAX_GROUP_OPS;i++) {
+                         time_measure_hwtime_set_timestamp(BEGIN_MEASURE);
+                         req_in->contracts_to_neg = &req_in->contracts_to_neg_data;
+                         req_in->contracts_to_neg->size = i + 1;
+                         for(j=0; j<req_in->contracts_to_neg->size; j++) {
+                                 create_contract(&req_in->contracts_to_neg->contracts[j]);
+                         }
+                         req_in->contracts_to_reneg = &req_in->contracts_to_reneg_data;
+                         req_in->contracts_to_reneg->size = 0;
+                         req_in->ss_to_reneg = &req_in->ss_to_reneg_data;
+                         req_in->ss_to_reneg->size = 0;
+                         req_in->ss_to_cancel = &req_in->ss_to_cancel_data;
+                         req_in->ss_to_cancel->size = 0;
+                         req_in->ss_new = &req_in->ss_new_data;
+                         req_in->ss_new->size = 0;
+                         ret = frescan_bwres_robjs_alloc(&req_in->robj, FRESCAN_BWRES_MX_PRIO);
+                         assert(ret == 0);
+                         ret = frescan_request_to_gn_message(req_in, msg, &size);
+                         assert(ret == 0);
+                         ret = frescan_bwres_robjs_free(req_in->robj);
+                         assert(ret == 0);
+                         frescan_bwres_requests_free(req);
+                         ret = frescan_send(&send_params, msg, size);
+                         assert(ret == 0);
+                         DEBUG("Receiving reply\n");
+                         ret = frescan_recv(&recv_params,
+                                             msg,
+                                             sizeof(msg),
+                                             &recv_bytes,
+                                             &from,
+                                             &prio);
+                         assert(ret == 0);
+                         DEBUG("Reply received, sleep\n");
+                         time_measure_hwtime_set_timestamp(END_MEASURE);
+                         sleep(2);
+                 }
+                 ret = time_measure_hwtime_write_membuffer(BEGIN_MEASURE);
+                 assert(ret == 0);
+                 ret = time_measure_hwtime_write_membuffer(END_MEASURE);
+                 assert(ret == 0);
+                 while (logger_manual_call() > 0);
+         } else {
+                 while(1) {
+                         DEBUG("Blocking to receive the GN request\n");
+                         ret = frescan_recv(&recv_params,
+                                         msg,
+                                         sizeof(msg),
+                                         &recv_bytes,
+                                         &from,
+                                         &prio);
+                         assert(ret == 0);
+                         ret = frescan_bwres_requests_alloc(&req);
+                         assert(ret == 0);
+                         ret = frescan_bwres_requests_get_data(req, &req_out);
+                         assert(ret == 0);
+                         req_out->type = *((uint8_t *)msg);
+                         msg_to_parse = msg + sizeof(uint8_t);
+                         recv_bytes   = recv_bytes - sizeof(uint8_t);
+                         ret = frescan_gn_message_to_request(msg_to_parse,
+                                                             req_out,
+                                                             recv_bytes);
+                         assert(ret == 0);
+                         DEBUG("PARSING the GN request\n");
+                         assert(req_out->type == FRESCAN_BWRES_REQ_GN);
+                         DEBUG("req: %d\n", req_out->req);
+                         DEBUG("num new contracts: %d\n", req_out->contracts_to_neg->size);
+                         DEBUG("send reply\n");
+                         send_params.to = from;
+                         ret = frescan_send(&send_params, msg, recv_bytes);
+                         assert(ret == 0);
+                 }
+         }
+         DEBUG("TEST OK\n");
+         while (1) sleep(1);
+         return 0;
+ }
+ /**
+  *  FRESCAN_BWRES_REQ_GN (COPY AND PASTE FROM frescan_bwres_messages.c)
+  */
+ static int frescan_request_to_gn_message
+                 (const frescan_bwres_request_data_t *data,
+                  uint8_t *msg,
+                  size_t  *size)
+ {
+         int ret, i;
+         uint8_t *msg_begin, *msg_tmp;
+         size_t bytes_written;
+         msg_begin = msg;
+         // type: FRESCAN_GN_MESSAGE
+         *((uint8_t *)msg) = (uint8_t)FRESCAN_BWRES_REQ_GN;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         // req
+         *((frescan_bwres_request_id_t *)msg) = data->req;
+         bytes_written = sizeof(frescan_bwres_request_id_t);
+         msg = msg + bytes_written;
+         DEBUG("GN message req:%u\n", data->req);
+         // NEG-GROUP
+         DEBUG("NEG-GROUP num contracts:%d\n", data->contracts_to_neg->size);
+         *((uint8_t *)msg) = (uint8_t)data->contracts_to_neg->size;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         for (i=0; i<data->contracts_to_neg->size; i++) {
+                 // reserve 2 bytes for the size of the marshalled contract
+                 msg_tmp = msg;
+                 msg     = msg + sizeof(uint16_t);
+                 // marshal the contract
+                 ret = frsh_contract_marshal
+                                 (&data->contracts_to_neg->contracts[i],
+                                   msg,
+                                   FRESCAN_BWRES_MX_MSG_SIZE - (msg - msg_begin),
+                                   &bytes_written);
+                 assert(ret == 0);
+                 // write the size and update the message pointer msg
+                 *((uint16_t *)msg_tmp) = (uint16_t)bytes_written;
+                 msg = msg + bytes_written;
+                 DEBUG("contract[%d].size:%u\n", i, bytes_written);
+         }
+         // RENEG-GROUP
+         DEBUG("RENEG-GROUP num contracts:%d\n",data->contracts_to_reneg->size);
+         *((uint8_t *)msg) = (uint8_t)data->contracts_to_reneg->size;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         for (i=0; i<data->contracts_to_reneg->size; i++) {
+                 // write the ss
+                 *((uint16_t *)msg) = (uint16_t)data->ss_to_reneg->ss[i];
+                 bytes_written = sizeof(uint16_t);
+                 msg = msg + bytes_written;
+                 // reserve 2 bytes for the size of the marshalled contract
+                 msg_tmp = msg;
+                 msg     = msg + sizeof(uint16_t);
+                 // marshal the contract
+                 ret = frsh_contract_marshal
+                                 (&data->contracts_to_reneg->contracts[i],
+                                   msg,
+                                   FRESCAN_BWRES_MX_MSG_SIZE - (msg - msg_begin),
+                                   &bytes_written);
+                 assert(ret == 0);
+                 // write the size and update the message pointer msg
+                 *((uint16_t *)msg_tmp) = (uint16_t)bytes_written;
+                 msg = msg + bytes_written;
+                 DEBUG("contract[%d].size:%u ss[%d]:%u\n",
+                       i, bytes_written, i, data->ss_to_reneg->ss[i]);
+         }
+         // CANCEL-GROUP
+         DEBUG("CANCEL-GROUP num ss:%d\n", data->ss_to_cancel->size);
+         *((uint8_t *)msg) = (uint8_t)data->ss_to_cancel->size;
+         bytes_written = sizeof(uint8_t);
+         msg = msg + bytes_written;
+         for (i=0; i<data->ss_to_cancel->size; i++) {
+                 // write the ss
+                 *((uint16_t *)msg) = (uint16_t)data->ss_to_cancel->ss[i];
+                 bytes_written = sizeof(uint16_t);
+                 msg = msg + bytes_written;
+                 DEBUG("ss[%d]:%u\n", i, data->ss_to_cancel->ss[i]);
+         }
+         *size = msg - msg_begin;
+         DEBUG("size:%u\n", *size);
+         return 0;
+ }
+ static int frescan_gn_message_to_request(const uint8_t *msg_to_parse,
+                                          frescan_bwres_request_data_t *data,
+                                          size_t size)
+ {
+         int ret, i;
+         uint8_t *msg;
+         size_t bytes_read, contract_size;
+         msg = (uint8_t *)msg_to_parse;
+         data->contracts_to_neg   = &data->contracts_to_neg_data;
+         data->contracts_to_reneg = &data->contracts_to_reneg_data;
+         data->ss_to_reneg        = &data->ss_to_reneg_data;
+         data->ss_to_cancel       = &data->ss_to_cancel_data;
+         data->ss_new             = &data->ss_new_data;
+         // req
+         data->req = *((frescan_bwres_request_id_t *)msg);
+         bytes_read = sizeof(frescan_bwres_request_id_t);
+         msg = msg + bytes_read;
+         DEBUG("GN message req:%u\n", data->req);
+         // NEG-GROUP
+         data->contracts_to_neg->size = *((uint8_t *)msg);
+         bytes_read = sizeof(uint8_t);
+         msg = msg + bytes_read;
+         DEBUG("NEG-GROUP num contracts:%u\n", data->contracts_to_neg->size);
+         for (i=0; i<data->contracts_to_neg->size; i++) {
+                 contract_size = *((uint16_t *)msg);
+                 bytes_read = sizeof(uint16_t);
+                 msg = msg + bytes_read;
+                 // unmarshal the contract
+                 ret = frsh_contract_unmarshal
+                                 (&data->contracts_to_neg->contracts[i],
+                                   msg,
+                                   contract_size);
+                 assert(ret == 0);
+                 bytes_read = contract_size;
+                 msg = msg + bytes_read;
+                 DEBUG("contract[%d].size:%u\n", i, contract_size);
+         }
+          // RENEG-GROUP
+         data->contracts_to_reneg->size = *((uint8_t *)msg);
+         bytes_read = sizeof(uint8_t);
+         msg = msg + bytes_read;
+         DEBUG("RENEG-GROUP num contracts:%u\n",data->contracts_to_reneg->size);
+         for (i=0; i<data->contracts_to_reneg->size; i++) {
+                 data->ss_to_reneg->ss[i] = *((uint16_t *)msg);
+                 bytes_read = sizeof(uint16_t);
+                 msg = msg + bytes_read;
+                 contract_size = *((uint16_t *)msg);
+                 bytes_read = sizeof(uint16_t);
+                 msg = msg + bytes_read;
+                 // unmarshal the contract
+                 ret = frsh_contract_unmarshal
+                                 (&data->contracts_to_reneg->contracts[i],
+                                   msg,
+                                   contract_size);
+                 assert(ret == 0);
+                 bytes_read = contract_size;
+                 msg = msg + bytes_read;
+                 DEBUG("contract[%d].size:%u ss[%d]:%u\n",
+                       i, contract_size, i, data->ss_to_reneg->ss[i]);
+         }
+         // CANCEL-GROUP
+         data->ss_to_cancel->size = *((uint8_t *)msg);
+         bytes_read = sizeof(uint8_t);
+         msg = msg + bytes_read;
+         DEBUG("CANCEL-GROUP num ss:%u\n", data->ss_to_cancel->size);
+         for (i=0; i<data->ss_to_cancel->size; i++) {
+                 // write the ss
+                 data->ss_to_cancel->ss[i] = *((uint16_t *)msg);
+                 bytes_read = sizeof(uint16_t);
+                 msg = msg + bytes_read;
+                 DEBUG("ss[%d]:%u\n", i, data->ss_to_cancel->ss[i]);
+         }
+         return 0;
+ }
+ extern int frescan_fna_network_bytes_to_budget
+                 (const frsh_resource_id_t resource_id,
+                  const size_t nbytes,
+                  frsh_rel_time_t *budget);
+ static void create_contract(frsh_contract_t *contract)
+ {
+         int ret;
+         frsh_rel_time_t budget_min, period_max;
+         DEBUG("Creating contract\n");
+         ret = frsh_contract_init(contract);
+         assert(ret == 0);
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 10, &budget_min);
+         assert(ret == 0);
+         period_max = frsh_msec_to_rel_time(3369); // 3,369 secs
+         ret = frsh_contract_set_basic_params
+                         (contract,
+                           &budget_min,
+                           &period_max,
+                           FRSH_WT_INDETERMINATE,
+                           FRSH_CT_REGULAR);
+         assert(ret == 0);
+         DEBUG("Setting preemption level manually to the contract\n");
+         ret = frsh_contract_set_preemption_level(contract, 7);
+         assert(ret == 0);
+ }
index 0000000000000000000000000000000000000000,88c7388862e88069ecf45a1aa772ae2cd62ad611..88c7388862e88069ecf45a1aa772ae2cd62ad611
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,144 +1,144 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 0
+ extern int frescan_fna_network_bytes_to_budget
+                                     (const frsh_resource_id_t resource_id,
+                                     const size_t nbytes,
+                                     frsh_rel_time_t *budget);
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         frescan_ss_t ss;
+         frsh_contract_t contract;
+         bool accepted;
+         frescan_server_params_t server_params;
+         frsh_rel_time_t budget_min, period_max;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         printf("Creating contract\n");
+         ret = frsh_contract_init(&contract);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 10, &budget_min);
+         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
+         period_max = frsh_msec_to_rel_time(3369); // 3,369 secs
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         printf("Setting preemption level manually to the contract\n");
+         ret = frsh_contract_set_preemption_level(&contract, 7);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         printf("Negotiating contract\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         while (1) {
+                 sleep(1);
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,04ec4792f3a358e5583a81c4a22916b4e9a33d0d..04ec4792f3a358e5583a81c4a22916b4e9a33d0d
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,188 +1,188 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include <assert.h>
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 0
+ // #define ENABLE_LOGGING
+ #ifdef ENABLE_LOGGING
+ #include <drivers/console_switcher.h>
+ #include <misc/logger.h>
+ #include <assert.h>
+ #define LOG_DEVICE LOG_ETHERNET
+ #endif
+ extern int frescan_fna_network_bytes_to_budget
+                                     (const frsh_resource_id_t resource_id,
+                                     const size_t nbytes,
+                                     frsh_rel_time_t *budget);
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         frescan_ss_t ss;
+         frsh_contract_t contract;
+         frescan_server_params_t server_params;
+         bool accepted;
+         frsh_rel_time_t budget_min, period_max;
+ #ifdef ENABLE_LOGGING
+         ret = logger_init(LOG_DEVICE);
+         assert(ret == 0);
+         printf("Changing to membuffer console\n");
+         MEMBUFFER_CONSOLE_INIT();
+ #endif
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         ret = frsh_contract_init(&contract);
+         assert(ret == 0);
+         ret = frsh_network_bytes_to_budget(FRSH_NETWORK_ID_DEFAULT,
+                                            8*10,
+                                            &budget_min);
+         assert(ret == 0);
+         period_max.tv_sec = 1; period_max.tv_nsec = 0;
+         ret = frsh_contract_set_basic_params(&contract,
+                                              &budget_min,
+                                              &period_max,
+                                              FRSH_WT_INDETERMINATE,
+                                              FRSH_CT_REGULAR);
+         assert(ret == 0);
+         ret = frsh_contract_set_preemption_level(&contract, 5);
+         assert(ret == 0);
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
+         ret = frsh_contract_init(&contract);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 8*1, &budget_min);
+         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
+         period_max = frsh_msec_to_rel_time(2);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+         ret = frsh_contract_set_preemption_level(&contract, 8);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+         printf("Negotiating a contract\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         printf("MAIN DONE\n");
+ #ifdef ENABLE_LOGGING
+         while (logger_manual_call() > 0);
+ #endif
+         while (1) sleep(1);
+         return 0;
+ }
index 0000000000000000000000000000000000000000,9caf16e39a1dbcea523ff01708f6b1f2da92e3f5..9caf16e39a1dbcea523ff01708f6b1f2da92e3f5
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,142 +1,142 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 1
+ extern int frescan_fna_network_bytes_to_budget
+                                     (const frsh_resource_id_t resource_id,
+                                     const size_t nbytes,
+                                     frsh_rel_time_t *budget);
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         frescan_ss_t ss;
+         frsh_contract_t contract;
+         frescan_server_params_t server_params;
+         bool accepted;
+         frsh_rel_time_t budget_min, period_max;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         ret = frsh_contract_init(&contract);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 10, &budget_min);
+         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
+         period_max = frsh_msec_to_rel_time(3369); // 3,369 secs
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 5);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         printf("Negotiating a contract\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         while (1) {
+                 sleep(1);
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,39e443bbff845794cc9fba2bdaaaeaff61928b2f..39e443bbff845794cc9fba2bdaaaeaff61928b2f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,159 +1,159 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 1
+ // #define ENABLE_LOGGING
+ #ifdef ENABLE_LOGGING
+ #include <drivers/console_switcher.h>
+ #include <misc/logger.h>
+ #include <assert.h>
+ #define LOG_DEVICE LOG_ETHERNET
+ #endif
+ extern int frescan_fna_network_bytes_to_budget
+                                     (const frsh_resource_id_t resource_id,
+                                     const size_t nbytes,
+                                     frsh_rel_time_t *budget);
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         frescan_ss_t ss;
+         frsh_contract_t contract;
+         frescan_server_params_t server_params;
+         bool accepted;
+         frsh_rel_time_t budget_min, period_max;
+ #ifdef ENABLE_LOGGING
+         ret = logger_init(LOG_DEVICE);
+         assert(ret == 0);
+         printf("Changing to membuffer console\n");
+         MEMBUFFER_CONSOLE_INIT();
+ #endif
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         ret = frsh_contract_init(&contract);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 8*5, &budget_min);
+         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
+         period_max = frsh_msec_to_rel_time(1);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+         ret = frsh_contract_set_preemption_level(&contract, 6);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+         printf("Negotiating a contract\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         printf("MAIN DONE\n");
+ #ifdef ENABLE_LOGGING
+         while (logger_manual_call() > 0);
+ #endif
+         while (1) sleep(1);
+         return 0;
+ }
index 0000000000000000000000000000000000000000,37494cf9b36f2be3264bf119f8ce3df81f7bd504..37494cf9b36f2be3264bf119f8ce3df81f7bd504
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,155 +1,155 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 1
+ extern int frescan_fna_network_bytes_to_budget
+                                     (const frsh_resource_id_t resource_id,
+                                     const size_t nbytes,
+                                     frsh_rel_time_t *budget);
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         frescan_ss_t ss_sc;
+         frsh_contract_t contract_sc;
+         frescan_server_params_t server_params;
+         bool accepted;
+         frsh_rel_time_t budget_min, budget_max, period_max, period_min;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         printf("Create a contract with spare capacity\n");
+         ret = frsh_contract_init(&contract_sc);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 8*1, &budget_min);
+         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 8*5, &budget_max);
+         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
+         period_max = frsh_msec_to_rel_time(1); // 3,369 secs
+         period_min = period_max;
+         ret = frsh_contract_set_basic_params
+                         (&contract_sc,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+         ret = frsh_contract_set_preemption_level
+                         (&contract_sc, FRESCAN_BWRES_NEG_MSG_PRIO + 1);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+         ret = frsh_contract_set_reclamation_params(&contract_sc,
+                                                    0,
+                                                    &budget_max,
+                                                    &period_min,
+                                                    FRSH_GR_CONTINUOUS,
+                                                    NULL,
+                                                    1,
+                                                    1);
+         if (ret != 0) PUT_ERROR ("could not set reclamation params");
+         printf("Negotiating a contract\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract_sc, &ss_sc, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
+         if (accepted) {
+                 printf("The contract was accepted, ss_sc:%u\n", ss_sc);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss_sc);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         while (1) sleep(1);
+         return 0;
+ }
index 0000000000000000000000000000000000000000,72358a24ae9e6b3c56c0dc39754bf389dbfd5c05..72358a24ae9e6b3c56c0dc39754bf389dbfd5c05
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,208 +1,208 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 1
+ extern int frescan_fna_network_bytes_to_budget
+                                     (const frsh_resource_id_t resource_id,
+                                     const size_t nbytes,
+                                     frsh_rel_time_t *budget);
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         frescan_ss_t ss_sc, ss_no_sc;
+         frsh_contract_t contract_sc, contract_no_sc;
+         frescan_server_params_t server_params;
+         bool accepted;
+         frsh_rel_time_t budget_min, budget_max, period_max, period_min;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         printf("Create a contract with spare capacity\n");
+         ret = frsh_contract_init(&contract_sc);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 8*1, &budget_min);
+         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 8*5, &budget_max);
+         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
+         period_max = frsh_msec_to_rel_time(1); // 3,369 secs
+         period_min = period_max;
+         ret = frsh_contract_set_basic_params
+                         (&contract_sc,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+         ret = frsh_contract_set_preemption_level
+                         (&contract_sc, FRESCAN_BWRES_NEG_MSG_PRIO + 1);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+         ret = frsh_contract_set_reclamation_params(&contract_sc,
+                                                    0,
+                                                    &budget_max,
+                                                    &period_min,
+                                                    FRSH_GR_CONTINUOUS,
+                                                    NULL,
+                                                    1,
+                                                    1);
+         if (ret != 0) PUT_ERROR ("could not set reclamation params");
+         printf("Negotiating a contract\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract_sc, &ss_sc, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
+         if (accepted) {
+                 printf("The contract was accepted, ss_sc:%u\n", ss_sc);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss_sc);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         printf("Create a contract without spare capacity\n");
+         ret = frsh_contract_init(&contract_no_sc);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         ret = frescan_fna_network_bytes_to_budget (NETWORK, 8*2, &budget_min);
+         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
+         ret = frsh_contract_set_basic_params
+                         (&contract_no_sc,
+                          &budget_min,
+                          &period_max,
+                          FRSH_WT_INDETERMINATE,
+                          FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+         ret = frsh_contract_set_preemption_level
+                         (&contract_no_sc, FRESCAN_BWRES_NEG_MSG_PRIO + 2);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+         printf("Negotiating non sc contract\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract_no_sc,
+                                       &ss_no_sc, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
+         if (accepted) {
+                 printf("The contract was accepted, ss_no_sc:%u\n", ss_no_sc);
+                 ret = frescan_servers_get_data(NETWORK,
+                                                &server_params, ss_no_sc);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         printf("Get params from sc vres\n");
+         ret = frescan_servers_get_data(NETWORK,
+                                        &server_params, ss_sc);
+         if (ret != 0) PUT_ERROR ("could not get servers data");
+         printf("B:%u, T=(%u,%u), P:%u\n",
+                server_params.budget,
+                server_params.period.tv_sec,
+                server_params.period.tv_nsec,
+                server_params.prio);
+         printf("MAIN DONE\n");
+         while (1) sleep(1);
+         return 0;
+ }
index 0000000000000000000000000000000000000000,917871e12d4318e4411afed3da95d08fa6d6b2fc..917871e12d4318e4411afed3da95d08fa6d6b2fc
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,169 +1,169 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 0
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         frescan_ss_t ss;
+         frsh_contract_t contract;
+         bool accepted;
+         frescan_server_params_t server_params;
+         frsh_rel_time_t budget_min, period_max;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         ret = frsh_contract_init(&contract);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         budget_min.tv_sec = 5;
+         period_max = frsh_msec_to_rel_time(3369);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                           &budget_min,
+                           &period_max,
+                           FRSH_WT_INDETERMINATE,
+                           FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 7);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         printf("Renegotiate the contract in 2 seconds\n");
+         sleep(2);
+         budget_min.tv_sec = 7;
+         period_max = frsh_msec_to_rel_time(2450);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                           &budget_min,
+                           &period_max,
+                           FRSH_WT_INDETERMINATE,
+                           FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 8);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         ret = frescan_bwres_renegotiate(NETWORK, &contract, ss, &accepted);
+         if (ret != 0) PUT_ERROR ("could not renegotiate");
+         if (accepted) {
+                 printf("The contract renegotiation was accepted, ss:%u\n", ss);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         while (1) {
+                 sleep(1);
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,201cf841629b6411e400a5d551b6964865cfe5f1..201cf841629b6411e400a5d551b6964865cfe5f1
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,169 +1,169 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frsh.h"
+ #include "frescan.h"
+ #include "frescan_bwres.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 1
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         frescan_ss_t ss;
+         frsh_contract_t contract;
+         frescan_server_params_t server_params;
+         bool accepted;
+         frsh_rel_time_t budget_min, period_max;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 10;
+         init_params.rx_channel_max_prio = NULL;
+         printf("Initializing FRESCAN\n");
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("Initializing BWRES\n");
+         ret = frescan_bwres_init(NETWORK);
+         if (ret != 0) PUT_ERROR ("could not init BWRES");
+         ret = frsh_contract_init(&contract);
+         if (ret != 0) PUT_ERROR ("could not init contract");
+         budget_min.tv_sec = 5;
+         period_max = frsh_msec_to_rel_time(3369);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                           &budget_min,
+                           &period_max,
+                           FRSH_WT_INDETERMINATE,
+                           FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 5);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         printf("Negotiating a contract\n");
+         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
+         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
+         if (accepted) {
+                 printf("The contract was accepted, ss:%u\n", ss);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         printf("Renegotiate the contract in 2 seconds\n");
+         sleep(2);
+         budget_min.tv_sec = 2;
+         period_max = frsh_msec_to_rel_time(6430);
+         ret = frsh_contract_set_basic_params
+                         (&contract,
+                           &budget_min,
+                           &period_max,
+                           FRSH_WT_INDETERMINATE,
+                           FRSH_CT_REGULAR);
+         if (ret != 0) PUT_ERROR ("could not set basic params");
+ #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
+         ret = frsh_contract_set_preemption_level(&contract, 2);
+         if (ret != 0) PUT_ERROR ("could not set preemption level");
+ #endif
+         ret = frescan_bwres_renegotiate(NETWORK, &contract, ss, &accepted);
+         if (ret != 0) PUT_ERROR ("could not renegotiate");
+         if (accepted) {
+                 printf("The contract renegotiation was accepted, ss:%u\n", ss);
+                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
+                 if (ret != 0) PUT_ERROR ("could not get servers data");
+                 printf("B:%u, T=(%u,%u), P:%u\n",
+                        server_params.budget,
+                        server_params.period.tv_sec,
+                        server_params.period.tv_nsec,
+                        server_params.prio);
+         } else {
+                 printf("The contract was not accepted\n");
+         }
+         while (1) {
+                 sleep(1);
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,52ada0eef0b55069427bf74a483d6ec11e4bbb43..52ada0eef0b55069427bf74a483d6ec11e4bbb43
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,159 +1,159 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ /*!
+  * @file test_frescan_bwres_robjs_timedwait.c
+  *
+  * @brief test for the basic behaviour of timedwait
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author
+  *      Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @comments
+  *
+  * This file contains a basic test for the frescan_reply_objects module.
+  * The main thread allocates a reply object, creates a thread and waits
+  * on the reply object until the thread signals it. Then it waits again, but
+  * as the thread only signals the reply one time, this tima a timeout will be
+  * produced.
+  *
+  * @license
+  *
+  * See the COPYING file in the FNA's root directory
+  *
+  */
+ #include <stdio.h>  /* for printf */
+ #include <assert.h> /* for assert */
+ #include <unistd.h> /* for sleep */
+ #include "fosa_threads_and_signals.h" /* for fosa_thread_xxx */
+ #include "fosa_clocks_and_timers.h" /* for fosa_clock_get_time */
+ #include "frescan_bwres_robjs.h"
+ #define CEILING 10
+ static void *thread_code(void *arg);
+ int main()
+ {
+         int err;
+         frescan_bwres_robj_id_t id;
+         fosa_thread_attr_t th_attr;
+         fosa_thread_id_t tid;
+         struct timespec now;
+         printf("TEST REPLY OBJECTS\n");
+         err = fosa_thread_set_prio(fosa_thread_self(), CEILING - 2);
+         assert(err == 0);
+         err = frescan_bwres_robjs_init(CEILING);
+         assert(err == 0);
+         err = frescan_bwres_robjs_alloc(&id, CEILING);
+         assert(err == 0);
+         err = fosa_thread_attr_init(&th_attr);
+         assert(err == 0);
+         err = fosa_thread_attr_set_prio(&th_attr, CEILING - 1);
+         assert(err == 0);
+         err = fosa_thread_create (&tid, &th_attr, thread_code, (void *) id);
+         assert(err == 0);
+         err = fosa_thread_attr_destroy(&th_attr);
+         assert(err == 0);
+         err = fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &now);
+         assert(err == 0);
+         printf("wait: %d sec %d nsec\n", now.tv_sec, now.tv_nsec);
+         now.tv_sec = now.tv_sec + 2;
+         err = frescan_bwres_robjs_timedwait(id, &now);
+         assert (err == 0);
+         err = fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &now);
+         assert(err == 0);
+         printf("wait again: %d sec %d nsec\n", now.tv_sec, now.tv_nsec);
+         now.tv_sec = now.tv_sec + 2;
+         err = frescan_bwres_robjs_timedwait(id, &now);
+         assert (err == FRESCAN_ETIMEDOUT);
+         printf("timeout!: %d sec %d nsec\n", now.tv_sec, now.tv_nsec);
+         err = frescan_bwres_robjs_free(id);
+         assert(err == 0);
+         printf("TEST [OK!]\n");
+         return 0;
+ }
+ static void *thread_code(void *arg)
+ {
+         int err;
+         frescan_bwres_robj_id_t reply = (frescan_bwres_robj_id_t)arg;
+         printf("Thread signaling\n");
+         err = frescan_bwres_robjs_signal(reply);
+         assert(err == 0);
+         printf("Thread terminating\n");
+         return NULL;
+ }
index 0000000000000000000000000000000000000000,d9f6ee819e921fa81c3a4a9de79a9530403a5407..d9f6ee819e921fa81c3a4a9de79a9530403a5407
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,142 +1,142 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ /*!
+  * @file test_frescan_bwres_robjs_wait.c
+  *
+  * @brief test for the basic behaviour of reply objects
+  *
+  * @version 0.01
+  *
+  * @date 1-Apr-2008
+  *
+  * @author
+  *      Daniel Sangorrin <daniel.sangorrin@unican.es>
+  *
+  * @comments
+  *
+  * This file contains a basic test for the frescan_bwres_robjs module.
+  * The main thread allocates a reply object, creates a thread and waits
+  * on the reply object until the thread signals it.
+  *
+  * @license
+  *
+  * See the COPYING file in the FNA's root directory
+  *
+  */
+ #include <stdio.h>  /* for printf */
+ #include <assert.h> /* for assert */
+ #include <unistd.h> /* for sleep */
+ #include "fosa_threads_and_signals.h" /* for fosa_thread_xxx */
+ #include "frescan_bwres_robjs.h"
+ #define CEILING 10
+ static void *thread_code(void *arg);
+ int main()
+ {
+         int err;
+         frescan_bwres_robj_id_t id;
+         fosa_thread_attr_t th_attr;
+         fosa_thread_id_t tid;
+         printf("TEST REPLY OBJECTS\n");
+         err = fosa_thread_set_prio(fosa_thread_self(), CEILING - 1);
+         assert(err == 0);
+         err = frescan_bwres_robjs_init(CEILING);
+         assert(err == 0);
+         err = frescan_bwres_robjs_alloc(&id, CEILING);
+         assert(err == 0);
+         err = fosa_thread_attr_init(&th_attr);
+         assert(err == 0);
+         err = fosa_thread_attr_set_prio(&th_attr, CEILING - 1);
+         assert(err == 0);
+         err = fosa_thread_create (&tid, &th_attr, thread_code, (void *) id);
+         assert(err == 0);
+         err = fosa_thread_attr_destroy(&th_attr);
+         assert(err == 0);
+         err = frescan_bwres_robjs_wait(id);
+         assert(err == 0);
+         printf("signal received\n");
+         err = frescan_bwres_robjs_free(id);
+         assert(err == 0);
+         printf("TEST [OK!]\n");
+         return 0;
+ }
+ static void *thread_code(void *arg)
+ {
+         int err;
+         frescan_bwres_robj_id_t reply = (frescan_bwres_robj_id_t)arg;
+         printf("Thread executing\n");
+         sleep(2);
+         printf("Thread signaling\n");
+         err = frescan_bwres_robjs_signal(reply);
+         assert(err == 0);
+         printf("Thread terminating\n");
+         return NULL;
+ }
index 0000000000000000000000000000000000000000,7bdc864341ef3fec0ddfcf0573973a6bcdae9323..7bdc864341ef3fec0ddfcf0573973a6bcdae9323
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,181 +1,181 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frescan.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ // #define SENDER
+ // #define ENABLE_LOGGING
+ #ifdef SENDER
+ #define LOCAL_NODE 1
+ #ifdef ENABLE_LOGGING
+ #include <drivers/console_switcher.h>
+ #include <misc/logger.h>
+ #include <assert.h>
+ #define LOG_DEVICE LOG_ETHERNET
+ #endif
+ static void pause(){
+         char key;
+         printf(" press Enter...");
+         key = getchar();
+ }
+ int main ()
+ {
+         int i, ret;
+         frescan_send_params_t params;
+         char msg[200];
+         int written;
+         frescan_init_params_t init_params;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+ #ifdef ENABLE_LOGGING
+         ret = logger_init(LOG_DEVICE);
+         assert(ret == 0);
+         printf("Changing to membuffer console\n");
+         MEMBUFFER_CONSOLE_INIT();
+ #endif
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("FRESCAN initialized (local node: %u)\n", LOCAL_NODE);
+         params.net      = NETWORK;
+         params.to       = 0;
+         params.channel  = 0;
+         params.flags    = FRESCAN_FP | FRESCAN_ASYNC;
+         params.prio     = 7;
+         while(1) {
+                 pause();
+                 for (i=0; i<=2; i++) {
+                         written = snprintf(msg, sizeof(msg), "his number is... %d", i);
+                         ret = frescan_send(&params, (uint8_t *)msg, written);
+                         if (ret != 0) PUT_ERROR ("could not send message\n");
+                         printf("SENT: %d\n", i);
+                 }
+ #ifdef ENABLE_LOGGING
+                 while (logger_manual_call() > 0);
+ #endif
+         }
+         return 0;
+ }
+ #else
+ #define LOCAL_NODE 0
+ int main ()
+ {
+         int ret;
+         frescan_recv_params_t params;
+         uint8_t msg[3000];
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_init_params_t init_params;
+         frescan_prio_t prio;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("FRESCAN initialized (local node: %u)\n", LOCAL_NODE);
+         params.net      = NETWORK;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SYNC;
+         while (1) {
+                 printf("RECEIVING...\n");
+                 ret = frescan_recv(&params, (uint8_t *)msg, sizeof(msg),
+                                     &recv_bytes, &from, &prio);
+                 if (ret != 0) PUT_ERROR ("could not send message");
+                 msg[recv_bytes] = '\0';
+                 printf("RECEIVED: %s with prio:%u from:%u\n", msg, prio, from);
+ //                 for (i=0; i<recv_bytes; i++) {
+ //                         printf("msg[%d] = 0x%X;\n", i, msg[i]);
+ //                 }
+         }
+         return 0;
+ }
+ #endif
index 0000000000000000000000000000000000000000,e10ae40024fb5ed8cec3e228570f282020a122b9..e10ae40024fb5ed8cec3e228570f282020a122b9
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,203 +1,203 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <time.h>
+ #include "frescan.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define SENDER
+ // #define ENABLE_LOGGING
+ #define ENABLE_PARALLEL_PORT_TRACER
+ #ifdef ENABLE_PARALLEL_PORT_TRACER
+ #include <sys/pio.h>
+ #define PP_BASE_REG    0x378
+ #define PP_DATA_REG    0     // Data port offset
+ #endif
+ #if 0
+ #include <stdio.h>
+ #define DEBUG(x,args...) printf("%s: " x, __func__ , ##args)
+ #else
+ #define DEBUG(x,args...)
+ #endif
+ #ifdef SENDER
+ #define LOCAL_NODE 1
+ #ifdef ENABLE_LOGGING
+ #include <drivers/console_switcher.h>
+ #include <misc/logger.h>
+ #include <assert.h>
+ #define LOG_DEVICE LOG_ETHERNET
+ #endif
+ int main ()
+ {
+         int i, ret;
+         frescan_send_params_t params;
+         char msg[200];
+         int written;
+         frescan_init_params_t init_params;
+         struct timespec my_period, next_activation;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+ #ifdef ENABLE_LOGGING
+         ret = logger_init(LOG_DEVICE);
+         assert(ret == 0);
+         DEBUG("Changing to membuffer console\n");
+         MEMBUFFER_CONSOLE_INIT();
+ #endif
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         DEBUG("FRESCAN initialized (local node: %u)\n", LOCAL_NODE);
+         params.net      = NETWORK;
+         params.to       = 0;
+         params.channel  = 0;
+         params.flags    = FRESCAN_FP | FRESCAN_ASYNC;
+         params.prio     = 7;
+         my_period.tv_sec  = 0;
+         my_period.tv_nsec = 100000000;
+         outb_p (PP_BASE_REG + PP_DATA_REG, 0x00);
+         for(i=0; 1; i++) {
+                 incr_timespec (next_activation, my_period); // the fosa one
+                 clock_nanosleep(CLOCK_MONOTONIC,
+                                 TIMER_ABSTIME,
+                                 &next_activation, NULL);
+                 written = snprintf(msg, sizeof(msg), "his number is... %d", i);
+ #ifdef ENABLE_PARALLEL_PORT_TRACER
+                 outb_p (PP_BASE_REG + PP_DATA_REG, 0xFF);
+ #endif
+                 ret = frescan_send(&params, (uint8_t *)msg, 32);
+                 if (ret != 0) PUT_ERROR ("could not send message\n");
+ #ifdef ENABLE_PARALLEL_PORT_TRACER
+                 outb_p (PP_BASE_REG + PP_DATA_REG, 0x00);
+ #endif
+                 DEBUG("SENT: %d\n", i);
+ #ifdef ENABLE_LOGGING
+                 while (logger_manual_call() > 0);
+ #endif
+         }
+         return 0;
+ }
+ #else
+ #define LOCAL_NODE 0
+ int main ()
+ {
+         int ret;
+         frescan_recv_params_t params;
+         uint8_t msg[3000];
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_init_params_t init_params;
+         frescan_prio_t prio;
+         struct timespec pulse_width = {0, 100000};
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         DEBUG("FRESCAN initialized (local node: %u)\n", LOCAL_NODE);
+         params.net      = NETWORK;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SYNC;
+         outb_p (PP_BASE_REG + PP_DATA_REG, 0x00);
+         while (1) {
+                 DEBUG("RECEIVING...\n");
+                 ret = frescan_recv(&params, (uint8_t *)msg, sizeof(msg),
+                                     &recv_bytes, &from, &prio);
+                 if (ret != 0) PUT_ERROR ("could not send message");
+ #ifdef ENABLE_PARALLEL_PORT_TRACER
+                 outb_p (PP_BASE_REG + PP_DATA_REG, 0xFF);
+                 nanosleep(&pulse_width, NULL);
+                 outb_p (PP_BASE_REG + PP_DATA_REG, 0x00);
+ #endif
+                 msg[recv_bytes] = '\0';
+                 DEBUG("RECEIVED: %s with prio:%u from:%u\n", msg, prio, from);
+         }
+         return 0;
+ }
+ #endif
index 0000000000000000000000000000000000000000,4f08fbfd001e0b9194ee560f86e10e27fbce0a4d..4f08fbfd001e0b9194ee560f86e10e27fbce0a4d
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,176 +1,176 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include <assert.h>
+ #include "frescan.h"
+ #include "frescan_servers.h"
+ #include "frescan_debug.h"
+ #define NETWORK 0
+ #define LOG_DEVICE LOG_ETHERNET
+ #define NUM_MSG_BYTES  8  // 8 32 64 512 1488
+ #define ENABLE_DEBUG   false
+ #define NUM_MEASURES   100
+ #define LOCAL_NODE 0 // 0 1
+ #include <misc/time_measurement_hwtime.h>
+ #include <misc/logger.h>
+ static const trace_point_id_t BEGIN = 0;
+ static const trace_point_id_t END = 1;
+ int main ()
+ {
+         int i, ret;
+         frescan_send_params_t send_params;
+         frescan_recv_params_t recv_params;
+         char msg[1500]; // big enough for all the messages
+         frescan_init_params_t init_params;
+         frescan_node_t me;
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_prio_t prio;
+         me = LOCAL_NODE;
+         DEBUG(ENABLE_DEBUG, ">> Initializing FRESCAN (me:%u)\n", me);
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) FRESCAN_ERROR ("could not init FRESCAN");
+         DEBUG(ENABLE_DEBUG, ">> Enter in loop for sending packets\n");
+         send_params.net      = NETWORK;
+         send_params.channel  = 0;
+         send_params.flags    = FRESCAN_FP | FRESCAN_ASYNC;
+         send_params.prio     = 9;
+         send_params.to       = (me == 0)? 1 : 0;
+         recv_params.net      = NETWORK;
+         recv_params.channel  = 0;
+         recv_params.flags    = FRESCAN_SYNC;
+         if (me == 0) {
+                 DEBUG(ENABLE_DEBUG, ">> Init logger and timer measurements\n");
+                 ret = logger_init(LOG_DEVICE);
+                 assert(ret == 0);
+                 ret = time_measure_hwtime_init(BEGIN, "frescan_begin");
+                 assert(ret == 0);
+                 ret = time_measure_hwtime_init(END, "frescan_end");
+                 assert(ret == 0);
+                 DEBUG(ENABLE_DEBUG, ">> Enter in loop for send-recv packets\n");
+                 for (i=0; i<NUM_MEASURES; i++) {
+                         time_measure_hwtime_set_timestamp(BEGIN);
+                         ret = frescan_send(&send_params,
+                                            (uint8_t *)msg,
+                                            NUM_MSG_BYTES);
+                         if (ret != 0) FRESCAN_ERROR ("could not send message\n");
+                         ret = frescan_recv(&recv_params,
+                                            (uint8_t *)msg,
+                                            sizeof(msg),
+                                            &recv_bytes,
+                                            &from,
+                                            &prio);
+                         if (ret != 0) FRESCAN_ERROR ("could not receive message");
+                         time_measure_hwtime_set_timestamp(END);
+                         DEBUG(ENABLE_DEBUG, ">> received %d bytes\n", recv_bytes);
+                 }
+                 ret = time_measure_hwtime_write_membuffer(BEGIN);
+                 assert(ret == 0);
+                 ret = time_measure_hwtime_write_membuffer(END);
+                 assert(ret == 0);
+                 while (logger_manual_call() > 0);
+         } else {
+                 DEBUG(ENABLE_DEBUG, ">> Enter in loop for recv-send packets\n");
+                 while(1) {
+                         ret = frescan_recv(&recv_params,
+                                            (uint8_t *)msg,
+                                            sizeof(msg),
+                                            &recv_bytes,
+                                            &from,
+                                            &prio);
+                         if (ret != 0) FRESCAN_ERROR ("could not receive message");
+                         ret = frescan_send(&send_params,
+                                            (uint8_t *)msg,
+                                            recv_bytes);
+                         if (ret != 0) FRESCAN_ERROR ("could not send message\n");
+                 }
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,2afff81cebf52e4171a6df377d1e3eaa049c2937..2afff81cebf52e4171a6df377d1e3eaa049c2937
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,86 +1,86 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frescan.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define LOCAL_NODE 1
+ int main ()
+ {
+         int ret;
+         frescan_init_params_t init_params;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("FRESCAN initialized\n");
+         while (1) {
+                 sleep(1);
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,4079cd82a1e0e5e84a4e32e57fd33ede6322e7ac..4079cd82a1e0e5e84a4e32e57fd33ede6322e7ac
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,173 +1,173 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h> // sleep
+ #include <stdint.h> // uint32_t
+ #include "frescan_queues.h"
+ #include "frescan_packets.h"
+ #include "frescan_debug.h"
+ #include <drivers/can.h>
+ #include <misc/linux_list.h>
+ #define DEBUG_ENABLE 1
+ // static void pause(){
+ //         char key;
+ //         printf(" press Enter...");
+ //         key = getchar();
+ // }
+ int main ()
+ {
+         int i, ret;
+         frescan_queues_t queues;
+         frescan_packet_t *packet, *head;
+         struct can_frame_t *frame;
+         frescan_prio_queue_t *pqueue;
+         frescan_prio_t prio;
+         bool blocking;
+         frescan_init_params_t init_params;
+         DEBUG(DEBUG_ENABLE, "init frames and packets pool\n");
+         // ret = can_framespool_init();
+         // if (ret != 0) FRESCAN_ERROR ("could not init frames pool\n");
+         ret = frescan_packets_init();
+         if (ret != 0) FRESCAN_ERROR ("could not init packet pool\n");
+         DEBUG(DEBUG_ENABLE, "init queues\n");
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_queues_init(&queues, &init_params);
+         if (ret != 0) FRESCAN_ERROR("could not initialize the queues\n");
+         head = NULL;
+         DEBUG(DEBUG_ENABLE, "create queue of 5 packets\n");
+         for (i=0; i<5; i++) {
+                 frame = can_framespool_alloc();
+                 if (frame == NULL) FRESCAN_ERROR ("frames pool is exhausted\n");
+                 frame->is_extended_format = 1;
+                 frame->is_rtr = 0;
+                 frame->id = 0x696969;
+                 frame->dlc = 8;
+                 frame->data[0] = 69;
+                 frame->data[7] = 69;
+                 packet = frescan_packets_alloc();
+                 if (packet == NULL) FRESCAN_ERROR ("could not alloc packet\n");
+                 packet->frame = frame;
+                 if (head == NULL) {
+                         DEBUG(DEBUG_ENABLE, "head was null\n");
+                         head = frescan_packets_alloc();
+                         if (head == NULL) FRESCAN_ERROR ("could not alloc packet\n");
+                         INIT_LIST_HEAD(&head->msg_list);
+                 }
+                 list_add_tail(&packet->msg_list, &head->msg_list);
+         }
+         DEBUG(DEBUG_ENABLE, "enqueue head in priority queue\n");
+         pqueue = queues.rx_channel_queues[0];
+         ret = frescan_pqueue_enqueue(pqueue, head, 7);
+         if (ret != 0) FRESCAN_ERROR ("could not enqueue packet\n");
+         blocking = true;
+         DEBUG(DEBUG_ENABLE, "dequeue head from priority queue\n");
+         ret = frescan_pqueue_dequeue(pqueue, &head, &prio, blocking);
+         if (ret != 0) FRESCAN_ERROR ("could not dequeue packet\n");
+         if (head == NULL) {
+                 if (blocking == false) {
+                         FRESCAN_ERROR ("blocking false packet null\n");
+                 } else {
+                         FRESCAN_ERROR ("blocking true, and packet = null\n");
+                 }
+         }
+         DEBUG(DEBUG_ENABLE, "traverse the list of packets\n");
+         list_for_each_entry(packet, &head->msg_list, msg_list) {
+                 DEBUG(DEBUG_ENABLE,
+                       "ID Packet, dlc: %u, frame pool pos: %u\n",
+                        packet->frame->dlc, packet->frame->pool_pos);
+                 ret = can_framespool_free(packet->frame);
+                 if (ret != 0) FRESCAN_ERROR("could not free frame\n");
+                 ret = frescan_packets_free(packet);
+                 if (ret != 0) FRESCAN_ERROR("could not free packet\n");
+         }
+         DEBUG(DEBUG_ENABLE, "free head\n");
+         ret = frescan_packets_free(head);
+         if (ret != 0) {
+                 FRESCAN_ERROR("could not free head packet\n");
+                 return -1;
+         }
+         return 0;
+ }
index 0000000000000000000000000000000000000000,2adac67defbc6f74f61b761b0f58e9d35ea51198..2adac67defbc6f74f61b761b0f58e9d35ea51198
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,232 +1,232 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ // mgcc test_frescan_servers_send_basic.c -L. -lfrescan -o mprogram_wifi2
+ // mgcc test_frescan_servers_send_basic.c -DSENDER -L. -lfrescan -o mprogram_wifi1
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frescan.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define SENDER
+ // #define ENABLE_LOGGING
+ #ifdef SENDER
+ #define LOCAL_NODE 0
+ #ifdef ENABLE_LOGGING
+ #include <drivers/console_switcher.h>
+ #include <misc/logger.h>
+ #include <assert.h>
+ #define LOG_DEVICE LOG_ETHERNET
+ #endif
+ static void pause(){
+         char key;
+         printf(" press Enter...");
+         key = getchar();
+ }
+ int main ()
+ {
+         int i, ret;
+         frescan_send_params_t params;
+         char msg[200];
+         int written;
+         frescan_init_params_t init_params;
+         frescan_server_params_t server_params, server_params_read;
+         frescan_budget_t current_budget;
+ #ifdef ENABLE_LOGGING
+         ret = logger_init(LOG_DEVICE);
+         assert(ret == 0);
+         printf("Changing to membuffer console\n");
+         MEMBUFFER_CONSOLE_INIT();
+ #endif
+         printf(">> Initializing FRESCAN\n");
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf(">> Creating a Server\n");
+         server_params.budget = 3;
+         server_params.period.tv_sec  = 3;
+         server_params.period.tv_nsec = 0;
+         server_params.prio = 4;
+         ret = frescan_servers_create(NETWORK,
+                                      &server_params,
+                                      &params.ss);
+         if (ret != 0) PUT_ERROR ("could not create server");
+         printf(">> Getting data from Server\n");
+         ret = frescan_servers_get_data(NETWORK,
+                                        &server_params_read,
+                                        params.ss);
+         if (ret != 0) PUT_ERROR ("could not get data from server");
+         printf("params: C = %d\n T = (%d, %d) P = %d\n",
+                server_params_read.budget,
+                server_params_read.period.tv_sec,
+                server_params_read.period.tv_nsec,
+                server_params_read.prio);
+         printf(">> Getting current_budget from Server\n");
+         ret = frescan_servers_get_current_budget(NETWORK,
+                                                  params.ss,
+                                                  &current_budget);
+         if (ret != 0) PUT_ERROR ("could not get current_budget");
+         printf("current_budget = %d\n", current_budget);
+         printf(">> Enter in loop for sending packets\n");
+         params.net      = NETWORK;
+         params.to       = 1;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SS | FRESCAN_ASYNC;
+         while(1) {
+                 pause();
+                 for (i=0; i<=2; i++) {
+                         written = snprintf(msg, sizeof(msg),
+                                            "his number is: %d", i);
+                         ret = frescan_send(&params, (uint8_t *)msg, written);
+                         if (ret != 0) PUT_ERROR ("could not send message\n");
+                         printf("SENT: %d\n", i);
+                         ret = frescan_servers_get_current_budget
+                                         (NETWORK, params.ss, &current_budget);
+                         if (ret != 0) PUT_ERROR ("could not get current_budget");
+                         printf("current_budget = %d\n", current_budget);
+                 }
+                 pause();
+                 ret = frescan_servers_get_current_budget
+                                 (NETWORK, params.ss, &current_budget);
+                 if (ret != 0) PUT_ERROR ("could not get current_budget");
+                 printf("current_budget = %d\n", current_budget);
+ #ifdef ENABLE_LOGGING
+                 while (logger_manual_call() > 0);
+ #endif
+ }
+         return 0;
+ }
+ #else
+ #define LOCAL_NODE 1
+ int main ()
+ {
+         int ret;
+         frescan_recv_params_t params;
+         uint8_t msg[3000];
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_init_params_t init_params;
+         frescan_prio_t prio;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("FRESCAN initialized\n");
+         params.net      = NETWORK;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SYNC;
+         while (1) {
+                 printf("RECEIVING...\n");
+                 ret = frescan_recv(&params, (uint8_t *)msg, sizeof(msg),
+                                    &recv_bytes, &from, &prio);
+                 if (ret != 0) PUT_ERROR ("could not send message");
+                 msg[recv_bytes] = '\0';
+                 printf("RECEIVED: %s with prio:%u\n", msg, prio);
+ //                 for (i=0; i<recv_bytes; i++) {
+ //                         printf("msg[%d] = 0x%X;\n", i, msg[i]);
+ //                 }
+         }
+         return 0;
+ }
+ #endif
index 0000000000000000000000000000000000000000,51c45337e126109e90b019c99ffdcb54963c5a37..51c45337e126109e90b019c99ffdcb54963c5a37
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,214 +1,214 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ // mgcc test_frescan_servers_send_basic.c -L. -lfrescan -o mprogram_wifi2
+ // mgcc test_frescan_servers_send_basic.c -DSENDER -L. -lfrescan -o mprogram_wifi1
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frescan.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define SENDER
+ // #define ENABLE_LOGGING
+ #ifdef SENDER
+ #define LOCAL_NODE 0
+ #ifdef ENABLE_LOGGING
+ #include <drivers/console_switcher.h>
+ #include <misc/logger.h>
+ #include <assert.h>
+ #define LOG_DEVICE LOG_ETHERNET
+ #endif
+ static void pause(){
+         char key;
+         printf(" press Enter...");
+         key = getchar();
+ }
+ int main ()
+ {
+         int i, ret;
+         frescan_send_params_t params;
+         char msg[200];
+         int written;
+         frescan_init_params_t init_params;
+         frescan_server_params_t server_params;
+ #ifdef ENABLE_LOGGING
+         ret = logger_init(LOG_DEVICE);
+         assert(ret == 0);
+         printf("Changing to membuffer console\n");
+         MEMBUFFER_CONSOLE_INIT();
+ #endif
+         printf(">> Initializing FRESCAN\n");
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf(">> Creating a Server\n");
+         server_params.budget = 3;
+         server_params.period.tv_sec  = 3;
+         server_params.period.tv_nsec = 0;
+         server_params.prio = 4;
+         ret = frescan_servers_create(NETWORK,
+                                      &server_params,
+                                      &params.ss);
+         if (ret != 0) PUT_ERROR ("could not create server");
+         printf(">> Destroy the Server\n");
+         ret = frescan_servers_destroy(NETWORK, params.ss);
+         if (ret != 0) PUT_ERROR ("could not destroy server");
+         printf(">> Creating a Server\n");
+         server_params.budget = 3;
+         server_params.period.tv_sec  = 3;
+         server_params.period.tv_nsec = 0;
+         server_params.prio = 7;
+         ret = frescan_servers_create(NETWORK,
+                                      &server_params,
+                                      &params.ss);
+         if (ret != 0) PUT_ERROR ("could not create server");
+         printf(">> Enter in loop for sending packets\n");
+         params.net      = NETWORK;
+         params.to       = 1;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SS | FRESCAN_ASYNC;
+         while(1) {
+                 pause();
+                 for (i=0; i<=2; i++) {
+                         written = snprintf(msg, sizeof(msg), "his number is: %d", i);
+                         ret = frescan_send(&params, (uint8_t *)msg, written);
+                         if (ret != 0) PUT_ERROR ("could not send message\n");
+                         printf("SENT: %d\n", i);
+                 }
+ #ifdef ENABLE_LOGGING
+                 while (logger_manual_call() > 0);
+ #endif
+         }
+         return 0;
+ }
+ #else
+ #define LOCAL_NODE 1
+ int main ()
+ {
+         int ret;
+         frescan_recv_params_t params;
+         uint8_t msg[3000];
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_init_params_t init_params;
+         frescan_prio_t prio;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("FRESCAN initialized\n");
+         params.net      = NETWORK;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SYNC;
+         while (1) {
+                 printf("RECEIVING...\n");
+                 ret = frescan_recv(&params, (uint8_t *)msg, sizeof(msg),
+                                    &recv_bytes, &from, &prio);
+                 if (ret != 0) PUT_ERROR ("could not send message");
+                 msg[recv_bytes] = '\0';
+                 printf("RECEIVED: %s with prio:%u\n", msg, prio);
+ //                 for (i=0; i<recv_bytes; i++) {
+ //                         printf("msg[%d] = 0x%X;\n", i, msg[i]);
+ //                 }
+         }
+         return 0;
+ }
+ #endif
index 0000000000000000000000000000000000000000,d84abb12ab0fd8a4aececf0eb3bc46858b0a4450..d84abb12ab0fd8a4aececf0eb3bc46858b0a4450
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,277 +1,277 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ // mgcc test_frescan_servers_send_basic.c -L. -lfrescan -o mprogram_wifi2
+ // mgcc test_frescan_servers_send_basic.c -DSENDER -L. -lfrescan -o mprogram_wifi1
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frescan.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define SENDER
+ // #define ENABLE_LOGGING
+ #ifdef SENDER
+ #define LOCAL_NODE 0
+ #ifdef ENABLE_LOGGING
+ #include <drivers/console_switcher.h>
+ #include <misc/logger.h>
+ #include <assert.h>
+ #define LOG_DEVICE LOG_ETHERNET
+ #endif
+ static void pause(){
+         char key;
+         printf(" press Enter...");
+         key = getchar();
+ }
+ int main ()
+ {
+         int i, ret;
+         frescan_send_params_t params;
+         char msg[200];
+         int written;
+         frescan_init_params_t init_params;
+         frescan_server_params_t server_params, server_params_read;
+         frescan_budget_t current_budget;
+ #ifdef ENABLE_LOGGING
+         ret = logger_init(LOG_DEVICE);
+         assert(ret == 0);
+         printf("Changing to membuffer console\n");
+         MEMBUFFER_CONSOLE_INIT();
+ #endif
+         printf(">> Initializing FRESCAN\n");
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf(">> Creating a Server\n");
+         server_params.budget = 6;
+         server_params.period.tv_sec  = 3;
+         server_params.period.tv_nsec = 0;
+         server_params.prio = 4;
+         ret = frescan_servers_create(NETWORK,
+                                      &server_params,
+                                      &params.ss);
+         if (ret != 0) PUT_ERROR ("could not create server");
+         printf(">> Getting data from Server\n");
+         ret = frescan_servers_get_data(NETWORK,
+                                        &server_params_read,
+                                        params.ss);
+         if (ret != 0) PUT_ERROR ("could not get data from server");
+         printf("params: C = %d\n T = (%d, %d) P = %d\n",
+                server_params_read.budget,
+                server_params_read.period.tv_sec,
+                server_params_read.period.tv_nsec,
+                server_params_read.prio);
+         printf(">> Getting current_budget from Server\n");
+         ret = frescan_servers_get_current_budget(NETWORK,
+                                                  params.ss,
+                                                  &current_budget);
+         if (ret != 0) PUT_ERROR ("could not get current_budget");
+         printf("current_budget = %d\n", current_budget);
+         printf(">> Setting perceived\n");
+         server_params.budget = 4;
+         server_params.period.tv_sec  = 2;
+         server_params.period.tv_nsec = 0;
+         server_params.prio = 8;
+         ret = frescan_servers_set_perceived(NETWORK,
+                                             &server_params,
+                                             params.ss);
+         if (ret != 0) PUT_ERROR ("could not set perceived");
+         printf(">> Getting data from Server\n");
+         ret = frescan_servers_get_data(NETWORK,
+                                        &server_params_read,
+                                        params.ss);
+         if (ret != 0) PUT_ERROR ("could not get data from server");
+         printf("params: C = %d\n T = (%d, %d) P = %d\n",
+                server_params_read.budget,
+                server_params_read.period.tv_sec,
+                server_params_read.period.tv_nsec,
+                server_params_read.prio);
+         ret = frescan_servers_get_current_budget(NETWORK,
+                                                  params.ss,
+                                                  &current_budget);
+         if (ret != 0) PUT_ERROR ("could not get current_budget");
+         printf("current_budget = %d\n", current_budget);
+         printf(">> Commit params to Server\n");
+         ret = frescan_servers_commit_perceived(NETWORK, params.ss);
+         if (ret != 0) PUT_ERROR ("could not commit params");
+         ret = frescan_servers_get_current_budget(NETWORK,
+                                                  params.ss,
+                                                  &current_budget);
+         if (ret != 0) PUT_ERROR ("could not get current_budget");
+         printf("current_budget = %d\n", current_budget);
+         printf(">> Enter in loop for sending packets\n");
+         params.net      = NETWORK;
+         params.to       = 1;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SS | FRESCAN_ASYNC;
+         while(1) {
+                 pause();
+                 for (i=0; i<=2; i++) {
+                         written = snprintf(msg, sizeof(msg),
+                                            "his number is: %d", i);
+                         ret = frescan_send(&params, (uint8_t *)msg, written);
+                         if (ret != 0) PUT_ERROR ("could not send message\n");
+                         printf("SENT: %d\n", i);
+                         ret = frescan_servers_get_current_budget
+                                         (NETWORK, params.ss, &current_budget);
+                         if (ret != 0) PUT_ERROR ("could not get current_budget");
+                         printf("current_budget = %d\n", current_budget);
+                 }
+                 pause();
+                 ret = frescan_servers_get_current_budget
+                                 (NETWORK, params.ss, &current_budget);
+                 if (ret != 0) PUT_ERROR ("could not get current_budget");
+                 printf("current_budget = %d\n", current_budget);
+ #ifdef ENABLE_LOGGING
+                 while (logger_manual_call() > 0);
+ #endif
+ }
+         return 0;
+ }
+ #else
+ #define LOCAL_NODE 1
+ int main ()
+ {
+         int ret;
+         frescan_recv_params_t params;
+         uint8_t msg[3000];
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_init_params_t init_params;
+         frescan_prio_t prio;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("FRESCAN initialized\n");
+         params.net      = NETWORK;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SYNC;
+         while (1) {
+                 printf("RECEIVING...\n");
+                 ret = frescan_recv(&params, (uint8_t *)msg, sizeof(msg),
+                                    &recv_bytes, &from, &prio);
+                 if (ret != 0) PUT_ERROR ("could not send message");
+                 msg[recv_bytes] = '\0';
+                 printf("RECEIVED: %s with prio:%u\n", msg, prio);
+ //                 for (i=0; i<recv_bytes; i++) {
+ //                         printf("msg[%d] = 0x%X;\n", i, msg[i]);
+ //                 }
+         }
+         return 0;
+ }
+ #endif
index 0000000000000000000000000000000000000000,b2fad5d10e8c1fce9c407e08e1b075ada5ee4f86..b2fad5d10e8c1fce9c407e08e1b075ada5ee4f86
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,196 +1,196 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ // mgcc test_frescan_servers_send_basic.c -L. -lfrescan -o mprogram_wifi2
+ // mgcc test_frescan_servers_send_basic.c -DSENDER -L. -lfrescan -o mprogram_wifi1
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frescan.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define SENDER
+ // #define ENABLE_LOGGING
+ #ifdef SENDER
+ #define LOCAL_NODE 0
+ #ifdef ENABLE_LOGGING
+ #include <drivers/console_switcher.h>
+ #include <misc/logger.h>
+ #include <assert.h>
+ #define LOG_DEVICE LOG_ETHERNET
+ #endif
+ static void pause(){
+         char key;
+         printf(" press Enter...");
+         key = getchar();
+ }
+ int main ()
+ {
+         int i, ret;
+         frescan_send_params_t params;
+         char msg[200];
+         int written;
+         frescan_init_params_t init_params;
+         frescan_server_params_t server_params;
+ #ifdef ENABLE_LOGGING
+         ret = logger_init(LOG_DEVICE);
+         assert(ret == 0);
+         printf("Changing to membuffer console\n");
+         MEMBUFFER_CONSOLE_INIT();
+ #endif
+         printf(">> Initializing FRESCAN\n");
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf(">> Creating a Server\n");
+         server_params.budget = 3;
+         server_params.period.tv_sec  = 3;
+         server_params.period.tv_nsec = 0;
+         server_params.prio = 4;
+         ret = frescan_servers_create(NETWORK,
+                                      &server_params,
+                                      &params.ss);
+         if (ret != 0) PUT_ERROR ("could not create server");
+         printf(">> Enter in loop for sending packets\n");
+         params.net      = NETWORK;
+         params.to       = 1;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SS | FRESCAN_ASYNC;
+         while(1) {
+                 pause();
+                 for (i=0; i<=2; i++) {
+                         written = snprintf(msg, sizeof(msg), "his number is: %d", i);
+                         ret = frescan_send(&params, (uint8_t *)msg, written);
+                         if (ret != 0) PUT_ERROR ("could not send message\n");
+                         printf("SENT: %d\n", i);
+ }
+ #ifdef ENABLE_LOGGING
+                 while (logger_manual_call() > 0);
+ #endif
+ }
+         return 0;
+ }
+ #else
+ #define LOCAL_NODE 1
+ int main ()
+ {
+         int ret;
+         frescan_recv_params_t params;
+         uint8_t msg[3000];
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_init_params_t init_params;
+         frescan_prio_t prio;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("FRESCAN initialized\n");
+         params.net      = NETWORK;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SYNC;
+         while (1) {
+                 printf("RECEIVING...\n");
+                 ret = frescan_recv(&params, (uint8_t *)msg, sizeof(msg),
+                                    &recv_bytes, &from, &prio);
+                 if (ret != 0) PUT_ERROR ("could not send message");
+                 msg[recv_bytes] = '\0';
+                 printf("RECEIVED: %s with prio:%u\n", msg, prio);
+ //                 for (i=0; i<recv_bytes; i++) {
+ //                         printf("msg[%d] = 0x%X;\n", i, msg[i]);
+ //                 }
+         }
+         return 0;
+ }
+ #endif
index 0000000000000000000000000000000000000000,680810b0ce7750180d5802c814c193cf036dd4ee..680810b0ce7750180d5802c814c193cf036dd4ee
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,180 +1,180 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include <assert.h>
+ #include <drivers/console_switcher.h>
+ #include <misc/logger.h>
+ #include "frescan.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ // #define SENDER
+ #ifdef SENDER
+ #define LOCAL_NODE 0
+ static void pause(){
+         char key;
+         printf(" press Enter...");
+         key = getchar();
+ }
+ int main ()
+ {
+         int i, ret;
+         frescan_send_params_t params;
+         char msg[200];
+         frescan_init_params_t init_params;
+         frescan_server_params_t server_params;
+         ret = logger_init(LOG_ETHERNET);
+         assert(ret == 0);
+ //         MEMBUFFER_CONSOLE_INIT();
+         printf(">> Initializing FRESCAN\n");
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf(">> Creating a Server\n");
+         server_params.budget = 4;
+         server_params.period.tv_sec  = 3;
+         server_params.period.tv_nsec = 0;
+         server_params.prio = 5;
+         ret = frescan_servers_create(NETWORK,
+                                      &server_params,
+                                      &params.ss);
+         if (ret != 0) PUT_ERROR ("could not create server");
+         printf(">> Enter in loop for sending packets\n");
+         params.net      = NETWORK;
+         params.to       = 1;
+         params.channel  = 2;
+         params.flags    = FRESCAN_SS | FRESCAN_ASYNC;
+         while(1) {
+                 pause();
+                 for (i=0; i<2; i++) {
+                         *((uint8_t *)msg) = (uint8_t)i;
+                         ret = frescan_send(&params, (uint8_t *)msg, 3);
+                         if (ret != 0) PUT_ERROR ("could not send message\n");
+                         while (logger_manual_call() > 0);
+                        printf("SENT\n");
+                 }
+         }
+         return 0;
+ }
+ #else
+ #define LOCAL_NODE 1
+ int main ()
+ {
+         int ret;
+         frescan_recv_params_t params;
+         uint8_t msg[3000];
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_init_params_t init_params;
+         frescan_prio_t prio;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("FRESCAN initialized\n");
+         params.net      = NETWORK;
+         params.channel  = 2;
+         params.flags    = FRESCAN_SYNC;
+         while (1) {
+                 printf("RECEIVING...\n");
+                 ret = frescan_recv(&params, (uint8_t *)msg, sizeof(msg),
+                                    &recv_bytes, &from, &prio);
+                 if (ret != 0) PUT_ERROR ("could not send message");
+                 printf("RECEIVED msg %u with prio:%u\n", msg[0], prio);
+ //                 for (i=0; i<recv_bytes; i++) {
+ //                         printf("msg[%d] = 0x%X;\n", i, msg[i]);
+ //                 }
+         }
+         return 0;
+ }
+ #endif
index 0000000000000000000000000000000000000000,6e7ac2a63da960140cb29dcedae5c0f2b11fa26a..6e7ac2a63da960140cb29dcedae5c0f2b11fa26a
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,195 +1,195 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include <assert.h>
+ #include "frescan.h"
+ #include "frescan_servers.h"
+ #include "frescan_debug.h"
+ #define NETWORK 0
+ #define LOG_DEVICE LOG_ETHERNET
+ #define NUM_MSG_BYTES  512  // 8 32 64 512 1488
+ #define ENABLE_DEBUG   false
+ #define NUM_MEASURES   100
+ #define LOCAL_NODE 0 // 0 1
+ #include <misc/time_measurement_hwtime.h>
+ #include <misc/logger.h>
+ static const trace_point_id_t BEGIN = 0;
+ static const trace_point_id_t END = 1;
+ #define DISABLE_MEASURES
+ int main ()
+ {
+         int i, ret;
+         frescan_send_params_t send_params;
+         frescan_recv_params_t recv_params;
+         char msg[1500]; // big enough for all the messages
+         frescan_init_params_t init_params;
+         frescan_server_params_t server_params;
+         frescan_node_t me;
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_prio_t prio;
+         me = LOCAL_NODE;
+         DEBUG(ENABLE_DEBUG, ">> Initializing FRESCAN (me:%u)\n", me);
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) FRESCAN_ERROR ("could not init FRESCAN");
+         DEBUG(ENABLE_DEBUG, ">> Creating a Server\n");
+         server_params.budget = NUM_MSG_BYTES / 8;
+         server_params.period.tv_sec  = 0;
+         server_params.period.tv_nsec = 500000000;
+         server_params.prio = 4;
+         ret = frescan_servers_create(NETWORK,
+                                      &server_params,
+                                      &send_params.ss);
+         if (ret != 0) FRESCAN_ERROR ("could not create server");
+         DEBUG(ENABLE_DEBUG, ">> Enter in loop for sending packets\n");
+         send_params.net      = NETWORK;
+         send_params.channel  = 0;
+         send_params.flags    = FRESCAN_SS | FRESCAN_ASYNC;
+         send_params.to = (me == 0)? 1 : 0;
+         recv_params.net      = NETWORK;
+         recv_params.channel  = 0;
+         recv_params.flags    = FRESCAN_SYNC;
+         if (me == 0) {
+                 DEBUG(ENABLE_DEBUG, ">> Init logger and timer measurements\n");
+ #ifndef DISABLE_MEASURES
+                 ret = logger_init(LOG_DEVICE);
+                 assert(ret == 0);
+                 ret = time_measure_hwtime_init(BEGIN, "frescan_begin");
+                 assert(ret == 0);
+                 ret = time_measure_hwtime_init(END, "frescan_end");
+                 assert(ret == 0);
+ #endif
+                 DEBUG(ENABLE_DEBUG, ">> Enter in loop for send-recv packets\n");
+                 for (i=0; i<NUM_MEASURES; i++) {
+ #ifndef DISABLE_MEASURES
+                         time_measure_hwtime_set_timestamp(BEGIN);
+ #endif
+                         ret = frescan_send(&send_params,
+                                            (uint8_t *)msg,
+                                            NUM_MSG_BYTES);
+                         if (ret != 0) FRESCAN_ERROR ("could not send message\n");
+                         ret = frescan_recv(&recv_params,
+                                            (uint8_t *)msg,
+                                            sizeof(msg),
+                                            &recv_bytes,
+                                            &from,
+                                            &prio);
+                         if (ret != 0) FRESCAN_ERROR ("could not receive message");
+ #ifndef DISABLE_MEASURES
+                         time_measure_hwtime_set_timestamp(END);
+ #endif
+                         DEBUG(ENABLE_DEBUG, ">> received %d bytes\n", recv_bytes);
+                         sleep(1);
+                 }
+ #ifndef DISABLE_MEASURES
+                 ret = time_measure_hwtime_write_membuffer(BEGIN);
+                 assert(ret == 0);
+                 ret = time_measure_hwtime_write_membuffer(END);
+                 assert(ret == 0);
+                 while (logger_manual_call() > 0);
+ #endif
+         } else {
+                 DEBUG(ENABLE_DEBUG, ">> Enter in loop for recv-send packets\n");
+                 while(1) {
+                         ret = frescan_recv(&recv_params,
+                                            (uint8_t *)msg,
+                                            sizeof(msg),
+                                            &recv_bytes,
+                                            &from,
+                                            &prio);
+                         if (ret != 0) FRESCAN_ERROR ("could not receive message");
+                         ret = frescan_send(&send_params,
+                                            (uint8_t *)msg,
+                                            recv_bytes);
+                         if (ret != 0) FRESCAN_ERROR ("could not send message\n");
+                 }
+         }
+         sleep(100);
+         return 0;
+ }
index 0000000000000000000000000000000000000000,3cb46aaf0b279ea69ea62d22421db316f9f8bb61..3cb46aaf0b279ea69ea62d22421db316f9f8bb61
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,206 +1,206 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ // mgcc test_frescan_servers_send_basic.c -L. -lfrescan -o mprogram_wifi2
+ // mgcc test_frescan_servers_send_basic.c -DSENDER -L. -lfrescan -o mprogram_wifi1
+ #include <stdio.h>  // perror
+ #include <stdlib.h> // exit
+ #include <unistd.h>   // sleep
+ #include "frescan.h"
+ #include "frescan_servers.h"
+ #define PUT_ERROR(s) {perror (s); exit (-1);}
+ #define NETWORK 0
+ #define SENDER
+ // #define ENABLE_LOGGING
+ #ifdef SENDER
+ #define LOCAL_NODE 0
+ #ifdef ENABLE_LOGGING
+ #include <drivers/console_switcher.h>
+ #include <misc/logger.h>
+ #include <assert.h>
+ #define LOG_DEVICE LOG_ETHERNET
+ #endif
+ static void pause(){
+         char key;
+         printf(" press Enter...");
+         key = getchar();
+ }
+ int main ()
+ {
+         int i, ret;
+         frescan_send_params_t params;
+         char msg[200];
+         int written;
+         frescan_init_params_t init_params;
+         frescan_server_params_t server_params;
+ #ifdef ENABLE_LOGGING
+         ret = logger_init(LOG_DEVICE);
+         assert(ret == 0);
+         printf("Changing to membuffer console\n");
+         MEMBUFFER_CONSOLE_INIT();
+ #endif
+         printf(">> Initializing FRESCAN\n");
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf(">> Creating a Server\n");
+         server_params.budget = 8;
+         server_params.period.tv_sec  = 3;
+         server_params.period.tv_nsec = 0;
+         server_params.prio = 6;
+         ret = frescan_servers_create(NETWORK,
+                                      &server_params,
+                                      &params.ss);
+         if (ret != 0) PUT_ERROR ("could not create server");
+         server_params.budget = 3;
+         server_params.period.tv_sec  = 2;
+         server_params.period.tv_nsec = 0;
+         server_params.prio = 4;
+         ret = frescan_servers_update(NETWORK,
+                                      &server_params,
+                                      params.ss);
+         if (ret != 0) PUT_ERROR ("could not update server");
+         printf(">> Enter in loop for sending packets\n");
+         params.net      = NETWORK;
+         params.to       = 1;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SS | FRESCAN_ASYNC;
+         while(1) {
+                 pause();
+                 for (i=0; i<=2; i++) {
+                         written = snprintf(msg, sizeof(msg), "his number is: %d", i);
+                         ret = frescan_send(&params, (uint8_t *)msg, written);
+                         if (ret != 0) PUT_ERROR ("could not send message\n");
+                         printf("SENT: %d\n", i);
+ }
+ #ifdef ENABLE_LOGGING
+                 while (logger_manual_call() > 0);
+ #endif
+ }
+         return 0;
+ }
+ #else
+ #define LOCAL_NODE 1
+ int main ()
+ {
+         int ret;
+         frescan_recv_params_t params;
+         uint8_t msg[3000];
+         size_t recv_bytes;
+         frescan_node_t from;
+         frescan_init_params_t init_params;
+         frescan_prio_t prio;
+         init_params.net = NETWORK;
+         init_params.node = LOCAL_NODE;
+         init_params.tx_fp_max_prio = 10;
+         init_params.rx_num_of_channels = 5;
+         init_params.rx_channel_max_prio = NULL;
+         ret = frescan_init(&init_params);
+         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+         printf("FRESCAN initialized\n");
+         params.net      = NETWORK;
+         params.channel  = 0;
+         params.flags    = FRESCAN_SYNC;
+         while (1) {
+                 printf("RECEIVING...\n");
+                 ret = frescan_recv(&params, (uint8_t *)msg, sizeof(msg),
+                                    &recv_bytes, &from, &prio);
+                 if (ret != 0) PUT_ERROR ("could not send message");
+                 msg[recv_bytes] = '\0';
+                 printf("RECEIVED: %s with prio:%u\n", msg, prio);
+ //                 for (i=0; i<recv_bytes; i++) {
+ //                         printf("msg[%d] = 0x%X;\n", i, msg[i]);
+ //                 }
+         }
+         return 0;
+ }
+ #endif
index 0000000000000000000000000000000000000000,14d3e112ef4fd61b8baf09b1e949abc40dde59a4..14d3e112ef4fd61b8baf09b1e949abc40dde59a4
mode 000000,100755..100755
--- /dev/null
@@@ -1,0 -1,8 +1,8 @@@
+ .PHONY: tests
+ include ../../config.mk
+ include ../../rules.mk
+ EXES := $(patsubst %.c,%.exe,$(wildcard *.c))
+ tests: $(EXES)
index 0000000000000000000000000000000000000000,fde13a69a58621a0d78239786c507109a534b033..fde13a69a58621a0d78239786c507109a534b033
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,233 +1,233 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ /*
+  * test_c_rtep_fna.c
+  *
+  * Goal:
+  *
+  * The goal of this program is to test the RTEP implementation of the functions
+  * defined at fna.h without passing through the FRSH interface.
+  *
+  * Algorithm:
+  *
+  * We have two nodes, a sender and a receiver. The sender negotiates a contract,
+  * send info to the receiver, then renegotiates the contract and finally it
+  * cancels the contract.
+  *
+  */
+ #include <assert.h> // for assert
+ #include <stdio.h> // for printf
+ #include <time.h> // for timespec
+ #include "frsh.h" // for frsh_contract_set_xxx, FRSH_NETWORK_ID_DEFAULT, frsh_network_address_t, frsh_stream_id_t
+ #include "fna.h" // for fna_vres_id_t
+ #include "frsh_fna.h" // for frsh_rtep_*
+ #include "rtep_fna.h" // for rtep_fna_operations
+ #include "rtep.h" // for rtep_station_id_t, rtep_channel_t
+ int main ()
+ {
+     int err;
+     rtep_station_id_t me, normal_station, multicast_station;
+     frsh_network_address_t frsh_address;
+     char multicast_name[] = "broadcast";
+     size_t max_size, max_multicast_size, budget_bytes, nbytes;
+     struct timespec budget_timespec, period_max;
+     frsh_contract_t frsh_contract;
+     fna_vres_id_t vres;
+     fna_endpoint_data_t endpoint;
+     const int MSG_BUFFER_MX = 10;
+     char msg_buffer[MSG_BUFFER_MX];
+     int msg_size;
+     int msg_counter;
+     printf("--------------------------------------------------\n");
+     printf("1.- fna_init\n");
+     printf("--------------------------------------------------\n");
+     err = rtep_fna_operations.fna_init(FRSH_NETWORK_ID_DEFAULT);
+     assert(err == 0);
+     printf("--------------------------------------------------\n");
+     printf("2.- fna_network_get_max_message_size\n");
+     printf("--------------------------------------------------\n");
+    // get broadcast address for FRESCOR
+     multicast_station = rtep_get_station_id_by_name
+             ((uint8_t *)multicast_name, sizeof(multicast_name)-1);
+     err = frsh_rtep_map_network_address
+             (FRSH_RESOURCE_ID_DEFAULT, multicast_station, &frsh_address);
+     assert (err == 0);
+    // maximum size per message for a broadcast address
+     err=rtep_fna_operations.fna_network_get_max_message_size
+             (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_multicast_size);
+     printf("Max multicast message size: %d\n", max_multicast_size);
+     assert (err == 0);
+     assert (max_multicast_size == MULTICAST_MTU);
+    // now the same with a normal address (i.e: 2)
+     normal_station = 2;
+     err=frsh_rtep_map_network_address
+             (FRSH_RESOURCE_ID_DEFAULT, normal_station, &frsh_address);
+     assert (err == 0);
+    // maximum size per message for a normal address
+     err=rtep_fna_operations.fna_network_get_max_message_size
+             (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_size);
+     printf("Max message size: %d\n", max_size);
+     assert (err == 0);
+     assert (max_size == MAX_RTEP_MTU);
+     printf("--------------------------------------------------\n");
+     printf("3.- fna_network_budget_to_bytes\n");
+     printf("--------------------------------------------------\n");
+     nbytes = 1700;
+     err=rtep_fna_operations.fna_network_bytes_to_budget
+             (FRSH_RESOURCE_ID_DEFAULT, nbytes, &budget_timespec);
+     assert (err == 0);
+     err=rtep_fna_operations.fna_network_budget_to_bytes
+             (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
+     assert (err == 0);
+     printf("%d user bytes -> %d budget bytes\n", nbytes, budget_bytes);
+     printf("--------------------------------------------------\n");
+     printf("4.- fna_network_get_min_effective_budget\n");
+     printf("--------------------------------------------------\n");
+     err=rtep_fna_operations.fna_network_get_min_eff_budget
+             (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec);
+     assert (err == 0);
+     err=rtep_fna_operations.fna_network_budget_to_bytes
+             (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
+     assert (err == 0);
+     printf("Minimum effective budget: %d\n", budget_bytes);
+     // send or receive
+     me = rtep_get_station_id();
+     if (me == 1) {
+         printf("--------------------------------------------------\n");
+         printf("5.- fna_contract_negotiate\n");
+         printf("--------------------------------------------------\n");
+         period_max.tv_sec = 3;
+         period_max.tv_nsec = 0;
+         // Create the contract
+         frsh_contract.workload = FRSH_WT_INDETERMINATE;
+         frsh_contract.granularity = FRSH_DEFAULT_GRANULARITY;
+         frsh_contract.weight = FRSH_DEFAULT_WEIGHT;
+         frsh_contract.importance = FRSH_DEFAULT_IMPORTANCE;
+         frsh_contract.resource_id = FRSH_RESOURCE_ID_DEFAULT;
+         frsh_contract.resource_type = FRSH_RT_NETWORK;
+         frsh_contract.budget_min = budget_timespec;
+         frsh_contract.period_max = period_max;
+         frsh_contract.d_equals_t = true;
+         frsh_contract.preemption_level = 4;
+         // Negotiate the contract
+         err = rtep_fna_operations.fna_contract_negotiate
+                 (FRSH_RESOURCE_ID_DEFAULT, &frsh_contract, &vres);
+         assert (err == 0);
+         printf("Contract accepted\n");
+         // Bind the vres to an endpoint
+         endpoint.endpoint_type = FRSH_SEND_ENDPOINT_TYPE;
+         endpoint.vres = vres;
+         endpoint.is_bound = true;
+         endpoint.destination = 2; // only for send_endpoints
+         endpoint.resource_id = FRSH_RESOURCE_ID_DEFAULT;
+         endpoint.stream_id = 7;
+         msg_counter = 0;
+         while(1) {
+             sleep(4);
+             printf("sending message\n");
+             msg_counter = msg_counter + 1;
+             msg_size = snprintf(msg_buffer, MSG_BUFFER_MX-1, "MSG %d", msg_counter);
+             err = rtep_fna_operations.fna_send_async
+                    (&endpoint, msg_buffer, msg_size);
+             assert (err == 0);
+         }
+     } else {
+         size_t received_bytes;
+         frsh_network_address_t from;
+         endpoint.endpoint_type = FRSH_RECEIVE_ENDPOINT_TYPE;
+         endpoint.is_bound = false;
+         endpoint.resource_id = FRSH_RESOURCE_ID_DEFAULT;
+         endpoint.stream_id = 7;
+         while(1) {
+             printf("blocking to receive\n");
+             err = rtep_fna_operations.fna_receive_sync
+                     (&endpoint, msg_buffer, MSG_BUFFER_MX, &received_bytes, &from);
+             assert (err == 0);
+             msg_buffer[received_bytes] = '\0';
+             printf("msg received: %s\n", msg_buffer);
+         }
+     }
+     return 0;
+ }
index 0000000000000000000000000000000000000000,79cfe9aab08e46e84248e4c0b715954422b93c0f..79cfe9aab08e46e84248e4c0b715954422b93c0f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,270 +1,270 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ /*
+  * test_c_rtep_fna.c
+  *
+  * Goal:
+  *
+  * The goal of this program is to test the RTEP implementation of the functions
+  * defined at fna.h without passing through the FRSH interface.
+  *
+  * Algorithm:
+  *
+  * We have two nodes, a sender and a receiver. The sender negotiates a contract,
+  * send info to the receiver, then renegotiates the contract and finally it
+  * cancels the contract.
+  *
+  */
+ #include <assert.h> // for assert
+ #include <time.h> // for timespec
+ #include "frsh.h" // for frsh_contract_set_xxx, FRSH_NETWORK_ID_DEFAULT, frsh_network_address_t, frsh_stream_id_t
+ #include "fna.h" // for fna_vres_id_t
+ #include "frsh_fna.h" // for frsh_rtep_*
+ #include "rtep_fna.h" // for rtep_fna_operations
+ #include "rtep.h" // for rtep_station_id_t, rtep_channel_t
+ #include <misc/time_measurement_hwtime.h>
+ #include <misc/logger.h>
+ static const trace_point_id_t BEGIN_CONTRACT_NEG = 0;
+ static const trace_point_id_t END_CONTRACT_NEG = 1;
+ #if 0
+ #include <stdio.h>
+ #define DEBUG(x,args...) printf("%s: " x, __func__ , ##args)
+ #else
+ #define DEBUG(x,args...)
+ #endif
+ #define MX_MEASURES 40
+ int main ()
+ {
+     int err, i;
+     rtep_station_id_t me, normal_station, multicast_station;
+     frsh_network_address_t frsh_address;
+     char multicast_name[] = "broadcast";
+     size_t max_size, max_multicast_size, budget_bytes, nbytes;
+     struct timespec budget_timespec, period_max;
+     frsh_contract_t frsh_contract;
+     fna_vres_id_t vres;
+     fna_endpoint_data_t endpoint;
+     const int MSG_BUFFER_MX = 10;
+     char msg_buffer[MSG_BUFFER_MX];
+     int msg_size;
+     int msg_counter;
+     err = logger_init(LOG_ETHERNET);
+     assert(err == 0);
+     err = time_measure_hwtime_init(BEGIN_CONTRACT_NEG, "contract_begin");
+     assert(err == 0);
+     err = time_measure_hwtime_init(END_CONTRACT_NEG, "contract_end");
+     assert(err == 0);
+     DEBUG("--------------------------------------------------\n");
+     DEBUG("1.- fna_init\n");
+     DEBUG("--------------------------------------------------\n");
+     err = rtep_fna_operations.fna_init(FRSH_NETWORK_ID_DEFAULT);
+     assert(err == 0);
+     DEBUG("--------------------------------------------------\n");
+     DEBUG("2.- fna_network_get_max_message_size\n");
+     DEBUG("--------------------------------------------------\n");
+    // get broadcast address for FRESCOR
+     multicast_station = rtep_get_station_id_by_name
+             ((uint8_t *)multicast_name, sizeof(multicast_name)-1);
+     err = frsh_rtep_map_network_address
+             (FRSH_RESOURCE_ID_DEFAULT, multicast_station, &frsh_address);
+     assert (err == 0);
+    // maximum size per message for a broadcast address
+     err=rtep_fna_operations.fna_network_get_max_message_size
+             (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_multicast_size);
+     DEBUG("Max multicast message size: %d\n", max_multicast_size);
+     assert (err == 0);
+     assert (max_multicast_size == MULTICAST_MTU);
+    // now the same with a normal address (i.e: 2)
+     normal_station = 2;
+     err=frsh_rtep_map_network_address
+             (FRSH_RESOURCE_ID_DEFAULT, normal_station, &frsh_address);
+     assert (err == 0);
+    // maximum size per message for a normal address
+     err=rtep_fna_operations.fna_network_get_max_message_size
+             (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_size);
+     DEBUG("Max message size: %d\n", max_size);
+     assert (err == 0);
+     assert (max_size == MAX_RTEP_MTU);
+     DEBUG("--------------------------------------------------\n");
+     DEBUG("3.- fna_network_budget_to_bytes\n");
+     DEBUG("--------------------------------------------------\n");
+     nbytes = 1700;
+     err=rtep_fna_operations.fna_network_bytes_to_budget
+             (FRSH_RESOURCE_ID_DEFAULT, nbytes, &budget_timespec);
+     assert (err == 0);
+     err=rtep_fna_operations.fna_network_budget_to_bytes
+             (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
+     assert (err == 0);
+     DEBUG("%d user bytes -> %d budget bytes\n", nbytes, budget_bytes);
+     DEBUG("--------------------------------------------------\n");
+     DEBUG("4.- fna_network_get_min_effective_budget\n");
+     DEBUG("--------------------------------------------------\n");
+     err=rtep_fna_operations.fna_network_get_min_eff_budget
+             (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec);
+     assert (err == 0);
+     err=rtep_fna_operations.fna_network_budget_to_bytes
+             (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
+     assert (err == 0);
+     DEBUG("Minimum effective budget: %d\n", budget_bytes);
+     // send or receive
+     me = rtep_get_station_id();
+     if (me == 1) {
+         DEBUG("--------------------------------------------------\n");
+         DEBUG("5.- fna_contract_negotiate\n");
+         DEBUG("--------------------------------------------------\n");
+         period_max.tv_sec = 3;
+         period_max.tv_nsec = 0;
+         // Create the contract
+         frsh_contract.workload = FRSH_WT_INDETERMINATE;
+         frsh_contract.granularity = FRSH_DEFAULT_GRANULARITY;
+         frsh_contract.weight = FRSH_DEFAULT_WEIGHT;
+         frsh_contract.importance = FRSH_DEFAULT_IMPORTANCE;
+         frsh_contract.resource_id = FRSH_RESOURCE_ID_DEFAULT;
+         frsh_contract.resource_type = FRSH_RT_NETWORK;
+         frsh_contract.budget_min = budget_timespec;
+         frsh_contract.period_max = period_max;
+         frsh_contract.d_equals_t = true;
+         frsh_contract.preemption_level = 4;
+         // Negotiate the contract
+         for (i=0; i<MX_MEASURES; i++) {
+                 time_measure_hwtime_set_timestamp(BEGIN_CONTRACT_NEG);
+                 err = rtep_fna_operations.fna_contract_negotiate
+                         (FRSH_RESOURCE_ID_DEFAULT, &frsh_contract, &vres);
+                 assert (err == 0);
+                 time_measure_hwtime_set_timestamp(END_CONTRACT_NEG);
+         }
+         printf("Contract accepted\n");
+         err = time_measure_hwtime_write_membuffer(BEGIN_CONTRACT_NEG);
+         assert(err == 0);
+         err = time_measure_hwtime_write_membuffer(END_CONTRACT_NEG);
+         assert(err == 0);
+         while (logger_manual_call() > 0);
+         // Bind the vres to an endpoint
+         endpoint.endpoint_type = FRSH_SEND_ENDPOINT_TYPE;
+         endpoint.vres = vres;
+         endpoint.is_bound = true;
+         endpoint.destination = 2; // only for send_endpoints
+         endpoint.resource_id = FRSH_RESOURCE_ID_DEFAULT;
+         endpoint.stream_id = 7;
+         msg_counter = 0;
+         while(1) {
+             sleep(4);
+             DEBUG("sending message\n");
+             msg_counter = msg_counter + 1;
+             msg_size = snprintf(msg_buffer, MSG_BUFFER_MX-1, "MSG %d", msg_counter);
+             err = rtep_fna_operations.fna_send_async
+                    (&endpoint, msg_buffer, msg_size);
+             assert (err == 0);
+         }
+     } else {
+         size_t received_bytes;
+         frsh_network_address_t from;
+         endpoint.endpoint_type = FRSH_RECEIVE_ENDPOINT_TYPE;
+         endpoint.is_bound = false;
+         endpoint.resource_id = FRSH_RESOURCE_ID_DEFAULT;
+         endpoint.stream_id = 7;
+         while(1) {
+             DEBUG("blocking to receive\n");
+             err = rtep_fna_operations.fna_receive_sync
+                     (&endpoint, msg_buffer, MSG_BUFFER_MX, &received_bytes, &from);
+             assert (err == 0);
+             msg_buffer[received_bytes] = '\0';
+             DEBUG("msg received: %s\n", msg_buffer);
+         }
+     }
+     return 0;
+ }
index 0000000000000000000000000000000000000000,c9ae3f18995065e4017d3466892d0761cebcd30e..c9ae3f18995065e4017d3466892d0761cebcd30e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,236 +1,236 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ /*
+  * test_c_rtep_fna.c
+  *
+  * Goal:
+  *
+  * The goal of this program is to test the RTEP implementation of the functions
+  * defined at fna.h without passing through the FRSH interface.
+  *
+  * Algorithm:
+  *
+  * We have two nodes, a sender and a receiver. The sender negotiates a contract,
+  * send info to the receiver, then renegotiates the contract and finally it
+  * cancels the contract.
+  *
+  */
+ #include <assert.h> // for assert
+ #include <stdio.h> // for printf
+ #include <time.h> // for timespec
+ #include "frsh.h" // for frsh_contract_set_xxx, FRSH_RESOURCE_ID_DEFAULT, frsh_network_address_t, frsh_stream_id_t
+ #include "fna.h" // for fna_vres_id_t
+ #include "frsh_fna.h" // for frsh_rtep_*
+ #include "rtep_fna.h" // for rtep_fna_operations
+ #include "rtep.h" // for rtep_station_id_t, rtep_channel_t
+ #include "fosa_threads_and_signals.h"
+ int main ()
+ {
+     int err;
+     rtep_station_id_t me, normal_station, multicast_station;
+     frsh_network_address_t frsh_address;
+     char multicast_name[] = "broadcast";
+     size_t max_size, max_multicast_size, budget_bytes, nbytes;
+     struct timespec budget_timespec, period_max;
+     frsh_contract_t frsh_contract;
+     fna_vres_id_t vres;
+     fna_endpoint_data_t endpoint;
+     const int MSG_BUFFER_MX = 10;
+     char msg_buffer[MSG_BUFFER_MX];
+     int msg_size;
+     int msg_counter;
+     printf("--------------------------------------------------\n");
+     printf("1.- fna_init\n");
+     printf("--------------------------------------------------\n");
+     err = frsh_init();
+ //     err = rtep_fna_operations.fna_init(FRSH_RESOURCE_ID_DEFAULT);
+     assert(err == 0);
+     printf("--------------------------------------------------\n");
+     printf("2.- fna_network_get_max_message_size\n");
+     printf("--------------------------------------------------\n");
+    // get broadcast address for FRESCOR
+     multicast_station = rtep_get_station_id_by_name
+             ((uint8_t *)multicast_name, sizeof(multicast_name)-1);
+     err = frsh_rtep_map_network_address
+             (FRSH_RESOURCE_ID_DEFAULT, multicast_station, &frsh_address);
+     assert (err == 0);
+    // maximum size per message for a broadcast address
+     err=rtep_fna_operations.fna_network_get_max_message_size
+             (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_multicast_size);
+     printf("Max multicast message size: %d\n", max_multicast_size);
+     assert (err == 0);
+     assert (max_multicast_size == MULTICAST_MTU);
+    // now the same with a normal address (i.e: 2)
+     normal_station = 2;
+     err=frsh_rtep_map_network_address
+             (FRSH_RESOURCE_ID_DEFAULT, normal_station, &frsh_address);
+     assert (err == 0);
+    // maximum size per message for a normal address
+     err=rtep_fna_operations.fna_network_get_max_message_size
+             (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_size);
+     printf("Max message size: %d\n", max_size);
+     assert (err == 0);
+     assert (max_size == MAX_RTEP_MTU);
+     printf("--------------------------------------------------\n");
+     printf("3.- fna_network_budget_to_bytes\n");
+     printf("--------------------------------------------------\n");
+     nbytes = 1700;
+     err=rtep_fna_operations.fna_network_bytes_to_budget
+             (FRSH_RESOURCE_ID_DEFAULT, nbytes, &budget_timespec);
+     assert (err == 0);
+     err=rtep_fna_operations.fna_network_budget_to_bytes
+             (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
+     assert (err == 0);
+     printf("%d user bytes -> %d budget bytes\n", nbytes, budget_bytes);
+     printf("--------------------------------------------------\n");
+     printf("4.- fna_network_get_min_effective_budget\n");
+     printf("--------------------------------------------------\n");
+     err=rtep_fna_operations.fna_network_get_min_eff_budget
+             (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec);
+     assert (err == 0);
+     err=rtep_fna_operations.fna_network_budget_to_bytes
+             (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
+     assert (err == 0);
+     printf("Minimum effective budget: %d\n", budget_bytes);
+     // send or receive
+     me = rtep_get_station_id();
+     if (me == 1) {
+         printf("--------------------------------------------------\n");
+         printf("5.- fna_contract_negotiate\n");
+         printf("--------------------------------------------------\n");
+         period_max.tv_sec = 3;
+         period_max.tv_nsec = 0;
+         // Create the contract
+         frsh_contract.workload = FRSH_WT_INDETERMINATE;
+         frsh_contract.granularity = FRSH_DEFAULT_GRANULARITY;
+         frsh_contract.weight = FRSH_DEFAULT_WEIGHT;
+         frsh_contract.importance = FRSH_DEFAULT_IMPORTANCE;
+         frsh_contract.resource_id = FRSH_RESOURCE_ID_DEFAULT;
+         frsh_contract.resource_type = FRSH_RT_NETWORK;
+         frsh_contract.budget_min = budget_timespec;
+         frsh_contract.period_max = period_max;
+         frsh_contract.d_equals_t = true;
+         frsh_contract.preemption_level = 4;
+         // Negotiate the contract
+         err = rtep_fna_operations.fna_contract_negotiate
+                 (FRSH_RESOURCE_ID_DEFAULT, &frsh_contract, &vres);
+         assert (err == 0);
+         printf("Contract accepted\n");
+         // Bind the vres to an endpoint
+         endpoint.endpoint_type = FRSH_SEND_ENDPOINT_TYPE;
+         endpoint.vres = vres;
+         endpoint.is_bound = true;
+         endpoint.destination = 2; // only for send_endpoints
+         endpoint.resource_id = FRSH_RESOURCE_ID_DEFAULT;
+         endpoint.stream_id = 7;
+         msg_counter = 0;
+         while(1) {
+             sleep(4);
+             printf("sending message\n");
+             msg_counter = msg_counter + 1;
+             msg_size = snprintf(msg_buffer, MSG_BUFFER_MX-1, "MSG %d", msg_counter);
+             err = rtep_fna_operations.fna_send_async
+                    (&endpoint, msg_buffer, msg_size);
+             assert (err == 0);
+         }
+     } else {
+         size_t received_bytes;
+         frsh_network_address_t from;
+         endpoint.endpoint_type = FRSH_RECEIVE_ENDPOINT_TYPE;
+         endpoint.is_bound = false;
+         endpoint.resource_id = FRSH_RESOURCE_ID_DEFAULT;
+         endpoint.stream_id = 7;
+         while(1) {
+             printf("blocking to receive\n");
+             err = rtep_fna_operations.fna_receive_sync
+                     (&endpoint, msg_buffer, MSG_BUFFER_MX, &received_bytes, &from);
+             assert (err == 0);
+             msg_buffer[received_bytes] = '\0';
+             printf("msg received: %s\n", msg_buffer);
+         }
+     }
+     return 0;
+ }
index 0000000000000000000000000000000000000000,400ecb866995a038edb297e9f42cccaf71ead6fe..400ecb866995a038edb297e9f42cccaf71ead6fe
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,182 +1,182 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ /*
+  * test_c_rtep_frsh_fna.c
+  *
+  * Goal:
+  *
+  * The goal of this program is to test the RTEP functions defined at frsh_fna.h
+  * which is the public part of frsh_fna.h. The interface of this public part
+  * is dependent of the underlying network protocol. We are not trying here to
+  * make a very intense test but a simple and basic one to check the correct
+  * behaviour of the functions.
+  *
+  * Algorithm:
+  *
+  * First we check the conversions between frsh and rtep addresses and streams.
+  * Then, we check the renegotiation functions for the period of the internal
+  * negotiation messages. And finally, we check the renegotiation functions for
+  * the internal service thread.
+  *
+  */
+ #include <assert.h> // for assert
+ #include <stdio.h> // for printf
+ #include <stdbool.h> // for bool
+ #include "frsh.h" // for FRSH_RESOURCE_ID_DEFAULT, frsh_network_address_t, frsh_stream_id_t
+ #include "rtep_fna.h" // for rtep_fna_operations.fna_init
+ #include "rtep.h" // for rtep_station_id_t, rtep_channel_t
+ #include "frsh_fna.h" // for frsh_rtep_*
+ int main ()
+ {
+     int err;
+     rtep_station_id_t rtep_station = 3;
+     frsh_network_address_t frsh_address;
+     rtep_channel_t in_stream = 7;
+     frsh_stream_id_t out_stream;
+     struct timespec neg_period = {2,0};
+     struct timespec get_period = {0,0};
+ //     struct timespec rtep_serv_thread_budget = {1,0};
+ //     struct timespec rtep_serv_thread_period = {5,0};
+ //     bool serv_thread_renegotiation_accepted = false;
+ //     struct timespec current_serv_thread_budget = {0,0};
+ //     struct timespec current_serv_thread_period = {0,0};
+     printf("1.- fna_init\n");
+     err=rtep_fna_operations.fna_init(FRSH_RESOURCE_ID_DEFAULT);
+     assert(err == 0);
+     printf("2.- frsh_rtep_map_network_address\n");
+     err=frsh_rtep_map_network_address
+             (FRSH_RESOURCE_ID_DEFAULT, rtep_station, &frsh_address);
+     assert(err == 0);
+     printf("rtep_address:%d -> frsh_address:%d\n", rtep_station, frsh_address);
+     assert(rtep_station == frsh_address);
+     printf("3.- frsh_rtep_map_stream_id\n");
+     err=frsh_rtep_map_stream_id
+             (FRSH_RESOURCE_ID_DEFAULT, in_stream, &out_stream);
+     assert(err == 0);
+     printf("rtep_channel:%d -> frsh_stream:%d\n", in_stream, out_stream);
+     assert(in_stream == out_stream);
+     printf("4.- frsh_rtep_negotiation_messages_vres_renegotiate period\n");
+     err=frsh_rtep_negotiation_messages_vres_get_period
+             (FRSH_RESOURCE_ID_DEFAULT, &get_period);
+     assert(err == 0);
+     printf("period before renegotiation: sec=%d nsec=%d\n",
+             get_period.tv_sec, get_period.tv_nsec);
+     err=frsh_rtep_negotiation_messages_vres_renegotiate
+             (FRSH_RESOURCE_ID_DEFAULT, &neg_period);
+     if (err == 0) {
+         printf("renegotiation accepted (period negotiated: sec=%d nsec=%d)\n",
+                neg_period.tv_sec, neg_period.tv_nsec);
+     } else {
+         printf("renegotiation not accepted\n");
+     }
+     assert (err == 0);
+     err=frsh_rtep_negotiation_messages_vres_get_period
+             (FRSH_RESOURCE_ID_DEFAULT, &get_period);
+     assert(err == 0);
+     printf("period after renegotiation: sec=%d nsec=%d\n",
+            get_period.tv_sec, get_period.tv_nsec);
+ // TODO: uncomment step 5 when internal thread has a frescor contract
+ // printf("5.- frsh_rtep_service_thread_vres_renegotiate\n");
+ //
+ // err=frsh_rtep_service_thread_vres_get_budget_and_period
+ //         (FRSH_RESOURCE_ID_DEFAULT,
+ //             &current_serv_thread_budget,
+ //             &current_serv_thread_period);
+ // assert(err == 0);
+ // printf("service thread budget (before renegotiation): sec=%d nsec=%d\n",
+ //         current_serv_thread_budget.tv_sec,
+ //         current_serv_thread_budget.tv_nsec);
+ // printf("service thread period (before renegotiation): sec=%d nsec=%d\n",
+ //         current_serv_thread_period.tv_sec,
+ //         current_serv_thread_period.tv_nsec);
+ //
+ // err=frsh_rtep_service_thread_vres_renegotiate
+ //         (FRSH_RESOURCE_ID_DEFAULT,
+ //             &rtep_serv_thread_budget,
+ //             &rtep_serv_thread_period,
+ //             &serv_thread_renegotiation_accepted);
+ // assert(err == 0);
+ //
+ // if (serv_thread_renegotiation_accepted) {
+ //     printf("service_thread renegotiation accepted\n");
+ // } else {
+ //     printf("service_thread renegotiation not accepted\n");
+ // }
+ // assert (err == 0);
+ //
+ // err=frsh_rtep_service_thread_vres_get_budget_and_period
+ //         (FRSH_RESOURCE_ID_DEFAULT,
+ //             &current_serv_thread_budget,
+ //             &current_serv_thread_period);
+ // assert(err == 0);
+ // printf("service thread budget (after renegotiation): sec=%d nsec=%d\n",
+ //         current_serv_thread_budget.tv_sec,
+ //         current_serv_thread_budget.tv_nsec);
+ // printf("service thread period (after renegotiation): sec=%d nsec=%d\n",
+ //         current_serv_thread_period.tv_sec,
+ //         current_serv_thread_period.tv_nsec);
+     printf("\nEND of the TEST\n");
+     return 0;
+ }
index 0000000000000000000000000000000000000000,1a0712c7eb6a17ce3264d2ac84159a1b968a78ea..1a0712c7eb6a17ce3264d2ac84159a1b968a78ea
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,8 +1,8 @@@
+ include ../../config.mk
+ include ../../rules.mk
+ CFLAGS += -I$(FNA_PATH)/src_unix/
+ LDFLAGS += -L$(FNA_PATH)/lib -lunixfna -L$(FRSH_PATH)/lib -lfrsh -L$(FOSA_PATH)/lib -lfosa_$(PLATFORM) -lm -lfna
+ test_unix_address.exe: test_unix_address.c
+       $(CC) $< $(CFLAGS)
index 0000000000000000000000000000000000000000,88583a4672d860a282fd90aa5183b00e6a519c6a..88583a4672d860a282fd90aa5183b00e6a519c6a
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,99 +1,99 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>
+ #include <frsh.h>
+ #include <string.h>
+ #include <stdlib.h>
+ int to_unix_path(const frsh_network_address_t addr,
+                         const frsh_stream_id_t       stream,
+                         char                         *str,
+                         size_t                       mx_size)
+ {
+         return snprintf(str, mx_size, "/tmp/unix_fna-%d-%d", addr, stream);
+ }
+ int to_addr_stream(frsh_network_address_t *addr,
+                    frsh_stream_id_t       *stream,
+                    char             *str,
+                    size_t           size)
+ {
+         char *token;
+         char *search = "-";
+         token = strtok(str, search);
+         token = strtok(NULL, search);
+         *addr = atoi(token);
+         token = strtok(NULL, search);
+         *stream = atoi(token);
+         return 0;
+ }
+ int main()
+ {
+         int err;
+         char myaddress[] = "/tmp/unix_fna-45-4";
+         frsh_network_address_t addr;
+         frsh_stream_id_t       stream;
+         char str[100];
+         printf("TEST for unix path\n");
+         err = to_addr_stream(&addr, &stream, myaddress, sizeof(myaddress));
+         printf("to_addr_stream: addr=%d, stream=%d, err=%d\n", addr, stream, err);
+         err = to_unix_path(0, 1, str, sizeof(str));
+         printf("to_unix_path: %s\n", str);
+         return 0;
+ }
index 0000000000000000000000000000000000000000,ee4917cab1b397163a1c31fa8eae8120f9f1764f..ee4917cab1b397163a1c31fa8eae8120f9f1764f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,162 +1,162 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>
+ #include <stdlib.h> /* atoi */
+ #include <unistd.h> /* sleep */
+ #include <assert.h>
+ #include <string.h> /* memset */
+ #include "frsh.h" // for FRSH_CPU_ID_DEFAULT
+ #include "fna.h" // for fna_vres_id_t
+ #include "unix_fna.h" // for unix_fna_operations
+ #define THE_SENDER_ADDR         0
+ #define THE_RECEIVER_ADDR       1
+ #define THE_STREAM_ID           3
+ void sender(void);
+ void receiver(void);
+ int main ()
+ {
+         int err;
+         err = unix_fna_operations.fna_init(FRSH_NETWORK_ID_DEFAULT);
+         assert(err == 0);
+         printf("I am %d\n", FRSH_CPU_ID_DEFAULT);
+         switch(FRSH_CPU_ID_DEFAULT) {
+         case 0:
+                 sender();
+                 break;
+         case 1:
+                 receiver();
+                 break;
+         default:
+                 printf("wrong node number\n");
+                 return -1;
+         }
+         return 0;
+ }
+ void sender(void)
+ {
+         int err, i;
+         frsh_contract_t contract;
+         fna_endpoint_data_t endpoint;
+         char buffer[100];
+         size_t size;
+         printf("I am the sender\n");
+         err = unix_fna_operations.fna_contract_negotiate
+                         (FRSH_NETWORK_ID_DEFAULT,
+                          &contract,
+                          &endpoint.vres);
+         assert(err == 0);
+         endpoint.endpoint_type  = FRSH_SEND_ENDPOINT_TYPE;
+         endpoint.is_bound       = true;
+         endpoint.destination    = THE_RECEIVER_ADDR;
+         endpoint.resource_id    = FRSH_NETWORK_ID_DEFAULT;
+         endpoint.stream_id      = THE_STREAM_ID;
+         for(i=0; i<10; i++) {
+                 sleep(1);
+                 size = snprintf(buffer, sizeof(buffer), "hello world %d", i);
+                 err = unix_fna_operations.fna_send_async(&endpoint,
+                                                          buffer,
+                                                          size);
+                 assert (err == 0);
+                 printf("sender : sent %s\n", buffer);
+         }
+         printf("Sender done\n");
+ }
+ void receiver(void)
+ {
+         int err, i;
+         fna_endpoint_data_t endpoint;
+         frsh_network_address_t from;
+         char buffer[100];
+         size_t received_bytes;
+         printf("I am the receiver\n");
+         endpoint.endpoint_type  = FRSH_RECEIVE_ENDPOINT_TYPE;
+         endpoint.is_bound       = false;
+         endpoint.resource_id    = FRSH_NETWORK_ID_DEFAULT;
+         endpoint.stream_id      = THE_STREAM_ID;
+         err = unix_fna_operations.fna_receive_endpoint_created(&endpoint);
+         assert (err == 0);
+         for(i=0; i<10; i++) {
+                 err = unix_fna_operations.fna_receive_sync(&endpoint,
+                                                            buffer,
+                                                            100,
+                                                            &received_bytes,
+                                                            &from);
+                 assert (err == 0);
+                 buffer[received_bytes] = '\0';
+                 printf("receiver : received %s from %d\n", buffer, from);
+         }
+         printf("Receiver done\n");
+ }
index 0000000000000000000000000000000000000000,f58201e7873e689f13baf2f9790eeeb2ed414f15..f58201e7873e689f13baf2f9790eeeb2ed414f15
mode 000000,100755..100755
--- /dev/null
@@@ -1,0 -1,26 +1,26 @@@
+ export PLATFORM=MARTE_OS
+ rm -f /tmp/unix_fna*
+ cd
+ cd frescor
+ make clean
+ cp frsh/include/frsh_configuration_parameters.h_cpu1 frsh/include/frsh_configuration_parameters.h
+ make all
+ cd fna/tests/tests_unix_fna
+ make test_unix_fna_send_receive.exe
+ cp mprogram /home/dsl/export/test_unix_fna_send_receive_cpu1.exe
+ cd
+ cd frescor
+ make clean
+ cp frsh/include/frsh_configuration_parameters.h_cpu2 frsh/include/frsh_configuration_parameters.h
+ make all
+ cd fna/tests/tests_unix_fna
+ make test_unix_fna_send_receive.exe
+ cp mprogram /home/dsl/export/test_unix_fna_send_receive_cpu2.exe
+ cd /home/dsl/export
+ ./test_unix_fna_send_receive_cpu2.exe &
+ ./test_unix_fna_send_receive_cpu1.exe
index 0000000000000000000000000000000000000000,2186cfa0a7a8d035eb21575c36a87ad0520caa37..2186cfa0a7a8d035eb21575c36a87ad0520caa37
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,174 +1,174 @@@
+ //----------------------------------------------------------------------
+ //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
+ //
+ //    Universidad de Cantabria,              SPAIN
+ //    University of York,                    UK
+ //    Scuola Superiore Sant'Anna,            ITALY
+ //    Kaiserslautern University,             GERMANY
+ //    Univ. Politecnica  Valencia,           SPAIN
+ //    Czech Technical University in Prague,  CZECH REPUBLIC
+ //    ENEA                                   SWEDEN
+ //    Thales Communication S.A.              FRANCE
+ //    Visual Tools S.A.                      SPAIN
+ //    Rapita Systems Ltd                     UK
+ //    Evidence                               ITALY
+ //
+ //    See http://www.frescor.org
+ //
+ //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+ //        in part by the European Union Sixth Framework Programme
+ //        The European Union is not liable of any use that may be
+ //        made of this code.
+ //
+ //
+ //  based on previous work (FSF) done in the FIRST project
+ //
+ //   Copyright (C) 2005  Mälardalen University, SWEDEN
+ //                       Scuola Superiore S.Anna, ITALY
+ //                       Universidad de Cantabria, SPAIN
+ //                       University of York, UK
+ //
+ // This file is part of FNA (Frescor Network Adaptation)
+ //
+ // FNA is free software; you can redistribute it and/or modify it
+ // under terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option) any
+ // later version.  FNA is distributed in the hope that it will be
+ // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // General Public License for more details. You should have received a
+ // copy of the GNU General Public License along with FNA; see file
+ // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+ // Cambridge, MA 02139, USA.
+ //
+ // As a special exception, including FNA header files in a file,
+ // instantiating FNA generics or templates, or linking other files
+ // with FNA objects to produce an executable application, does not
+ // by itself cause the resulting executable application to be covered
+ // by the GNU General Public License. This exception does not
+ // however invalidate any other reasons why the executable file might be
+ // covered by the GNU Public License.
+ // -----------------------------------------------------------------------
+ #include <stdio.h>
+ #include <stdlib.h> /* atoi */
+ #include <unistd.h> /* sleep */
+ #include <assert.h>
+ #include <string.h> /* memset */
+ #include <sys/socket.h>
+ #include <sys/un.h> /* struct sockaddr_un */
+ #define SENDER_PATH     "/tmp/sender_addr"
+ #define RECEIVER_PATH   "/tmp/receiver_addr"
+ void sender(void);
+ void receiver(void);
+ int main (int argc, char **argv)
+ {
+         if (argc != 2) {
+                 printf("please provide the node to execute:\n");
+                 printf("  $./mprogram 0 (sender)\n");
+                 printf("  $./mprogram 1 (receiver)\n");
+                 return -1;
+         }
+         switch(atoi(argv[1])) {
+         case 0:
+                 sender();
+                 break;
+         case 1:
+                 receiver();
+                 break;
+         default:
+                 printf("wrong node number\n");
+                 return -1;
+         }
+         unlink(SENDER_PATH);
+         unlink(RECEIVER_PATH);
+         return 0;
+ }
+ void sender(void)
+ {
+         int sock, err, i;
+         struct sockaddr_un sender_addr, receiver_addr;
+         char buffer[100];
+         size_t size;
+         ssize_t sent_bytes;
+         printf("I am the sender\n");
+         sock = socket(AF_UNIX, SOCK_DGRAM, 0);
+         assert(sock >= 0);
+         memset(&sender_addr, 0, sizeof(sender_addr));
+         sender_addr.sun_family = AF_UNIX;
+         strcpy(sender_addr.sun_path, SENDER_PATH);
+         err = bind(sock, (struct sockaddr *)&sender_addr, sizeof(sender_addr));
+         assert(err >= 0);
+         memset(&receiver_addr, 0, sizeof(receiver_addr));
+         receiver_addr.sun_family = AF_UNIX;
+         strcpy(receiver_addr.sun_path, RECEIVER_PATH);
+         for(i=0; i<10; i++) {
+                 sleep(1);
+                 size = snprintf(buffer, sizeof(buffer), "hello world %d", i);
+                 sent_bytes = sendto(sock,
+                                     buffer,
+                                     size,
+                                     0,
+                                     (struct sockaddr *) &receiver_addr,
+                                     sizeof(receiver_addr));
+                 assert(sent_bytes >= 0);
+                 printf("sender : sent %s\n", buffer);
+         }
+         close(sock);
+         printf("Sender done\n");
+ }
+ void receiver(void)
+ {
+         int sock, err, i;
+         struct sockaddr_un sender_addr, receiver_addr;
+         char buffer[100];
+         ssize_t received_bytes;
+         socklen_t from_len;
+         printf("I am the receiver\n");
+         sock = socket(AF_UNIX, SOCK_DGRAM, 0);
+         assert(sock >= 0);
+         memset(&receiver_addr, 0, sizeof(receiver_addr));
+         receiver_addr.sun_family = AF_UNIX;
+         strcpy(receiver_addr.sun_path, RECEIVER_PATH);
+         err = bind(sock, (struct sockaddr *)&receiver_addr, sizeof(receiver_addr));
+         assert(err >= 0);
+         for(i=0; i<10; i++) {
+                 from_len = sizeof(sender_addr);
+                 received_bytes = recvfrom(sock,
+                                           buffer,
+                                           sizeof(buffer),
+                                           0,
+                                           (struct sockaddr *)&sender_addr,
+                                           &from_len);
+                 assert(received_bytes >= 0);
+                 buffer[received_bytes] = '\0';
+                 printf("receiver : received %s\n", buffer);
+         }
+         close(sock);
+         printf("receiver done\n");
+ }