Exemplo n.º 1
0
    def create_ipv4_ipv6_record(self, test_count=1000):
        sessRec = DepiMcastSessionRecord()
        print "#########: write %s session in db." % (test_count * 2)
        current_time = time.time()
        print "current time is: " + str(
            datetime.datetime.fromtimestamp(current_time))
        for test_session in range(0, test_count):
            sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                              GroupIpAddr="10.79.31.1",
                                              SrcIpAddr="10.90.31.1",
                                              SessionId=test_session + 1)
            test_time = Convert.pack_timestamp_to_string(time.time())

            sessRec.updateDepiMcastSessionData("10.1.1.1", "1.1.1.1",
                                               time.time())
            sessRec.write()
            sessRec.updateDepiMcastSessionKey(IpAddrType=2,
                                              GroupIpAddr="2001::1",
                                              SrcIpAddr="2001::2",
                                              SessionId=test_session + 1)

            sessRec.updateDepiMcastSessionData("2001::1", "2001::1", test_time)
            sessRec.write()
        current_time = time.time()
        print "end time is: " + str(
            datetime.datetime.fromtimestamp(current_time))
        return True
Exemplo n.º 2
0
 def test_updateDepiMcastSessionKey(self):
     sessRec = DepiMcastSessionRecord()
     self.assertIsInstance(sessRec, DepiMcastSessionRecord)
     sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                       GroupIpAddr="10.79.31.1",
                                       SrcIpAddr="10.79.31.1",
                                       SessionId=1)
     self.assertEquals(sessRec.index.IpAddrType, 1)
     self.assertEquals(sessRec.index.SrcIpAddr, "10.79.31.1")
     self.assertEquals(sessRec.index.SessionId, 1)
Exemplo n.º 3
0
 def test_get_all_ipv6(self):
     sessRec = DepiMcastSessionRecord()
     sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                       GroupIpAddr="2001::1",
                                       SrcIpAddr="2001::1",
                                       SessionId=1)
     sessRec.write()
     ret = []
     for ses in sessRec.get_all():
         ret.append(ses)
     self.assertEquals(len(ret), 1)
Exemplo n.º 4
0
    def test_readwrite(self):
        sessRec = DepiMcastSessionRecord()
        sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                          GroupIpAddr="10.79.31.1",
                                          SrcIpAddr="10.79.31.1",
                                          SessionId=1)
        self.assertEquals(sessRec.index.IpAddrType, 1)
        self.assertEquals(sessRec.index.SrcIpAddr, "10.79.31.1")
        self.assertEquals(sessRec.index.SessionId, 1)
        sessRec.write()

        # get_all
        ret = []
        for ses in sessRec.get_all():
            ret.append(ses)
        self.assertEquals(len(ret), 1)

        sessRec = None
        sessRec = DepiMcastSessionRecord()
        sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                          GroupIpAddr="10.79.31.1",
                                          SrcIpAddr="10.79.31.1",
                                          SessionId=1)
        sessRec.read()
        self.assertEquals(sessRec.index.IpAddrType, 1)
        self.assertEquals(sessRec.index.GroupIpAddr, "10.79.31.1")
        self.assertEquals(sessRec.index.SrcIpAddr, "10.79.31.1")
        self.assertEquals(sessRec.index.SessionId, 1)
        self.assertEquals(sessRec.JoinTime, "")
        self.assertEquals(sessRec.LocalLcceIpAddr, "")
        self.assertEquals(sessRec.RemoteLcceIpAddr, "")

        # modify the property
        currtime = Convert.pack_timestamp_to_string(time.time())
        sessRec.JoinTime = currtime
        sessRec.write()
        sessRec.read()
        self.assertEquals(sessRec.index.IpAddrType, 1)
        self.assertEquals(sessRec.index.GroupIpAddr, "10.79.31.1")
        self.assertEquals(sessRec.index.SrcIpAddr, "10.79.31.1")
        self.assertEquals(sessRec.index.SessionId, 1)
        self.assertEquals(sessRec.JoinTime, currtime)
        self.assertEquals(sessRec.LocalLcceIpAddr, "")
        self.assertEquals(sessRec.RemoteLcceIpAddr, "")

        # get_all
        ret = []
        for ses in sessRec.get_all():
            ret.append(ses)
        self.assertEquals(len(ret), 1)
Exemplo n.º 5
0
 def test_invalid_key(self):
     sessRec = DepiMcastSessionRecord()
     sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                       GroupIpAddr="test",
                                       SrcIpAddr="10.90.31.1",
                                       SessionId=0x80010001)
     sessRec.updateDepiMcastSessionData("10.1.1.1", "1.1.1.1", time.time())
     sessRec.write()
     data = config()
     gpb = data.RpdInfo.DepiMcastSession
     item = gpb.add()
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record)
     print gpb[0]
     self.assertEqual(len(data.RpdInfo.DepiMcastSession), 1)
Exemplo n.º 6
0
    def test_performance(self):
        sessRec = DepiMcastSessionRecord()
        test_count = 1000
        print "#########: perfermance test about %s session in store" % test_count
        current_time = time.time()
        print "current time is: " + str(
            datetime.datetime.fromtimestamp(current_time))
        for test_session in range(0, test_count):
            sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                              GroupIpAddr="10.79.31.1",
                                              SrcIpAddr="10.90.31.1",
                                              SessionId=test_session)
            test_time = Convert.pack_timestamp_to_string(time.time())
            sessRec.updateDepiMcastSessionData("10.1.1.1", "1.1.1.1",
                                               test_time)
            sessRec.write()
        print "Write " + str(test_count) + " records need : " + str(
            time.time() - current_time)
        current_time = time.time()
        ret = []
        for record in sessRec.get_next_n(count=test_count):
            ret.append(record)
        self.assertEquals(len(ret), test_count)
        print "get_next_n " + str(test_count) + " records need : " + str(
            time.time() - current_time)

        print "current time is: " + str(
            datetime.datetime.fromtimestamp(time.time()))
        current_time = time.time()
        ret = []
        for record in sessRec.get_next_n(count=20):
            ret.append(record)
        self.assertEquals(len(ret), 20)
        end_time = time.time()
        print "get_next_n " + str(20) + " records need : " + str(end_time -
                                                                 current_time)
        print "End time is: " + str(datetime.datetime.fromtimestamp(end_time))
        self.assertEquals(len(ret), 20)

        current_time = time.time()
        ret = []
        for ses in sessRec.get_all():
            ret.append(ses)
        print "get_next_all " + str(test_count) + " records need : " + str(
            time.time() - current_time)
        self.assertEquals(len(ret), test_count)
Exemplo n.º 7
0
 def test_updateDepiMcastSessionData(self):
     sessRec = DepiMcastSessionRecord()
     sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                       GroupIpAddr="10.79.31.1",
                                       SrcIpAddr="10.79.31.1",
                                       SessionId=1)
     self.assertEquals(sessRec.index.IpAddrType, 1)
     self.assertEquals(sessRec.index.SrcIpAddr, "10.79.31.1")
     self.assertEquals(sessRec.index.SessionId, 1)
     testIP1 = "127.0.0.1"
     testIP2 = "127.0.0.2"
     testTime = Convert.pack_timestamp_to_string(time.time())
     sessRec.updateDepiMcastSessionData(LocalLcceIpAddr=testIP1,
                                        RemoteLcceIpAddr=testIP2,
                                        JoinTime=testTime)
     self.assertEquals(sessRec.LocalLcceIpAddr, testIP1)
     self.assertEquals(sessRec.RemoteLcceIpAddr, testIP2)
     self.assertEquals(sessRec.JoinTime, testTime)
Exemplo n.º 8
0
 def test_no_dup_record(self):
     sessRec = DepiMcastSessionRecord()
     sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                       GroupIpAddr="10.79.31.1",
                                       SrcIpAddr="10.79.31.1",
                                       SessionId=1)
     sessRec.write()
     sessRec = None
     sessRec = DepiMcastSessionRecord()
     sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                       GroupIpAddr="10.79.31.1",
                                       SrcIpAddr="10.79.31.1",
                                       SessionId=1)
     sessRec.write()
     ret = []
     for ses in sessRec.get_all():
         ret.append(ses)
     self.assertEquals(len(ret), 1)
Exemplo n.º 9
0
 def create_ipv4_ipv6_mcast(self, test_count):
     # create test_count records for ipv4 and test_count records for ipv6
     sessRec = DepiMcastSessionRecord()
     for test_session in range(0, test_count):
         sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                           GroupIpAddr="10.79.31.1",
                                           SrcIpAddr="10.79.31.1",
                                           SessionId=test_session)
         sessRec.LocalLcceIpAddr = "10.79.31.2"
         sessRec.RemoteLcceIpAddr = "10.79.31.1"
         sessRec.JoinTime = time.time()
         sessRec.write()
         sessRec.updateDepiMcastSessionKey(IpAddrType=2,
                                           GroupIpAddr="ff15:7079:7468:6f6e:6465:6d6f:6d63:6173",
                                           SrcIpAddr="2001::1",
                                           SessionId=test_session)
         sessRec.LocalLcceIpAddr = "2001::2"
         sessRec.RemoteLcceIpAddr = "2001::1"
         sessRec.JoinTime = time.time()
         sessRec.write()
Exemplo n.º 10
0
    def test_get_next_n(self):
        sessRec = DepiMcastSessionRecord()
        sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                          GroupIpAddr="10.79.31.1",
                                          SrcIpAddr="10.79.31.1",
                                          SessionId=1)
        sessRec.write()
        sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                          GroupIpAddr="10.79.31.1",
                                          SrcIpAddr="10.79.31.1",
                                          SessionId=2)
        sessRec.write()
        sessRec = DepiMcastSessionRecord()
        sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                          GroupIpAddr="10.79.31.1",
                                          SrcIpAddr="10.78.31.1",
                                          SessionId=1)
        sessRec.write()
        sessRec = DepiMcastSessionRecord()
        sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                          GroupIpAddr="10.79.31.1",
                                          SrcIpAddr="10.78.31.1",
                                          SessionId=2)
        sessRec.write()
        print "#########step 1: None key query, return value from the very first record"
        ret = []
        for record in sessRec.get_next_n(key=None, count=2):
            ret.append(record)
        self.assertEquals(len(ret), 2)

        print "#########step 2: key query, request count is larger than db have"
        record = DepiMcastSessionRecord()
        record.updateDepiMcastSessionKey(IpAddrType=1,
                                         GroupIpAddr="10.79.31.1",
                                         SrcIpAddr="10.79.31.1",
                                         SessionId=2)
        test_key = record.index
        ret = []
        for record in sessRec.get_next_n(key=None, count=2):
            ret.append(record)
        self.assertEquals(len(ret), 2)

        print "#########step 3: key query, request key is larger than db have"
        record = DepiMcastSessionRecord()
        record.updateDepiMcastSessionKey(IpAddrType=1,
                                         GroupIpAddr="10.79.31.1",
                                         SrcIpAddr="10.90.31.1",
                                         SessionId=1)
        ret = []
        for record in sessRec.get_next_n(key=None, count=2):
            ret.append(record)
        self.assertEquals(len(ret), 2)
Exemplo n.º 11
0
    def test_recvRpdInfo(self):
        # db support
        # clear db records
        sessRec = DepiMcastSessionRecord()
        sessRec.delete_all()
        sessRec = DepiMcastSessionRecord()
        test_count = 2
        for test_session in range(0, test_count):
            sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                              GroupIpAddr="10.79.31.1",
                                              SrcIpAddr="10.90.31.1",
                                              SessionId=test_session)
            sessRec.JoinTime = time.time()
            sessRec.write()

        print("######test_recvRpdInfo######")
        rcp_msg = t_RcpMessage()
        rcp_msg.RcpDataResult = t_RcpMessage.RCP_RESULT_OK
        rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION

        print("=====test case1: payload operation read, # no read count, no key=====")
        data = config()
        data.RpdInfo.DepiMcastSession.add()
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(data)
        rcp_msg.RpdDataMessage.RpdDataOperation = 2
        payload = rcp_msg.SerializeToString()
        msg = HalMessage("HalConfig",
                         SrcClientID="testRpdFM",
                         SeqNum=322,
                         CfgMsgType=MsgTypeRpdInfo,
                         CfgMsgPayload=payload)
        return_str = self.hal_client.recvRpdInfo(msg.msg)
        config_data = t_RcpMessage()
        config_data.ParseFromString(msg.msg.CfgMsgPayload)
        recv_rcp_msg = config_data.RpdDataMessage.RpdData
        self.assertEqual(len(recv_rcp_msg.RpdInfo.DepiMcastSession), 2)
        self.assertEqual(config_data.RcpDataResult, t_RcpMessage.RCP_RESULT_OK)

        print("=====test case2: payload operation read, # read with keylist=====")
        data = config()
        for sessionId in range(0, 3):
            req = data.RpdInfo.DepiMcastSession.add()
            req.IpAddrType = 1
            req.GroupIpAddr = "10.79.31.1"
            req.SrcIpAddr = "10.90.31.1"
            req.SessionId = sessionId + 1

        rcp_msg.RpdDataMessage.RpdData.CopyFrom(data)
        rcp_msg.RpdDataMessage.RpdDataOperation = 2
        payload = rcp_msg.SerializeToString()
        msg = HalMessage("HalConfig",
                         SrcClientID="testRpdFM",
                         SeqNum=322,
                         CfgMsgType=MsgTypeRpdInfo,
                         CfgMsgPayload=payload)
        return_str = self.hal_client.recvRpdInfo(msg.msg)
        config_data = t_RcpMessage()
        config_data.ParseFromString(msg.msg.CfgMsgPayload)
        recv_rcp_msg = config_data.RpdDataMessage.RpdData
        for item in recv_rcp_msg.RpdInfo.DepiMcastSession:
            print item
        self.assertEqual(len(recv_rcp_msg.RpdInfo.DepiMcastSession), 3)
        self.assertEquals(config_data.RcpDataResult, t_RcpMessage.RCP_RESULT_OK)

        print("=====test case3: payload operation read, # read with readcount=====")
        data = config()
        data.ReadCount = 3
        req = data.RpdInfo.DepiMcastSession.add()
        req.IpAddrType = 1
        req.GroupIpAddr = "10.79.31.1"
        req.SrcIpAddr = "10.90.31.1"
        req.SessionId = 0

        rcp_msg.RpdDataMessage.RpdData.CopyFrom(data)
        rcp_msg.RpdDataMessage.RpdDataOperation = 2
        payload = rcp_msg.SerializeToString()
        msg = HalMessage("HalConfig",
                         SrcClientID="testRpdFM",
                         SeqNum=322,
                         CfgMsgType=MsgTypeRpdInfo,
                         CfgMsgPayload=payload)
        return_str = self.hal_client.recvRpdInfo(msg.msg)
        config_data = t_RcpMessage()
        config_data.ParseFromString(msg.msg.CfgMsgPayload)
        recv_rcp_msg = config_data.RpdDataMessage.RpdData
        for item in recv_rcp_msg.RpdInfo.DepiMcastSession:
            print item
        self.assertEqual(len(recv_rcp_msg.RpdInfo.DepiMcastSession), 2)
        self.assertEquals(config_data.RcpDataResult, t_RcpMessage.RCP_RESULT_OK)