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):
        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)
Пример #6
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)
        if 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)
Пример #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 set_flows(self, dp, f):
        ofproto = dp.ofproto

        delete_flow_entry(dp)

        flow = {
            "priority":
            1000,
            "match": {
                "dl_type": 0x0800,
                "nw_proto": 6,
                "in_port": f["iport"],
                "nw_dst": self.dst['nw'],
                "tp_dst": self.dst['tp']
            },
            "actions": [{
                "type": "SET_NW_DST",
                "nw_dst": f["nw"]
            }, {
                "type": "SET_TP_DST",
                "tp_dst": f["tp"]
            }, {
                "type": "SET_DL_DST",
                "dl_dst": f["dl"]
            }, {
                "type": "OUTPUT",
                "port": f["oport"]
            }]
        }
        mod_flow_entry(dp, flow, ofproto.OFPFC_ADD)

        flow = {
            "priority":
            1000,
            "match": {
                "dl_type": 0x0800,
                "nw_proto": 6,
                "in_port": f["oport"],
                "nw_src": f["nw"],
                "tp_src": f["tp"]
            },
            "actions": [{
                "type": "SET_NW_SRC",
                "nw_src": self.dst['nw']
            }, {
                "type": "SET_TP_SRC",
                "tp_src": self.dst['tp']
            }, {
                "type": "SET_DL_SRC",
                "dl_src": f["dl"]
            }, {
                "type": "OUTPUT",
                "port": f["iport"]
            }]
        }
        mod_flow_entry(dp, flow, ofproto.OFPFC_ADD)
Пример #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
 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)
Пример #12
0
    def set_flows(self, dp, f):
        ofproto = dp.ofproto

        delete_flow_entry(dp)

        flow = {"priority":1000,
                "match":{"dl_type": 0x0800, "nw_proto": 6,"in_port":f["iport"], "nw_dst":self.dst['nw'],"tp_dst":self.dst['tp']},
                "actions":[{"type":"SET_NW_DST","nw_dst":f["nw"]},{"type":"SET_TP_DST","tp_dst":f["tp"]},
                           {"type":"SET_DL_DST","dl_dst":f["dl"]},{"type":"OUTPUT", "port":f["oport"]}]}
        mod_flow_entry(dp, flow, ofproto.OFPFC_ADD)

        flow = {"priority":1000,
                "match":{"dl_type": 0x0800, "nw_proto": 6,"in_port":f["oport"],"nw_src":f["nw"],"tp_src":f["tp"]},
                "actions":[{"type":"SET_NW_SRC","nw_src":self.dst['nw']},{"type":"SET_TP_SRC","tp_src":self.dst['tp']},
                           {"type":"SET_DL_SRC","dl_src":f["dl"]},{"type":"OUTPUT", "port":f["iport"]}]}
        mod_flow_entry(dp, flow, ofproto.OFPFC_ADD)
Пример #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)
Пример #14
0
    def mod_flow_entry(self, req, **kwargs):
        try:
            omniFlow = ast.literal_eval(req.body)  #Getting flow from req
        except SyntaxError:
            LOG.debug('Invalid syntax %s', req.body)
            return Response(status=400)

        omniDpid = omniFlow.get('dpid')  #Getting OmniUI dpid from flow
        if omniDpid is None:
            return Response(status=404)
        else:
            dpid = self.nospaceDPID(
                omniDpid.split(':'))  #Split OmniUI dpid into a list

        cmd = omniFlow.get('command')  #Getting OmniUI command from flow
        dp = self.dpset.get(int(dpid, 16))  #Getting datapath from Ryu dpid
        if dp is None:  #NB: convert dpid to int first
            return Response(status=404)

        if cmd == 'ADD':
            cmd = dp.ofproto.OFPFC_ADD
        elif cmd == 'MOD':
            cmd = dp.ofproto.OFPFC_MODIFY
        elif cmd == 'MOD_ST':
            cmd = dp.ofproto.OFPFC_MODIFY_STRICT
        elif cmd == 'DEL':
            cmd = dp.ofproto.OFPFC_DELETE
        elif cmd == 'DEL_ST':
            cmd = dp.ofproto.OFPFC_DELETE_STRICT
        else:
            return Response(status=404)

        ryuFlow = {}
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ryuFlow = self.ryuFlow_v1_0(dp, omniFlow)
            ofctl_v1_0.mod_flow_entry(dp, ryuFlow, cmd)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ryuFlow = self.ryuFlow_v1_3(dp, omniFlow)
            ofctl_v1_3.mod_flow_entry(dp, ryuFlow, cmd)
        else:
            return Response(status=404)

        return Response(status=200)
Пример #15
0
    def mod_flow_entry(self, req, **kwargs):
        try:
            omniFlow = ast.literal_eval(req.body)     #Getting flow from req
        except SyntaxError:
            LOG.debug('Invalid syntax %s', req.body)
            return Response(status=400)

        omniDpid = omniFlow.get('dpid')             #Getting OmniUI dpid from flow
        if omniDpid is None:
            return Response(status=404)
        else:
            dpid = self.nospaceDPID(omniDpid.split(':'))    #Split OmniUI dpid into a list

        cmd = omniFlow.get('command')                 #Getting OmniUI command from flow
        dp = self.dpset.get(int(dpid, 16))                #Getting datapath from Ryu dpid
        if dp is None:                                #NB: convert dpid to int first
            return Response(status=404)

        if cmd == 'ADD':
            cmd = dp.ofproto.OFPFC_ADD
        elif cmd == 'MOD':
            cmd = dp.ofproto.OFPFC_MODIFY
        elif cmd == 'MOD_ST':
            cmd = dp.ofproto.OFPFC_MODIFY_STRICT
        elif cmd == 'DEL':
            cmd = dp.ofproto.OFPFC_DELETE
        elif cmd == 'DEL_ST':
            cmd = dp.ofproto.OFPFC_DELETE_STRICT
        else:
            return Response(status=404)

        ryuFlow={}
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ryuFlow = self.ryuFlow_v1_0(dp, omniFlow)
            ofctl_v1_0.mod_flow_entry(dp, ryuFlow, cmd)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ryuFlow = self.ryuFlow_v1_3(dp, omniFlow)
            ofctl_v1_3.mod_flow_entry(dp, ryuFlow, cmd)
        else:
            return Response(status=404)

        return Response(status=200)