0

我正在使用 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

class IntHostEntry (object):
 likelihood=0.0
 credit=0
 zeroCreditTime=0
 PCH=[]
FCC_Queue=[]

"""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'

如何解决这个问题

4

1 回答 1

0

python 告诉你的是你试图在(your ) 和未调用 ( ) 上使用运算-floattime.clock()functionlocalhostrecord[address].FCC_Queue[index].whenInitiated

确保调用您的函数以使用它的返回值(注意()末尾的whenInititated):

if(time.clock() - localhostrecord[address].FCC_Queue[index].whenInitiated()) >=timeout:
于 2016-05-27T11:59:21.170 回答