def get_of_rules(self, translate_of_ports=True):   
        
        if len(self.ofi2pp) == 0:
            r,c = self.obtain_port_correspondence()
            if r<0:
                return r,c
        #get rules
        try:
            of_response = requests.get(self.url+"/restconf/config/opendaylight-inventory:nodes/node/" + self.id +
                                          "/table/0", headers=self.headers)
            error_text = "Openflow response %d: %s" % (of_response.status_code, of_response.text)

            # The configured page does not exist if there are no rules installed. In that case we return an empty dict
            if of_response.status_code == 404:
                return 0, {}

            elif of_response.status_code != 200:
                self.logger.warning("get_of_rules " + error_text)
                return -1 , error_text
            self.logger.debug("get_of_rules " + error_text)
            
            info = of_response.json()

            if type(info) != dict:
                self.logger.error("get_of_rules. Unexpected response not a dict: %s", str(info))
                return -1, "Unexpected openflow response, not a dict. Wrong version?"

            table = info.get('flow-node-inventory:table')
            if type(table) is not list:
                self.logger.error("get_of_rules. Unexpected response at 'flow-node-inventory:table', not a list: %s", str(type(table)))
                return -1, "Unexpected response at 'flow-node-inventory:table', not a list. Wrong version?"

            flow_list = table[0].get('flow')
            if flow_list is None:
                return 0, {}

            if type(flow_list) is not list:
                self.logger.error("get_of_rules. Unexpected response at 'flow-node-inventory:table'[0]:'flow', not a list: %s", str(type(flow_list)))
                return -1, "Unexpected response at 'flow-node-inventory:table'[0]:'flow', not a list. Wrong version?"

            #TODO translate ports according to translate_of_ports parameter

            rules = dict()
            for flow in flow_list:
                if not ('id' in flow and 'match' in flow and 'instructions' in flow and \
                   'instruction' in flow['instructions'] and 'apply-actions' in flow['instructions']['instruction'][0] and \
                    'action' in flow['instructions']['instruction'][0]['apply-actions']):
                        return -1, "unexpected openflow response, one or more elements are missing. Wrong version?"

                flow['instructions']['instruction'][0]['apply-actions']['action']

                rule = dict()
                rule['switch'] = self.dpid
                rule['priority'] = flow.get('priority')
                #rule['name'] = flow['id']
                #rule['cookie'] = flow['cookie']
                if 'in-port' in flow['match']:
                    in_port = flow['match']['in-port']
                    if not in_port in self.ofi2pp:
                        return -1, "Error: Ingress port "+in_port+" is not in switch port list"

                    if translate_of_ports:
                        in_port = self.ofi2pp[in_port]

                    rule['ingress_port'] = in_port

                    if 'vlan-match' in flow['match'] and 'vlan-id' in flow['match']['vlan-match'] and \
                                'vlan-id' in flow['match']['vlan-match']['vlan-id'] and \
                                'vlan-id-present' in flow['match']['vlan-match']['vlan-id'] and \
                                flow['match']['vlan-match']['vlan-id']['vlan-id-present'] == True:
                        rule['vlan_id'] = flow['match']['vlan-match']['vlan-id']['vlan-id']

                    if 'ethernet-match' in flow['match'] and 'ethernet-destination' in flow['match']['ethernet-match'] and \
                        'address' in flow['match']['ethernet-match']['ethernet-destination']:
                        rule['dst_mac'] = flow['match']['ethernet-match']['ethernet-destination']['address']

                instructions=flow['instructions']['instruction'][0]['apply-actions']['action']

                max_index=0
                for instruction in instructions:
                    if instruction['order'] > max_index:
                        max_index = instruction['order']

                actions=[None]*(max_index+1)
                for instruction in instructions:
                    if 'output-action' in instruction:
                        if not 'output-node-connector' in instruction['output-action']:
                            return -1, "unexpected openflow response, one or more elementa are missing. Wrong version?"

                        out_port = instruction['output-action']['output-node-connector']
                        if not out_port in self.ofi2pp:
                            return -1, "Error: Output port "+out_port+" is not in switch port list"

                        if translate_of_ports:
                            out_port = self.ofi2pp[out_port]

                        actions[instruction['order']] = ('out',out_port)

                    elif 'strip-vlan-action' in instruction:
                        actions[instruction['order']] = ('vlan', None)

                    elif 'set-field' in instruction:
                        if not ('vlan-match' in instruction['set-field'] and 'vlan-id' in  instruction['set-field']['vlan-match'] and 'vlan-id' in instruction['set-field']['vlan-match']['vlan-id']):
                            return -1, "unexpected openflow response, one or more elements are missing. Wrong version?"

                        actions[instruction['order']] = ('vlan', instruction['set-field']['vlan-match']['vlan-id']['vlan-id'])

                actions = [x for x in actions if x != None]

                rule['actions'] = list(actions)
                rules[flow['id']] = dict(rule)

                #flow['id']
                #flow['priority']
                #flow['cookie']
                #flow['match']['in-port']
                #flow['match']['vlan-match']['vlan-id']['vlan-id']
                # match -> in-port
                #      -> vlan-match -> vlan-id -> vlan-id
                #flow['match']['vlan-match']['vlan-id']['vlan-id-present']
                #TODO se asume que no se usan reglas con vlan-id-present:false
                #instructions -> instruction -> apply-actions -> action
                #instructions=flow['instructions']['instruction'][0]['apply-actions']['action']
                #Es una lista. Posibles elementos:
                #max_index=0
                #for instruction in instructions:
                #  if instruction['order'] > max_index:
                #    max_index = instruction['order']
                #actions=[None]*(max_index+1)
                #for instruction in instructions:
                #   if 'output-action' in instruction:
                #     actions[instruction['order']] = ('out',instruction['output-action']['output-node-connector'])
                #   elif 'strip-vlan-action' in instruction:
                #     actions[instruction['order']] = ('vlan', None)
                #   elif 'set-field' in instruction:
                #     actions[instruction['order']] = ('vlan', instruction['set-field']['vlan-match']['vlan-id']['vlan-id'])
                #
                #actions = [x for x in actions if x != None]
                #                                                       -> output-action -> output-node-connector
                #                                                       -> pop-vlan-action

            return 0, rules
        except (requests.exceptions.RequestException, ValueError) as e:
            #ValueError in the case that JSON can not be decoded
            error_text = type(e).__name__ + ": " + str(e)
            self.logger.error("get_of_rules " + error_text)
            return -1, error_text
Obtain the rules inserted at openflow controller
dataset/ETHPy150Open nfvlabs/openmano/openvim/ODL.py/OF_conn.get_of_rules