def test_mac_to_binary(self): """ MAC to binary and back """ mac = 'aa:bb:cc:dd:ee:ff' b = mac_pton(mac) mac2 = mac_ntop(b) self.assertEqual(type(mac), type(mac2)) self.assertEqual(mac2, mac)
def set_sw_if_index(self, sw_if_index): self._sw_if_index = sw_if_index self.generate_remote_hosts() self._local_ip4 = "172.16.%u.1" % self.sw_if_index self._local_ip4n = socket.inet_pton(socket.AF_INET, self.local_ip4) self._local_ip4_subnet = "172.16.%u.0" % self.sw_if_index self._local_ip4n_subnet = socket.inet_pton(socket.AF_INET, self._local_ip4_subnet) self._local_ip4_bcast = "172.16.%u.255" % self.sw_if_index self._local_ip4n_bcast = socket.inet_pton(socket.AF_INET, self._local_ip4_bcast) self.local_ip4_prefix_len = 24 self.has_ip4_config = False self.ip4_table_id = 0 self._local_ip6 = "fd01:%x::1" % self.sw_if_index self._local_ip6n = socket.inet_pton(socket.AF_INET6, self.local_ip6) self.local_ip6_prefix_len = 64 self.has_ip6_config = False self.ip6_table_id = 0 self._local_addr = { socket.AF_INET: self.local_ip4, socket.AF_INET6: self.local_ip6 } self._local_addr_n = { socket.AF_INET: self.local_ip4n, socket.AF_INET6: self.local_ip6n } self._remote_addr = { socket.AF_INET: self.remote_ip4, socket.AF_INET6: self.remote_ip6 } self._remote_addr_n = { socket.AF_INET: self.remote_ip4n, socket.AF_INET6: self.remote_ip6n } r = self.test.vapi.sw_interface_dump() for intf in r: if intf.sw_if_index == self.sw_if_index: self._name = intf.interface_name.split(b'\0', 1)[0].decode('utf8') self._local_mac = mac_ntop(intf.l2_address) self._dump = intf break else: raise Exception("Could not find interface with sw_if_index %d " "in interface dump %s" % (self.sw_if_index, moves.reprlib.repr(r))) self._local_ip6_ll = mk_ll_addr(self.local_mac) self._local_ip6n_ll = socket.inet_pton(socket.AF_INET6, self.local_ip6_ll) self._remote_ip6_ll = mk_ll_addr(self.remote_mac) self._remote_ip6n_ll = socket.inet_pton(socket.AF_INET6, self.remote_ip6_ll)
def set_sw_if_index(self, sw_if_index): self._sw_if_index = sw_if_index self.generate_remote_hosts() self._local_ip4 = "172.16.%u.1" % self.sw_if_index self._local_ip4n = socket.inet_pton(socket.AF_INET, self.local_ip4) self._local_ip4_subnet = "172.16.%u.0" % self.sw_if_index self._local_ip4n_subnet = socket.inet_pton(socket.AF_INET, self._local_ip4_subnet) self._local_ip4_bcast = "172.16.%u.255" % self.sw_if_index self._local_ip4n_bcast = socket.inet_pton(socket.AF_INET, self._local_ip4_bcast) self.local_ip4_prefix_len = 24 self.has_ip4_config = False self.ip4_table_id = 0 self._local_ip6 = "fd01:%x::1" % self.sw_if_index self._local_ip6n = socket.inet_pton(socket.AF_INET6, self.local_ip6) self.local_ip6_prefix_len = 64 self.has_ip6_config = False self.ip6_table_id = 0 self._local_addr = {socket.AF_INET: self.local_ip4, socket.AF_INET6: self.local_ip6} self._local_addr_n = {socket.AF_INET: self.local_ip4n, socket.AF_INET6: self.local_ip6n} self._remote_addr = {socket.AF_INET: self.remote_ip4, socket.AF_INET6: self.remote_ip6} self._remote_addr_n = {socket.AF_INET: self.remote_ip4n, socket.AF_INET6: self.remote_ip6n} r = self.test.vapi.sw_interface_dump() for intf in r: if intf.sw_if_index == self.sw_if_index: self._name = intf.interface_name.split(b'\0', 1)[0].decode('utf8') self._local_mac = mac_ntop(intf.l2_address) self._dump = intf break else: raise Exception( "Could not find interface with sw_if_index %d " "in interface dump %s" % (self.sw_if_index, moves.reprlib.repr(r))) self._local_ip6_ll = mk_ll_addr(self.local_mac) self._local_ip6n_ll = socket.inet_pton(socket.AF_INET6, self.local_ip6_ll) self._remote_ip6_ll = mk_ll_addr(self.remote_mac) self._remote_ip6n_ll = socket.inet_pton(socket.AF_INET6, self.remote_ip6_ll)
def test_mac_to_binary(self): mac = 'aa:bb:cc:dd:ee:ff' b = mac_pton(mac) mac2 = mac_ntop(b) self.assertEqual(type(mac), type(mac2)) self.assertEqual(mac2, mac)