本文整理汇总了Python中src.sim.Sim.set_debug方法的典型用法代码示例。如果您正苦于以下问题:Python Sim.set_debug方法的具体用法?Python Sim.set_debug怎么用?Python Sim.set_debug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.sim.Sim
的用法示例。
在下文中一共展示了Sim.set_debug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
Sim.set_debug(True)
# setup network
net = Network('../networks/one-hop.txt')
# setup routes
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup application
a = AppHandler(self.filename)
# setup connection
c1 = StopAndWait(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a)
c2 = StopAndWait(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a)
# send a file
with open(self.filename,'r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=0, event=data, handler=c1.send)
# run the simulation
Sim.scheduler.run()
示例2: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
Sim.set_debug(True)
# setup network
n1 = Node()
n2 = Node()
l = Link(address=1,startpoint=n1,endpoint=n2,queue_size=self.queue_size,bandwidth=10000000,propagation=0.01,loss=self.loss, printOut=True)
n1.add_link(l)
n1.add_forwarding_entry(address=2,link=l)
l = Link(address=2,startpoint=n2,endpoint=n1,queue_size=self.queue_size,bandwidth=10000000,propagation=0.01,loss=self.loss)
n2.add_link(l)
n2.add_forwarding_entry(address=1,link=l)
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup application
a = AppHandler("2_1-" + self.filename)
# setup connection
c1 = My_RTP(t1,1,1,2,1,a)
c2 = My_RTP(t2,2,1,1,1,a)
# setup application
a = AppHandler("2_2-" + self.filename)
# setup connection
c3 = My_RTP(t1,1,2,2,2,a)
c4 = My_RTP(t2,2,2,1,2,a)
# send a file
with open(self.filename,'r') as f:
while True:
data = f.read(1000)
if not data:
break
c1.load_buffer(data)
c3.load_buffer(data)
c1.set_file_prefix("2_1")
c2.set_file_prefix("2_1")
c3.set_file_prefix("2_2")
c4.set_file_prefix("2_2")
c1.open_window_file()
c3.open_window_file()
Sim.scheduler.add(delay=0, event="window_init", handler=c1.window_init)
Sim.scheduler.add(delay=0, event="window_init", handler=c3.window_init)
# run the simulation
Sim.scheduler.run()
n1.links[0].myfile.close()
c1.close_window_file()
c3.close_window_file()
Sim.close_rate_file()
示例3: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
if "a" in self.debug:
Sim.set_debug('AppHandler')
if "t" in self.debug:
Sim.set_debug('TCP')
# setup network
networkPlotter = Plotter('out/2-flows-simple')
net = Network(config='networks/one-hop.txt',plotter=networkPlotter)
net.loss(self.loss)
# setup routes
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup connection
c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,AppHandler(inputfile=self.inputfile,identifier="c1"),window=self.window,type=self.type,window_size_plot=True,sequence_plot=True)
c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,AppHandler(inputfile=self.inputfile,plot=True,identifier="c2"),window=self.window,type=self.type,receiver_flow_plot=True)
c3 = TCP(t1,n1.get_address('n2'),2,n2.get_address('n1'),2,AppHandler(inputfile=self.inputfile,identifier="c3"),window=self.window,type=self.type,window_size_plot=True,sequence_plot=True)
c4 = TCP(t2,n2.get_address('n1'),2,n1.get_address('n2'),2,AppHandler(inputfile=self.inputfile,plot=True,identifier="c4"),window=self.window,type=self.type,receiver_flow_plot=True)
global tcps
tcps = [c1, c2, c3, c4]
global original_size
f = open(self.inputfile, "rb")
try:
data = f.read(1000)
while data != "":
original_size += len(data)
Sim.scheduler.add(delay=0, event=data, handler=c1.send)
Sim.scheduler.add(delay=0, event=data, handler=c3.send)
data = f.read(1000)
finally:
f.close()
# run the simulation
global decisecondEvent
decisecondEvent = Sim.scheduler.add(delay=0.1, event=Sim, handler=self.decisecond)
Sim.scheduler.run()
networkPlotter.plot(self.sequencefile)
plotter.plot(self.sequencefile);
示例4: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
if "a" in self.debug:
Sim.set_debug('AppHandler')
if "t" in self.debug:
Sim.set_debug('TCP')
# setup network
net = Network('networks/one-hop.txt')
net.loss(self.loss)
# setup routes
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup application
a = AppHandler(self.inputfile)
# setup connection
c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a,window=self.window,type=self.type)
c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a,window=self.window,type=self.type)
global original_size
f = open(self.inputfile, "rb")
try:
data = f.read(1000)
while data != "":
original_size += len(data)
Sim.scheduler.add(delay=0, event=data, handler=c1.send)
data = f.read(1000)
finally:
f.close()
# run the simulation
Sim.scheduler.run()
plotter.plot(self.sequencefile);
示例5: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
Sim.set_debug(False)
# setup network
n1 = Node()
n2 = Node()
l = Link(address=1,startpoint=n1,endpoint=n2,loss=self.loss,bandwidth=100000000,propagation=0.01)
if self.experiments:
l = Link(address=1,startpoint=n1,endpoint=n2,loss=self.loss,bandwidth=100000000,propagation=0.01, queue_size=100)
n1.add_link(l)
n1.add_forwarding_entry(address=2,link=l)
l = Link(address=2,startpoint=n2,endpoint=n1,loss=self.loss,bandwidth=100000000,propagation=0.01)
if self.experiments:
l = Link(address=2,startpoint=n2,endpoint=n1,loss=self.loss,bandwidth=100000000,propagation=0.01, queue_size=100)
n2.add_link(l)
n2.add_forwarding_entry(address=1,link=l)
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup application
a = AppHandler(self.filename)
# setup connection
c1 = ReliableTransport(t1,1,1,2,1,self.window_size,a)
c2 = ReliableTransport(t2,2,1,1,1,self.window_size,a)
# send a file
with open(self.filename,'r') as f:
c1.stats.set_size(os.path.getsize(self.filename))
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=0, event=data, handler=c1.send)
# run the simulation
Sim.scheduler.run()
print "Average queueing delay =", c1.stats.average()
print "Throughput =", c1.stats.throughput(Sim.scheduler.current_time())
示例6: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
Sim.set_debug('AppHandler')
Sim.set_debug('TCP')
# setup network
net = Network('../networks/one-hop.txt')
net.loss(self.loss)
# setup routes
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0]) # n1 -> n2
n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0]) # n1 <- n2
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup application
tcp_flows = 1
a1 = AppHandler(self.filename, 1)
# setup connection
c1a = TCP(t1, n1.get_address('n2'), 1, n2.get_address('n1'), 1, 3000, a1)
c2a = TCP(t2, n2.get_address('n1'), 1, n1.get_address('n2'), 1, 3000, a1)
# send a file
with open(self.filename,'r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=0, event=data, handler=c1a.send)
# run the simulation
Sim.scheduler.run()
return tcp_flows
示例7: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
Sim.set_debug(True)
# setup network
n1 = Node()
n2 = Node()
l = Link(address=1,startpoint=n1,endpoint=n2,loss=self.loss,
bandwidth=10000000.0,propagation=0.01,queue_size=self.queue)
n1.add_link(l)
n1.add_forwarding_entry(address=2,link=l)
l = Link(address=2,startpoint=n2,endpoint=n1,loss=self.loss,
bandwidth=10000000.0,propagation=0.01,queue_size=self.queue)
n2.add_link(l)
n2.add_forwarding_entry(address=1,link=l)
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup application
a = AppHandler(self.filename)
# setup connection
c1 = TCP(t1,1,1,2,1,app=a,window=self.window)
c2 = TCP(t2,2,1,1,1,app=a,window=self.window)
# send a file
with open(self.filename,'r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=0, event=data, handler=c1.send)
# run the simulation
Sim.scheduler.run()
print "Total queuing delay: ", a.total_queuing_delay
print "Total packets sent: ", a.total_packets_sent
示例8: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
Sim.set_debug(True)
# setup network
n1 = Node()
n2 = Node()
l = Link(address=1,startpoint=n1,endpoint=n2,queue_size=self.queue_size,bandwidth=10000000,propagation=0.01,loss=self.loss)
n1.add_link(l)
n1.add_forwarding_entry(address=2,link=l)
l = Link(address=2,startpoint=n2,endpoint=n1,queue_size=self.queue_size,bandwidth=10000000,propagation=0.01,loss=self.loss)
n2.add_link(l)
n2.add_forwarding_entry(address=1,link=l)
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup application
a = AppHandler(self.filename)
# setup connection
c1 = My_RTP(t1,1,1,2,1,a)
c2 = My_RTP(t2,2,1,1,1,a)
# send a file
with open(self.filename,'r') as f:
while True:
data = f.read(1000)
if not data:
break
c1.load_buffer(data)
c1.window_init(self.window_size)
# run the simulation
Sim.scheduler.run()
示例9: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
#Sim.set_debug('AppHandler')
#Sim.set_debug('TCP')
Sim.set_debug('Link')
net = Network('networks/five.txt')
net.loss(self.loss)
# setup routes
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup application
a1 = AppHandler('test1.txt')
a2 = AppHandler('test2.txt')
a3 = AppHandler('test3.txt')
a4 = AppHandler('test4.txt')
a5 = AppHandler('test5.txt')
# setup connection
c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c3 = TCP(t1,n1.get_address('n2'),2,n2.get_address('n1'),2,a2,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c4 = TCP(t2,n2.get_address('n1'),2,n1.get_address('n2'),2,a2,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c5 = TCP(t1,n1.get_address('n2'),3,n2.get_address('n1'),3,a3,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c6 = TCP(t2,n2.get_address('n1'),3,n1.get_address('n2'),3,a3,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c7 = TCP(t1,n1.get_address('n2'),4,n2.get_address('n1'),4,a4,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c8 = TCP(t2,n2.get_address('n1'),4,n1.get_address('n2'),4,a4,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c9 = TCP(t1,n1.get_address('n2'),5,n2.get_address('n1'),5,a5,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c0 = TCP(t2,n2.get_address('n1'),5,n1.get_address('n2'),5,a5,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
# send a file
with open('test1.txt','r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=0, event=data, handler=c1.send)
with open('test2.txt','r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=1.5, event=data, handler=c3.send)
with open('test3.txt','r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=2, event=data, handler=c5.send)
with open('test4.txt','r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=2.5, event=data, handler=c7.send)
with open('test5.txt','r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=3, event=data, handler=c9.send)
# run the simulation
Sim.scheduler.run()
# print some results
print
print "========== Overall results =========="
time = Sim.scheduler.current_time()
print "Total time: %f seconds" % time
avg = numpy.mean(c2.queueing_delay_list)
print "Average queueing delay: %f" % avg
max = numpy.max(c2.queueing_delay_list)
print "Max queueing delay: %f" % max
file_size = os.path.getsize(self.filename)
print "File size: %i" % file_size
throughput = file_size / time
print "Throughput: %f" % throughput
# Variables for debugging
self.c3 = c3
self.c4 = c4
self.c2 = c2
self.c1 = c1
self.t1 = t1
self.t2 = t2
self.net = net
#.........这里部分代码省略.........
示例10: receive_packet
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
self.node = node
def receive_packet(self,packet):
print Sim.scheduler.current_time(),self.node.hostname,packet.ident
class DelayHandler(object):
def __init__(self, node):
self.node = node
def receive_packet(self,packet):
print Sim.scheduler.current_time(),packet.ident,packet.created,Sim.scheduler.current_time() - packet.created,packet.transmission_delay,packet.propagation_delay,packet.queueing_delay, self.node.hostname
if __name__ == '__main__':
# parameters
Sim.scheduler.reset()
Sim.set_debug(True)
# setup network
net = Network('../networks/five-nodes-line.txt')
# get nodes
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n3 = net.get_node('n3')
n4 = net.get_node('n4')
n5 = net.get_node('n5')
# setup broadcast application
b1 = BroadcastApp(n1)
n1.add_protocol(protocol="broadcast",handler=b1)
b2 = BroadcastApp(n2)
示例11: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
Sim.set_debug('AppHandler')
Sim.set_debug('TCP')
# setup network
if self.use_queue:
net = Network('networks/one-hop-queue.txt')
else:
net = Network('networks/one-hop.txt')
net.loss(self.loss)
# setup routes
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup application
a = AppHandler(self.filename)
# setup connection
c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a,window=self.window)
c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a,window=self.window)
# send a file
with open(self.filename,'r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=0, event=data, handler=c1.send)
# run the simulation
Sim.scheduler.run()
# print some results
print
print "========== Overall results =========="
time = Sim.scheduler.current_time()
print "Total time: %f seconds" % time
avg = numpy.mean(c2.queueing_delay_list)
print "Average queueing delay: %f" % avg
max = numpy.max(c2.queueing_delay_list)
print "Max queueing delay: %f" % max
file_size = os.path.getsize(self.filename)
print "File size: %i" % file_size
throughput = file_size / time
print "Throughput: %f" % throughput
print "%i,%f,%f,%f,%i,%f\n" % (self.window,time,avg,max,file_size,throughput)
if self.loss == 0.0:
print "Outputing results to experiment.csv"
output_fh = open('experiment.csv', 'a')
output_fh.write("%i,%f,%f,%f,%i,%f\n" % (self.window,time,avg,max,file_size,throughput))
output_fh.close()
示例12: HandleDataApp
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
import random
from dvrouting import DVRoutingApp
class HandleDataApp(object):
def __init__(self,node):
self.node = node
def receive_packet(self,packet):
print Sim.scheduler.current_time(),self.node.hostname,"received data"
if __name__ == '__main__':
# parameters
Sim.scheduler.reset()
Sim.set_debug(True)
Sim.set_debug('Nodedata')
# setup network
net = Network('networks/five-nodes-ring.txt')
# get nodes
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n3 = net.get_node('n3')
n4 = net.get_node('n4')
n5 = net.get_node('n5')
# setup handling data for node 5
n1.add_protocol(protocol="data",handler=HandleDataApp(n1))
n2.add_protocol(protocol="data",handler=HandleDataApp(n2))
示例13: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
Sim.set_debug('AppHandler')
Sim.set_debug('TCP')
# setup network
# net = Network('../networks/one-hop.txt')
net = Network('../networks/four-nodes.txt')
net.loss(self.loss)
# setup routes
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n3 = net.get_node('n3')
n4 = net.get_node('n4')
n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0]) # n1 -> n2
n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0]) # n1 <- n2
n2.add_forwarding_entry(address=n3.get_address('n2'),link=n2.links[1]) # n2 -> n3
n3.add_forwarding_entry(address=n2.get_address('n3'),link=n3.links[0]) # n2 <- n3
n2.add_forwarding_entry(address=n4.get_address('n2'),link=n2.links[2]) # n2 -> n4
n4.add_forwarding_entry(address=n2.get_address('n4'),link=n4.links[0]) # n2 <- n4
n1.add_forwarding_entry(address=n4.get_address('n2'),link=n1.links[0]) # n1 -> n2 -> n4
n3.add_forwarding_entry(address=n4.get_address('n2'),link=n3.links[0]) # n3 -> n2 -> n4
n4.add_forwarding_entry(address=n1.get_address('n2'),link=n4.links[0]) # n4 -> n2 -> n1
n4.add_forwarding_entry(address=n3.get_address('n2'),link=n4.links[0]) # n4 -> n2 -> n1
# setup transport
t1 = Transport(n1)
t3 = Transport(n3)
t4 = Transport(n4)
# setup application
tcp_flows = 2
a1 = AppHandler(self.filename,1)
a2 = AppHandler(self.filename,2)
# a3 = AppHandler(self.filename, 3)
# a4 = AppHandler(self.filename, 4)
# a5 = AppHandler(self.filename, 5)
# setup connection
# c1a = TCP(t1, n1.get_address('n2'), 1, n2.get_address('n1'), 1, a1)
# c2a = TCP(t2, n2.get_address('n1'), 1, n1.get_address('n2'), 1, a1)
### 4-node configuration
c1a = TCP(t1, n1.get_address('n2'), 1, n4.get_address('n2'), 1, a1)
c2a = TCP(t4, n4.get_address('n2'), 1, n1.get_address('n2'), 1, a1)
c1b = TCP(t3, n3.get_address('n2'), 2, n4.get_address('n2'), 2, a2)
c2b = TCP(t4, n4.get_address('n2'), 2, n3.get_address('n2'), 2, a2)
# c1b = TCP(t1, n1.get_address('n2'), 2, n2.get_address('n1'), 2, a2)
# c2b = TCP(t2, n2.get_address('n1'), 2, n1.get_address('n2'), 2, a2)
# c1c = TCP(t1, n1.get_address('n2'), 3, n2.get_address('n1'), 3, a3)
# c2c = TCP(t2, n2.get_address('n1'), 3, n1.get_address('n2'), 3, a3)
#
# c1d = TCP(t1, n1.get_address('n2'), 4, n2.get_address('n1'), 4, a4)
# c2d = TCP(t2, n2.get_address('n1'), 4, n1.get_address('n2'), 4, a4)
#
# c1e = TCP(t1, n1.get_address('n2'), 5, n2.get_address('n1'), 5, a5)
# c2e = TCP(t2, n2.get_address('n1'), 5, n1.get_address('n2'), 5, a5)
# send a file
with open(self.filename,'r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=0, event=data, handler=c1a.send)
Sim.scheduler.add(delay=0, event=data, handler=c1b.send)
# Sim.scheduler.add(delay=0, event=data, handler=c1a.send)
# Sim.scheduler.add(delay=0.1, event=data, handler=c1b.send)
# Sim.scheduler.add(delay=0.2, event=data, handler=c1c.send)
# Sim.scheduler.add(delay=0.3, event=data, handler=c1d.send)
# Sim.scheduler.add(delay=0.4, event=data, handler=c1e.send)
# run the simulation
Sim.scheduler.run()
return tcp_flows
示例14: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
if "a" in self.debug:
Sim.set_debug('AppHandler')
if "t" in self.debug:
Sim.set_debug('TCP')
# setup network
networkPlotter = Plotter('out/2-flows-advanced-competing-rtt')
net = Network(config='networks/competing-rtt.txt',plotter=networkPlotter)
net.loss(self.loss)
# setup routes
A = net.get_node('A')
B = net.get_node('B')
C = net.get_node('C')
D = net.get_node('D')
# A forwarding entries
A.add_forwarding_entry(address=B.get_address('C'),link=A.links[0])
A.add_forwarding_entry(address=C.get_address('A'),link=A.links[0])
A.add_forwarding_entry(address=D.get_address('C'),link=A.links[0])
# B forwarding entries
B.add_forwarding_entry(address=A.get_address('C'),link=B.links[0])
B.add_forwarding_entry(address=C.get_address('B'),link=B.links[0])
B.add_forwarding_entry(address=D.get_address('C'),link=B.links[0])
# C forwarding entries
C.add_forwarding_entry(address=A.get_address('C'),link=C.links[0])
C.add_forwarding_entry(address=B.get_address('C'),link=C.links[1])
C.add_forwarding_entry(address=D.get_address('C'),link=C.links[2])
# D forwarding entries
D.add_forwarding_entry(address=A.get_address('C'),link=D.links[0])
D.add_forwarding_entry(address=B.get_address('C'),link=D.links[0])
D.add_forwarding_entry(address=C.get_address('D'),link=D.links[0])
# setup transport
t1 = Transport(A)
t2 = Transport(B)
t4 = Transport(D)
# setup connection
c1 = TCP(t1,A.get_address('C'),1,D.get_address('C'),1,AppHandler(inputfile=self.inputfile,identifier="c1"),window=self.window,type=self.type,window_size_plot=True,sequence_plot=True)
c2 = TCP(t4,D.get_address('C'),1,A.get_address('C'),1,AppHandler(inputfile=self.inputfile,plot=True,identifier="c2"),window=self.window,type=self.type,receiver_flow_plot=True)
c3 = TCP(t2,B.get_address('C'),2,D.get_address('C'),2,AppHandler(inputfile=self.inputfile,identifier="c3"),window=self.window,type=self.type,window_size_plot=True,sequence_plot=True)
c4 = TCP(t4,D.get_address('C'),2,B.get_address('C'),2,AppHandler(inputfile=self.inputfile,plot=True,identifier="c4"),window=self.window,type=self.type,receiver_flow_plot=True)
global tcps
tcps = [c1, c2, c3, c4]
global original_size
f = open(self.inputfile, "rb")
try:
data = f.read(1000)
while data != "":
original_size += len(data)
Sim.scheduler.add(delay=0, event=data, handler=c1.send)
Sim.scheduler.add(delay=0, event=data, handler=c3.send)
data = f.read(1000)
finally:
f.close()
# run the simulation
global decisecondEvent
decisecondEvent = Sim.scheduler.add(delay=0.1, event=Sim, handler=self.decisecond)
Sim.scheduler.run()
networkPlotter.plot(self.sequencefile)
plotter.plot(self.sequencefile);
示例15: run
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import set_debug [as 别名]
def run(self):
# parameters
Sim.scheduler.reset()
#Sim.set_debug('AppHandler')
#Sim.set_debug('TCP')
Sim.set_debug('Link')
net = Network('networks/one.txt')
net.loss(self.loss)
# setup routes
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
# setup application
a1 = AppHandler('test.txt')
# setup connection
c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery,aiad=True)
c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery,aiad=True)
# send a file
with open('test.txt','r') as f:
while True:
data = f.read(1000)
if not data:
break
Sim.scheduler.add(delay=0, event=data, handler=c1.send)
# run the simulation
Sim.scheduler.run()
# print some results
print
print "========== Overall results =========="
time = Sim.scheduler.current_time()
print "Total time: %f seconds" % time
avg = numpy.mean(c2.queueing_delay_list)
print "Average queueing delay: %f" % avg
max = numpy.max(c2.queueing_delay_list)
print "Max queueing delay: %f" % max
file_size = os.path.getsize(self.filename)
print "File size: %i" % file_size
throughput = file_size / time
print "Throughput: %f" % throughput
plotter = Plotter()
print "Saving the sequence plot"
plotter.create_sequence_plot(c1.x, c1.y, c1.dropX, c1.dropY, c1.ackX, c1.ackY, chart_name='advanced/aiad/sequence.png')
plotter.clear()
plotter.rateTimePlot(c2.packets_received, Sim.scheduler.current_time(), 'advanced/aiad/rateTime1.png')
linkab = n1.links[0]
self.linkab = linkab
plotter.clear()
plotter.queueSizePlot(linkab.queue_log_x, linkab.queue_log_y, linkab.dropped_packets_x, linkab.dropped_packets_y, chart_name='advanced/aiad/queueSize.png')
plotter.clear()
plotter.windowSizePlot(c1.window_x, c1.window_y, chart_name="advanced/aiad/windowSize1.png")