Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions frrouting_automation/frr_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import fileinput




def load_config(filepath):
'''Read JSON configuration'''
topology = os.path.basename(filepath).split('.')[0]
Expand Down Expand Up @@ -42,14 +44,14 @@ def create_networks(links, client):

def create_containers(routers, client, topology):
'''Create a container for each router'''
client.images.pull('colgatenetresearch/frr:version-6.0')
#client.images.pull('frrouting/frr')
images = set()

for router_name in sorted(routers.keys()):
router = routers[router_name]
print("Creating %s" % router.name)
if router.image not in images:
client.images.pull(router.image)
#client.images.pull(router.image)
images.add(router.image)
client.containers.create(router.image, detach=True, name=router.name,
labels=[topology], cap_add=["NET_ADMIN", "SYS_ADMIN"])
Expand All @@ -59,6 +61,7 @@ def config_routers(routers, client):
router = routers[router_name]
config_daemons(router)
config_vtysh(router)
#scapyintegration(router,filename)

if "bgp" in router.protocols:
config_bgp(router)
Expand Down Expand Up @@ -183,7 +186,7 @@ def __str__(self):
class Router:
def __init__(self, name, as_num):
self.name = name
self.image = 'frrouting/frr'
self.image = 'scapyintergration:latest'
self.links = []
self.protocols = set()
self.as_num = as_num
Expand Down Expand Up @@ -272,12 +275,26 @@ def cleanup_topology(topology, client):
print("Cleaning up networks")
client.networks.prune()

def scapyintegration(routers,filename):


if (filename.lower()=="all"):
for router_name in sorted(routers.keys()):
os.system("docker cp ~/protocol-verification/frrouting_automation/scapy_scripts/. " + router_name +":/tmp/")

else:
for router_name in sorted(routers.keys()):
os.system("docker cp ~/protocol-verification/frrouting_automation/scapy_scripts/"+filename+" " + router_name +":/tmp/"+filename)


def main():
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", help="Path to JSON config file", required=True)
parser.add_argument("-a", "--action", choices=['start', 'stop', 'restart'], help="Operation to perform", required=True)
parser.add_argument("-sc", "--scapy", help="Transfer all files using 'all' or a specific file using its filename", required=False)
parser.add_argument("-t", "--tcp", choices=['tcpon'], help="Option to have tcpdump on", required=False)


settings = parser.parse_args()

# Load and parse configuration
Expand All @@ -294,10 +311,17 @@ def main():
print("ERROR: %s is already running; stop or restart the topology" % topology)
else:
launch_topology(topology, routers, links, client)
#implementing the scapy function.
if (settings.scapy in ['all']):
scapyintegration(routers,'all')

else:
scapyintegration(routers,settings.scapy)

#Settings for tcpdump
if (settings.tcp in ['tcpon']):
os.system('docker run --rm --net=host -v ~/protocol-verification/pattern_recog:/tcpdump kaazing/tcpdump')
client.close()


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions frrouting_automation/router_id_name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
router1
router2
router3
15 changes: 15 additions & 0 deletions frrouting_automation/scapy_scripts/arp_scan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import scapy.all as scapy

def Arp(ip):
print(ip)
arp_r = scapy.ARP(pdst=ip)
br = scapy.Ether(dst='ff:ff:ff:ff:ff:ff')
request = br/arp_r
answered, unanswered = scapy.srp(request, timeout=1)
print('\tIP \t\t\t MAC')
for i in answered:
ip, mac = i[1].psrc, i[1].hwsrc
print(ip, '\t\t' + mac)


Arp('172.17.0.0/24') # call the method
18 changes: 18 additions & 0 deletions frrouting_automation/scapy_scripts/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import scapy.all as scapy
from scapy_ospf import OSPF_Hdr, OSPF_Hello

packet = scapy.Ether(src='00:06:28:b9:85:31',dst='01:00:5e:00:00:05')


#packet.show()



packet = packet/scapy.Dot1Q(vlan=33)

#packet.show()
packet = packet/scapy.IP(src='192.16.2.2',dst='172.17.0.5')
packet = packet/OSPF_Hdr(src='192.16.2.2')
packet = packet/OSPF_Hello(router='172.17.2.2',backup='172.17.2.1',neighbor='172.17.2.1')
packet.show()
scapy.sendp(packet,loop=True,inter=0.1)
Loading