我正在用python在POX控制器中编写TRW算法,在这里,当发送者第一次发送时,我给主机分配一个时间段。TRW算法说,从内部主机发送到外部主机的第一个数据包将被发送到目的地,而无需安装任何流规则,因此我有一个函数来实现这一点
localhostrecord{}
class FCC_Queue_Entry (object):
"""this class object will be kept into FCC_Queue list of IntHostEntry class object"""
whenInitiated=0
dip=0
status=0
protocol=0
def __init__ (self,whenInitiated,dip,status,protocol):
self.whenInitiated = whenInitiated
self.dip = dip
self.status = status
self.protocol = protocol
以及
^{pr2}$“”“PCH保留以前与接收方联系过的所有主机地址”“
“”“保留FCC”“Queue”“Entry类的对象”“”
def __init__ (self,likelihood,credit,zeroCreditTime):
self.likelihood = likelihood
self.credit = credit
self.zeroCreditTime = zeroCreditTime
在那之后,我写了代码来发送数据包
def send_Packet(event, ip_packet, ip_protocol, dpidstr, buffer_id, src_port, out_port):
src = ip_packet.srcip
dst = ip_packet.dstip
if src not in localhostrecord:
log.info("local host %s is sending for the firsr time" %(src))
t = datetime.time(0, 0, 0)
newIntHost = IntHostEntry(1.0,10,t.second)
localhostrecord[src] = newIntHost
if dst not in localhostrecord[src].PCH:
localhostrecord[src].PCH.append(dst)
newEntry = FCC_Queue_Entry(time.clock(),dst,status[0],ip_protocol)
localhostrecord[src].FCC_Queue.append(newEntry)
,过了一段时间后,我使用
if(time.clock() - localhostrecord[address].FCC_Queue[index].whenInitiated>=timeout):
在哪里
localhostrecord[address].FCC_Queue[index].whenInitiated =time.clock()
用其他函数写的
我说错话了
TypeError: unsupported operand type(s) for -: 'float' and 'builtin_function_or_method'
如何解决这个问题
python告诉您的是,您试图在
float
(您的time.clock()
)和未调用的function
(localhostrecord[address].FCC_Queue[index].whenInitiated
)上使用-
运算符确保调用函数以使用它的返回值(注意
whenInititated
末尾的()
):相关问题 更多 >
编程相关推荐