我试图理解 Python 中的两个函数。它来自 ryu 开源控制器的代码。我怀疑它以某种方式实现了 LLDP 并尝试存储拓扑信息。我不知道是什么
@set_ev_cls(event.EventSwitchRequest)
和
@set_ev_cls(event.EventLinkRequest)
我不知道上面的语句在 Python 中是什么意思。如果有人能解释一下意思就好了。整个文件都在这里给出。链接到python源文件
@set_ev_cls(event.EventSwitchRequest)
def switch_request_handler(self, req):
# LOG.debug(req)
dpid = req.dpid
switches = []
if dpid is None:
# reply all list
for dp in self.dps.itervalues():
switches.append(self._get_switch(dp.id))
elif dpid in self.dps:
switches.append(self._get_switch(dpid))
rep = event.EventSwitchReply(req.src, switches)
self.reply_to_request(req, rep)
@set_ev_cls(event.EventLinkRequest)
def link_request_handler(self, req):
# LOG.debug(req)
dpid = req.dpid
if dpid is None:
links = self.links
else:
links = [link for link in self.links if link.src.dpid == dpid]
rep = event.EventLinkReply(req.src, dpid, links)
self.reply_to_request(req, rep)