Skip to content

Commit

Permalink
williamquintas#35: Evaluate data traffic periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
williamquintas committed Jun 30, 2022
1 parent b082ab4 commit c2d4a30
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions mininet_integration/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def create_topology() -> Mininet_wifi:

print("*** Start vehicles periodic functions\n")
os.system("mkdir {}/downloaded_files".format(PATH))
vehicle1.cmd("python vehicles_periodic_function.py &")
vehicle2.cmd("python vehicles_periodic_function.py &")
vehicle1.cmd("python vehicles_periodic_function.py vehicle1 &")
vehicle2.cmd("python vehicles_periodic_function.py vehicle2 &")

return net

Expand Down
33 changes: 29 additions & 4 deletions mininet_integration/vehicles_periodic_function.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os, random, threading

import os, random, sys, threading
from utils.constants import FILES_SIZES
from subprocess import Popen, PIPE

WAIT_SECONDS = 1
SERVER_ADDRESS = "10.0.0.3"
PATH = os.path.dirname(os.path.abspath(__file__))

def should_get_file():
return random.random() >= 0.5
return random.random() >= 0.9


def get_file():
if should_get_file():
Expand All @@ -22,5 +23,29 @@ def get_file():

threading.Timer(WAIT_SECONDS, get_file).start()


def build_command(interface: str, grep: str, field_position: int) -> str:
return 'ifconfig {} | grep "{}" | cut -d":" -f{} | cut -d" " -f1'.format(interface, grep, field_position)


def read_rx(interface: str) -> int:
command = build_command(interface, "RX bytes", 2)
rx = Popen(command, shell=True, stdout=PIPE).stdout.read()
return int(rx)


def read_tx(interface: str) -> int:
command = build_command(interface, "TX bytes", 3)
tx = Popen(command, shell=True, stdout=PIPE).stdout.read()
return int(tx)


def measure_rx_tx():
interface = "{}-wlan0".format(sys.argv[1])
print(interface, read_rx(interface), read_tx(interface))
threading.Timer(WAIT_SECONDS, measure_rx_tx).start()


if __name__ == '__main__':
get_file()
get_file()
measure_rx_tx()

0 comments on commit c2d4a30

Please sign in to comment.