public new object Clone()
 {
     PEQMessageBuildTree msg =
         new PEQMessageBuildTree(_DestinationID, _SenderID, _SequenceNumber,
         _SinkID, _HopCount);
     msg._nextHopCheat = _nextHopCheat;
     return msg;
 }
        /*       / \
         *     // | \\
         *    /   |   \
         *        |           */
        public void Initialize()
        {
            Notify(GenerateStaticReport());  // For Visualization

            // Set initial hello timer to random value
            PEQTimerHello timer =
                new PEQTimerHello(_randomValue.NextDouble() * _TIMER_HELLO, this);
            _eventManager.AddEvent(timer);

            if (_isSink)
            {
                // Send build tree (at future time...)
                PEQMessageBuildTree msgBT = new PEQMessageBuildTree(new VarID(_NUM_ID_BYTES), _id,
                    _sequenceNumber++, _id, 0x00);
                double time = _randomValue.NextDouble() * _TIMER_BUILDTREE;
                msgBT._nextHopCheat = _location;
                PEQTimerMessage outputTimer = new PEQTimerMessage(msgBT, time, this);
                _eventManager.AddEvent(outputTimer);

                // Add to BT to subscription table (this is early........)
                PEQTableEntrySubscription sub = new PEQTableEntrySubscription();
                sub._SinkID = _id;
                sub._nextHopCheat = _location;
                sub._HopCount = 0;
                sub._DestinationID = _id;
                sub._CriteriaType = 0x0000;
                sub._Valid = true;
                _tableSubscription.Add(sub);

                // Send subscription (at future time...)
                PEQMessageSubscribe msgSub = new PEQMessageSubscribe(new VarID(_NUM_ID_BYTES), _id,
                    _sequenceNumber++, _id, 0x00,
                    new PEQSubscriptionInfo(0x0001,
                        new PEQSubscriptionCriteria()));
                time = time + _TIMER_SUBSCRIBE;
                msgSub._nextHopCheat = _location;
                outputTimer = new PEQTimerMessage(msgSub, time, this);
                _eventManager.AddEvent(outputTimer);

                // Add subscription to subscription table (this is very early........)
                sub = new PEQTableEntrySubscription();
                sub._SinkID = _id;
                sub._nextHopCheat = _location;
                sub._HopCount = 0;
                sub._DestinationID = _id;
                sub._CriteriaType = 0x0001;
                sub._Valid = true;
                _tableSubscription.Add(sub);

                updateRoutingTable();
            }
        }
        private void processBuildTree(PEQMessageBuildTree msg)
        {
            bool found = false;   // if the Sink was found in the table
            bool update = false;  // if the Sink was added / modified
            // Look for Sink ID in Subscription Table to update
            foreach (PEQTableEntrySubscription entry in _tableSubscription)
            {
                if ((entry._SinkID == msg._SinkID) &&
                    (entry._CriteriaType == 0x0000))
                {
                    found = true;
                    if (msg._HopCount + 1 < entry._HopCount)
                    {
                        update = true;
                        entry._HopCount = (byte)(msg._HopCount + 1);
                        entry._DestinationID = msg._SenderID;
                        entry._nextHopCheat = msg._nextHopCheat;
                    }
                }
            }

            if (!found)
            {
                update = true;
                PEQTableEntrySubscription entry = new PEQTableEntrySubscription();
                entry._CriteriaType = 0x0000;
                entry._DestinationID = msg._SenderID;
                entry._HopCount = (byte)(msg._HopCount + 1);
                entry._SinkID = msg._SinkID;
                entry._nextHopCheat = msg._nextHopCheat;
                _tableSubscription.Add(entry);
            }

            if (update)
            {
                updateRoutingTable();
                sendBuildTree(msg);
            }
        }
        private void sendBuildTree(PEQMessageBuildTree msg)
        {
            // Propagate BuildTree message
            PEQMessageBuildTree newMsg = (PEQMessageBuildTree)msg.Clone();
            newMsg._SenderID = _id;
            newMsg._SequenceNumber = 0x00;
            newMsg._HopCount = (byte)(msg._HopCount + 1);
            newMsg._nextHopCheat = _location;

            PEQTimerMessage timerEvent = new PEQTimerMessage(newMsg,
                _eventManager.CurrentClock + _TIMER_WAIT_SEND, this);
            _eventManager.AddEvent(timerEvent);
        }