import json
from re import A
import resource
import logging, os, sys, time

from joblib import Logger
#from typing import Dict, Self, Tuple
os.environ['DEVICE_EMULATED_ONLY'] = 'YES'
from device.service.drivers.OpenFlow.OpenFlowDriver import OpenFlowDriver
logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)


def test_main():
    driver_settings = {
        'protocol': 'http', 
        'username': None,  
        'password': None,  
        'use_tls': False, 
    }
    driver = OpenFlowDriver('127.0.0.1', 8080 , **driver_settings)
    driver.Connect()

    import requests

    response = requests.get("http://127.0.0.1:8080/v1.0/topology/switches", timeout=10)
    LOGGER.info(f'the response is{response}')

  
    
    # Test: GetConfig
    #resource_keys = [ 'flows:1','description:1','switches','port_description:1','switch_info','links_info']
  #  config = driver.GetConfig(resource_keys )
  #  LOGGER.info('Specific configuration: %s', config)
    
    #resource_delete=["flowentry_delete:1"]
    #config = driver.DeleteConfig(resource_delete)
    #LOGGER.info('Specific configuration: %s', config)
    #a=driver.GetConfig(["flows:1"])
    #LOGGER.info('flow 1 = {:s}'.format(str(a)))
#    delete_data = {
#    "dpid": 2,
#    "cookie": 1,
#    "cookie_mask": 1,
#    "table_id": 0,
#    "idle_timeout": 30,
#    "hard_timeout": 30,
#    "priority": 11111,
#    "flags": 1,
#    "match":{
#        "in_port":2
#    },
#    "actions":[
#        {
#            "type":"ddf",
#            "port": 1
#        }
#    ]
# }
#    delete_result = driver.DeleteConfig([("flow_data", delete_data)])
#    LOGGER.info('resources_to_delete = {:s}'.format(str(delete_result)))
#    a=driver.GetConfig(["flows:1"])
#    LOGGER.info('flow 2 = {:s}'.format(str(a)))
#    flow_data = { 
#        "dpid": 2,
#        "priority": 22224,
#        "match": {
#            "in_port": 1
#        },
#        "actions": [
#            {
#                "type": "GOTO_TABLE",
#                "table_id": 1
#            }
#        ]
#    }
#    set_result = driver.SetConfig([('flow_data',flow_data)])
#    LOGGER.info(set_result)
#    driver.Disconnect()
#    
    raise Exception ()

if __name__ == '__main__':
    sys.exit(test_main())
