示例#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
示例#2
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)
    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)
 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)