我正在尝试创建一个自定义控制器文件,该文件基于 dpid 实例化 simple_switch_13.py 和 hub.py。在创建交换机或集线器时,我很难找到负责分配 dpid 的类。有人可以给我解决方案吗?
这是我写的代码
import logging
import warnings
from ryu.base import app_manager
from ryu.app.simple_switch_13 import SimpleSwitch13
from ryu.lib.dpid import dpid_to_str
from ryu.controller import dpset
LOG = logging.getLogger('ryu.controller.dpset')
homeDir = '/home/click'
class Controller(object):
def __init__( self, name, *ryuArgs, **kwargs ):
ryuCoreDir = '%s/ryu/ryu/app/' % homeDir
if not ryuArgs:
print( 'warning: no Ryu modules specified; '
'running simple_switch only\n' )
#ryuArgs = [ ryuCoreDir + 'simple_switch.py' ]
ryuArgs = [' ']
elif type( ryuArgs ) not in ( list, tuple ):
ryuArgs = [ ryuArgs ]
Controller.__init__( self, name,
command='ryu-manager',
cargs='--ofp-tcp-listen-port %s ' +
' '.join( ryuArgs ),
cdir=ryuCoreDir,
**kwargs )
def switch_features_handler(self, ev):
data_path_id = dpid_to_str(ev.dpid)
if (data_path_id == "00-00-00-00-02-01" or data_path_id == "00-00-00-00-02-02" or data_path_id == "00-00-00-00-02-03" or data_path_id == "00-00-00-00-02-04" or data_path_id == "00-00-00-00-02-05"):
SimpleSwitch13(app_manager.RyuApp)