Example #1
0
    def get_flow_stats(self, req, dpid, **_kwargs):
        if req.body == '':
            flow = {}
        else:
            try:
                flow = ast.literal_eval(req.body)
            except SyntaxError:
                LOG.debug('invalid syntax %s', req.body)
                return Response(status=400)

        dp = self.dpset.get(int(dpid))
        if dp is None:
            return Response(status=404)

        CMD_LIST.append(flow)
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            flows = ofctl_v1_0.get_flow_stats(dp, self.waiters, flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            flows = ofctl_v1_2.get_flow_stats(dp, self.waiters, flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            flows = ofctl_v1_3.get_flow_stats(dp, self.waiters, flow)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        body = json.dumps(flows)
        return Response(content_type='application/json', body=body)
Example #2
0
    def get_flow_stats(self, req, dpid, **_kwargs):
        if req.body == '':
            flow = {}
        else:
            try:
                flow = ast.literal_eval(req.body)
            except SyntaxError:
                LOG.debug('invalid syntax %s', req.body)
                return Response(status=400)

        dp = self.dpset.get(int(dpid))
        if dp is None:
            return Response(status=404)

        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            flows = ofctl_v1_0.get_flow_stats(dp, self.waiters, flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            flows = ofctl_v1_2.get_flow_stats(dp, self.waiters, flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            flows = ofctl_v1_3.get_flow_stats(dp, self.waiters, flow)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        body = json.dumps(flows)
        return (Response(content_type='application/json', body=body))
Example #3
0
	def get_flows(self):
		flows = {}
		for dpid, dp in self.dpset.get_all():
			if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
				flows.update(ofctl_v1_0.get_flow_stats(dp, self.waiters, {}))
			elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
				flows.update(ofctl_v1_2.get_flow_stats(dp, self.waiters, {}))
			elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
				flows.update(ofctl_v1_3.get_flow_stats(dp, self.waiters, {}))
		return flows
Example #4
0
	def get_flows(self):
		flows = {}
		for dpid, dp in self.dpset.get_all():
			if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
				flows.update(ofctl_v1_0.get_flow_stats(dp, self.waiters, {}))
			elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
				flows.update(ofctl_v1_2.get_flow_stats(dp, self.waiters, {}))
			elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
				flows.update(ofctl_v1_3.get_flow_stats(dp, self.waiters, {}))
		return flows
Example #5
0
    def get_flow_stats(self, req, dpid, **_kwargs):
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return Response(status=404)

        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            flows = ofctl_v1_0.get_flow_stats(dp, self.waiters)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        body = json.dumps(flows)
        return (Response(content_type='application/json', body=body))
Example #6
0
    def get_flow_stats(self, req, dpid, **_kwargs):
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return Response(status=404)

        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            flows = ofctl_v1_0.get_flow_stats(dp, self.waiters)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        body = json.dumps(flows)
        return (Response(content_type='application/json', body=body))
Example #7
0
 def getFlows(self, dpid):
     flow = {}
     dp = self.dpset.get(int(dpid))
     if dp is None:
         return None
     if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
         flows = ofctl_v1_0.get_flow_stats(dp, self.waiters, flow)
     elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
         flows = ofctl_v1_2.get_flow_stats(dp, self.waiters, flow)
     elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
         flows = ofctl_v1_3.get_flow_stats(dp, self.waiters, flow)
     else:
         LOG.debug('Unsupported OF protocol')
         return None
     return flows
Example #8
0
 def getFlows(self, dpid):
     flow = {}
     dp = self.dpset.get(int(dpid))
     if dp is None:
         return None
     if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
         flows = ofctl_v1_0.get_flow_stats(dp, self.waiters, flow)
     elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
         flows = ofctl_v1_2.get_flow_stats(dp, self.waiters, flow)
     elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
         flows = ofctl_v1_3.get_flow_stats(dp, self.waiters, flow)
     else:
         LOG.debug('Unsupported OF protocol')
         return None
     return flows
Example #9
0
    def get_flow_stats(self, req, dpid, **_kwargs):
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return Response(status=404)

        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            flows = ofctl_v1_0.get_flow_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            flows = ofctl_v1_2.get_flow_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            flows = ofctl_v1_3.get_flow_stats(dp, self.waiters)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        body = json.dumps(flows)
	res = Response(content_type='application/json', body=body)
	res.headers.add('Access-Control-Allow-Origin', '*')
        return res
Example #10
0
    def get_flow_stats(self, req, dpid, **_kwargs):
        dp = self.dpset.get(int(dpid, 0))
        if dp is None:
            return Response(status=404)

        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            flows = ofctl_v1_0.get_flow_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            flows = ofctl_v1_2.get_flow_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            # -------------------------- Fujitsu code start -----------------------------
            # For optical enhancing
            #            flows = ofctl_v1_3.get_flow_stats(dp, self.waiters)
            flows = ofctl_v1_3.get_flow_stats(dp, self.waiters, match)


# -------------------------- Fujitsu code end -------------------------------
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        body = json.dumps(flows)
        return (Response(content_type='application/json', body=body))
Example #11
0
    def flow_stats_reply_handler_API(self, dpid):
        flow = {}
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return None
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            flows = ofctl_v1_0.get_flow_stats(dp, self.waiters, flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            flows = ofctl_v1_2.get_flow_stats(dp, self.waiters, flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            flows = ofctl_v1_3.get_flow_stats(dp, self.waiters, flow)
        else:
            LOG.debug('Unsupported OF protocol')
            return None

        print '----------------------flowAPI----------------------'

        flowstatsReplyAPI = {}
        flowstatsReplyAPI["controller"] = controllerName

        for key in flows:
            temp = "%016x" %int(key)
            temp = map(str, temp)
            for i in range(2, 23, 3):
                temp.insert(i, ':')
            flowstatsReplyAPI["dpid"] = ''.join(temp)

            flowstatsReplyAPI["flows"] = []
            i = 0
            for inflow in flows[key]:
                if 'priority' in inflow:
                    flowstatsReplyAPI["flows"].append({})
                    flowstatsReplyAPI["flows"][i]["ingressPort"] = str(inflow['match']['in_port']) if 'in_port' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["dstMac"] = inflow['match']['dl_dst'] if 'dl_dst' in inflow['match'] else "00:00:00:00:00:00"
                    flowstatsReplyAPI["flows"][i]["srcMac"] = inflow['match']['dl_src'] if 'dl_src' in inflow['match'] else "00:00:00:00:00:00"
                    flowstatsReplyAPI["flows"][i]["dstIP"] = inflow['match']['nw_dst'] if 'nw_dst' in inflow['match'] else "0.0.0.0"
                    flowstatsReplyAPI["flows"][i]["dstIPMask"] = "0" # not support in ryu
                    flowstatsReplyAPI["flows"][i]["srcIP"] = inflow['match']['nw_src'] if 'nw_src' in inflow['match'] else "0.0.0.0"
                    flowstatsReplyAPI["flows"][i]["srcIPMask"] = "0" # not support in ryu
                    flowstatsReplyAPI["flows"][i]["netProtocol"] = hex(inflow['match']['nw_proto']) if 'nw_proto' in inflow['match'] else "0x00"
                    flowstatsReplyAPI["flows"][i]["dstPort"] = str(inflow['match']['tp_dst']) if 'tp_dst' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["srcPort"] = str(inflow['match']['tp_src']) if 'tp_src' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["vlan"] = str(inflow['match']['dl_vlan']) if 'dl_vlan' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["vlanP"] = str(inflow['match']['dl_vlan_pcp']) if 'dl_vlan_pcp' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["tosBits"] = str(inflow['match']['nw_tos']) if 'nw_tos' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["counterByte"] = str(inflow['byte_count'])
                    flowstatsReplyAPI["flows"][i]["counterPacket"] = str(inflow['packet_count'])
                    flowstatsReplyAPI["flows"][i]["idleTimeout"] = str(inflow['idle_timeout'])
                    flowstatsReplyAPI["flows"][i]["hardTimeout"] = str(inflow['hard_timeout'])
                    flowstatsReplyAPI["flows"][i]["priority"] = str(inflow['priority'])
                    flowstatsReplyAPI["flows"][i]["duration"] = str(inflow['duration_sec'])
                    flowstatsReplyAPI["flows"][i]["dlType"] = hex(inflow['match']['dl_type']) if 'dl_type' in inflow['match'] else "0x0000"

                    flowstatsReplyAPI["flows"][i]["actions"] = []
                    for action in inflow['actions']:
                        if len(action.split(':')) == 1:
                            act = {
                                "value": "0",
                                "type": action
                            }
                        else:
                            act = {
                                "value": action.split(':')[1],
                                "type": action.split(':')[0]
                            }
                        flowstatsReplyAPI["flows"][i]["actions"].append(act)

                    i += 1

        print json.dumps(flowstatsReplyAPI)
        tmpIP = coreURL + "/publish/flow"
        self.post_json_to_core(tmpIP, json.dumps(flowstatsReplyAPI))
        return flows
Example #12
0
    def flow_stats_reply_handler_API(self, dpid):
        flow = {}
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return None
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            flows = ofctl_v1_0.get_flow_stats(dp, self.waiters, flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            flows = ofctl_v1_2.get_flow_stats(dp, self.waiters, flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            flows = ofctl_v1_3.get_flow_stats(dp, self.waiters, flow)
        else:
            LOG.debug("Unsupported OF protocol")
            return None

        print "----------------------flowAPI----------------------"

        flowstatsReplyAPI = {}
        flowstatsReplyAPI["controller"] = controllerName

        for key in flows:
            temp = "%016x" % int(key)
            temp = map(str, temp)
            for i in range(2, 23, 3):
                temp.insert(i, ":")
            flowstatsReplyAPI["dpid"] = "".join(temp)

            flowstatsReplyAPI["flows"] = []
            i = 0
            for inflow in flows[key]:
                if "priority" in inflow:
                    flowstatsReplyAPI["flows"].append({})
                    flowstatsReplyAPI["flows"][i]["ingressPort"] = (
                        str(inflow["match"]["in_port"]) if "in_port" in inflow["match"] else "0"
                    )
                    flowstatsReplyAPI["flows"][i]["dstMac"] = (
                        inflow["match"]["dl_dst"] if "dl_dst" in inflow["match"] else "00:00:00:00:00:00"
                    )
                    flowstatsReplyAPI["flows"][i]["srcMac"] = (
                        inflow["match"]["dl_src"] if "dl_src" in inflow["match"] else "00:00:00:00:00:00"
                    )
                    flowstatsReplyAPI["flows"][i]["dstIP"] = (
                        inflow["match"]["nw_dst"] if "nw_dst" in inflow["match"] else "0.0.0.0"
                    )
                    flowstatsReplyAPI["flows"][i]["dstIPMask"] = "0"  # not support in ryu
                    flowstatsReplyAPI["flows"][i]["srcIP"] = (
                        inflow["match"]["nw_src"] if "nw_src" in inflow["match"] else "0.0.0.0"
                    )
                    flowstatsReplyAPI["flows"][i]["srcIPMask"] = "0"  # not support in ryu
                    flowstatsReplyAPI["flows"][i]["netProtocol"] = (
                        hex(inflow["match"]["nw_proto"]) if "nw_proto" in inflow["match"] else "0x00"
                    )
                    flowstatsReplyAPI["flows"][i]["dstPort"] = (
                        str(inflow["match"]["tp_dst"]) if "tp_dst" in inflow["match"] else "0"
                    )
                    flowstatsReplyAPI["flows"][i]["srcPort"] = (
                        str(inflow["match"]["tp_src"]) if "tp_src" in inflow["match"] else "0"
                    )
                    flowstatsReplyAPI["flows"][i]["vlan"] = (
                        str(inflow["match"]["dl_vlan"]) if "dl_vlan" in inflow["match"] else "0"
                    )
                    flowstatsReplyAPI["flows"][i]["vlanP"] = (
                        str(inflow["match"]["dl_vlan_pcp"]) if "dl_vlan_pcp" in inflow["match"] else "0"
                    )
                    flowstatsReplyAPI["flows"][i]["wildcards"] = (
                        str(inflow["match"]["wildcards"]) if "wildcards" in inflow["match"] else "0"
                    )
                    flowstatsReplyAPI["flows"][i]["tosBits"] = (
                        str(inflow["match"]["nw_tos"]) if "nw_tos" in inflow["match"] else "0"
                    )
                    flowstatsReplyAPI["flows"][i]["counterByte"] = str(inflow["byte_count"])
                    flowstatsReplyAPI["flows"][i]["counterPacket"] = str(inflow["packet_count"])
                    flowstatsReplyAPI["flows"][i]["idleTimeout"] = str(inflow["idle_timeout"])
                    flowstatsReplyAPI["flows"][i]["hardTimeout"] = str(inflow["hard_timeout"])
                    flowstatsReplyAPI["flows"][i]["priority"] = str(inflow["priority"])
                    flowstatsReplyAPI["flows"][i]["duration"] = str(inflow["duration_sec"])
                    flowstatsReplyAPI["flows"][i]["dlType"] = (
                        hex(inflow["match"]["dl_type"]) if "dl_type" in inflow["match"] else "0x0000"
                    )

                    flowstatsReplyAPI["flows"][i]["actions"] = []
                    for action in inflow["actions"]:
                        if len(action.split(":")) == 1:
                            act = {"value": "0", "type": action}
                        else:
                            act = {"value": action.split(":")[1], "type": action.split(":")[0]}
                        flowstatsReplyAPI["flows"][i]["actions"].append(act)

                    i += 1

        print json.dumps(flowstatsReplyAPI)
        tmpIP = "http://" + coreIP + ":" + corePort + "/publish/flow"
        self.post_json_to_core(tmpIP, json.dumps(flowstatsReplyAPI))
        return flows
Example #13
0
    def flow_stats_reply_handler_API(self, dpid):
        flow = {}
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return None
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            flows = ofctl_v1_0.get_flow_stats(dp, self.waiters, flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            flows = ofctl_v1_2.get_flow_stats(dp, self.waiters, flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            flows = ofctl_v1_3.get_flow_stats(dp, self.waiters, flow)
        else:
            LOG.debug('Unsupported OF protocol')
            return None

        print '----------------------flowAPI----------------------'

        flowstatsReplyAPI = {}
        flowstatsReplyAPI["controller"] = controllerName

        for key in flows:
            temp = "%016x" % int(key)
            temp = map(str, temp)
            for i in range(2, 23, 3):
                temp.insert(i, ':')
            flowstatsReplyAPI["dpid"] = ''.join(temp)

            flowstatsReplyAPI["flows"] = []
            i = 0
            for inflow in flows[key]:
                if 'priority' in inflow:
                    flowstatsReplyAPI["flows"].append({})
                    flowstatsReplyAPI["flows"][i]["ingressPort"] = str(
                        inflow['match']
                        ['in_port']) if 'in_port' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["dstMac"] = inflow['match'][
                        'dl_dst'] if 'dl_dst' in inflow[
                            'match'] else "00:00:00:00:00:00"
                    flowstatsReplyAPI["flows"][i]["srcMac"] = inflow['match'][
                        'dl_src'] if 'dl_src' in inflow[
                            'match'] else "00:00:00:00:00:00"
                    flowstatsReplyAPI["flows"][i]["dstIP"] = inflow['match'][
                        'nw_dst'] if 'nw_dst' in inflow['match'] else "0.0.0.0"
                    flowstatsReplyAPI["flows"][i][
                        "dstIPMask"] = "0"  # not support in ryu
                    flowstatsReplyAPI["flows"][i]["srcIP"] = inflow['match'][
                        'nw_src'] if 'nw_src' in inflow['match'] else "0.0.0.0"
                    flowstatsReplyAPI["flows"][i][
                        "srcIPMask"] = "0"  # not support in ryu
                    flowstatsReplyAPI["flows"][i]["netProtocol"] = hex(
                        inflow['match']['nw_proto']
                    ) if 'nw_proto' in inflow['match'] else "0x00"
                    flowstatsReplyAPI["flows"][i]["dstPort"] = str(
                        inflow['match']
                        ['tp_dst']) if 'tp_dst' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["srcPort"] = str(
                        inflow['match']
                        ['tp_src']) if 'tp_src' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["vlan"] = str(
                        inflow['match']
                        ['dl_vlan']) if 'dl_vlan' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["vlanP"] = str(
                        inflow['match']['dl_vlan_pcp']
                    ) if 'dl_vlan_pcp' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["tosBits"] = str(
                        inflow['match']
                        ['nw_tos']) if 'nw_tos' in inflow['match'] else "0"
                    flowstatsReplyAPI["flows"][i]["counterByte"] = str(
                        inflow['byte_count'])
                    flowstatsReplyAPI["flows"][i]["counterPacket"] = str(
                        inflow['packet_count'])
                    flowstatsReplyAPI["flows"][i]["idleTimeout"] = str(
                        inflow['idle_timeout'])
                    flowstatsReplyAPI["flows"][i]["hardTimeout"] = str(
                        inflow['hard_timeout'])
                    flowstatsReplyAPI["flows"][i]["priority"] = str(
                        inflow['priority'])
                    flowstatsReplyAPI["flows"][i]["duration"] = str(
                        inflow['duration_sec'])
                    flowstatsReplyAPI["flows"][i]["dlType"] = hex(
                        inflow['match']['dl_type']
                    ) if 'dl_type' in inflow['match'] else "0x0000"

                    flowstatsReplyAPI["flows"][i]["actions"] = []
                    for action in inflow['actions']:
                        if len(action.split(':')) == 1:
                            act = {"value": "0", "type": action}
                        else:
                            act = {
                                "value": action.split(':')[1],
                                "type": action.split(':')[0]
                            }
                        flowstatsReplyAPI["flows"][i]["actions"].append(act)

                    i += 1

        print json.dumps(flowstatsReplyAPI)
        tmpIP = coreURL + "/publish/flow"
        self.post_json_to_core(tmpIP, json.dumps(flowstatsReplyAPI))
        return flows