Ejemplo n.º 1
0
    def nodes(self, *args, **kwargs):
        """

        >>> anm = autonetkit.topos.multi_as()
        >>> g_phy = anm["phy"]
        >>> g_phy.nodes()
        [r4, r5, r6, r7, r1, r2, r3, r8, r9, r10]

        >>> g_phy.nodes(asn=1)
        [r4, r5, r1, r2, r3]

        >>> g_phy.nodes(asn=3)
        [r7, r8, r9, r10]

        >>> g_phy.nodes(asn=1, ibgp_role="RR")
        [r4, r5]

        >>> g_phy.nodes(asn=1, ibgp_role="RRC")
        [r1, r2, r3]

        """

        result = list(
            NmNode(self._anm, self._overlay_id, node) for node in self._graph)

        if len(args) or len(kwargs):
            result = self.filter(result, *args, **kwargs)
        return result
Ejemplo n.º 2
0
    def nodes(self, *args, **kwargs):
        """"""

        result = list(NmNode(self._anm, self._overlay_id, node)
                      for node in self._graph)

        if len(args) or len(kwargs):
            result = self.filter(result, *args, **kwargs)
        return result
Ejemplo n.º 3
0
    def add_node(self, node, retain=None, **kwargs):
        """Adds node to overlay"""
        nbunch = [node]
        self.add_nodes_from(nbunch, retain, **kwargs)

        try:
            node_id = node.id
        except AttributeError:
            node_id = node  # use the string node id
        return NmNode(self.anm, self._overlay_id, node_id)
Ejemplo n.º 4
0
    def dst(self):
        """Destination node of edge

        >>> anm = autonetkit.topos.house()
        >>> edge = anm['phy'].edge("r1", "r2")
        >>> edge.dst
        r2

        """

        return NmNode(self.anm, self.overlay_id, self.dst_id)
Ejemplo n.º 5
0
    def src(self):
        """Source node of edge

        >>> anm = autonetkit.topos.house()
        >>> edge = anm['phy'].edge("r1", "r2")
        >>> edge.src
        r1

        """

        return NmNode(self.anm, self.overlay_id, self.src_id)
Ejemplo n.º 6
0
    def node(self, key):
        """Returns node based on name
        This is currently O(N). Could use a lookup table"""

        # TODO: refactor

        try:
            if key.node_id in self._graph:
                return NmNode(self._anm, self._overlay_id, key.node_id)
        except AttributeError:

             # try as string id

            if key in self._graph:
                return NmNode(self._anm, self._overlay_id, key)

            # doesn't have node_id, likely a label string, search based on this # label

            for node in self:
                if str(node) == key:
                    return node
            log.warning('Unable to find node %s in %s ' % (key, self))
            return None
Ejemplo n.º 7
0
    def node(self, key):
        """Returns node based on name
        This is currently O(N). Could use a lookup table

        Example:

        >>> anm = autonetkit.topos.house()
        >>> g_phy = anm['phy']
        >>> r1 = g_phy.node("r1")

        Can also find across layers
        >>> r1_input = anm['input'].node(r1)

        """

        # TODO: refactor

        try:
            if key.node_id in self._graph:
                return NmNode(self._anm, self._overlay_id, key.node_id)
        except AttributeError:

            # try as string id

            if key in self._graph:
                return NmNode(self._anm, self._overlay_id, key)

            # doesn't have node_id, likely a label string, search based on this
            # label

            for node in self:
                if str(node) == key:
                    return node
            # TODO: change warning to an exception
            log.warning('Unable to find node %s in %s ' % (key, self))
            return None
Ejemplo n.º 8
0
    def dst(self):
        """Destination node of edge"""

        return NmNode(self.anm, self.overlay_id, self.dst_id)
Ejemplo n.º 9
0
    def src(self):
        """Source node of edge"""

        return NmNode(self.anm, self.overlay_id, self.src_id)
Ejemplo n.º 10
0
    def device(self, key):
        """To access programatically"""

        return NmNode(self._anm, self._overlay_id, key)
Ejemplo n.º 11
0
    def node_label(self, node):
        """"""

        return repr(NmNode(self._anm, self._overlay_id, node))
Ejemplo n.º 12
0
    def node(self):
        """Returns parent node of this interface"""

        from autonetkit.anm.node import NmNode
        return NmNode(self.anm, self.overlay_id, self.node_id)