admin | f44b54c | 2014-06-05 09:53:59 -0700 | [diff] [blame^] | 1 | #! /usr/bin/env python |
| 2 | ''' |
| 3 | This file creates the ONOS intents for the sanity 4 nodes tests. These intents will be translated into flows by ONOS and pushed to the switches. |
| 4 | ''' |
| 5 | |
| 6 | import json |
| 7 | import requests |
| 8 | |
| 9 | url = 'http://127.0.0.1:8080/wm/onos/datagrid/add/intents/json' |
| 10 | headers = {'Content-type': 'application/json', 'Accept': 'application/json'} |
| 11 | |
| 12 | |
| 13 | '''response |
| 14 | [{'intent_id':'5','status':'CREATED','log':['created, time:73268214932534']}] |
| 15 | ''' |
| 16 | |
| 17 | |
| 18 | |
| 19 | for i in range(6,16): |
| 20 | #intent = [{'intent_id': '%d' %i,'intent_type':'shortest_intent_type','intent_op':'add','srcSwitch':'8249','srcPort':1,'srcMac':'00:00:00:00:00:01','dstSwitch':'4103','dstPort':1,'dstMac':'00:00:00:00:00:02'}] |
| 21 | srcMac = '00:00:00:00:00:'+ str(hex(i)[2:]).zfill(2) |
| 22 | dstMac = '00:00:00:00:00:'+ str(hex(i+10)[2:]) |
| 23 | srcSwitch = '00:00:00:00:00:00:10:'+ str(i).zfill(2) |
| 24 | dstSwitch = '00:00:00:00:00:00:20:'+ str(i+25) |
| 25 | srcPort = 1 |
| 26 | dstPort = 1 |
| 27 | |
| 28 | intent = [{'intent_id': '%d' %(i),'intent_type':'shortest_intent_type','intent_op':'add','srcSwitch':srcSwitch,'srcPort':srcPort,'srcMac':srcMac,'dstSwitch':dstSwitch,'dstPort':dstPort,'dstMac':dstMac}] |
| 29 | |
| 30 | |
| 31 | print json.dumps(intent, sort_keys = True) |
| 32 | |
| 33 | |
| 34 | #r = requests.post(url, data=json.dumps(iid, sort_keys=True)+json.dumps(intent, sort_keys=True), headers = headers) |
| 35 | r = requests.post(url, data=json.dumps(intent, sort_keys=True), headers = headers) |
| 36 | print r |
| 37 | print r.content |
| 38 | |
| 39 | |
| 40 | |
| 41 | intent = [{'intent_id': '%d' %(i+10),'intent_type':'shortest_intent_type','intent_op':'add','srcSwitch':dstSwitch,'srcPort':dstPort,'srcMac':dstMac,'dstSwitch':srcSwitch,'dstPort':srcPort,'dstMac':srcMac}] |
| 42 | print json.dumps(intent, sort_keys = True) |
| 43 | r = requests.post(url, data=json.dumps(intent, sort_keys=True), headers = headers) |
| 44 | print r |
| 45 | print r.content |
| 46 | |