schema.sql.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 Gateway (\n"\
  39. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  40. " ip blob(16) NOT NULL,\n"\
  41. " ipVersion integer NOT NULL DEFAULT(4),\n"\
  42. " metric integer NOT NULL DEFAULT(0)\n"\
  43. ");\n"\
  44. "\n"\
  45. "CREATE UNIQUE INDEX Gateway_networkId_ip ON Gateway (networkId, ip);\n"\
  46. "\n"\
  47. "CREATE TABLE IpAssignment (\n"\
  48. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  49. " nodeId char(10) REFERENCES Node(id) ON DELETE CASCADE,\n"\
  50. " type integer NOT NULL DEFAULT(0),\n"\
  51. " ip blob(16) NOT NULL,\n"\
  52. " ipNetmaskBits integer NOT NULL DEFAULT(0),\n"\
  53. " ipVersion integer NOT NULL DEFAULT(4)\n"\
  54. ");\n"\
  55. "\n"\
  56. "CREATE UNIQUE INDEX IpAssignment_networkId_ip ON IpAssignment (networkId, ip);\n"\
  57. "\n"\
  58. "CREATE INDEX IpAssignment_networkId_nodeId ON IpAssignment (networkId, nodeId);\n"\
  59. "\n"\
  60. "CREATE TABLE IpAssignmentPool (\n"\
  61. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  62. " ipRangeStart blob(16) NOT NULL,\n"\
  63. " ipRangeEnd blob(16) NOT NULL,\n"\
  64. " ipVersion integer NOT NULL DEFAULT(4)\n"\
  65. ");\n"\
  66. "\n"\
  67. "CREATE UNIQUE INDEX IpAssignmentPool_networkId_ipRangeStart ON IpAssignmentPool (networkId,ipRangeStart);\n"\
  68. "\n"\
  69. "CREATE TABLE Member (\n"\
  70. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  71. " nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,\n"\
  72. " authorized integer NOT NULL DEFAULT(0),\n"\
  73. " activeBridge integer NOT NULL DEFAULT(0),\n"\
  74. " memberRevision integer NOT NULL DEFAULT(0),\n"\
  75. " PRIMARY KEY (networkId, nodeId)\n"\
  76. ");\n"\
  77. "\n"\
  78. "CREATE INDEX Member_networkId_activeBridge ON Member(networkId, activeBridge);\n"\
  79. "CREATE INDEX Member_networkId_memberRevision ON Member(networkId, memberRevision);\n"\
  80. "\n"\
  81. "CREATE TABLE Relay (\n"\
  82. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  83. " address char(10) NOT NULL,\n"\
  84. " phyAddress varchar(64) NOT NULL\n"\
  85. ");\n"\
  86. "\n"\
  87. "CREATE UNIQUE INDEX Relay_networkId_address ON Relay (networkId,address);\n"\
  88. "\n"\
  89. "CREATE TABLE Rule (\n"\
  90. " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
  91. " ruleNo integer NOT NULL,\n"\
  92. " nodeId char(10) REFERENCES Node(id),\n"\
  93. " sourcePort char(10),\n"\
  94. " destPort char(10),\n"\
  95. " vlanId integer,\n"\
  96. " vlanPcp integer,\n"\
  97. " etherType integer,\n"\
  98. " macSource char(12),\n"\
  99. " macDest char(12),\n"\
  100. " ipSource varchar(64),\n"\
  101. " ipDest varchar(64),\n"\
  102. " ipTos integer,\n"\
  103. " ipProtocol integer,\n"\
  104. " ipSourcePort integer,\n"\
  105. " ipDestPort integer,\n"\
  106. " flags integer,\n"\
  107. " invFlags integer,\n"\
  108. " \"action\" varchar(4096) NOT NULL DEFAULT('accept')\n"\
  109. ");\n"\
  110. "\n"\
  111. "CREATE UNIQUE INDEX Rule_networkId_ruleNo ON Rule (networkId, ruleNo);\n"\
  112. ""