Commit ac65fec7 authored by StevenWdV's avatar StevenWdV

Add project files.

parent 6b39923b
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>4a25d660-d6ae-48ba-bb8c-606d64c90d2e</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>
</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<Name>Networks bTCP</Name>
<RootNamespace>Networks bTCP</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="bTCP_client.py" />
<Compile Include="bTCP_server.py" />
<Compile Include="testframework.py" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in
the BeforeBuild and AfterBuild targets below. -->
<!--<Target Name="CoreCompile" />-->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
</Project>
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Networks bTCP", "Networks bTCP.pyproj", "{4A25D660-D6AE-48BA-BB8C-606D64C90D2E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4A25D660-D6AE-48BA-BB8C-606D64C90D2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A25D660-D6AE-48BA-BB8C-606D64C90D2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {735E1ABE-B80E-43A1-9B46-6145CF96DAB4}
EndGlobalSection
EndGlobal
#!/usr/local/bin/python3
import socket, argparse, random
from struct import *
#Handle arguments
parser = argparse.ArgumentParser()
parser.add_argument("-w", "--window", help="Define bTCP window size", type=int, default=100)
parser.add_argument("-t", "--timeout", help="Define bTCP timeout in milliseconds", type=int, default=100)
parser.add_argument("-i","--input", help="File to send", default="tmp.file")
args = parser.parse_args()
destination_ip = "127.0.0.1"
destination_port = 9001
#bTCP header
header_format = "I"
bTCP_header = pack(header_format, randint(0,100))
bTCP_payload = ""
udp_payload = bTCP_header
#UDP socket which will transport your bTCP packets
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#send payload
sock.sendto(udp_payload, (destination_ip, destination_port))
#!/usr/local/bin/python3
import socket, argparse
from struct import *
#Handle arguments
parser = argparse.ArgumentParser()
parser.add_argument("-w", "--window", help="Define bTCP window size", type=int, default=100)
parser.add_argument("-t", "--timeout", help="Define bTCP timeout in milliseconds", type=int, default=100)
parser.add_argument("-o","--output", help="Where to store file", default="tmp.file")
args = parser.parse_args()
server_ip = "127.0.0.1"
server_port = 9001
#Define a header format
header_format = "I"
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((server_ip, server_port))
while True:
data, addr = sock.recvfrom(1016)
print(unpack(header_format,data))
import unittest
import socket
import time
import sys
timeout=100
winsize=100
intf="lo"
netem_add="sudo tc qdisc add dev {} root netem".format(intf)
netem_change="sudo tc qdisc change dev {} root netem {}".format(intf,"{}")
netem_del="sudo tc qdisc del dev {} root netem".format(intf)
"""run command and retrieve output"""
def run_command_with_output(command, input=None, cwd=None, shell=True):
import subprocess
try:
process = subprocess.Popen(command, cwd=cwd, shell=shell, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
except Exception as inst:
print("problem running command : \n ", str(command))
[stdoutdata, stderrdata]=process.communicate(input) # no pipes set for stdin/stdout/stdout streams so does effectively only just wait for process ends (same as process.wait()
if process.returncode:
print(stderrdata)
print("problem running command : \n ", str(command), " ",process.returncode)
return stdoutdata
"""run command with no output piping"""
def run_command(command,cwd=None, shell=True):
import subprocess
process = None
try:
process = subprocess.Popen(command, shell=shell, cwd=cwd)
print(str(process))
except Exception as inst:
print("1. problem running command : \n ", str(command), "\n problem : ", str(inst))
process.communicate() # wait for the process to end
if process.returncode:
print("2. problem running command : \n ", str(command), " ", process.returncode)
class TestbTCPFramework(unittest.TestCase):
"""Test cases for bTCP"""
def setUp(self):
"""Prepare for testing"""
# default netem rule (does nothing)
run_command(netem_add)
# launch localhost server
def tearDown(self):
"""Clean up after testing"""
# clean the environment
run_command(netem_del)
# close server
def test_ideal_network(self):
"""reliability over an ideal framework"""
# setup environment (nothing to set)
# launch localhost client connecting to server
# client sends content to server
# server receives content from client
# content received by server matches the content sent by client
def test_flipping_network(self):
"""reliability over network with bit flips
(which sometimes results in lower layer packet loss)"""
# setup environment
run_command(netem_change.format("corrupt 1%"))
# launch localhost client connecting to server
# client sends content to server
# server receives content from client
# content received by server matches the content sent by client
def test_duplicates_network(self):
"""reliability over network with duplicate packets"""
# setup environment
run_command(netem_change.format("duplicate 10%"))
# launch localhost client connecting to server
# client sends content to server
# server receives content from client
# content received by server matches the content sent by client
def test_lossy_network(self):
"""reliability over network with packet loss"""
# setup environment
run_command(netem_change.format("loss 10% 25%"))
# launch localhost client connecting to server
# client sends content to server
# server receives content from client
# content received by server matches the content sent by client
def test_reordering_network(self):
"""reliability over network with packet reordering"""
# setup environment
run_command(netem_change.format("delay 20ms reorder 25% 50%"))
# launch localhost client connecting to server
# client sends content to server
# server receives content from client
# content received by server matches the content sent by client
def test_delayed_network(self):
"""reliability over network with delay relative to the timeout value"""
# setup environment
run_command(netem_change.format("delay "+str(timeout)+"ms 20ms"))
# launch localhost client connecting to server
# client sends content to server
# server receives content from client
# content received by server matches the content sent by client
def test_allbad_network(self):
"""reliability over network with all of the above problems"""
# setup environment
run_command(netem_change.format("corrupt 1% duplicate 10% loss 10% 25% delay 20ms reorder 25% 50%"))
# launch localhost client connecting to server
# client sends content to server
# server receives content from client
# content received by server matches the content sent by client
# def test_command(self):
# #command=['dir','.']
# out = run_command_with_output("dir .")
# print(out)
if __name__ == "__main__":
# Parse command line arguments
import argparse
parser = argparse.ArgumentParser(description="bTCP tests")
parser.add_argument("-w", "--window", help="Define bTCP window size used", type=int, default=100)
parser.add_argument("-t", "--timeout", help="Define the timeout value used (ms)", type=int, default=timeout)
args, extra = parser.parse_known_args()
timeout = args.timeout
winsize = args.window
# Pass the extra arguments to unittest
sys.argv[1:] = extra
# Start test suite
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment