SlideShare a Scribd company logo
1 of 17
Download to read offline
[Ryu_OpenFlow 1.3]
REST 연동
김지은
yeswldms@gmail.com
Ryu & REST API
•  Ryu, 웹서버기능 제공
: WSGI 같은 웹서버 기능, REST API 연동 가능
•  목표
1. MAC 주소 테이블 획득 API
: 스위칭 허브가 갖고 있는 MAC주소 테이블의 내용을 반환
: MAC 주소와 포트 번호의 Pair를 JSON 형식으로 반환
2. MAC 주소 테이블 등록 API
: MAC 주소와 포트 번호의 쌍을 MAC주소 테이블에 등록하고 스위치 플로우 항목에 추가
Simple_switch_rest_13.py
•  Download Sample Code
# wget https://github.com/osrg/ryu-book/blob/master/en/source/sources/simple_switch_rest_13.py
•  Simple_swtich_rest_13.py의 클래스
1, SimpleSwitchController : HTTP 요청을 받는 URL과 해당 메소드를 정의하는 컨트롤러 클래스
2. SimpleSwitchRest13 : 스위칭허브를 확장하고 MAC 주소 테이블을 업데이트하는 클래스
스위치에 플로우 항목을 추가 할 것이므로 FeatureReply메서드를 오버라이드하고 datapath 개체를 가짐
Class, SimpleSwitchRest13
•  View the Code
HTTP 요청을 받는 URL과 해당 메소드를 정의하는 컨트롤러 클래스
class SimpeSwitchRest13(simple_switch_13.SimpleSwitch13):
_CONTEXTS = { 'wsgi': WSGIApplication } # 클래스변수 _CONTEXT에서 Ryu의 WSGI와 호환되는 Web서버 클래스 지정
# wsgi라는 키에서 WSGI의 웹서버 인스턴스를 얻음
...
def __init__(self, *args, **kwargs):
super(SimpleSwitchRest13, self).__init__(*args, **kwargs)
self.switches = {}
wsgi = kwargs['wsgi'] # WSGIAplication의 인스턴스 얻기
wsgi.register(SimpleSwitchController, {simple_switch_instance_name : self}) # register메서드로 등록
... # register 메서드 실행 시, 컨트롤러의 생성자에서 SimpleSwitchRest13클래스의 인스턴스에 액세스 할 수 있도록
# simple_switch_api_app이라는 키 이름으로 dictionary 개체 전달
@set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
def switch_features_handler(self, ev): # 부모 클래스의 switch_features_handler를 오버라이딩
super(SimpleSwitchRest13, self).switch_features_handler(ev)
datapath = ev.msg.datapath # SwitchFeatures 이벤트가 발생한 시간에 이벤트 객체 ev의 datapath개체를 가져옴
self.switches[datapath.id] = datapath # 해당 객체를 switches에 저장
self.mac_to_port.setdefault(datapath.id, {}) # MAC주소 테이블에 초기값으로 빈 dictionary를 설정
...
Class, SimpleSwitchRest13
•  View the Code
def set_mac_to_port(self, dpid, entry): # 지정된 스위치에 MAC 주소와 포트를 등록하는 메소드, REST API가 PUT방식으로 호출될 때 실행
mac_table = self.mac_to_port.setdefault(dpid, {}) # MAC 주소 테이블 self.mac_to_port의 정보를 참조
datapath = self.switches.get(dpid)
entry_port = entry['port'] # mac, port값이 pair로
entry_mac = entry['mac']
if datapath is not None:
parser = datapath.ofproto_parser
if entry_port not in mac_table.values():
for mac, port in mac_table.items():
# from known device to new device
actions = [parser.OFPActionOutput(entry_port)]
match = parser.OFPMatch(in_port=port, eth_dst=entry_mac)
self.add_flow(datapath, 1, match, actions) # 플로우 항목 등록, 부모클래스의 add_flow()
# from new device to known device
actions = [parser.OFPActionOutput(port)]
match = parser.OFPMatch(in_port=entry_port, eth_dst=mac)
self.add_flow(datapath, 1, match, actions) # 플로우 항목 등록, 부모클래스의 add_flow()
mac_table.update({entry_mac : entry_port}) # entry에서 전달된 정보를 MAC주소 테이블에 저장
return mac_table
…
1 In_port=1, dst_mac = 00:00:00:00:00:02 Output=2
2 In_port=2, dst_mac = 00:00:00:00:00:01 Output=1
Host
A
Host
B
00:00:00:00:00:01, 1 00:00:00:00:00:02, 2
* 등록해야하는 플로우 항목
Class, SimpleSwitchController
•  View the Code
REST API에 대한 HTTP요청을 수락하는 컨트롤러 클래스
class SimpleSwitchController(ControllerBase):
def __init__(self, req, link, data, **config):
super(SimpleSwitchController, self).__init__(req, link, data, **config) # SimpleSwitchRest13 클래스의 인스턴스를 가져옴
self.simpl_switch_spp = data[simple_switch_instance_name]
...
# REST API URL과 해당 프로세스 구현부
@route('simpleswitch', url, methods=['GET'], requirements={'dpid': dpid_lib.DPID_PATTERN}) # route 데코레이터(설명 뒷장)
def list_mac_table(self, req, **kwargs): # REST API방식이 GET 방식이면 list_mac_table 메서드 호출
simple_switch = self.simpl_switch_spp
dpid = dpid_lib.str_to_dpid(kwargs['dpid']) # {dpid}부분에서 지정된 데이터 경로 ID에 해당하는 MAC주소 테이블 검색
if dpid not in simple_switch.mac_to_port: # 정보가 없는 스위치의 데이터 경로 ID를 지정하면 404에러코드 리턴
return Response(status=404)
mac_table = simple_switch.mac_to_port.get(dpid, {})
body = json.dumps(mac_table) # 검색된 MAC 주소 테이블의 항목이 Json형태로 변환되어 반환
return Response(content_type='application/json', body=body)
…
Class, SimpleSwitchController
•  View the Code
# MAC주소 테이블을 등록하는 REST API
@route('simpleswitch', url, methods=['PUT'], requirements={'dpid': dpid_lib.DPID_PATTERN}) # REST API가 PUT인 경우
def put_mac_table(self, req, **kwargs): # put_mac_table메서드 호출
simple_switch = self.simpl_switch_spp
dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
new_entry = eval(req.body)
if dpid not in simple_switch.mac_to_port: # Ryu에 연결하지 않은 다른 스위치의 경로 ID를 지정하면
return Response(status=404) # 404 error
try:
mac_table = simple_switch.set_mac_to_port(dpid, new_entry) # set_mac_to_port 메서드 호출
body = json.dumps(mac_table)
return Response(content_type='application/json', body=body)
except Exception as e:
return Response(status=500) # 실패시 500 error
...
* route 데코레이터
인수 이미
1 이름
2 URL 지정. http://<서버IP>:8080/simpleswitch/mactable/<데이터경로 ID>
3 HTTP 메서드 지정(GET 메서드 지정)
4 지정 위치의 형식 지정. URL(/simpleswitch/mactable/{dpid}의 {dpid}부분이 ryu/lib/dpid.py의 DPID_PATTERN에서
정의된 16진수여야 함
Ryubook Practice
•  이번엔,
MAC 주소 테이블을 중심으로 REST API를 추가하는 방법에 대해 설명
스위치에 원하는 플로우 항목을 추가하는 REST API 추가 및 사용
•  호스트에서 Mininet 실행
# mn --topo single,3 --mac --switch ovsk --controller remote –x
•  스위치에서 OpenFlow 프로토콜 설정
# ovs-vsctl set Bridge s1 protocols=OpenFlow13
확인
# ovs-ofctl -O OpenFlow13 dump-flows s1
OFPST_FLOW reply (OF1.3) (xid=0x2):
#
[참고] CURL
curl : http://lesstif.com/pages/viewpage.action?pageId=14745703
TEST
•  Mininet 실행 및 OpenFlow 1.3 설정
TEST
•  Mininet 실행 및 OpenFlow 1.3 설정
REST API를 추가한 스위칭 허브 실행
8080포트로 웹서버가 시작
TEST
•  Mininet shell에서 h1에서 h2로 ping
•  Ryu의 Packet-In 3번
TEST
•  스위칭 허브의 MAC 테이블 검색하는 REST API 실행
REST API를 호출하는 crul 명령
# curl –X GET http://127.0.0.1:8080/simpleswitch/mactable/00000000000000001
> h1, h2가 MAC 주소 테이블에 학습된 것을 확인
TEST
•  h1, h2를 MAC주소 테이블에 미리 저장 후 결과 확인
mininet 재실행 및 OpenFlow 1.3 재설정
스위치허브 재시작
TEST
•  h1, h2를 MAC주소 테이블에 미리 저장 후 결과 확인
MAC주소 테이블 업데이트를 위한 REST API를 호스트마다 호출
형식 : {“mac” : “MAC addr”, “port” : port number}
> h1, h2에 대응하는 플로우 항목이 스위치에 등록
TEST
•  h1, h2를 MAC주소 테이블에 미리 저장 후 결과 확인
h1에서 h2로 ping
TEST
•  h1, h2를 MAC주소 테이블에 미리 저장 후 결과 확인
1. 스위치에는 이미 플로우 항목이 존재하므로 Packet-In은 h1에서 h2로 ARP요청이 있을때만 발생.
•  2. 이후의 패킷 교환에서는 발생되지 않음
•  3. h2에서 h3으로라는 새로운 플로우 항목에 대하여 새로운 Packet-In발생
1.
2.
3.
이상입니다.
2015.05.09

More Related Content

What's hot

Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)
Sungjoon Yoon
 
Google Protocol buffer
Google Protocol bufferGoogle Protocol buffer
Google Protocol buffer
knight1128
 

What's hot (20)

파이썬 웹프로그래밍 1탄
파이썬 웹프로그래밍 1탄 파이썬 웹프로그래밍 1탄
파이썬 웹프로그래밍 1탄
 
One-day-codelab
One-day-codelabOne-day-codelab
One-day-codelab
 
제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처
제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처
제 4회 DGMIT R&D 컨퍼런스 : REST API - 리소스 지향적 아키텍처
 
Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)
 
Airflow를 이용한 데이터 Workflow 관리
Airflow를 이용한  데이터 Workflow 관리Airflow를 이용한  데이터 Workflow 관리
Airflow를 이용한 데이터 Workflow 관리
 
JSP 빠르게 시작하기
JSP 빠르게 시작하기JSP 빠르게 시작하기
JSP 빠르게 시작하기
 
[네이버오픈소스세미나] Pinpoint를 이용해서 서버리스 플랫폼 Apache Openwhisk 트레이싱하기 - 오승현
[네이버오픈소스세미나] Pinpoint를 이용해서 서버리스 플랫폼 Apache Openwhisk 트레이싱하기 - 오승현[네이버오픈소스세미나] Pinpoint를 이용해서 서버리스 플랫폼 Apache Openwhisk 트레이싱하기 - 오승현
[네이버오픈소스세미나] Pinpoint를 이용해서 서버리스 플랫폼 Apache Openwhisk 트레이싱하기 - 오승현
 
Json view 예제 설명
Json view 예제 설명Json view 예제 설명
Json view 예제 설명
 
NLog 소개
NLog 소개NLog 소개
NLog 소개
 
Pinpoint spring_camp 2015
Pinpoint spring_camp 2015Pinpoint spring_camp 2015
Pinpoint spring_camp 2015
 
막하는 스터디 첫 번째 만남 Node.js
막하는 스터디 첫 번째 만남 Node.js막하는 스터디 첫 번째 만남 Node.js
막하는 스터디 첫 번째 만남 Node.js
 
RESTful API 설계
RESTful API 설계RESTful API 설계
RESTful API 설계
 
How to use apache spark (based on the java example)
How to use apache spark (based on the java example)How to use apache spark (based on the java example)
How to use apache spark (based on the java example)
 
20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제
 
톰캣 #10-모니터링
톰캣 #10-모니터링톰캣 #10-모니터링
톰캣 #10-모니터링
 
파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄
 
파이썬 데이터베이스 연결 1탄
파이썬 데이터베이스 연결 1탄파이썬 데이터베이스 연결 1탄
파이썬 데이터베이스 연결 1탄
 
Browser Engineering - Ch1 Summary
Browser Engineering - Ch1 SummaryBrowser Engineering - Ch1 Summary
Browser Engineering - Ch1 Summary
 
Naver 오픈api-마이그레이션가이드 20160913-리뷰
Naver 오픈api-마이그레이션가이드 20160913-리뷰Naver 오픈api-마이그레이션가이드 20160913-리뷰
Naver 오픈api-마이그레이션가이드 20160913-리뷰
 
Google Protocol buffer
Google Protocol bufferGoogle Protocol buffer
Google Protocol buffer
 

Viewers also liked

Openstack Neutron and SDN
Openstack Neutron and SDNOpenstack Neutron and SDN
Openstack Neutron and SDN
inakipascual
 
Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)
MongoSF
 
Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010
Dirkjan Bussink
 
Introduction to tempest
Introduction to tempest Introduction to tempest
Introduction to tempest
openstackindia
 

Viewers also liked (20)

20150509 unix v6로 배우는 커널의 원리와 구조 3 김지은
20150509 unix v6로 배우는 커널의 원리와 구조 3 김지은20150509 unix v6로 배우는 커널의 원리와 구조 3 김지은
20150509 unix v6로 배우는 커널의 원리와 구조 3 김지은
 
Pgcon2012 ori-20120224
Pgcon2012 ori-20120224Pgcon2012 ori-20120224
Pgcon2012 ori-20120224
 
Introduction to Software Defined Networking and OpenStack Neutron
Introduction to Software Defined Networking and OpenStack NeutronIntroduction to Software Defined Networking and OpenStack Neutron
Introduction to Software Defined Networking and OpenStack Neutron
 
Openstack Neutron and SDN
Openstack Neutron and SDNOpenstack Neutron and SDN
Openstack Neutron and SDN
 
Debugging Ruby Systems
Debugging Ruby SystemsDebugging Ruby Systems
Debugging Ruby Systems
 
Debugging Ruby
Debugging RubyDebugging Ruby
Debugging Ruby
 
Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)
 
Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010Rubinius @ RubyAndRails2010
Rubinius @ RubyAndRails2010
 
OpenSource Hardware -Debian Way
OpenSource Hardware -Debian WayOpenSource Hardware -Debian Way
OpenSource Hardware -Debian Way
 
Operating OPNFV
Operating OPNFVOperating OPNFV
Operating OPNFV
 
OpenStack@Mini-Deb Conf'16 Mumbai
OpenStack@Mini-Deb Conf'16 MumbaiOpenStack@Mini-Deb Conf'16 Mumbai
OpenStack@Mini-Deb Conf'16 Mumbai
 
Your first patch to OpenStack
Your first patch to OpenStackYour first patch to OpenStack
Your first patch to OpenStack
 
Copr HD OpenStack Day India
Copr HD OpenStack Day IndiaCopr HD OpenStack Day India
Copr HD OpenStack Day India
 
Deploying openstack using ansible
Deploying openstack using ansibleDeploying openstack using ansible
Deploying openstack using ansible
 
The OpenStack Contribution Workflow
The OpenStack Contribution WorkflowThe OpenStack Contribution Workflow
The OpenStack Contribution Workflow
 
Your first patch to open stack
Your first patch to open stackYour first patch to open stack
Your first patch to open stack
 
Open stack qa and tempest
Open stack qa and tempestOpen stack qa and tempest
Open stack qa and tempest
 
Guts & OpenStack migration
Guts & OpenStack migrationGuts & OpenStack migration
Guts & OpenStack migration
 
OpenStack Storage Buddy Ceph
OpenStack Storage Buddy CephOpenStack Storage Buddy Ceph
OpenStack Storage Buddy Ceph
 
Introduction to tempest
Introduction to tempest Introduction to tempest
Introduction to tempest
 

Similar to Ryu with OpenFlow 1.3, REST API

SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8
Sangmin Lee
 
Tcp server / client
Tcp server / clientTcp server / client
Tcp server / client
문익 장
 
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
흥배 최
 

Similar to Ryu with OpenFlow 1.3, REST API (20)

Spring boot actuator
Spring boot   actuatorSpring boot   actuator
Spring boot actuator
 
막하는스터디 두번째만남 Express(20151025)
막하는스터디 두번째만남 Express(20151025)막하는스터디 두번째만남 Express(20151025)
막하는스터디 두번째만남 Express(20151025)
 
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjsNodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs
 
Startup JavaScript 8 - NPM, Express.JS
Startup JavaScript 8 - NPM, Express.JSStartup JavaScript 8 - NPM, Express.JS
Startup JavaScript 8 - NPM, Express.JS
 
7가지 동시성 모델 람다아키텍처
7가지 동시성 모델  람다아키텍처7가지 동시성 모델  람다아키텍처
7가지 동시성 모델 람다아키텍처
 
TR 069 클라이언트 검토자료 3편
TR 069 클라이언트 검토자료 3편TR 069 클라이언트 검토자료 3편
TR 069 클라이언트 검토자료 3편
 
Lam pstack
Lam pstackLam pstack
Lam pstack
 
SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8
 
Mean 스택을 사용한 IoT 개발
Mean 스택을 사용한 IoT 개발Mean 스택을 사용한 IoT 개발
Mean 스택을 사용한 IoT 개발
 
Java8 람다
Java8 람다Java8 람다
Java8 람다
 
20201121 코드 삼분지계
20201121 코드 삼분지계20201121 코드 삼분지계
20201121 코드 삼분지계
 
2.Connect Sunshine to the Cloud - 시온고 안드로이드 스터디
2.Connect Sunshine to the Cloud - 시온고 안드로이드 스터디2.Connect Sunshine to the Cloud - 시온고 안드로이드 스터디
2.Connect Sunshine to the Cloud - 시온고 안드로이드 스터디
 
Programming Cascading
Programming CascadingProgramming Cascading
Programming Cascading
 
Nodejs express
Nodejs expressNodejs express
Nodejs express
 
모델링 연습 리뷰
모델링 연습 리뷰모델링 연습 리뷰
모델링 연습 리뷰
 
Tcp server / client
Tcp server / clientTcp server / client
Tcp server / client
 
Presto User & Admin Guide
Presto User & Admin GuidePresto User & Admin Guide
Presto User & Admin Guide
 
Booting Spring Data REST
Booting Spring Data RESTBooting Spring Data REST
Booting Spring Data REST
 
리스펙토링 세미나 - 웹 브라우저 동작 개념, Node.js를 통한 서버 이해, REST API
리스펙토링 세미나 - 웹 브라우저 동작 개념, Node.js를 통한 서버 이해, REST API리스펙토링 세미나 - 웹 브라우저 동작 개념, Node.js를 통한 서버 이해, REST API
리스펙토링 세미나 - 웹 브라우저 동작 개념, Node.js를 통한 서버 이해, REST API
 
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
 

More from jieun kim

More from jieun kim (12)

KrDAG 오픈소스를 활용하여 웹블로그 만들기_김지은_201603
KrDAG 오픈소스를 활용하여 웹블로그 만들기_김지은_201603 KrDAG 오픈소스를 활용하여 웹블로그 만들기_김지은_201603
KrDAG 오픈소스를 활용하여 웹블로그 만들기_김지은_201603
 
OpenStack Korea 2015 상반기스터디(devops) 스크립트로 오픈스택 설치하기 20150728
OpenStack Korea 2015 상반기스터디(devops) 스크립트로 오픈스택 설치하기 20150728OpenStack Korea 2015 상반기스터디(devops) 스크립트로 오픈스택 설치하기 20150728
OpenStack Korea 2015 상반기스터디(devops) 스크립트로 오픈스택 설치하기 20150728
 
150625 마이크로커널 운영체제 김지은
150625 마이크로커널 운영체제 김지은150625 마이크로커널 운영체제 김지은
150625 마이크로커널 운영체제 김지은
 
150326 openstack, glance 김지은
150326 openstack, glance 김지은150326 openstack, glance 김지은
150326 openstack, glance 김지은
 
집단지성프로그래밍 05. 최적화(kayak.ipynb) 김지은_20150522
집단지성프로그래밍 05. 최적화(kayak.ipynb) 김지은_20150522집단지성프로그래밍 05. 최적화(kayak.ipynb) 김지은_20150522
집단지성프로그래밍 05. 최적화(kayak.ipynb) 김지은_20150522
 
집단지성프로그래밍 05. 최적화(optimization.ipynb) 김지은_20150522
집단지성프로그래밍 05. 최적화(optimization.ipynb) 김지은_20150522집단지성프로그래밍 05. 최적화(optimization.ipynb) 김지은_20150522
집단지성프로그래밍 05. 최적화(optimization.ipynb) 김지은_20150522
 
집단지성프로그래밍 05. 최적화(optimization) 김지은_20150522
집단지성프로그래밍 05. 최적화(optimization) 김지은_20150522집단지성프로그래밍 05. 최적화(optimization) 김지은_20150522
집단지성프로그래밍 05. 최적화(optimization) 김지은_20150522
 
20150509 unix v6로 배우는 커널의 원리와 구조 4 김지은
20150509 unix v6로 배우는 커널의 원리와 구조 4 김지은20150509 unix v6로 배우는 커널의 원리와 구조 4 김지은
20150509 unix v6로 배우는 커널의 원리와 구조 4 김지은
 
Build the OpenStack Cloud with Neutron Networing, IceHouse
Build the OpenStack Cloud with Neutron Networing, IceHouseBuild the OpenStack Cloud with Neutron Networing, IceHouse
Build the OpenStack Cloud with Neutron Networing, IceHouse
 
20150502 unix v6로 배우는 커널의 원리와 구조 1 김지은
20150502 unix v6로 배우는 커널의 원리와 구조 1 김지은20150502 unix v6로 배우는 커널의 원리와 구조 1 김지은
20150502 unix v6로 배우는 커널의 원리와 구조 1 김지은
 
150416 OpenStack Networking with Neutron Jieun, Kim
150416 OpenStack Networking with Neutron Jieun, Kim150416 OpenStack Networking with Neutron Jieun, Kim
150416 OpenStack Networking with Neutron Jieun, Kim
 
resource on openstack
 resource on openstack resource on openstack
resource on openstack
 

Ryu with OpenFlow 1.3, REST API

  • 2. Ryu & REST API •  Ryu, 웹서버기능 제공 : WSGI 같은 웹서버 기능, REST API 연동 가능 •  목표 1. MAC 주소 테이블 획득 API : 스위칭 허브가 갖고 있는 MAC주소 테이블의 내용을 반환 : MAC 주소와 포트 번호의 Pair를 JSON 형식으로 반환 2. MAC 주소 테이블 등록 API : MAC 주소와 포트 번호의 쌍을 MAC주소 테이블에 등록하고 스위치 플로우 항목에 추가
  • 3. Simple_switch_rest_13.py •  Download Sample Code # wget https://github.com/osrg/ryu-book/blob/master/en/source/sources/simple_switch_rest_13.py •  Simple_swtich_rest_13.py의 클래스 1, SimpleSwitchController : HTTP 요청을 받는 URL과 해당 메소드를 정의하는 컨트롤러 클래스 2. SimpleSwitchRest13 : 스위칭허브를 확장하고 MAC 주소 테이블을 업데이트하는 클래스 스위치에 플로우 항목을 추가 할 것이므로 FeatureReply메서드를 오버라이드하고 datapath 개체를 가짐
  • 4. Class, SimpleSwitchRest13 •  View the Code HTTP 요청을 받는 URL과 해당 메소드를 정의하는 컨트롤러 클래스 class SimpeSwitchRest13(simple_switch_13.SimpleSwitch13): _CONTEXTS = { 'wsgi': WSGIApplication } # 클래스변수 _CONTEXT에서 Ryu의 WSGI와 호환되는 Web서버 클래스 지정 # wsgi라는 키에서 WSGI의 웹서버 인스턴스를 얻음 ... def __init__(self, *args, **kwargs): super(SimpleSwitchRest13, self).__init__(*args, **kwargs) self.switches = {} wsgi = kwargs['wsgi'] # WSGIAplication의 인스턴스 얻기 wsgi.register(SimpleSwitchController, {simple_switch_instance_name : self}) # register메서드로 등록 ... # register 메서드 실행 시, 컨트롤러의 생성자에서 SimpleSwitchRest13클래스의 인스턴스에 액세스 할 수 있도록 # simple_switch_api_app이라는 키 이름으로 dictionary 개체 전달 @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER) def switch_features_handler(self, ev): # 부모 클래스의 switch_features_handler를 오버라이딩 super(SimpleSwitchRest13, self).switch_features_handler(ev) datapath = ev.msg.datapath # SwitchFeatures 이벤트가 발생한 시간에 이벤트 객체 ev의 datapath개체를 가져옴 self.switches[datapath.id] = datapath # 해당 객체를 switches에 저장 self.mac_to_port.setdefault(datapath.id, {}) # MAC주소 테이블에 초기값으로 빈 dictionary를 설정 ...
  • 5. Class, SimpleSwitchRest13 •  View the Code def set_mac_to_port(self, dpid, entry): # 지정된 스위치에 MAC 주소와 포트를 등록하는 메소드, REST API가 PUT방식으로 호출될 때 실행 mac_table = self.mac_to_port.setdefault(dpid, {}) # MAC 주소 테이블 self.mac_to_port의 정보를 참조 datapath = self.switches.get(dpid) entry_port = entry['port'] # mac, port값이 pair로 entry_mac = entry['mac'] if datapath is not None: parser = datapath.ofproto_parser if entry_port not in mac_table.values(): for mac, port in mac_table.items(): # from known device to new device actions = [parser.OFPActionOutput(entry_port)] match = parser.OFPMatch(in_port=port, eth_dst=entry_mac) self.add_flow(datapath, 1, match, actions) # 플로우 항목 등록, 부모클래스의 add_flow() # from new device to known device actions = [parser.OFPActionOutput(port)] match = parser.OFPMatch(in_port=entry_port, eth_dst=mac) self.add_flow(datapath, 1, match, actions) # 플로우 항목 등록, 부모클래스의 add_flow() mac_table.update({entry_mac : entry_port}) # entry에서 전달된 정보를 MAC주소 테이블에 저장 return mac_table … 1 In_port=1, dst_mac = 00:00:00:00:00:02 Output=2 2 In_port=2, dst_mac = 00:00:00:00:00:01 Output=1 Host A Host B 00:00:00:00:00:01, 1 00:00:00:00:00:02, 2 * 등록해야하는 플로우 항목
  • 6. Class, SimpleSwitchController •  View the Code REST API에 대한 HTTP요청을 수락하는 컨트롤러 클래스 class SimpleSwitchController(ControllerBase): def __init__(self, req, link, data, **config): super(SimpleSwitchController, self).__init__(req, link, data, **config) # SimpleSwitchRest13 클래스의 인스턴스를 가져옴 self.simpl_switch_spp = data[simple_switch_instance_name] ... # REST API URL과 해당 프로세스 구현부 @route('simpleswitch', url, methods=['GET'], requirements={'dpid': dpid_lib.DPID_PATTERN}) # route 데코레이터(설명 뒷장) def list_mac_table(self, req, **kwargs): # REST API방식이 GET 방식이면 list_mac_table 메서드 호출 simple_switch = self.simpl_switch_spp dpid = dpid_lib.str_to_dpid(kwargs['dpid']) # {dpid}부분에서 지정된 데이터 경로 ID에 해당하는 MAC주소 테이블 검색 if dpid not in simple_switch.mac_to_port: # 정보가 없는 스위치의 데이터 경로 ID를 지정하면 404에러코드 리턴 return Response(status=404) mac_table = simple_switch.mac_to_port.get(dpid, {}) body = json.dumps(mac_table) # 검색된 MAC 주소 테이블의 항목이 Json형태로 변환되어 반환 return Response(content_type='application/json', body=body) …
  • 7. Class, SimpleSwitchController •  View the Code # MAC주소 테이블을 등록하는 REST API @route('simpleswitch', url, methods=['PUT'], requirements={'dpid': dpid_lib.DPID_PATTERN}) # REST API가 PUT인 경우 def put_mac_table(self, req, **kwargs): # put_mac_table메서드 호출 simple_switch = self.simpl_switch_spp dpid = dpid_lib.str_to_dpid(kwargs['dpid']) new_entry = eval(req.body) if dpid not in simple_switch.mac_to_port: # Ryu에 연결하지 않은 다른 스위치의 경로 ID를 지정하면 return Response(status=404) # 404 error try: mac_table = simple_switch.set_mac_to_port(dpid, new_entry) # set_mac_to_port 메서드 호출 body = json.dumps(mac_table) return Response(content_type='application/json', body=body) except Exception as e: return Response(status=500) # 실패시 500 error ... * route 데코레이터 인수 이미 1 이름 2 URL 지정. http://<서버IP>:8080/simpleswitch/mactable/<데이터경로 ID> 3 HTTP 메서드 지정(GET 메서드 지정) 4 지정 위치의 형식 지정. URL(/simpleswitch/mactable/{dpid}의 {dpid}부분이 ryu/lib/dpid.py의 DPID_PATTERN에서 정의된 16진수여야 함
  • 8. Ryubook Practice •  이번엔, MAC 주소 테이블을 중심으로 REST API를 추가하는 방법에 대해 설명 스위치에 원하는 플로우 항목을 추가하는 REST API 추가 및 사용 •  호스트에서 Mininet 실행 # mn --topo single,3 --mac --switch ovsk --controller remote –x •  스위치에서 OpenFlow 프로토콜 설정 # ovs-vsctl set Bridge s1 protocols=OpenFlow13 확인 # ovs-ofctl -O OpenFlow13 dump-flows s1 OFPST_FLOW reply (OF1.3) (xid=0x2): # [참고] CURL curl : http://lesstif.com/pages/viewpage.action?pageId=14745703
  • 9. TEST •  Mininet 실행 및 OpenFlow 1.3 설정
  • 10. TEST •  Mininet 실행 및 OpenFlow 1.3 설정 REST API를 추가한 스위칭 허브 실행 8080포트로 웹서버가 시작
  • 11. TEST •  Mininet shell에서 h1에서 h2로 ping •  Ryu의 Packet-In 3번
  • 12. TEST •  스위칭 허브의 MAC 테이블 검색하는 REST API 실행 REST API를 호출하는 crul 명령 # curl –X GET http://127.0.0.1:8080/simpleswitch/mactable/00000000000000001 > h1, h2가 MAC 주소 테이블에 학습된 것을 확인
  • 13. TEST •  h1, h2를 MAC주소 테이블에 미리 저장 후 결과 확인 mininet 재실행 및 OpenFlow 1.3 재설정 스위치허브 재시작
  • 14. TEST •  h1, h2를 MAC주소 테이블에 미리 저장 후 결과 확인 MAC주소 테이블 업데이트를 위한 REST API를 호스트마다 호출 형식 : {“mac” : “MAC addr”, “port” : port number} > h1, h2에 대응하는 플로우 항목이 스위치에 등록
  • 15. TEST •  h1, h2를 MAC주소 테이블에 미리 저장 후 결과 확인 h1에서 h2로 ping
  • 16. TEST •  h1, h2를 MAC주소 테이블에 미리 저장 후 결과 확인 1. 스위치에는 이미 플로우 항목이 존재하므로 Packet-In은 h1에서 h2로 ARP요청이 있을때만 발생. •  2. 이후의 패킷 교환에서는 발생되지 않음 •  3. h2에서 h3으로라는 새로운 플로우 항목에 대하여 새로운 Packet-In발생 1. 2. 3.