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()
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)
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)