def _init_net_info(self): """ Fetches Gemel SDN network info from the API and initiates essential info such as number of vnets, number of simulations, etc """ # fetch list of simulation hosts sims_list = ApiWrapper.get_sims() idx = 0 ip_id_map = {} # assign a zero-based ID to each mac-address and store # the mapping for host_type, hosts in sims_list.items(): for host in hosts: host["id"] = idx host["type"] = host_type ip_id_map[host["overlay_ip"]] = idx idx += 1 # fetch list of know alerts and sort by ID alerts = ApiWrapper.get_known_alert() alerts = sorted(alerts, key=lambda x: x["id"]) # fetch ARP table self.arp_table = ApiWrapper.get_arp_table() # fetch vnet list self.vnets = ApiWrapper.vnet_list() self.simulations = sims_list self.host_count = idx self.ip_id_map = ip_id_map self.known_alerts = alerts
def test_arp(self): arp = ApiWrapper.get_arp_table() self.assertIsInstance(arp, dict) for ip, macs in arp.items(): self.assertRegex(ip, r"(\d{1,3}\.){3}\d{1,3}") self.assertIsInstance(macs, list) for m in macs: self.assertRegex(m, r"^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$")