TIPC protocol and Implementation Analysis 1, TIPC profile TIPC is a transparent interprocess communication protocol, which is mainly applied to high availability (HAL) and dynamic cluster environment. The software is currently maintained mainly by the Wind River (WindRiver) company, mainly supporting Linux, Solaris and VxWorks three operating systems, starting from the Linux kernel 2.6.34 to support the latest version of TIPC 2.0, but there are many protocol design features are not implemented. In a trusted network environment, TCP/IP protocol many operations are redundant, for example, the famous three times handshake, resulting in decreased communication efficiency, increase the application of communication time, not conducive to time response requirements of a higher application, such as processing cluster member nodes due to restart, Down machine and other causes of the increase and reduction. TIPC for the trusted network environment, reduce the establishment of communication links and addressing the target address of the operation (in the TCP/IP protocol, the completion of these operations between the nodes at least 9 times Packet Exchange, and the use of TIPC can be reduced to 2 times). This can increase the frequency of information exchange between nodes and reduce the time between nodes. 2, TIPC Protocol Introduction 2.1, the basis of the agreement some assumptions: • The majority of messages sent through the protocol are directly to the destination • Most messages have a short transmission time · Most messages are passed between nodes within the cluster. Packet loss rate is very low, retransmission does not occur frequently • Available bandwidth and memory are high • All the checksum packets are verified by the hardware checksum • The number of communication nodes is relatively limited and static for a certain period of time · Security is not a key factor relative to the Internet in a closed cluster environment these bases assume that the TIPC is a signal link layer protocol based on flow-driven (traffic-driven) and fixed-size sliding windows. Instead of the timer-driven (Timer-driven) Transport layer protocol. This allows TIPC to release the buffer earlier, detect the packet loss and retransmission earlier, and detect the node is not available. 2.2, TIPC Architecture Views Node A node B--------------------------| TIPC | | TIPC | | Application | | Application | |-------------| | | TIPC | TIPC Address TIPC address| TIPC | | | | | |-------------| | L2 bearer| Bearer address \/bearer address| L2 Bearer | | Service | /\ | Service | --------------------------| | |----------------Bearer Transport----------------| TIPC Architecture View 2.3, TIPC network structure TIPC Network is composed of a single processing unit or node. Network nodes are strictly layered, the rules are as follows: 1. The collection of related nodes constitutes a cluster: if each node in the cluster has at least one path to each of the other nodes (that is, cluster nodes are fully connected), then these nodes form a cluster with cluster nodes in each 1~4095.2 . The collection of related cluster constitutes a zone: if every cluster in zone has at least one path to every other cluster (that is, zone is fully connected), then these cluster constitute a cluster, each zone has 1 ~4095 a cluster, the size of each cluster need not be the same. 3. The collection of related zone constitutes a TIPC network: if each zone in the network has at least one path to every other zone (that is, the zone of the network is fully connected), then these zone form a TIPC network with TIPC 1~255 on each zone network, The size of each zone does not have to be the same. Nodes are generally grouped according to neighboring relationships, TIPC communication quality decreases with the increase of node distance, in a typical TIPC network, the nodes in the same cluster are the most frequent, followed by the same zone and different cluster nodes, The nodes in different zone are basically not communicating. Each node in the TIPC network has an address consisting of a zone ID, cluster ID, and Node ID, which is generally marked as. Among them: 1<=z<=255, 1<=c, n<=4095. If a TIPC network node has not been assigned an address, it is marked with <0 0= "0=" >. TIPC networks generally have their own IDs. This allows multiple logical TIPC networks to share the same physical media (such as an Ethernet LAN) without interfering with each other. ------------------------------------------------------ ----------| Zone <1> | | Zone <2> | | ----------------------- ---------------------- | | || | Cluster <1 1= "" > | | Cluster <1 2= "" > | | | | | | | | || | ------- | | ------- ------- | | | || | | | | | | | | | | | | || | | Node | | | | Node +--+ node | | | | | |<1 1= "" 1= "" >| -------| | |<1 2= "1=" ">| |<1 2=" "2=" ">| | | | | | | +---+ | | | | | | | | | | || | ---+--- | Node | |--| --+---- ------- | | | || | | |<1 1= "3=" >| | | | | ---+--- | | | | --+-- | | | || | | +---+ | | | | seco.| | | | || | | Node | -------| | |<1.2.| | | | || | |<1 1= "" 2= ">| | | | | | | | | ----- | | | || | ------- | | | | | || ----------------------- ---------------------- | | || | | | ---------------------------------------------------------------Typical TIPC network topology Note: 1. TIPC2.0 only supports a single cluster network. 2. TIPC Network node address and IP are very different, each TIPC node at most only one address, no network interface (interface) concept. 3. The address of each node and the ID of the TIPC network are assigned by the network administrator, and the programmer does not care about these. 2.4, TIPC message format messages are TIPC node portsThe basic unit of information exchange between the two. There are 2 basic messages in TIPC: 1. Payload Message: Transfer application-related content between applications and applications or applications and TIPC services. 2. Internal message: Transmits TIPC-related content between TIPC subsystems. Each TIPC message contains the header and the data 2 parts, the message header format and user-related, size from 6 words to 11 characters (word) range ( TIPC supports the maximum expansion of the head to 60 bytes in the future. The head is stored in 32-byte shape encoded in network byte order. To tell the truth, contact TIPC is also not two days a day, in the TSP and it daily dealings. Take a good look at it today. TIPC SourceForge site:http://tipc.sourceforge.net/index.shtml reprinted from: http://blog.chinaunix.net/ UID-20205875-ID-3042255.HTMLTIPC was made by one of Ericsson's engineers, and then open source. I've been thinking about this for a while and I think it's really good. TIPC is the abbreviation of transparent interprocess communication, an agreement between interprocess communication, which is transparent and transparent because it publishes a more concise and practical framework, Let the person who uses no longer need to know which machine a process is running on, and can communicate with this process. TIPC is essentially a socket implementation and is now part of the Linux kernel, which is good enough to be seen. Usually we use the SOCKET,TCP or UDP, used to identify a pair of sockets communication, nothing more than two socket IP address and port number. For example, using UDP socket, to send a datagram to another socket, you need to specify the address to the end, this address is the IP and port of that machine composition. Socket is managed in the kernel, when the kernel detects that the socket has data to read, it will notify the process of owning the socket to read the data inside. The inconvenient thing here is that to specify the End-to-end address, we have to know which machine the socket is in and how much the port is to send the data out. can only provide some application layer of information, you could let the kernel itself to find the location of the socket, and then send the message over? That's the kind of thing TIPC do. With TIPC, when we create the socket, we register our service type in the kernel, then at the sending end, the kernel can be routed to the corresponding s by simply specifying the service type.Ocket. At this time, for the application layer, the End-to-end address is only a service type services type! It is clear that the kernel maintains such a TIPC routing table, that is, the service to find the socket. And each machine has such a routing table, the information between them is like to be able to share the TIPC socket service for the entire cluster. With TIPC, this socket uses which IP, that port, we no longer need to know, very good very strong. Other features of the TIPC are: 1. There are times when multiple processes provide the same service, just for load balancing or other reasons, which can be used to identify different sockets with an integer variable instance, but specify the same service type. The address of the socket at this time is specified by service type and instance. You only need to specify the service type and a instance value when sending data, or you can specify an interval for service type and instance. For the latter, it is broadcast your datagram. 2. Managing the TIPC routing table described above is a process in the kernel called name server. It knows all the TIPC sockets in the cluster. Before sending datagram to a socket that serves a service, you can ask it if the socket for the service is already working, and it will tell you the state of the service. and registered a observer, when you care about the socket up after sending a message to inform you, so you can avoid the datagram to a non-existent socket. TIPC installation and configuration to compile the kernel: Step: 1.CP TIPC-1.7.5.TAR/USR/SRC/LINUX-2.6.16.21-0.82.TAR-XVF tipc-1.7.5.tar3.cd/usr/src/ linux-2.6.16.21-0.84. Enter/usr/src/linux-2.6.16.21-0.8/5.make menuconfig 6.make7.make bzImage8.make modules9.make Modules_install10.make install Installation configuration: Steps: 1. Place the TICP compression pack under/usr/src/linux-2.6.16.21-0.8, 2. TAR-XVF Tipc-1.7.5.tar 3.cd/usr/src/linux-2.6.16.21-0.8/Net/tipc4. Make (now 1.7.5 has provided an option that can be configured and can be configured using made menuconfig before making, and the default configuration is also available.) ) 5.insmod. Tipc.ko 6. Compile the Util Configuration tool provided by TIPC. 7./tipc-config-netid=1234-a=1.1.5 Configuration This node has an ID of 1234 address 1.1.5 8. ./tipc-config-be=eth:eth0/1.1.0 configures the means of communication through the first Ethernet port of the machine. Communicates only to nodes within this cluster. Configuring the 1.1.8 identity to communicate to the 1.1.8 node, 1.0.0 indicates that each cluster within the zone can communicate, and 0.0.0 communicates to any location. 2,TIPC Socket Interface Analysis: socket address socket address is a 16-byte structure, as follows: struct sockaddr{unsigned short sa_family; * Address family, af_xxx/Char SA_DATA[14]; /*14 byte protocol Address/}; For programming, we usually define different parallel structures for different protocols, such as TIPC socket addresses as follows: struct SOCKADDR_TIPC {unsigned short family;/* af_ TIPC */unsigned Char AddrType; /* Tipc_addr_name * * signed char scope; /* Tipc_cluster_scope/union {struct Tipc_portid id; struct {unsigned long type; unsigned long instance; unsigned long Domain /* 0:own zone */} name; } addr; TIPC Address: TIPC's address is described as follows: Port. Z represents zone, C means cluster,n represents node. Port can be viewed as a socket when the TIPC service is started, the address of the current node (which can be a single board or a host) is determined. We create a socket and we create a port. TIPC provides name service, specifies name in SOCKADDR_TIPC, SOCKADDR_TIPC and PorT is bound to send a message to the specified name to the corresponding socket, while the lower level does not require the user to perceive it. Name and port support 1 pairs of relationships, one name for multiple ports Create socketint socket (int domain, int type, int protocol); The purpose of this function is to create a socket and then return a socket descriptor. Domain here is the af_tipc,type usually has sock_stream,sock_dgram two kinds, represents the flow-oriented or package oriented. Protocol is usually set to 0. bind operation. Once there is a socket, we may want to associate the socket with an address on the machine, which is done by bind. Bind and connect, the original socket in the application of bind we need to specify the port, connect will automatically select the interface for us, but for the TIPC application layer, there is no such relationship. getsockname, gets the current address based on the socket descriptor. setsockopt its parameters are as follows: int SOCKFD, int level, int optname, const void *optval, socklen_t Optlen when level is SOL_TIPC, that is to use TIPC, OPTN AME has the following values to choose from. 1) Tipc_importance This value is used to identify the importance of this socket message, set to important when this socket in the event of congestion, the probability of a message loss is very small. From the following literal meaning can see its meaning, no longer repeat. Tipc_low_importance, Low priority tipc_medium_importance, medium priority tipc_high_importance high priority tipc_critical_importance. Emergency priority default is Tipc_low_importance 2 tipc_src_droppable is also used as congestion control, if set to this value, in the event of congestion, TIPC will discard the message, otherwise, the bar message into the queue cache. By default: For Sock_seqpacket, Sock_stream, SOCK_RDM three kinds of transmission, that is, reliable links, the message caching, SOCK_DGRAM, that is, unreliable links, the message discarded. 3) tipc_dest_droppable still serves as a congestion control. Useful for the following three cases, the message can not be sent to the destination address, or the destination address does not existAt, or the destination address has been congested. If this function is enabled, the message will be discarded if the above three cases occur, or the message will be returned to the sender. By default: Sock_seqpacket, sock_stream Two modes of transmission, returned to the sender. The message is discarded for SOCK_RDM and Sock_dgram. The goal is to do the right thing when communication fails with a link-oriented scenario without increasing the complexity of the processing of communication failures that are oriented to no links. 3) Tipc_conn_timeout Set the timeout time for connect, the unit is in milliseconds with sendto, this option is meaningless. Programming Example: Service.c#include #include #include #include #include #include #include the #include #include to #include #include #include #include #include #include #include #include #include #include test_msg_size 2048#define test_read_times 10#defin e test_msg_len 64*1024typedef struct tagdmsllogilinkaddrtipc{int uitype; int uiinstance;} Tipc_addr_str;int dmsgetsockaddr (struct sockaddr* socketaddr, tipc_addr_str *pstlogilinkadds) {struct sockaddr_tipc* addr = (struct sockaddr_tipc*) socketaddr; /* Set the Listening address */if ((0 = addr) | | (0 = Pstlogilinkadds)) {return 10000;} memset (addr, 0, sizeof (struct SOCKADDR_TIPC)); addr->family = AF_TIPC; Addr->addrtype = Tipc_addr_name; Addr->addr.name.name.type = pstlogilinkadds->uitype; Addr->addr.naMe.name.instance = pstlogilinkadds->uiinstance; Addr->addr.name.domain = 0; Addr->scope = 2; return 0;} int main () {int uiret,stsocket,uinum,n,i; struct sockaddr location_addr, tagsockaddr; struct SOCKADDR_TIPC; tipc_addr_str* Pstportname; void *pmsg; Fd_set Fdreadset; struct Timeval stwait; socklen_t addrlen = sizeof (struct sockaddr); static int uimsgnum = 0; Char Buf[test_msg_size]; struct MSGHDR stmsg; struct Iovec astiovec[1]; Pstportname = malloc (sizeof (TIPC_ADDR_STR)); Pstportname->uitype = 0x80000001; Pstportname->uiinstance = 130987; Stsocket = socket (AF_TIPC, SOCK_RDM, 0); if ( -1 = stsocket) {perror ("socket"); return-1} Uiret = Dmsgetsockaddr (&location_addr, pstportname); if (0!= uiret) {printf ("Dmsgetsockaddr Failed 0x%x", uiret); return-1;} Uiret = Bind (Stsocket, (__const_sockaddr_arg) &am P;location_addr, (socklen_t) sizeof (LOCATION_ADDR)); if (0!= uiret) {printf ("Bind Failed 0x%x", uiret); return-1; pMsg = malloc (test_msg_size); if (NULL = = = PMSG) {printf ("malloc Failed"); return-1; while (1) {Fd_zero (&fdreadset); Fd_set (Stsocket, &fdreadset); stwait.tv_sec = 0; Stwait.tv_usec = 10000; if (select (Stsocket + 1, &fdreadset, (fd_set*) 0, (fd_set*) 0, &stwait) >0) {//Uinum = 0;//while (Uinum < T Est_read_times) {n = recvfrom (Stsocket, PMSG, Test_msg_len, 0, (__sockaddr_arg) (struct SOCKADDR_TIPC *) &servaddr, (U nsigned int *) (size_t*) &addrlen); if (n <= 0) {Continue} Uimsgnum + = N/test_msg_size; Pstportname->uitype = 0x70000001; Pstportname->uiinstance = 130986; Uiret = Dmsgetsockaddr (&tagsockaddr, pstportname); if (0!= uiret) {printf ("Dmsgetsockaddr Failed 0x%x", uiret); return-1;} uinum++;//for (i = 0;i < uimsgnum;i++) {//PBuf = malloc (test_msg_size);//memset (PBuf, 0, test_msg_size); SendTo (St sockets, (void*) Buf, test_msg_size, 0, (struct sockaddr*) &tagsockaddr, sizeof (TAGSOCKADDR));/printf ("Send MSG num Is%d\n ", i); }} return 0;} Client.c#includE #include #include #include #include #include #include of the #include of #include, and #include the #include of the #include of the #include #include Clude #include #include #include #include #include #include #define Test_msg_len 64*1024#define test_msg_size 2048typedef struct tagdmsllogilinkaddrtipc{int uitype; int uiinstance;} tipc_logi_addr_str;//typedef void * (* osal_linux_task_entry) (vos_void *); int stsocket;int dmsgetsockaddr (struct Socka ddr* socketaddr, tipc_logi_addr_str *pstlogilinkadds) {struct sockaddr_tipc* ADDR = (struct sockaddr_tipc*) SocketAddr; * Set Listener Address/if ((0 = addr) | | (0 = Pstlogilinkadds)) {return-1;} memset (addr, 0, sizeof (struct SOCKADDR_TIPC)); addr->family = AF_TIPC; Addr->addrtype = Tipc_addr_name; Addr->addr.name.name.type = pstlogilinkadds->uitype; Addr->addr.name.name.instance = pstlogilinkadds->uiinstance; Addr->addr.name.domain = 0; Addr->scope = 2; return 0;} void Recvproc (void *pthis) {fd_set fdreadset; struct timeval stwait; int UINUM,N,UISECD; statIC int uimsgnum = 0; static struct Timeval Stendtimefei,ststarttimefei; struct SOCKADDR_TIPC servaddr; socklen_t addrlen = sizeof (struct sockaddr); void *pmsg; printf ("------------"); PMSG = malloc (test_msg_size); if (NULL = = PMSG) {printf ("malloc Failed"); return; while (1) {Fd_zero (&fdreadset); Fd_set (Stsocket, &fdreadset); stwait.tv_sec = 0; Stwait.tv_usec = 10000;//if (select (Stsocket + 1, &fdreadset, (fd_set*) 0, (fd_set*) 0, &stwait) >0) {//Uinum = 0; while (Uinum < test_read_times) {n = recvfrom (Stsocket, PMSG, Test_msg_len, 0, (__sockaddr_arg) (struct SOCKADDR_TI PC *) &servaddr, (unsigned int *) (size_t*) &addrlen); if (n <= 0) {continue} if (Uimsgnum = 0) {gettimeofday (&ststarttimefei,null);}//Uimsgnum + = N/test_msg_siz E uimsgnum++;//printf ("recv msg num is%d\n", uimsgnum);//uinum++; if ((uimsgnum%200000) = = 0) {gettimeofday (&stendtimefei,null); UISECD = (stendtimefei.tv_sec-ststarttimefei.tv_ SEC) *1000 + (StendtimefeI.TV_USEC-STSTARTTIMEFEI.TV_USEC)/1000; printf ("The Flux is%u\n", 200000/UISECD); Gettimeofday (&ststarttimefei,null); }}}}int main (int ac, char **av) {pthread_attr_t attr;/* Attributes for Thread */pthread_t tid; void *pthis; int Uire T,uisize,i,j; struct sockaddr location_addr, tagsockaddr; tipc_logi_addr_str* Pstportname; tipc_logi_addr_str* Pstdstportname; Char Buf[test_msg_size]; struct MSGHDR stmsg; int inum; Inum = Atoi (av[1]) uisize = test_msg_size; Pstportname = malloc (sizeof (TIPC_LOGI_ADDR_STR)); Pstdstportname = malloc (sizeof (TIPC_LOGI_ADDR_STR)); Pstportname->uitype = 0x70000001; Pstportname->uiinstance = 130986; Stsocket = socket (AF_TIPC, SOCK_RDM, 0); if ( -1 = stsocket) {perror ("socket"); exit (1);} Uiret = Dmsgetsockaddr (&location_addr, pstportname); if (0!= uiret) {printf ("\r\ndmsgetsockaddr Failed 0x%x", uiret); return-1;} Uiret = Bind (Stsocket, __const_sockaddr_arg ) &location_addr, (socklen_t) sizeof (LOCATION_ADDR)); if (0!= uiret) {Perror ("bind"); Exit (1); int sverrno = Pthread_attr_init (&attr); Pthread_attr_setdetachstate (&attr, pthread_create_detached); Uiret = Pthread_create (&tid, &attr, (void*) &recvproc, pThis); printf ("\ r \ n%u", Uiret); Fflush (stdout); Pstdstportname->uitype = 0x80000001; Pstdstportname->uiinstance = 130987; if (0!= dmsgetsockaddr (&tagsockaddr, pstdstportname)) {printf ("\r\ndmsgetsockaddr Failed 0x%x", Uiret); struct Iovec astiovec[1]; for (j= 0;; j +) {if (j%inum!= 0) {/* PBuf = malloc (uisize); memset (PBuf, 0, uisize); * * SendTo (Stsocket, (void*) Buf, Uisi Ze, 0, (struct sockaddr*) &tagsockaddr, sizeof (TAGSOCKADDR)); /* Currently only use Send a fragment interface * * *//uiret = sendto (Stsocket, PBuf, Uisize, 0, (__const_sockaddr_arg) (struct SOCKADDR_TIPC *) & TAGSOCKADDR, sizeof (TAGSOCKADDR)); if (0>uiret) {perror ("sendmsg"); return 10000;} printf ("Send num is%d", j); else {usleep (4000);}} return 0;}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.