天天看點

ns2.34中Bug一例

在ns2.34下擴充安裝LEACH協定,編譯時顯示錯誤:

mac/wireless-phy.cc: In member function ‘virtual void WirelessPhy::sendDown(Packet*)’:

mac/wireless-phy.cc:278: error: ‘class Node’ has no member named ‘getLoc’

mac/wireless-phy.cc: In member function ‘virtual int WirelessPhy::sendUp(Packet*)’:

mac/wireless-phy.cc:501: error: ‘class Node’ has no member named ‘getLoc’

make: *** [mac/wireless-phy.o] Error 1

錯誤提示在wireless-phy.cc的第278, 501行,類node的getLoc函數不存在。

通過檢視源代碼, 發現函數getLoc是類MobileNode的一個内聯函數,而MobileNode是類Node的子類。再次檢視,發現Wireless-phy.h中有一行加了注釋:

    // Why phy has a node_ and this guy has it all over again??

    //  MobileNode* node_;             // Mobile Node to which interface is attached .

看來更新ns2代碼的這個人沒有注意到這個問題,這裡的node_看似與Node類中的成員node_重複。但實際上還是有差别。找到問題了,打開注釋,同時修改wireless-phy.cc中的236行代碼:

else if (strcasecmp(argv[1], "node") == 0) {

            assert(node_ == 0);

            node_ = (Node *)obj;          //這一行改為node_=(MobileNode*)obj;

            return TCL_OK;

        }

問題解決。