本文整理汇总了Python中Packet.ip_src方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.ip_src方法的具体用法?Python Packet.ip_src怎么用?Python Packet.ip_src使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.ip_src方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import ip_src [as 别名]
def generate(self):
while(True):
Experiment.packet_count = Experiment.packet_count+1
addr = random.randint(0,Experiment.size-1)
ipstr = "10.0."+str(addr)+".1"
if(IPAddress(ipstr) in self.parent.prefix):
continue
p = Packet(name="packet")
p.ip_dst = int(IPAddress(ipstr))
p.ip_src = self.parent.ip
p.resp = False
p.probe = False
activate(p, p.run(self.parent))
yield hold, self, random.randint(2, 30)
示例2: p_get_route
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import ip_src [as 别名]
def p_get_route(self, ip, lasthop, packet):
self.ftableclean()
#check for flow table matches
forward_matches = filter(lambda x: (x.ip_src == packet.ip_src and x.ip_dst == packet.ip_dst), self.flow_table)
reverse_matches = filter(lambda x: (x.ip_dst == packet.ip_src and x.ip_src == packet.ip_dst), self.flow_table)
routes = filter(lambda x: x.match(ip) and (not x.link.destination in packet.path), self.rib)#and x.link.destination!=lasthop, self.rib)
if(len(routes) == 0):
routes = filter(lambda x: x.match(ip), self.rib)
oldroutes = filter(lambda x: now()-x.timestamp > 300 or x.rttval == 999, routes)
if(len(oldroutes)>0 and random.random() < 0.25):
outroute = oldroutes[0]
Experiment.old = Experiment.old + 1
else:
routes.sort(key=(lambda x: x.length*x.rttval))
if Experiment.m and len(routes)>1:
r1 = routes[0]
r2 = routes[1]
if r2.rttval - r1.rttval <= (r1.rttval/2):
m1frac = 1.0*r1.m/(r1.m+r2.m)
m2frac = 1.0*r2.m/(r1.m+r2.m)
if(random.random() <= m2frac):
outroute=r2
else:
outroute=r1
else:
outroute = r1
else:
Experiment.current = Experiment.current + 1
outroute = routes[0]
#print "forward", packet, "along", outroute, "from", routes
if(len(forward_matches) > 0) and not packet.resp:
f = forward_matches[0]
if f.expiry == 1:
f.expiry = 0
f.timestamp = now()
elif f.expiry == 2:
f.expiry = 1
return f.route.link
else:
if (now() - f.timestamp > 200 and random.random() < .25):
f.expiry = 2
Experiment.packet_count = Experiment.packet_count+1
Experiment.probe_count = Experiment.probe_count+1
p = Packet(name="packet")
p.ip_dst = packet.ip_dst
p.ip_src = self.ip
p.resp = False
p.probe = True
activate(p, p.run(self))
if(len(reverse_matches) > 0):
Experiment.revmatch = Experiment.revmatch+1
#if(reverse_matches[0].expiry == 2):
#print "ping came back"
#also cool
rtt = now() - reverse_matches[0].timestamp
reverse_matches[0].route.rtt(rtt)
self.flow_table.remove(reverse_matches[0])
else:
self.flow_table.append(Flow(packet.ip_src, packet.ip_dst, now(), now(), outroute, 0))
outroute.visited = True
#print "selected", outroute, "from", routes
return outroute.link