-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery Starbot ⭐ refactored ancker010/exabgp-flowspec-generator #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,25 +14,26 @@ | |
|
||
# Function to generate a random IPv4 address within the given prefix. | ||
def genipv4(): | ||
subnet = IPv4Network("192.168.0.0/16") | ||
subnet = IPv4Network("192.168.0.0/16") | ||
bits = getrandbits(subnet.max_prefixlen - subnet.prefixlen) | ||
addr = IPv4Address(subnet.network_address + bits) | ||
addr_str = str(addr) | ||
return addr_str | ||
return str(addr) | ||
|
||
def genipv6(): | ||
subnet6 = IPv6Network("2001:DB8:beef::/64") | ||
bits6 = getrandbits(subnet6.max_prefixlen - subnet6.prefixlen) | ||
addr6 = IPv6Address(subnet6.network_address + bits6) | ||
addr_str6 = str(addr6) | ||
return addr_str6 | ||
return str(addr6) | ||
Comment on lines
-27
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function genipv6 refactored with the following changes:
|
||
|
||
|
||
# Function to generate a list of flowspec rules based on random data. | ||
def genflows(): | ||
flow_types = [] | ||
flow_types.append( | ||
"announce flow route { match { source " + genipv4() + "/32; destination 192.168.255.10/32; destination-port =" + str(random.randint(1024, 65530)) + "; protocol tcp; } then { rate-limit " + str(random.randint(9600, 51200)) + "; } }") | ||
flow_types = [ | ||
"announce flow route { match { source " + genipv4() + | ||
"/32; destination 192.168.255.10/32; destination-port =" + str( | ||
random.randint(1024, 65530)) + "; protocol tcp; } then { rate-limit " + | ||
str(random.randint(9600, 51200)) + "; } }" | ||
] | ||
Comment on lines
-33
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function genflows refactored with the following changes:
|
||
flow_types.append("announce flow route { match { source " + genipv4() + "/32; } then { discard; } }") | ||
flow_types.append("announce flow route { match { source " + genipv4() + "/32; } then { redirect 666:666; } }") | ||
flow_types.append("announce flow route { match { destination " + genipv4() + "/32; } then { discard; } }") | ||
|
@@ -45,9 +46,12 @@ def genflows(): | |
return flow_types | ||
|
||
def genflows6(): | ||
flow_types6 = [] | ||
flow_types6.append( | ||
"announce flow route { match { source " + genipv6() + "/128; destination 2001:DB8:beef:cafe::1/128; destination-port =" + str(random.randint(1024, 65530)) + "; protocol tcp; } then { rate-limit " + str(random.randint(9600, 51200)) + "; } }") | ||
flow_types6 = [ | ||
"announce flow route { match { source " + genipv6() + | ||
"/128; destination 2001:DB8:beef:cafe::1/128; destination-port =" + str( | ||
random.randint(1024, 65530)) + "; protocol tcp; } then { rate-limit " + | ||
str(random.randint(9600, 51200)) + "; } }" | ||
] | ||
Comment on lines
-48
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function genflows6 refactored with the following changes:
|
||
flow_types6.append("announce flow route { match { source " + genipv6() + "/128; } then { discard; } }") | ||
flow_types6.append("announce flow route { match { source " + genipv6() + "/128; } then { redirect 666:666; } }") | ||
flow_types6.append("announce flow route { match { destination " + genipv6() + "/128; } then { discard; } }") | ||
|
@@ -63,11 +67,11 @@ def genflows6(): | |
|
||
# Append a randomly chosen item from the flow_types list to the messages list to be sent to exabgp. | ||
# This is probably overly complicated, but it does what I want it to do. | ||
for x in range(0, count): | ||
for _ in range(count): | ||
flows = genflows() | ||
messages.append(random.choice(flows)) | ||
|
||
for x in range(0, count): | ||
for x in range(count): | ||
Comment on lines
-66
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 66-70 refactored with the following changes:
|
||
flows6 = genflows6() | ||
messages.append(random.choice(flows6)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function genipv4 refactored with the following changes: