我在我的 simple_switch.py 中使用以下函数来填充到交换机的流。
def populate_of_flow(self,datapath,msg,src,dst):
ofproto = datapath.ofproto
dpid = datapath.id
self.mac_to_port.setdefault(dpid, {})
# learn a mac address to avoid FLOOD next time.
self.mac_to_port[dpid][src] = msg.in_port
if dst in self.mac_to_port[dpid]:
out_port = self.mac_to_port[dpid][dst]
else:
out_port = ofproto.OFPP_FLOOD
actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
fe_key = format_dpid_str(dpid_to_str(datapath.id)) + str(msg.in_port)
fe_list = self.g.vertices.index.lookup(switch_dpid_port=fe_key)
for fe in fe_list:
#print('flow entries for switch {} has output port {} action {}'.format(fe.switch_dpid,fe.actionOutputPort,fe.actions))
outport = fe.actionOutputPort
actions = [datapath.ofproto_parser.OFPActionOutput(outport)]
# install a flow to avoid packet_in next time
if out_port != ofproto.OFPP_FLOOD:
self.add_flow(datapath, msg.in_port, dst, actions)
print('msg.buffer_id {}'.format(msg.buffer_id))
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath, buffer_id=msg.buffer_id, in_port=msg.in_port,
actions=actions)
datapath.send_msg(out)
正如你在上面看到的,它需要“msg.buffer_id”。现在这个“msg”来自传递给事件处理程序的 PACKET_IN 事件。我想知道是否有更通用的 API 可以鉴于我知道路径并希望对流进行预编程,用于填充流。