我在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 我可以用来填充流程,因为我知道路径并希望对流程进行预编程。