def lisp_site_command(kv_pairs): global lisp_sites_by_name global lisp_sites_by_name_sorted site = lisp.lisp_site() allowed_rloc_set = [] if (kv_pairs.has_key("address")): for addr in kv_pairs["address"]: rloc = lisp.lisp_rloc() allowed_rloc_set.append(rloc) #endfor #endif allowed_eid_set = [] if (kv_pairs.has_key("eid-prefix")): for eid in kv_pairs["eid-prefix"]: site_eid = lisp.lisp_site_eid(site) allowed_eid_set.append(site_eid) #endfor #endif for kw in kv_pairs.keys(): value = kv_pairs[kw] if (kw == "site-name"): site.site_name = value if (kw == "description"): site.description = value if (kw == "authentication-key"): site.auth_key = lisp.lisp_parse_auth_key(value) #endif if (kw == "shutdown"): site.shutdown = True if value == "yes" else False #endif if (kw == "instance-id"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] if (v == "*"): site_eid.eid.store_iid_range(0, 0) else: if (v == ""): v = "0" site_eid.eid.instance_id = int(v) site_eid.group.instance_id = int(v) #endif #endfor #endif if (kw == "eid-prefix"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] if (v != ""): site_eid.eid.store_prefix(v) #endfor #endif if (kw == "group-prefix"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] if (v != ""): site_eid.group.store_prefix(v) #endfor #endif if (kw == "accept-more-specifics"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] yes_or_no = True if (v == "yes") else False site_eid.accept_more_specifics = yes_or_no #endfor #endif if (kw == "force-proxy-reply"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] yes_or_no = True if (v == "yes") else False site_eid.force_proxy_reply = yes_or_no #endfor #endif if (kw == "force-ttl"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] if (v == ""): continue site_eid.force_ttl = None if int(v) == 0 else int(v) #endfor #endif if (kw == "echo-nonce-capable"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] yes_or_no = True if (v == "yes") else False site_eid.echo_nonce_capable = yes_or_no #endfor #endif if (kw == "force-nat-proxy-reply"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] yes_or_no = True if (v == "yes") else False site_eid.force_nat_proxy_reply = yes_or_no #endfor #endif if (kw == "pitr-proxy-reply-drop"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] yes_or_no = True if (v == "yes") else False site_eid.pitr_proxy_reply_drop = yes_or_no #endfor #endif if (kw == "proxy-reply-action"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] site_eid.proxy_reply_action = v #endfor #endif if (kw == "require-signature"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] yes_or_no = True if (v == "yes") else False site_eid.require_signature = yes_or_no #endfor #endif if (kw == "policy-name"): for i in range(len(allowed_eid_set)): site_eid = allowed_eid_set[i] v = value[i] site_eid.policy = v #endfor #endif if (kw == "address"): for i in range(len(allowed_rloc_set)): rloc = allowed_rloc_set[i] v = value[i] if (v != ""): rloc.rloc.store_address(v) #endfor #endif if (kw == "priority"): for i in range(len(allowed_rloc_set)): rloc = allowed_rloc_set[i] v = value[i] if (v == ""): v = "0" rloc.priority = int(v) #endfor #endif if (kw == "weight"): for i in range(len(allowed_rloc_set)): rloc = allowed_rloc_set[i] v = value[i] if (v == ""): v = "0" rloc.weight = int(v) #endfor #endif #endfor # # Do not modify existing entries. We can only support adding new sites. # if (lisp_sites_by_name.has_key(site.site_name)): return # # Store values in internal data structures. Inside of lisp_site() sort # EID-prefixes. # lisp_sites_by_name[site.site_name] = site lisp_sites_by_name_sorted = sorted(lisp_sites_by_name) for site_eid in allowed_eid_set: site_eid.add_cache() key = site_eid.build_sort_key() site.allowed_prefixes[key] = site_eid #endfor for rloc in allowed_rloc_set: key = rloc.rloc.print_address() site.allowed_rlocs[key] = rloc #endfor # # Sort the site.allowed_preifxes{} array. # site.allowed_prefixes_sorted = sorted(site.allowed_prefixes) return
def lisp_ms_scale_inject(): global lisp_inject_mode_count # # Only do it once or never. # if (lisp_inject_mode_count == 0): return count = lisp_inject_mode_count i = lisp.bold("Injecting", False) lisp.fprint("{} {} entries into mapping system for scale testing". \ format(i, count)) # # Create EID-record info. # iid = 1300 phone = 9990000000 eid = lisp.lisp_address(lisp.LISP_AFI_NAME, "ct", 0, iid) group = lisp.lisp_address(lisp.LISP_AFI_NONE, "", 0, 0) parent_site = lisp.lisp_site_eid_lookup(eid, group, False) if (parent_site == None): lisp.fprint("No site found for instance-ID {}".format(iid)) return #endif if (parent_site.accept_more_specifics == False): lisp.fprint("Site must be configured with accept-more-specifics") return #endif # # Create RLOC-record info. # rloc = lisp.lisp_rloc() gps_record = ' "phone" : "{}", "text-interval" : "10", ' + \ '"gps" : "(37.623322,-122.384974579)" ' hs_record = ' "phone" : "{}", "health-state" : "not-tested" ' # # Now loop. # ts = lisp.lisp_get_timestamp() mem = 0 for i in range(1, count + 1): site_eid = lisp.lisp_site_eid(parent_site.site) site_eid.eid = copy.deepcopy(eid) site_eid.eid.address = hmac.new("ct", str(phone), hashlib.sha256).hexdigest() site_eid.dynamic = True site_eid.parent_for_more_specifics = parent_site site_eid.add_cache() site_eid.inherit_from_ams_parent() parent_site.more_specific_registrations.append(site_eid) # # Add GPS and HS RLOC records for EID entry. # gr = copy.deepcopy(rloc) json_string = "{" + gps_record.format(phone) + "}" gr.json = lisp.lisp_json(site_eid.eid.address, json_string) hr = copy.deepcopy(rloc) json_string = "{" + hs_record.format(phone) + "}" hr.json = lisp.lisp_json(site_eid.eid.address, json_string) site_eid.registered_rlocs = [gr, hr] mem += sys.getsizeof(site_eid) # # Print every 100 added. # if (i % 100 == 0): lisp.fprint("Added {} site-eid entries".format(i)) #endif # # Pause after 10000. # if (i % 10000 == 0 and i != count): lisp.fprint("Sleeping for 100ms ...") time.sleep(.1) #endif phone += 1 #endfor # # Compute and print elapsed time. # ts = time.time() - ts if (ts < 60): lisp.fprint("Finished in {} secs, memory {}".format(round(ts, 3), mem)) else: ts = ts / 60 lisp.fprint("Finished in {} mins, memory {}".format(round(ts, 1), mem)) #endif lisp_inject_mode_count = 0