📄 xtp.h
字号:
/*
* Copyright (c) 1997
* Sandia National Laboratories. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory, Sandia National Laboratories, and its
* contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef _XTP_H_
#define _XTP_H_
#define xtp_key u_quad_t
#define xtp_seq u_quad_t
/*
* XTP sequence numbers are 64 bit integers operated
* on with modular arithmetic. These macros can be
* used to compare such integers.
*/
#define XTP_SEQ_LT(a,b) ((quad_t)((a)-(b)) < (quad_t)0)
#define XTP_SEQ_LEQ(a,b) ((quad_t)((a)-(b)) <= (quad_t)0)
#define XTP_SEQ_GT(a,b) ((quad_t)((a)-(b)) > (quad_t)0)
#define XTP_SEQ_GEQ(a,b) ((quad_t)((a)-(b)) >= (quad_t)0)
#define XTP_SEQ_MAX(a,b) (XTP_SEQ_LT(a,b) ? (b) : (a))
#define XTP_SEQ_MIN(a,b) (XTP_SEQ_LT(a,b) ? (a) : (b))
/*
* XTP keys are 64 bit integers operated
* on with modular arithmetic. These macros can be
* used to compare such integers.
*/
#define XTP_KEY_LT(a,b) ((quad_t)((a)-(b)) < (quad_t)0)
#define XTP_KEY_LEQ(a,b) ((quad_t)((a)-(b)) <= (quad_t)0)
#define XTP_KEY_GT(a,b) ((quad_t)((a)-(b)) > (quad_t)0)
#define XTP_KEY_GEQ(a,b) ((quad_t)((a)-(b)) >= (quad_t)0)
/*
* Most other XTP fields are 32 bit integers operated
* on with modular arithmetic. These macros can be
* used to compare such integers.
*/
#define XTP_LT(a,b) ((int)((a)-(b)) < 0)
#define XTP_LEQ(a,b) ((int)((a)-(b)) <= 0)
#define XTP_GT(a,b) ((int)((a)-(b)) > 0)
#define XTP_GEQ(a,b) ((int)((a)-(b)) >= 0)
#define XTP_MAX(a,b) (XTP_LT(a,b) ? (b) : (a))
#define XTP_MIN(a,b) (XTP_LT(a,b) ? (a) : (b))
#define keytoindex(key) ((int)(((u_long)(key)) & (MAX_CONTEXTS - 1)))
/*
* Macros to convert 64-bit values
* to and from network representation
*/
#ifndef NTOHQ
#if WORDS_BIGENDIAN
#define NTOHQ(d)
#define HTONQ(d)
#else
#define NTOHQ(d) ((d) = (u_quad_t) \
((u_quad_t)(ntohl(*((u_long*)&(d)))) << 32) | \
((u_quad_t)(ntohl(*(((u_long*)&(d)) + 1)))))
#define HTONQ(d) ((d) = (u_quad_t) \
((u_quad_t)(htonl(*((u_long*)&(d)))) << 32) | \
((u_quad_t)(htonl(*(((u_long*)&(d)) + 1)))))
#endif
#endif
/*
* Macros to set/clr/check 64th bit
*/
#define TEST_HI_BIT(d) ((int)((u_quad_t)(d) >> 63))
#define SET_HI_BIT(d) ((u_quad_t)(d) | (u_quad_t)1 << 63)
#define CLR_HI_BIT(d) (((u_quad_t)(d) << 1) >> 1)
/*
* The XTP command field has two parts, options (3 bytes) and the packet
* type (1 byte). The structure below takes advantage of the fact that
* the lower byte of the options subfield is not currently used.
*/
typedef struct {
u_short options; /* XTP options bit flags */
u_char resv; /* Reserved flag field */
u_char ptype; /* Packet type */
} xtp_cmd;
/*
* XTP options bits
*/
#define XH_BTAG 0x0001 /* btag field present in data */
#define XH_END 0x0002 /* end of association */
#define XH_EOM 0x0004 /* end of message */
#define XH_WCLOSE 0x0008 /* writer process closed */
#define XH_RCLOSE 0x0010 /* reader process closed */
#define XH_DREQ 0x0020 /* request status upon data delivery */
#define XH_SREQ 0x0040 /* request for status immediately */
#define XH_FASTNAK 0x0080 /* fast negative acknowledgement */
#define XH_NOFLOW 0x0100 /* disable flow control */
#define XH_SORT 0x0200 /* sort value valid */
#define XH_RES 0x0400 /* reservation mode */
#define XH_MULTI 0x0800 /* multicast mode */
#define XH_NOERR 0x1000 /* error recovery disabled */
#define XH_EDGE 0x2000 /* send cntl on edge trigger */
#define XH_NOCHECK 0x4000 /* disable checksum over data */
/*
* Version number for compatibility checking
*/
#define X_VER 0x20 /* XTP 4.0 version number */
/*
* The ptype field of the xtp_cmd structure is a byte with the top
* 3 bits are the version number (0x20 is value "1") and the lower
* 5 bits are the packet type. Here we concatonate the version with
* the packet type value
*/
#define X_DATA 0x20 /* DATA packet (0) */
#define X_CNTL 0x21 /* CNTL packet (1) */
#define X_FIRST 0x22 /* FIRST packet (2) */
#define X_ECNTL 0x23 /* ECNTL packet (3) */
#define X_TCNTL 0x25 /* TCNTL packet (5) */
#define X_JCNTL 0x27 /* JCNTL packet (7) */
#define X_DIAG 0x28 /* DIAG packet (8) */
/*
* XTP header.
* Per XTP 95-21, March, 1995.
*/
struct xtphdr {
xtp_key xh_key; /* key */
xtp_cmd xh_cmd; /* command field */
u_long xh_dlen; /* data length */
u_short xh_check; /* checksum */
u_short xh_sort; /* sort */
u_long xh_sync; /* sync */
xtp_seq xh_seq; /* sequence number */
};
/*
* Header length is a constant, so define here for efficiency
*/
#define X_HDR_LEN 32 /* 32 bytes */
/*
* XTP address segment for IP
*/
struct xtpaddrseg {
u_short xa_len; /* address segment length (2) */
u_char xa_domain; /* address domain (1) */
u_char xa_format; /* address segment format (1) */
struct in_addr xa_dst; /* destination host address (4) */
struct in_addr xa_src; /* source host address (4) */
u_short xa_dport; /* destination port (2) */
u_short xa_sport; /* source port (2) */
};
/*
* Service types
*/
#define XA_UNSPEC 0x00 /* Unspecified */
#define XA_UNACKDG 0x01 /* Unacknowledged Datagram Service */
#define XA_ACKDG 0x02 /* Acknowledged Datagram Service */
#define XA_TRANS 0x03 /* Transaction Service */
#define XA_RELSTRM 0x04 /* Reliable Unicast Stream Service */
#define XA_UNACKMC 0x05 /* Unacknowledged Multicast Stream Service */
#define XA_RELMC 0x06 /* Reliable Multicast Stream Service */
/*
* Traffic Specifier 0: the null specifier
*/
struct xtptraf0 {
u_long pad; /* pad to meet 8-byte boundary */
};
/*
* Traffic Specifier 1: the normal XTP specifier
*/
struct xtptraf1 {
u_long maxdata; /* maximum Information Segment size (4) */
u_long inrate; /* incoming rate (4) */
u_long inburst; /* incoming burst (4) */
u_long outrate; /* outgoing rate (4) */
u_long outburst; /* outgoing burst (4) */
};
/*
* XTP Traffic Specifier
*/
struct xtptrafspec {
u_short xt_len; /* traffic segment length (2) */
u_char xt_service; /* type of service (1) */
u_char xt_format; /* traffic segment format (1) */
union {
struct xtptraf0 xt_ts0;
struct xtptraf1 xt_ts1;
} xt_tspec;
};
/*
* XTP Traffic Segment
*/
struct xtptrafseg {
u_long xt_rsvd; /* padding for alignment */
xtp_key xt_xkey; /* exchange key */
u_short xt_len; /* traffic segment length (2) */
u_char xt_service; /* type of service (1) */
u_char xt_format; /* traffic segment format (1) */
union {
struct xtptraf0 xt_ts0;
struct xtptraf1 xt_ts1;
} xt_tspec;
#define xt_ts0 xt_tspec.xt_ts0
#define xt_ts1 xt_tspec.xt_ts1
};
/*
* XTP Control Segment Fields
*/
/*
* Spans
*/
struct xtpspan {
xtp_seq span_a;
xtp_seq span_b;
};
/*
* Normal control segment
*/
struct xtpcntl {
xtp_seq xc_rseq; /* received sequence number (8) */
xtp_seq xc_alloc; /* allocation (upper edge of window) (8) */
u_long xc_echo; /* for echoing the sync value (4) */
};
/*
* Error-reporting control segment
*/
struct xtpecntl {
xtp_seq xc_rseq; /* ^ */
xtp_seq xc_alloc; /* | same as common */
u_long xc_echo; /* v */
u_long xc_nspan; /* number of spans (4) */
struct xtpspan xc_spans; /* spans (nspans * 16) */
};
/*
* Traffic-shaping control segment
*/
struct xtptcntl {
xtp_seq xc_rseq; /* ^ */
xtp_seq xc_alloc; /* | same as common */
u_long xc_echo; /* v */
u_long xc_rsvd; /* alignment */
xtp_key xc_xkey; /* exchange key field (8) */
};
/*
* Multicast join control segment
*/
struct xtpjcntl {
xtp_seq xc_rseq; /* ^ */
xtp_seq xc_alloc; /* | same as common */
u_long xc_echo; /* v */
u_long xc_rsvd; /* alignment */
xtp_key xc_xkey; /* exchange key field (8) */
};
/*
* Management Segment Fields
*/
struct xtpmgnt {
u_long xm_code; /* code for diag */
u_long xm_val; /* val for diag */
char xm_msg[128]; /* text of the diag message */
};
struct xtphdr_long {
struct xtphdr xp_header;
#define xh_key xp_header.xh_key
#define xh_cmd xp_header.xh_cmd
#define xh_dlen xp_header.xh_dlen
#define xh_check xp_header.xh_check
#define xh_sort xp_header.xh_sort
#define xh_sync xp_header.xh_sync
#define xh_seq xp_header.xh_seq
union {
struct xtpaddrseg addr; /* address segment */
struct xtpcntl cntl; /* common control segment */
struct xtptcntl tcntl; /* Traffic-shaping segment */
} xp_seg;
#define xp_addr xp_seg.addr
#define xp_cntl xp_seg.cntl
#define xp_tcntl xp_seg.tcntl
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -