def canonicalized_ip(ip): if isinstance(ip, str): return ip_from_user(ip) elif isinstance(ip, IP): return ip else: raise TypeError('unsupported ip form')
def ip(self, val): if isinstance(val, str): if '/' in val: val, net_len = val.split('/') net_len = int(net_len) mask = '1' * net_len + '0' * (32 - net_len) self.mask = IP.from_bits(bitarray(mask)) self._ip = ip_from_user(val)
def ip(self, val): if isinstance(val, str): if '/' not in val: raise ValueError( 'interface need subnet mask (e.g. "{}/24")'.format(val)) val, net_len = val.split('/') net_len = int(net_len) mask = '1' * net_len + '0' * (32 - net_len) self.mask = IP.from_bits(bitarray(mask)) self._ip = ip_from_user(val)
def __init__(self, ip=None, mac=None): super(Host, self).__init__(n_tips=1) self.tip = self.tips[0] self.nic = NIC(self.tip) self.libsocket = LibSocket(self) if mac is None: mac = self.index if ip is None: ip = '1.0.0.{}'.format(self.index) self.ip = ip_from_user(ip) self.mac = mac_from_user(mac) self.ip2mac = CacheTable(entry_duration=1000) self.arp_table = self.ip2mac self.avail_ports = defaultdict(lambda: 49152) self.pending_packets = defaultdict(deque) self.pending_frames = deque() self.sockets = {} mint.worker(self.run)
def mask(self, val): self._mask = ip_from_user(val)