CCSDS_study project
This commit is contained in:
44
Protocol_Modelization.py
Normal file
44
Protocol_Modelization.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# 导入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())
|
||||
Reference in New Issue
Block a user