TEST_F(CmMessageBlockTest, ReserveSpaceTest) { char szData[] = "0123456789xxxx"; const DWORD dwLen = static_cast<DWORD>(strlen(szData)); // the space should be 4 CCmMessageBlock mb(dwLen, szData, 0, dwLen - 4); ASSERT_EQ(4, mb.GetTopLevelSpace()); CmResult rv = mb.ReserveSpace(2); ASSERT_TRUE(CM_SUCCEEDED(rv)); ASSERT_EQ(4, mb.GetTopLevelSpace()); rv = mb.Write("abcd", 4); ASSERT_EQ(0, rv); ASSERT_EQ(0, mb.GetTopLevelSpace()); rv = mb.ReserveSpace(4); ASSERT_TRUE(CM_SUCCEEDED(rv)); ASSERT_EQ(4, mb.GetTopLevelSpace()); rv = mb.Write("efgh", 4); char szBuffer[19] = {0}; rv = mb.Read(szBuffer, dwLen + 4); printf("%s\n", szBuffer); ASSERT_TRUE(CM_SUCCEEDED(rv)); ASSERT_EQ(0, memcmp(szBuffer, "0123456789abcdefgh", dwLen+4)); }
TEST_F(CmMessageBlockTest, ChainedReserveTest) { char szData[] = "0123456789"; const DWORD dwLen = static_cast<DWORD>(strlen(szData)); CCmMessageBlock mb1(dwLen, szData, 0, dwLen); CCmMessageBlock mb2(dwLen, szData, 0, dwLen); mb1.Append(mb2.DuplicateChained()); CmResult rv = mb1.ReserveCapacity(dwLen + 4); ASSERT_TRUE(CM_SUCCEEDED(rv)); rv = mb1.Write("abcd", 4); ASSERT_TRUE(CM_SUCCEEDED(rv)); CCmMessageBlock* mbNext = mb1.GetNext(); rv = mbNext->ReserveCapacity(dwLen + 6); ASSERT_TRUE(CM_SUCCEEDED(rv)); rv = mbNext->Write("abcdef", 6); ASSERT_TRUE(CM_SUCCEEDED(rv)); char szBuffer[31] = {0}; rv = mb1.Read(szBuffer, 30); CM_ASSERTE(CM_SUCCEEDED(rv)); ASSERT_EQ(0, memcmp(szBuffer, "0123456789abcd0123456789abcdef", 30)); }
TEST(COFP10ActSetVlanVidTEST, simple) { COFP10ActSetVlanVid actSetVlanVid; actSetVlanVid.SetVlanVid(0x13dd); actSetVlanVid.Dump(); CCmMessageBlock block(actSetVlanVid.GetEncodeSpace()); CCmByteStreamNetwork stream(block); CmResult rv = actSetVlanVid.StreamTo(stream); EXPECT_TRUE(CM_SUCCEEDED(rv)); COFP10Action *pAction = nullptr; rv = COFP10Action::DecodeAction(stream, pAction); EXPECT_EQ(CM_OK, rv); EXPECT_TRUE(pAction != NULL); EXPECT_EQ(COFP10Action::OFPAT_SET_VLAN_VID, pAction->GetActionType()); EXPECT_EQ(actSetVlanVid.GetActionType(), pAction->GetActionType()); EXPECT_EQ(actSetVlanVid.GetActionLen(), pAction->GetActionLen()); COFP10ActSetVlanVid *pActSetVlanVid = dynamic_cast<COFP10ActSetVlanVid *>(pAction); if (pActSetVlanVid != NULL) { EXPECT_EQ(actSetVlanVid.GetVlanVid(), pActSetVlanVid->GetVlanVid()); } }
TEST(COFP10ActEnqueueTEST, simple) { COFP10ActEnqueue actEnqueue; actEnqueue.SetPortNum(0XABDD); actEnqueue.SetQueueId(0X1345ABDD); actEnqueue.Dump(); CCmMessageBlock block(actEnqueue.GetEncodeSpace()); CCmByteStreamNetwork stream(block); CmResult rv = actEnqueue.StreamTo(stream); EXPECT_TRUE(CM_SUCCEEDED(rv)); COFP10Action *pAction = nullptr; rv = COFP10Action::DecodeAction(stream, pAction); EXPECT_EQ(CM_OK, rv); EXPECT_TRUE(pAction != NULL); EXPECT_EQ(COFP10Action::OFPAT_ENQUEUE, pAction->GetActionType()); EXPECT_EQ(actEnqueue.GetActionType(), pAction->GetActionType()); EXPECT_EQ(actEnqueue.GetActionLen(), pAction->GetActionLen()); COFP10ActEnqueue *pActEnqueue = dynamic_cast<COFP10ActEnqueue *>(pAction); if (pActEnqueue != NULL) { EXPECT_EQ(actEnqueue.GetPortNum(), pActEnqueue->GetPortNum()); EXPECT_EQ(actEnqueue.GetQueueId(), pActEnqueue->GetQueueId()); } }
TEST(COFP10ActOutputTEST, simple) { COFP10ActOutput actOutput; actOutput.SetOutPort(0XABED); actOutput.SetMaxLen(COFP10ActOutput::OFPCML_NO_BUFFER); actOutput.Dump(); ACE_Message_Block block(actOutput.GetEncodeSpace()); ACE_OutputCDR outStream(&block); CmResult rv = actOutput.StreamTo(outStream); EXPECT_TRUE(CM_SUCCEEDED(rv)); COFP10Action *pAction = nullptr; ACE_InputCDR inStream(&block); rv = COFP10Action::DecodeAction(inStream, pAction); EXPECT_EQ(CM_OK, rv); EXPECT_TRUE(pAction != NULL); EXPECT_EQ(COFP10Action::OFPAT_OUTPUT, pAction->GetActionType()); EXPECT_EQ(actOutput.GetActionType(), pAction->GetActionType()); EXPECT_EQ(actOutput.GetActionLen(), pAction->GetActionLen()); COFP10ActOutput *pActOutput = dynamic_cast<COFP10ActOutput *>(pAction); if (pActOutput != NULL) { EXPECT_EQ(actOutput.GetOutPort(), pActOutput->GetOutPort()); EXPECT_EQ(actOutput.GetMaxLen(), pActOutput->GetMaxLen()); } }
TEST(COFP10ActSetTpPortTEST, simple) { COFP10ActSetTpPort actSetTpPort(COFP10Action::OFPAT_SET_TP_DST); actSetTpPort.SetTpPort(0xab01); actSetTpPort.Dump(); CCmMessageBlock block(actSetTpPort.GetEncodeSpace()); CCmByteStreamNetwork stream(block); CmResult rv = actSetTpPort.StreamTo(stream); EXPECT_TRUE(CM_SUCCEEDED(rv)); COFP10Action *pAction = nullptr; rv = COFP10Action::DecodeAction(stream, pAction); EXPECT_EQ(CM_OK, rv); EXPECT_TRUE(pAction != NULL); EXPECT_EQ(COFP10Action::OFPAT_SET_TP_DST, pAction->GetActionType()); EXPECT_EQ(actSetTpPort.GetActionType(), pAction->GetActionType()); EXPECT_EQ(actSetTpPort.GetActionLen(), pAction->GetActionLen()); COFP10ActSetTpPort *pActSetTpPort = dynamic_cast<COFP10ActSetTpPort *>(pAction); if (pActSetTpPort != NULL) { EXPECT_EQ(actSetTpPort.GetTpPort(), pActSetTpPort->GetTpPort()); } }
TEST(COFP10ActSetNwAddrTEST, simple) { COFP10ActSetNwAddr actSetNwAddr(COFP10Action::OFPAT_SET_NW_SRC); actSetNwAddr.SetNwAddr(0xab11ee77); actSetNwAddr.Dump(); CCmMessageBlock block(actSetNwAddr.GetEncodeSpace()); CCmByteStreamNetwork stream(block); CmResult rv = actSetNwAddr.StreamTo(stream); EXPECT_TRUE(CM_SUCCEEDED(rv)); COFP10Action *pAction = nullptr; rv = COFP10Action::DecodeAction(stream, pAction); EXPECT_EQ(CM_OK, rv); EXPECT_TRUE(pAction != NULL); EXPECT_EQ(COFP10Action::OFPAT_SET_NW_SRC, pAction->GetActionType()); EXPECT_EQ(actSetNwAddr.GetActionType(), pAction->GetActionType()); EXPECT_EQ(actSetNwAddr.GetActionLen(), pAction->GetActionLen()); COFP10ActSetNwAddr *pActSetNwAddr = dynamic_cast<COFP10ActSetNwAddr *>(pAction); if (pActSetNwAddr != NULL) { EXPECT_EQ(actSetNwAddr.GetNwAddr(), pActSetNwAddr->GetNwAddr()); } }
TEST(COFP10ActSetDlAddrTEST, simple) { ACE_CDR::Octet addr[OFP_ETH_ALEN] = {0xad, 0x0, 0x13, 0x55, 0xed, 0xff}; COFP10ActSetDlAddr actSetDlAddr(COFP10Action::OFPAT_SET_DL_DST); actSetDlAddr.SetDlAddr(addr); EXPECT_EQ(0, ::memcmp(addr, actSetDlAddr.GetDlAddr(), OFP_ETH_ALEN)); actSetDlAddr.Dump(); CCmMessageBlock block(actSetDlAddr.GetEncodeSpace()); CCmByteStreamNetwork stream(block); CmResult rv = actSetDlAddr.StreamTo(stream); EXPECT_TRUE(CM_SUCCEEDED(rv)); COFP10Action *pAction = nullptr; rv = COFP10Action::DecodeAction(stream, pAction); EXPECT_EQ(CM_OK, rv); EXPECT_TRUE(pAction != NULL); EXPECT_EQ(COFP10Action::OFPAT_SET_DL_DST, pAction->GetActionType()); EXPECT_EQ(actSetDlAddr.GetActionType(), pAction->GetActionType()); EXPECT_EQ(actSetDlAddr.GetActionLen(), pAction->GetActionLen()); COFP10ActSetDlAddr *pActSetDlAddr = dynamic_cast<COFP10ActSetDlAddr *>(pAction); if (pActSetDlAddr != NULL) { EXPECT_EQ(0, ::memcmp(addr, pActSetDlAddr->GetDlAddr(), OFP_ETH_ALEN)); } }
TEST(COFP10ActSetNwTosTEST, simple) { COFP10ActSetNwTos actSetNwTos; actSetNwTos.SetNwTos(0xab); actSetNwTos.Dump(); CCmMessageBlock block(actSetNwTos.GetEncodeSpace()); CCmByteStreamNetwork stream(block); CmResult rv = actSetNwTos.StreamTo(stream); EXPECT_TRUE(CM_SUCCEEDED(rv)); COFP10Action *pAction = nullptr; rv = COFP10Action::DecodeAction(stream, pAction); EXPECT_EQ(CM_OK, rv); EXPECT_TRUE(pAction != NULL); EXPECT_EQ(COFP10Action::OFPAT_SET_NW_TOS, pAction->GetActionType()); EXPECT_EQ(actSetNwTos.GetActionType(), pAction->GetActionType()); EXPECT_EQ(actSetNwTos.GetActionLen(), pAction->GetActionLen()); COFP10ActSetNwTos *pActSetNwTos = dynamic_cast<COFP10ActSetNwTos *>(pAction); if (pActSetNwTos != NULL) { EXPECT_EQ(actSetNwTos.GetNwTos(), pActSetNwTos->GetNwTos()); } }
TEST_F(CCmDns6ManagerTest,Dns6CancelResolveOK) { CCmComAutoPtr<CCmDns6Record> pDns6Record; CmResult rv = m_pDns6Manger->AsyncResolve(pDns6Record.ParaOut(),"TestFail",m_pDns6Observer,TRUE); EXPECT_TRUE(CM_ERROR_WOULD_BLOCK == rv); rv = m_pDns6Manger->CancelResolve(m_pDns6Observer); EXPECT_TRUE(CM_SUCCEEDED(rv)); }
TEST(COFP10ActStripVlanTEST, simple) { COFP10ActStripVlan actStripVlan; actStripVlan.Dump(); CCmMessageBlock block(actStripVlan.GetEncodeSpace()); CCmByteStreamNetwork stream(block); CmResult rv = actStripVlan.StreamTo(stream); EXPECT_TRUE(CM_SUCCEEDED(rv)); COFP10Action *pAction = nullptr; rv = COFP10Action::DecodeAction(stream, pAction); EXPECT_EQ(CM_OK, rv); EXPECT_TRUE(pAction != NULL); EXPECT_EQ(COFP10Action::OFPAT_STRIP_VLAN, pAction->GetActionType()); EXPECT_EQ(actStripVlan.GetActionType(), pAction->GetActionType()); EXPECT_EQ(actStripVlan.GetActionLen(), pAction->GetActionLen()); }
CmResult COFP10PacketOutMsg::StreamTo(ACE_OutputCDR &os) { CmResult lRet = CM_ERROR_FAILURE; lRet = COFPMessage::StreamTo(os); if (CM_FAILED(lRet)) { ACE_ERROR((LM_ERROR, ACE_TEXT("COFP10PacketOutMsg::StreamTo, COFPMessage::StreamTo fail\n"))); return lRet; } os<<m_tMember.buffer_id; os<<m_tMember.in_port; os<<m_tMember.actions_len; bool bGood = os.good_bit(); CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE); std::list<COFP10Action *>::const_iterator it = m_action_list.begin(); while (it != m_action_list.end()) { lRet = (*it)->StreamTo(os); CM_ASSERT_RETURN(CM_SUCCEEDED(lRet), CM_ERROR_FAILURE); it++; } if (m_PacketData) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("COFP10PacketOutMsg::StreamTo, m_PacketData->total_length() = %u\n"), m_PacketData->total_length())); std::string str = m_PacketData->flatten_chained(); os.write_char_array(str.c_str(), str.length()); } bGood = os.good_bit(); CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE); return CM_OK; }
TEST_F(CmMessageBlockTest, ReserveTest) { char szData[] = "0123456789abcdef"; DWORD dwDataLen = static_cast<DWORD>(strlen(szData)); CCmMessageBlock mb(dwDataLen, szData, 0, dwDataLen); LPCSTR pReadPtr = mb.GetTopLevelReadPtr(); LPCSTR pWritePtr = mb.GetTopLevelWritePtr(); DWORD dwSpace = mb.GetTopLevelSpace(); CmResult rv = mb.ReserveCapacity(10); ASSERT_TRUE(CM_SUCCEEDED(rv)); ASSERT_EQ(pReadPtr, mb.GetTopLevelReadPtr()); ASSERT_EQ(pWritePtr, mb.GetTopLevelWritePtr()); ASSERT_EQ(0, mb.GetTopLevelSpace()); rv = mb.ReserveCapacity(dwDataLen); ASSERT_TRUE(CM_SUCCEEDED(rv)); ASSERT_EQ(pReadPtr, mb.GetTopLevelReadPtr()); ASSERT_EQ(pWritePtr, mb.GetTopLevelWritePtr()); ASSERT_EQ(0, mb.GetTopLevelSpace()); char szBuffer[128] = {0}; rv = mb.Read(szBuffer, 2); ASSERT_TRUE(CM_SUCCEEDED(rv)); rv = mb.ReserveCapacity(20); ASSERT_TRUE(CM_SUCCEEDED(rv)); ASSERT_EQ(14, mb.GetTopLevelLength()); ASSERT_EQ(4 , mb.GetTopLevelSpace()); char szAppendData[] = "0123"; rv = mb.Write(szAppendData, 4); ASSERT_TRUE(CM_SUCCEEDED(rv)); rv = mb.Read(szBuffer + 2, 18); ASSERT_TRUE(CM_SUCCEEDED(rv)); ASSERT_TRUE(CM_SUCCEEDED(rv)); ASSERT_EQ(0, memcmp(szBuffer, mb.GetTopLevelReadPtr()-20, 20)); }
CmResult COFP10PacketOutMsg::StreamFrom(ACE_InputCDR &is) { CmResult lRet = CM_ERROR_FAILURE; lRet = COFPMessage::StreamFrom(is); if (CM_FAILED(lRet)) { ACE_ERROR((LM_ERROR, ACE_TEXT("COFP10PacketOutMsg::StreamFrom, COFPMessage::StreamFrom fail\n"))); return lRet; } is>>m_tMember.buffer_id; is>>m_tMember.in_port; is>>m_tMember.actions_len; bool bGood = is.good_bit(); CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE); if (m_tMember.actions_len > 0) { ACE_INT16 swListLen = m_tMember.actions_len; ACE_UINT16 i = 0; while (swListLen > 0) { COFP10Action *action = nullptr; lRet = COFP10Action::DecodeAction(is, action); if (CM_SUCCEEDED(lRet)) { m_action_list.push_back(action); ACE_DEBUG((LM_DEBUG, ACE_TEXT("action[%u], len=%u\n"), i++, action->GetActionLen())); swListLen -= action->GetActionLen(); } else { ACE_ERROR((LM_ERROR, ACE_TEXT("COFP10PacketOutMsg::StreamFrom, COFP10Action::DecodeAction failed\n"))); return CM_ERROR_FAILURE; } } } ACE_INT16 swDataLen = m_wLength - COFPMessage::GetStreamLen() - sizeof(m_tMember) - m_tMember.actions_len; if (swDataLen < 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("COFP10PacketOutMsg::StreamFrom, packet data len(%d) is invalid\n"), swDataLen)); ACE_ASSERT(0); return CM_ERROR_FAILURE; } if (swDataLen == 0) { m_wDataLen = 0; return CM_OK; } ACE_Message_Block Data(swDataLen); ACE_DEBUG((LM_DEBUG, ACE_TEXT("COFP10PacketOutMsg::StreamFrom, wr_ptr = %p, space = %u\n"), Data.wr_ptr(), Data.space())); bGood = is.read_char_array(Data.wr_ptr(), swDataLen); CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE); Data.wr_ptr((size_t)swDataLen); if (m_PacketData) { m_PacketData->append(Data.duplicate()); } else { m_PacketData = Data.duplicate(); } m_wDataLen += swDataLen; return CM_OK; }
CmResult COFP13PacketOutMsg::StreamFrom(ACE_InputCDR &is) { ACE_INT32 remainActLen = 0; ACE_INT32 packet_length = 0; ACE_CDR::Octet pad[6]; CmResult lRet = CM_ERROR_FAILURE; lRet = COFPMessage::StreamFrom(is); if (CM_FAILED(lRet)) { ACE_ERROR((LM_ERROR, ACE_TEXT("COFP13PacketOutMsg::StreamFrom(), COFPMessage::StreamFrom fail\n"))); return lRet; } ACE_DEBUG((LM_DEBUG, ACE_TEXT("COFP13PacketOutMsg::StreamFrom(): \n"))); is>>m_buffer_id; is>>m_in_port; is>>m_actions_len; is.read_octet_array(pad, sizeof(pad)); bool bGood = is.good_bit(); CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE); ACE_DEBUG((LM_DEBUG, ACE_TEXT("m_actions_len=%u\n"), m_actions_len)); if (m_actions_len>0) { remainActLen = m_actions_len; ACE_UINT16 i = 0; while (remainActLen > 0) { COFP13Action *action = nullptr; CmResult result = COFP13Action::DecodeAction(is, action); if (CM_SUCCEEDED(result)) { m_action_list.push_back(action); ACE_DEBUG((LM_DEBUG, ACE_TEXT("action[%u], len=%u\n"), i++, action->GetStreamLen())); remainActLen = remainActLen - (action->GetStreamLen()); } else { ACE_ERROR((LM_ERROR, ACE_TEXT("COFP13Action::DecodeAction failed.\n"))); return CM_ERROR_FAILURE; } } } ACE_UINT32 length = sizeof(m_buffer_id)+sizeof(m_in_port)+sizeof(m_actions_len)+sizeof(m_pad); ACE_DEBUG((LM_DEBUG, ACE_TEXT("length=%u\n"), length)); packet_length = m_wLength-COFPMessage::GetStreamLen()-length-m_actions_len; ACE_DEBUG((LM_DEBUG, ACE_TEXT("packet_length=%d, GetStreamLen=%u\n"), packet_length, GetStreamLen())); if (packet_length < 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("COFP13PacketOutMsg::StreamFrom, error, length=%u, actionlength=%u\n"), length, m_actions_len)); return CM_ERROR_FAILURE; } ACE_Message_Block data(packet_length); ACE_DEBUG((LM_DEBUG, ACE_TEXT("COFP13PacketOutMsg::StreamFrom, wr_ptr=%p, space=%u\n"), data.wr_ptr(), data.space())); bGood = is.read_char_array(data.wr_ptr(), packet_length); CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE); data.wr_ptr((size_t)packet_length); if (m_PacketData) { m_PacketData->append(data.duplicate()); } else { m_PacketData = data.duplicate(); } return CM_OK; }
CmResult COFP13PacketOutMsg::StreamTo(ACE_OutputCDR &os) { CmResult lRet = CM_ERROR_FAILURE; ACE_CDR::Octet pad[6]; lRet = COFPMessage::StreamTo(os); if (CM_FAILED(lRet)) { ACE_ERROR((LM_ERROR, ACE_TEXT("COFP13PacketOutMsg::StreamTo, COFPMessage::StreamTo fail\n"))); return lRet; } ACE_DEBUG((LM_DEBUG, ACE_TEXT("COFP13PacketOutMsg::StreamTo():\n"))); ACE_DEBUG((LM_DEBUG, ACE_TEXT("msgLen=%u\n"), GetMessageLength())); os<<m_buffer_id; os<<m_in_port; os<<m_actions_len; os.write_octet_array(pad, sizeof(pad)); bool bGood = os.good_bit(); CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE); ACE_DEBUG((LM_DEBUG, ACE_TEXT("m_actions_len=%u\n"), m_actions_len)); #if 0 while(!m_action_list.empty()) { CCmComAutoPtr<COpenFlowProtAction> action; action = m_action_list.front(); m_action_list.pop_front(); action->EncodeAction(os); } #endif ACE_UINT16 i = 0; std::list<COFP13Action *>::const_iterator it = m_action_list.begin(); while(it != m_action_list.end()) { lRet = (*it)->StreamTo(os); CM_ASSERT_RETURN(CM_SUCCEEDED(lRet), CM_ERROR_FAILURE); ACE_DEBUG((LM_DEBUG, ACE_TEXT("action[%u]'s length=%u\n"), i++, (*it)->GetActionLen())); bGood = os.good_bit(); CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE); it++; } // just for debugging ACE_UINT32 length = sizeof(m_buffer_id)+sizeof(m_in_port)+sizeof(m_actions_len)+sizeof(m_pad); ACE_DEBUG((LM_DEBUG, ACE_TEXT("length=%u\n"), length)); ACE_INT32 dataLen = GetStreamLen()-COFPMessage::GetStreamLen()-length-m_actions_len; ACE_DEBUG((LM_DEBUG, ACE_TEXT("dataLen=%d\n"), dataLen)); if (m_PacketData) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("m_PacketData->total_length() = %u\n"), m_PacketData->total_length())); std::string str = m_PacketData->flatten_chained(); bGood = os.write_char_array(str.c_str(), str.length()); CM_ASSERT_RETURN(bGood, CM_ERROR_FAILURE); } return CM_OK; }
TEST_F(CCmDns6ManagerTest,Dns6ShutDownOK) { CmResult rv = m_pDns6Manger->Shutdown(); EXPECT_TRUE(CM_SUCCEEDED(rv)); }