コード例 #1
0
        class NeighborAttributes(PseudowireNeighborSubAttributes):

            # ip -> self.neighbor.ip
            # pw_id -> self.neighbor.pw_id
            # evi -> self.neighbor.evi
            # ac_id -> self.neighbor.ac_id
            # source_ac_id -> self.neighbor.source_ac_id

            dhcp_ipv4_snooping_profile = managedattribute(
                name='dhcp_ipv4_snooping_profile',
                default=None,
                type=(
                    None,
                    managedattribute.test_is(False),  # False
                    managedattribute.test_istype(str),  # <profile>
                ))

            igmp_snooping_profile = managedattribute(
                name='igmp_snooping_profile',
                default=None,
                type=(
                    None,
                    managedattribute.test_is(False),  # False
                    managedattribute.test_istype(str),  # <profile>
                ))

            mld_snooping_profile = managedattribute(
                name='mld_snooping_profile',
                default=None,
                type=(
                    None,
                    managedattribute.test_is(False),  # False
                    managedattribute.test_istype(str),  # <profile>
                ))

            mpls_static_label = managedattribute(
                name='mpls_static_label',
                default=None,
                type=(None, managedattribute.test_istype(int)))

            pw_class = managedattribute(
                name='pw_class',
                default=None,
                type=(None, managedattribute.test_isinstance(PseudowireClass)))

            split_horizon = managedattribute(
                name='split_horizon',
                default=None,
                type=(None, managedattribute.test_istype(bool)))

            static_mac_address = managedattribute(name='static_mac_address',
                                                  default=None,
                                                  type=(None, MAC))
コード例 #2
0
class Pseudowire(Base):
    '''A Pseudowire.

    Example:

        # Containers (either Xconnect and/or BridgeDomain)
        xc = Xconnect(...)
        bd = BridgeDomain(...)

        # Create a PseudowireIPv4Neighbor:
        pwnbr1 = xc.create_pseudowire_neighbor(device=dev1, ip=lo2.ipv4.ip, pw_id=123)
        # Create a PseudowireIPv6Neighbor:
        pwnbr1 = xc.create_pseudowire_neighbor(device=dev1, ip=lo2.ipv6.ip, pw_id=123)
        # Create a PseudowireEviNeighbor
        pwnbr1 = xc.create_pseudowire_neighbor(device=dev1, evi=evi2, ac_id=123)
        # pwnbr1.container --> xc
        # pwnbr1.device --> dev1

        # Create a PseudowireIPv4Neighbor:
        pwnbr2 = bd.create_pseudowire_neighbor(device=dev2, ip=lo1.ipv4.ip, pw_id=123)
        # Create a PseudowireEviNeighbor
        pwnbr2 = bd.create_pseudowire_neighbor(device=dev2, evi=evi1, ac_id=123)
        # pwnbr2.container --> bd
        # pwnbr2.device --> dev2

        pw = Pseudowire(neighbors=[pwnbr1, pwnbr2])
        # Implicit:
        #  xc.add_segment(pw)
        #  bd.add_segment(pw)

    '''

    EncapsulationType = EncapsulationType

    EncapsulationProtocol = EncapsulationProtocol

    TransportMode = TransportMode

    neighbors = managedattribute(name='neighbors',
                                 read_only=True,
                                 gettype=frozenset)

    @property
    def neighbor_devices(self):
        return frozenset(neighbor.device for neighbor in self.neighbors)

    @property
    def testbed(self):
        for nbr in self.neighbors:
            return nbr.testbed

    pw_class = managedattribute(
        name='pw_class',
        default=None,
        type=(None, managedattribute.test_isinstance(PseudowireClass)))

    split_horizon = managedattribute(name='split_horizon',
                                     default=None,
                                     type=(None,
                                           managedattribute.test_istype(bool)))

    static_mac_address = managedattribute(name='static_mac_address',
                                          default=None,
                                          type=(None, MAC))

    ipv6_source = managedattribute(name='ipv6_source',
                                   default=None,
                                   type=(None, IPv6Address))

    dhcp_ipv4_snooping_profile = managedattribute(
        name='dhcp_ipv4_snooping_profile',
        default=None,
        type=(
            None,
            managedattribute.test_is(False),  # False
            managedattribute.test_istype(str),  # <profile>
        ))

    igmp_snooping_profile = managedattribute(
        name='igmp_snooping_profile',
        default=None,
        type=(
            None,
            managedattribute.test_is(False),  # False
            managedattribute.test_istype(str),  # <profile>
        ))

    mld_snooping_profile = managedattribute(
        name='mld_snooping_profile',
        default=None,
        type=(
            None,
            managedattribute.test_is(False),  # False
            managedattribute.test_istype(str),  # <profile>
        ))

    mpls_static_label = managedattribute(name='mpls_static_label',
                                         default=None,
                                         type=(None,
                                               managedattribute.test_is(int)))

    def __init__(self, neighbors, **kwargs):
        neighbors = set(neighbors)
        if len(neighbors) != 2:
            raise ValueError('Exactly 2 neighbors are expected: %r' %
                             (neighbors, ))  # XXXJST TODO
        for nbr in neighbors:
            if not isinstance(nbr, PseudowireNeighbor):
                raise ValueError('%r is not a PseudowireNeighbor' % (nbr, ))
        self._neighbors = set(neighbors)
        super().__init__()
        for nbr in self.neighbors:
            nbr.container.add_pseudowire(self)
        for k, v in kwargs.items():
            for nbr in self.neighbors:
                setattr(nbr, k, v)

    def __hash__(self):
        return hash(id(self))  # TODO Always unique