schema.sql 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. CREATE TABLE Config (
  2. k varchar(16) PRIMARY KEY NOT NULL,
  3. v varchar(1024) NOT NULL
  4. );
  5. CREATE TABLE Network (
  6. id char(16) PRIMARY KEY NOT NULL,
  7. name varchar(128) NOT NULL,
  8. private integer NOT NULL DEFAULT(1),
  9. enableBroadcast integer NOT NULL DEFAULT(1),
  10. allowPassiveBridging integer NOT NULL DEFAULT(0),
  11. v4AssignMode varchar(8) NOT NULL DEFAULT('none'),
  12. v6AssignMode varchar(8) NOT NULL DEFAULT('none'),
  13. multicastLimit integer NOT NULL DEFAULT(32),
  14. creationTime integer NOT NULL DEFAULT(0),
  15. revision integer NOT NULL DEFAULT(1),
  16. memberRevisionCounter integer NOT NULL DEFAULT(1)
  17. );
  18. CREATE TABLE AuthToken (
  19. id integer PRIMARY KEY NOT NULL,
  20. networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
  21. authMode integer NOT NULL DEFAULT(1),
  22. useCount integer NOT NULL DEFAULT(0),
  23. maxUses integer NOT NULL DEFAULT(0),
  24. expiresAt integer NOT NULL DEFAULT(0),
  25. token varchar(256) NOT NULL
  26. );
  27. CREATE INDEX AuthToken_networkId_token ON AuthToken(networkId,token);
  28. CREATE TABLE Node (
  29. id char(10) PRIMARY KEY NOT NULL,
  30. identity varchar(4096) NOT NULL
  31. );
  32. CREATE TABLE NodeHistory (
  33. nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,
  34. networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
  35. networkVisitCounter INTEGER NOT NULL DEFAULT(0),
  36. networkRequestAuthorized INTEGER NOT NULL DEFAULT(0),
  37. requestTime INTEGER NOT NULL DEFAULT(0),
  38. clientMajorVersion INTEGER NOT NULL DEFAULT(0),
  39. clientMinorVersion INTEGER NOT NULL DEFAULT(0),
  40. clientRevision INTEGER NOT NULL DEFAULT(0),
  41. networkRequestMetaData VARCHAR(1024),
  42. fromAddress VARCHAR(128)
  43. );
  44. CREATE INDEX NodeHistory_nodeId ON NodeHistory (nodeId);
  45. CREATE INDEX NodeHistory_networkId ON NodeHistory (networkId);
  46. CREATE INDEX NodeHistory_requestTime ON NodeHistory (requestTime);
  47. CREATE TABLE Gateway (
  48. networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
  49. ip blob(16) NOT NULL,
  50. ipVersion integer NOT NULL DEFAULT(4),
  51. metric integer NOT NULL DEFAULT(0)
  52. );
  53. CREATE UNIQUE INDEX Gateway_networkId_ip ON Gateway (networkId, ip);
  54. CREATE TABLE IpAssignment (
  55. networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
  56. nodeId char(10) REFERENCES Node(id) ON DELETE CASCADE,
  57. type integer NOT NULL DEFAULT(0),
  58. ip blob(16) NOT NULL,
  59. ipNetmaskBits integer NOT NULL DEFAULT(0),
  60. ipVersion integer NOT NULL DEFAULT(4)
  61. );
  62. CREATE UNIQUE INDEX IpAssignment_networkId_ip ON IpAssignment (networkId, ip);
  63. CREATE INDEX IpAssignment_networkId_nodeId ON IpAssignment (networkId, nodeId);
  64. CREATE TABLE IpAssignmentPool (
  65. networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
  66. ipRangeStart blob(16) NOT NULL,
  67. ipRangeEnd blob(16) NOT NULL,
  68. ipVersion integer NOT NULL DEFAULT(4)
  69. );
  70. CREATE UNIQUE INDEX IpAssignmentPool_networkId_ipRangeStart ON IpAssignmentPool (networkId,ipRangeStart);
  71. CREATE TABLE Member (
  72. networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
  73. nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,
  74. authorized integer NOT NULL DEFAULT(0),
  75. activeBridge integer NOT NULL DEFAULT(0),
  76. memberRevision integer NOT NULL DEFAULT(0),
  77. PRIMARY KEY (networkId, nodeId)
  78. );
  79. CREATE INDEX Member_networkId_activeBridge ON Member(networkId, activeBridge);
  80. CREATE INDEX Member_networkId_memberRevision ON Member(networkId, memberRevision);
  81. CREATE TABLE Relay (
  82. networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
  83. address char(10) NOT NULL,
  84. phyAddress varchar(64) NOT NULL
  85. );
  86. CREATE UNIQUE INDEX Relay_networkId_address ON Relay (networkId,address);
  87. CREATE TABLE Rule (
  88. networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
  89. ruleNo integer NOT NULL,
  90. nodeId char(10) REFERENCES Node(id),
  91. sourcePort char(10),
  92. destPort char(10),
  93. vlanId integer,
  94. vlanPcp integer,
  95. etherType integer,
  96. macSource char(12),
  97. macDest char(12),
  98. ipSource varchar(64),
  99. ipDest varchar(64),
  100. ipTos integer,
  101. ipProtocol integer,
  102. ipSourcePort integer,
  103. ipDestPort integer,
  104. flags integer,
  105. invFlags integer,
  106. "action" varchar(4096) NOT NULL DEFAULT('accept')
  107. );
  108. CREATE UNIQUE INDEX Rule_networkId_ruleNo ON Rule (networkId, ruleNo);