1 / 46

OSGi & U PnP 임베디드 시스템 특강 Spring 2009

OSGi & U PnP 임베디드 시스템 특강 Spring 2009. 한국외국어대학교 컴퓨터 및 정보통신공학과 200930251 최화영 ( hychoe@dislab.hufs.ac.kr). Contents. OSGi OSGi 란 ? OSGi 구성요소 OSGi Framework package Framework Bundle Service & Bundle life cycle Device Manager HttpService & LogService OSGi Bundle & Service 생성

jariath
Download Presentation

OSGi & U PnP 임베디드 시스템 특강 Spring 2009

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OSGi & UPnP 임베디드 시스템 특강 Spring 2009 한국외국어대학교 컴퓨터 및 정보통신공학과200930251 최화영(hychoe@dislab.hufs.ac.kr)

  2. Contents • OSGi • OSGi란? • OSGi구성요소 • OSGi Framework package • Framework • Bundle • Service & Bundle life cycle • Device Manager • HttpService & LogService • OSGi Bundle & Service 생성 • OSGiFramework의 구현 • Bundle의 설치, 삭제, 실행, 정지 • Framework & Bundle • Example: Equinox기반 OSGiBundle • UPnP • Home Network Middleware • UPnP란? • UPnP Entity • Protocol Stack Architecture • Protocol Stack • SSDP & GENA • SOAP • XML • UPnP Networking • Addressing • Discovery • Description • Control • Eventing • UPnP Control Point • Setup & Initialization • Discover • Description • Event – Subscribe, notify • Invoking Action • Shutting down Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  3. OSGi - Open Service Gateway Initiative Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  4. OSGi • OSGi(Open Service Gateway Initiative) • Service Gateway • 음성과 데이터, 멀티미디어 통신을 통합 관리하여 가정과 사무실 등으로 전송해주고 서비스해 주는 기능을 수행. • OSGi의 장점 • 하드웨어 플랫폼과 OS에 독립적 • 공통의 응용 API를 구현하므로 응용 분야에 독립적 • 하나의 플랫폼에 여러 종류의 서비스 제공자가 서비스를 제공 • 받을 수 있는 서비스가 다양 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  5. OSGi구성요소 • 주요 구성 요소 • Bundle : 서비스를 제공하기 위한 기능적 배포 단위 • Framework : 번들의 라이프 사이클을 관리하는 번들 실행 환경 • Service : 특정 기능을 수행하는 자바 인터페이스와 실제 구현 객체 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  6. OSGi Framework Package Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  7. Framework • OSGi Framework • 연속적으로 동작할 수 있는 애플리케이션을 작성할 수 있는 context제공이 목적. • 자바 프로그래밍 언어가 가진 코드의 네트워크 이동성을 이용 • 컴포넌트 기반의 개발 환경 제공 • 보다 풍부하고 구조적인 서비스 개발 가능 • OSGi Framework이 제공하고자 하는 환경의 목표 • 애플리케이션이 실행 중에도 동적으로 다운로드 및 업그레이드가 가능 • 제한된 메모리 디바이스 사용 가능 • 효율적이고 통합된 컴포넌트 개발환경 제공 • 애플리케이션 간의 의존성에 대한 관리 기능 제공 • 확장 가능성(scalable) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  8. Bundle • Bundle이란 ? • Unit of modularization – OSGi스펙 정의 • Bundle = JAR + OSGi정보(META-INF/MANIFEST.MF) • Bundle의 상태 • INSTALLED . 번들이 성공적으로 인스톨 된 상태 • RESOLVED . 번들이 현재 START 되거나 STOP가 될 준비가 되어 있는 상태 • STARTING . 번들이 START가 되고 있는 상태, 아직 return이 안된 상태. • STOPPING . 번들이 STOP하고 있는 상태, 아직 return이 안 된 상태 • ACTIVE . 번들이 현재 동작하고 있는 상태 • UNINSTALLED . 번들이 uninstall된 상태. Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  9. Service & Bundle life cycle Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  10. Device Manager • Device Manager • 디바이스 탐지(Device Detection) • 모든 새로운 디바이스인터페이스 객체를 검색 • 위치 단계(Location Phase) • 새로 추가된 모든 드라이버를 DriverLocator를 이용해 위치시킴 • 경선 단계(Bidding phase) • 각 드라이버를 디바이스 상에서 경선에 참여 • 추가 단계(Attach Phase) • 경선 단계에서의 최상위 드라이버 추가 • 청소 단계(Cleanup Phase) • idle 드라이버를 청소 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  11. Http & Log Service • HttpService • Framework 내의 다른 번들이 리소스를 등록할 수 있게 함. • HTTP를 통해서 Servlet에 접근할 수 있게 함. • 등록 가능 Entity • Servlet : Java Servlet API를 구현한 객체 • Resource : HTML 파일, GIF 파일, Class 파일 포함 • LogService • 이벤트와 에러 상황에 대한 리포트가 목적. • 번들로부터의 로그 요청을 받아들임 • LogReaderService : 다른 번들의 로그 항목을 읽어 들이는 역할 • 4개의 인터페이스로 구성 • LogEntry, LogListener, LogReaderService, LogService Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  12. OSGi Bundle & Service 생성 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  13. OSGi Framework의 구현(1) • 번들의 설치와 삭제 • 설치과정 - BundleContext.installBundle() 메쏘드를호출. • 번들이 이미 인스톨되어 있는 지를 확인 • 번들의 코드 베이스로부터 내용을 얻어 옴. • 새로운 번들을 생성하고 관련된 리소스들을 할당 • 번들의 상태를 INSTALLED 상태로변경 • 번들의 클래스 패스 및 네이티브 코드 의존성을 해결 • INSTALLED 타입의BundleEvent를브로드캐스트 • 위의 과정에서 예외가 발생하지 않았으면 종료하고, 예외가발생하면원래의상태로되돌리고종료 • 삭제과정 - Bundle.uninstall() 메쏘드에서구현됨. • 번들의 상태가ACTIVE이면, 이 번들을정지. • UNINSTALLED 타입의BundleEvent를브로드캐스팅 • 번들의 상태를 UNINSTALLED 상태로변경. • 번들이 점유하고 있는 영속 저장공간을 반환. Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  14. OSGi Framework의 구현(2) • 번들의 실행 • Framework가 Bundle.start() 메소드를호출. • 현재의 번들의 상태를 체크한다. • 현재 번들의 상태에 따라 다음과 같이 처리 • UNINSTALLED – IllegalStateException발생 • STARTING 혹은 STOPPING - 일정한시간동안대기(wait) • ACTIVE – 막바로종료함 • INSTALLED – 의존성을해결(resolve)함. (성공 후 RESOLVED 상태로전환됨) • RESOLVED – 다음단계로진행 • 번들의 상태를 STARTING 상태로변환함 • BundleActivator.start() 메쏘드호출 • 영속 저장공간에 번들의 상태를 시작된 상태로 기록 • STARTED 타입의번들이벤트를브로드캐스트. Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  15. OSGi Framework의 구현(3) • 번들의 정지 • Bundle.stop() 메소드를호출 • 현재의 번들의 상태를 체크 • 현재 번들의 상태에 따라 다음과 같이 처리 • UNINSTALLED – IllegalStateException발생 • STARTING 혹은 STOPPING - 일정한시간동안대기(wait) • INSTALLED 혹은 RESOLVED – 막바로리턴 • ACTIVE – 다음단계로진행 • 번들의 상태를 STOPPING 상태로변환함 • 영속 저장공간에 번들의 상태를 정지된 상태로 기록 • BundleActivator.stop() 메쏘드호출 • 이벤트 리스너와 이 번들에 의해 등록된 서비스의 등록을 모두 취소 • 번들의 상태를RESOLVED로변환함 • STOPPED 타입의BundleEvent를브로드캐스트 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  16. Framework & Bundle • 프레임워크와 서비스 번들의 상호 작용 Bundle Service Registry Hash Table Service Implementation (UPnPImpl) Name Service implementation Service Interface (UPnPService) Name Service implementation BundleActivator Start() Stop() Bundle Context Framework Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  17. Example: Equinox기반 OSGi Bundle(1) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  18. Example: Equinox기반 OSGiBundle(2) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  19. Example: Equinox기반 OSGiBundle(3) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  20. Example: Equinox기반 OSGiBundle(4) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  21. Example: Equinox기반 OSGi Bundle Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  22. UPnP - Universal Plug and Play Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  23. Home Network Middleware • 서로 다른 기종간의 서버와 클라이언트를 연결해주는 소프트웨어 • 애플리케이션이 어떤 시스템 환경에서도 동작할 수 있도록 지원해 주는 역할 • 모든 홈 네트워크를 구성하는데 있어 중심이 되는 소프트웨어 • 가정에 여러 개의 기기가 같거나 다른 홈 네트워킹 미디어에 의해 연결되어 있을 때, 각각의 기기 간의 인터페이스 사이에 완충 역할을 해 줄 중간층이 없이는 이들 기기 간의 제어나 데이터의 전송은 불가능함 • 기기간 완충 역할 • 미들웨어 기술을 이용하면 • 분산형 연산 환경과 서비스를 지원 가능 • 데이터 네트워크와 제어 네트워크를 쉽게 통합 가능 • 다양한 홈 네트워킹 기술을 이용한 기기 간의 데이터를 통합하기가 쉬움 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  24. UPnP(Universal Plug and Play) • UPnP • pc와 정보가전들 간에 peer-to-peer 연결을 위한 미들웨어 • 이미 검증된 네트워크 프로토콜 및 웹 기술을 기반으로 홈 네트워킹 기기간의 제어 모델 구현 • Feature • 개방형 분산 networking architecture • TCP/IP 기반의 Web 기술 활용가능 • network에 연결된 기기들 사이에 control 정보와 data 정보를 전달 • Device Driver 불필요 • OS나 application을 구현한 language에 독립적 UPnP에서 application을 위한 API를 규격화하지 않음. Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  25. UPnP Entity • Controllers(or control points) • UPnP Device의 표준서비스를 UPnP 방식으로 제어할 수 있는 장치 • Controlled Devices • UPnP Forum에서 정의한 Device의 표준 서비스를 지원하는 Device Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  26. UPnP Protocol Stack Architecture • IP기반의 Protocol 기술로써 IP가 지원되는 네트워크이면 전송 매체와 상관없이 지원 가능. UPnP Vendor Defined UPnP Forum Working Committee Defined UPnP Device Architecture Defined HTTPMU (Discovery) HTTPU (Discovery) SOAP (Control) HTTP SSDP SSDP GENA (Events) HTTP (Description) GENA UDP TCP IP Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  27. UPnP Protocol Stack • TPC/IP • HTTPU(HTTP over UDP)/HTTPMU(HTTP Multicast over UDP) • SSDP(Simple Service Discovery Protocol) • GENA(General Event Notification Architecture) • SOAP(Simple Object Access Protocol) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  28. SSDP & GENA • SSDP(Simple Service Discovery Protocol ) • 네트워크 서비스들을 발견하는 방식을 정의 • Device들은 SSDP를 이용하여 자신을 광고할 수 있음. • GENA(General Event Notification Architecture) • TCP/IP를 통한 HTTP 및 멀티캐스트 UDP를 사용하여 notification을 송수신하는 기능을 제공하기 위해 정의 • Event실행을 위하여 가입자 및 통보 발행자의 개념을 정의 • UPnP는 GENA 포맷을 사용하여 존재 발표 내용을 생성한 후 • SSDP 프로토콜을 통하여 전송하고 UPnP 이벤트 작업의 서비스 상태 변화를 신호로 알려주는 기능을 함. Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  29. SOAP • SOAP(Simple Object Access Protocol) • 원격 프로시저 호출을 수행하기 위한 XML문서와 HTTP의 사용 방법을 정의 • 기존의 인터넷 인프라를 통하여 방화벽 및 프록시에 아주 효율적인 기능 수행 • 보안용 SSL(Secure Sockets Layer)를 활용 • HTTP의 연결 관리 기능을 활용 • 인터넷 분산형 통신을 웹 페이지에 접속하는 것 만큼 쉽게 만듦. • UPnP는 SOAP를 사용하여 제어 메시지를 장치들로 전송 • 그 결과 및 오류 내역을 제어 포인트로 반환하는 역할 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  30. XML • XML(Extensible Markup Language) • 웹 상의 구조화된 데이터를 위한 범용 포맷 • 태그와 특성(Tags, Attributes)사용 • HTML과 비슷하나 사용자가 태그와 특성을 정의할 수 있음. • 다양한 문서 형태에 적합한 스키마를 정의하는데 아주 적합 • UPnP에서 장치 및 서비스 설명서, 제어 메시지 및 이벤트에 사용 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  31. 수동기기(Controlled Device) Gateway 능동기기(Control Point) Multi ISP Presentation Server (HTML UI) Web Browser Gateway (internet sharing, Firewell, VPN…) 5 Presentation 5 Control point controls device and/or views device status using HTML UI Event Client Event Server 4 Eventing: GENA 4 Control point listens to state changes of device Control Server (실제 구동 제어) Control Client 3 Control: SOAP 3 Control point invokes actions on device Description Server (Device, Service by XML) Description Client 2 Description 2 Control point learns about device capabilities 외부망 모뎀 접속 Discovery Client Discovery Server (기본 제원 설명) 1 Discovery: GENA, SSDP 1 Control point finds interesting device 0 Addressing: (1) DHCP / AutoIP+ARP (2) DNS 0 Control point and device get addresses UPnP Networking Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  32. Addressing(step0) • Addressing(step 0) • DHCP(Dynamic Host Configuration Protocol) • Auto-IP • Addressing 절차 • UPnP 접속 규격을 따르는 기기가 Network에 접속 • DHCP를 지원하는 host가 주위에 있는가 확인. • 주위에 없을 경우 • Auto-IP방식에 의해서 IP를 할당 • ARP(Address Resolution Protocol)를 이용해서 IP를 검증 • Auto-IP방식에 의해 IP 설정했을 경우라도 • 일정한 주기로 DHCP 지원 host 존재 여부 확인 • 발견될 경우, DHCP에 의해 IP 할당  IP를 재설정 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  33. Discovery(step1) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  34. Description(step2) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  35. Control(step3) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  36. Eventing(step4) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  37. Presentation(step5) Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  38. UPnP Control Point • 1.Setup &Initialization • 2.Discover • 3.Description • 4.Event – Subscribe, Notify • 5.Control – Action • 6.Shutting Down Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  39. Setup and Initialization • TvCtrlPointStart( ) • UPnP의 Control Point를 실행시킬 경우 처음으로 호출되는 함수. • Control Point를 작동시키는데 필요한 여러 가지 초기화 작업 수행. • Control command Thread 초기화 & 시작 • Time Thread 초기화 & 시작 • IP, Port 얻기 • UPnP 작동에 필요한 초기화 short int port = 0; char *ip_address = NULL; rc = UpnpInit( ip_address, port ); if (UPNP_E_SUCCESS != rc) { SampleUtil_Print( "UpnpInit() Error: %d", rc ); UpnpFinish(); return TV_ERROR; } ----------------------------------------------------------------------------- rc = UpnpRegisterClient( TvCtrlPointCallbackEventHandler, &ctrlpt_handle, &ctrlpt_handle); TvCtrlPointStart() UpnpInit() UpnpGetServerIpAddress() UpnpGetServerPort() UpnpRegisterClient()  Control Point가 NW에 참가했을음 NW를 통해 알림. TvCtrlPointRefresh()  Control Point가 관리하는 List를 깨끗이 지우고 재 생성. Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  40. Discover • TvCtrlPointCallbackEventHandler() • UPnP NW상에서 장치들의 정보를 얻어오는 과정, intTvCtrlPointCallbackEventHandler( Upnp_EventTypeEventType, void *Event, void *Cookie ) { switch ( EventType ) { case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: case UPNP_DISCOVERY_SEARCH_RESULT: { structUpnp_Discovery *d_event = ( structUpnp_Discovery * ) Event; IXML_Document*DescDoc=NULL; intret; if ((ret = UpnpDownloadXmlDoc( d_event->Location,&DescDoc)) != UPNP_E_SUCCESS){ /* … */ } else { TvCtrlPointAddDevice( DescDoc, d_event->Location, d_event->Expires ); } if (DescDoc) ixmlDocument_free( DescDoc ); TvCtrlPointPrintList(); break; } case UPNP_DISCOVERY_SEARCH_TIMEOUT: /* Nothing to do here... */ break; case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: { structUpnp_Discovery *d_event= (structUpnp_Discovery * ) Event; TvCtrlPointRemoveDevice(d_event->DeviceId); TvCtrlPointPrintList(); break; } } } Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  41. Description • UpnpDownloadXmlDoc() • UPnP에 추가된 Device의 세세한 사항을 알아오는 단계 • Control Point는 Discover에서 받은 url을 통해 Device내에 xml 문서를 가져옴. UpnpDownloadXmlDoc() UpnpdownloadUrlItem() Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  42. Event - Subscribe • UpnpSubscribe()/UpnpSubscribeAsync() • Device에 대한 상태 변화를 예의 주시할 경우 • Control Point는 해당 Device의 특정 Service에 Subscription을 요청 • Subscription이 맺어지면 • Device의 Status variable의 변화가 감지되는 경우 이를 Control point에 알려주게 됨. ret = UpnpSubscribe( ctrlpt_handle, eventURL[service], &TimeOut[service], eventSID[service] ); if(ret == UPNP_E_SUCCESS) { SampleUtil_Print( "Subscribed to EventURL with SID=%s", eventSID[service] ); } else { SampleUtil_Print( "Error Subscribing to EventURL-- %d", ret ); strcpy( eventSID[service], "" ); } TvCtrlPointAddDevice() UpnpSubscribe() • 일반적으로 Device가 advertisement하는 것을 Control Point가 받게 되면, 해당 service에 대해서 자동적으로 Subscribe를 요청하도록 되어 있음. Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  43. Event - notify • TvCtrlPointCallbackEventHandler() • Control point가 Device의 subscribe를 요청한 상태에서, Device의 status variable의 변화가 생기면 이를 control point에 알려주기 위해서 사용. intTvCtrlPointCallbackEventHandler( Upnp_EventTypeEventType, void *Event, void *Cookie ) { /* … */ switch ( EventType ) { /* … */ case UPNP_EVENT_RECEIVED: { structUpnp_Event *e_event = (structUpnp_Event * ) Event; TvCtrlPointHandleEvent( e_event->Sid, e_event->EventKey, e_event->ChangedVariables ); break; } /* … */ return 0; } Event를 받게 되면 자동적으로 TvCtrlPointHandleEvent()가 call 되어 지고, 이 함수의 내부로 들어가 어떤 Service인지 구분 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  44. Invoking Action • TvCtrlPointSendAction() • Control point에 등록된 Device에 어떤 명령을 내릴 때 이용하는 함수. IXML_Document *actionNode = NULL; if (0 == param_count) { actionNode= UpnpMakeAction(actionname, TvServiceType[service], 0, NULL); } else { for (param = 0; param < param_count; param++) { if (UpnpAddToAction( &actionNode, actionname,TvServiceType[service], param_name[param], param_val[param]) != UPNP_E_SUCCESS) { /* Handle error… */ } } } rc = UpnpSendActionAsync( ctrlpt_handle, devnode->device.TvService[service].ControlURL, TvServiceType[service], NULL, actionNode, TvCtrlPointCallbackEventHandler, NULL ); if (rc != UPNP_E_SUCCESS) { SampleUtil_Print( "Error in UpnpSendActionAsync -- %d", rc ); rc= TV_ERROR; } UpnpMakeAction() • XML문서 형식으로 wrapping 하는 함수 UpnpAddToAction() • Request문서에 argument를 추가해서 보낼 때 쓰이는 함수 UpnpSendActionAsync() • Action을 실제로 보낼 때 쓰이는 함수 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  45. Shutting Down • TvCtrlPointStop() • 등록된 Device 제거 • Mutex, Thread pool 제거 • web service, time thread 종료 intTvCtrlPointStop( void ) { TvCtrlPointRemoveAll(); UpnpUnRegisterClient( ctrlpt_handle ); UpnpFinish(); SampleUtil_Finish(); return TV_SUCCESS; } TvCtrlPointStop() TvCtrlPointRemoveAll() • Control Point가 가지고 있던 Device List를 제거하는 함수 UpnpUnRegiterClient() • UPnP NW상의 control Point이 탈퇴함을 알리는 함수 UpnpFinish() • 세부적인 종료 처리를 진행하는 함수 Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

  46. Q & A Database & Information Systems Lab.(http://dislab.hufs.ac.kr)

More Related