继之前大概讲的关于 mininet 的一些基本使用方法, 本文中整理一些关于 POX 控制器的使用.
POX 的教程可以参考这个视频, 感觉讲得很清楚 [需 FQ] :https://www.youtube.com/watch?v=4KGnxPzxc6w&t=192s
首先, 安装好 POX 之后, 进入 POX 目录, 里面有两个文件夹比较关键.
daniel@ubuntu:~/pox$ ls
debug-pox.py ext LICENSE NOTICE pox pox.py README setup.cfg tests tools
daniel@ubuntu:~/pox$ ls pox
boot.py core.py datapaths help.py info __init__.pyc log misc proto py.pyc tk.py web
boot.pyc core.pyc forwarding host_tracker __init__.py lib messenger openflow py.py samples topology
一个是 pox 目录下的 ext 文件夹, 这个是用于存放我们自己写的控制器代码的目录. 另一个是子 pox 目录下的 forwarding 目录, 这个里面有很多指的学习的 examples.
daniel@ubuntu:~/pox$ ls pox/forwarding
controller.py firewall.pyc hub.pyc l2_flowvisor.py l2_learning.pyc l2_pairs.py main.py topo_proactive.py
controller.pyc firewall_task2.py ids.click l2_learning (copy).py l2_multi.py l3_learning.py main.pyc
firewall.py firewall_task2.pyc __init__.py l2_learning.py l2_nx.py lb1.click my_learning.py
firewall.py~ hub.py __init__.pyc l2_learning.py~ l2_nx_self_learning.py lb2.click napt.click
注: 以上的 forwarding 目录中包含了很多我当时用于测试的本不属于该目录的文件, 请无视它们..
例如 hub.py 就是一个让 switch 执行类似于 hub 的 flooding 操作的一个控制文件, l2_learning.py 是一个可以学习路由表并进行相应转发策略的文件.
打开 hub.py 文件看看内容:
- # Copyright 2012 James McCauley
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at:
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- """Turns your complex OpenFlow switches into stupid hubs."""
- from pox.core import core
- import pox.openflow.libopenflow_01 as of
- from pox.lib.util import dpidToStr
- log = core.getLogger()
- def _handle_ConnectionUp (event):
- msg = of.ofp_flow_mod()
- msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD))
- event.connection.send(msg)
- log.info("Hubifying %s", dpidToStr(event.dpid))
- def launch ():
- core.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp)
- log.info("Hub running.")
具体代码以后要用到的时候再放上分析吧.
来源: https://www.cnblogs.com/XiaodongZhang/p/6431752.html