schema.sql.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #define ZT_NETCONF_SCHEMA_SQL \
  2. "CREATE TABLE Config (\n"\
  3. " k varchar(16) PRIMARY KEY NOT NULL,\n"\
  4. " v varchar(1024) NOT NULL\n"\
  5. ");\n"\
  6. "\n"\
  7. "CREATE TABLE Network (\n"\
  8. " id char(16) PRIMARY KEY NOT NULL,\n"\
  9. " name varchar(128) NOT NULL,\n"\
  10. " private integer NOT NULL DEFAULT(1),\n"\
  11. " enableBroadcast integer NOT NULL DEFAULT(1),\n"\
  12. " allowPassiveBridging integer NOT NULL DEFAULT(0),\n"\
  13. " v4AssignMode varchar(8) NOT NULL DEFAULT('none'),\n"\
  14. " v6AssignMode varchar(8) NOT NULL DEFAULT('none'),\n"\
  15. " multicastLimit integer NOT NULL DEFAULT(32),\n"\
  16. " creationTime integer NOT NULL DEFAULT(0),\n"\
  17. " revision integer NOT NULL DEFAULT(1)\n"\
  18. ");\n"\
  19. "\n"\
  20. "CREATE TABLE Node (\n"\
  21. " id char(10) PRIMARY KEY NOT NULL,\n"\
  22. " identity varchar(4096) NOT NULL,\n"\
  23. " lastAt varchar(64),\n"\
  24. " lastSeen integer NOT NULL DEFAULT(0),\n"\
  25. " firstSeen integer NOT NULL DEFAULT(0)\n"\
  26. ");\n"\
  27. "\n"\
  28. "CREATE TABLE IpAssignment (\n"\
  29. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  30. " nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,\n"\
  31. " ip blob(16) NOT NULL,\n"\
  32. " ipNetmaskBits integer NOT NULL DEFAULT(0),\n"\
  33. " ipVersion integer NOT NULL DEFAULT(4)\n"\
  34. ");\n"\
  35. "\n"\
  36. "CREATE INDEX IpAssignment_networkId_ip ON IpAssignment (networkId, ip);\n"\
  37. "\n"\
  38. "CREATE INDEX IpAssignment_networkId_nodeId ON IpAssignment (networkId, nodeId);\n"\
  39. "\n"\
  40. "CREATE INDEX IpAssignment_networkId ON IpAssignment (networkId);\n"\
  41. "\n"\
  42. "CREATE TABLE IpAssignmentPool (\n"\
  43. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  44. " ipNetwork blob(16) NOT NULL,\n"\
  45. " ipNetmaskBits integer NOT NULL,\n"\
  46. " ipVersion integer NOT NULL DEFAULT(4)\n"\
  47. ");\n"\
  48. "\n"\
  49. "CREATE INDEX IpAssignmentPool_networkId ON IpAssignmentPool (networkId);\n"\
  50. "\n"\
  51. "CREATE TABLE Member (\n"\
  52. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  53. " nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,\n"\
  54. " authorized integer NOT NULL DEFAULT(0),\n"\
  55. " activeBridge integer NOT NULL DEFAULT(0),\n"\
  56. " PRIMARY KEY (networkId, nodeId)\n"\
  57. ");\n"\
  58. "\n"\
  59. "CREATE INDEX Member_networkId ON Member (networkId);\n"\
  60. "\n"\
  61. "CREATE INDEX Member_networkId_activeBridge ON Member(networkId, activeBridge);\n"\
  62. "\n"\
  63. "CREATE TABLE MulticastRate (\n"\
  64. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  65. " mgMac char(12) NOT NULL,\n"\
  66. " mgAdi integer NOT NULL DEFAULT(0),\n"\
  67. " preload integer NOT NULL,\n"\
  68. " maxBalance integer NOT NULL,\n"\
  69. " accrual integer NOT NULL\n"\
  70. ");\n"\
  71. "\n"\
  72. "CREATE INDEX MulticastRate_networkId ON MulticastRate (networkId);\n"\
  73. "\n"\
  74. "CREATE TABLE Relay (\n"\
  75. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  76. " nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,\n"\
  77. " phyAddress varchar(64) NOT NULL,\n"\
  78. " PRIMARY KEY (networkId, nodeId)\n"\
  79. ");\n"\
  80. "\n"\
  81. "CREATE INDEX Relay_networkId ON Relay (networkId);\n"\
  82. "\n"\
  83. "CREATE TABLE Rule (\n"\
  84. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  85. " ruleId integer NOT NULL,\n"\
  86. " nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,\n"\
  87. " vlanId integer,\n"\
  88. " vlanPcp integer,\n"\
  89. " etherType integer,\n"\
  90. " macSource char(12),\n"\
  91. " macDest char(12),\n"\
  92. " ipSource varchar(64),\n"\
  93. " ipDest varchar(64),\n"\
  94. " ipTos integer,\n"\
  95. " ipProtocol integer,\n"\
  96. " ipSourcePort integer,\n"\
  97. " ipDestPort integer,\n"\
  98. " flags integer,\n"\
  99. " invFlags integer,\n"\
  100. " \"action\" varchar(4096) NOT NULL DEFAULT('accept')\n"\
  101. ");\n"\
  102. "\n"\
  103. "CREATE INDEX Rule_networkId ON Rule (networkId);\n"\
  104. ""