SDN实战:Build a VXLAN Tunnel by Making Python-based API Calls for DCI

SDN IN ACTION: Build a VXLAN tunnel by making Python-based API Calls on OpenDaylight and Provide the DCI service

 

薛国锋                                      [email protected]

 

今天做了个小实验,通过Python程序调用OpenDaylight的北向API,在两个DC之间建立VXLAN隧道,实现DCI;DC内部采用Mininet c0控制器和OpenFlow协议,跨DC采用OpenDaylight及OVSDB协议实现DC互联。通过本次实验深刻领悟到,SDN控制器实际上就是一个API Gateway ,提供北向RESTful API以及南向控制协议(OpenFlow、OVSDB、NetConf、BGP-LS等)之间的转换,实现网络动态可编程和业务自动化部署J

Today we will play with Python, making Python-based  API calls on OpenDaylight and building a VXLAN tunnel between two DCs. Inside each DC, the Mininet C0 controller and OpenFlow are deployed; and with OVSDB, OpenDaylight manages both DCs and provides the interconnect between them. After this test, we would be deeply impressed that the SDN controller is a natural API gateway providing the conversion between NB RESTful API and SB control protocols, such asOpenFlow, OVSDB, NetConf and BGP-LS, etc; and to provide the programmability for network automation and service agility. Below is the physical and logicaldesign and topology:


1 Run OpenDaylight and install the necessary features

[email protected]>feature:installodl-aaa-authn

[email protected]>feature:installodl-restconf-all

[email protected]>feature:installodl-dlux-core

[email protected]>feature:installodl-dluxapps-yangman

[email protected]>feature:installodl-dluxapps-topology

[email protected]>feature:installodl-l2switch-all

[email protected]>feature:installwebconsole

[email protected]>feature:installodl-mdsal-apidocs

[email protected]>feature:installodl-ovsdb-southbound-api

Please check the below web link for OVSDB user guide:

http://docs.opendaylight.org/en/stable-carbon/user-guide/ovsdb-user-guide.html

 

2 Set up DC1 – Mininet

 

Create the custom topology file – “dc1.py”:

from mininet.topo import Topo

class MyTopo( Topo ):

    def__init__( self ):

        #initilaize topology  

       Topo.__init__( self )

        # addhosts and switches

        h11 =self.addHost( ‘h11‘,ip= ‘10.0.0.1‘)

        h12 =self.addHost( ‘h12‘,ip= ‘10.0.0.2‘)

        s11 =self.addSwitch( ‘s11‘ )

        s12 =self.addSwitch( ‘s12‘ )

        s10 =self.addSwitch( ‘s10‘ )

        # addlinks

       self.addLink(h11,s11)

       self.addLink(h12,s12)

       self.addLink(s12,s10)

       self.addLink(s10,s11)

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

 

Create the virtual DC1 with  “dc1.py”::

[email protected]:~$sudo mn --custom dc1.py --topo mytopo

Configure OVS to listen for the connection initiated by the OVSDB Southbound Plugin of OpenDaylight:

mininet>sh ovs-vsctl set-manager ptcp:6640

3 Set up DC2 – Mininet

 

Create the custom topology file – “dc2.py”:

 

from mininet.topo import Topo

class MyTopo( Topo ):

    def__init__( self ):

        #initilaize topology  

       Topo.__init__( self )

        # addhosts and switches

        h21 =self.addHost( ‘h21‘,ip= ‘10.0.0.3‘)

        h22 =self.addHost( ‘h22‘,ip= ‘10.0.0.4‘)

        s21 =self.addSwitch( ‘s21‘ )

        s22 =self.addSwitch( ‘s22‘ )

        s20 =self.addSwitch( ‘s20‘ )

        # addlinks

       self.addLink(h21,s21)

       self.addLink(h22,s22)

       self.addLink(s22,s20)

       self.addLink(s20,s21)

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

 

Create the virtual DC2 with “dc2.py”:

[email protected]:~$sudo mn --custom dc2.py --topo mytopo

Configure OVS to listen for the connection initiated by the OVSDB Southbound Plugin of OpenDaylight:

mininet>sh ovs-vsctlset-manager ptcp:6640

 

4 Python Programming to MakeAPI Calls

 

Install Geany IDE and the Requests Library in Python:

[email protected]:~$sudo apt-getinstall geany

[email protected]:~$geany

[email protected]:~ $pip installrequests

 

Set Build Commands of  Geany IDE:

Configure the OVSDB Southbound Plugin in OpenDaylight toactively connect to DC1 and DC2:

 

import requests

import json

header = {‘content-type‘: ‘application/json‘}

commamd10 = {"network-topology:node":  [{

                            "node-id":"ovsdb://DC1",

                            "connection-info":

                            {

                                "ovsdb:remote-port":"6640", "ovsdb:remote-ip": "192.168.100.144"   }}]}

commamd20 = {"network-topology:node":  [{

                            "node-id":"ovsdb://DC2",

                            "connection-info":

                            {

                                "ovsdb:remote-port":"6640", "ovsdb:remote-ip": "192.168.100.145"   }}]}


# Making the API Call on OpenDaylight toconnect to DC1

r1 = requests.put(url=‘http://192.168.100.129:8181/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2FDC1‘,

                                                                     data=json.dumps(commamd10),

                                                                     headers=header,

                                                                     auth=(‘admin‘,‘admin‘)

                                                                 )  

# Making the API Call on OpenDaylight to connect to DC2

r2 = requests.put(url=‘http://192.168.100.129:8181/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2FDC2‘,

                                                                     data=json.dumps(commamd20),

                                                                     headers=header,

                                                                     auth=(‘admin‘,‘admin‘)

                                                                 )  

 

Configure and manage the vxlan ports of DC1 and DC2:


import requests

import json

header = {‘content-type‘: ‘application/json‘}

commamd11 = { "termination-point":

                                                 [{

                                                                "tp-id":"vxlanport",

                                                                "ovsdb:name":"vxlanport",

                                                                "ovsdb:interface-type":"ovsdb:interface-type-vxlan",

                                                                "ovsdb:options":

                                                                [{

                                                                       "option":"remote_ip", "value": "192.168.100.145"

                                                                }]}]}

commamd21 = { "termination-point":

                                                 [{

                                                                "tp-id":"vxlanport",

                                                                "ovsdb:name":"vxlanport",

                                                                "ovsdb:interface-type":"ovsdb:interface-type-vxlan",

                                                                "ovsdb:options":

                                                                [{

                                                                         "option":"remote_ip", "value": "192.168.100.144"

                                                                }]}]}


# Making the API Call on OpenDaylight to create the vxlan port on s10 of DC1

r1 = requests.put(url=‘http://192.168.100.129:8181/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2FDC1%2Fbridge%2Fs10/termination-point/vxlanport‘,

                                                                     data=json.dumps(commamd11),

                                                                     headers=header,

                                                                     auth=(‘admin‘,‘admin‘)

                                                                 )  

# Making the API Call on OpenDaylight to create the vxlan port on s20 of DC2

r2 = requests.put(url=‘http://192.168.100.129:8181/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2FDC1%2Fbridge%2Fs20/termination-point/vxlanport‘,

                                                                     data=json.dumps(commamd21),

                                                                     headers=header,

                                                                     auth=(‘admin‘,‘admin‘)

                                                                 )  

 

5 Check the Network

 

Check DC1

mininet>sh netstat –an | grep 6640

mininet>sh ovs-vsctl show

Check DC2

mininet>sh netstat –an | grep 6640

mininet>sh ovs-vsctl show


Read the network topology from OpenDaylight by Python making API calls:

 

import requests

import json

header = {‘content-type‘: ‘application/json‘}

r = requests.get( url=‘http://192.168.100.129:8181/restconf/operational/network-topology:network-topology‘,

                                                                  headers=header,

                                                                  auth=(‘admin‘,‘admin‘)

                                                                )  

 

print(r.status_code)

print(r.headers[‘content-type‘])

print(r.url)

 

rj = r.json()

 

print(‘\n‘+rj[‘network-topology‘][‘topology‘][0][‘topology-id‘])

print(‘\n‘+rj[‘network-topology‘][‘topology‘][1][‘topology-id‘])

 

for node inrj[‘network-topology‘][‘topology‘][0][‘node‘]:

                print(‘\n‘+node[‘node-id‘])

                if‘termination-point‘ in node:

                                forport in node[‘termination-point‘]:

                                                print(‘----‘+ port[‘tp-id‘])

Make the API calls by Yangman:



时间: 2024-10-15 00:36:53

SDN实战:Build a VXLAN Tunnel by Making Python-based API Calls for DCI的相关文章

SDN实战: Build a mini-lab environment and practice SDN-IP/ONOS with GNS3, Mininet and VMware

SDN IN ACTION: Build a mini-lab environment and practice SDN-IP/ONOS with GNS3, Mininet and VMware    薛国锋  [email protected] 本文主要通过简单的实验,对SDN相关概念以及ONOS开源软件等建立一个感性的印象,加深对核心概念的理解. SDN-IP is to adopt SDN/OpenFlow switches to replace the traditional IP/M

使用ESNP完成SDN技术静态方式VXLAN实现同子网(不同VLAN)的通信

1.SDN线路 2006年斯坦福大学发布 OpenFlow,网络设备转发和控制面分离,通过集中的控制面实现网络流量的灵活控制华为数据中心SDN的核心特征是适度的转控分离结合之外, 通过管理与控制分离, 实现网络业务自动化发放, 助力数据中心业务实现敏捷发放. 当下的SDN商业产品 您可以看到思科.华为等传统网络产品大佬依旧走着"一条道走到黑"的路子,即自有控制器+自由硬件转发设备+VXLAN的路子.但请注意,"大佬决定历史" 2.华为SDN的控制器和Vxlan 华为

【课程分享】深入浅出微信公众平台实战开发(微网站、LBS云、Api接口调用、服务号高级接口)

深入浅出微信公众平台实战开发(微网站.LBS云.Api接口调用.服务号高级接口) 课程下载地址:链接:http://pan.baidu.com/share/link?shareid=2214724072&uk=3611155194 密码:glvc 一.本课程是怎么样的一门课程(全面介绍) 1.1.课程的背景 微信公众平台的火热程度已经不用多言,无论是个人还是企业,政府还是商家,都已经开始搭建微信公众平台,微信的作用已经被各界人士认可.微信公众平台的技术需求市场缺口巨大. 1.2.课程内容简介 本

SDN实战: Practice SDN/OpenFlow with LINC-Switch and OpenDaylight

SDN IN ACTION: Practice SDN/OpenFlow with LINC-Switch and OpenDaylight 薛国锋  [email protected] 本次实验,重点学习了Erlang语言.LINC软件OpenFlow交换机以及OpenDaylight开源控制器. Last time we had built anemulated environment based on ONOS and Mininet, today we are going to play

javamail模拟邮箱功能--邮件删除-中级实战篇【邮件标记方法】(javamail API电子邮件实例)

前言: JavaMail jar包下载地址:http://java.sun.com/products/javamail/downloads/index.html 本章可能是讲解javamail的最后一篇了,上次更新完查看方法后,本打算周末更新的,没想今天周五挺闲,就地正法算了...就赶紧再下班前写完了.阅读本章节前建议阅读之前章节,因为这章是在之前的基础上增加的业务方法,不看之前的可能有点云里雾里.  点我前往 邮件标志:是指给邮件message对象设置一个Flag内部类里的属性字段,标志类型会

javamail模拟邮箱功能--邮件回复-中级实战篇【邮件回复方法】(javamail API电子邮件实例)

引言: JavaMai下载地址l jar包:http://java.sun.com/products/javamail/downloads/index.html 此篇是紧随上篇文章而封装出来的,阅读本篇章建议先阅读上一篇  -->javamail模拟邮箱功能获取邮件内容-中级实战篇[内容|附件下载方法](javamail API电子邮件实例) 在上一篇中,讲解了邮件获取内容的两个方法(HTML和附件),简单介绍了邮件发送和内容获取的相同和不同之处,并且引入了新类-->javax.mail.St

超多慕课网实战教程破解自学教程百度云盘分享-Python/Java/前端后端/小程序/运维测试/人工智能

以下课程,需要的可以加我微*信:hgh813210,备注你需要的课程 Java企业级电商项目架构演进之路 Tomcat集群与Redis分布式百度云实战分享 前端成长必经之路 基于Storm构建实时热力分布项目实战 Spark Streaming实时流处理项目实战 以慕课网日志分析为例 进入大数据 Spark SQL 的世界 手工测试企业项目实践及面试提升 Webpack + React全栈工程架构项目实战精讲 深度学习之神经网络核心原理与算法 Android应用发展趋势必备武器 热修复与插件化

spring-boot实战【04】:Spring Boot构建RESTful API

@Controller:修饰class,用来创建处理http请求的对象@RestController:Spring4之后加入的注解,原来在@Controller中返回json需要@ResponseBody来配合,如果直接用@RestController替代@Controller就不需要再配置@ResponseBody,默认返回json格式.@RequestMapping:配置url映射 下面我们尝试使用Spring MVC来实现一组对User对象操作的RESTful API,配合注释详细说明在S

python:爬虫1——实战(下载一张图片、用Python模拟浏览器,通过在线的有道词典来对文本翻译)

一.下载一只猫 import urllib.request response = urllib.request.urlopen("http://cdn.duitang.com/uploads/item/201111/24/20111124222137_wHYwc.jpg") cat_img = response.read() with open('cat_0.jpeg', 'wb') as f: f.write(cat_img) urlopen()中的url可以是string,也可以是