ryu安装

 

 

yum  install gcc libffi-dev libssl-dev libxml2-dev libxslt1-dev zlib1g-dev
pip3 install ryu

 

Prerequisites
If you got some error messages at the installation stage, please confirm dependencies for building the required Python packages.

% yum  install gcc python-dev libffi-dev libssl-dev libxml2-dev libxslt1-dev zlib1g-dev

 

若遇到six版本不够的问题,则:

pip uninstall six 
pip install six

pip3 install -r tools/pip-requires

greenlet.h:8:20: fatal error: Python.h: No such file or directory
For yum (CentOS, RHEL...):

sudo yum install python-devel   # for python2.x installs
sudo yum install python3-devel   # for python3.x installs

python3 setup.py install

 https://gist.github.com/gachiemchiep/18e11573285b5cc53d8a5bed49c48ff7

#Open vSwitch Lab kaskdaksdkdaks

Get started with Open vSwitch, flows and OpenFlow controllers.

##Pre-reqs

Linux system with OVS installed.

##Setup

Use this script to add a bridge with ports for testing. The interfaces are moved into IP namespaces to isolate them from the main namespace and from each other.

#!/bin/bash

if [ $# -ne 2 ]; then
    echo "usage: $0 port_num ovs_br"
    exit 1
fi

set -xe

port=p$1
ns=ns$1
br=$2
mac=00:00:00:00:00:0$1
ip=10.0.0.${1}/24

ovs-vsctl --may-exist add-br $br
ovs-vsctl add-port $br $port
ovs-vsctl set Interface $port type=internal
ip netns add $ns
ip link set $port netns $ns
ip netns exec $ns ip link set $port address $mac
ip netns exec $ns ip address add $ip dev $port
ip netns exec $ns sysctl -w net.ipv6.conf.${port}.disable_ipv6=1
ip netns exec $ns ip link set $port up
Call script like:

# sh add-port.sh 1 br0
# sh add-port.sh 2 br0
Then the bridge should look like:

# ovs-vsctl show
e3784497-dc8f-432d-9a2c-923148962c73
    Bridge "br0"
        Port "p2"
            Interface "p2"
                type: internal
        Port "br0"
            Interface "br0"
                type: internal
        Port "p1"
            Interface "p1"
                type: internal
##Test 1 - the NORMAL flow

####Test connectivity:

# ip netns exec ns1 ping -c1 10.0.0.2
####Show flows

# ovs-ofctl dump-flows br0
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=560.596s, table=0, n_packets=10, n_bytes=828, idle_age=551, priority=0 actions=NORMAL
This flow gets created by default when you create a bridge.. The NORMAL flow causes the bridge to behave like a simple MAC learning switch. It applies to all ports because no in_port was specified and that is like a wildcard for all ports

####Show the mac table

# ovs-appctl fdb/show br0
 port  VLAN  MAC                Age
    1     0  00:00:00:00:00:01    9
    2     0  00:00:00:00:00:02    9
####Delete all flows

# ovs-ofctl del-flows br0
and ping again - it should fail this time.

####Re-add the NORMAL flow

# ovs-ofctl add-flow br0 actions=NORMAL
##Test 2 - forwarding by port numbers

####Delete all flows

# ovs-ofctl del-flows br0
####Find ofport numbers (OpenFlow port numbers)

# ovs-ofctl show br0
####Add the flows

# ovs-ofctl add-flow br0 in_port=1,actions=output:2
# ovs-ofctl add-flow br0 in_port=2,actions=output:1
####Test

# ip netns exec ns1 ping -c1 10.0.0.2
####Test 3 - forward by destination mac address

####Delete all flows

# ovs-ofctl del-flows br0
####Add the flows

# ovs-ofctl add-flow br0 dl_dst=00:00:00:00:00:01,actions=output:1
# ovs-ofctl add-flow br0 dl_dst=00:00:00:00:00:02,actions=output:2
# ovs-ofctl add-flow br0 dl_dst=ff:ff:ff:ff:ff:ff,actions=flood
####Test

# ip netns exec ns1 ping -c1 10.0.0.2
Use dump-flows and watch the packet counters. Wait several minutes for the ARP cache in the namespaces to expire or delete those entries, and ping again. That should cause the broadcast/flood flow to happen on next ping.

##OVS with an external OpenFlow controller

###Setup

Install the Ryu controller from here

####Start Ryu with the sample L2 learning module

$ ryu-manager ryu/ryu/app/simple_switch.py
loading app ryu/ryu/app/simple_switch.py
loading app ryu.controller.ofp_handler
instantiating app ryu/ryu/app/simple_switch.py of SimpleSwitch
instantiating app ryu.controller.ofp_handler of OFPHandler
####Point the test bridge at it

# ovs-vsctl set-controller br0 tcp:127.0.0.1:6633    
####Check there are no flows yet

# ovs-ofctl dump-flows br0
NXST_FLOW reply (xid=0x4):
####Send some data

# ip netns exec ns1 ping -c1 10.0.0.2
####Check that the controller added new flows

# ovs-ofctl dump-flows br0
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=5.808s, table=0, n_packets=1, n_bytes=42, idle_age=0, in_port=2,dl_dst=00:00:00:00:00:01 actions=output:1
 cookie=0x0, duration=0.808s, table=0, n_packets=0, n_bytes=0, idle_age=0, in_port=1,dl_dst=00:00:00:00:00:02 actions=output:2
####Check controller console for new log messages

packet in 270705776096578 00:00:00:00:00:01 00:00:00:00:00:02 1
packet in 270705776096578 00:00:00:00:00:02 00:00:00:00:00:01 2
packet in 270705776096578 00:00:00:00:00:01 00:00:00:00:00:02 1
####Study and change the sample code

See here

 

pip  install scapy
[root@bogon ~]# cat pack.py 
import binascii
from scapy.all import *
a=Ether(src="8e:d9:18:87:5c:4a",dst="ea:44:97:dd:fb:70")/IP(dst="192.168.1.101",src="192.168.1.10", ttl=10)/ICMP()
print binascii.hexlify(str(a))

 

 

 

 

 

 

[root@kunpeng82 mininet]# ryu --version
ryu 4.34
[root@kunpeng82 mininet]# 
[root@kunpeng82 ryu-master]# find ./ -name simple_switch_13.py
./ryu/app/simple_switch_13.py
./build/lib/ryu/app/simple_switch_13.py
[root@kunpeng82 ryu-master]# cd ryu/app/
[root@kunpeng82 app]# ryu-manager --verbose simple_switch_13.py ofctl_rest.py rest_topology.py

 

 

cd ryu
PYTHONPATH=. ./bin/ryu-manager ryu/app/simple_switch.py

 

要建構的是 host 3 台,交換器 1 台的簡單環境。

mn 命令的參數如下:

名稱    數值    說明
topo    single,3    交換器 1 台、host 3 台的拓璞
mac    無    自動設定 host 的 MAC 位址
switch    ovsk    使用 Open vSwitch
controller    remote    指定外部的 OpenFlow Controller
x    無    啟動 xterm
執行的方法如下:

$ sudo mn --topo single,3 --mac --switch ovsk --controller remote -x
*** Creating network
*** Adding controller
Unable to contact the remote controller at 127.0.0.1:6633
*** Adding hosts:
h1 h2 h3
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1) (h3, s1)
*** Configuring hosts
h1 h2 h3
*** Running terms on localhost:10.0
*** Starting controller
*** Starting 1 switches
s1
*** Starting CLI:
mininet>
執行之後,會在 x windows 出現 5 個 xterm 視窗。 分別對應到 host 1 ~ 3 ,交換器和 Controller 。

在交換器的 xterm 視窗中設定 OpenFlow 的版本,視窗的標題為 「switch: s1 (root)」。

 

 

ryu控制器的启动:在app目录下执行ryu-manager example_switch.py --verbose

mininet的启动:在全局下执行sudo mn --controller=remote --mac --topo=tree,2,2

讲解:

1.在ryu控制器中会发现有33:33:00开头的mac地址,其为lldp的保留mac

2.如果想在显示的时候展示mac,则加入--mac,其在显示的时候可以显示出端口与mac

3.在mininet中可以自定义拓扑,这里使用的是树形结构,深度为2,叶子树为2

 

http://www.muzixing.com/pages/2014/09/20/ryuru-men-jiao-cheng.html

posted on 2020-05-21 20:27  tycoon3  阅读(422)  评论(0)    收藏  举报

导航