SDN2017 期末作业验收

一、项目描述

负载均衡程序

二、个人分工

小组名称:老肥羊
小组成员:李文博,冉思银,侯振源,李熙,汪志彬

三、代码演示及过程描述

拓扑代码:
from mininet.topo import Topo

class MyTopo( Topo ):
"Simple topology example."
def init( self ):

# Initialize topology
Topo.__init__( self )
h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
h4 = self.addHost('h4')

s1 = self.addSwitch('s1')
s2 = self.addSwitch('s2')
s3 = self.addSwitch('s3')
s4 = self.addSwitch('s4')

self.addLink(h1,s1)
self.addLink(s1,s2)
self.addLink(s1,s3)
self.addLink(s1,s4)
self.addLink(s2,s4)
self.addLink(s3,s4)
self.addLink(s4,h2)
self.addLink(s4,h3)
self.addLink(s4,h4)

topos = { 'mytopo': ( lambda: MyTopo() ) }

发流表:
import httplib2
import time

class OdlUtil:
url = ''
def init(self, host, port):
self.url = 'http://' + host + ':' + str(port)
def install_flow(self, container_name='default',username="admin", password="admin"):
http = httplib2.Http()
http.add_credentials(username, password)
headers = {'Accept': 'application/json'}
flow_name = 'flow_' + str(int(time.time()*1000))
s1zbody='{"group": [{ "group-type": "group-select","group-id": "1","group-name": "loadbalance","buckets": {"bucket": [{"bucket-id": "1","weight": "3","action": [{"order": "0","output-action": {"output-node-connector": "4"}}]},{"bucket-id": "2","weight": "2","action": [{"order": "0","output-action": {"output-node-connector": "2"}}]},{"bucket-id": "3","weight": "2","action": [{"order": "0","output-action": {"output-node-connector": "3"}}]}]}}]}'
s1lbody='{"flow": [{"id": "1","match": {"in-port": "1"},"instructions": {"instruction": [{"order": "0","apply-actions": {"action": [{"order": "0","group-action": {"group-id": "1"}}]}}]},"flow-name": "s1","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s2lbody='{"flow": [{"id": "1","match": {"in-port": "1"},"instructions": {"instruction": [{"order": "0","apply-actions": {"action": [{"order": "0","output-action": {"output-node-connector": "2"}}]}}]},"flow-name": "s2","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s3lbody='{"flow": [{"id": "1","match": {"in-port": "1"},"instructions": {"instruction": [{"order": "0","apply-actions": {"action": [{"order": "0","output-action": {"output-node-connector": "2"}}]}}]},"flow-name": "s3","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s4lbody='{"flow": [{"id": "1","match": {"in-port": "2","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.2/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "4"}}]}}]},"flow-name": "s4:s2toh2","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s4lbody2='{"flow": [{"id": "2","match": {"in-port": "2","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.3/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "5"}}]}}]},"flow-name": "s4:s2toh3","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s4lbody3='{"flow": [{"id": "3","match": {"in-port": "2","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.4/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "6"}}]}}]},"flow-name": "s4:s2toh4","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s4lbody4='{"flow": [{"id": "4","match": {"in-port": "1","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.2/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "4"}}]}}]},"flow-name": "s4:s1toh2","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s4lbody5='{"flow": [{"id": "5","match": {"in-port": "1","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.3/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "5"}}]}}]},"flow-name": "s4:s1toh3","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s4lbody6='{"flow": [{"id": "6","match": {"in-port": "1","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.4/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "6"}}]}}]},"flow-name": "s4:s1toh4","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s4lbody7='{"flow": [{"id": "7","match": {"in-port": "3","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.2/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "4"}}]}}]},"flow-name": "s4:s3toh2","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s4lbody8='{"flow": [{"id": "8","match": {"in-port": "3","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.3/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "5"}}]}}]},"flow-name": "s4:s3toh3","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
s4lbody9='{"flow": [{"id": "9","match": {"in-port": "3","ethernet-match": {"ethernet-type": {"type": "0x0800"}},"ipv4-destination": "10.0.0.4/32"},"instructions": {"instruction": [{"order": "0","apply-actions":{"action": [{"order": "0","output-action": {"output-node-connector": "6"}}]}}]},"flow-name": "s4:s3toh4","priority": "1000","cookie": "0x0001","table_id": "0"}]}'
headers = {'Content-type': 'application/json'}
num=0
while num < 1 :
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:group/1', body=s1zbody, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1', body=s1lbody, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:2/flow-node-inventory:table/0/flow/1', body=s2lbody, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:3/flow-node-inventory:table/0/flow/1', body=s3lbody, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/1', body=s4lbody, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/2', body=s4lbody2, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/3', body=s4lbody3, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/4', body=s4lbody4, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/5', body=s4lbody5, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/6', body=s4lbody6, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/7', body=s4lbody7, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/8', body=s4lbody8, method='PUT',headers=headers)
response, content = http.request(uri='http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:4/flow-node-inventory:table/0/flow/9', body=s4lbody9, method='PUT',headers=headers)
num=num + 1
print(content.decode())
odl = OdlUtil('127.0.0.1', '8181')
odl.install_flow()

代码大概思路:
服务器h2 ,h3,h4,h1是客户端,当h2,h1,h3向h1传输数据时,根据链路的使用状况动态的调整路由规则。
视频:
由于实验失败故无视频。

四、课程总结

在本学期这门课的学习中,我了解了什么是 SDN ,SDN 的基本思想和特点,有哪些控制器,控制层和数据层的通信标准协议;分布式控制器的几种扩展方式;ODL设计的三个层次,以及SDN 的应用领域等其他方方面面的知识。通过这些学习,我渐渐地对所谓的软件定义网络有了更深刻的理解,也算是打开了学习生活的另一扇新的大门。最后的负载均衡是一个大项目,在之前的课程中我们也对此有所了解,但实际却从没操作过,加之小组成员的时间协调没有做好,所以最后没能完成。但是通过这次实验还是充分了解了负载均衡的原理,学到了一些知识吧。

posted @ 2018-01-26 18:03  django0  阅读(270)  评论(0编辑  收藏  举报