File: mac_control.uts

package info (click to toggle)
scapy 2.6.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,956 kB
  • sloc: python: 163,618; sh: 90; makefile: 11
file content (149 lines) | stat: -rw-r--r-- 4,615 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
% MACControl test campaign

#
# execute test:
# $ test/run_tests -P "load_contrib('mac_control')" -t test/contrib/mac_control.uts
#

+ Basic layer handling

= pause frame

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC)/\
      MACControlPause(pause_time=0x1234)

frm = Ether(frm.do_build())

pause_layer  = frm[MACControlPause]
assert pause_layer.pause_time == 0x1234
assert pause_layer.get_pause_time(ETHER_SPEED_MBIT_10) == 0.238592

= gate frame

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC)/\
      MACControlGate(timestamp=0x12345678)
frm = Ether(frm.do_build())

gate_layer  = frm[MACControlGate]
assert gate_layer.timestamp == 0x12345678

= report frame

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC)/\
      MACControlReport(timestamp=0x12345678, pending_grants=0x23)

frm = Ether(frm.do_build())

report_layer = frm[MACControlReport]

assert report_layer.timestamp == 0x12345678
assert report_layer.pending_grants == 0x23

= report frame flags (generic for all other register frame types)

for flag in MACControl.REGISTER_FLAGS:
      frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC) / \
            MACControlReport(timestamp=0x12345678, flags=flag)
      frm = Ether(frm.do_build())
      report_layer = frm[MACControlReport]
      assert report_layer.flags == flag

= register_req frame

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC)/\
            MACControlRegisterReq(timestamp=0x87654321,
                                  echoed_pending_grants=0x12,
                                  sync_time=0x3344,
                                  assigned_port=0x7766)

frm = Ether(frm.do_build())
register_req_layer = frm[MACControlRegisterReq]

assert register_req_layer.timestamp == 0x87654321
assert (register_req_layer.echoed_pending_grants == 0x12)
assert (register_req_layer.sync_time == 0x3344)
assert (register_req_layer.assigned_port == 0x7766)

= register frame

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC)/\
            MACControlRegister(timestamp=0x11223344,
                               echoed_assigned_port=0x2277,
                               echoed_sync_time=0x3399)

frm = Ether(frm.do_build())
register_layer = frm[MACControlRegister]
assert register_layer.timestamp == 0x11223344
assert register_layer.echoed_assigned_port == 0x2277
assert register_layer.echoed_sync_time == 0x3399

= register_ack frame

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC)/\
            MACControlRegisterAck(timestamp=0x11223344,
                                  echoed_assigned_port=0x2277,
                                  echoed_sync_time=0x3399)

frm = Ether(frm.do_build())
register_ack_layer = frm[MACControlRegisterAck]
assert register_ack_layer.timestamp == 0x11223344
assert register_ack_layer.echoed_assigned_port == 0x2277
assert register_ack_layer.echoed_sync_time == 0x3399

= class based flow control frame

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC)/ \
      MACControlClassBasedFlowControl(c0_enabled=1, c0_pause_time=0x4321,
                                      c5_enabled=1, c5_pause_time=0x1234)

frm = Ether(frm.do_build())
cbfc_layer = frm[MACControlClassBasedFlowControl]
assert cbfc_layer.c0_enabled
assert cbfc_layer.c0_pause_time == 0x4321
assert cbfc_layer.c5_enabled
assert cbfc_layer.c5_pause_time == 0x1234
assert not cbfc_layer.c1_enabled
assert cbfc_layer.c1_pause_time == 0
assert not cbfc_layer.c7_enabled
assert cbfc_layer.c7_pause_time == 0
assert cbfc_layer._reserved == 0

+ test padding

= naked frame

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC) / \
            MACControlRegisterAck(timestamp=0x12345678)

frm = frm.do_build()
assert len(frm) == 60

= single vlan tag

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC) / \
            Dot1Q(vlan=42) / \
            MACControlRegisterAck(timestamp=0x12345678)

frm = frm.do_build()
assert len(frm) == 60

= QinQ

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC) / \
            Dot1Q(vlan=42) / \
            Dot1Q(vlan=42) / \
            MACControlRegisterAck(timestamp=0x12345678)

frm = frm.do_build()
assert len(frm) == 60

= hand craftet payload (disabled auto padding)

frm = Ether(src='00:01:01:01:01:01', dst=MACControl.DEFAULT_DST_MAC) / \
            MACControlRegisterAck(timestamp=0x12345678) / \
            Raw(b'may pass devices')

frm = Ether(frm.do_build())
raw_layer = frm[Raw]
assert raw_layer.load == b'may pass devices'
assert len(frm) < 64