def set_patch_flow(self, req_flow):

        # Check before send flow-mod
        dpid = req_flow.get("dpid")
        dp = self.dpset.get(dpid)
        if dp is None:
            return Response(status=400)
        inport = req_flow.get("inport")
        outport = req_flow.get("outport")
        mirrorport = req_flow.get("mirrorport")
        for flow in self.patch_flows:
            if dpid == flow["dpid"] and inport == flow["inport"]:
                LOG.info("Requested inport is already used (dpid:%s, inport:%d)", dpid, inport)
                return Response(status=400)

        new_flow = {"match": {"in_port": inport}, "actions": [{"type": "OUTPUT", "port": outport}]}
        if mirrorport is not None:
            new_flow["actions"].append({"type": "OUTPUT", "port": mirrorport})

        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ofctl_v1_0.mod_flow_entry(dp, new_flow, dp.ofproto.OFPFC_ADD)
            self.patch_flows.append(req_flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            ofctl_v1_2.mod_flow_entry(dp, new_flow, dp.ofproto.OFPFC_ADD)
            self.patch_flows.append(req_flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ofctl_v1_3.mod_flow_entry(dp, new_flow, dp.ofproto.OFPFC_ADD)
            self.patch_flows.append(req_flow)
        else:
            LOG.info("Unsupported OF protocol")
            return Response(status=501)

        return Response(status=200)
示例#2
0
    def mod_flow_entry(self, req, cmd, **_kwargs):
        try:
            flow = eval(req.body)
        except SyntaxError:
            LOG.debug('invalid syntax %s', req.body)
            return Response(status=400)

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

        if cmd == 'add':
            cmd = dp.ofproto.OFPFC_ADD
        elif cmd == 'modify':
            cmd = dp.ofproto.OFPFC_MODIFY
        elif cmd == 'delete':
            cmd = dp.ofproto.OFPFC_DELETE
        else:
            return Response(status=404)

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

        return Response(status=200)
    def delete_patch_flow(self, req_flow):

        # Check before send flow-mod
        dpid = req_flow.get("dpid")
        dp = self.dpset.get(dpid)
        if dp is None:
            return Response(status=400)
        inport = req_flow.get("inport")
        outport = req_flow.get("outport")
        mirrorport = req_flow.get("mirrorport")
        for flow in self.patch_flows:
            if dpid == flow["dpid"] and inport == flow["inport"]:
                break
        else:
            LOG.info("Requested inport is not used (dpid:%s, inport:%d)", dpid, inport)
            return Response(status=400)

        del_flow = {"match": {"in_port": inport}}
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ofctl_v1_0.mod_flow_entry(dp, del_flow, dp.ofproto.OFPFC_DELETE)
            self.patch_flows.remove(req_flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            ofctl_v1_2.mod_flow_entry(dp, del_flow, dp.ofproto.OFPFC_DELETE)
            self.patch_flows.remove(req_flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ofctl_v1_3.mod_flow_entry(dp, del_flow, dp.ofproto.OFPFC_DELETE)
            self.patch_flows.remove(req_flow)
        else:
            LOG.debug("Unsupported OF protocol")
            return Response(status=501)

        return Response(status=200)
示例#4
0
    def delete_patch_flow(self, req_flow):

        # Check before send flow-mod
        dpid = req_flow.get('dpid')
        dp = self.dpset.get(dpid)
        if dp is None:
            return Response(status=400)
        inport = req_flow.get('inport')
        outport = req_flow.get('outport')
        mirrorport = req_flow.get('mirrorport')
        for flow in self.patch_flows:
            if dpid == flow['dpid'] and inport == flow['inport']:
                break
        else:
            LOG.info('Requested inport is not used (dpid:%s, inport:%d)', dpid,
                     inport)
            return Response(status=400)

        del_flow = {'match': {'in_port': inport}}
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ofctl_v1_0.mod_flow_entry(dp, del_flow, dp.ofproto.OFPFC_DELETE)
            self.patch_flows.remove(req_flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            ofctl_v1_2.mod_flow_entry(dp, del_flow, dp.ofproto.OFPFC_DELETE)
            self.patch_flows.remove(req_flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ofctl_v1_3.mod_flow_entry(dp, del_flow, dp.ofproto.OFPFC_DELETE)
            self.patch_flows.remove(req_flow)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        return Response(status=200)
示例#5
0
    def mod_flow_entry(self, req, cmd, **_kwargs):
        try:
            flow = eval(req.body)
        except SyntaxError:
            LOG.debug('invalid syntax %s', req.body)
            return Response(status=400)

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

        if cmd == 'add':
            cmd = dp.ofproto.OFPFC_ADD
        elif cmd == 'modify':
            cmd = dp.ofproto.OFPFC_MODIFY
        elif cmd == 'delete':
            cmd = dp.ofproto.OFPFC_DELETE
        else:
            return Response(status=404)

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

        return Response(status=200)
示例#6
0
    def mod_flow_entry(self, req, cmd, **_kwargs):
        if cmd == "reset" or cmd == "reset_strict":
            try:
                flow = ast.literal_eval(req.body)
            except SyntaxError:
                LOG.debug('invalid syntax %s', req.body)
                return Response(status=400)

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

            if cmd == 'reset':
                cmd = dp.ofproto.OFPFC_MODIFY
            elif cmd == 'reset_strict':
                cmd = dp.ofproto.OFPFC_MODIFY_STRICT
            else:
                return Response(status=404)

            flow["flags"] = int(flow.get("flags", 0) | 4)
            if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
                ofctl_v1_0.mod_flow_entry(dp, flow, cmd)
            elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
                ofctl_v1_2.mod_flow_entry(dp, flow, cmd)
            elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
                ofctl_v1_3.mod_flow_entry(dp, flow, cmd)
            else:
                LOG.debug('Unsupported OF protocol')
                return Response(status=501)

            return Response(status=200)
        else:
            return super(RestController, self).mod_flow_entry(req, cmd, **_kwargs)
示例#7
0
    def mod_flow_entry(self, req, cmd, **_kwargs):
        try:
            flow = eval(req.body)
        except SyntaxError:
            LOG.debug('invalid syntax %s', req.body)
            return Response(status=400)

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

        if cmd == 'add':
            cmd = dp.ofproto.OFPFC_ADD
        elif cmd == 'modify':
            cmd = dp.ofproto.OFPFC_MODIFY
        elif cmd == 'delete':
            cmd = dp.ofproto.OFPFC_DELETE
        else:
            return Response(status=404)

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

        return Response(status=200)
	res = Response(content_type='application/json', body=body)
	res.headers.add('Access-Control-Allow-Origin', '*')
        return res
示例#8
0
	def mod_flow(self, datapath, flow, command):
		if datapath.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
			ofctl_v1_0.mod_flow_entry(datapath, flow, command)
		elif datapath.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
			ofctl_v1_2.mod_flow_entry(datapath, flow, command)
		elif datapath.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
			ofctl_v1_3.mod_flow_entry(datapath, flow, command)
示例#9
0
 def _mod_patch_flow_entry(self, dp, flow_rule, command):
     if dp.ofproto.OFP_VERSION in self.OFP_VERSIONS:
         if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
             ofctl_v1_0.mod_flow_entry(dp, flow_rule, command)
         elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
             ofctl_v1_2.mod_flow_entry(dp, flow_rule, command)
         elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
             ofctl_v1_3.mod_flow_entry(dp, flow_rule, command)
         return True
     else:
         msg = "Unsupported OFP version: %s" % dp.ofproto.OFP_VERSION
         raise patch_ofc_error.PatchOfcError(msg)
示例#10
0
 def _mod_patch_flow_entry(self, dp, flow_rule, command):
     if dp.ofproto.OFP_VERSION in self.OFP_VERSIONS:
         if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
             ofctl_v1_0.mod_flow_entry(dp, flow_rule, command)
         elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
             ofctl_v1_2.mod_flow_entry(dp, flow_rule, command)
         elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
             ofctl_v1_3.mod_flow_entry(dp, flow_rule, command)
         return True
     else:
         msg = "Unsupported OFP version: %s" % dp.ofproto.OFP_VERSION
         raise patch_ofc_error.PatchOfcError(msg)
示例#11
0
文件: ofctl_rest.py 项目: BennyE/ryu
    def delete_flow_entry(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:
            ofctl_v1_0.delete_flow_entry(dp)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            ofctl_v1_2.mod_flow_entry(dp, {}, dp.ofproto.OFPFC_DELETE)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ofctl_v1_3.mod_flow_entry(dp, {}, dp.ofproto.OFPFC_DELETE)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        return Response(status=200)
示例#12
0
    def delete_flow_entry(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:
            ofctl_v1_0.delete_flow_entry(dp)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            ofctl_v1_2.mod_flow_entry(dp, {}, dp.ofproto.OFPFC_DELETE)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ofctl_v1_3.mod_flow_entry(dp, {}, dp.ofproto.OFPFC_DELETE)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        return Response(status=200)
示例#13
0
    def set_patch_flow(self, req_flow):

        # Check before send flow-mod
        dpid = req_flow.get('dpid')
        dp = self.dpset.get(dpid)
        if dp is None:
            return Response(status=400)
        inport = req_flow.get('inport')
        outport = req_flow.get('outport')
        mirrorport = req_flow.get('mirrorport')
        for flow in self.patch_flows:
            if dpid == flow['dpid'] and inport == flow['inport']:
                LOG.info(
                    'Requested inport is already used (dpid:%s, inport:%d)',
                    dpid, inport)
                return Response(status=400)

        new_flow = {
            'match': {
                'in_port': inport
            },
            'actions': [{
                'type': 'OUTPUT',
                'port': outport
            }]
        }
        if mirrorport is not None:
            new_flow['actions'].append({'type': 'OUTPUT', 'port': mirrorport})

        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ofctl_v1_0.mod_flow_entry(dp, new_flow, dp.ofproto.OFPFC_ADD)
            self.patch_flows.append(req_flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            ofctl_v1_2.mod_flow_entry(dp, new_flow, dp.ofproto.OFPFC_ADD)
            self.patch_flows.append(req_flow)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ofctl_v1_3.mod_flow_entry(dp, new_flow, dp.ofproto.OFPFC_ADD)
            self.patch_flows.append(req_flow)
        else:
            LOG.info('Unsupported OF protocol')
            return Response(status=501)

        return Response(status=200)