Symulacja NAT na przedmiot Symulacje Komputerowe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.3 KiB

  1. /**
  2. * @file Main.cpp
  3. *
  4. * Created on: 07-01-2017
  5. * @author Piotr Dergun
  6. */
  7. #include "common.h"
  8. #include "Node.h"
  9. #include "NATRouter.h"
  10. #include "Simulation.h"
  11. /**
  12. * zwraca na stderr informację o parametrach uruchomienia programu
  13. * @param programName nazwa pliku wykonywalnego
  14. */
  15. void usage(string programName)
  16. {
  17. cerr << endl;
  18. cerr << "Usage:" << endl;
  19. cerr << programName << " p2p\t\t\tP2P simulation" << endl;
  20. cerr << programName << " nat <nodes>\t\tNAT overflow simulation" << endl;
  21. cerr << endl;
  22. exit(1);
  23. }
  24. /**
  25. * główna funkcja programu
  26. * @param argc ilość argumentów
  27. * @param argv tablica z argumentami
  28. */
  29. int main(int argc, char *argv[])
  30. {
  31. char *endptr=NULL;
  32. int nodesCount;
  33. if (argc < 2)
  34. usage(argv[0]);
  35. if (!strcmp(argv[1], "p2p"))
  36. {
  37. Simulation sim;
  38. sim.createThread("timer", SIM_TIMER, &sim);
  39. sim.p2pSimulation();
  40. }
  41. else if (!strcmp(argv[1], "nat"))
  42. {
  43. if (argc < 3)
  44. usage(argv[0]);
  45. nodesCount = strtol(argv[2], &endptr, 10);
  46. if (nodesCount < 1 || nodesCount > 253)
  47. {
  48. cerr << "Invalid number of nodes format [1,253]" << endl;
  49. usage(argv[0]);
  50. }
  51. Simulation sim;
  52. sim.createThread("timer", SIM_TIMER, &sim);
  53. sim.natOverflowSimulation(nodesCount);
  54. }
  55. else if (!strcmp(argv[1], "-v"))
  56. {
  57. }
  58. else
  59. usage(argv[0]);
  60. return 0;
  61. }