The invention discloses a network flow generating and repairing method based
on protocol constraint. The method comprises the following steps: analyzing an original traffic capture file, extracting basic features through
stream-level recombination and session segmentation, and mapping a continuous
time sequence and a discrete protocol field to a uniform feature space; and on the basis, constructing a
diffusion type network flow generation model to capture a statistical attribute and
time sequence dependency relationship of the network flow. In the generating or repairing process, a protocol state
machine is constructed, protocol constraint is introduced in the reverse denoising stage, the sampling process is constrained through a legality guiding mechanism, and protocol logic violation in the generating process is avoided. And finally, through feature inverse mapping and virtual
protocol stack state maintenance, reconstructing to obtain network flow data which meets a communication
protocol specification and can be correctly analyzed by a real
protocol stack. According to the method, the generation and repair of the network traffic can be realized under a unified framework, and the
correctness of a result in protocol
semantics is ensured.