def show_l2tp_session_link(self): """'show l2tp session' cabllback.""" # get all connections msg = l2tpMsg.L2tpCommandReq() msg.cmd = l2tpMsg.SYSTEM_INFO total_channel = 0 total_session = 0 ret = self.send(msg) if not ret: print "Send message to L2tp API failed" return else: systemResult = self.recv() sessionInfo = list() for connInfo in systemResult.sysInfo.conns: session_info_req = l2tpMsg.L2tpCommandReq() query_sess_msg = session_info_req.sess query_conn = query_sess_msg.conn query_conn.remoteAddr = connInfo.remoteAddr query_conn.localAddr = connInfo.localAddr query_conn.connectionID = connInfo.connectionID total_channel += 1 total_session += len(connInfo.localSessionID) for localSessionId in connInfo.localSessionID: query_sess_msg.localSessionID = localSessionId session_info_req.cmd = l2tpMsg.SESSION_INFO ret = self.send(session_info_req) if not ret: print "Send session query message to L2tp API failed" return session_info_rsp = self.recv() # get the correct result session_line = L2tpSessionLine() session_line.state = session_info_rsp.sessInfo.currentState session_line.local_session_id = session_info_rsp.sessInfo.localSessionID session_line.remote_session_id = session_info_rsp.sessInfo.remoteSessionID session_line.last_change_time = session_info_rsp.sessInfo.lastchangetime session_line.local_connection_id = session_info_rsp.sessInfo.connectionID session_line.type = session_info_rsp.sessInfo.sessionType session_line.link_status = "UP" if session_info_rsp.sessInfo.status else "DOWN" session_line.remote_connection_id = connInfo.remoteConnectionID session_line.remote_addr = connInfo.remoteAddr session_line.local_addr = connInfo.localAddr session_line.host_name = connInfo.hostname sessionInfo.append(session_line) print "L2TP Tunnel Information Total tunnels %d" % total_channel + " sessions %d" % total_session print L2tpSessionLine.HEADER_LINK # "LocID RemID LocTunID RemTunID State Type Last Chg" for session_line in sessionInfo: print "%08x " % session_line.local_session_id, \ "%08x " % session_line.remote_session_id, \ "%08x " % session_line.local_connection_id, \ "%08x " % session_line.remote_connection_id, \ "%-5s" % L2tpSessionLine.state_str[session_line.state], \ "%-10s" % session_line.type,\ "%-4s" % session_line.link_status,\ "%-s" % session_line.last_change_time del sessionInfo[:]
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)
def test_A1__handleConnectionQuery_connIDisNotin_connDB(self): """(remoteAddr, connID) is not in connectionDb Not create a connection. Check: Cannot find the connection in local connection DB Result: FAILURE. """ cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.CONNECTION_INFO para = l2tpMsg.ConnectionPara() # Create invalid addr and connID para.remoteAddr = "127.0.0.1" para.connectionID = 0xA90A0853 para.localAddr = L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress cmd.conn.MergeFrom(para) msg = self.api._handleMsg(cmd) # FAILURE = 2 self.assertEqual(msg.rsp, 2) self.assertEqual(msg.retMsg, "Cannot find the connection in local connection DB")
def _processMcastinfo(socket): cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.MCAST_INFO data = cmd.SerializeToString() socket.send(data) data = socket.recv() msg = l2tpMsg.L2tpCommandRsp() msg.ParseFromString(data) print(msg)
def _processUnbind(socket, unbindPara): cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.UNBIND_LOCAL_ADDRESS cmd.bindIP.localIP = unbindPara[0] data = cmd.SerializeToString() socket.send(data) data = socket.recv() msg = l2tpMsg.L2tpCommandRsp() msg.ParseFromString(data) print(msg)
def _processConnectionQuery(socket, connection): cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.CONNECTION_INFO para = l2tpMsg.ConnectionPara() para.remoteAddr = connection[0] para.connectionID = int(connection[1]) cmd.conn.MergeFrom(para) data = cmd.SerializeToString() socket.send(data) data = socket.recv() msg = l2tpMsg.L2tpCommandRsp() msg.ParseFromString(data) print(msg)
def _processDebug(socket, debugPara): cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.DEBUG debug = cmd.debug debug.module = debugPara[0] debug.level = debugPara[1] data = cmd.SerializeToString() socket.send(data) data = socket.recv() msg = l2tpMsg.L2tpCommandRsp() msg.ParseFromString(data) print(msg)
def test_D0__handleTest(self): cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.TEST cmd.test.para1 = "this is test para1" cmd.test.para2 = "this is test para2" msg = self.api._handleMsg(cmd) self.assertEqual(msg.rsp, l2tpMsg.SUCCESS) # add a fail case cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.TEST msg = self.api._handleTest(cmd) self.assertEqual(msg.rsp, l2tpMsg.FAILURE)
def test_B1__handleSessionQuery_connID_AND_sessID_isNotin_DB(self): """No connection and no session. Check: Cannot find the connection in local connection DB Result: FAILURE. """ # Create a msg cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.SESSION_INFO sess = cmd.sess conn = sess.conn conn.remoteAddr = '127.0.0.1' conn.localAddr = L2tpv3GlobalSettings.L2tpv3GlobalSettings.LocalIPAddress # Connection is not in connection DB conn.connectionID = 1652974642 # Local session is not in connection session # connection ------> session sess.localSessionID = 2406980214 msg = self.api._handleMsg(cmd) # FAILIURE = 2 self.assertEqual(msg.rsp, 2) self.assertEqual(msg.retMsg, "Cannot find the connection in local connection DB")
def show_l2tp_mcast(self): """'show l2tp multicast' cabllback.""" # msg = t_CliMessage() msg = l2tpMsg.L2tpCommandReq() msg.cmd = l2tpMsg.MCAST_INFO ret = self.send(msg) data = [] if ret: rsp = self.recv() for mcastInfo in rsp.mcast_info.mcastInfoList: mcast_line = L2tpMcastList() mcast_line.Grp = mcastInfo.grp mcast_line.Src = mcastInfo.src mcast_line.LocalIp = mcastInfo.local_ip mcast_line.interface = mcastInfo.interface mcast_line.status = mcastInfo.status mcast_line.last_change_time = mcastInfo.lastchange for session in mcastInfo.session: mcast_line.Session.append(session) item = (mcast_line.interface, mcast_line.LocalIp, mcast_line.Grp, mcast_line.Src, mcast_line.status, str(len(mcast_line.Session)), mcast_line.last_change_time) data.append(item) del mcast_line printval = { "header": L2tpMcastList.HEADER, "data": data} output = self.format_print(printval) print output del data[:] else: self.cli.log.error("send msg to module %d fail" % cli_def.L2TP_IPC)
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
def test_D2__handleConnectionTeardown(self): socket = self._createZmqInstance() cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.CONNECTION_TEARDOWN msg = self.api._handleMsg(cmd) self.assertEqual(msg.rsp, l2tpMsg.FAILURE)
def test_C2__handleDebug_is_debugmsg_AND_isin_system_and_isin_map(self): """Para: OK Can map the level name to logging level. Result: Success. """ debugPara = ['debug', 'info', 'warn', 'error'] allClasses = AddLoggerToClass.moduleMapping allClasses_keys = allClasses.keys() for level_value in debugPara: for module_value in allClasses_keys: cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.DEBUG debug = cmd.debug # Valid Para debug.module = module_value debug.level = level_value msg = self.api._handleMsg(cmd) # Success = 1 self.assertEqual(msg.rsp, 1)
def _processSysinfoQuery(socket): cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.SYSTEM_INFO data = cmd.SerializeToString() socket.send(data) data = socket.recv() msg = l2tpMsg.L2tpCommandRsp() msg.ParseFromString(data) print(msg) cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.STATS_INFO data = cmd.SerializeToString() socket.send(data) data = socket.recv() msg = l2tpMsg.L2tpCommandRsp() msg.ParseFromString(data) print(msg)
def show_l2tp_tunnel(self): """'show l2tp tunnel' cabllback.""" msg = l2tpMsg.L2tpCommandReq() msg.cmd = l2tpMsg.SYSTEM_INFO ret = self.send(msg) total_channel = 0 total_session = 0 if not ret: print "Send message to L2tp API failed" return else: connectionInfo = list() systemResult = self.recv() for connInfo in systemResult.sysInfo.conns: connection_line = L2tpConnectionLine() connection_line.remoteAddr = connInfo.remoteAddr connection_line.localAddr = connInfo.localAddr connection_line.connectionID = connInfo.connectionID connection_line.remote_connection_id = connInfo.remoteConnectionID connection_line.state = connInfo.currentState connection_line.host_name = connInfo.hostname connection_line.session_count = len(connInfo.localSessionID) connectionInfo.append(connection_line) total_channel += 1 total_session += connection_line.session_count print "L2TP Tunnel Information Total tunnels %d" % total_channel + " sessions %d" % total_session # "LocTunID RemTunID Remote Name State Remote Address SessCount" print_list = list() print_list.append(L2tpConnectionLine.HEADER) max_len = [len(a) for a in L2tpConnectionLine.HEADER] for connection_line in connectionInfo: dic = {} dic["LocTunID"] = str(hex(connection_line.connectionID))[2:] dic["RemTunID"] = str(hex(connection_line.remote_connection_id))[2:] dic["Remote Name"] = connection_line.host_name dic["State"] = L2tpConnectionLine.state_str[connection_line.state] dic["Remote Address"] = connection_line.remoteAddr dic["Local"] = connection_line.localAddr dic["Sessn Count"] = str(connection_line.session_count) para_tuple = (dic["LocTunID"], dic["RemTunID"], dic["Remote Name"], dic["State"], self.format_ipv6(dic["Remote Address"]), self.format_ipv6(dic["Local"]), dic["Sessn Count"]) print_list.append(para_tuple) max_len = [max_len[i] if max_len[i] > len(para_tuple[i]) else len(para_tuple[i]) for i in range(len(max_len))] generate_format = "" for len_str in max_len: generate_format += "%-" + str(len_str + 2) + "s" for field in print_list: print generate_format % field del connectionInfo[:]
def show_l2tp_stats(self): msg = l2tpMsg.L2tpCommandReq() msg.cmd = l2tpMsg.STATS_INFO ret = self.send(msg) if ret: rsp = self.recv() print rsp else: self.cli.log.error("send msg to module %d fail" % cli_def.L2TP_IPC)
def _processSessionQuery(socket, session, connection): cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.SESSION_INFO sess = cmd.sess conn = sess.conn conn.remoteAddr = connection[0] conn.connectionID = int(connection[1]) sess.localSessionID = int(session[0]) data = cmd.SerializeToString() socket.send(data) data = socket.recv() msg = l2tpMsg.L2tpCommandRsp() msg.ParseFromString(data) print(msg)
def show_l2tp(self): """'show l2tp' cabllback.""" msg = l2tpMsg.L2tpCommandReq() msg.cmd = l2tpMsg.SYSTEM_INFO ret = self.send(msg) print msg if ret: rsp = self.recv() print rsp else: self.cli.log.error("send msg to module %d fail" % cli_def.L2TP_IPC)
def test__handleMcastInfo(self): cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.MCAST_INFO msg = self.api._handleMsg(cmd) self.assertEqual(msg.rsp, l2tpMsg.SUCCESS) session_1 = ("127.0.0.1", "127.0.0.1", 1, 1) session_2 = ("127.0.0.1", "127.0.0.1", 2, 2) session_3 = ("127.0.0.1", "127.0.0.1", 3, 3) address = ("127.0.0.1", "5.5.5.1", "229.1.1.255", 0) mcast = Mcast(address=address) mcast.join(session_1) time.sleep(0.1) mcast.join(session_2) msg = self.api._handleMsg(cmd) print msg self.assertEqual(msg.rsp, l2tpMsg.SUCCESS) Mcast.McastDb[("127.0.0.1", "5.5.5.1", "225.1.1.255", 0)] = "test" msg = self.api._handleMsg(cmd) print msg data = [] print "********" for mcastInfo in msg.mcast_info.mcastInfoList: mcast_line = L2tpMcastList() mcast_line.Grp = mcastInfo.grp mcast_line.Src = mcastInfo.src mcast_line.LocalIp = mcastInfo.local_ip mcast_line.interface = mcastInfo.interface mcast_line.status = mcastInfo.status mcast_line.last_change_time = mcastInfo.lastchange for session in mcastInfo.session: mcast_line.Session.append(session) print mcast_line.Grp, mcast_line.Src, mcast_line.LocalIp, mcast_line.LocalIp, mcast_line.interface,\ mcast_line.status, mcast_line.last_change_time, len(mcast_line.Session) item = (mcast_line.interface, mcast_line.LocalIp, mcast_line.Grp, mcast_line.Src, mcast_line.status, str(len(mcast_line.Session)), mcast_line.last_change_time) data.append(item) del mcast_line printval = {"header": L2tpMcastList.HEADER, "data": data} output = testL2tpv3API.format_print(printval) print output del data[:] self.assertEqual(msg.rsp, l2tpMsg.SUCCESS) Mcast.McastDb.pop(("127.0.0.1", "5.5.5.1", "225.1.1.255", 0)) for key in Mcast.McastDb.keys(): Mcast.McastDb[key].close()
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")
def test_Z__handleSystemInfo(self): """ cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.SYSTEM_INFO Get system info """ cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.SYSTEM_INFO msg = self.api._handleMsg(cmd) print "\n------------handleSystemInfo--START------------\n", str(msg) print "\n------------handleSystemInfo--END------------\n" # SUCCESS = 1 self.assertEqual(msg.rsp, 1)
def recvMsg(self, module, timeout=None): """ recv ipc from other module """ if module in self.cli.ipc and self.cli.ipc[module]: try: bin = self.cli.ipc[module].recv() except KeyboardInterrupt: self.cli.log.error("receive KeyboardInterrupt") return None msg = l2tpMsg.L2tpCommandRsp() msg.ParseFromString(bin) return msg else: self.cli.log.error("Cannot receive msg since module %d socket is NULL" % module) return None
def test_C2__handleDebug_is_debugmsg_AND_isin_system_and_isnotin_map(self): """Para: debug.module is valid and debug.level is invalid. Check: Cannot map the level name to logging level Result: FAILURE. """ # allClasses== ['RemoteSessionID', 'L2tpv3Session', 'CallSerialNumber', # 'Hostname', 'L2tpv3Dispatcher', 'L2tpv3StopCCN', 'PseudowireCapList', # 'L2tpv3Hello', 'l2tpV3TerminatePkt', 'TieBreaker', 'L2tpv3CDN', 'RemoteEndID', # 'GeneralL2tpv3AVP', 'l2tpv3AVP', 'CircuitStatus', 'L2SpecificSublayer', # 'L2tpv3Network', 'PseudowireType', 'ProtocolVersion', 'ResultCode', # 'FrameCapabilities', 'L2tpv3SessionSenderFsm', 'LocalSessionID', 'L2tpv3ZLB', # 'SequencingRequired', 'L2tpv3API', 'ControlMessageAVP', 'L2tpV3Fsm', # 'L2tpv3ConnectionFsm', 'FirmwareRevision', 'L2tpv3Transport', 'VendorName', # 'ReceiveWinSize', 'L2tpv3SessionRecipientFsm', 'RouterID', # 'AssignedControlConnectionID', 'L2tpConnection', 'DataSequencing', # 'L2tpv3APITransport', 'L2tpv3ControlPacket'] # len(allClasses_keys) = 40 allClasses = AddLoggerToClass.moduleMapping allClasses_keys = allClasses.keys() for module_value in allClasses_keys: cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.DEBUG debug = cmd.debug # debug.module is valid debug.module = module_value # debug.level is invalid debug.level = "Not is in levelMapping" msg = self.api._handleMsg(cmd) # FAILIURE = 2 self.assertEqual(msg.rsp, 2) self.assertEqual(msg.retMsg, "Cannot map the level name to logging level")
def test_A0__handleConnectionQuery_isNot_conn_msg(self): """ msg.HasField("conn") = False Check: Cannot find the connection parameter in connection query msg Result: FAILURE """ # Create a msg cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.CONNECTION_INFO msg = self.api._handleMsg(cmd) self.assertEqual(msg.rsp, 2) self.assertEqual( msg.retMsg, "Cannot find the connection parameter in connection query msg")
def test_B0__handleSessionQuery_isNot_sess_msg(self): """ msg.HasField("sess") = False No any para Check: Cannot find the debug parameter in debug msg result: FAILURE """ cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.SESSION_INFO msg = self.api._handleMsg(cmd) # FAILURE = 2 self.assertEqual(msg.rsp, 2) self.assertEqual( msg.retMsg, "Cannot find the session parameter in session query msg")
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)
def test_C0__handleDebug_isNot_debugmsg(self): """ Check: Cannot find the debug parameter in debug msg cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.DEBUG No any para msg.HasField("debug") = False Result: FAILURE """ cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.DEBUG msg = self.api._handleMsg(cmd) # FAILIURE = 2 self.assertEqual(msg.rsp, 2) self.assertEqual(msg.retMsg, "Cannot find the debug parameter in debug msg")
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")
def test_C1__handleDebug_is_debugmsg_AND_isNotin_system(self): """Para is invalid(debug.module and debug.level) Check: Cannot find the debug module in system result: FAILURE. """ cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.DEBUG # Create invalid para debug = cmd.debug debug.module = 'RemoteSessionID is Invalid' debug.level = 'debug is invalid' msg = self.api._handleMsg(cmd) # FAILIURE = 2 self.assertEqual(msg.rsp, 2) self.assertEqual(msg.retMsg, "Cannot find the debug module in system")
def test_bind_local_ip(self): cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.BIND_LOCAL_ADDRESS cmd.bindIP.localIP = "127.0.0.3" msg = self.api._handleMsg(cmd) self.assertEqual(msg.rsp, l2tpMsg.SUCCESS) # not msg.HasField("bindIP") cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.BIND_LOCAL_ADDRESS # cmd.bindIP.localIP = "127.0.0.3" msg = self.api._handleMsg(cmd) self.assertEqual(msg.retMsg, "Cannot find the bindIP parameter in bindIP msg") self.assertEqual(msg.rsp, 2) cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.BIND_LOCAL_ADDRESS cmd.bindIP.localIP = "192.168.0.1" msg = self.api._handleMsg(cmd) # self.assertEqual(msg.retMsg, "Cannot find the bindIP parameter in # bindIP msg") self.assertEqual(msg.rsp, 2) cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.UNBIND_LOCAL_ADDRESS cmd.bindIP.localIP = "127.0.0.3" msg = self.api._handleMsg(cmd) self.assertEqual(msg.rsp, l2tpMsg.SUCCESS) cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.UNBIND_LOCAL_ADDRESS cmd.bindIP.localIP = "127.0.0.1" msg = self.api._handleMsg(cmd) self.assertEqual(msg.rsp, l2tpMsg.FAILURE) # not msg.HasField("bindIP") cmd = l2tpMsg.L2tpCommandReq() cmd.cmd = l2tpMsg.UNBIND_LOCAL_ADDRESS # cmd.bindIP.localIP = "127.0.0.3" msg = self.api._handleMsg(cmd) self.assertEqual(msg.retMsg, "Cannot find the bindIP parameter in bindIP msg") self.assertEqual(msg.rsp, 2)