51学通信论坛2017新版

标题: OpenDaylight VTN应用--控制数据包走不同路径 [打印本页]

作者: admin    时间: 2017-9-17 13:00
标题: OpenDaylight VTN应用--控制数据包走不同路径
本例子主要演示通过VTN配置流策略,控制h1到h2走不同的路径,分别为s1->s2>s3和s1->s4->s3,。利用mininet虚拟出openflow交换机,并对其进行控制,mininet交换机拓扑图如下:

[attach]960[/attach]

配置mininet拓扑:
Shell
sudo mn --controller=remote,ip=172.31.2.70 --custom different_path.py --topo mytopo
脚本拓扑如下所示:different_path.py
Shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

from mininet.topo import Topo
class MyTopo( Topo ):
"Simple topology example."
def __init__( self ):
"Create custom topo."
# Initialize topology
Topo.__init__( self )
# Add hosts and switches
leftHost = self.addHost( 'h1' )
rightHost = self.addHost( 'h2' )
leftSwitch = self.addSwitch( 's1' )
middleSwitch = self.addSwitch( 's2' )
middleSwitch2 = self.addSwitch( 's4' )
rightSwitch = self.addSwitch( 's3' )
# Add links
self.addLink( leftHost, leftSwitch )
self.addLink( leftSwitch, middleSwitch )
self.addLink( leftSwitch, middleSwitch2 )
self.addLink( middleSwitch, rightSwitch )
self.addLink( middleSwitch2, rightSwitch )
self.addLink( rightSwitch, rightHost )
topos = { 'mytopo': ( lambda: MyTopo ) }

查看拓扑链接结构:
Shell
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s3-eth3
s1 lo:s1-eth1:h1-eth0 s1-eth2:s2-eth1 s1-eth3:s4-eth1
s2 lo:s2-eth1:s1-eth2 s2-eth2:s3-eth1
s3 lo:s3-eth1:s2-eth2 s3-eth2:s4-eth2 s3-eth3:h2-eth0
s4 lo:s4-eth1:s1-eth3 s4-eth2:s3-eth2
添加如下of流表,如果没有改表项的话:
Shell
sudo ovs-ofctl add-flow s1 priority=0,actions=output:CONTROLLER
sudo ovs-ofctl add-flow s2 priority=0,actions=output:CONTROLLER
sudo ovs-ofctl add-flow s3 priority=0,actions=output:CONTROLLER
sudo ovs-ofctl add-flow s4 priority=0,actions=output:CONTROLLER
此时监测h1 ping h2是不通的:
Shell
mininet> h1 ping h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
From 10.0.0.1 icmp_seq=1 Destination Host Unreachable
From 10.0.0.1 icmp_seq=2 Destination Host Unreachable
下面通过vtn规则,使得h1与h2可以通信,调用接口创建相关资源:
Shell
curl -i --user admin:adminpass -H 'content-type: application/json' -X POST -d '{"vtn" : {"vtn_name":"vtn_one","description":"test VTN" }}' http://172.31.2.70:8083/vtn-webapi/vtns
HTTP/1.1 201 Created
Shell
curl -i --user admin:adminpass -H 'content-type: application/json' -X POST -d '{"controller": {"controller_id": "controller1", "ipaddr":"172.31.2.70", "type": "odc", "version": "1.0", "auditstatus":"enable"}}' http://172.31.2.70:8083/vtn-webapi/controllers
curl -i --user admin:adminpass -H 'content-type: application/json' -X POST -d '{"vbridge" : {"vbr_name":"vbr_one","controller_id":"controller1","domain_id":"(DEFAULT)" }}' http://172.31.2.70:8083/vtn-webapi/vtns/vtn_one/vbridges
curl -i --user admin:adminpass -H 'content-type: application/json' -X POST -d '{"interface": {"if_name": "if1","description": "if_desc1"}}' http://172.31.2.70:8083/vtn-webapi/vtns/vtn_one/vbridges/vbr_one/interfaces
HTTP/1.1 201 Created
curl -i --user admin:adminpass -H 'content-type: application/json' -X POST -d '{"interface": {"if_name": "if2","description": "if_desc2"}}' http://172.31.2.70:8083/vtn-webapi/vtns/vtn_one/vbridges/vbr_one/interfaces
curl -i --user admin:adminpass -H 'content-type: application/json' -X PUT -d '{"portmap":{"logical_port_id": "PP-OF:openflow:3-s3-eth1"}}' http://172.31.2.70:8083/vtn-webapi/vtns/vtn_one/vbridges/vbr_one/interfaces/if1/portmap
HTTP/1.1 204 No Content
curl -i --user admin:adminpass -H 'content-type: application/json' -X PUT -d '{"portmap":{"logical_port_id": "PP-OF:openflow:2-s2-eth1"}}' http://172.31.2.70:8083/vtn-webapi/vtns/vtn_one/vbridges/vbr_one/interfaces/if2/portmap
HTTP/1.1 204 No Content
监测是否可以通信:
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=437 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.533 ms
查询VTN数据流信息
Shell
curl -i -X GET -H 'content-type: application/json' --user 'admin:adminpass'"http://172.31.2.70:8083/vtn-webapi/dataflows?controller_id=controller1&srcmacaddr=deb9.f152.68a8&no_vlan_id=true&switch_id=00:00:00:00:00:00:00:01&port_name=s1-eth1"
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 754
Date: Thu, 21 Jan 2016 11:08:51 GMT
{"dataflows":[{"reason":"success","controller_dataflows":[{"egress_station_id":"3","ingress_port_name":"s1-eth1","match":{"macdstaddr":["8e34.e542.ceac"],"macsrcaddr":["deb9.f152.68a8"]},"pathinfos":[{"in_port_name":"s1-eth1","out_port_name":"s1-eth3","switch_id":"00:00:00:00:00:00:00:01"},{"in_port_name":"s4-eth1","out_port_name":"s4-eth2","switch_id":"00:00:00:00:00:00:00:04"},{"in_port_name":"s3-eth2","out_port_name":"s3-eth3","switch_id":"00:00:00:00:00:00:00:03"}],"ingress_domain_id":"(DEFAULT)","controller_type":"odc","ingress_station_id":"1","egress_port_name":"s3-eth3","ingress_switch_id":"00:00:00:00:00:00:00:01","controller_id":"controller1","flow_id":"3","egress_domain_id":"(DEFAULT)","egress_switch_id":"00:00:00:00:00:00:00:03"}]}]}
可以看出当前流路径是s1->s4->3
Shell
curl -i --user admin:admin -H 'content-type: application/json' -X PUT -d '{"name": "flowcond_1","match": [{"index": 1,"ethernet":{"src":"8e:34:e5:42:ce:ac","dst": "de:b9:f1:52:68:a8","type": 2048},"inetMatch": {"inet4": {"src": "10.0.0.1","dst": "10.0.0.2","protocol": 1}}}]}' http://172.31.2.70:8282/controller/nb/v2/vtn/default/flowconditions/flowcond_1
curl -i --user admin:admin -H 'content-type: application/json' -X PUT -d '{"index": 10, "condition":"flowcond_1", "policy":1, "idleTimeout": 300, "hardTimeout": 0}' http://172.31.2.70:8282/controller/nb/v2/vtn/default/pathmaps/1
HTTP/1.1 204 No Content
修改路径策略信息:s1->s2->s3
Shell
curl -i --user admin:admin -H 'content-type: application/json' -X PUT -d '{"id": 1,"default": 100000,"cost":[{"location": {"node": {"type":"OF", "id": "00:00:00:00:00:00:00:01"},"port": {"type": "OF","id": "2", "name": "s1-eth2"}},"cost": 1000},{"location": {"node": {"type": "OF", "id": "00:00:00:00:00:00:00:02"},"port": {"type": "OF","id": "2","name":"s2-eth2"}}, "cost": 1000},{"location": {"node": {"type": "OF", "id": "00:00:00:00:00:00:00:03"}, "port": {"type": "OF","id": "3","name": "s3-eth3"}},"cost": 100000}]}' http://172.31.2.70:8282/controller/nb/v2/vtn/default/pathpolicies/1
HTTP/1.1 204 No Content
声明:本文转载自网络。版权归原作者所有,如有侵权请联系删除。




欢迎光临 51学通信论坛2017新版 (http://bbs.51xuetongxin.com/) Powered by Discuz! X3