コード例 #1
0
ファイル: test_L2tpv3API.py プロジェクト: hujiangyi/or
    def test_handleStatsQuery(self):
        cmd = l2tpMsg.L2tpCommandReq()
        cmd.cmd = l2tpMsg.STATS_INFO
        msg = self.api._handleMsg(cmd)
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = None
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.l2tp_hal_client = None
        print msg

        global_dispatcher = Dispatcher()
        dispatcher = L2tpv3Dispatcher.L2tpv3Dispatcher(global_dispatcher,
                                                       "127.0.0.1", False,
                                                       None)
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = dispatcher
        dispatcher.stats.exception = 1
        dispatcher.stats.zmq_error = 1
        dispatcher.stats.error = 1
        # setup the halclient
        hal_client = L2tpHalClient("L2TP_HAL_CLIENT",
                                   "the HAL client of L2TP feature", "1.0",
                                   (3078, ), global_dispatcher)
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.l2tp_hal_client = hal_client
        hal_client.stats.exception = 10
        msg = self.api._handleMsg(cmd)
        print msg
        hal_client.stats = None
コード例 #2
0
ファイル: test_L2tpv3API.py プロジェクト: hujiangyi/or
    def test_A2__handleConnectionQuery_connID_isin_connDB(self):
        """(remoteAddr, connID) is in connectionDb Create a connection.

        Result: success.

        """
        # Create a connection
        global_dispatcher = Dispatcher()
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress = '127.0.0.1'
        dispatcher = L2tpv3Dispatcher.L2tpv3Dispatcher(
            global_dispatcher,
            L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress,
            create_global_listen=False)

        self.dispatcher = L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = dispatcher
        self.connection = L2tpv3Connection.L2tpConnection(
            9527, 21203, "127.0.0.1")

        # Create a msg
        cmd = l2tpMsg.L2tpCommandReq()
        cmd.cmd = l2tpMsg.CONNECTION_INFO

        # connection is in local connection DB
        para = l2tpMsg.ConnectionPara()

        # Get addr and connID invoke connection
        para.remoteAddr = self.connection.remoteAddr
        para.connectionID = self.connection.localConnID
        para.localAddr = L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress

        cmd.conn.MergeFrom(para)
        msg = self.api._handleMsg(cmd)
        # SUCCESS = 1
        self.assertEqual(msg.rsp, 1)
コード例 #3
0
ファイル: test_l2tp2Daemon.py プロジェクト: hujiangyi/or
    def CreateConnection(self, RemoteAddr):
        dispatcher = L2tpv3Dispatcher.L2tpv3Dispatcher(
            self.LocalAddr, createGlobalListen=False)
        dispatcher = L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = dispatcher
        self.dispatcher = dispatcher

        # we need to create connection
        connection = L2tpv3Connection.L2tpConnection(0, 0, RemoteAddr)
        self.connection = connection

        # Initiate SCCRQ connection request message
        connection.localRequest(RemoteAddr)

        processStep(dispatcher)

        # Validate if FSM current state is established

        if L2tpFsm.L2tpv3ConnectionFsm.StateEstablished != connection.fsm.current:
            self.logger.info(
                "FSM current state is not established,current state is:%s" %
                (connection.fsm.current))
            # self.fail("Connection is not establshed!!!")

        else:
            self.logger.info("Connection is established successfully")
コード例 #4
0
    def __init__(self, simulate_mode=False, agent_id=agent.ProcessAgent.AGENTTYPE_L2TP):

        super(L2tpAgent, self).__init__(agent_id)
        # The follow code is used to initialize l2tp
        # get the l2tp configuration path

        dispatcher = self.dispatcher
        l2tp_dispatcher = L2tpv3Dispatcher.L2tpv3Dispatcher(
            dispatcher,
            local_addr=None,
            # since we don't create global listen, set it to None
            create_global_listen=False)
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = l2tp_dispatcher

        # setup the halclient
        hal_client = L2tpHalClient("L2TP_HAL_CLIENT",
                                   "the HAL client of L2TP feature",
                                   "1.0", tuple(L2tpHalClient.notification_list.keys()), dispatcher,
                                   L2tpHalClient.supportmsg_list)
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.l2tp_hal_client = hal_client
        hal_client.start(l2tp_dispatcher.receive_hal_message)

        if L2tpv3GlobalSettings.L2tpv3GlobalSettings.l2tp_hal_client:
            self.logger.info("setup l2tp hal client successfully")

        # Construct the API transport path
        ApiPath = L2tpv3GlobalSettings.L2tpv3GlobalSettings.APITransportPath
        api = L2tpv3API.L2tpv3API(ApiPath)
        l2tp_dispatcher.register_zmq(api)

        self.l2tp_dispatcher = l2tp_dispatcher

        # the l2tp connection which will be checked, the schema is as follows:
        # (local_addr, remote_addr): {
        #   "status" : UP/DOWN
        #   "lastChangeTime": time()
        #   "id":core id
        # }
        self.l2tp_status = dict()

        self.register_poll_timer(1, self._check_l2tp_status_callback, None)
        self.counter = 0

        # setup link sock to get the link state change
        self.linksock = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, socket.NETLINK_ROUTE)
        self.linksock.bind((os.getpid(), self.RTMGRP_LINK))
        self.dispatcher.fd_register(self.linksock.fileno(),
                                    zmq.POLLIN, self.process_link_status)

        self.pingSocket = None
        self.dispatcher.timer_register(self.ARP_LEARN_TIME,
                                       self.learn_arp_us_l2tp_session,
                                       None,
                                       timer_type=DpTimerManager.TIMER_REPEATED)
コード例 #5
0
ファイル: test_L2tpv3API.py プロジェクト: hujiangyi/or
    def test_B3__handleSessionQuery_localsessionID_isin_AND_connID_isNotin_DB(
            self):
        """No connection and create session.

        Check: Cannot find the connection
        in local connection DB

        Result: Failure.

        """
        # Create a connection for connection ID
        global_dispatcher = Dispatcher()
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress = '127.0.0.1'
        dispatcher = L2tpv3Dispatcher.L2tpv3Dispatcher(
            global_dispatcher,
            L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress,
            create_global_listen=False)

        self.dispatcher = L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = dispatcher
        self.connection = L2tpv3Connection.L2tpConnection(
            10202, 1719, "127.0.0.1")

        # Create a session for sessionID
        session = L2tpv3Session.L2tpv3Session(randint(1, 0xFFFFFFFF), 0,
                                              "sender", self.connection)
        self.connection.addSession(session)
        session.LocalRequest()

        cmd = l2tpMsg.L2tpCommandReq()
        cmd.cmd = l2tpMsg.SESSION_INFO

        sess = cmd.sess
        conn = sess.conn

        # connectionID is not in local connection DB
        conn.remoteAddr = '127.0.0.1'
        # Connection is not in connection DB && return
        conn.connectionID = 1652974642

        # Local session is in connection session
        sess.localSessionID = session.localSessionId

        msg = self.api._handleMsg(cmd)

        # FAILIURE = 2
        self.assertEqual(msg.rsp, 2)
        self.assertEqual(msg.retMsg,
                         "Cannot find the connection in local connection DB")
コード例 #6
0
ファイル: test_L2tpv3API.py プロジェクト: hujiangyi/or
    def test_B4__handleSessionQuery_localsessionID_AND_connID_isin_DB(self):
        """Create connection and session.

        Result: success.

        """
        # Create a connection for connectionID
        global_dispatcher = Dispatcher()
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress = '127.0.0.1'
        dispatcher = L2tpv3Dispatcher.L2tpv3Dispatcher(
            global_dispatcher,
            L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress,
            create_global_listen=False)

        self.dispatcher = L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = dispatcher
        self.connection = L2tpv3Connection.L2tpConnection(
            3110, 7222, "127.0.0.1")

        # Create a session for sessionID
        session = L2tpv3Session.L2tpv3Session(randint(1, 0xFFFFFFFF), 0,
                                              "sender", self.connection)
        self.connection.addSession(session)
        session.LocalRequest()

        cmd = l2tpMsg.L2tpCommandReq()
        cmd.cmd = l2tpMsg.SESSION_INFO

        sess = cmd.sess
        conn = sess.conn

        # connection is in local connection DB
        conn.remoteAddr = self.connection.remoteAddr
        conn.localAddr = L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress
        conn.connectionID = self.connection.localConnID

        # Local session is in connection session
        sess.localSessionID = session.localSessionId

        msg = self.api._handleMsg(cmd)
        print msg

        # Success = 1
        self.assertEqual(msg.rsp, 1)
コード例 #7
0
ファイル: test_L2tpv3API.py プロジェクト: hujiangyi/or
    def test_B2__handleSessionQuery_sessID_isNotin_AND_connID_isin_DB(self):
        """Create connection and no session.

        Check: Cannot find the session in
        local connection DB

        Result: FAILURE.

        """
        # Create a connection for connection ID
        global_dispatcher = Dispatcher()
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress = '127.0.0.1'
        dispatcher = L2tpv3Dispatcher.L2tpv3Dispatcher(
            global_dispatcher,
            L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress,
            create_global_listen=False)

        self.dispatcher = L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = dispatcher
        self.connection = L2tpv3Connection.L2tpConnection(
            7097, 8208, "127.0.0.1")

        cmd = l2tpMsg.L2tpCommandReq()
        cmd.cmd = l2tpMsg.SESSION_INFO

        sess = cmd.sess
        conn = sess.conn

        # connection is in local connection DB
        conn.remoteAddr = self.connection.remoteAddr
        conn.localAddr = L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress
        conn.connectionID = self.connection.localConnID

        # Local session is not in connection session
        sess.localSessionID = 2406980214

        msg = self.api._handleMsg(cmd)

        # FAILIURE = 2
        self.assertEqual(msg.rsp, 2)
        self.assertEqual(msg.retMsg,
                         "Cannot find the session in local connection DB")
コード例 #8
0
    else:
        if len(sys.argv) > 2 and Convert.is_valid_ipv6_address(sys.argv[2]):
            RemoteIPAddress = sys.argv[2]
        else:
            RemoteIPAddress = "::1"
        if len(sys.argv) > 3 and Convert.is_valid_ipv6_address(sys.argv[3]):
            LocalIPAddress = sys.argv[3]
        else:
            LocalIPAddress = "::1"

    print "RemoteIPAddress ", RemoteIPAddress
    print "LocalIPAddress ", LocalIPAddress

    global_dispatcher = Dispatcher()
    l2tp_dispatcher = L2tpv3Dispatcher.L2tpv3Dispatcher(global_dispatcher,
                                                        LocalIPAddress,
                                                        create_global_listen=False)
    L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = l2tp_dispatcher

    l2tp_dispatcher.register_remote_address(RemoteIPAddress)

    # we need to create connection
    connection = L2tpv3Connection.L2tpConnection(
        0, 0, RemoteIPAddress, LocalIPAddress)

    def create_session_and_fire(connection):

        fsm = connection.fsm

        if fsm.fsm.current != 'established':
            return