Porting PicoTCP WIP
This commit is contained in:
36
kernel/picotcp/test/python/dhcp.py
Executable file
36
kernel/picotcp/test/python/dhcp.py
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/python
|
||||
# dhcp.py
|
||||
# Butterfly-like topology test for dhcp
|
||||
# One DHCP server, serving on two interface
|
||||
# Eigth DHCP clients, four on each network
|
||||
#
|
||||
# s1----@ @----r1
|
||||
# s2-----\__ DHCP __/-----r2
|
||||
# s3-----/ \-----r3
|
||||
# s4----@ @----r4
|
||||
#
|
||||
|
||||
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt1")
|
||||
net2 = Network(T, "pyt2")
|
||||
|
||||
server = Host(T, net1, net2, args="dhcpserver:eth1:172.16.1.2:255.255.255.0:64:128:eth2:172.16.2.2:255.255.255.0:64:128")
|
||||
|
||||
s1 = Host(T, net1, args="dhcpclient:eth1")
|
||||
s2 = Host(T, net1, args="dhcpclient:eth1")
|
||||
s3 = Host(T, net1, args="dhcpclient:eth1")
|
||||
s4 = Host(T, net1, args="dhcpclient:eth1")
|
||||
r1 = Host(T, net2, args="dhcpclient:eth1")
|
||||
r2 = Host(T, net2, args="dhcpclient:eth1")
|
||||
r3 = Host(T, net2, args="dhcpclient:eth1")
|
||||
r4 = Host(T, net2, args="dhcpclient:eth1")
|
||||
|
||||
raw_input("Press enter to continue ...")
|
||||
start(T)
|
||||
|
||||
wait(server)
|
||||
|
||||
cleanup()
|
||||
48
kernel/picotcp/test/python/fairness.py
Executable file
48
kernel/picotcp/test/python/fairness.py
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/python
|
||||
# fairness.py
|
||||
# A complex test for butterly-like topology,
|
||||
# using 3 TCP connections and 3 ping flows.
|
||||
#
|
||||
# s1---. .---r1
|
||||
# s2----\ /
|
||||
# s3-----\__.R1---R2.__/__.--r2
|
||||
# s4-----/ \
|
||||
# s5----/ \_.--r3
|
||||
# s6---^
|
||||
#
|
||||
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T)
|
||||
net2 = Network(T)
|
||||
net3 = Network(T)
|
||||
|
||||
#router1 = Host(T, net1, net2, "natbox:172.16.2.1:")
|
||||
#router2 = Host(T, net2, net3, "natbox:172.16.3.1:")
|
||||
router1 = Host(T, net1, net2)
|
||||
router2 = Host(T, net2, net3)
|
||||
|
||||
send1 = Host(T, net1, args="tcpbench:t:172.16.3.2:")
|
||||
send2 = Host(T, net1, args="tcpbench:t:172.16.3.3:")
|
||||
send3 = Host(T, net1, args="tcpbench:t:172.16.3.4:")
|
||||
|
||||
send4 = Host(T, net1, args="ping:172.16.3.2:")
|
||||
send5 = Host(T, net1, args="ping:172.16.3.3:")
|
||||
send6 = Host(T, net1, args="ping:172.16.3.4:")
|
||||
|
||||
|
||||
recv1 = Host(T, net3, args="tcpbench:r:")
|
||||
recv2 = Host(T, net3, args="tcpbench:r:")
|
||||
recv3 = Host(T, net3, args="tcpbench:r:")
|
||||
recv4 = Host(T, net3, args="tcpbench:r:")
|
||||
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
|
||||
wait(send1)
|
||||
wait(send2)
|
||||
wait(send3)
|
||||
|
||||
cleanup()
|
||||
47
kernel/picotcp/test/python/fairness_bottleneck.py
Executable file
47
kernel/picotcp/test/python/fairness_bottleneck.py
Executable file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/python
|
||||
# fairness.py
|
||||
# A complex test for butterly-like topology,
|
||||
# using 3 TCP connections and 3 ping flows.
|
||||
#
|
||||
# Bottleneck of 4 Mbit/300 ms overall delay is added.
|
||||
#
|
||||
# s1---. .---r1
|
||||
# s2----\ /
|
||||
# s3-----\__.R1---R2.__/__.--r2
|
||||
# s4-----/ \
|
||||
# s5----/ \_.--r3
|
||||
# s6---^
|
||||
#
|
||||
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T)
|
||||
net2 = Network(T)
|
||||
net3 = Network(T)
|
||||
|
||||
router1 = Host(T, net1, net2, delay2="150", bw2="20M")
|
||||
router2 = Host(T, net2, net3)
|
||||
|
||||
send1 = Host(T, net1, args="tcpbench:t:172.16.3.2:")
|
||||
send2 = Host(T, net1, args="tcpbench:t:172.16.3.3:")
|
||||
send3 = Host(T, net1, args="tcpbench:t:172.16.3.4:")
|
||||
|
||||
send4 = Host(T, net1, args="ping:172.16.3.2:")
|
||||
send5 = Host(T, net1, args="ping:172.16.3.3:")
|
||||
send6 = Host(T, net1, args="ping:172.16.3.4:")
|
||||
|
||||
|
||||
recv1 = Host(T, net3, args="tcpbench:r:")
|
||||
recv2 = Host(T, net3, args="tcpbench:r:")
|
||||
recv3 = Host(T, net3, args="tcpbench:r:")
|
||||
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
|
||||
wait(send1)
|
||||
wait(send2)
|
||||
wait(send3)
|
||||
|
||||
cleanup()
|
||||
47
kernel/picotcp/test/python/fairness_bottleneck_linux.py
Executable file
47
kernel/picotcp/test/python/fairness_bottleneck_linux.py
Executable file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/python
|
||||
# fairness.py
|
||||
# A complex test for butterly-like topology,
|
||||
# using 3 TCP connections and 3 ping flows.
|
||||
#
|
||||
# Bottleneck of 4 Mbit/300 ms overall delay is added.
|
||||
#
|
||||
# s1---. .---r1
|
||||
# s2----\ /
|
||||
# s3-----\__.R1---R2.__/__.--r2
|
||||
# s4-----/ \
|
||||
# s5----/ \_.--r3
|
||||
# s6---^
|
||||
#
|
||||
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T)
|
||||
net2 = Network(T, "pyt0")
|
||||
net3 = Network(T)
|
||||
|
||||
router1 = Host(T, net1, net2, delay2="150", bw2="4M")
|
||||
router2 = Host(T, net2, net3)
|
||||
|
||||
send1 = Host(T, net1, args="tcpbench:t:172.16.3.2:")
|
||||
send2 = Host(T, net1, args="tcpbench:t:172.16.3.3:")
|
||||
send3 = Host(T, net1, args="tcpbench:t:172.16.3.4:")
|
||||
|
||||
send4 = Host(T, net1, args="ping:172.16.3.2:")
|
||||
send5 = Host(T, net1, args="ping:172.16.3.3:")
|
||||
send6 = Host(T, net1, args="ping:172.16.3.4:")
|
||||
|
||||
|
||||
recv1 = Host(T, net3, args="tcpbench:r:")
|
||||
recv2 = Host(T, net3, args="tcpbench:r:")
|
||||
recv3 = Host(T, net3, args="tcpbench:r:")
|
||||
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
|
||||
wait(send1)
|
||||
wait(send2)
|
||||
wait(send3)
|
||||
|
||||
cleanup()
|
||||
60
kernel/picotcp/test/python/fragmentation.py
Executable file
60
kernel/picotcp/test/python/fragmentation.py
Executable file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# fragmentation.py
|
||||
#
|
||||
# Fragmentation test with PicoTCP sending and Linux receiving
|
||||
#
|
||||
# (sender) (Receiver)
|
||||
# PicoTCP ------------------------ Linux
|
||||
#
|
||||
# An udpclient is started which will give DATASIZE bytes in one go
|
||||
# to the socket. This data will be fragmented and send over to the
|
||||
# Linux, where it is reassembled and received in one piece.
|
||||
#
|
||||
|
||||
from topology import *
|
||||
import socket, random, string
|
||||
|
||||
SRC_ADDR = ''
|
||||
DST_ADDR = '172.16.1.1'
|
||||
SRC_PORT = 6667
|
||||
SENDTO_PORT = 6667
|
||||
LISTEN_PORT = 6667
|
||||
DATASIZE = 4000
|
||||
LOOPS = 4
|
||||
SUBLOOPS = 1
|
||||
UDPCLIENT = "udpclient:" + str(DST_ADDR) + ":" + str(SENDTO_PORT) + ":" + str(LISTEN_PORT) + ":" + str(DATASIZE) + ":" + str(LOOPS) + ":" + str(SUBLOOPS)
|
||||
|
||||
print UDPCLIENT
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
h1 = Host(T, net1, args=UDPCLIENT)
|
||||
|
||||
s_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s_udp.bind((SRC_ADDR, SRC_PORT))
|
||||
s_udp.settimeout(5);
|
||||
|
||||
raw_input("Press enter to continue ...")
|
||||
start(T)
|
||||
|
||||
while True:
|
||||
data, addr = s_udp.recvfrom(DATASIZE)
|
||||
#print data
|
||||
if len(data) == DATASIZE:
|
||||
print '\n\n'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '+++++ fragmentation test IS successful +++++'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '\n\n'
|
||||
cleanup()
|
||||
exit(0)
|
||||
|
||||
print '\n\n'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '+++++ fragmentation test NOT successful ++++'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '\n\n'
|
||||
cleanup()
|
||||
exit(1)
|
||||
|
||||
135
kernel/picotcp/test/python/howto.py
Normal file
135
kernel/picotcp/test/python/howto.py
Normal file
@ -0,0 +1,135 @@
|
||||
#PicoTCP topology test environment.
|
||||
#Guidelines to prepare test scenarios.
|
||||
#
|
||||
#The interface is simple, it has three objects:
|
||||
# * Topology
|
||||
# * Network
|
||||
# * Host
|
||||
#
|
||||
#And a handful of helping routines, such as:
|
||||
# * start()
|
||||
# * loop()
|
||||
# * sleep()
|
||||
# * wait()
|
||||
#
|
||||
#
|
||||
########################################################################
|
||||
#== Create a test scenario ==#
|
||||
########################################################################
|
||||
# Every script file will start with: "#!/usr/bin/python" in the first
|
||||
# line, and will have execution permissions. This script is an exception
|
||||
# because it is not intended to be run, as it is in fact a walkthrough to
|
||||
# all the functionalities.
|
||||
|
||||
# Importing the topology objects is mandatory, so add:
|
||||
from topology import *
|
||||
|
||||
# A Topology must be created to use all other objects:
|
||||
T = Topology()
|
||||
|
||||
# Now, we can create "Network" objects. The networks will have address
|
||||
# 172.16.X.0/24, where 'X' is the order of creation, starting from 1.
|
||||
#
|
||||
|
||||
network1 = Network(T)
|
||||
network2 = Network(T)
|
||||
# The two networks are separated and using different address pools:
|
||||
#
|
||||
# ## ### ## ## ## ### ## ##
|
||||
# # network1 # # network2 #
|
||||
# # 172.16.1.0 # # 172.16.2.0 #
|
||||
# ## ## ###### ## ## ######
|
||||
#
|
||||
|
||||
# If you are running your test as root, you can also add a tun-tap connection
|
||||
# to the network, which will be automatically configured:
|
||||
networkLocal = Network(T,'tap0')
|
||||
|
||||
|
||||
# In the same way ad networks, you can create a PicoTCP Host that connects to a
|
||||
# network as follows:
|
||||
host1_1 = Host(T, network1)
|
||||
|
||||
# Also, you can specify a role for the application/host, by using picoapp's
|
||||
# args format for '--app'. For example, the machine below will ping the previously
|
||||
# created one:
|
||||
host1_2 = Host(T, network1, args ="ping:172.16.1.1:")
|
||||
#
|
||||
# ## ### ## ## ## ### ## ##
|
||||
# host1.1--# network1 # # network2 #
|
||||
# # 172.16.1.0 # # 172.16.2.0 #
|
||||
# ## ## ###### ## ## ######
|
||||
# /
|
||||
# host1.2___/
|
||||
# (ping host1.1)
|
||||
#
|
||||
|
||||
# At this point, a picoTCP host with two network cards can connect
|
||||
# the two networks like this:
|
||||
router1 = Host(T, network1, network2)
|
||||
#
|
||||
# ## ### ## ## router1 ## ### ## ##
|
||||
# host1.1--# network1 #__/ \__ # network2 #
|
||||
# # 172.16.1.0 # # 172.16.2.0 #
|
||||
# ## ## ###### ## ## ######
|
||||
# /
|
||||
# host1.2___/
|
||||
# (ping host1.1)
|
||||
|
||||
# Now, we can attach an host to the second network too:
|
||||
# Connection to the host can be an emulated channel, i.e.
|
||||
# it is possible to add bidirectional delay and limited
|
||||
# bandwidth in the link between the host and the network:
|
||||
#
|
||||
|
||||
host2_2 = Host(network2, delay1="100", bw1="500K")
|
||||
#
|
||||
# ## ### ## ## router1 ## ### ## ##
|
||||
# host1.1--# network1 #__/ \__ # network2 #
|
||||
# # 172.16.1.0 # # 172.16.2.0 #
|
||||
# ## ## ###### ## ## ######
|
||||
# / *
|
||||
# host1.2.__/ \._*_*_host2.2
|
||||
# (ping host1.1)
|
||||
|
||||
## Since the routes will be automatically added before the test starts,
|
||||
# all the hosts in the networks will be reachable to each other:
|
||||
# all the picoapps will have their static routes populated automatically
|
||||
# by the topology tool, no matter how complex the network is. The only
|
||||
# requirement is that all the networks share at least one router.
|
||||
#
|
||||
# For this reason, we can create a host that pings across the network:
|
||||
host1_4 = Host(T, network1, args="ping:172.16.2.2:")
|
||||
#
|
||||
# host1.4.
|
||||
# (ping 2.2) \
|
||||
# \## ### ## ## router1 ## ### ## ##
|
||||
# host1.1--# network1 #__/ \__ # network2 #
|
||||
# # 172.16.1.0 # # 172.16.2.0 #
|
||||
# ## ## ###### ## ## ######
|
||||
# / *
|
||||
# host1.2.__/ \._*_*_host2.2
|
||||
# (ping host1.1)
|
||||
|
||||
########################################################################
|
||||
#== Start the test ==#
|
||||
########################################################################
|
||||
# All the host will be connected and activated when you call:
|
||||
start()
|
||||
|
||||
# At this point you may want to define your exit strategy. Valid commands
|
||||
# are:
|
||||
|
||||
loop() # Loop forever, until the test is interrupted (e.g. by ctrl+c)
|
||||
|
||||
sleep(N) # Sleep N seconds
|
||||
|
||||
wait(host1_4) # Wait for application running on host 1.4, and return only if
|
||||
# it has terminated
|
||||
|
||||
|
||||
########################################################################
|
||||
#== End the test ==#
|
||||
########################################################################
|
||||
# Always call:
|
||||
cleanup()
|
||||
13
kernel/picotcp/test/python/http_server_linux.py
Executable file
13
kernel/picotcp/test/python/http_server_linux.py
Executable file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
|
||||
h2 = Host(T, net1, args="httpd")
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
|
||||
wait(h2)
|
||||
cleanup()
|
||||
64
kernel/picotcp/test/python/multicast_recv.py
Executable file
64
kernel/picotcp/test/python/multicast_recv.py
Executable file
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/python
|
||||
# multicast_recv.py
|
||||
#
|
||||
# Multicast test with PicoTCP receiving and Linux sending
|
||||
#
|
||||
# (sender) (Receiver)
|
||||
# Linux ------------------------ PicoTCP
|
||||
# mcast to 224.7.7.7
|
||||
#
|
||||
from topology import *
|
||||
import socket, random, string
|
||||
|
||||
IF_ADDR = '172.16.1.1'
|
||||
LINK_ADDR = '172.16.1.2'
|
||||
MCAST_ADDR = '224.7.7.7'
|
||||
SRC_PORT = 5555
|
||||
LISTEN_PORT = 6667
|
||||
SENDTO_PORT = 6667
|
||||
MCASTRECV = "mcastreceive:" + str(LINK_ADDR) + ":" + str(MCAST_ADDR) + ":" + str(LISTEN_PORT) + ":" + str(SENDTO_PORT)
|
||||
|
||||
print MCASTRECV
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
h1 = Host(T, net1, args=MCASTRECV)
|
||||
|
||||
# sending socket
|
||||
s_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s_udp.bind((IF_ADDR, SRC_PORT))
|
||||
s_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s_udp.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
|
||||
s_udp.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(str(IF_ADDR)))
|
||||
|
||||
# receiving socket
|
||||
s_udp_recv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s_udp_recv.bind((IF_ADDR, LISTEN_PORT))
|
||||
s_udp_recv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s_udp_recv.settimeout(5);
|
||||
|
||||
raw_input("Press enter to continue ...")
|
||||
start(T)
|
||||
sleep(1)
|
||||
|
||||
while True:
|
||||
s_udp.sendto("multicast test succeeded", (str(MCAST_ADDR), LISTEN_PORT))
|
||||
data = s_udp_recv.recv(4096)
|
||||
#print data
|
||||
if 'succeeded' in data:
|
||||
print '\n\n'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '+++++ multicast_recv test IS successful +++++'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '\n\n'
|
||||
cleanup()
|
||||
exit(0)
|
||||
|
||||
print '\n\n'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '+++++ multicast_recv test NOT successful ++++'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '\n\n'
|
||||
cleanup()
|
||||
exit(1)
|
||||
|
||||
58
kernel/picotcp/test/python/multicast_send.py
Executable file
58
kernel/picotcp/test/python/multicast_send.py
Executable file
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# multicast_send.py
|
||||
#
|
||||
# Multicast test with PicoTCP sending and Linux receiving
|
||||
#
|
||||
# (sender) (Receiver)
|
||||
# PicoTCP ------------------------ Linux
|
||||
# mcast to 224.7.7.7
|
||||
#
|
||||
|
||||
from topology import *
|
||||
import socket, random, string, struct
|
||||
|
||||
IF_ADDR = '172.16.1.1'
|
||||
LINK_ADDR = '172.16.1.2'
|
||||
MCAST_ADDR = '224.7.7.7'
|
||||
LISTEN_PORT = 6667
|
||||
SENDTO_PORT = 6667
|
||||
MCASTSEND = "mcastsend:" + str(LINK_ADDR) + ":" + str(MCAST_ADDR) + ":" + str(SENDTO_PORT) + ":" + str(LISTEN_PORT)
|
||||
|
||||
print MCASTSEND
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
h1 = Host(T, net1, args=MCASTSEND)
|
||||
|
||||
s_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s_udp.bind((MCAST_ADDR, LISTEN_PORT))
|
||||
s_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s_udp.settimeout(5);
|
||||
|
||||
mreq = struct.pack("=4s4s", socket.inet_aton(str(MCAST_ADDR)), socket.inet_aton(str(IF_ADDR)))
|
||||
s_udp.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
|
||||
|
||||
raw_input("Press enter to continue ...")
|
||||
start(T)
|
||||
sleep(1)
|
||||
|
||||
while True:
|
||||
data = s_udp.recv(4096)
|
||||
#print data
|
||||
if 'end' in data:
|
||||
print '\n\n'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '+++++ multicast_send test IS successful +++++'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '\n\n'
|
||||
cleanup()
|
||||
exit(0)
|
||||
|
||||
print '\n\n'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '+++++ multicast_send test NOT successful ++++'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '\n\n'
|
||||
cleanup()
|
||||
exit(1)
|
||||
14
kernel/picotcp/test/python/noop.py
Executable file
14
kernel/picotcp/test/python/noop.py
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
|
||||
#h1 = Host(T, net1)
|
||||
h2 = Host(T, net1, args="noop")
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
|
||||
wait(h2)
|
||||
cleanup()
|
||||
14
kernel/picotcp/test/python/ping.py
Executable file
14
kernel/picotcp/test/python/ping.py
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T)
|
||||
|
||||
h1 = Host(T, net1)
|
||||
h2 = Host(T, net1, args="ping:172.16.1.1:")
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
|
||||
wait(h2)
|
||||
cleanup()
|
||||
14
kernel/picotcp/test/python/ping_delay.py
Executable file
14
kernel/picotcp/test/python/ping_delay.py
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T)
|
||||
|
||||
h1 = Host(T, net1, delay1="200")
|
||||
h2 = Host(T, net1, args="ping:172.16.1.1:")
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
|
||||
wait(h2)
|
||||
cleanup()
|
||||
14
kernel/picotcp/test/python/ping_linux.py
Executable file
14
kernel/picotcp/test/python/ping_linux.py
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
|
||||
#h1 = Host(T, net1)
|
||||
h2 = Host(T, net1, args="ping:172.16.1.1:")
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
|
||||
wait(h2)
|
||||
cleanup()
|
||||
17
kernel/picotcp/test/python/ping_nat.py
Executable file
17
kernel/picotcp/test/python/ping_nat.py
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, 'nat0')
|
||||
net2 = Network(T)
|
||||
|
||||
|
||||
h1 = Host(T, net1, args="ping:172.16.2.1:")
|
||||
h2 = Host(T, net2)
|
||||
router1 = Host(T, net1, net2, args="natbox:172.16.2.2:")
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
|
||||
wait(h1)
|
||||
cleanup()
|
||||
62
kernel/picotcp/test/python/reassembly.py
Executable file
62
kernel/picotcp/test/python/reassembly.py
Executable file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# reassemby.py
|
||||
#
|
||||
# Reassemly test with PicoTCP receiving and Linux sending
|
||||
#
|
||||
# (receiver) (Sender)
|
||||
# PicoTCP ------------------------ Linux
|
||||
#
|
||||
# An udpecho is started which will receive DATASIZE bytes in one go
|
||||
# from the socket. The Linux will send DATASIZE bytes in one go to the
|
||||
# udpecho, this data will be sent fragmented. The udpecho is to reassemble
|
||||
# this data and echo it back.
|
||||
#
|
||||
|
||||
from topology import *
|
||||
import socket, random, string
|
||||
|
||||
SRC_ADDR = ''
|
||||
LINK_ADDR = '172.16.1.2'
|
||||
SRC_PORT = 5555
|
||||
LISTEN_PORT = 6667
|
||||
SENDTO_PORT = 5555
|
||||
DATASIZE = 3400
|
||||
UDPECHO = "udpecho:" + str(LINK_ADDR) + ":" + str(LISTEN_PORT) + ":" + str(SENDTO_PORT) + ":" + str(DATASIZE)
|
||||
|
||||
print UDPECHO
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
h1 = Host(T, net1, args=UDPECHO)
|
||||
|
||||
str_send = ''.join(random.choice(string.ascii_lowercase) for x in range(DATASIZE))
|
||||
#print str_send
|
||||
s_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s_udp.bind((SRC_ADDR, SRC_PORT))
|
||||
s_udp.settimeout(5);
|
||||
|
||||
raw_input("Press enter to continue ...")
|
||||
start(T)
|
||||
|
||||
while True:
|
||||
s_udp.sendto(str_send, (LINK_ADDR, LISTEN_PORT))
|
||||
data = s_udp.recv(DATASIZE)
|
||||
#print len(data)
|
||||
if len(data) == DATASIZE:
|
||||
print '\n\n'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '+++++ reassembly test IS successful +++++'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '\n\n'
|
||||
cleanup()
|
||||
exit(0)
|
||||
|
||||
print '\n\n'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '+++++ reassembly test NOT successful ++++'
|
||||
print '+++++++++++++++++++++++++++++++++++++++++++++'
|
||||
print '\n\n'
|
||||
cleanup()
|
||||
exit(1)
|
||||
|
||||
18
kernel/picotcp/test/python/tcpbench-delay.py
Executable file
18
kernel/picotcp/test/python/tcpbench-delay.py
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "vde0")
|
||||
|
||||
send1 = Host(T, net1, args="tcpbench:t:172.16.1.3:7770:")
|
||||
recv1 = Host(T, net1, args="tcpbench:r:7770:", delay1="30", loss1="1")
|
||||
|
||||
|
||||
sleep(1)
|
||||
raw_input("Press enter to continue ...")
|
||||
|
||||
start(T)
|
||||
wait(send1)
|
||||
cleanup()
|
||||
17
kernel/picotcp/test/python/tcpbench-tap.py
Executable file
17
kernel/picotcp/test/python/tcpbench-tap.py
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
send1 = Host(T, net1, args="tcpbench:t:172.16.1.3:7770:")
|
||||
recv1 = Host(T, net1, args="tcpbench:r:7770:")
|
||||
|
||||
|
||||
sleep(1)
|
||||
raw_input("Press enter to continue ...")
|
||||
|
||||
start(T)
|
||||
wait(send1)
|
||||
cleanup()
|
||||
17
kernel/picotcp/test/python/tcpbench.py
Executable file
17
kernel/picotcp/test/python/tcpbench.py
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T)
|
||||
send1 = Host(T, net1, args="tcpbench:t:172.16.1.2:7770:")
|
||||
recv1 = Host(T, net1, args="tcpbench:r:7770:")
|
||||
|
||||
|
||||
sleep(1)
|
||||
#raw_input("Press enter to continue ...")
|
||||
|
||||
start(T)
|
||||
wait(send1)
|
||||
cleanup()
|
||||
14
kernel/picotcp/test/python/tcpbench_rx_linux.py
Executable file
14
kernel/picotcp/test/python/tcpbench_rx_linux.py
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
|
||||
h2 = Host(T, net1, args="tcpbench:r:6660:")
|
||||
|
||||
sleep(1)
|
||||
raw_input("Press enter to continue ...")
|
||||
start(T)
|
||||
|
||||
wait(h2)
|
||||
cleanup()
|
||||
15
kernel/picotcp/test/python/tcpbench_tx_linux.py
Executable file
15
kernel/picotcp/test/python/tcpbench_tx_linux.py
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
|
||||
#h1 = Host(T, net1)
|
||||
h3 = Host(T, net1, args="tcpbench:t:172.16.1.1:6660:")
|
||||
|
||||
sleep(1)
|
||||
raw_input("Press enter to continue ...")
|
||||
start(T)
|
||||
|
||||
wait(h3)
|
||||
cleanup()
|
||||
16
kernel/picotcp/test/python/tcpecho_linux.py
Executable file
16
kernel/picotcp/test/python/tcpecho_linux.py
Executable file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
|
||||
#h1 = Host(T, net1)
|
||||
h2 = Host(T, net1, args="tcpecho:8888", delay1="20", loss1="0.01")
|
||||
#h3 = Host(T, net1, args="tcpbench:t:172.16.1.1:")
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
|
||||
#wait(h3)
|
||||
wait(h2)
|
||||
cleanup()
|
||||
223
kernel/picotcp/test/python/topology.py
Executable file
223
kernel/picotcp/test/python/topology.py
Executable file
@ -0,0 +1,223 @@
|
||||
#!/usr/bin/python
|
||||
# Python classes definition for the picoTCP
|
||||
# topology test environment
|
||||
#
|
||||
# Copyright (c) 2013-2017 Altran Intelligent Systems. See LICENSE for usage.
|
||||
|
||||
import sys, os, subprocess, time, re
|
||||
|
||||
def test_tuntap():
|
||||
if not os.geteuid()==0:
|
||||
sys.exit("\nOnly root can use real devices contained in this script\n")
|
||||
|
||||
class Topology:
|
||||
def __init__(self):
|
||||
self.nets = []
|
||||
self.nodes = []
|
||||
self.nextn = 1
|
||||
self.hosts = []
|
||||
|
||||
|
||||
class Network:
|
||||
def __init__(self, topology, real=''):
|
||||
self.n = topology.nextn
|
||||
topology.nextn += 1
|
||||
self.nodes = []
|
||||
self.topology = topology
|
||||
self.topology.nets.append(self)
|
||||
self.sock = "/tmp/topology/net"+`self.n`
|
||||
self.nextn = 1
|
||||
vdecmd = ["vde_switch", "-x" , "-s", self.sock, "-m", self.sock+".mgmt"]
|
||||
if real != '':
|
||||
test_tuntap()
|
||||
vdecmd.append('-t')
|
||||
vdecmd.append(real)
|
||||
vdecmd.append('-x')
|
||||
self.pop = subprocess.Popen(vdecmd, stdin=subprocess.PIPE)
|
||||
self.hosts = []
|
||||
print ""
|
||||
print vdecmd
|
||||
print "Created network "+self.sock
|
||||
if real != '':
|
||||
subprocess.call(["ifconfig",real,"172.16."+`self.n`+".1", "netmask", "255.255.255.0", "up"])
|
||||
self.nextn = 2
|
||||
|
||||
class Node:
|
||||
def __init__(self,topology, network = None):
|
||||
if (network is None):
|
||||
network = Network(topology)
|
||||
self.net = network
|
||||
self.n = network.nextn
|
||||
network.nextn += 1
|
||||
self.net.nodes.append(self)
|
||||
self.topology = topology
|
||||
self.topology.nodes.append(self)
|
||||
|
||||
class Host:
|
||||
def add_routes(self, topology):
|
||||
for eth in [self.eth1, self.eth2]:
|
||||
if eth and not self.args.startswith("dhcpclient"):
|
||||
net = eth.net
|
||||
for h in topology.hosts:
|
||||
if h.eth1 and h.eth2:
|
||||
dst=""
|
||||
gw=""
|
||||
routing=False
|
||||
if (h.eth2.net.n == net.n) and (self not in h.eth1.net.hosts):
|
||||
if h.eth1.net.n > net.n or h.nat == False:
|
||||
print "FOUND route to net "+`h.eth1.net.n`
|
||||
dst_net = h.eth1.net.n
|
||||
gw_net = h.eth2.net.n
|
||||
gw_n = h.eth2.n
|
||||
routing=True
|
||||
elif (h.eth1.net.n == net.n) and (self not in h.eth2.net.hosts):
|
||||
if h.eth2.net.n > net.n or h.nat == False:
|
||||
print "FOUND route to net "+`h.eth2.net.n`
|
||||
dst_net = h.eth2.net.n
|
||||
gw_net = h.eth1.net.n
|
||||
gw_n = h.eth1.n
|
||||
routing=True
|
||||
|
||||
if (routing):
|
||||
dst = "172.16."+`dst_net`+".0"
|
||||
gw = "172.16."+`gw_net`+"."+`gw_n`
|
||||
self.routes.append("-r")
|
||||
self.routes.append(dst+":255.255.255.0:"+gw+":")
|
||||
if (routing and gw_net > dst_net and h.nat == False):
|
||||
dst_net -= 1
|
||||
while(dst_net > 0):
|
||||
dst = "172.16."+`dst_net`+".0"
|
||||
self.routes.append("-r")
|
||||
self.routes.append(dst+":255.255.255.0:"+gw+":")
|
||||
dst_net -= 1
|
||||
elif (routing and gw_net != None and gw_net < dst_net):
|
||||
dst_net += 1
|
||||
while(dst_net < net.topology.nextn):
|
||||
dst = "172.16."+`dst_net`+".0"
|
||||
self.routes.append("-r")
|
||||
self.routes.append(dst+":255.255.255.0:"+gw+":")
|
||||
dst_net += 1
|
||||
def parse_options(self, eth, delay, bw, loss):
|
||||
if (delay != "" or bw != ""):
|
||||
mysock = eth.net.sock + "__" + `eth.n`
|
||||
wirecmd = ['wirefilter', '-v']
|
||||
wirecmd.append(mysock +":" + eth.net.sock)
|
||||
if (delay != ''):
|
||||
wirecmd.append("-d")
|
||||
wirecmd.append(delay)
|
||||
if (bw != ''):
|
||||
wirecmd.append("-b")
|
||||
wirecmd.append(bw)
|
||||
if (loss != ''):
|
||||
wirecmd.append("-l")
|
||||
wirecmd.append(loss)
|
||||
print wirecmd
|
||||
subprocess.Popen(['vde_switch', '-s', mysock], stdin=subprocess.PIPE)
|
||||
subprocess.Popen(wirecmd, stdin=subprocess.PIPE)
|
||||
else:
|
||||
mysock = eth.net.sock
|
||||
return mysock
|
||||
|
||||
def __init__(self, topology, net1=None, net2=None, gw=None, args="tcpecho:5555", delay1="", bw1="", delay2="", bw2="", loss1="", loss2=""):
|
||||
if net1:
|
||||
self.eth1 = Node(topology, net1)
|
||||
net1.hosts.append(self)
|
||||
else:
|
||||
self.eth1 = None
|
||||
if net2:
|
||||
self.eth2 = Node(topology, net2)
|
||||
net2.hosts.append(self)
|
||||
else:
|
||||
self.eth2 = None
|
||||
self.cmd = ["./build/test/picoapp.elf"]
|
||||
self.gw = gw
|
||||
if args.startswith("nat"):
|
||||
self.nat = True
|
||||
else:
|
||||
self.nat = False
|
||||
|
||||
|
||||
if (net1):
|
||||
mysock = self.parse_options(self.eth1, delay1, bw1, loss1)
|
||||
if (args.startswith("dhcpclient")):
|
||||
self.cmd.append("--barevde")
|
||||
vdeline = "eth1:"+mysock+':'
|
||||
else:
|
||||
self.cmd.append("--vde")
|
||||
vdeline = "eth1:"+mysock+':'+"172.16."+`self.eth1.net.n`+"."+`self.eth1.n`+":255.255.255.0:"
|
||||
if (self.gw and re.search("172\.16\."+`self.eth1.net`, self.gw)):
|
||||
vdeline +=self.gw+":"
|
||||
self.cmd.append(vdeline)
|
||||
if (net2):
|
||||
mysock = self.parse_options(self.eth2, delay2, bw2, loss2)
|
||||
if (args.startswith("dhcpclient")):
|
||||
self.cmd.append("--barevde")
|
||||
vdeline = "eth2:"+mysock+':'
|
||||
else:
|
||||
self.cmd.append("--vde")
|
||||
vdeline = "eth2:"+mysock+':'+"172.16."+`self.eth2.net.n`+"."+`self.eth2.n`+":255.255.255.0:"
|
||||
if (self.gw and re.search("172\.16\."+`self.eth2.net`+".", self.gw)):
|
||||
vdeline +=self.gw+":"
|
||||
self.cmd.append(vdeline)
|
||||
self.args = args
|
||||
self.pop = None
|
||||
topology.hosts.append(self)
|
||||
self.routes = []
|
||||
|
||||
|
||||
def start(self):
|
||||
if self.pop:
|
||||
return
|
||||
for r in self.routes:
|
||||
self.cmd.append(r)
|
||||
self.cmd.append("-a")
|
||||
self.cmd.append(self.args)
|
||||
print self.cmd
|
||||
self.pop = subprocess.Popen(self.cmd)
|
||||
|
||||
|
||||
|
||||
def cleanup():
|
||||
try:
|
||||
subprocess.call(["killall","vde_switch"])
|
||||
subprocess.call(["killall","picoapp.elf"])
|
||||
subprocess.call(["killall","wirefilter"])
|
||||
os.unlink("/tmp/topology")
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def loop():
|
||||
while(True):
|
||||
time.sleep(1)
|
||||
sys.exit(0)
|
||||
|
||||
def sleep(n):
|
||||
time.sleep(n)
|
||||
|
||||
def wait(x):
|
||||
if (x is None):
|
||||
print("start failed: "+x.cmd)
|
||||
sys.exit(1)
|
||||
while (x.pop.poll() == None):
|
||||
time.sleep(1)
|
||||
print "Goodbye"
|
||||
sys.exit(0)
|
||||
|
||||
def start(T):
|
||||
print "Calculating routes.."
|
||||
for n in T.nets:
|
||||
for h in n.hosts:
|
||||
h.add_routes(T)
|
||||
print "Done!"
|
||||
print "Starting up..."
|
||||
for n in T.nets:
|
||||
for h in n.hosts:
|
||||
h.start()
|
||||
|
||||
try:
|
||||
os.mkdir("/tmp/topology/")
|
||||
except:
|
||||
pass
|
||||
cleanup()
|
||||
45
kernel/picotcp/test/python/traceroute_from_linux.py
Executable file
45
kernel/picotcp/test/python/traceroute_from_linux.py
Executable file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
'''
|
||||
Add route to 172.16.0.0/16 gw 172.16.1.2 on your host machine.
|
||||
|
||||
Should result in something like:
|
||||
~$ traceroute 172.16.8.2
|
||||
traceroute to 172.16.8.2 (172.16.8.2), 30 hops max, 60 byte packets
|
||||
1 172.16.1.2 (172.16.1.2) 0.481 ms 0.473 ms 0.467 ms
|
||||
2 172.16.2.2 (172.16.2.2) 4.680 ms 4.702 ms 4.700 ms
|
||||
3 172.16.3.2 (172.16.3.2) 8.759 ms 8.768 ms 8.766 ms
|
||||
4 172.16.4.2 (172.16.4.2) 10.791 ms 10.789 ms 10.786 ms
|
||||
5 172.16.5.2 (172.16.5.2) 12.826 ms 12.825 ms 12.821 ms
|
||||
6 172.16.6.2 (172.16.6.2) 14.844 ms 17.858 ms 17.857 ms
|
||||
7 172.16.7.2 (172.16.7.2) 17.858 ms 14.000 ms 13.999 ms
|
||||
8 172.16.8.2 (172.16.8.2) 18.032 ms 18.029 ms 18.023 ms
|
||||
|
||||
'''
|
||||
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, 'nat0')
|
||||
net2 = Network(T)
|
||||
net3 = Network(T)
|
||||
net4 = Network(T)
|
||||
net5 = Network(T)
|
||||
net6 = Network(T)
|
||||
net7 = Network(T)
|
||||
net8 = Network(T)
|
||||
|
||||
router1 = Host(T, net1, net2)
|
||||
router2 = Host(T, net2, net3)
|
||||
router3 = Host(T, net3, net4)
|
||||
router4 = Host(T, net4, net5)
|
||||
router5 = Host(T, net5, net6)
|
||||
router6 = Host(T, net6, net7)
|
||||
router7 = Host(T, net7, net8)
|
||||
|
||||
h1 = Host(T, net8)
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
loop()
|
||||
cleanup()
|
||||
45
kernel/picotcp/test/python/traceroute_nat_from_linux.py
Executable file
45
kernel/picotcp/test/python/traceroute_nat_from_linux.py
Executable file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
|
||||
'''
|
||||
Add route to 172.16.0.0/16 gw 172.16.1.2 on your host machine.
|
||||
|
||||
Should result in something like:
|
||||
~$ traceroute 172.16.8.2
|
||||
traceroute to 172.16.8.2 (172.16.8.2), 30 hops max, 60 byte packets
|
||||
1 172.16.1.2 (172.16.1.2) 0.481 ms 0.473 ms 0.467 ms
|
||||
2 172.16.2.2 (172.16.2.2) 4.680 ms 4.702 ms 4.700 ms
|
||||
3 172.16.3.2 (172.16.3.2) 8.759 ms 8.768 ms 8.766 ms
|
||||
4 172.16.4.2 (172.16.4.2) 10.791 ms 10.789 ms 10.786 ms
|
||||
5 172.16.5.2 (172.16.5.2) 12.826 ms 12.825 ms 12.821 ms
|
||||
6 172.16.6.2 (172.16.6.2) 14.844 ms 17.858 ms 17.857 ms
|
||||
7 172.16.7.2 (172.16.7.2) 17.858 ms 14.000 ms 13.999 ms
|
||||
8 172.16.8.2 (172.16.8.2) 18.032 ms 18.029 ms 18.023 ms
|
||||
|
||||
'''
|
||||
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, 'nat0')
|
||||
net2 = Network(T)
|
||||
net3 = Network(T)
|
||||
net4 = Network(T)
|
||||
net5 = Network(T)
|
||||
net6 = Network(T)
|
||||
net7 = Network(T)
|
||||
net8 = Network(T)
|
||||
|
||||
router1 = Host(T, net1, net2, args="natbox:172.16.2.1")
|
||||
router2 = Host(T, net2, net3, args="natbox:172.16.3.1")
|
||||
router3 = Host(T, net3, net4, args="natbox:172.16.4.1")
|
||||
router4 = Host(T, net4, net5, args="natbox:172.16.5.1")
|
||||
router5 = Host(T, net5, net6, args="natbox:172.16.6.1")
|
||||
router6 = Host(T, net6, net7, args="natbox:172.16.7.1")
|
||||
router7 = Host(T, net7, net8, args="natbox:172.16.8.1")
|
||||
|
||||
h1 = Host(T, net8)
|
||||
|
||||
sleep(1)
|
||||
start(T)
|
||||
loop()
|
||||
cleanup()
|
||||
16
kernel/picotcp/test/python/udpecho.py
Executable file
16
kernel/picotcp/test/python/udpecho.py
Executable file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
|
||||
from topology import *
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T,"udp0")
|
||||
echo = Host(T, net1, args="udpecho:172.16.1.2:7770:7770:1400:")
|
||||
|
||||
|
||||
sleep(1)
|
||||
raw_input("Press enter to continue ...")
|
||||
|
||||
start(T)
|
||||
wait(echo)
|
||||
cleanup()
|
||||
34
kernel/picotcp/test/python/zmq_linux.py
Executable file
34
kernel/picotcp/test/python/zmq_linux.py
Executable file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/python
|
||||
from topology import *
|
||||
import zmq
|
||||
import sys
|
||||
|
||||
T = Topology()
|
||||
net1 = Network(T, "pyt0")
|
||||
|
||||
#h1 = Host(T, net1)
|
||||
h2 = Host(T, net1, args="zeromq_prod:")
|
||||
|
||||
sleep(1)
|
||||
raw_input("Press enter to continue ...")
|
||||
start(T)
|
||||
|
||||
# Zeromq part
|
||||
ctx = zmq.Context()
|
||||
z = ctx.socket(zmq.SUB)
|
||||
z.setsockopt(zmq.SUBSCRIBE, "")
|
||||
z.connect("tcp://172.16.1.2:1207")
|
||||
print "In the loop..."
|
||||
for i in range(20):
|
||||
if z.poll(20000) == 0:
|
||||
print "Timeout!!!"
|
||||
cleanup()
|
||||
sys.exit(1)
|
||||
else:
|
||||
msg = z.recv()
|
||||
print "Recvd msg len=%d content: %s" % (len(msg), msg)
|
||||
|
||||
|
||||
|
||||
|
||||
cleanup()
|
||||
Reference in New Issue
Block a user