schema.sql.c 4.7 KB

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