IP网络5种基本寻址方式 (单播、多播、广播、任播、地域多播)

Addressing methods

The Internet Protocol and other network addressing systems recognize five main addressing methodologies:

-单播Unicast

addressing uses a one-to-one association between destination address and network endpoint: each destination address uniquely identifies a single receiver endpoint.

-多播Multicast

addressing uses a one-to-unique many association, datagrams are routed from a single sender to multiple selected endpoints simultaneously in a single transmission.

详见《TCP/IP 详解 卷2 :实现》

第12章 IP多播

第13章 IGMP:Internet 组管理协议

第14章 IP多播 选路(路由)

代码的实现:

1.http://www.tldp.org/HOWTO/Multicast-HOWTO-6.html

2.libuv 中也有实现 (uv.h、 /win/udp.c、 /unix/udp.c)

主要看setsockopt()操作,以下是加入,离开组 (公网上的D组IP),使用 IGMP协议

  switch (membership) {
case UV_JOIN_GROUP:
optname = IP_ADD_MEMBERSHIP;
break;
case UV_LEAVE_GROUP:
optname = IP_DROP_MEMBERSHIP;
break;
default:
return UV_EINVAL;
} if (setsockopt(handle->socket,
IPPROTO_IP,
optname,
(char*) &mreq,
sizeof mreq) == SOCKET_ERROR) {...}

UV_EXTERN int uv_udp_init(uv_loop_t*, uv_udp_t* handle);
UV_EXTERN int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, unsigned int flags);
UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
UV_EXTERN int uv_udp_bind(uv_udp_t* handle,
const struct sockaddr* addr,
unsigned int flags); UV_EXTERN int uv_udp_getsockname(const uv_udp_t* handle,
struct sockaddr* name,
int* namelen);
UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
const char* multicast_addr,
const char* interface_addr,
uv_membership membership);
UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on);
UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
UV_EXTERN int uv_udp_set_multicast_interface(uv_udp_t* handle,
const char* interface_addr);
UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on);
UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl);
UV_EXTERN int uv_udp_send(uv_udp_send_t* req,
uv_udp_t* handle,
const uv_buf_t bufs[],
unsigned int nbufs,
const struct sockaddr* addr,
uv_udp_send_cb send_cb);
UV_EXTERN int uv_udp_try_send(uv_udp_t* handle,
const uv_buf_t bufs[],
unsigned int nbufs,
const struct sockaddr* addr);
UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle,
uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb);
UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle);

这里有cisco 整理的Multicast RFC的文档列表

IETF RFCs for IP Multicast

This appendix contains Internet Engineering Task Force (IETF) RFCs related to IP multicast. For information about IETF RFCs, see http://www.ietf.org/rfc.html.

RFCs

  • RFC 2236 Internet Group Management Protocol
  • RFC 2365 Administratively Scoped IP Multicast
  • RFC 2858 Multiprotocol Extensions for BGP-4
  • RFC 3376 Internet Group Management Protocol, Version 3
  • RFC 3446 Anycast Rendezvous Point (RP) mechanism using Protocol Independent Multicast (PIM) and Multicast Source Discovery Protocol (MSDP)
  • RFC 3569 An Overview of Source-Specific Multicast (SSM)
  • RFC 3618 Multicast Source Discovery Protocol (MSDP)
  • RFC 4291 IP Version 6 Addressing Architecture
  • RFC 4541 Considerations for Internet Group Management Protocol (IGMP) and Multicast Listener Discovery (MLD) Snooping Switches
  • RFC 4601 Protocol Independent Multicast - Sparse Mode (PIM-SM): Protocol Specification (Revised)
  • RFC 4610 Anycast-RP Using Protocol Independent Multicast (PIM)
  • RFC 5059 Bootstrap Router (BSR) Mechanism for Protocol Independent Multicast (PIM)
  • RFC 5132 IP Multicast MIB

-广播boardcast

addressing uses a one-to-many association, datagrams are routed from a single sender to multiple endpoints simultaneously in a single transmission. The network automatically replicates datagrams as needed for all network segments (links) that contain an eligible receiver.

-任播Anycast

addressing routes datagrams to a single member of a group of potential receivers that are all identified by the same destination address. This is a one-to-nearest association.

-地域多播Geocast

refers to the delivery of information to a group of destinations in a network identified by their geographical locations. It is a specialized form of Multicast addressing used by some routing protocols for mobile ad hoc networks.

https://en.wikipedia.org/wiki/Geographic_routing

RFC 参考wiki中的 链接,这里我就不过多说明了

图片:

IP网络5种基本寻址方式 (单播、多播、广播、任播、地域多播)


需要特别说明的是 使用场合

  • 视频直播:

    基本都是 【组播】(寻址,路由分发) + UDP(穿透)

  • 视频点播:

    一般是用TCP。比较容易的控制进度,打开,关闭等操作。

    但是也有用UDP的,一些顺序控制,操作。 要自己实现。

youku视频点播,  抓包发现,既有TCP,又有UDP(大的视频)。 那么问题来了UDP遇到如下几个问题,怎么办?

1.网络丢包 +  帧顺序 问题
按照文件块发送,但是网络差的时候,UDP丢帧,就重传这个文件块的数据。
文件块保持数据的顺序性, UDP顺序保证的话,估计是adobeflash的服务器和adobeflash客户端中 有类RTSP的协议。( 增加 帧序号,等信息) 2. 进度等操作
(youku 拖拽位置等操作,如果是UDP做的话,那么每个位置坐标就要对应数据内容块的位置。 其实有可能是adobeflash框架中实现的(包里面有信息,暂时认为是类RTSP 的协议吧),youku只是用adobeflash的服务端而已。)
YouTube 的数据包也可以抓来看下,(应该也是用UDP, 每个数据包都有 时间戳,SYN顺序 等信息。)  从右开始插入排序,放到解码队列,然后再播放。

客户端使用时候再 具体做处理。

待验证。。。

广播:

一般用于局域网。

容易混淆的是 多播和任播,

==========

相关

  • webcast

    A webcast is a media presentation distributed over the Internet using streaming media technology to distribute a single content source to many simultaneous listeners/viewers. A webcast may either be distributed live or on demand. Essentially, webcasting is “broadcasting” over the Internet.

  • Packet forwarding

    Packet forwarding is the relaying of packets from one network segment to another by nodes in a computer network.

    The Network Layer of the OSI Layer is responsible for Packet Forwarding.[1] The simplest forwarding model—​unicasting—​involves a packet being relayed from link to link along a chain leading from the packet's source to its destination. However, other forwarding strategies are commonly used. Broadcasting requires a packet to be duplicated and copies sent on multiple links with the goal of delivering a copy to every device on the network. In practice, broadcast packets are not forwarded everywhere on a network, but only to devices within a broadcast domain, making broadcast a relative term. Less common than broadcasting, but perhaps of greater utility and theoretical significance, is multicasting, where a packet is selectively duplicated and copies delivered to each of a set of recipients.

  • Port forwarding 常用于穿透

    In computer networking, port forwarding or port mapping is an application of network address translation (NAT) that redirects a communication request from one address and port number combination to another while the packets are traversing a network gateway, such as a router or firewall. This technique is most commonly used to make services on a host residing on a protected or masqueraded (internal) network available to hosts on the opposite side of the gateway (external network), by remapping the destination IP address and port number of the communication to an internal host.[1][2]

    Types of port forwarding

    Port forwarding can be divided into the following types:[4]

    • Local port forwarding
    • Remote port forwarding
    • Dynamic port forwarding
  • p2pTV

    The term P2PTV refers to peer-to-peer (P2P) software applications designed to redistribute video streams in real time on a P2P network; the distributed video streams are typically TV channels from all over the world but may also come from other sources. The draw to these applications is significant because they have the potential to make any TV channel globally available by any individual feeding the stream into the network where each peer joining to watch the video is a relay to other peer viewers, allowing a scalable distribution among a large audience with no incremental cost for the source.

  • CDN

    Content networking techniques

需要注意的是,里面一些链接有相关的公司的产品, 直接可以通过这个 可以找到一些开源代码。

相关书籍:

Data.Communications.and.Networking 5th Edition

上一篇:Linux下源码编译安装MySQL 5.5.8


下一篇:sudo gem install cocoapods 没反应问题