![](/img/trans.png)
[英]POX - Installing a rule which says to send a dummy packet whenever a certain packet matches an ofp_match
[英]How Pox controller will send packet without installing flow rules
我正在使用pox控制器編寫蠕蟲檢測代碼,有人可以告訴我如何編寫一個函數,其中我的控制器將直接向主機發送數據包。我的意思是假設主機A現在將**** TCPSYN ****數據包作為流規則發送至主機B不可用,交換機現在將數據包發送到控制器我想編寫函數**** controller ****將數據包發送到主機B而不安裝任何流規則。
def _handle_PacketIn(自身,事件):
packet = event.parsed
log.info("Packet come in %s"%packet.type)
dpidstr = dpid_to_str(event.dpid)
# updating out mac to port mapping
self.macToPort[(event.connection,packet.src)] = event.port
dst_port = self.macToPort.get((event.connection,packet.dst))
tcpp = packet.find('tcp')
if tcpp and tcpp.SYN:
#here i want to write code where my controller will send tcp syn packet received from host A to the destination host(B) with installing any flow rules
if tcpp and tcpp.ACK:
#here i want to write code where my controller will receive tcp synack packet and send this syn ack packet to the sender(A) which has sent syn packet to host (B)
其實我的算法就像
這樣做會有一些代碼來處理數據包將有所幫助,但是無論如何,讓我嘗試介紹最簡單和最通用的情況。
假設您在主類init函數中有一個監聽數據包事件的監聽器,例如
core.openflow.addListenerByName("PacketIn", self._handle_PacketIn)
然后在處理事件的函數中
def _handle_PacketIn (self, event): msg = of.ofp_packet_out(data=event.ofp) msg.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD)) event.connection.send(msg)
因此,味精是控制器發送到交換機的味精,並且為了覆蓋所有端口,您只需將傳入的數據包泛洪到任何地方。 如果您知道目的地,則可以在此處進行調整以僅將數據包發送到所需的端口。 這將在閉環中失敗,但是它將為您提供一個起點。 在http://archive.openflow.org/wk/index.php/OpenFlow_Tutorial#ofp_action_output_class上檢查更多有關ofp_action_output類的信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.