Esempio n. 1
0
    def server_loop(self):
        if CONF.oxp_ctl_privkey is not None and CONF.oxp_ctl_cert is not None:
            if CONF.oxp_ca_certs is not None:
                server = StreamServer(
                    (CONF.oxp_listen_host, CONF.oxp_ssl_listen_port),
                    domain_connection_factory,
                    # change into the real handler
                    keyfile=CONF.oxp_ctl_privkey,
                    certfile=CONF.oxp_ctl_cert,
                    cert_reqs=ssl.CERT_REQUIRED,
                    ca_certs=CONF.oxp_ca_certs,
                    ssl_version=ssl.PROTOCOL_TLSv1,
                )
            else:
                server = StreamServer(
                    (CONF.oxp_listen_host, CONF.oxp_ssl_listen_port),
                    domain_connection_factory,  # to change
                    keyfile=CONF.oxp_ctl_privkey,
                    certfile=CONF.oxp_ctl_cert,
                    ssl_version=ssl.PROTOCOL_TLSv1,
                )
            LOG.info("oxp super controller set up at:%s:%s " % (CONF.oxp_listen_host, CONF.oxp_ssl_listen_port))
        else:
            server = StreamServer(
                (CONF.oxp_listen_host, CONF.oxp_tcp_listen_port), domain_connection_factory
            )  # to change
            LOG.info("oxp super controller set up at:%s:%s " % (CONF.oxp_listen_host, CONF.oxp_tcp_listen_port))

        # LOG.debug('loop')
        server.serve_forever()
Esempio n. 2
0
    def server_loop(self):
        if CONF.ctl_privkey is not None and CONF.ctl_cert is not None:
            if CONF.ca_certs is not None:
                server = StreamServer((CONF.ofp_listen_host,
                                       CONF.ofp_ssl_listen_port),
                                      datapath_connection_factory,
                                      keyfile=CONF.ctl_privkey,
                                      certfile=CONF.ctl_cert,
                                      cert_reqs=ssl.CERT_REQUIRED,
                                      ca_certs=CONF.ca_certs,
                                      ssl_version=ssl.PROTOCOL_TLSv1)
            else:
                server = StreamServer((CONF.ofp_listen_host,
                                       CONF.ofp_ssl_listen_port),
                                      datapath_connection_factory,
                                      keyfile=CONF.ctl_privkey,
                                      certfile=CONF.ctl_cert,
                                      ssl_version=ssl.PROTOCOL_TLSv1)
        else:
            server = StreamServer((CONF.ofp_listen_host,
                                   CONF.ofp_tcp_listen_port),
                                  datapath_connection_factory)

        # LOG.debug('loop')
        server.serve_forever()
Esempio n. 3
0
class Server(object):
    def __init__(self, *args):
        super(Server, self).__init__()
        self.clients = {}  #client = controller
        self.server = StreamServer(('0.0.0.0', 8888), self._connect)
        self.topo = {}

    def _connect(self, socket, address):
        print 'connected address:%s' % str(address)

        with contextlib.closing(Client(socket)) as client:
            client.server = self
            client_id = len(self.clients) + 1

            client.set_id(client_id)
            self.clients[client_id] = client
            client.start()

    def start(self):
        hub.spawn(self.monitor)
        print("Server start...")
        self.server.serve_forever()

    def monitor(self):
        while True:
            print self.topo
            hub.sleep(2)
Esempio n. 4
0
 def __init__(self, *args):
     super(GlobalController, self).__init__()
     self.agents = {}
     self.server = StreamServer(('0.0.0.0', 10807),
                                self._connection_factory)
     self.cross_domain_links = [
     ]  # ex: [{src: {dpid: 4, port: 3}, dst: {dpid: 1, port: 1} }]
     self.hosts = {}  # host -> domain number
Esempio n. 5
0
    def server_loop(self):
        if CONF.ctl_privkey is not None and CONF.ctl_cert is not None:
            if CONF.ca_certs is not None:
                server = StreamServer(
                    (CONF.ofp_listen_host, CONF.ofp_ssl_listen_port),
                    datapath_connection_factory,
                    keyfile=CONF.ctl_privkey,
                    certfile=CONF.ctl_cert,
                    cert_reqs=ssl.CERT_REQUIRED,
                    ca_certs=CONF.ca_certs,
                    ssl_version=ssl.PROTOCOL_TLSv1)
            else:
                server = StreamServer(
                    (CONF.ofp_listen_host, CONF.ofp_ssl_listen_port),
                    datapath_connection_factory,
                    keyfile=CONF.ctl_privkey,
                    certfile=CONF.ctl_cert,
                    ssl_version=ssl.PROTOCOL_TLSv1)
        else:
            server = StreamServer(
                (CONF.ofp_listen_host, CONF.ofp_tcp_listen_port),
                datapath_connection_factory)

        # LOG.debug('loop')
        server.serve_forever()
Esempio n. 6
0
    def server_loop(self, ofp_tcp_listen_port, ofp_ssl_listen_port):
        if CONF.ctl_privkey is not None and CONF.ctl_cert is not None:
            if CONF.ca_certs is not None:
                # (self, listen_info, handle=None, backlog=None,spawn='default', **ssl_args)
                server = StreamServer(
                    (CONF.ofp_listen_host, ofp_ssl_listen_port),
                    datapath_connection_factory,
                    keyfile=CONF.ctl_privkey,
                    certfile=CONF.ctl_cert,
                    cert_reqs=ssl.CERT_REQUIRED,
                    ca_certs=CONF.ca_certs,
                    ssl_version=ssl.PROTOCOL_TLSv1)
            else:
                server = StreamServer(
                    (CONF.ofp_listen_host, ofp_ssl_listen_port),
                    datapath_connection_factory,
                    keyfile=CONF.ctl_privkey,
                    certfile=CONF.ctl_cert,
                    ssl_version=ssl.PROTOCOL_TLSv1)
        else:
            server = StreamServer((CONF.ofp_listen_host, ofp_tcp_listen_port),
                                  datapath_connection_factory)

        # LOG.debug('loop')
        server.serve_forever()
Esempio n. 7
0
 def start(self):
     super(RheaNLSocket, self).start()
     log.debug("Netlink socket server listening on %s:%s", self.server_host,
               self.server_port)
     server_addr = ('localhost', 55652)
     inisock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     inisock.connect(server_addr)
     request = pickle.dumps(['ifaceTable'])
     inisock.send(request)
     msg = inisock.recv(8192)
     if msg != 'None':
         data = pickle.loads(msg)
         self.ifaceTable = data[1]
     request = pickle.dumps(['neighbourtable'])
     inisock.send(request)
     msg = inisock.recv(8192)
     if msg != 'None':
         data = pickle.loads(msg)
         self.neighbours = data[1]
     request = pickle.dumps(['get_unresolved'])
     inisock.send(request)
     msg = inisock.recv(8192)
     if msg != 'None':
         data = pickle.loads(msg)
         self.unresolvedneighbours = data[1]
     inisock.close()
     for iface in self.ifaceTable:
         log.info("Interface %s has address %s", iface['ifname'],
                  iface['mac-address'])
     return hub.spawn(StreamServer((self.server_host, self.server_port),
                      self.loop).serve_forever)
Esempio n. 8
0
    def start(self):
        super(BMPStation, self).start()
        self.logger.debug("listening on %s:%s" % (self.server_host,
                                                  self.server_port))

        return hub.spawn(StreamServer((self.server_host, self.server_port),
                                      self.loop).serve_forever)
 def start(self):
     """Start socket server."""
     if self.socket_path:
         stream_server = StreamServer((self.socket_path, None),
                                      self._loop).serve_forever
         self.thread = hub.spawn(stream_server)
     return self.thread
Esempio n. 10
0
 def start(self):
     """Start socket server."""
     if self.socket_path:
         if os.path.exists(self.socket_path):
             os.remove(self.socket_path)
         return hub.spawn(
             StreamServer((self.socket_path, None), self._loop).serve_forever)
     return None
Esempio n. 11
0
    def start(self):
        super(RheaRouteReceiver, self).start()
        self.logger.debug("listening on %s:%s", self.server_host,
                          self.server_port)

        return hub.spawn(
            StreamServer((self.server_host, self.server_port),
                         self.loop).serve_forever)
Esempio n. 12
0
    def server_loop(self, ofp_tcp_listen_port, ofp_ssl_listen_port):
        if CONF.ctl_privkey is not None and CONF.ctl_cert is not None:
            if not hasattr(ssl, 'SSLContext'):
                # anything less than python 2.7.9 supports only TLSv1
                # or less, thus we choose TLSv1
                ssl_args = {'ssl_version': ssl.PROTOCOL_TLSv1}
            else:
                # from 2.7.9 and versions 3.4+ ssl context creation is
                # supported. Protocol_TLS from 2.7.13 and from 3.5.3
                # replaced SSLv23. Functionality is similar.
                if hasattr(ssl, 'PROTOCOL_TLS'):
                    p = 'PROTOCOL_TLS'
                else:
                    p = 'PROTOCOL_SSLv23'

                ssl_args = {'ssl_ctx': ssl.SSLContext(getattr(ssl, p))}
                # Restrict non-safe versions
                ssl_args['ssl_ctx'].options |= ssl.OP_NO_SSLv3 | ssl.OP_NO_SSLv2

            if CONF.ca_certs is not None:
                server = StreamServer((CONF.ofp_listen_host,
                                       ofp_ssl_listen_port),
                                      datapath_connection_factory,
                                      keyfile=CONF.ctl_privkey,
                                      certfile=CONF.ctl_cert,
                                      cert_reqs=ssl.CERT_REQUIRED,
                                      ca_certs=CONF.ca_certs, **ssl_args)
            else:
                server = StreamServer((CONF.ofp_listen_host,
                                       ofp_ssl_listen_port),
                                      datapath_connection_factory,
                                      keyfile=CONF.ctl_privkey,
                                      certfile=CONF.ctl_cert, **ssl_args)
        else:
            server = StreamServer((CONF.ofp_listen_host,
                                   ofp_tcp_listen_port),
                                  datapath_connection_factory)

        # LOG.debug('loop')
        server.serve_forever()
Esempio n. 13
0
    def server_loop(self, ofp_tcp_listen_port, ofp_ssl_listen_port):
        if CONF.ctl_privkey is not None and CONF.ctl_cert is not None:
            if not hasattr(ssl, 'SSLContext'):
                # anything less than python 2.7.9 supports only TLSv1
                # or less, thus we choose TLSv1
                ssl_args = {'ssl_version': ssl.PROTOCOL_TLSv1}
            elif sys.version_info >= (3, 7,):
                # On Python3.7+ we can't wrap an SSLContext due to this bug:
                # https://github.com/eventlet/eventlet/issues/526
                # Lets assume the system has a new enough OpenSSL that
                # SSL is fully disabled.
                ssl_args = {'ssl_version': ssl.PROTOCOL_TLSv1}
            else:
                # from 2.7.9 and versions 3.4+ ssl context creation is
                # supported. Protocol_TLS from 2.7.13 and from 3.5.3
                # replaced SSLv23. Functionality is similar.
                if hasattr(ssl, 'PROTOCOL_TLS'):
                    p = 'PROTOCOL_TLS'
                else:
                    p = 'PROTOCOL_SSLv23'

                ssl_args = {'ssl_ctx': ssl.SSLContext(getattr(ssl, p))}
                # Restrict non-safe versions
                ssl_args['ssl_ctx'].options |= ssl.OP_NO_SSLv3 | ssl.OP_NO_SSLv2

            if CONF.ciphers is not None:
                ssl_args['ciphers'] = CONF.ciphers

            if CONF.ca_certs is not None:
                server = StreamServer((CONF.ofp_listen_host,
                                       ofp_ssl_listen_port),
                                      datapath_connection_factory,
                                      keyfile=CONF.ctl_privkey,
                                      certfile=CONF.ctl_cert,
                                      cert_reqs=ssl.CERT_REQUIRED,
                                      ca_certs=CONF.ca_certs, **ssl_args)
            else:
                server = StreamServer((CONF.ofp_listen_host,
                                       ofp_ssl_listen_port),
                                      datapath_connection_factory,
                                      keyfile=CONF.ctl_privkey,
                                      certfile=CONF.ctl_cert, **ssl_args)
        else:
            server = StreamServer((CONF.ofp_listen_host,
                                   ofp_tcp_listen_port),
                                  datapath_connection_factory)

        # LOG.debug('loop')
        server.serve_forever()
Esempio n. 14
0
    def server_loop(self, ofp_tcp_listen_port, ofp_ssl_listen_port):
        if CONF.ctl_privkey is not None and CONF.ctl_cert is not None:
            if not hasattr(ssl, 'SSLContext'):
                # anything less than python 2.7.9 supports only TLSv1
                # or less, thus we choose TLSv1
                ssl_args = {'ssl_version': ssl.PROTOCOL_TLSv1}
            else:
                # from 2.7.9 and versions 3.4+ ssl context creation is
                # supported. Protocol_TLS from 2.7.13 and from 3.5.3
                # replaced SSLv23. Functionality is similar.
                if hasattr(ssl, 'PROTOCOL_TLS'):
                    p = 'PROTOCOL_TLS'
                else:
                    p = 'PROTOCOL_SSLv23'

                ssl_args = {'ssl_ctx': ssl.SSLContext(getattr(ssl, p))}
                # Restrict non-safe versions
                ssl_args['ssl_ctx'].options |= ssl.OP_NO_SSLv3 | ssl.OP_NO_SSLv2

            if CONF.ciphers is not None:
                ssl_args['ciphers'] = CONF.ciphers

            if CONF.ca_certs is not None:
                server = StreamServer((CONF.ofp_listen_host,
                                       ofp_ssl_listen_port),
                                      datapath_connection_factory,
                                      keyfile=CONF.ctl_privkey,
                                      certfile=CONF.ctl_cert,
                                      cert_reqs=ssl.CERT_REQUIRED,
                                      ca_certs=CONF.ca_certs, **ssl_args)
            else:
                server = StreamServer((CONF.ofp_listen_host,
                                       ofp_ssl_listen_port),
                                      datapath_connection_factory,
                                      keyfile=CONF.ctl_privkey,
                                      certfile=CONF.ctl_cert, **ssl_args)
        else:
            server = StreamServer((CONF.ofp_listen_host,
                                   ofp_tcp_listen_port),
                                  datapath_connection_factory)

        # LOG.debug('loop')
        server.serve_forever()
Esempio n. 15
0
 def __init__(self, main_server, listen_info, conn_factory):
     StreamServer.__init__(self, listen_info, conn_factory, backlog=None)
     self.main_server = main_server
     self.logger = main_server.logger
Esempio n. 16
0
 def __init__(self, *args):
     super(GlobalController, self).__init__()
     self.agents = []
     self.server = StreamServer(('0.0.0.0', 10807), self._connection_factory)
Esempio n. 17
0
 def __call__(self):
     print "cliserver socket listening on port: %d" % CLI_SERVER_PORT
     server = StreamServer(('0.0.0.0', CLI_SERVER_PORT), cli_client_factory)
     server.serve_forever()
Esempio n. 18
0
 def __init__(self, *args):
     super(Server, self).__init__()
     self.clients = {}  #client = controller
     self.server = StreamServer(('0.0.0.0', 8888), self._connect)
     self.topo = {}
    def server_loop(self):
        server = StreamServer(('::', BGP_TCP_PORT), self.handler)

        LOG.info('BGP server starting...')
        server.serve_forever()
Esempio n. 20
0
    def server_loop(self):

        server = StreamServer(('::', BGP_TCP_PORT), self.handler)

        print "Starting server..."
        server.serve_forever()
Esempio n. 21
0
class GlobalController(object):
    def __init__(self, *args):
        super(GlobalController, self).__init__()
        self.agents = {}
        self.server = StreamServer(('0.0.0.0', 10807),
                                   self._connection_factory)
        self.cross_domain_links = [
        ]  # ex: [{src: {dpid: 4, port: 3}, dst: {dpid: 1, port: 1} }]
        self.hosts = {}  # host -> domain number

    def _connection_factory(self, socket, address):
        print 'connected socket:%s address:%s' % (socket, address)

        with contextlib.closing(GlobalAgent(socket, address)) as agent:
            agent.global_ctrn = self
            agent_id = len(self.agents)

            while agent_id in self.agents:
                agent_id = (agent_id + 1) % MAX_AGENTS

            agent.set_agent_id(agent_id)
            self.agents[agent_id] = agent
            agent.serve()
            LOG.info('Remove agent %d', agent_id)
            del self.agents[agent_id]

    def start(self):

        LOG.info('Waiting for connection.....')
        self.server.serve_forever()

    def print_agents_status(self):

        for agent in self.agents:
            print "%s:%s" % (
                agent.address,
                agent.__str__(),
            )

    def add_cross_domain_link(self, src, dst, agent_id):
        src['agent_id'] = agent_id
        link = {'src': src, 'dst': dst}
        link_rev = {'src': dst, 'dst': src}

        # ask for dpid
        msg = json.dumps({'cmd': 'ask_dpid', 'dpid': dst['dpid']})
        self.broad_cast(msg)

        for _link in self.cross_domain_links:

            if _link['src']['dpid'] == src['dpid'] and \
               _link['src']['port'] == src['port']:
                _link['src']['agent_id'] = agent_id
                break

            if _link['dst']['dpid'] == src['dpid'] and \
               _link['dst']['port'] == src['port']:
                _link['dst']['agent_id'] = agent_id
                break

        else:
            self.cross_domain_links.append(link)
            self.cross_domain_links.append(link_rev)

    def broad_cast(self, msg):

        for agent in self.agents.itervalues():
            agent.send(msg)

    def get_route(self, dst_host, agent):
        '''
            dst_host: mac address
            agent: source domain(lc) agent
        '''

        if dst_host not in self.hosts:
            msg = json.dumps({
                'cmd': 'route_result',
                'dpid': -1,
                'port': -1,
                'host': dst_host
            })
            LOG.debug('Unknown host %s', dst_host)
            agent.send(msg)
            return

        # get source and destination
        # from a? to a? (cross doamin)
        dst_agent = self.hosts[dst_host]
        src_agent_id = agent.agent_id
        src = 'a%d' % (src_agent_id, )
        dst = 'a%d' % (dst_agent.agent_id, )

        # generate link between agents
        links = self._get_agent_links()

        # generate graph
        g = nx.Graph()
        g.add_edges_from(links)

        path = []
        if nx.has_path(g, src, dst):
            path = nx.shortest_path(g, src, dst)

        # we only need first two element and get output port
        glink = self._get_agent_link(path[0], path[1])

        # find output dpid and port
        output_dpid = glink['src']['dpid']
        output_port = glink['src']['port']

        # send route result
        msg = json.dumps({
            'cmd': 'route_result',
            'dpid': output_dpid,
            'port': output_port,
            'host': dst_host
        })
        LOG.debug('send route result to agent %d, %d:%d %s', agent.agent_id,
                  output_dpid, output_port, dst_host)
        agent.send(msg)

    def _get_agent_link(self, src, dst):
        # convert a? to ?
        src_agent_id = int(src[1:])
        dst_agent_id = int(dst[1:])

        for glink in self.cross_domain_links:
            src = glink['src']
            dst = glink['dst']
            if src['agent_id'] == src_agent_id and \
               dst['agent_id'] == dst_agent_id:
                return glink

        return None

    def _get_agent_links(self):
        '''
            link: ('a1', 'a2')
        '''
        links = []

        for glink in self.cross_domain_links:
            src = glink['src']
            dst = glink['dst']

            if 'agent_id' in src and 'agent_id' in dst:
                src = 'a%d' % (src['agent_id'], )
                dst = 'a%d' % (dst['agent_id'], )
                links.append((src, dst))

        return links

    def response_host(self, host, agent):
        '''
            actually, it use for get route
        '''
        self.hosts[host] = agent
        LOG.debug('Add host %s to self.hosts', host)

    def response_dpid(self, dpid, agent_id):

        for link in self.cross_domain_links:

            if link['src']['dpid'] == dpid:
                link['src']['agent_id'] = agent_id

            if link['dst']['dpid'] == dpid:
                link['dst']['agent_id'] = agent_id
Esempio n. 22
0
    def server_loop(self):
        server = StreamServer(('::', BGP_TCP_PORT), self.handler)

        LOG.info('BGP server starting...')
        server.serve_forever()
Esempio n. 23
0
class GlobalController(object):

    def __init__(self, *args):
        super(GlobalController, self).__init__()
        self.agents = []
        self.server = StreamServer(('0.0.0.0', 10807), self._connection_factory)

    def _find_free_agent(self, busy_agent):
        '''
        find free agent
        rule:
            less loading score
            less switch control
        '''
        free_agent = None
        agents = sorted(self.agents, key=lambda x: (x.load_score, x.controlled_switch))

        for agent in agents:

            if agent.load_score < THRESHOLD and agent is not busy_agent:
                free_agent = agent
                break

        return free_agent


    def _balance_agents(self, busy_agent, free_agent):
        '''
        move one switch from busy to free
        '''
        # find one dpid for move
        for dpid in busy_agent.dpid_to_role:

            if busy_agent.dpid_to_role[dpid] == ROLE_MASTER and dpid in free_agent.dpid_to_role:
                # move it
                # TODO: not finish.
                pass
                





    def _serve_loop(self):
        # calculate load for each agent and send role to them.
        while True:

            self.print_agents_status()

            for agent in self.agents:

                if not agent.is_active:
                    self.agents.remove(agent)

                # local controller is overloaded
                free_agent = None

                if agent.load_score > THRESHOLD:
                    free_agent = self._find_free_agent(agent)

                if free_agent != None:
                    # move some switch to free agent
                    self._balance_agents(agent, free_agent)

            hub.sleep(1)

    def _connection_factory(self, socket, address):
        print('connected socket:%s address:%s', socket, address)

        with contextlib.closing(GlobalAgent(socket, address)) as agent:
            self.agents.append(agent)
            agent.serve()

    def start(self):
        thr = hub.spawn(self._serve_loop)
        print 'Waiting for connection.....'
        self.server.serve_forever()
        
        hub.joinall([thr])

    def print_agents_status(self):

        for agent in self.agents:
            print "%s:%s" % (agent.address, agent.__str__(), )
Esempio n. 24
0
class GlobalController(object):

    def __init__(self, *args):
        super(GlobalController, self).__init__()
        self.agents = {}
        self.server = StreamServer(('0.0.0.0', 10807), self._connection_factory)
        self.cross_domain_links = [] # ex: [{src: {dpid: 4, port: 3}, dst: {dpid: 1, port: 1} }]
        self.hosts = {} # host -> domain number


    def _connection_factory(self, socket, address):
        print 'connected socket:%s address:%s' % (socket, address)

        with contextlib.closing(GlobalAgent(socket, address)) as agent:
            agent.global_ctrn = self
            agent_id = len(self.agents)

            while agent_id in self.agents:
                agent_id = (agent_id + 1) % MAX_AGENTS

            agent.set_agent_id(agent_id)
            self.agents[agent_id] = agent
            agent.serve()
            LOG.info('Remove agent %d', agent_id)
            del self.agents[agent_id]


    def start(self):
        
        LOG.info('Waiting for connection.....')
        self.server.serve_forever()

    def print_agents_status(self):

        for agent in self.agents:
            print "%s:%s" % (agent.address, agent.__str__(), )

    def add_cross_domain_link(self, src, dst, agent_id):
        src['agent_id'] = agent_id
        link = {'src': src, 'dst': dst}
        link_rev = {'src': dst, 'dst': src}

        # ask for dpid
        msg = json.dumps({
            'cmd': 'ask_dpid',
            'dpid': dst['dpid']
            })
        self.broad_cast(msg)

        for _link in self.cross_domain_links:

            if _link['src']['dpid'] == src['dpid'] and \
                _link['src']['port'] == src['port']:
                _link['src']['agent_id'] = agent_id
                break

            if _link['dst']['dpid'] == src['dpid'] and \
                _link['dst']['port'] == src['port']:
                _link['dst']['agent_id'] = agent_id
                break

        else:
            self.cross_domain_links.append(link)
            self.cross_domain_links.append(link_rev)
        

            

    def broad_cast(self, msg):

        for agent in self.agents.itervalues():
            agent.send(msg)

    def get_route(self, dst_host, agent):
        '''
            dst_host: mac address
            agent: source domain(lc) agent
        '''

        if dst_host not in self.hosts:
            msg = json.dumps({
                'cmd': 'route_result',
                'dpid': -1,
                'port': -1,
                'host': dst_host
                })
            LOG.debug('Unknown host %s', dst_host)
            agent.send(msg)
            return

        
        # get source and destination
        # from a? to a? (cross doamin)
        dst_agent = self.hosts[dst_host]
        src_agent_id = agent.agent_id
        src = 'a%d' % (src_agent_id, )
        dst = 'a%d' % (dst_agent.agent_id, )

        # generate link between agents
        links = self._get_agent_links()

        # generate graph
        g = nx.Graph()
        g.add_edges_from(links)

        path = []
        if nx.has_path(g, src, dst):
            path = nx.shortest_path(g, src, dst)

        # we only need first two element and get output port
        glink = self._get_agent_link(path[0], path[1])

        # find output dpid and port
        output_dpid = glink['src']['dpid']
        output_port = glink['src']['port']

        # send route result
        msg = json.dumps({
            'cmd': 'route_result',
            'dpid': output_dpid,
            'port': output_port,
            'host': dst_host
        })
        LOG.debug('send route result to agent %d, %d:%d %s', 
                 agent.agent_id, output_dpid,
                 output_port, dst_host)
        agent.send(msg)


    def _get_agent_link(self, src, dst):
        # convert a? to ?
        src_agent_id = int(src[1:])
        dst_agent_id = int(dst[1:])

        for glink in self.cross_domain_links:
            src = glink['src']
            dst = glink['dst']
            if src['agent_id'] == src_agent_id and \
                dst['agent_id'] == dst_agent_id:
                return glink

        return None

    def _get_agent_links(self):
        '''
            link: ('a1', 'a2')
        '''
        links = []

        for glink in self.cross_domain_links:
            src = glink['src']
            dst = glink['dst']

            if 'agent_id' in src and 'agent_id' in dst:
                src = 'a%d' % (src['agent_id'], )
                dst = 'a%d' % (dst['agent_id'], )
                links.append((src, dst))

        return links


    def response_host(self, host, agent):
        '''
            actually, it use for get route
        '''
        self.hosts[host] = agent
        LOG.debug('Add host %s to self.hosts', host)


    def response_dpid(self, dpid, agent_id):

        for link in self.cross_domain_links:

            if link['src']['dpid'] == dpid:
                link['src']['agent_id'] = agent_id

            if link['dst']['dpid'] == dpid:
                link['dst']['agent_id'] = agent_id
Esempio n. 25
0
 def start(self):
     super(BgpMonitor, self).start()
     return hub.spawn(StreamServer(ADDR, self.handler).serve_forever)
Esempio n. 26
0
 def __init__(self, *args):
     super(GlobalController, self).__init__()
     self.agents = {}
     self.server = StreamServer(('0.0.0.0', 10807), self._connection_factory)
     self.cross_domain_links = [] # ex: [{src: {dpid: 4, port: 3}, dst: {dpid: 1, port: 1} }]
     self.hosts = {} # host -> domain number
Esempio n. 27
0
 def __call__(self):
     print "cliserver socket listening on port: %d" % CLI_SERVER_PORT
     server=StreamServer(('0.0.0.0', CLI_SERVER_PORT), cli_client_factory)
     server.serve_forever()
Esempio n. 28
0
 def __init__(self, main_server, listen_info, conn_factory):
     StreamServer.__init__(self, listen_info, conn_factory, backlog=None)
     self.main_server = main_server
     self.logger = main_server.logger
Esempio n. 29
0
    def start(self):
        super(BMPStation, self).start()

        return hub.spawn(
            StreamServer((SERVER_HOST, SERVER_PORT), self.loop).serve_forever)