commit
4894e1792a
|
@ -29,6 +29,9 @@ parser.add_argument('-a', '--aliases',
|
|||
parser.add_argument('-m', '--mesh', action='append',
|
||||
help='batman mesh interface')
|
||||
|
||||
parser.add_argument('-o', '--obscure', action='store_true',
|
||||
help='obscure client macs')
|
||||
|
||||
parser.add_argument('-d', '--destination-directory', action='store',
|
||||
help='destination directory for generated files',required=True)
|
||||
|
||||
|
@ -53,6 +56,9 @@ if options['aliases']:
|
|||
for aliases in options['aliases']:
|
||||
db.import_aliases(json.load(open(aliases)))
|
||||
|
||||
if options['obscure']:
|
||||
db.obscure_clients()
|
||||
|
||||
scriptdir = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
rrd = rrd(scriptdir + "/nodedb/", options['destination_directory'] + "/nodes")
|
||||
|
|
70
nodedb.py
70
nodedb.py
|
@ -36,6 +36,13 @@ class NodeDB:
|
|||
|
||||
raise
|
||||
|
||||
def maybe_node_by_id(self, mac):
|
||||
for node in self._nodes:
|
||||
if mac.lower() == node.id:
|
||||
return node
|
||||
|
||||
raise
|
||||
|
||||
def parse_vis_data(self,vis_data):
|
||||
for x in vis_data:
|
||||
|
||||
|
@ -204,6 +211,69 @@ class NodeDB:
|
|||
|
||||
link.type = "vpn"
|
||||
|
||||
def obscure_clients(self):
|
||||
|
||||
globalIdCounter = 0
|
||||
nodeCounters = {}
|
||||
clientIds = {}
|
||||
|
||||
for node in self._nodes:
|
||||
if node.flags['client']:
|
||||
node.macs = set()
|
||||
clientIds[node.id] = None
|
||||
sys.stderr.write("client:" + node.id)
|
||||
|
||||
for link in self._links:
|
||||
ids = link.source.interface
|
||||
idt = link.target.interface
|
||||
try:
|
||||
node_source = self.maybe_node_by_fuzzy_mac(ids)
|
||||
node_target = self.maybe_node_by_id(idt)
|
||||
if ids in clientIds and idt in clientIds:
|
||||
# This is for corner cases, when a client
|
||||
# is linked to another client.
|
||||
clientIds[ids] = str(globalIdCounter)
|
||||
id1 = str(globalIdCounter)
|
||||
globalIdCounter += 1
|
||||
|
||||
clientIds[idt] = str(globalIdCounter)
|
||||
idt = str(globalIdCounter)
|
||||
globalIdCounter += 1
|
||||
|
||||
elif ids in clientIds:
|
||||
sys.stderr.write("passed ids")
|
||||
newId = generateId(idt)
|
||||
clientIds[ids] = newId
|
||||
ids = newId
|
||||
|
||||
link.source.interface = ids;
|
||||
node_source.id = ids;
|
||||
|
||||
elif idt in clientIds:
|
||||
sys.stderr.write("passed idt")
|
||||
newId = generateId(ids,nodeCounters)
|
||||
clientIds[idt] = newId
|
||||
idt = newId
|
||||
|
||||
link.target.interface = idt;
|
||||
node_target.id = idt;
|
||||
|
||||
link.id = ids + "-" + idt
|
||||
|
||||
except:
|
||||
raise
|
||||
|
||||
# extends node id by incremented node counter
|
||||
def generateId(nodeId,nodeCounters):
|
||||
if nodeId in nodeCounters:
|
||||
n = nodeCounters[nodeId]
|
||||
nodeCounters[nodeId] = n + 1
|
||||
else:
|
||||
nodeCounters[nodeId] = 1
|
||||
n = 0
|
||||
|
||||
return nodeId + "_" + str(n)
|
||||
|
||||
# compares two MACs and decides whether they are
|
||||
# similar and could be from the same node
|
||||
def is_similar(a, b):
|
||||
|
|
Loading…
Reference in a new issue