-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror_pattern_synthesizer.py
More file actions
62 lines (49 loc) · 2.1 KB
/
error_pattern_synthesizer.py
File metadata and controls
62 lines (49 loc) · 2.1 KB
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
# Run with python version 2
import random
HEX_FIELD = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
if __name__ == "__main__":
# receive 3 parameters
symbols = raw_input("How many patterns do you want to generate ? ")
symbols = int(symbols,10)
symbolSize = raw_input("Enter Symbol size in bytes: ")
symbolSize = int(symbolSize,10)
print 'Up to this moment, we just support Hex representation (field is fixed to 8)'
packetErrorRate = raw_input("Packets error rate(%): ")
packetErrorRate = int(packetErrorRate,10)
symbolErrorRate = raw_input("Symbols error rate(%): ")
symbolErrorRate = int(symbolErrorRate,10)
fileName = "pktErr-"
fileName += str(packetErrorRate)
fileName +="-symErr-"
fileName += str(symbolErrorRate)
fileName += ".txt"
file= open(fileName,"w+")
originalPacketList = []
OriginalPacket = ''
# two hex representation can be seen as a byte
for i in range (0,symbolSize):
tempA = HEX_FIELD[random.randrange(0,16,1)]
tempB = HEX_FIELD[random.randrange(0,16,1)]
tempSymbol = tempA + tempB
OriginalPacket += tempSymbol
originalPacketList.append(tempSymbol)
print "The original Packet: ", OriginalPacket
for i in range(0,symbols):
# write error pattern into a file
packetErrorChance = random.randrange(1,101,1)
if(packetErrorChance<packetErrorRate):
# we should change the symbol
errorPattern =''
for j in range (0 , symbolSize):
symbolErrorChance = random.randrange(1,101,1)
if(symbolErrorChance < symbolErrorRate ):
error = ''
firstRandHex = HEX_FIELD[random.randrange(0,16,1)]
secondRandHex = HEX_FIELD[random.randrange(0,16,1)]
error = firstRandHex + secondRandHex
errorPattern +=error
else:
errorPattern +=originalPacketList[j]
file.write(errorPattern+"\n")
else:
file.write(OriginalPacket+"\n")