📄 encdec.h
字号:
/********************************************************************/
/* Product Name: ZXB10 */
/* Module Name: A075 */
/* File Name: Encdec.h */
/* Author Name: Jing Xiaoyuan, Li Jianping */
/* weng.qing */
/* Creat Date: 12/20/99 */
/* Version : 1.1 */
/* Function : Ldp进程的编解码头文件 */
/* Description : 兼容性改造 date:2k/11/24 */
/* References : draft-ietf-mpls-ldp-11.txt */
/* draft-ietf-mpls-crldp-04.txt */
/********************************************************************/
#ifndef _ENCDEC_H
#define _ENCDEC_H
#ifdef VXWORKS
#define __LITTLE_ENDIAN__
#define LITTLE_ENDIAN_BYTE_ORDER
#include <types.h> /* u_long, u_char, u_short, float etc. */
#else
#include <sys/types.h> /* unsigned long, unsigned char, unsigned short, float etc. */
#endif /*VXWORKS */
#include <mpls_in.h>
#include "_noalign.h"
#define MEM_COPY(X, Y, Z) memcpy(X, Y, Z)
/*******************************************************************
* Added by ljp at 02/11/99 *
********************************************************************/
#define bzero(x, y) memset(x,0,y)
/* macros to handle different byte orders (little endian or big endian) */
#ifdef LITTLE_ENDIAN_BYTE_ORDER
#define BITFIELDS_ASCENDING_2(X, Y) Y; X;
#define BITFIELDS_ASCENDING_3(X, Y, Z) Z; Y; X;
#define BITFIELDS_ASCENDING_4(X, Y, Z, W) W; Z; Y; X;
#define BITFIELDS_ASCENDING_7(X, Y, Z, W, U, A, B) B; A; U; W; Z; Y; X;
#else
#define BITFIELDS_ASCENDING_2(X, Y) X; Y;
#define BITFIELDS_ASCENDING_3(X, Y, Z) X; Y; Z;
#define BITFIELDS_ASCENDING_4(X, Y, Z, W) X; Y; Z; W;
#define BITFIELDS_ASCENDING_7(X, Y, Z, W, U, A, B) X; Y; Z; W; U; A; B;
#endif /*LITTLE_ENDIAN_BYTE_ORDER */
/* macros used to decode the entire LDP; they declare local var for
different type of messages */
/*mplsLdp ## e ## Msg_t test ## e ## Msg; */
#define MPLS_MSGSTRUCT( e ) \
mplsLdp ## e ## Msg_t e ## Msg;
/*test ## e ## Msg */
#define MPLS_MSGPARAM( e ) \
e ## Msg
/* add by jxy 12/06/1999 */
#define MPLS_DECODE_LDPMSG( e ) \
Mpls_decodeLdp ## e ## Msg
#define PRINT_MSG( e ) \
print ## e ## Msg
#define DEBUG_INFO 0 /* set this to 0 if no debug info
required */
/* debug macros */
#define DEBUG_CALL(X) if (DEBUG_INFO) X;
#define PRINT_2(X, Y) if (DEBUG_INFO) printf(X, Y)
#define PRINT_4(X, Y, Z, W) if (DEBUG_INFO) printf(X, Y, Z, W)
#define PRINT_ERR(X) if (DEBUG_INFO) printf(X)
#define PRINT_ERR_2(X, Y) if (DEBUG_INFO) printf(X, Y)
#define PRINT_ERR_4(X, Y, Z, W) if (DEBUG_INFO) printf(X, Y, Z, W)
/*
* MESSAGE TYPE CONSTANS & TLV CONSTANTS
*/
#define MPLS_LDP_ATMLBLMAXLEN 10 /* for mib MPLS_ATMLBLMAXLEN 10 */
#define MPLS_LDP_HDRSIZE 10 /* the size for mpls ldp pdu hdr*/
#define MPLS_MSGHDRFIXLEN 4 /* MessageType + MessageLength */
#define MPLS_TLVFIXLEN 4 /* type + len */
#define MPLS_MSGIDFIXLEN 4 /* message ID */
#define MPLS_LDPIDLEN 6 /* lsrId (4)+ space(2) */
#define MPLS_PDUMAXLEN 4096 /* octets */
#define MPLS_VERSION 0x0001
#define MPLS_IPV4ADDRFAMILYN 0x0100 /* rfc 1700 (network order) ?? */
#define MPLS_INIFINITE_TIMEVAL 0xfffff
/* draft-ietf-mpls-ldp-11.txt page 57 */
/* for initialize message */
#define MPLS_INIT_MSGTYPE 0x0200 /* initialization msg */
#define MPLS_CSP_TLVTYPE 0x0500 /* common params for init msg */
#define MPLS_ASP_TLVTYPE 0x0501 /* atm session params */
#define MPLS_FSP_TLVTYPE 0x0502 /* frame relay session params */
#define MPLS_ASPFIXLEN 4 /* M + N + D + res */
#define MPLS_FSPFIXLEN 4 /* M + N + res */
#define MPLS_CSPFIXLEN 14 /* protocolV + ... + ldp ids */
#define MPLS_ATMLRGFIXLEN 8
#define MPLS_FRLRGFIXLEN 8
#define MPLS_ASP_NOMERGE 0
#define MPLS_ASP_VPMERGE 1
#define MPLS_ASP_VCMERGE 2
#define MPLS_ASP_VPVCMERGE 3
#define MPLS_FRLBLMAXLEN 10 /*???wengqing 2k/11/24 */
#define MPLS_FRDLCI10BITS 0
#define MPLS_FRDLCI23BITS 2
/* draft-ietf-mpls-ldp-11.txt page 65 Len values 1 and 3 are reserved*/
/* draft-ietf-mpls-ldp-11.txt page 49 */
/* for notification message */
#define MPLS_NOT_MSGTYPE 0x0001 /* notification msg */
#define MPLS_NOT_ST_TLVTYPE 0x0300 /* status tlv for not msg */
#define MPLS_NOT_ES_TLVTYPE 0x0301 /* extended status for not msg */
#define MPLS_NOT_RP_TLVTYPE 0x0302 /* returned PDU for not msg */
#define MPLS_NOT_RM_TLVTYPE 0x0303 /* returned msg for not msg */
#define MPLS_STATUSFIXLEN 10 /* status code + id + type */
#define MPLS_EXSTATUSLEN 4
#define MPLS_NOT_MAXSIZE MPLS_PDUMAXLEN - MPLS_TLVFIXLEN - \
MPLS_MSGIDFIXLEN - MPLS_STATUSFIXLEN
/* wengqing 2k/11/24 - MPLS_STATUSFIXLEN */
/* draft-ietf-mpls-ldp-11.txt page 53 */
/* for hello message */
#define MPLS_HELLO_MSGTYPE 0x0100 /* hello msg */
#define MPLS_CHP_TLVTYPE 0x0400 /* Common Hello Param Tlv */
#define MPLS_IPV4_TRADR_TLVTYPE 0x0401 /* Ipv4 Transport Address Tlv */
#define MPLS_CSN_TLVTYPE 0x0402 /* Conf Seq Number Param Tlv */
#define MPLS_IPV6_TRADR_TLVTYPE 0x0403 /* Ipv6 Transport Address Tlv */
#define MPLS_CHPFIXLEN 4
#define MPLS_CSNFIXLEN 4 /* HoldTime+T+R+Reserved */
//#define MPLS_TRADRFIXLEN 4
#define MPLS_IPV4_TRADRFIXLEN 4
#define MPLS_IPV6_TRADRFIXLEN 16 /* wengqing 2k/11/24
draft-ietf-mpls-ldp-11.txt page 55 */
/* draft-ietf-mpls-ldp-11.txt page 66 */
/* for keep alive message */
#define MPLS_KEEPAL_MSGTYPE 0x0201 /* keep alive msg */
/* draft-ietf-mpls-ldp-11.txt page 66 */
/* for address messages */
#define MPLS_ADDR_MSGTYPE 0x0300 /* address msg */
#define MPLS_ADDRWITH_MSGTYPE 0x0301 /* address withdraw msg */
#define MPLS_ADDRLIST_TLVTYPE 0x0101 /* addrss list tlv type */
#define MPLS_IPv4LEN 4
#define MPLS_ADDFAMFIXLEN 2
#define MPLS_ADDLISTMAXLEN (MPLS_PDUMAXLEN - MPLS_TLVFIXLEN - MPLS_MSGIDFIXLEN - MPLS_ADDFAMFIXLEN)
#define MPLS_MAXNUMBERADR ((MPLS_ADDLISTMAXLEN) / MPLS_IPv4LEN)
/* wengqing 2k/11/24 originally
MPLS_ADDLISTMAXLEN
MPLS_PDUMAXLEN - 2*MPLS_TLVFIXLEN - \
MPLS_MSGIDFIXLEN - MPLS_ADDFAMFIXLEN
only defined for ipv4 address
*/
/* draft-ietf-mpls-ldp-11.txt page 68,page 37 */
/* draft-ietf-mpls-crldp-04.txt page */
/* for label mapping message */
#define MPLS_LBLMAP_MSGTYPE 0x0400 /* label mapping msg */
#define MPLS_FEC_TLVTYPE 0x0100 /* label mapping msg */
#define MPLS_GENLBL_TLVTYPE 0x0200 /* generic label tlv */
#define MPLS_ATMLBL_TLVTYPE 0x0201 /* atm label tlv */
#define MPLS_FRLBL_TLVTYPE 0x0202 /* frame relay label tlv */
#define MPLS_HOPCOUNT_TLVTYPE 0x0103 /* ho count tlv */
#define MPLS_PATH_TLVTYPE 0x0104 /* path vector tlv */
#define MPLS_REQMSGID_TLVTYPE 0x0600 /* lbl request msg id tlv */
#define MPLS_WC_FEC 0x01 /* wildcard fec element */
#define MPLS_PREFIX_FEC 0x02 /* prefix fec element */
#define MPLS_HOSTADR_FEC 0x03 /* host addr fec element */
#define MPLS_CRLSP_FEC 0x04 /* crlsp fec element */
#define MPLS_FECMAXLEN (MPLS_PDUMAXLEN - 2*MPLS_TLVFIXLEN - \
MPLS_MSGIDFIXLEN- MPLS_LBLFIXLEN)
#define MPLS_LBLFIXLEN 4 /* atm: v + vpi + vci + res */
/* generic: Label */
/* fr: reserved + Len + DLCI */
/*???wengqing 2k/11/24
MPLS_FECMAXLEN
MPLS_PDUMAXLEN - 2*MPLS_TLVFIXLEN - \
MPLS_MSGIDFIXLEN
*/
#define MPLS_HOPCOUNTFIXLEN 1 /* HC value */
#define MPLS_FEC_ELEMTYPELEN 1
#define MPLS_FEC_PRELENLEN 1
#define MPLS_FEC_HOSTADDRLEN 1 /* wengqing 2k/11/24
Host Address Len */
#define MPLS_FEC_HOSTADDR 4
#define MPLS_FEC_ADRFAMLEN 2
#define MPLS_FEC_CRLSPLEN 1 /* length of cr lsp fec */
#define MPLS_MAXHOPSNUMBER 255 /* max # hops in path vector */
#define MPLS_MAXNUMFECELEMENT 10 /* max # of fec elements */
/* ??? wengqing 2k/11/24 */
/* draft-ietf-mpls-ldp-11.txt page 73*/
/* for label request message */
#define MPLS_LBLREQ_MSGTYPE 0x0401 /* label request msg */
//#define MPLS_LBLMSGID_TLVTYPE 0x0601 /* lbl return msg id tlv */
/* wengqing 2k/11/24
no this tlv */
/* draft-ietf-mpls-ldp-11.txt page 77 */
/* for label withdraw and release messages */
#define MPLS_LBLWITH_MSGTYPE 0x0402 /* label withdraw msg */
#define MPLS_LBLREL_MSGTYPE 0x0403 /* label release msg */
/* draft-ietf-mpls-ldp-11.txt page 74 */
#define MPLS_LBLABORT_MSGTYPE 0x0404 /* label abort request msg */
/* for ER tlvs */
#define MPLS_ER_TLVTYPE 0x0800 /* constraint routing tlv */
#define MPLS_TRAFFIC_TLVTYPE 0x0810 /* traffic parameters tlv */
//#define MPLS_PDR_TLVTYPE 0x0811 /* traffic peak data rate tlv */
//#define MPLS_CDR_TLVTYPE 0x0812 /* committed data rate tlv */
//#define MPLS_CBT_TLVTYPE 0x0813 /* committed burst tolerance */
/* wengqing 2k/11/24 should be deleted */
#define MPLS_PREEMPT_TLVTYPE 0x0820 /* preemption tlv */
#define MPLS_LSPID_TLVTYPE 0x0821 /* lspid tlv */
#define MPLS_RESCLASS_TLVTYPE 0x0822 /* resource class tlv */
#define MPLS_PINNING_TLVTYPE 0x0823 /* route pinning tlv */
#define MPLS_ERHOP_IPV4_TLVTYPE 0x0801 /* explicit routing ipv4 tlv */
#define MPLS_ERHOP_IPV6_TLVTYPE 0x0802 /* explicit routing ipv6 tlv */
#define MPLS_ERHOP_AS_TLVTYPE 0x0803 /* explicit routing autonomous
system number tlv */
#define MPLS_ERHOP_LSPID_TLVTYPE 0x0804 /* explicit routing lspid tlv */
#define MPLS_ERHOP_IPV4_FIXLEN 8 /* fix length in bytes */
#define MPLS_ERHOP_IPV6_FIXLEN 20 /* fix length in bytes */
#define MPLS_ERHOP_AS_FIXLEN 4 /* fix length in bytes */
#define MPLS_ERHOP_LSPID_FIXLEN 8 /* fix length in bytes */
#define MPLS_IPV6ADRLENGTH 16
#define MPLS_MAX_ER_HOPS 20 /* decent number of hops;
change if required */
/* wengqing 2k/11/24
how to determine? */
#define MPLS_PREEMPTTLV_FIXLEN 4 /* setPrio + holdPrio + res */
#define MPLS_LSPIDTLV_FIXLEN 8 /* res + crlspId + routerId */
#define MPLS_TRAFFICPARAMLENGTH 4 /* traffic parameters length */
#define MPLS_CRLSP_ACTION_INIT 0x0 /* LSPID tlv action flag initate*/
#define MPLS_CRLSP_ACTION_MODIFY 0x1 /* LSPID tlv action flag modify */
#define MPLS_LDP_UNKNOWN_TLV_NO 5 /* mpls unknown tlv number */
#define MPLS_LDP_UNKNOWN_TLV_LENGTH 256 /* mpls unknown tlv length */
/*
* Error codes
*/
#define MPLS_ENC_BUFFTOOSMALL -1
#define MPLS_MSG_LENGTH_ERROR -2
#define MPLS_TLV_LENGTH_ERROR -3
#define MPLS_TLV_VAL_ERROR -4
#define MPLS_ENC_TLVERROR -5
#define MPLS_ENC_ATMLBLERROR -6
#define MPLS_ENC_BASEMSGERROR -7
#define MPLS_FECELEM_ERROR -8
#define MPLS_ENC_CSPERROR -9
#define MPLS_ENC_ASPERROR -11
#define MPLS_ENC_FSPERROR -13
#define MPLS_ENC_STATUSERROR -16
#define MPLS_ENC_EXSTATERROR -18
#define MPLS_ENC_RETPDUERROR -20
#define MPLS_ENC_RETMSGERROR -22
#define MPLS_PDU_LENGTH_ERROR -24
#define MPLS_ENC_CHPERROR -25
#define MPLS_ENC_CSNERROR -27
#define MPLS_ENC_TRADRERROR -29
#define MPLS_ENC_ADRLISTERROR -31
#define MPLS_WC_FECERROR -33
#define MPLS_ENC_FECERROR -35
#define MPLS_ENC_GENLBLERROR -37
#define MPLS_ENC_MAPATMERROR -39
#define MPLS_ENC_FRLBLERROR -41
#define MPLS_ENC_COSERROR -43
#define MPLS_ENC_HOPCOUNTERROR -45
#define MPLS_ENC_PATHVECERROR -47
#define MPLS_ENC_LBLMSGIDERROR -49
#define MPLS_ENC_HDRTLVERROR -51
#define MPLS_ENC_FECELEMERROR -53
#define MPLS_ENC_FSPLBLERROR -55
#define MPLS_ENC_ERHOPERROR -57
#define MPLS_ENC_ERTLVERROR -59
#define MPLS_ENC_ERHOPLENERROR -61
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -