本文整理汇总了Python中empower.main.RUNTIME类的典型用法代码示例。如果您正苦于以下问题:Python RUNTIME类的具体用法?Python RUNTIME怎么用?Python RUNTIME使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RUNTIME类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
def delete(self, *args, **kwargs):
""" Delete a tenant request.
Args:
tenant_id: network name of a tenant
Example URLs:
PUT /api/v1/pending/52313ecb-9d00-4b7d-b873-b55d3d9ada26
"""
try:
if len(args) == 0:
pendings = RUNTIME.load_pending_tenants()
for pending in pendings:
RUNTIME.reject_tenant(pending.tenant_id)
else:
tenant_id = UUID(args[0])
RUNTIME.reject_tenant(tenant_id)
except ValueError as ex:
self.send_error(400, message=ex)
except KeyError as ex:
self.send_error(404, message=ex)
self.set_status(204, None)
示例2: _on_disconnect
def _on_disconnect(self):
""" Handle WTP disconnection """
if not self.wtp:
return
LOG.info("WTP disconnected: %s", self.wtp.addr)
# remove hosted lvaps
for addr in list(RUNTIME.lvaps.keys()):
lvap = RUNTIME.lvaps[addr]
dl_wtps = [block.radio for block in lvap.downlink.keys()]
ul_wtps = [block.radio for block in lvap.uplink.keys()]
# in case the downlink went down, the remove also the uplinks
if self.wtp in dl_wtps:
RUNTIME.remove_lvap(lvap.addr)
elif self.wtp in ul_wtps:
LOG.info("Deleting LVAP (UL): %s", lvap.addr)
lvap.clear_uplink()
# remove hosted vaps
for tenant_id in RUNTIME.tenants.keys():
for vap_id in list(RUNTIME.tenants[tenant_id].vaps.keys()):
vap = RUNTIME.tenants[tenant_id].vaps[vap_id]
if vap.wtp == self.wtp:
LOG.info("Deleting VAP: %s", vap.net_bssid)
del RUNTIME.tenants[vap.tenant_id].vaps[vap.net_bssid]
# reset state
self.wtp.last_seen = 0
self.wtp.connection = None
self.wtp.ports = {}
self.wtp.supports = ResourcePool()
self.wtp = None
示例3: _handle_auth_request
def _handle_auth_request(self, wtp, request):
"""Handle an incoming AUTH_REQUEST message.
Args:
request, a AUTH_REQUEST message
Returns:
None
"""
if not wtp.connection:
LOG.info("Auth request from disconnected WTP %s", wtp.addr)
return
sta = EtherAddress(request.sta)
bssid = EtherAddress(request.bssid)
if sta not in RUNTIME.lvaps:
LOG.info("Auth request from unknown LVAP %s", sta)
return
lvap = RUNTIME.lvaps[sta]
if not RUNTIME.is_allowed(sta):
LOG.info("Auth request from %s ignored (white list)", sta)
return
if RUNTIME.is_denied(sta):
LOG.info("Auth request from %s ignored (black list)", sta)
return
lvap_bssid = None
# the request bssid is the lvap's unique bssid
if lvap.net_bssid == bssid:
lvap_bssid = lvap.net_bssid
# else if is a shared bssid
else:
shared_tenants = [x for x in RUNTIME.tenants.values()
if x.bssid_type == T_TYPE_SHARED]
wtp = RUNTIME.wtps[wtp.addr]
# look for bssid in shared tenants
for tenant in shared_tenants:
if bssid in tenant.vaps and tenant.vaps[bssid].wtp == wtp:
lvap_bssid = bssid
break
# invalid bssid, ignore request
if not lvap_bssid:
return
# this will trigger an add lvap message to update the bssid
lvap.lvap_bssid = lvap_bssid
LOG.info("Auth request from %s for BSSID %s, replying", sta, bssid)
self.send_auth_response(lvap)
示例4: get
def get(self, *args, **kwargs):
""" Lists all the tenants requested. Returns 404 if the requested
tenant does not exists.
Args:
tenant_id: network name of a tenant
Example URLs:
GET /api/v1/pending
GET /api/v1/pending/TenantName
"""
try:
if len(args) > 1:
raise ValueError("Invalid url")
if len(args) == 0:
user = self.get_argument("user", default=None)
if user:
pendings = RUNTIME.load_pending_tenants(user)
else:
pendings = RUNTIME.load_pending_tenants()
self.write_as_json(pendings)
else:
tenant_id = UUID(args[0])
pending = RUNTIME.load_pending_tenant(tenant_id)
self.write_as_json(pending)
except ValueError as ex:
self.send_error(400, message=ex)
except KeyError as ex:
self.send_error(404, message=ex)
示例5: _handle_assoc_request
def _handle_assoc_request(self, request):
"""Handle an incoming ASSOC_REQUEST message.
Args:
request, a ASSOC_REQUEST message
Returns:
None
"""
wtp_addr = EtherAddress(request.wtp)
try:
wtp = RUNTIME.wtps[wtp_addr]
except KeyError:
LOG.info("Assoc request from unknown WTP %s", wtp_addr)
return
if not wtp.connection:
LOG.info("Assoc request from disconnected WTP %s", wtp_addr)
return
sta = EtherAddress(request.sta)
if sta not in RUNTIME.lvaps:
LOG.info("Assoc request from unknown LVAP %s", sta)
return
lvap = RUNTIME.lvaps[sta]
if not RUNTIME.is_allowed(sta):
LOG.info("Assoc request from %s ignored (white list)", sta)
return
if RUNTIME.is_denied(sta):
LOG.info("Assoc request from %s ignored (black list)", sta)
return
ssid = SSID(request.ssid.decode('UTF-8'))
matches = [x for x in RUNTIME.tenants.values()
if SSID(x.tenant_name) == ssid]
if not matches:
LOG.info("Assoc request to unknown SSID: %s ", request.ssid)
return
# this will trigger an add lvap message to update the ssid
lvap.ssid = ssid
# this will trigger an add lvap message to update the assoc id
lvap.assoc_id = self.server.assoc_id
LOG.info("Assoc request sta %s assoc id %u ssid %s, sending response",
lvap.addr,
lvap.assoc_id,
lvap.ssid)
self.send_assoc_response(lvap)
示例6: put
def put(self, *args, **kwargs):
""" Update an account.
Args:
username: the username
Request:
version: protocol version (1.0)
username: username
password: password
role: tole
name: name
surname: surname
email: email
Example URLs:
PUT /api/v1/accounts/test
{
"version" : 1.0,
"username" : "foo",
"password" : "foo",
"role" : "user",
"name" : "foo",
"surname" : "foo",
"email" : "[email protected]"
}
"""
try:
if len(args) != 1:
raise ValueError("Invalid url")
request = tornado.escape.json_decode(self.request.body)
if "version" not in request:
raise ValueError("missing version element")
del request['version']
RUNTIME.update_account(args[0], request)
except ValueError as ex:
self.send_error(400, message=ex)
except AttributeError as ex:
self.send_error(400, message=ex)
except KeyError as ex:
self.send_error(404, message=ex)
except KeyError as ex:
self.send_error(404, message=ex)
self.set_status(204, None)
示例7: post
def post(self, *args, **kwargs):
""" Create a new tenant.
Args:
None
Request:
version: protocol version (1.0)
owner: the username of the requester
tenant_id: the network name
desc: a description for the new tenant
Example URLs:
POST /api/v1/tenants
"""
try:
if len(args) > 1:
raise ValueError("Invalid url")
request = tornado.escape.json_decode(self.request.body)
if "version" not in request:
raise ValueError("missing version element")
if "owner" not in request:
raise ValueError("missing owner element")
if "desc" not in request:
raise ValueError("missing desc element")
if "tenant_name" not in request:
raise ValueError("missing tenant_name element")
if len(args) == 1:
tenant_id = UUID(args[0])
else:
tenant_id = None
tenant_id = \
RUNTIME.add_tenant(request['owner'],
request['desc'],
request['tenant_name'],
tenant_id)
self.set_header("Location", "/api/v1/tenants/%s" % tenant_id)
except ValueError as ex:
self.send_error(400, message=ex)
except KeyError as ex:
self.send_error(404, message=ex)
self.set_status(201, None)
示例8: _on_disconnect
def _on_disconnect(self):
"""Handle VBSP disconnection."""
if not self.vbs:
return
LOG.info("VBS disconnected: %s", self.vbs.addr)
# remove hosted ues
for addr in list(RUNTIME.ues.keys()):
ue = RUNTIME.ues[addr]
if ue.vbs == self.vbs:
RUNTIME.remove_ue(ue.addr)
# reset state
self.vbs.last_seen = 0
self.vbs.connection = None
self.vbs.ues = {}
self.vbs.period = 0
示例9: post
def post(self):
username = self.get_argument("username", "")
password = self.get_argument("password", "")
if RUNTIME.check_permission(username, password):
self.set_secure_cookie("user", username)
self.redirect(self.get_argument("next", "/"))
else:
error_msg = "Login incorrect."
self.redirect("/auth/login/" +
"?error=" +
tornado.escape.url_escape(error_msg))
示例10: _handle_auth_request
def _handle_auth_request(self, request):
"""Handle an incoming AUTH_REQUEST message.
Args:
request, a AUTH_REQUEST message
Returns:
None
"""
wtp_addr = EtherAddress(request.wtp)
try:
wtp = RUNTIME.wtps[wtp_addr]
except KeyError:
LOG.info("Auth request from unknown WTP %s", wtp_addr)
return
if not wtp.connection:
LOG.info("Auth request from disconnected WTP %s", wtp_addr)
return
sta = EtherAddress(request.sta)
if sta not in RUNTIME.lvaps:
LOG.info("Auth request from unknown LVAP %s", sta)
return
lvap = RUNTIME.lvaps[sta]
if not RUNTIME.is_allowed(sta):
LOG.info("Auth request from %s ignored (white list)", sta)
return
if RUNTIME.is_denied(sta):
LOG.info("Auth request from %s ignored (black list)", sta)
return
LOG.info("Auth request from %s, sending auth response", sta)
self.send_auth_response(lvap)
示例11: _handle_probe_request
def _handle_probe_request(self, request):
"""Handle an incoming PROBE_REQUEST message.
Args:
request, a PROBE_REQUEST message
Returns:
None
"""
wtp_addr = EtherAddress(request.wtp)
try:
wtp = RUNTIME.wtps[wtp_addr]
except KeyError:
LOG.info("Probe request from unknown WTP (%s)", wtp_addr)
return
if not wtp.connection:
LOG.info("Probe request from disconnected WTP %s", wtp_addr)
return
sta = EtherAddress(request.sta)
if sta in RUNTIME.lvaps:
return
if not RUNTIME.is_allowed(sta):
return
if RUNTIME.is_denied(sta):
return
ssid = SSID(request.ssid)
if request.ssid == b'':
LOG.info("Probe request from %s ssid %s", sta, "Broadcast")
else:
LOG.info("Probe request from %s ssid %s", sta, ssid)
# generate list of available SSIDs
ssids = set()
for tenant in RUNTIME.tenants.values():
if tenant.bssid_type == T_TYPE_SHARED:
continue
for wtp_in_tenant in tenant.wtps.values():
if wtp_addr == wtp_in_tenant.addr:
ssids.add(tenant.tenant_name)
if not ssids:
LOG.info("No SSIDs available at this WTP")
return
# spawn new LVAP
LOG.info("Spawning new LVAP %s on %s", sta, wtp.addr)
net_bssid = generate_bssid(BASE_MAC, sta)
lvap = LVAP(sta, net_bssid, net_bssid)
lvap._ssids = ssids
RUNTIME.lvaps[sta] = lvap
# TODO: This should be built starting from the probe request
lvap.supports.add(ResourceBlock(lvap, sta, 1, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 2, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 3, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 4, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 5, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 6, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 7, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 8, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 9, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 10, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 11, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 36, BT_L20))
lvap.supports.add(ResourceBlock(lvap, sta, 48, BT_L20))
# This will trigger an LVAP ADD message (and REMOVE if necessary)
requested = ResourcePool()
hwaddr = EtherAddress(request.hwaddr)
channel = request.channel
band = request.band
requested.add(ResourceBlock(wtp, hwaddr, channel, band))
lvap.scheduled_on = wtp.supports & requested
LOG.info("Sending probe response to %s", lvap.addr)
self.send_probe_response(lvap)
示例12: prepare
def prepare(self):
"""Prepare to handler reply."""
self.set_header('Content-Type', 'application/json')
if not self.RIGHTS[self.request.method]:
return
auth_header = self.request.headers.get('Authorization')
if auth_header is None or not auth_header.startswith('Basic '):
self.set_header('WWW-Authenticate', 'Basic realm=Restricted')
self.send_error(401)
return
auth_bytes = bytes(auth_header[6:], 'utf-8')
auth_decoded = base64.b64decode(auth_bytes).decode()
username, password = auth_decoded.split(':', 2)
# account does not exists
if not RUNTIME.check_permission(username, password):
self.send_error(401)
return
self.account = RUNTIME.get_account(username)
if self.account.role in self.RIGHTS[self.request.method]:
if self.account.role == ROLE_ADMIN:
return
if self.request.uri.startswith("/api/v1/accounts"):
pattern = re.compile("/api/v1/accounts/([a-zA-Z0-9:-]*)/?")
match = pattern.match(self.request.uri)
if match and match.group(1):
if match.group(1) in RUNTIME.accounts:
account = RUNTIME.accounts[match.group(1)]
if self.account.username == account.username:
return
else:
self.send_error(401)
return
return
if self.request.uri.startswith("/api/v1/pending"):
pattern = re.compile("/api/v1/pending/([a-zA-Z0-9-]*)/?")
match = pattern.match(self.request.uri)
if match and match.group(1):
try:
tenant_id = UUID(match.group(1))
except ValueError:
self.send_error(400)
return
pending = RUNTIME.load_pending_tenant(tenant_id)
if pending:
if self.account.username == pending.owner:
return
self.send_error(401)
return
return
if self.request.uri.startswith("/api/v1/tenants"):
pattern = re.compile("/api/v1/tenants/([a-zA-Z0-9-]*)/?")
match = pattern.match(self.request.uri)
if match and match.group(1):
tenant_id = UUID(match.group(1))
if tenant_id in RUNTIME.tenants:
tenant = RUNTIME.tenants[tenant_id]
if self.account.username == tenant.owner:
return
self.send_error(401)
return
return
self.send_error(401)
return
示例13: _handle_UEs_id_repl
def _handle_UEs_id_repl(self, main_msg):
"""Handle an incoming UEs ID reply.
Args:
message, a emage_msg containing UE IDs (RNTIs)
Returns:
None
"""
active_ues = {}
inactive_ues = {}
event_type = main_msg.WhichOneof("event_types")
msg = protobuf_to_dict(main_msg)
ues_id_msg_repl = msg[event_type]["mUEs_id"]["repl"]
if ues_id_msg_repl["status"] != configs_pb2.CREQS_SUCCESS:
return
# List of active UEs
if "active_ue_id" in ues_id_msg_repl:
for ue in ues_id_msg_repl["active_ue_id"]:
active_ues[(self.vbs.addr, ue["rnti"])] = {}
if "imsi" in ue:
active_ues[(self.vbs.addr, ue["rnti"])]["imsi"] = ue["imsi"]
else:
active_ues[(self.vbs.addr, ue["rnti"])]["imsi"] = None
if "plmn_id" in ue:
active_ues[(self.vbs.addr, ue["rnti"])]["plmn_id"] = \
ue["plmn_id"]
else:
active_ues[(self.vbs.addr, ue["rnti"])]["plmn_id"] = None
# List of inactive UEs
if "inactive_ue_id" in ues_id_msg_repl:
for ue in ues_id_msg_repl["inactive_ue_id"]:
inactive_ues[(self.vbs.addr, ue["rnti"])] = {}
if "imsi" in ue:
inactive_ues[(self.vbs.addr, ue["rnti"])]["imsi"] = \
ue["imsi"]
else:
inactive_ues[(self.vbs.addr, ue["rnti"])]["imsi"] = None
if "plmn_id" in ue:
inactive_ues[(self.vbs.addr, ue["rnti"])]["plmn_id"] = \
ue["plmn_id"]
else:
inactive_ues[(self.vbs.addr, ue["rnti"])]["plmn_id"] = None
for vbs_id, rnti in active_ues.keys():
ue_id = (self.vbs.addr, rnti)
if ue_id not in RUNTIME.ues:
new_ue = UE(ue_id, ue_id[1], self.vbs)
RUNTIME.ues[ue_id] = new_ue
ue = RUNTIME.ues[ue_id]
imsi = active_ues[ue_id]["imsi"]
plmn_id = int(active_ues[ue_id]["plmn_id"])
# Setting IMSI of UE
ue.imsi = imsi
if not ue.plmn_id and plmn_id:
# Setting tenant
ue.tenant = RUNTIME.load_tenant_by_plmn_id(plmn_id)
if ue.tenant:
# Adding UE to tenant
LOG.info("Adding %s to tenant %s", ue.addr,
ue.tenant.plmn_id)
ue.tenant.ues[ue.addr] = ue
# Raise UE join
self.server.send_ue_join_message_to_self(ue)
# Create a trigger for reporting RRC measurements config.
from empower.ue_confs.ue_rrc_meas_confs import ue_rrc_meas_confs
conf_req = {
"event_type": "trigger"
}
ue_rrc_meas_confs(tenant_id=ue.tenant.tenant_id,
vbs=ue.vbs.addr,
ue=ue.rnti,
conf_req=conf_req)
if ue.plmn_id and not plmn_id:
# Raise UE leave
self.server.send_ue_leave_message_to_self(ue)
# Removing UE from tenant
LOG.info("Removing %s from tenant %s", ue.addr,
ue.tenant.plmn_id)
del ue.tenant.ues[ue.addr]
#.........这里部分代码省略.........
示例14: _handle_UEs_id_repl
def _handle_UEs_id_repl(self, main_msg):
"""Handle an incoming UEs ID reply.
Args:
message, a emage_msg containing UE IDs (RNTIs)
Returns:
None
"""
active_ues = {}
inactive_ues = {}
event_type = main_msg.WhichOneof("event_types")
msg = protobuf_to_dict(main_msg)
ues_id_msg_repl = msg[event_type]["mUEs_id"]["repl"]
if ues_id_msg_repl["status"] != configs_pb2.CREQS_SUCCESS:
return
# List of active UEs
if "active_ue_id" in ues_id_msg_repl:
for ue in ues_id_msg_repl["active_ue_id"]:
active_ues[ue["rnti"]] = {}
if "imsi" in ue:
active_ues[ue["rnti"]]["imsi"] = ue["imsi"]
else:
active_ues[ue["rnti"]]["imsi"] = None
if "plmn_id" in ue:
active_ues[ue["rnti"]]["plmn_id"] = ue["plmn_id"]
else:
active_ues[ue["rnti"]]["plmn_id"] = None
# List of inactive UEs
if "inactive_ue_id" in ues_id_msg_repl:
for ue in ues_id_msg_repl["inactive_ue_id"]:
inactive_ues[ue["rnti"]] = {}
if "imsi" in ue:
inactive_ues[ue["rnti"]]["imsi"] = ue["imsi"]
else:
inactive_ues[ue["rnti"]]["imsi"] = None
if "plmn_id" in ue:
inactive_ues[ue["rnti"]]["plmn_id"] = ue["plmn_id"]
else:
inactive_ues[ue["rnti"]]["plmn_id"] = None
for rnti in active_ues:
ue_id = hex_to_ether(rnti)
if ue_id not in RUNTIME.ues:
ue_id = hex_to_ether(rnti)
imsi = active_ues[ue["rnti"]]["imsi"]
new_ue = UE(ue_id, imsi, self.vbs)
RUNTIME.ues[ue_id] = new_ue
ue = RUNTIME.ues[ue_id]
plmn_id = int(active_ues[rnti]["plmn_id"])
if not ue.plmn_id and plmn_id:
# setting tenant
ue.tenant = RUNTIME.load_tenant_by_plmn_id(plmn_id)
if ue.tenant:
# adding UE to tenant
LOG.info("Adding %s to tenant %s", ue.addr,
ue.tenant.plmn_id)
ue.tenant.ues[ue.addr] = ue
# Raise UE join
self.server.send_ue_join_message_to_self(ue)
if ue.plmn_id and not plmn_id:
# removing UE from tenant
LOG.info("Removing %s from tenant %s", ue.addr,
ue.tenant.plmn_id)
del ue.tenant.ues[ue.addr]
# Raise UE leave
self.server.send_ue_leave_message_to_self(ue)
# setting tenant
ue.tenant = None
existing_ues = []
existing_ues.extend(RUNTIME.ues.keys())
for ue_id in existing_ues:
if ether_to_hex(ue_id) not in active_ues:
RUNTIME.remove_ue(ue_id)
示例15: _handle_assoc_request
def _handle_assoc_request(self, request):
"""Handle an incoming ASSOC_REQUEST message.
Args:
request, a ASSOC_REQUEST message
Returns:
None
"""
wtp_addr = EtherAddress(request.wtp)
try:
wtp = RUNTIME.wtps[wtp_addr]
except KeyError:
LOG.info("Assoc request from unknown WTP %s", wtp_addr)
return
if not wtp.connection:
LOG.info("Assoc request from disconnected WTP %s", wtp_addr)
return
sta = EtherAddress(request.sta)
if sta not in RUNTIME.lvaps:
LOG.info("Assoc request from unknown LVAP %s", sta)
return
lvap = RUNTIME.lvaps[sta]
if not RUNTIME.is_allowed(sta):
LOG.info("Assoc request from %s ignored (white list)", sta)
return
if RUNTIME.is_denied(sta):
LOG.info("Assoc request from %s ignored (black list)", sta)
return
ssid = SSID(request.ssid.decode('UTF-8'))
bssid = EtherAddress(request.bssid)
tenant_name = None
# look for ssid in shared tenants
for tenant_id in RUNTIME.tenants:
tenant = RUNTIME.tenants[tenant_id]
if tenant.bssid_type == T_TYPE_UNIQUE:
continue
if bssid in tenant.vaps and ssid == tenant.tenant_name:
tenant_name = tenant.tenant_name
# otherwise this must be the lvap unique bssid
if lvap.net_bssid == bssid and ssid in lvap.ssids:
tenant_name = ssid
if not tenant_name:
LOG.info("Assoc request sta %s for ssid %s bssid %s, ignoring",
lvap.addr, lvap.ssid, lvap.lvap_bssid)
return
# this will trigger an add lvap message to update the ssid
lvap.tenant = RUNTIME.load_tenant(tenant_name)
# this will trigger an add lvap message to update the assoc id
lvap.assoc_id = self.server.assoc_id
LOG.info("Assoc request sta %s ssid %s bssid %s assoc id %u, replying",
lvap.addr, lvap.ssid, lvap.lvap_bssid, lvap.assoc_id)
self.send_assoc_response(lvap)