0

まず、私はpythonが初めてです!最近、コードでいくつかの問題に直面しています。これは、2 つのフロー ルールを複数のスイッチにインストールするためのコードです。

    import inspect
    from pox.core import core
    import pox.openflow.libopenflow_01 as of
    from pox.lib.revent import *
    from pox.lib.util import dpidToStr
    from pox.lib.addresses import EthAddr, IPAddr
    import pox.lib.packet as pkt
    from collections import namedtuple
    import os
    import csv
    from csv import DictReader
    import time

    log = core.getLogger()
    FirewallPolicies = "%s/pox/pox/misc/firewall-policies.csv" % os.environ[ 'HOME' ]

    class CustomFirewall (EventMixin):

    def __init__ (self):
    self.listenTo(core.openflow)
    log.debug("Enabling Firewall Module")

    def _handle_ConnectionUp (self, event):
    ''' Add your logic here ... '''
    ReadFile = open(FirewallPolicies, 'r')
    ReaderFile = csv.DictReader(ReadFile)
    Deny = {}
    for row in ReaderFile:
            Deny[row['id']] = ({'mac_0':row['mac_0'],'mac_1':row['mac_1']})
    log.debug("Deny table - %s",Deny)
    for x in Deny.values():
            log.debug("Source Mac is %s",x['mac_0'])
            log.debug("Destination Mac is %s",x['mac_1'])
            log.debug("1")
            match = of.ofp_match(dl_src = x['mac_0'], dl_dst = x['mac_1'])
            log.debug("2")
            fm = of.ofp_flow_mod()
            fm.priority = 20
            fm.match = match
            event.connection.send(fm)
            log.debug("Firewall rules installed on %s", dpidToStr(event.dpid))

    def launch ():
    '''
    Starting the Firewall module
    '''
    log.debug("Jyoti's Custom firewall launched")
    core.registerNew(CustomFirewall)

問題: 最初のルールをスイッチにインストールできますが、2 番目のルールをインストールできません。

エラー メッセージ: DEBUG:misc.Custom_firewall_2:Source Mac is 00:00:00:00:00:01

DEBUG:misc.Custom_firewall_2:宛先 Mac は 00:00:00:00:00:02 です

DEBUG:misc.Custom_firewall_2:1

DEBUG:misc.Custom_firewall_2:2

DEBUG:misc.Custom_firewall_2:ファイアウォール ルールが 00-00-00-00-00-09 にインストールされました ->最初のルールがインストールされました

DEBUG:misc.Custom_firewall_2:ソース Mac は 00:00:00:00:00:04 です

DEBUG:misc.Custom_firewall_2:宛先 Mac は 00:00:00:00:00:03 です

DEBUG:misc.Custom_firewall_2:1

DEBUG:misc.Custom_firewall_2:2

DEBUG:openflow.of_01:[00-00-00-00-00-09 33] ソケット エラー: ピアによる接続のリセット -> 2 番目のルールのインストールに失敗

INFO:openflow.of_01:[00-00-00-00-00-09 33] 切断されました

DEBUG:misc.Custom_firewall_2:00-00-00-00-00-09 にインストールされたファイアウォール ルール

ERROR:openflow.of_01:[00-00-00-00-00-0f 37] オープンフロー

エラー: [00-00-00-00-00-0f 37]

エラー: ヘッダー: [00-00-00-00-00-0f 37]

エラー: バージョン: 1 [00-00-00-00-00-0f 37]

エラー: タイプ: 1 (OFPT_ERROR)

...

...

... すぐ

ノート:

self.connection.send(fm) を使用すると、次のようになります。

    self.connection.send(fm)
    AttributeError: 'CustomFirewall' object has no attribute 'connection'

event.connection.send(fm) を使用すると、接続のリセットの問題が発生します

この問題の原因がわかりません。誰でもこれで私を助けてもらえますか?

4

1 に答える 1