私はpythonとpoxコントローラーの初心者です。受信したパケットを分類するために、pox にコードを追加したいと考えています。送信元と宛先の IP/ポートのペア間を移動する IP パケットを、一定期間内に同一のプロトコルでカウントしたいと考えています。次のようなリストが必要です。
[ [送信元 IP 、DS ヒント、送信元ポート 、送信先ポート 、プロトコル = tcp 、フロー カウント = x]
[送信元 IP、DS ヒント、送信元ポート、送信先ポート、プロトコル = IP、フロー カウント = y]
[ソース IP、DS ヒント、ソース ポート、DST ポート、プロトコル=ICMP、フロー カウント=z]]
python でリストのリストを使用しました。これは、フローごとに 1 つのリストを意味します。そして、コードのフロー カウント セクションを pox の L2_learning コンポーネント (_handle_PacketIn 関数内) に追加しました。したがって、コントローラで packet_in が受信されるたびに、計算が実行されます。
しかし、エラーが発生しました: RuntimeError: maximum recursion depth exceeded。
コードで再帰関数を使用していません。許可されるスタックの深さを増やしましたが、エラーはまだ存在します。
さらに、特定の時間間隔でリスト (名前: フローリスト) のリストを満たすようにプログラムをスケジュールする方法がわかりません。コントローラーに到達するすべてのパケットをこの中で考慮する必要があるため、少し混乱しています。一方、すべてのパケットを計算すると、前述のエラーが発生します。
特定の間隔でフロー カウント (上記) を計算する方法を教えてください。そして、このスケジューリングのコードをプログラムのどこに配置すればよいでしょうか?
コントローラでパケットが受信されるたびにリストを印刷するのではなく、その時間間隔でのみ完成したリストを印刷するために、フローリストを印刷するためのコマンドを配置する場所。
(最大再帰深度を超えた)エラーを解決するにはどうすればよいですか?
コードは次のとおりです。
sys.setrecursionlimit(10000)
class LearningSwitch (object):
flowlist=[]
def __init__ (self, connection, transparent):
.......
LearningSwitch.flowlist=[]
def _handle_PacketIn (self, event):
flag=0
packet = event.parsed
if packet.type == packet.IP_TYPE:
ip_packet=packet.payload
#-------------TCP-----------------
if (packet.find('tcp')):
tcp_packet = ip_packet.payload
for thisflow in LearningSwitch.flowlist:
if (thisflow[0]==packet.next.srcip and thisflow[1]==packet.next.dstip and thisflow [2]==tcp_packet.srcport and thisflow[3]==tcp_packet.dstport,thisflow[4]== "TCP"):
thisflow[5]+=1
flag=1
if (flag!=1):
LearningSwitch.flowlist.append([packet.next.srcip,packet.next.dstip,tcp_packet.srcport,tcp_packet.dstport,"TCP",1])
#---------- ICMP --------------------
elif (packet.find('icmp')):
icmp_packet = ip_packet.payload
for thisflow in LearningSwitch.flowlist:
if (thisflow[0]==ip_packet.srcip and thisflow[1]==ip_packet.dstip and thisflow[4]== "ICMP"):
thisflow[5]+=1
flag=1
if (flag!=1):
LearningSwitch.flowlist.append([packet.next.srcip,packet.next.dstip,"--","--","ICMP",1])
#------------ IPV4 ---------------------
elif (packet.find('ipv4')):
for thisflow in LearningSwitch.flowlist:
if (thisflow[0]==packet.next.srcip and thisflow[1]==packet.next.dstip and thisflow[4]== "IP"):
thisflow[5]+=1
flag=1
if (flag!=1):
LearningSwitch.flowlist.append([packet.next.srcip,packet.next.dstip,"--","--","IP",1])
print LearningSwitch.flowlist
#---- The rest of the code is from L2_learning component
.
.
.
.
class l2_learning (object):
def __init__ (self, transparent):
core.openflow.addListeners(self)
self.transparent = transparent
def _handle_ConnectionUp (self, event):
log.debug("Connection %s" % (event.connection,))
LearningSwitch(event.connection, self.transparent)
def launch (transparent=False, hold_down=_flood_delay):
"""
Starts an L2 learning switch.
"""
try:
global _flood_delay
_flood_delay = int(str(hold_down), 10)
assert _flood_delay >= 0
except:
raise RuntimeError("Expected hold-down to be a number")
core.registerNew(l2_learning, str_to_bool(transparent))
これはエラーです:
return -other.__cmp__(self)
File "/home/manager/pox/pox/lib/addresses.py", line 347, in __cmp__
return -other.__cmp__(self)
File "/home/manager/pox/pox/lib/addresses.py", line 214, in __cmp__
return -other.__cmp__(self)
File "/home/manager/pox/pox/lib/addresses.py", line 347, in __cmp__
return -other.__cmp__(self)
File "/home/manager/pox/pox/lib/addresses.py", line 214, in __cmp__
return -other.__cmp__(self)
File "/home/manager/pox/pox/lib/addresses.py", line 347, in __cmp__
return -other.__cmp__(self)
File "/home/manager/pox/pox/lib/addresses.py", line 214, in __cmp__
return -other.__cmp__(self)
File "/home/manager/pox/pox/lib/addresses.py", line 347, in __cmp__
return -other.__cmp__(self)
File "/home/manager/pox/pox/lib/addresses.py", line 214, in __cmp__
return -other.__cmp__(self)
RuntimeError: maximum recursion depth exceeded
ご親切にありがとうございました。