CN101697546B - Method for implementing protocol data unit (PDU) used for packing and unpacking network bytes - Google Patents

Method for implementing protocol data unit (PDU) used for packing and unpacking network bytes Download PDF

Info

Publication number
CN101697546B
CN101697546B CN200910233479A CN200910233479A CN101697546B CN 101697546 B CN101697546 B CN 101697546B CN 200910233479 A CN200910233479 A CN 200910233479A CN 200910233479 A CN200910233479 A CN 200910233479A CN 101697546 B CN101697546 B CN 101697546B
Authority
CN
China
Prior art keywords
field
type
protocol
fields
length
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN200910233479A
Other languages
Chinese (zh)
Other versions
CN101697546A (en
Inventor
杨学书
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ho whale cloud computing Polytron Technologies Inc
Original Assignee
ZTEsoft Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by ZTEsoft Technology Co Ltd filed Critical ZTEsoft Technology Co Ltd
Priority to CN200910233479A priority Critical patent/CN101697546B/en
Publication of CN101697546A publication Critical patent/CN101697546A/en
Application granted granted Critical
Publication of CN101697546B publication Critical patent/CN101697546B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention discloses a method for implementing a protocol data unit (PDU) used for packing and unpacking network bytes, which comprises the following steps: firstly, defining an XML field configuration file of a needed transmission protocol; and then performing packing and unpacking, wherein the XML field configuration file comprises order, length and data type of fields in the transmission protocol. The method solves the problems of complex programming model and inconvenient protocol field change in the conventional network programming, improves the efficiency of network byte stream programming, facilitates packing and unpacking the network bytes, shields the difference of high-low bytes, and provides good debugging information and unified traffic monitoring.

Description

The protocol Data Unit PDU implementation method that is used for the network bytes packing and unpacks
Technical field
The present invention relates to telecom business support system, the especially packing of the real-time Socket message of Online Charging System, separate packet technology, specifically a kind of protocol Data Unit PDU implementation method that is used for the network bytes packing and unpacks.
Background technology
The Modern Telecommunication business support system generally all is made up of a plurality of network element nodes; Accomplish functions such as charging, comprehensive customer service, Short Message Service Gateway, voice gateways, the control that continues respectively; In order telecommunication service to be provided to the end user, need mutual communication between each network element, accomplish functions such as data sync, business continuing control; In such complicated distributed system, ubiquitous based on the network service demand of TCP/IP.
Traditional network bytes is packed and unpacked needs to pay close attention to various java data type conversion constantly the details that is binary data, and the position that need when programming, note current packing, parsing field.This programming mode has proposed higher requirement to programmer's ability, and as easy as rolling off a log makeing mistakes.Traditional network bytes packaging technique also has a problem that autgmentability is bad, and that is exactly when increasing new procotol, the code that need write packing again and unpack.Therefore, this packing and the method that unpacks are too loaded down with trivial details, and be complicated at programming model, and protocol fields needs to use inconvenience under the situation of often change, can not satisfy simple, as to be prone to expansion requirement.
Summary of the invention
The objective of the invention is to existing network bytes packing and the method complicacy that unpacks, complicated at programming model; Protocol fields needs under the situation of often change; Use inconvenience; Can not satisfy simple, as to be prone to expansion requirement problem, propose a kind of protocol Data Unit PDU implementation method that is used for the network bytes packing and unpacks that solves the complex network programming.
Technical scheme of the present invention is:
A kind of protocol Data Unit PDU implementation method that is used for the network bytes packing and unpacks, it may further comprise the steps:
(a). define the expandable mark language XML field configuration file of required host-host protocol, comprise order, length and the data type of field in the host-host protocol;
(b). packing: read the field configuration file of this agreement, obtain the data type and the data length of each field, the java fundamental type numerical value of this each field of agreement is set then, read all fields of this agreement successively:
If this field is the java fundamental type, convert the java fundamental type numerical value of this field into byte data; If this field is a son bag type, read all fields of son bag, be packaged into byte data successively; Travel through all fields of this agreement, obtain final byte arrays;
(c). unpack: the byte arrays that acquisition need unpack, according to the protocol fields configuration file that reads in advance, obtain the data length of an only field:
If the java basic data type that this field is converts byte data into predefined java basic data type; If the type of this field is a son bag type, resolve all fields of this child bag successively, obtain the java basic data type; Travel through all fields of this agreement, resolve successively and obtain the java basic data type.
Beneficial effect of the present invention:
It is complicated to the invention solves the programming model that exists in the legacy network programming, and protocol fields changes the problem of inconvenience, provides a kind of network bytes simple, that be prone to expansion to flow packing, unpacking method.
The present invention improves the efficient of network bytes stream programming, make the network bytes packing, unpack and become simple; Shielded the difference of high low byte, good Debugging message is provided and unified traffic monitoring is provided.
Description of drawings
Fig. 1 concerns sketch map in each object in the PDU implementation method of the present invention.
Embodiment
Below in conjunction with accompanying drawing and embodiment the present invention is further described.
Define order, length, the data type of field in the agreement through the XML configuration file.The complicacy read-write of shielding original data type is automatically converted to intelligible basic data type with it, realizes that high low byte preface arbitrarily changes, and can adapt to protocol configuration flexibly.
Shown in figure one, the relation in each object in the PDU implementation method has been described, relevant noun is explained as follows:
Protocol object (Protocol): a byte stream by one or more PDU objects are formed is abstract, can represent a complete agreement, such as the MML agreement, and the SMPP agreement
Son bag (PduBean): for the distincter protocol object of organizing, perhaps reuse protocol definition, can use the form of son bag to organize protocol fields
Protocol fields object (PduField): not subdivisible PDU object, the Field Definition of an atom of expression
PDU: interface definition, protocol object, Zi Bao, protocol fields all realize the IPdu interface, can realize self-contained between such object like this, can think a kind of realization of component pattern.
During practical implementation:
Definition, the exploitation how the example explanation is used the network packing, separated packet technology realization agreement that be embodied as with a MML agreement.
One, as shown in the table like the byte that requires in the agreement:
The message opening flag Verification with Operation information The affairs head Can the thread of a conversation Message header Message-length The message opening flag
The message sending order
Two, definition protocol configuration file is following:
<?xml?version=″1.0″encoding=″UTF-8″?>
<zsmart>
<protocol>
<bufferDefine?name=″MML″>
!--defining main message body-->
<buffer?id=″MML_REQ″seq=″1″fieldname=″MsgBeginFlag″type=″5″
Length=" 4 " defaultValue=" ' SC ' " comments=" message opening flag " />
<buffer id=″MML_REQ″ seq=″2″fieldname=″TotalLen″ type=″5″
Length=" 4 " defaultValue=" 0000 " comments=" total length field " />
<buffer id=″MML_REQ″ seq=″3″fieldname=″msgHeader″ type=″0″
Length=" 4 " defaultValue=" " comments=" message header, son bag " />
<buffer id=″MML_REQ″seq=″4″fieldname=″MML_SessionHeader″
Type=" 0 " length=" 4 " defaultValue=" ' SC ' " comments=" the meeting thread of a conversation, son bag " />
<buffer id=″MML_REQ″seq=″5″fieldname=″MML_transHeader″
Type=" 0 " length=" 4 " defaultValue=" ' SC ' " comments=" affairs head, son bag " />
<buffer?id=″MML_REQ″seq=″6″fieldname=″MML_CMD″ type=″5″
Length=" 0 " defaultValue=" " comments=" MML instruction " />
<buffer id=″MML_REQ″seq=″7″fieldname=″CheckSum″ type=″5″
Length=" 8 " defaultValue=" 9B94EDA4 " comments=" verification with " />
!--definition message chieftain bag-->
<buffer id=″msgHeader″ seq=″1″ fieldname=″version″ type=″5″
Length=" 4 " defaultValue=" 1.00 " comments=" version number " />
<buffer id=″msgHeader″ seq=″2″?fieldname=″endFlag″ type=″5″
Length=" 8 " defaultValue=" JS123456 " comments=" end mark " />
<buffer id=″msgHeader″?seq=″3″?fieldname=″serviceName″ type=″5″
Length=" 8 " defaultValue=" PPS " comments=" Service name " />
!--definition session chieftain bag-->
<buffer id=″MML_SessionHeader″ seq=″1″fieldname=″session_id″
Type=" 5 " length=" 8 " defaultValue=" 00000000 " comments=" session id " />
<buffer id=″MML_SessionHeader″ seq=″2″
fieldname=″session_control_word″type=″5″length=″6″defaultValue=″DlgCon″
Comments=" session control word " />
<buffer id=″MML_SessionHeader″?seq=″3″fieldname=″session?reserved″
Type=" 5 " length=" 4 " defaultValue=" FFFF " comments=" session reserved word " />
!--definition affairs chieftain bag-->
<buffer id=″MML_transHeader″?seq=″1″fieldname=″trans_id″?type=″5″
Length=" 8 " defaultValue=" 00000001 " comments=" affairs ID " />
<buffer id=″MML_transHeader″seq=″2″fieldname=″trans_control_word″
Type=" 5 " length=" 6 " defaultValue=" TxBeg " comments=" affairs control word " />
<buffer id=″MML_transHeader″ ?seq=″3″fieldname=″trans_reserved″
Type=" 5 " length=" 4 " defaultValue=" FFFF " comments=" affairs reserved word " />
!--definition heartbeat message-->
<buffer id=″MML_HEART″ seq=″1″fieldname=″MsgBeginFlag″
Type=" 5 " length=" 4 " defaultValue=" ' SC " ' comments=" message opening flag " />
<buffer?id=″MML_HEART″ seq=″2″?fieldname=″TotalLen″ type=″5″
Length=" 4 " defaultValue=" 0004 " comments=" total length field " />
<buffer id=″MML_HEART″ seq=″3″fieldname=″msgBody″ type=″5″
Length=" 4 " defaultValue=" HBHB " comments=" total length field " />
<buffer?id=″MML_HEART″seq=″4″fieldname=″CheckSum″type=″5″
Length=" 8 " defaultValue=" 00000000 " comments=" verification with " />
</bufferDefine>
</protocol>
</zsmart>
Profile Description:
1, bufferDesine: define a procotol bag
2, buffer: define a single protocol fields
3, Id: define this field and belong to that sub-packet
4, Seq: the serial number in the child bag (in a sub-packet, sequence number can not repeat)
5, Fieldname: field name, in a sub-packet, field name can not repeat
Type: corresponding java data type 1:Byte 2:Short 3:Int 4:Long 5:String (variable length) 6:byte [] array 7:CString, with the character string of NULL end
7, length: field length, if the character string of variable length is made as 0 with length, if field type is Byte, Short, Int, Long can use the default-length of j ava
8, defaultValue: default value, can the field default value be set through this field, if do not give this field settings, will use predefined default value during packing.
Owing to when protocol definition, specified the length and the order of each field, all PDU can accomplish according to order and pack automatically and unpack.
Three, in program, quote protocol object, accomplish protocol packing, unpack.
Packing process is following:
Read configuration file, obtain data type, the data length of a field; The java fundamental type numerical value of each field is set; Java fundamental type numerical value with each field converts byte data into successively; If this field is a son bag type, obtain all fields that change the son bag, be packaged into byte data successively.Travel through all fields, obtain final byte arrays.
It is following to separate packet procedures:
The byte arrays that acquisition need unpack according to the protocol fields configuration of reading in advance, obtains the data length of an only field, converts byte data into predefined java basic data type; Likewise,, resolve all fields of this child bag successively, obtain the java basic data type if the type of this field is a son bag field.Travel through all fields, resolve successively and obtain the java basic data type.
Four, the PDU interface programming for example
The simple protocol packing
// acquisition MML heartbeat protocol definition
Protocol?mmlReq=ProtocolTools.getProtocol(″MML.MML_HEART″,1);
// the msgBody field value is set, its residual value uses the default configuration of configuration file
mmlReq.getPduField(″msgBody″).setValue(″HBHB″);
// packetizes messages
byte[]heartBytes=mmlReq.pack();
logger.info(″MML Heart ″+heartBytes.length+″Bytes″+PubFunc.hexToString(heartBytes));
// print protocol bag details
logger.info(mmlReq);
Top code has been demonstrated the process of using the PDU programming model to pack, can see, and utilizes PDU programming model framework, can realize protocol packing very easily.Promote the efficient of programming.
Execution result
-MML?Heart?16Bytes?27?53?43?27?30?30?30?30?48?42?48?42?31?32?32?32
-mmlHeart:
,[MsgBeginFlag,S,′SC′,,len=4,Hex=27 53 4327 ],[TotalLen,S,0000,,len=4,Hex=30 30 ?3030 ],[msgBody,S,HBHB,,len=4,Hex=48 42 ?4842],[CheckSum,S,1222,,len=4,Hex=31323232]
Top output result has shown title, length, corresponding java value, 16 hex value of each protocol fields, contrasts 16 binary information of whole bag, can obtain needed Debugging message very easily.
The present invention does not relate to all identical with the prior art prior art that maybe can adopt of part and realizes.

Claims (1)

1. one kind is used for the protocol Data Unit PDU implementation method that network bytes is packed and unpacked, and it is characterized in that it may further comprise the steps:
(a). define the expandable mark language XML field configuration file of required host-host protocol, comprise order, length and the data type of field in the host-host protocol;
(b). packing: read the field configuration file of this agreement, obtain the data type and the data length of each field, the java fundamental type numerical value of this each field of agreement is set then, read all fields of this agreement successively:
If this field is the java fundamental type, convert the java fundamental type numerical value of this field into byte data; If this field is a son bag type, read all fields of son bag, be packaged into byte data successively; Travel through all fields of this agreement, obtain final byte arrays;
(c). unpack: the byte arrays that acquisition need unpack, according to the protocol fields configuration file that reads in advance, obtain the data length of an only field:
If this field is the java basic data type, convert byte data into predefined java basic data type; If the type of this field is a son bag type, resolve all fields of this child bag successively, obtain the java basic data type; Travel through all fields of this agreement, resolve successively and obtain the java basic data type.
CN200910233479A 2009-10-30 2009-10-30 Method for implementing protocol data unit (PDU) used for packing and unpacking network bytes Active CN101697546B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN200910233479A CN101697546B (en) 2009-10-30 2009-10-30 Method for implementing protocol data unit (PDU) used for packing and unpacking network bytes

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN200910233479A CN101697546B (en) 2009-10-30 2009-10-30 Method for implementing protocol data unit (PDU) used for packing and unpacking network bytes

Publications (2)

Publication Number Publication Date
CN101697546A CN101697546A (en) 2010-04-21
CN101697546B true CN101697546B (en) 2012-10-03

Family

ID=42142620

Family Applications (1)

Application Number Title Priority Date Filing Date
CN200910233479A Active CN101697546B (en) 2009-10-30 2009-10-30 Method for implementing protocol data unit (PDU) used for packing and unpacking network bytes

Country Status (1)

Country Link
CN (1) CN101697546B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101944025A (en) * 2010-09-16 2011-01-12 福建鑫诺通讯技术有限公司 Automatic TCP/UDP (Transmission Control Protocol/User Datagram Protocol) data packing and unpacking method based on PYTHON language
CN102571775A (en) * 2011-12-27 2012-07-11 长春希达电子技术有限公司 Server communication module, client communication module and network communication system
CN102611530A (en) * 2012-03-08 2012-07-25 北京神州数码思特奇信息技术股份有限公司 Telecommunication data encoding method and telecommunication data decoding method
CN106528823B (en) * 2016-11-18 2019-08-30 中国银行股份有限公司 A kind of configuration of message and output method and device
CN111641638A (en) * 2020-05-28 2020-09-08 浪潮(北京)电子信息产业有限公司 Data transmission method and related device

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101370165A (en) * 2007-08-17 2009-02-18 中兴通讯股份有限公司 Data packet transmission method for multimedia broadcasting service
CN101388900A (en) * 2007-09-12 2009-03-18 大唐移动通信设备有限公司 Processing method, apparatus and system for protocol data unit filling

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101370165A (en) * 2007-08-17 2009-02-18 中兴通讯股份有限公司 Data packet transmission method for multimedia broadcasting service
CN101388900A (en) * 2007-09-12 2009-03-18 大唐移动通信设备有限公司 Processing method, apparatus and system for protocol data unit filling

Also Published As

Publication number Publication date
CN101697546A (en) 2010-04-21

Similar Documents

Publication Publication Date Title
CN101697546B (en) Method for implementing protocol data unit (PDU) used for packing and unpacking network bytes
CN106254381A (en) Protocol analysis method, device and comprise the Layer2 switching system of protocol analysis device
CN106134133B (en) Tunneling time critical messages between substations over WAN
CN105337991A (en) Integrated message flow searching and updating method
CN103546357B (en) The different communication means and system, gateway that is networked between network locomotive again
CN107483592A (en) A kind of transaction processing method based on General Front End Processor and a kind of General Front End Processor
CN105337968A (en) Cross platform communication protocol code conversion method and system
CN105025056A (en) Internet of Things information collection and monitoring system design method
CN111756861A (en) System for realizing internal and external network data exchange based on configuration file
CN109526030A (en) Processing method, device and the equipment of message
CN110266702A (en) Wireshark protocol analysis method based on XML
CN108092739A (en) The transmission method and device of business
CN110213756A (en) A kind of data transmission method, device and its relevant device
WO2019128462A1 (en) Data transmission method, sending apparatus and receiving apparatus
CN102438017A (en) Routing function-based conversion apparatus of Modbus protocol and BACnet Ethernet protocol and conversion method thereof
CN110191447A (en) The filter method and relevant apparatus of Bluetooth broadcast packet in a kind of ESL
WO2015101152A1 (en) Method for extracting transmission payload of dfa-based http chunked transfer encoding
CN103731332B (en) Master-slave communication method and OLT system
CN117041370A (en) Communication method and system
CN105991214A (en) Data transmission method and data transmission device
CN108629048A (en) A kind of routing parameter transmits optimization method and system
CN107342920A (en) Things-internet gateway access device and its data interactive method
CN103246671A (en) Processing method and device for abstract syntax notation files
CN109039537B (en) AMCC information transmission method and system
CN205946180U (en) Independent wireless network system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C56 Change in the name or address of the patentee
CP01 Change in the name or title of a patent holder

Address after: Yuhuatai District of Nanjing City, Jiangsu province 210012 Bauhinia Road No. 68

Patentee after: ZTEsoft Technology Co., Ltd.

Address before: Yuhuatai District of Nanjing City, Jiangsu province 210012 Bauhinia Road No. 68

Patentee before: Nanjing ZTEsoft Technology Co., Ltd.

CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: 210012 room 627, Ning Shuang Road, Yuhuatai District, Nanjing, Jiangsu, 627

Patentee after: Ho whale cloud computing Polytron Technologies Inc

Address before: 210012 No. 68 Bauhinia Road, Yuhuatai District, Jiangsu, Nanjing

Patentee before: ZTEsoft Technology Co., Ltd.