diff --git a/ipv6-config/INFO.md b/ipv6-config/INFO.md new file mode 100644 index 0000000..aac5add --- /dev/null +++ b/ipv6-config/INFO.md @@ -0,0 +1,42 @@ +## Instructions + +Edit ipv6.json as follow: +`{"HOST":{"counter" : 5, "ipv6": ["ADDRESSES"],"dev": ["DEVICES"]}}` + + - HOST = the name of the host in the topology + - counter = number of ADDRESSES and DEVICES (must be the same) + - ADDRESSES = list of IPv6 addresses to assign + - DEVICES = list of devices according to the related ipv6 address to be assigned + +Let's sort ADDRESSES and DEVICES arrays according to the order, for example: + - ADDRESSES[i] is the IPv6 address to be assigned to the interface DEVICES[i] + +## ipv6.json +This file contains the IPv6 addresses and the interfaces related to the addresses for each host. +If the topology changes this file has to be changed according to the topology in terms of: + - Name of each host + - IPv6 addresses of each host + - Interfaces related to each IPv6 address of each host + +## routes.json +Like _ipv6.json_ this file contain the list of the routes to add to each host + +`{"peo2":{"ROUTE":{"via": "NEXT_HOP_ADDRESS","dev": "DEVICE_TO_NEXT_HOP"}}}` + - ROUTE = the route to add + - NEXT_HOP_ADDRESS = the address of the next hop + - DEVICE_TO_NEXT_HOP = the host interface to NEXT_HOP_ADDRESS + + ## topology.json +This file contains the description of the desired topology of the network: + +`{"counter":VALUE,"subnet0":"default","subnet(i)":{"network":"NET_ADDRESS","netmask":"NET_VALUE"}}` + + - VALUE = number of the subnets + - SUBNET0 has to be keeped + - (i) = number of the subnet + - NET_ADDRESS = network address without netmask + - NET_VALUE = "/netmask" + +This file has to be changed according to the topology of the network. + + \ No newline at end of file diff --git a/ipv6-config/docs/ADDRESSING_README.md b/ipv6-config/docs/ADDRESSING_README.md new file mode 100644 index 0000000..363a279 --- /dev/null +++ b/ipv6-config/docs/ADDRESSING_README.md @@ -0,0 +1,148 @@ +# Mattia's README file + +*** +# Test using Bash commands +## Introduction +_First approach was the insert of IPv6 addresses via bash. According to the _IPv6_Manual_Strucure_ +file I made SSH connection using MGM addresses from Linux machine to VMs and then I added IPv6 addresses to every machine. Finally I tested PP link between each Subnet +with ping6 command_ + + + +## BASH Command List +##### SSH to VMs + - `ssh ` + - `VMs SSH password = "1234"` + - `sudo su` + +> Usually I obtain **su** rights to run some commands like **ip**. +> SSH connection are made according to Management addresses listed in the _IPv6_Manual_Strucure_ file +taken from the _Deploymet_Example_OUT_ file. + +##### Adding new IPv6 address + - `ip -6 addr add / dev ` + +##### Removing existing IPv6 address + - `ip -6 addr del / dev ` + +##### Ping an IPv6 device + - `ping6 ` + + + +## Procedure and comments + 1. Make SSH connection to every machine in the OSHI_Example_Project + - `ssh 10.255.255.1` **cro5** + - `ssh 10.255.254.1` **cro3** + - `ssh 10.255.253.1` **cro4** + - `ssh 10.255.252.1` **peo2** + - `ssh 10.255.251.1` **peo6** + - `ssh 10.255.250.1` **cer1** + - `ssh 10.255.249.1` **cer7** + - `ssh 10.255.248.1` **ctr8** + + 2. According to the IPv6 Structure proposed let's assign IPv6 addresses to VMs. Make attention to assign the address to the correct interface. According to the IPv4 topology we can assign IPv6 addresses to the same IPv4 interfaces such that we can support IPv6 to IPv4. + - `ip -6 addr add fd3c:9f20:5d73:01::01/64 dev vi1` **peo2** on Subnet1 + - `ip -6 addr add fd3c:9f20:5d73:01::02/64 dev cer1-eth1` **cer1** on Subnet1 + + 3. If I add a **new IPv6 address**, the system automatically creates the route for the network + - `ip -6 route show` **peo2** + - `fd3c:9f20:5d73:1::/64 dev vi1 proto kernel metric 256` + + 4. To fully support OSHI_Example to IPv6 we can add also MGM IPv6 addresses + - `ip -6 addr add fd3c:9f20:5d73:ffff::01/64 dev vi0` **cro5** + - (...) + + 5. Adding IPv6 to VMs we have to add IPv6 also to our Linux machine + - `ip -6 addr add fd3c:9f20:5d73:ffff::02/64 dev eth0` + - (...) + + 6. Ping in each PP Subnet using IPv6 + - `ping6 fd3c:9f20:5d73:01::01` from **cer1** to **peo2** + - (...) + + 7. Adding loopback IPv6 address to _lo_ interface + - `ip -6 addr add
/128 dev lo` + - LO addresses are chosen according to the _IPv6_Manual_Structure file_ + + +## Automatic allocation of IPv6 addresses + +Using this script _MQ_ipv6_ssh_address.sh_ for the OSHI_Example_Project I can execute automatically commands described above. +The script uses + +`sshpass -p ` + +to connect using ssh to the target VM without asking the password known a priori; +then I concatenated the command + +`ssh
` + +to give IPv6 address to the target VM; for example + +`pass=1234` +`peo2="10.255.252.1"` +`sshpass -p $pass ssh $peo2 'sudo ip -6 addr add fd3c:9f20:5d73:01::01/64 dev vi1'` + +The script also automatic assign LO IPv6 addresses to each VM + +`sshpass -p $pass ssh $cro4 'sudo ip -6 addr add fdac::03/128 dev lo'` + +*** + +# SSH Using Python + +## Introduction +I rearranged the work made using bash commands in a python file that reads information from JSON files and makes SSH connection to assign IPv6 addresses. + + +## Procedure +1. I created a Python script that takes informations about topology from _overall_info.json_ placed in the _/tmp_ folder + - MGM addresses useful to make SSH connections + +2. I takes other information about IPv6 addresses to be assigned to each host from _ipv6.json_ made by myself and that contains _Subnets_ and the structure of the _IPv6 Network_ + - IPv6 Addresses + - Interfaces + +3. I collected and I sorted following informations into some arrays + - Topology hosts _(pair of hosts each in the related subnet)_ + - E.G. _(peo2,cer1,peo2,cro4,...)_ + - MGM addresses of related hosts + - E.G. _(10.255.252.1, 10.255.250.1, 10.255.252.1, 10.255.253.1, ...)_ + - IPv6 addresses of related hosts + - Interfaces of related hosts + Arrays are sorted such that the index [i] of any array is related to the same host: + IPv6[i] - DEV[i] - MGM[i] are related all to hosts[i] + + +4. In this way I could make SSH operation using _subprocess_ with one single command in a _for_ cycle : + +`for i in range(0,len(mgm_sort)): + ssh=subprocess.Popen(['sshpass','-p',psswd,'ssh',mgm_sort[i],'sudo', 'ip', '-6', 'addr', 'add',ipv6[i] ,'dev', dev[i]])` + + +5. The same it is done about Loopback IPv6 addresses. + +`for i in range(0,len(mgm)): + ssh=subprocess.Popen(['sshpass','-p',psswd,'ssh',mgm[i],'sudo', 'ip', '-6', 'addr', 'add',lo6[i] ,'dev', 'lo'])` + +#### Comments + +To make SSH connection it is use Python library _subprocess_ +`shell=subprocess.Popen(['command','parameter','parameter'])` +*** +# References + - [Deployment_Example_OUT](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/Deployment_OUT.txt?at=master) + - [IPv6_Structure](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/IPv6_Structure.txt?at=master) + - [IPv6 Private Addresses Structure](http://simpledns.com/private-ipv6.aspx) + - [RFC4193](http://www.rfc-editor.org/rfc/rfc4193.txt) + +# Setup + - [MQ_ipv6_ssh_address.sh](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/MQ_ipv6_ssh_address.sh?at=master) + - [IPv6.py](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/ipv6.py?at=master) + - [Subnets.json](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/ipv6.json?at=master) + - [LoopbackIPv6.json](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/loopback6.json?at=master) + - [pingv6.py](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/4c223dda36a1b639785a0f3e4db3d5553196ce17/ipv6/pingv6.py?at=master) +**** +# OSHI Example Topology +![OSHI_Example](https://bytebucket.org/nip1617/ipv6-oshi-grpc/raw/47e92648c943342635e0dbcfaa2c5edc1ed10fec/ipv6/media/OSHI_SUB.jpg?token=756d566ef420f40fa81e663e1b81db83b55ea08f) diff --git a/ipv6-config/docs/OSHI.jpg b/ipv6-config/docs/OSHI.jpg new file mode 100644 index 0000000..381c9fa Binary files /dev/null and b/ipv6-config/docs/OSHI.jpg differ diff --git a/ipv6-config/docs/OSHI_SUB.jpg b/ipv6-config/docs/OSHI_SUB.jpg new file mode 100644 index 0000000..fdeeb1d Binary files /dev/null and b/ipv6-config/docs/OSHI_SUB.jpg differ diff --git a/ipv6-config/docs/ROUTING_Readme.md b/ipv6-config/docs/ROUTING_Readme.md new file mode 100644 index 0000000..5100c14 --- /dev/null +++ b/ipv6-config/docs/ROUTING_Readme.md @@ -0,0 +1,55 @@ +# Marco Pantanella - README + + *** + +## Assegnazione delle rotte + +Per l'assegnazione delle rotte, si consideri la figura seguente, rappresentante la topologia di rete: + +![topology](https://bytebucket.org/nip1617/ipv6-oshi-grpc/raw/c6cd8ec6449792d6d034424071a7603835e1ad9c/ipv6/media/topologia.jpg?token=b0a16ce415c94493daf86e5e59310a50a8febf77) + +basata sulla struttura e gli indirizzi IPv6 indicati nel file: [IPv6 Structure](https://bitbucket.org/nip1617/ipv6-oshi-grpc/raw/88e4668e8ce806db0f1f309bdafcb972522f7891/ipv6/IPv6_Structure.txt). + +Ho creato inizialmente un script **JSON** ([routes.json](https://bitbucket.org/nip1617/ipv6-oshi-grpc/raw/88e4668e8ce806db0f1f309bdafcb972522f7891/ipv6/routes.json)) che indica per ogni gateway la rotta di default e le rotte alternative da me stabilite e contiene per ognuna di esse le variabili _via_ e _dev_. +Successivamente abbiamo implementato uno script ***_python_*** ([IPv6.py](https://bitbucket.org/nip1617/ipv6-oshi-grpc/raw/88e4668e8ce806db0f1f309bdafcb972522f7891/ipv6/ipv6.py)) che assegna gli indirizzi IPv6 e le rotte in base ai corrispettivi file _JSON_ ([address.json](https://bitbucket.org/nip1617/ipv6-oshi-grpc/raw/88e4668e8ce806db0f1f309bdafcb972522f7891/ipv6/ipv6.json)) e ([routes.json](https://bitbucket.org/nip1617/ipv6-oshi-grpc/raw/88e4668e8ce806db0f1f309bdafcb972522f7891/ipv6/routes.json)). +Prima di fare cio', vengono creati gli array per gli indirizzi di management, per gli indirizzi delle rotte di destinazione e infine per le interfacce (_via_) e i device (_dev_), con la seguente relazione: + + for i in range(0,len(topo_ex)): + for j in range(0,len(subnetaddr)): + if subnetaddr[j] in route[topo_ex[i]]: + route_addr.append(subnetaddr[j]) + mgm_route.append(mgm[i]) + via.append(str(route[topo_ex[i]][subnetaddr[j]]['via'].decode('unicode_escape'))) + dev_route.append(str(route[topo_ex[i]][subnetaddr[j]]['dev'].decode('unicode_escape'))) + +dove: + +- `subnetddr = ['default','fd3c:9f20:5d73:01::/64','fd3c:9f20:5d73:02::/64','fd3c:9f20:5d73:03::/64','fd3c:9f20:5d73:04::/64','fd3c:9f20:5d73:05::/64','fd3c:9f20:5d73:06::/64','fd3c:9f20:5d73:07::/64','fd3c:9f20:5d73:08::/64','fd3c:9f20:5d73:09::/64','fd3c:9f20:5d73:0a::/64','fd3c:9f20:5d73:0b::/64']` + contiene gli indirizzi di tutte le subnet + +- `topo_ex = ['peo2','peo6','cer1','cer7','cro3','cro4','cro5','ctr8']` +contiene i nodi della topologia di rete presa in considerazione + +vengono dunque confrontati gli indirizzi delle subnet in subnetddr con gli indirizzi delle rotte di destinazione per ogni nodo nel file json routes.json e se presenti, vengono estrapolati i dati necessari per creare gli array: + +- _mgm_route_ : contenente gli indirizzi di management per la connessione _ssh_ +- _route_addr_: contenente gli indirizzi delle rotte di destinazione +- _via_: contenente gli indirizzi delle rotte di passaggio +- _dev_: contenente i device di uscita dai gateway + +## SSH SESSION + +Infine per assegnare le rotte, viene stabilita una connessione **SSH** su ogni _Virtual Machine_ , dove viene prima abilitato l' _IPv6 Forwarding_ con il seguente comando: + + sudo sysctl -w net.ipv6.conf.all.forwarding=1 + +Successivamente vengono utilizzati nel seguente ciclo _for_ gli array precedentemente ricavati: + + for i in range(0,len(mgm_route)): + ssh=subprocess.Popen(['sshpass','-p',psswd,'ssh',mgm_route[i],'sudo','ip','-6','r','add',route_addr[i],'via',via[i],'dev',dev_route[i]]) +a questo punto, ogni nodo della rete avra' le rotte stabilite nel file _routes.json_ e viene confermato all'utente l'avvenuta configurazione con il messaggio "_configured successfully_". + +#### Commenti +Per instaurare connessioni SSH in python è stata usata la libreria _subprocess_ +`shell=subprocess.Popen(['command','parameter','parameter'])` + diff --git a/ipv6-config/docs/topologia.jpg b/ipv6-config/docs/topologia.jpg new file mode 100644 index 0000000..9a38954 Binary files /dev/null and b/ipv6-config/docs/topologia.jpg differ diff --git a/ipv6-config/ipv6.json b/ipv6-config/ipv6.json new file mode 100644 index 0000000..f3c036a --- /dev/null +++ b/ipv6-config/ipv6.json @@ -0,0 +1,42 @@ +{ + "peo2":{ + "counter" : 5, + "ipv6": ["fdac::04/128","fd3c:9f20:5d73:01::01/64","fd3c:9f20:5d73:02::01/64","fd3c:9f20:5d73:04::01/64","fd3c:9f20:5d73:05::01/64"], + "dev": ["lo","vi1","vi2","vi3","vi4"] + }, + "peo6": { + "counter" : 5, + "ipv6": ["fdac::05/128","fd3c:9f20:5d73:06::01/64","fd3c:9f20:5d73:08::01/64","fd3c:9f20:5d73:09::01/64","fd3c:9f20:5d73:0a::01/64"], + "dev": ["lo","vi1","vi2","vi3","vi4"] + }, + "cer1":{ + "counter" : 2, + "ipv6": ["fdac::06/128","fd3c:9f20:5d73:01::02/64"], + "dev": ["lo","cer1-eth1"] + }, + "cer7": { + "counter" : 2, + "ipv6": ["fdac::07/128","fd3c:9f20:5d73:0a::02/64"], + "dev": ["lo","cer7-eth1"] + }, + "cro3": { + "counter" : 5, + "ipv6": ["fdac::02/128","fd3c:9f20:5d73:03::01/64","fd3c:9f20:5d73:05::02/64","fd3c:9f20:5d73:06::02/64","fd3c:9f20:5d73:07::01/64"], + "dev": ["lo","vi1","vi2","vi3","vi4"] + }, + "cro4": { + "counter" : 4, + "ipv6": ["fdac::03/128","fd3c:9f20:5d73:02::02/64","fd3c:9f20:5d73:07::02/64","fd3c:9f20:5d73:08::02/64"], + "dev": ["lo","vi1","vi2","vi3"] + }, + "cro5": { + "counter" : 4, + "ipv6": ["fdac::01/128","fd3c:9f20:5d73:03::02/64","fd3c:9f20:5d73:04::02/64","fd3c:9f20:5d73:09::02/64"], + "dev": ["lo","vi1","vi2","vi3"] + }, + "ctr8": { + "counter" : 2, + "ipv6": ["fdac::08/128","fd3c:9f20:5d73:0b::01/64"], + "dev": ["lo","ctr8-eth1"] + } +} \ No newline at end of file diff --git a/ipv6-config/ipv6.py b/ipv6-config/ipv6.py new file mode 100644 index 0000000..18b034d --- /dev/null +++ b/ipv6-config/ipv6.py @@ -0,0 +1,121 @@ +#!/usr/bin/python +import json +import subprocess +#AHAHAHAH BEL LOGO ;) +print '=========================================================' +print '|| ||' +print '|| __ ________ __ _ _______ ||' +print '|| || | _____ | || || | -----_| ||' +print '|| || ||_____|| || || ||______ ||' +print '|| || | ______| || || | ----- | ||' +print '|| || || |||| ||_____|| ||' +print '|| || || || |_______| ||' +print '|| ||' +print '|| Mattia Quadrini, Marco Pantanella ||' +print '|| ||' +print '=========================================================' +#OPEN JSON /TMP/OVERALL_INFO +print '***Open /tmp/overall_info.json***' +with open('/tmp/overall_info.json', 'r') as overall_info: + oinfo = json.load(overall_info) +print '***---------------------------***' + +#VARIABLES +#Constraint : manual insert of hosts in the topology +topo_ex = ['peo2','peo6','cer1','cer7','cro3','cro4','cro5','ctr8'] +mgm = [] +psswd = '1234' + +ipv6 = [] +dev = [] +count = [] +mgm_sort = [] +route_addr = [] +mgm_route = [] +via = [] +dev_route = [] +subnetaddr = [] + + +#MANAGEMENT ADDRESSES +#Open the json file and save mgm informations in mgm[] +print '' +print '***Storing MGM addresses from overall_info.json***' +for i in range(0,len(topo_ex)): + mgm.append(str(oinfo[topo_ex[i]]['mgt_IP'])) +print mgm +print '' +print '***--------------------------------------------***' +print '' + +#Some Debug to show useful information +print '***Debug Info: MGM Addresses***' +print '***-------------------------***' +for i in range(0,len(mgm)): + print topo_ex[i] + ': ' + mgm[i] +print '***-------------------------***' +print ' Example topology: ' +print topo_ex +print '***-------------------------***' + +#IPV6 NETWORK +print '*** Storing subnets ***' +IPV6_file = open('./ipv6.json','r') +ipv6net = json.load(IPV6_file) +print '***-------------------------***' + +for i in range(0,len(topo_ex)): + ipv6 = ipv6 + (ipv6net[topo_ex[i]]['ipv6']) + dev = dev + (ipv6net[topo_ex[i]]['dev']) + +for i in range(0,len(topo_ex)): + count.append(ipv6net[topo_ex[i]]['counter']) + +for i in range(0,len(topo_ex)): + for j in range(0,count[i]): + mgm_sort.append(mgm[i]) + +# TOPOLOGY +topology_file = open('./topology.json','r') +topology = json.load(topology_file) + +subnetaddr.append(str(topology['subnet0'])) +for i in range(1,topology['counter']): + subnetaddr.append(str(topology['subnet'+str(i)]['network'])+str(topology['subnet'+str(i)]['netmask'])) + +print subnetaddr + +# ROUTES +print '*** Sorting route addresses ***' +route_file = open('./routes.json','r') +route = json.load(route_file) + +for i in range(0,len(topo_ex)): + for j in range(0,len(subnetaddr)): + if subnetaddr[j] in route[topo_ex[i]]: + route_addr.append(subnetaddr[j]) + mgm_route.append(mgm[i]) + via.append(str(route[topo_ex[i]][subnetaddr[j]]['via'].decode('unicode_escape'))) + dev_route.append(str(route[topo_ex[i]][subnetaddr[j]]['dev'].decode('unicode_escape'))) + +print '***-------------------------***' + +# SSH SESSION + +print '***Start SSH session and addresses & route assignment***' +# IPv6 Addresses +for g in range(0,len(mgm_sort)): + subprocess.Popen(['sshpass','-p',psswd,'ssh',mgm_sort[g],'sudo', 'ip', '-6', 'addr', 'add',ipv6[g],'dev',dev[g]]) + + +#Enable IP Forwarding +for i in range(0,len(mgm)): + ssh=subprocess.Popen(['sshpass','-p',psswd,'ssh',mgm[i],'sudo','sysctl','-w','net.ipv6.conf.all.forwarding=1']) + +# IPv6 Routing +for i in range(0,len(mgm_route)): + ssh=subprocess.Popen(['sshpass','-p',psswd,'ssh',mgm_route[i],'sudo','ip','-6','r','add',route_addr[i],'via',via[i],'dev',dev_route[i]]) +print '' +print '+=======================================================+' +print '| Configured Successfully |' +print '+=======================================================+' diff --git a/ipv6-config/routes.json b/ipv6-config/routes.json new file mode 100644 index 0000000..d4ff27b --- /dev/null +++ b/ipv6-config/routes.json @@ -0,0 +1,95 @@ +{ + "peo2":{ + "default":{ + "via": "fd3c:9f20:5d73:04::02", + "dev": "vi3" + }, + "fd3c:9f20:5d73:0b::/64":{ + "via": "fd3c:9f20:5d73:05::02", + "dev": "vi4" + } + }, + "peo6":{ + "default":{ + "via": "fd3c:9f20:5d73:09::02", + "dev": "vi3" + }, + "fd3c:9f20:5d73:0b::/64":{ + "via": "fd3c:9f20:5d73:06::02", + "dev": "vi1" + } + }, + "cer1":{ + "default":{ + "via": "fd3c:9f20:5d73:01::01", + "dev": "cer1-eth1" + } + }, + "cer7":{ + "default":{ + "via": "fd3c:9f20:5d73:0a::01", + "dev": "cer7-eth1" + } + }, + "cro3":{ + "default":{ + "via": "fd3c:9f20:5d73:03::02", + "dev": "vi1" + }, + "fd3c:9f20:5d73:01::/64":{ + "via": "fd3c:9f20:5d73:05::01", + "dev": "vi2" + }, + "fd3c:9f20:5d73:0a::/64":{ + "via": "fd3c:9f20:5d73:06::01", + "dev": "vi3" + } + }, + "cro4":{ + "default": { + "via": "fd3c:9f20:5d73:08::01", + "dev": "vi3" + }, + "fd3c:9f20:5d73:01::/64":{ + "via": "fd3c:9f20:5d73:02::01", + "dev": "vi1" + }, + "fd3c:9f20:5d73:04::/64":{ + "via": "fd3c:9f20:5d73:02::01", + "dev": "vi1" + }, + "fd3c:9f20:5d73:0b::/64":{ + "via": "fd3c:9f20:5d73:07::01", + "dev": "vi2" + } + }, + "cro5":{ + "default":{ + "via": "fd3c:9f20:5d73:03::01", + "dev": "vi1" + }, + "fd3c:9f20:5d73:01::/64":{ + "via": "fd3c:9f20:5d73:04::01", + "dev": "vi2" + }, + "fd3c:9f20:5d73:02::/64":{ + "via": "fd3c:9f20:5d73:04::01", + "dev": "vi2" + }, + "fd3c:9f20:5d73:08::/64":{ + "via": "fd3c:9f20:5d73:09::01", + "dev": "vi3" + }, + "fd3c:9f20:5d73:0a::/64":{ + "via": "fd3c:9f20:5d73:09::01", + "dev": "vi3" + } + }, + "ctr8":{ + "default":{ + "via": "fd3c:9f20:5d73:0b::02", + "dev": "ctr8-eth1" + } + } + +} \ No newline at end of file diff --git a/ipv6-config/topology.json b/ipv6-config/topology.json new file mode 100644 index 0000000..6ebf599 --- /dev/null +++ b/ipv6-config/topology.json @@ -0,0 +1,15 @@ +{ + "counter":11, + "subnet0":"default", + "subnet1":{"network":"fd3c:9f20:5d73:01::","netmask":"/64"}, + "subnet2":{"network":"fd3c:9f20:5d73:02::","netmask":"/64"}, + "subnet3":{"network":"fd3c:9f20:5d73:03::","netmask":"/64"}, + "subnet4":{"network":"fd3c:9f20:5d73:04::","netmask":"/64"}, + "subnet5":{"network":"fd3c:9f20:5d73:05::","netmask":"/64"}, + "subnet6":{"network":"fd3c:9f20:5d73:06::","netmask":"/64"}, + "subnet7":{"network":"fd3c:9f20:5d73:07::","netmask":"/64"}, + "subnet8":{"network":"fd3c:9f20:5d73:08::","netmask":"/64"}, + "subnet9":{"network":"fd3c:9f20:5d73:09::","netmask":"/64"}, + "subnet10":{"network":"fd3c:9f20:5d73:0a::","netmask":"/64"}, + "subnet11":{"network":"fd3c:9f20:5d73:0b::","netmask":"/64"} +} \ No newline at end of file diff --git a/ipv6-config_old_version/docs/ADDRESSING_README.md b/ipv6-config_old_version/docs/ADDRESSING_README.md new file mode 100644 index 0000000..363a279 --- /dev/null +++ b/ipv6-config_old_version/docs/ADDRESSING_README.md @@ -0,0 +1,148 @@ +# Mattia's README file + +*** +# Test using Bash commands +## Introduction +_First approach was the insert of IPv6 addresses via bash. According to the _IPv6_Manual_Strucure_ +file I made SSH connection using MGM addresses from Linux machine to VMs and then I added IPv6 addresses to every machine. Finally I tested PP link between each Subnet +with ping6 command_ + + + +## BASH Command List +##### SSH to VMs + - `ssh ` + - `VMs SSH password = "1234"` + - `sudo su` + +> Usually I obtain **su** rights to run some commands like **ip**. +> SSH connection are made according to Management addresses listed in the _IPv6_Manual_Strucure_ file +taken from the _Deploymet_Example_OUT_ file. + +##### Adding new IPv6 address + - `ip -6 addr add / dev ` + +##### Removing existing IPv6 address + - `ip -6 addr del / dev ` + +##### Ping an IPv6 device + - `ping6 ` + + + +## Procedure and comments + 1. Make SSH connection to every machine in the OSHI_Example_Project + - `ssh 10.255.255.1` **cro5** + - `ssh 10.255.254.1` **cro3** + - `ssh 10.255.253.1` **cro4** + - `ssh 10.255.252.1` **peo2** + - `ssh 10.255.251.1` **peo6** + - `ssh 10.255.250.1` **cer1** + - `ssh 10.255.249.1` **cer7** + - `ssh 10.255.248.1` **ctr8** + + 2. According to the IPv6 Structure proposed let's assign IPv6 addresses to VMs. Make attention to assign the address to the correct interface. According to the IPv4 topology we can assign IPv6 addresses to the same IPv4 interfaces such that we can support IPv6 to IPv4. + - `ip -6 addr add fd3c:9f20:5d73:01::01/64 dev vi1` **peo2** on Subnet1 + - `ip -6 addr add fd3c:9f20:5d73:01::02/64 dev cer1-eth1` **cer1** on Subnet1 + + 3. If I add a **new IPv6 address**, the system automatically creates the route for the network + - `ip -6 route show` **peo2** + - `fd3c:9f20:5d73:1::/64 dev vi1 proto kernel metric 256` + + 4. To fully support OSHI_Example to IPv6 we can add also MGM IPv6 addresses + - `ip -6 addr add fd3c:9f20:5d73:ffff::01/64 dev vi0` **cro5** + - (...) + + 5. Adding IPv6 to VMs we have to add IPv6 also to our Linux machine + - `ip -6 addr add fd3c:9f20:5d73:ffff::02/64 dev eth0` + - (...) + + 6. Ping in each PP Subnet using IPv6 + - `ping6 fd3c:9f20:5d73:01::01` from **cer1** to **peo2** + - (...) + + 7. Adding loopback IPv6 address to _lo_ interface + - `ip -6 addr add
/128 dev lo` + - LO addresses are chosen according to the _IPv6_Manual_Structure file_ + + +## Automatic allocation of IPv6 addresses + +Using this script _MQ_ipv6_ssh_address.sh_ for the OSHI_Example_Project I can execute automatically commands described above. +The script uses + +`sshpass -p ` + +to connect using ssh to the target VM without asking the password known a priori; +then I concatenated the command + +`ssh
` + +to give IPv6 address to the target VM; for example + +`pass=1234` +`peo2="10.255.252.1"` +`sshpass -p $pass ssh $peo2 'sudo ip -6 addr add fd3c:9f20:5d73:01::01/64 dev vi1'` + +The script also automatic assign LO IPv6 addresses to each VM + +`sshpass -p $pass ssh $cro4 'sudo ip -6 addr add fdac::03/128 dev lo'` + +*** + +# SSH Using Python + +## Introduction +I rearranged the work made using bash commands in a python file that reads information from JSON files and makes SSH connection to assign IPv6 addresses. + + +## Procedure +1. I created a Python script that takes informations about topology from _overall_info.json_ placed in the _/tmp_ folder + - MGM addresses useful to make SSH connections + +2. I takes other information about IPv6 addresses to be assigned to each host from _ipv6.json_ made by myself and that contains _Subnets_ and the structure of the _IPv6 Network_ + - IPv6 Addresses + - Interfaces + +3. I collected and I sorted following informations into some arrays + - Topology hosts _(pair of hosts each in the related subnet)_ + - E.G. _(peo2,cer1,peo2,cro4,...)_ + - MGM addresses of related hosts + - E.G. _(10.255.252.1, 10.255.250.1, 10.255.252.1, 10.255.253.1, ...)_ + - IPv6 addresses of related hosts + - Interfaces of related hosts + Arrays are sorted such that the index [i] of any array is related to the same host: + IPv6[i] - DEV[i] - MGM[i] are related all to hosts[i] + + +4. In this way I could make SSH operation using _subprocess_ with one single command in a _for_ cycle : + +`for i in range(0,len(mgm_sort)): + ssh=subprocess.Popen(['sshpass','-p',psswd,'ssh',mgm_sort[i],'sudo', 'ip', '-6', 'addr', 'add',ipv6[i] ,'dev', dev[i]])` + + +5. The same it is done about Loopback IPv6 addresses. + +`for i in range(0,len(mgm)): + ssh=subprocess.Popen(['sshpass','-p',psswd,'ssh',mgm[i],'sudo', 'ip', '-6', 'addr', 'add',lo6[i] ,'dev', 'lo'])` + +#### Comments + +To make SSH connection it is use Python library _subprocess_ +`shell=subprocess.Popen(['command','parameter','parameter'])` +*** +# References + - [Deployment_Example_OUT](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/Deployment_OUT.txt?at=master) + - [IPv6_Structure](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/IPv6_Structure.txt?at=master) + - [IPv6 Private Addresses Structure](http://simpledns.com/private-ipv6.aspx) + - [RFC4193](http://www.rfc-editor.org/rfc/rfc4193.txt) + +# Setup + - [MQ_ipv6_ssh_address.sh](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/MQ_ipv6_ssh_address.sh?at=master) + - [IPv6.py](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/ipv6.py?at=master) + - [Subnets.json](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/ipv6.json?at=master) + - [LoopbackIPv6.json](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/eea8669a79af1ee77b0258a44db807d3287eb8ce/ipv6/loopback6.json?at=master) + - [pingv6.py](https://bitbucket.org/nip1617/ipv6-oshi-grpc/src/4c223dda36a1b639785a0f3e4db3d5553196ce17/ipv6/pingv6.py?at=master) +**** +# OSHI Example Topology +![OSHI_Example](https://bytebucket.org/nip1617/ipv6-oshi-grpc/raw/47e92648c943342635e0dbcfaa2c5edc1ed10fec/ipv6/media/OSHI_SUB.jpg?token=756d566ef420f40fa81e663e1b81db83b55ea08f) diff --git a/ipv6-config_old_version/docs/OSHI.jpg b/ipv6-config_old_version/docs/OSHI.jpg new file mode 100644 index 0000000..381c9fa Binary files /dev/null and b/ipv6-config_old_version/docs/OSHI.jpg differ diff --git a/ipv6-config_old_version/docs/OSHI_SUB.jpg b/ipv6-config_old_version/docs/OSHI_SUB.jpg new file mode 100644 index 0000000..fdeeb1d Binary files /dev/null and b/ipv6-config_old_version/docs/OSHI_SUB.jpg differ diff --git a/ipv6-config_old_version/docs/ROUTING_Readme.md b/ipv6-config_old_version/docs/ROUTING_Readme.md new file mode 100644 index 0000000..5100c14 --- /dev/null +++ b/ipv6-config_old_version/docs/ROUTING_Readme.md @@ -0,0 +1,55 @@ +# Marco Pantanella - README + + *** + +## Assegnazione delle rotte + +Per l'assegnazione delle rotte, si consideri la figura seguente, rappresentante la topologia di rete: + +![topology](https://bytebucket.org/nip1617/ipv6-oshi-grpc/raw/c6cd8ec6449792d6d034424071a7603835e1ad9c/ipv6/media/topologia.jpg?token=b0a16ce415c94493daf86e5e59310a50a8febf77) + +basata sulla struttura e gli indirizzi IPv6 indicati nel file: [IPv6 Structure](https://bitbucket.org/nip1617/ipv6-oshi-grpc/raw/88e4668e8ce806db0f1f309bdafcb972522f7891/ipv6/IPv6_Structure.txt). + +Ho creato inizialmente un script **JSON** ([routes.json](https://bitbucket.org/nip1617/ipv6-oshi-grpc/raw/88e4668e8ce806db0f1f309bdafcb972522f7891/ipv6/routes.json)) che indica per ogni gateway la rotta di default e le rotte alternative da me stabilite e contiene per ognuna di esse le variabili _via_ e _dev_. +Successivamente abbiamo implementato uno script ***_python_*** ([IPv6.py](https://bitbucket.org/nip1617/ipv6-oshi-grpc/raw/88e4668e8ce806db0f1f309bdafcb972522f7891/ipv6/ipv6.py)) che assegna gli indirizzi IPv6 e le rotte in base ai corrispettivi file _JSON_ ([address.json](https://bitbucket.org/nip1617/ipv6-oshi-grpc/raw/88e4668e8ce806db0f1f309bdafcb972522f7891/ipv6/ipv6.json)) e ([routes.json](https://bitbucket.org/nip1617/ipv6-oshi-grpc/raw/88e4668e8ce806db0f1f309bdafcb972522f7891/ipv6/routes.json)). +Prima di fare cio', vengono creati gli array per gli indirizzi di management, per gli indirizzi delle rotte di destinazione e infine per le interfacce (_via_) e i device (_dev_), con la seguente relazione: + + for i in range(0,len(topo_ex)): + for j in range(0,len(subnetaddr)): + if subnetaddr[j] in route[topo_ex[i]]: + route_addr.append(subnetaddr[j]) + mgm_route.append(mgm[i]) + via.append(str(route[topo_ex[i]][subnetaddr[j]]['via'].decode('unicode_escape'))) + dev_route.append(str(route[topo_ex[i]][subnetaddr[j]]['dev'].decode('unicode_escape'))) + +dove: + +- `subnetddr = ['default','fd3c:9f20:5d73:01::/64','fd3c:9f20:5d73:02::/64','fd3c:9f20:5d73:03::/64','fd3c:9f20:5d73:04::/64','fd3c:9f20:5d73:05::/64','fd3c:9f20:5d73:06::/64','fd3c:9f20:5d73:07::/64','fd3c:9f20:5d73:08::/64','fd3c:9f20:5d73:09::/64','fd3c:9f20:5d73:0a::/64','fd3c:9f20:5d73:0b::/64']` + contiene gli indirizzi di tutte le subnet + +- `topo_ex = ['peo2','peo6','cer1','cer7','cro3','cro4','cro5','ctr8']` +contiene i nodi della topologia di rete presa in considerazione + +vengono dunque confrontati gli indirizzi delle subnet in subnetddr con gli indirizzi delle rotte di destinazione per ogni nodo nel file json routes.json e se presenti, vengono estrapolati i dati necessari per creare gli array: + +- _mgm_route_ : contenente gli indirizzi di management per la connessione _ssh_ +- _route_addr_: contenente gli indirizzi delle rotte di destinazione +- _via_: contenente gli indirizzi delle rotte di passaggio +- _dev_: contenente i device di uscita dai gateway + +## SSH SESSION + +Infine per assegnare le rotte, viene stabilita una connessione **SSH** su ogni _Virtual Machine_ , dove viene prima abilitato l' _IPv6 Forwarding_ con il seguente comando: + + sudo sysctl -w net.ipv6.conf.all.forwarding=1 + +Successivamente vengono utilizzati nel seguente ciclo _for_ gli array precedentemente ricavati: + + for i in range(0,len(mgm_route)): + ssh=subprocess.Popen(['sshpass','-p',psswd,'ssh',mgm_route[i],'sudo','ip','-6','r','add',route_addr[i],'via',via[i],'dev',dev_route[i]]) +a questo punto, ogni nodo della rete avra' le rotte stabilite nel file _routes.json_ e viene confermato all'utente l'avvenuta configurazione con il messaggio "_configured successfully_". + +#### Commenti +Per instaurare connessioni SSH in python è stata usata la libreria _subprocess_ +`shell=subprocess.Popen(['command','parameter','parameter'])` + diff --git a/ipv6-config_old_version/docs/topologia.jpg b/ipv6-config_old_version/docs/topologia.jpg new file mode 100644 index 0000000..9a38954 Binary files /dev/null and b/ipv6-config_old_version/docs/topologia.jpg differ diff --git a/ipv6-config_old_version/ipv6.json b/ipv6-config_old_version/ipv6.json new file mode 100644 index 0000000..4b892f4 --- /dev/null +++ b/ipv6-config_old_version/ipv6.json @@ -0,0 +1,40 @@ +{ + "Subnet01":{"peo2","cer1"}, + "Subnet02": {"peo2","cro4"}, + "Subnet03": {"cro3","cro5"}, + "Subnet04": {"peo2","cro5"}, + "Subnet05": {"peo2","cro3"}, + "Subnet06": {"peo6","cro3"}, + "Subnet07": {"cro3","cro4"}, + "Subnet08": {"peo6","cro4"}, + "Subnet09": {"peo6","cro5" + "peo6": { + "ipv6": "fd3c:9f20:5d73:09::01/64", + "dev": "vi3" + }, + "cro5": { + "ipv6": "fd3c:9f20:5d73:09::02/64", + "dev": "vi3" + } + }, + "Subnet10": { + "peo6": { + "ipv6": "fd3c:9f20:5d73:0a::01/64", + "dev": "vi4" + }, + "cer7": { + "ipv6": "fd3c:9f20:5d73:0a::02/64", + "dev": "cer7-eth1" + } + }, + "Subnet11": { + "ctr8": { + "ipv6": "fd3c:9f20:5d73:0b::01/64", + "dev": "ctr8-eth1" + }, + "cro3": { + "ipv6": "fd3c:9f20:5d73:0b::02/64", + "dev": "vi5" + } + } +} \ No newline at end of file diff --git a/ipv6-config_old_version/ipv6.py b/ipv6-config_old_version/ipv6.py new file mode 100644 index 0000000..11d8e3a --- /dev/null +++ b/ipv6-config_old_version/ipv6.py @@ -0,0 +1,180 @@ +#!/usr/bin/python + +import json +import subprocess +#AHAHAHAH BEL LOGO ;) +print '=========================================================' +print '|| ||' +print '|| __ ________ __ _ _______ ||' +print '|| || | _____ | || || | -----_| ||' +print '|| || ||_____|| || || ||______ ||' +print '|| || | ______| || || | ----- | ||' +print '|| || || |||| ||_____|| ||' +print '|| || || || |_______| ||' +print '|| ||' +print '|| Mattia Quadrini, Marco Pantanella ||' +print '|| ||' +print '=========================================================' +#OPEN JSON /TMP/OVERALL_INFO +print '***Open /tmp/overall_info.json***' +with open('/tmp/overall_info.json', 'r') as overall_info: + oinfo = json.load(overall_info) +print '***---------------------------***' + +#VARIABLES +#Constraint : manual insert of hosts in the topology +topo_ex = ['peo2','peo6','cer1','cer7','cro3','cro4','cro5','ctr8'] +mgm = [] +psswd = '1234' +#We can modify addresses deleting names ("Subnets") and changing the "for" cycle (row 78) on the array +subnets = ['Subnet01','Subnet02','Subnet03','Subnet04','Subnet05','Subnet06','Subnet07','Subnet08','Subnet09','Subnet10','Subnet11'] +hosts = [] + +s1= ['peo2','cer1'] +s2 = ['peo2','cro4'] +s3 = ['cro3','cro5'] +s4 = ['peo2','cro5'] +s5 = ['peo2','cro3'] +s6 = ['peo6','cro3'] +s7 = ['cro3','cro4'] +s8 = ['peo6','cro4'] +s9 = ['peo6','cro5'] +s10 = ['peo6','cer7'] +s11 = ['ctr8','cro3'] +deb = s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11 + +ipv6 = [] +dev = [] + +#Save MGM addresses to make SSH connetction +#Open the json file and save mgm informations in mgm[] +print '' +print '***Storing MGM addresses from overall_info.json***' +for i in range(0,len(topo_ex)): + mgm.append(str(oinfo[topo_ex[i]]['mgt_IP'])) +print mgm +print '' +print '***--------------------------------------------***' +print '' + +#Some Debug to show useful information +print '***Debug Info: MGM Addresses***' +print '***-------------------------***' +for i in range(0,len(mgm)): + print topo_ex[i] + ': ' + mgm[i] +print '***-------------------------***' +print ' Example topology: ' +print topo_ex +print '***-------------------------***' + +#OPEN JSON IPv6NET +#Open the IPv6 JSON file and save information about IPv6 and interfaces +print '*** Storing subnets ***' +IPV6_file = open('./ipv6.json','r') +ipv6net = json.load(IPV6_file) +print '***-------------------------***' + +#Save IPv6 addresses +#Storing hosts from JSON to array sorted according to subnets structure +print '*** Storing IPv6 addresses ***' +for i in range(0,len(subnets)): + for j in range(len(topo_ex)): + if topo_ex[j] in ipv6net[subnets[i]]: + hosts.append(topo_ex[j]) +#print '*** Hosts ***' +#print hosts +print '***-------------------------***' + +#Storing IPv6 Addresses from JSON to array sorted according to hosts order +j=0 +while(j