def debug(cls, _, __, ___): config = load_service_config('pipelined') qos_impl_type = QosImplType(config["qos"]["impl"]) qos_store = QosStore(cls.__name__) for k, v in qos_store.items(): _, imsi, ip_addr, rule_num, d = get_key(k) _, qid, ambr, leaf = get_data(v) print('imsi :', imsi) print('ip_addr :', ip_addr) print('rule_num :', rule_num) print('direction :', d) print('qos_handle:', qid) print('qos_handle_ambr:', ambr) print('qos_handle_ambr_leaf:', leaf) if qos_impl_type == QosImplType.OVS_METER: MeterManager.dump_meter_state(v) else: intf = 'nat_iface' if d == FlowMatch.UPLINK else 'enodeb_iface' print("Dev: ", config[intf]) TrafficClass.dump_class_state(config[intf], qid) if leaf and leaf != qid: print("Leaf:") TrafficClass.dump_class_state(config[intf], leaf) if ambr: print("AMBR (parent):") TrafficClass.dump_class_state(config[intf], ambr)
def debug(cls, _, __, ___): config = load_service_config('pipelined') qos_impl_type = QosImplType(config["qos"]["impl"]) qos_store = QosStore(cls.__name__, client=get_default_client()) for k, v in qos_store.items(): _, imsi, ip_addr, rule_num, d = get_key(k) _, qid, ambr, leaf = get_data(v) print('imsi :', imsi) print('ip_addr :', ip_addr) print('rule_num :', rule_num) print('direction :', d) print('qos_handle:', qid) print('qos_handle_ambr:', ambr) print('qos_handle_ambr_leaf:', leaf) if qos_impl_type == QosImplType.OVS_METER: MeterManager.dump_meter_state(v) else: dev = config[ 'nat_iface'] if d == FlowMatch.UPLINK else 'gtpu_sys_2152' print("Dev: ", dev) TrafficClass.dump_class_state(dev, qid) if leaf and leaf != qid: print("Leaf:") TrafficClass.dump_class_state(dev, leaf) if ambr: print("AMBR (parent):") TrafficClass.dump_class_state(dev, ambr) if qos_impl_type == QosImplType.LINUX_TC: dev = config['nat_iface'] print("Root stats for: ", dev) TrafficClass.dump_root_class_stats(dev) dev = 'gtpu_sys_2152' print("Root stats for: ", dev) TrafficClass.dump_root_class_stats(dev)
def callback(fut): LOG.debug("read_all_state complete => \n%s", fut.result()) qos_state = fut.result() try: # populate state from db in_store_qid = set() purge_store_set = set() for k, v in self._qos_store.items(): if v not in qos_state: purge_store_set.add(k) continue in_store_qid.add(v) _, imsi, rule_num, d = get_key(k) self._subscriber_map[imsi][rule_num] = (v, d) # purge entries from qos_store for k in purge_store_set: LOG.debug("purging qos_store entry %s qos_handle", k) del self._qos_store[k] # purge unreferenced qos configs from system for qos_handle, d in qos_state.items(): if qos_handle not in in_store_qid: LOG.debug("removing qos_handle %d", qos_handle) self.qos_impl.remove_qos(qos_handle, d, recovery_mode=True) self._initialized = True LOG.info("init complete with state recovered successfully") except Exception as e: # pylint: disable=broad-except # in case of any exception start clean slate LOG.error("error %s. restarting clean", str(e)) self._clean_restart = True self.setup()
def _setupInternal(self): if self._clean_restart: LOG.info("Qos Setup: clean start") self.impl.destroy() self._redis_store.clear() self.impl.setup() self._initialized = True else: # read existing state from qos_impl LOG.info("Qos Setup: recovering existing state pbs1") self.impl.setup() qos_state = self.impl.read_all_state() try: # populate state from db in_store_qid = set() purge_store_set = set() for rule, qid in self._redis_store.items(): if qid not in qos_state: purge_store_set.add(rule) continue in_store_qid.add(qid) _, imsi, ip_addr, rule_num, direction = get_key(rule) subscriber = self.get_or_create_subscriber(imsi) subscriber.update_rule(ip_addr, rule_num, direction, qid) qid_state = qos_state[qid] if qid_state['ambr_qid'] != 0: session = subscriber.get_or_create_session(ip_addr) ambr_qid = qid_state['ambr_qid'] leaf = 0 # its AMBR QoS handle if its config matches with parent # pylint: disable=too-many-function-args if self.impl.same_qos_config(direction, ambr_qid, qid): leaf = qid session.set_ambr(direction, qid_state['ambr_qid'], leaf) # purge entries from qos_store for rule in purge_store_set: LOG.debug("purging qos_store entry %s qos_handle", rule) del self._redis_store[rule] # purge unreferenced qos configs from system for qos_handle in qos_state: if qos_handle not in in_store_qid: LOG.debug("removing qos_handle %d", qos_handle) self.impl.remove_qos( qos_handle, qos_state[qos_handle]['direction'], recovery_mode=True) LOG.info("init complete with state recovered successfully") except Exception as e: # pylint: disable=broad-except # in case of any exception start clean slate LOG.error("error %s. restarting clean", str(e)) self._clean_restart = True self._initialized = True
def debug(cls, _): config = load_service_config('pipelined') qos_impl_type = QosImplType(config["qos"]["impl"]) qos_store = QosStore(cls.__name__) for k, v in qos_store.items(): _, imsi, rule_num, d = get_key(k) print('imsi :', imsi) print('rule_num :', rule_num) print('direction :', d) print('qos_handle:', v) if qos_impl_type == QosImplType.OVS_METER: MeterManager.dump_meter_state(v) else: intf = 'nat_iface' if d == FlowMatch.UPLINK else 'enodeb_iface' TrafficClass.dump_class_state(config[intf], v)
def callback(fut): LOG.debug("read_all_state complete => \n%s", fut.result()) qos_state = fut.result() try: # populate state from db in_store_qid = set() purge_store_set = set() for k, v in self._qos_store.items(): if v not in qos_state: purge_store_set.add(k) continue in_store_qid.add(v) _, imsi, ip_addr, rule_num, d = get_key(k) subscriber = self.get_or_create_subscriber(imsi) subscriber.update_rule(ip_addr, rule_num, d, v) qid_state = qos_state[v] if qid_state['ambr_qid'] != 0: session = subscriber.get_or_create_session(ip_addr) ambr_qid = qid_state['ambr_qid'] leaf = 0 # its AMBR QoS handle if its config matches with parent # pylint: disable=too-many-function-args if self.impl.same_qos_config(d, ambr_qid, v): leaf = v session.set_ambr(d, qid_state['ambr_qid'], leaf) # purge entries from qos_store for k in purge_store_set: LOG.debug("purging qos_store entry %s qos_handle", k) del self._qos_store[k] # purge unreferenced qos configs from system for qos_handle in qos_state: if qos_handle not in in_store_qid: LOG.debug("removing qos_handle %d", qos_handle) self.impl.remove_qos( qos_handle, qos_state[qos_handle]['direction'], recovery_mode=True) self._initialized = True LOG.info("init complete with state recovered successfully") except Exception as e: # pylint: disable=broad-except # in case of any exception start clean slate LOG.error("error %s. restarting clean", str(e)) self._clean_restart = True self.setup()
def testQosKeyUtils(self): k = get_subscriber_key("1234", '1.1.1.1', 10, 0) j = get_key_json(k) self.assertTrue(get_key(j) == k)
def _setupInternal(self): if self._initialized: return if self._clean_restart: LOG.info("Qos Setup: clean start") self.impl.destroy() self._redis_store.clear() self.impl.setup() self._initialized = True else: # read existing state from qos_impl LOG.info("Qos Setup: recovering existing state") self.impl.setup() cur_qos_state, apn_qid_list = self.impl.read_all_state() LOG.debug("Initial qos_state -> %s", json.dumps(cur_qos_state, indent=1)) LOG.debug("apn_qid_list -> %s", apn_qid_list) LOG.debug("Redis state: %s", self._redis_store) try: # populate state from db in_store_qid = set() in_store_ambr_qid = set() purge_store_set = set() for rule, sub_data in self._redis_store.items(): _, qid, ambr, leaf = get_data(sub_data) if qid not in cur_qos_state: LOG.warning("missing qid: %s in TC", qid) purge_store_set.add(rule) continue if ambr and ambr != 0 and ambr not in cur_qos_state: purge_store_set.add(rule) LOG.warning("missing ambr class: %s of qid %d", ambr, qid) continue if leaf and leaf != 0 and leaf not in cur_qos_state: purge_store_set.add(rule) LOG.warning("missing leaf class: %s of qid %d", leaf, qid) continue if ambr: qid_state = cur_qos_state[qid] if qid_state['ambr_qid'] != ambr: purge_store_set.add(rule) LOG.warning( "Inconsistent amber class: %s of qid %d", qid_state['ambr_qid'], ambr) continue in_store_qid.add(qid) if ambr: in_store_qid.add(ambr) in_store_ambr_qid.add(ambr) in_store_qid.add(leaf) _, imsi, ip_addr, rule_num, direction = get_key(rule) subscriber = self.get_or_create_subscriber(imsi) subscriber.update_rule(ip_addr, rule_num, direction, qid, ambr, leaf) session = subscriber.get_or_create_session(ip_addr) session.set_ambr(direction, ambr, leaf) # purge entries from qos_store for rule in purge_store_set: LOG.debug("purging qos_store entry %s", rule) del self._redis_store[rule] # purge unreferenced qos configs from system # Step 1. Delete child nodes lost_and_found_apn_list = set() for qos_handle in cur_qos_state: if qos_handle not in in_store_qid: if qos_handle in apn_qid_list: lost_and_found_apn_list.add(qos_handle) else: LOG.debug("removing qos_handle %d", qos_handle) self.impl.remove_qos( qos_handle, cur_qos_state[qos_handle]['direction'], recovery_mode=True) if len(lost_and_found_apn_list) > 0: # Step 2. delete qos ambr without any leaf nodes for qos_handle in lost_and_found_apn_list: if qos_handle not in in_store_ambr_qid: LOG.debug("removing apn qos_handle %d", qos_handle) self.impl.remove_qos( qos_handle, cur_qos_state[qos_handle]['direction'], recovery_mode=True, skip_filter=True) final_qos_state, _ = self.impl.read_all_state() LOG.info("final_qos_state -> %s", json.dumps(final_qos_state, indent=1)) LOG.info("final_redis state -> %s", self._redis_store) except Exception as e: # pylint: disable=broad-except # in case of any exception start clean slate LOG.error("error %s. restarting clean %s", e, traceback.format_exc()) self._clean_restart = True self._initialized = True
def _setupInternal(self): if self._initialized: return if self._clean_restart: LOG.info("Qos Setup: clean start") self.impl.destroy() self._redis_store.clear() self.impl.setup() self._initialized = True else: # read existing state from qos_impl LOG.info("Qos Setup: recovering existing state") self.impl.setup() qos_state, apn_qid_list = self.impl.read_all_state() LOG.debug("qos_state -> %s", json.dumps(qos_state, indent=1)) LOG.debug("apn_qid_list -> %s", apn_qid_list) try: # populate state from db in_store_qid = set() purge_store_set = set() for rule, qid in self._redis_store.items(): if qid not in qos_state: purge_store_set.add(rule) continue in_store_qid.add(qid) _, imsi, ip_addr, rule_num, direction = get_key(rule) subscriber = self.get_or_create_subscriber(imsi) subscriber.update_rule(ip_addr, rule_num, direction, qid) qid_state = qos_state[qid] if qid_state['ambr_qid'] != 0: session = subscriber.get_or_create_session(ip_addr) ambr_qid = qid_state['ambr_qid'] leaf = 0 # its AMBR QoS handle if its config matches with parent # pylint: disable=too-many-function-args if self.impl.same_qos_config(direction, ambr_qid, qid): leaf = qid session.set_ambr(direction, qid_state['ambr_qid'], leaf) # purge entries from qos_store for rule in purge_store_set: LOG.debug("purging qos_store entry %s qos_handle", rule) del self._redis_store[rule] # purge unreferenced qos configs from system # Step 1. Delete child nodes apn_list_for_step_2 = [] for qos_handle in qos_state: if qos_handle not in in_store_qid: if qos_handle in apn_qid_list: apn_list_for_step_2.append(qos_handle) else: LOG.debug("removing qos_handle %d", qos_handle) self.impl.remove_qos( qos_handle, qos_state[qos_handle]['direction'], recovery_mode=True) # Step 2. delete qos handle without any child qos_state2, apn_qid_list2 = self.impl.read_all_state() LOG.debug("intermediate qos_state -> %s", json.dumps(qos_state2, indent=1)) LOG.debug("intermediate apn_qid_list -> %s", apn_qid_list2) for qos_handle in apn_list_for_step_2: if qos_handle not in apn_qid_list2: LOG.debug("removing qos_handle %d", qos_handle) self.impl.remove_qos( qos_handle, qos_state[qos_handle]['direction'], recovery_mode=True) final_qos_state, _ = self.impl.read_all_state() LOG.info("final_qos_state -> %s", json.dumps(final_qos_state, indent=1)) LOG.info("final_redis state -> %s", self._redis_store) except Exception as e: # pylint: disable=broad-except # in case of any exception start clean slate LOG.error("error %s. restarting clean %s", e, traceback.format_exc()) self._clean_restart = True self._initialized = True
def testQosKeyUtils(self, ): k = get_subscriber_key("imsi1234", 10, 0) j = get_json(k) self.assertTrue(get_key(j) == k)