diff --git a/exercises/basic/receive.py b/exercises/basic/receive.py index 04e9bd973..746d317a5 100755 --- a/exercises/basic/receive.py +++ b/exercises/basic/receive.py @@ -1,14 +1,20 @@ #!/usr/bin/env python3 -import sys -import struct import os +import sys -from scapy.all import sniff, sendp, hexdump, get_if_list, get_if_hwaddr -from scapy.all import Packet, IPOption -from scapy.all import ShortField, IntField, LongField, BitField, FieldListField, FieldLenField -from scapy.all import IP, TCP, UDP, Raw +from scapy.all import ( + TCP, + FieldLenField, + FieldListField, + IntField, + IPOption, + ShortField, + get_if_list, + sniff +) from scapy.layers.inet import _IPOption_HDR + def get_if(): ifs=get_if_list() iface=None @@ -44,7 +50,7 @@ def handle_pkt(pkt): def main(): ifaces = [i for i in os.listdir('/sys/class/net/') if 'eth' in i] iface = ifaces[0] - print(("sniffing on %s" % iface)) + print("sniffing on %s" % iface) sys.stdout.flush() sniff(iface = iface, prn = lambda x: handle_pkt(x)) diff --git a/exercises/basic/send.py b/exercises/basic/send.py index b320b0d92..e12213c3f 100755 --- a/exercises/basic/send.py +++ b/exercises/basic/send.py @@ -1,13 +1,10 @@ #!/usr/bin/env python3 -import argparse -import sys -import socket import random -import struct +import socket +import sys + +from scapy.all import IP, TCP, Ether, get_if_hwaddr, get_if_list, sendp -from scapy.all import sendp, send, get_if_list, get_if_hwaddr -from scapy.all import Packet -from scapy.all import Ether, IP, UDP, TCP def get_if(): ifs=get_if_list() @@ -30,7 +27,7 @@ def main(): addr = socket.gethostbyname(sys.argv[1]) iface = get_if() - print(("sending on interface %s to %s" % (iface, str(addr)))) + print("sending on interface %s to %s" % (iface, str(addr))) pkt = Ether(src=get_if_hwaddr(iface), dst='ff:ff:ff:ff:ff:ff') pkt = pkt /IP(dst=addr) / TCP(dport=1234, sport=random.randint(49152,65535)) / sys.argv[2] pkt.show2() diff --git a/exercises/basic_tunnel/myTunnel_header.py b/exercises/basic_tunnel/myTunnel_header.py index 5a5922ec8..714e0029c 100644 --- a/exercises/basic_tunnel/myTunnel_header.py +++ b/exercises/basic_tunnel/myTunnel_header.py @@ -1,6 +1,6 @@ + from scapy.all import * -import sys, os TYPE_MYTUNNEL = 0x1212 TYPE_IPV4 = 0x0800 diff --git a/exercises/basic_tunnel/receive.py b/exercises/basic_tunnel/receive.py index 3b065c00f..ac5b3ea75 100755 --- a/exercises/basic_tunnel/receive.py +++ b/exercises/basic_tunnel/receive.py @@ -1,14 +1,10 @@ #!/usr/bin/env python3 -import sys -import struct import os +import sys -from scapy.all import sniff, sendp, hexdump, get_if_list, get_if_hwaddr -from scapy.all import Packet, IPOption -from scapy.all import ShortField, IntField, LongField, BitField, FieldListField, FieldLenField -from scapy.all import IP, TCP, UDP, Raw -from scapy.layers.inet import _IPOption_HDR from myTunnel_header import MyTunnel +from scapy.all import TCP, get_if_list, sniff + def get_if(): ifs=get_if_list() @@ -34,7 +30,7 @@ def handle_pkt(pkt): def main(): ifaces = [i for i in os.listdir('/sys/class/net/') if 'eth' in i] iface = ifaces[0] - print(("sniffing on %s" % iface)) + print("sniffing on %s" % iface) sys.stdout.flush() sniff(iface = iface, prn = lambda x: handle_pkt(x)) diff --git a/exercises/basic_tunnel/send.py b/exercises/basic_tunnel/send.py index ac29bd909..5d01f463c 100755 --- a/exercises/basic_tunnel/send.py +++ b/exercises/basic_tunnel/send.py @@ -1,15 +1,11 @@ #!/usr/bin/env python3 import argparse -import sys -import socket import random -import struct -import argparse +import socket -from scapy.all import sendp, send, get_if_list, get_if_hwaddr, hexdump -from scapy.all import Packet -from scapy.all import Ether, IP, UDP, TCP from myTunnel_header import MyTunnel +from scapy.all import IP, TCP, Ether, get_if_hwaddr, get_if_list, sendp + def get_if(): ifs=get_if_list() @@ -35,11 +31,11 @@ def main(): iface = get_if() if (dst_id is not None): - print(("sending on interface {} to dst_id {}".format(iface, str(dst_id)))) + print("sending on interface {} to dst_id {}".format(iface, str(dst_id))) pkt = Ether(src=get_if_hwaddr(iface), dst='ff:ff:ff:ff:ff:ff') pkt = pkt / MyTunnel(dst_id=dst_id) / IP(dst=addr) / args.message else: - print(("sending on interface {} to IP addr {}".format(iface, str(addr)))) + print("sending on interface {} to IP addr {}".format(iface, str(addr))) pkt = Ether(src=get_if_hwaddr(iface), dst='ff:ff:ff:ff:ff:ff') pkt = pkt / IP(dst=addr) / TCP(dport=1234, sport=random.randint(49152,65535)) / args.message diff --git a/exercises/calc/calc.py b/exercises/calc/calc.py index 5209c6b7c..5750a3f9c 100644 --- a/exercises/calc/calc.py +++ b/exercises/calc/calc.py @@ -1,17 +1,17 @@ #!/usr/bin/env python3 -import argparse -import sys -import socket -import random -import struct import re -from scapy.all import sendp, send, srp1 -from scapy.all import Packet, hexdump -from scapy.all import Ether, StrFixedLenField, XByteField, IntField -from scapy.all import bind_layers -import readline +from scapy.all import ( + Ether, + IntField, + Packet, + StrFixedLenField, + XByteField, + bind_layers, + srp1 +) + class P4calc(Packet): name = "P4calc" @@ -84,7 +84,7 @@ def main(): if resp: p4calc=resp[P4calc] if p4calc: - print((p4calc.result)) + print(p4calc.result) else: print("cannot find P4calc header in the packet") else: diff --git a/exercises/ecn/receive.py b/exercises/ecn/receive.py index ca368eed0..fa3836e6b 100755 --- a/exercises/ecn/receive.py +++ b/exercises/ecn/receive.py @@ -1,11 +1,8 @@ #!/usr/bin/env python3 import sys -import struct -from scapy.all import sniff, sendp, hexdump, get_if_list, get_if_hwaddr -from scapy.all import Packet -from scapy.all import IP, UDP, Raw -from scapy.layers.inet import _IPOption_HDR +from scapy.all import get_if_list, sniff + def get_if(): ifs=get_if_list() @@ -28,7 +25,7 @@ def handle_pkt(pkt): def main(): iface = 'eth0' - print(("sniffing on %s" % iface)) + print("sniffing on %s" % iface) sys.stdout.flush() sniff(filter="udp and port 4321", iface = iface, prn = lambda x: handle_pkt(x)) diff --git a/exercises/ecn/send.py b/exercises/ecn/send.py index 1a6778cfa..0cccb2019 100755 --- a/exercises/ecn/send.py +++ b/exercises/ecn/send.py @@ -1,18 +1,11 @@ #!/usr/bin/env python3 -import argparse -import sys import socket -import random -import struct +import sys +from time import sleep -from scapy.all import sendp, send, hexdump, get_if_list, get_if_hwaddr -from scapy.all import Packet, IPOption -from scapy.all import Ether, IP, UDP -from scapy.all import IntField, FieldListField, FieldLenField, ShortField -from scapy.layers.inet import _IPOption_HDR +from scapy.all import IP, UDP, Ether, get_if_hwaddr, get_if_list, sendp -from time import sleep def get_if(): ifs=get_if_list() diff --git a/exercises/link_monitor/receive.py b/exercises/link_monitor/receive.py index a7250e3f8..4ef7040b8 100755 --- a/exercises/link_monitor/receive.py +++ b/exercises/link_monitor/receive.py @@ -2,6 +2,7 @@ from probe_hdrs import * + def expand(x): yield x while x.payload: @@ -14,11 +15,11 @@ def handle_pkt(pkt): print("") for sw in data_layers: utilization = 0 if sw.cur_time == sw.last_time else 8.0*sw.byte_cnt/(sw.cur_time - sw.last_time) - print(("Switch {} - Port {}: {} Mbps".format(sw.swid, sw.port, utilization))) + print("Switch {} - Port {}: {} Mbps".format(sw.swid, sw.port, utilization)) def main(): iface = 'eth0' - print(("sniffing on {}".format(iface))) + print("sniffing on {}".format(iface)) sniff(iface = iface, prn = lambda x: handle_pkt(x)) diff --git a/exercises/link_monitor/send.py b/exercises/link_monitor/send.py index 0ba04160b..c4e1a7080 100755 --- a/exercises/link_monitor/send.py +++ b/exercises/link_monitor/send.py @@ -1,8 +1,10 @@ #!/usr/bin/env python3 import sys import time + from probe_hdrs import * + def main(): probe_pkt = Ether(dst='ff:ff:ff:ff:ff:ff', src=get_if_hwaddr('eth0')) / \ diff --git a/exercises/load_balance/receive.py b/exercises/load_balance/receive.py index 1156e7c45..671088120 100755 --- a/exercises/load_balance/receive.py +++ b/exercises/load_balance/receive.py @@ -1,14 +1,19 @@ #!/usr/bin/env python3 -import sys -import struct import os +import sys -from scapy.all import sniff, sendp, hexdump, get_if_list, get_if_hwaddr -from scapy.all import Packet, IPOption -from scapy.all import ShortField, IntField, LongField, BitField, FieldListField, FieldLenField -from scapy.all import IP, UDP, Raw +from scapy.all import ( + FieldLenField, + FieldListField, + IntField, + IPOption, + ShortField, + get_if_list, + sniff +) from scapy.layers.inet import _IPOption_HDR + def get_if(): ifs=get_if_list() iface=None diff --git a/exercises/load_balance/send.py b/exercises/load_balance/send.py index 939a12871..e12213c3f 100755 --- a/exercises/load_balance/send.py +++ b/exercises/load_balance/send.py @@ -1,13 +1,10 @@ #!/usr/bin/env python3 -import argparse -import sys -import socket import random -import struct +import socket +import sys + +from scapy.all import IP, TCP, Ether, get_if_hwaddr, get_if_list, sendp -from scapy.all import sendp, send, get_if_list, get_if_hwaddr -from scapy.all import Packet -from scapy.all import Ether, IP, UDP, TCP def get_if(): ifs=get_if_list() diff --git a/exercises/mri/receive.py b/exercises/mri/receive.py index 2f8a5fbba..5c834f694 100755 --- a/exercises/mri/receive.py +++ b/exercises/mri/receive.py @@ -1,13 +1,19 @@ #!/usr/bin/env python3 import sys -import struct -from scapy.all import sniff, sendp, hexdump, get_if_list, get_if_hwaddr -from scapy.all import Packet, IPOption -from scapy.all import PacketListField, ShortField, IntField, LongField, BitField, FieldListField, FieldLenField -from scapy.all import IP, UDP, Raw +from scapy.all import ( + FieldLenField, + IntField, + IPOption, + Packet, + PacketListField, + ShortField, + get_if_list, + sniff +) from scapy.layers.inet import _IPOption_HDR + def get_if(): ifs=get_if_list() iface=None diff --git a/exercises/mri/send.py b/exercises/mri/send.py index 5d0104647..8e0001eeb 100755 --- a/exercises/mri/send.py +++ b/exercises/mri/send.py @@ -1,18 +1,25 @@ #!/usr/bin/env python3 -import argparse -import sys import socket -import random -import struct +import sys +from time import sleep -from scapy.all import sendp, send, hexdump, get_if_list, get_if_hwaddr -from scapy.all import Packet, IPOption -from scapy.all import Ether, IP, UDP -from scapy.all import IntField, FieldListField, FieldLenField, ShortField, PacketListField +from scapy.all import ( + IP, + UDP, + Ether, + FieldLenField, + IntField, + IPOption, + Packet, + PacketListField, + ShortField, + get_if_hwaddr, + get_if_list, + sendp +) from scapy.layers.inet import _IPOption_HDR -from time import sleep def get_if(): ifs=get_if_list() diff --git a/exercises/p4runtime/mycontroller.py b/exercises/p4runtime/mycontroller.py index 7f127e6c5..4be31586c 100755 --- a/exercises/p4runtime/mycontroller.py +++ b/exercises/p4runtime/mycontroller.py @@ -1,19 +1,20 @@ #!/usr/bin/env python3 import argparse -import grpc import os import sys from time import sleep +import grpc + # Import P4Runtime lib from parent utils dir # Probably there's a better way of doing this. sys.path.append( os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../utils/')) import p4runtime_lib.bmv2 +import p4runtime_lib.helper from p4runtime_lib.error_utils import printGrpcError from p4runtime_lib.switch import ShutdownAllSwitchConnections -import p4runtime_lib.helper SWITCH_TO_HOST_PORT = 1 SWITCH_TO_SWITCH_PORT = 2 diff --git a/exercises/p4runtime/solution/mycontroller.py b/exercises/p4runtime/solution/mycontroller.py index 6a9a20baa..926a6c329 100755 --- a/exercises/p4runtime/solution/mycontroller.py +++ b/exercises/p4runtime/solution/mycontroller.py @@ -1,18 +1,19 @@ #!/usr/bin/env python3 import argparse -import grpc import os import sys from time import sleep +import grpc + # Import P4Runtime lib from parent utils dir # Probably there's a better way of doing this. sys.path.append( os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../utils/')) import p4runtime_lib.bmv2 -from p4runtime_lib.switch import ShutdownAllSwitchConnections import p4runtime_lib.helper +from p4runtime_lib.switch import ShutdownAllSwitchConnections SWITCH_TO_HOST_PORT = 1 SWITCH_TO_SWITCH_PORT = 2 diff --git a/exercises/qos/receive.py b/exercises/qos/receive.py index ee1e4ad33..73555bd01 100755 --- a/exercises/qos/receive.py +++ b/exercises/qos/receive.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3 import sys -from scapy.all import sniff, get_if_list + +from scapy.all import sniff def handle_pkt(pkt): diff --git a/exercises/qos/send.py b/exercises/qos/send.py index c0c6afc1e..4b6bd42d9 100755 --- a/exercises/qos/send.py +++ b/exercises/qos/send.py @@ -2,12 +2,10 @@ import argparse import socket - -from scapy.all import sendp, send, hexdump, get_if_list, get_if_hwaddr -from scapy.all import Ether, IP, UDP, TCP - from time import sleep +from scapy.all import IP, TCP, UDP, Ether, get_if_hwaddr, get_if_list, sendp + def get_if(): iface = None diff --git a/exercises/source_routing/receive.py b/exercises/source_routing/receive.py index 435311e07..12f58e71d 100755 --- a/exercises/source_routing/receive.py +++ b/exercises/source_routing/receive.py @@ -1,12 +1,10 @@ #!/usr/bin/env python3 import sys -import struct -from scapy.all import sniff, sendp, hexdump, get_if_list, get_if_hwaddr, bind_layers -from scapy.all import Packet, IPOption -from scapy.all import IP, UDP, Raw, Ether -from scapy.layers.inet import _IPOption_HDR +from scapy.all import Ether, IPOption, Packet, bind_layers, get_if_list, sniff from scapy.fields import * +from scapy.layers.inet import _IPOption_HDR + def get_if(): ifs=get_if_list() diff --git a/exercises/source_routing/send.py b/exercises/source_routing/send.py index f972aed93..26230228a 100755 --- a/exercises/source_routing/send.py +++ b/exercises/source_routing/send.py @@ -1,15 +1,19 @@ #!/usr/bin/env python3 -import argparse -import sys import socket -import random -import struct +import sys -from scapy.all import sendp, send, get_if_list, get_if_hwaddr, bind_layers -from scapy.all import Packet -from scapy.all import Ether, IP, UDP +from scapy.all import ( + IP, + UDP, + Ether, + Packet, + bind_layers, + get_if_hwaddr, + get_if_list, + sendp +) from scapy.fields import * -import readline + def get_if(): ifs=get_if_list() diff --git a/utils/mininet/appcontroller.py b/utils/mininet/appcontroller.py index 3c7ead16f..f783bd944 100644 --- a/utils/mininet/appcontroller.py +++ b/utils/mininet/appcontroller.py @@ -2,6 +2,7 @@ from shortest_path import ShortestPath + class AppController: def __init__(self, manifest=None, target=None, topo=None, net=None, links=None): diff --git a/utils/mininet/apptopo.py b/utils/mininet/apptopo.py index f2b615290..ac543afa9 100644 --- a/utils/mininet/apptopo.py +++ b/utils/mininet/apptopo.py @@ -1,5 +1,6 @@ from mininet.topo import Topo + class AppTopo(Topo): def __init__(self, links, latencies={}, manifest=None, target=None, diff --git a/utils/mininet/multi_switch_mininet.py b/utils/mininet/multi_switch_mininet.py index 0d58358bc..288ad6c02 100755 --- a/utils/mininet/multi_switch_mininet.py +++ b/utils/mininet/multi_switch_mininet.py @@ -15,25 +15,21 @@ # limitations under the License. # -import signal -import os -import sys -import subprocess import argparse -import json import importlib +import json +import os import re +import sys from time import sleep -from mininet.net import Mininet -from mininet.topo import Topo -from mininet.link import TCLink -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -from p4_mininet import P4Switch, P4Host -import apptopo import appcontroller +import apptopo +from mininet.cli import CLI +from mininet.link import TCLink +from mininet.log import setLogLevel +from mininet.net import Mininet +from p4_mininet import P4Host, P4Switch parser = argparse.ArgumentParser(description='Mininet demo') parser.add_argument('--behavioral-exe', help='Path to behavioral executable', diff --git a/utils/mininet/p4_mininet.py b/utils/mininet/p4_mininet.py index 81757541a..fcfacc13a 100644 --- a/utils/mininet/p4_mininet.py +++ b/utils/mininet/p4_mininet.py @@ -13,15 +13,16 @@ # limitations under the License. # -from mininet.net import Mininet -from mininet.node import Switch, Host -from mininet.log import setLogLevel, info, error, debug -from mininet.moduledeps import pathCheck -from sys import exit -from time import sleep import os -import tempfile import socket +import tempfile +from sys import exit +from time import sleep + +from mininet.log import debug, error, info +from mininet.moduledeps import pathCheck +from mininet.node import Host, Switch + class P4Host(Host): def config(self, **params): diff --git a/utils/mininet/single_switch_mininet.py b/utils/mininet/single_switch_mininet.py index 9c2431d8e..5a807aa34 100755 --- a/utils/mininet/single_switch_mininet.py +++ b/utils/mininet/single_switch_mininet.py @@ -15,17 +15,16 @@ # limitations under the License. # -from mininet.net import Mininet -from mininet.topo import Topo -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -from p4_mininet import P4Switch, P4Host - import argparse from subprocess import PIPE, Popen from time import sleep +from mininet.cli import CLI +from mininet.log import setLogLevel +from mininet.net import Mininet +from mininet.topo import Topo +from p4_mininet import P4Host, P4Switch + parser = argparse.ArgumentParser(description='Mininet demo') parser.add_argument('--behavioral-exe', help='Path to behavioral executable', type=str, action="store", required=True) diff --git a/utils/netstat.py b/utils/netstat.py index bb12ffdf5..fa7f1ea25 100644 --- a/utils/netstat.py +++ b/utils/netstat.py @@ -14,6 +14,8 @@ # import psutil + + def check_listening_on_port(port): for c in psutil.net_connections(kind='inet'): if c.status == 'LISTEN' and c.laddr[1] == port: diff --git a/utils/p4_mininet.py b/utils/p4_mininet.py index fad514178..2554f2da1 100644 --- a/utils/p4_mininet.py +++ b/utils/p4_mininet.py @@ -13,16 +13,14 @@ # limitations under the License. # -from mininet.net import Mininet -from mininet.node import Switch, Host -from mininet.log import setLogLevel, info, error, debug -from mininet.moduledeps import pathCheck -from sys import exit import os import tempfile -import socket +from sys import exit from time import sleep +from mininet.log import debug, error, info +from mininet.moduledeps import pathCheck +from mininet.node import Host, Switch from netstat import check_listening_on_port SWITCH_START_TIMEOUT = 10 # seconds diff --git a/utils/p4apprunner.py b/utils/p4apprunner.py index e3a9e0035..c06d03470 100755 --- a/utils/p4apprunner.py +++ b/utils/p4apprunner.py @@ -16,11 +16,11 @@ import argparse -from collections import OrderedDict import json import os import sys import tarfile +from collections import OrderedDict parser = argparse.ArgumentParser(description='p4apprunner') parser.add_argument('--build-dir', help='Directory to build in.', diff --git a/utils/p4runtime_lib/bmv2.py b/utils/p4runtime_lib/bmv2.py index eebb44ad4..92780de1a 100644 --- a/utils/p4runtime_lib/bmv2.py +++ b/utils/p4runtime_lib/bmv2.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .switch import SwitchConnection from p4.tmp import p4config_pb2 +from .switch import SwitchConnection + def buildDeviceConfig(bmv2_json_file_path=None): "Builds the device config for BMv2" diff --git a/utils/p4runtime_lib/convert.py b/utils/p4runtime_lib/convert.py index 50d6a5d84..671b9107c 100644 --- a/utils/p4runtime_lib/convert.py +++ b/utils/p4runtime_lib/convert.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import math import re import socket -import math - ''' This package contains several helper functions for encoding to and decoding from byte strings: - integers diff --git a/utils/p4runtime_lib/error_utils.py b/utils/p4runtime_lib/error_utils.py index 532ca32a1..c3818d076 100644 --- a/utils/p4runtime_lib/error_utils.py +++ b/utils/p4runtime_lib/error_utils.py @@ -15,10 +15,10 @@ import sys -from google.rpc import status_pb2, code_pb2 import grpc +from google.rpc import code_pb2, status_pb2 from p4.v1 import p4runtime_pb2 -from p4.v1 import p4runtime_pb2_grpc + # Used to indicate that the gRPC error Status object returned by the server has # an incorrect format. diff --git a/utils/p4runtime_lib/helper.py b/utils/p4runtime_lib/helper.py index e05688a98..c57e0de29 100644 --- a/utils/p4runtime_lib/helper.py +++ b/utils/p4runtime_lib/helper.py @@ -15,11 +15,12 @@ import re import google.protobuf.text_format -from p4.v1 import p4runtime_pb2 from p4.config.v1 import p4info_pb2 +from p4.v1 import p4runtime_pb2 from .convert import encode + class P4InfoHelper(object): def __init__(self, p4_info_filepath): p4info = p4info_pb2.P4Info() diff --git a/utils/p4runtime_lib/simple_controller.py b/utils/p4runtime_lib/simple_controller.py index ffce5c1ef..61cd61010 100755 --- a/utils/p4runtime_lib/simple_controller.py +++ b/utils/p4runtime_lib/simple_controller.py @@ -19,11 +19,10 @@ import os import sys -from . import bmv2 -from . import helper - from p4.config.v1 import p4info_pb2 +from . import bmv2, helper + def error(msg): print(' - ERROR! ' + msg, file=sys.stderr) diff --git a/utils/p4runtime_lib/switch.py b/utils/p4runtime_lib/switch.py index 0c171a5f9..d02fee885 100644 --- a/utils/p4runtime_lib/switch.py +++ b/utils/p4runtime_lib/switch.py @@ -12,14 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from queue import Queue from abc import abstractmethod from datetime import datetime +from queue import Queue import grpc -from p4.v1 import p4runtime_pb2 -from p4.v1 import p4runtime_pb2_grpc from p4.tmp import p4config_pb2 +from p4.v1 import p4runtime_pb2, p4runtime_pb2_grpc MSG_LOG_MAX_LEN = 1024 diff --git a/utils/p4runtime_switch.py b/utils/p4runtime_switch.py index 31d735f6c..7c46c8866 100644 --- a/utils/p4runtime_switch.py +++ b/utils/p4runtime_switch.py @@ -14,15 +14,16 @@ # limitations under the License. # -import sys, os, tempfile, socket +import os +import tempfile from time import sleep -from mininet.node import Switch +from mininet.log import debug, error, info from mininet.moduledeps import pathCheck -from mininet.log import info, error, debug - -from p4_mininet import P4Switch, SWITCH_START_TIMEOUT +from mininet.node import Switch from netstat import check_listening_on_port +from p4_mininet import SWITCH_START_TIMEOUT, P4Switch + class P4RuntimeSwitch(P4Switch): "BMv2 switch with gRPC support" diff --git a/utils/run_exercise.py b/utils/run_exercise.py index 42886d6f2..44c8ff62c 100755 --- a/utils/run_exercise.py +++ b/utils/run_exercise.py @@ -19,18 +19,20 @@ # We encourage you to dissect this script to better understand the BMv2/Mininet # environment used by the P4 tutorial. # -import os, sys, json, subprocess, re, argparse +import argparse +import json +import os +import subprocess from time import sleep -from p4_mininet import P4Switch, P4Host - +import p4runtime_lib.simple_controller +from mininet.cli import CLI +from mininet.link import TCLink from mininet.net import Mininet from mininet.topo import Topo -from mininet.link import TCLink -from mininet.cli import CLI - +from p4_mininet import P4Host, P4Switch from p4runtime_switch import P4RuntimeSwitch -import p4runtime_lib.simple_controller + def configureP4Switch(**switch_args): """ Helper class that is called by mininet to initialize