def __init__(self, logger, topo_file, routing_table_file): self.logger = logger # Read the Fixed routing table first f = open(routing_table_file, "r") routing_config = json.load(f) f.close() for rt in routing_config: sn = Subnet(rt["subnet"], rt["router_port"], rt["router_mac"], rt["gateway"]) self.subnets.append(sn) # Read the fixed configuration from the topology file topo_agraph = pgv.AGraph(topo_file) switchnames = {} # Read router name and dpid from topo for node in topo_agraph.nodes(): if node.startswith("s"): if node.attr["router"]: router_name = str(node) self.router_dpid = NetUtils.int_from_mac_colon_hex( node.attr["dpid"]) else: switchnames[str(node)] = NetUtils.int_from_mac_colon_hex( node.attr["dpid"]) # Mark all the internal ports in the switches, since these need special attention for link in topo_agraph.edges(): (src_node, dst_node) = link if str(src_node) == router_name: dpid = switchnames[str(dst_node)] if dpid not in self.internal_ports: self.internal_ports[dpid] = [] self.internal_ports[dpid].append(int(link.attr['dport']))
def __init__(self, logger, topo_file, routing_table_file): self.logger = logger # Read the Fixed routing table first f = open(routing_table_file, "r") routing_config = json.load(f) f.close() for rt in routing_config: sn = Subnet(rt["subnet"],rt["router_port"],rt["router_mac"],rt["gateway"]) self.subnets.append(sn) # Read the fixed configuration from the topology file topo_agraph = pgv.AGraph(topo_file) switchnames = {} # Read router name and dpid from topo for node in topo_agraph.nodes(): if node.startswith("s"): if node.attr["router"]: router_name = str(node) self.router_dpid = NetUtils.int_from_mac_colon_hex(node.attr["dpid"]) else: switchnames[str(node)] = NetUtils.int_from_mac_colon_hex(node.attr["dpid"]) # Mark all the internal ports in the switches, since these need special attention for link in topo_agraph.edges(): (src_node, dst_node) = link if str(src_node) == router_name: dpid = switchnames[ str(dst_node) ] if dpid not in self.internal_ports: self.internal_ports[dpid] = [] self.internal_ports[dpid].append(int(link.attr['dport']))