我正在使用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'
如何解决这个问题
答案 0 :(得分:0)
python告诉你的是,你试图在-
(你的float
)和未被叫time.clock()
({{1}上使用function
运算符}})
请务必致电您的函数以使用它的返回值(请注意localhostrecord[address].FCC_Queue[index].whenInitiated
末尾的()
):
whenInititated