运行截图:
tcpdump验证过程:
(h2和h3都收到了h1的数据包)
分析:L2 Switch模块和POX的hub无太大区别,都是使用OFPP_FLOOD标记让数据包向所有端口发送,本质是集线器
(二)进阶还没搞
心得体会RYU的安装代码参考:
git clone https://github.com/faucetsdn/ryu.git
cd ryu
sudo pip3 install -r tools/pip-requires -i https://pypi.tuna.tsinghua.edu.cn/simple
sudo python3 setup.py install
L2Switch源码
from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_0
class L2Switch(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
def __init__(self, *args, **kwargs):
super(L2Switch, self).__init__(*args, **kwargs)
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def packet_in_handler(self, ev):
msg = ev.msg
dp = msg.datapath
ofp = dp.ofproto
ofp_parser = dp.ofproto_parser
actions = [ofp_parser.OFPActionOutput(ofp.OFPP_FLOOD)]
data = None
if msg.buffer_id == ofp.OFP_NO_BUFFER:
data = msg.data
out = ofp_parser.OFPPacketOut(
datapath=dp, buffer_id=msg.buffer_id, in_port=msg.in_port,
actions=actions, data = data)
dp.send_msg(out)
遇到困难:可视化拓扑图光秃秃的只有一个交换机
原因:本来就只能显示交换机。和ODL不一样。尴尬