Files
CCSDS_study/Protocol_Modelization.py
2026-05-05 21:54:35 +08:00

44 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 导入Netzob库
from netzob.all import *
# 定义以太网802.3协议的各个字段
# 1. 以太网长度字段16位2字节
eth_length = Field(bitarray('0000000000000000'), "eth.length")
# 2. IEEE 802.2 LLC头部固定3字节
eth_llc = Field(Raw(nbBytes=3), "eth.llc")
# 3. 以太网载荷字段
eth_payload = Field(Raw(), name="eth.payload")
# 4. 填充字段保证以太网最小帧长60字节
eth_padding = Field(Padding(
[eth_length, eth_llc, eth_payload],
data=Raw(nbBytes=1),
modulo=8*60),
"eth.padding"
)
# 5. 以太网CRC校验字段32位
eth_crc_802_3 = Field(bitarray('00000000000000000000000000000000'), "eth.crc")
# 设置CRC32校验规则
eth_crc_802_3.domain = CRC32(
[eth_length, eth_llc, eth_payload, eth_padding],
dataType=Raw(nbBytes=4, unitSize=UnitSize.SIZE_32)
)
# 设置长度字段计算LLC+载荷的总长度
eth_length.domain = Size(
[eth_llc, eth_payload],
dataType=uint16(),
factor=1./8
)
# 构建完整的以太网802.3协议符号
symbol = Symbol(
name="ethernet_802_3",
fields=[eth_length, eth_llc, eth_payload, eth_padding, eth_crc_802_3]
)
# 打印协议结构
print(symbol.str_structure())