Add net centric

This commit is contained in:
Isaac Shoebottom 2024-02-26 07:23:13 -04:00
parent 82228b3704
commit ee9a752d7f

105
netcentric.py Normal file
View File

@ -0,0 +1,105 @@
# Calculate internet checksum for any arbitrary length variable amount of binary numbers
def checksum(*args):
length = len(bin(args[0])) - 2
result = 0
for arg in args:
result += arg
if result > (2 ** length) - 1:
result = (result & ((2 ** length) - 1)) + 1
return result ^ ((2 ** length) - 1)
def e2e_delay(P, L, N, R):
# P = propagation speed
# L = packet length
# N = number of packets
# R = transmission rate
return (P - 1) * (L / R) + N * (L / R)
def estimate_e2e_delay(PS, T):
# PS = packet size
# T = Throughput
return PS / T
def trans_delay(L, R):
# L = packet length
# R = transmission rate
return L / R
def prop_delay(P, L):
# P = propagation speed
# L = packet length
return P * L
def traffic_intensity(L, pps, R):
# L = packet length
# pps = packets per second
# R = transmission rate
return (L * pps) / R
def cs_time(N, F, U):
# N = Number of copies
# F = File size
# U = Server upload rate
return (N * F) / U
def cs_time_n_clients(N, F, U, D):
# N = Number of copies
# F = File size
# U = Server upload rate
# D = Client download rate
return max(cs_time(N, F, U), F / D)
def p2p_time(N, F, U, CD, D):
# N = Number of copies
# F = File size
# U = Server upload rate
# CU = Client upload rate
# D = Client download rate
return max((F / U), (N * F) / (U + (N * CD)), F / D)
def utilisation(L, R, RTT):
# L = packet length
# R = transmission rate
# RTT = round trip time
return (L / R) / (L / R + RTT)
def utilisation_pipeline(L, R, RTT, N):
# L = packet length
# R = transmission rate
# RTT = round trip time
# N = window size
return N / (1 + (RTT / (L / R)))
def print_byte_tables():
print("Byte Conversion Table")
print("1 B = 8 bits")
print("kB = 1024 bytes")
print("MB = 1024 kB")
print("GB = 1024 MB")
print("TB = 1024 GB")
def man():
print("checksum(0b, 0b,)")
print("e2e_delay(P, L, N, R)")
print("estimate_e2e_delay(PS, T)")
print("trans_delay(L, R)")
print("prop_delay(P, L)")
print("traffic_intensity(L, pps, R)")
print("cs_time(N, F, U)")
print("cs_time_n_clients(N, F, U, D)")
print("p2p_time(N, F, U, CD, D)")
print("utilisation(L, R, RTT)")
print("utilisation_pipeline(L, R, RTT, N)")
print("print_byte_tables()")