OpenDaylight學習 ( by quqi99 )

quqi99發表於2013-06-23

                    OpenDaylight學習 ( by quqi99 )


作者:張華  發表於:2013-06-13
版權宣告:可以任意轉載,轉載時請務必以超連結形式標明文章原始出處和作者資訊及本版權宣告

( http://blog.csdn.net/quqi99 )


     在我看來,SDN的本質從技術上講主要是下面三點:

1)有一個控制器,用於將控制流和資料流分離。交換機向控制器請示將資料包往哪個埠轉發。交換機和控制器之間的南橋協議有一個標準叫OpenFlow,但並不是所有廠家都願意遵守標準的。OpenDayLight除了支援OpenFlow協議以外,也支援其他的一些協議。

2)將租戶tenant的概念做到了交換機之中。雲端計算的本質就是向租戶租服務,服務對於租戶應該是隔離的。傳統的二層網路用VLAN做隔離,現在還要加上tenant做隔離。只不過以前tenant這個概念做在應用層,現在直接下層到L2層了。另外,VLAN有很多缺點(如vlan號只能對1-4094,這個對於公有云不合適,且需要配置實際物理交換機),所以可以通過像GRE之類的一些遂道技術再自定義幀頭,在頭中就可以自定義類似於vlantenant的隔離概念,就像一個應用程式一樣,通過socket發出去,接收方再通過自定義協議解析資料。

3)控制器向要提供北橋API,供使用者呼叫來實現軟體定義網路。


、  經過今天一天對opendaylight的初步學習,達到了幾下目的。

1)opendaylight長成什麼樣子,它的原理熟悉了。除了CLI及REST APIs沒有細看以外,其他high level一點的也都能理解了。

2)雖然openstack的opendaylight外掛的程式碼還沒有出來,但能夠想象它今後會怎麼在openstack中運用。也清楚了這個外掛怎麼寫的大致步驟。

3)熟悉了mininet的用法,mininet是一個用在一臺機器上模擬openflow實驗環境的。它的實現原理是:採用root namespace做openflow交換機,其他的每一個host就是一個namespace,host與switch之間通過veth對等裝置相連。

     但由於opendaylight的文件非常不清晰,有一點不是太明白,導致後面的實驗沒有做:

1)不清楚下列設定controller-node的命令的nodeA是怎麼來的,nodeA應該是資料庫的一個類似於uuid的值,但不清楚什麼命令可以得到它。

       oscp(config)# controller-node <nodeA>



安裝OpenDayLight控制器

     可以從原始碼編譯,也可以直接下載編譯好的OpenDayLight Controller(https://jenkins.opendaylight.org/controller/job/controller-nightly/lastSuccessfulBuild/artifact/opendaylight/distribution/opendaylight/target/),我們選擇直接從原始碼編譯的方式:

1, 安裝maven,java, ant ( sudo yum install ant)之類的軟體,下面說maven的安裝步驟:

http://mirror.bit.edu.cn/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.zip

解壓後,直接在~/.bashrc檔案中設定下列環境變數即可:

export JAVA_HOME=/bak/java/jdk1.7.0_21

export M2_HOME=/bak/java/apache-maven-3.0.5

export MAVEN_OPTS="-Xms256m -Xmx512m"

export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH


2,下載OpenDayLightController的程式碼,並編譯:

git clone https://git.opendaylight.org/gerrit/p/controller.git

cd controller/opendaylight/distribution/opendaylight/

mvn clean install (這步偶爾第一次執行會出錯,出錯後加-X引數再執行一遍就可以了)


3, 啟動OpenDayLightController,

cd controller/opendaylight/distribution/opendaylight/target/distribution.opendaylight-0.1.0-SNAPSHOT-osgipackage/opendaylight

./run.sh

然後就可以在瀏覽器中訪問連結http://localhost:8080


4,(可選)eclipse開發環境環境建立如下:

1)在eclipse中安裝maven外掛 (eclipse market裡找maven integration for eclipse)

2)匯入“existing maven project”, 我將workspace設定為:/bak/opendaylight/controller

3)  設定OSGItarget, controller/opendaylight/distribution/opendaylight/opendaylight.target

4)  debug模式啟動opendaylight-osgi-launcher

5opendaylight Gerrit的地址,https://git.opendaylight.org/gerrit/


或者用其他openflow控制器,如floodlight, http://docs.projectfloodlight.org/display/floodlightcontroller/Installation+Guide

$ git clone git://github.com/floodlight/floodlight.git
$ cd floodlight
$ git checkout fl-last-passed-build
$ ant

$java -jar target/floodlight.jar # run Floodlight

http://localhost:8080/ui/index.html


安裝mininet

mininet目前不能執行在64位系統上,不得不下載virtualbox映象 http://floodlight.openflowhub.org/files/floodlight-vm.zip

啟動mininet,並連線控制器

sudo mn  --controller=remote --ip=192.168.99.104  --port=6633 --mac --topo=tree,depth=2

或簡單的,sudo mn --controller=remote --ip=192.168.99.104 --port=6633

root@localhost:/home/floodlight# dpctl show tcp:127.0.0.1:6634

features_reply (xid=0xc1d3ddd4): ver:0x1, dpid:1

n_tables:2, n_buffers:256

features: capabilities:0x87, actions:0xfff

 1(s1-eth1): addr:f2:91:cb:40:c7:5a, config: 0, state:0

     current:    10GB-FD COPPER 

 2(s1-eth2): addr:1a:91:f7:1e:2a:be, config: 0, state:0

     current:    10GB-FD COPPER 

 3(s1-eth3): addr:16:04:cc:cb:59:de, config: 0, state:0

     current:    10GB-FD COPPER 

 LOCAL(dp0): addr:00:23:20:89:2d:61, config: 0x1, state:0x1

get_config_reply (xid=0x9f508db3): miss_send_len=0

root@localhost:/home/floodlight# dpctl dump-flows tcp:127.0.0.1:6634

stats_reply (xid=0x77dd14d8): flags=none type=1(flow)


root@localhost:/home/floodlight# sudo dpctl add-flow tcp:127.0.0.1:6634 in_port=1,idle_timeout=360,actions=output:2

root@localhost:/home/floodlight# dpctl dump-flows tcp:127.0.0.1:6634

stats_reply (xid=0x469554d): flags=none type=1(flow)

  cookie=0, duration_sec=2s, duration_nsec=939000000s, table_id=0, priority=32768, n_packets=0, n_bytes=0, idle_timeout=360,hard_timeout=0,in_port=1,actions=output:2




OpenDaylight SDN Controller Platform (OSCP)

注意,OpenDayLight Controller和OSCP實際上2個獨立的SDN控制器專案(分別由Cisco和BigSwitch承當)。不過,BigSwitch於6月份退出OpenDayLight(降級為silver member),OSCP這個專案基本上也就廢棄了(從2013-06起就沒有更新過)

git clone ssh://veryhua2006@git.opendaylight.org:29418/net-virt-platform.git
./setup.sh
make
java -jar target/sdnplatform.jar 
source ./workspace/ve/bin/activate 
make stop-sdncon reset-cassandra start-sdncon (OSCP REST APIs實現在一個單純的程式sdncon)
java -jar sdnplatform/target/sdnplatform.jar


GUI地址:http://192.168.99.100:8000/ 

執行CLI命令 ( https://wiki.opendaylight.org/view/OpenDaylight_Command-Line_Interface_(CLI):Main)
[hua@laptop net-virt-platform]$ cd cli/

[hua@laptop cli]$ ./cli.py 

version200

default controller: 127.0.0.1:8000, SDN OS 1.0 - custom version

laptop> help

For help on specific commands type help <topic>

Commands:

  clearterm   Clears and resets the terminal screen

  connect     Connect to a controller's REST API

  date        Display current date and time

  debug       Manage various cli debugging features

  echo        Echo remaining arguments

  enable      Enter enable mode

  exit        Exit current mode

  help        Help on commands or topics

  history     Display history of commands

  logout      Exit from cli

  no          Delete or disable configuration parameters

  ping        ping a switch or ip address

  set         Manage CLI sessions settings

  show        Show links, controller managed switch to switch interfaces

  test        Perform various tests on the network

  trace       Determine the L3 path to some destination

  traceroute  Determine the L3 path to some destination

  tunnel-link

  version

  watch       Iterate indicated command displaying results

laptop> show switch

# Switch DPID             Alias Connected Since         IP Address     Tun Capable -Enabled -State   Core Switch

-|-----------------------|-----|-----------------------|--------------|-----------|--------|--------|-----------

1 00:00:00:00:00:00:00:01       2013-06-23 17:34:35 CST 192.168.99.104 False       False disabled False

laptop> show host

# MAC Address       Address Space VLAN IP Address Switch/OF Port (Physical Port)      Tag Last Seen

-|-----------------|-------------|----|----------|-----------------------------------|---|---------

1 32:a7:38:9c:83:9b default            Unknown    00:00:00:00:00:00:00:01/1 (s1-eth1)     0 minute

2 ae:60:9e:e8:38:9b default            Unknown    00:00:00:00:00:00:00:01/2 (s1-eth2)     0 minute

3 b2:04:d3:3c:d9:79 default            Unknown    00:00:00:00:00:00:00:01/3 (s1-eth3)     0 minute

laptop> show link

None.


eclipse:
1) make eclipse
2) Import "sdnplatform" project into any eclipse workspace


OpenDaylight Network virtualization (ONV)

ONV是執行在OSCP平臺上的一個NaaS應用,座標相當於OpenStack Neutron

它具有:

      1. tenant隔離

  1. 3層路由功能

  2. Opendaylightquantum外掛呼叫ONV的北橋APIs



OpenDaylight Neutron外掛

      今後opendaylight會往社群提供一個外掛,位於neutron/plugin/oscp,它有一個RestProxy會去調OSCPRESTAPIs,有點類似於floodlight的那個rest外掛,不過好像程式碼還沒提交進去,我們先猜測一下它的用法。估計用devstack的話,配置得至少多出幾列幾項:

enable_service oscp
Q_PLUGIN=oscp
BS_FL_CONTROLLERS_PORT=<ip_address:port>
BS_FL_CONTROLLER_TIMEOUT=10


這些步驟分解的話,應該是:

1)配置所有節點上的OVS使用openflow控制器

NETWORK_CONTROLERS=<comma-seperated-list-of-network-ctrls>
sudo ovs-vsctl \--no-wait \-\- \--if-exists del-br br-int
sudo ovs-vsctl \--no-wait add-br br-int
sudo ovs-vsctl \--no-wait br-set-external-id br-int bridge-id br-int
for ctrl in `echo ${NETWORK_CONTROLERS} \| tr ',' ' '`
do
 sudo ovs-vsctl set-controller br-int "tcp:${ctrl}:6633"
done

2)資料庫及配置

$ mysql -u root -p$PASS -e 'DROP DATABASE IF EXISTS oscp_neutron;'
$ mysql -u root -p$PASS -e 'CREATE DATABASE IF NOT EXISTS oscp_neutron;'

vi /etc/quantum/neutron.conf

[DEFAULT]
core_plugin = neutron.plugins.oscp.plugin.RestProxy
allow_overlapping_ips = False
lock_path = <path_to_which_neutron_process_can_write_to>
vi /etc/neutron/plugins/oscp/restproxy.ini
[DATABASE]
sql_connection = mysql://<username>:<password>@<database_ip>:3306/restproxy_neutron
[RESTPROXY]
servers=<controller_ip:port_num>,<controller_ip:port>
serverauth=<username>:<password>
serverssl=False

vi /etc/nova/nova.conf

libvirt_vif_type=ethernet
libvirt_vif_driver=nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver
3)啟動
neutron-server --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/oscp/restproxy.ini


要開放控制節點提供REST介面的埠,好像neutron外掛能訪問:https://wiki.opendaylight.org/view/OpenDaylight_Network_Virtualization_(ONV):OpenStack

OpenDaylight的文件不是很清晰,暫不清楚下面的nodeA的值怎麼得來?

oscp> enable

oscp# configure

oscp(config)# controller-node <nodeA>

oscp(config-controller)# interface Ethernet 0

oscp(config-controller-if)# firewall allow  web

用命令列檢視:show controller-node all

RESTAPI檢視:http://192.168.99.100:8000/rest/v1/model/controller-node


如果它要用到外部閘道器的話,也得像用neutroncli命令那樣呼叫OSCPCLI命令配置外部閘道器,見:https://wiki.opendaylight.org/view/OpenDaylight_OpenStack_Quantum_Plugin:Main


連結:

REST API doc,https://wiki.opendaylight.org/view/OpenDaylight_SDN_Controller_Platform_(OSCP):Rest_Reference

CLI doc,

 https://wiki.opendaylight.org/view/OpenDaylight_Command-Line_Interface_(CLI):Main


相關文章