import requests
import json

#Content type must be included in the header
header = {"content-type": "application/json", "Accept": "application/json"}
#url = "http://localhost:8181/onos/v1/flows/of:0000000000000001"
url = "http://localhost:8181/onos/v1/flows?appId=org.onosproject.cli"
#Switch ID needed for single flow
#flow1 = {
flow1 = {"flows" : [
  {
  "priority": 4123,
  "timeout":0,
  "isPermanent": "true",
  "deviceId":"of:0000000000000001",
  "treatment": {
    "instructions": [
      {
        "type": "OUTPUT",
        "port": 2
      }
    ]
  },
  "selector": {
    "criteria": [
      {
        "type": "ETH_TYPE",
        "ethType": "0x88cc"
      },
	  {
        "type": "ETH_SRC",
        "mac": "00:00:00:00:00:01"
      }
    ]
  }
}
]
}
flow2 = {"flows" : [
  {
  "priority": 1,
  "timeout":0,
  "isPermanent": "true",
  "deviceId":"of:0000000000000001",
  "treatment": {
    "instructions": [
      {
        "type": "OUTPUT",
        "port": 2
      }
    ]
  },
  "selector": {
    "criteria": [
      {
        "type": "ETH_TYPE",
        "ethType": "0x88cc"
      },
	  {
        "type": "ETH_SRC",
        "mac": "00:00:00:00:00:01"
      }
    ]
  }
}
]

flow_url = "http://localhost:8181/onos/v1/flows/"
r = requests.post(url, data=json.dumps(flow1), headers=header, auth=('onos', 'rocks'))
print(r.status_code, r.reason)
print (r.text)
r = requests.get(flow_url, auth=('onos','rocks'))
print(r.status_code, r.reason)
print (r.text)
