Esempio n. 1
0
def address_pair(n: Node, use_v4=True, use_v6=True) \
        -> Tuple[Optional[str], Optional[str]]:
    """Returns a tuple (ip, ip6) with ip/ip6 being one of the IPv4/IPv6
       addresses of the node n"""
    from .link import IPIntf  # Prevent circular imports
    v4_str = v6_str = None
    for itf in n.intfList():
        # Mininet switches have a loopback interface
        # declared as an Intf.
        # This object does not have ips() or ip6s() methods.
        if not isinstance(itf, IPIntf):
            continue

        if use_v4 and v4_str is None:
            itf.updateIP()
            v4 = next(itf.ips(), None)
            v4_str = v4.ip.compressed if v4 is not None else v4
        if use_v6 and v6_str is None:
            itf.updateIP6()
            v6 = next(itf.ip6s(exclude_lls=True), None)
            v6_str = v6.ip.compressed if v6 is not None else v6
        if (not use_v4 or v4_str is not None) \
                and (not use_v6 or v6_str is not None):
            break
    return v4_str, v6_str
Esempio n. 2
0
def realIntfList(n: Node) -> List['IPIntf']:
    """Return the list of interfaces of node n excluding loopback"""
    return [i for i in n.intfList() if i.name != 'lo']