本文整理汇总了Python中networks.network.Network类的典型用法代码示例。如果您正苦于以下问题:Python Network类的具体用法?Python Network怎么用?Python Network使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Network类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
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()
开发者ID:Steve525,项目名称:bene-lab-4-routing,代码行数:35,代码来源:transfer.py
示例2: main
def main():
# parameters
Sim.scheduler.reset()
# 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 app
d = DelayHandler()
net.nodes['n2'].add_protocol(protocol="delay", handler=d)
# setup packet generator
destination = n2.get_address('n1')
max_rate = 1000000 // (1000 * 8)
load = 0.8 * max_rate
g = Generator(node=n1, destination=destination, load=load, duration=10)
Sim.scheduler.add(delay=0, event='generate', handler=g.handle)
# run the simulation
Sim.scheduler.run()
开发者ID:zappala,项目名称:bene,代码行数:26,代码来源:delay.py
示例3: main
def main():
# parameters
Sim.scheduler.reset()
# setup network
net = Network('../networks/five-nodes.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)
n2.add_protocol(protocol="broadcast", handler=b2)
b3 = BroadcastApp(n3)
n3.add_protocol(protocol="broadcast", handler=b3)
b4 = BroadcastApp(n4)
n4.add_protocol(protocol="broadcast", handler=b4)
b5 = BroadcastApp(n5)
n5.add_protocol(protocol="broadcast", handler=b5)
# send a broadcast packet from 1 with TTL 2, so everyone should get it
p = Packet(
source_address=n1.get_address('n2'),
destination_address=0,
ident=1, ttl=2, protocol='broadcast', length=100)
Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet)
# send a broadcast packet from 1 with TTL 1, so just nodes 2 and 3
# should get it
p = Packet(
source_address=n1.get_address('n2'),
destination_address=0,
ident=2, ttl=1, protocol='broadcast', length=100)
Sim.scheduler.add(delay=1, event=p, handler=n1.send_packet)
# send a broadcast packet from 3 with TTL 1, so just nodes 1, 4, and 5
# should get it
p = Packet(
source_address=n3.get_address('n1'),
destination_address=0,
ident=3, ttl=1, protocol='broadcast', length=100)
Sim.scheduler.add(delay=2, event=p, handler=n3.send_packet)
# run the simulation
Sim.scheduler.run()
开发者ID:zappala,项目名称:bene,代码行数:51,代码来源:broadcast.py
示例4: MainNetworkView
class MainNetworkView(GeographicalView, NetworkView):
subtype = 'network'
menu_type = 'network'
def __init__(self, controller):
self.network = Network(self)
super().__init__(controller)
# given a graphical node, retrieves all attached graphical links
def attached_glinks(self, gnode):
for link in self.network.attached_links(gnode.node):
if 'vc' in link.subtype:
continue
yield link.glink[self]
def draw_objects(self, *objects):
for obj in objects:
if obj.class_type == 'node' and self not in obj.gnode:
GraphicalNetworkNode(self, obj)
if obj.class_type == 'link' and self not in obj.glink:
if 'vc' in obj.subtype:
continue
self.draw_objects(obj.source, obj.destination)
GraphicalLink(self, obj)
def dropEvent(self, event):
pos = self.mapToScene(event.pos())
geo_pos = self.world_map.to_geographical_coordinates(pos.x(), pos.y())
if event.mimeData().hasFormat('application/x-dnditemdata'):
new_gnode = GraphicalNetworkNode(self)
new_gnode.setPos(pos)
# update the nodes coordinates at creation
new_gnode.node.longitude, new_gnode.node.latitude = geo_pos
开发者ID:mintoo,项目名称:NetDim,代码行数:34,代码来源:main_network_view.py
示例5: run
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);
开发者ID:StevenC4,项目名称:bene,代码行数:45,代码来源:transfer.py
示例6: run
def run(self):
# parameters
Sim.scheduler.reset()
if hasattr(self, 'debug') and "a" in self.debug:
Sim.set_debug('AppHandler')
if hasattr(self, 'debug') and "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.filename)
# setup connection
c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a,dynamic_rto=self.dynamic_rto)
c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a,dynamic_rto=self.dynamic_rto)
f = open(self.filename, "rb")
try:
data = f.read(1000)
while data != "":
Sim.scheduler.add(delay=0, event=data, handler=c1.send)
data = f.read(1000)
finally:
f.close()
# run the simulation
Sim.scheduler.run()
开发者ID:StevenC4,项目名称:bene,代码行数:41,代码来源:transmission-time.py
示例7: run
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
开发者ID:kbpontius,项目名称:lab2-CS460,代码行数:40,代码来源:transfer-test.py
示例8: main
def main():
# parameters
Sim.scheduler.reset()
# 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 app
d = DelayHandler()
net.nodes['n2'].add_protocol(protocol="delay", handler=d)
# send one packet
p = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000)
Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet)
# take the link down
Sim.scheduler.add(delay=1, event=None, handler=n1.get_link('n2').down)
# send one packet (it won't go through)
p = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000)
Sim.scheduler.add(delay=1.1, event=p, handler=n1.send_packet)
# bring the link up
Sim.scheduler.add(delay=2, event=None, handler=n1.get_link('n2').up)
# send one packet (and now it goes through)
p = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000)
Sim.scheduler.add(delay=2.1, event=p, handler=n1.send_packet)
# run the simulation
Sim.scheduler.run()
开发者ID:zappala,项目名称:bene,代码行数:37,代码来源:simple.py
示例9: range
results[self.percentage] = []
results[self.percentage].append(packet.queueing_delay)
if __name__ == '__main__':
# parameters
percentages = [.1, .2, .3, .4, .5, .6, .7, .75, .8, .9, .95, .98]
max_rate = 1000000/(1000*8)
for percentage in percentages:
for x in range (0, 3):
Sim.scheduler.reset()
# 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 app
d = DelayHandler(percentage=percentage)
net.nodes['n2'].add_protocol(protocol="delay",handler=d)
# setup packet generator
destination = n2.get_address('n1')
load = percentage*max_rate
g = Generator(node=n1,destination=destination,load=load,duration=10)
开发者ID:StevenC4,项目名称:bene,代码行数:31,代码来源:queueing-theory.py
示例10: run
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
开发者ID:kbpontius,项目名称:lab4-CS460,代码行数:85,代码来源:transfer.py
示例11: endOutput
if packet.ident == self.packetCount - 1:
self.endOutput()
def endOutput(self):
outputFile.close()
if __name__ == "__main__":
outputFile = open("output-problem2-1b.txt", "w")
# parameters
Sim.scheduler.reset()
# setup network
net = Network("config-3n-1Gbps-1Gbps-100ms-100ms.txt")
# setup routes
n1 = net.get_node("n1")
n2 = net.get_node("n2")
n3 = net.get_node("n3")
# setup forwarding entries
a2 = n2.get_address("n1")
a1 = n1.get_address("n2")
a3 = n3.get_address("n2")
n1.add_forwarding_entry(address=a2, link=n1.links[0])
n2.add_forwarding_entry(address=a1, link=n2.links[0])
n2.add_forwarding_entry(address=a3, link=n2.links[1])
n3.add_forwarding_entry(address=a2, link=n3.links[0])
开发者ID:kbpontius,项目名称:CS460-Lab1,代码行数:30,代码来源:lab1-problem2-1b.py
示例12: run
def run(self):
# parameters
Sim.scheduler.reset()
#Sim.set_debug('AppHandler')
#Sim.set_debug('TCP')
Sim.set_debug('Link')
net = Network('networks/competing.txt')
net.loss(self.loss)
# setup routes
# n1 - n3 - n4
# |
# n2
n1 = net.get_node('n1')
n2 = net.get_node('n2')
n3 = net.get_node('n3')
n4 = net.get_node('n4')
# n1 forwarding entries
n1.add_forwarding_entry(address=n3.get_address('n1'),link=n1.links[0])
n1.add_forwarding_entry(address=n4.get_address('n3'),link=n1.links[0])
# n2 forwarding entries
n2.add_forwarding_entry(address=n3.get_address('n2'),link=n2.links[0])
n2.add_forwarding_entry(address=n4.get_address('n3'),link=n2.links[0])
# n3 forwarding entries
n3.add_forwarding_entry(address=n1.get_address('n3'),link=n3.links[0])
n3.add_forwarding_entry(address=n2.get_address('n3'),link=n3.links[1])
n3.add_forwarding_entry(address=n4.get_address('n3'),link=n3.links[2])
# n4 forwarding entries
n4.add_forwarding_entry(address=n1.get_address('n3'),link=n4.links[0])
n4.add_forwarding_entry(address=n2.get_address('n3'),link=n4.links[0])
n4.add_forwarding_entry(address=n3.get_address('n4'),link=n4.links[0])
# setup transport
t1 = Transport(n1)
t2 = Transport(n2)
t4 = Transport(n4)
# setup application
a1 = AppHandler('test1.txt')
a2 = AppHandler('test2.txt')
# setup connection
c1 = TCP(t1,n1.get_address('n3'),1,n4.get_address('n3'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c2 = TCP(t4,n4.get_address('n3'),1,n1.get_address('n3'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c3 = TCP(t2,n2.get_address('n3'),2,n4.get_address('n3'),2,a2,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
c4 = TCP(t4,n4.get_address('n3'),2,n2.get_address('n3'),2,a2,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=0, event=data, handler=c3.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
linkab = n1.links[0]
self.linkab = linkab
l = linkab
# Plotting
plotter = Plotter()
# Plot sequence charts
#.........这里部分代码省略.........
开发者ID:nathand8,项目名称:bene,代码行数:101,代码来源:competingRtt.py
示例13: DelayHandler
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)
n2.add_protocol(protocol="broadcast",handler=b2)
b3 = BroadcastApp(n3)
n3.add_protocol(protocol="broadcast",handler=b3)
开发者ID:mkeagar,项目名称:cs460,代码行数:31,代码来源:5node_line_routingApp.py
示例14: NodePrinter
print "(%s) --------> ENDING <--------" % Sim.scheduler.current_time()
class NodePrinter(object):
def __init__(self, node):
self.node = node
def receive_packet(self, packet):
print "%s - (%s) Packet ARRIVED - Data: %s; Source_Address: %s; Destination_Address: %s" % (Sim.scheduler.current_time(), self.node.hostname, packet.body, packet.source_address, packet.destination_address)
if __name__ == '__main__':
# parameters
Sim.scheduler.reset()
Sim.set_debug(True)
# setup network
net = Network('../networks/fifteen-nodes.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')
n6 = net.get_node('n6')
n7 = net.get_node('n7')
n8 = net.get_node('n8')
n9 = net.get_node('n9')
n10 = net.get_node('n10')
n11 = net.get_node('n11')
n12 = net.get_node('n12')
n13 = net.get_node('n13')
开发者ID:kbpontius,项目名称:lab5-rework-CS460,代码行数:31,代码来源:distance-vector.py
示例15: __init__
def __init__(self, controller):
self.network = Network(self)
super().__init__(controller)
开发者ID:mintoo,项目名称:NetDim,代码行数:3,代码来源:main_network_view.py
示例16: run
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()
开发者ID:nathand8,项目名称:bene,代码行数:61,代码来源:transfer.py
示例17: run
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")
开发者ID:nathand8,项目名称:bene,代码行数:66,代码来源:advancedAiad.py
示例18: run
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
#.........这里部分代码省略.........
开发者ID:nathand8,项目名称:bene,代码行数:101,代码来源:five.py
示例19: receive_packet
def receive_packet(self,packet):
f = open(self.filename, "a")
f.write("Node:\t\t\t\t{:s}\n".format(self.node.hostname))
f.write("Packet Created:\t\t{:f}\n".format(packet.created))
f.write("Packet Identifier:\t{:d}\n".format(packet.ident))
f.write("Time Received:\t\t{:f}\n\n".format(Sim.scheduler.current_time()))
f.close()
if __name__ == '__main__':
# ------------------------- 2 nodes, 1Mbps, 1s, 1 packet, 1000 bytes ------------------------- #
# parameters
Sim.scheduler.reset()
# setup network
net = Network('../../networks/lab1/2-nodes/1Mbps-1s.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 app
filename = "../../out/lab1/2-nodes/1Mbps-1s-1packet-1000bytes.txt"
description = "2 Nodes - 1 packet\n1Mbps, 1s, 1 packet, 1000 bytes\n\n"
t = TransmitApp(n2, filename, description)
n2.add_protocol(protocol="delay", handler=t)
# send one packet
p = packet.Packet(destination_address=n2.get_address('n1'),ident=1,protocol='delay',length=1000)
开发者ID:StevenC4,项目名称:bene,代码行数:31,代码来源:lab-network-simulation.py
注:本文中的networks.network.Network类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论