Skip to content

Commit

Permalink
katran
Browse files Browse the repository at this point in the history
Reviewed By: jermenkoo

Differential Revision: D64389607

fbshipit-source-id: bcea45ae43e83628e0f401c754f61237466080d9
  • Loading branch information
generatedunixname89002005287564 authored and facebook-github-bot committed Oct 15, 2024
1 parent 3632571 commit 40a2b77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
7 changes: 3 additions & 4 deletions katran/lib/testing/fplane_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

from __future__ import absolute_import, division, print_function

import argparse
import time
Expand Down Expand Up @@ -191,7 +190,7 @@ def __init__(self, args, queue):
self._queue = queue

def sniff_packets(self):
pcap_filter = "ether src host {}".format(self._katran_mac)
pcap_filter = f"ether src host {self._katran_mac}"
sniff(filter=pcap_filter, iface=self._iface, prn=self.process_received_packet)

def send_test_pckts(self):
Expand Down Expand Up @@ -224,9 +223,9 @@ def read_queue(self):

def print_test_results(self):
for test in self._recved_pckts.values():
print("test: {:70} passed".format(test))
print(f"test: {test:70} passed")
for test in self._missed_pckts.values():
print("test: {:70} failed".format(test))
print(f"test: {test:70} failed")

def process_received_packet(self, packet):
if self._verbose:
Expand Down
9 changes: 3 additions & 6 deletions tools/tcpdump_encap_helper/tcpdump_encap_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def ipv4_in_hex(addr):
@param string addr ipv4 address
@return string hex representation of this address
"""
return "0x{:08X}".format(int(ipaddress.ip_address(addr)))
return f"0x{int(ipaddress.ip_address(addr)):08X}"


def ip6_exploded(addr):
Expand All @@ -51,8 +51,7 @@ def ip6_exploded(addr):
@return list<string> ipv6 addresses splited into 4 groups by 32bit each
"""
return [
"0x{:04X}".format(x)
for x in struct.unpack("!IIII", ipaddress.ip_address(addr).packed)
f"0x{x:04X}" for x in struct.unpack("!IIII", ipaddress.ip_address(addr).packed)
]


Expand All @@ -68,9 +67,7 @@ def modify_filter(tcpdump_filters, value, offset, size, v6=False):
packet_type = "ip"
if v6:
packet_type = "ip6"
tcpdump_filters.append(
"({}[{}:{}] == {} )".format(packet_type, offset, size, value)
)
tcpdump_filters.append(f"({packet_type}[{offset}:{size}] == {value} )")
return tcpdump_filters


Expand Down

0 comments on commit 40a2b77

Please sign in to comment.