schema.sql.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. " memberRevisionCounter integer NOT NULL DEFAULT(1)\n"\
  19. ");\n"\
  20. "\n"\
  21. "CREATE TABLE AuthToken (\n"\
  22. " id integer PRIMARY KEY NOT NULL,\n"\
  23. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  24. " authMode integer NOT NULL DEFAULT(1),\n"\
  25. " useCount integer NOT NULL DEFAULT(0),\n"\
  26. " maxUses integer NOT NULL DEFAULT(0),\n"\
  27. " expiresAt integer NOT NULL DEFAULT(0),\n"\
  28. " token varchar(256) NOT NULL\n"\
  29. ");\n"\
  30. "\n"\
  31. "CREATE INDEX AuthToken_networkId_token ON AuthToken(networkId,token);\n"\
  32. "\n"\
  33. "CREATE TABLE Node (\n"\
  34. " id char(10) PRIMARY KEY NOT NULL,\n"\
  35. " identity varchar(4096) NOT NULL\n"\
  36. ");\n"\
  37. "\n"\
  38. "CREATE TABLE NodeHistory (\n"\
  39. " nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,\n"\
  40. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  41. " networkVisitCounter INTEGER NOT NULL DEFAULT(0),\n"\
  42. " networkRequestAuthorized INTEGER NOT NULL DEFAULT(0),\n"\
  43. " requestTime INTEGER NOT NULL DEFAULT(0),\n"\
  44. " clientMajorVersion INTEGER NOT NULL DEFAULT(0),\n"\
  45. " clientMinorVersion INTEGER NOT NULL DEFAULT(0),\n"\
  46. " clientRevision INTEGER NOT NULL DEFAULT(0),\n"\
  47. " networkRequestMetaData VARCHAR(1024),\n"\
  48. " fromAddress VARCHAR(128)\n"\
  49. ");\n"\
  50. "\n"\
  51. "CREATE INDEX NodeHistory_nodeId ON NodeHistory (nodeId);\n"\
  52. "CREATE INDEX NodeHistory_networkId ON NodeHistory (networkId);\n"\
  53. "CREATE INDEX NodeHistory_requestTime ON NodeHistory (requestTime);\n"\
  54. "\n"\
  55. "CREATE TABLE Gateway (\n"\
  56. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  57. " ip blob(16) NOT NULL,\n"\
  58. " ipVersion integer NOT NULL DEFAULT(4),\n"\
  59. " metric integer NOT NULL DEFAULT(0)\n"\
  60. ");\n"\
  61. "\n"\
  62. "CREATE UNIQUE INDEX Gateway_networkId_ip ON Gateway (networkId, ip);\n"\
  63. "\n"\
  64. "CREATE TABLE IpAssignment (\n"\
  65. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  66. " nodeId char(10) REFERENCES Node(id) ON DELETE CASCADE,\n"\
  67. " type integer NOT NULL DEFAULT(0),\n"\
  68. " ip blob(16) NOT NULL,\n"\
  69. " ipNetmaskBits integer NOT NULL DEFAULT(0),\n"\
  70. " ipVersion integer NOT NULL DEFAULT(4)\n"\
  71. ");\n"\
  72. "\n"\
  73. "CREATE UNIQUE INDEX IpAssignment_networkId_ip ON IpAssignment (networkId, ip);\n"\
  74. "\n"\
  75. "CREATE INDEX IpAssignment_networkId_nodeId ON IpAssignment (networkId, nodeId);\n"\
  76. "\n"\
  77. "CREATE TABLE IpAssignmentPool (\n"\
  78. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  79. " ipRangeStart blob(16) NOT NULL,\n"\
  80. " ipRangeEnd blob(16) NOT NULL,\n"\
  81. " ipVersion integer NOT NULL DEFAULT(4)\n"\
  82. ");\n"\
  83. "\n"\
  84. "CREATE UNIQUE INDEX IpAssignmentPool_networkId_ipRangeStart ON IpAssignmentPool (networkId,ipRangeStart);\n"\
  85. "\n"\
  86. "CREATE TABLE Member (\n"\
  87. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  88. " nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,\n"\
  89. " authorized integer NOT NULL DEFAULT(0),\n"\
  90. " activeBridge integer NOT NULL DEFAULT(0),\n"\
  91. " memberRevision integer NOT NULL DEFAULT(0),\n"\
  92. " PRIMARY KEY (networkId, nodeId)\n"\
  93. ");\n"\
  94. "\n"\
  95. "CREATE INDEX Member_networkId_activeBridge ON Member(networkId, activeBridge);\n"\
  96. "CREATE INDEX Member_networkId_memberRevision ON Member(networkId, memberRevision);\n"\
  97. "\n"\
  98. "CREATE TABLE Relay (\n"\
  99. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  100. " address char(10) NOT NULL,\n"\
  101. " phyAddress varchar(64) NOT NULL\n"\
  102. ");\n"\
  103. "\n"\
  104. "CREATE UNIQUE INDEX Relay_networkId_address ON Relay (networkId,address);\n"\
  105. "\n"\
  106. "CREATE TABLE Rule (\n"\
  107. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  108. " ruleNo integer NOT NULL,\n"\
  109. " nodeId char(10) REFERENCES Node(id),\n"\
  110. " sourcePort char(10),\n"\
  111. " destPort char(10),\n"\
  112. " vlanId integer,\n"\
  113. " vlanPcp integer,\n"\
  114. " etherType integer,\n"\
  115. " macSource char(12),\n"\
  116. " macDest char(12),\n"\
  117. " ipSource varchar(64),\n"\
  118. " ipDest varchar(64),\n"\
  119. " ipTos integer,\n"\
  120. " ipProtocol integer,\n"\
  121. " ipSourcePort integer,\n"\
  122. " ipDestPort integer,\n"\
  123. " flags integer,\n"\
  124. " invFlags integer,\n"\
  125. " \"action\" varchar(4096) NOT NULL DEFAULT('accept')\n"\
  126. ");\n"\
  127. "\n"\
  128. "CREATE UNIQUE INDEX Rule_networkId_ruleNo ON Rule (networkId, ruleNo);\n"\
  129. ""