forked from MrKalzu/traceroute_map
New database schema.
This commit is contained in:
parent
93e785c2ae
commit
4ffd7052a5
@ -43,31 +43,60 @@ def parse_traceroute_output(output):
|
|||||||
previous_ip = ip_address
|
previous_ip = ip_address
|
||||||
return hops
|
return hops
|
||||||
|
|
||||||
def create_tables():
|
def create_tables(databasefile):
|
||||||
conn = sqlite3.connect('traceroute.db')
|
# Connect to the SQLite database
|
||||||
|
conn = sqlite3.connect(databasefile)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# Table to store unique links
|
# SQL statements to create the tables
|
||||||
cursor.execute('''
|
create_links_table = """
|
||||||
CREATE TABLE IF NOT EXISTS links (
|
CREATE TABLE IF NOT EXISTS Links (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
source_ip TEXT,
|
source_ip TEXT NOT NULL,
|
||||||
destination_ip TEXT,
|
destination_ip TEXT NOT NULL,
|
||||||
UNIQUE(source_ip, destination_ip)
|
UNIQUE(source_ip, destination_ip)
|
||||||
)
|
);
|
||||||
''')
|
"""
|
||||||
|
|
||||||
# Table to store latency and timestamp for each link
|
create_paths_table = """
|
||||||
cursor.execute('''
|
CREATE TABLE IF NOT EXISTS Paths (
|
||||||
CREATE TABLE IF NOT EXISTS link_latency (
|
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
link_id INTEGER,
|
start_ip TEXT NOT NULL,
|
||||||
latency REAL,
|
end_ip TEXT NOT NULL,
|
||||||
timestamp TEXT,
|
hops_json TEXT NOT NULL,
|
||||||
FOREIGN KEY (link_id) REFERENCES links (id)
|
UNIQUE(start_ip, end_ip, hops_json)
|
||||||
)
|
);
|
||||||
''')
|
"""
|
||||||
|
|
||||||
|
create_latency_table = """
|
||||||
|
CREATE TABLE IF NOT EXISTS Latency (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
link_id INTEGER NOT NULL,
|
||||||
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
latency_ms REAL NOT NULL,
|
||||||
|
FOREIGN KEY (link_id) REFERENCES Links(id)
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
|
||||||
|
create_hopdetails_table = """
|
||||||
|
CREATE TABLE IF NOT EXISTS HopDetails (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
link_id INTEGER NOT NULL,
|
||||||
|
ttl INTEGER,
|
||||||
|
icmp_type INTEGER,
|
||||||
|
icmp_code INTEGER,
|
||||||
|
packet_loss REAL,
|
||||||
|
FOREIGN KEY (link_id) REFERENCES Links(id)
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Execute the SQL statements
|
||||||
|
cursor.execute(create_links_table)
|
||||||
|
cursor.execute(create_paths_table)
|
||||||
|
cursor.execute(create_latency_table)
|
||||||
|
cursor.execute(create_hopdetails_table)
|
||||||
|
|
||||||
|
# Commit changes and close the connection
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user