def create_stream_ip6(self, src_if, src_ip, dst_ip): pkts = [] for i in range(0, N_PKTS_IN_STREAM): info = self.create_packet_info(src_if, src_if) payload = self.info_to_payload(info) p = (Ether(dst=getmacbyip6(dst_ip), src=src_if.remote_mac) / IPv6(src=src_ip, dst=dst_ip) / UDP(sport=1234, dport=1234) / Raw(payload)) info.data = p.copy() pkts.append(p) return pkts
def _get_mac_address_of_ip(self, ip_addr: IPAddress): if ip_addr.version == IPAddress.IPV4: ip_str = socket.inet_ntop(socket.AF_INET, ip_addr.address) addr_str = getmacbyip(ip_str) else: ip_str = socket.inet_ntop(socket.AF_INET6, ip_addr.address) addr_str = getmacbyip6(ip_str) if not addr_str: LOG.error("Coudn't find mac for IP: %s, disabling ebpf" % (ip_str)) return None LOG.debug("IP: %s, mac: %s" % (ip_str, addr_str)) return self._pack_mac_addr(addr_str)
def _get_gw_mac_address_v6(self, ip: IPAddress) -> str: try: gw_ip = ipaddress.ip_address(ip.address) mac = getmacbyip6(str(gw_ip)) self.logger.debug("Got mac %s for IP: %s", mac, gw_ip) return mac except Scapy_Exception as ex: self.logger.warning("Error in probing Mac address: err %s", ex) return "" except ValueError: self.logger.warning( "Invalid GW Ip address: [%s]", str(ip), ) return ""
def verify_capture_ip6(self, rx_if, sent): capture = rx_if.get_capture(len(sent)) self.assertEqual(len(capture), len(sent)) for i in range(len(capture)): tx = sent[i] rx = capture[i] eth = rx[Ether] self.assertEqual(eth.type, 0x86DD) tx_ip = tx[IPv6] rx_ip = rx[IPv6] # check the MAC address on the RX'd packet is correctly formed self.assertEqual(eth.dst, getmacbyip6(rx_ip.dst)) self.assertEqual(rx_ip.src, tx_ip.src) self.assertEqual(rx_ip.dst, tx_ip.dst) # IP processing post pop has decremented the TTL self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim)