1 / 35

Module 6 - Practical use of Sockets

Module 6 - Practical use of Sockets. Objectives. 고성능 인터넷 서버 프로그래밍 (High performance internet server programming) 기법에 대해 이해한다 . fork() 를 이용한 다중 프로세스 프로그램에 대해 이해한다 . 다중 스레드 기법을 이용한 프로그램에 대해 소개한다 . select() 시스템 콜을 활용하여 I/O Multiplexing 소켓을 작성한다 . Multicast 개념에 대해 알아본다 .

gayora
Télécharger la présentation

Module 6 - Practical use of Sockets

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. Module 6 - Practical use of Sockets

  2. Objectives • 고성능 인터넷 서버 프로그래밍(High performance internet server programming) 기법에 대해 이해한다. • fork()를 이용한 다중 프로세스 프로그램에 대해 이해한다. • 다중 스레드 기법을 이용한 프로그램에 대해 소개한다. • select() 시스템 콜을 활용하여 I/O Multiplexing 소켓을 작성한다. • Multicast 개념에 대해 알아본다. • Multicast socket을 작성하고 간단한 프로그램을 작성한다. • IPv6 라이브러리에 대해 알아본다. • IPv6 소켓 라이브러리를 이용하여 간단한 프로그램을 작성한다.

  3. Server program • Single service • Multiple service 클 라 이 언 트 서 버 클 라 이 언 트 (1) 서 버 클 라 이 언 트 (2) 클 라 이 언 트 (3)

  4. Multi-process • Process • 수행 중인 program • 고유한 메모리 영역을 가지며, 각각 다른 실행 상태를 가질 수 있다. • Multi-process • 여러 개의 프로세스들이 연관을 가지거나 가지지 않은 채로 작동 • Fork() 함수를 호출하여 생성 • 기존 프로세스의 완전한 복사본을 생성 • 동일한 메모리 구조, 동일한 파일 설명자들을 가짐 • 부모 프로세스 : 자식 프로세스의 프로세스 번호를 반환 • 자식 프로세스 : 0 값을 반환 • 생성된 프로세스 종료 : exit() 호출 • 프로세스간의 통신 • IPC(Inter-process Communication), FIFO(First In, First Out), Shared Memory, …

  5. Multi-thread • 프로세스에서 새로운 영역을 가진다는 특징을 제외하고, 새로운 파일 설명자들을 갖는다는 특징을 제외한 개념의 작은 프로세스라고 볼 수 있다. • 한 프로세스에는 여러 개의 스레드가 존재할 수 있다. • 스레드는 스택을 제외한 모든 메모리 공간을 공유하게 된다. • 컨텍스트 스위칭이 빠르며 자원의 낭비가 적다. • 기본 스레드 생성 int pthread_create(phtread_t *tid, const pthread_attr_t *inttr, void*(*start_routine)(void *), void *arg)

  6. select() function • Select() function # include <time.h> int select ( int maxfdp1, //최대 파일(및 소켓)번호 크기 +1 fd_set *readfds, // 읽기상태 변화를 감지할 소켓 지정 fd_set *writefds, //쓰기상태 변화를 감지할 소켓 지정 fd_set *exceptfds, // 예외상태 변화를 감지할 소켓 지정 struct timeval *tvptr); // select() 시스템 콜이 기다리는 시간 • Return • Success : number of file descriptors selected, file descriptor masks modified for selected device • Failure : -1 and errno set to indicate error • Timeout : 1 and file descriptor masks cleared

  7. Fd_set를 사용하기 위한 매크로 • FD_ZERO(fd_set *fdset) • *fdset의 모든 비트를 clear • FD_SET(int fd, fd_set *fdset) • 소켓 fd를 해당 *fdset이 가능하도록 구조체에 해당 비트를 1로 세트 • FD_CLR(int fd, fd_set *fdset) • *fdset 중 소켓 fd에 해당하는 비트를 0으로 세트 • FD_ISSET(int fd, fd_set *fdset) • fdset 중 소켓 fd에 해당하는 비트가 세트되어 있으면 양수 값인 fd를 리턴

  8. Broadcast and Multicast • Unicast • a single interface • Broadcast • all hosts on(small, local)network • Multicast • multiple recipients(group)

  9. Internet Multicasting Sender-Oriented (One-to-Many) Receiver-Oriented (Many-to-Many)

  10. Not A Receiver Receiver Receiver Receiver Unicast Traffic VideoServer 1.5 Mb x 2 = 3 Mb 1.5 Mb x 1 = 1.5 Mb 1.5 Mb x 1 = 1.5 Mb 1.5 Mb x 1 = 1.5 Mb 1.5 Mb x 1 = 1.5 Mb

  11. Not A Receiver Receiver Receiver Receiver Broadcast Traffic 1.5 Mb Broadcast Traffic의 경우, Multimedia Application을 사용하지 않는 Host도 Broadcast Traffic을 처리해야 한다. 통상 Transport Layer에서 Packet을 폐기한다 VideoServer I don’t want to receive this video stream, but my CPU still needs to process that 1.5 MB of data! 1.5 Mb 1.5 Mb 1.5 Mb 1.5 Mb 1.5 Mb 1.5 Mb

  12. Not A Receiver Receiver Receiver Receiver Multicast Traffic 1.5 Mb VideoServer 1.5 Mb 1.5 Mb 1.5 Mb 1.5 Mb 1.5 Mb Multicast Server는 Multicast Address(special broadcast address)를 사용하여 하나의 Packet을 사용하여 모든 노드에 Data를 전달한다. Multicast Application을 사용하지 않는 호스트는 통상 Layer2에서 Frame을 폐기할 수 있다.

  13. Unicast vs. Multicast Unicast Server Router Multicast Server Router

  14. Local multicast • Some local networks are by nature multi/broadcast: Ethernet, Token Ring, FDDI, ... • Ethernet, Token Ring: • broadcast: all ones • multicast: 01.xx.xx.xx.xx.xx • ATM • point-to-point links • need ATM-level multicast server

  15. IP multicast • host-group model • Deering, 1991: • 같은 ip Multicast 주소를 가지는 host들 • groups may have any number of members • there are no topological restrictions on group membership • membership is dynamic and autonomous • host groups may be transient or permanent • network-level • data packets same, only address changes • need help of routers • special IP addresses(class D) • 224.0.0.0 through 239.255.255.255 • map IP multicast address into Ethernet multicast address : 01.00.5E.00.00.00 + lower 23bits • ex) 224.0.0.1 --> 01.00.5E.00.00.01

  16. 24 31 0 7 8 15 16 23 Class D IP 주소 1110 224 Not Low-Order 23 Bits of Multi-cast Used Group ID Copied to Ethernet Address 01 00 5E 00000001 00000000 01011110 0 48-Bit 이더넷 주소 (MAC) IP Multicast 와 이더넷주소 매핑 • 01:00:5e:00:00:00 - 01:00:5e:7f:ff:ff • 01:00:5e는 동일하다.(상위 24Bit는 동일한 값을 사용하며 25번째 bit값은 항상 0이다.) • 01:00:5e +0+그룹 Address의 하위 23bit를 Octet 단위로 16진수 값으로 변환한 값으로 산출된다. • 224.128.64.32와 224.0.64.32는 01:00:5e:00:40:20으로 동일한 이더넷 주소를 갖게 된다. 이 경우는 IP Level에서 구분될 것이다.

  17. Multicasting의 장점 • Bandwidth의 최소화 R sender R R R receiver unicast R multicast

  18. MBONE • Multicast BackBONE • Virtual Network on the Internet • Testbed for multicast routing and applications • routers and hosts support IP Multicasting • Multimedia Conferencing, Live TV/Radio, Distributed Game, Distance learning lecture • World Wide Experimental Network • Many-to-Many, One-to-Many transfer • Tunnel Based • virtual point-to-point link • IP-in-IP encapsulation 기술을 이용 • needed until deployment of multicast-capable a backbone routers • tunnel들의 모임이 MBONE • mrouter Based

  19. MBONE Elements • IP Multicast(Receiver-Oriented Multicast) • “Host Extension for IP Multicasting” : RFC 1112 • use D Class IP address • Tunnel and Encapsulation • Metric, Threshold, TTL • Mbone Protocols

  20. 네트워크 터 널 : Router : Multicast Router Virtual Network using Tunneling • Not all routers cannot support multicasting

  21. Tunnel & IP Encapsulation 1 Hm Multicast Packet Encapsulated Packet 3 2 Rm Rm Hm Hm Hm IP Encapsulation Normal Multicast Packet multicast dest. tunnel source tunnel dest. original source 2 3 1 Gm 203.252.134.48 224.2.0.1 17 UDP RTP audio/video data (UDP) 203.252.134.46 143.248.172.41 4 (IP) source: 203.252.134.48; group:224.0.0.1; MBONE tunnel: 203.252.134.46 to 143.248.172.41

  22. Metric & Threshold & TTL • Metric • Tunnel cost • selecting Tunnel which has low metric sum • prevent multicast routing loop • Threshold • Tunnel access-level • restrict multicast range • TTL(Time-to-Live) • Multicast packet life-time • decrease 1 by passing mrouter • control of multicasting range • transfer multicast packet if the value of TTL is greater than that of Threshold

  23. MBONE Protocols • Group Management Protocol • IGMP (Internet Group Management Protocol) • Multicast Packet Routing Protocol • DVMRP (Distance Vector Multicast Routing Protocol) • MOSPF (Multicast Open Shortest Path First) • PIM (Protocol Independent Multicast) • CBT(Core Based Tree) • Reliable Multicast Transport Protocol • RMTP, SRM, TMTP…….. • Multicast key management Protocol • GKMP, SMKD, …

  24. MBONE Tools • Session Manager tool • Sd, sdr • Audio tool • Vat • Video tool • Nv, vic, ivs • Others • Wb, nt, imm,mMOD

  25. Multicast programming • UDP 소켓을 이용 • Multicast 구조체 struct ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; } • Multicast options • IP_ADD_MEMBERSHIP • IP_DROP_MEMBERSHIP • IP_MULTICAST_LOOP • IP_MULTICAST_TTL • IP_MULTICAST_IF

  26. Programming 절차 • 멀티캐스트 그룹주소 지정 • ip_mreq 구조체 지정 • 수신 UDP 소켓 생성 • 멀티캐스트 그룹 가입 • 소켓 재사용 옵션 지정 • 바인딩 • 멀티캐스트 패킷전송

  27. ip_mreq 구조체 지정 struct sockaddr_in mcast_group; struct ip_mreq mreq; /* 멀티캐스트 그룹 주소 지정 : mcast_group */ mreq.imr_multiaddr = mcast_group.sin_addr; mreq.imr_interfaces.s_addr = htonl(INADDR_ANY);

  28. 수신 UDP 소켓 생성 recv_sock = socket(AF_INET, SOCK_DGRAM, 0); • Multicast 그룹 가입 setsockopt(recv_sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

  29. 소켓 재사용 옵션 지정 unsigned int flag = 1; setsockopt(recv_sock, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)); • Socket binding bind(recv_sock, (struct sockaddr*)&mreq_group, sizeof(mcast_group));

  30. 멀티캐스트 패킷전송 send_sock = socket(AF_INET, SOCK_DGRAM, 0); sendto(send_sock, msg, strlen(msg), (struct sockaddr*) &mcast_group, sizeof)mcast_group)); • Loopback setsockopt(send_sock, IPPROTO_IP, IP_MULTICCAST_LOOP, &no, sizeof(no)); 크기가 1 바이트 이어야 함

  31. IPv6 programming • IPv4에서 주요 변경 부분 • IP 주소의 크기를 표시한 API 부분 • 새로운 데이터 구조 필요 • IP 주소를 처리하는 어플리케이션 부분

  32. IPv6 Address family

  33. Structure

  34. Function 변환

More Related