ryu 為一python 寫成之SDN controller
優點是簡單方便,連我第一次使用python都可以輕易看懂,opendaylight跟onos尤其是ODL實在太複雜了karaf、OSGi、maven、buck,沒有相關工具經驗的入門者實在太痛苦
ryu安裝方式有二(macOS)
- 使用homebrew安裝brew install python
- easy_install pip
- pip install -r tools/pip-requires
- pip install –upgrade pip
- pip install --upgrade six
- git source code回來安裝
- git clone git://github.com/osrg/ryu.git
- cd ryu
- python ./setup.py install
- ryu-manager --verbose --observe-links ryu.topology.switches ryu.app.rest_topology ryu.app.ofctl_rest ryu.app.simple_switch_13
如果想要執行自己的app就直接在ryu-manager上去就好, e.g. ryu-manager test.py
- pip install ryu
順帶提一下send flow mod的部份
在ryu/app/裡面的simple_switch_13.py有寫到
@set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
//這裡set_ev_cls是定義當符合第一個參數類型的packet時會call下面這個define,
第二個參數是指當符合switch某個狀態時才能收到packet,這裡分別是指收到feature reply才call下面的define以及controller跟switch完成連接後才能收到packet
def switch_features_handler(self, ev):
datapath = ev.msg.datapath
//ev.msg代表一個of packet,裡面的datapath element代表是從哪個switch來
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
# install table-miss flow entry
#
# We specify NO BUFFER to max_len of the output action due to
# OVS bug. At this moment, if we specify a lesser number, e.g.,
# 128, OVS will send Packet-In with invalid buffer_id and
# truncated packet data. In that case, we cannot output packets
# correctly. The bug has been fixed in OVS v2.1.0.
match = parser.OFPMatch()
//呼叫填入flowmod match欄位的地方,定義以及範例在ryu/ryu/ofproto/ofproto_v1_3_parser.py的class OFPMatch(StringifyMixin),本處並無填參數表示match沒有特別的OXM feild
actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
ofproto.OFPCML_NO_BUFFER)]
//呼叫填入flowmod action欄位的地方,定義以及範例在ryu/ryu/ofproto/ofproto_v1_3_parser.py的class OFPActionOutput(OFPAction),第一個參數為flow裡面action要output的port,第二個為length
self.add_flow(datapath, 0, match, actions)
def add_flow(self, datapath, priority, match, actions, buffer_id=None):
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
actions)]
//以下兩行為自己印的debug message
LOG.debug (actions)
LOG.debug (match)
if buffer_id:
mod = parser.OFPFlowMod(datapath=datapath, buffer_id=buffer_id,
priority=priority, match=match,
instructions=inst)
else:
mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
match=match, instructions=inst)
datapath.send_msg(mod)
參考:http://ryu-zhdoc.readthedocs.io/getting_started.html
https://hazy.today/1612-再試%20SDN:利用%20RYU%20控制%20OpenFlow%20交換器/
http://www.muzixing.com/pages/2014/09/20/ryuru-men-jiao-cheng.html
http://yhhuanglab.blogspot.tw/2015/08/ryu-gui.html
留言列表