Ejemplo n.º 1
0
    def reserve(self, resv):
        # logger.info("ovsgre:OvsManager:reserve: enter")
        # This just only reserve vlans for source/destination/tunnel interfaces
        if resv is None:
            raise ManagerException("OvsManager:reserve",
                                   "The reservation parameter is null.")

        self.check_stp(resv)

        resv_id = uuid.uuid4()
        logger.info("ovsManager:reserve: new resv_id=%s." % resv_id)

        if dict_resvParameter.has_key(resv_id):
            logger.error("Never here. Reservation id is duplicated(%s)." %
                         (resv_id))
            raise ManagerException("OvsManager:reserve",
                                   "The reservation id is already used.")

        resvp = resvParameter(self.ovs_id, resv)

        (s_vlan, d_vlan, t_vlan) = resvp.allocate()
        resv.trans_vlan = t_vlan

        dict_resvParameter[resv_id] = resvp
        self.dict_isSetRule[resv_id] = False
        logger.info("ovsManager:reserve: done. resv_id=%s" % (resv_id))
        return resv_id
Ejemplo n.º 2
0
    def status (self, resv):
        if resv is None or not dict_resvParameter.has_key(resv.resv_id):
            logger.info("ovsManager:status: resv_id=%s" % (resv.resv_id))
            for key in dict_resvParameter:
                logger.info("ovsManager:status: resvp=%s" % (key))
            raise ManagerException("OvsManager:status", "The reservation is null.")

        resvp = dict_resvParameter[resv.resv_id]
        if resvp is None:
            raise ManagerException("OvsManager:status", "The ResvParameter is null.")

        rc = self.check_rule(self.src_if, resvp.s_vlan, resvp.t_vlan)
        if not rc:
            ### This operation is caused we can not remove flow rules 
            ### and teardown gre tunnel in a normal island.
            # self.dict_isSetRule[resv.resv_id] = False
            return False

        rc = self.check_rule(self.dst_if, resvp.d_vlan, resvp.t_vlan)
        if not rc:
            ### This operation is caused we can not remove flow rules 
            ### and teardown gre tunnel in a normal island.
            # self.dict_isSetRule[resv.resv_id] = False
            return False
        return True
Ejemplo n.º 3
0
    def status (self, resv):
        if resv is None or not dict_resvParameter.has_key(resv.resv_id):
            logger.info("ovsManager:status: resv_id=%s" % (resv.resv_id))
            for key in dict_resvParameter:
                logger.info("ovsManager:status: resvp=%s" % (key))
            raise ManagerException("OvsManager:status", "The reservation is null.")

        resvp = dict_resvParameter[resv.resv_id]
        if resvp is None:
            raise ManagerException("OvsManager:status", "The ResvParameter is null.")

        rc = self.check_rule(self.src_if, resvp.s_vlan, resvp.t_vlan)
        if not rc:
            ### This operation is caused we can not remove flow rules 
            ### and teardown gre tunnel in a normal island.
            # self.dict_isSetRule[resv.resv_id] = False
            return False

        rc = self.check_rule(self.dst_if, resvp.d_vlan, resvp.t_vlan)
        if not rc:
            ### This operation is caused we can not remove flow rules 
            ### and teardown gre tunnel in a normal island.
            # self.dict_isSetRule[resv.resv_id] = False
            return False
        return True
Ejemplo n.º 4
0
    def update(self, resv):
        fmt = "UPDATE %s SET %s=\"%s\",  %s=\"%s\",  %s=\"%s\",  %s=\"%s\",  %s=\"%s\" WHERE resv_urn=\"%s\""

        error = resv.error
        if error is not None:
            error = error.replace("\"", "")
            error = error.replace("\'", "")

        sql = fmt % (mySQLtbl, 
                     "geni_expires", resv.end_time,
                     "geni_operational_status", resv.ostatus,
                     "geni_allocation_status", resv.astatus,
                     "geni_error", error,
                     "geni_action", resv.action,
                     resv.urn)

        logger.info("tnrm_db:update: sql=%s" % sql)

        try:
            self.open()
            self.cur.execute(sql)
            self.cur.execute("COMMIT")
        except Exception as e:
            logger.error("tnrm_db:restart: ex=%s" % e)
            raise e
        finally:
            self.close()
Ejemplo n.º 5
0
    def update(self, resv):
        fmt = "UPDATE %s SET %s=\"%s\",  %s=\"%s\",  %s=\"%s\",  %s=\"%s\",  %s=\"%s\" WHERE resv_urn=\"%s\""

        error = resv.error
        if error is not None:
            error = error.replace("\"", "")
            error = error.replace("\'", "")

        sql = fmt % (mySQLtbl, 
                     "geni_expires", resv.end_time,
                     "geni_operational_status", resv.ostatus,
                     "geni_allocation_status", resv.astatus,
                     "geni_error", error,
                     "geni_action", resv.action,
                     resv.urn)

        logger.info("tnrm_db:update: sql=%s" % sql)

        try:
            self.open()
            self.cur.execute(sql)
            self.cur.execute("COMMIT")
        except Exception as e:
            logger.error("tnrm_db:restart: ex=%s" % e)
            raise e
        finally:
            self.close()
Ejemplo n.º 6
0
    def teardown_tunnel(self, src_if, dst_if):
        sw = get_swManager(src_if)
        ofport = None
        
        try:
            # ofport = sw.get_port(src_if.ofdev)
            ofdev, ofport = src_if.get_of(self.ovs_id)
            ofport2 = sw.get_port(ofdev)
            if ofport != ofport2:
                logger.error("teardown_tunnel:ofdev=%s: mismatch ofport=%s, ofport2=%s" % (ofdev, ofport, ofport2))
                ofport = ofport2
        except Exception as e:
            logger.info("teardown_tunnel:gre port is None")
            
        if ofport is not None:
            urlbase = src_if.ryu_url
            dpid = src_if.dpid

            logger.info("teardown gre link here. url=%s, dpid=%s, ovsdb=%s, dev=%s, type=%s, local=%s, remote=%s" %
                        (urlbase, dpid, src_if.ovsdb, ofdev, src_if.gtype, src_if.address, dst_if.address));

            params = {}
            params["ovsdb"] = src_if.ovsdb
            params["name"] = ofdev
            params["remote_ip"] = dst_if.address

            ovsif.del_tunnel(urlbase, dpid, params)

        # src_if.ofport = None
        src_if.set_of(self.ovs_id, ofdev, None)
        sw.set_free(ofdev)
Ejemplo n.º 7
0
    def add_rule(self, interface, sevlan, ofvlan):
        urlbase = interface.ryu_url
        dpid = interface.dpid
        ofdev, ofport = interface.get_of(self.ovs_id)

        params = {}
        params["dpid"] = int(dpid, 16)
        params["priority"] = OF_PRIORITY
        params["idel_timeout"] = OF_TIMEOUT
        params["hard_timeout"] = OF_TIMEOUT
        params["cookie"] = OF_COOKIE
        params["cookie_mask"] = OF_COOKIE_MASK
        params["table_id"] = OF_TABLE_ID
        params["flags"] = OF_FLAGS

        matchs = {"in_port": interface.seport, "dl_vlan": sevlan} 
        params["match"] = matchs
        # actions = [{"type":"SET_VLAN_VID", "vlan_vid": ofvlan}, {"type":"OUTPUT", "port": interface.ofport}] 
        actions = [{"type":"SET_VLAN_VID", "vlan_vid": ofvlan}, {"type":"OUTPUT", "port": ofport}] 
        params["actions"] = actions
        rc = ovsif.add_flow(urlbase, params)
        logger.info("add_rule: ret=%s" % rc)

        # matchs = {"in_port": interface.ofport, "dl_vlan": ofvlan} 
        matchs = {"in_port": ofport, "dl_vlan": ofvlan} 
        params["match"] = matchs
        actions = [{"type":"SET_VLAN_VID", "vlan_vid": sevlan}, {"type":"OUTPUT", "port": interface.seport}] 
        params["actions"] = actions
        rc = ovsif.add_flow(urlbase, params)
        logger.info("add_rule: ret=%s" % rc)
Ejemplo n.º 8
0
    def get_port(self, dev):
        if self.dict_dev.has_key(dev):
            port = self.dict_dev[dev]
            logger.info("swManager: get_port: dev=%s, ofport=%s" % (dev, port))
            return self.dict_dev[dev]

        raise ManagerException("ovsgre:swManager:get_port", "This dev(%s) does not exist." % dev)
Ejemplo n.º 9
0
    def get_port(self, dev):
        if self.dict_dev.has_key(dev):
            port = self.dict_dev[dev]
            logger.info("swManager: get_port: dev=%s, ofport=%s" % (dev, port))
            return self.dict_dev[dev]

        raise ManagerException("ovsgre:swManager:get_port", "This dev(%s) does not exist." % dev)
Ejemplo n.º 10
0
    def restart (self):
        fmt = "SELECT * from %s"
        sql = fmt % mySQLtbl
        logger.info("tnrm_db:select: sql=%s" % sql)

        try:
            self.open()
            self.cur.execute(sql)
            rows = self.cur.fetchall()
        except Exception as e:
            logger.error("tnrm_db:restart: ex=%s" % e)
            raise e
        finally:
            self.close()

        drows = []
        for row in rows:
            d = self.row2dict(row)
            drows.append(d)
            logger.info("tnrm_db:select: row=%s" % self.row2str(d))

            if False:
                pass
                # ep = Endpoint(ep_name, ep_vlantag, node, stp)
                # resv = Reservation(None, d["slice_urn"], d["resv_urn"], None, path, d["geni_expires"], d["start_time"]);

            manifest = reservation.manifest_rspec + d["manifest_node"] + d["manifest_link"] + reservation.close_rspec;

            current_time = datetime.datetime.utcnow()
            ic_time = unix_time_sec(current_time)
            try:
                is_datetime = datetime.datetime.strptime(d["start_time"], '%Y-%m-%d %H:%M:%S.%f')
            except Exception as e:
                try:
                    is_datetime = datetime.datetime.strptime(d["start_time"], '%Y-%m-%d %H:%M:%S')
                except Exception as ee:
                    logger.error("restart db: bad start time format: %s" % d["start_time"])
                    continue
            is_time = unix_time_sec(is_datetime)

            try:
                ie_datetime = datetime.datetime.strptime(d["geni_expires"], '%Y-%m-%d %H:%M:%S.%f')
            except Exception as e:
                try:
                    ie_datetime = datetime.datetime.strptime(d["geni_expires"], '%Y-%m-%d %H:%M:%S')
                except Exception as ee:
                    logger.error("restart db: bad start time format: %s" % d["geni_expires"])
                    continue
            ie_time = unix_time_sec(ie_datetime)

            # logger.info("start_time:   %s, %d" % (d["start_time"], is_time))
            # logger.info("end_time:     %s, %d" % (d["geni_expires"], ie_time))
            # logger.info("current_time: %s, %d" % (current_time, ic_time))

            # try:
            self.tnrm.re_allocate(
                d["slice_urn"], d["resv_urn"], manifest, is_datetime, 
                ie_datetime, d["nsi_id"], d["transvlan"], 
                d["geni_operational_status"], d["geni_allocation_status"], 
                d["geni_error"], d["geni_action"])
Ejemplo n.º 11
0
    def find_dev(self, src_if, dst_if):
        urlbase = src_if.ryu_url
        dpid = src_if.dpid

        params = {}
        params["ovsdb"] = src_if.ovsdb
        if (src_if.gtype == "ovsgre"):
            params["type"] = "gre"
        else:
            raise ManagerException("OvsManager:find_dev", 
                                   "Type (%s) is unknown, must be \"ovsgre\"." % (src_if.gtype))
        params["local_ip"] = src_if.address
        params["remote_ip"] = dst_if.address

        logger.info("search gre link. url=%s, dpid=%s, ovsdb=%s, type=%s, local=%s, remote=%s" % (urlbase, dpid, params["ovsdb"], params["type"], params["local_ip"], params["remote_ip"]));

        finds = ovsif.get_tunnel_info(urlbase, dpid, params)
        if len(finds) == 0:
            return (None, None)
        elif len(finds) == 1:
            for p in finds.keys():
                logger.info("find gre link. dev=%s, ofport=%s" % (p, finds[p]))
                return (p, finds[p])
        else:
            raise ManagerException("OvsManager:init", "Duplicate path is exist. %s" % finds)
Ejemplo n.º 12
0
    def teardown_tunnel(self, src_if, dst_if):
        sw = get_swManager(src_if)
        ofport = None
        
        try:
            # ofport = sw.get_port(src_if.ofdev)
            ofdev, ofport = src_if.get_of(self.ovs_id)
            ofport2 = sw.get_port(ofdev)
            if ofport != ofport2:
                logger.error("teardown_tunnel:ofdev=%s: mismatch ofport=%s, ofport2=%s" % (ofdev, ofport, ofport2))
                ofport = ofport2
        except Exception as e:
            logger.error("teardown_tunnel:gre port is None. ex=%s" % e)
            
        if ofport is not None:
            urlbase = src_if.ryu_url
            dpid = src_if.dpid

            logger.info("teardown gre link here. url=%s, dpid=%s, ovsdb=%s, dev=%s, type=%s, local=%s, remote=%s" %
                        (urlbase, dpid, src_if.ovsdb, ofdev, src_if.gtype, src_if.address, dst_if.address));

            params = {}
            params["ovsdb"] = src_if.ovsdb
            params["name"] = ofdev
            params["remote_ip"] = dst_if.address

            ovsif.del_tunnel(urlbase, dpid, params)

        # src_if.ofport = None
        src_if.set_of(self.ovs_id, ofdev, None)
        sw.set_free(ofdev)
Ejemplo n.º 13
0
    def add_rule(self, interface, sevlan, ofvlan):
        urlbase = interface.ryu_url
        dpid = interface.dpid
        ofdev, ofport = interface.get_of(self.ovs_id)

        params = {}
        params["dpid"] = int(dpid, 16)
        params["priority"] = OF_PRIORITY
        params["idel_timeout"] = OF_TIMEOUT
        params["hard_timeout"] = OF_TIMEOUT
        params["cookie"] = OF_COOKIE
        params["cookie_mask"] = OF_COOKIE_MASK
        params["table_id"] = OF_TABLE_ID
        params["flags"] = OF_FLAGS

        matchs = {"in_port": interface.seport, "dl_vlan": sevlan} 
        params["match"] = matchs
        # actions = [{"type":"SET_VLAN_VID", "vlan_vid": ofvlan}, {"type":"OUTPUT", "port": interface.ofport}] 
        actions = [{"type":"SET_VLAN_VID", "vlan_vid": ofvlan}, {"type":"OUTPUT", "port": ofport}] 
        params["actions"] = actions
        rc = ovsif.add_flow(urlbase, params)
        logger.info("add_rule: ret=%s" % rc)

        # matchs = {"in_port": interface.ofport, "dl_vlan": ofvlan} 
        matchs = {"in_port": ofport, "dl_vlan": ofvlan} 
        params["match"] = matchs
        actions = [{"type":"SET_VLAN_VID", "vlan_vid": sevlan}, {"type":"OUTPUT", "port": interface.seport}] 
        params["actions"] = actions
        rc = ovsif.add_flow(urlbase, params)
        logger.info("add_rule: ret=%s" % rc)
Ejemplo n.º 14
0
    def find_dev(self, src_if, dst_if):
        urlbase = src_if.ryu_url
        dpid = src_if.dpid

        params = {}
        params["ovsdb"] = src_if.ovsdb
        if (src_if.gtype == "ovsgre"):
            params["type"] = "gre"
        else:
            raise ManagerException("OvsManager:find_dev", 
                                   "Type (%s) is unknown, must be \"ovsgre\"." % (src_if.gtype))
        params["local_ip"] = src_if.address
        params["remote_ip"] = dst_if.address

        logger.info("search gre link. url=%s, dpid=%s, ovsdb=%s, type=%s, local=%s, remote=%s" % (urlbase, dpid, params["ovsdb"], params["type"], params["local_ip"], params["remote_ip"]));

        finds = ovsif.get_tunnel_info(urlbase, dpid, params)
        if len(finds) == 0:
            return (None, None)
        elif len(finds) == 1:
            for p in finds.keys():
                logger.info("find gre link. dev=%s, ofport=%s" % (p, finds[p]))
                return (p, finds[p])
        else:
            raise ManagerException("OvsManager:init", "Duplicate path is exist. %s" % finds)
Ejemplo n.º 15
0
    def allocate(self, vlan=None):
        logger.info("ovsgre:vlanManager:allocate: vlan=%s" % (vlan))
        ivlan = 0
        if vlan is not None:
            try:
                ivlan = int(vlan)
            except Exception:
                raise ManagerException(
                    "ovsgre:allocate",
                    "This vlan (%s) can not convert to integer." % vlan)

            # if (ivlan < self.vlan_min or ivlan > self.vlan_max):
            #   raise ManagerException("ovsgre:allocate", "This vlan (%s) is outof vlan range." % vlan)

        if vlan is None:
            if self.isTunnel:
                vlan = self.search()
                logger.info("VlanManagter: new allocate vlan is %s." % (vlan))
            else:
                raise ManagerException("ovsgre:allocate",
                                       "Vlan is unset for STP.")

        if self.dict_vlans.has_key(vlan):
            raise ManagerException("ovsgre:allocate",
                                   "This vlan (%s) is already used." % vlan)

        self.dict_vlans[vlan] = vlan
        return vlan
Ejemplo n.º 16
0
    def get_port(self, interface):
        urlbase = interface.ryu_url
        dpid = interface.dpid

        params = {}
        params["ovsdb"] = interface.ovsdb
        name = interface.sedev

        port = ovsif.get_port(urlbase, dpid, params, name)
        logger.info("get port. url=%s, dpid=%s, ovsdb=%s, dev=%s" % (urlbase, dpid, params["ovsdb"], name))
        return port
Ejemplo n.º 17
0
    def get_port(self, interface):
        urlbase = interface.ryu_url
        dpid = interface.dpid

        params = {}
        params["ovsdb"] = interface.ovsdb
        name = interface.sedev

        port = ovsif.get_port(urlbase, dpid, params, name)
        logger.info("get port. url=%s, dpid=%s, ovsdb=%s, dev=%s" % (urlbase, dpid, params["ovsdb"], name))
        return port
Ejemplo n.º 18
0
def get_swManager (interface):
    stp = interface.nsi_stp_id
    key = interface.ryu_url + "/" + interface.dpid
    logger.info("get_swManager: key=%s" % key)

    if dict_swManager.has_key(key):
        return dict_swManager[key]

    logger.info("get_swManager: new swManager")
    sw = swManager(interface)
    dict_swManager[key] = sw
    return sw
Ejemplo n.º 19
0
def get_swManager (interface):
    stp = interface.nsi_stp_id
    key = interface.ryu_url + "/" + interface.dpid
    logger.info("get_swManager: key=%s" % key)

    if dict_swManager.has_key(key):
        return dict_swManager[key]

    logger.info("get_swManager: new swManager")
    sw = swManager(interface)
    dict_swManager[key] = sw
    return sw
Ejemplo n.º 20
0
    def free (self):
        keep = None
        try:
            self.s_vman.free(self.s_vlan)
        except Exception as ex:
            logger.info("free: source vlan tun:%s" % (self.s_vlan))
            keep = ex

        try:
            self.d_vman.free(self.d_vlan)
        except Exception as ex:
            logger.info("destination vlan tun:%s" % (self.d_vlan))
            keep = ex

        try:
            self.t_vman.free(self.t_vlan)
        except Exception as ex:
            logger.info("tunnel vlan tun:%s" % (self.t_vlan))
            keep = ex

        if keep is not None:
            raise keep

        logger.info("freed vlan src:%s, dst:%s, tun:%s" % (self.s_vlan, self.d_vlan, self.t_vlan))
        return (self.s_vlan, self.d_vlan, self.t_vlan)
Ejemplo n.º 21
0
    def free (self):
        keep = None
        try:
            self.s_vman.free(self.s_vlan)
        except Exception as ex:
            logger.info("free: source vlan tun:%s" % (self.s_vlan))
            keep = ex

        try:
            self.d_vman.free(self.d_vlan)
        except Exception as ex:
            logger.info("destination vlan tun:%s" % (self.d_vlan))
            keep = ex

        try:
            self.t_vman.free(self.t_vlan)
        except Exception as ex:
            logger.info("tunnel vlan tun:%s" % (self.t_vlan))
            keep = ex

        if keep is not None:
            raise keep

        logger.info("freed vlan src:%s, dst:%s, tun:%s" % (self.s_vlan, self.d_vlan, self.t_vlan))
        return (self.s_vlan, self.d_vlan, self.t_vlan)
Ejemplo n.º 22
0
    def delete(self, resv):
        fmt = "DELETE FROM %s WHERE resv_urn=\"%s\""
        sql = fmt % (mySQLtbl, resv.urn)

        logger.info("tnrm_db:delete: sql=%s" % sql)

        try:
            self.open()
            self.cur.execute(sql)
            self.cur.execute("COMMIT")
        except Exception as e:
            logger.error("tnrm_db:delete: ex=%s" % e)
            raise e
        finally:
            self.close()
Ejemplo n.º 23
0
    def delete(self, resv):
        fmt = "DELETE FROM %s WHERE resv_urn=\"%s\""
        sql = fmt % (mySQLtbl, resv.urn)

        logger.info("tnrm_db:delete: sql=%s" % sql)

        try:
            self.open()
            self.cur.execute(sql)
            self.cur.execute("COMMIT")
        except Exception as e:
            logger.error("tnrm_db:delete: ex=%s" % e)
            raise e
        finally:
            self.close()
Ejemplo n.º 24
0
    def update_time(self, resv):
        fmt = "UPDATE %s SET %s=\"%s\" WHERE resv_urn=\"%s\""
        sql = fmt % (mySQLtbl, 
                     "geni_expires", resv.end_time, resv.urn)

        logger.info("tnrm_db:update: sql=%s" % sql)

        try:
            self.open()
            self.cur.execute(sql)
            self.cur.execute("COMMIT")
        except Exception as e:
            logger.error("tnrm_db:restart: ex=%s" % e)
            raise e
        finally:
            self.close()
Ejemplo n.º 25
0
    def update_time(self, resv):
        fmt = "UPDATE %s SET %s=\"%s\" WHERE resv_urn=\"%s\""
        sql = fmt % (mySQLtbl, 
                     "geni_expires", resv.end_time, resv.urn)

        logger.info("tnrm_db:update: sql=%s" % sql)

        try:
            self.open()
            self.cur.execute(sql)
            self.cur.execute("COMMIT")
        except Exception as e:
            logger.error("tnrm_db:restart: ex=%s" % e)
            raise e
        finally:
            self.close()
Ejemplo n.º 26
0
    def restart (self):
        fmt = "SELECT * from %s"
        sql = fmt % mySQLtbl
        logger.info("tnrm_db:select: sql=%s" % sql)

        try:
            self.open()
            self.cur.execute(sql)
            rows = self.cur.fetchall()
        except Exception as e:
            logger.error("tnrm_db:restart: ex=%s" % e)
            raise e
        finally:
            self.close()

        drows = []
        for row in rows:
            d = self.row2dict(row)
            drows.append(d)
            logger.info("tnrm_db:select: row=%s" % self.row2str(d))

            if False:
                pass
                # ep = Endpoint(ep_name, ep_vlantag, node, stp)
                # resv = Reservation(None, d["slice_urn"], d["resv_urn"], None, path, d["geni_expires"], d["start_time"]);

            manifest = reservation.manifest_rspec + d["manifest_node"] + d["manifest_link"] + reservation.close_rspec;

            current_time = datetime.datetime.utcnow()
            ic_time = unix_time_sec(current_time)
            is_datetime = datetime.datetime.strptime(d["start_time"], '%Y-%m-%d %H:%M:%S.%f')
            is_time = unix_time_sec(is_datetime)
            ie_datetime = datetime.datetime.strptime(d["geni_expires"], '%Y-%m-%d %H:%M:%S.%f')
            ie_time = unix_time_sec(ie_datetime)

            # logger.info("start_time:   %s, %d" % (d["start_time"], is_time))
            # logger.info("end_time:     %s, %d" % (d["geni_expires"], ie_time))
            # logger.info("current_time: %s, %d" % (current_time, ic_time))

            # try:
            self.tnrm.re_allocate(
                d["slice_urn"], d["resv_urn"], manifest, is_datetime, 
                ie_datetime, d["nsi_id"], d["transvlan"], 
                d["geni_operational_status"], d["geni_allocation_status"], 
                d["geni_error"], d["geni_action"])
Ejemplo n.º 27
0
    def del_rule(self, interface, sevlan, ofvlan):
        urlbase = interface.ryu_url
        dpid = interface.dpid
        ofdev, ofport = interface.get_of(self.ovs_id)

        params = {}
        params["dpid"] = int(dpid, 16)

        matchs = {"in_port": interface.seport, "dl_vlan": sevlan} 
        params["match"] = matchs
        rc = ovsif.del_flow(urlbase, params)
        logger.info("del_rule: ret=%s" % rc)

        # matchs = {"in_port": interface.ofport, "dl_vlan": ofvlan} 
        matchs = {"in_port": ofport, "dl_vlan": ofvlan} 
        params["match"] = matchs
        rc = ovsif.del_flow(urlbase, params)
        logger.info("del_rule: ret=%s" % rc)
Ejemplo n.º 28
0
    def del_rule(self, interface, sevlan, ofvlan):
        urlbase = interface.ryu_url
        dpid = interface.dpid
        ofdev, ofport = interface.get_of(self.ovs_id)

        params = {}
        params["dpid"] = int(dpid, 16)

        matchs = {"in_port": interface.seport, "dl_vlan": sevlan} 
        params["match"] = matchs
        rc = ovsif.del_flow(urlbase, params)
        logger.info("del_rule: ret=%s" % rc)

        # matchs = {"in_port": interface.ofport, "dl_vlan": ofvlan} 
        matchs = {"in_port": ofport, "dl_vlan": ofvlan} 
        params["match"] = matchs
        rc = ovsif.del_flow(urlbase, params)
        logger.info("del_rule: ret=%s" % rc)
Ejemplo n.º 29
0
    def allocate (self):
        try:
            self.s_vman.allocate(self.s_vlan)
        except Exception as ex:
            raise ex

        try:
            self.d_vman.allocate(self.d_vlan)
        except Exception as ex:
            self.s_vman.free(self.s_vlan)
            raise ex

        try:
            self.t_vlan = self.t_vman.allocate(self.t_vlan)
        except Exception as ex:
            self.s_vman.free(self.s_vlan)
            self.d_vman.free(self.d_vlan)
            raise ex

        logger.info("allocated vlan src:%s, dst:%s, tun:%s" % (self.s_vlan, self.d_vlan, self.t_vlan))
        return (self.s_vlan, self.d_vlan, self.t_vlan)
Ejemplo n.º 30
0
    def allocate (self):
        try:
            self.s_vman.allocate(self.s_vlan)
        except Exception as ex:
            raise ex

        try:
            self.d_vman.allocate(self.d_vlan)
        except Exception as ex:
            self.s_vman.free(self.s_vlan)
            raise ex

        try:
            self.t_vlan = self.t_vman.allocate(self.t_vlan)
        except Exception as ex:
            self.s_vman.free(self.s_vlan)
            self.d_vman.free(self.d_vlan)
            raise ex

        logger.info("allocated vlan src:%s, dst:%s, tun:%s" % (self.s_vlan, self.d_vlan, self.t_vlan))
        return (self.s_vlan, self.d_vlan, self.t_vlan)
Ejemplo n.º 31
0
    def search (self):
        for v in xrange(self.vlan_pos, self.vlan_max):
            logger.info("ovsgre:vlanManager:search: vlan=%d" % (v))
            if self.dict_vlans.has_key(str(v)):
                continue
            else:
                self.vlan_pos = v + 1
                if self.vlan_pos == self.vlan_max:
                    self.vlan_pos = self.vlan_min
                return str(v)
                
        for v in xrange(self.vlan_min, self.vlan_pos):
            logger.info("ovsgre:vlanManager:search: vlan=%d" % (v))
            if self.dict_vlans.has_key(str(v)):
                continue
            else:
                self.vlan_pos = v + 1
                if self.vlan_pos == self.vlan_max:
                    self.vlan_pos = self.vlan_min
                return str(v)

        raise ManagerException("proxy:allocate_vlan", "New vlan is not allocated.")
Ejemplo n.º 32
0
    def provision (self, resv):
        # provison:nsiv2, poa geni_start
        if resv is None or not dict_resvParameter.has_key(resv.resv_id):
            logger.info("ovsManager:provision: resv_id=%s" % (resv.resv_id))
            for key in dict_resvParameter:
                logger.info("ovsManager:provision: resvp=%s" % (key))
            raise ManagerException("OvsManager:provision", "The reservation is null.")
        
        resvp = dict_resvParameter[resv.resv_id]
        if resvp is None:
            raise ManagerException("OvsManager:privision", "The ResvParameter is null.")

        if self.isSetup:
            # already setup
            pass
        else:
            try:
                ### setup src->dst
                self.setup_tunnel(self.src_if, self.dst_if)
            except:
                raise

            try:
                ### setup dst->src
                self.setup_tunnel(self.dst_if, self.src_if)
            except:
                ### teardown tunnel by setup_tunnel(self.src_if, self.dst_if)
                self.teardown_tunnel(self.src_if, self.dst_if)
                raise
                
            self.isSetup = True

        self.dict_used[resv.resv_id] = resv.resv_id

        if self.dict_isSetRule[resv.resv_id]:
            # already set flow rule
            pass
        else:
            #### add code for set rule
            logger.info("set flow rule. %s?vlan=%s:%s?vlan=%s, gre?vlan=%s." % 
                        (resvp.s_stp, resvp.s_vlan, resvp.d_stp, resvp.d_vlan, resvp.t_vlan))
            try:
                ### add src
                self.add_rule(self.src_if, resvp.s_vlan, resvp.t_vlan)
            except Exception as ex:
                logger.error("provision: error in add rule: src_if=%s sevlan=%s, ofvlan=%s, ex=%s" % (self.src_if, resvp.s_vlan, resvp.t_vlan, ex))
                raise ex

            try:
                ### add dst
                self.add_rule(self.dst_if, resvp.d_vlan, resvp.t_vlan)
            except Exception as ex:
                logger.error("provision: error in add rule: dst_if=%s sevlan=%s, ofvlan=%s, ex=%s" % (self.dst_if, resvp.s_vlan, resvp.t_vlan, ex))
                self.del_rule(self.src_if, resvp.s_vlan, resvp.t_vlan)
                raise ex

            self.dict_isSetRule[resv.resv_id] = True

        return resv.resv_id
Ejemplo n.º 33
0
    def search (self):
        for v in xrange(self.vlan_pos, self.vlan_max):
            logger.info("ovsgre:vlanManager:search: vlan=%d" % (v))
            if self.dict_vlans.has_key(str(v)):
                continue
            else:
                self.vlan_pos = v + 1
                if self.vlan_pos == self.vlan_max:
                    self.vlan_pos = self.vlan_min
                return str(v)
                
        for v in xrange(self.vlan_min, self.vlan_pos):
            logger.info("ovsgre:vlanManager:search: vlan=%d" % (v))
            if self.dict_vlans.has_key(str(v)):
                continue
            else:
                self.vlan_pos = v + 1
                if self.vlan_pos == self.vlan_max:
                    self.vlan_pos = self.vlan_min
                return str(v)

        raise ManagerException("proxy:allocate_vlan", "New vlan is not allocated.")
Ejemplo n.º 34
0
    def __init__ (self, ovs_id, resv):
        self.ovs_id = ovs_id;
        self.resv = resv;
        self.s_stp = self.resv.path.sep.stp
        self.d_stp = self.resv.path.dep.stp
        self.t_stp = getKey(self.s_stp, self.d_stp)

        #self.s_vlan = self.resv.path.sep.vlantag
        #self.d_vlan = self.resv.path.dep.vlantag
        self.s_vlan = self.resv.src_vlan
        self.d_vlan = self.resv.dst_vlan
        self.t_vlan = self.resv.trans_vlan
        self.s_if = self.resv.src_if
        self.d_if = self.resv.dst_if

        self.s_vman = None
        self.d_vman = None
        self.t_vman = None
        (self.s_vman, self.d_vman, self.t_vman) = get_vlanManager(self.s_stp, self.d_stp)
        
        self.s_ofdev, self.s_ofport = self.s_if.get_of(self.ovs_id)
        self.d_ofdev, self.d_ofport = self.d_if.get_of(self.ovs_id)
        logger.info("ovsgre:ResvParameter:init: %s" % self)
Ejemplo n.º 35
0
    def __init__ (self, ovs_id, resv):
        self.ovs_id = ovs_id;
        self.resv = resv;
        self.s_stp = self.resv.path.sep.stp
        self.d_stp = self.resv.path.dep.stp
        self.t_stp = getKey(self.s_stp, self.d_stp)

        #self.s_vlan = self.resv.path.sep.vlantag
        #self.d_vlan = self.resv.path.dep.vlantag
        self.s_vlan = self.resv.src_vlan
        self.d_vlan = self.resv.dst_vlan
        self.t_vlan = self.resv.trans_vlan
        self.s_if = self.resv.src_if
        self.d_if = self.resv.dst_if

        self.s_vman = None
        self.d_vman = None
        self.t_vman = None
        (self.s_vman, self.d_vman, self.t_vman) = get_vlanManager(self.s_stp, self.d_stp)
        
        self.s_ofdev, self.s_ofport = self.s_if.get_of(self.ovs_id)
        self.d_ofdev, self.d_ofport = self.d_if.get_of(self.ovs_id)
        logger.info("ovsgre:ResvParameter:init: %s" % self)
Ejemplo n.º 36
0
    def allocate (self, vlan = None):
        logger.info("ovsgre:vlanManager:allocate: vlan=%s" % (vlan))
        ivlan = 0
        if vlan is not None:
            try:
                ivlan = int(vlan)
            except Exception:
                raise ManagerException("ovsgre:allocate", "This vlan (%s) can not convert to integer." % vlan)

            # if (ivlan < self.vlan_min or ivlan > self.vlan_max):
            #   raise ManagerException("ovsgre:allocate", "This vlan (%s) is outof vlan range." % vlan)

        if vlan is None:
            if self.isTunnel:
                vlan = self.search()
                logger.info("VlanManagter: new allocate vlan is %s." % (vlan))
            else:
                raise ManagerException("ovsgre:allocate", "Vlan is unset for STP.")

        if self.dict_vlans.has_key(vlan):
            raise ManagerException("ovsgre:allocate", "This vlan (%s) is already used." % vlan)

        self.dict_vlans[vlan] = vlan
        return vlan
Ejemplo n.º 37
0
    def reserve (self, resv):
        # logger.info("ovsgre:OvsManager:reserve: enter")
        # This just only reserve vlans for source/destination/tunnel interfaces
        if resv is None:
            raise ManagerException("OvsManager:reserve", "The reservation parameter is null.")
        
        self.check_stp(resv)

        resv_id = uuid.uuid4()
        logger.info("ovsManager:reserve: new resv_id=%s." % resv_id)
        
        if dict_resvParameter.has_key(resv_id):
            logger.error("Never here. Reservation id is duplicated(%s)." % (resv_id))
            raise ManagerException("OvsManager:reserve", "The reservation id is already used.")

        resvp = resvParameter(self.ovs_id, resv)

        (s_vlan, d_vlan, t_vlan) = resvp.allocate()
        resv.trans_vlan = t_vlan

        dict_resvParameter[resv_id] = resvp
        self.dict_isSetRule[resv_id] = False
        logger.info("ovsManager:reserve: done. resv_id=%s" % (resv_id))
        return resv_id
Ejemplo n.º 38
0
    def setup_tunnel(self, src_if, dst_if):
        logger.info("setup src_if=%s" % src_if)
        logger.info("setup dst_if=%s" % dst_if)

        sw = get_swManager(src_if)
        ofport = None

        try:
            # ofport = sw.get_port(src_if.ofdev)
            ofdev, ofport = src_if.get_of(self.ovs_id)
            ofport2 = sw.get_port(ofdev)
            if ofport != ofport2:
                logger.error(
                    "setup_tunnel:ofdev=%s: mismatch ofport=%s, ofport2=%s" %
                    (ofdev, ofport, ofport2))
                ofport = ofport2
        except Exception as ex:
            logger.info("setup_tunnel:gre port is None")

        if ofport is None:
            urlbase = src_if.ryu_url
            dpid = src_if.dpid

            logger.info(
                "setup gre link here. url=%s, dpid=%s, ovsdb=%s, dev=%s, type=%s, local=%s, remote=%s"
                % (urlbase, dpid, src_if.ovsdb, ofdev, src_if.gtype,
                   src_if.address, dst_if.address))

            params = {}
            params["ovsdb"] = src_if.ovsdb
            params["name"] = ofdev
            if (src_if.gtype == "ovsgre"):
                params["type"] = "gre"
            else:
                raise ManagerException(
                    "OvsManager:setup_tunnel",
                    "Type (%s) is unknown, must be \"ovsgre\"." %
                    (src_if.gtype))
            params["local_ip"] = src_if.address
            params["remote_ip"] = dst_if.address

            ofport = ovsif.add_tunnel(urlbase, dpid, params)

        # src_if.ofport = ofport
        src_if.set_of(self.ovs_id, ofdev, ofport)
        sw.set_used(ofdev, ofport)
Ejemplo n.º 39
0
def get_ovsManager (src_if, dst_if):
    key = get_ovsManagerKey (src_if, dst_if)
    logger.info("get_ovsManager: %s" % key)

    if dict_ovsManager.has_key(key):
        logger.info("get_ovsManager: %s is already exist." % key)
        return dict_ovsManager[key]

    key = get_ovsManagerKey (dst_if, src_if)
    if dict_ovsManager.has_key(key):
        logger.info("get_ovsManager: %s is already exist." % key)
        return dict_ovsManager[key]

    key = get_ovsManagerKey (src_if, dst_if)
    ovsManager = OvsManager(src_if, dst_if)
    logger.info("get_ovsManager: %s is created now." % key)
    dict_ovsManager[key] = ovsManager
    return dict_ovsManager[key]
Ejemplo n.º 40
0
def get_ovsManager (src_if, dst_if):
    key = get_ovsManagerKey (src_if, dst_if)
    logger.info("get_ovsManager: %s" % key)

    if dict_ovsManager.has_key(key):
        logger.info("get_ovsManager: %s is already exist." % key)
        return dict_ovsManager[key]

    key = get_ovsManagerKey (dst_if, src_if)
    if dict_ovsManager.has_key(key):
        logger.info("get_ovsManager: %s is already exist." % key)
        return dict_ovsManager[key]

    key = get_ovsManagerKey (src_if, dst_if)
    ovsManager = OvsManager(src_if, dst_if)
    logger.info("get_ovsManager: %s is created now." % key)
    dict_ovsManager[key] = ovsManager
    return dict_ovsManager[key]
Ejemplo n.º 41
0
    def re_provision (self, resv):
        # provison:nsiv2, poa geni_start
        logger.info("ovsManager:re_provision has_key(%s)=%s" %
                    (resv.resv_id, dict_resvParameter.has_key(resv.resv_id)))
        if resv is None or not dict_resvParameter.has_key(resv.resv_id):
            logger.info("ovsManager:re_provision: resv_id=%s" % (resv.resv_id))
            for key in dict_resvParameter:
                logger.info("ovsManager:re_provision: resvp=%s" % (key))
            raise ManagerException("OvsManager:re_provision", "The reservation is null.")

        resvp = dict_resvParameter[resv.resv_id]
        if resvp is None:
            raise ManagerException("OvsManager:re_privision", "The ResvParameter is null.")

        self.isSetup = True
        self.dict_used[resv.resv_id] = resv.resv_id
        self.dict_isSetRule[resv.resv_id] = True

        logger.info("ovsManager:re_provision: done. resv_id=%s" % (resv.resv_id))
        return resv.resv_id
Ejemplo n.º 42
0
    def re_provision (self, resv):
        # provison:nsiv2, poa geni_start
        logger.info("ovsManager:re_provision has_key(%s)=%s" %
                    (resv.resv_id, dict_resvParameter.has_key(resv.resv_id)))
        if resv is None or not dict_resvParameter.has_key(resv.resv_id):
            logger.info("ovsManager:re_provision: resv_id=%s" % (resv.resv_id))
            for key in dict_resvParameter:
                logger.info("ovsManager:re_provision: resvp=%s" % (key))
            raise ManagerException("OvsManager:re_provision", "The reservation is null.")

        resvp = dict_resvParameter[resv.resv_id]
        if resvp is None:
            raise ManagerException("OvsManager:re_privision", "The ResvParameter is null.")

        self.isSetup = True
        self.dict_used[resv.resv_id] = resv.resv_id
        self.dict_isSetRule[resv.resv_id] = True

        logger.info("ovsManager:re_provision: done. resv_id=%s" % (resv.resv_id))
        return resv.resv_id
Ejemplo n.º 43
0
    def setup_tunnel(self, src_if, dst_if):
        logger.info("setup src_if=%s" % src_if)
        logger.info("setup dst_if=%s" % dst_if)

        sw = get_swManager(src_if)
        ofport = None

        try:
            # ofport = sw.get_port(src_if.ofdev)
            ofdev, ofport = src_if.get_of(self.ovs_id)
            ofport2 = sw.get_port(ofdev)
            if ofport != ofport2:
                logger.error("setup_tunnel:ofdev=%s: mismatch ofport=%s, ofport2=%s" % (ofdev, ofport, ofport2))
                ofport = ofport2
        except Exception as ex:
            logger.info("setup_tunnel:gre port is None")
            
        if ofport is None:
            urlbase = src_if.ryu_url
            dpid = src_if.dpid

            logger.info("setup gre link here. url=%s, dpid=%s, ovsdb=%s, dev=%s, type=%s, local=%s, remote=%s" %
                        (urlbase, dpid, src_if.ovsdb, ofdev, src_if.gtype, src_if.address, dst_if.address));

            params = {}
            params["ovsdb"] = src_if.ovsdb
            params["name"] = ofdev
            if (src_if.gtype == "ovsgre"):
                params["type"] = "gre"
            else:
                raise ManagerException("OvsManager:setup_tunnel", 
                                       "Type (%s) is unknown, must be \"ovsgre\"." % (src_if.gtype))
            params["local_ip"] = src_if.address
            params["remote_ip"] = dst_if.address

            ofport = ovsif.add_tunnel(urlbase, dpid, params)

        # src_if.ofport = ofport
        src_if.set_of(self.ovs_id, ofdev, ofport)
        sw.set_used(ofdev, ofport)
Ejemplo n.º 44
0
    def allocate_dev(self, dst_if):
        lkey = self.key + ":" + dst_if.ryu_url + "/" + dst_if.dpid
        logger.info("swManager:allocate_dev: lkey=%s." % lkey)

        if self.dict_path.has_key(lkey):
            dev = self.dict_key[lkey]
            logger.info("swManager:allocate_dev: old device is %s." % dev)
            # return self.dict_dev[lkey]
            return dev

        for v in xrange(dev_min, dev_max):
            dev = "%s%03d" % (ovsif.PREFIX_DEV, v)
            if dev in self.dict_dev:
                continue
            else:
                logger.info("swManager:allocate_dev: new device is %s." % dev)
                self.dict_path[lkey] = dev
                self.set_used(dev, None)
                return dev

        raise ManagerException("OvsManager:swManager:allocate_dev", 
                               "There is no resources for device in openvSwitch.")
Ejemplo n.º 45
0
    def allocate_dev(self, dst_if):
        lkey = self.key + ":" + dst_if.ryu_url + "/" + dst_if.dpid
        logger.info("swManager:allocate_dev: lkey=%s." % lkey)

        if self.dict_path.has_key(lkey):
            dev = self.dict_key[lkey]
            logger.info("swManager:allocate_dev: old device is %s." % dev)
            # return self.dict_dev[lkey]
            return dev

        for v in xrange(dev_min, dev_max):
            dev = "%s%03d" % (ovsif.PREFIX_DEV, v)
            if dev in self.dict_dev:
                continue
            else:
                logger.info("swManager:allocate_dev: new device is %s." % dev)
                self.dict_path[lkey] = dev
                self.set_used(dev, None)
                return dev

        raise ManagerException("OvsManager:swManager:allocate_dev", 
                               "There is no resources for device in openvSwitch.")
Ejemplo n.º 46
0
    def release (self, resv):
        e = None
        ### release:nsiv2, poa geni_stop
        if resv is None or not dict_resvParameter.has_key(resv.resv_id):
            raise ManagerException("OvsManager:release", "The reservation is null.")
        
        resvp = dict_resvParameter[resv.resv_id]
        if resvp is None:
            raise ManagerException("OvsManager:release", "The ResvParameter is null.")

        if self.dict_isSetRule.has_key(resv.resv_id):
            if self.dict_isSetRule[resv.resv_id]:
                logger.info("delete flow rule here. %s?vlan=%s:%s?vlan=%s, gre?vlan=%s." % 
                            (resvp.s_stp, resvp.s_vlan, resvp.d_stp, resvp.d_vlan, resvp.t_vlan))

                try:
                    ### delete src
                    self.del_rule(self.src_if, resvp.s_vlan, resvp.t_vlan)
                except Exception as ex:
                    e = ex
                    logger.error("release: error in delete rule: src_if=%s sevlan=%s, ofvlan=%s, ex=%s" % (self.src_if, resvp.s_vlan, resvp.t_vlan, ex))

                try:
                    ### delete dst
                    self.del_rule(self.dst_if, resvp.d_vlan, resvp.t_vlan)
                except Exception as ex:
                    e = ex
                    logger.error("release: error in delete rule: dst_if=%s sevlan=%s, ofvlan=%s, ex=%s" % (self.dst_if, resvp.d_vlan, resvp.t_vlan, ex))

                self.dict_isSetRule[resv.resv_id] = False
                
            else:
                # already delete flow rule
                pass

        else:
            logger.info("OvsManager:release: This reservation (%s) does not have isSetRule." %
                        (resv.resv_id))

        if self.dict_used.has_key(resv.resv_id):
            del self.dict_used[resv.resv_id]
        else:
            logger.info("OvsManager:release: This reservation (%s) does not used this gre link." %
                        (resv.resv_id))

        if self.isSetup:
            if len(self.dict_used) > 0:
                logger.info("This gre link is shared other reservtion. Do not teardown now.")
            else:
                e = None
                ### teardown src->dst
                try:
                    self.teardown_tunnel(self.src_if, self.dst_if)
                except Exception as ex:
                    e = ex
                    logger.error("release: error in teardown #1: src_if=%s, dst_if=%s ex=%s" % (self.src_if, self.dst_if, ex))

                ### teardown dst->src
                try:
                    self.teardown_tunnel(self.dst_if, self.src_if)
                except Exception as ex:
                    e = ex
                    logger.error("release: error in teardown #2: src_if=%s, dst_if=%s ex=%s" % (self.dst_if, self.src_if, ex))

                self.isSetup = False
                self.isSetup = False

        else:
            logger.info("This link is already teardown.");
            
        if e is not None:
            raise e

        return resv.resv_id
Ejemplo n.º 47
0
    def insert (self, resv):
        fmt = "INSERT INTO %s VALUES ("

        for i in range(0, mySQLtables_items):
            if i == (mySQLtables_items - 1):
                fmt += "\'%s\')"
            else:
                fmt += "\'%s\', "

        logger.info("tnrm_db:insert: fmt=%s" % fmt)

        trans_vlan = "0"
        if resv.trans_vlan is not None:
            trans_vlan = resv.trans_vlan

        error = resv.error
        if error is not None:
            error = error.replace("\"", "")
            error = error.replace("\'", "")

        sql = (fmt % (
                mySQLtbl,
                #1: slice_urn
                resv.slice_urn,
                #2: resv_urn
                resv.urn,
                #3: nsi_id
                resv.resv_id,
                #4: srcstp
                resv.src_if.felix_stp_id,
                #5: dststp
                resv.dst_if.felix_stp_id,
                #6: srcvlan
                int(resv.src_vlan),
                #7: dstvlan
                int(resv.dst_vlan),
                #8: transvlan
                int (trans_vlan),
                #9: geni_operational_status
                resv.ostatus,
                #10: geni_expires
                resv.end_time,
                #11: geni_allocation_status
                resv.astatus,
                #12: geni_sliver_urn
                resv.gid,
                #13: geni_urn
                resv.slice_urn,
                #14: geni_error
                error,
                #15: geni_action
                resv.action,
                #16: start_time
                resv.start_time,
                #16: manifest_node
                resv.manifest_node,
                #17: manifest_link
                resv.manifest_link 
                ))

        logger.info("tnrm_db:insert: sql=%s" % sql)
        try:
            self.open()
            self.cur.execute(sql)
            self.cur.execute("COMMIT")
        except Exception as e:
            logger.error("tnrm_db:insert: ex=%s" % e)
        finally:
            self.close()
Ejemplo n.º 48
0
    def insert (self, resv):
        fmt = "INSERT INTO %s VALUES ("

        for i in range(0, mySQLtables_items):
            if i == (mySQLtables_items - 1):
                fmt += "\'%s\')"
            else:
                fmt += "\'%s\', "

        logger.info("tnrm_db:insert: fmt=%s" % fmt)

        trans_vlan = "0"
        if resv.trans_vlan is not None:
            trans_vlan = resv.trans_vlan

        sql = (fmt % (
                mySQLtbl,
                #1: slice_urn
                resv.slice_urn,
                #2: resv_urn
                resv.urn,
                #3: nsi_id
                resv.resv_id,
                #4: srcstp
                resv.src_if.felix_stp_id,
                #5: dststp
                resv.dst_if.felix_stp_id,
                #6: srcvlan
                int(resv.src_vlan),
                #7: dstvlan
                int(resv.dst_vlan),
                #8: transvlan
                int (trans_vlan),
                #9: geni_operational_status
                resv.ostatus,
                #10: geni_expires
                resv.end_time,
                #11: geni_allocation_status
                resv.astatus,
                #12: geni_sliver_urn
                resv.gid,
                #13: geni_urn
                resv.slice_urn,
                #14: geni_error
                resv.error,
                #15: geni_action
                resv.action,
                #16: start_time
                resv.start_time,
                #16: manifest_node
                resv.manifest_node,
                #17: manifest_link
                resv.manifest_link 
                ))

        logger.info("tnrm_db:insert: sql=%s" % sql)
        try:
            self.open()
            self.cur.execute(sql)
            self.cur.execute("COMMIT")
        except Exception as e:
            logger.error("tnrm_db:insert: ex=%s" % e)
        finally:
            self.close()
Ejemplo n.º 49
0
def unix_time_sec(dt):
    # print type(dt)
    # print type(epoch)
    delta = dt - epoch
    logger.info("timezone=%s" % (dt.tzinfo))
    return int(delta.total_seconds())
Ejemplo n.º 50
0
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# import amsoil.core.log
# logger = amsoil.core.log.getLogger('TN-RM:ovsgre')
# import log
# logger = log.getLogger('tnrm:ovsgre')
from tn_rm_delegate import logger
logger.info("start proxy from TNRM to OVSGRE.")

from tn_rm_exceptions import ManagerException, ParamException
from datetime import datetime, timedelta, time
from reservation import Request, Reservation, Manager, Endpoint, Path
from proxy_interface import Proxy
import ovsif as ovsif

import uuid

dict_ovsManager = {}
dict_resvParameter = {}
dict_vlanManager = {}
dict_swManager = {}
tvlan_min = 1500
tvlan_max = 3000
Ejemplo n.º 51
0
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# import eisoil.core.log
# logger = eisoil.core.log.getLogger('TN-RM:ovsgre')
# import log
# logger = log.getLogger('tnrm:ovsgre')
from tn_rm_delegate import logger
logger.info("start proxy from TNRM to OVSGRE.")

from tn_rm_exceptions import ManagerException, ParamException
from datetime import datetime, timedelta, time
from reservation import Request, Reservation, Manager, Endpoint, Path
from proxy_interface import Proxy
import ovsif as ovsif

import uuid

dict_ovsManager = {}
dict_resvParameter = {}
dict_vlanManager = {}
dict_swManager = {}
tvlan_min = 1500
tvlan_max = 3000
Ejemplo n.º 52
0
 def set_free(self, dev):
     del self.dict_dev[dev]
     logger.info("swManager: set_free: dev=%s." % dev)
Ejemplo n.º 53
0
 def set_used(self, dev, ofport):
     self.dict_dev[dev] = ofport
     logger.info("swManager: set_used: dev=%s, ofport=%s." % (dev, ofport))
Ejemplo n.º 54
0
def unix_time_sec(dt):
    # print type(dt)
    # print type(epoch)
    delta = dt - epoch
    logger.info("timezone=%s" % (dt.tzinfo))
    return int(delta.total_seconds())
Ejemplo n.º 55
0
 def set_free(self, dev):
     del self.dict_dev[dev]
     logger.info("swManager: set_free: dev=%s." % dev)
Ejemplo n.º 56
0
 def set_used(self, dev, ofport):
     self.dict_dev[dev] = ofport
     logger.info("swManager: set_used: dev=%s, ofport=%s." % (dev, ofport))
Ejemplo n.º 57
0
    def release (self, resv):
        e = None
        ### release:nsiv2, poa geni_stop
        if resv is None or not dict_resvParameter.has_key(resv.resv_id):
            raise ManagerException("OvsManager:release", "The reservation is null.")
        
        resvp = dict_resvParameter[resv.resv_id]
        if resvp is None:
            raise ManagerException("OvsManager:release", "The ResvParameter is null.")

        if self.dict_isSetRule.has_key(resv.resv_id):
            if self.dict_isSetRule[resv.resv_id]:
                logger.info("delete flow rule here. %s?vlan=%s:%s?vlan=%s, gre?vlan=%s." % 
                            (resvp.s_stp, resvp.s_vlan, resvp.d_stp, resvp.d_vlan, resvp.t_vlan))

                try:
                    ### delete src
                    self.del_rule(self.src_if, resvp.s_vlan, resvp.t_vlan)
                except Exception as ex:
                    e = ex
                    logger.error("release: error in delete rule: src_if=%s sevlan=%s, ofvlan=%s, ex=%s" % (self.src_if, resvp.s_vlan, resvp.t_vlan, ex))

                try:
                    ### delete dst
                    self.del_rule(self.dst_if, resvp.d_vlan, resvp.t_vlan)
                except Exception as ex:
                    e = ex
                    logger.error("release: error in delete rule: dst_if=%s sevlan=%s, ofvlan=%s, ex=%s" % (self.dst_if, resvp.d_vlan, resvp.t_vlan, ex))

                self.dict_isSetRule[resv.resv_id] = False
                
            else:
                # already delete flow rule
                pass

        else:
            logger.info("OvsManager:release: This reservation (%s) does not have isSetRule." %
                        (resv.resv_id))

        if self.dict_used.has_key(resv.resv_id):
            del self.dict_used[resv.resv_id]
        else:
            logger.info("OvsManager:release: This reservation (%s) does not used this gre link." %
                        (resv.resv_id))

        if self.isSetup:
            if len(self.dict_used) > 0:
                logger.info("This gre link is shared other reservtion. Do not teardown now.")
            else:
                e = None
                ### teardown src->dst
                try:
                    self.teardown_tunnel(self.src_if, self.dst_if)
                except Exception as ex:
                    e = ex
                    logger.error("release: error in teardown: src_if=%s, dst_if=%s ex=%s" % (self.src_if, self.dst_if, ex))

                ### teardown dst->src
                try:
                    self.teardown_tunnel(self.dst_if, self.src_if)
                except Exception as ex:
                    e = ex
                    logger.error("release: error in teardown: src_if=%s, dst_if=%s ex=%s" % (self.dst_if, self.src_if, ex))

                self.isSetup = False
                self.isSetup = False

        else:
            logger.info("This link is already teardown.");
            
        if e is not None:
            raise e

        return resv.resv_id
Ejemplo n.º 58
0
 def __init__ (self, src_if):
     self.src_if = src_if
     self.dict_dev = {}
     self.dict_path = {}
     self.key = self.src_if.ryu_url + "/" + self.src_if.dpid
     logger.info("swManager: init: key=%s." % self.key)
Ejemplo n.º 59
0
 def __init__ (self, src_if):
     self.src_if = src_if
     self.dict_dev = {}
     self.dict_path = {}
     self.key = self.src_if.ryu_url + "/" + self.src_if.dpid
     logger.info("swManager: init: key=%s." % self.key)