コード例 #1
0
ファイル: nodedb.py プロジェクト: smoe/ffmap-backend
  def parse_vis_data(self,vis_data):
    for x in vis_data:

      if 'of' in x:
        try:
          node = self.maybe_node_by_mac((x['of'], x['secondary']))
        except:
          node = Node()
          node.flags['online'] = True
          if 'legacy' in x:
            node.flags['legacy'] = True
          self._nodes.append(node)

        node.add_mac(x['of'])
        node.add_mac(x['secondary'])

    for x in vis_data:

      if 'router' in x:
        try:
          node = self.maybe_node_by_mac((x['router'], ))
        except:
          node = Node()
          node.flags['online'] = True
          if 'legacy' in x:
            node.flags['legacy'] = True
          node.add_mac(x['router'])
          self._nodes.append(node)

        # If it's a TT link and the MAC is very similar
        # consider this MAC as one of the routers
        # MACs
        if 'gateway' in x and x['label'] == "TT":
          if is_similar(x['router'], x['gateway']):
            node.add_mac(x['gateway'])

            # skip processing as regular link
            continue

        try:
          if 'neighbor' in x:
            try:
              node = self.maybe_node_by_mac((x['neighbor']))
            except:
              continue

          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          node = self.maybe_node_by_mac((x['neighbor'], ))
        except:
          node = Node()
          node.flags['online'] = True
          if x['label'] == 'TT':
            node.flags['client'] = True

          node.add_mac(x['neighbor'])
          self._nodes.append(node)

    for x in vis_data:

      if 'router' in x:
        try:
          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          router = self.maybe_node_by_mac((x['router'], ))
          neighbor = self.maybe_node_by_mac((x['neighbor'], ))
        except:
          continue

        # filter TT links merged in previous step
        if router == neighbor:
          continue

        link = Link()
        link.source = LinkConnector()
        link.source.interface = x['router']
        link.source.id = self._nodes.index(router)
        link.target = LinkConnector()
        link.target.interface = x['neighbor']
        link.target.id = self._nodes.index(neighbor)
        link.quality = x['label']
        link.id = "-".join(sorted((link.source.interface, link.target.interface)))

        if x['label'] == "TT":
          link.type = "client"

        self._links.append(link)

    for x in vis_data:

      if 'primary' in x:
        try:
          node = self.maybe_node_by_mac((x['primary'], ))
        except:
          continue

        node.id = x['primary']
コード例 #2
0
    def parse_vis_data(self, vis_data):
        for x in vis_data:

            if 'of' in x:
                try:
                    node = self.maybe_node_by_mac((x['of'], x['secondary']))
                except:
                    node = Node()
                    node.lastseen = self.time
                    node.flags['online'] = True
                    if 'legacy' in x:
                        node.flags['legacy'] = True
                    self._nodes.append(node)

                node.add_mac(x['of'])
                node.add_mac(x['secondary'])

        for x in vis_data:

            if 'router' in x:
                try:
                    node = self.maybe_node_by_mac((x['router'], ))
                except:
                    node = Node()
                    node.lastseen = self.time
                    node.flags['online'] = True
                    if 'legacy' in x:
                        node.flags['legacy'] = True
                    node.add_mac(x['router'])
                    self._nodes.append(node)

                # If it's a TT link and the MAC is very similar
                # consider this MAC as one of the routers
                # MACs
                if 'gateway' in x and x['label'] == "TT":
                    if is_similar(x['router'], x['gateway']):
                        node.add_mac(x['gateway'])

                        # skip processing as regular link
                        continue

                try:
                    if 'neighbor' in x:
                        try:
                            node = self.maybe_node_by_mac((x['neighbor']))
                        except:
                            continue

                    if 'gateway' in x:
                        x['neighbor'] = x['gateway']

                    node = self.maybe_node_by_mac((x['neighbor'], ))
                except:
                    node = Node()
                    node.lastseen = self.time
                    node.flags['online'] = True
                    if x['label'] == 'TT':
                        node.flags['client'] = True

                    node.add_mac(x['neighbor'])
                    self._nodes.append(node)

        for x in vis_data:

            if 'router' in x:
                try:
                    if 'gateway' in x:
                        x['neighbor'] = x['gateway']

                    router = self.maybe_node_by_mac((x['router'], ))
                    neighbor = self.maybe_node_by_mac((x['neighbor'], ))
                except:
                    continue

                # filter TT links merged in previous step
                if router == neighbor:
                    continue

                link = Link()
                link.source = LinkConnector()
                link.source.interface = x['router']
                link.source.id = self._nodes.index(router)
                link.target = LinkConnector()
                link.target.interface = x['neighbor']
                link.target.id = self._nodes.index(neighbor)
                link.quality = x['label']
                link.id = "-".join(
                    sorted((link.source.interface, link.target.interface)))

                if x['label'] == "TT":
                    link.type = "client"

                self._links.append(link)

        for x in vis_data:

            if 'primary' in x:
                try:
                    node = self.maybe_node_by_mac((x['primary'], ))
                except:
                    continue

                node.id = x['primary']
コード例 #3
0
ファイル: nodedb.py プロジェクト: NeoRaider/ffmap-d3
  def import_batman(self, lines):

    for line in lines:
      x = json.loads(line)

      if 'of' in x:
        try:
          node = self.maybe_node_by_mac((x['of'], x['secondary']))
        except:
          node = Node()
          node.flags['online'] = True
          self._nodes.append(node)

        node.add_mac(x['of'])
        node.add_mac(x['secondary'])

    for line in lines:
      x = json.loads(line)

      if 'router' in x:
        try:
          node = self.maybe_node_by_mac((x['router'], ))
        except:
          node = Node()
          node.flags['online'] = True
          node.add_mac(x['router'])
          self._nodes.append(node)

        # If it's a TT link and the MAC is very similar
        # consider this MAC as one of the routers
        # MACs
        if 'gateway' in x and x['label'] == "TT":
          router = list(int(i, 16) for i in x['router'].split(":"))
          gateway = list(int(i, 16) for i in x['gateway'].split(":"))

          # first byte must only differ in bit 2
          if router[0] == gateway[0] | 2:
            # count different bytes
            a = [x for x in zip(router[1:], gateway[1:]) if x[0] != x[1]]

            # no more than two additional bytes must differ
            if len(a) <= 2:
              delta = 0
              if len(a) > 0:
                delta = sum(abs(i[0] -i[1]) for i in a)

              if delta < 8:
                # This TT link looks like a mac of the router!
                node.add_mac(x['gateway'])

                # skip processing as regular link
                continue

        try:
          if 'neighbor' in x:
            try:
              node = self.maybe_node_by_mac((x['neighbor']))
            except:
              continue

          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          node = self.maybe_node_by_mac((x['neighbor'], ))
        except:
          node = Node()
          node.flags['online'] = True
          if x['label'] == 'TT':
            node.flags['client'] = True

          node.add_mac(x['neighbor'])
          self._nodes.append(node)

    for line in lines:
      x = json.loads(line)

      if 'router' in x:
        try:
          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          router = self.maybe_node_by_mac((x['router'], ))
          neighbor = self.maybe_node_by_mac((x['neighbor'], ))
        except:
          continue

        # filter TT links merged in previous step
        if router == neighbor:
          continue

        link = Link()
        link.source = LinkConnector()
        link.source.interface = x['router']
        link.source.id = self._nodes.index(router)
        link.target = LinkConnector()
        link.target.interface = x['neighbor']
        link.target.id = self._nodes.index(neighbor)
        link.quality = x['label']
        link.id = "-".join(sorted((link.source.interface, link.target.interface)))

        if x['label'] == "TT":
          link.type = "client"

        self._links.append(link)

    for line in lines:
      x = json.loads(line)

      if 'primary' in x:
        try:
          node = self.maybe_node_by_mac((x['primary'], ))
        except:
          continue

        node.id = x['primary']
コード例 #4
0
  def parse_vis_data(self,vis_data):
    for x in vis_data:

      if 'of' in x:
        try:
          node = self.maybe_node_by_mac((x['of'], x['secondary']))
        except KeyError:
          node = Node()
          node.lastseen = self.time
          node.firstseen = self.time
          node.flags['online'] = True
          self._nodes.append(node)

        node.add_mac(x['of'])
        node.add_mac(x['secondary'])

    for x in vis_data:
      if 'router' in x:
        # TTs will be processed later
        if x['label'] == "TT":
          continue

        try:
          node = self.maybe_node_by_mac((x['router'], ))
        except KeyError:
          node = Node()
          node.lastseen = self.time
          node.firstseen = self.time
          node.flags['online'] = True
          node.add_mac(x['router'])
          self._nodes.append(node)

        try:
          if 'neighbor' in x:
            try:
              node = self.maybe_node_by_mac((x['neighbor'], ))
            except KeyError:
              continue

          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          node = self.maybe_node_by_mac((x['neighbor'], ))
        except KeyError:
          node = Node()
          node.lastseen = self.time
          node.firstseen = self.time
          node.flags['online'] = True
          node.add_mac(x['neighbor'])
          self._nodes.append(node)

    for x in vis_data:
      if 'router' in x:
        # TTs will be processed later
        if x['label'] == "TT":
          continue

        try:
          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          router = self.maybe_node_by_mac((x['router'], ))
          neighbor = self.maybe_node_by_mac((x['neighbor'], ))
        except KeyError:
          continue

        # filter TT links merged in previous step
        if router == neighbor:
          continue

        link = Link()
        link.source = LinkConnector()
        link.source.interface = x['router']
        link.source.id = self._nodes.index(router)
        link.target = LinkConnector()
        link.target.interface = x['neighbor']
        link.target.id = self._nodes.index(neighbor)
        link.quality = x['label']
        link.id = "-".join(sorted((link.source.interface, link.target.interface)))

        self._links.append(link)

    for x in vis_data:
      if 'primary' in x:
        try:
          node = self.maybe_node_by_mac((x['primary'], ))
        except KeyError:
          continue

        node.id = x['primary']

    for x in vis_data:
      if 'router' in x and x['label'] == 'TT':
        try:
          node = self.maybe_node_by_mac((x['router'], ))
          node.add_mac(x['gateway'])
          node.clientcount += 1
        except KeyError:
          pass
 
    # don't count node as its own client
    for node in self._nodes:
      if node.clientcount > 0:
        node.clientcount -= 1
コード例 #5
0
ファイル: nodedb.py プロジェクト: freifunk-saar/ffmap-backend
    def parse_vis_data(self, vis_data):
        for x in vis_data:

            if 'of' in x:
                try:
                    node = self.maybe_node_by_mac((x['of'], x['secondary']))
                except:
                    node = Node()
                    node.lastseen = self.time
                    node.firstseen = self.time
                    node.flags['online'] = True
                    self._nodes.append(node)

                node.add_mac(x['of'])
                node.add_mac(x['secondary'])

        for x in vis_data:
            if 'router' in x:
                # TTs will be processed later
                if x['label'] == "TT":
                    continue

                try:
                    node = self.maybe_node_by_mac((x['router'], ))
                except:
                    node = Node()
                    node.lastseen = self.time
                    node.firstseen = self.time
                    node.flags['online'] = True
                    node.add_mac(x['router'])
                    self._nodes.append(node)

                try:
                    if 'neighbor' in x:
                        try:
                            node = self.maybe_node_by_mac((x['neighbor']))
                        except:
                            continue

                    if 'gateway' in x:
                        x['neighbor'] = x['gateway']

                    node = self.maybe_node_by_mac((x['neighbor'], ))
                except:
                    node = Node()
                    node.lastseen = self.time
                    node.firstseen = self.time
                    node.flags['online'] = True
                    node.add_mac(x['neighbor'])
                    self._nodes.append(node)

        for x in vis_data:
            if 'router' in x:
                # TTs will be processed later
                if x['label'] == "TT":
                    continue

                try:
                    if 'gateway' in x:
                        x['neighbor'] = x['gateway']

                    router = self.maybe_node_by_mac((x['router'], ))
                    neighbor = self.maybe_node_by_mac((x['neighbor'], ))
                except:
                    continue

                # filter TT links merged in previous step
                if router == neighbor:
                    continue

                link = Link()
                link.source = LinkConnector()
                link.source.interface = x['router']
                link.source.id = self._nodes.index(router)
                link.target = LinkConnector()
                link.target.interface = x['neighbor']
                link.target.id = self._nodes.index(neighbor)
                link.quality = x['label']
                link.id = "-".join(
                    sorted((link.source.interface, link.target.interface)))

                self._links.append(link)

        for x in vis_data:
            if 'primary' in x:
                try:
                    node = self.maybe_node_by_mac((x['primary'], ))
                except:
                    continue

                node.id = x['primary']

        for x in vis_data:
            if 'router' in x and x['label'] == 'TT':
                try:
                    node = self.maybe_node_by_mac((x['router'], ))
                    node.add_mac(x['gateway'])
                    node.clientcount += 1
                except:
                    pass

        # don't count node as its own client
        for node in self._nodes:
            if node.clientcount > 0:
                node.clientcount -= 1