Esempio n. 1
0
    def interfaces(self, node):
        phy_loopback_zero = self.anm['phy'].interface(node.loopback_zero)
        if node.ip.use_ipv4:
            ipv4_loopback_subnet = netaddr.IPNetwork('0.0.0.0/32')
            ipv4_loopback_zero = phy_loopback_zero['ipv4']
            ipv4_address = ipv4_loopback_zero.ip_address
            node.loopback_zero.use_ipv4 = True
            node.loopback_zero.ipv4_address = ipv4_address
            node.loopback_zero.ipv4_subnet = ipv4_loopback_subnet
            node.loopback_zero.ipv4_cidr = \
                sn_preflen_to_network(ipv4_address,
                    ipv4_loopback_subnet.prefixlen)

        if node.ip.use_ipv6:
            #TODO: clean this up so can set on router_base: call cidr not address and update templates
            node.loopback_zero.use_ipv6 = True
            ipv6_loopback_zero = phy_loopback_zero['ipv6']
            node.loopback_zero.ipv6_address = \
                sn_preflen_to_network(ipv6_loopback_zero.ip_address,
                    128)

        super(IosBaseCompiler, self).interfaces(node)

        for interface in node.physical_interfaces:
            interface.use_cdp = node.use_cdp  # use node value
Esempio n. 2
0
    def interfaces(self, node):
        phy_loopback_zero = self.anm['phy'
                                     ].interface(node.loopback_zero)
        if node.ip.use_ipv4:
            ipv4_loopback_subnet = netaddr.IPNetwork('0.0.0.0/32')
            ipv4_loopback_zero = phy_loopback_zero['ipv4']
            ipv4_address = ipv4_loopback_zero.ip_address
            node.loopback_zero.use_ipv4 = True
            node.loopback_zero.ipv4_address = ipv4_address
            node.loopback_zero.ipv4_subnet = ipv4_loopback_subnet
            node.loopback_zero.ipv4_cidr = \
                sn_preflen_to_network(ipv4_address,
                                      ipv4_loopback_subnet.prefixlen)

        if node.ip.use_ipv6:
            # TODO: clean this up so can set on router_base: call cidr not
            # address and update templates
            node.loopback_zero.use_ipv6 = True
            ipv6_loopback_zero = phy_loopback_zero['ipv6']
            node.loopback_zero.ipv6_address = \
                sn_preflen_to_network(ipv6_loopback_zero.ip_address,
                                      128)

        super(BrocadeBaseCompiler, self).interfaces(node)

        for interface in node.physical_interfaces():
            interface.use_fdp = node.use_fdp  # use node value

        for interface in node.interfaces:
            interface.sub_ints = []  # temporary until full subinterfaces
Esempio n. 3
0
    def interfaces(self, node):
        node.interfaces = []

        node.loopback_zero.id = self.lo_interface
        node.loopback_zero.description = "Loopback"

        for interface in node.physical_interfaces:
            phy_int = self.anm['phy'].interface(interface)
            interface.physical = True
            #TODO: allocate ID in platform compiler

            if not phy_int:
                # for instance if added as management interface to nidb in compile
                continue
                
            interface.description = phy_int.description
            if node.ip.use_ipv4:
                ipv4_int = phy_int['ipv4']
                interface.ipv4_address = ipv4_int.ip_address
                interface.ipv4_subnet = ipv4_int.subnet
                interface.ipv4_cidr = sn_preflen_to_network(interface.ipv4_address,
                        interface.ipv4_subnet.prefixlen)

            if node.ip.use_ipv6:
                ipv6_int = phy_int['ipv6']
#TODO: for consistency, make ipv6_cidr
                interface.ipv6_subnet = ipv6_int.subnet
                interface.ipv6_address = sn_preflen_to_network(ipv6_int.ip_address,
                        interface.ipv6_subnet.prefixlen)

        for interface in node.loopback_interfaces:
            #TODO: check if nonzero is different to __eq__
            if interface == node.loopback_zero:
                continue
            else:
                #print "here for non zero", interface.id
                phy_int = self.anm['phy'].interface(interface)
                if node.ip.use_ipv4:
                    ipv4_int = phy_int['ipv4']
                    interface.ipv4_address = ipv4_int.loopback
                    interface.ipv4_subnet = node.loopback_subnet
                    interface.ipv4_cidr = sn_preflen_to_network(interface.ipv4_address,
                            interface.ipv4_subnet.prefixlen)

                if node.ip.use_ipv6:
                    ipv6_int = phy_int['ipv6']
#TODO: for consistency, make ipv6_cidr
                    #interface.ipv6_subnet = ipv6_int.loopback # TODO: do we need for consistency?
                    interface.ipv6_address = sn_preflen_to_network(
                            ipv6_int.loopback, 128)

                # secondary loopbacks
                #TODO: check why vrf names not showing up for all
                #print vrf_interface.vrf_name
                pass

            continue
Esempio n. 4
0
    def copy_across_ip_addresses(self):
        log.info("Copying IP addresses to device model")
        # TODO: try/except and raise SystemError as fatal error if cant copy
        from autonetkit.ank import sn_preflen_to_network

        # TODO:  check if this will clobber with platform?
        for node in self.nidb.l3devices(host=self.host):
            phy_node = self.anm['phy'].node(node)

            node.add_stanza("ip")
            node.ip.use_ipv4 = phy_node.use_ipv4 or False
            node.ip.use_ipv6 = phy_node.use_ipv6 or False

            for interface in node.interfaces:
                phy_int = phy_node.interface(interface)
                if phy_node.use_ipv4:
                    ipv4_int = phy_int['ipv4']
                    if node.is_server() and interface.is_loopback:
                        continue
                    if interface.is_physical and not interface.is_bound:
                        continue

                    # TODO: also need to skip layer2 virtual interfaces
                    # interface is connected
                    try:
                        interface.ipv4_address = ipv4_int.ip_address
                        interface.ipv4_subnet = ipv4_int.subnet
                        interface.ipv4_cidr = sn_preflen_to_network(interface.ipv4_address,
                                                                    interface.ipv4_subnet.prefixlen)
                    except AttributeError:
                        log.warning(
                            "Unable to copy across IPv4 for %s" % interface)
                    else:
                        interface.use_ipv4 = True
                if phy_node.use_ipv6:
                    ipv6_int = phy_int['ipv6']
                    if node.is_server() and interface.is_loopback:
                        continue
                    if interface.is_physical and not interface.is_bound:
                        continue
                    try:
                        # TODO: copy ip address as well
                        interface.ipv6_subnet = ipv6_int.subnet
                        interface.ipv6_address = sn_preflen_to_network(ipv6_int.ip_address,
                                                                       interface.ipv6_subnet.prefixlen)
                    except AttributeError:
                        log.warning(
                            "Unable to copy IPv6 subnet for %s" % interface)
                    else:
                        interface.use_ipv6 = True
Esempio n. 5
0
def manual_ipv6_infrastructure_allocation(anm):
    """Applies manual IPv6 allocation"""

    import netaddr
    g_ipv6 = anm['ipv6']
    g_in = anm['input']
    log.info('Using specified IPv6 infrastructure allocation')

    for node in g_ipv6.l3devices():
        for interface in node.physical_interfaces():
            if not interface['input'].is_bound:
                continue  # unbound interface
            if not interface['ipv6'].is_bound:
                continue
            ip_address = netaddr.IPAddress(interface['input'
                                                     ].ipv6_address)
            prefixlen = interface['input'].ipv6_prefixlen
            interface.ip_address = ip_address
            interface.prefixlen = prefixlen
            cidr_string = '%s/%s' % (ip_address, prefixlen)
            interface.subnet = netaddr.IPNetwork(cidr_string)

    broadcast_domains = [d for d in g_ipv6 if d.broadcast_domain]

    # TODO: allow this to work with specified ip_address/subnet as well as
    # ip_address/prefixlen

    global_infra_block = None
    try:
        # Note this is only pickling up if explictly set in g_in
        infra_subnet = g_in.data.ipv6_infra_subnet
        infra_prefix = g_in.data.ipv6_infra_prefix
        global_infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        log.info("Unable to parse specified ipv4 infra subnets %s/%s")
Esempio n. 6
0
def manual_ipv6_infrastructure_allocation(anm):
    """Applies manual IPv6 allocation"""

    import netaddr
    g_ipv6 = anm['ipv6']
    g_in = anm['input']
    log.info('Using specified IPv6 infrastructure allocation')

    for node in g_ipv6.l3devices():
        for interface in node.physical_interfaces():
            if not interface['input'].is_bound:
                continue  # unbound interface
            if not interface['ipv6'].is_bound:
                continue
            ip_address = netaddr.IPAddress(interface['input'].ipv6_address)
            prefixlen = interface['input'].ipv6_prefixlen
            interface.ip_address = ip_address
            interface.prefixlen = prefixlen
            cidr_string = '%s/%s' % (ip_address, prefixlen)
            interface.subnet = netaddr.IPNetwork(cidr_string)

    broadcast_domains = [d for d in g_ipv6 if d.broadcast_domain]

    # TODO: allow this to work with specified ip_address/subnet as well as
    # ip_address/prefixlen

    global_infra_block = None
    try:
        # Note this is only pickling up if explictly set in g_in
        infra_subnet = g_in.data.ipv6_infra_subnet
        infra_prefix = g_in.data.ipv6_infra_prefix
        global_infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        log.info("Unable to parse specified ipv4 infra subnets %s/%s")
Esempio n. 7
0
def extract_ipv6_blocks(anm):

    # TODO: set all these blocks globally in config file, rather than repeated
    # in load, build_network, compile, etc

    from autonetkit.ank import sn_preflen_to_network
    from netaddr import IPNetwork
    g_in = anm['input']

    ipv6_defaults = SETTINGS["IP Addressing"]["v6"]

    try:
        infra_subnet = g_in.data.ipv6_infra_subnet
        infra_prefix = g_in.data.ipv6_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, error:
        infra_block = IPNetwork(
            '%s/%s' %
            (ipv6_defaults["infra_subnet"], ipv6_defaults["infra_prefix"]))
        if infra_subnet is None or infra_prefix is None:
            log.debug('Using default IPv6 infra_subnet %s', infra_block)
        else:
            log.warning(
                'Unable to obtain IPv6 infra_subnet from input graph: %s, using default %s'
                % (error, infra_block))
Esempio n. 8
0
    def interfaces(self, node):
        phy_loopback_zero = self.anm['phy'
                                     ].interface(node.loopback_zero)
        if node.ip.use_ipv4:
            ipv4_loopback_subnet = netaddr.IPNetwork('0.0.0.0/32')
            ipv4_loopback_zero = phy_loopback_zero['ipv4']
            ipv4_address = ipv4_loopback_zero.ip_address
            node.loopback_zero.use_ipv4 = True
            node.loopback_zero.ipv4_address = ipv4_address
            node.loopback_zero.ipv4_subnet = ipv4_loopback_subnet
            node.loopback_zero.ipv4_cidr = \
                sn_preflen_to_network(ipv4_address,
                                      ipv4_loopback_subnet.prefixlen)

        if node.ip.use_ipv6:
            # TODO: clean this up so can set on router_base: call cidr not
            # address and update templates
            node.loopback_zero.use_ipv6 = True
            ipv6_loopback_zero = phy_loopback_zero['ipv6']
            node.loopback_zero.ipv6_address = \
                sn_preflen_to_network(ipv6_loopback_zero.ip_address,
                                      128)

        super(IosBaseCompiler, self).interfaces(node)

        for interface in node.physical_interfaces():
            interface.use_cdp = node.use_cdp  # use node value

        for interface in node.interfaces:
            interface.sub_ints = []  # temporary until full subinterfaces

        for interface in node.physical_interfaces():
            g_ext_conn = self.anm['ext_conn']
            if node not in g_ext_conn:
                continue

            node_ext_conn = g_ext_conn.node(node)
            ext_int = node_ext_conn.interface(interface)
            for sub_int in ext_int.sub_int or []:
                stanza = ConfigStanza(
                    id=sub_int['id'],
                    ipv4_address=sub_int['ipv4_address'],
                    ipv4_prefixlen=sub_int['ipv4_prefixlen'],
                    ipv4_subnet=sub_int['ipv4_subnet'],
                    dot1q=sub_int['dot1q'],
                )
                interface.sub_ints.append(stanza)
Esempio n. 9
0
    def interfaces(self, node):
        phy_loopback_zero = self.anm['phy'].interface(node.loopback_zero)
        if node.ip.use_ipv4:
            ipv4_loopback_subnet = netaddr.IPNetwork('0.0.0.0/32')
            ipv4_loopback_zero = phy_loopback_zero['ipv4']
            ipv4_address = ipv4_loopback_zero.ip_address
            node.loopback_zero.use_ipv4 = True
            node.loopback_zero.ipv4_address = ipv4_address
            node.loopback_zero.ipv4_subnet = ipv4_loopback_subnet
            node.loopback_zero.ipv4_cidr = \
                sn_preflen_to_network(ipv4_address,
                                      ipv4_loopback_subnet.prefixlen)

        if node.ip.use_ipv6:
            # TODO: clean this up so can set on router_base: call cidr not
            # address and update templates
            node.loopback_zero.use_ipv6 = True
            ipv6_loopback_zero = phy_loopback_zero['ipv6']
            node.loopback_zero.ipv6_address = \
                sn_preflen_to_network(ipv6_loopback_zero.ip_address,
                                      128)

        super(IosBaseCompiler, self).interfaces(node)

        for interface in node.physical_interfaces():
            interface.use_cdp = node.use_cdp  # use node value

        for interface in node.interfaces:
            interface.sub_ints = []  # temporary until full subinterfaces

        for interface in node.physical_interfaces():
            g_ext_conn = self.anm['ext_conn']
            if node not in g_ext_conn:
                continue

            node_ext_conn = g_ext_conn.node(node)
            ext_int = node_ext_conn.interface(interface)
            for sub_int in ext_int.sub_int or []:
                stanza = ConfigStanza(
                    id=sub_int['id'],
                    ipv4_address=sub_int['ipv4_address'],
                    ipv4_prefixlen=sub_int['ipv4_prefixlen'],
                    ipv4_subnet=sub_int['ipv4_subnet'],
                    dot1q=sub_int['dot1q'],
                )
                interface.sub_ints.append(stanza)
Esempio n. 10
0
    def copy_across_ip_addresses(self):
        #TODO: try/except and raise SystemError as fatal error if cant copy
        from autonetkit.ank import sn_preflen_to_network

        #TODO:  check if this will clobber with platform?
        for node in self.nidb.l3devices(host=self.host):
            phy_node = self.anm['phy'].node(node)

            node.add_stanza("ip")
            node.ip.use_ipv4 = phy_node.use_ipv4 or False
            node.ip.use_ipv6 = phy_node.use_ipv6 or False

            for interface in node.interfaces:
                phy_int = phy_node.interface(interface)
                if phy_node.use_ipv4:
                    ipv4_int = phy_int['ipv4']
                    if node.is_server() and interface.is_loopback:
                        continue
                    if interface.is_physical and not interface.is_bound:
                        continue
                    # interface is connected
                    interface.use_ipv4 = True
                    interface.ipv4_address = ipv4_int.ip_address
                    interface.ipv4_subnet = ipv4_int.subnet
                    interface.ipv4_cidr = sn_preflen_to_network(
                        interface.ipv4_address,
                        interface.ipv4_subnet.prefixlen)
                if phy_node.use_ipv6:
                    ipv6_int = phy_int['ipv6']
                    if node.is_server() and interface.is_loopback:
                        continue
                    if interface.is_physical and not interface.is_bound:
                        continue
                    interface.use_ipv6 = True
                    try:
                        #TODO: copy ip address as well
                        interface.ipv6_subnet = ipv6_int.subnet
                        interface.ipv6_address = sn_preflen_to_network(
                            ipv6_int.ip_address,
                            interface.ipv6_subnet.prefixlen)
                    except AttributeError:
                        log.warning("Unable to copy IPv6 subnet for %s" %
                                    interface)
Esempio n. 11
0
    def interfaces(self, node):
        phy_loopback_zero = self.anm['phy'].interface(node.loopback_zero)
        if node.ip.use_ipv4:
            ipv4_loopback_subnet = netaddr.IPNetwork("0.0.0.0/32")
            ipv4_loopback_zero = phy_loopback_zero['ipv4']
            ipv4_address = ipv4_loopback_zero.ip_address
            node.loopback_zero.ipv4_address = ipv4_address
            node.loopback_zero.ipv4_subnet = ipv4_loopback_subnet
            node.loopback_zero.ipv4_cidr = sn_preflen_to_network(
                    ipv4_address, ipv4_loopback_subnet.prefixlen)

        if node.ip.use_ipv6:
            ipv6_loopback_zero = phy_loopback_zero['ipv6']
            node.loopback_zero.ipv6_address = sn_preflen_to_network(
                ipv6_loopback_zero.ip_address, 128)

        super(IosBaseCompiler, self).interfaces(node)

        for interface in node.physical_interfaces:
            interface.use_cdp = node.use_cdp # use node value
Esempio n. 12
0
def extract_ipv4_blocks(anm):
    #TODO: set all these blocks globally in config file, rather than repeated in load, build_network, compile, etc
    from autonetkit.ank import sn_preflen_to_network
    from netaddr import IPNetwork
    g_in = anm['input']

    try:
        infra_subnet = g_in.data.ipv4_infra_subnet
        infra_prefix = g_in.data.ipv4_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        log.debug("Unable to obtain infra_subnet from input graph: %s" % e)
        infra_block = IPNetwork("10.0.0.0/8")
Esempio n. 13
0
def extract_ipv4_blocks(anm):
    #TODO: set all these blocks globally in config file, rather than repeated in load, build_network, compile, etc
    from autonetkit.ank import sn_preflen_to_network
    from netaddr import IPNetwork
    g_in = anm['input']

    try:
        infra_subnet = g_in.data.ipv4_infra_subnet
        infra_prefix = g_in.data.ipv4_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        log.debug("Unable to obtain infra_subnet from input graph: %s" % e)
        infra_block = IPNetwork("10.0.0.0/8")
Esempio n. 14
0
def extract_ipv4_blocks(anm):

    # TODO: set all these blocks globally in config file, rather than repeated in load, build_network, compile, etc

    from autonetkit.ank import sn_preflen_to_network
    from netaddr import IPNetwork
    g_in = anm['input']
    ipv4_defaults = SETTINGS["IP Addressing"]["v4"]

    try:
        infra_subnet = g_in.data.ipv4_infra_subnet
        infra_prefix = g_in.data.ipv4_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        infra_block = IPNetwork('%s/%s' % (ipv4_defaults["infra_subnet"], ipv4_defaults["infra_prefix"]))
        log.warning('Unable to obtain IPv4 infra_subnet from input graph: %s, using default %s'
            % (e, infra_block))
Esempio n. 15
0
def manual_ipv4_loopback_allocation(anm):
    """Applies manual IPv4 allocation"""

    import netaddr

    g_ipv4 = anm["ipv4"]
    g_in = anm["input"]

    for l3_device in g_ipv4.l3devices():
        try:
            l3_device.loopback = IPAddress(l3_device["input"].loopback_v4)
        except netaddr.AddrFormatError:
            log.debug("Unable to parse IP address %s on %s", l3_device["input"].loopback_v6, l3_device)

    try:
        loopback_subnet = g_in.data.ipv4_loopback_subnet
        loopback_prefix = g_in.data.ipv4_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet, loopback_prefix)
    except Exception, e:
        log.info("Unable to parse specified ipv4 loopback subnets %s/%s")
Esempio n. 16
0
def manual_ipv4_loopback_allocation(anm):
    """Applies manual IPv4 allocation"""

    import netaddr
    g_ipv4 = anm['ipv4']
    g_in = anm['input']

    for l3_device in g_ipv4.l3devices():
        try:
            l3_device.loopback = IPAddress(l3_device['input'].loopback_v4)
        except netaddr.AddrFormatError:
            log.debug("Unable to parse IP address %s on %s",
                      l3_device['input'].loopback_v6, l3_device)

    try:
        loopback_subnet = g_in.data.ipv4_loopback_subnet
        loopback_prefix = g_in.data.ipv4_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, e:
        log.info("Unable to parse specified ipv4 loopback subnets %s/%s")
Esempio n. 17
0
def extract_ipv4_blocks(anm):

    # TODO: set all these blocks globally in config file, rather than repeated
    # in load, build_network, compile, etc

    from netaddr import IPNetwork

    g_in = anm["input"]
    ipv4_defaults = SETTINGS["IP Addressing"]["v4"]

    # TODO: wrap these in a common function

    try:
        infra_subnet = g_in.data.ipv4_infra_subnet
        infra_prefix = g_in.data.ipv4_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        infra_block = IPNetwork("%s/%s" % (ipv4_defaults["infra_subnet"], ipv4_defaults["infra_prefix"]))
        if infra_subnet is None or infra_prefix is None:
            log.debug("Using default IPv4 infra_subnet %s" % infra_block)
        else:
            log.warning("Unable to obtain IPv4 infra_subnet from input graph: %s, using default %s" % (e, infra_block))
Esempio n. 18
0
def manual_ipv4_infrastructure_allocation(anm):
    """Applies manual IPv4 allocation"""

    import netaddr

    g_ipv4 = anm["ipv4"]
    g_in = anm["input"]
    log.info("Using specified IPv4 infrastructure allocation")

    for node in g_ipv4.l3devices():
        for interface in node.edge_interfaces():
            if not interface["input"].is_bound:
                continue  # unbound interface
            if not interface["ipv4"].is_bound:
                continue
            if interface["ip"].allocate is False:
                # TODO: copy interface allocate attribute across
                continue

            ip_address = netaddr.IPAddress(interface["input"].ipv4_address)
            prefixlen = interface["input"].ipv4_prefixlen
            interface.ip_address = ip_address
            interface.prefixlen = prefixlen
            cidr_string = "%s/%s" % (ip_address, prefixlen)
            interface.subnet = netaddr.IPNetwork(cidr_string)

    broadcast_domains = [d for d in g_ipv4 if d.broadcast_domain]

    # TODO: allow this to work with specified ip_address/subnet as well as
    # ip_address/prefixlen

    global_infra_block = None
    try:
        # Note this is only pickling up if explictly set in g_in
        infra_subnet = g_in.data.ipv4_infra_subnet
        infra_prefix = g_in.data.ipv4_infra_prefix
        global_infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        log.info("Unable to parse specified ipv4 infra subnets %s/%s")
Esempio n. 19
0
def manual_ipv6_loopback_allocation(anm):
    """Applies manual IPv6 allocation"""

    import netaddr
    g_ipv6 = anm['ipv6']
    g_in = anm['input']

    for l3_device in g_ipv6.l3devices():
        try:
            l3_device.loopback = IPAddress(l3_device['input'].loopback_v6)
        except netaddr.AddrFormatError:
            log.debug("Unable to parse IP address %s on %s",
                      l3_device['input'].loopback_v6, l3_device)

    # also need to form aggregated IP blocks (used for e.g. routing prefix
    # advertisement)
    try:
        loopback_subnet = g_in.data.ipv6_loopback_subnet
        loopback_prefix = g_in.data.ipv6_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, e:
        log.info("Unable to parse specified ipv4 loopback subnets %s/%s")
Esempio n. 20
0
def manual_ipv6_loopback_allocation(anm):
    """Applies manual IPv6 allocation"""

    import netaddr
    g_ipv6 = anm['ipv6']
    g_in = anm['input']

    for l3_device in g_ipv6.l3devices():
        try:
            l3_device.loopback = IPAddress(l3_device['input'].loopback_v6)
        except netaddr.AddrFormatError:
            log.debug("Unable to parse IP address %s on %s",
                l3_device['input'].loopback_v6, l3_device)

    # also need to form aggregated IP blocks (used for e.g. routing prefix
    # advertisement)
    try:
        loopback_subnet = g_in.data.ipv6_loopback_subnet
        loopback_prefix = g_in.data.ipv6_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, e:
        log.info("Unable to parse specified ipv4 loopback subnets %s/%s")
Esempio n. 21
0
    def interfaces(self, node):
        node.interfaces = []

        node.loopback_zero.id = self.lo_interface
        node.loopback_zero.description = 'Loopback'
        phy_node = self.anm['phy'].node(node)
        node.loopback_zero.custom_config = phy_node.loopback_zero.custom_config

        if node.ip.use_ipv4:
            ipv4_node = self.anm['ipv4'].node(node)
            node.loopback_zero.ipv4_address = ipv4_node.loopback
            node.loopback_zero.ipv4_subnet = node.loopback_subnet

        #TODO: bne consistent wit hcidr name so can use in cisco ios xr templates
        #if node.ip.use_ipv6:
        #ipv6_node = self.anm['ipv6'].node(node)
        #node.loopback_zero.ipv6_address = ipv6_node.loopback
        #node.loopback_zero.ipv6_subnet = node.loopback_subnet

        for interface in node.physical_interfaces():
            phy_int = self.anm['phy'].interface(interface)
            interface.physical = True

            # TODO: allocate ID in platform compiler

            if not phy_int:
                # for instance if added as management interface to nidb in compile
                continue

            interface.custom_config = phy_int.custom_config

            interface.description = phy_int.description
            remote_edges = phy_int.edges()
            if len(remote_edges):
                interface.description = 'to %s' \
                    % remote_edges[0].dst.label

            # TODO: fix the description to use mapped label

            if node.ip.use_ipv4:
                ipv4_int = phy_int['ipv4']
                if ipv4_int.is_bound:

                    # interface is connected

                    interface.use_ipv4 = True
                    interface.ipv4_address = ipv4_int.ip_address
                    interface.ipv4_subnet = ipv4_int.subnet
                    interface.ipv4_cidr = \
                        sn_preflen_to_network(interface.ipv4_address,
                            interface.ipv4_subnet.prefixlen)

            if node.ip.use_ipv6:
                ipv6_int = phy_int['ipv6']
                if ipv6_int.is_bound:

                    # interface is connected

                    interface.use_ipv6 = True

                    # TODO: for consistency, make ipv6_cidr

                    interface.ipv6_subnet = ipv6_int.subnet
                    try:
                        interface.ipv6_address = \
                        sn_preflen_to_network(ipv6_int.ip_address,
                            interface.ipv6_subnet.prefixlen)
                    except AttributeError:
                        log.warning("Unable to format interface ")

        for interface in node.loopback_interfaces():

            # TODO: check if nonzero is different to __eq__

            if interface == node.loopback_zero:
                continue
            else:
                phy_int = self.anm['phy'].interface(interface)
                if node.ip.use_ipv4:
                    ipv4_int = phy_int['ipv4']
                    interface.use_ipv4 = True

                    interface.ipv4_address = ipv4_int.loopback
                    interface.ipv4_subnet = node.loopback_subnet
                    interface.ipv4_cidr = \
                        sn_preflen_to_network(interface.ipv4_address,
                            interface.ipv4_subnet.prefixlen)

                if node.ip.use_ipv6:
                    ipv6_int = phy_int['ipv6']
                    interface.use_ipv6 = True

                    # TODO: for consistency, make ipv6_cidr
                    # interface.ipv6_subnet = ipv6_int.loopback # TODO: do we need for consistency?

                    interface.ipv6_address = \
                        sn_preflen_to_network(ipv6_int.loopback, 128)

                # secondary loopbacks
                # TODO: check why vrf names not showing up for all
                # print vrf_interface.vrf_name

            continue
Esempio n. 22
0
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, error:
        infra_block = IPNetwork(
            '%s/%s' %
            (ipv6_defaults["infra_subnet"], ipv6_defaults["infra_prefix"]))
        if infra_subnet is None or infra_prefix is None:
            log.debug('Using default IPv6 infra_subnet %s', infra_block)
        else:
            log.warning(
                'Unable to obtain IPv6 infra_subnet from input graph: %s, using default %s'
                % (error, infra_block))

    try:
        loopback_subnet = g_in.data.ipv6_loopback_subnet
        loopback_prefix = g_in.data.ipv6_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, error:
        loopback_block = IPNetwork('%s/%s' %
                                   (ipv6_defaults["loopback_subnet"],
                                    ipv6_defaults["loopback_prefix"]))
        if loopback_subnet is None or loopback_prefix is None:
            log.debug('Using default IPv6 loopback_subnet %s', loopback_block)
        else:
            log.warning(
                'Unable to obtain IPv6 loopback_subnet from" input graph: %s, using default %s'
                % (error, loopback_block))

    try:
        vrf_loopback_subnet = g_in.data.ipv6_vrf_loopback_subnet
        vrf_loopback_prefix = g_in.data.ipv6_vrf_loopback_prefix
        vrf_loopback_block = sn_preflen_to_network(vrf_loopback_subnet,
Esempio n. 23
0
        infra_subnet = g_in.data.ipv4_infra_subnet
        infra_prefix = g_in.data.ipv4_infra_prefix
        infra_block = sn_preflen_to_network(infra_subnet, infra_prefix)
    except Exception, e:
        infra_block = IPNetwork(
            '%s/%s' % (ipv4_defaults["infra_subnet"], ipv4_defaults["infra_prefix"]))
        if infra_subnet is None or infra_prefix is None:
            log.debug('Using default IPv4 infra_subnet %s' % infra_block)
        else:
            log.warning('Unable to obtain IPv4 infra_subnet from input graph: %s, using default %s' % (
                e, infra_block))

    try:
        loopback_subnet = g_in.data.ipv4_loopback_subnet
        loopback_prefix = g_in.data.ipv4_loopback_prefix
        loopback_block = sn_preflen_to_network(loopback_subnet,
                                               loopback_prefix)
    except Exception, e:
        loopback_block = IPNetwork(
            '%s/%s' % (ipv4_defaults["loopback_subnet"], ipv4_defaults["loopback_prefix"]))
        if loopback_subnet is None or loopback_prefix is None:
            log.debug('Using default IPv4 loopback_subnet %s' % loopback_block)
        else:
            log.warning('Unable to obtain IPv4 loopback_subnet from input graph: %s, using default %s' % (
                e, loopback_block))

    try:
        vrf_loopback_subnet = g_in.data.ipv4_vrf_loopback_subnet
        vrf_loopback_prefix = g_in.data.ipv4_vrf_loopback_prefix
        vrf_loopback_block = sn_preflen_to_network(vrf_loopback_subnet,
                                                   vrf_loopback_prefix)
    except Exception, e:
Esempio n. 24
0
    def assign_management_interfaces(self):
        g_phy = self.anm['phy']
        lab_topology = self.nidb.topology[self.host]
        oob_management_ips = {}

        #TODO: make this seperate function
        from netaddr import IPNetwork, IPRange

        mgmt_address_start = g_phy.data.mgmt_address_start 
        mgmt_address_end = g_phy.data.mgmt_address_end 
        mgmt_prefixlen = int(g_phy.data.mgmt_prefixlen)

        #TODO: need to check if range is insufficient
        mgmt_ips = (IPRange(mgmt_address_start, mgmt_address_end))
        mgmt_ips_iter = iter(mgmt_ips) # to iterate over

        mgmt_address_start_network = IPNetwork(mgmt_address_start) # as /32 for supernet
        mgmt_address_end_network = IPNetwork(mgmt_address_end) # as /32 for supernet
        # retrieve the first supernet, as this is the range requested. subsequent are the subnets
        start_subnet = mgmt_address_start_network.supernet(mgmt_prefixlen)[0] # retrieve first
        end_subnet = mgmt_address_end_network.supernet(mgmt_prefixlen)[0] # retrieve first

        try: # validation
            assert(start_subnet == end_subnet)
            log.debug("Verified: Cisco management subnets match")
        except AssertionError:
            log.warning("Error: Cisco management subnets do not match: %s and %s, using start subnet"
                    % (start_subnet, end_subnet))

        mgmt_subnet = start_subnet
        hosts_to_allocate = sorted(self.nidb.nodes('is_router', host=self.host))
        dhcp_subtypes = {"os"}
        dhcp_hosts = [h for h in hosts_to_allocate if h.device_subtype in dhcp_subtypes]
        non_dhcp_hosts = [h for h in hosts_to_allocate if h.device_subtype not in dhcp_subtypes]

        try: # validation
            assert(len(mgmt_ips) >= len(non_dhcp_hosts))
            log.debug("Verified: Cisco management IP range is sufficient size %s for %s hosts"
                    % (len(mgmt_ips), len(non_dhcp_hosts)))
        except AssertionError:
            log.warning("Error: Cisco management IP range is insufficient size %s for %s hosts"
                    % (len(mgmt_ips), len(non_dhcp_hosts)))
            # TODO: need to use default range
            return

        for nidb_node in hosts_to_allocate:
            for interface in nidb_node.physical_interfaces:
                if interface.management:
                    interface.description = "OOB Management"
                    interface.physical = True
                    if nidb_node in dhcp_hosts:
                        interface.use_dhcp = True
                        oob_management_ips[str(nidb_node)] = "dhcp"
                    else:
                        ipv4_address = mgmt_ips_iter.next()
                        interface.ipv4_address = ipv4_address
                        interface.ipv4_subnet = mgmt_subnet
                        interface.ipv4_cidr = sn_preflen_to_network(ipv4_address, mgmt_prefixlen)
                        oob_management_ips[str(nidb_node)] = ipv4_address

        lab_topology.oob_management_ips = oob_management_ips
Esempio n. 25
0
    def copy_across_ip_addresses(self):
        # log.info("Copying IP addresses to device model")
        # TODO: try/except and raise SystemError as fatal error if cant copy
        from autonetkit.ank import sn_preflen_to_network

        # TODO:  check if this will clobber with platform?
        for node in self.nidb.l3devices(host=self.host):
            phy_node = self.anm['phy'].node(node)

            node.add_stanza("ip")
            node.ip.use_ipv4 = phy_node.use_ipv4 or False
            node.ip.use_ipv6 = phy_node.use_ipv6 or False

            for interface in node.interfaces:
                phy_int = phy_node.interface(interface)
                if phy_int.exclude_igp is not None:
                    interface.exclude_igp = phy_int.exclude_igp

                if phy_node.use_ipv4:
                    ipv4_int = phy_int['ipv4']
                    """
                    TODO: refactor this logic (and for ipv6) to only check if None
                    then compilers are more pythonic - test for IP is None
                    rather than bound etc - simplifies logic
                    make try to copy, and if fail then warn and set use_ipv4 to False
                    """
                    if node.is_server() and interface.is_loopback:
                        continue
                    if interface.is_physical and not interface.is_bound:
                        continue

                    # permit unbound ip interfaces (e.g. if skipped for l2 encap)
                    if interface.is_physical and not ipv4_int.is_bound:
                        interface.use_ipv4 = False
                        continue

                    if ipv4_int.ip_address is None:
                        #TODO: put into dev log
                        log.debug("No IP address allocated on %s", interface)
                        interface.use_ipv4 = False
                        continue

                    # TODO: also need to skip layer2 virtual interfaces
                    # interface is connected
                    try:
                        interface.ipv4_address = ipv4_int.ip_address
                        interface.ipv4_subnet = ipv4_int.subnet
                        interface.ipv4_cidr = sn_preflen_to_network(
                            interface.ipv4_address,
                            interface.ipv4_subnet.prefixlen)
                    except AttributeError, error:
                        log.warning("Unable to copy across IPv4 for %s" %
                                    interface)
                        log.debug(error)
                    else:
                        interface.use_ipv4 = True
                if phy_node.use_ipv6:
                    ipv6_int = phy_int['ipv6']
                    if node.is_server() and interface.is_loopback:
                        continue
                    if interface.is_physical and not interface.is_bound:
                        continue
                    # permit unbound ip interfaces (e.g. if skipped for l2 encap)
                    if interface.is_physical and not ipv6_int.is_bound:
                        interface.use_ipv6 = False
                        continue
                    if ipv6_int.ip_address is None:
                        #TODO: put into dev log
                        log.debug("No IP address allocated on %s", interface)
                        interface.use_ipv6 = False
                        continue
                    try:
                        # TODO: copy ip address as well
                        interface.ipv6_subnet = ipv6_int.subnet
                        interface.ipv6_address = sn_preflen_to_network(
                            ipv6_int.ip_address,
                            interface.ipv6_subnet.prefixlen)
                    except AttributeError:
                        log.warning("Unable to copy IPv6 subnet for %s" %
                                    interface)
                    else:
                        interface.use_ipv6 = True
Esempio n. 26
0
    def interfaces(self, node):
        node.interfaces = []

        node.loopback_zero.id = self.lo_interface
        node.loopback_zero.description = 'Loopback'
        phy_node = self.anm['phy'].node(node)
        node.loopback_zero.custom_config = phy_node.loopback_zero.custom_config

        if node.ip.use_ipv4:
            ipv4_node = self.anm['ipv4'].node(node)
            node.loopback_zero.ipv4_address = ipv4_node.loopback
            node.loopback_zero.ipv4_subnet = node.loopback_subnet

        #TODO: bne consistent wit hcidr name so can use in cisco ios xr templates
        #if node.ip.use_ipv6:
            #ipv6_node = self.anm['ipv6'].node(node)
            #node.loopback_zero.ipv6_address = ipv6_node.loopback
            #node.loopback_zero.ipv6_subnet = node.loopback_subnet

        for interface in node.physical_interfaces:
            phy_int = self.anm['phy'].interface(interface)
            interface.physical = True

            # TODO: allocate ID in platform compiler

            if not phy_int:
                # for instance if added as management interface to nidb in compile
                continue

            interface.custom_config = phy_int.custom_config

            interface.description = phy_int.description
            remote_edges = phy_int.edges()
            if len(remote_edges):
                interface.description = 'to %s' \
                    % remote_edges[0].dst.label

            # TODO: fix the description to use mapped label

            if node.ip.use_ipv4:
                ipv4_int = phy_int['ipv4']
                if ipv4_int.is_bound:

                    # interface is connected

                    interface.use_ipv4 = True
                    interface.ipv4_address = ipv4_int.ip_address
                    interface.ipv4_subnet = ipv4_int.subnet
                    interface.ipv4_cidr = \
                        sn_preflen_to_network(interface.ipv4_address,
                            interface.ipv4_subnet.prefixlen)

            if node.ip.use_ipv6:
                ipv6_int = phy_int['ipv6']
                if ipv6_int.is_bound:

                    # interface is connected

                    interface.use_ipv6 = True

# TODO: for consistency, make ipv6_cidr

                    interface.ipv6_subnet = ipv6_int.subnet
                    try:
                        interface.ipv6_address = \
                        sn_preflen_to_network(ipv6_int.ip_address,
                            interface.ipv6_subnet.prefixlen)
                    except AttributeError:
                        log.warning("Unable to format interface ")

        for interface in node.loopback_interfaces:

            # TODO: check if nonzero is different to __eq__

            if interface == node.loopback_zero:
                continue
            else:
                phy_int = self.anm['phy'].interface(interface)
                if node.ip.use_ipv4:
                    ipv4_int = phy_int['ipv4']
                    interface.use_ipv4 = True

                    interface.ipv4_address = ipv4_int.loopback
                    interface.ipv4_subnet = node.loopback_subnet
                    interface.ipv4_cidr = \
                        sn_preflen_to_network(interface.ipv4_address,
                            interface.ipv4_subnet.prefixlen)

                if node.ip.use_ipv6:
                    ipv6_int = phy_int['ipv6']
                    interface.use_ipv6 = True

# TODO: for consistency, make ipv6_cidr
                    # interface.ipv6_subnet = ipv6_int.loopback # TODO: do we need for consistency?

                    interface.ipv6_address = \
                        sn_preflen_to_network(ipv6_int.loopback, 128)

                # secondary loopbacks
                # TODO: check why vrf names not showing up for all
                # print vrf_interface.vrf_name

            continue
Esempio n. 27
0
    def interfaces(self, node):
        node.interfaces = []

        node.loopback_zero.id = self.lo_interface
        node.loopback_zero.description = "Loopback"

        for interface in node.physical_interfaces:
            phy_int = self.anm['phy'].interface(interface)
            interface.physical = True
            #TODO: allocate ID in platform compiler

            if not phy_int:
                # for instance if added as management interface to nidb in compile
                continue

            interface.description = phy_int.description
            remote_edges = phy_int.edges()
            if len(remote_edges):
                interface.description = "to %s" % remote_edges[0].dst.label

            #TODO: fix the description to use mapped label
            if node.ip.use_ipv4:
                ipv4_int = phy_int['ipv4']
                if ipv4_int.is_bound:
                    # interface is connected
                    interface.use_ipv4 = True
                    interface.ipv4_address = ipv4_int.ip_address
                    interface.ipv4_subnet = ipv4_int.subnet
                    interface.ipv4_cidr = sn_preflen_to_network(interface.ipv4_address,
                            interface.ipv4_subnet.prefixlen)

            if node.ip.use_ipv6:
                ipv6_int = phy_int['ipv6']
                if ipv6_int.is_bound:
                    # interface is connected
                    interface.use_ipv6 = True
#TODO: for consistency, make ipv6_cidr
                    interface.ipv6_subnet = ipv6_int.subnet
                    interface.ipv6_address = sn_preflen_to_network(ipv6_int.ip_address,
                            interface.ipv6_subnet.prefixlen)

        for interface in node.loopback_interfaces:
            #TODO: check if nonzero is different to __eq__
            if interface == node.loopback_zero:
                continue
            else:
                phy_int = self.anm['phy'].interface(interface)
                if node.ip.use_ipv4:
                    ipv4_int = phy_int['ipv4']
                    interface.use_ipv4 = True

                    interface.ipv4_address = ipv4_int.loopback
                    interface.ipv4_subnet = node.loopback_subnet
                    interface.ipv4_cidr = sn_preflen_to_network(interface.ipv4_address,
                            interface.ipv4_subnet.prefixlen)

                if node.ip.use_ipv6:
                    ipv6_int = phy_int['ipv6']
                    interface.use_ipv6 = True
#TODO: for consistency, make ipv6_cidr
                    #interface.ipv6_subnet = ipv6_int.loopback # TODO: do we need for consistency?
                    interface.ipv6_address = sn_preflen_to_network(
                            ipv6_int.loopback, 128)

                # secondary loopbacks
                #TODO: check why vrf names not showing up for all
                #print vrf_interface.vrf_name
            continue
Esempio n. 28
0
    def copy_across_ip_addresses(self):
        # log.info("Copying IP addresses to device model")
        # TODO: try/except and raise SystemError as fatal error if cant copy
        from autonetkit.ank import sn_preflen_to_network

        # TODO:  check if this will clobber with platform?
        for node in self.nidb.l3devices(host=self.host):
            phy_node = self.anm['phy'].node(node)

            node.add_stanza("ip")
            node.ip.use_ipv4 = phy_node.use_ipv4 or False
            node.ip.use_ipv6 = phy_node.use_ipv6 or False

            for interface in node.interfaces:
                phy_int = phy_node.interface(interface)
                if phy_int.exclude_igp is not None:
                    interface.exclude_igp = phy_int.exclude_igp

                if phy_node.use_ipv4:
                    ipv4_int = phy_int['ipv4']

                    """
                    TODO: refactor this logic (and for ipv6) to only check if None
                    then compilers are more pythonic - test for IP is None
                    rather than bound etc - simplifies logic
                    make try to copy, and if fail then warn and set use_ipv4 to False
                    """
                    if node.is_server() and interface.is_loopback:
                        continue
                    if interface.is_physical and not interface.is_bound:
                        continue

                    # permit unbound ip interfaces (e.g. if skipped for l2 encap)
                    if interface.is_physical and not ipv4_int.is_bound:
                        interface.use_ipv4 = False
                        continue

                    if ipv4_int.ip_address is None:
                        #TODO: put into dev log
                        log.debug("No IP address allocated on %s", interface)
                        interface.use_ipv4 = False
                        continue

                    # TODO: also need to skip layer2 virtual interfaces
                    # interface is connected
                    try:
                        interface.ipv4_address = ipv4_int.ip_address
                        interface.ipv4_subnet = ipv4_int.subnet
                        interface.ipv4_cidr = sn_preflen_to_network(interface.ipv4_address,
                                                                    interface.ipv4_subnet.prefixlen)
                    except AttributeError, error:
                        log.warning(
                            "Unable to copy across IPv4 for %s" % interface)
                        log.debug(error)
                    else:
                        interface.use_ipv4 = True
                if phy_node.use_ipv6:
                    ipv6_int = phy_int['ipv6']
                    if node.is_server() and interface.is_loopback:
                        continue
                    if interface.is_physical and not interface.is_bound:
                        continue
                    # permit unbound ip interfaces (e.g. if skipped for l2 encap)
                    if interface.is_physical and not ipv6_int.is_bound:
                        interface.use_ipv6 = False
                        continue
                    if ipv6_int.ip_address is None:
                        #TODO: put into dev log
                        log.debug("No IP address allocated on %s", interface)
                        interface.use_ipv6 = False
                        continue
                    try:
                        # TODO: copy ip address as well
                        interface.ipv6_subnet = ipv6_int.subnet
                        interface.ipv6_address = sn_preflen_to_network(ipv6_int.ip_address,
                                                                       interface.ipv6_subnet.prefixlen)
                    except AttributeError:
                        log.warning(
                            "Unable to copy IPv6 subnet for %s" % interface)
                    else:
                        interface.use_ipv6 = True