SwitchCore.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef SwitchCore_H
  16. #define SwitchCore_H
  17. #include "interface/Interface.h"
  18. #include "util/log/Log.h"
  19. #include "wire/Message.h"
  20. #include "util/events/EventBase.h"
  21. #include "util/Linker.h"
  22. Linker_require("switch/SwitchCore.c")
  23. #include <stdint.h>
  24. /** The switch core which is opaque to users. */
  25. struct SwitchCore;
  26. /**
  27. * Create a new router core.
  28. *
  29. * @param logger what to log output to.
  30. * @param allocator the memory allocator to use for allocating the core context and interfaces.
  31. */
  32. struct SwitchCore* SwitchCore_new(struct Log* logger,
  33. struct Allocator* allocator,
  34. struct EventBase* base);
  35. /**
  36. * Register a new interface.
  37. * All interfaces are point to point so messages sent down an interface.
  38. *
  39. * @param iface the interface to add.
  40. * @param trust the amount that you trust the connected node.
  41. * @param labelOut_be a buffer which will be filled with the label part for getting
  42. * to the newly added node. It will be set to the big endian value.
  43. * @param core the switchcore.
  44. * @return 0 on success, SwitchCore_addInterface_OUT_OF_SPACE if there are no more interface slots.
  45. */
  46. #define SwitchCore_addInterface_OUT_OF_SPACE -1
  47. int SwitchCore_addInterface(struct Interface* iface,
  48. const uint64_t trust,
  49. uint64_t* labelOut_be,
  50. struct SwitchCore* core);
  51. /**
  52. * Set the router interface.
  53. * This interface is needed by all switches because a switch cannot function without a router.
  54. * Do not send messages before registering this interface and at least one other.
  55. *
  56. * @param iface the router interface.
  57. * @param core the switchcore.
  58. * @return 0
  59. */
  60. int SwitchCore_setRouterInterface(struct Interface* iface, struct SwitchCore* core);
  61. void SwitchCore_swapInterfaces(struct Interface* if1, struct Interface* if2);
  62. #endif