当前位置: 首页>>代码示例>>Python>>正文


Python node.Node方法代码示例

本文整理汇总了Python中mininet.node.Node方法的典型用法代码示例。如果您正苦于以下问题:Python node.Node方法的具体用法?Python node.Node怎么用?Python node.Node使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mininet.node的用法示例。


在下文中一共展示了node.Node方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
def build(self):
        super().build()
        self.broadcast_domains = self._broadcast_domains()
        log.info("*** Found", len(self.broadcast_domains),
                 "broadcast domains\n")
        if self.allocate_IPs:
            self._allocate_IPs()
        # Physical interfaces are their own broadcast domain
        for itf_name, n in self.physical_interface.items():
            try:
                itf = PhysicalInterface(itf_name, node=self[n])
                log.info('\n*** Adding Physical interface',
                         itf_name, 'to', n, '\n')
                self.broadcast_domains.append(BroadcastDomain(itf))
            except KeyError:
                log.error('!!! Node', n, 'not found!\n')
        try:
            self.topo.post_build(self)
        except AttributeError as e:
            log.error('*** Skipping post_build():', e, '\n') 
开发者ID:cnp3,项目名称:ipmininet,代码行数:22,代码来源:ipnet.py

示例2: address_pair

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
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 
开发者ID:cnp3,项目名称:ipmininet,代码行数:27,代码来源:utils.py

示例3: find_node

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
def find_node(start: Node, node_name: str) -> Optional[Intf]:
    """
    :param start: The starting node of the search
    :param node_name: The name of the node to find
    :return: The interface of the node connected to start with node_name as name
    """

    if start.name == node_name:
        return start.intf()

    visited = set()  # type: Set[IPIntf]
    to_visit = realIntfList(start)
    # Explore all interfaces recursively, until we find one
    # connected to the node
    while to_visit:
        i = to_visit.pop()
        if i in visited:
            continue
        visited.add(i)
        for n in i.broadcast_domain.interfaces:
            if n.node.name == node_name:
                return n
            if L3Router.is_l3router_intf(n):
                to_visit.extend(realIntfList(n.node))
    return None 
开发者ID:cnp3,项目名称:ipmininet,代码行数:27,代码来源:utils.py

示例4: _addresses_of

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
def _addresses_of(devname: str, node: Optional[Node] = None):
    """Return the addresses of a named interface"""
    cmdline = ['ip', 'address', 'show', 'dev', devname]
    try:
        if node is not None:
            addrstr = node.cmd(*cmdline)
        else:
            addrstr = subprocess.check_output(cmdline).decode("utf-8")
    except (OSError, subprocess.CalledProcessError):
        addrstr = None
    if not addrstr:
        log.warning('Failed to run ip address!')
        return None, (), ()
    mac, v4, v6 = _parse_addresses(addrstr)
    return (mac,
            sorted(v4, key=OrderedAddress, reverse=True),
            sorted(v6, key=OrderedAddress, reverse=True)) 
开发者ID:cnp3,项目名称:ipmininet,代码行数:19,代码来源:link.py

示例5: node_for_ip

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
def node_for_ip(self, ip: Union[str, IPv4Address, IPv6Address]) -> Node:
        """Return the node owning a given IP address

        :param ip: an IP address
        :return: a node name"""
        return self._ip_allocs[str(ip)] 
开发者ID:cnp3,项目名称:ipmininet,代码行数:8,代码来源:ipnet.py

示例6: _ping_set

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
def _ping_set(self, src: Node,
                  dst_dict: Mapping[Node, Union[IPv4Address, IPv6Address, str]],
                  timeout: Optional[str], v4=True) -> Tuple[int, int]:
        """Do the actual ping to the dict of {dst: dst_ip} from src

           :param src: origin of the ping
           :param dst_dict: destinations {dst: dst_ip} of the ping
           :param timeout: the time to wait for a response, as string
           :param v4: whether IPv4 or IPv6 is used
           :param return: a tuple (lost packets, sent packets)"""
        if len(dst_dict) == 0:
            return 0, 0
        lost = 0
        packets = 0
        opts = ''
        if timeout:
            opts = '-W %s' % timeout

        log.output("%s --%s--> " % (src.name, "IPv4" if v4 else "IPv6"))
        for dst, dst_ip in dst_dict.items():
            result = src.cmd('%s -c1 %s %s' % ("ping" if v4 else PING6_CMD,
                                               opts, dst_ip))
            sent, received = self._parsePing(result)
            lost += sent - received
            packets += sent
            log.output("%s " % dst.name if received else "X ")
        log.output('\n')

        return lost, packets 
开发者ID:cnp3,项目名称:ipmininet,代码行数:31,代码来源:ipnet.py

示例7: realIntfList

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
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'] 
开发者ID:cnp3,项目名称:ipmininet,代码行数:5,代码来源:utils.py

示例8: init_floating_network

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
def init_floating_network(self, name="default"):
        """
        Initialize the floating network component for the emulator.
        Will not do anything if already initialized.
        """
        if self.net is not None and self.floating_switch is None:
            # create a floating network
            fn = self.floating_network = Net(name)
            fn.id = str(uuid.uuid4())
            fn.set_cidr(self.floating_netmask)

            # create a subnet
            fn.subnet_id = str(uuid.uuid4())
            fn.subnet_name = fn.name + "-sub"

            # create a port for the host
            port = Port("root-port")
            # port.id = str(uuid.uuid4())
            port.net_name = fn.name

            # get next free ip
            root_ip = fn.get_new_ip_address(port.name)
            port.ip_address = root_ip
            # floating ip network setup
            # wierd way of getting a datacenter object
            first_dc = list(self.net.dcs.values())[0]
            # set a dpid for the switch. for this we have to get the id of the
            # next possible dc
            self.floating_switch = self.net.addSwitch(
                "fs1", dpid=hex(first_dc._get_next_dc_dpid())[2:])
            # this is the interface appearing on the physical host
            self.floating_root = Node('root', inNamespace=False)
            self.net.hosts.append(self.floating_root)
            self.net.nameToNode['root'] = self.floating_root
            self.floating_intf = self.net.addLink(
                self.floating_root, self.floating_switch).intf1
            self.floating_root.setIP(root_ip, intf=self.floating_intf)
            self.floating_nodes[(self.floating_root.name,
                                 root_ip)] = self.floating_root 
开发者ID:sonata-nfv,项目名称:son-emu,代码行数:41,代码来源:manage.py

示例9: start

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
def start():

    global net, attacker, running

    if running:
        return '\nServer already running.\n'

    setLogLevel('info')

    topo = MixTopo()
    net = Mininet(topo=topo)

    s1 = net['s1']
    plc2 = net['plc2']
    plc3 = net['plc3']

    s2, rtu2a, scada = net.get('s2', 'rtu2a', 'scada')
    rtu2b, attacker2 = net.get('rtu2b', 'attacker2')
    s3 = net.get('s3')

    # NOTE: root-eth0 interface on the host
    root = Node('root', inNamespace=False)
    intf = net.addLink(root, s3).intf1
    print('DEBUG root intf: {}'.format(intf))
    root.setIP('10.0.0.30', intf=intf)
    # NOTE: all packet from root to the 10.0.0.0 network
    root.cmd('route add -net ' + '10.0.0.0' + ' dev ' + str(intf))


    net.start()
    info('Welcome')

    # NOTE: use for debugging
    #s1.cmd('tcpdump -i s1-eth1 -w /tmp/s1-eth1.pcap &')
    #s1.cmd('tcpdump -i s1-eth2 -w /tmp/s1-eth2.pcap &')

    SLEEP = 0.5

    # NOTE: swat challenge 1 and 2
    plc3.cmd(sys.executable + ' plc3.py &')
    sleep(SLEEP)
    plc2.cmd(sys.executable + ' plc2.py &')
    sleep(SLEEP)

    # NOTE: wadi challenge 1
    scada.cmd(sys.executable + ' scada.py &')
    sleep(SLEEP)
    rtu2a.cmd(sys.executable + ' rtu2a.py &')
    sleep(SLEEP)
    # NOTE: wadi challenge 2
    rtu2b.cmd(sys.executable + ' rtu2b.py &')
    sleep(SLEEP)


    running = True
    return '\nServer started.\n' 
开发者ID:scy-phy,项目名称:minicps,代码行数:58,代码来源:run.py

示例10: __init__

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
def __init__(self,
                 router: Type[Router] = Router,
                 config: Type[RouterConfig] = BasicRouterConfig,
                 use_v4=True,
                 ipBase='192.168.0.0/16',
                 max_v4_prefixlen=24,
                 use_v6=True,
                 ip6Base='fc00::/7',
                 allocate_IPs=True,
                 max_v6_prefixlen=48,
                 igp_metric=MIN_IGP_METRIC,
                 igp_area=OSPF_DEFAULT_AREA,
                 host: Type[IPHost] = IPHost,
                 link: Type[IPLink] = IPLink,
                 intf: Type[IPIntf] = IPIntf,
                 switch: Type[IPSwitch] = IPSwitch,
                 controller: Optional[Type[Controller]] = None,
                 *args, **kwargs):
        """Extends Mininet by adding IP-related ivars/functions and
        configuration knobs.


        :param router: The class to use to build routers
        :param config: The default configuration for the routers
        :param use_v4: Enable IPv4
        :param max_v4_prefixlen: The maximal IPv4 prefix for the auto-allocated
                                    broadcast domains
        :param use_v6: Enable IPv6
        :param ip6Base: Base prefix to use for IPv6 allocations
        :param max_v6_prefixlen: Maximal IPv6 prefixlen to auto-allocate
        :param allocate_IPs: whether to auto-allocate subnets in the network
        :param igp_metric: The default IGP metric for the links
        :param igp_area: The default IGP area for the links"""
        self.router = router
        self.config = config
        self.routers = []  # type: List[Router]
        # We need this to be able to do inverse-lookups
        self._ip_allocs = {}  # type: Dict[str, Node]
        self.max_v4_prefixlen = max_v4_prefixlen
        self._unallocated_ipbase = [ip_network(ipBase)]
        self.use_v4 = use_v4
        self.use_v6 = use_v6
        self.ip6Base = ip6Base
        self.max_v6_prefixlen = max_v6_prefixlen
        self._unallocated_ip6base = [ip_network(ip6Base)]
        self.broadcast_domains = None
        self.igp_metric = igp_metric
        self.igp_area = igp_area
        self.allocate_IPs = allocate_IPs
        self.physical_interface = {}  # type: Dict[IPIntf, Node]
        super().__init__(ipBase=ipBase, host=host, switch=switch, link=link,
                         intf=intf, controller=controller, *args, **kwargs) 
开发者ID:cnp3,项目名称:ipmininet,代码行数:54,代码来源:ipnet.py

示例11: addLink

# 需要导入模块: from mininet import node [as 别名]
# 或者: from mininet.node import Node [as 别名]
def addLink(self, node1: Node, node2: Node,
                igp_metric: Optional[int] = None,
                igp_area: Optional[str] = None,
                igp_passive=False,
                v4_width=1, v6_width=1,
                *args, **params) -> IPLink:
        """Register a link with additional properties

        :param igp_metric: the associated igp metric for this link
        :param igp_area: the associated igp area for this link
        :param igp_passive: whether IGP should create adjacencies over this
                            link or not
        :param v4_width: the number of IPv4 addresses to allocate on the
                         interfaces
        :param v6_width: the number of IPv6 addresses to allocate on the
                         interfaces
        :param ra: list of AdvPrefix objects, each one representing an
                   advertised prefix
        :param rdnss: list of AdvRDNSS objects, each one representing
                   an advertised DNS server
        """
        # Handles defaults
        if not igp_metric:
            igp_metric = self.igp_metric
        if not igp_area:
            igp_area = self.igp_area
        # Register all link properties
        props = {'igp_metric': igp_metric,
                 'igp_area': igp_area,
                 'igp_passive': igp_passive,
                 'v4_width': v4_width,
                 'v6_width': v6_width}
        # Update interface properties with link properties
        for pstr in ('params1', 'params2'):
            try:
                p = params[pstr]
            except KeyError:
                p = params[pstr] = {}
            for k, v in props.items():
                # Only iff not already specified
                if k not in p:
                    p[k] = v
        return super().addLink(node1=node1, node2=node2, *args, **params) 
开发者ID:cnp3,项目名称:ipmininet,代码行数:45,代码来源:ipnet.py


注:本文中的mininet.node.Node方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。