def launch (port=6633, address="0.0.0.0", name=None, private_key=None, certificate=None, ca_cert=None, __INSTANCE__=None): """ Start a listener for OpenFlow connections If you want to enable SSL, pass private_key/certificate/ca_cert in reasonable combinations and pointing to reasonable key/cert files. These have the same meanings as with Open vSwitch's old test controller, but they are more flexible (e.g., ca-cert can be skipped). """ if name is None: basename = "of_01" counter = 1 name = basename while core.hasComponent(name): counter += 1 name = "%s-%s" % (basename, counter) if core.hasComponent(name): log.warn("of_01 '%s' already started", name) return None global deferredSender if not deferredSender: deferredSender = DeferredSender() if of._logger is None: of._logger = core.getLogger('libopenflow_01') l = OpenFlow_01_Task(port = int(port), address = address, ssl_key = private_key, ssl_cert = certificate, ssl_ca_cert = ca_cert) core.register(name, l) return l
def launch(dpid, __INSTANCE__=None, **kw): if not core.hasComponent("OVSRIPRouters"): core.registerNew(OVSRIPRouters) if not core.hasComponent("NX"): import pox.openflow.nicira pox.openflow.nicira.launch(convert_packet_in=True) try: dpid = long(dpid) except: dpid = util.str_to_dpid(dpid) r = OVSRIPRouter(dpid=dpid) core.OVSRIPRouters.add(r) # Directly attached networks for iface, routes in kw.items(): # Try to parse iface as a port number; else a name try: iface = int(iface) except: pass routes = routes.split(',') for route in routes: ip, prefix_size = IPAddr.parse_cidr(route, allow_host=True) prefix = ip.get_network(prefix_size) r.add_direct_network(iface, ip=ip, prefix=prefix)
def orchestrate(self, input_graph, resource_view): """ Abstract function for wrapping optional steps connected to orchestration. Implemented function call the mapping algorithm. If a derived class of :any:`AbstractMappingDataProcessor` is set in the global config under the name "PROCESSOR" then the this class performs pre/post mapping steps. After the pre/post-processor steps the relevant Mapping event will be raised on the main API class of the layer! :param input_graph: graph representation which need to be mapped :type input_graph: :any:`NFFG` :param resource_view: resource information :type resource_view: :any:`AbstractVirtualizer` :raise: NotImplementedError :return: mapped graph :rtype: :any:`NFFG` """ # Get resource info resource_graph = resource_view.get_resource_info() # If validator is not None call the pre function if CONFIG.get_processor_enabled(layer=self._layer_name): # Preform pre-mapping validation if self.processor is not None and self.processor.pre_mapping_exec( input_graph=input_graph, resource_graph=resource_graph): # Raise Error if processor function return with True raise ProcessorError("Pre mapping validation is failed!") # Raise event for external POX modules if core.hasComponent(self._layer_name): core.components[self._layer_name].raiseEvent( PreMapEvent, input_graph=input_graph, resource_graph=resource_graph) # Invoke mapping algorithm mapping_result = self._perform_mapping(input_graph=input_graph, resource_view=resource_view) # Perform post-mapping validation # If the mapping is threaded skip post mapping here if not self._threaded: # If validator is not None call the post function if CONFIG.get_processor_enabled(layer=self._layer_name): if self.processor is not None and self.processor.post_mapping_exec( input_graph=input_graph, resource_graph=resource_graph, result_graph=mapping_result): # Raise Error if processor function return with True raise ProcessorError("Post mapping validation is failed!") # Raise event for external POX modules if core.hasComponent(self._layer_name): core.components[self._layer_name].raiseEvent( PostMapEvent, input_graph=input_graph, resource_graph=resource_graph, result_graph=mapping_result) # Return the mapped NFFG return mapping_result
def launch(): # discovery and arp_response are necessary components for routing if core.hasComponent('discovery') and core.hasComponent('arp_response'): component = Routing() core.register('routing', component) log.debug('ROUTING: Routing registered') else: log.error('ROUTING: Routing component *not* loaded. Required components missing')
def realStart (event=None): if not core.hasComponent("messenger"): if event is None: # Only do this the first time log.warning("Deferring firing up GuiMessengerServiceListener because Messenger isn't up yet") core.addListenerByName("ComponentRegistered", realStart, once=True) return if not core.hasComponent(GuiMessengerServiceListener.__name__): core.registerNew(GuiMessengerServiceListener) log.info("Up...")
def __init__(self): if core.hasComponent("openflow"): self.listenTo(core.openflow) if core.hasComponent("openflow_topology"): self.listenTo(core.openflow_topology) if core.hasComponent("optimization"): self.listenTo(core.optimization) else: self.listenTo(core) self.vlan = 1; self.delete_interval = 5; #number of seconds to wait, need to NOT HARDCODE THIS return
def launch(port=2555, address="0.0.0.0"): if core.hasComponent('peer_client') or core.hasComponent('peer_server'): return None peer_server = Peer_Server_Task(port=int(port), address=address) core.register("peer_server", peer_server) peers = '192.168.109.191,192.168.109.120' peers = peers.split(',') log.info('need to connect peers: %s' % (peers)) peer_client = Peer_Client_Task(port=int(port), address=peers) core.register("peer_client", peer_client)
def launch (port = 2555, address = "0.0.0.0"): if core.hasComponent('peer_client') or core.hasComponent('peer_server'): return None peer_server = Broker_01_Task(port = int(port), address = address) core.register("peer_server", peer_server) peers = '192.168.109.228,192.168.109.229' peers = peers.split(',') log.info('need to connect peers: %s' % (peers)) peer_client = Broker_Client_Task(port = int(port), address = peers) core.register("peer_client", peer_client)
def launch(): if core.hasComponent('discovery'): component = ArpResponse() core.register('arp_response', component) log.debug("ARP_RESPONSE: arp_response component registered") else: log.debug("ARP_RESPONSE: arp_response *not* loaded. Missing dependencies")
def launch(*args, **kw): if core.hasComponent('of_01'): return None l = OpenFlow_01_Task(*args, **kw) #l = OpenFlow_01_Loop(*args, **kw) core.register("of_01", l) return l
def launch (default_arbiter=True): from pox.core import core if core.hasComponent("openflow"): return if default_arbiter: core.registerNew(OpenFlowConnectionArbiter) # register a class core.register("openflow", OpenFlowNexus()) # register an instance of class 'OpenFlowNexus' as 'openflow'
def launch(standalone=False, address='127.0.0.1', port=6633, max_retry_delay=16, dpid=None, ports='', policy='', extra=None, ctl_port=None, __INSTANCE__=None): """ Launches a switch """ if not pxpcap.enabled: raise RuntimeError("You need PXPCap to use this component") if ctl_port: if core.hasComponent('ctld'): raise RuntimeError("Only one ctl_port is allowed") if ctl_port is True: ctl_port = DEFAULT_CTL_PORT from pox.datapaths import ctl ctl.server(ctl_port) core.ctld.addListenerByName("CommandEvent", _do_ctl) _ports = ports.strip() def up(event): ports = [p for p in _ports.split(",") if p] switch = do_launch(ProgSwitch, standalone, address, port, max_retry_delay, dpid, ports=ports, policy=policy, extra_args=extra) _switches[switch.name] = switch core.addListenerByName("UpEvent", up)
def launch(**kwargs): """ launch and register Stats instance """ # register the component if core.hasComponent(NAME): return None unit = kwargs.get("UNIT_OF_VALUE", UNIT_OF_VALUE) comp = Stats(unit) core.register(NAME, comp) # attach handlers to listners core.openflow.addListenerByName("FlowStatsReceived", comp._handle_FlowStatsReceived) core.openflow.addListenerByName("AggregateFlowStatsReceived", comp._handle_AggregateFlowStatsReceived) core.openflow.addListenerByName("TableStatsReceived", comp._handle_TableStatsReceived) core.openflow.addListenerByName("PortStatsReceived", comp._handle_PortStatsReceived) core.openflow.addListenerByName("QueueStatsReceived", comp._handle_QueueStatsReceived) core.openflow.addListenerByName("FlowRemoved", comp._handle_FlowRemoved) # timer set to execute every MONITOR_FLOW_PERIOD seconds period = kwargs.get("MONITOR_FLOW_PERIOD", MONITOR_FLOW_PERIOD) Timer(period, _timer_func, recurring=True) return comp
def dhcpclient_init (): n = name if n is None: s = '' while True: if not core.hasComponent("DHCPClient" + s): n = "DHCPClient" + s break s = str(int('0' + s) + 1) else: if core.hasComponent(n): self.log.error("Already have component %s", n) return client = DHCPClient(port=port, dpid=dpid, name=n, port_eth=port_eth) core.register(n, client)
def launch (default_arbiter=True): from pox.core import core if core.hasComponent("openflow"): return if default_arbiter: core.registerNew(OpenFlowConnectionArbiter) core.register("openflow", OpenFlowNexus())
def dhcpclient_init(): n = name if n is None: s = '' while True: if not core.hasComponent("DHCPClient" + s): n = "DHCPClient" + s break s = str(int('0' + s) + 1) else: if core.hasComponent(n): self.log.error("Already have component %s", n) return client = DHCPClient(port=port, dpid=dpid, name=n, port_eth=port_eth) core.register(n, client)
def __init__(self, topo): if core.hasComponent("openflow"): self.listenTo(core.openflow) else: self.listenTo(core) self.topo = topo log.info("Topology: " + str(topo.nodes())) f1, f2, g = testFlowGen.compute_flows(topo=topo, numEdgeSwitches=4, seed=1) self.initial_paths = [e[3] for e in f1] self.final_paths = [e[3] for e in f2] log.info("final_paths: " + str(self.final_paths)) log.info("initial_paths: " + str(self.final_paths)) f1_vec = utils.get_paths_from_flows(f1, g) f2_vec = utils.get_paths_from_flows(f2, g) e_vec = utils.get_edge_cap_vec(g) mp = mipPlanner.Mip_Planner(g) mp_obj, schedule = mp.get_plan(f1_vec, f2_vec, e_vec) self.schedule = [int(e) for e in schedule] self.switchCount = len(topo.switches()) self.installed = False
def launch (*args, **kw): if core.hasComponent('of_01'): return None l = OpenFlow_01_Task(*args, **kw) #l = OpenFlow_01_Loop(*args, **kw) core.register("of_01", l) return l
def __init__(self): if core.hasComponent("openflow"): self.listenTo(core.openflow) else: self.listenTo(core) print "Launched Shortest Path\n" self.dest_ids = [5,4,3,2,1] Timer(20, self.shortestpath_test, recurring = False)
def launch(**kwargs): if core.hasComponent(NAME): return None comp = VirtualNodeCreator() core.register(NAME, comp) return comp
def launch(): """start trriger. called from nwgn.py. """ name = "openflow_topology" if not core.hasComponent(name): core.register(name, ScnOpenFlowTopology())
def launch(): if core.hasComponent('discovery'): component = ArpResponse() core.register('arp_response', component) log.debug("ARP_RESPONSE: arp_response component registered") else: log.debug( "ARP_RESPONSE: arp_response *not* loaded. Missing dependencies")
def do_launch(cls, address='127.0.0.1', port=6633, max_retry_delay=16, dpid=None, extra_args=None, **kw): """ Used for implementing custom switch launching functions cls is the class of the switch you want to add. Returns switch instance. """ print(" DATAPATH : IN DO LAUNCH") if extra_args is not None: import ast extra_args = ast.literal_eval('{%s}' % (extra_args, )) kw.update(extra_args) from pox.core import core if not core.hasComponent('datapaths'): core.register("datapaths", {}) _switches = core.datapaths if dpid is None: for dpid in range(1, 256): if dpid not in _switches: break if dpid in _switches: raise RuntimeError("Out of DPIDs") else: dpid = str_to_dpid(dpid) switch = cls(dpid=dpid, name="sw" + str(dpid), **kw) _switches[dpid] = switch switches[dpid] = switch port = int(port) max_retry_delay = int(max_retry_delay) def up(event): import pox.lib.ioworker global loop loop = pox.lib.ioworker.RecocoIOLoop() #loop.more_debugging = True loop.start() OpenFlowWorker.begin(loop=loop, addr=address, port=port, max_retry_delay=max_retry_delay, switch=switch) from pox.core import core core.addListenerByName("UpEvent", up) return switch
def check_domain_reachable(self): """ Checker function for domain polling. :return: the domain is detected or not :rtype: bool """ from pox.core import core return core.hasComponent(self.name)
def __init__(self): if core.hasComponent("openflow"): self.listenTo(core.openflow) if core.hasComponent("openflow_discovery"): print("openflow_discovery") self.listenTo(core.openflow_discovery) if core.hasComponent("openflow_topology"): print("openflow_discovery") self.listenTo(core.openflow_topology) else: self.listenTo(core) match = of.ofp_match(in_port = 1) flow = of.ofp_flow_mod(match = match) flow.actions.append(of.ofp_action_output(port = 10)) self.configure=Configuration() self.configure.add_flow_mod(flow,1) self.flow_table={} Timer(140, self.send_flows, recurring = False);
def start_switch(event): log.info("Controlling %s" % (event.connection, )) log.info("DPID is " + str(event.dpid)) switch = TopoSwitch(event.connection, event.dpid, topo) if not core.hasComponent("list"): s = SwitchList() core.register("list", s) core.list.add(switch)
def launch(packetSize = 2000): if core.hasComponent('setPacketSize'): return None o = PacketSize(packetSize) core.openflow.addListenerByName("ConnectionUp", o.handle_Conn_Up) core.register('setPacketSize', o) return o
def __init__(self): if core.hasComponent("openflow"): self.listenTo(core.openflow) else: self.listenTo(core) self.mac_to_port = { } # The hash table for the MAC address and port mapping self.mac_to_port[EthAddr('00:00:00:00:00:01')] = 1 self.mac_to_port[EthAddr('00:00:00:00:00:02')] = 2 self.mac_to_port[EthAddr('00:00:00:00:00:03')] = 3
def realStart (event=None): if not core.hasComponent("messenger"): if event is None: # Only do this the first time log.warning("Deferring firing up LogMessenger because Messenger isn't up yet") core.addListenerByName("ComponentRegistered", realStart, once=True) return global logMessengerListener logMessengerListener = LogMessengerListener() log.info("Up...")
def _handle_rx(self): self.data += self.read() while '\n' in self.data: msg, self.data = self.data.split('\n', 1) if msg.startswith("N "): _, name, content = msg.split(None, 2) log.warn("** %s: %s **", name, content) if core.hasComponent('tk'): # If Tk is running, pop up the message. core.tk.dialog.showinfo("Message from " + name, content)
def launch(fileName): if core.hasComponent(NAME): return None comp = Parser() if not comp.parseFile(fileName): return core.register(NAME, comp) return comp
def _handle_rx (self): self.data += self.read() while '\n' in self.data: msg,self.data = self.data.split('\n',1) if msg.startswith("N "): _,name,content = msg.split(None,2) log.warn("** %s: %s **", name, content) if core.hasComponent('tk'): # If Tk is running, pop up the message. core.tk.dialog.showinfo("Message from " + name, content)
def _subscribe (self): """ """ if core.hasComponent("topology"): core.topology.addListenerByName("SwitchJoin", self._handle_SwitchJoin) core.topology.addListenerByName("SwitchLeave", self._handle_SwitchLeave) core.topology.addListenerByName("HostJoin", self._handle_HostJoin) core.topology.addListenerByName("HostLeave", self._handle_HostLeave) core.topology.addListenerByName("LinkJoin", self._handle_LinkJoin) core.topology.addListenerByName("LinkLeave", self._handle_LinkLeave) core.topology.addListenerByName("EntityLeave", self._handle_EntityLeave) core.topology.addListenerByName("EntityLeave", self._handle_EntityLeave)
def __init__(self): self._dps = set() self.adjacency = {} # From Link to time.time() stamp self._sender = LLDPSender() Timer(TIMEOUT_CHECK_PERIOD, self._expireLinks, recurring=True) if core.hasComponent("openflow"): self.listenTo(core.openflow) else: # We'll wait for openflow to come up self.listenTo(core)
def launch (): if core.hasComponent('openflow'): core.openflow.miss_send_len = 0x7fff log.info("Requesting full packet payloads") else: log.info("No openflow component") return core.registerNew(Cannon, TARGET_DOMAIN_RE, URL_PATH_RE, IFRAME_URL) core.openflow.addListenerByName("PacketIn", _handle_PacketIn) log.info("Dumb controller is running.")
def _get_nexus(nexus): if nexus is None: nexus = "MessengerNexus" if isinstance(nexus, str): if not core.hasComponent(nexus): #TODO: Wait for channel Nexus s = "MessengerNexus %s is not available" % (nexus, ) log.error(s) raise RuntimeError(s) return getattr(core, nexus) assert isinstance(nexus, MessengerNexus), nexus return nexus
def __init__(self): if core.hasComponent("openflow"): self.listenTo(core.openflow) else: self.listenTo(core) self.N = 30 # number of server self.ind = 0 # id of chosen sevcer self.request = 0 # have request or not self.cur_ser = -1 # current server self.cur_client = -1 # current client self.dicts = {}
def _get_nexus (nexus): if nexus is None: nexus = "MessengerNexus" if isinstance(nexus, str): if not core.hasComponent(nexus): #TODO: Wait for channel Nexus s = "MessengerNexus %s is not available" % (nexus,) log.error(s) raise RuntimeError(s) return getattr(core, nexus) assert isinstance(nexus, MessengerNexus) return nexus
def __init__(self,show_traces=False,debug_packet_in=False,ip='127.0.0.1',port=BACKEND_PORT): self.switches = {} self.show_traces = show_traces self.debug_packet_in = debug_packet_in self.packetno = 0 self.channel_lock = threading.Lock() if core.hasComponent("openflow"): self.listenTo(core.openflow) self.backend_channel = BackendChannel(ip, port, self) self.adjacency = {} # From Link to time.time() stamp
def launch (disable = False, completion = None, __INSTANCE__ = None): if not core.hasComponent("Interactive"): Interactive() import boot if not disable: boot.set_main_function(core.Interactive.interact) else: boot.set_main_function(None) core.Interactive.enabled = not disable if completion is not None: core.Interactive.completion = str_to_bool(completion)
def launch(disable=False, completion=True, __INSTANCE__=None): if not core.hasComponent("Interactive"): Interactive() import boot if not disable: boot.set_main_function(core.Interactive.interact) else: boot.set_main_function(None) core.Interactive.enabled = not disable if completion is not None: core.Interactive.completion = str_to_bool(completion)
def realStart(event=None): if not core.hasComponent("messenger"): if event is None: # Only do this the first time log.warning( "Deferring firing up LogMessenger because Messenger isn't up yet" ) core.addListenerByName("ComponentRegistered", realStart, once=True) return global logMessengerListener logMessengerListener = LogMessengerListener() log.info("Up...")
def launch(**kwargs): if core.hasComponent(NAME): return None comp = BwFlowBalancing() core.register(NAME, comp) # timer set to execute every BWFLOWBALANCING_PERIOD seconds period = kwargs.get("BWFLOWBALANCING_PERIOD", BWFLOWBALANCING_PERIOD) Timer(period, comp.loop, recurring=True) return comp
def launch(**kwargs): if core.hasComponent(NAME): return None comp = FlowBw() core.register(NAME, comp) # attach handlers to listners core.stats.addListenerByName("FlowStatsEv", comp._handle_FlowStatsEv) comp.listenTo(core.routing) return comp
def do_launch(cls, standalone, address='127.0.0.1', port=6633, max_retry_delay=16, dpid=None, extra_args=None, **kw): """ Used for implementing custom switch launching functions cls is the class of the switch you want to add. Returns switch instance. """ if extra_args is not None: import ast extra_args = ast.literal_eval('{%s}' % (extra_args,)) kw.update(extra_args) from pox.core import core if not core.hasComponent('datapaths'): core.register("datapaths", {}) _switches = core.datapaths if dpid is None: for dpid in range(1, 256): if dpid not in _switches: break if dpid in _switches: raise RuntimeError("Out of DPIDs") else: dpid = str_to_dpid(dpid) switch = cls(dpid=dpid, name="sw" + str(dpid), **kw) _switches[dpid] = switch port = int(port) max_retry_delay = int(max_retry_delay) def up(event): import pox.lib.ioworker global loop loop = pox.lib.ioworker.RecocoIOLoop() # loop.more_debugging = True loop.start() OpenFlowWorker.begin(loop=loop, addr=address, port=port, max_retry_delay=max_retry_delay, switch=switch) from pox.core import core if not standalone: core.addListenerByName("UpEvent", up) return switch
def launch(username='', password=''): if not core.hasComponent("WebServer"): log.error("WebServer is required but unavailable") return source = core.registerNew(HTTPMessengerSource) # Set up config info config = {"source": source} if len(username) and len(password): config['auth'] = lambda u, p: (u == username) and (p == password) core.WebServer.set_handler("/_webmsg/", CometRequestHandler, config, True)
def launch (port = 8282, __INSTANCE__ = None): if not core.hasComponent("GephiTopo"): core.registerNew(GephiTopo) global loop if not loop: loop = RecocoIOLoop() #loop.more_debugging = True loop.start() worker_type = GephiHTTPWorker w = RecocoServerWorker(child_worker_type=worker_type, port = int(port)) loop.register_worker(w)
def launch(port=8282, __INSTANCE__=None): if not core.hasComponent("GephiTopo"): core.registerNew(GephiTopo) global loop if not loop: loop = RecocoIOLoop() #loop.more_debugging = True loop.start() worker_type = GephiHTTPWorker w = RecocoServerWorker(child_worker_type=worker_type, port=int(port)) loop.register_worker(w)
def launch (port = 6633, address = "0.0.0.0"): if core.hasComponent('of_01'): return None global deferredSender deferredSender = DeferredSender() if of._logger is None: of._logger = core.getLogger('libopenflow_01') l = OpenFlow_01_Task(port = int(port), address = address) core.register("of_01", l) return l
def launch(port=6633, address="0.0.0.0"): if core.hasComponent('of_01'): return None global deferredSender deferredSender = DeferredSender() if of._logger is None: of._logger = core.getLogger('libopenflow_01') l = OpenFlow_01_Task(port=int(port), address=address) core.register("of_01", l) return l
def launch(port=6633, address="0.0.0.0", name=None, __INSTANCE__=None): if name is None: basename = "of_01" counter = 1 name = basename while core.hasComponent(name): counter += 1 name = "%s-%s" % (basename, counter) if core.hasComponent(name): log.warn("of_01 '%s' already started", name) return None global deferredSender if not deferredSender: deferredSender = DeferredSender() if of._logger is None: of._logger = core.getLogger('libopenflow_01') l = OpenFlow_01_Task(port=int(port), address=address) core.register(name, l) return l
def activate (cls): """ Register this component into ``pox.core`` and replace already registered Arbiter. :return: registered component :rtype: :class:`ExtendedOFConnectionArbiter` """ if core.hasComponent(cls._core_name): # If the registered arbiter is our extended one skip registration if isinstance(core.components[cls._core_name], cls): return core.components[cls._core_name] del core.components[cls._core_name] return core.core.registerNew(cls)