One Train for Two Tasks: An Encrypted Traffic Classification Framework Using Supervised Contrastive Learning

Haozhen Zhang, Xi Xiao, Le Yu, Qing Li, Zhen Ling, Ye ZhangarXiv 2024 · DOI

Abstract

As internet traffic becomes increasingly encrypted, traditional classification methods like Deep Packet Inspection (DPI) are losing efficacy. We present CLE-TFE (Contrastive Learning Enhanced Temporal Fusion Encoder), a novel framework designed to perform both packet-level and flow-level encrypted traffic classification within a single training pass. By integrating supervised contrastive learning (SCL) and graph-based data augmentation, CLE-TFE captures semantic-invariant features across different traffic samples. Our results demonstrate that CLE-TFE achieves state-of-the-art accuracy—including a 1.0000 F1-score on the ISCX-Tor dataset—while utilizing only 1/14th of the computational resources required by large-scale models like ET-BERT.

Introduction

The transition toward near-universal encryption (via VPNs, Tor, and TLS) has created a significant blind spot for network security. While encryption protects user privacy, it also provides cover for malicious activities. Current deep learning approaches to traffic classification often suffer from two primary limitations: redundancy and feature underutilization. Most models treat packet-level and flow-level classification as isolated problems, requiring separate training cycles. Furthermore, they often fail to learn the underlying relationships between similar traffic types, focusing instead on raw statistical features in isolation.

The CLE-TFE Framework

CLE-TFE addresses these challenges by employing a Graph Neural Network (GNN) backbone enhanced with several key innovations designed to unify multi-level classification tasks.

The CLE-TFE framework architecture, illustrating the joint packet-level and flow-level contrastive learning paths.

Supervised Contrastive Learning (SCL)

Unlike standard self-supervised contrastive learning, which matches a sample only with its own augmented version, CLE-TFE utilizes labels to treat all samples within a batch sharing the same label as "positives." This approach forces the model to cluster similar traffic types together in the embedding space, sharpening decision boundaries.

Dual-Level Augmentation and Multi-Task Learning

The framework operates at two granularities:

  1. Packet Level: Traffic is represented as graphs of byte correlations. Data augmentation is performed by randomly dropping nodes (bytes) or edges (correlations).
  2. Flow Level: The model processes sequences of packets. To simulate real-world network conditions, flow augmentation involves randomly dropping entire packets.

A shared backbone with dual classification heads allows the model to learn from both signals simultaneously, creating a "helper effect" where improved packet representations lead to more robust flow-level understanding.

Experimental Evaluation

The model was evaluated on two industry-standard benchmarks: ISCX VPN-nonVPN and ISCX Tor-nonTor. These datasets contain complex, multi-layered encrypted traffic that is notoriously difficult to classify. To maintain efficiency, flows were limited to the first 15 packets and filtered for those containing payloads.

Results and Discussion

CLE-TFE demonstrated superior performance across multiple metrics. Notably, it achieved a perfect 1.0000 F1-score on the ISCX-Tor dataset and outperformed the previous state-of-the-art (TFE-GNN) by 2.4% to 5.7% on other benchmarks.

t-SNE visualizations of flow and packet representations, comparing the default CLE-TFE with variants lacking the contrastive learning (CL) task.

Efficiency and Robustness

A critical advantage of CLE-TFE is its computational efficiency. The model requires approximately 1/14th of the Floating Point Operations (FLOPs) used by heavyweights like ET-BERT, making it suitable for deployment in resource-constrained environments. Ablation studies revealed that perturbing packet headers during graph augmentation had a more significant impact than perturbing payloads, suggesting the model relies heavily on structural metadata to distinguish protocols.

Conclusion

CLE-TFE proves that a well-designed GNN architecture, when combined with supervised contrastive learning, can match or exceed the performance of much larger pre-trained models. By unifying packet and flow classification into a single, efficient training pass, the framework offers a scalable solution for modern encrypted traffic analysis. Future work will explore learnable graph augmentation and hard negative mining to further refine the model's discriminative power.

Summary updated

BibTeX
@misc{zhang2024one,
  author = {Haozhen Zhang and Xi Xiao and Le Yu and Qing Li and Zhen Ling and Ye Zhang},
  title = {{One Train for Two Tasks: An Encrypted Traffic Classification Framework Using Supervised Contrastive Learning}},
  year = {2024},
  eprint = {2402.07501},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.07501},
}
Figure