Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        /*       / \
         *     // | \\
         *    /   |   \
         *        |           */
        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();
            }
        }
Exemplo n.º 3
0
        private void processSearch(PEQMessageSearch msg)
        {
            PEQTableEntrySubscription subscriptionEntry = null;

            foreach (PEQTableEntrySubscription entry in _tableSubscription)
            {
                if ((entry._SinkID == msg._SinkID) && entry._Valid)
                {
                    if (subscriptionEntry == null)
                        subscriptionEntry = entry;
                    else if (subscriptionEntry._HopCount > entry._HopCount)
                        subscriptionEntry = entry;
                }
            }

            if (subscriptionEntry == null)
            {
                subscriptionEntry = new PEQTableEntrySubscription();
                subscriptionEntry._HopCount = 0xff;
                subscriptionEntry._Valid = false;
                subscriptionEntry._nextHopCheat = null;
                subscriptionEntry._CriteriaType = 0x0000;
            }

            sendResponse(subscriptionEntry, msg);
        }
Exemplo n.º 4
0
        private void sendResponse(PEQTableEntrySubscription Subscription,
            PEQMessageSearch msg)
        {
            PEQMessageResponse newMsg = new PEQMessageResponse(msg._SenderID,
                _id, msg._SequenceNumber, Subscription._HopCount,
                msg._SinkID);
            newMsg._nextHopCheat = _location;

            PEQTimerMessage timerEvent = new PEQTimerMessage(newMsg,
                _eventManager.CurrentClock + _TIMER_RANDOM_WAIT_SEND
                * RandomValue.NextDouble(), this);
            _eventManager.AddEvent(timerEvent);
        }
Exemplo n.º 5
0
        private void processResponse(PEQMessageResponse msg)
        {
            bool allReceived = true;
            PEQTableEntrySearch winner = null;
            Byte hopCount = 0xFF;
            foreach (PEQTableEntrySearch entry in _tableSearch)
            {
                if ((msg._SinkID == entry._SinkID)
                    && (msg._SenderID == entry._DestinationID))
                {
                    entry._ResponseReceived = true;
                    entry._HopCount = msg._HopCount;
                    entry._nextHopCheat = msg._nextHopCheat;

                    // Update Subscription
                    bool found = false;
                    foreach (PEQTableEntrySubscription subscription in
                        _tableSubscription)
                    {
                        if ((subscription._DestinationID == msg._SenderID)
                            && (subscription._SinkID == msg._SinkID))
                        {
                            found = true;
                            subscription._HopCount = msg._HopCount;
                            subscription._Valid = true;
                            subscription._nextHopCheat = msg._nextHopCheat;
                            subscription._Timestamp = _eventManager.CurrentClock;
                        }
                    }
                    if (!found && (msg._HopCount < 0xFF)) // add!
                    {
                        PEQTableEntrySubscription newSubscription = new PEQTableEntrySubscription();
                        newSubscription._CriteriaType = 0x0001;  // this should be included with Search/Response message
                        newSubscription._DestinationID = msg._SenderID;
                        newSubscription._HopCount = msg._HopCount;
                        newSubscription._nextHopCheat = msg._nextHopCheat;
                        newSubscription._SinkID = msg._SinkID;
                        newSubscription._Timestamp = _eventManager.CurrentClock;
                        newSubscription._Valid = true;

                        _tableSubscription.Add(newSubscription);
                    }
                }
                else if ((msg._SinkID == entry._SinkID)
                    && (!entry._ResponseReceived))
                    allReceived = false;
                if (entry._HopCount < hopCount)
                {
                    hopCount = entry._HopCount;
                    winner = entry;
                }
            }

            if (allReceived)
            {
                completeSearch(winner);
            }
        }